Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 2023 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Algebra.Order.ToIntervalMod
import Mathlib.Analysis.SpecialFunctions.Log.Base
/-!
# Akra-Bazzi theorem: The polynomial growth condition
This file defines and develops an API for the polynomial growth condition that appears in the
statement of the Akra-Bazzi theorem: for the Akra-Bazzi theorem to hold, the function `g` must
satisfy the condition that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for u between b*n and n for any constant
`b ∈ (0,1)`.
## Implementation notes
Our definition states that the condition must hold for any `b ∈ (0,1)`. This is equivalent to
only requiring it for `b = 1/2` or any other particular value between 0 and 1. While this
could in principle make it harder to prove that a particular function grows polynomially,
this issue doesn't seem to arise in practice.
-/
open Finset Real Filter Asymptotics
open scoped Topology
namespace AkraBazziRecurrence
/-- The growth condition that the function `g` must satisfy for the Akra-Bazzi theorem to apply.
It roughly states that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for `u` between `b*n` and `n` for any
constant `b ∈ (0,1)`. -/
def GrowsPolynomially (f : ℝ → ℝ) : Prop :=
∀ b ∈ Set.Ioo 0 1, ∃ c₁ > 0, ∃ c₂ > 0,
∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, f u ∈ Set.Icc (c₁ * (f x)) (c₂ * f x)
namespace GrowsPolynomially
lemma congr_of_eventuallyEq {f g : ℝ → ℝ} (hfg : f =ᶠ[atTop] g) (hg : GrowsPolynomially g) :
GrowsPolynomially f := by
intro b hb
have hg' := hg b hb
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hg'⟩ := hg'
refine ⟨c₁, hc₁_mem, c₂, hc₂_mem, ?_⟩
filter_upwards [hg', (tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hfg, hfg]
with x hx₁ hx₂ hx₃
intro u hu
rw [hx₂ u hu.1, hx₃]
exact hx₁ u hu
lemma iff_eventuallyEq {f g : ℝ → ℝ} (h : f =ᶠ[atTop] g) :
GrowsPolynomially f ↔ GrowsPolynomially g :=
⟨fun hf => congr_of_eventuallyEq h.symm hf, fun hg => congr_of_eventuallyEq h hg⟩
variable {f : ℝ → ℝ}
lemma eventually_atTop_le {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) :
∃ c > 0, ∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, f u ≤ c * f x := by
obtain ⟨c₁, _, c₂, hc₂, h⟩ := hf b hb
refine ⟨c₂, hc₂, ?_⟩
filter_upwards [h]
exact fun _ H u hu => (H u hu).2
lemma eventually_atTop_le_nat {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) :
∃ c > 0, ∀ᶠ (n : ℕ) in atTop, ∀ u ∈ Set.Icc (b * n) n, f u ≤ c * f n := by
obtain ⟨c, hc_mem, hc⟩ := hf.eventually_atTop_le hb
exact ⟨c, hc_mem, hc.natCast_atTop⟩
lemma eventually_atTop_ge {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) :
∃ c > 0, ∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, c * f x ≤ f u := by
obtain ⟨c₁, hc₁, c₂, _, h⟩ := hf b hb
refine ⟨c₁, hc₁, ?_⟩
filter_upwards [h]
exact fun _ H u hu => (H u hu).1
lemma eventually_atTop_ge_nat {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) :
∃ c > 0, ∀ᶠ (n : ℕ) in atTop, ∀ u ∈ Set.Icc (b * n) n, c * f n ≤ f u := by
obtain ⟨c, hc_mem, hc⟩ := hf.eventually_atTop_ge hb
exact ⟨c, hc_mem, hc.natCast_atTop⟩
lemma eventually_zero_of_frequently_zero (hf : GrowsPolynomially f) (hf' : ∃ᶠ x in atTop, f x = 0) :
∀ᶠ x in atTop, f x = 0 := by
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hf⟩ := hf (1/2) (by norm_num)
rw [frequently_atTop] at hf'
filter_upwards [eventually_forall_ge_atTop.mpr hf, eventually_gt_atTop 0] with x hx hx_pos
obtain ⟨x₀, hx₀_ge, hx₀⟩ := hf' (max x 1)
have x₀_pos := calc
0 < 1 := by norm_num
_ ≤ x₀ := le_of_max_le_right hx₀_ge
have hmain : ∀ (m : ℕ) (z : ℝ), x ≤ z →
z ∈ Set.Icc ((2 : ℝ)^(-(m : ℤ) -1) * x₀) ((2 : ℝ)^(-(m : ℤ)) * x₀) → f z = 0 := by
intro m
induction m with
| zero =>
simp only [CharP.cast_eq_zero, neg_zero, zero_sub, zpow_zero, one_mul] at *
specialize hx x₀ (le_of_max_le_left hx₀_ge)
simp only [hx₀, mul_zero, Set.Icc_self, Set.mem_singleton_iff] at hx
refine fun z _ hz => hx _ ?_
simp only [zpow_neg, zpow_one] at hz
simp only [one_div, hz]
| succ k ih =>
intro z hxz hz
simp only [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one] at *
have hx' : x ≤ (2 : ℝ)^(-(k : ℤ) - 1) * x₀ := by
calc x ≤ z := hxz
_ ≤ _ := by simp only [neg_add, ← sub_eq_add_neg] at hz; exact hz.2
specialize hx ((2 : ℝ)^(-(k : ℤ) - 1) * x₀) hx' z
specialize ih ((2 : ℝ)^(-(k : ℤ) - 1) * x₀) hx' ?ineq
case ineq =>
rw [Set.left_mem_Icc]
gcongr
· norm_num
· omega
simp only [ih, mul_zero, Set.Icc_self, Set.mem_singleton_iff] at hx
refine hx ⟨?lb₁, ?ub₁⟩
case lb₁ =>
rw [one_div, ← zpow_neg_one, ← mul_assoc, ← zpow_add₀ (by norm_num)]
have h₁ : (-1 : ℤ) + (-k - 1) = -k - 2 := by ring
have h₂ : -(k + (1 : ℤ)) - 1 = -k - 2 := by ring
rw [h₁]
rw [h₂] at hz
exact hz.1
case ub₁ =>
have := hz.2
simp only [neg_add, ← sub_eq_add_neg] at this
exact this
refine hmain ⌊-logb 2 (x / x₀)⌋₊ x le_rfl ⟨?lb, ?ub⟩
case lb =>
rw [← le_div_iff₀ x₀_pos]
refine (logb_le_logb (b := 2) (by norm_num) (zpow_pos (by norm_num) _)
(by positivity)).mp ?_
rw [← rpow_intCast, logb_rpow (by norm_num) (by norm_num), ← neg_le_neg_iff]
simp only [Int.cast_sub, Int.cast_neg, Int.cast_natCast, Int.cast_one, neg_sub, sub_neg_eq_add]
calc -logb 2 (x/x₀) ≤ ⌈-logb 2 (x/x₀)⌉₊ := Nat.le_ceil (-logb 2 (x / x₀))
_ ≤ _ := by rw [add_comm]; exact_mod_cast Nat.ceil_le_floor_add_one _
case ub =>
rw [← div_le_iff₀ x₀_pos]
refine (logb_le_logb (b := 2) (by norm_num) (by positivity)
(zpow_pos (by norm_num) _)).mp ?_
rw [← rpow_intCast, logb_rpow (by norm_num) (by norm_num), ← neg_le_neg_iff]
simp only [Int.cast_neg, Int.cast_natCast, neg_neg]
have : 0 ≤ -logb 2 (x / x₀) := by
rw [neg_nonneg]
refine logb_nonpos (by norm_num) (by positivity) ?_
rw [div_le_one x₀_pos]
exact le_of_max_le_left hx₀_ge
exact_mod_cast Nat.floor_le this
lemma eventually_atTop_nonneg_or_nonpos (hf : GrowsPolynomially f) :
(∀ᶠ x in atTop, 0 ≤ f x) ∨ (∀ᶠ x in atTop, f x ≤ 0) := by
obtain ⟨c₁, _, c₂, _, h⟩ := hf (1/2) (by norm_num)
match lt_trichotomy c₁ c₂ with
| .inl hlt => -- c₁ < c₂
left
filter_upwards [h, eventually_ge_atTop 0] with x hx hx_nonneg
have h' : 3 / 4 * x ∈ Set.Icc (1 / 2 * x) x := by
rw [Set.mem_Icc]
exact ⟨by gcongr ?_ * x; norm_num, by linarith⟩
have hu := hx (3/4 * x) h'
have hu := Set.nonempty_of_mem hu
rw [Set.nonempty_Icc] at hu
have hu' : 0 ≤ (c₂ - c₁) * f x := by linarith
exact nonneg_of_mul_nonneg_right hu' (by linarith)
| .inr (.inr hgt) => -- c₂ < c₁
right
filter_upwards [h, eventually_ge_atTop 0] with x hx hx_nonneg
have h' : 3 / 4 * x ∈ Set.Icc (1 / 2 * x) x := by
rw [Set.mem_Icc]
exact ⟨by gcongr ?_ * x; norm_num, by linarith⟩
have hu := hx (3/4 * x) h'
have hu := Set.nonempty_of_mem hu
rw [Set.nonempty_Icc] at hu
have hu' : (c₁ - c₂) * f x ≤ 0 := by linarith
exact nonpos_of_mul_nonpos_right hu' (by linarith)
| .inr (.inl heq) => -- c₁ = c₂
have hmain : ∃ c, ∀ᶠ x in atTop, f x = c := by
simp only [heq, Set.Icc_self, Set.mem_singleton_iff, one_mul] at h
rw [eventually_atTop] at h
obtain ⟨n₀, hn₀⟩ := h
refine ⟨f (max n₀ 2), ?_⟩
rw [eventually_atTop]
refine ⟨max n₀ 2, ?_⟩
refine Real.induction_Ico_mul _ 2 (by norm_num) (by positivity) ?base ?step
case base =>
intro x ⟨hxlb, hxub⟩
have h₁ := calc n₀ ≤ 1 * max n₀ 2 := by simp
_ ≤ 2 * max n₀ 2 := by gcongr; norm_num
have h₂ := hn₀ (2 * max n₀ 2) h₁ (max n₀ 2) ⟨by simp [hxlb], by linarith⟩
rw [h₂]
exact hn₀ (2 * max n₀ 2) h₁ x ⟨by simp [hxlb], le_of_lt hxub⟩
case step =>
intro n hn hyp_ind z hz
have z_nonneg : 0 ≤ z := by
calc (0 : ℝ) ≤ (2 : ℝ)^n * max n₀ 2 := by
exact mul_nonneg (pow_nonneg (by norm_num) _) (by norm_num)
_ ≤ z := by exact_mod_cast hz.1
have le_2n : max n₀ 2 ≤ (2 : ℝ)^n * max n₀ 2 := by
nth_rewrite 1 [← one_mul (max n₀ 2)]
gcongr
exact one_le_pow₀ (by norm_num : (1 : ℝ) ≤ 2)
have n₀_le_z : n₀ ≤ z := by
calc n₀ ≤ max n₀ 2 := by simp
_ ≤ (2 : ℝ)^n * max n₀ 2 := le_2n
_ ≤ _ := by exact_mod_cast hz.1
have fz_eq_c₂fz : f z = c₂ * f z := hn₀ z n₀_le_z z ⟨by linarith, le_rfl⟩
have z_to_half_z' : f (1/2 * z) = c₂ * f z := hn₀ z n₀_le_z (1/2 * z) ⟨le_rfl, by linarith⟩
have z_to_half_z : f (1/2 * z) = f z := by rwa [← fz_eq_c₂fz] at z_to_half_z'
have half_z_to_base : f (1/2 * z) = f (max n₀ 2) := by
refine hyp_ind (1/2 * z) ⟨?lb, ?ub⟩
case lb =>
calc max n₀ 2 ≤ ((1 : ℝ)/(2 : ℝ)) * (2 : ℝ) ^ 1 * max n₀ 2 := by simp
_ ≤ ((1 : ℝ)/(2 : ℝ)) * (2 : ℝ) ^ n * max n₀ 2 := by gcongr; norm_num
_ ≤ _ := by rw [mul_assoc]; gcongr; exact_mod_cast hz.1
case ub =>
have h₁ : (2 : ℝ)^n = ((1 : ℝ)/(2 : ℝ)) * (2 : ℝ)^(n+1) := by
rw [one_div, pow_add, pow_one]
ring
rw [h₁, mul_assoc]
gcongr
exact_mod_cast hz.2
rw [← z_to_half_z, half_z_to_base]
obtain ⟨c, hc⟩ := hmain
cases le_or_lt 0 c with
| inl hpos =>
exact Or.inl <| by filter_upwards [hc] with _ hc; simpa only [hc]
| inr hneg =>
right
filter_upwards [hc] with x hc
exact le_of_lt <| by simpa only [hc]
lemma eventually_atTop_zero_or_pos_or_neg (hf : GrowsPolynomially f) :
(∀ᶠ x in atTop, f x = 0) ∨ (∀ᶠ x in atTop, 0 < f x) ∨ (∀ᶠ x in atTop, f x < 0) := by
if h : ∃ᶠ x in atTop, f x = 0 then
exact Or.inl <| eventually_zero_of_frequently_zero hf h
else
rw [not_frequently] at h
push_neg at h
cases eventually_atTop_nonneg_or_nonpos hf with
| inl h' =>
refine Or.inr (Or.inl ?_)
simp only [lt_iff_le_and_ne]
rw [eventually_and]
exact ⟨h', by filter_upwards [h] with x hx; exact hx.symm⟩
| inr h' =>
refine Or.inr (Or.inr ?_)
simp only [lt_iff_le_and_ne]
rw [eventually_and]
exact ⟨h', h⟩
protected lemma neg {f : ℝ → ℝ} (hf : GrowsPolynomially f) : GrowsPolynomially (-f) := by
intro b hb
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hf⟩ := hf b hb
refine ⟨c₂, hc₂_mem, c₁, hc₁_mem, ?_⟩
filter_upwards [hf] with x hx
intro u hu
simp only [Pi.neg_apply, Set.neg_mem_Icc_iff, neg_mul_eq_mul_neg, neg_neg]
exact hx u hu
protected lemma neg_iff {f : ℝ → ℝ} : GrowsPolynomially f ↔ GrowsPolynomially (-f) :=
⟨fun hf => hf.neg, fun hf => by rw [← neg_neg f]; exact hf.neg⟩
protected lemma abs (hf : GrowsPolynomially f) : GrowsPolynomially (fun x => |f x|) := by
cases eventually_atTop_nonneg_or_nonpos hf with
| inl hf' =>
have hmain : f =ᶠ[atTop] fun x => |f x| := by
filter_upwards [hf'] with x hx
rw [abs_of_nonneg hx]
rw [← iff_eventuallyEq hmain]
exact hf
| inr hf' =>
have hmain : -f =ᶠ[atTop] fun x => |f x| := by
filter_upwards [hf'] with x hx
simp only [Pi.neg_apply, abs_of_nonpos hx]
rw [← iff_eventuallyEq hmain]
exact hf.neg
protected lemma norm (hf : GrowsPolynomially f) : GrowsPolynomially (fun x => ‖f x‖) := by
simp only [norm_eq_abs]
exact hf.abs
end GrowsPolynomially
variable {f : ℝ → ℝ}
lemma growsPolynomially_const {c : ℝ} : GrowsPolynomially (fun _ => c) := by
refine fun _ _ => ⟨1, by norm_num, 1, by norm_num, ?_⟩
filter_upwards [] with x
simp
lemma growsPolynomially_id : GrowsPolynomially (fun x => x) := by
intro b hb
refine ⟨b, hb.1, ?_⟩
refine ⟨1, by norm_num, ?_⟩
filter_upwards with x u hu
simp only [one_mul, gt_iff_lt, not_le, Set.mem_Icc]
exact ⟨hu.1, hu.2⟩
protected lemma GrowsPolynomially.mul {f g : ℝ → ℝ} (hf : GrowsPolynomially f)
(hg : GrowsPolynomially g) : GrowsPolynomially fun x => f x * g x := by
suffices GrowsPolynomially fun x => |f x| * |g x| by
cases eventually_atTop_nonneg_or_nonpos hf with
| inl hf' =>
cases eventually_atTop_nonneg_or_nonpos hg with
| inl hg' =>
have hmain : (fun x => f x * g x) =ᶠ[atTop] fun x => |f x| * |g x| := by
filter_upwards [hf', hg'] with x hx₁ hx₂
rw [abs_of_nonneg hx₁, abs_of_nonneg hx₂]
rwa [iff_eventuallyEq hmain]
| inr hg' =>
have hmain : (fun x => f x * g x) =ᶠ[atTop] fun x => -|f x| * |g x| := by
filter_upwards [hf', hg'] with x hx₁ hx₂
simp [abs_of_nonneg hx₁, abs_of_nonpos hx₂]
simp only [iff_eventuallyEq hmain, neg_mul]
exact this.neg
| inr hf' =>
cases eventually_atTop_nonneg_or_nonpos hg with
| inl hg' =>
have hmain : (fun x => f x * g x) =ᶠ[atTop] fun x => -|f x| * |g x| := by
filter_upwards [hf', hg'] with x hx₁ hx₂
rw [abs_of_nonpos hx₁, abs_of_nonneg hx₂, neg_neg]
simp only [iff_eventuallyEq hmain, neg_mul]
exact this.neg
| inr hg' =>
have hmain : (fun x => f x * g x) =ᶠ[atTop] fun x => |f x| * |g x| := by
filter_upwards [hf', hg'] with x hx₁ hx₂
simp [abs_of_nonpos hx₁, abs_of_nonpos hx₂]
simp only [iff_eventuallyEq hmain, neg_mul]
exact this
intro b hb
have hf := hf.abs b hb
have hg := hg.abs b hb
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hf⟩ := hf
obtain ⟨c₃, hc₃_mem, c₄, hc₄_mem, hg⟩ := hg
refine ⟨c₁ * c₃, by show 0 < c₁ * c₃; positivity, ?_⟩
refine ⟨c₂ * c₄, by show 0 < c₂ * c₄; positivity, ?_⟩
filter_upwards [hf, hg] with x hf hg
intro u hu
refine ⟨?lb, ?ub⟩
case lb => calc
c₁ * c₃ * (|f x| * |g x|) = (c₁ * |f x|) * (c₃ * |g x|) := by ring
_ ≤ |f u| * |g u| := by
gcongr
· exact (hf u hu).1
· exact (hg u hu).1
case ub => calc
|f u| * |g u| ≤ (c₂ * |f x|) * (c₄ * |g x|) := by
gcongr
· exact (hf u hu).2
· exact (hg u hu).2
_ = c₂ * c₄ * (|f x| * |g x|) := by ring
lemma GrowsPolynomially.const_mul {f : ℝ → ℝ} {c : ℝ} (hf : GrowsPolynomially f) :
GrowsPolynomially fun x => c * f x :=
GrowsPolynomially.mul growsPolynomially_const hf
protected lemma GrowsPolynomially.add {f g : ℝ → ℝ} (hf : GrowsPolynomially f)
(hg : GrowsPolynomially g) (hf' : 0 ≤ᶠ[atTop] f) (hg' : 0 ≤ᶠ[atTop] g) :
GrowsPolynomially fun x => f x + g x := by
intro b hb
have hf := hf b hb
have hg := hg b hb
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hf⟩ := hf
obtain ⟨c₃, hc₃_mem, c₄, _, hg⟩ := hg
refine ⟨min c₁ c₃, by show 0 < min c₁ c₃; positivity, ?_⟩
refine ⟨max c₂ c₄, by show 0 < max c₂ c₄; positivity, ?_⟩
filter_upwards [hf, hg,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hf',
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hg',
eventually_ge_atTop 0] with x hf hg hf' hg' hx_pos
intro u hu
have hbx : b * x ≤ x := calc
b * x ≤ 1 * x := by gcongr; exact le_of_lt hb.2
_ = x := by ring
have fx_nonneg : 0 ≤ f x := hf' x hbx
have gx_nonneg : 0 ≤ g x := hg' x hbx
refine ⟨?lb, ?ub⟩
case lb => calc
min c₁ c₃ * (f x + g x) = min c₁ c₃ * f x + min c₁ c₃ * g x := by simp only [mul_add]
_ ≤ c₁ * f x + c₃ * g x := by
gcongr
· exact min_le_left _ _
· exact min_le_right _ _
_ ≤ f u + g u := by
gcongr
· exact (hf u hu).1
· exact (hg u hu).1
case ub => calc
max c₂ c₄ * (f x + g x) = max c₂ c₄ * f x + max c₂ c₄ * g x := by simp only [mul_add]
_ ≥ c₂ * f x + c₄ * g x := by gcongr
· exact le_max_left _ _
· exact le_max_right _ _
_ ≥ f u + g u := by gcongr
· exact (hf u hu).2
· exact (hg u hu).2
lemma GrowsPolynomially.add_isLittleO {f g : ℝ → ℝ} (hf : GrowsPolynomially f)
(hfg : g =o[atTop] f) : GrowsPolynomially fun x => f x + g x := by
intro b hb
have hb_ub := hb.2
rw [isLittleO_iff] at hfg
cases hf.eventually_atTop_nonneg_or_nonpos with
| inl hf' => -- f is eventually non-negative
have hf := hf b hb
obtain ⟨c₁, hc₁_mem : 0 < c₁, c₂, hc₂_mem : 0 < c₂, hf⟩ := hf
specialize hfg (c := 1/2) (by norm_num)
refine ⟨c₁ / 3, by positivity, 3*c₂, by positivity, ?_⟩
filter_upwards [hf,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hfg,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hf',
eventually_ge_atTop 0] with x hf₁ hfg' hf₂ hx_nonneg
have hbx : b * x ≤ x := by nth_rewrite 2 [← one_mul x]; gcongr
have hfg₂ : ‖g x‖ ≤ 1/2 * f x := by
calc ‖g x‖ ≤ 1/2 * ‖f x‖ := hfg' x hbx
_ = 1/2 * f x := by congr; exact norm_of_nonneg (hf₂ _ hbx)
have hx_ub : f x + g x ≤ 3/2 * f x := by
calc _ ≤ f x + ‖g x‖ := by gcongr; exact le_norm_self (g x)
_ ≤ f x + 1/2 * f x := by gcongr
_ = 3/2 * f x := by ring
have hx_lb : 1/2 * f x ≤ f x + g x := by
calc f x + g x ≥ f x - ‖g x‖ := by
rw [sub_eq_add_neg, norm_eq_abs]; gcongr; exact neg_abs_le (g x)
_ ≥ f x - 1/2 * f x := by gcongr
_ = 1/2 * f x := by ring
intro u ⟨hu_lb, hu_ub⟩
have hfu_nonneg : 0 ≤ f u := hf₂ _ hu_lb
have hfg₃ : ‖g u‖ ≤ 1/2 * f u := by
calc ‖g u‖ ≤ 1/2 * ‖f u‖ := hfg' _ hu_lb
_ = 1/2 * f u := by congr; simp only [norm_eq_abs, abs_eq_self, hfu_nonneg]
refine ⟨?lb, ?ub⟩
case lb =>
calc f u + g u ≥ f u - ‖g u‖ := by
rw [sub_eq_add_neg, norm_eq_abs]; gcongr; exact neg_abs_le _
_ ≥ f u - 1/2 * f u := by gcongr
_ = 1/2 * f u := by ring
_ ≥ 1/2 * (c₁ * f x) := by gcongr; exact (hf₁ u ⟨hu_lb, hu_ub⟩).1
_ = c₁/3 * (3/2 * f x) := by ring
_ ≥ c₁/3 * (f x + g x) := by gcongr
case ub =>
calc _ ≤ f u + ‖g u‖ := by gcongr; exact le_norm_self (g u)
_ ≤ f u + 1/2 * f u := by gcongr
_ = 3/2 * f u := by ring
_ ≤ 3/2 * (c₂ * f x) := by gcongr; exact (hf₁ u ⟨hu_lb, hu_ub⟩).2
_ = 3*c₂ * (1/2 * f x) := by ring
_ ≤ 3*c₂ * (f x + g x) := by gcongr
| inr hf' => -- f is eventually nonpos
have hf := hf b hb
obtain ⟨c₁, hc₁_mem : 0 < c₁, c₂, hc₂_mem : 0 < c₂, hf⟩ := hf
specialize hfg (c := 1/2) (by norm_num)
refine ⟨3*c₁, by positivity, c₂/3, by positivity, ?_⟩
filter_upwards [hf,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hfg,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hf',
eventually_ge_atTop 0] with x hf₁ hfg' hf₂ hx_nonneg
have hbx : b * x ≤ x := by nth_rewrite 2 [← one_mul x]; gcongr
have hfg₂ : ‖g x‖ ≤ -1/2 * f x := by
calc ‖g x‖ ≤ 1/2 * ‖f x‖ := hfg' x hbx
_ = 1/2 * (-f x) := by congr; exact norm_of_nonpos (hf₂ x hbx)
_ = _ := by ring
have hx_ub : f x + g x ≤ 1/2 * f x := by
calc _ ≤ f x + ‖g x‖ := by gcongr; exact le_norm_self (g x)
_ ≤ f x + (-1/2 * f x) := by gcongr
_ = 1/2 * f x := by ring
have hx_lb : 3/2 * f x ≤ f x + g x := by
calc f x + g x ≥ f x - ‖g x‖ := by
rw [sub_eq_add_neg, norm_eq_abs]; gcongr; exact neg_abs_le (g x)
_ ≥ f x + 1/2 * f x := by
rw [sub_eq_add_neg]
gcongr
refine le_of_neg_le_neg ?bc.a
rwa [neg_neg, ← neg_mul, ← neg_div]
_ = 3/2 * f x := by ring
intro u ⟨hu_lb, hu_ub⟩
have hfu_nonpos : f u ≤ 0 := hf₂ _ hu_lb
have hfg₃ : ‖g u‖ ≤ -1/2 * f u := by
calc ‖g u‖ ≤ 1/2 * ‖f u‖ := hfg' _ hu_lb
_ = 1/2 * (-f u) := by congr; exact norm_of_nonpos hfu_nonpos
_ = -1/2 * f u := by ring
refine ⟨?lb, ?ub⟩
case lb =>
calc f u + g u ≥ f u - ‖g u‖ := by
rw [sub_eq_add_neg, norm_eq_abs]; gcongr; exact neg_abs_le _
_ ≥ f u + 1/2 * f u := by
rw [sub_eq_add_neg]
gcongr
refine le_of_neg_le_neg ?_
rwa [neg_neg, ← neg_mul, ← neg_div]
_ = 3/2 * f u := by ring
_ ≥ 3/2 * (c₁ * f x) := by gcongr; exact (hf₁ u ⟨hu_lb, hu_ub⟩).1
_ = 3*c₁ * (1/2 * f x) := by ring
_ ≥ 3*c₁ * (f x + g x) := by gcongr
case ub =>
calc _ ≤ f u + ‖g u‖ := by gcongr; exact le_norm_self (g u)
_ ≤ f u - 1/2 * f u := by
rw [sub_eq_add_neg]
gcongr
rwa [← neg_mul, ← neg_div]
_ = 1/2 * f u := by ring
_ ≤ 1/2 * (c₂ * f x) := by gcongr; exact (hf₁ u ⟨hu_lb, hu_ub⟩).2
_ = c₂/3 * (3/2 * f x) := by ring
_ ≤ c₂/3 * (f x + g x) := by gcongr
protected lemma GrowsPolynomially.inv {f : ℝ → ℝ} (hf : GrowsPolynomially f) :
GrowsPolynomially fun x => (f x)⁻¹ := by
cases hf.eventually_atTop_zero_or_pos_or_neg with
| inl hf' =>
refine fun b hb => ⟨1, by simp, 1, by simp, ?_⟩
have hb_pos := hb.1
filter_upwards [hf', (tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hf']
with x hx hx'
intro u hu
simp only [hx, inv_zero, mul_zero, Set.Icc_self, Set.mem_singleton_iff, hx' u hu.1]
| inr hf_pos_or_neg =>
suffices GrowsPolynomially fun x => |(f x)⁻¹| by
cases hf_pos_or_neg with
| inl hf' =>
have hmain : (fun x => (f x)⁻¹) =ᶠ[atTop] fun x => |(f x)⁻¹| := by
filter_upwards [hf'] with x hx₁
rw [abs_of_nonneg (inv_nonneg_of_nonneg (le_of_lt hx₁))]
rwa [iff_eventuallyEq hmain]
| inr hf' =>
have hmain : (fun x => (f x)⁻¹) =ᶠ[atTop] fun x => -|(f x)⁻¹| := by
filter_upwards [hf'] with x hx₁
simp [abs_of_nonpos (inv_nonpos.mpr (le_of_lt hx₁))]
rw [iff_eventuallyEq hmain]
exact this.neg
have hf' : ∀ᶠ x in atTop, f x ≠ 0 := by
cases hf_pos_or_neg with
| inl H => filter_upwards [H] with _ hx; exact (ne_of_lt hx).symm
| inr H => filter_upwards [H] with _ hx; exact (ne_of_gt hx).symm
simp only [abs_inv]
have hf := hf.abs
intro b hb
have hb_pos := hb.1
obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hf⟩ := hf b hb
refine ⟨c₂⁻¹, by show 0 < c₂⁻¹; positivity, ?_⟩
refine ⟨c₁⁻¹, by show 0 < c₁⁻¹; positivity, ?_⟩
filter_upwards [hf, hf', (tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hf']
with x hx hx' hx''
intro u hu
have h₁ : 0 < |f u| := by rw [abs_pos]; exact hx'' u hu.1
refine ⟨?lb, ?ub⟩
case lb =>
rw [← mul_inv]
gcongr
exact (hx u hu).2
case ub =>
rw [← mul_inv]
gcongr
exact (hx u hu).1
protected lemma GrowsPolynomially.div {f g : ℝ → ℝ} (hf : GrowsPolynomially f)
(hg : GrowsPolynomially g) : GrowsPolynomially fun x => f x / g x := by
have : (fun x => f x / g x) = fun x => f x * (g x)⁻¹ := by ext; rw [div_eq_mul_inv]
rw [this]
exact GrowsPolynomially.mul hf (GrowsPolynomially.inv hg)
protected lemma GrowsPolynomially.rpow (p : ℝ) (hf : GrowsPolynomially f)
(hf_nonneg : ∀ᶠ x in atTop, 0 ≤ f x) : GrowsPolynomially fun x => (f x) ^ p := by
intro b hb
obtain ⟨c₁, (hc₁_mem : 0 < c₁), c₂, hc₂_mem, hfnew⟩ := hf b hb
have hc₁p : 0 < c₁ ^ p := Real.rpow_pos_of_pos hc₁_mem _
have hc₂p : 0 < c₂ ^ p := Real.rpow_pos_of_pos hc₂_mem _
cases le_or_lt 0 p with
| inl => -- 0 ≤ p
refine ⟨c₁^p, hc₁p, ?_⟩
refine ⟨c₂^p, hc₂p, ?_⟩
filter_upwards [eventually_gt_atTop 0, hfnew, hf_nonneg,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hf_nonneg]
with x _ hf₁ hf_nonneg hf_nonneg₂
intro u hu
have fu_nonneg : 0 ≤ f u := hf_nonneg₂ u hu.1
refine ⟨?lb, ?ub⟩
case lb => calc
c₁^p * (f x)^p = (c₁ * f x)^p := by rw [mul_rpow (le_of_lt hc₁_mem) hf_nonneg]
_ ≤ _ := by gcongr; exact (hf₁ u hu).1
case ub => calc
(f u)^p ≤ (c₂ * f x)^p := by gcongr; exact (hf₁ u hu).2
_ = _ := by rw [← mul_rpow (le_of_lt hc₂_mem) hf_nonneg]
| inr hp => -- p < 0
match hf.eventually_atTop_zero_or_pos_or_neg with
| .inl hzero => -- eventually zero
refine ⟨1, by norm_num, 1, by norm_num, ?_⟩
filter_upwards [hzero, hfnew] with x hx hx'
intro u hu
simp only [hx, ne_eq, zero_rpow (ne_of_lt hp), mul_zero, le_refl, not_true, lt_self_iff_false,
Set.Icc_self, Set.mem_singleton_iff]
simp only [hx, mul_zero, Set.Icc_self, Set.mem_singleton_iff] at hx'
rw [hx' u hu, zero_rpow (ne_of_lt hp)]
| .inr (.inl hpos) => -- eventually positive
refine ⟨c₂^p, hc₂p, ?_⟩
refine ⟨c₁^p, hc₁p, ?_⟩
filter_upwards [eventually_gt_atTop 0, hfnew, hpos,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hpos]
with x _ hf₁ hf_pos hf_pos₂
intro u hu
refine ⟨?lb, ?ub⟩
case lb => calc
c₂^p * (f x)^p = (c₂ * f x)^p := by rw [mul_rpow (le_of_lt hc₂_mem) (le_of_lt hf_pos)]
_ ≤ _ := rpow_le_rpow_of_exponent_nonpos (hf_pos₂ u hu.1) (hf₁ u hu).2 (le_of_lt hp)
case ub => calc
(f u)^p ≤ (c₁ * f x)^p := by
exact rpow_le_rpow_of_exponent_nonpos (by positivity) (hf₁ u hu).1 (le_of_lt hp)
_ = _ := by rw [← mul_rpow (le_of_lt hc₁_mem) (le_of_lt hf_pos)]
| .inr (.inr hneg) => -- eventually negative (which is impossible)
have : ∀ᶠ (_ : ℝ) in atTop, False := by
filter_upwards [hf_nonneg, hneg] with x hx hx'; linarith
rw [Filter.eventually_false_iff_eq_bot] at this
exact False.elim <| (atTop_neBot).ne this
protected lemma GrowsPolynomially.pow (p : ℕ) (hf : GrowsPolynomially f)
(hf_nonneg : ∀ᶠ x in atTop, 0 ≤ f x) : GrowsPolynomially fun x => (f x) ^ p := by
simp_rw [← rpow_natCast]
exact hf.rpow p hf_nonneg
protected lemma GrowsPolynomially.zpow (p : ℤ) (hf : GrowsPolynomially f)
(hf_nonneg : ∀ᶠ x in atTop, 0 ≤ f x) : GrowsPolynomially fun x => (f x) ^ p := by
simp_rw [← rpow_intCast]
exact hf.rpow p hf_nonneg
lemma growsPolynomially_rpow (p : ℝ) : GrowsPolynomially fun x => x ^ p :=
(growsPolynomially_id).rpow p (eventually_ge_atTop 0)
lemma growsPolynomially_pow (p : ℕ) : GrowsPolynomially fun x => x ^ p :=
(growsPolynomially_id).pow p (eventually_ge_atTop 0)
lemma growsPolynomially_zpow (p : ℤ) : GrowsPolynomially fun x => x ^ p :=
(growsPolynomially_id).zpow p (eventually_ge_atTop 0)
lemma growsPolynomially_log : GrowsPolynomially Real.log := by
intro b hb
have hb₀ : 0 < b := hb.1
refine ⟨1 / 2, by norm_num, ?_⟩
refine ⟨1, by norm_num, ?_⟩
have h_tendsto : Tendsto (fun x => 1 / 2 * Real.log x) atTop atTop :=
Tendsto.const_mul_atTop (by norm_num) Real.tendsto_log_atTop
filter_upwards [eventually_gt_atTop 1,
(tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop
<| h_tendsto.eventually (eventually_gt_atTop (-Real.log b)) ] with x hx_pos hx
intro u hu
refine ⟨?lb, ?ub⟩
case lb => calc
1 / 2 * Real.log x = Real.log x + (-1 / 2) * Real.log x := by ring
_ ≤ Real.log x + Real.log b := by
gcongr
rw [neg_div, neg_mul, ← neg_le]
refine le_of_lt (hx x ?_)
calc b * x ≤ 1 * x := by gcongr; exact le_of_lt hb.2
_ = x := by rw [one_mul]
_ = Real.log (b * x) := by rw [← Real.log_mul (by positivity) (by positivity), mul_comm]
_ ≤ Real.log u := by gcongr; exact hu.1
case ub =>
rw [one_mul]
gcongr
· calc 0 < b * x := by positivity
_ ≤ u := by exact hu.1
· exact hu.2
|
lemma GrowsPolynomially.of_isTheta {f g : ℝ → ℝ} (hg : GrowsPolynomially g) (hf : f =Θ[atTop] g)
(hf' : ∀ᶠ x in atTop, 0 ≤ f x) : GrowsPolynomially f := by
intro b hb
have hb_pos := hb.1
have hf_lb := isBigO_iff''.mp hf.isBigO_symm
have hf_ub := isBigO_iff'.mp hf.isBigO
obtain ⟨c₁, hc₁_pos : 0 < c₁, hf_lb⟩ := hf_lb
obtain ⟨c₂, hc₂_pos : 0 < c₂, hf_ub⟩ := hf_ub
have hg := hg.norm b hb
obtain ⟨c₃, hc₃_pos : 0 < c₃, hg⟩ := hg
obtain ⟨c₄, hc₄_pos : 0 < c₄, hg⟩ := hg
have h_lb_pos : 0 < c₁ * c₂⁻¹ * c₃ := by positivity
have h_ub_pos : 0 < c₂ * c₄ * c₁⁻¹ := by positivity
refine ⟨c₁ * c₂⁻¹ * c₃, h_lb_pos, ?_⟩
refine ⟨c₂ * c₄ * c₁⁻¹, h_ub_pos, ?_⟩
have c₂_cancel : c₂⁻¹ * c₂ = 1 := inv_mul_cancel₀ (by positivity)
have c₁_cancel : c₁⁻¹ * c₁ = 1 := inv_mul_cancel₀ (by positivity)
filter_upwards [(tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hf',
(tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hf_lb,
(tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hf_ub,
(tendsto_id.const_mul_atTop hb_pos).eventually_forall_ge_atTop hg,
eventually_ge_atTop 0]
with x hf_pos h_lb h_ub hg_bound hx_pos
intro u hu
have hbx : b * x ≤ x :=
calc b * x ≤ 1 * x := by gcongr; exact le_of_lt hb.2
_ = x := by rw [one_mul]
have hg_bound := hg_bound x hbx
refine ⟨?lb, ?ub⟩
case lb => calc
c₁ * c₂⁻¹ * c₃ * f x ≤ c₁ * c₂⁻¹ * c₃ * (c₂ * ‖g x‖) := by
rw [← Real.norm_of_nonneg (hf_pos x hbx)]; gcongr; exact h_ub x hbx
_ = (c₂⁻¹ * c₂) * c₁ * (c₃ * ‖g x‖) := by ring
_ = c₁ * (c₃ * ‖g x‖) := by simp [c₂_cancel]
_ ≤ c₁ * ‖g u‖ := by gcongr; exact (hg_bound u hu).1
_ ≤ f u := by
rw [← Real.norm_of_nonneg (hf_pos u hu.1)]
exact h_lb u hu.1
case ub => calc
f u ≤ c₂ * ‖g u‖ := by rw [← Real.norm_of_nonneg (hf_pos u hu.1)]; exact h_ub u hu.1
_ ≤ c₂ * (c₄ * ‖g x‖) := by gcongr; exact (hg_bound u hu).2
_ = c₂ * c₄ * (c₁⁻¹ * c₁) * ‖g x‖ := by simp [c₁_cancel]; ring
_ = c₂ * c₄ * c₁⁻¹ * (c₁ * ‖g x‖) := by ring
_ ≤ c₂ * c₄ * c₁⁻¹ * f x := by
gcongr
rw [← Real.norm_of_nonneg (hf_pos x hbx)]
| Mathlib/Computability/AkraBazzi/GrowsPolynomially.lean | 662 | 708 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.ModEq
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Pell's equation and Matiyasevic's theorem
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1`
*in the special case that `d = a ^ 2 - 1`*.
This is then applied to prove Matiyasevic's theorem that the power
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
problem. For the definition of Diophantine function, see `NumberTheory.Dioph`.
For results on Pell's equation for arbitrary (positive, non-square) `d`, see
`NumberTheory.Pell`.
## Main definition
* `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation
constructed recursively from the initial solution `(0, 1)`.
## Main statements
* `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell`
* `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if
the first variable is the `x`-component in a solution to Pell's equation - the key step towards
Hilbert's tenth problem in Davis' version of Matiyasevic's theorem.
* `eq_pow_of_pell` shows that the power function is Diophantine.
## Implementation notes
The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci
numbers but instead Davis' variant of using solutions to Pell's equation.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem
-/
namespace Pell
open Nat
section
variable {d : ℤ}
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `ℤ√d`. -/
def IsPell : ℤ√d → Prop
| ⟨x, y⟩ => x * x - d * y * y = 1
theorem isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1
| ⟨x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf
theorem isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d)
| ⟨x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff]
theorem isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) :=
isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc,
star_mul, isPell_norm.1 hb, isPell_norm.1 hc])
theorem isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b)
| ⟨x, y⟩ => by simp [IsPell, Zsqrtd.star_mk]
end
section
variable {a : ℕ} (a1 : 1 < a)
private def d (_a1 : 1 < a) :=
a * a - 1
@[simp]
theorem d_pos : 0 < d a1 :=
tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a)
-- TODO(lint): Fix double namespace issue
/-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
--@[nolint dup_namespace]
def pell : ℕ → ℕ × ℕ
| 0 => (1, 0)
| n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a)
/-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ :=
(pell a1 n).1
/-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ :=
(pell a1 n).2
@[simp]
theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) :=
show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from
match pell a1 n with
| (_, _) => rfl
@[simp]
theorem xn_zero : xn a1 0 = 1 :=
rfl
@[simp]
theorem yn_zero : yn a1 0 = 0 :=
rfl
@[simp]
theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n :=
rfl
@[simp]
theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a :=
rfl
theorem xn_one : xn a1 1 = a := by simp
theorem yn_one : yn a1 1 = 1 := by simp
/-- The Pell `x` sequence, considered as an integer sequence. -/
def xz (n : ℕ) : ℤ :=
xn a1 n
/-- The Pell `y` sequence, considered as an integer sequence. -/
def yz (n : ℕ) : ℤ :=
yn a1 n
section
/-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/
def az (a : ℕ) : ℤ :=
a
end
include a1 in
theorem asq_pos : 0 < a * a :=
le_trans (le_of_lt a1)
(by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this)
theorem dz_val : ↑(d a1) = az a * az a - 1 :=
have : 1 ≤ a * a := asq_pos a1
by rw [Pell.d, Int.ofNat_sub this]; rfl
@[simp]
theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n :=
rfl
@[simp]
theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a :=
rfl
/-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pellZd (n : ℕ) : ℤ√(d a1) :=
⟨xn a1 n, yn a1 n⟩
@[simp]
theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n :=
rfl
@[simp]
theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n :=
rfl
theorem isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 :=
⟨fun h =>
(Nat.cast_inj (R := ℤ)).1
(by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h),
fun h =>
show ((x * x : ℕ) - (d a1 * y * y : ℕ) : ℤ) = 1 by
rw [← Int.ofNat_sub <| le_of_lt <| Nat.lt_of_sub_eq_succ h, h]; rfl⟩
@[simp]
theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ := by ext <;> simp
theorem isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) :=
show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val]
theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n)
| 0 => rfl
| n + 1 => by
let o := isPell_one a1
simpa using Pell.isPell_mul (isPell_pellZd n) o
@[simp]
theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 :=
isPell_pellZd a1 n
@[simp]
theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 :=
let pn := pell_eqz a1 n
have h : (↑(xn a1 n * xn a1 n) : ℤ) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by
repeat' rw [Int.natCast_mul]; exact pn
have hl : d a1 * yn a1 n * yn a1 n ≤ xn a1 n * xn a1 n :=
Nat.cast_le.1 <| Int.le.intro _ <| add_eq_of_eq_sub' <| Eq.symm h
(Nat.cast_inj (R := ℤ)).1 (by rw [Int.ofNat_sub hl]; exact h)
instance dnsq : Zsqrtd.Nonsquare (d a1) :=
⟨fun n h =>
have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1)
have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _)
have : (n + 1) * (n + 1) ≤ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_self na
have : n + n ≤ 0 :=
@Nat.le_of_add_le_add_right _ (n * n + 1) _ (by ring_nf at this ⊢; assumption)
Nat.ne_of_gt (d_pos a1) <| by
rwa [Nat.eq_zero_of_le_zero ((Nat.le_add_left _ _).trans this)] at h⟩
| Mathlib/NumberTheory/PellMatiyasevic.lean | 220 | 220 | |
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import Mathlib.Algebra.Order.Group.Indicator
import Mathlib.Algebra.Order.Pi
import Mathlib.Analysis.Normed.Group.Basic
/-!
# Indicator function and (e)norm
This file contains a few simple lemmas about `Set.indicator`, `norm` and `enorm`.
## Tags
indicator, norm
-/
open Set
section ENormedAddMonoid
variable {α ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε] {s t : Set α} (f : α → ε) (a : α)
lemma enorm_indicator_eq_indicator_enorm :
‖indicator s f a‖ₑ = indicator s (fun a => ‖f a‖ₑ) a :=
flip congr_fun a (indicator_comp_of_zero (enorm_zero (E := ε))).symm
theorem enorm_indicator_le_of_subset (h : s ⊆ t) (f : α → ε) (a : α) :
‖indicator s f a‖ₑ ≤ ‖indicator t f a‖ₑ := by
simp only [enorm_indicator_eq_indicator_enorm]
apply indicator_le_indicator_of_subset ‹_› (zero_le _)
theorem indicator_enorm_le_enorm_self : indicator s (fun a => ‖f a‖ₑ) a ≤ ‖f a‖ₑ :=
indicator_le_self' (fun _ _ ↦ zero_le _) a
theorem enorm_indicator_le_enorm_self : ‖indicator s f a‖ₑ ≤ ‖f a‖ₑ := by
rw [enorm_indicator_eq_indicator_enorm]
apply indicator_enorm_le_enorm_self
end ENormedAddMonoid
section SeminormedAddGroup
|
variable {α E : Type*} [SeminormedAddGroup E] {s t : Set α} (f : α → E) (a : α)
| Mathlib/Analysis/NormedSpace/IndicatorFunction.lean | 44 | 46 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Algebra.ZMod
import Mathlib.Data.Nat.Multiplicity
import Mathlib.FieldTheory.Perfect
import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
## The Frobenius operator
If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p`
that raises `r : R` to the power `p`.
By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`.
It turns out that this endomorphism can be described by polynomials over `ℤ`
that do not depend on `R` or the fact that it has characteristic `p`.
In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R`
for every commutative ring `R`.
Unfortunately, the aforementioned polynomials can not be obtained using the machinery
of `wittStructureInt` that was developed in `StructurePolynomial.lean`.
We therefore have to define the polynomials by hand, and check that they have the required property.
In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius`
that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`.
### Main definitions and results
* `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`;
* `frobeniusFun`: the Frobenius endomorphism on Witt vectors;
* `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function;
* `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to
`WittVector.map (frobenius R p)`.
TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism,
and bundle it into `WittVector.frobenius`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
local notation "𝕎" => WittVector p -- type as `\bbW`
noncomputable section
open MvPolynomial Finset
variable (p)
/-- The rational polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`.
These polynomials actually have integral coefficients,
see `frobeniusPoly` and `map_frobeniusPoly`. -/
def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ :=
bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n)
theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by
delta frobeniusPolyRat
rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply]
local notation "v" => multiplicity
/-- An auxiliary polynomial over the integers, that satisfies
`p * (frobeniusPolyAux p n) + X n ^ p = frobeniusPoly p n`.
This makes it easy to show that `frobeniusPoly p n` is congruent to `X n ^ p`
modulo `p`. -/
noncomputable def frobeniusPolyAux : ℕ → MvPolynomial ℕ ℤ
| n => X (n + 1) - ∑ i : Fin n, have _ := i.is_lt
∑ j ∈ range (p ^ (n - i)),
(((X (i : ℕ) ^ p) ^ (p ^ (n - (i : ℕ)) - (j + 1)) : MvPolynomial ℕ ℤ) *
(frobeniusPolyAux i) ^ (j + 1)) *
C (((p ^ (n - i)).choose (j + 1) / (p ^ (n - i - v p (j + 1)))
* ↑p ^ (j - v p (j + 1)) : ℕ) : ℤ)
omit hp in
theorem frobeniusPolyAux_eq (n : ℕ) :
frobeniusPolyAux p n =
X (n + 1) - ∑ i ∈ range n,
∑ j ∈ range (p ^ (n - i)),
(X i ^ p) ^ (p ^ (n - i) - (j + 1)) * frobeniusPolyAux p i ^ (j + 1) *
C ↑((p ^ (n - i)).choose (j + 1) / p ^ (n - i - v p (j + 1)) *
↑p ^ (j - v p (j + 1)) : ℕ) := by
rw [frobeniusPolyAux, ← Fin.sum_univ_eq_sum_range]
/-- The polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`. -/
def frobeniusPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
X n ^ p + C (p : ℤ) * frobeniusPolyAux p n
/-
Our next goal is to prove
```
lemma map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n
```
This lemma has a rather long proof, but it mostly boils down to applying induction,
and then using the following two key facts at the right point.
-/
/-- A key divisibility fact for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₁ (n j : ℕ) (hj : j < p ^ n) :
p ^ (n - v p (j + 1)) ∣ (p ^ n).choose (j + 1) := by
apply pow_dvd_of_le_emultiplicity
rw [hp.out.emultiplicity_choose_prime_pow hj j.succ_ne_zero]
/-- A key numerical identity needed for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₂ {n i j : ℕ} (hi : i ≤ n) (hj : j < p ^ (n - i)) :
j - v p (j + 1) + n = i + j + (n - i - v p (j + 1)) := by
generalize h : v p (j + 1) = m
rsuffices ⟨h₁, h₂⟩ : m ≤ n - i ∧ m ≤ j
· rw [tsub_add_eq_add_tsub h₂, add_comm i j, add_tsub_assoc_of_le (h₁.trans (Nat.sub_le n i)),
add_assoc, tsub_right_comm, add_comm i,
tsub_add_cancel_of_le (le_tsub_of_add_le_right ((le_tsub_iff_left hi).mp h₁))]
have hle : p ^ m ≤ j + 1 := h ▸ Nat.le_of_dvd j.succ_pos (pow_multiplicity_dvd _ _)
exact ⟨(Nat.pow_le_pow_iff_right hp.1.one_lt).1 (hle.trans hj),
Nat.le_of_lt_succ ((m.lt_pow_self hp.1.one_lt).trans_le hle)⟩
theorem map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_mul, RingHom.map_pow, map_C, map_X, eq_intCast,
Int.cast_natCast, frobeniusPolyRat]
refine Nat.strong_induction_on n ?_; clear n
intro n IH
rw [xInTermsOfW_eq]
simp only [map_sum, map_sub, map_mul, map_pow (bind₁ _), bind₁_C_right]
have h1 : (p : ℚ) ^ n * ⅟ (p : ℚ) ^ n = 1 := by rw [← mul_pow, mul_invOf_self, one_pow]
rw [bind₁_X_right, Function.comp_apply, wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ,
sum_range_succ, tsub_self, add_tsub_cancel_left, pow_zero, pow_one, pow_one, sub_mul, add_mul,
add_mul, mul_right_comm, mul_right_comm (C ((p : ℚ) ^ (n + 1))), ← C_mul, ← C_mul, pow_succ',
mul_assoc (p : ℚ) ((p : ℚ) ^ n), h1, mul_one, C_1, one_mul, add_comm _ (X n ^ p), add_assoc,
← add_sub, add_right_inj, frobeniusPolyAux_eq, RingHom.map_sub, map_X, mul_sub, sub_eq_add_neg,
add_comm _ (C (p : ℚ) * X (n + 1)), ← add_sub,
add_right_inj, neg_eq_iff_eq_neg, neg_sub, eq_comm]
simp only [map_sum, mul_sum, sum_mul, ← sum_sub_distrib]
apply sum_congr rfl
intro i hi
rw [mem_range] at hi
rw [← IH i hi]
clear IH
rw [add_comm (X i ^ p), add_pow, sum_range_succ', pow_zero, tsub_zero, Nat.choose_zero_right,
one_mul, Nat.cast_one, mul_one, mul_add, add_mul, Nat.succ_sub (le_of_lt hi),
Nat.succ_eq_add_one (n - i), pow_succ', pow_mul, add_sub_cancel_right, mul_sum, sum_mul]
apply sum_congr rfl
intro j hj
rw [mem_range] at hj
rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow,
RingHom.map_pow, RingHom.map_pow, map_C, map_X, mul_pow]
rw [mul_comm (C (p : ℚ) ^ i), mul_comm _ ((X i ^ p) ^ _), mul_comm (C (p : ℚ) ^ (j + 1)),
mul_comm (C (p : ℚ))]
simp only [mul_assoc]
apply congr_arg
apply congr_arg
rw [← C_eq_coe_nat]
simp only [← RingHom.map_pow, ← C_mul]
rw [C_inj]
simp only [invOf_eq_inv, eq_intCast, inv_pow, Int.cast_natCast, Nat.cast_mul, Int.cast_mul]
rw [Rat.natCast_div _ _ (map_frobeniusPoly.key₁ p (n - i) j hj)]
simp only [Nat.cast_pow, pow_add, pow_one]
suffices
(((p ^ (n - i)).choose (j + 1) : ℚ) * (p : ℚ) ^ (j - v p (j + 1)) * p * (p ^ n : ℚ))
= (p : ℚ) ^ j * p * ↑((p ^ (n - i)).choose (j + 1) * p ^ i) *
(p : ℚ) ^ (n - i - v p (j + 1)) by
have aux : ∀ k : ℕ, (p : ℚ)^ k ≠ 0 := by
intro; apply pow_ne_zero; exact mod_cast hp.1.ne_zero
simpa [aux, -one_div, -pow_eq_zero_iff', field_simps] using this.symm
rw [mul_comm _ (p : ℚ), mul_assoc, mul_assoc, ← pow_add,
map_frobeniusPoly.key₂ p hi.le hj, Nat.cast_mul, Nat.cast_pow]
ring
theorem frobeniusPoly_zmod (n : ℕ) :
MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n) = X n ^ p := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_pow, RingHom.map_mul, map_X, map_C]
simp only [Int.cast_natCast, add_zero, eq_intCast, ZMod.natCast_self, zero_mul, C_0]
@[simp]
theorem bind₁_frobeniusPoly_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPoly p) (wittPolynomial p ℤ n) = wittPolynomial p ℤ (n + 1) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_bind₁, map_frobeniusPoly, bind₁_frobeniusPolyRat_wittPolynomial,
map_wittPolynomial]
variable {p}
/-- `frobeniusFun` is the function underlying the ring endomorphism
`frobenius : 𝕎 R →+* frobenius 𝕎 R`. -/
def frobeniusFun (x : 𝕎 R) : 𝕎 R :=
mk p fun n => MvPolynomial.aeval x.coeff (frobeniusPoly p n)
omit hp in
theorem coeff_frobeniusFun (x : 𝕎 R) (n : ℕ) :
coeff (frobeniusFun x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) := by
rw [frobeniusFun, coeff_mk]
variable (p) in
/-- `frobeniusFun` is tautologically a polynomial function.
See also `frobenius_isPoly`. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance frobeniusFun_isPoly : IsPoly p fun R _ Rcr => @frobeniusFun p R _ Rcr :=
⟨⟨frobeniusPoly p, by intros; funext n; apply coeff_frobeniusFun⟩⟩
@[ghost_simps]
theorem ghostComponent_frobeniusFun (n : ℕ) (x : 𝕎 R) :
ghostComponent n (frobeniusFun x) = ghostComponent (n + 1) x := by
simp only [ghostComponent_apply, frobeniusFun, coeff_mk, ← bind₁_frobeniusPoly_wittPolynomial,
aeval_bind₁]
|
/-- If `R` has characteristic `p`, then there is a ring endomorphism
that raises `r : R` to the power `p`.
| Mathlib/RingTheory/WittVector/Frobenius.lean | 218 | 220 |
/-
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.Elements
import Mathlib.CategoryTheory.IsConnected
import Mathlib.CategoryTheory.SingleObj
import Mathlib.GroupTheory.GroupAction.Quotient
import Mathlib.GroupTheory.SemidirectProduct
/-!
# Actions as functors and as categories
From a multiplicative action M ↻ X, we can construct a functor from M to the category of
types, mapping the single object of M to X and an element `m : M` to map `X → X` given by
multiplication by `m`.
This functor induces a category structure on X -- a special case of the category of elements.
A morphism `x ⟶ y` in this category is simply a scalar `m : M` such that `m • x = y`. In the case
where M is a group, this category is a groupoid -- the *action groupoid*.
-/
open MulAction SemidirectProduct
namespace CategoryTheory
universe u
variable (M : Type*) [Monoid M] (X : Type u) [MulAction M X]
/-- A multiplicative action M ↻ X viewed as a functor mapping the single object of M to X
and an element `m : M` to the map `X → X` given by multiplication by `m`. -/
@[simps]
def actionAsFunctor : SingleObj M ⥤ Type u where
obj _ := X
map := (· • ·)
map_id _ := funext <| MulAction.one_smul
map_comp f g := funext fun x => (smul_smul g f x).symm
/-- A multiplicative action M ↻ X induces a category structure on X, where a morphism
from x to y is a scalar taking x to y. Due to implementation details, the object type
of this category is not equal to X, but is in bijection with X. -/
def ActionCategory :=
(actionAsFunctor M X).Elements
instance : Category (ActionCategory M X) := by
dsimp only [ActionCategory]
infer_instance
namespace ActionCategory
/-- The projection from the action category to the monoid, mapping a morphism to its
label. -/
def π : ActionCategory M X ⥤ SingleObj M :=
CategoryOfElements.π _
@[simp]
theorem π_map (p q : ActionCategory M X) (f : p ⟶ q) : (π M X).map f = f.val :=
rfl
@[simp]
theorem π_obj (p : ActionCategory M X) : (π M X).obj p = SingleObj.star M :=
Unit.ext _ _
variable {M X}
/-- The canonical map `ActionCategory M X → X`. It is given by `fun x => x.snd`, but
has a more explicit type. -/
protected def back : ActionCategory M X → X := fun x => x.snd
instance : CoeTC X (ActionCategory M X) :=
⟨fun x => ⟨(), x⟩⟩
@[simp]
theorem coe_back (x : X) : ActionCategory.back (x : ActionCategory M X) = x :=
rfl
@[simp]
theorem back_coe (x : ActionCategory M X) : ↑x.back = x := by cases x; rfl
variable (M X)
/-- An object of the action category given by M ↻ X corresponds to an element of X. -/
def objEquiv : X ≃ ActionCategory M X where
toFun x := x
invFun x := x.back
left_inv := coe_back
| right_inv := back_coe
| Mathlib/CategoryTheory/Action.lean | 89 | 89 |
/-
Copyright (c) 2020 Ashvni Narayanan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ashvni Narayanan
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Ring.Subring.Defs
import Mathlib.Algebra.Ring.Subsemiring.Basic
import Mathlib.RingTheory.NonUnitalSubring.Defs
import Mathlib.Data.Set.Finite.Basic
/-!
# Subrings
We prove that subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `Subring R`, sending a subset of `R`
to the subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [Ring R] (S : Type u) [Ring S] (f g : R →+* S)`
`(A : Subring R) (B : Subring S) (s : Set R)`
* `instance : CompleteLattice (Subring R)` : the complete lattice structure on the subrings.
* `Subring.center` : the center of a ring `R`.
* `Subring.closure` : subring closure of a set, i.e., the smallest subring that includes the set.
* `Subring.gi` : `closure : Set M → Subring M` and coercion `(↑) : Subring M → et M`
form a `GaloisInsertion`.
* `comap f B : Subring A` : the preimage of a subring `B` along the ring homomorphism `f`
* `map f A : Subring B` : the image of a subring `A` along the ring homomorphism `f`.
* `prod A B : Subring (R × S)` : the product of subrings
* `f.range : Subring B` : the range of the ring homomorphism `f`.
* `eqLocus f g : Subring R` : given ring homomorphisms `f g : R →+* S`,
the subring of `R` where `f x = g x`
## Implementation notes
A subring is implemented as a subsemiring which is also an additive subgroup.
The initial PR was as a submonoid which is also an additive subgroup.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a subring's underlying set.
## Tags
subring, subrings
-/
assert_not_exists OrderedRing
universe u v w
variable {R : Type u} {S : Type v} {T : Type w} [Ring R]
variable [Ring S] [Ring T]
namespace Subring
variable {s t : Subring R}
-- Porting note: there is no `Subring.toSubmonoid` but we can't define it because there is a
-- projection `s.toSubmonoid`
@[mono]
theorem toSubsemiring_strictMono : StrictMono (toSubsemiring : Subring R → Subsemiring R) :=
fun _ _ => id
@[mono]
theorem toSubsemiring_mono : Monotone (toSubsemiring : Subring R → Subsemiring R) :=
toSubsemiring_strictMono.monotone
@[gcongr]
lemma toSubsemiring_lt_toSubsemiring (hst : s < t) : s.toSubsemiring < t.toSubsemiring := hst
@[gcongr]
lemma toSubsemiring_le_toSubsemiring (hst : s ≤ t) : s.toSubsemiring ≤ t.toSubsemiring := hst
@[mono]
theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Subring R → AddSubgroup R) :=
fun _ _ => id
@[mono]
theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Subring R → AddSubgroup R) :=
toAddSubgroup_strictMono.monotone
@[gcongr]
lemma toAddSubgroup_lt_toAddSubgroup (hst : s < t) : s.toAddSubgroup < t.toAddSubgroup := hst
@[gcongr]
lemma toAddSubgroup_le_toAddSubgroup (hst : s ≤ t) : s.toAddSubgroup ≤ t.toAddSubgroup := hst
@[mono]
theorem toSubmonoid_strictMono : StrictMono (fun s : Subring R => s.toSubmonoid) := fun _ _ => id
@[mono]
theorem toSubmonoid_mono : Monotone (fun s : Subring R => s.toSubmonoid) :=
toSubmonoid_strictMono.monotone
end Subring
namespace Subring
variable (s : Subring R)
/-- Product of a list of elements in a subring is in the subring. -/
protected theorem list_prod_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s :=
list_prod_mem
/-- Sum of a list of elements in a subring is in the subring. -/
protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
list_sum_mem
/-- Product of a multiset of elements in a subring of a `CommRing` is in the subring. -/
protected theorem multiset_prod_mem {R} [CommRing R] (s : Subring R) (m : Multiset R) :
(∀ a ∈ m, a ∈ s) → m.prod ∈ s :=
multiset_prod_mem _
/-- Sum of a multiset of elements in a `Subring` of a `Ring` is
in the `Subring`. -/
protected theorem multiset_sum_mem {R} [Ring R] (s : Subring R) (m : Multiset R) :
(∀ a ∈ m, a ∈ s) → m.sum ∈ s :=
multiset_sum_mem _
/-- Product of elements of a subring of a `CommRing` indexed by a `Finset` is in the
subring. -/
protected theorem prod_mem {R : Type*} [CommRing R] (s : Subring R) {ι : Type*} {t : Finset ι}
{f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s :=
prod_mem h
/-- Sum of elements in a `Subring` of a `Ring` indexed by a `Finset`
is in the `Subring`. -/
protected theorem sum_mem {R : Type*} [Ring R] (s : Subring R) {ι : Type*} {t : Finset ι}
{f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s :=
sum_mem h
/-! ## top -/
/-- The subring `R` of the ring `R`. -/
instance : Top (Subring R) :=
⟨{ (⊤ : Submonoid R), (⊤ : AddSubgroup R) with }⟩
@[simp]
theorem mem_top (x : R) : x ∈ (⊤ : Subring R) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : Subring R) : Set R) = Set.univ :=
rfl
/-- The ring equiv between the top element of `Subring R` and `R`. -/
@[simps!]
def topEquiv : (⊤ : Subring R) ≃+* R :=
Subsemiring.topEquiv
instance {R : Type*} [Ring R] [Fintype R] : Fintype (⊤ : Subring R) :=
inferInstanceAs (Fintype (⊤ : Set R))
theorem card_top (R) [Ring R] [Fintype R] : Fintype.card (⊤ : Subring R) = Fintype.card R :=
Fintype.card_congr topEquiv.toEquiv
/-! ## comap -/
/-- The preimage of a subring along a ring homomorphism is a subring. -/
def comap {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring S) : Subring R :=
{ s.toSubmonoid.comap (f : R →* S), s.toAddSubgroup.comap (f : R →+ S) with
carrier := f ⁻¹' s.carrier }
@[simp]
theorem coe_comap (s : Subring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s :=
rfl
@[simp]
theorem mem_comap {s : Subring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s :=
Iff.rfl
theorem comap_comap (s : Subring T) (g : S →+* T) (f : R →+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! ## map -/
/-- The image of a subring along a ring homomorphism is a subring. -/
def map {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring R) : Subring S :=
{ s.toSubmonoid.map (f : R →* S), s.toAddSubgroup.map (f : R →+ S) with
carrier := f '' s.carrier }
@[simp]
theorem coe_map (f : R →+* S) (s : Subring R) : (s.map f : Set S) = f '' s :=
rfl
@[simp]
theorem mem_map {f : R →+* S} {s : Subring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl
@[simp]
theorem map_id : s.map (RingHom.id R) = s :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_le_iff_le_comap {f : R →+* S} {s : Subring R} {t : Subring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ =>
map_le_iff_le_comap
/-- A subring is isomorphic to its image under an injective function -/
noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f :=
{ Equiv.Set.image f s hf with
map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _)
map_add' := fun _ _ => Subtype.ext (f.map_add _ _) }
@[simp]
theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) :
(equivMapOfInjective s f hf x : S) = f x :=
rfl
end Subring
namespace RingHom
variable (g : S →+* T) (f : R →+* S)
/-! ## range -/
/-- The range of a ring homomorphism, as a subring of the target. See Note [range copy pattern]. -/
def range {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) : Subring S :=
((⊤ : Subring R).map f).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : (f.range : Set S) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : R →+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y :=
Iff.rfl
theorem range_eq_map (f : R →+* S) : f.range = Subring.map f ⊤ := by
ext
simp
theorem mem_range_self (f : R →+* S) (x : R) : f x ∈ f.range :=
mem_range.mpr ⟨x, rfl⟩
theorem map_range : f.range.map g = (g.comp f).range := by
simpa only [range_eq_map] using (⊤ : Subring R).map_map g f
/-- The range of a ring homomorphism is a fintype, if the domain is a fintype.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype S`. -/
instance fintypeRange [Fintype R] [DecidableEq S] (f : R →+* S) : Fintype (range f) :=
Set.fintypeRange f
end RingHom
namespace Subring
/-! ## bot -/
instance : Bot (Subring R) :=
⟨(Int.castRingHom R).range⟩
instance : Inhabited (Subring R) :=
⟨⊥⟩
theorem coe_bot : ((⊥ : Subring R) : Set R) = Set.range ((↑) : ℤ → R) :=
RingHom.coe_range (Int.castRingHom R)
theorem mem_bot {x : R} : x ∈ (⊥ : Subring R) ↔ ∃ n : ℤ, ↑n = x :=
RingHom.mem_range
/-! ## inf -/
/-- The inf of two subrings is their intersection. -/
instance : Min (Subring R) :=
⟨fun s t =>
{ s.toSubmonoid ⊓ t.toSubmonoid, s.toAddSubgroup ⊓ t.toAddSubgroup with carrier := s ∩ t }⟩
@[simp]
theorem coe_inf (p p' : Subring R) : ((p ⊓ p' : Subring R) : Set R) = (p : Set R) ∩ p' :=
rfl
@[simp]
theorem mem_inf {p p' : Subring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
instance : InfSet (Subring R) :=
⟨fun s =>
Subring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, t.toSubmonoid) (⨅ t ∈ s, Subring.toAddSubgroup t)
(by simp) (by simp)⟩
@[simp, norm_cast]
theorem coe_sInf (S : Set (Subring R)) : ((sInf S : Subring R) : Set R) = ⋂ s ∈ S, ↑s :=
rfl
theorem mem_sInf {S : Set (Subring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → Subring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
theorem mem_iInf {ι : Sort*} {S : ι → Subring R} {x : R} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by
simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp]
theorem sInf_toSubmonoid (s : Set (Subring R)) :
(sInf s).toSubmonoid = ⨅ t ∈ s, t.toSubmonoid :=
mk'_toSubmonoid _ _
@[simp]
theorem sInf_toAddSubgroup (s : Set (Subring R)) :
(sInf s).toAddSubgroup = ⨅ t ∈ s, Subring.toAddSubgroup t :=
mk'_toAddSubgroup _ _
/-- Subrings of a ring form a complete lattice. -/
instance : CompleteLattice (Subring R) :=
{ completeLatticeOfInf (Subring R) fun _ =>
IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with
bot := ⊥
bot_le := fun s _x hx =>
let ⟨n, hn⟩ := mem_bot.1 hx
hn ▸ intCast_mem s n
top := ⊤
le_top := fun _s _x _hx => trivial
inf := (· ⊓ ·)
inf_le_left := fun _s _t _x => And.left
inf_le_right := fun _s _t _x => And.right
le_inf := fun _s _t₁ _t₂ h₁ h₂ _x hx => ⟨h₁ hx, h₂ hx⟩ }
theorem eq_top_iff' (A : Subring R) : A = ⊤ ↔ ∀ x : R, x ∈ A :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
/-! ## Center of a ring -/
section
variable (R)
/-- The center of a ring `R` is the set of elements that commute with everything in `R` -/
def center : Subring R :=
{ Subsemiring.center R with
carrier := Set.center R
neg_mem' := Set.neg_mem_center }
theorem coe_center : ↑(center R) = Set.center R :=
rfl
@[simp]
theorem center_toSubsemiring : (center R).toSubsemiring = Subsemiring.center R :=
rfl
variable {R}
theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g :=
Subsemigroup.mem_center_iff
instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ =>
decidable_of_iff' _ mem_center_iff
@[simp]
theorem center_eq_top (R) [CommRing R] : center R = ⊤ :=
SetLike.coe_injective (Set.center_eq_univ R)
/-- The center is commutative. -/
instance : CommRing (center R) :=
{ inferInstanceAs (CommSemiring (Subsemiring.center R)), (center R).toRing with }
/-- The center of isomorphic (not necessarily associative) rings are isomorphic. -/
@[simps!] def centerCongr (e : R ≃+* S) : center R ≃+* center S :=
NonUnitalSubsemiring.centerCongr e
/-- The center of a (not necessarily associative) ring
is isomorphic to the center of its opposite. -/
@[simps!] def centerToMulOpposite : center R ≃+* center Rᵐᵒᵖ :=
NonUnitalSubsemiring.centerToMulOpposite
end
section DivisionRing
variable {K : Type u} [DivisionRing K]
instance instField : Field (center K) where
inv a := ⟨a⁻¹, Set.inv_mem_center a.prop⟩
mul_inv_cancel _ ha := Subtype.ext <| mul_inv_cancel₀ <| Subtype.coe_injective.ne ha
div a b := ⟨a / b, Set.div_mem_center a.prop b.prop⟩
div_eq_mul_inv _ _ := Subtype.ext <| div_eq_mul_inv _ _
inv_zero := Subtype.ext inv_zero
-- TODO: use a nicer defeq
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
@[simp]
theorem center.coe_inv (a : center K) : ((a⁻¹ : center K) : K) = (a : K)⁻¹ :=
rfl
@[simp]
theorem center.coe_div (a b : center K) : ((a / b : center K) : K) = (a : K) / (b : K) :=
rfl
end DivisionRing
section Centralizer
/-- The centralizer of a set inside a ring as a `Subring`. -/
def centralizer (s : Set R) : Subring R :=
{ Subsemiring.centralizer s with neg_mem' := Set.neg_mem_centralizer }
@[simp, norm_cast]
theorem coe_centralizer (s : Set R) : (centralizer s : Set R) = s.centralizer :=
rfl
theorem centralizer_toSubmonoid (s : Set R) :
(centralizer s).toSubmonoid = Submonoid.centralizer s :=
rfl
theorem centralizer_toSubsemiring (s : Set R) :
(centralizer s).toSubsemiring = Subsemiring.centralizer s :=
rfl
theorem mem_centralizer_iff {s : Set R} {z : R} : z ∈ centralizer s ↔ ∀ g ∈ s, g * z = z * g :=
Iff.rfl
theorem center_le_centralizer (s) : center R ≤ centralizer s :=
s.center_subset_centralizer
theorem centralizer_le (s t : Set R) (h : s ⊆ t) : centralizer t ≤ centralizer s :=
Set.centralizer_subset h
@[simp]
theorem centralizer_eq_top_iff_subset {s : Set R} : centralizer s = ⊤ ↔ s ⊆ center R :=
SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset
@[simp]
theorem centralizer_univ : centralizer Set.univ = center R :=
SetLike.ext' (Set.centralizer_univ R)
end Centralizer
/-! ## subring closure of a subset -/
/-- The `Subring` generated by a set. -/
def closure (s : Set R) : Subring R :=
sInf { S | s ⊆ S }
theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : Subring R, s ⊆ S → x ∈ S :=
mem_sInf
/-- The subring generated by a set includes the set. -/
@[simp, aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_closure {s : Set R} : s ⊆ closure s := fun _ hx => mem_closure.2 fun _ hS => hS hx
theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h =>
hP (subset_closure h)
/-- A subring `t` includes `closure s` if and only if it includes `s`. -/
@[simp]
theorem closure_le {s : Set R} {t : Subring R} : closure s ≤ t ↔ s ⊆ t :=
⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩
/-- Subring closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
@[gcongr]
theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 <| Set.Subset.trans h subset_closure
theorem closure_eq_of_le {s : Set R} {t : Subring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all
elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {s : Set R} {p : (x : R) → x ∈ closure s → Prop}
(mem : ∀ (x) (hx : x ∈ s), p x (subset_closure hx))
(zero : p 0 (zero_mem _)) (one : p 1 (one_mem _))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy))
(neg : ∀ x hx, p x hx → p (-x) (neg_mem hx))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
{x} (hx : x ∈ closure s) : p x hx :=
let K : Subring R :=
{ carrier := { x | ∃ hx, p x hx }
mul_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, mul _ _ _ _ hpx hpy⟩
add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩
neg_mem' := fun ⟨_, hpx⟩ ↦ ⟨_, neg _ _ hpx⟩
zero_mem' := ⟨_, zero⟩
one_mem' := ⟨_, one⟩ }
closure_le (t := K) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id
/-- An induction principle for closure membership, for predicates with two arguments. -/
@[elab_as_elim]
theorem closure_induction₂ {s : Set R} {p : (x y : R) → x ∈ closure s → y ∈ closure s → Prop}
(mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_closure hx) (subset_closure hy))
(zero_left : ∀ x hx, p 0 x (zero_mem _) hx) (zero_right : ∀ x hx, p x 0 hx (zero_mem _))
(one_left : ∀ x hx, p 1 x (one_mem _) hx) (one_right : ∀ x hx, p x 1 hx (one_mem _))
(neg_left : ∀ x y hx hy, p x y hx hy → p (-x) y (neg_mem hx) hy)
(neg_right : ∀ x y hx hy, p x y hx hy → p x (-y) hx (neg_mem hy))
(add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz)
(add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz))
(mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz)
(mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz))
{x y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) :
p x y hx hy := by
induction hy using closure_induction with
| mem z hz => induction hx using closure_induction with
| mem _ h => exact mem_mem _ _ h hz
| zero => exact zero_left _ _
| one => exact one_left _ _
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂
| neg _ _ h => exact neg_left _ _ _ _ h
| zero => exact zero_right x hx
| one => exact one_right x hx
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂
| neg _ _ h => exact neg_right _ _ _ _ h
theorem mem_closure_iff {s : Set R} {x} :
x ∈ closure s ↔ x ∈ AddSubgroup.closure (Submonoid.closure s : Set R) :=
⟨fun h => by
induction h using closure_induction with
| mem _ hx => exact AddSubgroup.subset_closure (Submonoid.subset_closure hx)
| zero => exact zero_mem _
| one => exact AddSubgroup.subset_closure (one_mem _)
| add _ _ _ _ hx hy => exact add_mem hx hy
| neg _ _ hx => exact neg_mem hx
| mul _ _ _hx _hy hx hy =>
clear _hx _hy
induction hx, hy using AddSubgroup.closure_induction₂ with
| mem _ _ hx hy => exact AddSubgroup.subset_closure (mul_mem hx hy)
| one_left => simpa using zero_mem _
| one_right => simpa using zero_mem _
| mul_left _ _ _ _ _ _ h₁ h₂ => simpa [add_mul] using add_mem h₁ h₂
| mul_right _ _ _ _ _ _ h₁ h₂ => simpa [mul_add] using add_mem h₁ h₂
| inv_left _ _ _ _ h => simpa [neg_mul] using neg_mem h
| inv_right _ _ _ _ h => simpa [mul_neg] using neg_mem h,
fun h => by
induction h using AddSubgroup.closure_induction with
| mem x hx =>
induction hx using Submonoid.closure_induction with
| mem _ h => exact subset_closure h
| one => exact one_mem _
| mul _ _ _ _ h₁ h₂ => exact mul_mem h₁ h₂
| one => exact zero_mem _
| mul _ _ _ _ h₁ h₂ => exact add_mem h₁ h₂
| inv _ _ h => exact neg_mem h⟩
lemma closure_le_centralizer_centralizer (s : Set R) :
closure s ≤ centralizer (centralizer s) :=
closure_le.mpr Set.subset_centralizer_centralizer
/-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/
abbrev closureCommRingOfComm {s : Set R} (hcomm : ∀ x ∈ s, ∀ y ∈ s, x * y = y * x) :
CommRing (closure s) :=
{ (closure s).toRing with
mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦
have := closure_le_centralizer_centralizer s
Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) }
theorem exists_list_of_mem_closure {s : Set R} {x : R} (hx : x ∈ closure s) :
∃ L : List (List R), (∀ t ∈ L, ∀ y ∈ t, y ∈ s ∨ y = (-1 : R)) ∧ (L.map List.prod).sum = x := by
rw [mem_closure_iff] at hx
induction hx using AddSubgroup.closure_induction with
| mem _ hx =>
obtain ⟨l, hl, h⟩ := Submonoid.exists_list_of_mem_closure hx
exact ⟨[l], by simp [h]; clear_aux_decl; tauto⟩
| one => exact ⟨[], List.forall_mem_nil _, rfl⟩
| mul _ _ _ _ hL hM =>
obtain ⟨⟨L, HL1, HL2⟩, ⟨M, HM1, HM2⟩⟩ := And.intro hL hM
exact ⟨L ++ M, List.forall_mem_append.2 ⟨HL1, HM1⟩, by
rw [List.map_append, List.sum_append, HL2, HM2]⟩
| inv _ _ hL =>
obtain ⟨L, hL⟩ := hL
exact ⟨L.map (List.cons (-1)),
List.forall_mem_map.2 fun j hj => List.forall_mem_cons.2 ⟨Or.inr rfl, hL.1 j hj⟩,
hL.2 ▸
List.recOn L (by simp)
(by simp +contextual [List.map_cons, add_comm])⟩
variable (R) in
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure R _) (↑) where
choice s _ := closure s
gc _s _t := closure_le
le_l_u _s := subset_closure
choice_eq _s _h := rfl
/-- Closure of a subring `S` equals `S`. -/
@[simp]
theorem closure_eq (s : Subring R) : closure (s : Set R) = s :=
(Subring.gi R).l_u_eq s
@[simp]
theorem closure_empty : closure (∅ : Set R) = ⊥ :=
(Subring.gi R).gc.l_bot
@[simp]
theorem closure_univ : closure (Set.univ : Set R) = ⊤ :=
@coe_top R _ ▸ closure_eq ⊤
theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t :=
(Subring.gi R).gc.l_sup
theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(Subring.gi R).gc.l_iSup
theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(Subring.gi R).gc.l_sSup
@[simp]
theorem closure_singleton_intCast (n : ℤ) : closure {(n : R)} = ⊥ :=
bot_unique <| closure_le.2 <| Set.singleton_subset_iff.mpr <| intCast_mem _ _
@[simp]
theorem closure_singleton_natCast (n : ℕ) : closure {(n : R)} = ⊥ :=
mod_cast closure_singleton_intCast n
@[simp]
theorem closure_singleton_zero : closure {(0 : R)} = ⊥ := mod_cast closure_singleton_natCast 0
@[simp]
theorem closure_singleton_one : closure {(1 : R)} = ⊥ := mod_cast closure_singleton_natCast 1
@[simp]
theorem closure_insert_intCast (n : ℤ) (s : Set R) : closure (insert (n : R) s) = closure s := by
rw [Set.insert_eq, closure_union]
simp
@[simp]
theorem closure_insert_natCast (n : ℕ) (s : Set R) : closure (insert (n : R) s) = closure s :=
mod_cast closure_insert_intCast n s
@[simp]
theorem closure_insert_zero (s : Set R) : closure (insert 0 s) = closure s :=
mod_cast closure_insert_natCast 0 s
@[simp]
theorem closure_insert_one (s : Set R) : closure (insert 1 s) = closure s :=
mod_cast closure_insert_natCast 1 s
theorem map_sup (s t : Subring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : R →+* S) (s : ι → Subring R) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem map_inf (s t : Subring R) (f : R →+* S) (hf : Function.Injective f) :
(s ⊓ t).map f = s.map f ⊓ t.map f := SetLike.coe_injective (Set.image_inter hf)
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : R →+* S) (hf : Function.Injective f)
(s : ι → Subring R) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
theorem comap_inf (s t : Subring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ι : Sort*} (f : R →+* S) (s : ι → Subring S) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : R →+* S) : (⊥ : Subring R).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : R →+* S) : (⊤ : Subring S).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- Given `Subring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ×̂ t`
as a subring of `R × S`. -/
def prod (s : Subring R) (t : Subring S) : Subring (R × S) :=
{ s.toSubmonoid.prod t.toSubmonoid, s.toAddSubgroup.prod t.toAddSubgroup with carrier := s ×ˢ t }
@[norm_cast]
theorem coe_prod (s : Subring R) (t : Subring S) :
(s.prod t : Set (R × S)) = (s : Set R) ×ˢ (t : Set S) :=
rfl
theorem mem_prod {s : Subring R} {t : Subring S} {p : R × S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[gcongr, mono]
theorem prod_mono ⦃s₁ s₂ : Subring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : Subring S⦄ (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
theorem prod_mono_right (s : Subring R) : Monotone fun t : Subring S => s.prod t :=
prod_mono (le_refl s)
theorem prod_mono_left (t : Subring S) : Monotone fun s : Subring R => s.prod t := fun _ _ hs =>
prod_mono hs (le_refl t)
theorem prod_top (s : Subring R) : s.prod (⊤ : Subring S) = s.comap (RingHom.fst R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
theorem top_prod (s : Subring S) : (⊤ : Subring R).prod s = s.comap (RingHom.snd R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[simp]
theorem top_prod_top : (⊤ : Subring R).prod (⊤ : Subring S) = ⊤ :=
(top_prod _).trans <| comap_top _
/-- Product of subrings is isomorphic to their product as rings. -/
def prodEquiv (s : Subring R) (t : Subring S) : s.prod t ≃+* s × t :=
{ Equiv.Set.prod (s : Set R) (t : Set S) with
map_mul' := fun _x _y => rfl
map_add' := fun _x _y => rfl }
/-- The underlying set of a non-empty directed sSup of subrings is just a union of the subrings.
Note that this fails without the directedness assumption (the union of two subrings is
typically not a subring) -/
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subring R} (hS : Directed (· ≤ ·) S)
{x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
let U : Subring R :=
Subring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubmonoid) (⨆ i, (S i).toAddSubgroup)
(Submonoid.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS)
suffices ⨆ i, S i ≤ U by simpa [U] using @this x
exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩
theorem coe_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Subring R} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Subring R) : Set R) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
theorem mem_sSup_of_directedOn {S : Set (Subring R)} (Sne : S.Nonempty) (hS : DirectedOn (· ≤ ·) S)
{x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk,
exists_prop]
theorem coe_sSup_of_directedOn {S : Set (Subring R)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
theorem mem_map_equiv {f : R ≃+* S} {K : Subring R} {x : S} :
x ∈ K.map (f : R →+* S) ↔ f.symm x ∈ K :=
@Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x
theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : Subring R) :
K.map (f : R →+* S) = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : Subring S) :
K.comap (f : R →+* S) = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
end Subring
namespace RingHom
variable {s : Subring R}
open Subring
/-- Restriction of a ring homomorphism to its range interpreted as a subsemiring.
This is the bundled version of `Set.rangeFactorization`. -/
def rangeRestrict (f : R →+* S) : R →+* f.range :=
f.codRestrict f.range fun x => ⟨x, rfl⟩
@[simp]
theorem coe_rangeRestrict (f : R →+* S) (x : R) : (f.rangeRestrict x : S) = f x :=
rfl
theorem rangeRestrict_surjective (f : R →+* S) : Function.Surjective f.rangeRestrict :=
fun ⟨_y, hy⟩ =>
let ⟨x, hx⟩ := mem_range.mp hy
⟨x, Subtype.ext hx⟩
theorem range_eq_top {f : R →+* S} :
f.range = (⊤ : Subring S) ↔ Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ
@[deprecated (since := "2024-11-11")] alias range_top_iff_surjective := range_eq_top
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
@[simp]
theorem range_eq_top_of_surjective (f : R →+* S) (hf : Function.Surjective f) :
f.range = (⊤ : Subring S) :=
range_eq_top.2 hf
@[deprecated (since := "2024-11-11")] alias range_top_of_surjective := range_eq_top_of_surjective
section eqLocus
variable {S : Type v} [Semiring S]
/-- The subring of elements `x : R` such that `f x = g x`, i.e.,
the equalizer of f and g as a subring of R -/
def eqLocus (f g : R →+* S) : Subring R :=
{ (f : R →* S).eqLocusM g, (f : R →+ S).eqLocus g with carrier := { x | f x = g x } }
@[simp]
theorem eqLocus_same (f : R →+* S) : f.eqLocus f = ⊤ :=
SetLike.ext fun _ => eq_self_iff_true _
/-- If two ring homomorphisms are equal on a set, then they are equal on its subring closure. -/
theorem eqOn_set_closure {f g : R →+* S} {s : Set R} (h : Set.EqOn f g s) :
Set.EqOn f g (closure s) :=
show closure s ≤ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_set_top {f g : R →+* S} (h : Set.EqOn f g (⊤ : Subring R)) : f = g :=
ext fun _x => h trivial
theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊤) {f g : R →+* S} (h : s.EqOn f g) :
f = g :=
eq_of_eqOn_set_top <| hs ▸ eqOn_set_closure h
end eqLocus
theorem closure_preimage_le (f : R →+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a ring homomorphism of the subring generated by a set equals
the subring generated by the image of the set. -/
theorem map_closure (f : R →+* S) (s : Set R) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Subring.gi S).gc (Subring.gi R).gc
fun _ ↦ rfl
end RingHom
namespace Subring
open RingHom
/-- The ring homomorphism associated to an inclusion of subrings. -/
def inclusion {S T : Subring R} (h : S ≤ T) : S →+* T :=
S.subtype.codRestrict _ fun x => h x.2
@[simp]
theorem range_subtype (s : Subring R) : s.subtype.range = s :=
SetLike.coe_injective <| (coe_rangeS _).trans Subtype.range_coe
theorem range_fst : (fst R S).rangeS = ⊤ :=
(fst R S).rangeS_top_of_surjective <| Prod.fst_surjective
theorem range_snd : (snd R S).rangeS = ⊤ :=
(snd R S).rangeS_top_of_surjective <| Prod.snd_surjective
@[simp]
theorem prod_bot_sup_bot_prod (s : Subring R) (t : Subring S) : s.prod ⊥ ⊔ prod ⊥ t = s.prod t :=
le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) fun p hp =>
Prod.fst_mul_snd p ▸
mul_mem
((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, SetLike.mem_coe.2 <| one_mem ⊥⟩)
((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨SetLike.mem_coe.2 <| one_mem ⊥, hp.2⟩)
end Subring
namespace RingEquiv
variable {s t : Subring R}
/-- Makes the identity isomorphism from a proof two subrings of a multiplicative
monoid are equal. -/
def subringCongr (h : s = t) : s ≃+* t :=
{ Equiv.setCongr <| congr_arg _ h with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its
`RingHom.range`. -/
def ofLeftInverse {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) : R ≃+* f.range :=
{ f.rangeRestrict with
toFun := fun x => f.rangeRestrict x
invFun := fun x => (g ∘ f.range.subtype) x
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := RingHom.mem_range.mp x.prop
show f (g x) = x by rw [← hx', h x'] }
@[simp]
theorem ofLeftInverse_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f) (x : R) :
↑(ofLeftInverse h x) = f x :=
rfl
@[simp]
theorem ofLeftInverse_symm_apply {g : S → R} {f : R →+* S} (h : Function.LeftInverse g f)
(x : f.range) : (ofLeftInverse h).symm x = g x :=
rfl
/-- Given an equivalence `e : R ≃+* S` of rings and a subring `s` of `R`,
`subringMap e s` is the induced equivalence between `s` and `s.map e` -/
def subringMap (e : R ≃+* S) : s ≃+* s.map e.toRingHom :=
e.subsemiringMap s.toSubsemiring
end RingEquiv
namespace Subring
variable {s : Set R}
-- attribute [local reducible] closure -- Porting note: not available in Lean4
@[elab_as_elim]
protected theorem InClosure.recOn {C : R → Prop} {x : R} (hx : x ∈ closure s) (h1 : C 1)
(hneg1 : C (-1)) (hs : ∀ z ∈ s, ∀ n, C n → C (z * n)) (ha : ∀ {x y}, C x → C y → C (x + y)) :
C x := by
have h0 : C 0 := add_neg_cancel (1 : R) ▸ ha h1 hneg1
rcases exists_list_of_mem_closure hx with ⟨L, HL, rfl⟩
clear hx
induction' L with hd tl ih
· exact h0
rw [List.forall_mem_cons] at HL
suffices C (List.prod hd) by
rw [List.map_cons, List.sum_cons]
exact ha this (ih HL.2)
replace HL := HL.1
clear ih tl
rsuffices ⟨L, HL', HP | HP⟩ :
∃ L : List R, (∀ x ∈ L, x ∈ s) ∧ (List.prod hd = List.prod L ∨ List.prod hd = -List.prod L)
· rw [HP]
clear HP HL hd
induction' L with hd tl ih
· exact h1
rw [List.forall_mem_cons] at HL'
rw [List.prod_cons]
exact hs _ HL'.1 _ (ih HL'.2)
· rw [HP]
clear HP HL hd
induction' L with hd tl ih
· exact hneg1
rw [List.prod_cons, neg_mul_eq_mul_neg]
rw [List.forall_mem_cons] at HL'
exact hs _ HL'.1 _ (ih HL'.2)
induction' hd with hd tl ih
· exact ⟨[], List.forall_mem_nil _, Or.inl rfl⟩
rw [List.forall_mem_cons] at HL
rcases ih HL.2 with ⟨L, HL', HP | HP⟩ <;> rcases HL.1 with hhd | hhd
· exact
⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩,
Or.inl <| by rw [List.prod_cons, List.prod_cons, HP]⟩
· exact ⟨L, HL', Or.inr <| by rw [List.prod_cons, hhd, neg_one_mul, HP]⟩
· exact
⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩,
Or.inr <| by rw [List.prod_cons, List.prod_cons, HP, neg_mul_eq_mul_neg]⟩
· exact ⟨L, HL', Or.inl <| by rw [List.prod_cons, hhd, HP, neg_one_mul, neg_neg]⟩
theorem closure_preimage_le (f : R →+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
end Subring
/-! ## Actions by `Subring`s
These are just copies of the definitions about `Subsemiring` starting from
`Subsemiring.MulAction`.
When `R` is commutative, `Algebra.ofSubring` provides a stronger result than those found in
this file, which uses the same scalar action.
-/
section Actions
namespace Subring
variable {α β : Type*}
-- Porting note: Lean can find this instance already
/-- The action by a subring is the action by the underlying ring. -/
instance [SMul R α] (S : Subring R) : SMul S α :=
inferInstanceAs (SMul S.toSubsemiring α)
theorem smul_def [SMul R α] {S : Subring R} (g : S) (m : α) : g • m = (g : R) • m :=
rfl
-- Porting note: Lean can find this instance already
instance smulCommClass_left [SMul R β] [SMul α β] [SMulCommClass R α β] (S : Subring R) :
SMulCommClass S α β :=
inferInstanceAs (SMulCommClass S.toSubsemiring α β)
-- Porting note: Lean can find this instance already
instance smulCommClass_right [SMul α β] [SMul R β] [SMulCommClass α R β] (S : Subring R) :
SMulCommClass α S β :=
inferInstanceAs (SMulCommClass α S.toSubsemiring β)
-- Porting note: Lean can find this instance already
/-- Note that this provides `IsScalarTower S R R` which is needed by `smul_mul_assoc`. -/
instance [SMul α β] [SMul R α] [SMul R β] [IsScalarTower R α β] (S : Subring R) :
IsScalarTower S α β :=
inferInstanceAs (IsScalarTower S.toSubsemiring α β)
-- Porting note: Lean can find this instance already
instance [SMul R α] [FaithfulSMul R α] (S : Subring R) : FaithfulSMul S α :=
inferInstanceAs (FaithfulSMul S.toSubsemiring α)
-- Porting note: Lean can find this instance already
/-- The action by a subring is the action by the underlying ring. -/
instance [MulAction R α] (S : Subring R) : MulAction S α :=
inferInstanceAs (MulAction S.toSubsemiring α)
-- Porting note: Lean can find this instance already
/-- The action by a subring is the action by the underlying ring. -/
instance [AddMonoid α] [DistribMulAction R α] (S : Subring R) : DistribMulAction S α :=
inferInstanceAs (DistribMulAction S.toSubsemiring α)
-- Porting note: Lean can find this instance already
/-- The action by a subring is the action by the underlying ring. -/
instance [Monoid α] [MulDistribMulAction R α] (S : Subring R) : MulDistribMulAction S α :=
inferInstanceAs (MulDistribMulAction S.toSubsemiring α)
-- Porting note: Lean can find this instance already
/-- The action by a subring is the action by the underlying ring. -/
instance [Zero α] [SMulWithZero R α] (S : Subring R) : SMulWithZero S α :=
inferInstanceAs (SMulWithZero S.toSubsemiring α)
/-- The action by a subring is the action by the underlying ring. -/
instance [Zero α] [MulActionWithZero R α] (S : Subring R) : MulActionWithZero S α :=
-- inferInstanceAs (MulActionWithZero S.toSubsemiring α) -- Porting note: does not work
Subsemiring.mulActionWithZero S.toSubsemiring
/-- The action by a subring is the action by the underlying ring. -/
instance [AddCommMonoid α] [Module R α] (S : Subring R) : Module S α :=
-- inferInstanceAs (Module S.toSubsemiring α) -- Porting note: does not work
Subsemiring.module S.toSubsemiring
-- Porting note: Lean can find this instance already
/-- The action by a subsemiring is the action by the underlying ring. -/
instance [Semiring α] [MulSemiringAction R α] (S : Subring R) : MulSemiringAction S α :=
inferInstanceAs (MulSemiringAction S.toSubmonoid α)
/-- The center of a semiring acts commutatively on that semiring. -/
instance center.smulCommClass_left : SMulCommClass (center R) R R :=
Subsemiring.center.smulCommClass_left
/-- The center of a semiring acts commutatively on that semiring. -/
instance center.smulCommClass_right : SMulCommClass R (center R) R :=
Subsemiring.center.smulCommClass_right
end Subring
end Actions
namespace Subring
theorem map_comap_eq (f : R →+* S) (t : Subring S) : (t.comap f).map f = t ⊓ f.range :=
SetLike.coe_injective Set.image_preimage_eq_inter_range
theorem map_comap_eq_self
{f : R →+* S} {t : Subring S} (h : t ≤ f.range) : (t.comap f).map f = t := by
simpa only [inf_of_le_left h] using Subring.map_comap_eq f t
theorem map_comap_eq_self_of_surjective
{f : R →+* S} (hf : Function.Surjective f) (t : Subring S) : (t.comap f).map f = t :=
map_comap_eq_self <| by simp [hf]
theorem comap_map_eq (f : R →+* S) (s : Subring R) :
(s.map f).comap f = s ⊔ closure (f ⁻¹' {0}) := by
apply le_antisymm
· intro x hx
rw [mem_comap, mem_map] at hx
obtain ⟨y, hy, hxy⟩ := hx
replace hxy : x - y ∈ f ⁻¹' {0} := by simp [hxy]
rw [← closure_eq s, ← closure_union, ← add_sub_cancel y x]
exact Subring.add_mem _ (subset_closure <| Or.inl hy) (subset_closure <| Or.inr hxy)
· rw [← map_le_iff_le_comap, map_sup, f.map_closure]
apply le_of_eq
rw [sup_eq_left, closure_le]
exact (Set.image_preimage_subset f {0}).trans (Set.singleton_subset_iff.2 (s.map f).zero_mem)
theorem comap_map_eq_self {f : R →+* S} {s : Subring R}
(h : f ⁻¹' {0} ⊆ s) : (s.map f).comap f = s := by
convert comap_map_eq f s
rwa [left_eq_sup, closure_le]
theorem comap_map_eq_self_of_injective
{f : R →+* S} (hf : Function.Injective f) (s : Subring R) : (s.map f).comap f = s :=
SetLike.coe_injective (Set.preimage_image_eq _ hf)
end Subring
theorem AddSubgroup.int_mul_mem {G : AddSubgroup R} (k : ℤ) {g : R} (h : g ∈ G) :
(k : R) * g ∈ G := by
convert AddSubgroup.zsmul_mem G h k using 1
rw [zsmul_eq_mul]
| Mathlib/Algebra/Ring/Subring/Basic.lean | 1,127 | 1,129 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# The argument of a complex number.
We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π],
such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
open Filter Metric Set
open scoped ComplexConjugate Real Topology
namespace Complex
variable {a x z : ℂ}
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re then Real.arcsin (x.im / ‖x‖)
else if 0 ≤ x.im then Real.arcsin ((-x).im / ‖x‖) + π else Real.arcsin ((-x).im / ‖x‖) - π
theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / ‖x‖ := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1
(abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / ‖x‖ := by
rw [arg]
split_ifs with h₁ h₂
· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *]
· rw [Real.cos_add_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
· rw [Real.cos_sub_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
@[simp]
theorem norm_mul_exp_arg_mul_I (x : ℂ) : ‖x‖ * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· have : ‖x‖ ≠ 0 := norm_ne_zero_iff.mpr hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm ‖x‖]
@[simp]
theorem norm_mul_cos_add_sin_mul_I (x : ℂ) : (‖x‖ * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by
rw [← exp_mul_I, norm_mul_exp_arg_mul_I]
@[simp]
lemma norm_mul_cos_arg (x : ℂ) : ‖x‖ * Real.cos (arg x) = x.re := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x)
@[simp]
lemma norm_mul_sin_arg (x : ℂ) : ‖x‖ * Real.sin (arg x) = x.im := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x)
theorem norm_eq_one_iff (z : ℂ) : ‖z‖ = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by
refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩
· calc
exp (arg z * I) = ‖z‖ * exp (arg z * I) := by rw [hz, ofReal_one, one_mul]
_ = z :=norm_mul_exp_arg_mul_I z
· rintro ⟨θ, rfl⟩
exact Complex.norm_exp_ofReal_mul_I θ
@[deprecated (since := "2025-02-16")] alias abs_mul_exp_arg_mul_I := norm_mul_exp_arg_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_add_sin_mul_I := norm_mul_cos_add_sin_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_arg := norm_mul_cos_arg
@[deprecated (since := "2025-02-16")] alias abs_mul_sin_arg := norm_mul_sin_arg
@[deprecated (since := "2025-02-16")] alias abs_eq_one_iff := norm_eq_one_iff
@[simp]
theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by
ext x
simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range]
theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) :
arg (r * (cos θ + sin θ * I)) = θ := by
simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one]
simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ←
mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr]
by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2)
· rw [if_pos]
exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁]
· rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁
rcases h₁ with h₁ | h₁
· replace hθ := hθ.1
have hcos : Real.cos θ < 0 := by
rw [← neg_pos, ← Real.cos_add_pi]
refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ
rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith;
linarith; exact hsin.not_le; exact hcos.not_le]
· replace hθ := hθ.2
have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith)
have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩
rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith;
linarith; exact hsin; exact hcos.not_le]
theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by
rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ]
lemma arg_exp_mul_I (θ : ℝ) :
arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by
convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2
· rw [← exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
· convert toIocMod_mem_Ioc _ _ _
ring
@[simp]
theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl]
theorem ext_norm_arg {x y : ℂ} (h₁ : ‖x‖ = ‖y‖) (h₂ : x.arg = y.arg) : x = y := by
rw [← norm_mul_exp_arg_mul_I x, ← norm_mul_exp_arg_mul_I y, h₁, h₂]
theorem ext_norm_arg_iff {x y : ℂ} : x = y ↔ ‖x‖ = ‖y‖ ∧ arg x = arg y :=
⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_norm_arg⟩
@[deprecated (since := "2025-02-16")] alias ext_abs_arg := ext_norm_arg
@[deprecated (since := "2025-02-16")] alias ext_abs_arg_iff := ext_norm_arg_iff
theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by
have hπ : 0 < π := Real.pi_pos
rcases eq_or_ne z 0 with (rfl | hz)
· simp [hπ, hπ.le]
rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩
rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN
rw [← norm_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N]
have := arg_mul_cos_add_sin_mul_I (norm_pos_iff.mpr hz) hN
push_cast at this
rwa [this]
@[simp]
theorem range_arg : Set.range arg = Set.Ioc (-π) π :=
(Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩
theorem arg_le_pi (x : ℂ) : arg x ≤ π :=
(arg_mem_Ioc x).2
theorem neg_pi_lt_arg (x : ℂ) : -π < arg x :=
(arg_mem_Ioc x).1
theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π :=
abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩
@[simp]
theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by
rcases eq_or_ne z 0 with (rfl | h₀); · simp
calc
0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) :=
⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by
contrapose!
intro h
exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩
_ ↔ _ := by rw [sin_arg, le_div_iff₀ (norm_pos_iff.mpr h₀), zero_mul]
@[simp]
theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 :=
lt_iff_lt_of_le_iff_le arg_nonneg_iff
theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by
rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero]
conv_lhs =>
rw [← norm_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul,
arg_mul_cos_add_sin_mul_I (mul_pos hr (norm_pos_iff.mpr hx)) x.arg_mem_Ioc]
theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x :=
mul_comm x r ▸ arg_real_mul x hr
theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (‖y‖ / ‖x‖ : ℂ) * x = y := by
simp only [ext_norm_arg_iff, norm_mul, norm_div, norm_real, norm_norm,
div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hx), eq_self_iff_true, true_and]
rw [← ofReal_div, arg_real_mul]
exact div_pos (norm_pos_iff.mpr hy) (norm_pos_iff.mpr hx)
@[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one]
/-- This holds true for all `x : ℂ` because of the junk values `0 / 0 = 0` and `arg 0 = 0`. -/
@[simp] lemma arg_div_self (x : ℂ) : arg (x / x) = 0 := by
obtain rfl | hx := eq_or_ne x 0 <;> simp [*]
@[simp]
theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)]
@[simp]
theorem arg_I : arg I = π / 2 := by simp [arg, le_refl]
@[simp]
theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl]
@[simp]
theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by
by_cases h : x = 0
· simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re]
rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right₀ (norm_ne_zero_iff.mpr h)]
theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx]
@[simp, norm_cast]
lemma natCast_arg {n : ℕ} : arg n = 0 :=
ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg
@[simp]
lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg ofNat(n) = 0 :=
natCast_arg
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 217 | 217 | |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland
-/
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Algebra.Group.Units.Hom
import Mathlib.Algebra.Ring.Hom.Defs
/-!
# Units in semirings and rings
-/
universe u v w x
variable {α : Type u} {β : Type v} {R : Type x}
open Function
namespace Units
section HasDistribNeg
variable [Monoid α] [HasDistribNeg α]
/-- Each element of the group of units of a ring has an additive inverse. -/
instance : Neg αˣ :=
⟨fun u => ⟨-↑u, -↑u⁻¹, by simp, by simp⟩⟩
/-- Representing an element of a ring's unit group as an element of the ring commutes with
mapping this element to its additive inverse. -/
@[simp, norm_cast]
protected theorem val_neg (u : αˣ) : (↑(-u) : α) = -u :=
rfl
@[simp, norm_cast]
protected theorem coe_neg_one : ((-1 : αˣ) : α) = -1 :=
rfl
instance : HasDistribNeg αˣ :=
Units.ext.hasDistribNeg _ Units.val_neg Units.val_mul
@[field_simps]
theorem neg_divp (a : α) (u : αˣ) : -(a /ₚ u) = -a /ₚ u := by simp only [divp, neg_mul]
end HasDistribNeg
section Ring
variable [Ring α]
-- Needs to have higher simp priority than divp_add_divp. 1000 is the default priority.
@[field_simps 1010]
theorem divp_add_divp_same (a b : α) (u : αˣ) : a /ₚ u + b /ₚ u = (a + b) /ₚ u := by
simp only [divp, add_mul]
-- Needs to have higher simp priority than divp_sub_divp. 1000 is the default priority.
@[field_simps 1010]
theorem divp_sub_divp_same (a b : α) (u : αˣ) : a /ₚ u - b /ₚ u = (a - b) /ₚ u := by
rw [sub_eq_add_neg, sub_eq_add_neg, neg_divp, divp_add_divp_same]
@[field_simps]
theorem add_divp (a b : α) (u : αˣ) : a + b /ₚ u = (a * u + b) /ₚ u := by
simp only [divp, add_mul, Units.mul_inv_cancel_right]
|
@[field_simps]
| Mathlib/Algebra/Ring/Units.lean | 67 | 68 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by
classical
exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor.
TODO: deprecate this in favor of `Order.IsSuccLimit`. -/
def IsLimit (o : Ordinal) : Prop :=
IsSuccLimit o
theorem isLimit_iff {o} : IsLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by
simp [IsLimit, IsSuccLimit]
theorem IsLimit.isSuccPrelimit {o} (h : IsLimit o) : IsSuccPrelimit o :=
IsSuccLimit.isSuccPrelimit h
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
IsSuccLimit.succ_lt h
theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot
theorem not_zero_isLimit : ¬IsLimit 0 :=
not_isSuccLimit_bot
theorem not_succ_isLimit (o) : ¬IsLimit (succ o) :=
not_isSuccLimit_succ o
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
IsSuccLimit.succ_lt_iff h
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
@[simp]
theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o :=
liftInitialSeg.isSuccLimit_apply_iff
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
IsSuccLimit.bot_lt h
theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 :=
h.pos.ne'
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.succ_lt h.pos
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.succ_lt (IsLimit.nat_lt h n)
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by
simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o
theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) :
IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h
-- TODO: this is an iff with `IsSuccPrelimit`
theorem IsLimit.sSup_Iio {o : Ordinal} (h : IsLimit o) : sSup (Iio o) = o := by
apply (csSup_le' (fun a ha ↦ le_of_lt ha)).antisymm
apply le_of_forall_lt
intro a ha
exact (lt_succ a).trans_le (le_csSup bddAbove_Iio (h.succ_lt ha))
theorem IsLimit.iSup_Iio {o : Ordinal} (h : IsLimit o) : ⨆ a : Iio o, a.1 = o := by
rw [← sSup_eq_iSup', h.sSup_Iio]
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal)
(zero : motive 0) (succ : ∀ o, motive o → motive (succ o))
(isLimit : ∀ o, IsLimit o → (∀ o' < o, motive o') → motive o) : motive o := by
refine SuccOrder.limitRecOn o (fun a ha ↦ ?_) (fun a _ ↦ succ a) isLimit
convert zero
simpa using ha
@[simp]
theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ :=
SuccOrder.limitRecOn_isMin _ _ _ isMin_bot
@[simp]
theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) :
@limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) :=
SuccOrder.limitRecOn_succ ..
@[simp]
theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) :
@limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ :=
SuccOrder.limitRecOn_of_isSuccLimit ..
/-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l`
added to all cases. The final term's domain is the ordinals below `l`. -/
@[elab_as_elim]
def boundedLimitRecOn {l : Ordinal} (lLim : l.IsLimit) {motive : Iio l → Sort*} (o : Iio l)
(zero : motive ⟨0, lLim.pos⟩)
(succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩)
(isLimit : (o : Iio l) → IsLimit o → (Π o' < o, motive o') → motive o) : motive o :=
limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero)
(fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h)
(fun _o ho ih _ ↦ isLimit _ ho fun _o' h ↦ ih _ h _) o.2
@[simp]
theorem boundedLimitRec_zero {l} (lLim : l.IsLimit) {motive} (H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨0, lLim.pos⟩ H₁ H₂ H₃ = H₁ := by
rw [boundedLimitRecOn, limitRecOn_zero]
@[simp]
theorem boundedLimitRec_succ {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o
(@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_succ]
rfl
theorem boundedLimitRec_limit {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃ oLim) :
@boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦
@boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_limit]
rfl
instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
theorem enum_succ_eq_top {o : Ordinal} :
enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ :=
rfl
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩
convert enum_lt_enum.mpr _
· rw [enum_typein]
· rw [Subtype.mk_lt_mk, lt_succ_iff]
theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType :=
⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r, Subtype.mk_lt_mk]
apply lt_succ
@[simp]
theorem typein_ordinal (o : Ordinal.{u}) :
@typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm
theorem mk_Iio_ordinal (o : Ordinal.{u}) :
#(Iio o) = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← typein_ordinal]
rfl
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.succ_lt h))
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f :=
H.strictMono.id_le
theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a :=
H.strictMono.le_apply
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
H.le_apply.le_iff_eq
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
induction b using limitRecOn with
| zero =>
obtain ⟨x, px⟩ := p0
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| succ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| isLimit S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (ho : IsLimit o) : IsLimit (f o) := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
use (H.lt_iff.2 ho.pos).ne_bot
intro a ha
obtain ⟨b, hb, hab⟩ := (H.limit_lt ho).1 ha
rw [← succ_le_iff] at hab
apply hab.trans_lt
rwa [H.lt_iff]
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) :
a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h _ l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ ⟨_, l⟩) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; rcases enum _ ⟨_, l⟩ with x | x <;> intro this
· cases this (enum s ⟨0, h.pos⟩)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
theorem isLimit_add (a) {b} : IsLimit b → IsLimit (a + b) :=
(isNormal_add_right a).isLimit
alias IsLimit.add := isLimit_add
/-! ### Subtraction on ordinals -/
/-- The set in the definition of subtraction is nonempty. -/
private theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by
simpa using Ordinal.sub_eq_zero_iff_le.not
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by
rw [← add_le_add_iff_left b]
exact h.trans (le_add_sub a b)
theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by
obtain hab | hba := lt_or_le a b
· rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le]
· rwa [sub_lt_of_le hba]
theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by
use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩
rintro ⟨d, hd, ha⟩
exact ha.trans_lt (add_lt_add_left hd b)
theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by
simpa using (lt_add_iff hb).not
@[deprecated add_le_iff (since := "2024-12-08")]
theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) :
a + b ≤ c :=
(add_le_iff hb.ne').2 h
theorem isLimit_sub {a b} (ha : IsLimit a) (h : b < a) : IsLimit (a - b) := by
rw [isLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt]
refine ⟨h, fun c hc ↦ ?_⟩
rw [lt_sub] at hc ⊢
rw [add_succ]
exact ha.succ_lt hc
/-! ### Multiplication of ordinals -/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, _⟩ ⟨β, s, _⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨_, _, _⟩ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or]
simp only [eq_self_iff_true, true_and]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false, or_false]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr,
sumProdDistrib_apply_left, sumProdDistrib_apply_right, reduceCtorEq] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or, false_and, false_or]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
instance mulLeftMono : MulLeftMono Ordinal.{u} :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
instance mulRightMono : MulRightMono Ordinal.{u} :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ ⟨_, l⟩) by
obtain ⟨b, a⟩ := enum _ ⟨_, l⟩
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
obtain ⟨-, -, h⟩ | ⟨-, h⟩ := h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
obtain ⟨-, -, h⟩ | ⟨e, h⟩ := h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and, false_or,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and] at h ⊢
obtain ⟨-, -, h₂_h⟩ | e₂ := h₂ <;> [exact asymm h h₂_h; exact e₂ rfl]
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h _ l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
theorem isNormal_mul_right {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun _ l _ => mul_le_of_limit l⟩
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(isNormal_mul_right a0).lt_iff
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(isNormal_mul_right a0).le_iff
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(isNormal_mul_right a0).inj
theorem isLimit_mul {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(isNormal_mul_right a0).isLimit
theorem isLimit_mul_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact isLimit_add _ l
· exact isLimit_mul l.pos lb
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
private theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c)
(IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c :=
le_antisymm
((mul_le_of_limit l).2 fun c' h => by
apply (mul_le_mul_left' (le_succ c') _).trans
rw [IH _ h]
apply (add_le_add_left _ _).trans
· rw [← mul_succ]
exact mul_le_mul_left' (succ_le_of_lt <| l.succ_lt h) _
· rw [← ba]
exact le_add_right _ _)
(mul_le_mul_right' (le_add_right _ _) _)
theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by
induction c using limitRecOn with
| zero => simp only [succ_zero, mul_one]
| succ c IH =>
rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ]
| isLimit c l IH =>
rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc]
theorem add_mul_limit {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) : (a + b) * c = a * c :=
add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
private theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
private theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| zero => simp only [mul_zero, Ordinal.zero_le]
| succ _ _ => rw [succ_le_iff, lt_div c0]
| isLimit _ h₁ h₂ =>
revert h₁ h₂
simp +contextual only [mul_le_of_limit, limit_le, forall_true_iff]
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
theorem div_le_left {a b : Ordinal} (h : a ≤ b) (c : Ordinal) : a / c ≤ b / c := by
obtain rfl | hc := eq_or_ne c 0
· rw [div_zero, div_zero]
· rw [le_div hc]
exact (mul_div_le a c).trans h
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
theorem mul_add_div_mul {a c : Ordinal} (hc : c < a) (b d : Ordinal) :
(a * b + c) / (a * d) = b / d := by
have ha : a ≠ 0 := ((Ordinal.zero_le c).trans_lt hc).ne'
obtain rfl | hd := eq_or_ne d 0
· rw [mul_zero, div_zero, div_zero]
· have H := mul_ne_zero ha hd
apply le_antisymm
· rw [← lt_succ_iff, div_lt H, mul_assoc]
· apply (add_lt_add_left hc _).trans_le
rw [← mul_succ]
apply mul_le_mul_left'
rw [succ_le_iff]
exact lt_mul_succ_div b hd
· rw [le_div H, mul_assoc]
exact (mul_le_mul_left' (mul_div_le b d) a).trans (le_add_right _ c)
theorem mul_div_mul_cancel {a : Ordinal} (ha : a ≠ 0) (b c) : a * b / (a * c) = b / c := by
convert mul_add_div_mul (Ordinal.pos_iff_ne_zero.2 ha) b c using 1
rw [add_zero]
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply isLimit_sub h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact isLimit_add a h
· simpa only [add_zero]
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
theorem mul_add_mod_mul {w x : Ordinal} (hw : w < x) (y z : Ordinal) :
(x * y + w) % (x * z) = x * (y % z) + w := by
rw [mod_def, mul_add_div_mul hw]
apply sub_eq_of_add_eq
rw [← add_assoc, mul_assoc, ← mul_add, div_add_mod]
theorem mul_mod_mul (x y z : Ordinal) : (x * y) % (x * z) = x * (y % z) := by
obtain rfl | hx := Ordinal.eq_zero_or_pos x
· simp
· convert mul_add_mod_mul hx y z using 1 <;>
rw [add_zero]
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
/-! ### Casting naturals into ordinals, compatibility with operations -/
instance instCharZero : CharZero Ordinal := by
refine ⟨fun a b h ↦ ?_⟩
rwa [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_inj, Nat.cast_inj] at h
@[simp]
theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by
rw [← Nat.cast_one, ← Nat.cast_add, add_comm]
rfl
@[simp]
theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] :
1 + (ofNat(m) : Ordinal) = Order.succ (OfNat.ofNat m : Ordinal) :=
one_add_natCast m
@[simp, norm_cast]
theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n
| 0 => by simp
| n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one]
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by
rcases le_total m n with h | h
· rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (Nat.cast_le.2 h), Nat.cast_zero]
· rw [← add_left_cancel_iff (a := ↑n), ← Nat.cast_add, add_tsub_cancel_of_le h,
Ordinal.add_sub_cancel_of_le (Nat.cast_le.2 h)]
@[simp, norm_cast]
theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· have hn' : (n : Ordinal) ≠ 0 := Nat.cast_ne_zero.2 hn
apply le_antisymm
· rw [le_div hn', ← natCast_mul, Nat.cast_le, mul_comm]
apply Nat.div_mul_le_self
· rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, Nat.cast_lt, mul_comm,
← Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)]
apply Nat.lt_succ_self
@[simp, norm_cast]
theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by
rw [← add_left_cancel_iff, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add,
Nat.div_add_mod]
@[simp]
theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n
| 0 => by simp
| n + 1 => by simp [lift_natCast n]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u, v} ofNat(n) = OfNat.ofNat n :=
lift_natCast n
theorem lt_omega0 {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by
simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat]
theorem nat_lt_omega0 (n : ℕ) : ↑n < ω :=
lt_omega0.2 ⟨_, rfl⟩
theorem eq_nat_or_omega0_le (o : Ordinal) : (∃ n : ℕ, o = n) ∨ ω ≤ o := by
obtain ho | ho := lt_or_le o ω
· exact Or.inl <| lt_omega0.1 ho
· exact Or.inr ho
theorem omega0_pos : 0 < ω :=
nat_lt_omega0 0
theorem omega0_ne_zero : ω ≠ 0 :=
omega0_pos.ne'
theorem one_lt_omega0 : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega0 1
theorem isLimit_omega0 : IsLimit ω := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
refine ⟨omega0_ne_zero, fun o h => ?_⟩
obtain ⟨n, rfl⟩ := lt_omega0.1 h
exact nat_lt_omega0 (n + 1)
theorem omega0_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o :=
⟨fun h n => (nat_lt_omega0 _).le.trans h, fun H =>
le_of_forall_lt fun a h => by
let ⟨n, e⟩ := lt_omega0.1 h
rw [e, ← succ_le_iff]; exact H (n + 1)⟩
theorem nat_lt_limit {o} (h : IsLimit o) : ∀ n : ℕ, ↑n < o
| 0 => h.pos
| n + 1 => h.succ_lt (nat_lt_limit h n)
theorem omega0_le_of_isLimit {o} (h : IsLimit o) : ω ≤ o :=
omega0_le.2 fun n => le_of_lt <| nat_lt_limit h n
theorem natCast_add_omega0 (n : ℕ) : n + ω = ω := by
refine le_antisymm (le_of_forall_lt fun a ha ↦ ?_) (le_add_left _ _)
obtain ⟨b, hb', hb⟩ := (lt_add_iff omega0_ne_zero).1 ha
obtain ⟨m, rfl⟩ := lt_omega0.1 hb'
apply hb.trans_lt
exact_mod_cast nat_lt_omega0 (n + m)
theorem one_add_omega0 : 1 + ω = ω :=
mod_cast natCast_add_omega0 1
theorem add_omega0 {a : Ordinal} (h : a < ω) : a + ω = ω := by
obtain ⟨n, rfl⟩ := lt_omega0.1 h
exact natCast_add_omega0 n
@[simp]
theorem natCast_add_of_omega0_le {o} (h : ω ≤ o) (n : ℕ) : n + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, natCast_add_omega0]
@[simp]
theorem one_add_of_omega0_le {o} (h : ω ≤ o) : 1 + o = o :=
mod_cast natCast_add_of_omega0_le h 1
open Ordinal
theorem isLimit_iff_omega0_dvd {a : Ordinal} : IsLimit a ↔ a ≠ 0 ∧ ω ∣ a := by
refine ⟨fun l => ⟨l.ne_zero, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩
· refine (limit_le l).2 fun x hx => le_of_lt ?_
rw [← div_lt omega0_ne_zero, ← succ_le_iff, le_div omega0_ne_zero, mul_succ,
add_le_of_limit isLimit_omega0]
intro b hb
rcases lt_omega0.1 hb with ⟨n, rfl⟩
exact
(add_le_add_right (mul_div_le _ _) _).trans
(lt_sub.1 <| nat_lt_limit (isLimit_sub l hx) _).le
· rcases h with ⟨a0, b, rfl⟩
refine isLimit_mul_left isLimit_omega0 (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0)
intro e
simp only [e, mul_zero]
@[simp]
theorem natCast_mod_omega0 (n : ℕ) : n % ω = n :=
mod_eq_of_lt (nat_lt_omega0 n)
end Ordinal
namespace Cardinal
open Ordinal
@[simp]
theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by
rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega0_le]
rwa [← ord_aleph0, ord_le_ord]
theorem isLimit_ord {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact Ordinal.isLimit_omega0
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.toType :=
toType_noMax_of_succ_lt fun _ ↦ (isLimit_ord h).succ_lt
end Cardinal
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 2,201 | 2,204 | |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory.Shift
import Mathlib.Algebra.Homology.TotalComplex
/-!
# Behaviour of the total complex with respect to shifts
There are two ways to shift objects in `HomologicalComplex₂ C (up ℤ) (up ℤ)`:
* by shifting the first indices (and changing signs of horizontal differentials),
which corresponds to the shift by `ℤ` on `CochainComplex (CochainComplex C ℤ) ℤ`.
* by shifting the second indices (and changing signs of vertical differentials).
These two sorts of shift functors shall be abbreviated as
`HomologicalComplex₂.shiftFunctor₁ C x` and
`HomologicalComplex₂.shiftFunctor₂ C y`.
In this file, for any `K : HomologicalComplex₂ C (up ℤ) (up ℤ)`, we define an isomorphism
`K.totalShift₁Iso x : ((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧`
for any `x : ℤ` (which does not involve signs) and an isomorphism
`K.totalShift₂Iso y : ((shiftFunctor₂ C y).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦y⟧`
for any `y : ℤ` (which is given by the multiplication by `(p * y).negOnePow` on the
summand in bidegree `(p, q)` of `K`).
Depending on the order of the "composition" of the two isomorphisms
`totalShift₁Iso` and `totalShift₂Iso`, we get
two ways to identify `((shiftFunctor₁ C x).obj ((shiftFunctor₂ C y).obj K)).total (up ℤ)`
and `(K.total (up ℤ))⟦x + y⟧`. The lemma `totalShift₁Iso_trans_totalShift₂Iso` shows that
these two compositions of isomorphisms differ by the sign `(x * y).negOnePow`.
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category ComplexShape Limits
namespace HomologicalComplex₂
variable (C : Type*) [Category C] [Preadditive C]
/-- The shift on bicomplexes obtained by shifting the first indices (and changing the
sign of differentials). -/
abbrev shiftFunctor₁ (x : ℤ) :
HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) :=
shiftFunctor _ x
/-- The shift on bicomplexes obtained by shifting the second indices (and changing the
sign of differentials). -/
abbrev shiftFunctor₂ (y : ℤ) :
HomologicalComplex₂ C (up ℤ) (up ℤ) ⥤ HomologicalComplex₂ C (up ℤ) (up ℤ) :=
(shiftFunctor _ y).mapHomologicalComplex _
variable {C}
variable (K L : HomologicalComplex₂ C (up ℤ) (up ℤ)) (f : K ⟶ L)
/-- The isomorphism `(((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b` when `a' = a + x`. -/
def shiftFunctor₁XXIso (a x a' : ℤ) (h : a' = a + x) (b : ℤ) :
(((shiftFunctor₁ C x).obj K).X a).X b ≅ (K.X a').X b := eqToIso (by subst h; rfl)
/-- The isomorphism `(((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b'` when `b' = b + y`. -/
def shiftFunctor₂XXIso (a b y b' : ℤ) (h : b' = b + y) :
(((shiftFunctor₂ C y).obj K).X a).X b ≅ (K.X a).X b' := eqToIso (by subst h; rfl)
@[simp]
lemma shiftFunctor₁XXIso_refl (a b x : ℤ) :
K.shiftFunctor₁XXIso a x (a + x) rfl b = Iso.refl _ := rfl
@[simp]
lemma shiftFunctor₂XXIso_refl (a b y : ℤ) :
K.shiftFunctor₂XXIso a b y (b + y) rfl = Iso.refl _ := rfl
variable (x y : ℤ) [K.HasTotal (up ℤ)]
instance : ((shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := fun n =>
hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + x)) _
{ toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a + x, b⟩, by
simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢
omega⟩
invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a - x, b), by
simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢
omega⟩
left_inv := by
rintro ⟨⟨a, b⟩, h⟩
ext
· dsimp
omega
· rfl
right_inv := by
intro ⟨⟨a, b⟩, h⟩
ext
· dsimp
omega
· rfl }
(fun _ => Iso.refl _)
instance : ((shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := fun n =>
hasCoproduct_of_equiv_of_iso (K.toGradedObject.mapObjFun (π (up ℤ) (up ℤ) (up ℤ)) (n + y)) _
{ toFun := fun ⟨⟨a, b⟩, h⟩ => ⟨⟨a, b + y⟩, by
simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢
omega⟩
invFun := fun ⟨⟨a, b⟩, h⟩ => ⟨(a, b - y), by
simp only [Set.mem_preimage, instTotalComplexShape_π, Set.mem_singleton_iff] at h ⊢
omega⟩
left_inv _ := by simp
right_inv _ := by simp }
(fun _ => Iso.refl _)
instance : ((shiftFunctor₂ C y ⋙ shiftFunctor₁ C x).obj K).HasTotal (up ℤ) := by
dsimp
infer_instance
instance : ((shiftFunctor₁ C x ⋙ shiftFunctor₂ C y).obj K).HasTotal (up ℤ) := by
dsimp
infer_instance
/-- Auxiliary definition for `totalShift₁Iso`. -/
noncomputable def totalShift₁XIso (n n' : ℤ) (h : n + x = n') :
(((shiftFunctor₁ C x).obj K).total (up ℤ)).X n ≅ (K.total (up ℤ)).X n' where
hom := totalDesc _ (fun p q hpq => K.ιTotal (up ℤ) (p + x) q n' (by dsimp at hpq ⊢; omega))
inv := totalDesc _ (fun p q hpq =>
(K.XXIsoOfEq _ _ _ (Int.sub_add_cancel p x) rfl).inv ≫
((shiftFunctor₁ C x).obj K).ιTotal (up ℤ) (p - x) q n
(by dsimp at hpq ⊢; omega))
hom_inv_id := by
ext p q h
dsimp
simp only [ι_totalDesc_assoc, CochainComplex.shiftFunctor_obj_X', ι_totalDesc, comp_id]
exact ((shiftFunctor₁ C x).obj K).XXIsoOfEq_inv_ιTotal _ (by omega) rfl _ _
inv_hom_id := by
ext
dsimp
simp only [ι_totalDesc_assoc, Category.assoc, ι_totalDesc, XXIsoOfEq_inv_ιTotal, comp_id]
@[reassoc]
lemma D₁_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') :
((shiftFunctor₁ C x).obj K).D₁ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom =
x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₁ (up ℤ) n₀' n₁') := by
by_cases h : (up ℤ).Rel n₀ n₁
· apply total.hom_ext
intro p q hpq
dsimp at h hpq
dsimp [totalShift₁XIso]
rw [ι_D₁_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₁,
((shiftFunctor₁ C x).obj K).d₁_eq _ rfl _ _ (by dsimp; omega),
K.d₁_eq _ (show p + x + 1 = p + 1 + x by omega) _ _ (by dsimp; omega)]
dsimp
rw [one_smul, Category.assoc, ι_totalDesc, one_smul, Linear.units_smul_comp]
· rw [D₁_shape _ _ _ _ h, zero_comp, D₁_shape, comp_zero, smul_zero]
intro h'
apply h
dsimp at h' ⊢
omega
@[reassoc]
lemma D₂_totalShift₁XIso_hom (n₀ n₁ n₀' n₁' : ℤ) (h₀ : n₀ + x = n₀') (h₁ : n₁ + x = n₁') :
((shiftFunctor₁ C x).obj K).D₂ (up ℤ) n₀ n₁ ≫ (K.totalShift₁XIso x n₁ n₁' h₁).hom =
x.negOnePow • ((K.totalShift₁XIso x n₀ n₀' h₀).hom ≫ K.D₂ (up ℤ) n₀' n₁') := by
| by_cases h : (up ℤ).Rel n₀ n₁
· apply total.hom_ext
intro p q hpq
dsimp at h hpq
dsimp [totalShift₁XIso]
rw [ι_D₂_assoc, Linear.comp_units_smul, ι_totalDesc_assoc, ι_D₂,
((shiftFunctor₁ C x).obj K).d₂_eq _ _ rfl _ (by dsimp; omega),
K.d₂_eq _ _ rfl _ (by dsimp; omega), smul_smul,
Linear.units_smul_comp, Category.assoc, ι_totalDesc]
dsimp
congr 1
rw [add_comm p, Int.negOnePow_add, ← mul_assoc, Int.units_mul_self, one_mul]
· rw [D₂_shape _ _ _ _ h, zero_comp, D₂_shape, comp_zero, smul_zero]
intro h'
apply h
dsimp at h' ⊢
omega
/-- The isomorphism `((shiftFunctor₁ C x).obj K).total (up ℤ) ≅ (K.total (up ℤ))⟦x⟧`
expressing the compatibility of the total complex with the shift on the first indices.
This isomorphism does not involve signs. -/
| Mathlib/Algebra/Homology/TotalComplexShift.lean | 161 | 181 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-!
# Integral average of a function
In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average
value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it
is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability
measure, then the average of any function is equal to its integral.
For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For
average w.r.t. the volume, one can omit `∂volume`.
Both have a version for the Lebesgue integral rather than Bochner.
We prove several version of the first moment method: An integrable function is below/above its
average on a set of positive measure:
* `measure_le_setLAverage_pos` for the Lebesgue integral
* `measure_le_setAverage_pos` for the Bochner integral
## Implementation notes
The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner
integrals work for the average without modifications. For theorems that require integrability of a
function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`.
## Tags
integral, center mass, average value
-/
open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function
open scoped Topology ENNReal Convex
variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α}
{s t : Set α}
/-!
### Average value of a function w.r.t. a measure
The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation:
`⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total
measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if
`f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to
its integral.
-/
namespace MeasureTheory
section ENNReal
variable (μ) {f g : α → ℝ≥0∞}
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure.
It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite
measure. In a probability space, the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s`
has measure `1`, then the average of any function is equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If
`s` has measure `1`, then the average of any function is equal to its integral. -/
notation3 (prettyPrint := false)
"⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r
@[simp]
theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero]
@[simp]
theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage]
theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl
theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by
rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul]
theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) :
⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero]
· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq
theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [laverage_eq', restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq'
variable {μ}
theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by
simp only [laverage_eq, lintegral_congr_ae h]
theorem setLAverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by
simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr
theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by
simp only [laverage_eq, setLIntegral_congr_fun hs h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun
theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq]
exact div_lt_top hf (measure_univ_ne_zero.2 hμ)
theorem setLAverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ :=
laverage_lt_top
@[deprecated (since := "2025-04-22")] alias setLaverage_lt_top := setLAverage_lt_top
theorem laverage_add_measure :
⨍⁻ x, f x ∂(μ + ν) =
μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by
by_cases hμ : IsFiniteMeasure μ; swap
· rw [not_isFiniteMeasure_iff] at hμ
simp [laverage_eq, hμ]
by_cases hν : IsFiniteMeasure ν; swap
· rw [not_isFiniteMeasure_iff] at hν
simp [laverage_eq, hν]
haveI := hμ; haveI := hν
simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div,
← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq]
theorem measure_mul_setLAverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) :
μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by
have := Fact.mk h.lt_top
rw [← measure_mul_laverage, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias measure_mul_setLaverage := measure_mul_setLAverage
theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
⨍⁻ x in s ∪ t, f x ∂μ =
μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by
rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ]
theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by
refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩,
ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by
by_cases hs₀ : μ s = 0
· rw [← ae_eq_empty] at hs₀
rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union]
exact right_mem_segment _ _ _
· refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_mem_openSegment_compl_self [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ)
(hs₀ : μ s ≠ 0) (hsc₀ : μ sᶜ ≠ 0) :
⨍⁻ x, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in sᶜ, f x ∂μ) := by
simpa only [union_compl_self, restrict_univ] using
laverage_union_mem_openSegment aedisjoint_compl_right hs.compl hs₀ hsc₀ (measure_ne_top _ _)
(measure_ne_top _ _)
@[simp]
theorem laverage_const (μ : Measure α) [IsFiniteMeasure μ] [h : NeZero μ] (c : ℝ≥0∞) :
⨍⁻ _x, c ∂μ = c := by
simp only [laverage, lintegral_const, measure_univ, mul_one]
theorem setLAverage_const (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) (c : ℝ≥0∞) : ⨍⁻ _x in s, c ∂μ = c := by
simp only [setLAverage_eq, lintegral_const, Measure.restrict_apply, MeasurableSet.univ,
univ_inter, div_eq_mul_inv, mul_assoc, ENNReal.mul_inv_cancel hs₀ hs, mul_one]
@[deprecated (since := "2025-04-22")] alias setLaverage_const := setLAverage_const
theorem laverage_one [IsFiniteMeasure μ] [NeZero μ] : ⨍⁻ _x, (1 : ℝ≥0∞) ∂μ = 1 :=
laverage_const _ _
| theorem setLAverage_one (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : ⨍⁻ _x in s, (1 : ℝ≥0∞) ∂μ = 1 :=
setLAverage_const hs₀ hs _
| Mathlib/MeasureTheory/Integral/Average.lean | 227 | 229 |
/-
Copyright (c) 2024 Emilie Burgun. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Emilie Burgun
-/
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Dynamics.PeriodicPts.Defs
import Mathlib.GroupTheory.GroupAction.Defs
/-!
# Properties of `fixedPoints` and `fixedBy`
This module contains some useful properties of `MulAction.fixedPoints` and `MulAction.fixedBy`
that don't directly belong to `Mathlib.GroupTheory.GroupAction.Basic`.
## Main theorems
* `MulAction.fixedBy_mul`: `fixedBy α (g * h) ⊆ fixedBy α g ∪ fixedBy α h`
* `MulAction.fixedBy_conj` and `MulAction.smul_fixedBy`: the pointwise group action of `h` on
`fixedBy α g` is equal to the `fixedBy` set of the conjugation of `h` with `g`
(`fixedBy α (h * g * h⁻¹)`).
* `MulAction.set_mem_fixedBy_of_movedBy_subset` shows that if a set `s` is a superset of
`(fixedBy α g)ᶜ`, then the group action of `g` cannot send elements of `s` outside of `s`.
This is expressed as `s ∈ fixedBy (Set α) g`, and `MulAction.set_mem_fixedBy_iff` allows one
to convert the relationship back to `g • x ∈ s ↔ x ∈ s`.
* `MulAction.not_commute_of_disjoint_smul_movedBy` allows one to prove that `g` and `h`
do not commute from the disjointness of the `(fixedBy α g)ᶜ` set and `h • (fixedBy α g)ᶜ`,
which is a property used in the proof of Rubin's theorem.
The theorems above are also available for `AddAction`.
## Pointwise group action and `fixedBy (Set α) g`
Since `fixedBy α g = { x | g • x = x }` by definition, properties about the pointwise action of
a set `s : Set α` can be expressed using `fixedBy (Set α) g`.
To properly use theorems using `fixedBy (Set α) g`, you should `open Pointwise` in your file.
`s ∈ fixedBy (Set α) g` means that `g • s = s`, which is equivalent to say that
`∀ x, g • x ∈ s ↔ x ∈ s` (the translation can be done using `MulAction.set_mem_fixedBy_iff`).
`s ∈ fixedBy (Set α) g` is a weaker statement than `s ⊆ fixedBy α g`: the latter requires that
all points in `s` are fixed by `g`, whereas the former only requires that `g • x ∈ s`.
-/
namespace MulAction
open Pointwise
variable {α : Type*}
variable {G : Type*} [Group G] [MulAction G α]
variable {M : Type*} [Monoid M] [MulAction M α]
section FixedPoints
variable (α) in
/-- In a multiplicative group action, the points fixed by `g` are also fixed by `g⁻¹` -/
@[to_additive (attr := simp)
"In an additive group action, the points fixed by `g` are also fixed by `g⁻¹`"]
theorem fixedBy_inv (g : G) : fixedBy α g⁻¹ = fixedBy α g := by
ext
rw [mem_fixedBy, mem_fixedBy, inv_smul_eq_iff, eq_comm]
@[to_additive]
theorem smul_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} :
g • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by
rw [mem_fixedBy, smul_left_cancel_iff]
rfl
@[to_additive]
theorem smul_inv_mem_fixedBy_iff_mem_fixedBy {a : α} {g : G} :
g⁻¹ • a ∈ fixedBy α g ↔ a ∈ fixedBy α g := by
rw [← fixedBy_inv, smul_mem_fixedBy_iff_mem_fixedBy, fixedBy_inv]
@[to_additive minimalPeriod_eq_one_iff_fixedBy]
theorem minimalPeriod_eq_one_iff_fixedBy {a : α} {g : G} :
Function.minimalPeriod (fun x => g • x) a = 1 ↔ a ∈ fixedBy α g :=
Function.minimalPeriod_eq_one_iff_isFixedPt
variable (α) in
@[to_additive]
theorem fixedBy_subset_fixedBy_zpow (g : G) (j : ℤ) :
fixedBy α g ⊆ fixedBy α (g ^ j) := by
intro a a_in_fixedBy
rw [mem_fixedBy, zpow_smul_eq_iff_minimalPeriod_dvd,
minimalPeriod_eq_one_iff_fixedBy.mpr a_in_fixedBy, Int.natCast_one]
exact one_dvd j
variable (M α) in
@[to_additive (attr := simp)]
theorem fixedBy_one_eq_univ : fixedBy α (1 : M) = Set.univ :=
Set.eq_univ_iff_forall.mpr <| one_smul M
variable (α) in
@[to_additive]
theorem fixedBy_mul (m₁ m₂ : M) : fixedBy α m₁ ∩ fixedBy α m₂ ⊆ fixedBy α (m₁ * m₂) := by
intro a ⟨h₁, h₂⟩
rw [mem_fixedBy, mul_smul, h₂, h₁]
variable (α) in
@[to_additive]
theorem smul_fixedBy (g h : G) :
h • fixedBy α g = fixedBy α (h * g * h⁻¹) := by
ext a
simp_rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, mul_smul, smul_eq_iff_eq_inv_smul h]
end FixedPoints
section Pointwise
/-!
### `fixedBy` sets of the pointwise group action
The theorems below need the `Pointwise` scoped to be opened (using `open Pointwise`)
to be used effectively.
-/
/--
If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in `s` after being
moved by `g`.
-/
@[to_additive "If a set `s : Set α` is in `fixedBy (Set α) g`, then all points of `s` will stay in
`s` after being moved by `g`."]
theorem set_mem_fixedBy_iff (s : Set α) (g : G) :
s ∈ fixedBy (Set α) g ↔ ∀ x, g • x ∈ s ↔ x ∈ s := by
simp_rw [mem_fixedBy, ← eq_inv_smul_iff, Set.ext_iff, Set.mem_inv_smul_set_iff, Iff.comm]
@[to_additive]
theorem smul_mem_of_set_mem_fixedBy {s : Set α} {g : G} (s_in_fixedBy : s ∈ fixedBy (Set α) g)
{x : α} : g • x ∈ s ↔ x ∈ s := (set_mem_fixedBy_iff s g).mp s_in_fixedBy x
/--
If `s ⊆ fixedBy α g`, then `g • s = s`, which means that `s ∈ fixedBy (Set α) g`.
Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a
weaker statement (it allows for points `x ∈ s` for which `g • x ≠ x` and `g • x ∈ s`).
-/
@[to_additive "If `s ⊆ fixedBy α g`, then `g +ᵥ s = s`, which means that `s ∈ fixedBy (Set α) g`.
Note that the reverse implication is in general not true, as `s ∈ fixedBy (Set α) g` is a
weaker statement (it allows for points `x ∈ s` for which `g +ᵥ x ≠ x` and `g +ᵥ x ∈ s`)."]
theorem set_mem_fixedBy_of_subset_fixedBy {s : Set α} {g : G} (s_ss_fixedBy : s ⊆ fixedBy α g) :
s ∈ fixedBy (Set α) g := by
rw [← fixedBy_inv]
ext x
rw [Set.mem_inv_smul_set_iff]
refine ⟨fun gxs => ?xs, fun xs => (s_ss_fixedBy xs).symm ▸ xs⟩
rw [← fixedBy_inv] at s_ss_fixedBy
rwa [← s_ss_fixedBy gxs, inv_smul_smul] at gxs
theorem smul_subset_of_set_mem_fixedBy {s t : Set α} {g : G} (t_ss_s : t ⊆ s)
(s_in_fixedBy : s ∈ fixedBy (Set α) g) : g • t ⊆ s :=
(Set.smul_set_subset_smul_set_iff.mpr t_ss_s).trans s_in_fixedBy.subset
/-!
If a set `s : Set α` is a superset of `(MulAction.fixedBy α g)ᶜ` (resp. `(AddAction.fixedBy α g)ᶜ`),
then no point or subset of `s` can be moved outside of `s` by the group action of `g`.
-/
/-- If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`. -/
@[to_additive "If `(fixedBy α g)ᶜ ⊆ s`, then `g` cannot move a point of `s` outside of `s`."]
theorem set_mem_fixedBy_of_movedBy_subset {s : Set α} {g : G} (s_subset : (fixedBy α g)ᶜ ⊆ s) :
s ∈ fixedBy (Set α) g := by
rw [← fixedBy_inv]
ext a
rw [Set.mem_inv_smul_set_iff]
by_cases a ∈ fixedBy α g
case pos a_fixed =>
rw [a_fixed]
case neg a_moved =>
constructor <;> (intro; apply s_subset)
· exact a_moved
· rwa [Set.mem_compl_iff, smul_mem_fixedBy_iff_mem_fixedBy]
end Pointwise
section Commute
/-!
## Pointwise image of the `fixedBy` set by a commuting group element
If two group elements `g` and `h` commute, then `g` fixes `h • x` (resp. `h +ᵥ x`)
if and only if `g` fixes `x`.
This is equivalent to say that if `Commute g h`, then `fixedBy α g ∈ fixedBy (Set α) h` and
`(fixedBy α g)ᶜ ∈ fixedBy (Set α) h`.
-/
/--
If `g` and `h` commute, then `g` fixes `h • x` iff `g` fixes `x`.
This is equivalent to say that the set `fixedBy α g` is fixed by `h`.
-/
@[to_additive "If `g` and `h` commute, then `g` fixes `h +ᵥ x` iff `g` fixes `x`.
This is equivalent to say that the set `fixedBy α g` is fixed by `h`.
"]
theorem fixedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) :
(fixedBy α g) ∈ fixedBy (Set α) h := by
ext x
rw [Set.mem_smul_set_iff_inv_smul_mem, mem_fixedBy, ← mul_smul, comm.inv_right, mul_smul,
smul_left_cancel_iff, mem_fixedBy]
/--
If `g` and `h` commute, then `g` fixes `(h ^ j) • x` iff `g` fixes `x`.
-/
@[to_additive "If `g` and `h` commute, then `g` fixes `(j • h) +ᵥ x` iff `g` fixes `x`."]
theorem smul_zpow_fixedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) :
h ^ j • fixedBy α g = fixedBy α g :=
fixedBy_subset_fixedBy_zpow (Set α) h j (fixedBy_mem_fixedBy_of_commute comm)
/--
If `g` and `h` commute, then `g` moves `h • x` iff `g` moves `x`.
This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`.
-/
@[to_additive "If `g` and `h` commute, then `g` moves `h +ᵥ x` iff `g` moves `x`.
This is equivalent to say that the set `(fixedBy α g)ᶜ` is fixed by `h`."]
theorem movedBy_mem_fixedBy_of_commute {g h : G} (comm : Commute g h) :
(fixedBy α g)ᶜ ∈ fixedBy (Set α) h := by
rw [mem_fixedBy, Set.smul_set_compl, fixedBy_mem_fixedBy_of_commute comm]
/--
If `g` and `h` commute, then `g` moves `h ^ j • x` iff `g` moves `x`.
-/
@[to_additive "If `g` and `h` commute, then `g` moves `(j • h) +ᵥ x` iff `g` moves `x`."]
theorem smul_zpow_movedBy_eq_of_commute {g h : G} (comm : Commute g h) (j : ℤ) :
h ^ j • (fixedBy α g)ᶜ = (fixedBy α g)ᶜ :=
fixedBy_subset_fixedBy_zpow (Set α) h j (movedBy_mem_fixedBy_of_commute comm)
end Commute
section Faithful
variable [FaithfulSMul G α]
variable [FaithfulSMul M α]
/-- If the multiplicative action of `M` on `α` is faithful,
then `fixedBy α m = Set.univ` implies that `m = 1`. -/
@[to_additive "If the additive action of `M` on `α` is faithful,
| then `fixedBy α m = Set.univ` implies that `m = 1`."]
theorem fixedBy_eq_univ_iff_eq_one {m : M} : fixedBy α m = Set.univ ↔ m = 1 := by
rw [← (smul_left_injective' (M := M) (α := α)).eq_iff, Set.eq_univ_iff_forall]
| Mathlib/GroupTheory/GroupAction/FixedPoints.lean | 238 | 240 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Sean Leather
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.Pairwise
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Lookmap
import Mathlib.Data.Sigma.Basic
/-!
# Utilities for lists of sigmas
This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store.
If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value
`s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store.
## Main Definitions
- `List.keys` extracts the list of keys.
- `List.NodupKeys` determines if the store has duplicate keys.
- `List.lookup`/`lookup_all` accesses the value(s) of a particular key.
- `List.kreplace` replaces the first value with a given key by a given value.
- `List.kerase` removes a value.
- `List.kinsert` inserts a value.
- `List.kunion` computes the union of two stores.
- `List.kextract` returns a value with a given key and the rest of the values.
-/
universe u u' v v'
namespace List
variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)}
/-! ### `keys` -/
/-- List of keys from a list of key-value pairs -/
def keys : List (Sigma β) → List α :=
map Sigma.fst
@[simp]
theorem keys_nil : @keys α β [] = [] :=
rfl
@[simp]
theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys :=
rfl
theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys :=
mem_map_of_mem
theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ b : β a, Sigma.mk a b ∈ l :=
let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h
Eq.recOn e (Exists.intro b' m)
theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l :=
⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩
theorem not_mem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l :=
(not_congr mem_keys).trans not_exists
theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 :=
Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ =>
let ⟨_, h₂⟩ := exists_of_mem_keys h₁
f _ h₂ rfl
@[deprecated (since := "2025-04-27")]
alias not_eq_key := ne_key
/-! ### `NodupKeys` -/
/-- Determines whether the store uses a key several times. -/
def NodupKeys (l : List (Sigma β)) : Prop :=
l.keys.Nodup
theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
pairwise_map
theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) :
Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
nodupKeys_iff_pairwise.1 h
@[simp]
theorem nodupKeys_nil : @NodupKeys α β [] :=
Pairwise.nil
@[simp]
theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} :
NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys]
theorem not_mem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
s.1 ∉ l.keys :=
(nodupKeys_cons.1 h).1
theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
NodupKeys l :=
(nodupKeys_cons.1 h).2
theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l)
(h' : s' ∈ l) : s.1 = s'.1 → s = s' :=
@Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _
(fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl)
((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h'
theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by
cases nd.eq_of_fst_eq h h' rfl; rfl
theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] :=
nodup_singleton _
theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ :=
Nodup.sublist <| h.map _
protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l :=
Nodup.of_map _
theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ :=
(h.map _).nodup_iff
theorem nodupKeys_flatten {L : List (List (Sigma β))} :
NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by
rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map]
refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_
apply iff_of_eq; congr! with (l₁ l₂)
simp [keys, disjoint_iff_ne, Sigma.forall]
theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by
simp [List.nodup_range']
@[deprecated (since := "2025-01-28")] alias nodup_enum_map_fst := nodup_zipIdx_map_snd
theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup)
(h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ :=
(perm_ext_iff_of_nodup nd₀ nd₁).2 h
variable [DecidableEq α] [DecidableEq α']
/-! ### `dlookup` -/
/-- `dlookup a l` is the first value in `l` corresponding to the key `a`,
or `none` if no such element exists. -/
def dlookup (a : α) : List (Sigma β) → Option (β a)
| [] => none
| ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l
@[simp]
theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) :=
rfl
@[simp]
theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b :=
dif_pos rfl
@[simp]
theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simp [h, dlookup_isSome]
theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by
simp [← dlookup_isSome, Option.isNone_iff_eq_none]
theorem of_mem_dlookup {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l
| ⟨a', b'⟩ :: l, H => by
by_cases h : a = a'
· subst a'
simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H
simp [H]
· simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H
simp [of_mem_dlookup H]
theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) :
b ∈ dlookup a l := by
obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h))
cases nd.eq_of_mk_mem h (of_mem_dlookup h')
exact h'
theorem map_dlookup_eq_find (a : α) :
∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l
| [] => rfl
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simpa [h] using map_dlookup_eq_find a l
theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) :
b ∈ dlookup a l ↔ Sigma.mk a b ∈ l :=
⟨of_mem_dlookup, mem_dlookup nd⟩
theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by
ext b; simp only [mem_dlookup_iff nd₁, mem_dlookup_iff nd₂]; exact p.mem_iff
theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys)
(h : ∀ x y, y ∈ l₀.dlookup x ↔ y ∈ l₁.dlookup x) : l₀ ~ l₁ :=
mem_ext nd₀.nodup nd₁.nodup fun ⟨a, b⟩ => by
rw [← mem_dlookup_iff, ← mem_dlookup_iff, h] <;> assumption
theorem dlookup_map (l : List (Sigma β))
{f : α → α'} (hf : Function.Injective f) (g : ∀ a, β a → β' (f a)) (a : α) :
(l.map fun x => ⟨f x.1, g _ x.2⟩).dlookup (f a) = (l.dlookup a).map (g a) := by
induction' l with b l IH
· rw [map_nil, dlookup_nil, dlookup_nil, Option.map_none']
· rw [map_cons]
obtain rfl | h := eq_or_ne a b.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.map_some']
· rw [dlookup_cons_ne _ _ h, dlookup_cons_ne _ _ (fun he => h <| hf he), IH]
theorem dlookup_map₁ {β : Type v} (l : List (Σ _ : α, β))
{f : α → α'} (hf : Function.Injective f) (a : α) :
(l.map fun x => ⟨f x.1, x.2⟩ : List (Σ _ : α', β)).dlookup (f a) = l.dlookup a := by
rw [dlookup_map (β' := fun _ => β) l hf (fun _ x => x) a, Option.map_id']
theorem dlookup_map₂ {γ δ : α → Type*} {l : List (Σ a, γ a)} {f : ∀ a, γ a → δ a} (a : α) :
(l.map fun x => ⟨x.1, f _ x.2⟩ : List (Σ a, δ a)).dlookup a = (l.dlookup a).map (f a) :=
dlookup_map l Function.injective_id _ _
/-! ### `lookupAll` -/
/-- `lookup_all a l` is the list of all values in `l` corresponding to the key `a`. -/
def lookupAll (a : α) : List (Sigma β) → List (β a)
| [] => []
| ⟨a', b⟩ :: l => if h : a' = a then Eq.recOn h b :: lookupAll a l else lookupAll a l
@[simp]
theorem lookupAll_nil (a : α) : lookupAll a [] = @nil (β a) :=
rfl
@[simp]
theorem lookupAll_cons_eq (l) (a : α) (b : β a) : lookupAll a (⟨a, b⟩ :: l) = b :: lookupAll a l :=
dif_pos rfl
@[simp]
theorem lookupAll_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → lookupAll a (s :: l) = lookupAll a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem lookupAll_eq_nil {a : α} :
∀ {l : List (Sigma β)}, lookupAll a l = [] ↔ ∀ b : β a, Sigma.mk a b ∉ l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp only [lookupAll_cons_eq, mem_cons, Sigma.mk.inj_iff, heq_eq_eq, true_and, not_or,
false_iff, not_forall, not_and, not_not, reduceCtorEq]
use b
simp
· simp [h, lookupAll_eq_nil]
theorem head?_lookupAll (a : α) : ∀ l : List (Sigma β), head? (lookupAll a l) = dlookup a l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst h; simp
· rw [lookupAll_cons_ne, dlookup_cons_ne, head?_lookupAll a l] <;> assumption
theorem mem_lookupAll {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ lookupAll a l ↔ Sigma.mk a b ∈ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp [*, mem_lookupAll]
· simp [*, mem_lookupAll]
theorem lookupAll_sublist (a : α) : ∀ l : List (Sigma β), (lookupAll a l).map (Sigma.mk a) <+ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp only [ne_eq, not_true, lookupAll_cons_eq, List.map]
exact (lookupAll_sublist a l).cons₂ _
· simp only [ne_eq, h, not_false_iff, lookupAll_cons_ne]
exact (lookupAll_sublist a l).cons _
theorem lookupAll_length_le_one (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
length (lookupAll a l) ≤ 1 := by
have := Nodup.sublist ((lookupAll_sublist a l).map _) h
rw [map_map] at this
rwa [← nodup_replicate, ← map_const]
theorem lookupAll_eq_dlookup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
lookupAll a l = (dlookup a l).toList := by
rw [← head?_lookupAll]
have h1 := lookupAll_length_le_one a h; revert h1
rcases lookupAll a l with (_ | ⟨b, _ | ⟨c, l⟩⟩) <;> intro h1 <;> try rfl
exact absurd h1 (by simp)
theorem lookupAll_nodup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : (lookupAll a l).Nodup := by
(rw [lookupAll_eq_dlookup a h]; apply Option.toList_nodup)
theorem perm_lookupAll (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : lookupAll a l₁ = lookupAll a l₂ := by
simp [lookupAll_eq_dlookup, nd₁, nd₂, perm_dlookup a nd₁ nd₂ p]
theorem dlookup_append (l₁ l₂ : List (Sigma β)) (a : α) :
(l₁ ++ l₂).dlookup a = (l₁.dlookup a).or (l₂.dlookup a) := by
induction l₁ with
| nil => rfl
| cons x l₁ IH =>
rw [cons_append]
obtain rfl | hb := Decidable.eq_or_ne a x.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.or]
· rw [dlookup_cons_ne _ _ hb, dlookup_cons_ne _ _ hb, IH]
/-! ### `kreplace` -/
/-- Replaces the first value with key `a` by `b`. -/
def kreplace (a : α) (b : β a) : List (Sigma β) → List (Sigma β) :=
lookmap fun s => if a = s.1 then some ⟨a, b⟩ else none
theorem kreplace_of_forall_not (a : α) (b : β a) {l : List (Sigma β)}
(H : ∀ b : β a, Sigma.mk a b ∉ l) : kreplace a b l = l :=
lookmap_of_forall_not _ <| by
rintro ⟨a', b'⟩ h; dsimp; split_ifs
· subst a'
exact H _ h
· rfl
theorem kreplace_self {a : α} {b : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) : kreplace a b l = l := by
refine (lookmap_congr ?_).trans (lookmap_id' (Option.guard fun (s : Sigma β) => a = s.1) ?_ _)
· rintro ⟨a', b'⟩ h'
dsimp [Option.guard]
split_ifs
· subst a'
simp [nd.eq_of_mk_mem h h']
· rfl
· rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩
dsimp [Option.guard]
split_ifs
· simp
· rintro ⟨⟩
theorem keys_kreplace (a : α) (b : β a) : ∀ l : List (Sigma β), (kreplace a b l).keys = l.keys :=
lookmap_map_eq _ _ <| by
rintro ⟨a₁, b₂⟩ ⟨a₂, b₂⟩
dsimp
split_ifs with h <;> simp +contextual [h]
theorem kreplace_nodupKeys (a : α) (b : β a) {l : List (Sigma β)} :
(kreplace a b l).NodupKeys ↔ l.NodupKeys := by simp [NodupKeys, keys_kreplace]
theorem Perm.kreplace {a : α} {b : β a} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kreplace a b l₁ ~ kreplace a b l₂ :=
perm_lookmap _ <| by
refine nd.pairwise_ne.imp ?_
intro x y h z h₁ w h₂
split_ifs at h₁ h₂ with h_2 h_1 <;> cases h₁ <;> cases h₂
exact (h (h_2.symm.trans h_1)).elim
/-! ### `kerase` -/
/-- Remove the first pair with the key `a`. -/
def kerase (a : α) : List (Sigma β) → List (Sigma β) :=
eraseP fun s => a = s.1
@[simp]
theorem kerase_nil {a} : @kerase _ β _ a [] = [] :=
rfl
@[simp]
theorem kerase_cons_eq {a} {s : Sigma β} {l : List (Sigma β)} (h : a = s.1) :
kerase a (s :: l) = l := by simp [kerase, h]
@[simp]
theorem kerase_cons_ne {a} {s : Sigma β} {l : List (Sigma β)} (h : a ≠ s.1) :
kerase a (s :: l) = s :: kerase a l := by simp [kerase, h]
@[simp]
theorem kerase_of_not_mem_keys {a} {l : List (Sigma β)} (h : a ∉ l.keys) : kerase a l = l := by
induction l with
| nil => rfl
| cons _ _ ih => simp [not_or] at h; simp [h.1, ih h.2]
theorem kerase_sublist (a : α) (l : List (Sigma β)) : kerase a l <+ l :=
eraseP_sublist
theorem kerase_keys_subset (a) (l : List (Sigma β)) : (kerase a l).keys ⊆ l.keys :=
((kerase_sublist a l).map _).subset
theorem mem_keys_of_mem_keys_kerase {a₁ a₂} {l : List (Sigma β)} :
a₁ ∈ (kerase a₂ l).keys → a₁ ∈ l.keys :=
@kerase_keys_subset _ _ _ _ _ _
theorem exists_of_kerase {a : α} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ (b : β a) (l₁ l₂ : List (Sigma β)),
a ∉ l₁.keys ∧ l = l₁ ++ ⟨a, b⟩ :: l₂ ∧ kerase a l = l₁ ++ l₂ := by
induction l with
| nil => cases h
| cons hd tl ih =>
by_cases e : a = hd.1
· subst e
exact ⟨hd.2, [], tl, by simp, by cases hd; rfl, by simp⟩
· simp only [keys_cons, mem_cons] at h
rcases h with h | h
· exact absurd h e
rcases ih h with ⟨b, tl₁, tl₂, h₁, h₂, h₃⟩
exact ⟨b, hd :: tl₁, tl₂, not_mem_cons_of_ne_of_not_mem e h₁, by (rw [h₂]; rfl), by
simp [e, h₃]⟩
@[simp]
theorem mem_keys_kerase_of_ne {a₁ a₂} {l : List (Sigma β)} (h : a₁ ≠ a₂) :
a₁ ∈ (kerase a₂ l).keys ↔ a₁ ∈ l.keys :=
(Iff.intro mem_keys_of_mem_keys_kerase) fun p =>
if q : a₂ ∈ l.keys then
match l, kerase a₂ l, exists_of_kerase q, p with
| _, _, ⟨_, _, _, _, rfl, rfl⟩, p => by simpa [keys, h] using p
else by simp [q, p]
theorem keys_kerase {a} {l : List (Sigma β)} : (kerase a l).keys = l.keys.erase a := by
rw [keys, kerase, erase_eq_eraseP, eraseP_map, Function.comp_def]
congr
theorem kerase_kerase {a a'} {l : List (Sigma β)} :
(kerase a' l).kerase a = (kerase a l).kerase a' := by
by_cases h : a = a'
· subst a'; rfl
induction' l with x xs
· rfl
· by_cases a' = x.1
· subst a'
simp [kerase_cons_ne h, kerase_cons_eq rfl]
by_cases h' : a = x.1
· subst a
simp [kerase_cons_eq rfl, kerase_cons_ne (Ne.symm h)]
· simp [kerase_cons_ne, *]
theorem NodupKeys.kerase (a : α) : NodupKeys l → (kerase a l).NodupKeys :=
NodupKeys.sublist <| kerase_sublist _ _
theorem Perm.kerase {a : α} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kerase a l₁ ~ kerase a l₂ := by
apply Perm.eraseP
apply (nodupKeys_iff_pairwise.1 nd).imp
intros; simp_all
@[simp]
theorem not_mem_keys_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
a ∉ (kerase a l).keys := by
induction l with
| nil => simp
| cons hd tl ih =>
simp? at nd says simp only [nodupKeys_cons] at nd
by_cases h : a = hd.1
· subst h
simp [nd.1]
· simp [h, ih nd.2]
@[simp]
theorem dlookup_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
dlookup a (kerase a l) = none :=
dlookup_eq_none.mpr (not_mem_keys_kerase a nd)
@[simp]
theorem dlookup_kerase_ne {a a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kerase a' l) = dlookup a l := by
induction l with
| nil => rfl
| cons hd tl ih =>
obtain ⟨ah, bh⟩ := hd
by_cases h₁ : a = ah <;> by_cases h₂ : a' = ah
· substs h₁ h₂
cases Ne.irrefl h
· subst h₁
simp [h₂]
· subst h₂
simp [h]
· simp [h₁, h₂, ih]
theorem kerase_append_left {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∈ l₁.keys → kerase a (l₁ ++ l₂) = kerase a l₁ ++ l₂
| [], _, h => by cases h
| s :: l₁, l₂, h₁ => by
if h₂ : a = s.1 then simp [h₂]
else simp at h₁; rcases h₁ with h₁ | h₁ <;>
[exact absurd h₁ h₂; simp [h₂, kerase_append_left h₁]]
theorem kerase_append_right {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∉ l₁.keys → kerase a (l₁ ++ l₂) = l₁ ++ kerase a l₂
| [], _, _ => rfl
| _ :: l₁, l₂, h => by
simp only [keys_cons, mem_cons, not_or] at h
simp [h.1, kerase_append_right h.2]
theorem kerase_comm (a₁ a₂) (l : List (Sigma β)) :
kerase a₂ (kerase a₁ l) = kerase a₁ (kerase a₂ l) :=
if h : a₁ = a₂ then by simp [h]
else
if ha₁ : a₁ ∈ l.keys then
if ha₂ : a₂ ∈ l.keys then
match l, kerase a₁ l, exists_of_kerase ha₁, ha₂ with
| _, _, ⟨b₁, l₁, l₂, a₁_nin_l₁, rfl, rfl⟩, _ =>
if h' : a₂ ∈ l₁.keys then by
simp [kerase_append_left h',
kerase_append_right (mt (mem_keys_kerase_of_ne h).mp a₁_nin_l₁)]
else by
simp [kerase_append_right h', kerase_append_right a₁_nin_l₁,
@kerase_cons_ne _ _ _ a₂ ⟨a₁, b₁⟩ _ (Ne.symm h)]
else by simp [ha₂, mt mem_keys_of_mem_keys_kerase ha₂]
else by simp [ha₁, mt mem_keys_of_mem_keys_kerase ha₁]
theorem sizeOf_kerase [SizeOf (Sigma β)] (x : α)
(xs : List (Sigma β)) : SizeOf.sizeOf (List.kerase x xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with y ys
· simp
· by_cases x = y.1 <;> simp [*]
/-! ### `kinsert` -/
/-- Insert the pair `⟨a, b⟩` and erase the first pair with the key `a`. -/
def kinsert (a : α) (b : β a) (l : List (Sigma β)) : List (Sigma β) :=
⟨a, b⟩ :: kerase a l
@[simp]
theorem kinsert_def {a} {b : β a} {l : List (Sigma β)} : kinsert a b l = ⟨a, b⟩ :: kerase a l :=
rfl
theorem mem_keys_kinsert {a a'} {b' : β a'} {l : List (Sigma β)} :
a ∈ (kinsert a' b' l).keys ↔ a = a' ∨ a ∈ l.keys := by by_cases h : a = a' <;> simp [h]
theorem kinsert_nodupKeys (a) (b : β a) {l : List (Sigma β)} (nd : l.NodupKeys) :
(kinsert a b l).NodupKeys :=
nodupKeys_cons.mpr ⟨not_mem_keys_kerase a nd, nd.kerase a⟩
theorem Perm.kinsert {a} {b : β a} {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (p : l₁ ~ l₂) :
kinsert a b l₁ ~ kinsert a b l₂ :=
(p.kerase nd₁).cons _
theorem dlookup_kinsert {a} {b : β a} (l : List (Sigma β)) :
dlookup a (kinsert a b l) = some b := by
simp only [kinsert, dlookup_cons_eq]
theorem dlookup_kinsert_ne {a a'} {b' : β a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kinsert a' b' l) = dlookup a l := by simp [h]
/-! ### `kextract` -/
/-- Finds the first entry with a given key `a` and returns its value (as an `Option` because there
might be no entry with key `a`) alongside with the rest of the entries. -/
def kextract (a : α) : List (Sigma β) → Option (β a) × List (Sigma β)
| [] => (none, [])
| s :: l =>
if h : s.1 = a then (some (Eq.recOn h s.2), l)
else
let (b', l') := kextract a l
(b', s :: l')
@[simp]
theorem kextract_eq_dlookup_kerase (a : α) :
∀ l : List (Sigma β), kextract a l = (dlookup a l, kerase a l)
| [] => rfl
| ⟨a', b⟩ :: l => by
simp only [kextract]; dsimp; split_ifs with h
· subst a'
simp [kerase]
· simp [kextract, Ne.symm h, kextract_eq_dlookup_kerase a l, kerase]
/-! ### `dedupKeys` -/
/-- Remove entries with duplicate keys from `l : List (Sigma β)`. -/
def dedupKeys : List (Sigma β) → List (Sigma β) :=
List.foldr (fun x => kinsert x.1 x.2) []
theorem dedupKeys_cons {x : Sigma β} (l : List (Sigma β)) :
dedupKeys (x :: l) = kinsert x.1 x.2 (dedupKeys l) :=
rfl
theorem nodupKeys_dedupKeys (l : List (Sigma β)) : NodupKeys (dedupKeys l) := by
dsimp [dedupKeys]
generalize hl : nil = l'
have : NodupKeys l' := by
rw [← hl]
apply nodup_nil
clear hl
induction' l with x xs l_ih
· apply this
· cases x
simp only [foldr_cons, kinsert_def, nodupKeys_cons, ne_eq, not_true]
constructor
· simp only [keys_kerase]
apply l_ih.not_mem_erase
· exact l_ih.kerase _
theorem dlookup_dedupKeys (a : α) (l : List (Sigma β)) : dlookup a (dedupKeys l) = dlookup a l := by
induction' l with l_hd _ l_ih
· rfl
obtain ⟨a', b⟩ := l_hd
by_cases h : a = a'
· subst a'
rw [dedupKeys_cons, dlookup_kinsert, dlookup_cons_eq]
· rw [dedupKeys_cons, dlookup_kinsert_ne h, l_ih, dlookup_cons_ne]
exact h
theorem sizeOf_dedupKeys [SizeOf (Sigma β)]
(xs : List (Sigma β)) : SizeOf.sizeOf (dedupKeys xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with x xs
· simp [dedupKeys]
· simp only [dedupKeys_cons, kinsert_def, Nat.add_le_add_iff_left, Sigma.eta]
trans
· apply sizeOf_kerase
· assumption
/-! ### `kunion` -/
/-- `kunion l₁ l₂` is the append to l₁ of l₂ after, for each key in l₁, the
first matching pair in l₂ is erased. -/
def kunion : List (Sigma β) → List (Sigma β) → List (Sigma β)
| [], l₂ => l₂
| s :: l₁, l₂ => s :: kunion l₁ (kerase s.1 l₂)
@[simp]
theorem nil_kunion {l : List (Sigma β)} : kunion [] l = l :=
rfl
@[simp]
theorem kunion_nil : ∀ {l : List (Sigma β)}, kunion l [] = l
| [] => rfl
| _ :: l => by rw [kunion, kerase_nil, kunion_nil]
@[simp]
theorem kunion_cons {s} {l₁ l₂ : List (Sigma β)} :
kunion (s :: l₁) l₂ = s :: kunion l₁ (kerase s.1 l₂) :=
rfl
@[simp]
theorem mem_keys_kunion {a} {l₁ l₂ : List (Sigma β)} :
a ∈ (kunion l₁ l₂).keys ↔ a ∈ l₁.keys ∨ a ∈ l₂.keys := by
induction l₁ generalizing l₂ with
| nil => simp
| cons s l₁ ih => by_cases h : a = s.1 <;> [simp [h]; simp [h, ih]]
@[simp]
theorem kunion_kerase {a} :
∀ {l₁ l₂ : List (Sigma β)}, kunion (kerase a l₁) (kerase a l₂) = kerase a (kunion l₁ l₂)
| [], _ => rfl
| s :: _, l => by by_cases h : a = s.1 <;> simp [h, kerase_comm a s.1 l, kunion_kerase]
theorem NodupKeys.kunion (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) : (kunion l₁ l₂).NodupKeys := by
induction l₁ generalizing l₂ with
| nil => simp only [nil_kunion, nd₂]
| cons s l₁ ih =>
simp? at nd₁ says simp only [nodupKeys_cons] at nd₁
simp [not_or, nd₁.1, nd₂, ih nd₁.2 (nd₂.kerase s.1)]
theorem Perm.kunion_right {l₁ l₂ : List (Sigma β)} (p : l₁ ~ l₂) (l) :
kunion l₁ l ~ kunion l₂ l := by
induction p generalizing l with
| nil => rfl
| cons hd _ ih =>
simp [ih (List.kerase _ _), Perm.cons]
| swap s₁ s₂ l => simp [kerase_comm, Perm.swap]
| trans _ _ ih₁₂ ih₂₃ => exact Perm.trans (ih₁₂ l) (ih₂₃ l)
theorem Perm.kunion_left :
∀ (l) {l₁ l₂ : List (Sigma β)}, l₁.NodupKeys → l₁ ~ l₂ → kunion l l₁ ~ kunion l l₂
| [], _, _, _, p => p
| s :: l, _, _, nd₁, p => ((p.kerase nd₁).kunion_left l <| nd₁.kerase s.1).cons s
theorem Perm.kunion {l₁ l₂ l₃ l₄ : List (Sigma β)} (nd₃ : l₃.NodupKeys) (p₁₂ : l₁ ~ l₂)
(p₃₄ : l₃ ~ l₄) : kunion l₁ l₃ ~ kunion l₂ l₄ :=
(p₁₂.kunion_right l₃).trans (p₃₄.kunion_left l₂ nd₃)
@[simp]
theorem dlookup_kunion_left {a} {l₁ l₂ : List (Sigma β)} (h : a ∈ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₁ := by
induction' l₁ with s _ ih generalizing l₂ <;> simp at h; rcases h with h | h <;> obtain ⟨a'⟩ := s
· subst h
simp
· rw [kunion_cons]
by_cases h' : a = a'
· subst h'
simp
· simp [h', ih h]
@[simp]
theorem dlookup_kunion_right {a} {l₁ l₂ : List (Sigma β)} (h : a ∉ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₂ := by
induction l₁ generalizing l₂ with
| nil => simp
| cons _ _ ih => simp_all [not_or]
theorem mem_dlookup_kunion {a} {b : β a} {l₁ l₂ : List (Sigma β)} :
b ∈ dlookup a (kunion l₁ l₂) ↔ b ∈ dlookup a l₁ ∨ a ∉ l₁.keys ∧ b ∈ dlookup a l₂ := by
induction l₁ generalizing l₂ with
| nil => simp
| cons s _ ih =>
obtain ⟨a'⟩ := s
by_cases h₁ : a = a'
· subst h₁
simp
· let h₂ := @ih (kerase a' l₂)
simp? [h₁] at h₂ says
simp only [Option.mem_def, ne_eq, h₁, not_false_eq_true, dlookup_kerase_ne] at h₂
simp [h₁, h₂]
@[simp]
theorem dlookup_kunion_eq_some {a} {b : β a} {l₁ l₂ : List (Sigma β)} :
dlookup a (kunion l₁ l₂) = some b ↔
dlookup a l₁ = some b ∨ a ∉ l₁.keys ∧ dlookup a l₂ = some b :=
mem_dlookup_kunion
theorem mem_dlookup_kunion_middle {a} {b : β a} {l₁ l₂ l₃ : List (Sigma β)}
(h₁ : b ∈ dlookup a (kunion l₁ l₃)) (h₂ : a ∉ keys l₂) :
b ∈ dlookup a (kunion (kunion l₁ l₂) l₃) :=
match mem_dlookup_kunion.mp h₁ with
| Or.inl h => mem_dlookup_kunion.mpr (Or.inl (mem_dlookup_kunion.mpr (Or.inl h)))
| Or.inr h => mem_dlookup_kunion.mpr <| Or.inr ⟨mt mem_keys_kunion.mp (not_or.mpr ⟨h.1, h₂⟩), h.2⟩
end List
| Mathlib/Data/List/Sigma.lean | 767 | 771 | |
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Nat.PSub
import Mathlib.Data.Nat.Size
import Mathlib.Data.Num.Bitwise
/-!
# Properties of the binary representation of integers
-/
open Int
attribute [local simp] add_assoc
namespace PosNum
variable {α : Type*}
@[simp, norm_cast]
theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 :=
rfl
@[simp]
theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 :=
rfl
@[simp, norm_cast]
theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = (n : α) + n :=
rfl
@[simp, norm_cast]
theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = ((n : α) + n) + 1 :=
rfl
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n
| 1 => Nat.cast_one
| bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat]
| bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat]
@[norm_cast]
theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
@[simp, norm_cast]
theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 => rfl
| bit0 _ => rfl
| bit1 p =>
(congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <|
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm]
theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl
theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n
| 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one]
| a, 1 => by rw [add_one a, succ_to_nat, cast_one]
| bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _
| bit0 a, bit1 b =>
(congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm]
| bit1 a, bit0 b =>
(congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm]
| bit1 a, bit1 b =>
show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by
rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm]
theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n)
| 1, b => by simp [one_add]
| bit0 a, 1 => congr_arg bit0 (add_one a)
| bit1 a, 1 => congr_arg bit1 (add_one a)
| bit0 _, bit0 _ => rfl
| bit0 a, bit1 b => congr_arg bit0 (add_succ a b)
| bit1 _, bit0 _ => rfl
| bit1 a, bit1 b => congr_arg bit1 (add_succ a b)
theorem bit0_of_bit0 : ∀ n, n + n = bit0 n
| 1 => rfl
| bit0 p => congr_arg bit0 (bit0_of_bit0 p)
| bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ]
theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n :=
show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ]
@[norm_cast]
theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n
| 1 => (mul_one _).symm
| bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib]
| bit1 p =>
(add_to_nat (bit0 (m * p)) m).trans <|
show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib]
theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ)
| 1 => Nat.zero_lt_one
| bit0 p =>
let h := to_nat_pos p
add_pos h h
| bit1 _p => Nat.succ_pos _
theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n :=
show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by
intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h
theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by
induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;>
try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl
theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop)
| 1, 1 => rfl
| bit0 a, 1 =>
let h : (1 : ℕ) ≤ a := to_nat_pos a
Nat.add_le_add h h
| bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a
| 1, bit0 b =>
let h : (1 : ℕ) ≤ b := to_nat_pos b
Nat.add_le_add h h
| 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b
| bit0 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.add_lt_add this this
· rw [this]
· exact Nat.add_lt_add this this
| bit0 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
· rw [this]
apply Nat.lt_succ_self
· exact cmp_to_nat_lemma this
| bit1 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact cmp_to_nat_lemma this
· rw [this]
apply Nat.lt_succ_self
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
| bit1 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
· rw [this]
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
@[norm_cast]
theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n :=
show (m : ℕ) < n ↔ cmp m n = Ordering.lt from
match cmp m n, cmp_to_nat m n with
| Ordering.lt, h => by simp only at h; simp [h]
| Ordering.eq, h => by simp only at h; simp [h, lt_irrefl]
| Ordering.gt, h => by simp [not_lt_of_gt h]
@[norm_cast]
theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr lt_to_nat
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl
theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl
theorem add_one : ∀ n : Num, n + 1 = succ n
| 0 => rfl
| pos p => by cases p <;> rfl
theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n)
| 0, n => by simp [zero_add]
| pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ']
| pos _, pos _ => congr_arg pos (PosNum.add_succ _ _)
theorem bit0_of_bit0 : ∀ n : Num, n + n = n.bit0
| 0 => rfl
| pos p => congr_arg pos p.bit0_of_bit0
theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1
| 0 => rfl
| pos p => congr_arg pos p.bit1_of_bit1
@[simp]
theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat']
theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) :=
Nat.binaryRec_eq _ _ (.inl rfl)
@[simp]
theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl
theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0
| 0 => rfl
| pos _n => rfl
theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 :=
@(Nat.binaryRec (by simp [zero_add]) fun b n ih => by
cases b
· erw [ofNat'_bit true n, ofNat'_bit]
simp only [← bit1_of_bit1, ← bit0_of_bit0, cond]
· rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add],
ofNat'_bit, ofNat'_bit, ih]
simp only [cond, add_one, bit1_succ])
@[simp]
theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by
induction n
· simp only [Nat.add_zero, ofNat'_zero, add_zero]
· simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *]
@[simp, norm_cast]
theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 :=
rfl
@[simp]
theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 :=
rfl
@[simp, norm_cast]
theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 :=
rfl
@[simp]
theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n :=
rfl
theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1
| 0 => (Nat.zero_add _).symm
| pos _p => PosNum.succ_to_nat _
theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 :=
succ'_to_nat n
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n
| 0 => Nat.cast_zero
| pos p => p.cast_to_nat
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n
| 0, 0 => rfl
| 0, pos _q => (Nat.zero_add _).symm
| pos _p, 0 => rfl
| pos _p, pos _q => PosNum.add_to_nat _ _
@[norm_cast]
theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n
| 0, 0 => rfl
| 0, pos _q => (zero_mul _).symm
| pos _p, 0 => rfl
| pos _p, pos _q => PosNum.mul_to_nat _ _
theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop)
| 0, 0 => rfl
| 0, pos _ => to_nat_pos _
| pos _, 0 => to_nat_pos _
| pos a, pos b => by
have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b
exacts [id, congr_arg pos, id]
@[norm_cast]
theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n :=
show (m : ℕ) < n ↔ cmp m n = Ordering.lt from
match cmp m n, cmp_to_nat m n with
| Ordering.lt, h => by simp only at h; simp [h]
| Ordering.eq, h => by simp only at h; simp [h, lt_irrefl]
| Ordering.gt, h => by simp [not_lt_of_gt h]
@[norm_cast]
theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr lt_to_nat
end Num
namespace PosNum
@[simp]
theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n
| 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl
| bit0 p => by
simpa only [Nat.bit_false, cond_false, two_mul, of_to_nat' p] using Num.ofNat'_bit false p
| bit1 p => by
simpa only [Nat.bit_true, cond_true, two_mul, of_to_nat' p] using Num.ofNat'_bit true p
end PosNum
namespace Num
@[simp, norm_cast]
theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n
| 0 => ofNat'_zero
| pos p => p.of_to_nat'
lemma toNat_injective : Function.Injective (castNum : Num → ℕ) :=
Function.LeftInverse.injective of_to_nat'
@[norm_cast]
theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff
/-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting.
```lean
example (n : Num) (m : Num) : n ≤ n + m := by
transfer_rw
exact Nat.le_add_right _ _
```
-/
scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic|
(repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat]
repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero]))
/--
This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and
then trying to call `simp`.
```lean
example (n : Num) (m : Num) : n ≤ n + m := by transfer
```
-/
scoped macro (name := transfer) "transfer" : tactic => `(tactic|
(intros; transfer_rw; try simp))
instance addMonoid : AddMonoid Num where
add := (· + ·)
zero := 0
zero_add := zero_add
add_zero := add_zero
add_assoc := by transfer
nsmul := nsmulRec
instance addMonoidWithOne : AddMonoidWithOne Num :=
{ Num.addMonoid with
natCast := Num.ofNat'
one := 1
natCast_zero := ofNat'_zero
natCast_succ := fun _ => ofNat'_succ }
instance commSemiring : CommSemiring Num where
__ := Num.addMonoid
__ := Num.addMonoidWithOne
mul := (· * ·)
npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩
mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero]
zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul]
mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one]
one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul]
add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm]
mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm]
mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc]
left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add]
right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul]
instance partialOrder : PartialOrder Num where
lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le]
le_refl := by transfer
le_trans a b c := by transfer_rw; apply le_trans
le_antisymm a b := by transfer_rw; apply le_antisymm
instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid Num where
add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c
le_of_add_le_add_left a b c :=
show a + b ≤ a + c → b ≤ c by transfer_rw; apply le_of_add_le_add_left
instance linearOrder : LinearOrder Num :=
{ le_total := by
intro a b
transfer_rw
apply le_total
toDecidableLT := Num.decidableLT
toDecidableLE := Num.decidableLE
-- This is relying on an automatically generated instance name,
-- generated in a `deriving` handler.
-- See https://github.com/leanprover/lean4/issues/2343
toDecidableEq := instDecidableEqNum }
instance isStrictOrderedRing : IsStrictOrderedRing Num :=
{ zero_le_one := by decide
mul_lt_mul_of_pos_left := by
intro a b c
transfer_rw
apply mul_lt_mul_of_pos_left
mul_lt_mul_of_pos_right := by
intro a b c
transfer_rw
apply mul_lt_mul_of_pos_right
exists_pair_ne := ⟨0, 1, by decide⟩ }
@[norm_cast]
theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n :=
add_ofNat' _ _
@[norm_cast]
theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
@[simp, norm_cast]
theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n
| 0 => by rw [Nat.cast_zero, cast_zero]
| n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n]
@[simp, norm_cast]
theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by
rw [← cast_to_nat, to_of_nat]
@[norm_cast]
theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n :=
⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩
-- The priority should be `high`er than `cast_to_nat`.
@[simp high, norm_cast]
theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n :=
of_to_nat'
@[norm_cast]
theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n :=
⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩
end Num
namespace PosNum
variable {α : Type*}
open Num
-- The priority should be `high`er than `cast_to_nat`.
@[simp high, norm_cast]
theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n :=
of_to_nat'
@[norm_cast]
theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n :=
⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩
theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n
| 1 => rfl
| bit0 n =>
have : Nat.succ ↑(pred' n) = ↑n := by
rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)]
match (motive :=
∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (n + n))
pred' n, this with
| 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl
| Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm
| bit1 _ => rfl
@[simp]
theorem pred'_succ' (n) : pred' (succ' n) = n :=
Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ]
@[simp]
theorem succ'_pred' (n) : succ' (pred' n) = n :=
to_nat_inj.1 <| by
rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)]
instance dvd : Dvd PosNum :=
⟨fun m n => pos m ∣ pos n⟩
@[norm_cast]
theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n :=
Num.dvd_to_nat (pos m) (pos n)
theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n
| 1 => Nat.size_one.symm
| bit0 n => by
rw [size, succ_to_nat, size_to_nat n, cast_bit0, ← two_mul]
erw [@Nat.size_bit false n]
have := to_nat_pos n
dsimp [Nat.bit]; omega
| bit1 n => by
rw [size, succ_to_nat, size_to_nat n, cast_bit1, ← two_mul]
erw [@Nat.size_bit true n]
dsimp [Nat.bit]; omega
theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n
| 1 => rfl
| bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n]
| bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n]
theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat]
theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos
/-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting.
```lean
example (n : PosNum) (m : PosNum) : n ≤ n + m := by
transfer_rw
exact Nat.le_add_right _ _
```
-/
scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic|
(repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat]
repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero]))
/--
This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world
and then trying to call `simp`.
```lean
example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer
```
-/
scoped macro (name := transfer) "transfer" : tactic => `(tactic|
(intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm]))
instance addCommSemigroup : AddCommSemigroup PosNum where
add := (· + ·)
add_assoc := by transfer
add_comm := by transfer
instance commMonoid : CommMonoid PosNum where
mul := (· * ·)
one := (1 : PosNum)
npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩
mul_assoc := by transfer
one_mul := by transfer
mul_one := by transfer
mul_comm := by transfer
instance distrib : Distrib PosNum where
add := (· + ·)
mul := (· * ·)
left_distrib := by transfer; simp [mul_add]
right_distrib := by transfer; simp [mul_add, mul_comm]
instance linearOrder : LinearOrder PosNum where
lt := (· < ·)
lt_iff_le_not_le := by
intro a b
transfer_rw
apply lt_iff_le_not_le
le := (· ≤ ·)
le_refl := by transfer
le_trans := by
intro a b c
transfer_rw
apply le_trans
le_antisymm := by
intro a b
transfer_rw
apply le_antisymm
le_total := by
intro a b
transfer_rw
apply le_total
toDecidableLT := by infer_instance
toDecidableLE := by infer_instance
toDecidableEq := by infer_instance
@[simp]
theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n]
@[simp, norm_cast]
theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> simp [bit, two_mul]
@[simp, norm_cast]
theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by
rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat]
@[simp 500, norm_cast]
theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by
rw [← add_one, cast_add, cast_one]
@[simp, norm_cast]
theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj]
@[simp]
theorem one_le_cast [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) :
(1 : α) ≤ n := by
rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos
@[simp]
theorem cast_pos [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : 0 < (n : α) :=
lt_of_lt_of_le zero_lt_one (one_le_cast n)
@[simp, norm_cast]
theorem cast_mul [NonAssocSemiring α] (m n) : ((m * n : PosNum) : α) = m * n := by
rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat]
@[simp]
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
-- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required.
revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;>
simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this]
@[simp, norm_cast]
theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : PosNum} :
(m : α) < n ↔ m < n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat]
@[simp, norm_cast]
theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : PosNum} :
(m : α) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr cast_lt
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by
cases b <;> cases n <;> simp [bit, two_mul] <;> rfl
theorem cast_succ' [AddMonoidWithOne α] (n) : (succ' n : α) = n + 1 := by
rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat]
theorem cast_succ [AddMonoidWithOne α] (n) : (succ n : α) = n + 1 :=
cast_succ' n
@[simp, norm_cast]
theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : Num) : α) = m + n := by
rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat]
@[simp, norm_cast]
theorem cast_bit0 [NonAssocSemiring α] (n : Num) : (n.bit0 : α) = 2 * (n : α) := by
rw [← bit0_of_bit0, two_mul, cast_add]
@[simp, norm_cast]
theorem cast_bit1 [NonAssocSemiring α] (n : Num) : (n.bit1 : α) = 2 * (n : α) + 1 := by
rw [← bit1_of_bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl
@[simp, norm_cast]
theorem cast_mul [NonAssocSemiring α] : ∀ m n, ((m * n : Num) : α) = m * n
| 0, 0 => (zero_mul _).symm
| 0, pos _q => (zero_mul _).symm
| pos _p, 0 => (mul_zero _).symm
| pos _p, pos _q => PosNum.cast_mul _ _
theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n
| 0 => Nat.size_zero.symm
| pos p => p.size_to_nat
theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n
| 0 => rfl
| pos p => p.size_eq_natSize
theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat]
@[simp 999]
theorem ofNat'_eq : ∀ n, Num.ofNat' n = n :=
Nat.binaryRec (by simp) fun b n IH => by tauto
theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl
theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl
theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n :=
⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩
@[simp]
theorem cast_toZNum [Zero α] [One α] [Add α] [Neg α] : ∀ n : Num, (n.toZNum : α) = n
| 0 => rfl
| Num.pos _p => rfl
@[simp]
theorem cast_toZNumNeg [SubtractionMonoid α] [One α] : ∀ n : Num, (n.toZNumNeg : α) = -n
| 0 => neg_zero.symm
| Num.pos _p => rfl
@[simp]
theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by
cases m <;> cases n <;> rfl
end Num
namespace PosNum
open Num
theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : ℕ) = Nat.pred n := by
unfold pred
cases e : pred' n
· have : (1 : ℕ) ≤ Nat.pred n := Nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h)
rw [← pred'_to_nat, e] at this
exact absurd this (by decide)
· rw [← pred'_to_nat, e]
rfl
theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl
theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt :=
Iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt :=
not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem pred_to_nat : ∀ n : Num, (pred n : ℕ) = Nat.pred n
| 0 => rfl
| pos p => by rw [pred, PosNum.pred'_to_nat]; rfl
theorem ppred_to_nat : ∀ n : Num, (↑) <$> ppred n = Nat.ppred n
| 0 => rfl
| pos p => by
rw [ppred, Option.map_some, Nat.ppred_eq_some.2]
rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)]
rfl
theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by
cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
-- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required.
revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;>
simp [show m ≠ n from fun e => by rw [e] at this; exact lt_irrefl _ this]
@[simp, norm_cast]
theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) < n ↔ m < n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat]
@[simp, norm_cast]
theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr cast_lt
@[simp, norm_cast]
theorem cast_inj [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} :
(m : α) = n ↔ m = n := by
rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj]
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt :=
Iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt :=
not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide
theorem castNum_eq_bitwise {f : Num → Num → Num} {g : Bool → Bool → Bool}
(p : PosNum → PosNum → Num)
(gff : g false false = false) (f00 : f 0 0 = 0)
(f0n : ∀ n, f 0 (pos n) = cond (g false true) (pos n) 0)
(fn0 : ∀ n, f (pos n) 0 = cond (g true false) (pos n) 0)
(fnn : ∀ m n, f (pos m) (pos n) = p m n) (p11 : p 1 1 = cond (g true true) 1 0)
(p1b : ∀ b n, p 1 (PosNum.bit b n) = bit (g true b) (cond (g false true) (pos n) 0))
(pb1 : ∀ a m, p (PosNum.bit a m) 1 = bit (g a true) (cond (g true false) (pos m) 0))
(pbb : ∀ a b m n, p (PosNum.bit a m) (PosNum.bit b n) = bit (g a b) (p m n)) :
∀ m n : Num, (f m n : ℕ) = Nat.bitwise g m n := by
intros m n
obtain - | m := m <;> obtain - | n := n <;>
try simp only [show zero = 0 from rfl, show ((0 : Num) : ℕ) = 0 from rfl]
· rw [f00, Nat.bitwise_zero]; rfl
· rw [f0n, Nat.bitwise_zero_left]
cases g false true <;> rfl
· rw [fn0, Nat.bitwise_zero_right]
cases g true false <;> rfl
· rw [fnn]
have this b (n : PosNum) : (cond b (↑n) 0 : ℕ) = ↑(cond b (pos n) 0 : Num) := by
cases b <;> rfl
have this' b (n : PosNum) : ↑ (pos (PosNum.bit b n)) = Nat.bit b ↑n := by
cases b <;> simp
induction' m with m IH m IH generalizing n <;> obtain - | n | n := n
any_goals simp only [show one = 1 from rfl, show pos 1 = 1 from rfl,
show PosNum.bit0 = PosNum.bit false from rfl, show PosNum.bit1 = PosNum.bit true from rfl,
show ((1 : Num) : ℕ) = Nat.bit true 0 from rfl]
all_goals
repeat rw [this']
rw [Nat.bitwise_bit gff]
any_goals rw [Nat.bitwise_zero, p11]; cases g true true <;> rfl
any_goals rw [Nat.bitwise_zero_left, ← Bool.cond_eq_ite, this, ← bit_to_nat, p1b]
any_goals rw [Nat.bitwise_zero_right, ← Bool.cond_eq_ite, this, ← bit_to_nat, pb1]
all_goals
rw [← show ∀ n : PosNum, ↑(p m n) = Nat.bitwise g ↑m ↑n from IH]
rw [← bit_to_nat, pbb]
@[simp, norm_cast]
theorem castNum_or : ∀ m n : Num, ↑(m ||| n) = (↑m ||| ↑n : ℕ) := by
apply castNum_eq_bitwise fun x y => pos (PosNum.lor x y) <;>
(try rintro (_ | _)) <;> (try rintro (_ | _)) <;> intros <;> rfl
@[simp, norm_cast]
theorem castNum_and : ∀ m n : Num, ↑(m &&& n) = (↑m &&& ↑n : ℕ) := by
apply castNum_eq_bitwise PosNum.land <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_ldiff : ∀ m n : Num, (ldiff m n : ℕ) = Nat.ldiff m n := by
apply castNum_eq_bitwise PosNum.ldiff <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_xor : ∀ m n : Num, ↑(m ^^^ n) = (↑m ^^^ ↑n : ℕ) := by
apply castNum_eq_bitwise PosNum.lxor <;> intros <;> (try cases_type* Bool) <;> rfl
@[simp, norm_cast]
theorem castNum_shiftLeft (m : Num) (n : Nat) : ↑(m <<< n) = (m : ℕ) <<< (n : ℕ) := by
cases m <;> dsimp only [← shiftl_eq_shiftLeft, shiftl]
· symm
apply Nat.zero_shiftLeft
simp only [cast_pos]
induction' n with n IH
· rfl
simp [PosNum.shiftl_succ_eq_bit0_shiftl, Nat.shiftLeft_succ, IH, pow_succ, ← mul_assoc, mul_comm,
-shiftl_eq_shiftLeft, -PosNum.shiftl_eq_shiftLeft, shiftl, mul_two]
@[simp, norm_cast]
theorem castNum_shiftRight (m : Num) (n : Nat) : ↑(m >>> n) = (m : ℕ) >>> (n : ℕ) := by
obtain - | m := m <;> dsimp only [← shiftr_eq_shiftRight, shiftr]
· symm
apply Nat.zero_shiftRight
induction' n with n IH generalizing m
· cases m <;> rfl
have hdiv2 : ∀ m, Nat.div2 (m + m) = m := by intro; rw [Nat.div2_val]; omega
obtain - | m | m := m <;> dsimp only [PosNum.shiftr, ← PosNum.shiftr_eq_shiftRight]
· rw [Nat.shiftRight_eq_div_pow]
symm
apply Nat.div_eq_of_lt
simp
· trans
· apply IH
change Nat.shiftRight m n = Nat.shiftRight (m + m + 1) (n + 1)
rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add]
apply congr_arg fun x => Nat.shiftRight x n
simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2]
· trans
· apply IH
change Nat.shiftRight m n = Nat.shiftRight (m + m) (n + 1)
rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add]
apply congr_arg fun x => Nat.shiftRight x n
simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2]
@[simp]
theorem castNum_testBit (m n) : testBit m n = Nat.testBit m n := by
cases m with dsimp only [testBit]
| zero =>
rw [show (Num.zero : Nat) = 0 from rfl, Nat.zero_testBit]
| pos m =>
rw [cast_pos]
induction' n with n IH generalizing m <;> obtain - | m | m := m
<;> simp only [PosNum.testBit]
· rfl
· rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_zero]
· rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_zero]
· simp [Nat.testBit_add_one]
· rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_succ, IH]
· rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_succ, IH]
end Num
namespace Int
/-- Cast a `SNum` to the corresponding integer. -/
def ofSnum : SNum → ℤ :=
SNum.rec' (fun a => cond a (-1) 0) fun a _p IH => cond a (2 * IH + 1) (2 * IH)
instance snumCoe : Coe SNum ℤ :=
⟨ofSnum⟩
end Int
instance SNum.lt : LT SNum :=
⟨fun a b => (a : ℤ) < b⟩
instance SNum.le : LE SNum :=
⟨fun a b => (a : ℤ) ≤ b⟩
| Mathlib/Data/Num/Lemmas.lean | 1,253 | 1,258 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.RingTheory.MvPolynomial.Basic
/-!
## Polynomials over finite fields
-/
namespace MvPolynomial
variable {σ : Type*}
/-- A polynomial over the integers is divisible by `n : ℕ`
if and only if it is zero over `ZMod n`. -/
theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) :
C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 :=
C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _
section frobenius
variable {p : ℕ} [Fact p.Prime]
theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by
apply induction_on f
· intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card]
· simp only [map_add]; intro _ _ hf hg; rw [hf, hg]
· simp only [expand_X, map_mul]
intro _ _ hf; rw [hf, frobenius_def]
theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p :=
(frobenius_zmod _).symm
end frobenius
end MvPolynomial
namespace MvPolynomial
noncomputable section
open Set LinearMap Submodule
variable {K : Type*} {σ : Type*}
section Indicator
variable [Fintype K] [Fintype σ]
/-- Over a field, this is the indicator function as an `MvPolynomial`. -/
def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K :=
∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1))
section CommRing
variable [CommRing K]
theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by
nontriviality
have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
zero_pow this.ne', sub_zero, Finset.prod_const_one]
theorem degrees_indicator (c : σ → K) :
degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by
rw [indicator]
classical
refine degrees_prod_le.trans <| Finset.sum_le_sum fun s _ ↦ degrees_sub_le.trans ?_
rw [degrees_one, Multiset.zero_union]
refine le_trans degrees_pow_le (nsmul_le_nsmul_right ?_ _)
refine degrees_sub_le.trans ?_
rw [degrees_C, Multiset.union_zero]
exact degrees_X' _
theorem indicator_mem_restrictDegree (c : σ → K) :
indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by
classical
rw [mem_restrictDegree_iff_sup, indicator]
intro n
refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_)
simp_rw [← Multiset.coe_countAddMonoidHom, map_sum,
AddMonoidHom.map_nsmul, Multiset.coe_countAddMonoidHom, nsmul_eq_mul, Nat.cast_id]
trans
· refine Finset.sum_eq_single n ?_ ?_
· intro b _ ne
simp [Multiset.count_singleton, ne, if_neg (Ne.symm _)]
· intro h; exact (h <| Finset.mem_univ _).elim
· rw [Multiset.count_singleton_self, mul_one]
end CommRing
variable [Field K]
theorem eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := by
obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by rwa [Ne, funext_iff, not_forall] at h
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
Finset.prod_eq_zero_iff]
refine ⟨i, Finset.mem_univ _, ?_⟩
rw [FiniteField.pow_card_sub_one_eq_one, sub_self]
rwa [Ne, sub_eq_zero]
end Indicator
section
variable (K σ)
/-- `MvPolynomial.eval` as a `K`-linear map. -/
@[simps]
def evalₗ [CommSemiring K] : MvPolynomial σ K →ₗ[K] (σ → K) → K where
toFun p e := eval e p
map_add' p q := by ext x; simp
map_smul' a p := by ext e; simp
variable [Field K] [Fintype K] [Finite σ]
theorem map_restrict_dom_evalₗ : (restrictDegree σ K (Fintype.card K - 1)).map (evalₗ K σ) = ⊤ := by
cases nonempty_fintype σ
refine top_unique (SetLike.le_def.2 fun e _ => mem_map.2 ?_)
classical
refine ⟨∑ n : σ → K, e n • indicator n, ?_, ?_⟩
· exact sum_mem fun c _ => smul_mem _ _ (indicator_mem_restrictDegree _)
· ext n
simp only [_root_.map_sum, @Finset.sum_apply (σ → K) (fun _ => K) _ _ _ _ _, Pi.smul_apply,
map_smul]
simp only [evalₗ_apply]
trans
· refine Finset.sum_eq_single n (fun b _ h => ?_) ?_
· rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero]
· exact fun h => (h <| Finset.mem_univ n).elim
· rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one]
end
end
end MvPolynomial
namespace MvPolynomial
open scoped Cardinal
open LinearMap Submodule
universe u
variable (σ : Type u) (K : Type u) [Fintype K]
/-- The submodule of multivariate polynomials whose degree of each variable is strictly less
than the cardinality of K. -/
def R [CommRing K] : Type u :=
restrictDegree σ K (Fintype.card K - 1)
-- The `AddCommGroup, Module K, Inhabited` instances should be constructed by a deriving handler.
noncomputable instance [CommRing K] : AddCommGroup (R σ K) :=
inferInstanceAs (AddCommGroup (restrictDegree σ K (Fintype.card K - 1)))
noncomputable instance [CommRing K] : Module K (R σ K) :=
inferInstanceAs (Module K (restrictDegree σ K (Fintype.card K - 1)))
noncomputable instance [CommRing K] : Inhabited (R σ K) :=
inferInstanceAs (Inhabited (restrictDegree σ K (Fintype.card K - 1)))
/-- Evaluation in the `MvPolynomial.R` subtype. -/
def evalᵢ [CommRing K] : R σ K →ₗ[K] (σ → K) → K :=
(evalₗ K σ).comp (restrictDegree σ K (Fintype.card K - 1)).subtype
-- TODO: would be nice to replace this by suitable decidability assumptions
open Classical in
noncomputable instance decidableRestrictDegree (m : ℕ) :
DecidablePred (· ∈ { n : σ →₀ ℕ | ∀ i, n i ≤ m }) := by
simp only [Set.mem_setOf_eq]; infer_instance
variable [Field K]
open Classical in
theorem rank_R [Fintype σ] : Module.rank K (R σ K) = Fintype.card (σ → K) :=
calc
Module.rank K (R σ K) =
Module.rank K (↥{ s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 } →₀ K) :=
LinearEquiv.rank_eq
(Finsupp.supportedEquivFinsupp { s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 })
_ = #{ s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 } := by rw [rank_finsupp_self']
_ = #{ s : σ → ℕ | ∀ n : σ, s n < Fintype.card K } := by
refine Quotient.sound ⟨Equiv.subtypeEquiv Finsupp.equivFunOnFinite fun f => ?_⟩
refine forall_congr' fun n => le_tsub_iff_right ?_
exact Fintype.card_pos_iff.2 ⟨0⟩
_ = #(σ → { n // n < Fintype.card K }) :=
(@Equiv.subtypePiEquivPi σ (fun _ => ℕ) fun _ n => n < Fintype.card K).cardinal_eq
_ = #(σ → Fin (Fintype.card K)) :=
(Equiv.arrowCongr (Equiv.refl σ) Fin.equivSubtype.symm).cardinal_eq
_ = #(σ → K) := (Equiv.arrowCongr (Equiv.refl σ) (Fintype.equivFin K).symm).cardinal_eq
_ = Fintype.card (σ → K) := Cardinal.mk_fintype _
instance [Finite σ] : FiniteDimensional K (R σ K) := by
cases nonempty_fintype σ
classical
| exact
IsNoetherian.iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.mpr <| by
simpa only [rank_R] using Cardinal.nat_lt_aleph0 (Fintype.card (σ → K)))
open Classical in
theorem finrank_R [Fintype σ] : Module.finrank K (R σ K) = Fintype.card (σ → K) :=
Module.finrank_eq_of_rank_eq (rank_R σ K)
theorem range_evalᵢ [Finite σ] : range (evalᵢ σ K) = ⊤ := by
rw [evalᵢ, LinearMap.range_comp, range_subtype]
exact map_restrict_dom_evalₗ K σ
theorem ker_evalₗ [Finite σ] : ker (evalᵢ σ K) = ⊥ := by
cases nonempty_fintype σ
refine (ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank ?_).mpr (range_evalᵢ σ K)
classical
| Mathlib/FieldTheory/Finite/Polynomial.lean | 204 | 220 |
/-
Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/
import Mathlib.Algebra.Pointwise.Stabilizer
import Mathlib.Data.Setoid.Partition
import Mathlib.GroupTheory.GroupAction.Pointwise
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.Index
import Mathlib.Tactic.IntervalCases
/-! # Blocks
Given `SMul G X`, an action of a type `G` on a type `X`, we define
- the predicate `MulAction.IsBlock G B` states that `B : Set X` is a block,
which means that the sets `g • B`, for `g ∈ G`, are equal or disjoint.
Under `Group G` and `MulAction G X`, this is equivalent to the classical
definition `MulAction.IsBlock.def_one`
- a bunch of lemmas that give examples of “trivial” blocks : ⊥, ⊤, singletons,
and non trivial blocks: orbit of the group, orbit of a normal subgroup…
The non-existence of nontrivial blocks is the definition of primitive actions.
## Results for actions on finite sets
- `MulAction.IsBlock.ncard_block_mul_ncard_orbit_eq` : The cardinality of a block
multiplied by the number of its translates is the cardinal of the ambient type
- `MulAction.IsBlock.eq_univ_of_card_lt` : a too large block is equal to `Set.univ`
- `MulAction.IsBlock.subsingleton_of_card_lt` : a too small block is a subsingleton
- `MulAction.IsBlock.of_subset` : the intersections of the translates of a finite subset
that contain a given point is a block
- `MulAction.BlockMem` : the type of blocks containing a given element
- `MulAction.BlockMem.instBoundedOrder` :
the type of blocks containing a given element is a bounded order.
## References
We follow [Wielandt-1964].
-/
open Set
open scoped Pointwise
namespace MulAction
section orbits
variable {G : Type*} [Group G] {X : Type*} [MulAction G X]
@[to_additive]
theorem orbit.eq_or_disjoint (a b : X) :
orbit G a = orbit G b ∨ Disjoint (orbit G a) (orbit G b) := by
apply (em (Disjoint (orbit G a) (orbit G b))).symm.imp _ id
simp +contextual
only [Set.not_disjoint_iff, ← orbit_eq_iff, forall_exists_index, and_imp, eq_comm, implies_true]
@[to_additive]
theorem orbit.pairwiseDisjoint :
(Set.range fun x : X => orbit G x).PairwiseDisjoint id := by
rintro s ⟨x, rfl⟩ t ⟨y, rfl⟩ h
contrapose! h
exact (orbit.eq_or_disjoint x y).resolve_right h
/-- Orbits of an element form a partition -/
@[to_additive "Orbits of an element form a partition"]
theorem IsPartition.of_orbits :
Setoid.IsPartition (Set.range fun a : X => orbit G a) := by
apply orbit.pairwiseDisjoint.isPartition_of_exists_of_ne_empty
· intro x
exact ⟨_, ⟨x, rfl⟩, mem_orbit_self x⟩
· rintro ⟨a, ha : orbit G a = ∅⟩
exact (MulAction.orbit_nonempty a).ne_empty ha
end orbits
section SMul
variable (G : Type*) {X : Type*} [SMul G X] {B : Set X} {a : X}
-- Change terminology to IsFullyInvariant?
/-- A set `B` is a `G`-fixed block if `g • B = B` for all `g : G`. -/
@[to_additive "A set `B` is a `G`-fixed block if `g +ᵥ B = B` for all `g : G`."]
def IsFixedBlock (B : Set X) := ∀ g : G, g • B = B
/-- A set `B` is a `G`-invariant block if `g • B ⊆ B` for all `g : G`.
Note: It is not necessarily a block when the action is not by a group. -/
@[to_additive
"A set `B` is a `G`-invariant block if `g +ᵥ B ⊆ B` for all `g : G`.
Note: It is not necessarily a block when the action is not by a group. "]
def IsInvariantBlock (B : Set X) := ∀ g : G, g • B ⊆ B
section IsTrivialBlock
/-- A trivial block is a `Set X` which is either a subsingleton or `univ`.
Note: It is not necessarily a block when the action is not by a group. -/
@[to_additive
"A trivial block is a `Set X` which is either a subsingleton or `univ`.
Note: It is not necessarily a block when the action is not by a group."]
def IsTrivialBlock (B : Set X) := B.Subsingleton ∨ B = univ
variable {M α N β : Type*}
section monoid
variable [Monoid M] [MulAction M α] [Monoid N] [MulAction N β]
@[to_additive]
theorem IsTrivialBlock.image {φ : M → N} {f : α →ₑ[φ] β}
(hf : Function.Surjective f) {B : Set α} (hB : IsTrivialBlock B) :
IsTrivialBlock (f '' B) := by
obtain hB | hB := hB
· apply Or.intro_left; apply Set.Subsingleton.image hB
· apply Or.intro_right; rw [hB]
simp only [Set.top_eq_univ, Set.image_univ, Set.range_eq_univ, hf]
@[to_additive]
theorem IsTrivialBlock.preimage {φ : M → N} {f : α →ₑ[φ] β}
(hf : Function.Injective f) {B : Set β} (hB : IsTrivialBlock B) :
IsTrivialBlock (f ⁻¹' B) := by
obtain hB | hB := hB
· apply Or.intro_left; exact Set.Subsingleton.preimage hB hf
· apply Or.intro_right; simp only [hB, Set.top_eq_univ]; apply Set.preimage_univ
end monoid
variable [Group M] [MulAction M α] [Monoid N] [MulAction N β]
@[to_additive]
theorem IsTrivialBlock.smul {B : Set α} (hB : IsTrivialBlock B) (g : M) :
IsTrivialBlock (g • B) := by
cases hB with
| inl h =>
left
exact (Function.Injective.subsingleton_image_iff (MulAction.injective g)).mpr h
| inr h =>
right
rw [h, ← Set.image_smul, Set.image_univ_of_surjective (MulAction.surjective g)]
@[to_additive]
theorem IsTrivialBlock.smul_iff {B : Set α} (g : M) :
IsTrivialBlock (g • B) ↔ IsTrivialBlock B := by
constructor
· intro H
convert IsTrivialBlock.smul H g⁻¹
simp only [inv_smul_smul]
· intro H
exact IsTrivialBlock.smul H g
end IsTrivialBlock
/-- A set `B` is a `G`-block iff the sets of the form `g • B` are pairwise equal or disjoint. -/
@[to_additive
"A set `B` is a `G`-block iff the sets of the form `g +ᵥ B` are pairwise equal or disjoint. "]
def IsBlock (B : Set X) := ∀ ⦃g₁ g₂ : G⦄, g₁ • B ≠ g₂ • B → Disjoint (g₁ • B) (g₂ • B)
variable {G} {s : Set G} {g g₁ g₂ : G}
@[to_additive]
lemma isBlock_iff_smul_eq_smul_of_nonempty :
IsBlock G B ↔ ∀ ⦃g₁ g₂ : G⦄, (g₁ • B ∩ g₂ • B).Nonempty → g₁ • B = g₂ • B := by
simp_rw [IsBlock, ← not_disjoint_iff_nonempty_inter, not_imp_comm]
@[to_additive]
lemma isBlock_iff_pairwiseDisjoint_range_smul :
IsBlock G B ↔ (range fun g : G ↦ g • B).PairwiseDisjoint id := pairwiseDisjoint_range_iff.symm
@[to_additive]
lemma isBlock_iff_smul_eq_smul_or_disjoint :
IsBlock G B ↔ ∀ g₁ g₂ : G, g₁ • B = g₂ • B ∨ Disjoint (g₁ • B) (g₂ • B) :=
forall₂_congr fun _ _ ↦ or_iff_not_imp_left.symm
@[to_additive]
lemma IsBlock.smul_eq_smul_of_subset (hB : IsBlock G B) (hg : g₁ • B ⊆ g₂ • B) :
g₁ • B = g₂ • B := by
by_contra! hg'
obtain rfl : B = ∅ := by simpa using (hB hg').eq_bot_of_le hg
simp at hg'
@[to_additive]
lemma IsBlock.not_smul_set_ssubset_smul_set (hB : IsBlock G B) : ¬ g₁ • B ⊂ g₂ • B :=
fun hab ↦ hab.ne <| hB.smul_eq_smul_of_subset hab.subset
@[to_additive]
lemma IsBlock.disjoint_smul_set_smul (hB : IsBlock G B) (hgs : ¬ g • B ⊆ s • B) :
Disjoint (g • B) (s • B) := by
rw [← iUnion_smul_set, disjoint_iUnion₂_right]
exact fun b hb ↦ hB fun h ↦ hgs <| h.trans_subset <| smul_set_subset_smul hb
@[to_additive]
lemma IsBlock.disjoint_smul_smul_set (hB : IsBlock G B) (hgs : ¬ g • B ⊆ s • B) :
Disjoint (s • B) (g • B) := (hB.disjoint_smul_set_smul hgs).symm
@[to_additive]
alias ⟨IsBlock.smul_eq_smul_of_nonempty, _⟩ := isBlock_iff_smul_eq_smul_of_nonempty
@[to_additive]
alias ⟨IsBlock.pairwiseDisjoint_range_smul, _⟩ := isBlock_iff_pairwiseDisjoint_range_smul
@[to_additive]
alias ⟨IsBlock.smul_eq_smul_or_disjoint, _⟩ := isBlock_iff_smul_eq_smul_or_disjoint
/-- A fixed block is a block. -/
@[to_additive "A fixed block is a block."]
lemma IsFixedBlock.isBlock (hfB : IsFixedBlock G B) : IsBlock G B := by simp [IsBlock, hfB _]
/-- The empty set is a block. -/
@[to_additive (attr := simp) "The empty set is a block."]
lemma IsBlock.empty : IsBlock G (∅ : Set X) := by simp [IsBlock]
/-- A singleton is a block. -/
@[to_additive "A singleton is a block."]
lemma IsBlock.singleton : IsBlock G ({a} : Set X) := by simp [IsBlock]
/-- Subsingletons are (trivial) blocks. -/
@[to_additive "Subsingletons are (trivial) blocks."]
lemma IsBlock.of_subsingleton (hB : B.Subsingleton) : IsBlock G B :=
hB.induction_on .empty fun _ ↦ .singleton
/-- A fixed block is an invariant block. -/
@[to_additive "A fixed block is an invariant block."]
lemma IsFixedBlock.isInvariantBlock (hB : IsFixedBlock G B) : IsInvariantBlock G B :=
fun _ ↦ (hB _).le
end SMul
section Monoid
variable {M X : Type*} [Monoid M] [MulAction M X] {B : Set X} {s : Set M}
@[to_additive]
lemma IsBlock.disjoint_smul_right (hB : IsBlock M B) (hs : ¬ B ⊆ s • B) : Disjoint B (s • B) := by
simpa using hB.disjoint_smul_set_smul (g := 1) (by simpa using hs)
@[to_additive]
lemma IsBlock.disjoint_smul_left (hB : IsBlock M B) (hs : ¬ B ⊆ s • B) : Disjoint (s • B) B :=
(hB.disjoint_smul_right hs).symm
end Monoid
section Group
variable {G : Type*} [Group G] {X : Type*} [MulAction G X] {B : Set X}
@[to_additive]
lemma isBlock_iff_disjoint_smul_of_ne :
IsBlock G B ↔ ∀ ⦃g : G⦄, g • B ≠ B → Disjoint (g • B) B := by
refine ⟨fun hB g ↦ by simpa using hB (g₂ := 1), fun hB g₁ g₂ h ↦ ?_⟩
simp only [disjoint_smul_set_right, ne_eq, ← inv_smul_eq_iff, smul_smul] at h ⊢
exact hB h
@[to_additive]
lemma isBlock_iff_smul_eq_of_nonempty :
IsBlock G B ↔ ∀ ⦃g : G⦄, (g • B ∩ B).Nonempty → g • B = B := by
| simp_rw [isBlock_iff_disjoint_smul_of_ne, ← not_disjoint_iff_nonempty_inter, not_imp_comm]
@[to_additive]
lemma isBlock_iff_smul_eq_or_disjoint :
IsBlock G B ↔ ∀ g : G, g • B = B ∨ Disjoint (g • B) B :=
isBlock_iff_disjoint_smul_of_ne.trans <| forall_congr' fun _ ↦ or_iff_not_imp_left.symm
@[to_additive]
lemma isBlock_iff_smul_eq_of_mem :
IsBlock G B ↔ ∀ ⦃g : G⦄ ⦃a : X⦄, a ∈ B → g • a ∈ B → g • B = B := by
simp [isBlock_iff_smul_eq_of_nonempty, Set.Nonempty, mem_smul_set]
@[to_additive] alias ⟨IsBlock.disjoint_smul_of_ne, _⟩ := isBlock_iff_disjoint_smul_of_ne
@[to_additive] alias ⟨IsBlock.smul_eq_of_nonempty, _⟩ := isBlock_iff_smul_eq_of_nonempty
| Mathlib/GroupTheory/GroupAction/Blocks.lean | 264 | 277 |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Kim Morrison
-/
import Mathlib.CategoryTheory.Subobject.MonoOver
import Mathlib.CategoryTheory.Skeletal
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.Tactic.ApplyFun
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# Subobjects
We define `Subobject X` as the quotient (by isomorphisms) of
`MonoOver X := {f : Over X // Mono f.hom}`.
Here `MonoOver X` is a thin category (a pair of objects has at most one morphism between them),
so we can think of it as a preorder. However as it is not skeletal, it is not a partial order.
There is a coercion from `Subobject X` back to the ambient category `C`
(using choice to pick a representative), and for `P : Subobject X`,
`P.arrow : (P : C) ⟶ X` is the inclusion morphism.
We provide
* `def pullback [HasPullbacks C] (f : X ⟶ Y) : Subobject Y ⥤ Subobject X`
* `def map (f : X ⟶ Y) [Mono f] : Subobject X ⥤ Subobject Y`
* `def «exists_» [HasImages C] (f : X ⟶ Y) : Subobject X ⥤ Subobject Y`
and prove their basic properties and relationships.
These are all easy consequences of the earlier development
of the corresponding functors for `MonoOver`.
The subobjects of `X` form a preorder making them into a category. We have `X ≤ Y` if and only if
`X.arrow` factors through `Y.arrow`: see `ofLE`/`ofLEMk`/`ofMkLE`/`ofMkLEMk` and
`le_of_comm`. Similarly, to show that two subobjects are equal, we can supply an isomorphism between
the underlying objects that commutes with the arrows (`eq_of_comm`).
See also
* `CategoryTheory.Subobject.factorThru` :
an API describing factorization of morphisms through subobjects.
* `CategoryTheory.Subobject.lattice` :
the lattice structures on subobjects.
## Notes
This development originally appeared in Bhavik Mehta's "Topos theory for Lean" repository,
and was ported to mathlib by Kim Morrison.
### Implementation note
Currently we describe `pullback`, `map`, etc., as functors.
It may be better to just say that they are monotone functions,
and even avoid using categorical language entirely when describing `Subobject X`.
(It's worth keeping this in mind in future use; it should be a relatively easy change here
if it looks preferable.)
### Relation to pseudoelements
There is a separate development of pseudoelements in `CategoryTheory.Abelian.Pseudoelements`,
as a quotient (but not by isomorphism) of `Over X`.
When a morphism `f` has an image, the image represents the same pseudoelement.
In a category with images `Pseudoelements X` could be constructed as a quotient of `MonoOver X`.
In fact, in an abelian category (I'm not sure in what generality beyond that),
`Pseudoelements X` agrees with `Subobject X`, but we haven't developed this in mathlib yet.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
namespace CategoryTheory
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C}
variable {D : Type u₂} [Category.{v₂} D]
/-!
We now construct the subobject lattice for `X : C`,
as the quotient by isomorphisms of `MonoOver X`.
Since `MonoOver X` is a thin category, we use `ThinSkeleton` to take the quotient.
Essentially all the structure defined above on `MonoOver X` descends to `Subobject X`,
with morphisms becoming inequalities, and isomorphisms becoming equations.
-/
/-- The category of subobjects of `X : C`, defined as isomorphism classes of monomorphisms into `X`.
-/
def Subobject (X : C) :=
ThinSkeleton (MonoOver X)
instance (X : C) : PartialOrder (Subobject X) :=
inferInstanceAs <| PartialOrder (ThinSkeleton (MonoOver X))
namespace Subobject
-- Porting note: made it a def rather than an abbreviation
-- because Lean would make it too transparent
/-- Convenience constructor for a subobject. -/
def mk {X A : C} (f : A ⟶ X) [Mono f] : Subobject X :=
(toThinSkeleton _).obj (MonoOver.mk' f)
section
attribute [local ext] CategoryTheory.Comma
protected theorem ind {X : C} (p : Subobject X → Prop)
(h : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], p (Subobject.mk f)) (P : Subobject X) : p P := by
apply Quotient.inductionOn'
intro a
exact h a.arrow
protected theorem ind₂ {X : C} (p : Subobject X → Subobject X → Prop)
(h : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g],
p (Subobject.mk f) (Subobject.mk g))
(P Q : Subobject X) : p P Q := by
apply Quotient.inductionOn₂'
intro a b
exact h a.arrow b.arrow
end
/-- Declare a function on subobjects of `X` by specifying a function on monomorphisms with
codomain `X`. -/
protected def lift {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α)
(h :
∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g] (i : A ≅ B),
i.hom ≫ g = f → F f = F g) :
Subobject X → α := fun P =>
Quotient.liftOn' P (fun m => F m.arrow) fun m n ⟨i⟩ =>
h m.arrow n.arrow ((MonoOver.forget X ⋙ Over.forget X).mapIso i) (Over.w i.hom)
@[simp]
protected theorem lift_mk {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α) {h A}
(f : A ⟶ X) [Mono f] : Subobject.lift F h (Subobject.mk f) = F f :=
rfl
/-- The category of subobjects is equivalent to the `MonoOver` category. It is more convenient to
use the former due to the partial order instance, but oftentimes it is easier to define structures
on the latter. -/
noncomputable def equivMonoOver (X : C) : Subobject X ≌ MonoOver X :=
ThinSkeleton.equivalence _
/-- Use choice to pick a representative `MonoOver X` for each `Subobject X`.
-/
noncomputable def representative {X : C} : Subobject X ⥤ MonoOver X :=
(equivMonoOver X).functor
instance : (representative (X := X)).IsEquivalence :=
(equivMonoOver X).isEquivalence_functor
/-- Starting with `A : MonoOver X`, we can take its equivalence class in `Subobject X`
then pick an arbitrary representative using `representative.obj`.
This is isomorphic (in `MonoOver X`) to the original `A`.
-/
noncomputable def representativeIso {X : C} (A : MonoOver X) :
representative.obj ((toThinSkeleton _).obj A) ≅ A :=
(equivMonoOver X).counitIso.app A
/-- Use choice to pick a representative underlying object in `C` for any `Subobject X`.
Prefer to use the coercion `P : C` rather than explicitly writing `underlying.obj P`.
-/
noncomputable def underlying {X : C} : Subobject X ⥤ C :=
representative ⋙ MonoOver.forget _ ⋙ Over.forget _
instance : CoeOut (Subobject X) C where coe Y := underlying.obj Y
-- Porting note: removed as it has become a syntactic tautology
-- @[simp]
-- theorem underlying_as_coe {X : C} (P : Subobject X) : underlying.obj P = P :=
-- rfl
/-- If we construct a `Subobject Y` from an explicit `f : X ⟶ Y` with `[Mono f]`,
then pick an arbitrary choice of underlying object `(Subobject.mk f : C)` back in `C`,
it is isomorphic (in `C`) to the original `X`.
-/
noncomputable def underlyingIso {X Y : C} (f : X ⟶ Y) [Mono f] : (Subobject.mk f : C) ≅ X :=
(MonoOver.forget _ ⋙ Over.forget _).mapIso (representativeIso (MonoOver.mk' f))
/-- The morphism in `C` from the arbitrarily chosen underlying object to the ambient object.
-/
noncomputable def arrow {X : C} (Y : Subobject X) : (Y : C) ⟶ X :=
(representative.obj Y).obj.hom
instance arrow_mono {X : C} (Y : Subobject X) : Mono Y.arrow :=
(representative.obj Y).property
@[simp]
theorem arrow_congr {A : C} (X Y : Subobject A) (h : X = Y) :
eqToHom (congr_arg (fun X : Subobject A => (X : C)) h) ≫ Y.arrow = X.arrow := by
induction h
simp
@[simp]
theorem representative_coe (Y : Subobject X) : (representative.obj Y : C) = (Y : C) :=
rfl
@[simp]
theorem representative_arrow (Y : Subobject X) : (representative.obj Y).arrow = Y.arrow :=
rfl
@[reassoc (attr := simp)]
theorem underlying_arrow {X : C} {Y Z : Subobject X} (f : Y ⟶ Z) :
underlying.map f ≫ arrow Z = arrow Y :=
Over.w (representative.map f)
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem underlyingIso_arrow {X Y : C} (f : X ⟶ Y) [Mono f] :
(underlyingIso f).inv ≫ (Subobject.mk f).arrow = f :=
Over.w _
@[reassoc (attr := simp)]
theorem underlyingIso_hom_comp_eq_mk {X Y : C} (f : X ⟶ Y) [Mono f] :
(underlyingIso f).hom ≫ f = (mk f).arrow :=
(Iso.eq_inv_comp _).1 (underlyingIso_arrow f).symm
/-- Two morphisms into a subobject are equal exactly if
the morphisms into the ambient object are equal -/
@[ext]
theorem eq_of_comp_arrow_eq {X Y : C} {P : Subobject Y} {f g : X ⟶ P}
(h : f ≫ P.arrow = g ≫ P.arrow) : f = g :=
(cancel_mono P.arrow).mp h
theorem mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂] (g : A₁ ⟶ A₂)
(w : g ≫ f₂ = f₁) : mk f₁ ≤ mk f₂ :=
⟨MonoOver.homMk _ w⟩
@[simp]
theorem mk_arrow (P : Subobject X) : mk P.arrow = P :=
Quotient.inductionOn' P fun Q => by
obtain ⟨e⟩ := @Quotient.mk_out' _ (isIsomorphicSetoid _) Q
exact Quotient.sound' ⟨MonoOver.isoMk (Iso.refl _) ≪≫ e⟩
theorem le_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ⟶ (Y : C)) (w : f ≫ Y.arrow = X.arrow) :
X ≤ Y := by
convert mk_le_mk_of_comm _ w <;> simp
theorem le_mk_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : (X : C) ⟶ A)
(w : g ≫ f = X.arrow) : X ≤ mk f :=
le_of_comm (g ≫ (underlyingIso f).inv) <| by simp [w]
theorem mk_le_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : A ⟶ (X : C))
(w : g ≫ X.arrow = f) : mk f ≤ X :=
le_of_comm ((underlyingIso f).hom ≫ g) <| by simp [w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
@[ext (iff := false)]
theorem eq_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ≅ (Y : C))
(w : f.hom ≫ Y.arrow = X.arrow) : X = Y :=
le_antisymm (le_of_comm f.hom w) <| le_of_comm f.inv <| f.inv_comp_eq.2 w.symm
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
theorem eq_mk_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : (X : C) ≅ A)
(w : i.hom ≫ f = X.arrow) : X = mk f :=
eq_of_comm (i.trans (underlyingIso f).symm) <| by simp [w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
theorem mk_eq_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : A ≅ (X : C))
(w : i.hom ≫ X.arrow = f) : mk f = X :=
Eq.symm <| eq_mk_of_comm _ i.symm <| by rw [Iso.symm_hom, Iso.inv_comp_eq, w]
/-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with
the arrows. -/
theorem mk_eq_mk_of_comm {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (i : A₁ ≅ A₂)
(w : i.hom ≫ g = f) : mk f = mk g :=
eq_mk_of_comm _ ((underlyingIso f).trans i) <| by simp [w]
lemma mk_surjective {X : C} (S : Subobject X) :
∃ (A : C) (i : A ⟶ X) (_ : Mono i), S = Subobject.mk i :=
⟨_, S.arrow, inferInstance, by simp⟩
-- We make `X` and `Y` explicit arguments here so that when `ofLE` appears in goal statements
-- it is possible to see its source and target
-- (`h` will just display as `_`, because it is in `Prop`).
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
def ofLE {B : C} (X Y : Subobject B) (h : X ≤ Y) : (X : C) ⟶ (Y : C) :=
underlying.map <| h.hom
@[reassoc (attr := simp)]
theorem ofLE_arrow {B : C} {X Y : Subobject B} (h : X ≤ Y) : ofLE X Y h ≫ Y.arrow = X.arrow :=
underlying_arrow _
instance {B : C} (X Y : Subobject B) (h : X ≤ Y) : Mono (ofLE X Y h) := by
fconstructor
intro Z f g w
replace w := w =≫ Y.arrow
ext
simpa using w
theorem ofLE_mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂]
(g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) :
ofLE _ _ (mk_le_mk_of_comm g w) = (underlyingIso _).hom ≫ g ≫ (underlyingIso _).inv := by
ext
simp [w]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
def ofLEMk {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) : (X : C) ⟶ A :=
ofLE X (mk f) h ≫ (underlyingIso f).hom
instance {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) :
Mono (ofLEMk X f h) := by
dsimp only [ofLEMk]
infer_instance
@[simp]
theorem ofLEMk_comp {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (h : X ≤ mk f) :
ofLEMk X f h ≫ f = X.arrow := by simp [ofLEMk]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
def ofMkLE {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) : A ⟶ (X : C) :=
(underlyingIso f).inv ≫ ofLE (mk f) X h
instance {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) :
Mono (ofMkLE f X h) := by
dsimp only [ofMkLE]
infer_instance
@[simp]
theorem ofMkLE_arrow {B A : C} {f : A ⟶ B} [Mono f] {X : Subobject B} (h : mk f ≤ X) :
ofMkLE f X h ≫ X.arrow = f := by simp [ofMkLE]
/-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/
def ofMkLEMk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) :
A₁ ⟶ A₂ :=
(underlyingIso f).inv ≫ ofLE (mk f) (mk g) h ≫ (underlyingIso g).hom
instance {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) :
Mono (ofMkLEMk f g h) := by
dsimp only [ofMkLEMk]
infer_instance
@[simp]
theorem ofMkLEMk_comp {B A₁ A₂ : C} {f : A₁ ⟶ B} {g : A₂ ⟶ B} [Mono f] [Mono g] (h : mk f ≤ mk g) :
ofMkLEMk f g h ≫ g = f := by simp [ofMkLEMk]
@[reassoc (attr := simp)]
theorem ofLE_comp_ofLE {B : C} (X Y Z : Subobject B) (h₁ : X ≤ Y) (h₂ : Y ≤ Z) :
ofLE X Y h₁ ≫ ofLE Y Z h₂ = ofLE X Z (h₁.trans h₂) := by
simp only [ofLE, ← Functor.map_comp underlying]
congr 1
@[reassoc (attr := simp)]
theorem ofLE_comp_ofLEMk {B A : C} (X Y : Subobject B) (f : A ⟶ B) [Mono f] (h₁ : X ≤ Y)
(h₂ : Y ≤ mk f) : ofLE X Y h₁ ≫ ofLEMk Y f h₂ = ofLEMk X f (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ← Functor.map_comp_assoc underlying]
congr 1
@[reassoc (attr := simp)]
theorem ofLEMk_comp_ofMkLE {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (Y : Subobject B)
(h₁ : X ≤ mk f) (h₂ : mk f ≤ Y) : ofLEMk X f h₁ ≫ ofMkLE f Y h₂ = ofLE X Y (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ← Functor.map_comp underlying, assoc, Iso.hom_inv_id_assoc]
congr 1
@[reassoc (attr := simp)]
theorem ofLEMk_comp_ofMkLEMk {B A₁ A₂ : C} (X : Subobject B) (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B)
[Mono g] (h₁ : X ≤ mk f) (h₂ : mk f ≤ mk g) :
ofLEMk X f h₁ ≫ ofMkLEMk f g h₂ = ofLEMk X g (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying,
assoc, Iso.hom_inv_id_assoc]
congr 1
@[reassoc (attr := simp)]
theorem ofMkLE_comp_ofLE {B A₁ : C} (f : A₁ ⟶ B) [Mono f] (X Y : Subobject B) (h₁ : mk f ≤ X)
(h₂ : X ≤ Y) : ofMkLE f X h₁ ≫ ofLE X Y h₂ = ofMkLE f Y (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp underlying,
assoc]
congr 1
@[reassoc (attr := simp)]
theorem ofMkLE_comp_ofLEMk {B A₁ A₂ : C} (f : A₁ ⟶ B) [Mono f] (X : Subobject B) (g : A₂ ⟶ B)
[Mono g] (h₁ : mk f ≤ X) (h₂ : X ≤ mk g) :
ofMkLE f X h₁ ≫ ofLEMk X g h₂ = ofMkLEMk f g (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying, assoc]
congr 1
@[reassoc (attr := simp)]
theorem ofMkLEMk_comp_ofMkLE {B A₁ A₂ : C} (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B) [Mono g]
(X : Subobject B) (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ X) :
ofMkLEMk f g h₁ ≫ ofMkLE g X h₂ = ofMkLE f X (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp underlying,
assoc, Iso.hom_inv_id_assoc]
congr 1
@[reassoc (attr := simp)]
theorem ofMkLEMk_comp_ofMkLEMk {B A₁ A₂ A₃ : C} (f : A₁ ⟶ B) [Mono f] (g : A₂ ⟶ B) [Mono g]
(h : A₃ ⟶ B) [Mono h] (h₁ : mk f ≤ mk g) (h₂ : mk g ≤ mk h) :
ofMkLEMk f g h₁ ≫ ofMkLEMk g h h₂ = ofMkLEMk f h (h₁.trans h₂) := by
simp only [ofMkLE, ofLEMk, ofLE, ofMkLEMk, ← Functor.map_comp_assoc underlying, assoc,
Iso.hom_inv_id_assoc]
congr 1
@[simp]
theorem ofLE_refl {B : C} (X : Subobject B) : ofLE X X le_rfl = 𝟙 _ := by
apply (cancel_mono X.arrow).mp
simp
@[simp]
theorem ofMkLEMk_refl {B A₁ : C} (f : A₁ ⟶ B) [Mono f] : ofMkLEMk f f le_rfl = 𝟙 _ := by
apply (cancel_mono f).mp
simp
-- As with `ofLE`, we have `X` and `Y` as explicit arguments for readability.
/-- An equality of subobjects gives an isomorphism of the corresponding objects.
(One could use `underlying.mapIso (eqToIso h))` here, but this is more readable.) -/
@[simps]
def isoOfEq {B : C} (X Y : Subobject B) (h : X = Y) : (X : C) ≅ (Y : C) where
hom := ofLE _ _ h.le
inv := ofLE _ _ h.ge
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def isoOfEqMk {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X = mk f) : (X : C) ≅ A where
hom := ofLEMk X f h.le
inv := ofMkLE f X h.ge
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def isoOfMkEq {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f = X) : A ≅ (X : C) where
hom := ofMkLE f X h.le
inv := ofLEMk X f h.ge
/-- An equality of subobjects gives an isomorphism of the corresponding objects. -/
@[simps]
def isoOfMkEqMk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f = mk g) :
A₁ ≅ A₂ where
hom := ofMkLEMk f g h.le
inv := ofMkLEMk g f h.ge
lemma mk_lt_mk_of_comm {X A₁ A₂ : C} {i₁ : A₁ ⟶ X} {i₂ : A₂ ⟶ X} [Mono i₁] [Mono i₂]
(f : A₁ ⟶ A₂) (fac : f ≫ i₂ = i₁) (hf : ¬ IsIso f) :
Subobject.mk i₁ < Subobject.mk i₂ := by
obtain _ | h := (mk_le_mk_of_comm _ fac).lt_or_eq
· assumption
· exfalso
apply hf
convert (isoOfMkEqMk i₁ i₂ h).isIso_hom
rw [← cancel_mono i₂, isoOfMkEqMk_hom, ofMkLEMk_comp, fac]
lemma mk_lt_mk_iff_of_comm {X A₁ A₂ : C} {i₁ : A₁ ⟶ X} {i₂ : A₂ ⟶ X} [Mono i₁] [Mono i₂]
(f : A₁ ⟶ A₂) (fac : f ≫ i₂ = i₁) :
Subobject.mk i₁ < Subobject.mk i₂ ↔ ¬ IsIso f :=
⟨fun h hf ↦ by simp only [mk_eq_mk_of_comm i₁ i₂ (asIso f) fac, lt_self_iff_false] at h,
mk_lt_mk_of_comm f fac⟩
end Subobject
namespace MonoOver
variable {P Q : MonoOver X} (f : P ⟶ Q)
include f in
lemma subobjectMk_le_mk_of_hom :
Subobject.mk P.obj.hom ≤ Subobject.mk Q.obj.hom :=
Subobject.mk_le_mk_of_comm f.left (by simp)
lemma isIso_left_iff_subobjectMk_eq :
IsIso f.left ↔ Subobject.mk P.1.hom = Subobject.mk Q.1.hom :=
⟨fun _ ↦ Subobject.mk_eq_mk_of_comm _ _ (asIso f.left) (by simp),
fun h ↦ ⟨Subobject.ofMkLEMk _ _ h.symm.le, by simp [← cancel_mono P.1.hom],
by simp [← cancel_mono Q.1.hom]⟩⟩
lemma isIso_iff_subobjectMk_eq :
IsIso f ↔ Subobject.mk P.1.hom = Subobject.mk Q.1.hom := by
rw [isIso_iff_isIso_left, isIso_left_iff_subobjectMk_eq]
end MonoOver
open CategoryTheory.Limits
namespace Subobject
/-- Any functor `MonoOver X ⥤ MonoOver Y` descends to a functor
`Subobject X ⥤ Subobject Y`, because `MonoOver Y` is thin. -/
def lower {Y : D} (F : MonoOver X ⥤ MonoOver Y) : Subobject X ⥤ Subobject Y :=
ThinSkeleton.map F
/-- Isomorphic functors become equal when lowered to `Subobject`.
(It's not as evil as usual to talk about equality between functors
because the categories are thin and skeletal.) -/
theorem lower_iso (F₁ F₂ : MonoOver X ⥤ MonoOver Y) (h : F₁ ≅ F₂) : lower F₁ = lower F₂ :=
ThinSkeleton.map_iso_eq h
/-- A ternary version of `Subobject.lower`. -/
def lower₂ (F : MonoOver X ⥤ MonoOver Y ⥤ MonoOver Z) : Subobject X ⥤ Subobject Y ⥤ Subobject Z :=
ThinSkeleton.map₂ F
@[simp]
theorem lower_comm (F : MonoOver Y ⥤ MonoOver X) :
toThinSkeleton _ ⋙ lower F = F ⋙ toThinSkeleton _ :=
rfl
/-- An adjunction between `MonoOver A` and `MonoOver B` gives an adjunction
between `Subobject A` and `Subobject B`. -/
def lowerAdjunction {A : C} {B : D} {L : MonoOver A ⥤ MonoOver B} {R : MonoOver B ⥤ MonoOver A}
(h : L ⊣ R) : lower L ⊣ lower R :=
ThinSkeleton.lowerAdjunction _ _ h
/-- An equivalence between `MonoOver A` and `MonoOver B` gives an equivalence
between `Subobject A` and `Subobject B`. -/
@[simps]
def lowerEquivalence {A : C} {B : D} (e : MonoOver A ≌ MonoOver B) : Subobject A ≌ Subobject B where
functor := lower e.functor
inverse := lower e.inverse
unitIso := by
apply eqToIso
convert ThinSkeleton.map_iso_eq e.unitIso
· exact ThinSkeleton.map_id_eq.symm
· exact (ThinSkeleton.map_comp_eq _ _).symm
counitIso := by
apply eqToIso
convert ThinSkeleton.map_iso_eq e.counitIso
· exact (ThinSkeleton.map_comp_eq _ _).symm
· exact ThinSkeleton.map_id_eq.symm
section Pullback
variable [HasPullbacks C]
/-- When `C` has pullbacks, a morphism `f : X ⟶ Y` induces a functor `Subobject Y ⥤ Subobject X`,
by pulling back a monomorphism along `f`. -/
def pullback (f : X ⟶ Y) : Subobject Y ⥤ Subobject X :=
lower (MonoOver.pullback f)
theorem pullback_id (x : Subobject X) : (pullback (𝟙 X)).obj x = x := by
induction' x using Quotient.inductionOn' with f
exact Quotient.sound ⟨MonoOver.pullbackId.app f⟩
theorem pullback_comp (f : X ⟶ Y) (g : Y ⟶ Z) (x : Subobject Z) :
(pullback (f ≫ g)).obj x = (pullback f).obj ((pullback g).obj x) := by
induction' x using Quotient.inductionOn' with t
exact Quotient.sound ⟨(MonoOver.pullbackComp _ _).app t⟩
theorem pullback_obj_mk {A B X Y : C} {f : Y ⟶ X} {i : A ⟶ X} [Mono i]
{j : B ⟶ Y} [Mono j] {f' : B ⟶ A}
(h : IsPullback f' j i f) :
(pullback f).obj (mk i) = mk j :=
((equivMonoOver Y).inverse.mapIso
(MonoOver.pullbackObjIsoOfIsPullback _ _ _ _ h)).to_eq
theorem pullback_obj {X Y : C} (f : Y ⟶ X) (x : Subobject X) :
(pullback f).obj x = mk (pullback.snd x.arrow f) := by
obtain ⟨Z, i, _, rfl⟩ := mk_surjective x
rw [pullback_obj_mk (IsPullback.of_hasPullback i f)]
exact mk_eq_mk_of_comm _ _ (asIso (pullback.map i f (mk i).arrow f
(underlyingIso i).inv (𝟙 _) (𝟙 _) (by simp) (by simp))) (by simp)
instance (f : X ⟶ Y) : (pullback f).Faithful where
end Pullback
section Map
/-- We can map subobjects of `X` to subobjects of `Y`
by post-composition with a monomorphism `f : X ⟶ Y`.
-/
def map (f : X ⟶ Y) [Mono f] : Subobject X ⥤ Subobject Y :=
lower (MonoOver.map f)
lemma map_mk {A X Y : C} (i : A ⟶ X) [Mono i] (f : X ⟶ Y) [Mono f] :
(map f).obj (mk i) = mk (i ≫ f) :=
rfl
theorem map_id (x : Subobject X) : (map (𝟙 X)).obj x = x := by
induction' x using Quotient.inductionOn' with f
exact Quotient.sound ⟨(MonoOver.mapId _).app f⟩
theorem map_comp (f : X ⟶ Y) (g : Y ⟶ Z) [Mono f] [Mono g] (x : Subobject X) :
(map (f ≫ g)).obj x = (map g).obj ((map f).obj x) := by
induction' x using Quotient.inductionOn' with t
exact Quotient.sound ⟨(MonoOver.mapComp _ _).app t⟩
lemma map_obj_injective {X Y : C} (f : X ⟶ Y) [Mono f] :
Function.Injective (Subobject.map f).obj := by
intro X₁ X₂ h
induction' X₁ using Subobject.ind with X₁ i₁ _
induction' X₂ using Subobject.ind with X₂ i₂ _
simp only [map_mk] at h
exact mk_eq_mk_of_comm _ _ (isoOfMkEqMk _ _ h) (by simp [← cancel_mono f])
/-- Isomorphic objects have equivalent subobject lattices. -/
def mapIso {A B : C} (e : A ≅ B) : Subobject A ≌ Subobject B :=
lowerEquivalence (MonoOver.mapIso e)
-- Porting note: the note below doesn't seem true anymore
-- @[simps] here generates a lemma `map_iso_to_order_iso_to_equiv_symm_apply`
-- whose left hand side is not in simp normal form.
/-- In fact, there's a type level bijection between the subobjects of isomorphic objects,
which preserves the order. -/
def mapIsoToOrderIso (e : X ≅ Y) : Subobject X ≃o Subobject Y where
toFun := (map e.hom).obj
invFun := (map e.inv).obj
left_inv g := by simp_rw [← map_comp, e.hom_inv_id, map_id]
right_inv g := by simp_rw [← map_comp, e.inv_hom_id, map_id]
map_rel_iff' {A B} := by
dsimp
constructor
· intro h
apply_fun (map e.inv).obj at h
· simpa only [← map_comp, e.hom_inv_id, map_id] using h
· apply Functor.monotone
· intro h
apply_fun (map e.hom).obj at h
· exact h
· apply Functor.monotone
@[simp]
theorem mapIsoToOrderIso_apply (e : X ≅ Y) (P : Subobject X) :
mapIsoToOrderIso e P = (map e.hom).obj P :=
rfl
@[simp]
theorem mapIsoToOrderIso_symm_apply (e : X ≅ Y) (Q : Subobject Y) :
(mapIsoToOrderIso e).symm Q = (map e.inv).obj Q :=
rfl
/-- `map f : Subobject X ⥤ Subobject Y` is
the left adjoint of `pullback f : Subobject Y ⥤ Subobject X`. -/
def mapPullbackAdj [HasPullbacks C] (f : X ⟶ Y) [Mono f] : map f ⊣ pullback f :=
lowerAdjunction (MonoOver.mapPullbackAdj f)
@[simp]
theorem pullback_map_self [HasPullbacks C] (f : X ⟶ Y) [Mono f] (g : Subobject X) :
(pullback f).obj ((map f).obj g) = g := by
revert g
exact Quotient.ind (fun g' => Quotient.sound ⟨(MonoOver.pullbackMapSelf f).app _⟩)
theorem map_pullback [HasPullbacks C] {X Y Z W : C} {f : X ⟶ Y} {g : X ⟶ Z} {h : Y ⟶ W} {k : Z ⟶ W}
[Mono h] [Mono g] (comm : f ≫ h = g ≫ k) (t : IsLimit (PullbackCone.mk f g comm))
(p : Subobject Y) : (map g).obj ((pullback f).obj p) = (pullback k).obj ((map h).obj p) := by
revert p
apply Quotient.ind'
| intro a
apply Quotient.sound
apply ThinSkeleton.equiv_of_both_ways
· refine MonoOver.homMk (pullback.lift (pullback.fst _ _) _ ?_) (pullback.lift_snd _ _ _)
change _ ≫ a.arrow ≫ h = (pullback.snd _ _ ≫ g) ≫ _
rw [assoc, ← comm, pullback.condition_assoc]
· refine MonoOver.homMk (pullback.lift (pullback.fst _ _)
(PullbackCone.IsLimit.lift t (pullback.fst _ _ ≫ a.arrow) (pullback.snd _ _) _)
(PullbackCone.IsLimit.lift_fst _ _ _ ?_).symm) ?_
· rw [← pullback.condition, assoc]
rfl
· dsimp
rw [pullback.lift_snd_assoc]
apply PullbackCone.IsLimit.lift_snd
end Map
section Exists
| Mathlib/CategoryTheory/Subobject/Basic.lean | 644 | 662 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Deepro Choudhury, Scott Carnahan
-/
import Mathlib.LinearAlgebra.PerfectPairing.Basic
import Mathlib.LinearAlgebra.Reflection
/-!
# Root data and root systems
This file contains basic definitions for root systems and root data.
## Main definitions:
* `RootPairing`: Given two perfectly-paired `R`-modules `M` and `N` (over some commutative ring
`R`) a root pairing with indexing set `ι` is the data of an `ι`-indexed subset of `M`
("the roots") an `ι`-indexed subset of `N` ("the coroots"), and an `ι`-indexed set of
permutations of `ι` such that each root-coroot pair evaluates to `2`, and the permutation
attached to each element of `ι` is compatible with the reflections on the corresponding roots and
coroots.
* `RootDatum`: A root datum is a root pairing for which the roots and coroots take values in
finitely-generated free Abelian groups.
* `RootSystem`: A root system is a root pairing for which the roots span their ambient module.
## Implementation details
A root datum is sometimes defined as two subsets: roots and coroots, together with a bijection
between them, subject to hypotheses. However the hypotheses ensure that the bijection is unique and
so the question arises of whether this bijection should be part of the data of a root datum or
whether one should merely assert its existence. For root systems, things are even more extreme: the
coroots are uniquely determined by the roots. Furthermore a root system induces a canonical
non-degenerate bilinear form on the ambient space and many informal accounts even include this form
as part of the data.
We have opted for a design in which some of the uniquely-determined data is included: the bijection
between roots and coroots is (implicitly) included and the coroots are included for root systems.
Empirically this seems to be by far the most convenient design and by providing extensionality
lemmas expressing the uniqueness we expect to get the best of both worlds.
Furthermore, we require roots and coroots to be injections from a base indexing type `ι` rather than
subsets of their codomains. This design was chosen to avoid the bijection between roots and coroots
being a dependently-typed object. A third option would be to have the roots and coroots be subsets
but to avoid having a dependently-typed bijection by defining it globally with junk value `0`
outside of the roots and coroots. This would work but lacks the convenient symmetry that the chosen
design enjoys: by introducing the indexing type `ι`, one does not have to pick a direction
(`roots → coroots` or `coroots → roots`) for the forward direction of the bijection. Besides,
providing the user with the additional definitional power to specify an indexing type `ι` is a
benefit and the junk-value pattern is a cost.
As a final point of divergence from the classical literature, we make the reflection permutation on
roots and coroots explicit, rather than specifying only that reflection preserves the sets of roots
and coroots. This is necessary when working with infinite root systems, where the coroots are not
uniquely determined by the roots, because without it, the reflection permutations on roots and
coroots may not correspond. For this purpose, we define a map from `ι` to permutations on `ι`, and
require that it is compatible with reflections and coreflections.
-/
open Set Function
open Module hiding reflection
open Submodule (span)
open AddSubgroup (zmultiples)
noncomputable section
variable (ι R M N : Type*)
[CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
/-- Given two perfectly-paired `R`-modules `M` and `N`, a root pairing with indexing set `ι`
is the data of an `ι`-indexed subset of `M` ("the roots"), an `ι`-indexed subset of `N`
("the coroots"), and an `ι`-indexed set of permutations of `ι`, such that each root-coroot pair
evaluates to `2`, and the permutation attached to each element of `ι` is compatible with the
reflections on the corresponding roots and coroots.
It exists to allow for a convenient unification of the theories of root systems and root data. -/
structure RootPairing extends PerfectPairing R M N where
/-- A parametrized family of vectors, called roots. -/
root : ι ↪ M
/-- A parametrized family of dual vectors, called coroots. -/
coroot : ι ↪ N
root_coroot_two : ∀ i, toLinearMap (root i) (coroot i) = 2
/-- A parametrized family of permutations, induced by reflections. This corresponds to the
classical requirement that the symmetry attached to each root (later defined in
`RootPairing.reflection`) leave the whole set of roots stable: as explained above, we
formalize this stability by fixing the image of the roots through each reflection (whence the
permutation); and similarly for coroots. -/
reflection_perm : ι → (ι ≃ ι)
reflection_perm_root : ∀ i j,
root j - toPerfectPairing (root j) (coroot i) • root i = root (reflection_perm i j)
reflection_perm_coroot : ∀ i j,
coroot j - toPerfectPairing (root i) (coroot j) • coroot i = coroot (reflection_perm i j)
/-- A root datum is a root pairing with coefficients in the integers and for which the root and
coroot spaces are finitely-generated free Abelian groups.
Note that the latter assumptions `[Finite ℤ X₁] [Finite ℤ X₂]` should be supplied as mixins, and
that freeness follows automatically since two finitely-generated Abelian groups in perfect pairing
are necessarily free. Moreover Lean knows this, e.g., via `PerfectPairing.reflexive_left`,
`Module.instNoZeroSMulDivisorsOfIsDomain`, `Module.free_of_finite_type_torsion_free'`. -/
abbrev RootDatum (X₁ X₂ : Type*) [AddCommGroup X₁] [AddCommGroup X₂] := RootPairing ι ℤ X₁ X₂
/-- A root system is a root pairing for which the roots and coroots span their ambient modules.
Note that this is slightly more general than the usual definition in the sense that `N` is not
required to be the dual of `M`. -/
structure RootSystem extends RootPairing ι R M N where
span_root_eq_top : span R (range root) = ⊤
span_coroot_eq_top : span R (range coroot) = ⊤
attribute [simp] RootSystem.span_root_eq_top
attribute [simp] RootSystem.span_coroot_eq_top
namespace RootPairing
variable {ι R M N}
variable (P : RootPairing ι R M N) (i j : ι)
@[simp]
lemma toLinearMap_eq_toPerfectPairing (x : M) (y : N) :
P.toLinearMap x y = P.toPerfectPairing x y := rfl
@[deprecated (since := "2025-04-20")]
alias toLin_toPerfectPairing := toLinearMap_eq_toPerfectPairing
/-- If we interchange the roles of `M` and `N`, we still have a root pairing. -/
protected def flip : RootPairing ι R N M :=
{ P.toPerfectPairing.flip with
root := P.coroot
coroot := P.root
root_coroot_two := P.root_coroot_two
reflection_perm := P.reflection_perm
reflection_perm_root := P.reflection_perm_coroot
reflection_perm_coroot := P.reflection_perm_root }
@[simp]
lemma flip_flip : P.flip.flip = P :=
rfl
variable (ι R M N) in
/-- `RootPairing.flip` as an equivalence. -/
@[simps] def flipEquiv : RootPairing ι R N M ≃ RootPairing ι R M N where
toFun P := P.flip
invFun P := P.flip
left_inv _ := rfl
right_inv _ := rfl
/-- If we interchange the roles of `M` and `N`, we still have a root system. -/
protected def _root_.RootSystem.flip (P : RootSystem ι R M N) : RootSystem ι R N M :=
{ toRootPairing := P.toRootPairing.flip
span_root_eq_top := P.span_coroot_eq_top
span_coroot_eq_top := P.span_root_eq_top }
@[simp]
protected lemma _root_.RootSystem.flip_flip (P : RootSystem ι R M N) :
P.flip.flip = P :=
rfl
variable (ι R M N) in
/-- `RootSystem.flip` as an equivalence. -/
@[simps] def _root_.RootSystem.flipEquiv : RootSystem ι R N M ≃ RootSystem ι R M N where
toFun P := P.flip
invFun P := P.flip
left_inv _ := rfl
right_inv _ := rfl
lemma ne_zero [NeZero (2 : R)] : (P.root i : M) ≠ 0 :=
fun h ↦ NeZero.ne' (2 : R) <| by simpa [h] using P.root_coroot_two i
lemma ne_zero' [NeZero (2 : R)] : (P.coroot i : N) ≠ 0 :=
P.flip.ne_zero i
lemma exists_ne_zero [Nonempty ι] [NeZero (2 : R)] : ∃ i, P.root i ≠ 0 := by
obtain ⟨i⟩ := inferInstanceAs (Nonempty ι)
exact ⟨i, P.ne_zero i⟩
lemma exists_ne_zero' [Nonempty ι] [NeZero (2 : R)] : ∃ i, P.coroot i ≠ 0 :=
P.flip.exists_ne_zero
include P in
protected lemma nontrivial [Nonempty ι] [NeZero (2 : R)] : Nontrivial M := by
obtain ⟨i, hi⟩ := P.exists_ne_zero
exact ⟨P.root i, 0, hi⟩
include P in
protected lemma nontrivial' [Nonempty ι] [NeZero (2 : R)] : Nontrivial N :=
P.flip.nontrivial
/-- Roots written as functionals on the coweight space. -/
abbrev root' (i : ι) : Dual R N := P.toPerfectPairing (P.root i)
/-- Coroots written as functionals on the weight space. -/
abbrev coroot' (i : ι) : Dual R M := P.toPerfectPairing.flip (P.coroot i)
/-- This is the pairing between roots and coroots. -/
def pairing : R := P.root' i (P.coroot j)
@[simp]
lemma root_coroot_eq_pairing : P.toPerfectPairing (P.root i) (P.coroot j) = P.pairing i j :=
rfl
@[simp]
lemma root'_coroot_eq_pairing : P.root' i (P.coroot j) = P.pairing i j :=
rfl
@[simp]
lemma root_coroot'_eq_pairing : P.coroot' i (P.root j) = P.pairing j i :=
rfl
lemma coroot_root_eq_pairing : P.toLinearMap.flip (P.coroot i) (P.root j) = P.pairing j i := by
| simp
@[simp]
lemma pairing_same : P.pairing i i = 2 := P.root_coroot_two i
| Mathlib/LinearAlgebra/RootSystem/Defs.lean | 211 | 214 |
/-
Copyright (c) 2024 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker
-/
import Mathlib.Probability.Notation
import Mathlib.Probability.CDF
import Mathlib.Analysis.SpecialFunctions.Gamma.Basic
/-! # Gamma distributions over ℝ
Define the gamma measure over the reals.
## Main definitions
* `gammaPDFReal`: the function `a r x ↦ r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x))`
for `0 ≤ x` or `0` else, which is the probability density function of a gamma distribution with
shape `a` and rate `r` (when `ha : 0 < a ` and `hr : 0 < r`).
* `gammaPDF`: `ℝ≥0∞`-valued pdf,
`gammaPDF a r = ENNReal.ofReal (gammaPDFReal a r)`.
* `gammaMeasure`: a gamma measure on `ℝ`, parametrized by its shape `a` and rate `r`.
* `gammaCDFReal`: the CDF given by the definition of CDF in `ProbabilityTheory.CDF` applied to the
gamma measure.
-/
open scoped ENNReal NNReal
open MeasureTheory Real Set Filter Topology
/-- A Lebesgue Integral from -∞ to y can be expressed as the sum of one from -∞ to 0 and 0 to x -/
lemma lintegral_Iic_eq_lintegral_Iio_add_Icc {y z : ℝ} (f : ℝ → ℝ≥0∞) (hzy : z ≤ y) :
∫⁻ x in Iic y, f x = (∫⁻ x in Iio z, f x) + ∫⁻ x in Icc z y, f x := by
rw [← Iio_union_Icc_eq_Iic hzy, lintegral_union measurableSet_Icc]
simp_rw [Set.disjoint_iff_forall_ne, mem_Iio, mem_Icc]
intros
linarith
namespace ProbabilityTheory
section GammaPDF
/-- The pdf of the gamma distribution depending on its scale and rate -/
noncomputable
def gammaPDFReal (a r x : ℝ) : ℝ :=
if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x)) else 0
/-- The pdf of the gamma distribution, as a function valued in `ℝ≥0∞` -/
noncomputable
def gammaPDF (a r x : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (gammaPDFReal a r x)
lemma gammaPDF_eq (a r x : ℝ) :
gammaPDF a r x =
ENNReal.ofReal (if 0 ≤ x then r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x)) else 0) :=
rfl
lemma gammaPDF_of_neg {a r x : ℝ} (hx : x < 0) : gammaPDF a r x = 0 := by
simp only [gammaPDF_eq, if_neg (not_le.mpr hx), ENNReal.ofReal_zero]
lemma gammaPDF_of_nonneg {a r x : ℝ} (hx : 0 ≤ x) :
gammaPDF a r x = ENNReal.ofReal (r ^ a / (Gamma a) * x ^ (a-1) * exp (-(r * x))) := by
simp only [gammaPDF_eq, if_pos hx]
/-- The Lebesgue integral of the gamma pdf over nonpositive reals equals 0 -/
lemma lintegral_gammaPDF_of_nonpos {x a r : ℝ} (hx : x ≤ 0) :
∫⁻ y in Iio x, gammaPDF a r y = 0 := by
rw [setLIntegral_congr_fun (g := fun _ ↦ 0) measurableSet_Iio]
· rw [lintegral_zero, ← ENNReal.ofReal_zero]
· simp only [gammaPDF_eq, ENNReal.ofReal_eq_zero]
filter_upwards with a (_ : a < _)
rw [if_neg (by linarith)]
/-- The gamma pdf is measurable. -/
@[measurability]
lemma measurable_gammaPDFReal (a r : ℝ) : Measurable (gammaPDFReal a r) :=
Measurable.ite measurableSet_Ici (((measurable_id'.pow_const _).const_mul _).mul
(measurable_id'.const_mul _).neg.exp) measurable_const
/-- The gamma pdf is strongly measurable -/
@[measurability]
lemma stronglyMeasurable_gammaPDFReal (a r : ℝ) :
StronglyMeasurable (gammaPDFReal a r) :=
(measurable_gammaPDFReal a r).stronglyMeasurable
/-- The gamma pdf is positive for all positive reals -/
lemma gammaPDFReal_pos {x a r : ℝ} (ha : 0 < a) (hr : 0 < r) (hx : 0 < x) :
0 < gammaPDFReal a r x := by
simp only [gammaPDFReal, if_pos hx.le]
positivity
/-- The gamma pdf is nonnegative -/
lemma gammaPDFReal_nonneg {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (x : ℝ) :
0 ≤ gammaPDFReal a r x := by
unfold gammaPDFReal
split_ifs <;> positivity
open Measure
/-- The pdf of the gamma distribution integrates to 1 -/
@[simp]
lemma lintegral_gammaPDF_eq_one {a r : ℝ} (ha : 0 < a) (hr : 0 < r) :
∫⁻ x, gammaPDF a r x = 1 := by
have leftSide : ∫⁻ x in Iio 0, gammaPDF a r x = 0 := by
rw [setLIntegral_congr_fun measurableSet_Iio
(ae_of_all _ (fun x (hx : x < 0) ↦ gammaPDF_of_neg hx)), lintegral_zero]
have rightSide : ∫⁻ x in Ici 0, gammaPDF a r x =
∫⁻ x in Ici 0, ENNReal.ofReal (r ^ a / Gamma a * x ^ (a - 1) * exp (-(r * x))) :=
setLIntegral_congr_fun measurableSet_Ici (ae_of_all _ (fun _ ↦ gammaPDF_of_nonneg))
rw [← ENNReal.toReal_eq_one_iff, ← lintegral_add_compl _ measurableSet_Ici, compl_Ici,
leftSide, rightSide, add_zero, ← integral_eq_lintegral_of_nonneg_ae]
· simp_rw [integral_Ici_eq_integral_Ioi, mul_assoc]
rw [integral_const_mul, integral_rpow_mul_exp_neg_mul_Ioi ha hr, div_mul_eq_mul_div,
← mul_assoc, mul_div_assoc, div_self (Gamma_pos_of_pos ha).ne', mul_one,
div_rpow zero_le_one hr.le, one_rpow, mul_one_div, div_self (rpow_pos_of_pos hr _).ne']
· rw [EventuallyLE, ae_restrict_iff' measurableSet_Ici]
exact ae_of_all _ (fun x (hx : 0 ≤ x) ↦ by positivity)
· apply (measurable_gammaPDFReal a r).aestronglyMeasurable.congr
refine (ae_restrict_iff' measurableSet_Ici).mpr <| ae_of_all _ fun x (hx : 0 ≤ x) ↦ ?_
simp_rw [gammaPDFReal, eq_true_intro hx, ite_true]
end GammaPDF
open MeasureTheory
/-- Measure defined by the gamma distribution -/
noncomputable
def gammaMeasure (a r : ℝ) : Measure ℝ :=
volume.withDensity (gammaPDF a r)
|
lemma isProbabilityMeasureGamma {a r : ℝ} (ha : 0 < a) (hr : 0 < r) :
IsProbabilityMeasure (gammaMeasure a r) where
| Mathlib/Probability/Distributions/Gamma.lean | 128 | 130 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mitchell Lee
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Indicator
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Topology.Algebra.InfiniteSum.Defs
import Mathlib.Topology.Algebra.Monoid.Defs
/-!
# Lemmas on infinite sums and products in topological monoids
This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to
keep the basic file of definitions as short as possible.
Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`.
-/
noncomputable section
open Filter Finset Function Topology
variable {α β γ : Type*}
section HasProd
variable [CommMonoid α] [TopologicalSpace α]
variable {f g : β → α} {a b : α}
/-- Constant one function has product `1` -/
@[to_additive "Constant zero function has sum `0`"]
theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds]
@[to_additive]
theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by
convert @hasProd_one α β _ _
@[to_additive]
theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) :=
hasProd_one.multipliable
@[to_additive]
theorem multipliable_empty [IsEmpty β] : Multipliable f :=
hasProd_empty.multipliable
/-- See `multipliable_congr_cofinite` for a version allowing the functions to
disagree on a finite set. -/
@[to_additive "See `summable_congr_cofinite` for a version allowing the functions to
disagree on a finite set."]
theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g :=
iff_of_eq (congr_arg Multipliable <| funext hfg)
/-- See `Multipliable.congr_cofinite` for a version allowing the functions to
disagree on a finite set. -/
@[to_additive "See `Summable.congr_cofinite` for a version allowing the functions to
disagree on a finite set."]
theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g :=
(multipliable_congr hfg).mp hf
@[to_additive]
lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a :=
(funext h : g = f) ▸ hf
@[to_additive]
theorem HasProd.hasProd_of_prod_eq {g : γ → α}
(h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' →
∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b)
(hf : HasProd g a) : HasProd f a :=
le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf
@[to_additive]
theorem hasProd_iff_hasProd {g : γ → α}
(h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' →
∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b)
(h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' →
∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) :
HasProd f a ↔ HasProd g a :=
⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩
@[to_additive]
theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g)
(hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f :=
exists_congr fun _ ↦ hg.hasProd_iff hf
@[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) :
HasProd (extend g f 1) a ↔ HasProd f a := by
rw [← hg.hasProd_iff, extend_comp hg]
exact extend_apply' _ _
@[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) :
Multipliable (extend g f 1) ↔ Multipliable f :=
exists_congr fun _ ↦ hasProd_extend_one hg
@[to_additive]
theorem hasProd_subtype_iff_mulIndicator {s : Set β} :
HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by
rw [← Set.mulIndicator_range_comp, Subtype.range_coe,
hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset]
@[to_additive]
theorem multipliable_subtype_iff_mulIndicator {s : Set β} :
Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) :=
exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator
@[to_additive (attr := simp)]
theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a :=
hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _
@[to_additive]
protected theorem Finset.multipliable (s : Finset β) (f : β → α) :
Multipliable (f ∘ (↑) : (↑s : Set β) → α) :=
(s.hasProd f).multipliable
@[to_additive]
protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) :
Multipliable (f ∘ (↑) : s → α) := by
have := hs.toFinset.multipliable f
rwa [hs.coe_toFinset] at this
@[to_additive]
theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by
apply multipliable_of_ne_finset_one (s := h.toFinset); simp
@[to_additive]
lemma Multipliable.of_finite [Finite β] {f : β → α} : Multipliable f :=
multipliable_of_finite_mulSupport <| Set.finite_univ.subset (Set.subset_univ _)
@[to_additive]
theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) :=
suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this
hasProd_prod_of_ne_finset_one <| by simpa [hf]
@[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) :=
hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..)
@[to_additive (attr := simp)]
lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) :=
hasProd_unique (Set.restrict {m} f)
@[to_additive]
theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) :
HasProd (fun b' ↦ if b' = b then a else 1) a := by
convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb')
exact (if_pos rfl).symm
@[to_additive]
theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a :=
e.injective.hasProd_iff <| by simp
@[to_additive]
| theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) :
HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a :=
(Equiv.ofInjective g hg).hasProd_iff.symm
| Mathlib/Topology/Algebra/InfiniteSum/Basic.lean | 153 | 156 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.InitTail
/-!
# Truncated Witt vectors
The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors.
It retains the first `n` coefficients of each Witt vector.
In this file, we set up the basic quotient API for this ring.
The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors.
## Main declarations
- `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors
- `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors
- `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector,
to obtain a truncated Witt vector
- `TruncatedWittVector.truncate`: the homomorphism that truncates
a truncated Witt vector of length `n` to one of length `m` (for some `m ≤ n`)
- `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors
that is compatible with a family of ring homomorphisms to the truncated Witt vectors:
this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open Function (Injective Surjective)
noncomputable section
variable {p : ℕ} (n : ℕ) (R : Type*)
local notation "𝕎" => WittVector p -- type as `\bbW`
/-- A truncated Witt vector over `R` is a vector of elements of `R`,
i.e., the first `n` coefficients of a Witt vector.
We will define operations on this type that are compatible with the (untruncated) Witt
vector operations.
`TruncatedWittVector p n R` takes a parameter `p : ℕ` that is not used in the definition.
In practice, this number `p` is assumed to be a prime number,
and under this assumption we construct a ring structure on `TruncatedWittVector p n R`.
(`TruncatedWittVector p₁ n R` and `TruncatedWittVector p₂ n R` are definitionally
equal as types but will have different ring operations.)
-/
@[nolint unusedArguments]
def TruncatedWittVector (_ : ℕ) (n : ℕ) (R : Type*) :=
Fin n → R
instance (p n : ℕ) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) :=
⟨fun _ => default⟩
variable {n R}
namespace TruncatedWittVector
variable (p) in
/-- Create a `TruncatedWittVector` from a vector `x`. -/
def mk (x : Fin n → R) : TruncatedWittVector p n R :=
x
/-- `x.coeff i` is the `i`th entry of `x`. -/
def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R :=
x i
@[ext]
theorem ext {x y : TruncatedWittVector p n R} (h : ∀ i, x.coeff i = y.coeff i) : x = y :=
funext h
@[simp]
theorem coeff_mk (x : Fin n → R) (i : Fin n) : (mk p x).coeff i = x i :=
rfl
@[simp]
theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by
ext i; rw [coeff_mk]
variable [CommRing R]
/-- We can turn a truncated Witt vector `x` into a Witt vector
by setting all coefficients after `x` to be 0.
-/
def out (x : TruncatedWittVector p n R) : 𝕎 R :=
@WittVector.mk' p _ fun i => if h : i < n then x.coeff ⟨i, h⟩ else 0
@[simp]
theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by
rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta]
theorem out_injective : Injective (@out p n R _) := by
intro x y h
ext i
rw [WittVector.ext_iff] at h
simpa only [coeff_out] using h ↑i
end TruncatedWittVector
namespace WittVector
variable (n)
section
/-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`,
which has the same base `p` as `x`.
This function is bundled into a ring homomorphism in `WittVector.truncate` -/
def truncateFun (x : 𝕎 R) : TruncatedWittVector p n R :=
TruncatedWittVector.mk p fun i => x.coeff i
end
variable {n}
@[simp]
theorem coeff_truncateFun (x : 𝕎 R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by
rw [truncateFun, TruncatedWittVector.coeff_mk]
variable [CommRing R]
@[simp]
theorem out_truncateFun (x : 𝕎 R) : (truncateFun n x).out = init n x := by
ext i
dsimp [TruncatedWittVector.out, init, select, coeff_mk]
split_ifs with hi; swap; · rfl
rw [coeff_truncateFun, Fin.val_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
@[simp]
theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by
simp only [WittVector.truncateFun, coeff_out, mk_coeff]
open WittVector
variable (p n R)
variable [Fact p.Prime]
instance : Zero (TruncatedWittVector p n R) :=
⟨truncateFun n 0⟩
instance : One (TruncatedWittVector p n R) :=
⟨truncateFun n 1⟩
instance : NatCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : IntCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : Add (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out + y.out)⟩
instance : Mul (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out * y.out)⟩
instance : Neg (TruncatedWittVector p n R) :=
⟨fun x => truncateFun n (-x.out)⟩
instance : Sub (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out - y.out)⟩
instance hasNatScalar : SMul ℕ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasIntScalar : SMul ℤ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasNatPow : Pow (TruncatedWittVector p n R) ℕ :=
⟨fun x m => truncateFun n (x.out ^ m)⟩
@[simp]
theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by
show coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0
rw [coeff_truncateFun, WittVector.zero_coeff]
end TruncatedWittVector
/-- A macro tactic used to prove that `truncateFun` respects ring operations. -/
macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic =>
`(tactic|
{ show _ = WittVector.truncateFun n _
apply TruncatedWittVector.out_injective
iterate rw [WittVector.out_truncateFun]
first
| rw [WittVector.init_add]
| rw [WittVector.init_mul]
| rw [WittVector.init_neg]
| rw [WittVector.init_sub]
| rw [WittVector.init_nsmul]
| rw [WittVector.init_zsmul]
| rw [WittVector.init_pow]})
namespace WittVector
variable (p n R)
variable [CommRing R]
theorem truncateFun_surjective : Surjective (@truncateFun p n R) :=
Function.RightInverse.surjective TruncatedWittVector.truncateFun_out
variable [Fact p.Prime]
@[simp]
theorem truncateFun_zero : truncateFun n (0 : 𝕎 R) = 0 := rfl
@[simp]
theorem truncateFun_one : truncateFun n (1 : 𝕎 R) = 1 := rfl
variable {p R}
@[simp]
theorem truncateFun_add (x y : 𝕎 R) :
truncateFun n (x + y) = truncateFun n x + truncateFun n y := by
witt_truncateFun_tac
@[simp]
theorem truncateFun_mul (x y : 𝕎 R) :
truncateFun n (x * y) = truncateFun n x * truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_neg (x : 𝕎 R) : truncateFun n (-x) = -truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_sub (x y : 𝕎 R) :
truncateFun n (x - y) = truncateFun n x - truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_nsmul (m : ℕ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_zsmul (m : ℤ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_pow (x : 𝕎 R) (m : ℕ) : truncateFun n (x ^ m) = truncateFun n x ^ m := by
witt_truncateFun_tac
theorem truncateFun_natCast (m : ℕ) : truncateFun n (m : 𝕎 R) = m := rfl
theorem truncateFun_intCast (m : ℤ) : truncateFun n (m : 𝕎 R) = m := rfl
end WittVector
namespace TruncatedWittVector
open WittVector
variable (p n R)
variable [CommRing R]
variable [Fact p.Prime]
instance instCommRing : CommRing (TruncatedWittVector p n R) :=
(truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R)
| (truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n)
(truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n)
(truncateFun_intCast n)
| Mathlib/RingTheory/WittVector/Truncated.lean | 268 | 270 |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import Mathlib.Algebra.Field.Subfield.Defs
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.Normed.Ring.Basic
/-!
# Normed division rings and fields
In this file we define normed fields, and (more generally) normed division rings. We also prove
some theorems about these definitions.
Some useful results that relate the topology of the normed field to the discrete topology include:
* `norm_eq_one_iff_ne_zero_of_discrete`
Methods for constructing a normed field instance from a given real absolute value on a field are
given in:
* AbsoluteValue.toNormedField
-/
-- Guard against import creep.
assert_not_exists AddChar comap_norm_atTop DilationEquiv Finset.sup_mul_le_mul_sup_of_nonneg
IsOfFinOrder Isometry.norm_map_of_map_one NNReal.isOpen_Ico_zero Rat.norm_cast_real
RestrictScalars
variable {G α β ι : Type*}
open Filter
open scoped Topology NNReal ENNReal
/-- A normed division ring is a division ring endowed with a seminorm which satisfies the equality
`‖x y‖ = ‖x‖ ‖y‖`. -/
class NormedDivisionRing (α : Type*) extends Norm α, DivisionRing α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is multiplicative. -/
protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b
-- see Note [lower instance priority]
/-- A normed division ring is a normed ring. -/
instance (priority := 100) NormedDivisionRing.toNormedRing [β : NormedDivisionRing α] :
NormedRing α :=
{ β with norm_mul_le a b := (NormedDivisionRing.norm_mul a b).le }
-- see Note [lower instance priority]
/-- The norm on a normed division ring is strictly multiplicative. -/
instance (priority := 100) NormedDivisionRing.toNormMulClass [NormedDivisionRing α] :
NormMulClass α where
norm_mul := NormedDivisionRing.norm_mul
section NormedDivisionRing
variable [NormedDivisionRing α] {a b : α}
instance (priority := 900) NormedDivisionRing.to_normOneClass : NormOneClass α :=
⟨mul_left_cancel₀ (mt norm_eq_zero.1 (one_ne_zero' α)) <| by rw [← norm_mul, mul_one, mul_one]⟩
@[simp]
theorem norm_div (a b : α) : ‖a / b‖ = ‖a‖ / ‖b‖ :=
map_div₀ (normHom : α →*₀ ℝ) a b
@[simp]
theorem nnnorm_div (a b : α) : ‖a / b‖₊ = ‖a‖₊ / ‖b‖₊ :=
map_div₀ (nnnormHom : α →*₀ ℝ≥0) a b
@[simp]
theorem norm_inv (a : α) : ‖a⁻¹‖ = ‖a‖⁻¹ :=
map_inv₀ (normHom : α →*₀ ℝ) a
@[simp]
theorem nnnorm_inv (a : α) : ‖a⁻¹‖₊ = ‖a‖₊⁻¹ :=
NNReal.eq <| by simp
@[simp]
lemma enorm_inv {a : α} (ha : a ≠ 0) : ‖a⁻¹‖ₑ = ‖a‖ₑ⁻¹ := by simp [enorm, ENNReal.coe_inv, ha]
@[simp]
theorem norm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖ = ‖a‖ ^ n :=
map_zpow₀ (normHom : α →*₀ ℝ)
@[simp]
theorem nnnorm_zpow : ∀ (a : α) (n : ℤ), ‖a ^ n‖₊ = ‖a‖₊ ^ n :=
map_zpow₀ (nnnormHom : α →*₀ ℝ≥0)
theorem dist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) :
dist z⁻¹ w⁻¹ = dist z w / (‖z‖ * ‖w‖) := by
rw [dist_eq_norm, inv_sub_inv' hz hw, norm_mul, norm_mul, norm_inv, norm_inv, mul_comm ‖z‖⁻¹,
mul_assoc, dist_eq_norm', div_eq_mul_inv, mul_inv]
theorem nndist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) :
nndist z⁻¹ w⁻¹ = nndist z w / (‖z‖₊ * ‖w‖₊) :=
NNReal.eq <| dist_inv_inv₀ hz hw
lemma norm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) :
‖a * b * a⁻¹ * b⁻¹ - 1‖ ≤ 2 * ‖a‖⁻¹ * ‖b‖⁻¹ * ‖a - 1‖ * ‖b - 1‖ := by
simpa using norm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb)
lemma nnnorm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) :
‖a * b * a⁻¹ * b⁻¹ - 1‖₊ ≤ 2 * ‖a‖₊⁻¹ * ‖b‖₊⁻¹ * ‖a - 1‖₊ * ‖b - 1‖₊ := by
simpa using nnnorm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb)
namespace NormedDivisionRing
section Discrete
variable {𝕜 : Type*} [NormedDivisionRing 𝕜] [DiscreteTopology 𝕜]
lemma norm_eq_one_iff_ne_zero_of_discrete {x : 𝕜} : ‖x‖ = 1 ↔ x ≠ 0 := by
constructor <;> intro hx
· contrapose! hx
simp [hx]
· have : IsOpen {(0 : 𝕜)} := isOpen_discrete {0}
simp_rw [Metric.isOpen_singleton_iff, dist_eq_norm, sub_zero] at this
obtain ⟨ε, εpos, h'⟩ := this
wlog h : ‖x‖ < 1 generalizing 𝕜 with H
· push_neg at h
rcases h.eq_or_lt with h|h
· rw [h]
replace h := norm_inv x ▸ inv_lt_one_of_one_lt₀ h
rw [← inv_inj, inv_one, ← norm_inv]
exact H (by simpa) h' h
obtain ⟨k, hk⟩ : ∃ k : ℕ, ‖x‖ ^ k < ε := exists_pow_lt_of_lt_one εpos h
rw [← norm_pow] at hk
specialize h' _ hk
simp [hx] at h'
@[simp]
lemma norm_le_one_of_discrete
(x : 𝕜) : ‖x‖ ≤ 1 := by
rcases eq_or_ne x 0 with rfl|hx
· simp
· simp [norm_eq_one_iff_ne_zero_of_discrete.mpr hx]
lemma unitClosedBall_eq_univ_of_discrete : (Metric.closedBall 0 1 : Set 𝕜) = Set.univ := by
ext
simp
@[deprecated (since := "2024-12-01")]
alias discreteTopology_unit_closedBall_eq_univ := unitClosedBall_eq_univ_of_discrete
end Discrete
end NormedDivisionRing
end NormedDivisionRing
/-- A normed field is a field with a norm satisfying ‖x y‖ = ‖x‖ ‖y‖. -/
class NormedField (α : Type*) extends Norm α, Field α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is multiplicative. -/
protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b
/-- A nontrivially normed field is a normed field in which there is an element of norm different
from `0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by
multiplication by the powers of any element, and thus to relate algebra and topology. -/
class NontriviallyNormedField (α : Type*) extends NormedField α where
/-- The norm attains a value exceeding 1. -/
non_trivial : ∃ x : α, 1 < ‖x‖
/-- A densely normed field is a normed field for which the image of the norm is dense in `ℝ≥0`,
which means it is also nontrivially normed. However, not all nontrivally normed fields are densely
normed; in particular, the `Padic`s exhibit this fact. -/
class DenselyNormedField (α : Type*) extends NormedField α where
/-- The range of the norm is dense in the collection of nonnegative real numbers. -/
lt_norm_lt : ∀ x y : ℝ, 0 ≤ x → x < y → ∃ a : α, x < ‖a‖ ∧ ‖a‖ < y
section NormedField
/-- A densely normed field is always a nontrivially normed field.
See note [lower instance priority]. -/
instance (priority := 100) DenselyNormedField.toNontriviallyNormedField [DenselyNormedField α] :
NontriviallyNormedField α where
non_trivial :=
let ⟨a, h, _⟩ := DenselyNormedField.lt_norm_lt 1 2 zero_le_one one_lt_two
⟨a, h⟩
variable [NormedField α]
-- see Note [lower instance priority]
instance (priority := 100) NormedField.toNormedDivisionRing : NormedDivisionRing α :=
{ ‹NormedField α› with }
-- see Note [lower instance priority]
instance (priority := 100) NormedField.toNormedCommRing : NormedCommRing α :=
{ ‹NormedField α› with norm_mul_le a b := (norm_mul a b).le }
end NormedField
namespace NormedField
section Nontrivially
variable (α) [NontriviallyNormedField α]
theorem exists_one_lt_norm : ∃ x : α, 1 < ‖x‖ :=
‹NontriviallyNormedField α›.non_trivial
theorem exists_one_lt_nnnorm : ∃ x : α, 1 < ‖x‖₊ := exists_one_lt_norm α
theorem exists_one_lt_enorm : ∃ x : α, 1 < ‖x‖ₑ :=
exists_one_lt_nnnorm α |>.imp fun _ => ENNReal.coe_lt_coe.mpr
theorem exists_lt_norm (r : ℝ) : ∃ x : α, r < ‖x‖ :=
let ⟨w, hw⟩ := exists_one_lt_norm α
let ⟨n, hn⟩ := pow_unbounded_of_one_lt r hw
⟨w ^ n, by rwa [norm_pow]⟩
theorem exists_lt_nnnorm (r : ℝ≥0) : ∃ x : α, r < ‖x‖₊ := exists_lt_norm α r
theorem exists_lt_enorm {r : ℝ≥0∞} (hr : r ≠ ∞) : ∃ x : α, r < ‖x‖ₑ := by
lift r to ℝ≥0 using hr
exact mod_cast exists_lt_nnnorm α r
theorem exists_norm_lt {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < r :=
let ⟨w, hw⟩ := exists_lt_norm α r⁻¹
⟨w⁻¹, by rwa [← Set.mem_Ioo, norm_inv, ← Set.mem_inv, Set.inv_Ioo_0_left hr]⟩
theorem exists_nnnorm_lt {r : ℝ≥0} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < r :=
exists_norm_lt α hr
/-- TODO: merge with `_root_.exists_enorm_lt`. -/
theorem exists_enorm_lt {r : ℝ≥0∞} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < r :=
match r with
| ∞ => exists_one_lt_enorm α |>.imp fun _ hx => ⟨zero_le_one.trans_lt hx, ENNReal.coe_lt_top⟩
| (r : ℝ≥0) => exists_nnnorm_lt α (ENNReal.coe_pos.mp hr) |>.imp fun _ =>
And.imp ENNReal.coe_pos.mpr ENNReal.coe_lt_coe.mpr
theorem exists_norm_lt_one : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < 1 :=
exists_norm_lt α one_pos
theorem exists_nnnorm_lt_one : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < 1 := exists_norm_lt_one _
theorem exists_enorm_lt_one : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < 1 := exists_enorm_lt _ one_pos
variable {α}
@[instance]
theorem nhdsNE_neBot (x : α) : NeBot (𝓝[≠] x) := by
rw [← mem_closure_iff_nhdsWithin_neBot, Metric.mem_closure_iff]
rintro ε ε0
rcases exists_norm_lt α ε0 with ⟨b, hb0, hbε⟩
refine ⟨x + b, mt (Set.mem_singleton_iff.trans add_eq_left).1 <| norm_pos_iff.1 hb0, ?_⟩
rwa [dist_comm, dist_eq_norm, add_sub_cancel_left]
@[deprecated (since := "2025-03-02")]
alias punctured_nhds_neBot := nhdsNE_neBot
@[instance]
theorem nhdsWithin_isUnit_neBot : NeBot (𝓝[{ x : α | IsUnit x }] 0) := by
simpa only [isUnit_iff_ne_zero] using nhdsNE_neBot (0 : α)
end Nontrivially
section Densely
variable (α) [DenselyNormedField α]
theorem exists_lt_norm_lt {r₁ r₂ : ℝ} (h₀ : 0 ≤ r₁) (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖ ∧ ‖x‖ < r₂ :=
DenselyNormedField.lt_norm_lt r₁ r₂ h₀ h
theorem exists_lt_nnnorm_lt {r₁ r₂ : ℝ≥0} (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖₊ ∧ ‖x‖₊ < r₂ :=
mod_cast exists_lt_norm_lt α r₁.prop h
instance denselyOrdered_range_norm : DenselyOrdered (Set.range (norm : α → ℝ)) where
dense := by
rintro ⟨-, x, rfl⟩ ⟨-, y, rfl⟩ hxy
let ⟨z, h⟩ := exists_lt_norm_lt α (norm_nonneg _) hxy
exact ⟨⟨‖z‖, z, rfl⟩, h⟩
instance denselyOrdered_range_nnnorm : DenselyOrdered (Set.range (nnnorm : α → ℝ≥0)) where
dense := by
rintro ⟨-, x, rfl⟩ ⟨-, y, rfl⟩ hxy
let ⟨z, h⟩ := exists_lt_nnnorm_lt α hxy
exact ⟨⟨‖z‖₊, z, rfl⟩, h⟩
end Densely
end NormedField
/-- A normed field is nontrivially normed
provided that the norm of some nonzero element is not one. -/
def NontriviallyNormedField.ofNormNeOne {𝕜 : Type*} [h' : NormedField 𝕜]
(h : ∃ x : 𝕜, x ≠ 0 ∧ ‖x‖ ≠ 1) : NontriviallyNormedField 𝕜 where
toNormedField := h'
non_trivial := by
rcases h with ⟨x, hx, hx1⟩
rcases hx1.lt_or_lt with hlt | hlt
· use x⁻¹
rw [norm_inv]
exact (one_lt_inv₀ (norm_pos_iff.2 hx)).2 hlt
· exact ⟨x, hlt⟩
noncomputable instance Real.normedField : NormedField ℝ :=
{ Real.normedAddCommGroup, Real.field with
norm_mul := abs_mul }
noncomputable instance Real.denselyNormedField : DenselyNormedField ℝ where
lt_norm_lt _ _ h₀ hr :=
let ⟨x, h⟩ := exists_between hr
⟨x, by rwa [Real.norm_eq_abs, abs_of_nonneg (h₀.trans h.1.le)]⟩
namespace Real
theorem toNNReal_mul_nnnorm {x : ℝ} (y : ℝ) (hx : 0 ≤ x) : x.toNNReal * ‖y‖₊ = ‖x * y‖₊ := by
ext
simp only [NNReal.coe_mul, nnnorm_mul, coe_nnnorm, Real.toNNReal_of_nonneg, norm_of_nonneg, hx,
NNReal.coe_mk]
theorem nnnorm_mul_toNNReal (x : ℝ) {y : ℝ} (hy : 0 ≤ y) : ‖x‖₊ * y.toNNReal = ‖x * y‖₊ := by
rw [mul_comm, mul_comm x, toNNReal_mul_nnnorm x hy]
end Real
/-! ### Induced normed structures -/
section Induced
variable {F : Type*} (R S : Type*) [FunLike F R S]
/-- An injective non-unital ring homomorphism from a `DivisionRing` to a `NormedRing` induces a
`NormedDivisionRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedDivisionRing.induced [DivisionRing R] [NormedDivisionRing S]
[NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NormedDivisionRing R :=
{ NormedAddCommGroup.induced R S f hf, ‹DivisionRing R› with
norm_mul x y := show ‖f _‖ = _ from (map_mul f x y).symm ▸ norm_mul (f x) (f y) }
/-- An injective non-unital ring homomorphism from a `Field` to a `NormedRing` induces a
`NormedField` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedField.induced [Field R] [NormedField S] [NonUnitalRingHomClass F R S] (f : F)
(hf : Function.Injective f) : NormedField R :=
{ NormedDivisionRing.induced R S f hf with
mul_comm := mul_comm }
end Induced
namespace SubfieldClass
variable {S F : Type*} [SetLike S F]
/--
If `s` is a subfield of a normed field `F`, then `s` is equipped with an induced normed
field structure.
-/
instance toNormedField [NormedField F] [SubfieldClass S F] (s : S) : NormedField s :=
NormedField.induced s F (SubringClass.subtype s) Subtype.val_injective
end SubfieldClass
namespace AbsoluteValue
/-- A real absolute value on a field determines a `NormedField` structure. -/
noncomputable def toNormedField {K : Type*} [Field K] (v : AbsoluteValue K ℝ) : NormedField K where
toField := inferInstanceAs (Field K)
__ := v.toNormedRing
norm_mul := v.map_mul
end AbsoluteValue
| Mathlib/Analysis/Normed/Field/Basic.lean | 975 | 977 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.CoreAttrs
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends PartialOrder α where
/-- The binary supremum, used to derive `Max α` -/
sup : α → α → α
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ sup a b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ sup a b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c
instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by rw [← sup_assoc, sup_idem]
le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by rwa [sup_assoc, hbc]
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
@[gcongr]
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂)
@[gcongr]
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
sup_le_sup le_rfl h₁
@[gcongr]
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
sup_le_sup h₁ le_rfl
theorem sup_idem (a : α) : a ⊔ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp
instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc]
instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩
theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by
rw [sup_comm, sup_comm a, sup_assoc]
theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp
theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp
theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by
rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by
rw [sup_assoc, sup_assoc, sup_comm b]
theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by
rw [sup_assoc, sup_left_comm b, ← sup_assoc]
theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c :=
(sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc
| Mathlib/Order/Lattice.lean | 219 | 219 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Notation.Pi
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Filter.Defs
/-!
# Theory of filters on sets
A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`,
is upwards-closed, and is stable under intersection. They are mostly used to
abstract two related kinds of ideas:
* *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions
at a point or at infinity, etc...
* *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough
a point `x`, or for close enough pairs of points, or things happening almost everywhere in the
sense of measure theory. Dually, filters can also express the idea of *things happening often*:
for arbitrarily large `n`, or at a point in any neighborhood of given a point etc...
## Main definitions
In this file, we endow `Filter α` it with a complete lattice structure.
This structure is lifted from the lattice structure on `Set (Set X)` using the Galois
insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to
the smallest filter containing it in the other direction.
We also prove `Filter` is a monadic functor, with a push-forward operation
`Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the
order on filters.
The examples of filters appearing in the description of the two motivating ideas are:
* `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N`
* `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic)
* `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces
defined in `Mathlib/Topology/UniformSpace/Basic.lean`)
* `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ`
(defined in `Mathlib/MeasureTheory/OuterMeasure/AE`)
The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is
`Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come
rather late in this file in order to immediately relate them to the lattice structure).
## Notations
* `∀ᶠ x in f, p x` : `f.Eventually p`;
* `∃ᶠ x in f, p x` : `f.Frequently p`;
* `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`;
* `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`;
* `𝓟 s` : `Filter.Principal s`, localized in `Filter`.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which
we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element
`⊥` for its lattice structure, at the cost of including the assumption
`[NeBot f]` in a number of lemmas and definitions.
-/
assert_not_exists OrderedSemiring Fintype
open Function Set Order
open scoped symmDiff
universe u v w x y
namespace Filter
variable {α : Type u} {f g : Filter α} {s t : Set α}
instance inhabitedMem : Inhabited { s : Set α // s ∈ f } :=
⟨⟨univ, f.univ_sets⟩⟩
theorem filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
@[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl
@[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl
/-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g.,
`Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/
protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g :=
Filter.ext <| compl_surjective.forall.2 h
instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where
trans h₁ h₂ := mem_of_superset h₂ h₁
instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where
trans h₁ h₂ := mem_of_superset h₁ h₂
@[simp]
theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f :=
⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩,
and_imp.2 inter_mem⟩
theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f :=
inter_mem hs ht
theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f :=
⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs =>
mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩
lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem
/-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by
apply Subsingleton.induction_on hf <;> simp
/-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] :
(⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by
rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range]
theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩
theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h =>
mem_of_superset h hst
theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P)
(hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by
constructor
· rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩
exact
⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩
· rintro ⟨u, huf, hPu, hQu⟩
exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩
theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} :
(∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b :=
Set.forall_in_swap
end Filter
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x}
theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl
section Lattice
variable {f g : Filter α} {s t : Set α}
protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop]
/-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/
inductive GenerateSets (g : Set (Set α)) : Set α → Prop
| basic {s : Set α} : s ∈ g → GenerateSets g s
| univ : GenerateSets g univ
| superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t
| inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t)
/-- `generate g` is the largest filter containing the sets `g`. -/
def generate (g : Set (Set α)) : Filter α where
sets := {s | GenerateSets g s}
univ_sets := GenerateSets.univ
sets_of_superset := GenerateSets.superset
inter_sets := GenerateSets.inter
lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) :
U ∈ generate s := GenerateSets.basic h
theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets :=
Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu =>
hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy =>
inter_mem hx hy
@[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s :=
le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <|
le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl
/-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly
`s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/
protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where
sets := s
univ_sets := hs ▸ univ_mem
sets_of_superset := hs ▸ mem_of_superset
inter_sets := hs ▸ inter_mem
theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} :
Filter.mkOfClosure s hs = generate s :=
Filter.ext fun u =>
show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl
/-- Galois insertion from sets of sets into filters. -/
def giGenerate (α : Type*) :
@GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where
gc _ _ := le_generate_iff
le_l_u _ _ h := GenerateSets.basic h
choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ :=
Iff.rfl
theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem, (inter_univ s).symm⟩
theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem, s, h, (univ_inter s).symm⟩
theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) :
s ∩ t ∈ f ⊓ g :=
⟨s, hs, t, ht, rfl⟩
theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g)
(h : s ∩ t ⊆ u) : u ∈ f ⊓ g :=
mem_of_superset (inter_mem_inf hs ht) h
theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} :
s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s :=
⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ =>
mem_inf_of_inter h₁ h₂ sub⟩
section CompleteLattice
/-- Complete lattice structure on `Filter α`. -/
instance instCompleteLatticeFilter : CompleteLattice (Filter α) where
inf a b := min a b
sup a b := max a b
le_sup_left _ _ _ h := h.1
le_sup_right _ _ _ h := h.2
sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩
inf_le_left _ _ _ := mem_inf_of_left
inf_le_right _ _ _ := mem_inf_of_right
le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb)
le_sSup _ _ h₁ _ h₂ := h₂ h₁
sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂
sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂
le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁
le_top _ _ := univ_mem'
bot_le _ _ _ := trivial
instance : Inhabited (Filter α) := ⟨⊥⟩
end CompleteLattice
theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne'
@[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left
theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g :=
⟨ne_bot_of_le_ne_bot hf.1 hg⟩
theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g :=
hf.mono hg
@[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by
simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff]
theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff]
theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl
/-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot`
as the second alternative, to be used as an instance. -/
theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk
theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(giGenerate α).gc.u_inf
theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets :=
(giGenerate α).gc.u_sInf
theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets :=
(giGenerate α).gc.u_iInf
theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) :=
(giGenerate α).gc.l_bot
theorem generate_univ : Filter.generate univ = (⊥ : Filter α) :=
bot_unique fun _ _ => GenerateSets.basic (mem_univ _)
theorem generate_union {s t : Set (Set α)} :
Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t :=
(giGenerate α).gc.l_sup
theorem generate_iUnion {s : ι → Set (Set α)} :
Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) :=
(giGenerate α).gc.l_iSup
@[simp]
theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
Iff.rfl
theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g :=
⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩
@[simp]
theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by
simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter]
@[simp]
theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by
simp [neBot_iff]
theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) :=
eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff]
theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i :=
iInf_le f i hs
@[simp]
theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f :=
⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩
theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } :=
Set.ext fun _ => le_principal_iff
theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by
simp only [le_principal_iff, mem_principal]
@[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono
@[mono]
theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2
@[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by
simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl
@[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl
@[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ :=
top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true]
@[simp]
theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ :=
bot_unique fun _ _ => empty_subset _
theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s :=
eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def]
/-! ### Lattice equations -/
theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩
theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id
theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty :=
@Filter.nonempty_of_mem α f hf s hs
@[simp]
theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl
theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α :=
nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f)
theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc =>
(nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s
theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ :=
empty_mem_iff_bot.mp <| univ_mem' isEmptyElim
protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by
simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty,
@eq_comm _ ∅]
theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f)
(ht : t ∈ g) : Disjoint f g :=
Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩
theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h =>
not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩
theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by
simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
/-- There is exactly one filter on an empty type. -/
instance unique [IsEmpty α] : Unique (Filter α) where
default := ⊥
uniq := filter_eq_bot_of_isEmpty
theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α :=
not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _)
/-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are
equal. -/
theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by
refine top_unique fun s hs => ?_
obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
exact univ_mem
theorem forall_mem_nonempty_iff_neBot {f : Filter α} :
(∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f :=
⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩
instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) :=
forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]
instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) :=
⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩
theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α :=
⟨fun _ =>
by_contra fun h' =>
haveI := not_nonempty_iff.1 h'
not_subsingleton (Filter α) inferInstance,
@Filter.instNontrivialFilter α⟩
theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S :=
le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩)
fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs
theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f :=
eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm
theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by
rw [iInf_subtype']
exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop]
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] :
(iInf f).sets = ⋃ i, (f i).sets :=
let ⟨i⟩ := ne
let u :=
{ sets := ⋃ i, (f i).sets
univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩
sets_of_superset := by
simp only [mem_iUnion, exists_imp]
exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩
inter_sets := by
simp only [mem_iUnion, exists_imp]
intro x y a hx b hy
rcases h a b with ⟨c, ha, hb⟩
exact ⟨c, inter_mem (ha hx) (hb hy)⟩ }
have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion
congr_arg Filter.sets this.symm
theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) :
s ∈ iInf f ↔ ∃ i, s ∈ f i := by
simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by
haveI := ne.to_subtype
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets :=
ext fun t => by simp [mem_biInf_of_directed h ne]
@[simp]
theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) :=
Filter.ext fun x => by simp only [mem_sup, mem_join]
@[simp]
theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) :=
Filter.ext fun x => by simp only [mem_iSup, mem_join]
instance : DistribLattice (Filter α) :=
{ Filter.instCompleteLatticeFilter with
le_sup_inf := by
intro x y z s
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
rintro hs t₁ ht₁ t₂ ht₂ rfl
exact
⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂,
x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ }
/-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/
theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
(∀ i, NeBot (f i)) → NeBot (iInf f) :=
not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot,
mem_iInf_of_directed hd] using id
/-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/
theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f)
(hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by
cases isEmpty_or_nonempty ι
· constructor
simp [iInf_of_empty f, top_ne_bot]
· exact iInf_neBot_of_directed' hd hb
theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
@iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ =>
⟨ne_of_mem_of_not_mem hf hbot⟩
theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩
theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩
theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩
/-! #### `principal` equations -/
@[simp]
theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) :=
le_antisymm
(by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp]
theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) :=
Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal]
@[simp]
theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) :=
Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff]
@[simp]
theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ :=
empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff
@[simp]
theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty :=
neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm
alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff
theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) :=
IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by
rw [sup_principal, union_compl_self, principal_univ]
theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by
simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal,
← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl]
lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by
simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq]
lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by
ext
simp only [mem_iSup, mem_inf_principal]
theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by
rw [← empty_mem_iff_bot, mem_inf_principal]
simp only [mem_empty_iff_false, imp_false, compl_def]
theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by
rwa [inf_principal_eq_bot, compl_compl] at h
theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) :
s \ t ∈ f ⊓ 𝓟 tᶜ :=
inter_mem_inf hs <| mem_principal_self tᶜ
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
end Lattice
@[mono, gcongr]
theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs
/-! ### Eventually -/
theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f :=
Iff.rfl
@[simp]
theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l :=
Iff.rfl
protected theorem ext' {f₁ f₂ : Filter α}
(h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ :=
Filter.ext h
theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop}
(hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x :=
h hp
theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f)
(h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x :=
mem_of_superset hU h
protected theorem Eventually.and {p q : α → Prop} {f : Filter α} :
f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x :=
inter_mem
@[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem
theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x :=
univ_mem' hp
@[simp]
theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ :=
empty_mem_iff_bot
@[simp]
theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by
by_cases h : p <;> simp [h, t.ne]
theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y :=
exists_mem_subset_iff.symm
theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) :
∃ v ∈ f, ∀ y ∈ v, p y :=
eventually_iff_exists_mem.1 hp
theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x :=
mp_mem hp hq
theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x :=
hp.mp (Eventually.of_forall hq)
theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop}
(h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y :=
fun y => h.mono fun _ h => h y
@[simp]
theorem eventually_and {p q : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x :=
inter_mem_iff
theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x)
(h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x :=
h'.mp (h.mono fun _ hx => hx.mp)
theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) :
(∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x :=
⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩
@[simp]
theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x :=
by_cases (fun h : p => by simp [h]) fun h => by simp [h]
@[simp]
theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by
simp only [@or_comm _ q, eventually_or_distrib_left]
theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by
simp only [imp_iff_not_or, eventually_or_distrib_left]
@[simp]
theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x :=
⟨⟩
@[simp]
theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x :=
Iff.rfl
@[simp]
theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x :=
Iff.rfl
@[simp]
theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x :=
Iff.rfl
@[simp]
theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} :
(∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x :=
mem_iSup
@[simp]
theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x :=
Iff.rfl
theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop}
(hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x :=
Filter.eventually_principal.mp (hP.filter_mono hf)
theorem eventually_inf {f g : Filter α} {p : α → Prop} :
(∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x :=
mem_inf_iff_superset
theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} :
(∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x :=
mem_inf_principal
theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} :
(∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where
mp h _ := by filter_upwards [h] with _ pa _ using pa
mpr h := by filter_upwards [h univ] with _ pa using pa (by simp)
/-! ### Frequently -/
theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) :
∃ᶠ x in f, p x :=
compl_not_mem h
theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) :
∃ᶠ x in f, p x :=
Eventually.frequently (Eventually.of_forall h)
theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x :=
mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h
lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) :
(∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x :=
⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩
theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) :
∃ᶠ x in g, p x :=
mt (fun h' => h'.filter_mono hle) h
theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x :=
h.mp (Eventually.of_forall hpq)
theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x)
(hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
refine mt (fun h => hq.mp <| h.mono ?_) hp
exact fun x hpq hq hp => hpq ⟨hp, hq⟩
theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
simpa only [and_comm] using hq.and_eventually hp
theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by
by_contra H
replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H)
exact hp H
theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) :
∃ x, p x :=
hp.frequently.exists
lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} :
(∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by
rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl
lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) :=
frequently_iff_neBot
theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} :
(∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x :=
⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by
simpa only [and_not_self_iff, exists_false] using H hp⟩
theorem frequently_iff {f : Filter α} {P : α → Prop} :
(∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by
simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)]
rfl
@[simp]
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
@[simp]
theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by
simp only [Filter.Frequently, not_not]
@[simp]
theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by
simp [frequently_iff_neBot]
@[simp]
theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp
@[simp]
theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by
by_cases p <;> simp [*]
@[simp]
theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and]
theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp
theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp
theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by
simp [imp_iff_not_or]
theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib]
theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by
simp only [frequently_imp_distrib, frequently_const]
theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
@[simp]
theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp]
@[simp]
theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by
simp only [@and_comm _ q, frequently_and_distrib_left]
@[simp]
theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp
@[simp]
theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently]
@[simp]
theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by
simp [Filter.Frequently, not_forall]
theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by
simp only [Filter.Frequently, eventually_inf_principal, not_and]
alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal
theorem frequently_sup {p : α → Prop} {f g : Filter α} :
(∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by
simp only [Filter.Frequently, eventually_sup, not_and_or]
@[simp]
theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by
simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop]
@[simp]
theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} :
(∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by
simp only [Filter.Frequently, eventually_iSup, not_forall]
theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) :
∃ f : α → β, ∀ᶠ x in l, r x (f x) := by
haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty
choose! f hf using fun x (hx : ∃ y, r x y) => hx
exact ⟨f, h.mono hf⟩
lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)]
{P : ∀ i : ι, α i → Prop} {F : Filter ι} :
(∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by
classical
refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩
refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩
filter_upwards [H] with i hi
exact dif_pos hi ▸ hi.choose_spec
/-!
### Relation “eventually equal”
-/
section EventuallyEq
variable {l : Filter α} {f g : α → β}
theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h
@[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff]
theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop)
(hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) :=
hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl
theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t :=
eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff
alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set
@[simp]
theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by
simp [eventuallyEq_set]
theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∃ s ∈ l, EqOn f g s :=
Eventually.exists_mem h
theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) :
f =ᶠ[l] g :=
eventually_of_mem hs h
theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s :=
eventually_iff_exists_mem
theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) :
f =ᶠ[l'] g :=
h₂ h₁
@[refl, simp]
theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f :=
Eventually.of_forall fun _ => rfl
protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f :=
EventuallyEq.refl l f
theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl
alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq
@[symm]
theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f :=
H.mono fun _ => Eq.symm
lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩
@[trans]
theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) :
f =ᶠ[l] h :=
H₂.rw (fun x y => f x = y) H₁
theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) :
f =ᶠ[l] h ↔ g =ᶠ[l] h :=
⟨H.symm.trans, H.trans⟩
theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) :
f =ᶠ[l] g ↔ f =ᶠ[l] h :=
⟨(·.trans H), (·.trans H.symm)⟩
instance {l : Filter α} :
Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where
trans := EventuallyEq.trans
theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') :
(fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) :=
hf.mp <|
hg.mono <| by
intros
simp only [*]
@[deprecated (since := "2025-03-10")]
alias EventuallyEq.prod_mk := EventuallyEq.prodMk
-- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t.
-- composition on the right.
theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) :
h ∘ f =ᶠ[l] h ∘ g :=
H.mono fun _ hx => congr_arg h hx
theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ)
(Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) :=
(Hf.prodMk Hg).fun_comp (uncurry h)
@[to_additive]
theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x :=
h.comp₂ (· * ·) h'
@[to_additive const_smul]
theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) :
(fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c :=
h.fun_comp (· ^ c)
@[to_additive]
theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
(fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ :=
h.fun_comp Inv.inv
@[to_additive]
theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x :=
h.comp₂ (· / ·) h'
attribute [to_additive] EventuallyEq.const_smul
@[to_additive]
theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β}
(hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x :=
hf.comp₂ (· • ·) hg
theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x :=
hf.comp₂ (· ⊔ ·) hg
theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x :=
hf.comp₂ (· ⊓ ·) hg
theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) :
f ⁻¹' s =ᶠ[l] g ⁻¹' s :=
h.fun_comp s
theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) :=
h.comp₂ (· ∧ ·) h'
theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) :=
h.comp₂ (· ∨ ·) h'
theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) :
(sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) :=
h.fun_comp Not
theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α}
(h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) :=
(h.diff h').union (h'.diff h)
theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s :=
eventuallyEq_set.trans <| by simp
theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by
simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp]
theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by
rw [inter_comm, inter_eventuallyEq_left]
@[simp]
theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s :=
Iff.rfl
theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} :
f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x :=
eventually_inf_principal
theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm
theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 :=
⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩
theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x :=
eventually_iff_all_subsets
section LE
variable [LE β] {l : Filter α}
theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f' ≤ᶠ[l] g' :=
H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H
theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' :=
⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩
theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} :
f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x :=
eventually_iff_all_subsets
end LE
section Preorder
variable [Preorder β] {l : Filter α} {f g h : α → β}
theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g :=
h.mono fun _ => le_of_eq
@[refl]
theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f :=
EventuallyEq.rfl.le
theorem EventuallyLE.rfl : f ≤ᶠ[l] f :=
EventuallyLE.refl l f
@[trans]
theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₂.mp <| H₁.mono fun _ => le_trans
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans
@[trans]
theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.le.trans H₂
instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyEq.trans_le
@[trans]
theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h :=
H₁.trans H₂.le
instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where
trans := EventuallyLE.trans_eq
end Preorder
variable {l : Filter α}
theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g)
(h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g :=
h₂.mp <| h₁.mono fun _ => le_antisymm
theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by
simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and]
theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) :
g ≤ᶠ[l] f ↔ g =ᶠ[l] f :=
⟨fun h' => h'.antisymm h, EventuallyEq.le⟩
theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) :
∀ᶠ x in l, f x ≠ g x :=
h.mono fun _ hx => hx.ne
theorem Eventually.ne_top_of_lt [Preorder β] [OrderTop β] {l : Filter α} {f g : α → β}
(h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ :=
h.mono fun _ hx => hx.ne_top
theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β}
(h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ :=
h.mono fun _ hx => hx.lt_top
theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} :
(∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ :=
⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩
@[mono]
theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) :=
h'.mp <| h.mono fun _ => And.imp
@[mono]
theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') :
(s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) :=
h'.mp <| h.mono fun _ => Or.imp
@[mono]
theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) :
(tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) :=
h.mono fun _ => mt
@[mono]
theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') :
(s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s :=
eventually_inf_principal.symm
theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} :
s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t :=
set_eventuallyLE_iff_mem_inf_principal.trans <| by
simp only [le_inf_iff, inf_le_left, true_and, le_principal_iff]
theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} :
s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by
simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le]
theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂)
(hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by
filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx
theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h)
(hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by
filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx
theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g :=
hf.mono fun _ => _root_.le_sup_of_le_left
theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β}
(hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g :=
hg.mono fun _ => _root_.le_sup_of_le_right
theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l :=
fun _ hs => h.mono fun _ hm => hm hs
end EventuallyEq
end Filter
open Filter
theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g :=
h
theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s)
(hl : s ∈ l) : f =ᶠ[l] g :=
h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl
theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t :=
Filter.Eventually.of_forall h
variable {α β : Type*} {F : Filter α} {G : Filter β}
namespace Filter
lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} :
sᶜ ∈ comk p he hmono hunion ↔ p s := by
simp
end Filter
| Mathlib/Order/Filter/Basic.lean | 2,143 | 2,144 | |
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn, Joachim Breitner
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.GroupTheory.FreeGroup.IsFreeGroup
import Mathlib.SetTheory.Cardinal.Basic
/-!
# The coproduct (a.k.a. the free product) of groups or monoids
Given an `ι`-indexed family `M` of monoids,
we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`.
As usual, we use the suffix `I` for an indexed (co)product,
leaving `Coprod` for the coproduct of two monoids.
When `ι` and all `M i` have decidable equality,
the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words.
This bijection is constructed
by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`.
When `M i` are all groups, `Monoid.CoprodI M` is also a group
(and the coproduct in the category of groups).
## Main definitions
- `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid.
- `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`.
- `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property.
- `Monoid.CoprodI.Word M`: the type of reduced words.
- `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`.
- `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words
with first letter from `M i` and last letter from `M j`,
together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`).
Used in the proof of the Ping-Pong-lemma.
- `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma,
proving injectivity of the `lift`. See the documentation of that theorem for more information.
## Remarks
There are many answers to the question "what is the coproduct of a family `M` of monoids?",
and they are all equivalent but not obviously equivalent.
We provide two answers.
The first, almost tautological answer is given by `Monoid.CoprodI M`,
which is a quotient of the type of words in the alphabet `Σ i, M i`.
It's straightforward to define and easy to prove its universal property.
But this answer is not completely satisfactory,
because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct
since `Monoid.CoprodI M` is defined as a quotient.
The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`.
An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`,
where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`.
Since we only work with reduced words, there is no need for quotienting,
and it is easy to tell when two elements are distinct.
However it's not obvious that this is even a monoid!
We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word,
i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types.
This means that `Monoid.CoprodI.Word M` can be given a monoid structure,
and it lets us tell when two elements of `Monoid.CoprodI M` are distinct.
There is also a completely tautological, maximally inefficient answer
given by `MonCat.Colimits.ColimitType`.
Whereas `Monoid.CoprodI M` at least ensures that
(any instance of) associativity holds by reflexivity,
in this answer associativity holds because of quotienting.
Yet another answer, which is constructively more satisfying,
could be obtained by showing that `Monoid.CoprodI.Rel` is confluent.
## References
[van der Waerden, *Free products of groups*][MR25465]
-/
open Set
variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)]
/-- A relation on the free monoid on alphabet `Σ i, M i`,
relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/
inductive Monoid.CoprodI.Rel : FreeMonoid (Σ i, M i) → FreeMonoid (Σ i, M i) → Prop
| of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1
| of_mul {i : ι} (x y : M i) :
Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩)
/-- The free product (categorical coproduct) of an indexed family of monoids. -/
def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient
-- The `Monoid` instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : Monoid (Monoid.CoprodI M) := by
delta Monoid.CoprodI; infer_instance
instance : Inhabited (Monoid.CoprodI M) :=
⟨1⟩
namespace Monoid.CoprodI
/-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent
letters can come from the same summand. -/
@[ext]
structure Word where
/-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no
two adjacent letters are from the same summand -/
toList : List (Σi, M i)
/-- A reduced word does not contain `1` -/
ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1
/-- Adjacent letters are not from the same summand. -/
chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l'
variable {M}
/-- The inclusion of a summand into the free product. -/
def of {i : ι} : M i →* CoprodI M where
toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x)
map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i))
map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y))
theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) :=
rfl
variable {N : Type*} [Monoid N]
/-- See note [partially-applied ext lemmas]. -/
-- Porting note: higher `ext` priority
@[ext 1100]
theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
FreeMonoid.hom_eq fun ⟨i, x⟩ => by
rw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply]
unfold CoprodI
rw [← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]
/-- A map out of the free product corresponds to a family of maps out of the summands. This is the
universal property of the free product, characterizing it as a categorical coproduct. -/
@[simps symm_apply]
def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where
toFun fi :=
Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <|
Con.conGen_le <| by
simp_rw [Con.ker_rel]
rintro _ _ (i | ⟨x, y⟩) <;> simp
invFun f _ := f.comp of
left_inv := by
intro fi
ext i x
rfl
right_inv := by
intro f
ext i x
rfl
@[simp]
theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i :=
congr_fun (lift.symm_apply_apply fi) i
@[simp]
theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m :=
DFunLike.congr_fun (lift_comp_of ..) m
@[simp]
theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) :
lift (fun i ↦ f.comp (of (i := i))) = f :=
lift.apply_symm_apply f
@[simp]
theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) :=
lift_comp_of' (.id _)
theorem of_leftInverse [DecidableEq ι] (i : ι) :
Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by
simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply]
theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by
classical exact (of_leftInverse i).injective
theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) :
MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by
rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift,
range_sigma_eq_iUnion_range, Submonoid.closure_iUnion]
simp only [MonoidHom.mclosure_range]
theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} :
MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by
simp [mrange_eq_iSup]
@[simp]
theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by
simp [← mrange_eq_iSup]
@[simp]
| theorem mclosure_iUnion_range_of :
Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by
| Mathlib/GroupTheory/CoprodI.lean | 199 | 200 |
/-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Bhavik Mehta, Yaël Dillies
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.Convex.Hull
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.Topology.Bornology.Absorbs
/-!
# Local convexity
This file defines absorbent and balanced sets.
An absorbent set is one that "surrounds" the origin. The idea is made precise by requiring that any
point belongs to all large enough scalings of the set. This is the vector world analog of a
topological neighborhood of the origin.
A balanced set is one that is everywhere around the origin. This means that `a • s ⊆ s` for all `a`
of norm less than `1`.
## Main declarations
For a module over a normed ring:
* `Absorbs`: A set `s` absorbs a set `t` if all large scalings of `s` contain `t`.
* `Absorbent`: A set `s` is absorbent if every point eventually belongs to all large scalings of
`s`.
* `Balanced`: A set `s` is balanced if `a • s ⊆ s` for all `a` of norm less than `1`.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
absorbent, balanced, locally convex, LCTVS
-/
open Set
open Pointwise Topology
variable {𝕜 𝕝 E F : Type*} {ι : Sort*} {κ : ι → Sort*}
section SeminormedRing
variable [SeminormedRing 𝕜]
section SMul
variable [SMul 𝕜 E] {s A B : Set E}
variable (𝕜) in
/-- A set `A` is balanced if `a • A` is contained in `A` whenever `a` has norm at most `1`. -/
def Balanced (A : Set E) :=
∀ a : 𝕜, ‖a‖ ≤ 1 → a • A ⊆ A
lemma absorbs_iff_norm : Absorbs 𝕜 A B ↔ ∃ r, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A :=
Filter.atTop_basis.cobounded_of_norm.eventually_iff.trans <| by simp only [true_and]; rfl
alias ⟨_, Absorbs.of_norm⟩ := absorbs_iff_norm
lemma Absorbs.exists_pos (h : Absorbs 𝕜 A B) : ∃ r > 0, ∀ c : 𝕜, r ≤ ‖c‖ → B ⊆ c • A :=
let ⟨r, hr₁, hr⟩ := (Filter.atTop_basis' 1).cobounded_of_norm.eventually_iff.1 h
⟨r, one_pos.trans_le hr₁, hr⟩
theorem balanced_iff_smul_mem : Balanced 𝕜 s ↔ ∀ ⦃a : 𝕜⦄, ‖a‖ ≤ 1 → ∀ ⦃x : E⦄, x ∈ s → a • x ∈ s :=
forall₂_congr fun _a _ha => smul_set_subset_iff
alias ⟨Balanced.smul_mem, _⟩ := balanced_iff_smul_mem
theorem balanced_iff_closedBall_smul : Balanced 𝕜 s ↔ Metric.closedBall (0 : 𝕜) 1 • s ⊆ s := by
simp [balanced_iff_smul_mem, smul_subset_iff]
@[simp]
theorem balanced_empty : Balanced 𝕜 (∅ : Set E) := fun _ _ => by rw [smul_set_empty]
@[simp]
theorem balanced_univ : Balanced 𝕜 (univ : Set E) := fun _a _ha => subset_univ _
theorem Balanced.union (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∪ B) := fun _a ha =>
smul_set_union.subset.trans <| union_subset_union (hA _ ha) <| hB _ ha
theorem Balanced.inter (hA : Balanced 𝕜 A) (hB : Balanced 𝕜 B) : Balanced 𝕜 (A ∩ B) := fun _a ha =>
smul_set_inter_subset.trans <| inter_subset_inter (hA _ ha) <| hB _ ha
theorem balanced_iUnion {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋃ i, f i) :=
fun _a ha => (smul_set_iUnion _ _).subset.trans <| iUnion_mono fun _ => h _ _ ha
theorem balanced_iUnion₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) :
Balanced 𝕜 (⋃ (i) (j), f i j) :=
balanced_iUnion fun _ => balanced_iUnion <| h _
theorem Balanced.sInter {S : Set (Set E)} (h : ∀ s ∈ S, Balanced 𝕜 s) : Balanced 𝕜 (⋂₀ S) :=
fun _ _ => (smul_set_sInter_subset ..).trans (fun _ _ => by aesop)
theorem balanced_iInter {f : ι → Set E} (h : ∀ i, Balanced 𝕜 (f i)) : Balanced 𝕜 (⋂ i, f i) :=
fun _a ha => (smul_set_iInter_subset _ _).trans <| iInter_mono fun _ => h _ _ ha
theorem balanced_iInter₂ {f : ∀ i, κ i → Set E} (h : ∀ i j, Balanced 𝕜 (f i j)) :
Balanced 𝕜 (⋂ (i) (j), f i j) :=
balanced_iInter fun _ => balanced_iInter <| h _
theorem Balanced.mulActionHom_preimage [SMul 𝕜 F] {s : Set F} (hs : Balanced 𝕜 s)
(f : E →[𝕜] F) : Balanced 𝕜 (f ⁻¹' s) := fun a ha x ⟨y,⟨hy₁,hy₂⟩⟩ => by
rw [mem_preimage, ← hy₂, map_smul]
exact hs a ha (smul_mem_smul_set hy₁)
variable [SMul 𝕝 E] [SMulCommClass 𝕜 𝕝 E]
theorem Balanced.smul (a : 𝕝) (hs : Balanced 𝕜 s) : Balanced 𝕜 (a • s) := fun _b hb =>
(smul_comm _ _ _).subset.trans <| smul_set_mono <| hs _ hb
end SMul
section Module
variable [AddCommGroup E] [Module 𝕜 E] {s t : Set E}
theorem Balanced.neg : Balanced 𝕜 s → Balanced 𝕜 (-s) :=
forall₂_imp fun _ _ h => (smul_set_neg _ _).subset.trans <| neg_subset_neg.2 h
@[simp]
theorem balanced_neg : Balanced 𝕜 (-s) ↔ Balanced 𝕜 s :=
⟨fun h ↦ neg_neg s ▸ h.neg, fun h ↦ h.neg⟩
theorem Balanced.neg_mem_iff [NormOneClass 𝕜] (h : Balanced 𝕜 s) {x : E} : -x ∈ s ↔ x ∈ s :=
⟨fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx,
fun hx ↦ by simpa using h.smul_mem (a := -1) (by simp) hx⟩
theorem Balanced.neg_eq [NormOneClass 𝕜] (h : Balanced 𝕜 s) : -s = s :=
Set.ext fun _ ↦ h.neg_mem_iff
theorem Balanced.add (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s + t) := fun _a ha =>
(smul_add _ _ _).subset.trans <| add_subset_add (hs _ ha) <| ht _ ha
theorem Balanced.sub (hs : Balanced 𝕜 s) (ht : Balanced 𝕜 t) : Balanced 𝕜 (s - t) := by
simp_rw [sub_eq_add_neg]
exact hs.add ht.neg
theorem balanced_zero : Balanced 𝕜 (0 : Set E) := fun _a _ha => (smul_zero _).subset
end Module
end SeminormedRing
section NormedDivisionRing
variable [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E}
theorem absorbs_iff_eventually_nhdsNE_zero :
Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝[≠] 0, MapsTo (c • ·) t s := by
rw [absorbs_iff_eventually_cobounded_mapsTo, ← Filter.inv_cobounded₀]; rfl
@[deprecated (since := "2025-03-03")]
alias absorbs_iff_eventually_nhdsWithin_zero := absorbs_iff_eventually_nhdsNE_zero
alias ⟨Absorbs.eventually_nhdsNE_zero, _⟩ := absorbs_iff_eventually_nhdsNE_zero
@[deprecated (since := "2025-03-03")]
alias Absorbs.eventually_nhdsWithin_zero := Absorbs.eventually_nhdsNE_zero
theorem absorbent_iff_eventually_nhdsNE_zero :
Absorbent 𝕜 s ↔ ∀ x : E, ∀ᶠ c : 𝕜 in 𝓝[≠] 0, c • x ∈ s :=
forall_congr' fun x ↦ by simp only [absorbs_iff_eventually_nhdsNE_zero, mapsTo_singleton]
@[deprecated (since := "2025-03-03")]
alias absorbent_iff_eventually_nhdsWithin_zero := absorbent_iff_eventually_nhdsNE_zero
alias ⟨Absorbent.eventually_nhdsNE_zero, _⟩ := absorbent_iff_eventually_nhdsWithin_zero
@[deprecated (since := "2025-03-03")]
alias Absorbent.eventually_nhdsWithin_zero := Absorbent.eventually_nhdsNE_zero
theorem absorbs_iff_eventually_nhds_zero (h₀ : 0 ∈ s) :
Absorbs 𝕜 s t ↔ ∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s := by
rw [← nhdsNE_sup_pure, Filter.eventually_sup, Filter.eventually_pure,
← absorbs_iff_eventually_nhdsNE_zero, and_iff_left]
intro x _
simpa only [zero_smul]
theorem Absorbs.eventually_nhds_zero (h : Absorbs 𝕜 s t) (h₀ : 0 ∈ s) :
∀ᶠ c : 𝕜 in 𝓝 0, MapsTo (c • ·) t s :=
(absorbs_iff_eventually_nhds_zero h₀).1 h
variable [NormedRing 𝕝] [Module 𝕜 𝕝] [IsBoundedSMul 𝕜 𝕝] [SMulWithZero 𝕝 E] [IsScalarTower 𝕜 𝕝 E]
{a b : 𝕜} {x : E}
/-- Scalar multiplication (by possibly different types) of a balanced set is monotone. -/
theorem Balanced.smul_mono (hs : Balanced 𝕝 s) {a : 𝕝} (h : ‖a‖ ≤ ‖b‖) : a • s ⊆ b • s := by
obtain rfl | hb := eq_or_ne b 0
· rw [norm_zero, norm_le_zero_iff] at h
simp only [h, ← image_smul, zero_smul, Subset.rfl]
· calc
| a • s = b • (b⁻¹ • a) • s := by rw [smul_assoc, smul_inv_smul₀ hb]
_ ⊆ b • s := smul_set_mono <| hs _ <| by
rw [norm_smul, norm_inv, ← div_eq_inv_mul]
exact div_le_one_of_le₀ h (norm_nonneg _)
theorem Balanced.smul_mem_mono [SMulCommClass 𝕝 𝕜 E] (hs : Balanced 𝕝 s) {b : 𝕝}
(ha : a • x ∈ s) (hba : ‖b‖ ≤ ‖a‖) : b • x ∈ s := by
rcases eq_or_ne a 0 with rfl | ha₀
· simp_all
| Mathlib/Analysis/LocallyConvex/Basic.lean | 197 | 205 |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Pseudoelements in abelian categories
A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows
ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a
common domain making a commutative square with the two arrows. While the construction shows that
pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these
pseudoelements through commutative diagrams in an abelian category to prove exactness properties.
This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof
in the category of abelian groups can more or less directly be converted into a proof using
pseudoelements.
A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma.
Pseudoelements are in some ways weaker than actual elements in a concrete category. The most
important limitation is that there is no extensionality principle: If `f g : X ⟶ Y`, then
`∀ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`,
it does). A corollary of this is that we can not define arrows in abelian categories by dictating
their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this:
First, we construct some morphism using universal properties, and then we use diagram chasing
of pseudoelements to verify that is has some desirable property such as exactness.
It should be noted that the Freyd-Mitchell embedding theorem
(see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of
pseudoelement (in particular one that gives extensionality) and this file should be updated to
go use that instead!
## Main results
We define the type of pseudoelements of an object and, in particular, the zero pseudoelement.
We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`)
and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`).
Here are the metatheorems we provide:
* A morphism `f` is zero if and only if it is the zero function on pseudoelements.
* A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements.
* A morphism `f` is a monomorphism if and only if it is injective on pseudoelements
if and only if `∀ a, f a = 0 → f = 0`.
* A sequence `f, g` of morphisms is exact if and only if
`∀ a, g (f a) = 0` and `∀ b, g b = 0 → ∃ a, f a = b`.
* If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some
pseudoelement `a''` such that `f a'' = 0` and for every `g` we have
`g a' = 0 → g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away
by that: pseudoelements of an object do not form an abelian group.
## Notations
We introduce coercions from an object of an abelian category to the set of its pseudoelements
and from a morphism to the function it induces on pseudoelements.
These coercions must be explicitly enabled via local instances:
`attribute [local instance] objectToSort homToFun`
## Implementation notes
It appears that sometimes the coercion from morphisms to functions does not work, i.e.,
writing `g a` raises a "function expected" error. This error can be fixed by writing
`(g : X ⟶ Y) a`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Abelian
open CategoryTheory.Preadditive
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
attribute [local instance] Over.coeFromHom
/-- This is just composition of morphisms in `C`. Another way to express this would be
`(Over.map f).obj a`, but our definition has nicer definitional properties. -/
def app {P Q : C} (f : P ⟶ Q) (a : Over P) : Over Q :=
a.hom ≫ f
@[simp]
theorem app_hom {P Q : C} (f : P ⟶ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl
/-- Two arrows `f : X ⟶ P` and `g : Y ⟶ P` are called pseudo-equal if there is some object
`R` and epimorphisms `p : R ⟶ X` and `q : R ⟶ Y` such that `p ≫ f = q ≫ g`. -/
def PseudoEqual (P : C) (f g : Over P) : Prop :=
∃ (R : C) (p : R ⟶ f.1) (q : R ⟶ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom
theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) :=
fun f => ⟨f.1, 𝟙 f.1, 𝟙 f.1, inferInstance, inferInstance, by simp⟩
theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) :=
fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩
variable [Abelian.{v} C]
section
/-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will
be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/
theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by
intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩
refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q',
epi_comp _ _, epi_comp _ _, ?_⟩
rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm',
Category.assoc]
end
/-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/
def Pseudoelement.setoid (P : C) : Setoid (Over P) :=
⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩
attribute [local instance] Pseudoelement.setoid
/-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being
pseudo-equal. -/
def Pseudoelement (P : C) : Type max u v :=
Quotient (Pseudoelement.setoid P)
namespace Pseudoelement
/-- A coercion from an object of an abelian category to its pseudoelements. -/
def objectToSort : CoeSort C (Type max u v) :=
⟨fun P => Pseudoelement P⟩
attribute [local instance] objectToSort
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort
/-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/
def overToSort {P : C} : Coe (Over P) (Pseudoelement P) :=
⟨Quot.mk (PseudoEqual P)⟩
attribute [local instance] overToSort
theorem over_coe_def {P Q : C} (a : Q ⟶ P) : (a : Pseudoelement P) = ⟦↑a⟧ := rfl
/-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/
theorem pseudoApply_aux {P Q : C} (f : P ⟶ Q) (a b : Over P) : a ≈ b → app f a ≈ app f b :=
fun ⟨R, p, q, ep, Eq, comm⟩ =>
⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩
/-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/
def pseudoApply {P Q : C} (f : P ⟶ Q) : P → Q :=
Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f)
/-- A coercion from morphisms to functions on pseudoelements. -/
def homToFun {P Q : C} : CoeFun (P ⟶ Q) fun _ => P → Q :=
⟨pseudoApply⟩
attribute [local instance] homToFun
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun
theorem pseudoApply_mk' {P Q : C} (f : P ⟶ Q) (a : Over P) : f ⟦a⟧ = ⟦↑(a.hom ≫ f)⟧ := rfl
/-- Applying a pseudoelement to a composition of morphisms is the same as composing
with each morphism. Sadly, this is not a definitional equality, but at least it is
true. -/
theorem comp_apply {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) (a : P) : (f ≫ g) a = g (f a) :=
Quotient.inductionOn a fun x =>
Quotient.sound <| by
simp only [app]
rw [← Category.assoc, Over.coe_hom]
/-- Composition of functions on pseudoelements is composition of morphisms. -/
theorem comp_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : g ∘ f = f ≫ g :=
funext fun _ => (comp_apply _ _ _).symm
section Zero
/-!
In this section we prove that for every `P` there is an equivalence class that contains
precisely all the zero morphisms ending in `P` and use this to define *the* zero
pseudoelement.
-/
section
attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts
/-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/
theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f ≈ (0 : Q ⟶ P) ↔ f.hom = 0 :=
⟨fun ⟨R, p, q, _, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf =>
⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by
rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩
end
theorem zero_eq_zero' {P Q R : C} :
(⟦((0 : Q ⟶ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟶ P) : Over P)⟧ :=
Quotient.sound <| (pseudoZero_aux R _).2 rfl
/-- The zero pseudoelement is the class of a zero morphism. -/
def pseudoZero {P : C} : P :=
⟦(0 : P ⟶ P)⟧
-- Porting note: in mathlib3, we couldn't make this an instance
-- as it would have fired on `coe_sort`.
-- However now that coercions are treated differently, this is a structural instance triggered by
-- the appearance of `Pseudoelement`.
instance hasZero {P : C} : Zero P :=
⟨pseudoZero⟩
instance {P : C} : Inhabited P :=
⟨0⟩
theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = ⟦↑(0 : P ⟶ P)⟧ := rfl
@[simp]
theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟶ P) : Over P)⟧ = (0 : Pseudoelement P) :=
zero_eq_zero'
/-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/
theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by
rw [← pseudoZero_aux P a]
exact Quotient.eq'
end Zero
open Pseudoelement
/-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/
@[simp]
theorem apply_zero {P Q : C} (f : P ⟶ Q) : f 0 = 0 := by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- The zero morphism maps every pseudoelement to 0. -/
@[simp]
theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟶ Q) a = 0 :=
Quotient.inductionOn a fun a' => by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- An extensionality lemma for being the zero arrow. -/
theorem zero_morphism_ext {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → f = 0 := fun h => by
rw [← Category.id_comp f]
exact (pseudoZero_iff (𝟙 P ≫ f : Over Q)).1 (h (𝟙 P))
theorem zero_morphism_ext' {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → 0 = f :=
Eq.symm ∘ zero_morphism_ext f
theorem eq_zero_iff {P Q : C} (f : P ⟶ Q) : f = 0 ↔ ∀ a, f a = 0 :=
⟨fun h a => by simp [h], zero_morphism_ext _⟩
/-- A monomorphism is injective on pseudoelements. -/
theorem pseudo_injective_of_mono {P Q : C} (f : P ⟶ Q) [Mono f] : Function.Injective f := by
intro abar abar'
refine Quotient.inductionOn₂ abar abar' fun a a' ha => ?_
apply Quotient.sound
have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(a'.hom ≫ f)⟧ := by convert ha
have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this
exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by
simp only [Category.assoc]
exact comm⟩
/-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/
theorem zero_of_map_zero {P Q : C} (f : P ⟶ Q) : Function.Injective f → ∀ a, f a = 0 → a = 0 :=
fun h a ha => by
rw [← apply_zero f] at ha
exact h ha
/-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/
theorem mono_of_zero_of_map_zero {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0 → a = 0) → Mono f :=
fun h => (mono_iff_cancel_zero _).2 fun _ g hg =>
(pseudoZero_iff (g : Over P)).1 <|
h _ <| show f g = 0 from (pseudoZero_iff (g ≫ f : Over Q)).2 hg
section
/-- An epimorphism is surjective on pseudoelements. -/
theorem pseudo_surjective_of_epi {P Q : C} (f : P ⟶ Q) [Epi f] : Function.Surjective f :=
fun qbar =>
Quotient.inductionOn qbar fun q =>
⟨(pullback.fst f q.hom : Over P),
Quotient.sound <|
⟨pullback f q.hom, 𝟙 (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by
| rw [Category.id_comp, ← pullback.condition, app_hom, Over.coe_hom]⟩⟩
| Mathlib/CategoryTheory/Abelian/Pseudoelements.lean | 297 | 298 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
import Qq
/-! # Power function on `ℝ`
We construct the power functions `x ^ y`, where `x` and `y` are real numbers.
-/
noncomputable section
open Real ComplexConjugate Finset Set
/-
## Definitions
-/
namespace Real
variable {x y z : ℝ}
/-- The real power function `x ^ y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for
`y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/
noncomputable def rpow (x y : ℝ) :=
((x : ℂ) ^ (y : ℂ)).re
noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by
simp only [rpow_def, Complex.cpow_def]; split_ifs <;>
simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul,
(Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero]
theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by
rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp]
@[simp, norm_cast]
theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast,
Complex.ofReal_re]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n
@[simp]
theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul]
@[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow]
theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [rpow_def_of_nonneg hx]
split_ifs <;> simp [*, exp_ne_zero]
@[simp]
lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by
simp [rpow_eq_zero_iff_of_nonneg, *]
@[simp]
lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 :=
Real.rpow_eq_zero hx hy |>.not
open Real
theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by
rw [rpow_def, Complex.cpow_def, if_neg]
· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by
simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log,
Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul]
ring
rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ←
Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul,
Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im,
Real.log_neg_eq_log]
ring
· rw [Complex.ofReal_eq_zero]
exact ne_of_lt hx
theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by
split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
@[bound]
theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by
rw [rpow_def_of_pos hx]; apply exp_pos
@[simp]
theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *]
theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
constructor
· intro hyp
simp only [rpow_def, Complex.ofReal_zero] at hyp
by_cases h : x = 0
· subst h
simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp
exact Or.inr ⟨rfl, hyp.symm⟩
· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp
exact Or.inl ⟨h, hyp.symm⟩
· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩)
· exact zero_rpow h
· exact rpow_zero _
theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by
rw [← zero_rpow_eq_iff, eq_comm]
@[simp]
theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one]
@[bound]
theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by
rw [rpow_def_of_nonneg hx]; split_ifs <;>
simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by
have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _
rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg]
@[bound]
theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by
rcases le_or_lt 0 x with hx | hx
· rw [abs_rpow_of_nonneg hx]
· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul,
abs_of_pos (exp_pos _)]
exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _)
theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by
refine (abs_rpow_le_abs_rpow x y).trans ?_
by_cases hx : x = 0
· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one]
· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs]
lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by
rw [rpow_def_of_pos hx₀, mul_inv_cancel₀]
exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩
/-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/
lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by
calc
_ ≤ |x ^ (log x)⁻¹| := le_abs_self _
_ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow ..
rw [← log_abs]
obtain hx | hx := (abs_nonneg x).eq_or_gt
· simp [hx]
· rw [rpow_def_of_pos hx]
gcongr
exact mul_inv_le_one
theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by
simp_rw [Real.norm_eq_abs]
exact abs_rpow_of_nonneg hx_nonneg
variable {w x y z : ℝ}
theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by
simp only [rpow_def_of_pos hx, mul_add, exp_add]
theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by
rcases hx.eq_or_lt with (rfl | pos)
· rw [zero_rpow h, zero_eq_mul]
have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0
exact this.imp zero_rpow zero_rpow
· exact rpow_add pos _ _
/-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add' hx]; rwa [h]
theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
rcases hy.eq_or_lt with (rfl | hy)
· rw [zero_add, rpow_zero, one_mul]
exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz)
/-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for
`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.
The inequality is always true, though, and given in this lemma. -/
theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by
rcases le_iff_eq_or_lt.1 hx with (H | pos)
· by_cases h : y + z = 0
· simp only [H.symm, h, rpow_zero]
calc
(0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 :=
mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one
_ = 1 := by simp
· simp [rpow_add', ← H, h]
· simp [rpow_add pos]
theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) :
(a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x :=
map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s
theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ}
(h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by
induction' s using Finset.cons_induction with i s hi ihs
· rw [sum_empty, Finset.prod_empty, rpow_zero]
· rw [forall_mem_cons] at h
rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)]
theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg]
theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]
theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by
simp only [sub_eq_add_neg] at h ⊢
simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv]
protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ}
(hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) :=
hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr)
end Real
/-!
## Comparing real and complex powers
-/
namespace Complex
theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by
simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;>
simp [Complex.ofReal_log hx]
theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) :
(x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by
rcases hx.eq_or_lt with (rfl | hlt)
· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*]
have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne
rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log,
log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx),
ofReal_zero, zero_mul, add_zero]
lemma cpow_ofReal (x : ℂ) (y : ℝ) :
x ^ (y : ℂ) = ↑(‖x‖ ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by
rcases eq_or_ne x 0 with rfl | hx
· simp [ofReal_cpow le_rfl]
· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)]
norm_cast
rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul,
Real.exp_log]
rwa [norm_pos_iff]
lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖x‖ ^ y * Real.cos (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos]
lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = ‖x‖ ^ y * Real.sin (arg x * y) := by
rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin]
theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) :
‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub,
Real.rpow_def_of_pos (norm_pos_iff.mpr hz)]
theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) :
‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]]
rcases eq_or_ne w.re 0 with hw | hw
· simp [hw, h rfl hw]
· rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero]
exact ne_of_apply_ne re hw
theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by
by_cases h : z = 0 → w.re = 0 → w = 0
· exact (norm_cpow_of_imp h).le
· push_neg at h
simp [h]
@[simp]
theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by
rw [norm_cpow_of_imp] <;> simp
@[simp]
theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by
rw [← norm_cpow_real]; simp
theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by
rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le,
zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le]
theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) :
‖(x : ℂ) ^ y‖ = x ^ re y := by
rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg]
@[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero
@[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp
@[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le
@[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real
@[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat
@[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos :=
norm_cpow_eq_rpow_re_of_pos
@[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg :=
norm_cpow_eq_rpow_re_of_nonneg
open Filter in
lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) :
(fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_cpow_eq_rpow_re_of_pos ht]
lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs]
lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) :
‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by
rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _]
lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ :=
(norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _
theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) :
(x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by
rw [cpow_mul, ofReal_cpow hx]
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos
· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le
end Complex
/-! ### Positivity extension -/
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1)
when the exponent is zero. The other cases are done in `evalRpow`. -/
@[positivity (_ : ℝ) ^ (0 : ℝ)]
def evalRpowZero : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) =>
assertInstancesCommute
pure (.positive q(Real.rpow_zero_pos $a))
| _, _, _ => throwError "not Real.rpow"
/-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when
the base is nonnegative and positive when the base is positive. -/
@[positivity (_ : ℝ) ^ (_ : ℝ)]
def evalRpow : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa =>
pure (.positive q(Real.rpow_pos_of_pos $pa $b))
| .nonnegative pa =>
pure (.nonnegative q(Real.rpow_nonneg $pa $b))
| _ => pure .none
| _, _, _ => throwError "not Real.rpow"
end Mathlib.Meta.Positivity
/-!
## Further algebraic properties of `rpow`
-/
namespace Real
variable {x y z : ℝ} {n : ℕ}
theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _),
Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;>
simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im,
neg_lt_zero, pi_pos, le_of_lt pi_pos]
lemma rpow_pow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : (x ^ y) ^ n = (x ^ n) ^ y := by
simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y]
lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : (x ^ y) ^ n = (x ^ n) ^ y := by
simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y]
lemma rpow_add_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_def, rpow_def, Complex.ofReal_add,
Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast,
Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm]
lemma rpow_add_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
simpa using rpow_add_intCast hx y n
lemma rpow_sub_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_add_intCast hx y (-n)
lemma rpow_sub_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
simpa using rpow_sub_intCast hx y n
lemma rpow_add_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_intCast]
lemma rpow_add_natCast' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by
rw [rpow_add' hx h, rpow_natCast]
lemma rpow_sub_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_intCast]
lemma rpow_sub_natCast' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by
rw [rpow_sub' hx h, rpow_natCast]
theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' hx h, rpow_one]
lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' hx h, rpow_one]
lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' hx h, rpow_one]
@[simp]
theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by
rw [← rpow_natCast]
simp only [Nat.cast_ofNat]
theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by
suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H
simp only [rpow_intCast, zpow_one, zpow_neg]
theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by
iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all
· rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)]
all_goals positivity
theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm]
theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by
simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy]
theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by
apply exp_injective
rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y]
theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) :
y * log x = log z ↔ x ^ y = z :=
⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h,
by rintro rfl; rw [log_rpow hx]⟩
@[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul hx, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul hx, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel₀ hn0, rpow_one]
theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn
rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel₀ hn0, rpow_one]
lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_natCast]
lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul hx, rpow_intCast]
lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul hx, rpow_intCast]
/-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved
in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/
/-!
## Order and monotonicity
-/
@[gcongr, bound]
theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by
rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx
· rw [← hx, zero_rpow (ne_of_gt hz)]
exact rpow_pos_of_pos (by rwa [← hx] at hxy) _
· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp]
exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz
theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) :
StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) :=
fun _ ha _ _ hab => rpow_lt_rpow ha hab hr
@[gcongr, bound]
theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by
rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl
rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp
exact le_of_lt (rpow_lt_rpow h h₁' h₂')
theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) :
MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) :=
fun _ ha _ _ hab => rpow_le_rpow ha hab hr
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by
have := hx.trans hxy
rw [← inv_lt_inv₀, ← rpow_neg, ← rpow_neg]
on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz)
all_goals positivity
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by
have := hx.trans_le hxy
rw [← inv_le_inv₀, ← rpow_neg, ← rpow_neg]
on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz)
all_goals positivity
theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩
theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le,
fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz
lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity
lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity
lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y :=
lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz
lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z :=
lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz
theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by
rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x < y ^ z⁻¹ ↔ y < x ^ z := by
rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ^ z⁻¹ < y ↔ y ^ z < x := by
rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) :
x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by
rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity
theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by
repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)]
rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx)
@[gcongr]
theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by
repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)]
rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx)
theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) :
x ^ z < y ^ z := by
have hx : 0 < x := hy.trans hxy
rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z),
inv_lt_inv₀ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)]
exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz
theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) :
StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) :=
fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr
theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) :
x ^ z ≤ y ^ z := by
rcases ne_or_eq z 0 with hz_zero | rfl
case inl =>
rcases ne_or_eq x y with hxy' | rfl
case inl =>
exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy)
(Ne.lt_of_le hz_zero hz)
case inr => simp
case inr => simp
theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) :
AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) :=
fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr
@[simp]
theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by
have x_pos : 0 < x := lt_trans zero_lt_one hx
rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos,
log_rpow x_pos, mul_le_mul_right (log_pos hx)]
@[simp]
theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by
rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le]
theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by
repeat' rw [rpow_def_of_pos hx0]
rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1)
theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by
repeat' rw [rpow_def_of_pos hx0]
rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1)
@[simp]
theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
x ^ y ≤ x ^ z ↔ z ≤ y := by
rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0,
mul_le_mul_right_of_neg (log_neg hx0 hx1)]
@[simp]
theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
x ^ y < x ^ z ↔ z < y := by
rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le]
theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by
rw [← one_rpow z]
exact rpow_lt_rpow hx1 hx2 hz
theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by
rw [← one_rpow z]
exact rpow_le_rpow hx1 hx2 hz
theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by
convert rpow_lt_rpow_of_exponent_lt hx hz
exact (rpow_zero x).symm
theorem rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := by
convert rpow_le_rpow_of_exponent_le hx hz
exact (rpow_zero x).symm
theorem one_lt_rpow {x z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by
rw [← one_rpow z]
exact rpow_lt_rpow zero_le_one hx hz
|
theorem one_le_rpow {x z : ℝ} (hx : 1 ≤ x) (hz : 0 ≤ z) : 1 ≤ x ^ z := by
| Mathlib/Analysis/SpecialFunctions/Pow/Real.lean | 670 | 671 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Set.Piecewise
import Mathlib.Logic.Equiv.Defs
import Mathlib.Tactic.Core
import Mathlib.Tactic.Attr.Core
/-!
# Partial equivalences
This files defines equivalences between subsets of given types.
An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively
from α to β and from β to α (just like equivs), which are inverse to each other on the subsets
`e.source` and `e.target` of respectively α and β.
They are designed in particular to define charts on manifolds.
The main functionality is `e.trans f`, which composes the two partial equivalences by restricting
the source and target to the maximal set where the composition makes sense.
As for equivs, we register a coercion to functions and use it in our simp normal form: we write
`e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`.
## Main definitions
* `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ
* `PartialEquiv.symm`: the inverse of a partial equivalence
* `PartialEquiv.trans`: the composition of two partial equivalences
* `PartialEquiv.refl`: the identity partial equivalence
* `PartialEquiv.ofSet`: the identity on a set `s`
* `EqOnSource`: equivalence relation describing the "right" notion of equality for partial
equivalences (see below in implementation notes)
## Implementation notes
There are at least three possible implementations of partial equivalences:
* equivs on subtypes
* pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial
equivalence is not defined
* pairs of functions defined everywhere, keeping the source and target as additional data
Each of these implementations has pros and cons.
* When dealing with subtypes, one still need to define additional API for composition and
restriction of domains. Checking that one always belongs to the right subtype makes things very
tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for
instance).
* With option-valued functions, the composition is very neat (it is just the usual composition, and
the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds,
where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of
overhead as one would need to extend all classes of smoothness to option-valued maps.
* The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that
there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`).
In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding
source and target and equality there. Moreover, there are no partial equivs in this sense between
an empty type and a nonempty type. Since empty types are not that useful, and since one almost never
needs to talk about equal partial equivs, this is not an issue in practice.
Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of
equality, and show that many properties are invariant under this equivalence relation.
### Local coding conventions
If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`,
then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`.
-/
open Lean Meta Elab Tactic
/-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined
functions (`PartialEquiv`, `PartialHomeomorph`, etc).
This is in a separate file from `Mathlib.Logic.Equiv.MfldSimpsAttr` because attributes need a new
file to become functional.
-/
/-- Common `@[simps]` configuration options used for manifold-related declarations. -/
def mfld_cfg : Simps.Config where
attrs := [`mfld_simps]
fullyApplied := false
namespace Tactic.MfldSetTac
/-- A very basic tactic to show that sets showing up in manifolds coincide or are included
in one another. -/
elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do
let g ← getMainGoal
let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs
match goalTy with
| (``Eq, #[_ty, _e₁, _e₂]) =>
evalTactic (← `(tactic| (
apply Set.ext; intro my_y
constructor <;>
· intro h_my_y
try simp only [*, mfld_simps] at h_my_y
try simp only [*, mfld_simps])))
| (``Subset, #[_ty, _inst, _e₁, _e₂]) =>
evalTactic (← `(tactic| (
intro my_y h_my_y
try simp only [*, mfld_simps] at h_my_y
try simp only [*, mfld_simps])))
| _ => throwError "goal should be an equality or an inclusion"
attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply
end Tactic.MfldSetTac
open Function Set
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The
(global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are
inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of
`target` are irrelevant. -/
structure PartialEquiv (α : Type*) (β : Type*) where
/-- The global function which has a partial inverse. Its value outside of the `source` subset is
irrelevant. -/
toFun : α → β
/-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/
invFun : β → α
/-- The domain of the partial equivalence. -/
source : Set α
/-- The codomain of the partial equivalence. -/
target : Set β
/-- The proposition that elements of `source` are mapped to elements of `target`. -/
map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target
/-- The proposition that elements of `target` are mapped to elements of `source`. -/
map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source
/-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/
left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x
/-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/
right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x
attribute [coe] PartialEquiv.toFun
namespace PartialEquiv
variable (e : PartialEquiv α β) (e' : PartialEquiv β γ)
instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) :=
⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _,
eqOn_empty _ _⟩⟩
/-- The inverse of a partial equivalence -/
@[symm]
protected def symm : PartialEquiv β α where
toFun := e.invFun
invFun := e.toFun
source := e.target
target := e.source
map_source' := e.map_target'
map_target' := e.map_source'
left_inv' := e.right_inv'
right_inv' := e.left_inv'
instance : CoeFun (PartialEquiv α β) fun _ => α → β :=
⟨PartialEquiv.toFun⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : PartialEquiv α β) : β → α :=
e.symm
initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply)
theorem coe_mk (f : α → β) (g s t ml mr il ir) :
(PartialEquiv.mk f g s t ml mr il ir : α → β) = f := rfl
@[simp, mfld_simps]
theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) :
((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g :=
rfl
@[simp, mfld_simps]
theorem invFun_as_coe : e.invFun = e.symm :=
rfl
@[simp, mfld_simps]
theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
/-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/
lemma map_source'' : e '' e.source ⊆ e.target :=
fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx)
@[simp, mfld_simps]
theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
@[simp, mfld_simps]
theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
@[simp, mfld_simps]
theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) :
x = e.symm y ↔ e x = y :=
⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩
protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source
theorem symm_mapsTo : MapsTo e.symm e.target e.source :=
e.symm.mapsTo
protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv
protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv
protected theorem invOn : InvOn e.symm e e.source e.target :=
⟨e.leftInvOn, e.rightInvOn⟩
protected theorem injOn : InjOn e e.source :=
e.leftInvOn.injOn
protected theorem bijOn : BijOn e e.source e.target :=
e.invOn.bijOn e.mapsTo e.symm_mapsTo
protected theorem surjOn : SurjOn e e.source e.target :=
e.bijOn.surjOn
/-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain
and to `t` in the codomain. -/
@[simps -fullyApplied]
def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) :
PartialEquiv α β where
toFun := e
invFun := e.symm
source := s
target := t
map_source' _ hx := h ▸ mem_image_of_mem _ hx
map_target' x hx := by
subst t
rcases hx with ⟨x, hx, rfl⟩
rwa [e.symm_apply_apply]
left_inv' x _ := e.symm_apply_apply x
right_inv' x _ := e.apply_symm_apply x
/-- Associate a `PartialEquiv` to an `Equiv`. -/
@[simps! (config := mfld_cfg)]
def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β :=
e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq]
instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) :=
⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩
/-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/
@[simps -fullyApplied]
def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α)
(hs : e.source = s) (t : Set β) (ht : e.target = t) :
PartialEquiv α β where
toFun := f
invFun := g
source := s
target := t
map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source
map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target
left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv
right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv
theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g)
(s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) :
e.copy f hf g hg s hs t ht = e := by
substs f g s t
cases e
rfl
/-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/
protected def toEquiv : e.source ≃ e.target where
toFun x := ⟨e x, e.map_source x.mem⟩
invFun y := ⟨e.symm y, e.map_target y.mem⟩
left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx
right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy
@[simp, mfld_simps]
theorem symm_source : e.symm.source = e.target :=
rfl
@[simp, mfld_simps]
theorem symm_target : e.symm.target = e.source :=
rfl
@[simp, mfld_simps]
theorem symm_symm : e.symm.symm = e := rfl
theorem symm_bijective :
Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
theorem image_source_eq_target : e '' e.source = e.target :=
e.bijOn.image_eq
theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by
rw [← image_source_eq_target, forall_mem_image]
theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by
rw [← image_source_eq_target, exists_mem_image]
/-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if
any of the following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
-/
def IsImage (s : Set α) (t : Set β) : Prop :=
∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
namespace IsImage
variable {e} {s : Set α} {t : Set β} {x : α}
theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s :=
h hx
theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) :=
e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx]
protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s :=
h.symm_apply_mem_iff
@[simp]
theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t :=
⟨fun h => h.symm, fun h => h.symm⟩
protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) :=
fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩
theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) :=
h.symm.mapsTo
/-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/
@[simps -fullyApplied]
def restr (h : e.IsImage s t) : PartialEquiv α β where
toFun := e
invFun := e.symm
source := e.source ∩ s
target := e.target ∩ t
map_source' := h.mapsTo
map_target' := h.symm_mapsTo
left_inv' := e.leftInvOn.mono inter_subset_left
right_inv' := e.rightInvOn.mono inter_subset_left
theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t :=
h.restr.image_source_eq_target
theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
h.symm.image_eq
theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by
simp only [IsImage, Set.ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff]
alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq
theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
symm_iff.symm.trans iff_preimage_eq
alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq
theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t :=
of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h
theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t :=
of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h
protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx)
protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx)
protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx)
protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s \ s') (t \ t') :=
h.inter h'.compl
theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)]
[∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) :
LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by
rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩)
· rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he]
· rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs),
e'.left_inv he]
theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t)
(h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) :
e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq]
theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t)
(hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) :
EqOn e.symm e'.symm (e.target ∩ t) := by
rw [← h.image_eq]
rintro y ⟨x, hx, rfl⟩
have hx' := hx; rw [hs] at hx'
rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1]
end IsImage
theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx]
theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source)
(ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target :=
IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty]
theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by
rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm]
theorem image_source_inter_eq (s : Set α) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by
rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm]
theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s := by
rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h]
theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
theorem symm_image_target_inter_eq (s : Set β) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) :=
e.symm.image_source_inter_eq _
theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.symm.image_source_inter_eq' _
theorem source_inter_preimage_inv_preimage (s : Set α) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
Set.ext fun x => and_congr_right_iff.2 fun hx =>
by simp only [mem_preimage, e.left_inv hx]
theorem source_inter_preimage_target_inter (s : Set β) :
e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩
theorem target_inter_inv_preimage_preimage (s : Set β) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s :=
(e.leftInvOn.mono h).image_image
theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image_of_subset_source h
theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target :=
e.mapsTo
theorem symm_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.image_source_eq_target
theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source :=
e.symm_mapsTo
/-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/
@[ext]
protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x)
(hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by
have A : (e : α → β) = e' := by
ext x
exact h x
have B : (e.symm : β → α) = e'.symm := by
ext x
exact hsymm x
have I : e '' e.source = e.target := e.image_source_eq_target
have I' : e' '' e'.source = e'.target := e'.image_source_eq_target
rw [A, hs, I'] at I
cases e; cases e'
simp_all
/-- Restricting a partial equivalence to `e.source ∩ s` -/
protected def restr (s : Set α) : PartialEquiv α β :=
(@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr
@[simp, mfld_simps]
theorem restr_coe (s : Set α) : (e.restr s : α → β) = e :=
rfl
@[simp, mfld_simps]
theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm :=
rfl
@[simp, mfld_simps]
theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s :=
rfl
theorem source_restr_subset_source (s : Set α) : (e.restr s).source ⊆ e.source := inter_subset_left
@[simp, mfld_simps]
theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s :=
rfl
theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) :
e.restr s = e :=
PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h])
@[simp, mfld_simps]
theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
/-- The identity partial equiv -/
protected def refl (α : Type*) : PartialEquiv α α :=
(Equiv.refl α).toPartialEquiv
@[simp, mfld_simps]
theorem refl_source : (PartialEquiv.refl α).source = univ :=
rfl
@[simp, mfld_simps]
theorem refl_target : (PartialEquiv.refl α).target = univ :=
rfl
@[simp, mfld_simps]
theorem refl_coe : (PartialEquiv.refl α : α → α) = id :=
rfl
@[simp, mfld_simps]
theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α :=
rfl
@[mfld_simps]
theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp
@[mfld_simps]
theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by simp
/-- The identity partial equivalence on a set `s` -/
def ofSet (s : Set α) : PartialEquiv α α where
toFun := id
invFun := id
source := s
target := s
map_source' _ hx := hx
map_target' _ hx := hx
left_inv' _ _ := rfl
right_inv' _ _ := rfl
@[simp, mfld_simps]
theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s :=
rfl
@[simp, mfld_simps]
theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s :=
rfl
@[simp, mfld_simps]
theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id :=
rfl
@[simp, mfld_simps]
theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s :=
rfl
| /-- `Function.const` as a `PartialEquiv`.
It consists of two constant maps in opposite directions. -/
@[simps]
def single (a : α) (b : β) : PartialEquiv α β where
toFun := Function.const α b
invFun := Function.const β a
source := {a}
target := {b}
map_source' _ _ := rfl
map_target' _ _ := rfl
left_inv' a' ha' := by rw [eq_of_mem_singleton ha', const_apply]
right_inv' b' hb' := by rw [eq_of_mem_singleton hb', const_apply]
| Mathlib/Logic/Equiv/PartialEquiv.lean | 557 | 569 |
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Combinatorics.SimpleGraph.Dart
import Mathlib.Combinatorics.SimpleGraph.Finite
import Mathlib.Data.ZMod.Basic
/-!
# Degree-sum formula and handshaking lemma
The degree-sum formula is that the sum of the degrees of the vertices in
a finite graph is equal to twice the number of edges. The handshaking lemma,
a corollary, is that the number of odd-degree vertices is even.
## Main definitions
- `SimpleGraph.sum_degrees_eq_twice_card_edges` is the degree-sum formula.
- `SimpleGraph.even_card_odd_degree_vertices` is the handshaking lemma.
- `SimpleGraph.odd_card_odd_degree_vertices_ne` is that the number of odd-degree
vertices different from a given odd-degree vertex is odd.
- `SimpleGraph.exists_ne_odd_degree_of_exists_odd_degree` is that the existence of an
odd-degree vertex implies the existence of another one.
## Implementation notes
We give a combinatorial proof by using the facts that (1) the map from
darts to vertices is such that each fiber has cardinality the degree
of the corresponding vertex and that (2) the map from darts to edges is 2-to-1.
## Tags
simple graphs, sums, degree-sum formula, handshaking lemma
-/
assert_not_exists Field TwoSidedIdeal
open Finset
namespace SimpleGraph
universe u
variable {V : Type u} (G : SimpleGraph V)
section DegreeSum
variable [Fintype V] [DecidableRel G.Adj]
theorem dart_fst_fiber [DecidableEq V] (v : V) :
({d : G.Dart | d.fst = v} : Finset _) = univ.image (G.dartOfNeighborSet v) := by
ext d
simp only [mem_image, true_and, mem_filter, SetCoe.exists, mem_univ, exists_prop_of_true]
constructor
· rintro rfl
exact ⟨_, d.adj, by ext <;> rfl⟩
· rintro ⟨e, he, rfl⟩
rfl
theorem dart_fst_fiber_card_eq_degree [DecidableEq V] (v : V) :
#{d : G.Dart | d.fst = v} = G.degree v := by
simpa only [dart_fst_fiber, Finset.card_univ, card_neighborSet_eq_degree] using
card_image_of_injective univ (G.dartOfNeighborSet_injective v)
theorem dart_card_eq_sum_degrees : Fintype.card G.Dart = ∑ v, G.degree v := by
haveI := Classical.decEq V
simp only [← card_univ, ← dart_fst_fiber_card_eq_degree]
exact card_eq_sum_card_fiberwise (by simp)
variable {G} in
| theorem Dart.edge_fiber [DecidableEq V] (d : G.Dart) :
({d' : G.Dart | d'.edge = d.edge} : Finset _) = {d, d.symm} :=
Finset.ext fun d' => by simpa using dart_edge_eq_iff d' d
| Mathlib/Combinatorics/SimpleGraph/DegreeSum.lean | 73 | 76 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Eric Wieser
-/
import Mathlib.Data.Matrix.Basis
import Mathlib.Data.Matrix.Composition
import Mathlib.Data.Matrix.Kronecker
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# Algebra isomorphisms between tensor products and matrices
## Main definitions
* `matrixEquivTensor : Matrix n n A ≃ₐ[R] (A ⊗[R] Matrix n n R)`.
* `Matrix.kroneckerTMulAlgEquiv :
Matrix m m A ⊗[R] Matrix n n B ≃ₐ[R] Matrix (m × n) (m × n) (A ⊗[R] B)`,
where the forward map is the (tensor-ified) kronecker product.
-/
suppress_compilation
open TensorProduct Algebra.TensorProduct Matrix
variable {l m n p : Type*} {R A B M N : Type*}
section Module
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Semiring A] [Semiring B]
variable [Module R M] [Module R N] [Algebra R A] [Algebra R B]
variable [Fintype l] [Fintype m] [Fintype n] [Fintype p]
variable [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq p]
open Kronecker
variable (l m n p R M N)
attribute [local ext] ext_linearMap
/-- `Matrix.kroneckerTMul` as a linear equivalence, when the two arguments are tensored. -/
def kroneckerTMulLinearEquiv :
Matrix l m M ⊗[R] Matrix n p N ≃ₗ[R] Matrix (l × n) (m × p) (M ⊗[R] N) :=
.ofLinear
(TensorProduct.lift <| kroneckerTMulBilinear _)
((LinearMap.lsum R _ R fun ii => LinearMap.lsum R _ R fun jj => TensorProduct.map
(stdBasisMatrixLinearMap R ii.1 jj.1) (stdBasisMatrixLinearMap R ii.2 jj.2))
∘ₗ (ofLinearEquiv R).symm.toLinearMap)
(by
ext : 4
simp [-LinearMap.lsum_apply, LinearMap.lsum_piSingle,
stdBasisMatrix_kroneckerTMul_stdBasisMatrix])
(by
ext : 5
simp [-LinearMap.lsum_apply, LinearMap.lsum_piSingle,
stdBasisMatrix_kroneckerTMul_stdBasisMatrix])
@[simp]
theorem kroneckerTMulLinearEquiv_tmul (a : Matrix l m M) (b : Matrix n p N) :
kroneckerTMulLinearEquiv l m n p R M N (a ⊗ₜ b) = a ⊗ₖₜ b := rfl
@[simp]
theorem kroneckerTMulAlgEquiv_symm_stdBasisMatrix_tmul
(ia : l) (ja : m) (ib : n) (jb : p) (a : M) (b : N) :
(kroneckerTMulLinearEquiv l m n p R M N).symm (stdBasisMatrix (ia, ib) (ja, jb) (a ⊗ₜ b)) =
stdBasisMatrix ia ja a ⊗ₜ stdBasisMatrix ib jb b := by
rw [LinearEquiv.symm_apply_eq, kroneckerTMulLinearEquiv_tmul,
stdBasisMatrix_kroneckerTMul_stdBasisMatrix]
@[simp]
theorem kroneckerTMulLinearEquiv_one :
kroneckerTMulLinearEquiv m m n n R A B 1 = 1 := by simp [Algebra.TensorProduct.one_def]
/-- Note this can't be stated for rectangular matrices because there is no
`HMul (TensorProduct R _ _) (TensorProduct R _ _) (TensorProduct R _ _)` instance. -/
@[simp]
theorem kroneckerTMulLinearEquiv_mul :
∀ x y : Matrix m m A ⊗[R] Matrix n n B,
kroneckerTMulLinearEquiv m m n n R A B (x * y) =
kroneckerTMulLinearEquiv m m n n R A B x * kroneckerTMulLinearEquiv m m n n R A B y :=
(kroneckerTMulLinearEquiv m m n n R A B).toLinearMap.map_mul_iff.2 <| by
ext : 10
simp [stdBasisMatrix_kroneckerTMul_stdBasisMatrix, mul_kroneckerTMul_mul]
end Module
variable [CommSemiring R]
variable [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
variable (n R A)
namespace MatrixEquivTensor
/-- (Implementation detail).
The function underlying `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`,
as an `R`-bilinear map.
-/
def toFunBilinear : A →ₗ[R] Matrix n n R →ₗ[R] Matrix n n A :=
(Algebra.lsmul R R (Matrix n n A)).toLinearMap.compl₂ (Algebra.linearMap R A).mapMatrix
@[simp]
theorem toFunBilinear_apply (a : A) (m : Matrix n n R) :
toFunBilinear n R A a m = a • m.map (algebraMap R A) :=
rfl
/-- (Implementation detail).
The function underlying `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`,
as an `R`-linear map.
-/
def toFunLinear : A ⊗[R] Matrix n n R →ₗ[R] Matrix n n A :=
TensorProduct.lift (toFunBilinear n R A)
| variable [DecidableEq n] [Fintype n]
/-- The function `(A ⊗[R] Matrix n n R) →ₐ[R] Matrix n n A`, as an algebra homomorphism.
-/
def toFunAlgHom : A ⊗[R] Matrix n n R →ₐ[R] Matrix n n A :=
algHomOfLinearMapTensorProduct (toFunLinear n R A)
(by
intros
simp_rw [toFunLinear, lift.tmul, toFunBilinear_apply, Matrix.map_mul]
| Mathlib/RingTheory/MatrixAlgebra.lean | 113 | 121 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.InnerProductSpace.Orthogonal
import Mathlib.Analysis.InnerProductSpace.Symmetric
import Mathlib.Analysis.NormedSpace.RCLike
import Mathlib.Analysis.RCLike.Lemmas
import Mathlib.Algebra.DirectSum.Decomposition
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`K.orthogonalProjection : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = K.orthogonalProjection u` in `K` minimizes the
distance `‖u - v‖` to `u`.
Also a linear isometry equivalence `K.reflection : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `K.reflection u` to satisfy
`u + (K.reflection u) = 2 • K.orthogonalProjection u`.
Basic API for `orthogonalProjection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma
`Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable section
open InnerProductSpace
open RCLike Real Filter
open LinearMap (ker range)
open Topology Finsupp
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "absR" => abs
/-! ### Orthogonal projection in inner product spaces -/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
/-- **Existence of minimizers**, aka the **Hilbert projection theorem**.
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/
theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K)
(h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by
let δ := ⨅ w : K, ‖u - w‖
letI : Nonempty K := ne.to_subtype
have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _
have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by
have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n =>
lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat
have h := fun n => exists_lt_of_ciInf_lt (hδ n)
let w : ℕ → K := fun n => Classical.choose (h n)
exact ⟨w, fun n => Classical.choose_spec (h n)⟩
rcases exists_seq with ⟨w, hw⟩
have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by
have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds
have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by
convert h.add tendsto_one_div_add_atTop_nhds_zero_nat
simp only [add_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _)
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : CauchySeq fun n => (w n : F) := by
rw [cauchySeq_iff_le_tendsto_0]
-- splits into three goals
let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1))
use fun n => √(b n)
constructor
-- first goal : `∀ (n : ℕ), 0 ≤ √(b n)`
· intro n
exact sqrt_nonneg _
constructor
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)`
· intro p q N hp hq
let wp := (w p : F)
let wq := (w q : F)
let a := u - wq
let b := u - wp
let half := 1 / (2 : ℝ)
let div := 1 / ((N : ℝ) + 1)
have :
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) :=
calc
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ :=
by ring
_ =
absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) +
‖wp - wq‖ * ‖wp - wq‖ := by
rw [abs_of_nonneg]
exact zero_le_two
_ =
‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ +
‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul]
_ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ←
one_add_one_eq_two, add_smul]
simp only [one_smul]
have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm
have eq₂ : u + u - (wq + wp) = a + b := by
show u + u - (wq + wp) = u - wq + (u - wp)
abel
rw [eq₁, eq₂]
_ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _
have eq : δ ≤ ‖u - half • (wq + wp)‖ := by
rw [smul_add]
apply δ_le'
apply h₂
repeat' exact Subtype.mem _
repeat' exact le_of_lt one_half_pos
exact add_halves 1
have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp_rw [mul_assoc]
gcongr
have eq₂ : ‖a‖ ≤ δ + div :=
le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _)
have eq₂' : ‖b‖ ≤ δ + div :=
le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _)
rw [dist_eq_norm]
apply nonneg_le_nonneg_of_sq_le_sq
· exact sqrt_nonneg _
rw [mul_self_sqrt]
· calc
‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp [← this]
_ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr
_ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr
_ = 8 * δ * div + 4 * div * div := by ring
positivity
-- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)`
suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0)
from this.comp tendsto_one_div_add_atTop_nhds_zero_nat
exact Continuous.tendsto' (by fun_prop) _ _ (by simp)
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with
⟨v, hv, w_tendsto⟩
use v
use hv
have h_cont : Continuous fun v => ‖u - v‖ :=
Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id)
have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by
convert Tendsto.comp h_cont.continuousAt w_tendsto
exact tendsto_nhds_unique this norm_tendsto
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
letI : Nonempty K := ⟨⟨v, hv⟩⟩
constructor
· intro eq w hw
let δ := ⨅ w : K, ‖u - w‖
let p := ⟪u - v, w - v⟫_ℝ
let q := ‖w - v‖ ^ 2
have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _
have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩
have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by
have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 :=
calc ‖u - v‖ ^ 2
_ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by
simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _)
rw [eq]; apply δ_le'
apply h hw hv
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _]
_ = ‖u - v - θ • (w - v)‖ ^ 2 := by
have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by
rw [smul_sub, sub_smul, one_smul]
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev]
rw [this]
_ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by
rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul]
simp only [sq]
show
‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) +
absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) =
‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖)
rw [abs_of_pos hθ₁]; ring
have eq₁ :
‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 =
‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by
abel
rw [eq₁, le_add_iff_nonneg_right] at this
have eq₂ :
θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) =
θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring
rw [eq₂] at this
exact le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁)
by_cases hq : q = 0
· rw [hq] at this
have : p ≤ 0 := by
have := this (1 : ℝ) (by norm_num) (by norm_num)
linarith
exact this
· have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm
by_contra hp
rw [not_le] at hp
let θ := min (1 : ℝ) (p / q)
have eq₁ : θ * q ≤ p :=
calc
θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
_ = p := div_mul_cancel₀ _ hq
have : 2 * p ≤ p :=
calc
2 * p ≤ θ * q := by
exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ])
_ ≤ p := eq₁
linarith
· intro h
apply le_antisymm
· apply le_ciInf
intro w
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _)
have := h w w.2
calc
‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith
_ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by
rw [sq]
refine le_add_of_nonneg_right ?_
exact sq_nonneg _
_ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm
_ = ‖u - w‖ * ‖u - w‖ := by
have : u - v - (w - v) = u - w := by abel
rw [this, sq]
· show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩
apply ciInf_le
use 0
rintro y ⟨z, rfl⟩
exact norm_nonneg _
variable (K : Submodule 𝕜 E)
namespace Submodule
/-- Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) :
∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K
exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
/-- Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superseded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over
any `RCLike` field.
-/
theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
Iff.intro
(by
intro h
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
rwa [norm_eq_iInf_iff_real_inner_le_zero] at h
exacts [K.convex, hv]
intro w hw
have le : ⟪u - v, w⟫_ℝ ≤ 0 := by
let w' := w + v
have : w' ∈ K := Submodule.add_mem _ hw hv
have h₁ := h w' this
have h₂ : w' - v = w := by
simp only [w', add_neg_cancel_right, sub_eq_add_neg]
rw [h₂] at h₁
exact h₁
have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by
let w'' := -w + v
have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv
have h₁ := h w'' this
have h₂ : w'' - v = -w := by
simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg]
rw [h₂, inner_neg_right] at h₁
linarith
exact le_antisymm le ge)
(by
intro h
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
intro w hw
let w' := w - v
have : w' ∈ K := Submodule.sub_mem _ hw hv
have h₁ := h w' this
exact le_of_eq h₁
rwa [norm_eq_iInf_iff_real_inner_le_zero]
exacts [Submodule.convex _, hv])
/-- Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := K.restrictScalars ℝ
constructor
· intro H
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).1 H
intro w hw
apply RCLike.ext
· simp [A w hw]
· symm
calc
im (0 : 𝕜) = 0 := im.map_zero
_ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm
_ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right]
_ = im ⟪u - v, w⟫ := by simp
· intro H
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by
intro w hw
rw [real_inner_eq_re_inner, H w hw]
exact zero_re'
exact (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).2 this
/-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if every vector `v : E` admits an
orthogonal projection to `K`. -/
class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where
exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ
instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] :
K.HasOrthogonalProjection where
exists_orthogonal v := by
rcases K.exists_norm_eq_iInf_of_complete_subspace (completeSpace_coe_iff_isComplete.mp ‹_›) v
with ⟨w, hwK, hw⟩
refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩
rwa [← K.norm_eq_iInf_iff_inner_eq_zero hwK]
instance [K.HasOrthogonalProjection] : Kᗮ.HasOrthogonalProjection where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩
refine ⟨_, hw, ?_⟩
rw [sub_sub_cancel]
exact K.le_orthogonal_orthogonal hwK
instance HasOrthogonalProjection.map_linearIsometryEquiv [K.HasOrthogonalProjection]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
(K.map (f.toLinearEquiv : E →ₗ[𝕜] E')).HasOrthogonalProjection where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩
refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩
erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu]
instance HasOrthogonalProjection.map_linearIsometryEquiv' [K.HasOrthogonalProjection]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
(K.map f.toLinearIsometry).HasOrthogonalProjection :=
HasOrthogonalProjection.map_linearIsometryEquiv K f
instance : (⊤ : Submodule 𝕜 E).HasOrthogonalProjection := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩
section orthogonalProjection
variable [K.HasOrthogonalProjection]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonalProjection` and should not
be used once that is defined. -/
def orthogonalProjectionFn (v : E) :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose
variable {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_mem (v : E) : K.orthogonalProjectionFn v ∈ K :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - K.orthogonalProjectionFn v, w⟫ = 0 :=
(K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : K.orthogonalProjectionFn u = v := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜]
have hvs : K.orthogonalProjectionFn u - v ∈ K :=
Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm
have huo : ⟪u - K.orthogonalProjectionFn u, K.orthogonalProjectionFn u - v⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero u _ hvs
have huv : ⟪u - v, K.orthogonalProjectionFn u - v⟫ = 0 := hvo _ hvs
have houv : ⟪u - v - (u - K.orthogonalProjectionFn u), K.orthogonalProjectionFn u - v⟫ = 0 := by
rw [inner_sub_left, huo, huv, sub_zero]
rwa [sub_sub_sub_cancel_left] at houv
variable (K)
theorem orthogonalProjectionFn_norm_sq (v : E) :
‖v‖ * ‖v‖ =
‖v - K.orthogonalProjectionFn v‖ * ‖v - K.orthogonalProjectionFn v‖ +
‖K.orthogonalProjectionFn v‖ * ‖K.orthogonalProjectionFn v‖ := by
set p := K.orthogonalProjectionFn v
have h' : ⟪v - p, p⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v)
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp
/-- The orthogonal projection onto a complete subspace. -/
def orthogonalProjection : E →L[𝕜] K :=
LinearMap.mkContinuous
{ toFun := fun v => ⟨K.orthogonalProjectionFn v, orthogonalProjectionFn_mem v⟩
map_add' := fun x y => by
have hm : K.orthogonalProjectionFn x + K.orthogonalProjectionFn y ∈ K :=
Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y)
have ho :
∀ w ∈ K, ⟪x + y - (K.orthogonalProjectionFn x + K.orthogonalProjectionFn y), w⟫ = 0 := by
intro w hw
rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho]
map_smul' := fun c x => by
have hm : c • K.orthogonalProjectionFn x ∈ K :=
Submodule.smul_mem K _ (orthogonalProjectionFn_mem x)
have ho : ∀ w ∈ K, ⟪c • x - c • K.orthogonalProjectionFn x, w⟫ = 0 := by
intro w hw
rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
mul_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] }
1 fun x => by
simp only [one_mul, LinearMap.coe_mk]
refine le_of_pow_le_pow_left₀ two_ne_zero (norm_nonneg _) ?_
change ‖K.orthogonalProjectionFn x‖ ^ 2 ≤ ‖x‖ ^ 2
nlinarith [K.orthogonalProjectionFn_norm_sq x]
variable {K}
@[simp]
theorem orthogonalProjectionFn_eq (v : E) :
K.orthogonalProjectionFn v = (K.orthogonalProjection v : E) :=
rfl
/-- The characterization of the orthogonal projection. -/
@[simp]
theorem orthogonalProjection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - K.orthogonalProjection v, w⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero v
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp]
theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - K.orthogonalProjection v ∈ Kᗮ := by
intro w hw
rw [inner_eq_zero_symm]
exact orthogonalProjection_inner_eq_zero _ _ hw
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K)
(hvo : u - v ∈ Kᗮ) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E}
(hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] )
@[simp]
theorem orthogonalProjection_orthogonal_val (u : E) :
(Kᗮ.orthogonalProjection u : E) = u - K.orthogonalProjection u :=
eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _)
(K.le_orthogonal_orthogonal (K.orthogonalProjection u).2) <| by simp
theorem orthogonalProjection_orthogonal (u : E) :
Kᗮ.orthogonalProjection u =
⟨u - K.orthogonalProjection u, sub_orthogonalProjection_mem_orthogonal _⟩ :=
Subtype.eq <| orthogonalProjection_orthogonal_val _
/-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/
theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [U.HasOrthogonalProjection] (y : E) :
‖y - U.orthogonalProjection y‖ = ⨅ x : U, ‖y - x‖ := by
rw [U.norm_eq_iInf_iff_inner_eq_zero (Submodule.coe_mem _)]
exact orthogonalProjection_inner_eq_zero _
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [K'.HasOrthogonalProjection]
(h : K = K') (u : E) : (K.orthogonalProjection u : E) = (K'.orthogonalProjection u : E) := by
subst h; rfl
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp]
theorem orthogonalProjection_mem_subspace_eq_self (v : K) : K.orthogonalProjection v = v := by
ext
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
theorem orthogonalProjection_eq_self_iff {v : E} : (K.orthogonalProjection v : E) = v ↔ v ∈ K := by
refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩
· rw [← h]
simp
· simp
@[simp]
theorem orthogonalProjection_eq_zero_iff {v : E} : K.orthogonalProjection v = 0 ↔ v ∈ Kᗮ := by
refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal
(zero_mem _) ?_⟩
· simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v
· simpa
@[simp]
theorem ker_orthogonalProjection : LinearMap.ker K.orthogonalProjection = Kᗮ := by
ext; exact orthogonalProjection_eq_zero_iff
theorem _root_.LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f.toLinearMap).HasOrthogonalProjection]
(x : E) : f (p.orthogonalProjection x) = (p.map f.toLinearMap).orthogonalProjection (f x) := by
refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm
· refine Submodule.apply_coe_mem_map _ _
rcases hy with ⟨x', hx', rfl : f x' = y⟩
rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx']
theorem _root_.LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f).HasOrthogonalProjection] (x : E) :
f (p.orthogonalProjection x) = (p.map f).orthogonalProjection (f x) :=
have : (p.map f.toLinearMap).HasOrthogonalProjection := ‹_›
f.map_orthogonalProjection p x
/-- Orthogonal projection onto the `Submodule.map` of a subspace. -/
theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] (x : E') :
((p.map (f.toLinearEquiv : E →ₗ[𝕜] E')).orthogonalProjection x : E') =
f (p.orthogonalProjection (f.symm x)) := by
simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using
(f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm
/-- The orthogonal projection onto the trivial submodule is the zero map. -/
@[simp]
theorem orthogonalProjection_bot : (⊥ : Submodule 𝕜 E).orthogonalProjection = 0 := by ext
variable (K)
/-- The orthogonal projection has norm `≤ 1`. -/
theorem orthogonalProjection_norm_le : ‖K.orthogonalProjection‖ ≤ 1 :=
LinearMap.mkContinuous_norm_le _ (by norm_num) _
variable (𝕜)
theorem smul_orthogonalProjection_singleton {v : E} (w : E) :
((‖v‖ ^ 2 : ℝ) : 𝕜) • ((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by
suffices (((𝕜 ∙ v).orthogonalProjection (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by
simpa using this
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero
· rw [Submodule.mem_span_singleton]
use ⟪v, w⟫
· rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left]
simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm]
/-- Formula for orthogonal projection onto a single vector. -/
theorem orthogonalProjection_singleton {v : E} (w : E) :
((𝕜 ∙ v).orthogonalProjection w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by
by_cases hv : v = 0
· rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)]
simp
have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv)
have key :
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • (((𝕜 ∙ v).orthogonalProjection w) : E) =
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by
simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -map_pow]
convert key using 1 <;> field_simp [hv']
/-- Formula for orthogonal projection onto a single unit vector. -/
theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) :
((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by
rw [← smul_orthogonalProjection_singleton 𝕜 w]
simp [hv]
end orthogonalProjection
section reflection
variable [K.HasOrthogonalProjection]
/-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/
def reflectionLinearEquiv : E ≃ₗ[𝕜] E :=
LinearEquiv.ofInvolutive
(2 • (K.subtype.comp K.orthogonalProjection.toLinearMap) - LinearMap.id) fun x => by
simp [two_smul]
/-- Reflection in a complete subspace of an inner product space. The word "reflection" is
sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes
more generally to cover operations such as reflection in a point. The definition here, of
reflection in a subspace, is a more general sense of the word that includes both those common
cases. -/
def reflection : E ≃ₗᵢ[𝕜] E :=
{ K.reflectionLinearEquiv with
norm_map' := by
intro x
let w : K := K.orthogonalProjection x
let v := x - w
have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2
convert norm_sub_eq_norm_add this using 2
· rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe,
LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul,
LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply,
ContinuousLinearMap.coe_coe]
dsimp [v]
abel
· simp only [v, add_sub_cancel, eq_self_iff_true] }
variable {K}
/-- The result of reflecting. -/
theorem reflection_apply (p : E) : K.reflection p = 2 • (K.orthogonalProjection p : E) - p :=
rfl
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_symm : K.reflection.symm = K.reflection :=
rfl
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_inv : K.reflection⁻¹ = K.reflection :=
rfl
variable (K)
/-- Reflecting twice in the same subspace. -/
@[simp]
theorem reflection_reflection (p : E) : K.reflection (K.reflection p) = p :=
K.reflection.left_inv p
/-- Reflection is involutive. -/
theorem reflection_involutive : Function.Involutive K.reflection :=
K.reflection_reflection
/-- Reflection is involutive. -/
@[simp]
theorem reflection_trans_reflection :
K.reflection.trans K.reflection = LinearIsometryEquiv.refl 𝕜 E :=
LinearIsometryEquiv.ext <| reflection_involutive K
/-- Reflection is involutive. -/
@[simp]
theorem reflection_mul_reflection : K.reflection * K.reflection = 1 :=
reflection_trans_reflection _
theorem reflection_orthogonal_apply (v : E) : Kᗮ.reflection v = -K.reflection v := by
simp [reflection_apply]; abel
theorem reflection_orthogonal : Kᗮ.reflection = .trans K.reflection (.neg _) := by
ext; apply reflection_orthogonal_apply
variable {K}
theorem reflection_singleton_apply (u v : E) :
reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by
rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow]
/-- A point is its own reflection if and only if it is in the subspace. -/
theorem reflection_eq_self_iff (x : E) : K.reflection x = x ↔ x ∈ K := by
rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜,
two_smul ℕ, ← two_smul 𝕜]
refine (smul_right_injective E ?_).eq_iff
exact two_ne_zero
theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : K.reflection x = x :=
(reflection_eq_self_iff x).mpr hx
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[K.HasOrthogonalProjection] (x : E') :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (K.reflection (f.symm x)) := by
simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x]
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[K.HasOrthogonalProjection] :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans (K.reflection.trans f) :=
LinearIsometryEquiv.ext <| reflection_map_apply f K
/-- Reflection through the trivial subspace {0} is just negation. -/
@[simp]
theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by
ext; simp [reflection_apply]
end reflection
end Submodule
section Orthogonal
namespace Submodule
/-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/
theorem sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂)
[K₁.HasOrthogonalProjection] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by
ext x
rw [Submodule.mem_sup]
let v : K₁ := orthogonalProjection K₁ x
have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x
constructor
· rintro ⟨y, hy, z, hz, rfl⟩
exact K₂.add_mem (h hy) hz.2
· exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩
variable {K} in
/-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/
theorem sup_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : K ⊔ Kᗮ = ⊤ := by
convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2
simp
/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/
theorem exists_add_mem_mem_orthogonal [K.HasOrthogonalProjection] (v : E) :
∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z :=
⟨K.orthogonalProjection v, Subtype.coe_prop _, v - K.orthogonalProjection v,
sub_orthogonalProjection_mem_orthogonal _, by simp⟩
/-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal
complement is itself. -/
@[simp]
theorem orthogonal_orthogonal [K.HasOrthogonalProjection] : Kᗮᗮ = K := by
ext v
constructor
· obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v
intro hv
have hz' : z = 0 := by
have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm]
simpa [inner_add_right, hyz] using hv z hz
simp [hy, hz']
· intro hv w hw
rw [inner_eq_zero_symm]
exact hw v hv
/-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K`
is the topological closure of `K`.
Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space
structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum
of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/
theorem orthogonal_orthogonal_eq_closure [CompleteSpace E] :
Kᗮᗮ = K.topologicalClosure := by
refine le_antisymm ?_ ?_
· convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1
rw [K.topologicalClosure.orthogonal_orthogonal]
· exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal
variable {K}
/-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/
theorem isCompl_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : IsCompl K Kᗮ :=
⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩
@[simp]
theorem orthogonalComplement_eq_orthogonalComplement {L : Submodule 𝕜 E} [K.HasOrthogonalProjection]
[L.HasOrthogonalProjection] : Kᗮ = Lᗮ ↔ K = L :=
⟨fun h ↦ by simpa using congr(Submodule.orthogonal $(h)),
fun h ↦ congr(Submodule.orthogonal $(h))⟩
@[simp]
theorem orthogonal_eq_bot_iff [K.HasOrthogonalProjection] : Kᗮ = ⊥ ↔ K = ⊤ := by
refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩
intro h
have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace
rwa [h, sup_comm, bot_sup_eq] at this
/-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/
theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [K.HasOrthogonalProjection]
{v : E} (hv : v ∈ Kᗮ) : K.orthogonalProjection v = 0 := by
ext
convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv]
/-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/
theorem IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] (h : U ⟂ V) : U.orthogonalProjection ∘L V.subtypeL = 0 :=
ContinuousLinearMap.ext fun v =>
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop
/-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/
theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] : U.orthogonalProjection ∘L V.subtypeL = 0 ↔ U ⟂ V :=
⟨fun h u hu v hv => by
convert orthogonalProjection_inner_eq_zero v u hu using 2
have : U.orthogonalProjection v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V)
rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩
theorem orthogonalProjection_eq_linear_proj [K.HasOrthogonalProjection] (x : E) :
K.orthogonalProjection x =
K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by
have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace
conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x]
rw [map_add, orthogonalProjection_mem_subspace_eq_self,
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero]
theorem orthogonalProjection_coe_linearMap_eq_linearProj [K.HasOrthogonalProjection] :
(K.orthogonalProjection : E →ₗ[𝕜] K) =
K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace :=
LinearMap.ext <| orthogonalProjection_eq_linear_proj
/-- The reflection in `K` of an element of `Kᗮ` is its negation. -/
theorem reflection_mem_subspace_orthogonalComplement_eq_neg [K.HasOrthogonalProjection] {v : E}
(hv : v ∈ Kᗮ) : K.reflection v = -v := by
simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv]
/-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/
theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero
[Kᗮ.HasOrthogonalProjection] {v : E} (hv : v ∈ K) : Kᗮ.orthogonalProjection v = 0 :=
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv)
/-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/
theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] [V.HasOrthogonalProjection] (h : U ≤ V) (x : E) :
U.orthogonalProjection (V.orthogonalProjection x) = U.orthogonalProjection x :=
Eq.symm <| by
simpa only [sub_eq_zero, map_sub] using
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero
(Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x))
/-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`,
the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on
`(⨆ i, U i).topologicalClosure` along `atTop`. -/
theorem orthogonalProjection_tendsto_closure_iSup {ι : Type*} [Preorder ι]
(U : ι → Submodule 𝕜 E) [∀ i, (U i).HasOrthogonalProjection]
[(⨆ i, U i).topologicalClosure.HasOrthogonalProjection] (hU : Monotone U) (x : E) :
Filter.Tendsto (fun i => ((U i).orthogonalProjection x : E)) atTop
(𝓝 ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E)) := by
refine .of_neBot_imp fun h ↦ ?_
cases atTop_neBot_iff.mp h
let y := ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E)
have proj_x : ∀ i, (U i).orthogonalProjection x = (U i).orthogonalProjection y := fun i =>
(orthogonalProjection_orthogonalProjection_of_le
((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm
suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖((U i).orthogonalProjection y : E) - y‖ < ε by
simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this
intro ε hε
obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by
have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _
rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem
exact y_mem ε hε
rw [dist_eq_norm] at hay
obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha
refine ⟨I, fun i (hi : I ≤ i) => ?_⟩
rw [norm_sub_rev, orthogonalProjection_minimal]
refine lt_of_le_of_lt ?_ hay
change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖
exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _
/-- Given a monotone family `U` of complete submodules of `E` with dense span supremum,
and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/
theorem orthogonalProjection_tendsto_self {ι : Type*} [Preorder ι]
(U : ι → Submodule 𝕜 E) [∀ t, (U t).HasOrthogonalProjection] (hU : Monotone U) (x : E)
(hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) :
Filter.Tendsto (fun t => ((U t).orthogonalProjection x : E)) atTop (𝓝 x) := by
have : (⨆ i, U i).topologicalClosure.HasOrthogonalProjection := by
rw [top_unique hU']
infer_instance
convert orthogonalProjection_tendsto_closure_iSup U hU x
rw [eq_comm, orthogonalProjection_eq_self_iff, top_unique hU']
trivial
/-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/
theorem triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by
rw [Kᗮ.orthogonal_orthogonal_eq_closure]
exact K.isClosed_orthogonal.submodule_topologicalClosure_eq
/-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/
theorem topologicalClosure_eq_top_iff [CompleteSpace E] :
K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by
rw [← K.orthogonal_orthogonal_eq_closure]
constructor <;> intro h
· rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot]
· rw [h, Submodule.bot_orthogonal_eq_top]
end Submodule
namespace Dense
/- TODO: Move to another file? -/
open Submodule
variable {K} {x y : E}
theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by
have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on
hK continuous_const (Subtype.forall.1 h)
simpa using congr_fun this x
theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 :=
eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2
/-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/
theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y :=
sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h
theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y :=
hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h)
theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) :
x = y :=
hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h)
theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 :=
hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v]
| end Dense
namespace Submodule
variable {K}
/-- The reflection in `Kᗮ` of an element of `K` is its negation. -/
theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [K.HasOrthogonalProjection] {v : E}
(hv : v ∈ K) : Kᗮ.reflection v = -v :=
| Mathlib/Analysis/InnerProductSpace/Projection.lean | 949 | 957 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.AbsolutelyContinuous
/-!
# Vitali families
On a metric space `X` with a measure `μ`, consider for each `x : X` a family of measurable sets with
nonempty interiors, called `setsAt x`. This family is a Vitali family if it satisfies the following
property: consider a (possibly non-measurable) set `s`, and for any `x` in `s` a
subfamily `f x` of `setsAt x` containing sets of arbitrarily small diameter. Then one can extract
a disjoint subfamily covering almost all `s`.
Vitali families are provided by covering theorems such as the Besicovitch covering theorem or the
Vitali covering theorem. They make it possible to formulate general versions of theorems on
differentiations of measure that apply in both contexts.
This file gives the basic definition of Vitali families. More interesting developments of this
notion are deferred to other files:
* constructions of specific Vitali families are provided by the Besicovitch covering theorem, in
`Besicovitch.vitaliFamily`, and by the Vitali covering theorem, in `Vitali.vitaliFamily`.
* The main theorem on differentiation of measures along a Vitali family is proved in
`VitaliFamily.ae_tendsto_rnDeriv`.
## Main definitions
* `VitaliFamily μ` is a structure made, for each `x : X`, of a family of sets around `x`, such that
one can extract an almost everywhere disjoint covering from any subfamily containing sets of
arbitrarily small diameters.
Let `v` be such a Vitali family.
* `v.FineSubfamilyOn` describes the subfamilies of `v` from which one can extract almost
everywhere disjoint coverings. This property, called
`v.FineSubfamilyOn.exists_disjoint_covering_ae`, is essentially a restatement of the definition
of a Vitali family. We also provide an API to use efficiently such a disjoint covering.
* `v.filterAt x` is a filter on sets of `X`, such that convergence with respect to this filter
means convergence when sets in the Vitali family shrink towards `x`.
## References
* [Herbert Federer, Geometric Measure Theory, Chapter 2.8][Federer1996] (Vitali families are called
Vitali relations there)
-/
open MeasureTheory Metric Set Filter TopologicalSpace MeasureTheory.Measure
open scoped Topology
variable {X : Type*} [PseudoMetricSpace X]
/-- On a metric space `X` with a measure `μ`, consider for each `x : X` a family of measurable sets
with nonempty interiors, called `setsAt x`. This family is a Vitali family if it satisfies the
following property: consider a (possibly non-measurable) set `s`, and for any `x` in `s` a
subfamily `f x` of `setsAt x` containing sets of arbitrarily small diameter. Then one can extract
a disjoint subfamily covering almost all `s`.
Vitali families are provided by covering theorems such as the Besicovitch covering theorem or the
Vitali covering theorem. They make it possible to formulate general versions of theorems on
differentiations of measure that apply in both contexts.
-/
structure VitaliFamily {m : MeasurableSpace X} (μ : Measure X) where
/-- Sets of the family "centered" at a given point. -/
setsAt : X → Set (Set X)
/-- All sets of the family are measurable. -/
measurableSet : ∀ x : X, ∀ s ∈ setsAt x, MeasurableSet s
/-- All sets of the family have nonempty interior. -/
nonempty_interior : ∀ x : X, ∀ s ∈ setsAt x, (interior s).Nonempty
/-- For any closed ball around `x`, there exists a set of the family contained in this ball. -/
nontrivial : ∀ (x : X), ∀ ε > (0 : ℝ), ∃ s ∈ setsAt x, s ⊆ closedBall x ε
/-- Consider a (possibly non-measurable) set `s`,
and for any `x` in `s` a subfamily `f x` of `setsAt x`
containing sets of arbitrarily small diameter.
Then one can extract a disjoint subfamily covering almost all `s`. -/
covering : ∀ (s : Set X) (f : X → Set (Set X)),
(∀ x ∈ s, f x ⊆ setsAt x) → (∀ x ∈ s, ∀ ε > (0 : ℝ), ∃ t ∈ f x, t ⊆ closedBall x ε) →
∃ t : Set (X × Set X), (∀ p ∈ t, p.1 ∈ s) ∧ (t.PairwiseDisjoint fun p ↦ p.2) ∧
(∀ p ∈ t, p.2 ∈ f p.1) ∧ μ (s \ ⋃ p ∈ t, p.2) = 0
namespace VitaliFamily
variable {m0 : MeasurableSpace X} {μ : Measure X}
/-- A Vitali family for a measure `μ` is also a Vitali family for any measure absolutely continuous
with respect to `μ`. -/
def mono (v : VitaliFamily μ) (ν : Measure X) (hν : ν ≪ μ) : VitaliFamily ν where
__ := v
covering s f h h' :=
let ⟨t, ts, disj, mem_f, hμ⟩ := v.covering s f h h'
⟨t, ts, disj, mem_f, hν hμ⟩
/-- Given a Vitali family `v` for a measure `μ`, a family `f` is a fine subfamily on a set `s` if
every point `x` in `s` belongs to arbitrarily small sets in `v.setsAt x ∩ f x`. This is precisely
the subfamilies for which the Vitali family definition ensures that one can extract a disjoint
covering of almost all `s`. -/
def FineSubfamilyOn (v : VitaliFamily μ) (f : X → Set (Set X)) (s : Set X) : Prop :=
∀ x ∈ s, ∀ ε > 0, ∃ t ∈ v.setsAt x ∩ f x, t ⊆ closedBall x ε
namespace FineSubfamilyOn
variable {v : VitaliFamily μ} {f : X → Set (Set X)} {s : Set X} (h : v.FineSubfamilyOn f s)
include h
theorem exists_disjoint_covering_ae :
∃ t : Set (X × Set X),
(∀ p : X × Set X, p ∈ t → p.1 ∈ s) ∧
(t.PairwiseDisjoint fun p => p.2) ∧
(∀ p : X × Set X, p ∈ t → p.2 ∈ v.setsAt p.1 ∩ f p.1) ∧
μ (s \ ⋃ (p : X × Set X) (_ : p ∈ t), p.2) = 0 :=
v.covering s (fun x => v.setsAt x ∩ f x) (fun _ _ => inter_subset_left) h
/-- Given `h : v.FineSubfamilyOn f s`, then `h.index` is a set parametrizing a disjoint
covering of almost every `s`. -/
protected def index : Set (X × Set X) :=
h.exists_disjoint_covering_ae.choose
/-- Given `h : v.FineSubfamilyOn f s`, then `h.covering p` is a set in the family,
for `p ∈ h.index`, such that these sets form a disjoint covering of almost every `s`. -/
@[nolint unusedArguments]
protected def covering (_h : FineSubfamilyOn v f s) : X × Set X → Set X :=
fun p => p.2
theorem index_subset : ∀ p : X × Set X, p ∈ h.index → p.1 ∈ s :=
h.exists_disjoint_covering_ae.choose_spec.1
theorem covering_disjoint : h.index.PairwiseDisjoint h.covering :=
h.exists_disjoint_covering_ae.choose_spec.2.1
open scoped Function in -- required for scoped `on` notation
theorem covering_disjoint_subtype : Pairwise (Disjoint on fun x : h.index => h.covering x) :=
(pairwise_subtype_iff_pairwise_set _ _).2 h.covering_disjoint
theorem covering_mem {p : X × Set X} (hp : p ∈ h.index) : h.covering p ∈ f p.1 :=
(h.exists_disjoint_covering_ae.choose_spec.2.2.1 p hp).2
theorem covering_mem_family {p : X × Set X} (hp : p ∈ h.index) : h.covering p ∈ v.setsAt p.1 :=
(h.exists_disjoint_covering_ae.choose_spec.2.2.1 p hp).1
theorem measure_diff_biUnion : μ (s \ ⋃ p ∈ h.index, h.covering p) = 0 :=
h.exists_disjoint_covering_ae.choose_spec.2.2.2
theorem index_countable [SecondCountableTopology X] : h.index.Countable :=
h.covering_disjoint.countable_of_nonempty_interior fun _ hx =>
v.nonempty_interior _ _ (h.covering_mem_family hx)
protected theorem measurableSet_u {p : X × Set X} (hp : p ∈ h.index) :
MeasurableSet (h.covering p) :=
v.measurableSet p.1 _ (h.covering_mem_family hp)
theorem measure_le_tsum_of_absolutelyContinuous [SecondCountableTopology X] {ρ : Measure X}
(hρ : ρ ≪ μ) : ρ s ≤ ∑' p : h.index, ρ (h.covering p) :=
calc
ρ s ≤ ρ ((s \ ⋃ p ∈ h.index, h.covering p) ∪ ⋃ p ∈ h.index, h.covering p) :=
measure_mono (by simp only [subset_union_left, diff_union_self])
_ ≤ ρ (s \ ⋃ p ∈ h.index, h.covering p) + ρ (⋃ p ∈ h.index, h.covering p) :=
(measure_union_le _ _)
_ = ∑' p : h.index, ρ (h.covering p) := by
rw [hρ h.measure_diff_biUnion, zero_add,
measure_biUnion h.index_countable h.covering_disjoint fun x hx => h.measurableSet_u hx]
theorem measure_le_tsum [SecondCountableTopology X] : μ s ≤ ∑' x : h.index, μ (h.covering x) :=
h.measure_le_tsum_of_absolutelyContinuous Measure.AbsolutelyContinuous.rfl
end FineSubfamilyOn
/-- One can enlarge a Vitali family by adding to the sets `f x` at `x` all sets which are not
contained in a `δ`-neighborhood on `x`. This does not change the local filter at a point, but it
can be convenient to get a nicer global behavior. -/
def enlarge (v : VitaliFamily μ) (δ : ℝ) (δpos : 0 < δ) : VitaliFamily μ where
setsAt x := v.setsAt x ∪ {s | MeasurableSet s ∧ (interior s).Nonempty ∧ ¬s ⊆ closedBall x δ}
measurableSet := by
rintro x s (hs | hs)
exacts [v.measurableSet _ _ hs, hs.1]
nonempty_interior := by
rintro x s (hs | hs)
exacts [v.nonempty_interior _ _ hs, hs.2.1]
nontrivial := by
intro x ε εpos
rcases v.nontrivial x ε εpos with ⟨s, hs, h's⟩
exact ⟨s, mem_union_left _ hs, h's⟩
covering := by
intro s f fset ffine
let g : X → Set (Set X) := fun x => f x ∩ v.setsAt x
have : ∀ x ∈ s, ∀ ε : ℝ, ε > 0 → ∃ t ∈ g x, t ⊆ closedBall x ε := by
intro x hx ε εpos
obtain ⟨t, tf, ht⟩ : ∃ t ∈ f x, t ⊆ closedBall x (min ε δ) :=
ffine x hx (min ε δ) (lt_min εpos δpos)
rcases fset x hx tf with (h't | h't)
· exact ⟨t, ⟨tf, h't⟩, ht.trans (closedBall_subset_closedBall (min_le_left _ _))⟩
· refine False.elim (h't.2.2 ?_)
exact ht.trans (closedBall_subset_closedBall (min_le_right _ _))
rcases v.covering s g (fun x _ => inter_subset_right) this with ⟨t, ts, tdisj, tg, μt⟩
exact ⟨t, ts, tdisj, fun p hp => (tg p hp).1, μt⟩
variable (v : VitaliFamily μ)
/-- Given a vitali family `v`, then `v.filterAt x` is the filter on `Set X` made of those families
that contain all sets of `v.setsAt x` of a sufficiently small diameter. This filter makes it
possible to express limiting behavior when sets in `v.setsAt x` shrink to `x`. -/
def filterAt (x : X) : Filter (Set X) := (𝓝 x).smallSets ⊓ 𝓟 (v.setsAt x)
theorem _root_.Filter.HasBasis.vitaliFamily {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X}
(h : (𝓝 x).HasBasis p s) : (v.filterAt x).HasBasis p (fun i ↦ {t ∈ v.setsAt x | t ⊆ s i}) := by
simpa only [← Set.setOf_inter_eq_sep] using h.smallSets.inf_principal _
theorem filterAt_basis_closedBall (x : X) :
(v.filterAt x).HasBasis (0 < ·) ({t ∈ v.setsAt x | t ⊆ closedBall x ·}) :=
nhds_basis_closedBall.vitaliFamily v
theorem mem_filterAt_iff {x : X} {s : Set (Set X)} :
s ∈ v.filterAt x ↔ ∃ ε > (0 : ℝ), ∀ t ∈ v.setsAt x, t ⊆ closedBall x ε → t ∈ s := by
simp only [(v.filterAt_basis_closedBall x).mem_iff, ← and_imp, subset_def, mem_setOf]
instance filterAt_neBot (x : X) : (v.filterAt x).NeBot :=
(v.filterAt_basis_closedBall x).neBot_iff.2 <| v.nontrivial _ _
theorem eventually_filterAt_iff {x : X} {P : Set X → Prop} :
(∀ᶠ t in v.filterAt x, P t) ↔ ∃ ε > (0 : ℝ), ∀ t ∈ v.setsAt x, t ⊆ closedBall x ε → P t :=
v.mem_filterAt_iff
theorem tendsto_filterAt_iff {ι : Type*} {l : Filter ι} {f : ι → Set X} {x : X} :
Tendsto f l (v.filterAt x) ↔
(∀ᶠ i in l, f i ∈ v.setsAt x) ∧ ∀ ε > (0 : ℝ), ∀ᶠ i in l, f i ⊆ closedBall x ε := by
simp only [filterAt, tendsto_inf, nhds_basis_closedBall.smallSets.tendsto_right_iff,
tendsto_principal, and_comm, mem_powerset_iff]
theorem eventually_filterAt_mem_setsAt (x : X) : ∀ᶠ t in v.filterAt x, t ∈ v.setsAt x :=
(v.tendsto_filterAt_iff.mp tendsto_id).1
theorem eventually_filterAt_subset_closedBall (x : X) {ε : ℝ} (hε : 0 < ε) :
∀ᶠ t : Set X in v.filterAt x, t ⊆ closedBall x ε :=
(v.tendsto_filterAt_iff.mp tendsto_id).2 ε hε
theorem eventually_filterAt_measurableSet (x : X) : ∀ᶠ t in v.filterAt x, MeasurableSet t := by
filter_upwards [v.eventually_filterAt_mem_setsAt x] with _ ha using v.measurableSet _ _ ha
theorem frequently_filterAt_iff {x : X} {P : Set X → Prop} :
(∃ᶠ t in v.filterAt x, P t) ↔ ∀ ε > (0 : ℝ), ∃ t ∈ v.setsAt x, t ⊆ closedBall x ε ∧ P t := by
simp only [(v.filterAt_basis_closedBall x).frequently_iff, ← and_assoc, subset_def, mem_setOf]
theorem eventually_filterAt_subset_of_nhds {x : X} {o : Set X} (hx : o ∈ 𝓝 x) :
∀ᶠ t in v.filterAt x, t ⊆ o :=
(eventually_smallSets_subset.2 hx).filter_mono inf_le_left
theorem fineSubfamilyOn_of_frequently (v : VitaliFamily μ) (f : X → Set (Set X)) (s : Set X)
(h : ∀ x ∈ s, ∃ᶠ t in v.filterAt x, t ∈ f x) : v.FineSubfamilyOn f s := by
intro x hx ε εpos
obtain ⟨t, tv, ht, tf⟩ : ∃ t ∈ v.setsAt x, t ⊆ closedBall x ε ∧ t ∈ f x :=
v.frequently_filterAt_iff.1 (h x hx) ε εpos
exact ⟨t, ⟨tv, tf⟩, ht⟩
end VitaliFamily
| Mathlib/MeasureTheory/Covering/VitaliFamily.lean | 278 | 283 | |
/-
Copyright (c) 2021 Noam Atar. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Noam Atar
-/
import Mathlib.Order.Ideal
import Mathlib.Order.PFilter
/-!
# Prime ideals
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more
structure, such as a bottom element, a top element, or a join-semilattice structure.
- `Order.Ideal.PrimePair`: A pair of an `Order.Ideal` and an `Order.PFilter` which form a partition
of `P`. This is useful as giving the data of a prime ideal is the same as giving the data of a
prime filter.
- `Order.Ideal.IsPrime`: a predicate for prime ideals. Dual to the notion of a prime filter.
- `Order.PFilter.IsPrime`: a predicate for prime filters. Dual to the notion of a prime ideal.
## References
- <https://en.wikipedia.org/wiki/Ideal_(order_theory)>
## Tags
ideal, prime
-/
open Order.PFilter
namespace Order
variable {P : Type*}
namespace Ideal
/-- A pair of an `Order.Ideal` and an `Order.PFilter` which form a partition of `P`.
-/
structure PrimePair (P : Type*) [Preorder P] where
I : Ideal P
F : PFilter P
isCompl_I_F : IsCompl (I : Set P) F
namespace PrimePair
variable [Preorder P] (IF : PrimePair P)
theorem compl_I_eq_F : (IF.I : Set P)ᶜ = IF.F :=
IF.isCompl_I_F.compl_eq
theorem compl_F_eq_I : (IF.F : Set P)ᶜ = IF.I :=
IF.isCompl_I_F.eq_compl.symm
theorem I_isProper : IsProper IF.I := by
obtain ⟨w, h⟩ := IF.F.nonempty
apply isProper_of_not_mem (_ : w ∉ IF.I)
rwa [← IF.compl_I_eq_F] at h
protected theorem disjoint : Disjoint (IF.I : Set P) IF.F :=
IF.isCompl_I_F.disjoint
theorem I_union_F : (IF.I : Set P) ∪ IF.F = Set.univ :=
| IF.isCompl_I_F.sup_eq_top
theorem F_union_I : (IF.F : Set P) ∪ IF.I = Set.univ :=
IF.isCompl_I_F.symm.sup_eq_top
| Mathlib/Order/PrimeIdeal.lean | 68 | 71 |
/-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Kernel.Composition.MapComap
import Mathlib.Probability.Martingale.Convergence
import Mathlib.Probability.Process.PartitionFiltration
/-!
# Kernel density
Let `κ : Kernel α (γ × β)` and `ν : Kernel α γ` be two finite kernels with `Kernel.fst κ ≤ ν`,
where `γ` has a countably generated σ-algebra (true in particular for standard Borel spaces).
We build a function `density κ ν : α → γ → Set β → ℝ` jointly measurable in the first two arguments
such that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`,
`∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
There are two main applications of this construction.
* Disintegration of kernels: for `κ : Kernel α (γ × β)`, we want to build a kernel
`η : Kernel (α × γ) β` such that `κ = fst κ ⊗ₖ η`. For `β = ℝ`, we can use the density of `κ`
with respect to `fst κ` for intervals to build a kernel cumulative distribution function for `η`.
The construction can then be extended to `β` standard Borel.
* Radon-Nikodym theorem for kernels: for `κ ν : Kernel α γ`, we can use the density to build a
Radon-Nikodym derivative of `κ` with respect to `ν`. We don't need `β` here but we can apply the
density construction to `β = Unit`. The derivative construction will use `density` but will not
be exactly equal to it because we will want to remove the `fst κ ≤ ν` assumption.
## Main definitions
* `ProbabilityTheory.Kernel.density`: for `κ : Kernel α (γ × β)` and `ν : Kernel α γ` two finite
kernels, `Kernel.density κ ν` is a function `α → γ → Set β → ℝ`.
## Main statements
* `ProbabilityTheory.Kernel.setIntegral_density`: for all measurable sets `A : Set γ` and
`s : Set β`, `∫ x in A, Kernel.density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
* `ProbabilityTheory.Kernel.measurable_density`: the function
`p : α × γ ↦ Kernel.density κ ν p.1 p.2 s` is measurable.
## Construction of the density
If we were interested only in a fixed `a : α`, then we could use the Radon-Nikodym derivative to
build the density function `density κ ν`, as follows.
```
def density' (κ : Kernel α (γ × β)) (ν : kernel a γ) (a : α) (x : γ) (s : Set β) : ℝ :=
(((κ a).restrict (univ ×ˢ s)).fst.rnDeriv (ν a) x).toReal
```
However, we can't turn those functions for each `a` into a measurable function of the pair `(a, x)`.
In order to obtain measurability through countability, we use the fact that the measurable space `γ`
is countably generated. For each `n : ℕ`, we define (in the file
`Mathlib.Probability.Process.PartitionFiltration`) a finite partition of `γ`, such that those
partitions are finer as `n` grows, and the σ-algebra generated by the union of all partitions is the
σ-algebra of `γ`. For `x : γ`, `countablePartitionSet n x` denotes the set in the partition such
that `x ∈ countablePartitionSet n x`.
For a given `n`, the function `densityProcess κ ν n : α → γ → Set β → ℝ` defined by
`fun a x s ↦ (κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal` has
the desired property that `∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal` for
all `A` in the σ-algebra generated by the partition at scale `n` and is measurable in `(a, x)`.
`countableFiltration γ` is the filtration of those σ-algebras for all `n : ℕ`.
The functions `densityProcess κ ν n` described here are a bounded `ν`-martingale for the filtration
`countableFiltration γ`. By Doob's martingale L1 convergence theorem, that martingale converges to
a limit, which has a product-measurable version and satisfies the integral equality for all `A` in
`⨆ n, countableFiltration γ n`. Finally, the partitions were chosen such that that supremum is equal
to the σ-algebra on `γ`, hence the equality holds for all measurable sets.
We have obtained the desired density function.
## References
The construction of the density process in this file follows the proof of Theorem 9.27 in
[O. Kallenberg, Foundations of modern probability][kallenberg2021], adapted to use a countably
generated hypothesis instead of specializing to `ℝ`.
-/
open MeasureTheory Set Filter MeasurableSpace
open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
[CountablyGenerated γ] {κ : Kernel α (γ × β)} {ν : Kernel α γ}
section DensityProcess
/-- An `ℕ`-indexed martingale that is a density for `κ` with respect to `ν` on the sets in
`countablePartition γ n`. Used to define its limit `ProbabilityTheory.Kernel.density`, which is
a density for those kernels for all measurable sets. -/
noncomputable
def densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) (s : Set β) :
ℝ :=
(κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal
lemma densityProcess_def (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (s : Set β) :
(fun t ↦ densityProcess κ ν n a t s)
= fun t ↦ (κ a (countablePartitionSet n t ×ˢ s) / ν a (countablePartitionSet n t)).toReal :=
rfl
lemma measurable_densityProcess_countableFiltration_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ)
(n : ℕ) {s : Set β} (hs : MeasurableSet s) :
Measurable[mα.prod (countableFiltration γ n)] (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
change Measurable[mα.prod (countableFiltration γ n)]
((fun (p : α × countablePartition γ n) ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2)
∘ (fun (p : α × γ) ↦ (p.1, ⟨countablePartitionSet n p.2, countablePartitionSet_mem n p.2⟩)))
have h1 : @Measurable _ _ (mα.prod ⊤) _
(fun p : α × countablePartition γ n ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2) := by
refine Measurable.div ?_ ?_
· refine measurable_from_prod_countable (fun t ↦ ?_)
exact Kernel.measurable_coe _ ((measurableSet_countablePartition _ t.prop).prod hs)
· refine measurable_from_prod_countable ?_
rintro ⟨t, ht⟩
exact Kernel.measurable_coe _ (measurableSet_countablePartition _ ht)
refine h1.comp (measurable_fst.prodMk ?_)
change @Measurable (α × γ) (countablePartition γ n) (mα.prod (countableFiltration γ n)) ⊤
((fun c ↦ ⟨countablePartitionSet n c, countablePartitionSet_mem n c⟩) ∘ (fun p : α × γ ↦ p.2))
exact (measurable_countablePartitionSet_subtype n ⊤).comp measurable_snd
| lemma measurable_densityProcess_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
refine Measurable.mono (measurable_densityProcess_countableFiltration_aux κ ν n hs) ?_ le_rfl
exact sup_le_sup le_rfl (comap_mono ((countableFiltration γ).le _))
| Mathlib/Probability/Kernel/Disintegration/Density.lean | 122 | 127 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Analysis.NormedSpace.Real
import Mathlib.Data.Rat.Cast.CharZero
/-!
# Real logarithm
In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from
its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and
`log (-x) = log x`.
We prove some basic properties of this function and show that it is continuous.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {x y : ℝ}
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
@[pp_nodot]
noncomputable def log (x : ℝ) : ℝ :=
if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩
theorem log_of_ne_zero (hx : x ≠ 0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ :=
dif_neg hx
theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by
rw [log_of_ne_zero hx.ne']
congr
exact abs_of_pos hx
theorem exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = |x| := by
rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk]
theorem exp_log (hx : 0 < x) : exp (log x) = x := by
rw [exp_log_eq_abs hx.ne']
exact abs_of_pos hx
theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by
rw [exp_log_eq_abs (ne_of_lt hx)]
exact abs_of_neg hx
theorem le_exp_log (x : ℝ) : x ≤ exp (log x) := by
by_cases h_zero : x = 0
· rw [h_zero, log, dif_pos rfl, exp_zero]
exact zero_le_one
· rw [exp_log_eq_abs h_zero]
exact le_abs_self _
@[simp]
theorem log_exp (x : ℝ) : log (exp x) = x :=
exp_injective <| exp_log (exp_pos x)
theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≤ exp x := by
by_cases hx0 : x ≤ 0
· apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x)
· have h := add_one_le_exp (log x)
rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h
theorem two_mul_le_exp {x : ℝ} : 2 * x ≤ exp x := by
by_cases hx0 : x < 0
· exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le)
(exp_nonneg x)
· apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp
have := Real.add_one_le_exp 1
rwa [one_add_one_eq_two] at this
theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩
theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩
@[simp]
theorem range_log : range log = univ :=
log_surjective.range_eq
@[simp]
theorem log_zero : log 0 = 0 :=
dif_pos rfl
@[simp]
theorem log_one : log 1 = 0 :=
exp_injective <| by rw [exp_log zero_lt_one, exp_zero]
/-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/
@[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by
obtain rfl | hx := eq_or_ne x 0 <;> simp [*]
@[simp]
theorem log_abs (x : ℝ) : log |x| = log x := by
by_cases h : x = 0
· simp [h]
· rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs]
@[simp]
theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg]
theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by
rw [sinh_eq, exp_neg, exp_log hx]
theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by
rw [cosh_eq, exp_neg, exp_log hx]
theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ =>
⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩
theorem log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y :=
exp_injective <| by
rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]
theorem log_div (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y :=
exp_injective <| by
rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]
@[simp]
theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by
by_cases hx : x = 0; · simp [hx]
rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]
theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≤ log y ↔ x ≤ y := by
rw [← exp_le_exp, exp_log h, exp_log h₁]
@[gcongr, bound]
lemma log_le_log (hx : 0 < x) (hxy : x ≤ y) : log x ≤ log y :=
(log_le_log_iff hx (hx.trans_le hxy)).2 hxy
@[gcongr, bound]
theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by
rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)]
theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by
rw [← exp_lt_exp, exp_log hx, exp_log hy]
theorem log_le_iff_le_exp (hx : 0 < x) : log x ≤ y ↔ x ≤ exp y := by rw [← exp_le_exp, exp_log hx]
theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx]
theorem le_log_iff_exp_le (hy : 0 < y) : x ≤ log y ↔ exp x ≤ y := by rw [← exp_le_exp, exp_log hy]
theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy]
theorem log_pos_iff (hx : 0 ≤ x) : 0 < log x ↔ 1 < x := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
rw [← log_one]
exact log_lt_log_iff zero_lt_one hx
@[bound]
theorem log_pos (hx : 1 < x) : 0 < log x :=
(log_pos_iff (lt_trans zero_lt_one hx).le).2 hx
theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by
rw [← neg_neg x, log_neg_eq_log]
have : 1 < -x := by linarith
exact log_pos this
theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by
rw [← log_one]
exact log_lt_log_iff h zero_lt_one
@[bound]
theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 :=
(log_neg_iff h0).2 h1
theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by
rw [← neg_neg x, log_neg_eq_log]
have h0' : 0 < -x := by linarith
have h1' : -x < 1 := by linarith
exact log_neg h0' h1'
theorem log_nonneg_iff (hx : 0 < x) : 0 ≤ log x ↔ 1 ≤ x := by rw [← not_lt, log_neg_iff hx, not_lt]
@[bound]
theorem log_nonneg (hx : 1 ≤ x) : 0 ≤ log x :=
(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx
theorem log_nonpos_iff (hx : 0 ≤ x) : log x ≤ 0 ↔ x ≤ 1 := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
rw [← not_lt, log_pos_iff hx.le, not_lt]
@[deprecated (since := "2025-01-16")]
alias log_nonpos_iff' := log_nonpos_iff
@[bound]
theorem log_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : log x ≤ 0 :=
(log_nonpos_iff hx).2 h'x
theorem log_natCast_nonneg (n : ℕ) : 0 ≤ log n := by
if hn : n = 0 then
simp [hn]
else
have : (1 : ℝ) ≤ n := mod_cast Nat.one_le_of_lt <| Nat.pos_of_ne_zero hn
exact log_nonneg this
theorem log_neg_natCast_nonneg (n : ℕ) : 0 ≤ log (-n) := by
rw [← log_neg_eq_log, neg_neg]
exact log_natCast_nonneg _
theorem log_intCast_nonneg (n : ℤ) : 0 ≤ log n := by
cases lt_trichotomy 0 n with
| inl hn =>
have : (1 : ℝ) ≤ n := mod_cast hn
exact log_nonneg this
| inr hn =>
cases hn with
| inl hn => simp [hn.symm]
| inr hn =>
have : (1 : ℝ) ≤ -n := by rw [← neg_zero, ← lt_neg] at hn; exact mod_cast hn
rw [← log_neg_eq_log]
exact log_nonneg this
theorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun _ hx _ _ hxy => log_lt_log hx hxy
theorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) := by
rintro x (hx : x < 0) y (hy : y < 0) hxy
rw [← log_abs y, ← log_abs x]
refine log_lt_log (abs_pos.2 hy.ne) ?_
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
theorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) :=
strictMonoOn_log.injOn
theorem log_lt_sub_one_of_pos (hx1 : 0 < x) (hx2 : x ≠ 1) : log x < x - 1 := by
have h : log x ≠ 0 := by
rwa [← log_one, log_injOn_pos.ne_iff hx1]
exact mem_Ioi.mpr zero_lt_one
linarith [add_one_lt_exp h, exp_log hx1]
theorem eq_one_of_pos_of_log_eq_zero {x : ℝ} (h₁ : 0 < x) (h₂ : log x = 0) : x = 1 :=
log_injOn_pos (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.log_one.symm)
theorem log_ne_zero_of_pos_of_ne_one {x : ℝ} (hx_pos : 0 < x) (hx : x ≠ 1) : log x ≠ 0 :=
mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx
@[simp]
theorem log_eq_zero {x : ℝ} : log x = 0 ↔ x = 0 ∨ x = 1 ∨ x = -1 := by
constructor
· intro h
rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero)
· refine Or.inr (Or.inr (neg_eq_iff_eq_neg.mp ?_))
rw [← log_neg_eq_log x] at h
exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h
· exact Or.inl rfl
· exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h))
· rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log]
theorem log_ne_zero {x : ℝ} : log x ≠ 0 ↔ x ≠ 0 ∧ x ≠ 1 ∧ x ≠ -1 := by
simpa only [not_or] using log_eq_zero.not
@[simp]
theorem log_pow (x : ℝ) (n : ℕ) : log (x ^ n) = n * log x := by
induction n with
| zero => simp
| succ n ih =>
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· rw [pow_succ, log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul]
@[simp]
theorem log_zpow (x : ℝ) (n : ℤ) : log (x ^ n) = n * log x := by
cases n
· rw [Int.ofNat_eq_coe, zpow_natCast, log_pow, Int.cast_natCast]
· rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul]
theorem log_sqrt {x : ℝ} (hx : 0 ≤ x) : log (√x) = log x / 2 := by
rw [eq_div_iff, mul_comm, ← Nat.cast_two, ← log_pow, sq_sqrt hx]
exact two_ne_zero
theorem log_le_sub_one_of_pos {x : ℝ} (hx : 0 < x) : log x ≤ x - 1 := by
rw [le_sub_iff_add_le]
convert add_one_le_exp (log x)
rw [exp_log hx]
lemma one_sub_inv_le_log_of_pos (hx : 0 < x) : 1 - x⁻¹ ≤ log x := by
simpa [add_comm] using log_le_sub_one_of_pos (inv_pos.2 hx)
/-- See `Real.log_le_sub_one_of_pos` for the stronger version when `x ≠ 0`. -/
lemma log_le_self (hx : 0 ≤ x) : log x ≤ x := by
obtain rfl | hx := hx.eq_or_lt
· simp
· exact (log_le_sub_one_of_pos hx).trans (by linarith)
/-- See `Real.one_sub_inv_le_log_of_pos` for the stronger version when `x ≠ 0`. -/
lemma neg_inv_le_log (hx : 0 ≤ x) : -x⁻¹ ≤ log x := by
rw [neg_le, ← log_inv]; exact log_le_self <| inv_nonneg.2 hx
/-- Bound for `|log x * x|` in the interval `(0, 1]`. -/
theorem abs_log_mul_self_lt (x : ℝ) (h1 : 0 < x) (h2 : x ≤ 1) : |log x * x| < 1 := by
have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1
| replace := log_le_sub_one_of_pos this
replace : log (1 / x) < 1 / x := by linarith
rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff₀ h1] at this
have aux : 0 ≤ -log x * x := by
| Mathlib/Analysis/SpecialFunctions/Log/Basic.lean | 309 | 312 |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.Order.CompleteBooleanAlgebra
/-!
# Properties of morphisms
We provide the basic framework for talking about properties of morphisms.
The following meta-property is defined
* `RespectsLeft P Q`: `P` respects the property `Q` on the left if `P f → P (i ≫ f)` where
`i` satisfies `Q`.
* `RespectsRight P Q`: `P` respects the property `Q` on the right if `P f → P (f ≫ i)` where
`i` satisfies `Q`.
* `Respects`: `P` respects `Q` if `P` respects `Q` both on the left and on the right.
-/
universe w v v' u u'
open CategoryTheory Opposite
noncomputable section
namespace CategoryTheory
variable (C : Type u) [Category.{v} C] {D : Type*} [Category D]
/-- A `MorphismProperty C` is a class of morphisms between objects in `C`. -/
def MorphismProperty :=
∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop
instance : CompleteBooleanAlgebra (MorphismProperty C) where
le P₁ P₂ := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P₁ f → P₂ f
__ := inferInstanceAs (CompleteBooleanAlgebra (∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop))
lemma MorphismProperty.le_def {P Q : MorphismProperty C} :
P ≤ Q ↔ ∀ {X Y : C} (f : X ⟶ Y), P f → Q f := Iff.rfl
instance : Inhabited (MorphismProperty C) :=
⟨⊤⟩
lemma MorphismProperty.top_eq : (⊤ : MorphismProperty C) = fun _ _ _ => True := rfl
variable {C}
namespace MorphismProperty
@[ext]
lemma ext (W W' : MorphismProperty C) (h : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), W f ↔ W' f) :
W = W' := by
funext X Y f
rw [h]
@[simp]
lemma top_apply {X Y : C} (f : X ⟶ Y) : (⊤ : MorphismProperty C) f := by
simp only [top_eq]
lemma of_eq_top {P : MorphismProperty C} (h : P = ⊤) {X Y : C} (f : X ⟶ Y) : P f := by
simp [h]
@[simp]
lemma sSup_iff (S : Set (MorphismProperty C)) {X Y : C} (f : X ⟶ Y) :
sSup S f ↔ ∃ (W : S), W.1 f := by
dsimp [sSup, iSup]
constructor
· rintro ⟨_, ⟨⟨_, ⟨⟨_, ⟨_, h⟩, rfl⟩, rfl⟩⟩, rfl⟩, hf⟩
exact ⟨⟨_, h⟩, hf⟩
· rintro ⟨⟨W, hW⟩, hf⟩
exact ⟨_, ⟨⟨_, ⟨_, ⟨⟨W, hW⟩, rfl⟩⟩, rfl⟩, rfl⟩, hf⟩
@[simp]
lemma iSup_iff {ι : Sort*} (W : ι → MorphismProperty C) {X Y : C} (f : X ⟶ Y) :
iSup W f ↔ ∃ i, W i f := by
apply (sSup_iff (Set.range W) f).trans
constructor
· rintro ⟨⟨_, i, rfl⟩, hf⟩
exact ⟨i, hf⟩
· rintro ⟨i, hf⟩
exact ⟨⟨_, i, rfl⟩, hf⟩
/-- The morphism property in `Cᵒᵖ` associated to a morphism property in `C` -/
@[simp]
def op (P : MorphismProperty C) : MorphismProperty Cᵒᵖ := fun _ _ f => P f.unop
/-- The morphism property in `C` associated to a morphism property in `Cᵒᵖ` -/
@[simp]
def unop (P : MorphismProperty Cᵒᵖ) : MorphismProperty C := fun _ _ f => P f.op
theorem unop_op (P : MorphismProperty C) : P.op.unop = P :=
rfl
theorem op_unop (P : MorphismProperty Cᵒᵖ) : P.unop.op = P :=
rfl
/-- The inverse image of a `MorphismProperty D` by a functor `C ⥤ D` -/
def inverseImage (P : MorphismProperty D) (F : C ⥤ D) : MorphismProperty C := fun _ _ f =>
P (F.map f)
@[simp]
lemma inverseImage_iff (P : MorphismProperty D) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) :
P.inverseImage F f ↔ P (F.map f) := by rfl
/-- The image (up to isomorphisms) of a `MorphismProperty C` by a functor `C ⥤ D` -/
def map (P : MorphismProperty C) (F : C ⥤ D) : MorphismProperty D := fun _ _ f =>
∃ (X' Y' : C) (f' : X' ⟶ Y') (_ : P f'), Nonempty (Arrow.mk (F.map f') ≅ Arrow.mk f)
lemma map_mem_map (P : MorphismProperty C) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (hf : P f) :
(P.map F) (F.map f) := ⟨X, Y, f, hf, ⟨Iso.refl _⟩⟩
lemma monotone_map (F : C ⥤ D) :
Monotone (map · F) := by
intro P Q h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩
exact ⟨X', Y', f', h _ hf', ⟨e⟩⟩
section
variable (P : MorphismProperty C)
/-- The set in `Set (Arrow C)` which corresponds to `P : MorphismProperty C`. -/
def toSet : Set (Arrow C) := setOf (fun f ↦ P f.hom)
/-- The family of morphisms indexed by `P.toSet` which corresponds
to `P : MorphismProperty C`, see `MorphismProperty.ofHoms_homFamily`. -/
def homFamily (f : P.toSet) : f.1.left ⟶ f.1.right := f.1.hom
lemma homFamily_apply (f : P.toSet) : P.homFamily f = f.1.hom := rfl
@[simp]
lemma homFamily_arrow_mk {X Y : C} (f : X ⟶ Y) (hf : P f) :
P.homFamily ⟨Arrow.mk f, hf⟩ = f := rfl
@[simp]
lemma arrow_mk_mem_toSet_iff {X Y : C} (f : X ⟶ Y) : Arrow.mk f ∈ P.toSet ↔ P f := Iff.rfl
lemma of_eq {X Y : C} {f : X ⟶ Y} (hf : P f)
{X' Y' : C} {f' : X' ⟶ Y'}
(hX : X = X') (hY : Y = Y') (h : f' = eqToHom hX.symm ≫ f ≫ eqToHom hY) :
P f' := by
rw [← P.arrow_mk_mem_toSet_iff] at hf ⊢
rwa [(Arrow.mk_eq_mk_iff f' f).2 ⟨hX.symm, hY.symm, h⟩]
end
/-- The class of morphisms given by a family of morphisms `f i : X i ⟶ Y i`. -/
inductive ofHoms {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) : MorphismProperty C
| mk (i : ι) : ofHoms f (f i)
lemma ofHoms_iff {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) {A B : C} (g : A ⟶ B) :
ofHoms f g ↔ ∃ i, Arrow.mk g = Arrow.mk (f i) := by
constructor
· rintro ⟨i⟩
exact ⟨i, rfl⟩
· rintro ⟨i, h⟩
rw [← (ofHoms f).arrow_mk_mem_toSet_iff, h, arrow_mk_mem_toSet_iff]
constructor
@[simp]
lemma ofHoms_homFamily (P : MorphismProperty C) : ofHoms P.homFamily = P := by
ext _ _ f
constructor
· intro hf
rw [ofHoms_iff] at hf
obtain ⟨⟨f, hf⟩, ⟨_, _⟩⟩ := hf
exact hf
· intro hf
exact ⟨(⟨f, hf⟩ : P.toSet)⟩
/-- A morphism property `P` satisfies `P.RespectsRight Q` if it is stable under post-composition
with morphisms satisfying `Q`, i.e. whenever `P` holds for `f` and `Q` holds for `i` then `P`
holds for `f ≫ i`. -/
class RespectsRight (P Q : MorphismProperty C) : Prop where
postcomp {X Y Z : C} (i : Y ⟶ Z) (hi : Q i) (f : X ⟶ Y) (hf : P f) : P (f ≫ i)
/-- A morphism property `P` satisfies `P.RespectsLeft Q` if it is stable under
pre-composition with morphisms satisfying `Q`, i.e. whenever `P` holds for `f`
and `Q` holds for `i` then `P` holds for `i ≫ f`. -/
class RespectsLeft (P Q : MorphismProperty C) : Prop where
precomp {X Y Z : C} (i : X ⟶ Y) (hi : Q i) (f : Y ⟶ Z) (hf : P f) : P (i ≫ f)
/-- A morphism property `P` satisfies `P.Respects Q` if it is stable under composition on the
left and right by morphisms satisfying `Q`. -/
class Respects (P Q : MorphismProperty C) : Prop extends P.RespectsLeft Q, P.RespectsRight Q where
instance (P Q : MorphismProperty C) [P.RespectsLeft Q] [P.RespectsRight Q] : P.Respects Q where
instance (P Q : MorphismProperty C) [P.RespectsLeft Q] : P.op.RespectsRight Q.op where
postcomp i hi f hf := RespectsLeft.precomp (Q := Q) i.unop hi f.unop hf
instance (P Q : MorphismProperty C) [P.RespectsRight Q] : P.op.RespectsLeft Q.op where
precomp i hi f hf := RespectsRight.postcomp (Q := Q) i.unop hi f.unop hf
instance RespectsLeft.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsLeft Q]
[P₂.RespectsLeft Q] : (P₁ ⊓ P₂).RespectsLeft Q where
precomp i hi f hf := ⟨precomp i hi f hf.left, precomp i hi f hf.right⟩
instance RespectsRight.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsRight Q]
[P₂.RespectsRight Q] : (P₁ ⊓ P₂).RespectsRight Q where
postcomp i hi f hf := ⟨postcomp i hi f hf.left, postcomp i hi f hf.right⟩
variable (C)
/-- The `MorphismProperty C` satisfied by isomorphisms in `C`. -/
def isomorphisms : MorphismProperty C := fun _ _ f => IsIso f
/-- The `MorphismProperty C` satisfied by monomorphisms in `C`. -/
def monomorphisms : MorphismProperty C := fun _ _ f => Mono f
/-- The `MorphismProperty C` satisfied by epimorphisms in `C`. -/
def epimorphisms : MorphismProperty C := fun _ _ f => Epi f
section
variable {C}
/-- `P` respects isomorphisms, if it respects the morphism property `isomorphisms C`, i.e.
it is stable under pre- and postcomposition with isomorphisms. -/
abbrev RespectsIso (P : MorphismProperty C) : Prop := P.Respects (isomorphisms C)
lemma RespectsIso.mk (P : MorphismProperty C)
(hprecomp : ∀ {X Y Z : C} (e : X ≅ Y) (f : Y ⟶ Z) (_ : P f), P (e.hom ≫ f))
(hpostcomp : ∀ {X Y Z : C} (e : Y ≅ Z) (f : X ⟶ Y) (_ : P f), P (f ≫ e.hom)) :
P.RespectsIso where
precomp e (_ : IsIso e) f hf := hprecomp (asIso e) f hf
postcomp e (_ : IsIso e) f hf := hpostcomp (asIso e) f hf
lemma RespectsIso.precomp (P : MorphismProperty C) [P.RespectsIso] {X Y Z : C} (e : X ⟶ Y)
[IsIso e] (f : Y ⟶ Z) (hf : P f) : P (e ≫ f) :=
RespectsLeft.precomp (Q := isomorphisms C) e ‹IsIso e› f hf
instance : RespectsIso (⊤ : MorphismProperty C) where
precomp _ _ _ _ := trivial
postcomp _ _ _ _ := trivial
lemma RespectsIso.postcomp (P : MorphismProperty C) [P.RespectsIso] {X Y Z : C} (e : Y ⟶ Z)
[IsIso e] (f : X ⟶ Y) (hf : P f) : P (f ≫ e) :=
RespectsRight.postcomp (Q := isomorphisms C) e ‹IsIso e› f hf
instance RespectsIso.op (P : MorphismProperty C) [RespectsIso P] : RespectsIso P.op where
precomp e (_ : IsIso e) f hf := postcomp P e.unop f.unop hf
postcomp e (_ : IsIso e) f hf := precomp P e.unop f.unop hf
instance RespectsIso.unop (P : MorphismProperty Cᵒᵖ) [RespectsIso P] : RespectsIso P.unop where
precomp e (_ : IsIso e) f hf := postcomp P e.op f.op hf
postcomp e (_ : IsIso e) f hf := precomp P e.op f.op hf
/-- The closure by isomorphisms of a `MorphismProperty` -/
def isoClosure (P : MorphismProperty C) : MorphismProperty C :=
fun _ _ f => ∃ (Y₁ Y₂ : C) (f' : Y₁ ⟶ Y₂) (_ : P f'), Nonempty (Arrow.mk f' ≅ Arrow.mk f)
lemma le_isoClosure (P : MorphismProperty C) : P ≤ P.isoClosure :=
fun _ _ f hf => ⟨_, _, f, hf, ⟨Iso.refl _⟩⟩
instance isoClosure_respectsIso (P : MorphismProperty C) :
RespectsIso P.isoClosure where
precomp := fun e (he : IsIso e) f ⟨_, _, f', hf', ⟨iso⟩⟩ => ⟨_, _, f', hf',
⟨Arrow.isoMk (asIso iso.hom.left ≪≫ asIso (inv e)) (asIso iso.hom.right) (by simp)⟩⟩
postcomp := fun e (he : IsIso e) f ⟨_, _, f', hf', ⟨iso⟩⟩ => ⟨_, _, f', hf',
⟨Arrow.isoMk (asIso iso.hom.left) (asIso iso.hom.right ≪≫ asIso e) (by simp)⟩⟩
lemma monotone_isoClosure : Monotone (isoClosure (C := C)) := by
intro P Q h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩
exact ⟨X', Y', f', h _ hf', ⟨e⟩⟩
theorem cancel_left_of_respectsIso (P : MorphismProperty C) [hP : RespectsIso P] {X Y Z : C}
(f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] : P (f ≫ g) ↔ P g :=
⟨fun h => by simpa using RespectsIso.precomp P (inv f) (f ≫ g) h, RespectsIso.precomp P f g⟩
theorem cancel_right_of_respectsIso (P : MorphismProperty C) [hP : RespectsIso P] {X Y Z : C}
(f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] : P (f ≫ g) ↔ P f :=
⟨fun h => by simpa using RespectsIso.postcomp P (inv g) (f ≫ g) h, RespectsIso.postcomp P g f⟩
lemma comma_iso_iff (P : MorphismProperty C) [P.RespectsIso] {A B : Type*} [Category A] [Category B]
{L : A ⥤ C} {R : B ⥤ C} {f g : Comma L R} (e : f ≅ g) :
P f.hom ↔ P g.hom := by
simp [← Comma.inv_left_hom_right e.hom, cancel_left_of_respectsIso, cancel_right_of_respectsIso]
theorem arrow_iso_iff (P : MorphismProperty C) [RespectsIso P] {f g : Arrow C}
(e : f ≅ g) : P f.hom ↔ P g.hom :=
P.comma_iso_iff e
theorem arrow_mk_iso_iff (P : MorphismProperty C) [RespectsIso P] {W X Y Z : C}
{f : W ⟶ X} {g : Y ⟶ Z} (e : Arrow.mk f ≅ Arrow.mk g) : P f ↔ P g :=
P.arrow_iso_iff e
theorem RespectsIso.of_respects_arrow_iso (P : MorphismProperty C)
(hP : ∀ (f g : Arrow C) (_ : f ≅ g) (_ : P f.hom), P g.hom) : RespectsIso P where
precomp {X Y Z} e (he : IsIso e) f hf := by
refine hP (Arrow.mk f) (Arrow.mk (e ≫ f)) (Arrow.isoMk (asIso (inv e)) (Iso.refl _) ?_) hf
simp
postcomp {X Y Z} e (he : IsIso e) f hf := by
refine hP (Arrow.mk f) (Arrow.mk (f ≫ e)) (Arrow.isoMk (Iso.refl _) (asIso e) ?_) hf
simp
lemma isoClosure_eq_iff (P : MorphismProperty C) :
P.isoClosure = P ↔ P.RespectsIso := by
refine ⟨(· ▸ P.isoClosure_respectsIso), fun hP ↦ le_antisymm ?_ (P.le_isoClosure)⟩
intro X Y f ⟨X', Y', f', hf', ⟨e⟩⟩
exact (P.arrow_mk_iso_iff e).1 hf'
lemma isoClosure_eq_self (P : MorphismProperty C) [P.RespectsIso] :
P.isoClosure = P := by rwa [isoClosure_eq_iff]
@[simp]
lemma isoClosure_isoClosure (P : MorphismProperty C) :
P.isoClosure.isoClosure = P.isoClosure :=
P.isoClosure.isoClosure_eq_self
lemma isoClosure_le_iff (P Q : MorphismProperty C) [Q.RespectsIso] :
P.isoClosure ≤ Q ↔ P ≤ Q := by
constructor
· exact P.le_isoClosure.trans
· intro h
exact (monotone_isoClosure h).trans (by rw [Q.isoClosure_eq_self])
instance map_respectsIso (P : MorphismProperty C) (F : C ⥤ D) :
(P.map F).RespectsIso := by
apply RespectsIso.of_respects_arrow_iso
intro f g e ⟨X', Y', f', hf', ⟨e'⟩⟩
exact ⟨X', Y', f', hf', ⟨e' ≪≫ e⟩⟩
lemma map_le_iff (P : MorphismProperty C) {F : C ⥤ D} (Q : MorphismProperty D)
[RespectsIso Q] :
P.map F ≤ Q ↔ P ≤ Q.inverseImage F := by
constructor
· intro h X Y f hf
exact h (F.map f) (map_mem_map P F f hf)
· intro h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩
exact (Q.arrow_mk_iso_iff e).1 (h _ hf')
@[simp]
lemma map_isoClosure (P : MorphismProperty C) (F : C ⥤ D) :
| P.isoClosure.map F = P.map F := by
apply le_antisymm
· rw [map_le_iff]
intro X Y f ⟨X', Y', f', hf', ⟨e⟩⟩
exact ⟨_, _, f', hf', ⟨F.mapArrow.mapIso e⟩⟩
· exact monotone_map _ (le_isoClosure P)
| Mathlib/CategoryTheory/MorphismProperty/Basic.lean | 338 | 343 |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Localization.LocalizerMorphism
import Mathlib.CategoryTheory.HomCongr
/-!
# Bijections between morphisms in two localized categories
Given two localization functors `L₁ : C ⥤ D₁` and `L₂ : C ⥤ D₂` for the same
class of morphisms `W : MorphismProperty C`, we define a bijection
`Localization.homEquiv W L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ≃ (L₂.obj X ⟶ L₂.obj Y)`
between the types of morphisms in the two localized categories.
More generally, given a localizer morphism `Φ : LocalizerMorphism W₁ W₂`, we define a map
`Φ.homMap L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))`.
The definition `Localization.homEquiv` is obtained by applying the construction
to the identity localizer morphism.
-/
namespace CategoryTheory
open Category
variable {C C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C]
[Category C₁] [Category C₂] [Category C₃]
[Category D₁] [Category D₂] [Category D₃]
namespace LocalizerMorphism
variable {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} {W₃ : MorphismProperty C₃}
(Φ : LocalizerMorphism W₁ W₂) (Ψ : LocalizerMorphism W₂ W₃)
(L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁]
(L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂]
(L₃ : C₃ ⥤ D₃) [L₃.IsLocalization W₃]
{X Y Z : C₁}
/-- If `Φ : LocalizerMorphism W₁ W₂` is a morphism of localizers, `L₁` and `L₂`
are localization functors for `W₁` and `W₂`, then this is the induced map
`(L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))`
for all objects `X` and `Y`. -/
noncomputable def homMap (f : L₁.obj X ⟶ L₁.obj Y) :
L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y) :=
Iso.homCongr ((CatCommSq.iso _ _ _ _).symm.app _) ((CatCommSq.iso _ _ _ _).symm.app _)
((Φ.localizedFunctor L₁ L₂).map f)
@[simp]
lemma homMap_map (f : X ⟶ Y) :
Φ.homMap L₁ L₂ (L₁.map f) = L₂.map (Φ.functor.map f) := by
dsimp [homMap]
erw [← NatTrans.naturality_assoc]
simp
variable (X) in
@[simp]
lemma homMap_id :
Φ.homMap L₁ L₂ (𝟙 (L₁.obj X)) = 𝟙 (L₂.obj (Φ.functor.obj X)) := by
simpa using Φ.homMap_map L₁ L₂ (𝟙 X)
@[reassoc]
lemma homMap_comp (f : L₁.obj X ⟶ L₁.obj Y) (g : L₁.obj Y ⟶ L₁.obj Z) :
Φ.homMap L₁ L₂ (f ≫ g) = Φ.homMap L₁ L₂ f ≫ Φ.homMap L₁ L₂ g := by
simp [homMap]
@[reassoc]
lemma homMap_apply (G : D₁ ⥤ D₂) (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G) (f : L₁.obj X ⟶ L₁.obj Y) :
Φ.homMap L₁ L₂ f = e.hom.app X ≫ G.map f ≫ e.inv.app Y := by
let G' := Φ.localizedFunctor L₁ L₂
let e' := CatCommSq.iso Φ.functor L₁ L₂ G'
change e'.hom.app X ≫ G'.map f ≫ e'.inv.app Y = _
letI : Localization.Lifting L₁ W₁ (Φ.functor ⋙ L₂) G := ⟨e.symm⟩
let α : G' ≅ G := Localization.liftNatIso L₁ W₁ (L₁ ⋙ G') (Φ.functor ⋙ L₂) _ _ e'.symm
have : e = e' ≪≫ isoWhiskerLeft _ α := by
ext X
dsimp [α]
rw [Localization.liftNatTrans_app]
erw [id_comp]
rw [Iso.hom_inv_id_app_assoc]
rfl
simp [this]
@[simp]
lemma id_homMap (f : L₁.obj X ⟶ L₁.obj Y) :
(id W₁).homMap L₁ L₁ f = f := by
simpa using (id W₁).homMap_apply L₁ L₁ (𝟭 D₁) (Iso.refl _) f
@[simp]
lemma homMap_homMap (f : L₁.obj X ⟶ L₁.obj Y) :
Ψ.homMap L₂ L₃ (Φ.homMap L₁ L₂ f) = (Φ.comp Ψ).homMap L₁ L₃ f := by
let G := Φ.localizedFunctor L₁ L₂
let G' := Ψ.localizedFunctor L₂ L₃
let e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G := CatCommSq.iso _ _ _ _
let e' : Ψ.functor ⋙ L₃ ≅ L₂ ⋙ G' := CatCommSq.iso _ _ _ _
rw [Φ.homMap_apply L₁ L₂ G e, Ψ.homMap_apply L₂ L₃ G' e',
(Φ.comp Ψ).homMap_apply L₁ L₃ (G ⋙ G')
(Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e' ≪≫
(Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e _ ≪≫
Functor.associator _ _ _)]
dsimp
simp only [Functor.map_comp, assoc, comp_id, id_comp]
end LocalizerMorphism
namespace Localization
variable (W : MorphismProperty C) (L₁ : C ⥤ D₁) [L₁.IsLocalization W]
(L₂ : C ⥤ D₂) [L₂.IsLocalization W] (L₃ : C ⥤ D₃) [L₃.IsLocalization W]
{X Y Z : C}
/-- Bijection between types of morphisms in two localized categories
for the same class of morphisms `W`. -/
@[simps -isSimp apply]
noncomputable def homEquiv :
(L₁.obj X ⟶ L₁.obj Y) ≃ (L₂.obj X ⟶ L₂.obj Y) where
toFun := (LocalizerMorphism.id W).homMap L₁ L₂
invFun := (LocalizerMorphism.id W).homMap L₂ L₁
left_inv f := by
rw [LocalizerMorphism.homMap_homMap]
apply LocalizerMorphism.id_homMap
right_inv g := by
rw [LocalizerMorphism.homMap_homMap]
apply LocalizerMorphism.id_homMap
@[simp]
lemma homEquiv_symm_apply (g : L₂.obj X ⟶ L₂.obj Y) :
(homEquiv W L₁ L₂).symm g = homEquiv W L₂ L₁ g := rfl
lemma homEquiv_eq (G : D₁ ⥤ D₂) (e : L₁ ⋙ G ≅ L₂) (f : L₁.obj X ⟶ L₁.obj Y) :
homEquiv W L₁ L₂ f = e.inv.app X ≫ G.map f ≫ e.hom.app Y := by
rw [homEquiv_apply, LocalizerMorphism.homMap_apply (LocalizerMorphism.id W) L₁ L₂ G e.symm,
Iso.symm_hom, Iso.symm_inv]
@[simp]
lemma homEquiv_refl (f : L₁.obj X ⟶ L₁.obj Y) :
homEquiv W L₁ L₁ f = f := by
apply LocalizerMorphism.id_homMap
lemma homEquiv_trans (f : L₁.obj X ⟶ L₁.obj Y) :
homEquiv W L₂ L₃ (homEquiv W L₁ L₂ f) = homEquiv W L₁ L₃ f := by
dsimp only [homEquiv_apply]
apply LocalizerMorphism.homMap_homMap
lemma homEquiv_comp (f : L₁.obj X ⟶ L₁.obj Y) (g : L₁.obj Y ⟶ L₁.obj Z) :
homEquiv W L₁ L₂ (f ≫ g) = homEquiv W L₁ L₂ f ≫ homEquiv W L₁ L₂ g := by
apply LocalizerMorphism.homMap_comp
| @[simp]
lemma homEquiv_map (f : X ⟶ Y) : homEquiv W L₁ L₂ (L₁.map f) = L₂.map f := by
simp [homEquiv_apply]
| Mathlib/CategoryTheory/Localization/HomEquiv.lean | 151 | 153 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Order.Filter.AtTopBot.Archimedean
import Mathlib.Order.Iterate
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.InfiniteSum.Real
import Mathlib.Topology.Instances.EReal.Lemmas
/-!
# A collection of specific limit computations
This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
-/
assert_not_exists Basis NormedSpace
noncomputable section
open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal
variable {α : Type*} {β : Type*} {ι : Type*}
theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat
theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) :=
tendsto_const_div_atTop_nhds_zero_nat 1
theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
rw [← NNReal.tendsto_coe]
exact _root_.tendsto_inverse_atTop_nhds_zero_nat
theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝ≥0) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat
theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C ≠ ⊥) (h' : C ≠ ⊤) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
have : (fun n : ℕ ↦ C / n) = fun n : ℕ ↦ ((C.toReal / n : ℝ) : EReal) := by
ext n
nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n]
rw [this, ← coe_zero, tendsto_coe]
exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal
theorem tendsto_one_div_add_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) :=
suffices Tendsto (fun n : ℕ ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa
(tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1)
theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜]
[Algebra ℝ≥0 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ≥0 𝕜] :
Tendsto (algebraMap ℝ≥0 𝕜 ∘ fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
convert (continuous_algebraMap ℝ≥0 𝕜).continuousAt.tendsto.comp
tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero]
theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ 𝕜]
[TopologicalSpace 𝕜] [ContinuousSMul ℝ 𝕜] :
Tendsto (algebraMap ℝ 𝕜 ∘ fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜
/-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division
algebra over `ℝ`, e.g., `ℂ`).
TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this
statement simultaneously on `ℚ`, `ℝ` and `ℂ`. -/
theorem tendsto_natCast_div_add_atTop {𝕜 : Type*} [DivisionRing 𝕜] [TopologicalSpace 𝕜]
[CharZero 𝕜] [Algebra ℝ 𝕜] [ContinuousSMul ℝ 𝕜] [IsTopologicalDivisionRing 𝕜] (x : 𝕜) :
Tendsto (fun n : ℕ ↦ (n : 𝕜) / (n + x)) atTop (𝓝 1) := by
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn ↦ _)) _
· exact fun n : ℕ ↦ 1 / (1 + x / n)
· field_simp [Nat.cast_ne_zero.mpr hn]
· have : 𝓝 (1 : 𝕜) = 𝓝 (1 / (1 + x * (0 : 𝕜))) := by
rw [mul_zero, add_zero, div_one]
rw [this]
refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp)
simp_rw [div_eq_mul_inv]
refine tendsto_const_nhds.mul ?_
have := ((continuous_algebraMap ℝ 𝕜).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero, Filter.tendsto_atTop'] at this
refine Iff.mpr tendsto_atTop' ?_
intros
simp_all only [comp_apply, map_inv₀, map_natCast]
/-- For any positive `m : ℕ`, `((n % m : ℕ) : ℝ) / (n : ℝ)` tends to `0` as `n` tends to `∞`. -/
theorem tendsto_mod_div_atTop_nhds_zero_nat {m : ℕ} (hm : 0 < m) :
Tendsto (fun n : ℕ => ((n % m : ℕ) : ℝ) / (n : ℝ)) atTop (𝓝 0) := by
have h0 : ∀ᶠ n : ℕ in atTop, 0 ≤ (fun n : ℕ => ((n % m : ℕ) : ℝ)) n := by aesop
exact tendsto_bdd_div_atTop_nhds_zero h0
(.of_forall (fun n ↦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop
theorem Filter.EventuallyEq.div_mul_cancel {α G : Type*} [GroupWithZero G] {f g : α → G}
{l : Filter α} (hg : Tendsto g l (𝓟 {0}ᶜ)) : (fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x := by
filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}ᶜ)] with x hx
aesop
/-- If `g` tends to `∞`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/
theorem Filter.EventuallyEq.div_mul_cancel_atTop {α K : Type*}
[Semifield K] [LinearOrder K] [IsStrictOrderedRing K]
{f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) :
(fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x :=
div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <|
mem_of_superset (Ioi_mem_atTop 0) <| by simp
/-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive
constant, then `f` tends to `∞`. -/
theorem Tendsto.num {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
{f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto f l atTop :=
(hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg)
/-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive
constant, then `f` tends to `∞`. -/
theorem Tendsto.den {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K]
[TopologicalSpace K] [OrderTopology K]
[ContinuousInv K] {f g : α → K} {l : Filter α} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto g l atTop :=
have hlim' : Tendsto (fun x => g x / f x) l (𝓝 a⁻¹) := by
simp_rw [← inv_div (f _)]
exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim
(hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf)
/-- If when `x` tends to `∞`, `f x / g x` tends to a positive constant, then `f` tends to `∞` if
and only if `g` tends to `∞`. -/
theorem Tendsto.num_atTop_iff_den_atTop {α K : Type*}
[Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K]
[OrderTopology K] [ContinuousInv K] {f g : α → K} {l : Filter α} {a : K} (ha : 0 < a)
(hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) :
Tendsto f l atTop ↔ Tendsto g l atTop :=
⟨fun hf ↦ Tendsto.den hf ha hlim, fun hg ↦ Tendsto.num hg ha hlim⟩
/-! ### Powers -/
theorem tendsto_add_one_pow_atTop_atTop_of_pos
[Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α}
(h : 0 < r) : Tendsto (fun n : ℕ ↦ (r + 1) ^ n) atTop atTop :=
tendsto_atTop_atTop_of_monotone' (pow_right_mono₀ <| le_add_of_nonneg_left h.le) <|
not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h
theorem tendsto_pow_atTop_atTop_of_one_lt
[Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α}
(h : 1 < r) : Tendsto (fun n : ℕ ↦ r ^ n) atTop atTop :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h)
theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : ℕ} (h : 1 < m) :
Tendsto (fun n : ℕ ↦ m ^ n) atTop atTop :=
tsub_add_cancel_of_le (le_of_lt h) ▸ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h)
theorem tendsto_pow_atTop_nhds_zero_of_lt_one {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
h₁.eq_or_lt.elim
(fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by
simp [_root_.pow_succ, ← hr, tendsto_const_nhds])
(fun hr ↦
have := (one_lt_inv₀ hr).2 h₂ |> tendsto_pow_atTop_atTop_of_one_lt
(tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp)
@[simp] theorem tendsto_pow_atTop_nhds_zero_iff {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by
rw [tendsto_zero_iff_abs_tendsto_zero]
refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩
· by_cases hr : 1 = |r|
· replace h : Tendsto (fun n : ℕ ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h]
simp only [hr.symm, one_pow] at h
exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds
· apply @not_tendsto_nhds_of_tendsto_atTop 𝕜 ℕ _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _
· refine (pow_right_strictMono₀ <| lt_of_le_of_ne (le_of_not_lt hr_le)
hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_)
obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr))
exact ⟨n, le_of_lt hn⟩
· simpa only [← abs_pow]
· simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h
theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {𝕜 : Type*}
[Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
[Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝[>] 0) :=
tendsto_inf.2
⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le h₂,
tendsto_principal.2 <| Eventually.of_forall fun _ ↦ pow_pos h₁ _⟩
theorem uniformity_basis_dist_pow_of_lt_one {α : Type*} [PseudoMetricSpace α] {r : ℝ} (h₀ : 0 < r)
(h₁ : r < 1) :
(uniformity α).HasBasis (fun _ : ℕ ↦ True) fun k ↦ { p : α × α | dist p.1 p.2 < r ^ k } :=
Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos h₀ _) fun _ ε0 ↦
(exists_pow_lt_of_lt_one ε0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩
theorem geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) :
c ^ n * u 0 ≤ u n := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
theorem lt_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem le_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, u (k + 1) ≤ c * u k) :
u n ≤ c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`,
then it goes to +∞. -/
theorem tendsto_atTop_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c)
(hu : ∀ n, c * v n ≤ v (n + 1)) : Tendsto v atTop atTop :=
(tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <|
(tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const h₀
theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
NNReal.tendsto_coe.1 <| by
simp only [NNReal.coe_pow, NNReal.coe_zero,
_root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr]
@[simp]
protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 :=
⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using
tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0∞} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := by
rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩
rw [← ENNReal.coe_zero]
norm_cast at *
apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0∞} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := by
refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
lift r to NNReal
· refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr ▸ h))
exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩
rw [← coe_zero] at h
norm_cast at h ⊢
exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝ≥0∞} :
Tendsto (fun n ↦ r^n) atTop (𝓝 ∞) ↔ 1 < r := by
refine ⟨?_, ?_⟩
· contrapose!
intro r_le_one h_tends
specialize h_tends (Ioi_mem_nhds one_lt_top)
simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends
obtain ⟨n, hn⟩ := h_tends
exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_one₀ (zero_le _) r_le_one
· intro r_gt_one
have obs := @Tendsto.inv ℝ≥0∞ ℕ _ _ _ (fun n ↦ (r⁻¹)^n) atTop 0
simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs
simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one
lemma ENNReal.eq_zero_of_le_mul_pow {x r : ℝ≥0∞} {ε : ℝ≥0} (hr : r < 1)
(h : ∀ n : ℕ, x ≤ ε * r ^ n) : x = 0 := by
rw [← nonpos_iff_eq_zero]
refine ge_of_tendsto' (f := fun (n : ℕ) ↦ ε * r ^ n) (x := atTop) ?_ h
rw [← mul_zero (M₀ := ℝ≥0∞) (a := ε)]
exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top)
/-! ### Geometric series -/
section Geometric
theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ :=
have : r ≠ 1 := ne_of_lt h₂
have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) :=
((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds
(hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by
simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv]
theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Summable fun n : ℕ ↦ r ^ n :=
⟨_, hasSum_geometric_of_lt_one h₁ h₂⟩
theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
(hasSum_geometric_of_lt_one h₁ h₂).tsum_eq
theorem hasSum_geometric_two : HasSum (fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n) 2 := by
convert hasSum_geometric_of_lt_one _ _ <;> norm_num
theorem summable_geometric_two : Summable fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n :=
⟨_, hasSum_geometric_two⟩
theorem summable_geometric_two_encode {ι : Type*} [Encodable ι] :
Summable fun i : ι ↦ (1 / 2 : ℝ) ^ Encodable.encode i :=
summable_geometric_two.comp_injective Encodable.encode_injective
|
theorem tsum_geometric_two : (∑' n : ℕ, ((1 : ℝ) / 2) ^ n) = 2 :=
hasSum_geometric_two.tsum_eq
theorem sum_geometric_two_le (n : ℕ) : (∑ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≤ 2 := by
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i := by
intro i
apply pow_nonneg
norm_num
convert summable_geometric_two.sum_le_tsum (range n) (fun i _ ↦ this i)
| Mathlib/Analysis/SpecificLimits/Basic.lean | 317 | 326 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Ring.Unbundled.Basic
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
assert_not_exists MonoidHom
open Function
universe u
variable {R : Type u}
-- TODO: assume weaker typeclasses
/-- An ordered semiring is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedAddMonoid R, ZeroLEOneClass R where
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
attribute [instance 100] IsOrderedRing.toZeroLEOneClass
/-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R where
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the left
by a positive element `0 < c` to obtain `c * a < c * b`. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the right
by a positive element `0 < c` to obtain `a * c < b * c`. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass
attribute [instance 100] IsStrictOrderedRing.toNontrivial
lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) :
IsOrderedRing R where
mul_le_mul_of_nonneg_left a b c ab hc := by
simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ hc (sub_nonneg.2 ab)
mul_le_mul_of_nonneg_right a b c ab hc := by
simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 ab) hc
lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) :
IsStrictOrderedRing R where
mul_lt_mul_of_pos_left a b c ab hc := by
simpa only [mul_sub, sub_pos] using mul_pos _ _ hc (sub_pos.2 ab)
mul_lt_mul_of_pos_right a b c ab hc := by
simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 ab) hc
section IsOrderedRing
variable [Semiring R] [PartialOrder R] [IsOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toPosMulMono : PosMulMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_left _ _ _ h x.2
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toMulPosMono : MulPosMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_right _ _ _ h x.2
end IsOrderedRing
/-- Turn an ordered domain into a strict ordered ring. -/
lemma IsOrderedRing.toIsStrictOrderedRing (R : Type*)
[Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] :
IsStrictOrderedRing R :=
.of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne')
section IsStrictOrderedRing
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toPosMulStrictMono : PosMulStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_left _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toMulPosStrictMono : MulPosStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_right _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where
__ := ‹IsStrictOrderedRing R›
mul_le_mul_of_nonneg_left _ _ _ := mul_le_mul_of_nonneg_left
mul_le_mul_of_nonneg_right _ _ _ := mul_le_mul_of_nonneg_right
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toCharZero :
CharZero R where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
end IsStrictOrderedRing
section LinearOrder
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R]
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by
contrapose! hab
obtain ha | ha := hab.1.lt_or_lt <;> obtain hb | hb := hab.2.lt_or_lt
exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne']
-- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring.
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where
mul_left_cancel_of_ne_zero {a b c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h]
mul_right_cancel_of_ne_zero {b a c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h]
end LinearOrder
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
set_option linter.deprecated false in
/-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedSemiring (R : Type u) extends Semiring R, OrderedAddCommMonoid R where
/-- `0 ≤ 1` in any ordered semiring. -/
protected zero_le_one : (0 : R) ≤ 1
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
set_option linter.deprecated false in
/-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is
monotone and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommSemiring (R : Type u) extends OrderedSemiring R, CommSemiring R where
mul_le_mul_of_nonneg_right a b c ha hc :=
-- parentheses ensure this generates an `optParam` rather than an `autoParam`
(by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc)
set_option linter.deprecated false in
/-- An `OrderedRing` is a ring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R where
/-- `0 ≤ 1` in any ordered ring. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of non-negative elements is non-negative. -/
protected mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b
set_option linter.deprecated false in
/-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone
and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommRing (R : Type u) extends OrderedRing R, CommRing R
set_option linter.deprecated false in
/-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedSemiring (R : Type u) extends Semiring R, OrderedCancelAddCommMonoid R,
Nontrivial R where
/-- In a strict ordered semiring, `0 ≤ 1`. -/
protected zero_le_one : (0 : R) ≤ 1
/-- Left multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- Right multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
set_option linter.deprecated false in
/-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that
addition is strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommSemiring (R : Type u) extends StrictOrderedSemiring R, CommSemiring R
set_option linter.deprecated false in
/-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone
and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R, Nontrivial R where
/-- In a strict ordered ring, `0 ≤ 1`. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of two positive elements is positive. -/
protected mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b
set_option linter.deprecated false in
/-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommRing (R : Type*) extends StrictOrderedRing R, CommRing R
/- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to
explore changing this, but be warned that the instances involving `Domain` may cause typeclass
search loops. -/
set_option linter.deprecated false in
/-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemiring (R : Type u) extends StrictOrderedSemiring R,
LinearOrderedAddCommMonoid R
set_option linter.deprecated false in
/-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such
that addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommSemiring (R : Type*) extends StrictOrderedCommSemiring R,
LinearOrderedSemiring R
set_option linter.deprecated false in
/-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and
multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedRing (R : Type u) extends StrictOrderedRing R, LinearOrder R
set_option linter.deprecated false in
/-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is
monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommRing (R : Type u) extends LinearOrderedRing R, CommMonoid R
attribute [nolint docBlame]
StrictOrderedSemiring.toOrderedCancelAddCommMonoid
StrictOrderedCommSemiring.toCommSemiring
LinearOrderedSemiring.toLinearOrderedAddCommMonoid
LinearOrderedRing.toLinearOrder
OrderedSemiring.toOrderedAddCommMonoid
OrderedCommSemiring.toCommSemiring
StrictOrderedCommRing.toCommRing
OrderedRing.toOrderedAddCommGroup
OrderedCommRing.toCommRing
StrictOrderedRing.toOrderedAddCommGroup
LinearOrderedCommSemiring.toLinearOrderedSemiring
LinearOrderedCommRing.toCommMonoid
section OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R}
lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c]
gcongr
lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b]
gcongr
end OrderedRing
| Mathlib/Algebra/Order/Ring/Defs.lean | 889 | 891 | |
/-
Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Principal
/-!
# Ordinal arithmetic with cardinals
This file collects results about the cardinality of different ordinal operations.
-/
universe u v
open Cardinal Ordinal Set
/-! ### Cardinal operations with ordinal indices -/
namespace Cardinal
/-- Bounds the cardinal of an ordinal-indexed union of sets. -/
lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}}
(ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β)
(hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by
simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp]
rw [← lift_le.{u}]
apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc))
rw [mk_toType]
refine mul_le_mul' ho (ciSup_le' ?_)
intro i
simpa using hA _ (o.enumIsoToType.symm i).2
lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal}
(ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β)
(hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by
apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA
rwa [Cardinal.lift_le]
end Cardinal
@[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")]
alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le
/-! ### Cardinality of ordinals -/
namespace Ordinal
theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) :
Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by
simp_rw [← mk_toType]
rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}]
apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2,
(mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩))
rw [EquivLike.comp_surjective]
rintro ⟨x, hx⟩
obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx
exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩
theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) :
(⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by
have := lift_card_iSup_le_sum_card f
rwa [Cardinal.lift_id'] at this
theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) :
(⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by
apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _)
simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x)
theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) :
(⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by
apply (card_iSup_Iio_le_sum_card f).trans
convert ← sum_le_iSup_lift _
· exact mk_toType o
· exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card)
theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) :
(a ^ b).card ≤ max a.card b.card := by
refine limitRecOn b ?_ ?_ ?_
· simpa using one_lt_omega0.le.trans ha
· intro b IH
rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
· apply (max_le_max_left _ IH).trans
rw [← max_assoc, max_self]
exact max_le_max_left _ le_self_add
· rw [ne_eq, card_eq_zero, opow_eq_zero]
rintro ⟨rfl, -⟩
cases omega0_pos.not_le ha
· rwa [aleph0_le_card]
· intro b hb IH
rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb]
apply (card_iSup_Iio_le_card_mul_iSup _).trans
rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm]
· apply max_le _ (le_max_right _ _)
apply ciSup_le'
intro c
exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le))
· simpa using hb.pos.ne'
· refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_
· exact Cardinal.bddAbove_of_small _
· simpa
theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) :
(a ^ b).card ≤ max a.card b.card := by
obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a
· apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans
apply (card_opow_le_of_omega0_le_left le_rfl _).trans
simp [hb]
· exact card_opow_le_of_omega0_le_left ha b
theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by
obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a
· obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b
· rw [← natCast_opow, card_nat]
exact le_max_of_le_left (nat_lt_aleph0 _).le
· exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _)
· exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _)
theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card
· exact left_le_opow a hb
· exact right_le_opow b (one_lt_omega0.trans_le ha)
theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) :
(a ^ b).card = max a.card b.card := by
apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card
· exact left_le_opow a (omega0_pos.trans_le hb)
· exact right_le_opow b ha
theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by
rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0]
theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by
rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm]
theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by
obtain rfl | ho := Ordinal.eq_zero_or_pos o
· rw [omega_zero]
exact principal_opow_omega0
· intro a b ha hb
rw [lt_omega_iff_card_lt] at ha hb ⊢
apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb))
rwa [← aleph_zero, aleph_lt_aleph]
theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· ^ ·) o := by
obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩
exact principal_opow_omega a
theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by
apply (isInitial_ord c).principal_opow
rwa [omega0_le_ord]
/-! ### Initial ordinals are principal -/
theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by
intro a b ha hb
rw [lt_ord, card_add] at *
exact add_lt_of_lt hc ha hb
theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· + ·) o := by
rw [← h.ord_card]
apply principal_add_ord
rwa [aleph0_le_card]
theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) :=
(isInitial_omega o).principal_add (omega0_le_omega o)
theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by
intro a b ha hb
rw [lt_ord, card_mul] at *
exact mul_lt_of_lt hc ha hb
theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) :
Principal (· * ·) o := by
rw [← h.ord_card]
apply principal_mul_ord
rwa [aleph0_le_card]
theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) :=
(isInitial_omega o).principal_mul (omega0_le_omega o)
@[deprecated principal_add_omega (since := "2024-11-08")]
theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord :=
principal_add_ord <| aleph0_le_aleph o
end Ordinal
| Mathlib/SetTheory/Cardinal/Ordinal.lean | 204 | 207 | |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Emilie Uthaiwat, Oliver Nash
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Div
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.RingTheory.Polynomial.Tower
/-!
# Nilpotency in polynomial rings.
This file is a place for results related to nilpotency in (single-variable) polynomial rings.
## Main results:
* `Polynomial.isNilpotent_iff`
* `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent`
-/
namespace Polynomial
variable {R : Type*} {r : R}
section Semiring
variable [Semiring R] {P : R[X]}
lemma isNilpotent_C_mul_pow_X_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent ((C r) * X ^ n) := by
refine Commute.isNilpotent_mul_left (commute_X_pow _ _).symm ?_
obtain ⟨m, hm⟩ := hnil
refine ⟨m, ?_⟩
rw [← C_pow, hm, C_0]
lemma isNilpotent_pow_X_mul_C_of_isNilpotent (n : ℕ) (hnil : IsNilpotent r) :
IsNilpotent (X ^ n * (C r)) := by
rw [commute_X_pow]
exact isNilpotent_C_mul_pow_X_of_isNilpotent n hnil
| @[simp] lemma isNilpotent_monomial_iff {n : ℕ} :
IsNilpotent (monomial (R := R) n r) ↔ IsNilpotent r :=
exists_congr fun k ↦ by simp
| Mathlib/RingTheory/Polynomial/Nilpotent.lean | 45 | 47 |
/-
Copyright (c) 2024 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Pietro Monticone
-/
import Mathlib.NumberTheory.Cyclotomic.Embeddings
import Mathlib.NumberTheory.Cyclotomic.Rat
import Mathlib.NumberTheory.NumberField.Units.DirichletTheorem
import Mathlib.RingTheory.Fintype
/-!
# Third Cyclotomic Field
We gather various results about the third cyclotomic field. The following notations are used in this
file: `K` is a number field such that `IsCyclotomicExtension {3} ℚ K`, `ζ` is any primitive `3`-rd
root of unity in `K`, `η` is the element in the units of the ring of integers corresponding to `ζ`
and `λ = η - 1`.
## Main results
* `IsCyclotomicExtension.Rat.Three.Units.mem`: Given a unit `u : (𝓞 K)ˣ`, we have that
`u ∈ {1, -1, η, -η, η^2, -η^2}`.
* `IsCyclotomicExtension.Rat.Three.eq_one_or_neg_one_of_unit_of_congruent`: Given a unit
`u : (𝓞 K)ˣ`, if `u` is congruent to an integer modulo `3`, then `u = 1` or `u = -1`.
This is a special case of the so-called *Kummer's lemma* (see for example [washington_cyclotomic],
Theorem 5.36
-/
open NumberField Units InfinitePlace nonZeroDivisors Polynomial
namespace IsCyclotomicExtension.Rat.Three
variable {K : Type*} [Field K]
variable {ζ : K} (hζ : IsPrimitiveRoot ζ ↑(3 : ℕ+)) (u : (𝓞 K)ˣ)
local notation3 "η" => (IsPrimitiveRoot.isUnit (hζ.toInteger_isPrimitiveRoot) (by decide)).unit
local notation3 "λ" => hζ.toInteger - 1
lemma coe_eta : (η : 𝓞 K) = hζ.toInteger := rfl
lemma _root_.IsPrimitiveRoot.toInteger_cube_eq_one : hζ.toInteger ^ 3 = 1 :=
hζ.toInteger_isPrimitiveRoot.pow_eq_one
/-- Let `u` be a unit in `(𝓞 K)ˣ`, then `u ∈ [1, -1, η, -η, η^2, -η^2]`. -/
-- Here `List` is more convenient than `Finset`, even if further from the informal statement.
-- For example, `fin_cases` below does not work with a `Finset`.
theorem Units.mem [NumberField K] [IsCyclotomicExtension {3} ℚ K] :
u ∈ [1, -1, η, -η, η ^ 2, -η ^ 2] := by
have hrank : rank K = 0 := by
dsimp only [rank]
rw [card_eq_nrRealPlaces_add_nrComplexPlaces, nrRealPlaces_eq_zero (n := 3) K (by decide),
zero_add, nrComplexPlaces_eq_totient_div_two (n := 3)]
rfl
obtain ⟨⟨x, e⟩, hxu, -⟩ := exist_unique_eq_mul_prod _ u
replace hxu : u = x := by
rw [← mul_one x.1, hxu]
apply congr_arg
rw [← Finset.prod_empty]
congr
rw [Finset.univ_eq_empty_iff, hrank]
infer_instance
obtain ⟨n, hnpos, hn⟩ := isOfFinOrder_iff_pow_eq_one.1 <| (CommGroup.mem_torsion _ _).1 x.2
replace hn : (↑u : K) ^ ((⟨n, hnpos⟩ : ℕ+) : ℕ) = 1 := by
rw [← map_pow]
convert map_one (algebraMap (𝓞 K) K)
rw_mod_cast [hxu, hn]
simp
obtain ⟨r, hr3, hru⟩ := hζ.exists_pow_or_neg_mul_pow_of_isOfFinOrder (by decide)
(isOfFinOrder_iff_pow_eq_one.2 ⟨n, hnpos, hn⟩)
replace hr : r ∈ Finset.Ico 0 3 := Finset.mem_Ico.2 ⟨by simp, hr3⟩
replace hru : ↑u = η ^ r ∨ ↑u = -η ^ r := by
rcases hru with h | h
· left; ext; exact h
· right; ext; exact h
fin_cases hr <;> rcases hru with h | h <;> simp [h]
/-- We have that `λ ^ 2 = -3 * η`. -/
private lemma lambda_sq : λ ^ 2 = -3 * η := by
ext
calc (λ ^ 2 : K) = η ^ 2 + η + 1 - 3 * η := by
simp only [RingOfIntegers.map_mk, IsUnit.unit_spec]; ring
_ = 0 - 3 * η := by simpa using hζ.isRoot_cyclotomic (by decide)
_ = -3 * η := by ring
/-- We have that `η ^ 2 = -η - 1`. -/
lemma eta_sq : (η ^ 2 : 𝓞 K) = - η - 1 := by
rw [← neg_add', ← add_eq_zero_iff_eq_neg, ← add_assoc]
ext; simpa using hζ.isRoot_cyclotomic (by decide)
/-- If a unit `u` is congruent to an integer modulo `λ ^ 2`, then `u = 1` or `u = -1`.
This is a special case of the so-called *Kummer's lemma*. -/
theorem eq_one_or_neg_one_of_unit_of_congruent
[NumberField K] [IsCyclotomicExtension {3} ℚ K] (hcong : ∃ n : ℤ, λ ^ 2 ∣ (u - n : 𝓞 K)) :
u = 1 ∨ u = -1 := by
replace hcong : ∃ n : ℤ, (3 : 𝓞 K) ∣ (↑u - n : 𝓞 K) := by
obtain ⟨n, x, hx⟩ := hcong
exact ⟨n, -η * x, by rw [← mul_assoc, mul_neg, ← neg_mul, ← lambda_sq, hx]⟩
have hζ := IsCyclotomicExtension.zeta_spec 3 ℚ K
have := Units.mem hζ u
fin_cases this
· left; rfl
· right; rfl
all_goals exfalso
· exact hζ.not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide) hcong
· apply hζ.not_exists_int_prime_dvd_sub_of_prime_ne_two' (by decide)
obtain ⟨n, x, hx⟩ := hcong
rw [sub_eq_iff_eq_add] at hx
refine ⟨-n, -x, sub_eq_iff_eq_add.2 ?_⟩
simp only [PNat.val_ofNat, Nat.cast_ofNat, mul_neg, Int.cast_neg, ← neg_add, ← hx,
Units.val_neg, IsUnit.unit_spec, RingOfIntegers.neg_mk, neg_neg]
· exact (hζ.pow_of_coprime 2 (by decide)).not_exists_int_prime_dvd_sub_of_prime_ne_two'
(by decide) hcong
· apply (hζ.pow_of_coprime 2 (by decide)).not_exists_int_prime_dvd_sub_of_prime_ne_two'
(by decide)
obtain ⟨n, x, hx⟩ := hcong
refine ⟨-n, -x, sub_eq_iff_eq_add.2 ?_⟩
have : (hζ.pow_of_coprime 2 (by decide)).toInteger = hζ.toInteger ^ 2 := by ext; simp
simp only [this, PNat.val_ofNat, Nat.cast_ofNat, mul_neg, Int.cast_neg, ← neg_add, ←
sub_eq_iff_eq_add.1 hx, Units.val_neg, val_pow_eq_pow_val, IsUnit.unit_spec, neg_neg]
variable (x : 𝓞 K)
/-- Let `(x : 𝓞 K)`. Then we have that `λ` divides one amongst `x`, `x - 1` and `x + 1`. -/
lemma lambda_dvd_or_dvd_sub_one_or_dvd_add_one [NumberField K] [IsCyclotomicExtension {3} ℚ K] :
λ ∣ x ∨ λ ∣ x - 1 ∨ λ ∣ x + 1 := by
classical
have := hζ.finite_quotient_toInteger_sub_one (by decide)
let _ := Fintype.ofFinite (𝓞 K ⧸ Ideal.span {λ})
let _ : Ring (𝓞 K ⧸ Ideal.span {λ}) := CommRing.toRing -- to speed up instance synthesis
let _ : AddGroup (𝓞 K ⧸ Ideal.span {λ}) := AddGroupWithOne.toAddGroup -- ditto
have := Finset.mem_univ (Ideal.Quotient.mk (Ideal.span {λ}) x)
have h3 : Fintype.card (𝓞 K ⧸ Ideal.span {λ}) = 3 := by
rw [← Nat.card_eq_fintype_card, hζ.card_quotient_toInteger_sub_one,
hζ.norm_toInteger_sub_one_of_prime_ne_two' (by decide)]
simp only [PNat.val_ofNat, Nat.cast_ofNat, Int.reduceAbs]
rw [Finset.univ_of_card_le_three h3.le] at this
simp only [Finset.mem_insert, Finset.mem_singleton] at this
rcases this with h | h | h
· left
exact Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 h
· right; left
refine Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 ?_
rw [RingHom.map_sub, h, RingHom.map_one, sub_self]
· right; right
refine Ideal.mem_span_singleton.1 <| Ideal.Quotient.eq_zero_iff_mem.1 ?_
rw [RingHom.map_add, h, RingHom.map_one, neg_add_cancel]
/-- We have that `η ^ 2 + η + 1 = 0`. -/
lemma eta_sq_add_eta_add_one : (η : 𝓞 K) ^ 2 + η + 1 = 0 := by
rw [eta_sq]
ring
/-- We have that `x ^ 3 - 1 = (x - 1) * (x - η) * (x - η ^ 2)`. -/
lemma cube_sub_one_eq_mul : x ^ 3 - 1 = (x - 1) * (x - η) * (x - η ^ 2) := by
symm
calc _ = x ^ 3 - x ^ 2 * (η ^ 2 + η + 1) + x * (η ^ 2 + η + η ^ 3) - η ^ 3 := by ring
_ = x ^ 3 - x ^ 2 * (η ^ 2 + η + 1) + x * (η ^ 2 + η + 1) - 1 := by
simp [hζ.toInteger_cube_eq_one]
_ = x ^ 3 - 1 := by rw [eta_sq_add_eta_add_one hζ]; ring
variable [NumberField K] [IsCyclotomicExtension {3} ℚ K]
/-- We have that `λ` divides `x * (x - 1) * (x - (η + 1))`. -/
lemma lambda_dvd_mul_sub_one_mul_sub_eta_add_one : λ ∣ x * (x - 1) * (x - (η + 1)) := by
rcases lambda_dvd_or_dvd_sub_one_or_dvd_add_one hζ x with h | h | h
· exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_left h _) _
| · exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_right h _) _
· refine dvd_mul_of_dvd_right ?_ _
rw [show x - (η + 1) = x + 1 - (η - 1 + 3) by ring]
exact dvd_sub h <| dvd_add dvd_rfl hζ.toInteger_sub_one_dvd_prime'
/-- If `λ` divides `x - 1`, then `λ ^ 4` divides `x ^ 3 - 1`. -/
lemma lambda_pow_four_dvd_cube_sub_one_of_dvd_sub_one {x : 𝓞 K} (h : λ ∣ x - 1) :
λ ^ 4 ∣ x ^ 3 - 1 := by
obtain ⟨y, hy⟩ := h
have : x ^ 3 - 1 = λ ^ 3 * (y * (y - 1) * (y - (η + 1))) := by
| Mathlib/NumberTheory/Cyclotomic/Three.lean | 168 | 177 |
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Some results on free modules over rings satisfying strong rank condition
This file contains some results on free modules over rings satisfying strong rank condition.
Most of them are generalized from the same result assuming the base ring being division ring,
and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean`
and `Mathlib/LinearAlgebra/FiniteDimensional.lean`.
-/
open Cardinal Module Module Set Submodule
universe u v
section Module
variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V]
/-- The `ι` indexed basis on `V`, where `ι` is an empty type and `V` is zero-dimensional.
See also `Module.finBasis`.
-/
noncomputable def Basis.ofRankEqZero [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) : Basis ι K V :=
haveI : Subsingleton V := by
obtain ⟨_, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (hV ▸ b.mk_eq_rank'')
exact b.repr.toEquiv.subsingleton
Basis.empty _
@[simp]
theorem Basis.ofRankEqZero_apply [Module.Free K V] {ι : Type*} [IsEmpty ι]
(hV : Module.rank K V = 0) (i : ι) : Basis.ofRankEqZero hV i = 0 := rfl
theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} :
c ≤ Module.rank K V ↔ ∃ s : Set V, #s = c ∧ LinearIndepOn K id s := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
· intro h
obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V)
let t := t'.reindexRange
have : LinearIndepOn K id (Set.range t') := by
convert t.linearIndependent.linearIndepOn_id
ext
simp [t]
rw [← t.mk_eq_rank'', le_mk_iff_exists_subset] at h
rcases h with ⟨s, hst, hsc⟩
exact ⟨s, hsc, this.mono hst⟩
· rintro ⟨s, rfl, si⟩
exact si.cardinal_le_rank
theorem le_rank_iff_exists_linearIndependent_finset
[Module.Free K V] {n : ℕ} : ↑n ≤ Module.rank K V ↔
∃ s : Finset V, s.card = n ∧ LinearIndependent K ((↑) : ↥(s : Set V) → V) := by
simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset]
constructor
· rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩
exact ⟨t, rfl, si⟩
· rintro ⟨s, rfl, si⟩
exact ⟨s, ⟨s, rfl, rfl⟩, si⟩
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
theorem rank_le_one_iff [Module.Free K V] :
Module.rank K V ≤ 1 ↔ ∃ v₀ : V, ∀ v, ∃ r : K, r • v₀ = v := by
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
constructor
· intro hd
rw [← b.mk_eq_rank'', le_one_iff_subsingleton] at hd
rcases isEmpty_or_nonempty κ with hb | ⟨⟨i⟩⟩
· use 0
have h' : ∀ v : V, v = 0 := by
simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm
intro v
simp [h' v]
· use b i
have h' : (K ∙ b i) = ⊤ :=
(subsingleton_range b).eq_singleton_of_mem (mem_range_self i) ▸ b.span_eq
intro v
have hv : v ∈ (⊤ : Submodule K V) := mem_top
rwa [← h', mem_span_singleton] at hv
· rintro ⟨v₀, hv₀⟩
have h : (K ∙ v₀) = ⊤ := by
ext
simp [mem_span_singleton, hv₀]
rw [← rank_top, ← h]
refine (rank_span_le _).trans_eq ?_
simp
/-- A vector space has dimension `1` if and only if there is a
single non-zero vector of which all vectors are multiples. -/
theorem rank_eq_one_iff [Module.Free K V] :
Module.rank K V = 1 ↔ ∃ v₀ : V, v₀ ≠ 0 ∧ ∀ v, ∃ r : K, r • v₀ = v := by
haveI := nontrivial_of_invariantBasisNumber K
refine ⟨fun h ↦ ?_, fun ⟨v₀, h, hv⟩ ↦ (rank_le_one_iff.2 ⟨v₀, hv⟩).antisymm ?_⟩
· obtain ⟨v₀, hv⟩ := rank_le_one_iff.1 h.le
refine ⟨v₀, fun hzero ↦ ?_, hv⟩
simp_rw [hzero, smul_zero, exists_const] at hv
haveI : Subsingleton V := .intro fun _ _ ↦ by simp_rw [← hv]
exact one_ne_zero (h ▸ rank_subsingleton' K V)
· by_contra H
rw [not_le, lt_one_iff_zero] at H
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (H ▸ b.mk_eq_rank'')
haveI := b.repr.toEquiv.subsingleton
exact h (Subsingleton.elim _ _)
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s ≤ 1 ↔ ∃ v₀ ∈ s, s ≤ K ∙ v₀ := by
simp_rw [rank_le_one_iff, le_span_singleton_iff]
constructor
· rintro ⟨⟨v₀, hv₀⟩, h⟩
use v₀, hv₀
intro v hv
obtain ⟨r, hr⟩ := h ⟨v, hv⟩
use r
rwa [Subtype.ext_iff, coe_smul] at hr
· rintro ⟨v₀, hv₀, h⟩
use ⟨v₀, hv₀⟩
rintro ⟨v, hv⟩
obtain ⟨r, hr⟩ := h v hv
use r
rwa [Subtype.ext_iff, coe_smul]
/-- A submodule has dimension `1` if and only if there is a
single non-zero vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s = 1 ↔ ∃ v₀ ∈ s, v₀ ≠ 0 ∧ s ≤ K ∙ v₀ := by
simp_rw [rank_eq_one_iff, le_span_singleton_iff]
refine ⟨fun ⟨⟨v₀, hv₀⟩, H, h⟩ ↦ ⟨v₀, hv₀, fun h' ↦ by
simp only [h', ne_eq] at H; exact H rfl, fun v hv ↦ ?_⟩,
fun ⟨v₀, hv₀, H, h⟩ ↦ ⟨⟨v₀, hv₀⟩,
fun h' ↦ H (by rwa [AddSubmonoid.mk_eq_zero] at h'), fun ⟨v, hv⟩ ↦ ?_⟩⟩
· obtain ⟨r, hr⟩ := h ⟨v, hv⟩
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul] at hr⟩
· obtain ⟨r, hr⟩ := h v hv
exact ⟨r, by rwa [Subtype.ext_iff, coe_smul]⟩
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
submodule is contained in its span. -/
theorem rank_submodule_le_one_iff' (s : Submodule K V) [Module.Free K s] :
Module.rank K s ≤ 1 ↔ ∃ v₀, s ≤ K ∙ v₀ := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
· rw [rank_submodule_le_one_iff]
rintro ⟨v₀, _, h⟩
exact ⟨v₀, h⟩
· rintro ⟨v₀, h⟩
obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := s)
simpa [b.mk_eq_rank''] using b.linearIndependent.map' _ (ker_inclusion _ _ h)
|>.cardinal_le_rank.trans (rank_span_le {v₀})
theorem Submodule.rank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] :
Module.rank K W ≤ 1 ↔ W.IsPrincipal := by
simp only [rank_le_one_iff, Submodule.isPrincipal_iff, le_antisymm_iff, le_span_singleton_iff,
span_singleton_le_iff_mem]
constructor
· rintro ⟨⟨m, hm⟩, hm'⟩
choose f hf using hm'
exact ⟨m, ⟨fun v hv => ⟨f ⟨v, hv⟩, congr_arg ((↑) : W → V) (hf ⟨v, hv⟩)⟩, hm⟩⟩
· rintro ⟨a, ⟨h, ha⟩⟩
choose f hf using h
exact ⟨⟨a, ha⟩, fun v => ⟨f v.1 v.2, Subtype.ext (hf v.1 v.2)⟩⟩
theorem Module.rank_le_one_iff_top_isPrincipal [Module.Free K V] :
Module.rank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by
haveI := Module.Free.of_equiv (topEquiv (R := K) (M := V)).symm
rw [← Submodule.rank_le_one_iff_isPrincipal, rank_top]
/-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis.
-/
theorem finrank_eq_one_iff [Module.Free K V] (ι : Type*) [Unique ι] :
finrank K V = 1 ↔ Nonempty (Basis ι K V) := by
constructor
· intro h
exact ⟨Module.basisUnique ι h⟩
· rintro ⟨b⟩
simpa using finrank_eq_card_basis b
/-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`.
-/
theorem finrank_eq_one_iff' [Module.Free K V] :
finrank K V = 1 ↔ ∃ v ≠ 0, ∀ w : V, ∃ c : K, c • v = w := by
rw [← rank_eq_one_iff]
exact toNat_eq_iff one_ne_zero
/-- A finite dimensional module has dimension at most 1 iff
there is some `v : V` so every vector is a multiple of `v`.
-/
theorem finrank_le_one_iff [Module.Free K V] [Module.Finite K V] :
finrank K V ≤ 1 ↔ ∃ v : V, ∀ w : V, ∃ c : K, c • v = w := by
rw [← rank_le_one_iff, ← finrank_eq_rank, Nat.cast_le_one]
theorem Submodule.finrank_le_one_iff_isPrincipal
(W : Submodule K V) [Module.Free K W] [Module.Finite K W] :
finrank K W ≤ 1 ↔ W.IsPrincipal := by
rw [← W.rank_le_one_iff_isPrincipal, ← finrank_eq_rank, Nat.cast_le_one]
theorem Module.finrank_le_one_iff_top_isPrincipal [Module.Free K V] [Module.Finite K V] :
finrank K V ≤ 1 ↔ (⊤ : Submodule K V).IsPrincipal := by
rw [← Module.rank_le_one_iff_top_isPrincipal, ← finrank_eq_rank, Nat.cast_le_one]
variable (K V) in
theorem lift_cardinalMk_eq_lift_cardinalMk_field_pow_lift_rank [Module.Free K V]
[Module.Finite K V] : lift.{u} #V = lift.{v} #K ^ lift.{u} (Module.rank K V) := by
haveI := nontrivial_of_invariantBasisNumber K
obtain ⟨s, hs⟩ := Module.Free.exists_basis (R := K) (M := V)
-- `Module.Finite.finite_basis` is in a much later file, so we copy its proof to here
| haveI : Finite s := by
obtain ⟨t, ht⟩ := ‹Module.Finite K V›
exact basis_finite_of_finite_spans t.finite_toSet ht hs
| Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean | 223 | 225 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Action.Prod
import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.Data.Finite.Sigma
import Mathlib.Data.Set.Finite.Range
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Defs
/-!
# Basic properties of group actions
This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of
actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation
of `•` belong elsewhere.
## Main definitions
* `MulAction.orbit`
* `MulAction.fixedPoints`
* `MulAction.fixedBy`
* `MulAction.stabilizer`
-/
universe u v
open Pointwise
open Function
namespace MulAction
variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] {β : Type*} [MulAction M β]
section Orbit
variable {α M}
@[to_additive]
lemma fst_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) :
x.1 ∈ MulAction.orbit M y.1 := by
rcases h with ⟨g, rfl⟩
exact mem_orbit _ _
@[to_additive]
lemma snd_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) :
x.2 ∈ MulAction.orbit M y.2 := by
rcases h with ⟨g, rfl⟩
exact mem_orbit _ _
@[to_additive]
lemma _root_.Finite.finite_mulAction_orbit [Finite M] (a : α) : Set.Finite (orbit M a) :=
Set.finite_range _
variable (M)
@[to_additive]
theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ :=
(surjective_smul M a).range_eq
end Orbit
section FixedPoints
variable {M α}
@[to_additive (attr := simp)]
theorem subsingleton_orbit_iff_mem_fixedPoints {a : α} :
(orbit M a).Subsingleton ↔ a ∈ fixedPoints M α := by
rw [mem_fixedPoints]
constructor
· exact fun h m ↦ h (mem_orbit a m) (mem_orbit_self a)
· rintro h _ ⟨m, rfl⟩ y ⟨p, rfl⟩
simp only [h]
@[to_additive mem_fixedPoints_iff_card_orbit_eq_one]
theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] :
a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by
simp only [← subsingleton_orbit_iff_mem_fixedPoints, le_antisymm_iff,
Fintype.card_le_one_iff_subsingleton, Nat.add_one_le_iff, Fintype.card_pos_iff,
Set.subsingleton_coe, iff_self_and, Set.nonempty_coe_sort, orbit_nonempty, implies_true]
@[to_additive instDecidablePredMemSetFixedByAddOfDecidableEq]
instance (m : M) [DecidableEq β] :
DecidablePred fun b : β => b ∈ MulAction.fixedBy β m := fun b ↦ by
simp only [MulAction.mem_fixedBy, Equiv.Perm.smul_def]
infer_instance
end FixedPoints
end MulAction
/-- `smul` by a `k : M` over a group is injective, if `k` is not a zero divisor.
The general theory of such `k` is elaborated by `IsSMulRegular`.
The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/
theorem smul_cancel_of_non_zero_divisor {M G : Type*} [Monoid M] [AddGroup G]
[DistribMulAction M G] (k : M) (h : ∀ x : G, k • x = 0 → x = 0) {a b : G} (h' : k • a = k • b) :
a = b := by
rw [← sub_eq_zero]
refine h _ ?_
rw [smul_sub, h', sub_self]
namespace MulAction
variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β]
@[to_additive] theorem fixedPoints_of_subsingleton [Subsingleton α] :
fixedPoints G α = .univ := by
apply Set.eq_univ_of_forall
simp only [mem_fixedPoints]
intro x hx
apply Subsingleton.elim ..
/-- If a group acts nontrivially, then the type is nontrivial -/
@[to_additive "If a subgroup acts nontrivially, then the type is nontrivial."]
theorem nontrivial_of_fixedPoints_ne_univ (h : fixedPoints G α ≠ .univ) :
Nontrivial α :=
(subsingleton_or_nontrivial α).resolve_left fun _ ↦ h fixedPoints_of_subsingleton
section Orbit
-- TODO: This proof is redoing a special case of `MulAction.IsInvariantBlock.isBlock`. Can we move
-- this lemma earlier to golf?
@[to_additive (attr := simp)]
theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a :=
(smul_orbit_subset g a).antisymm <|
calc
orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm
_ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _)
/-- The action of a group on an orbit is transitive. -/
@[to_additive "The action of an additive group on an orbit is transitive."]
instance (a : α) : IsPretransitive G (orbit G a) :=
⟨by
rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩
use h * g⁻¹
ext1
simp [mul_smul]⟩
@[to_additive]
lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α :=
Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup
@[to_additive]
lemma orbitRel_subgroupOf (H K : Subgroup G) :
orbitRel (H.subgroupOf K) α = orbitRel (H ⊓ K : Subgroup G) α := by
rw [← Subgroup.subgroupOf_map_subtype]
ext x
simp_rw [orbitRel_apply]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h with ⟨⟨gv, gp⟩, rfl⟩
simp only [Submonoid.mk_smul]
refine mem_orbit _ (⟨gv, ?_⟩ : Subgroup.map K.subtype (H.subgroupOf K))
simpa using gp
· rcases h with ⟨⟨gv, gp⟩, rfl⟩
simp only [Submonoid.mk_smul]
simp only [Subgroup.subgroupOf_map_subtype, Subgroup.mem_inf] at gp
refine mem_orbit _ (⟨⟨gv, ?_⟩, ?_⟩ : H.subgroupOf K)
· exact gp.2
· simp only [Subgroup.mem_subgroupOf]
exact gp.1
variable (G α)
/-- An action is pretransitive if and only if the quotient by `MulAction.orbitRel` is a
subsingleton. -/
@[to_additive "An additive action is pretransitive if and only if the quotient by
`AddAction.orbitRel` is a subsingleton."]
theorem pretransitive_iff_subsingleton_quotient :
IsPretransitive G α ↔ Subsingleton (orbitRel.Quotient G α) := by
refine ⟨fun _ ↦ ⟨fun a b ↦ ?_⟩, fun _ ↦ ⟨fun a b ↦ ?_⟩⟩
· refine Quot.inductionOn a (fun x ↦ ?_)
exact Quot.inductionOn b (fun y ↦ Quot.sound <| exists_smul_eq G y x)
· have h : Quotient.mk (orbitRel G α) b = ⟦a⟧ := Subsingleton.elim _ _
exact Quotient.eq''.mp h
/-- If `α` is non-empty, an action is pretransitive if and only if the quotient has exactly one
element. -/
@[to_additive "If `α` is non-empty, an additive action is pretransitive if and only if the
quotient has exactly one element."]
theorem pretransitive_iff_unique_quotient_of_nonempty [Nonempty α] :
IsPretransitive G α ↔ Nonempty (Unique <| orbitRel.Quotient G α) := by
rw [unique_iff_subsingleton_and_nonempty, pretransitive_iff_subsingleton_quotient, iff_self_and]
exact fun _ ↦ (nonempty_quotient_iff _).mpr inferInstance
variable {G α}
@[to_additive]
instance (x : orbitRel.Quotient G α) : IsPretransitive G x.orbit where
exists_smul_eq := by
induction x using Quotient.inductionOn'
rintro ⟨y, yh⟩ ⟨z, zh⟩
rw [orbitRel.Quotient.mem_orbit, Quotient.eq''] at yh zh
rcases yh with ⟨g, rfl⟩
rcases zh with ⟨h, rfl⟩
refine ⟨h * g⁻¹, ?_⟩
ext
simp [mul_smul]
variable (G) (α)
local notation "Ω" => orbitRel.Quotient G α
@[to_additive]
lemma _root_.Finite.of_finite_mulAction_orbitRel_quotient [Finite G] [Finite Ω] : Finite α := by
rw [(selfEquivSigmaOrbits' G _).finite_iff]
have : ∀ g : Ω, Finite g.orbit := by
intro g
induction g using Quotient.inductionOn'
simpa [Set.finite_coe_iff] using Finite.finite_mulAction_orbit _
exact Finite.instSigma
variable (β)
@[to_additive]
lemma orbitRel_le_fst :
orbitRel G (α × β) ≤ (orbitRel G α).comap Prod.fst :=
Setoid.le_def.2 fst_mem_orbit_of_mem_orbit
@[to_additive]
lemma orbitRel_le_snd :
orbitRel G (α × β) ≤ (orbitRel G β).comap Prod.snd :=
Setoid.le_def.2 snd_mem_orbit_of_mem_orbit
end Orbit
section Stabilizer
variable (G)
variable {G}
/-- If the stabilizer of `a` is `S`, then the stabilizer of `g • a` is `gSg⁻¹`. -/
theorem stabilizer_smul_eq_stabilizer_map_conj (g : G) (a : α) :
stabilizer G (g • a) = (stabilizer G a).map (MulAut.conj g).toMonoidHom := by
ext h
rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul,
inv_mul_cancel, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) :
stabilizer G a ≃* stabilizer G b :=
let g : G := Classical.choose h
have hg : g • b = a := Classical.choose_spec h
have this : stabilizer G a = (stabilizer G b).map (MulAut.conj g).toMonoidHom := by
rw [← hg, stabilizer_smul_eq_stabilizer_map_conj]
(MulEquiv.subgroupCongr this).trans ((MulAut.conj g).subgroupMap <| stabilizer G b).symm
end Stabilizer
end MulAction
namespace AddAction
variable {G α : Type*} [AddGroup G] [AddAction G α]
/-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/
theorem stabilizer_vadd_eq_stabilizer_map_conj (g : G) (a : α) :
stabilizer G (g +ᵥ a) = (stabilizer G a).map (AddAut.conj g).toMul.toAddMonoidHom := by
ext h
rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd,
neg_add_cancel, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv,
AddAut.conj_symm_apply]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) :
stabilizer G a ≃+ stabilizer G b :=
let g : G := Classical.choose h
have hg : g +ᵥ b = a := Classical.choose_spec h
have this : stabilizer G a = (stabilizer G b).map (AddAut.conj g).toMul.toAddMonoidHom := by
rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj]
(AddEquiv.addSubgroupCongr this).trans ((AddAut.conj g).addSubgroupMap <| stabilizer G b).symm
end AddAction
attribute [to_additive existing] MulAction.stabilizer_smul_eq_stabilizer_map_conj
attribute [to_additive existing] MulAction.stabilizerEquivStabilizerOfOrbitRel
theorem Equiv.swap_mem_stabilizer {α : Type*} [DecidableEq α] {S : Set α} {a b : α} :
Equiv.swap a b ∈ MulAction.stabilizer (Equiv.Perm α) S ↔ (a ∈ S ↔ b ∈ S) := by
rw [MulAction.mem_stabilizer_iff, Set.ext_iff, ← swap_inv]
simp_rw [Set.mem_inv_smul_set_iff, Perm.smul_def, swap_apply_def]
exact ⟨fun h ↦ by simpa [Iff.comm] using h a, by intros; split_ifs <;> simp [*]⟩
namespace MulAction
variable {G : Type*} [Group G] {α : Type*} [MulAction G α]
/-- To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions. -/
@[to_additive
"To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions."]
theorem le_stabilizer_iff_smul_le (s : Set α) (H : Subgroup G) :
H ≤ stabilizer G s ↔ ∀ g ∈ H, g • s ⊆ s := by
constructor
· intro hyp g hg
apply Eq.subset
rw [← mem_stabilizer_iff]
exact hyp hg
· intro hyp g hg
rw [mem_stabilizer_iff]
apply subset_antisymm (hyp g hg)
intro x hx
use g⁻¹ • x
constructor
· apply hyp g⁻¹ (inv_mem hg)
simp only [Set.smul_mem_smul_set_iff, hx]
· simp only [smul_inv_smul]
end MulAction
section
variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
variable {M} in
lemma Module.stabilizer_units_eq_bot_of_ne_zero {x : M} (hx : x ≠ 0) :
MulAction.stabilizer Rˣ x = ⊥ := by
rw [eq_bot_iff]
intro g (hg : g.val • x = x)
ext
rw [← sub_eq_zero, ← smul_eq_zero_iff_left hx, Units.val_one, sub_smul, hg, one_smul, sub_self]
end
| Mathlib/GroupTheory/GroupAction/Basic.lean | 547 | 551 | |
/-
Copyright (c) 2023 Iván Renison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Iván Renison
-/
import Mathlib.Combinatorics.SimpleGraph.Circulant
import Mathlib.Combinatorics.SimpleGraph.Coloring
import Mathlib.Combinatorics.SimpleGraph.Hasse
import Mathlib.Data.Fin.Parity
/-!
# Concrete colorings of common graphs
This file defines colorings for some common graphs
## Main declarations
* `SimpleGraph.pathGraph.bicoloring`: Bicoloring of a path graph.
-/
assert_not_exists Field
namespace SimpleGraph
theorem two_le_chromaticNumber_of_adj {α} {G : SimpleGraph α} {u v : α} (hadj : G.Adj u v) :
2 ≤ G.chromaticNumber := by
refine le_of_not_lt ?_
intro h
have hc : G.Colorable 1 := chromaticNumber_le_iff_colorable.mp (Order.le_of_lt_add_one h)
let c : G.Coloring (Fin 1) := hc.some
exact c.valid hadj (Subsingleton.elim (c u) (c v))
/-- Bicoloring of a path graph -/
def pathGraph.bicoloring (n : ℕ) :
Coloring (pathGraph n) Bool :=
Coloring.mk (fun u ↦ u.val % 2 = 0) <| by
intro u v
rw [pathGraph_adj]
rintro (h | h) <;> simp [← h, not_iff, Nat.succ_mod_two_eq_zero_iff]
|
/-- Embedding of `pathGraph 2` into the first two elements of `pathGraph n` for `2 ≤ n` -/
def pathGraph_two_embedding (n : ℕ) (h : 2 ≤ n) : pathGraph 2 ↪g pathGraph n where
toFun v := ⟨v, trans v.2 h⟩
inj' := by
rintro v w
rw [Fin.mk.injEq]
| Mathlib/Combinatorics/SimpleGraph/ConcreteColorings.lean | 41 | 47 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Finsupp
import Mathlib.Data.Finsupp.Order
import Mathlib.Order.Interval.Finset.Basic
/-!
# Finite intervals of finitely supported functions
This file provides the `LocallyFiniteOrder` instance for `ι →₀ α` when `α` itself is locally
finite and calculates the cardinality of its finite intervals.
## Main declarations
* `Finsupp.rangeSingleton`: Postcomposition with `Singleton.singleton` on `Finset` as a
`Finsupp`.
* `Finsupp.rangeIcc`: Postcomposition with `Finset.Icc` as a `Finsupp`.
Both these definitions use the fact that `0 = {0}` to ensure that the resulting function is finitely
supported.
-/
noncomputable section
open Finset Finsupp Function Pointwise
variable {ι α : Type*}
namespace Finsupp
section RangeSingleton
variable [Zero α] {f : ι →₀ α} {i : ι} {a : α}
/-- Pointwise `Singleton.singleton` bundled as a `Finsupp`. -/
@[simps]
def rangeSingleton (f : ι →₀ α) : ι →₀ Finset α where
toFun i := {f i}
support := f.support
mem_support_toFun i := by
rw [← not_iff_not, not_mem_support_iff, not_ne_iff]
exact singleton_injective.eq_iff.symm
theorem mem_rangeSingleton_apply_iff : a ∈ f.rangeSingleton i ↔ a = f i :=
mem_singleton
end RangeSingleton
section RangeIcc
variable [Zero α] [PartialOrder α] [LocallyFiniteOrder α] [DecidableEq ι]
variable {f g : ι →₀ α} {i : ι} {a : α}
/-- Pointwise `Finset.Icc` bundled as a `Finsupp`. -/
@[simps toFun]
def rangeIcc (f g : ι →₀ α) : ι →₀ Finset α where
toFun i := Icc (f i) (g i)
support := f.support ∪ g.support
mem_support_toFun i := by
rw [mem_union, ← not_iff_not, not_or, not_mem_support_iff, not_mem_support_iff, not_ne_iff]
exact Icc_eq_singleton_iff.symm
lemma coe_rangeIcc (f g : ι →₀ α) : rangeIcc f g i = Icc (f i) (g i) := rfl
@[simp]
theorem rangeIcc_support (f g : ι →₀ α) :
(rangeIcc f g).support = f.support ∪ g.support := rfl
theorem mem_rangeIcc_apply_iff : a ∈ f.rangeIcc g i ↔ f i ≤ a ∧ a ≤ g i := mem_Icc
end RangeIcc
section PartialOrder
variable [PartialOrder α] [Zero α] [LocallyFiniteOrder α] [DecidableEq ι] [DecidableEq α]
variable (f g : ι →₀ α)
instance instLocallyFiniteOrder : LocallyFiniteOrder (ι →₀ α) :=
LocallyFiniteOrder.ofIcc (ι →₀ α) (fun f g => (f.support ∪ g.support).finsupp <| f.rangeIcc g)
fun f g x => by
refine
(mem_finsupp_iff_of_support_subset <| Finset.subset_of_eq <| rangeIcc_support _ _).trans ?_
simp_rw [mem_rangeIcc_apply_iff]
exact forall_and
theorem Icc_eq : Icc f g = (f.support ∪ g.support).finsupp (f.rangeIcc g) := rfl
theorem card_Icc : #(Icc f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)):= by
simp_rw [Icc_eq, card_finsupp, coe_rangeIcc]
theorem card_Ico : #(Ico f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 1 := by
rw [card_Ico_eq_card_Icc_sub_one, card_Icc]
theorem card_Ioc : #(Ioc f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 1 := by
rw [card_Ioc_eq_card_Icc_sub_one, card_Icc]
theorem card_Ioo : #(Ioo f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 2 := by
rw [card_Ioo_eq_card_Icc_sub_two, card_Icc]
end PartialOrder
section Lattice
variable [Lattice α] [Zero α] [LocallyFiniteOrder α] (f g : ι →₀ α)
open scoped Classical in
theorem card_uIcc :
#(uIcc f g) = ∏ i ∈ f.support ∪ g.support, #(uIcc (f i) (g i)) := by
rw [← support_inf_union_support_sup]; exact card_Icc (_ : ι →₀ α) _
| end Lattice
| Mathlib/Data/Finsupp/Interval.lean | 113 | 114 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Basic
import Mathlib.Data.WSeq.Defs
import Mathlib.Data.WSeq.Productive
import Mathlib.Data.WSeq.Relation
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Seq/WSeq.lean | 1,741 | 1,744 | |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kim Morrison
-/
import Mathlib.Algebra.Category.Ring.Colimits
import Mathlib.Algebra.Category.Ring.Instances
import Mathlib.Algebra.Category.Ring.Limits
import Mathlib.Algebra.Ring.Subring.Basic
import Mathlib.RingTheory.Localization.AtPrime
import Mathlib.RingTheory.Spectrum.Prime.Topology
import Mathlib.Topology.Sheaves.LocalPredicate
/-!
# The structure sheaf on `PrimeSpectrum R`.
We define the structure sheaf on `TopCat.of (PrimeSpectrum R)`, for a commutative ring `R` and prove
basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the
localizations, cut out by the condition that the function must be locally equal to a ratio of
elements of `R`.
Because the condition "is equal to a fraction" passes to smaller open subsets,
the subset of functions satisfying this condition is automatically a subpresheaf.
Because the condition "is locally equal to a fraction" is local,
it is also a subsheaf.
(It may be helpful to refer back to `Mathlib/Topology/Sheaves/SheafOfFunctions.lean`,
where we show that dependent functions into any type family form a sheaf,
and also `Mathlib/Topology/Sheaves/LocalPredicate.lean`, where we characterise the predicates
which pick out sub-presheaves and sub-sheaves of these sheaves.)
We also set up the ring structure, obtaining
`structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R)`.
We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`.
First, `StructureSheaf.stalkIso` gives an isomorphism between the stalk of the structure sheaf
at a point `p` and the localization of `R` at the prime ideal `p`. Second,
`StructureSheaf.basicOpenIso` gives an isomorphism between the structure sheaf on `basicOpen f`
and the localization of `R` at the submonoid of powers of `f`.
## References
* [Robin Hartshorne, *Algebraic Geometry*][Har77]
-/
universe u
noncomputable section
variable (R : Type u) [CommRing R]
open TopCat
open TopologicalSpace
open CategoryTheory
open Opposite
namespace AlgebraicGeometry
/-- The prime spectrum, just as a topological space.
-/
def PrimeSpectrum.Top : TopCat :=
TopCat.of (PrimeSpectrum R)
namespace StructureSheaf
/-- The type family over `PrimeSpectrum R` consisting of the localization over each point.
-/
def Localizations (P : PrimeSpectrum.Top R) : Type u :=
Localization.AtPrime P.asIdeal
instance commRingLocalizations (P : PrimeSpectrum.Top R) : CommRing <| Localizations R P :=
inferInstanceAs <| CommRing <| Localization.AtPrime P.asIdeal
instance localRingLocalizations (P : PrimeSpectrum.Top R) : IsLocalRing <| Localizations R P :=
inferInstanceAs <| IsLocalRing <| Localization.AtPrime P.asIdeal
instance (P : PrimeSpectrum.Top R) : Inhabited (Localizations R P) :=
⟨1⟩
instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : Algebra R (Localizations R x) :=
inferInstanceAs <| Algebra R (Localization.AtPrime x.1.asIdeal)
instance (U : Opens (PrimeSpectrum.Top R)) (x : U) :
IsLocalization.AtPrime (Localizations R x) (x : PrimeSpectrum.Top R).asIdeal :=
Localization.isLocalization
variable {R}
/-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction
`r / s` in each of the stalks (which are localizations at various prime ideals).
-/
def IsFraction {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : Prop :=
∃ r s : R, ∀ x : U, ¬s ∈ x.1.asIdeal ∧ f x * algebraMap _ _ s = algebraMap _ _ r
theorem IsFraction.eq_mk' {U : Opens (PrimeSpectrum.Top R)} {f : ∀ x : U, Localizations R x}
(hf : IsFraction f) :
∃ r s : R,
∀ x : U,
∃ hs : s ∉ x.1.asIdeal,
f x =
IsLocalization.mk' (Localization.AtPrime _) r
(⟨s, hs⟩ : (x : PrimeSpectrum.Top R).asIdeal.primeCompl) := by
rcases hf with ⟨r, s, h⟩
refine ⟨r, s, fun x => ⟨(h x).1, (IsLocalization.mk'_eq_iff_eq_mul.mpr ?_).symm⟩⟩
exact (h x).2.symm
variable (R)
/-- The predicate `IsFraction` is "prelocal",
in the sense that if it holds on `U` it holds on any open subset `V` of `U`.
-/
def isFractionPrelocal : PrelocalPredicate (Localizations R) where
pred {_} f := IsFraction f
res := by rintro V U i f ⟨r, s, w⟩; exact ⟨r, s, fun x => w (i x)⟩
/-- We will define the structure sheaf as
the subsheaf of all dependent functions in `Π x : U, Localizations R x`
consisting of those functions which can locally be expressed as a ratio of
(the images in the localization of) elements of `R`.
Quoting Hartshorne:
For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions
$s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$,
and such that $s$ is locally a quotient of elements of $A$:
to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$,
contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$,
and $s(𝔮) = a/f$ in $A_𝔮$.
Now Hartshorne had the disadvantage of not knowing about dependent functions,
so we replace his circumlocution about functions into a disjoint union with
`Π x : U, Localizations x`.
-/
def isLocallyFraction : LocalPredicate (Localizations R) :=
(isFractionPrelocal R).sheafify
@[simp]
theorem isLocallyFraction_pred {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) :
(isLocallyFraction R).pred f =
∀ x : U,
∃ (V : _) (_ : x.1 ∈ V) (i : V ⟶ U),
∃ r s : R,
∀ y : V, ¬s ∈ y.1.asIdeal ∧ f (i y : U) * algebraMap _ _ s = algebraMap _ _ r :=
rfl
/-- The functions satisfying `isLocallyFraction` form a subring.
-/
def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) :
Subring (∀ x : U.unop, Localizations R x) where
carrier := { f | (isLocallyFraction R).pred f }
zero_mem' := by
refine fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨?_, ?_⟩⟩
· rw [← Ideal.ne_top_iff_one]; exact y.1.isPrime.1
· simp
one_mem' := by
refine fun x => ⟨unop U, x.2, 𝟙 _, 1, 1, fun y => ⟨?_, ?_⟩⟩
· rw [← Ideal.ne_top_iff_one]; exact y.1.isPrime.1
· simp
add_mem' := by
intro a b ha hb x
rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩
rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩
refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * sb + rb * sa, sa * sb, ?_⟩
intro ⟨y, hy⟩
rcases wa (Opens.infLELeft _ _ ⟨y, hy⟩) with ⟨nma, wa⟩
rcases wb (Opens.infLERight _ _ ⟨y, hy⟩) with ⟨nmb, wb⟩
fconstructor
· intro H; cases y.isPrime.mem_or_mem H <;> contradiction
· simp only [Opens.apply_mk, Pi.add_apply, RingHom.map_mul, add_mul, RingHom.map_add] at wa wb ⊢
rw [← wa, ← wb]
simp only [mul_assoc]
congr 2
rw [mul_comm]
neg_mem' := by
intro a ha x
rcases ha x with ⟨V, m, i, r, s, w⟩
refine ⟨V, m, i, -r, s, ?_⟩
intro y
rcases w y with ⟨nm, w⟩
fconstructor
· exact nm
· simp only [RingHom.map_neg, Pi.neg_apply]
rw [← w]
simp only [neg_mul]
mul_mem' := by
intro a b ha hb x
rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩
rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩
refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * rb, sa * sb, ?_⟩
intro ⟨y, hy⟩
rcases wa (Opens.infLELeft _ _ ⟨y, hy⟩) with ⟨nma, wa⟩
rcases wb (Opens.infLERight _ _ ⟨y, hy⟩) with ⟨nmb, wb⟩
fconstructor
· intro H; cases y.isPrime.mem_or_mem H <;> contradiction
· simp only [Opens.apply_mk, Pi.mul_apply, RingHom.map_mul] at wa wb ⊢
rw [← wa, ← wb]
simp only [mul_left_comm, mul_assoc, mul_comm]
end StructureSheaf
open StructureSheaf
/-- The structure sheaf (valued in `Type`, not yet `CommRingCat`) is the subsheaf consisting of
functions satisfying `isLocallyFraction`.
-/
def structureSheafInType : Sheaf (Type u) (PrimeSpectrum.Top R) :=
subsheafToTypes (isLocallyFraction R)
instance commRingStructureSheafInTypeObj (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) :
CommRing ((structureSheafInType R).1.obj U) :=
(sectionsSubring R U).toCommRing
open PrimeSpectrum
/-- The structure presheaf, valued in `CommRingCat`, constructed by dressing up the `Type` valued
structure presheaf.
-/
@[simps obj_carrier]
def structurePresheafInCommRing : Presheaf CommRingCat (PrimeSpectrum.Top R) where
obj U := CommRingCat.of ((structureSheafInType R).1.obj U)
map {_ _} i := CommRingCat.ofHom
{ toFun := (structureSheafInType R).1.map i
map_zero' := rfl
map_add' := fun _ _ => rfl
map_one' := rfl
map_mul' := fun _ _ => rfl }
/-- Some glue, verifying that the structure presheaf valued in `CommRingCat` agrees
with the `Type` valued structure presheaf.
-/
def structurePresheafCompForget :
structurePresheafInCommRing R ⋙ forget CommRingCat ≅ (structureSheafInType R).1 :=
NatIso.ofComponents fun _ => Iso.refl _
open TopCat.Presheaf
/-- The structure sheaf on $Spec R$, valued in `CommRingCat`.
This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later.
-/
def Spec.structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R) :=
⟨structurePresheafInCommRing R,
(-- We check the sheaf condition under `forget CommRingCat`.
isSheaf_iff_isSheaf_comp
_ _).mpr
(isSheaf_of_iso (structurePresheafCompForget R).symm (structureSheafInType R).cond)⟩
open Spec (structureSheaf)
namespace StructureSheaf
@[simp]
theorem res_apply (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U)
(s : (structureSheaf R).1.obj (op U)) (x : V) :
((structureSheaf R).1.map i.op s).1 x = (s.1 (i x) :) :=
rfl
/-
Notation in this comment
X = Spec R
OX = structure sheaf
In the following we construct an isomorphism between OX_p and R_p given any point p corresponding
to a prime ideal in R.
We do this via 8 steps:
1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api]
2. def toOpen (U) : R ⟶ OX(U)
3. [2] def toStalk (p : Spec R) : R ⟶ OX_p
4. [2] def toBasicOpen (f : R) : R_f ⟶ OX(D_f)
5. [3] def localizationToStalk (p : Spec R) : R_p ⟶ OX_p
6. def openToLocalization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p
7. [6] def stalkToFiberRingHom (p : Spec R) : OX_p ⟶ R_p
8. [5,7] def stalkIso (p : Spec R) : OX_p ≅ R_p
In the square brackets we list the dependencies of a construction on the previous steps.
-/
/-- The section of `structureSheaf R` on an open `U` sending each `x ∈ U` to the element
`f/g` in the localization of `R` at `x`. -/
def const (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) :
(structureSheaf R).1.obj (op U) :=
⟨fun x => IsLocalization.mk' _ f ⟨g, hu x x.2⟩, fun x =>
⟨U, x.2, 𝟙 _, f, g, fun y => ⟨hu y y.2, IsLocalization.mk'_spec _ _ _⟩⟩⟩
@[simp]
theorem const_apply (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) :
(const R f g U hu).1 x =
IsLocalization.mk' (Localization.AtPrime x.1.asIdeal) f ⟨g, hu x x.2⟩ :=
rfl
theorem const_apply' (f g : R) (U : Opens (PrimeSpectrum.Top R))
(hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U)
(hx : g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) :
(const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hx⟩ :=
rfl
theorem exists_const (U) (s : (structureSheaf R).1.obj (op U)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) :
∃ (V : Opens (PrimeSpectrum.Top R)) (_ : x ∈ V) (i : V ⟶ U) (f g : R) (hg : _),
const R f g V hg = (structureSheaf R).1.map i.op s :=
let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩
⟨V, hxV, iVU, f, g, fun y hyV => (hfg ⟨y, hyV⟩).1,
Subtype.eq <| funext fun y => IsLocalization.mk'_eq_iff_eq_mul.2 <| Eq.symm <| (hfg y).2⟩
@[simp]
theorem res_const (f g : R) (U hu V hv i) :
(structureSheaf R).1.map i (const R f g U hu) = const R f g V hv :=
rfl
theorem res_const' (f g : R) (V hv) :
(structureSheaf R).1.map (homOfLE hv).op (const R f g (PrimeSpectrum.basicOpen g) fun _ => id) =
const R f g V hv :=
rfl
theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 :=
Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by
rw [RingHom.map_zero]
exact (mul_eq_zero_of_left rfl ((algebraMap R (Localizations R x)) _)).symm
theorem const_self (f : R) (U hu) : const R f f U hu = 1 :=
Subtype.eq <| funext fun _ => IsLocalization.mk'_self _ _
theorem const_one (U) : (const R 1 1 U fun _ _ => Submonoid.one_mem _) = 1 :=
const_self R 1 U _
theorem const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) :
const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ =
const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U fun x hx =>
Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) :=
Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_add _ _
⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩
theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) :
const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ =
const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) :=
Subtype.eq <|
funext fun x =>
Eq.symm <| IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩
theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) :
const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ :=
Subtype.eq <|
funext fun x =>
IsLocalization.mk'_eq_of_eq (by rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk])
theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) :
const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg; rfl
theorem const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by
rw [const_mul, const_congr R rfl (mul_comm g f), const_self]
theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) :
const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by
rw [const_mul, const_ext]; rw [mul_assoc]
theorem const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) :
const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by
rw [mul_comm, const_mul_cancel]
/-- The canonical ring homomorphism interpreting an element of `R` as
a section of the structure sheaf. -/
def toOpen (U : Opens (PrimeSpectrum.Top R)) :
CommRingCat.of R ⟶ (structureSheaf R).1.obj (op U) := CommRingCat.ofHom
{ toFun f :=
⟨fun _ => algebraMap R _ f, fun x =>
⟨U, x.2, 𝟙 _, f, 1, fun y =>
⟨(Ideal.ne_top_iff_one _).1 y.1.2.1, by simp [RingHom.map_one, mul_one]⟩⟩⟩
map_one' := Subtype.eq <| funext fun _ => RingHom.map_one _
map_mul' _ _ := Subtype.eq <| funext fun _ => RingHom.map_mul _ _ _
map_zero' := Subtype.eq <| funext fun _ => RingHom.map_zero _
map_add' _ _ := Subtype.eq <| funext fun _ => RingHom.map_add _ _ _ }
@[simp]
theorem toOpen_res (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) :
toOpen R U ≫ (structureSheaf R).1.map i.op = toOpen R V :=
rfl
@[simp]
theorem toOpen_apply (U : Opens (PrimeSpectrum.Top R)) (f : R) (x : U) :
(toOpen R U f).1 x = algebraMap _ _ f :=
rfl
theorem toOpen_eq_const (U : Opens (PrimeSpectrum.Top R)) (f : R) :
toOpen R U f = const R f 1 U fun x _ => (Ideal.ne_top_iff_one _).1 x.2.1 :=
Subtype.eq <| funext fun _ => Eq.symm <| IsLocalization.mk'_one _ f
/-- The canonical ring homomorphism interpreting an element of `R` as an element of
the stalk of `structureSheaf R` at `x`. -/
def toStalk (x : PrimeSpectrum.Top R) : CommRingCat.of R ⟶ (structureSheaf R).presheaf.stalk x :=
(toOpen R ⊤ ≫ (structureSheaf R).presheaf.germ _ x (by trivial))
@[simp]
theorem toOpen_germ (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) :
toOpen R U ≫ (structureSheaf R).presheaf.germ U x hx = toStalk R x := by
rw [← toOpen_res R ⊤ U (homOfLE le_top : U ⟶ ⊤), Category.assoc, Presheaf.germ_res]; rfl
@[simp]
theorem germ_toOpen
(U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) (f : R) :
(structureSheaf R).presheaf.germ U x hx (toOpen R U f) = toStalk R x f := by
rw [← toOpen_germ]; rfl
theorem toOpen_Γgerm_apply (x : PrimeSpectrum.Top R) (f : R) :
(structureSheaf R).presheaf.Γgerm x (toOpen R ⊤ f) = toStalk R x f :=
rfl
theorem isUnit_to_basicOpen_self (f : R) : IsUnit (toOpen R (PrimeSpectrum.basicOpen f) f) :=
isUnit_of_mul_eq_one _ (const R 1 f (PrimeSpectrum.basicOpen f) fun _ => id) <| by
rw [toOpen_eq_const, const_mul_rev]
theorem isUnit_toStalk (x : PrimeSpectrum.Top R) (f : x.asIdeal.primeCompl) :
IsUnit (toStalk R x (f : R)) := by
rw [← germ_toOpen R (PrimeSpectrum.basicOpen (f : R)) x f.2 (f : R)]
exact RingHom.isUnit_map _ (isUnit_to_basicOpen_self R f)
/-- The canonical ring homomorphism from the localization of `R` at `p` to the stalk
of the structure sheaf at the point `p`. -/
def localizationToStalk (x : PrimeSpectrum.Top R) :
CommRingCat.of (Localization.AtPrime x.asIdeal) ⟶ (structureSheaf R).presheaf.stalk x :=
CommRingCat.ofHom <|
show Localization.AtPrime x.asIdeal →+* _ from IsLocalization.lift (isUnit_toStalk R x)
@[simp]
theorem localizationToStalk_of (x : PrimeSpectrum.Top R) (f : R) :
localizationToStalk R x (algebraMap _ (Localization _) f) = toStalk R x f :=
IsLocalization.lift_eq (S := Localization x.asIdeal.primeCompl) _ f
@[simp]
theorem localizationToStalk_mk' (x : PrimeSpectrum.Top R) (f : R) (s : x.asIdeal.primeCompl) :
localizationToStalk R x (IsLocalization.mk' (Localization.AtPrime x.asIdeal) f s) =
(structureSheaf R).presheaf.germ (PrimeSpectrum.basicOpen (s : R)) x s.2
(const R f s (PrimeSpectrum.basicOpen s) fun _ => id) :=
(IsLocalization.lift_mk'_spec (S := Localization.AtPrime x.asIdeal) _ _ _ _).2 <| by
rw [← germ_toOpen R (PrimeSpectrum.basicOpen s) x s.2,
← germ_toOpen R (PrimeSpectrum.basicOpen s) x s.2, ← RingHom.map_mul, toOpen_eq_const,
toOpen_eq_const, const_mul_cancel']
/-- The ring homomorphism that takes a section of the structure sheaf of `R` on the open set `U`,
implemented as a subtype of dependent functions to localizations at prime ideals, and evaluates
the section on the point corresponding to a given prime ideal. -/
def openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) :
(structureSheaf R).1.obj (op U) ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) :=
CommRingCat.ofHom
{ toFun s := (s.1 ⟨x, hx⟩ :)
map_one' := rfl
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl }
@[simp]
theorem coe_openToLocalization (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) :
(openToLocalization R U x hx :
(structureSheaf R).1.obj (op U) → Localization.AtPrime x.asIdeal) =
fun s => s.1 ⟨x, hx⟩ :=
rfl
theorem openToLocalization_apply (U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R)
(hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) :
openToLocalization R U x hx s = s.1 ⟨x, hx⟩ :=
rfl
/-- The ring homomorphism from the stalk of the structure sheaf of `R` at a point corresponding to
a prime ideal `p` to the localization of `R` at `p`,
formed by gluing the `openToLocalization` maps. -/
def stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
(structureSheaf R).presheaf.stalk x ⟶ CommRingCat.of (Localization.AtPrime x.asIdeal) :=
Limits.colimit.desc ((OpenNhds.inclusion x).op ⋙ (structureSheaf R).1)
{ pt := _
ι := { app := fun U =>
openToLocalization R ((OpenNhds.inclusion _).obj (unop U)) x (unop U).2 } }
@[simp]
theorem germ_comp_stalkToFiberRingHom
(U : Opens (PrimeSpectrum.Top R)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) :
(structureSheaf R).presheaf.germ U x hx ≫ stalkToFiberRingHom R x =
openToLocalization R U x hx :=
Limits.colimit.ι_desc _ _
@[simp]
theorem stalkToFiberRingHom_germ (U : Opens (PrimeSpectrum.Top R))
(x : PrimeSpectrum.Top R) (hx : x ∈ U) (s : (structureSheaf R).1.obj (op U)) :
stalkToFiberRingHom R x ((structureSheaf R).presheaf.germ U x hx s) = s.1 ⟨x, hx⟩ :=
RingHom.ext_iff.mp (CommRingCat.hom_ext_iff.mp (germ_comp_stalkToFiberRingHom R U x hx)) s
@[simp]
theorem toStalk_comp_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
toStalk R x ≫ stalkToFiberRingHom R x = CommRingCat.ofHom (algebraMap _ _) := by
rw [toStalk, Category.assoc, germ_comp_stalkToFiberRingHom]; rfl
@[simp]
theorem stalkToFiberRingHom_toStalk (x : PrimeSpectrum.Top R) (f : R) :
stalkToFiberRingHom R x (toStalk R x f) = algebraMap _ _ f :=
RingHom.ext_iff.1 (CommRingCat.hom_ext_iff.mp (toStalk_comp_stalkToFiberRingHom R x)) _
/-- The ring isomorphism between the stalk of the structure sheaf of `R` at a point `p`
corresponding to a prime ideal in `R` and the localization of `R` at `p`. -/
@[simps]
def stalkIso (x : PrimeSpectrum.Top R) :
(structureSheaf R).presheaf.stalk x ≅ CommRingCat.of (Localization.AtPrime x.asIdeal) where
hom := stalkToFiberRingHom R x
inv := localizationToStalk R x
hom_inv_id := by
apply stalk_hom_ext
intro U hxU
ext s
dsimp only [CommRingCat.hom_comp, RingHom.coe_comp, Function.comp_apply, CommRingCat.hom_id,
RingHom.coe_id, id_eq]
rw [stalkToFiberRingHom_germ]
obtain ⟨V, hxV, iVU, f, g, (hg : V ≤ PrimeSpectrum.basicOpen _), hs⟩ :=
exists_const _ _ s x hxU
have := res_apply R U V iVU s ⟨x, hxV⟩
dsimp only [isLocallyFraction_pred, Opens.apply_mk] at this
rw [← this, ← hs, const_apply, localizationToStalk_mk']
refine (structureSheaf R).presheaf.germ_ext V hxV (homOfLE hg) iVU ?_
rw [← hs, res_const']
inv_hom_id := CommRingCat.hom_ext <|
@IsLocalization.ringHom_ext R _ x.asIdeal.primeCompl (Localization.AtPrime x.asIdeal) _ _
(Localization.AtPrime x.asIdeal) _ _
(RingHom.comp (stalkToFiberRingHom R x).hom (localizationToStalk R x).hom)
(RingHom.id (Localization.AtPrime _)) <| by
ext f
rw [RingHom.comp_apply, RingHom.comp_apply, localizationToStalk_of,
stalkToFiberRingHom_toStalk, RingHom.comp_apply, RingHom.id_apply]
instance (x : PrimeSpectrum R) : IsIso (stalkToFiberRingHom R x) :=
(stalkIso R x).isIso_hom
instance (x : PrimeSpectrum R) : IsLocalHom (stalkToFiberRingHom R x).hom :=
isLocalHom_of_isIso _
instance (x : PrimeSpectrum R) : IsIso (localizationToStalk R x) :=
(stalkIso R x).isIso_inv
instance (x : PrimeSpectrum R) : IsLocalHom (localizationToStalk R x).hom :=
isLocalHom_of_isIso _
@[simp, reassoc]
theorem stalkToFiberRingHom_localizationToStalk (x : PrimeSpectrum.Top R) :
stalkToFiberRingHom R x ≫ localizationToStalk R x = 𝟙 _ :=
(stalkIso R x).hom_inv_id
@[simp, reassoc]
theorem localizationToStalk_stalkToFiberRingHom (x : PrimeSpectrum.Top R) :
localizationToStalk R x ≫ stalkToFiberRingHom R x = 𝟙 _ :=
(stalkIso R x).inv_hom_id
/-- The canonical ring homomorphism interpreting `s ∈ R_f` as a section of the structure sheaf
on the basic open defined by `f ∈ R`. -/
def toBasicOpen (f : R) :
Localization.Away f →+* (structureSheaf R).1.obj (op <| PrimeSpectrum.basicOpen f) :=
IsLocalization.Away.lift f (isUnit_to_basicOpen_self R f)
@[simp]
theorem toBasicOpen_mk' (s f : R) (g : Submonoid.powers s) :
toBasicOpen R s (IsLocalization.mk' (Localization.Away s) f g) =
const R f g (PrimeSpectrum.basicOpen s) fun _ hx => Submonoid.powers_le.2 hx g.2 :=
(IsLocalization.lift_mk'_spec _ _ _ _).2 <| by
rw [toOpen_eq_const, toOpen_eq_const, const_mul_cancel']
@[simp]
theorem localization_toBasicOpen (f : R) :
RingHom.comp (toBasicOpen R f) (algebraMap R (Localization.Away f)) =
(toOpen R (PrimeSpectrum.basicOpen f)).hom :=
RingHom.ext fun g => by
rw [toBasicOpen, IsLocalization.Away.lift, RingHom.comp_apply, IsLocalization.lift_eq]
@[simp]
theorem toBasicOpen_to_map (s f : R) :
toBasicOpen R s (algebraMap R (Localization.Away s) f) =
const R f 1 (PrimeSpectrum.basicOpen s) fun _ _ => Submonoid.one_mem _ :=
(IsLocalization.lift_eq _ _).trans <| toOpen_eq_const _ _ _
-- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2.
theorem toBasicOpen_injective (f : R) : Function.Injective (toBasicOpen R f) := by
intro s t h_eq
obtain ⟨a, ⟨b, hb⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers f) s
obtain ⟨c, ⟨d, hd⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers f) t
simp only [toBasicOpen_mk'] at h_eq
rw [IsLocalization.eq]
-- We know that the fractions `a/b` and `c/d` are equal as sections of the structure sheaf on
-- `basicOpen f`. We need to show that they agree as elements in the localization of `R` at `f`.
-- This amounts showing that `r * (d * a) = r * (b * c)`, for some power `r = f ^ n` of `f`.
-- We define `I` as the ideal of *all* elements `r` satisfying the above equation.
let I : Ideal R :=
{ carrier := { r : R | r * (d * a) = r * (b * c) }
zero_mem' := by simp only [Set.mem_setOf_eq, zero_mul]
add_mem' := fun {r₁ r₂} hr₁ hr₂ => by dsimp at hr₁ hr₂ ⊢; simp only [add_mul, hr₁, hr₂]
smul_mem' := fun {r₁ r₂} hr₂ => by dsimp at hr₂ ⊢; simp only [mul_assoc, hr₂] }
-- Our claim now reduces to showing that `f` is contained in the radical of `I`
suffices f ∈ I.radical by
obtain ⟨n, hn⟩ := this
exact ⟨⟨f ^ n, n, rfl⟩, hn⟩
rw [← PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, PrimeSpectrum.mem_vanishingIdeal]
intro p hfp
contrapose hfp
rw [PrimeSpectrum.mem_zeroLocus, Set.not_subset]
have := congr_fun (congr_arg Subtype.val h_eq) ⟨p, hfp⟩
dsimp at this
rw [IsLocalization.eq (S := Localization.AtPrime p.asIdeal)] at this
obtain ⟨r, hr⟩ := this
exact ⟨r.1, hr, r.2⟩
/-
Auxiliary lemma for surjectivity of `toBasicOpen`.
Every section can locally be represented on basic opens `basicOpen g` as a fraction `f/g`
-/
theorem locally_const_basicOpen (U : Opens (PrimeSpectrum.Top R))
(s : (structureSheaf R).1.obj (op U)) (x : U) :
∃ (f g : R) (i : PrimeSpectrum.basicOpen g ⟶ U), x.1 ∈ PrimeSpectrum.basicOpen g ∧
(const R f g (PrimeSpectrum.basicOpen g) fun _ hy => hy) =
(structureSheaf R).1.map i.op s := by
-- First, any section `s` can be represented as a fraction `f/g` on some open neighborhood of `x`
-- and we may pass to a `basicOpen h`, since these form a basis
obtain ⟨V, hxV : x.1 ∈ V.1, iVU, f, g, hVDg : V ≤ PrimeSpectrum.basicOpen g, s_eq⟩ :=
exists_const R U s x.1 x.2
obtain ⟨_, ⟨h, rfl⟩, hxDh, hDhV : PrimeSpectrum.basicOpen h ≤ V⟩ :=
PrimeSpectrum.isTopologicalBasis_basic_opens.exists_subset_of_mem_open hxV V.2
-- The problem is of course, that `g` and `h` don't need to coincide.
-- But, since `basicOpen h ≤ basicOpen g`, some power of `h` must be a multiple of `g`
obtain ⟨n, hn⟩ := (PrimeSpectrum.basicOpen_le_basicOpen_iff h g).mp (Set.Subset.trans hDhV hVDg)
-- Actually, we will need a *nonzero* power of `h`.
-- This is because we will need the equality `basicOpen (h ^ n) = basicOpen h`, which only
-- holds for a nonzero power `n`. We therefore artificially increase `n` by one.
replace hn := Ideal.mul_mem_right h (Ideal.span {g}) hn
rw [← pow_succ, Ideal.mem_span_singleton'] at hn
obtain ⟨c, hc⟩ := hn
have basic_opens_eq := PrimeSpectrum.basicOpen_pow h (n + 1) (by omega)
have i_basic_open := eqToHom basic_opens_eq ≫ homOfLE hDhV
-- We claim that `(f * c) / h ^ (n+1)` is our desired representation
use f * c, h ^ (n + 1), i_basic_open ≫ iVU, (basic_opens_eq.symm.le :) hxDh
rw [op_comp, Functor.map_comp, ConcreteCategory.comp_apply, ← s_eq, res_const]
-- Note that the last rewrite here generated an additional goal, which was a parameter
-- of `res_const`. We prove this goal first
swap
· intro y hy
rw [basic_opens_eq] at hy
exact (Set.Subset.trans hDhV hVDg :) hy
-- All that is left is a simple calculation
apply const_ext
rw [mul_assoc f c g, hc]
/-
Auxiliary lemma for surjectivity of `toBasicOpen`.
A local representation of a section `s` as fractions `a i / h i` on finitely many basic opens
`basicOpen (h i)` can be "normalized" in such a way that `a i * h j = h i * a j` for all `i, j`
-/
theorem normalize_finite_fraction_representation (U : Opens (PrimeSpectrum.Top R))
(s : (structureSheaf R).1.obj (op U)) {ι : Type*} (t : Finset ι) (a h : ι → R)
(iDh : ∀ i : ι, PrimeSpectrum.basicOpen (h i) ⟶ U)
(h_cover : U ≤ ⨆ i ∈ t, PrimeSpectrum.basicOpen (h i))
(hs :
∀ i : ι,
(const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) fun _ hy => hy) =
(structureSheaf R).1.map (iDh i).op s) :
∃ (a' h' : ι → R) (iDh' : ∀ i : ι, PrimeSpectrum.basicOpen (h' i) ⟶ U),
(U ≤ ⨆ i ∈ t, PrimeSpectrum.basicOpen (h' i)) ∧
(∀ (i) (_ : i ∈ t) (j) (_ : j ∈ t), a' i * h' j = h' i * a' j) ∧
∀ i ∈ t,
(structureSheaf R).1.map (iDh' i).op s =
const R (a' i) (h' i) (PrimeSpectrum.basicOpen (h' i)) fun _ hy => hy := by
-- First we show that the fractions `(a i * h j) / (h i * h j)` and `(h i * a j) / (h i * h j)`
-- coincide in the localization of `R` at `h i * h j`
have fractions_eq :
∀ i j : ι,
IsLocalization.mk' (Localization.Away (h i * h j))
(a i * h j) ⟨h i * h j, Submonoid.mem_powers _⟩ =
IsLocalization.mk' _ (h i * a j) ⟨h i * h j, Submonoid.mem_powers _⟩ := by
intro i j
let D := PrimeSpectrum.basicOpen (h i * h j)
let iDi : D ⟶ PrimeSpectrum.basicOpen (h i) := homOfLE (PrimeSpectrum.basicOpen_mul_le_left _ _)
let iDj : D ⟶ PrimeSpectrum.basicOpen (h j) :=
homOfLE (PrimeSpectrum.basicOpen_mul_le_right _ _)
-- Crucially, we need injectivity of `toBasicOpen`
apply toBasicOpen_injective R (h i * h j)
rw [toBasicOpen_mk', toBasicOpen_mk']
simp only []
-- Here, both sides of the equation are equal to a restriction of `s`
trans
on_goal 1 =>
convert congr_arg ((structureSheaf R).1.map iDj.op) (hs j).symm using 1
convert congr_arg ((structureSheaf R).1.map iDi.op) (hs i) using 1
all_goals rw [res_const]; apply const_ext; ring
-- The remaining two goals were generated during the rewrite of `res_const`
-- These can be solved immediately
exacts [PrimeSpectrum.basicOpen_mul_le_left _ _, PrimeSpectrum.basicOpen_mul_le_right _ _]
-- From the equality in the localization, we obtain for each `(i,j)` some power `(h i * h j) ^ n`
-- which equalizes `a i * h j` and `h i * a j`
have exists_power :
∀ i j : ι, ∃ n : ℕ, a i * h j * (h i * h j) ^ n = h i * a j * (h i * h j) ^ n := by
intro i j
obtain ⟨⟨c, n, rfl⟩, hc⟩ := IsLocalization.eq.mp (fractions_eq i j)
use n + 1
rw [pow_succ]
dsimp at hc
convert hc using 1 <;> ring
let n := fun p : ι × ι => (exists_power p.1 p.2).choose
have n_spec := fun p : ι × ι => (exists_power p.fst p.snd).choose_spec
-- We need one power `(h i * h j) ^ N` that works for *all* pairs `(i,j)`
-- Since there are only finitely many indices involved, we can pick the supremum.
let N := (t ×ˢ t).sup n
have basic_opens_eq : ∀ i : ι, PrimeSpectrum.basicOpen (h i ^ (N + 1)) =
PrimeSpectrum.basicOpen (h i) := fun i => PrimeSpectrum.basicOpen_pow _ _ (by omega)
-- Expanding the fraction `a i / h i` by the power `(h i) ^ n` gives the desired normalization
refine
⟨fun i => a i * h i ^ N, fun i => h i ^ (N + 1), fun i => eqToHom (basic_opens_eq i) ≫ iDh i,
?_, ?_, ?_⟩
· simpa only [basic_opens_eq] using h_cover
· intro i hi j hj
-- Here we need to show that our new fractions `a i / h i` satisfy the normalization condition
-- Of course, the power `N` we used to expand the fractions might be bigger than the power
-- `n (i, j)` which was originally chosen. We denote their difference by `k`
have n_le_N : n (i, j) ≤ N := Finset.le_sup (Finset.mem_product.mpr ⟨hi, hj⟩)
obtain ⟨k, hk⟩ := Nat.le.dest n_le_N
simp only [← hk, pow_add, pow_one]
-- To accommodate for the difference `k`, we multiply both sides of the equation `n_spec (i, j)`
-- by `(h i * h j) ^ k`
convert congr_arg (fun z => z * (h i * h j) ^ k) (n_spec (i, j)) using 1 <;>
· simp only [n, mul_pow]; ring
-- Lastly, we need to show that the new fractions still represent our original `s`
intro i _
rw [op_comp, Functor.map_comp, ConcreteCategory.comp_apply, ← hs, res_const]
-- additional goal spit out by `res_const`
swap
· exact (basic_opens_eq i).le
apply const_ext
dsimp
rw [pow_succ]
ring
-- Porting note: in the following proof there are two places where `⋃ i, ⋃ (hx : i ∈ _), ... `
-- though `hx` is not used in `...` part, it is still required to maintain the structure of
-- the original proof in mathlib3.
set_option linter.unusedVariables false in
-- The proof here follows the argument in Hartshorne's Algebraic Geometry, Proposition II.2.2.
theorem toBasicOpen_surjective (f : R) : Function.Surjective (toBasicOpen R f) := by
intro s
-- In this proof, `basicOpen f` will play two distinct roles: Firstly, it is an open set in the
-- prime spectrum. Secondly, it is used as an indexing type for various families of objects
-- (open sets, ring elements, ...). In order to make the distinction clear, we introduce a type
-- alias `ι` that is used whenever we want think of it as an indexing type.
let ι : Type u := PrimeSpectrum.basicOpen f
-- First, we pick some cover of basic opens, on which we can represent `s` as a fraction
choose a' h' iDh' hxDh' s_eq' using locally_const_basicOpen R (PrimeSpectrum.basicOpen f) s
-- Since basic opens are compact, we can pass to a finite subcover
obtain ⟨t, ht_cover'⟩ :=
(PrimeSpectrum.isCompact_basicOpen f).elim_finite_subcover
(fun i : ι => PrimeSpectrum.basicOpen (h' i)) (fun i => PrimeSpectrum.isOpen_basicOpen)
-- Here, we need to show that our basic opens actually form a cover of `basicOpen f`
fun x hx => by rw [Set.mem_iUnion]; exact ⟨⟨x, hx⟩, hxDh' ⟨x, hx⟩⟩
simp only [← Opens.coe_iSup, SetLike.coe_subset_coe] at ht_cover'
-- We use the normalization lemma from above to obtain the relation `a i * h j = h i * a j`
obtain ⟨a, h, iDh, ht_cover, ah_ha, s_eq⟩ :=
normalize_finite_fraction_representation R (PrimeSpectrum.basicOpen f)
s t a' h' iDh' ht_cover' s_eq'
clear s_eq' iDh' hxDh' ht_cover' a' h'
simp only [← SetLike.coe_subset_coe, Opens.coe_iSup] at ht_cover
replace ht_cover : (PrimeSpectrum.basicOpen f : Set <| PrimeSpectrum R) ⊆
⋃ (i : ι) (x : i ∈ t), (PrimeSpectrum.basicOpen (h i) : Set _) := ht_cover
-- Next we show that some power of `f` is a linear combination of the `h i`
obtain ⟨n, hn⟩ : f ∈ (Ideal.span (h '' ↑t)).radical := by
rw [← PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, PrimeSpectrum.zeroLocus_span]
simp [PrimeSpectrum.basicOpen_eq_zeroLocus_compl] at ht_cover
replace ht_cover : (PrimeSpectrum.zeroLocus {f})ᶜ ⊆
⋃ (i : ι) (x : i ∈ t), (PrimeSpectrum.zeroLocus {h i})ᶜ := ht_cover
rw [Set.compl_subset_comm] at ht_cover
-- Why doesn't `simp_rw` do this?
simp_rw [Set.compl_iUnion, compl_compl, ← PrimeSpectrum.zeroLocus_iUnion,
← Finset.set_biUnion_coe, ← Set.image_eq_iUnion] at ht_cover
apply PrimeSpectrum.vanishingIdeal_anti_mono ht_cover
exact PrimeSpectrum.subset_vanishingIdeal_zeroLocus {f} (Set.mem_singleton f)
replace hn := Ideal.mul_mem_right f _ hn
rw [← pow_succ, Ideal.span, Finsupp.mem_span_image_iff_linearCombination] at hn
rcases hn with ⟨b, b_supp, hb⟩
rw [Finsupp.linearCombination_apply_of_mem_supported R b_supp] at hb
dsimp at hb
-- Finally, we have all the ingredients.
-- We claim that our preimage is given by `(∑ (i : ι) ∈ t, b i * a i) / f ^ (n+1)`
use
IsLocalization.mk' (Localization.Away f) (∑ i ∈ t, b i * a i)
(⟨f ^ (n + 1), n + 1, rfl⟩ : Submonoid.powers _)
rw [toBasicOpen_mk']
-- Since the structure sheaf is a sheaf, we can show the desired equality locally.
-- Annoyingly, `Sheaf.eq_of_locally_eq'` requires an open cover indexed by a *type*, so we need to
-- coerce our finset `t` to a type first.
let tt := ((t : Set (PrimeSpectrum.basicOpen f)) : Type u)
apply
(structureSheaf R).eq_of_locally_eq' (fun i : tt => PrimeSpectrum.basicOpen (h i))
(PrimeSpectrum.basicOpen f) fun i : tt => iDh i
· -- This feels a little redundant, since already have `ht_cover` as a hypothesis
-- Unfortunately, `ht_cover` uses a bounded union over the set `t`, while here we have the
-- Union indexed by the type `tt`, so we need some boilerplate to translate one to the other
intro x hx
rw [SetLike.mem_coe, TopologicalSpace.Opens.mem_iSup]
have := ht_cover hx
rw [← Finset.set_biUnion_coe, Set.mem_iUnion₂] at this
rcases this with ⟨i, i_mem, x_mem⟩
exact ⟨⟨i, i_mem⟩, x_mem⟩
rintro ⟨i, hi⟩
dsimp
change (structureSheaf R).1.map (iDh i).op _ = (structureSheaf R).1.map (iDh i).op _
rw [s_eq i hi, res_const]
-- Again, `res_const` spits out an additional goal
swap
· intro y hy
change y ∈ PrimeSpectrum.basicOpen (f ^ (n + 1))
rw [PrimeSpectrum.basicOpen_pow f (n + 1) (by omega)]
exact (leOfHom (iDh i) :) hy
-- The rest of the proof is just computation
apply const_ext
rw [← hb, Finset.sum_mul, Finset.mul_sum]
apply Finset.sum_congr rfl
intro j hj
rw [mul_assoc, ah_ha j hj i hi]
ring
instance isIso_toBasicOpen (f : R) :
IsIso (CommRingCat.ofHom (toBasicOpen R f)) :=
haveI : IsIso ((forget CommRingCat).map (CommRingCat.ofHom (toBasicOpen R f))) :=
(isIso_iff_bijective _).mpr ⟨toBasicOpen_injective R f, toBasicOpen_surjective R f⟩
isIso_of_reflects_iso _ (forget CommRingCat)
/-- The ring isomorphism between the structure sheaf on `basicOpen f` and the localization of `R`
at the submonoid of powers of `f`. -/
def basicOpenIso (f : R) :
(structureSheaf R).1.obj (op (PrimeSpectrum.basicOpen f)) ≅
CommRingCat.of (Localization.Away f) :=
(asIso (CommRingCat.ofHom (toBasicOpen R f))).symm
instance stalkAlgebra (p : PrimeSpectrum R) : Algebra R ((structureSheaf R).presheaf.stalk p) :=
(toStalk R p).hom.toAlgebra
@[simp]
theorem stalkAlgebra_map (p : PrimeSpectrum R) (r : R) :
algebraMap R ((structureSheaf R).presheaf.stalk p) r = toStalk R p r :=
rfl
/-- Stalk of the structure sheaf at a prime p as localization of R -/
instance IsLocalization.to_stalk (p : PrimeSpectrum R) :
IsLocalization.AtPrime ((structureSheaf R).presheaf.stalk p) p.asIdeal := by
convert (IsLocalization.isLocalization_iff_of_ringEquiv (S := Localization.AtPrime p.asIdeal) _
(stalkIso R p).symm.commRingCatIsoToRingEquiv).mp
Localization.isLocalization
apply Algebra.algebra_ext
intro
rw [stalkAlgebra_map]
congr 2
change toStalk R p = _ ≫ (stalkIso R p).inv
rw [Iso.eq_comp_inv]
exact toStalk_comp_stalkToFiberRingHom R p
instance openAlgebra (U : (Opens (PrimeSpectrum R))ᵒᵖ) : Algebra R ((structureSheaf R).val.obj U) :=
(toOpen R (unop U)).hom.toAlgebra
@[simp]
theorem openAlgebra_map (U : (Opens (PrimeSpectrum R))ᵒᵖ) (r : R) :
algebraMap R ((structureSheaf R).val.obj U) r = toOpen R (unop U) r :=
rfl
/-- Sections of the structure sheaf of Spec R on a basic open as localization of R -/
instance IsLocalization.to_basicOpen (r : R) :
IsLocalization.Away r ((structureSheaf R).val.obj (op <| PrimeSpectrum.basicOpen r)) := by
convert (IsLocalization.isLocalization_iff_of_ringEquiv (S := Localization.Away r) _
(basicOpenIso R r).symm.commRingCatIsoToRingEquiv).mp
Localization.isLocalization
apply Algebra.algebra_ext
intro x
congr 1
exact (localization_toBasicOpen R r).symm
instance to_basicOpen_epi (r : R) : Epi (toOpen R (PrimeSpectrum.basicOpen r)) :=
⟨fun _ _ h => CommRingCat.hom_ext (IsLocalization.ringHom_ext (Submonoid.powers r)
(CommRingCat.hom_ext_iff.mp h))⟩
@[elementwise]
theorem to_global_factors :
toOpen R ⊤ =
CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R))) ≫
CommRingCat.ofHom (toBasicOpen R (1 : R)) ≫
(structureSheaf R).1.map (eqToHom PrimeSpectrum.basicOpen_one.symm).op := by
rw [← Category.assoc]
change toOpen R ⊤ =
(CommRingCat.ofHom <| (toBasicOpen R 1).comp (algebraMap R (Localization.Away 1))) ≫
(structureSheaf R).1.map (eqToHom _).op
rw [localization_toBasicOpen R, CommRingCat.ofHom_hom, toOpen_res]
instance isIso_to_global : IsIso (toOpen R ⊤) := by
let hom := CommRingCat.ofHom (algebraMap R (Localization.Away (1 : R)))
haveI : IsIso hom :=
(IsLocalization.atOne R (Localization.Away (1 : R))).toRingEquiv.toCommRingCatIso.isIso_hom
rw [to_global_factors R]
infer_instance
/-- The ring isomorphism between the ring `R` and the global sections `Γ(X, 𝒪ₓ)`. -/
@[simps! inv]
def globalSectionsIso : CommRingCat.of R ≅ (structureSheaf R).1.obj (op ⊤) :=
asIso (toOpen R ⊤)
@[simp]
theorem globalSectionsIso_hom (R : CommRingCat) : (globalSectionsIso R).hom = toOpen R ⊤ :=
rfl
@[simp, reassoc, elementwise nosimp]
theorem toStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R} (h : x ⤳ y) :
toStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h = toStalk R x := by
dsimp [toStalk]; simp [-toOpen_germ]
@[simp, reassoc, elementwise nosimp]
theorem localizationToStalk_stalkSpecializes {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
(h : x ⤳ y) :
StructureSheaf.localizationToStalk R y ≫ (structureSheaf R).presheaf.stalkSpecializes h =
CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h) ≫
StructureSheaf.localizationToStalk R x := by
ext : 1
apply IsLocalization.ringHom_ext (S := Localization.AtPrime y.asIdeal) y.asIdeal.primeCompl
rw [CommRingCat.hom_comp, RingHom.comp_assoc, CommRingCat.hom_comp, RingHom.comp_assoc]
dsimp [localizationToStalk, PrimeSpectrum.localizationMapOfSpecializes]
rw [IsLocalization.lift_comp, IsLocalization.lift_comp, IsLocalization.lift_comp]
exact CommRingCat.hom_ext_iff.mp (toStalk_stalkSpecializes h)
@[simp, reassoc, elementwise nosimp]
theorem stalkSpecializes_stalk_to_fiber {R : Type*} [CommRing R] {x y : PrimeSpectrum R}
(h : x ⤳ y) :
(structureSheaf R).presheaf.stalkSpecializes h ≫ StructureSheaf.stalkToFiberRingHom R x =
StructureSheaf.stalkToFiberRingHom R y ≫
(CommRingCat.ofHom (PrimeSpectrum.localizationMapOfSpecializes h)) := by
change _ ≫ (StructureSheaf.stalkIso R x).hom = (StructureSheaf.stalkIso R y).hom ≫ _
rw [← Iso.eq_comp_inv, Category.assoc, ← Iso.inv_comp_eq]
exact localizationToStalk_stalkSpecializes h
section Comap
variable {R} {S : Type u} [CommRing S] {P : Type u} [CommRing P]
/--
Given a ring homomorphism `f : R →+* S`, an open set `U` of the prime spectrum of `R` and an open
set `V` of the prime spectrum of `S`, such that `V ⊆ (comap f) ⁻¹' U`, we can push a section `s`
on `U` to a section on `V`, by composing with `Localization.localRingHom _ _ f` from the left and
`comap f` from the right. Explicitly, if `s` evaluates on `comap f p` to `a / b`, its image on `V`
evaluates on `p` to `f(a) / f(b)`.
At the moment, we work with arbitrary dependent functions `s : Π x : U, Localizations R x`. Below,
we prove the predicate `isLocallyFraction` is preserved by this map, hence it can be extended to
a morphism between the structure sheaves of `R` and `S`.
-/
def comapFun (f : R →+* S) (U : Opens (PrimeSpectrum.Top R)) (V : Opens (PrimeSpectrum.Top S))
(hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1) (s : ∀ x : U, Localizations R x) (y : V) :
Localizations S y :=
Localization.localRingHom (PrimeSpectrum.comap f y.1).asIdeal _ f rfl
(s ⟨PrimeSpectrum.comap f y.1, hUV y.2⟩ :)
theorem comapFunIsLocallyFraction (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
(V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
(s : ∀ x : U, Localizations R x) (hs : (isLocallyFraction R).toPrelocalPredicate.pred s) :
(isLocallyFraction S).toPrelocalPredicate.pred (comapFun f U V hUV s) := by
rintro ⟨p, hpV⟩
-- Since `s` is locally fraction, we can find a neighborhood `W` of `PrimeSpectrum.comap f p`
-- in `U`, such that `s = a / b` on `W`, for some ring elements `a, b : R`.
rcases hs ⟨PrimeSpectrum.comap f p, hUV hpV⟩ with ⟨W, m, iWU, a, b, h_frac⟩
-- We claim that we can write our new section as the fraction `f a / f b` on the neighborhood
-- `(comap f) ⁻¹ W ⊓ V` of `p`.
refine ⟨Opens.comap (PrimeSpectrum.comap f) W ⊓ V, ⟨m, hpV⟩, Opens.infLERight _ _, f a, f b, ?_⟩
rintro ⟨q, ⟨hqW, hqV⟩⟩
specialize h_frac ⟨PrimeSpectrum.comap f q, hqW⟩
refine ⟨h_frac.1, ?_⟩
dsimp only [comapFun]
erw [← Localization.localRingHom_to_map (PrimeSpectrum.comap f q).asIdeal, ← RingHom.map_mul,
h_frac.2, Localization.localRingHom_to_map]
rfl
/-- For a ring homomorphism `f : R →+* S` and open sets `U` and `V` of the prime spectra of `R` and
`S` such that `V ⊆ (comap f) ⁻¹ U`, the induced ring homomorphism from the structure sheaf of `R`
at `U` to the structure sheaf of `S` at `V`.
Explicitly, this map is given as follows: For a point `p : V`, if the section `s` evaluates on `p`
to the fraction `a / b`, its image on `V` evaluates on `p` to the fraction `f(a) / f(b)`.
-/
def comap (f : R →+* S) (U : Opens (PrimeSpectrum.Top R)) (V : Opens (PrimeSpectrum.Top S))
(hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1) :
(structureSheaf R).1.obj (op U) →+* (structureSheaf S).1.obj (op V) where
toFun s := ⟨comapFun f U V hUV s.1, comapFunIsLocallyFraction f U V hUV s.1 s.2⟩
map_one' :=
Subtype.ext <|
funext fun p => by
dsimp
rw [comapFun, (sectionsSubring R (op U)).coe_one, Pi.one_apply, RingHom.map_one]
rfl
map_zero' :=
Subtype.ext <|
funext fun p => by
dsimp
rw [comapFun, (sectionsSubring R (op U)).coe_zero, Pi.zero_apply, RingHom.map_zero]
rfl
map_add' s t :=
Subtype.ext <|
funext fun p => by
dsimp
rw [comapFun, (sectionsSubring R (op U)).coe_add, Pi.add_apply, RingHom.map_add]
rfl
map_mul' s t :=
Subtype.ext <|
funext fun p => by
dsimp
rw [comapFun, (sectionsSubring R (op U)).coe_mul, Pi.mul_apply, RingHom.map_mul]
rfl
@[simp]
theorem comap_apply (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
(V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1)
(s : (structureSheaf R).1.obj (op U)) (p : V) :
(comap f U V hUV s).1 p =
Localization.localRingHom (PrimeSpectrum.comap f p.1).asIdeal _ f rfl
(s.1 ⟨PrimeSpectrum.comap f p.1, hUV p.2⟩ :) :=
rfl
theorem comap_const (f : R →+* S) (U : Opens (PrimeSpectrum.Top R))
(V : Opens (PrimeSpectrum.Top S)) (hUV : V.1 ⊆ PrimeSpectrum.comap f ⁻¹' U.1) (a b : R)
(hb : ∀ x : PrimeSpectrum R, x ∈ U → b ∈ x.asIdeal.primeCompl) :
comap f U V hUV (const R a b U hb) =
const S (f a) (f b) V fun p hpV => hb (PrimeSpectrum.comap f p) (hUV hpV) :=
Subtype.eq <|
funext fun p => by
rw [comap_apply, const_apply, const_apply, Localization.localRingHom_mk']
/-- For an inclusion `i : V ⟶ U` between open sets of the prime spectrum of `R`, the comap of the
identity from OO_X(U) to OO_X(V) equals as the restriction map of the structure sheaf.
This is a generalization of the fact that, for fixed `U`, the comap of the identity from OO_X(U)
to OO_X(U) is the identity.
-/
theorem comap_id_eq_map (U V : Opens (PrimeSpectrum.Top R)) (iVU : V ⟶ U) :
(comap (RingHom.id R) U V fun _ hpV => leOfHom iVU <| hpV) =
((structureSheaf R).1.map iVU.op).hom :=
RingHom.ext fun s => Subtype.eq <| funext fun p => by
rw [comap_apply]
-- Unfortunately, we cannot use `Localization.localRingHom_id` here, because
-- `PrimeSpectrum.comap (RingHom.id R) p` is not *definitionally* equal to `p`. Instead, we use
-- that we can write `s` as a fraction `a/b` in a small neighborhood around `p`. Since
-- `PrimeSpectrum.comap (RingHom.id R) p` equals `p`, it is also contained in the same
-- neighborhood, hence `s` equals `a/b` there too.
obtain ⟨W, hpW, iWU, h⟩ := s.2 (iVU p)
obtain ⟨a, b, h'⟩ := h.eq_mk'
obtain ⟨hb₁, s_eq₁⟩ := h' ⟨p, hpW⟩
obtain ⟨hb₂, s_eq₂⟩ :=
h' ⟨PrimeSpectrum.comap (RingHom.id _) p.1, hpW⟩
dsimp only at s_eq₁ s_eq₂
erw [s_eq₂, Localization.localRingHom_mk', ← s_eq₁, ← res_apply _ _ _ iVU]
/--
The comap of the identity is the identity. In this variant of the lemma, two open subsets `U` and
`V` are given as arguments, together with a proof that `U = V`. This is useful when `U` and `V`
are not definitionally equal.
-/
theorem comap_id {U V : Opens (PrimeSpectrum.Top R)} (hUV : U = V) :
(comap (RingHom.id R) U V fun p hpV => by rwa [hUV, PrimeSpectrum.comap_id]) =
(eqToHom (show (structureSheaf R).1.obj (op U) = _ by rw [hUV])).hom := by
rw [comap_id_eq_map U V (eqToHom hUV.symm), eqToHom_op, eqToHom_map]
@[simp]
theorem comap_id' (U : Opens (PrimeSpectrum.Top R)) :
(comap (RingHom.id R) U U fun p hpU => by rwa [PrimeSpectrum.comap_id]) = RingHom.id _ := by
rw [comap_id rfl]; rfl
theorem comap_comp (f : R →+* S) (g : S →+* P) (U : Opens (PrimeSpectrum.Top R))
(V : Opens (PrimeSpectrum.Top S)) (W : Opens (PrimeSpectrum.Top P))
(hUV : ∀ p ∈ V, PrimeSpectrum.comap f p ∈ U) (hVW : ∀ p ∈ W, PrimeSpectrum.comap g p ∈ V) :
(comap (g.comp f) U W fun p hpW => hUV (PrimeSpectrum.comap g p) (hVW p hpW)) =
(comap g V W hVW).comp (comap f U V hUV) :=
RingHom.ext fun s =>
Subtype.eq <|
funext fun p => by
rw [comap_apply, Localization.localRingHom_comp _ (PrimeSpectrum.comap g p.1).asIdeal] <;>
simp
@[elementwise, reassoc]
theorem toOpen_comp_comap (f : R →+* S) (U : Opens (PrimeSpectrum.Top R)) :
(toOpen R U ≫ CommRingCat.ofHom (comap f U (Opens.comap (PrimeSpectrum.comap f) U)
fun _ => id)) =
CommRingCat.ofHom f ≫ toOpen S _ :=
CommRingCat.hom_ext <| RingHom.ext fun _ => Subtype.eq <| funext fun _ =>
Localization.localRingHom_to_map _ _ _ _ _
lemma comap_basicOpen (f : R →+* S) (x : R) :
comap f (PrimeSpectrum.basicOpen x) (PrimeSpectrum.basicOpen (f x))
(PrimeSpectrum.comap_basicOpen f x).le =
IsLocalization.map (M := .powers x) (T := .powers (f x)) _ f
(Submonoid.powers_le.mpr (Submonoid.mem_powers _)) :=
IsLocalization.ringHom_ext (.powers x) <| by
simpa [CommRingCat.hom_ext_iff] using toOpen_comp_comap f _
end Comap
end StructureSheaf
end AlgebraicGeometry
| Mathlib/AlgebraicGeometry/StructureSheaf.lean | 1,147 | 1,156 | |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.ByContra
import Mathlib.Util.Delaborators
import Mathlib.Tactic.Lift
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not
be decidable. The definition is in the module `Mathlib.Data.Set.Defs`.
This file provides some basic definitions related to sets and functions not present in the
definitions file, as well as extra lemmas for functions defined in the definitions file and
`Mathlib.Data.Set.Operations` (empty set, univ, union, intersection, insert, singleton,
set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : Set α` and `s₁ s₂ : Set α` are subsets of `α`
- `t : Set β` is a subset of `β`.
Definitions in the file:
* `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Notation
* `sᶜ` for the complement of `s`
## Implementation notes
* `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.Nonempty` dot notation can be used.
* For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
-/
assert_not_exists RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {α : Type u} {s t : Set α}
instance instBooleanAlgebra : BooleanAlgebra (Set α) :=
{ (inferInstance : BooleanAlgebra (α → Prop)) with
sup := (· ∪ ·),
le := (· ≤ ·),
lt := fun s t => s ⊆ t ∧ ¬t ⊆ s,
inf := (· ∩ ·),
bot := ∅,
compl := (·ᶜ),
top := univ,
sdiff := (· \ ·) }
instance : HasSSubset (Set α) :=
⟨(· < ·)⟩
@[simp]
theorem top_eq_univ : (⊤ : Set α) = univ :=
rfl
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) :
CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α s
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
end Set
section SetCoe
variable {α : Type u}
instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩
theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } :=
rfl
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 :=
(@SetCoe.exists _ _ fun x => p x.1 x.2).symm
theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 :=
(@SetCoe.forall _ _ fun x => p x.1 x.2).symm
@[simp]
theorem set_coe_cast :
∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩
| _, _, rfl, _, _ => rfl
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
/-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/
theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t :=
fun h₁ _ h₂ => by rw [← h₁]; exact h₂
namespace Set
variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
theorem setOf_injective : Function.Injective (@setOf α) := injective_id
theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl
/-! ### Lemmas about `mem` and `setOf` -/
theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a :=
Iff.rfl
/-- This lemma is intended for use with `rw` where a membership predicate is needed,
hence the explicit argument and the equality in the reverse direction from normal.
See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/
theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl
/-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to `simp`. -/
theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a :=
h
theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a :=
Iff.rfl
@[simp]
theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s :=
rfl
theorem setOf_set {s : Set α} : setOf s = s :=
rfl
theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x :=
Iff.rfl
theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a :=
Iff.rfl
theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) :=
bijective_id
theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x :=
Iff.rfl
theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s :=
Iff.rfl
@[simp]
theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a :=
Iff.rfl
theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } :=
rfl
theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } :=
rfl
/-! ### Subset and strict subset relations -/
instance : IsRefl (Set α) (· ⊆ ·) :=
show IsRefl (Set α) (· ≤ ·) by infer_instance
instance : IsTrans (Set α) (· ⊆ ·) :=
show IsTrans (Set α) (· ≤ ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) :=
show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance
instance : IsAntisymm (Set α) (· ⊆ ·) :=
show IsAntisymm (Set α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Set α) (· ⊂ ·) :=
show IsIrrefl (Set α) (· < ·) by infer_instance
instance : IsTrans (Set α) (· ⊂ ·) :=
show IsTrans (Set α) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· < ·) (· < ·) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) :=
show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance
instance : IsAsymm (Set α) (· ⊂ ·) :=
show IsAsymm (Set α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t :=
rfl
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) :=
rfl
@[refl]
theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id
theorem Subset.rfl {s : Set α} : s ⊆ s :=
Subset.refl s
@[trans]
theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h
@[trans]
theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩
theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩
-- an alternative name
theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b :=
Subset.antisymm
theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ :=
@h _
theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt <| mem_of_subset_of_mem h
theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by
simp only [subset_def, not_forall, exists_prop]
theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by
simp [not_subset]
lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s :=
not_subset.1 h.2
protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (Set α) _ s t
theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩
theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s :=
⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩
protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂)
(hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩
protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂)
(hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩
theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) :=
id
theorem not_not_mem : ¬a ∉ s ↔ a ∈ s :=
not_not
/-! ### Non-empty sets -/
theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty :=
nonempty_subtype
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s :=
Iff.rfl
theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty :=
⟨x, h⟩
theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅
| ⟨_, hx⟩, hs => hs hx
/-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/
protected noncomputable def Nonempty.some (h : s.Nonempty) : α :=
Classical.choose h
protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s :=
Classical.choose_spec h
theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
hs.imp ht
theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h
⟨x, xs, xt⟩
theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty :=
nonempty_of_not_subset ht.2
theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty :=
(nonempty_of_ssubset ht).of_diff
theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty :=
hs.imp fun _ => Or.inl
theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty :=
ht.imp fun _ => Or.inr
@[simp]
theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty :=
exists_or
theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty :=
h.imp fun _ => And.right
theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Iff.rfl
theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by
simp_rw [inter_nonempty]
theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by
simp_rw [inter_nonempty, and_comm]
theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty :=
⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩
@[simp]
theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty
| ⟨x⟩ => ⟨x, trivial⟩
theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) :=
nonempty_subtype.2
theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩
instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) :=
Set.univ_nonempty.to_subtype
-- Redeclare for refined keys
-- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))`
instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) :=
inferInstanceAs (Nonempty (univ : Set α))
theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_›
@[deprecated (since := "2024-11-23")] alias nonempty_of_nonempty_subtype := Nonempty.of_subtype
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : Set α) = { _x : α | False } :=
rfl
@[simp]
theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False :=
Iff.rfl
@[simp]
theorem setOf_false : { _a : α | False } = ∅ :=
rfl
@[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl
@[simp]
theorem empty_subset (s : Set α) : ∅ ⊆ s :=
nofun
@[simp]
theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ :=
(Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s :=
subset_empty_iff.symm
theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ :=
subset_empty_iff.1 h
theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ :=
eq_empty_of_subset_empty fun x _ => isEmptyElim x
/-- There is exactly one set of a type that is empty. -/
instance uniqueEmpty [IsEmpty α] : Unique (Set α) where
default := ∅
uniq := eq_empty_of_isEmpty
/-- See also `Set.nonempty_iff_ne_empty`. -/
theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by
simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `Set.not_nonempty_iff_eq_empty`. -/
theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty.not_right
/-- See also `nonempty_iff_ne_empty'`. -/
theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by
rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `not_nonempty_iff_eq_empty'`. -/
theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty'.not_right
alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx
@[simp]
theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ :=
not_iff_not.1 <| by simpa using nonempty_iff_ne_empty
theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 <| e ▸ h
theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True :=
iff_true_intro fun _ => False.elim
instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) :=
⟨fun x => x.2⟩
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
/-!
### Universal set.
In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp]
theorem setOf_true : { _x : α | True } = univ :=
rfl
@[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl
@[simp]
theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α :=
eq_empty_iff_forall_not_mem.trans
⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩
theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e =>
not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm
@[simp]
theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial
@[simp]
theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ :=
@top_le_iff _ _ _ s
alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff
theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial
theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩
exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t)
theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α)
| ⟨x⟩ => ⟨x, trivial⟩
theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]
theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]
theorem univ_unique [Unique α] : @Set.univ α = {default} :=
Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default
theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ :=
lt_top_iff_ne_top
instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) :=
⟨⟨∅, univ, empty_ne_univ⟩⟩
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } :=
rfl
theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b :=
Or.inl
theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b :=
Or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b :=
H
theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P)
(H₃ : x ∈ b → P) : P :=
Or.elim H₁ H₂ H₃
@[simp]
theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b :=
Iff.rfl
@[simp]
theorem union_self (a : Set α) : a ∪ a = a :=
ext fun _ => or_self_iff
@[simp]
theorem union_empty (a : Set α) : a ∪ ∅ = a :=
ext fun _ => iff_of_eq (or_false _)
@[simp]
theorem empty_union (a : Set α) : ∅ ∪ a = a :=
ext fun _ => iff_of_eq (false_or _)
theorem union_comm (a b : Set α) : a ∪ b = b ∪ a :=
ext fun _ => or_comm
theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) :=
ext fun _ => or_assoc
instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) :=
⟨union_assoc⟩
instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) :=
⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext fun _ => or_left_comm
theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ :=
ext fun _ => or_right_comm
@[simp]
theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s :=
sup_eq_left
@[simp]
theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t :=
sup_eq_right
theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t :=
union_eq_right.mpr h
theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s :=
union_eq_left.mpr h
@[simp]
theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl
@[simp]
theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr
theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ =>
Or.rec (@sr _) (@tr _)
@[simp]
theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr' fun _ => or_imp).trans forall_and
@[gcongr]
theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) :
s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
@[gcongr]
theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_left
theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_right
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
@[simp]
theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by
simp only [← subset_empty_iff]
exact union_subset_iff
@[simp]
theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _
@[simp]
theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _
@[simp]
theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s :=
left_lt_sup
@[simp]
theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t :=
right_lt_sup
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } :=
rfl
@[simp, mfld_simps]
theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b :=
Iff.rfl
theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
@[simp]
theorem inter_self (a : Set α) : a ∩ a = a :=
ext fun _ => and_self_iff
@[simp]
theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ :=
ext fun _ => iff_of_eq (and_false _)
@[simp]
theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ :=
ext fun _ => iff_of_eq (false_and _)
theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a :=
ext fun _ => and_comm
theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) :=
ext fun _ => and_assoc
instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) :=
⟨inter_assoc⟩
instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) :=
⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => and_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => and_right_comm
@[simp, mfld_simps]
theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left
@[simp]
theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right
theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h =>
⟨rs h, rt h⟩
@[simp]
theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr' fun _ => imp_and).trans forall_and
@[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left
@[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right
@[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf
@[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf
theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left.mpr
theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right.mpr
theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u :=
inf_congr_left ht hu
theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u :=
inf_congr_right hs ht
theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u :=
inf_eq_inf_iff_left
theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t :=
inf_eq_inf_iff_right
@[simp, mfld_simps]
theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _
@[simp, mfld_simps]
theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _
@[gcongr]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H Subset.rfl
@[gcongr]
theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter Subset.rfl H
theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right subset_union_left
theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right subset_union_right
theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} :=
rfl
theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} :=
inter_comm _ _
@[simp]
theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s :=
inf_lt_right
@[simp]
theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t :=
inf_lt_left
/-! ### Distributivity laws -/
theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u :=
inf_sup_left _ _ _
theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u :=
inf_sup_right _ _ _
theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left _ _ _
theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right _ _ _
theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) :=
sup_sup_distrib_left _ _ _
theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) :=
sup_sup_distrib_right _ _ _
theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) :=
inf_inf_distrib_left _ _ _
theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) :=
inf_inf_distrib_right _ _ _
theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) :=
sup_sup_sup_comm _ _ _ _
theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) :=
inf_inf_inf_comm _ _ _ _
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
section Sep
variable {p q : α → Prop} {x : α}
theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } :=
⟨xs, px⟩
@[simp]
theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t :=
rfl
@[simp]
theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x :=
Iff.rfl
theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff]
theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s :=
inter_eq_self_of_subset_right h
@[simp]
theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left
@[simp]
theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp]
@[simp]
theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by
simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and]
theorem sep_true : { x ∈ s | True } = s :=
inter_univ s
theorem sep_false : { x ∈ s | False } = ∅ :=
inter_empty s
theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ :=
empty_inter {x | p x}
theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } :=
univ_inter {x | p x}
@[simp]
theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } :=
union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p
@[simp]
theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } :=
inter_inter_distrib_right s t {x | p x}
@[simp]
theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } :=
inter_inter_distrib_left s {x | p x} {x | q x}
@[simp]
theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } :=
inter_union_distrib_left s p q
@[simp]
theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } :=
rfl
end Sep
/-- See also `Set.sdiff_inter_right_comm`. -/
lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc ..
/-- See also `Set.inter_diff_assoc`. -/
lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm ..
lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm ..
theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
/-- A version of `diff_union_diff_cancel` with more general hypotheses. -/
theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u :=
sdiff_sup_sdiff_cancel' hi hu
theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h
theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) :=
inf_sdiff_distrib_left _ _ _
theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) :=
inf_sdiff_distrib_right _ _ _
theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) :=
inf_sdiff
/-! ### Lemmas about complement -/
theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } :=
rfl
theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ :=
h
theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } :=
rfl
theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s :=
h
theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s :=
not_not
@[simp]
theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ :=
inf_compl_eq_bot
@[simp]
theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ :=
compl_inf_eq_bot
@[simp]
theorem compl_empty : (∅ : Set α)ᶜ = univ :=
compl_bot
@[simp]
theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ :=
compl_sup
theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ :=
compl_inf
@[simp]
theorem compl_univ : (univ : Set α)ᶜ = ∅ :=
compl_top
@[simp]
theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ :=
compl_eq_bot
@[simp]
theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ :=
compl_eq_top
theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty :=
compl_univ_iff.not.trans nonempty_iff_ne_empty.symm
lemma inl_compl_union_inr_compl {α β : Type*} {s : Set α} {t : Set β} :
Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by
rw [compl_union]
aesop
theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ :=
(ne_univ_iff_exists_not_mem s).symm
theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ :=
ext fun _ => or_iff_not_and_not
theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ :=
ext fun _ => and_iff_not_or_not
@[simp]
theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ :=
eq_univ_iff_forall.2 fun _ => em _
@[simp]
theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self]
theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s :=
@compl_le_iff_compl_le _ s _ _
theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ :=
@le_compl_iff_le_compl _ _ _ t
@[simp]
theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s :=
@compl_le_compl_iff_le (Set α) _ _ _
@[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h
theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t :=
(@isCompl_compl _ u _).le_sup_right_iff_inf_left_le
theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ :=
Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left
theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c :=
forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or
theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t :=
(not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm
/-! ### Lemmas about set difference -/
theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx
theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm]
theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t :=
inter_compl_nonempty_iff
theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le
theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ :=
diff_eq_compl_inter ▸ inter_subset_left
theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u :=
sup_sdiff_cancel' h₁ h₂
theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t :=
sup_sdiff_cancel_right h
theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h
theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h
@[simp]
theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
@[simp]
theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
sup_sdiff
@[simp]
theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ :=
inf_sdiff_self_right
@[simp]
theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s :=
sup_inf_sdiff s t
@[simp]
theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by
rw [union_comm]
exact sup_inf_sdiff _ _
@[simp]
theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s :=
inter_union_diff _ _
@[gcongr]
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff
@[gcongr]
theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
sdiff_le_sdiff_right ‹s₁ ≤ s₂›
@[gcongr]
theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
sdiff_le_sdiff_left ‹t ≤ u›
theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) :
r \ s ⊆ r \ t ↔ t ⊆ s :=
sdiff_le_sdiff_iff_le hs ht
theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s :=
top_sdiff.symm
@[simp]
theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ :=
bot_sdiff
theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
@[simp]
theorem diff_empty {s : Set α} : s \ ∅ = s :=
sdiff_bot
@[simp]
theorem diff_univ (s : Set α) : s \ univ = ∅ :=
diff_eq_empty.2 (subset_univ s)
theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) :=
sdiff_sdiff_left
-- the following statement contains parentheses to help the reader
theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff
theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t :=
show s ≤ s \ t ∪ t from le_sdiff_sup
theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s :=
Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _)
theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm
theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u :=
sdiff_inf
theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) :=
sdiff_sup.symm
theorem diff_compl : s \ tᶜ = s ∩ t :=
sdiff_compl
theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ :=
Eq.trans compl_sdiff himp_eq
theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u :=
sdiff_sdiff_right'
theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by
rw [diff_eq, diff_eq, inter_right_comm]
theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by
rw [diff_eq, diff_eq, inter_right_comm]
@[simp]
theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t :=
sup_sdiff_self _ _
@[simp]
theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t :=
sdiff_sup_self _ _
@[simp]
theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ :=
inf_sdiff_self_left
@[simp]
theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right _ _
@[simp]
theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left _ _
theorem diff_self {s : Set α} : s \ s = ∅ :=
sdiff_self
theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t :=
sup_eq_sdiff_sup_sdiff_sup_inf
/-! ### Powerset -/
theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h
theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h
@[simp]
theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s :=
Iff.rfl
theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext fun _ => subset_inter_iff
@[simp]
theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩
theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2
@[simp]
theorem powerset_nonempty : (𝒫 s).Nonempty :=
⟨∅, fun _ h => empty_subset s h⟩
@[simp]
theorem powerset_empty : 𝒫(∅ : Set α) = {∅} :=
ext fun _ => subset_empty_iff
@[simp]
theorem powerset_univ : 𝒫(univ : Set α) = univ :=
eq_univ_of_forall subset_univ
/-! ### Sets defined as an if-then-else -/
@[deprecated _root_.mem_dite (since := "2025-01-30")]
protected theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) :
(x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h :=
_root_.mem_dite
theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by
simp [mem_dite]
@[simp]
theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t Set.univ ↔ p → x ∈ t :=
mem_dite_univ_right p (fun _ => t) x
theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by
split_ifs <;> simp_all
@[simp]
theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p Set.univ t ↔ ¬p → x ∈ t :=
mem_dite_univ_left p (fun _ => t) x
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not]
exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
@[simp]
theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t ∅ ↔ p ∧ x ∈ t :=
(mem_dite_empty_right p (fun _ => t) x).trans (by simp)
theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false]
exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩
@[simp]
theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t :=
(mem_dite_empty_left p (fun _ => t) x).trans (by simp)
/-! ### If-then-else for sets -/
/-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`.
Defined as `s ∩ t ∪ s' \ t`. -/
protected def ite (t s s' : Set α) : Set α :=
s ∩ t ∪ s' \ t
@[simp]
theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by
rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
@[simp]
theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by
rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq]
@[simp]
theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by
rw [← ite_compl, ite_inter_self]
@[simp]
theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
@[simp]
theorem ite_same (t s : Set α) : t.ite s s = s :=
inter_union_diff _ _
@[simp]
theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite]
@[simp]
theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite]
@[simp]
theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite]
@[simp]
theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite]
@[simp]
theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite]
@[simp]
theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite]
theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' :=
union_subset_union inter_subset_left diff_subset
theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' :=
ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) :
t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
ext x
simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union]
tauto
theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by
rw [ite_inter_inter, ite_same]
theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) :
t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same]
theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by
simp only [subset_def, ← forall_and]
refine forall_congr' fun x => ?_
by_cases hx : x ∈ t <;> simp [*, Set.ite]
theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) :
t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)]
theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) :
t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)]
end Set
open Set
namespace Function
variable {α : Type*} {β : Type*}
theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅)
{s : Set α} : (f s).Nonempty ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff]
end Function
namespace Subsingleton
variable {α : Type*} [Subsingleton α]
theorem eq_univ_of_nonempty {s : Set α} : s.Nonempty → s = univ := fun ⟨x, hx⟩ =>
eq_univ_of_forall fun y => Subsingleton.elim x y ▸ hx
@[elab_as_elim]
theorem set_cases {p : Set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
(s.eq_empty_or_nonempty.elim fun h => h.symm ▸ h0) fun h => (eq_univ_of_nonempty h).symm ▸ h1
theorem mem_iff_nonempty {α : Type*} [Subsingleton α] {s : Set α} {x : α} : x ∈ s ↔ s.Nonempty :=
⟨fun hx => ⟨x, hx⟩, fun ⟨y, hy⟩ => Subsingleton.elim y x ▸ hy⟩
end Subsingleton
/-! ### Decidability instances for sets -/
namespace Set
variable {α : Type u} (s t : Set α) (a b : α)
instance decidableSdiff [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s \ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∉ t))
instance decidableInter [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∩ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∈ t))
instance decidableUnion [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∪ t) :=
inferInstanceAs (Decidable (a ∈ s ∨ a ∈ t))
instance decidableCompl [Decidable (a ∈ s)] : Decidable (a ∈ sᶜ) :=
inferInstanceAs (Decidable (a ∉ s))
instance decidableEmptyset : Decidable (a ∈ (∅ : Set α)) := Decidable.isFalse (by simp)
instance decidableUniv : Decidable (a ∈ univ) := Decidable.isTrue (by simp)
instance decidableInsert [Decidable (a = b)] [Decidable (a ∈ s)] : Decidable (a ∈ insert b s) :=
inferInstanceAs (Decidable (_ ∨ _))
instance decidableSetOf (p : α → Prop) [Decidable (p a)] : Decidable (a ∈ { a | p a }) := by
assumption
end Set
variable {α : Type*} {s t u : Set α}
namespace Equiv
/-- Given a predicate `p : α → Prop`, produces an equivalence between
`Set {a : α // p a}` and `{s : Set α // ∀ a ∈ s, p a}`. -/
protected def setSubtypeComm (p : α → Prop) :
Set {a : α // p a} ≃ {s : Set α // ∀ a ∈ s, p a} where
toFun s := ⟨{a | ∃ h : p a, s ⟨a, h⟩}, fun _ h ↦ h.1⟩
invFun s := {a | a.val ∈ s.val}
left_inv s := by ext a; exact ⟨fun h ↦ h.2, fun h ↦ ⟨a.property, h⟩⟩
right_inv s := by ext; exact ⟨fun h ↦ h.2, fun h ↦ ⟨s.property _ h, h⟩⟩
@[simp]
protected lemma setSubtypeComm_apply (p : α → Prop) (s : Set {a // p a}) :
(Equiv.setSubtypeComm p) s = ⟨{a | ∃ h : p a, ⟨a, h⟩ ∈ s}, fun _ h ↦ h.1⟩ :=
rfl
@[simp]
protected lemma setSubtypeComm_symm_apply (p : α → Prop) (s : {s // ∀ a ∈ s, p a}) :
(Equiv.setSubtypeComm p).symm s = {a | a.val ∈ s.val} :=
rfl
end Equiv
| Mathlib/Data/Set/Basic.lean | 1,775 | 1,775 | |
/-
Copyright (c) 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn
-/
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
import Mathlib.Topology.FiberBundle.Basic
/-!
# Vector bundles
In this file we define (topological) vector bundles.
Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let
`E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a
topological vector space over `R`.
To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the
following properties:
* The bundle trivializations in the trivialization atlas should be continuous linear equivs in the
fibers;
* For any two trivializations `e`, `e'` in the atlas the transition function considered as a map
from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator
norm topology on `F →L[R] F`.
If these conditions are satisfied, we register the typeclass `VectorBundle R F E`.
We define constructions on vector bundles like pullbacks and direct sums in other files.
## Main Definitions
* `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base
set.
* `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the
(continuous) linear fiberwise equivalences a trivialization induces.
* They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt`
and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined
everywhere, since they are extended using the zero function.
* `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only
makes sense on the intersection of their base sets, but is extended outside it using the identity.
* Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over
possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous
(semi)linear map between the chosen fibers of those bundles.
## Implementation notes
The implementation choices in the vector bundle definition are discussed in the "Implementation
notes" section of `Mathlib.Topology.FiberBundle.Basic`.
## Tags
Vector bundle
-/
noncomputable section
open Bundle Set Topology
variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*)
section TopologicalVectorSpace
variable {F E}
variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B]
/-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Pretrivialization
variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 :=
Pretrivialization.IsLinear.linear b hb
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A fiberwise linear inverse to `e`. -/
@[simps!]
protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by
refine IsLinearMap.mk' (e.symm b) ?_
by_cases hb : b ∈ e.baseSet
· exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦
congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear
· rw [e.coe_symm_of_not_mem hb]
exact (0 : F →ₗ[R] E b).isLinear
/-- A pretrivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
@[simps -fullyApplied]
def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F where
toFun y := (e ⟨b, y⟩).2
invFun := e.symm b
left_inv := e.symm_apply_apply_mk hb
right_inv v := by simp_rw [e.apply_mk_symm hb v]
map_add' v w := (e.linear R hb).map_add v w
map_smul' c v := (e.linear R hb).map_smul c v
open Classical in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0
variable {R}
open Classical in
theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [Pretrivialization.linearMapAt]
split_ifs <;> rfl
theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).left_inv y
theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).right_inv y
end Pretrivialization
variable [TopologicalSpace (TotalSpace F E)]
/-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Trivialization
variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 :=
Trivialization.IsLinear.linear b hb
instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R :=
{ (‹_› : e.IsLinear R) with }
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A trivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F :=
e.toPretrivialization.linearEquivAt R b hb
variable {R}
@[simp]
theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 :=
rfl
@[simp]
theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v :=
rfl
variable (R) in
/-- A fiberwise linear inverse to `e`. -/
protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b :=
e.toPretrivialization.symmₗ R b
theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.symmₗ R b) = e.symm b :=
rfl
variable (R) in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
e.toPretrivialization.linearMapAt R b
open Classical in
theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 :=
e.toPretrivialization.coe_linearMapAt b
theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y :=
e.toPretrivialization.symmₗ_linearMapAt hb y
theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : F) : e.linearMapAt R b (e.symmₗ R b y) = y :=
e.toPretrivialization.linearMapAt_symmₗ hb y
variable (R) in
open Classical in
/-- A coordinate change function between two trivializations, as a continuous linear equivalence.
Defined to be the identity when `b` does not lie in the base set of both trivializations. -/
def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) :
F ≃L[R] F :=
{ toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet
then (e.linearEquivAt R b (hb.1 :)).symm.trans (e'.linearEquivAt R b hb.2)
else LinearEquiv.refl R F
| continuous_toFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
| Mathlib/Topology/VectorBundle/Basic.lean | 245 | 247 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Kim Morrison
-/
import Mathlib.Data.List.Chain
/-!
# Ranges of naturals as lists
This file shows basic results about `List.iota`, `List.range`, `List.range'`
and defines `List.finRange`.
`finRange n` is the list of elements of `Fin n`.
`iota n = [n, n - 1, ..., 1]` and `range n = [0, ..., n - 1]` are basic list constructions used for
tactics. `range' a b = [a, ..., a + b - 1]` is there to help prove properties about them.
Actual maths should use `List.Ico` instead.
-/
universe u
open Nat
namespace List
variable {α : Type u}
theorem getElem_range'_1 {n m} (i) (H : i < (range' n m).length) :
(range' n m)[i] = n + i := by simp
theorem chain'_range_succ (r : ℕ → ℕ → Prop) (n : ℕ) :
Chain' r (range n.succ) ↔ ∀ m < n, r m m.succ := by
rw [range_succ]
induction' n with n hn
· simp
· rw [range_succ]
simp only [append_assoc, singleton_append, chain'_append_cons_cons, chain'_singleton, and_true]
rw [hn, forall_lt_succ]
theorem chain_range_succ (r : ℕ → ℕ → Prop) (n a : ℕ) :
Chain r a (range n.succ) ↔ r a 0 ∧ ∀ m < n, r m m.succ := by
rw [range_succ_eq_map, chain_cons, and_congr_right_iff, ← chain'_range_succ, range_succ_eq_map]
exact fun _ => Iff.rfl
section Ranges
/-- From `l : List ℕ`, construct `l.ranges : List (List ℕ)` such that
`l.ranges.map List.length = l` and `l.ranges.join = range l.sum`
* Example: `[1,2,3].ranges = [[0],[1,2],[3,4,5]]` -/
def ranges : List ℕ → List (List ℕ)
| [] => nil
| a::l => range a::(ranges l).map (map (a + ·))
/-- The members of `l.ranges` are pairwise disjoint -/
theorem ranges_disjoint (l : List ℕ) :
Pairwise Disjoint (ranges l) := by
induction l with
| nil => exact Pairwise.nil
| cons a l hl =>
simp only [ranges, pairwise_cons]
constructor
· intro s hs
obtain ⟨s', _, rfl⟩ := mem_map.mp hs
intro u hu
rw [mem_map]
rintro ⟨v, _, rfl⟩
rw [mem_range] at hu
omega
· rw [pairwise_map]
apply Pairwise.imp _ hl
intro u v
apply disjoint_map
exact fun u v => Nat.add_left_cancel
/-- The lengths of the members of `l.ranges` are those given by `l` -/
theorem ranges_length (l : List ℕ) :
l.ranges.map length = l := by
induction l with
| nil => simp only [ranges, map_nil]
| cons a l hl => -- (a :: l)
simp only [ranges, map_cons, length_range, map_map, cons.injEq, true_and]
conv_rhs => rw [← hl]
apply map_congr_left
intro s _
simp only [Function.comp_apply, length_map]
end Ranges
end List
| Mathlib/Data/List/Range.lean | 147 | 151 | |
/-
Copyright (c) 2020 Kenji Nakagawa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.Algebra.Algebra.Subalgebra.Pointwise
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.RingTheory.Spectrum.Maximal.Localization
import Mathlib.RingTheory.ChainOfDivisors
import Mathlib.RingTheory.DedekindDomain.Basic
import Mathlib.RingTheory.FractionalIdeal.Operations
import Mathlib.Algebra.Squarefree.Basic
/-!
# Dedekind domains and ideals
In this file, we show a ring is a Dedekind domain iff all fractional ideals are invertible.
Then we prove some results on the unique factorization monoid structure of the ideals.
## Main definitions
- `IsDedekindDomainInv` alternatively defines a Dedekind domain as an integral domain where
every nonzero fractional ideal is invertible.
- `isDedekindDomainInv_iff` shows that this does note depend on the choice of field of
fractions.
- `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`.
## Main results:
- `isDedekindDomain_iff_isDedekindDomainInv`
- `Ideal.uniqueFactorizationMonoid`
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. The `..._iff` lemmas express this independence.
Often, definitions assume that Dedekind domains are not fields. We found it more practical
to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring
-/
variable (R A K : Type*) [CommRing R] [CommRing A] [Field K]
open scoped nonZeroDivisors Polynomial
section Inverse
namespace FractionalIdeal
variable {R₁ : Type*} [CommRing R₁] [IsDomain R₁] [Algebra R₁ K] [IsFractionRing R₁ K]
variable {I J : FractionalIdeal R₁⁰ K}
noncomputable instance : Inv (FractionalIdeal R₁⁰ K) := ⟨fun I => 1 / I⟩
theorem inv_eq : I⁻¹ = 1 / I := rfl
theorem inv_zero' : (0 : FractionalIdeal R₁⁰ K)⁻¹ = 0 := div_zero
theorem inv_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
J⁻¹ = ⟨(1 : FractionalIdeal R₁⁰ K) / J, fractional_div_of_nonzero h⟩ := div_nonzero h
theorem coe_inv_of_nonzero {J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
(↑J⁻¹ : Submodule R₁ K) = IsLocalization.coeSubmodule K ⊤ / (J : Submodule R₁ K) := by
simp_rw [inv_nonzero _ h, coe_one, coe_mk, IsLocalization.coeSubmodule_top]
variable {K}
theorem mem_inv_iff (hI : I ≠ 0) {x : K} : x ∈ I⁻¹ ↔ ∀ y ∈ I, x * y ∈ (1 : FractionalIdeal R₁⁰ K) :=
mem_div_iff_of_nonzero hI
theorem inv_anti_mono (hI : I ≠ 0) (hJ : J ≠ 0) (hIJ : I ≤ J) : J⁻¹ ≤ I⁻¹ := by
-- Porting note: in Lean3, introducing `x` would just give `x ∈ J⁻¹ → x ∈ I⁻¹`, but
-- in Lean4, it goes all the way down to the subtypes
intro x
simp only [val_eq_coe, mem_coe, mem_inv_iff hJ, mem_inv_iff hI]
exact fun h y hy => h y (hIJ hy)
theorem le_self_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) :
I ≤ I * I⁻¹ :=
le_self_mul_one_div hI
variable (K)
theorem coe_ideal_le_self_mul_inv (I : Ideal R₁) :
(I : FractionalIdeal R₁⁰ K) ≤ I * (I : FractionalIdeal R₁⁰ K)⁻¹ :=
le_self_mul_inv coeIdeal_le_one
/-- `I⁻¹` is the inverse of `I` if `I` has an inverse. -/
theorem right_inverse_eq (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : J = I⁻¹ := by
have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h
suffices h' : I * (1 / I) = 1 from
congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl
apply le_antisymm
· apply mul_le.mpr _
intro x hx y hy
rw [mul_comm]
exact (mem_div_iff_of_nonzero hI).mp hy x hx
rw [← h]
apply mul_left_mono I
apply (le_div_iff_of_nonzero hI).mpr _
intro y hy x hx
rw [mul_comm]
exact mul_mem_mul hy hx
theorem mul_inv_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ ∃ J, I * J = 1 :=
⟨fun h => ⟨I⁻¹, h⟩, fun ⟨J, hJ⟩ => by rwa [← right_inverse_eq K I J hJ]⟩
theorem mul_inv_cancel_iff_isUnit {I : FractionalIdeal R₁⁰ K} : I * I⁻¹ = 1 ↔ IsUnit I :=
(mul_inv_cancel_iff K).trans isUnit_iff_exists_inv.symm
variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K']
@[simp]
protected theorem map_inv (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
I⁻¹.map (h : K →ₐ[R₁] K') = (I.map h)⁻¹ := by
rw [inv_eq, FractionalIdeal.map_div, FractionalIdeal.map_one, inv_eq]
open Submodule Submodule.IsPrincipal
@[simp]
theorem spanSingleton_inv (x : K) : (spanSingleton R₁⁰ x)⁻¹ = spanSingleton _ x⁻¹ :=
one_div_spanSingleton x
theorem spanSingleton_div_spanSingleton (x y : K) :
spanSingleton R₁⁰ x / spanSingleton R₁⁰ y = spanSingleton R₁⁰ (x / y) := by
rw [div_spanSingleton, mul_comm, spanSingleton_mul_spanSingleton, div_eq_mul_inv]
theorem spanSingleton_div_self {x : K} (hx : x ≠ 0) :
spanSingleton R₁⁰ x / spanSingleton R₁⁰ x = 1 := by
rw [spanSingleton_div_spanSingleton, div_self hx, spanSingleton_one]
theorem coe_ideal_span_singleton_div_self {x : R₁} (hx : x ≠ 0) :
(Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) / Ideal.span ({x} : Set R₁) = 1 := by
rw [coeIdeal_span_singleton,
spanSingleton_div_self K <|
(map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx]
theorem spanSingleton_mul_inv {x : K} (hx : x ≠ 0) :
spanSingleton R₁⁰ x * (spanSingleton R₁⁰ x)⁻¹ = 1 := by
rw [spanSingleton_inv, spanSingleton_mul_spanSingleton, mul_inv_cancel₀ hx, spanSingleton_one]
theorem coe_ideal_span_singleton_mul_inv {x : R₁} (hx : x ≠ 0) :
(Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K) *
(Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ = 1 := by
rw [coeIdeal_span_singleton,
spanSingleton_mul_inv K <|
(map_ne_zero_iff _ <| FaithfulSMul.algebraMap_injective R₁ K).mpr hx]
theorem spanSingleton_inv_mul {x : K} (hx : x ≠ 0) :
(spanSingleton R₁⁰ x)⁻¹ * spanSingleton R₁⁰ x = 1 := by
rw [mul_comm, spanSingleton_mul_inv K hx]
theorem coe_ideal_span_singleton_inv_mul {x : R₁} (hx : x ≠ 0) :
(Ideal.span ({x} : Set R₁) : FractionalIdeal R₁⁰ K)⁻¹ * Ideal.span ({x} : Set R₁) = 1 := by
rw [mul_comm, coe_ideal_span_singleton_mul_inv K hx]
theorem mul_generator_self_inv {R₁ : Type*} [CommRing R₁] [Algebra R₁ K] [IsLocalization R₁⁰ K]
(I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) :
I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 := by
-- Rewrite only the `I` that appears alone.
conv_lhs => congr; rw [eq_spanSingleton_of_principal I]
rw [spanSingleton_mul_spanSingleton, mul_inv_cancel₀, spanSingleton_one]
intro generator_I_eq_zero
apply h
rw [eq_spanSingleton_of_principal I, generator_I_eq_zero, spanSingleton_zero]
theorem invertible_of_principal (I : FractionalIdeal R₁⁰ K)
[Submodule.IsPrincipal (I : Submodule R₁ K)] (h : I ≠ 0) : I * I⁻¹ = 1 :=
mul_div_self_cancel_iff.mpr
⟨spanSingleton _ (generator (I : Submodule R₁ K))⁻¹, mul_generator_self_inv _ I h⟩
theorem invertible_iff_generator_nonzero (I : FractionalIdeal R₁⁰ K)
[Submodule.IsPrincipal (I : Submodule R₁ K)] :
I * I⁻¹ = 1 ↔ generator (I : Submodule R₁ K) ≠ 0 := by
constructor
· intro hI hg
apply ne_zero_of_mul_eq_one _ _ hI
rw [eq_spanSingleton_of_principal I, hg, spanSingleton_zero]
· intro hg
apply invertible_of_principal
rw [eq_spanSingleton_of_principal I]
intro hI
have := mem_spanSingleton_self R₁⁰ (generator (I : Submodule R₁ K))
rw [hI, mem_zero_iff] at this
contradiction
theorem isPrincipal_inv (I : FractionalIdeal R₁⁰ K) [Submodule.IsPrincipal (I : Submodule R₁ K)]
(h : I ≠ 0) : Submodule.IsPrincipal I⁻¹.1 := by
rw [val_eq_coe, isPrincipal_iff]
use (generator (I : Submodule R₁ K))⁻¹
have hI : I * spanSingleton _ (generator (I : Submodule R₁ K))⁻¹ = 1 :=
mul_generator_self_inv _ I h
exact (right_inverse_eq _ I (spanSingleton _ (generator (I : Submodule R₁ K))⁻¹) hI).symm
variable {K}
lemma den_mem_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) :
(algebraMap R₁ K) (I.den : R₁) ∈ I⁻¹ := by
rw [mem_inv_iff hI]
intro i hi
rw [← Algebra.smul_def (I.den : R₁) i, ← mem_coe, coe_one]
suffices Submodule.map (Algebra.linearMap R₁ K) I.num ≤ 1 from
this <| (den_mul_self_eq_num I).symm ▸ smul_mem_pointwise_smul i I.den I.coeToSubmodule hi
apply le_trans <| map_mono (show I.num ≤ 1 by simp only [Ideal.one_eq_top, le_top, bot_eq_zero])
rw [Ideal.one_eq_top, Submodule.map_top, one_eq_range]
lemma num_le_mul_inv (I : FractionalIdeal R₁⁰ K) : I.num ≤ I * I⁻¹ := by
by_cases hI : I = 0
· rw [hI, num_zero_eq <| FaithfulSMul.algebraMap_injective R₁ K, zero_mul, zero_eq_bot,
coeIdeal_bot]
· rw [mul_comm, ← den_mul_self_eq_num']
exact mul_right_mono I <| spanSingleton_le_iff_mem.2 (den_mem_inv hI)
lemma bot_lt_mul_inv {I : FractionalIdeal R₁⁰ K} (hI : I ≠ ⊥) : ⊥ < I * I⁻¹ :=
lt_of_lt_of_le (coeIdeal_ne_zero.2 (hI ∘ num_eq_zero_iff.1)).bot_lt I.num_le_mul_inv
noncomputable instance : InvOneClass (FractionalIdeal R₁⁰ K) := { inv_one := div_one }
end FractionalIdeal
section IsDedekindDomainInv
variable [IsDomain A]
/-- A Dedekind domain is an integral domain such that every fractional ideal has an inverse.
This is equivalent to `IsDedekindDomain`.
In particular we provide a `fractional_ideal.comm_group_with_zero` instance,
assuming `IsDedekindDomain A`, which implies `IsDedekindDomainInv`. For **integral** ideals,
`IsDedekindDomain`(`_inv`) implies only `Ideal.cancelCommMonoidWithZero`.
-/
def IsDedekindDomainInv : Prop :=
∀ I ≠ (⊥ : FractionalIdeal A⁰ (FractionRing A)), I * I⁻¹ = 1
open FractionalIdeal
variable {R A K}
theorem isDedekindDomainInv_iff [Algebra A K] [IsFractionRing A K] :
IsDedekindDomainInv A ↔ ∀ I ≠ (⊥ : FractionalIdeal A⁰ K), I * I⁻¹ = 1 := by
let h : FractionalIdeal A⁰ (FractionRing A) ≃+* FractionalIdeal A⁰ K :=
FractionalIdeal.mapEquiv (FractionRing.algEquiv A K)
refine h.toEquiv.forall_congr (fun {x} => ?_)
rw [← h.toEquiv.apply_eq_iff_eq]
simp [h, IsDedekindDomainInv]
theorem FractionalIdeal.adjoinIntegral_eq_one_of_isUnit [Algebra A K] [IsFractionRing A K] (x : K)
(hx : IsIntegral A x) (hI : IsUnit (adjoinIntegral A⁰ x hx)) : adjoinIntegral A⁰ x hx = 1 := by
set I := adjoinIntegral A⁰ x hx
have mul_self : IsIdempotentElem I := by
apply coeToSubmodule_injective
simp only [coe_mul, adjoinIntegral_coe, I]
rw [(Algebra.adjoin A {x}).isIdempotentElem_toSubmodule]
convert congr_arg (· * I⁻¹) mul_self <;>
simp only [(mul_inv_cancel_iff_isUnit K).mpr hI, mul_assoc, mul_one]
namespace IsDedekindDomainInv
variable [Algebra A K] [IsFractionRing A K] (h : IsDedekindDomainInv A)
include h
theorem mul_inv_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I * I⁻¹ = 1 :=
isDedekindDomainInv_iff.mp h I hI
theorem inv_mul_eq_one {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : I⁻¹ * I = 1 :=
(mul_comm _ _).trans (h.mul_inv_eq_one hI)
protected theorem isUnit {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) : IsUnit I :=
isUnit_of_mul_eq_one _ _ (h.mul_inv_eq_one hI)
theorem isNoetherianRing : IsNoetherianRing A := by
refine isNoetherianRing_iff.mpr ⟨fun I : Ideal A => ?_⟩
by_cases hI : I = ⊥
· rw [hI]; apply Submodule.fg_bot
have hI : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI
exact I.fg_of_isUnit (IsFractionRing.injective A (FractionRing A)) (h.isUnit hI)
theorem integrallyClosed : IsIntegrallyClosed A := by
-- It suffices to show that for integral `x`,
-- `A[x]` (which is a fractional ideal) is in fact equal to `A`.
refine (isIntegrallyClosed_iff (FractionRing A)).mpr (fun {x hx} => ?_)
rw [← Set.mem_range, ← Algebra.mem_bot, ← Subalgebra.mem_toSubmodule, Algebra.toSubmodule_bot,
Submodule.one_eq_span, ← coe_spanSingleton A⁰ (1 : FractionRing A), spanSingleton_one, ←
FractionalIdeal.adjoinIntegral_eq_one_of_isUnit x hx (h.isUnit _)]
· exact mem_adjoinIntegral_self A⁰ x hx
· exact fun h => one_ne_zero (eq_zero_iff.mp h 1 (Algebra.adjoin A {x}).one_mem)
open Ring
theorem dimensionLEOne : DimensionLEOne A := ⟨by
-- We're going to show that `P` is maximal because any (maximal) ideal `M`
-- that is strictly larger would be `⊤`.
rintro P P_ne hP
refine Ideal.isMaximal_def.mpr ⟨hP.ne_top, fun M hM => ?_⟩
-- We may assume `P` and `M` (as fractional ideals) are nonzero.
have P'_ne : (P : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr P_ne
have M'_ne : (M : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hM.ne_bot
-- In particular, we'll show `M⁻¹ * P ≤ P`
suffices (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ P by
rw [eq_top_iff, ← coeIdeal_le_coeIdeal (FractionRing A), coeIdeal_top]
calc
(1 : FractionalIdeal A⁰ (FractionRing A)) = _ * _ * _ := ?_
_ ≤ _ * _ := mul_right_mono
((P : FractionalIdeal A⁰ (FractionRing A))⁻¹ * M : FractionalIdeal A⁰ (FractionRing A)) this
_ = M := ?_
· rw [mul_assoc, ← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne,
one_mul, h.inv_mul_eq_one M'_ne]
· rw [← mul_assoc (P : FractionalIdeal A⁰ (FractionRing A)), h.mul_inv_eq_one P'_ne, one_mul]
-- Suppose we have `x ∈ M⁻¹ * P`, then in fact `x = algebraMap _ _ y` for some `y`.
intro x hx
have le_one : (M⁻¹ : FractionalIdeal A⁰ (FractionRing A)) * P ≤ 1 := by
rw [← h.inv_mul_eq_one M'_ne]
exact mul_left_mono _ ((coeIdeal_le_coeIdeal (FractionRing A)).mpr hM.le)
obtain ⟨y, _hy, rfl⟩ := (mem_coeIdeal _).mp (le_one hx)
-- Since `M` is strictly greater than `P`, let `z ∈ M \ P`.
obtain ⟨z, hzM, hzp⟩ := SetLike.exists_of_lt hM
-- We have `z * y ∈ M * (M⁻¹ * P) = P`.
have zy_mem := mul_mem_mul (mem_coeIdeal_of_mem A⁰ hzM) hx
rw [← RingHom.map_mul, ← mul_assoc, h.mul_inv_eq_one M'_ne, one_mul] at zy_mem
obtain ⟨zy, hzy, zy_eq⟩ := (mem_coeIdeal A⁰).mp zy_mem
rw [IsFractionRing.injective A (FractionRing A) zy_eq] at hzy
-- But `P` is a prime ideal, so `z ∉ P` implies `y ∈ P`, as desired.
exact mem_coeIdeal_of_mem A⁰ (Or.resolve_left (hP.mem_or_mem hzy) hzp)⟩
/-- Showing one side of the equivalence between the definitions
`IsDedekindDomainInv` and `IsDedekindDomain` of Dedekind domains. -/
theorem isDedekindDomain : IsDedekindDomain A :=
{ h.isNoetherianRing, h.dimensionLEOne, h.integrallyClosed with }
end IsDedekindDomainInv
end IsDedekindDomainInv
variable [Algebra A K] [IsFractionRing A K]
variable {A K}
theorem one_mem_inv_coe_ideal [IsDomain A] {I : Ideal A} (hI : I ≠ ⊥) :
(1 : K) ∈ (I : FractionalIdeal A⁰ K)⁻¹ := by
rw [FractionalIdeal.mem_inv_iff (FractionalIdeal.coeIdeal_ne_zero.mpr hI)]
intro y hy
rw [one_mul]
exact FractionalIdeal.coeIdeal_le_one hy
/-- Specialization of `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` to Dedekind domains:
Let `I : Ideal A` be a nonzero ideal, where `A` is a Dedekind domain that is not a field.
Then `exists_primeSpectrum_prod_le_and_ne_bot_of_domain` states we can find a product of prime
ideals that is contained within `I`. This lemma extends that result by making the product minimal:
let `M` be a maximal ideal that contains `I`, then the product including `M` is contained within `I`
and the product excluding `M` is not contained within `I`. -/
theorem exists_multiset_prod_cons_le_and_prod_not_le [IsDedekindDomain A] (hNF : ¬IsField A)
{I M : Ideal A} (hI0 : I ≠ ⊥) (hIM : I ≤ M) [hM : M.IsMaximal] :
∃ Z : Multiset (PrimeSpectrum A),
(M ::ₘ Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧
¬Multiset.prod (Z.map PrimeSpectrum.asIdeal) ≤ I := by
-- Let `Z` be a minimal set of prime ideals such that their product is contained in `J`.
obtain ⟨Z₀, hZ₀⟩ := PrimeSpectrum.exists_primeSpectrum_prod_le_and_ne_bot_of_domain hNF hI0
obtain ⟨Z, ⟨hZI, hprodZ⟩, h_eraseZ⟩ :=
wellFounded_lt.has_min
{Z | (Z.map PrimeSpectrum.asIdeal).prod ≤ I ∧ (Z.map PrimeSpectrum.asIdeal).prod ≠ ⊥}
⟨Z₀, hZ₀.1, hZ₀.2⟩
obtain ⟨_, hPZ', hPM⟩ := hM.isPrime.multiset_prod_le.mp (hZI.trans hIM)
-- Then in fact there is a `P ∈ Z` with `P ≤ M`.
obtain ⟨P, hPZ, rfl⟩ := Multiset.mem_map.mp hPZ'
classical
have := Multiset.map_erase PrimeSpectrum.asIdeal (fun _ _ => PrimeSpectrum.ext) P Z
obtain ⟨hP0, hZP0⟩ : P.asIdeal ≠ ⊥ ∧ ((Z.erase P).map PrimeSpectrum.asIdeal).prod ≠ ⊥ := by
rwa [Ne, ← Multiset.cons_erase hPZ', Multiset.prod_cons, Ideal.mul_eq_bot, not_or, ←
this] at hprodZ
-- By maximality of `P` and `M`, we have that `P ≤ M` implies `P = M`.
have hPM' := (P.isPrime.isMaximal hP0).eq_of_le hM.ne_top hPM
subst hPM'
-- By minimality of `Z`, erasing `P` from `Z` is exactly what we need.
refine ⟨Z.erase P, ?_, ?_⟩
· convert hZI
rw [this, Multiset.cons_erase hPZ']
· refine fun h => h_eraseZ (Z.erase P) ⟨h, ?_⟩ (Multiset.erase_lt.mpr hPZ)
exact hZP0
namespace FractionalIdeal
open Ideal
lemma not_inv_le_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A}
(hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) : ¬(I⁻¹ : FractionalIdeal A⁰ K) ≤ 1 := by
have hNF : ¬IsField A := fun h ↦ letI := h.toField; (eq_bot_or_eq_top I).elim hI0 hI1
wlog hM : I.IsMaximal generalizing I
· rcases I.exists_le_maximal hI1 with ⟨M, hmax, hIM⟩
have hMbot : M ≠ ⊥ := (M.bot_lt_of_maximal hNF).ne'
refine mt (le_trans <| inv_anti_mono ?_ ?_ ?_) (this hMbot hmax.ne_top hmax) <;>
simpa only [coeIdeal_ne_zero, coeIdeal_le_coeIdeal]
have hI0 : ⊥ < I := I.bot_lt_of_maximal hNF
obtain ⟨⟨a, haI⟩, ha0⟩ := Submodule.nonzero_mem_of_bot_lt hI0
replace ha0 : a ≠ 0 := Subtype.coe_injective.ne ha0
let J : Ideal A := Ideal.span {a}
have hJ0 : J ≠ ⊥ := mt Ideal.span_singleton_eq_bot.mp ha0
have hJI : J ≤ I := I.span_singleton_le_iff_mem.2 haI
-- Then we can find a product of prime (hence maximal) ideals contained in `J`,
-- such that removing element `M` from the product is not contained in `J`.
obtain ⟨Z, hle, hnle⟩ := exists_multiset_prod_cons_le_and_prod_not_le hNF hJ0 hJI
-- Choose an element `b` of the product that is not in `J`.
obtain ⟨b, hbZ, hbJ⟩ := SetLike.not_le_iff_exists.mp hnle
have hnz_fa : algebraMap A K a ≠ 0 :=
mt ((injective_iff_map_eq_zero _).mp (IsFractionRing.injective A K) a) ha0
-- Then `b a⁻¹ : K` is in `M⁻¹` but not in `1`.
refine Set.not_subset.2 ⟨algebraMap A K b * (algebraMap A K a)⁻¹, (mem_inv_iff ?_).mpr ?_, ?_⟩
· exact coeIdeal_ne_zero.mpr hI0.ne'
· rintro y₀ hy₀
obtain ⟨y, h_Iy, rfl⟩ := (mem_coeIdeal _).mp hy₀
rw [mul_comm, ← mul_assoc, ← RingHom.map_mul]
have h_yb : y * b ∈ J := by
apply hle
rw [Multiset.prod_cons]
exact Submodule.smul_mem_smul h_Iy hbZ
rw [Ideal.mem_span_singleton'] at h_yb
rcases h_yb with ⟨c, hc⟩
rw [← hc, RingHom.map_mul, mul_assoc, mul_inv_cancel₀ hnz_fa, mul_one]
apply coe_mem_one
· refine mt (mem_one_iff _).mp ?_
rintro ⟨x', h₂_abs⟩
rw [← div_eq_mul_inv, eq_div_iff_mul_eq hnz_fa, ← RingHom.map_mul] at h₂_abs
have := Ideal.mem_span_singleton'.mpr ⟨x', IsFractionRing.injective A K h₂_abs⟩
contradiction
theorem exists_not_mem_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥)
(hI1 : I ≠ ⊤) : ∃ x ∈ (I⁻¹ : FractionalIdeal A⁰ K), x ∉ (1 : FractionalIdeal A⁰ K) :=
Set.not_subset.1 <| not_inv_le_one_of_ne_bot hI0 hI1
theorem mul_inv_cancel_of_le_one [h : IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥)
(hI : (I * (I : FractionalIdeal A⁰ K)⁻¹)⁻¹ ≤ 1) : I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by
-- We'll show a contradiction with `exists_not_mem_one_of_ne_bot`:
-- `J⁻¹ = (I * I⁻¹)⁻¹` cannot have an element `x ∉ 1`, so it must equal `1`.
obtain ⟨J, hJ⟩ : ∃ J : Ideal A, (J : FractionalIdeal A⁰ K) = I * (I : FractionalIdeal A⁰ K)⁻¹ :=
le_one_iff_exists_coeIdeal.mp mul_one_div_le_one
by_cases hJ0 : J = ⊥
· subst hJ0
refine absurd ?_ hI0
rw [eq_bot_iff, ← coeIdeal_le_coeIdeal K, hJ]
exact coe_ideal_le_self_mul_inv K I
by_cases hJ1 : J = ⊤
· rw [← hJ, hJ1, coeIdeal_top]
exact (not_inv_le_one_of_ne_bot (K := K) hJ0 hJ1 (hJ ▸ hI)).elim
/-- Nonzero integral ideals in a Dedekind domain are invertible.
We will use this to show that nonzero fractional ideals are invertible,
and finally conclude that fractional ideals in a Dedekind domain form a group with zero.
-/
theorem coe_ideal_mul_inv [h : IsDedekindDomain A] (I : Ideal A) (hI0 : I ≠ ⊥) :
I * (I : FractionalIdeal A⁰ K)⁻¹ = 1 := by
-- We'll show `1 ≤ J⁻¹ = (I * I⁻¹)⁻¹ ≤ 1`.
apply mul_inv_cancel_of_le_one hI0
by_cases hJ0 : I * (I : FractionalIdeal A⁰ K)⁻¹ = 0
· rw [hJ0, inv_zero']; exact zero_le _
intro x hx
-- In particular, we'll show all `x ∈ J⁻¹` are integral.
suffices x ∈ integralClosure A K by
rwa [IsIntegrallyClosed.integralClosure_eq_bot, Algebra.mem_bot, Set.mem_range,
← mem_one_iff] at this
-- For that, we'll find a subalgebra that is f.g. as a module and contains `x`.
-- `A` is a noetherian ring, so we just need to find a subalgebra between `{x}` and `I⁻¹`.
rw [mem_integralClosure_iff_mem_fg]
have x_mul_mem : ∀ b ∈ (I⁻¹ : FractionalIdeal A⁰ K), x * b ∈ (I⁻¹ : FractionalIdeal A⁰ K) := by
intro b hb
rw [mem_inv_iff (coeIdeal_ne_zero.mpr hI0)]
dsimp only at hx
rw [val_eq_coe, mem_coe, mem_inv_iff hJ0] at hx
simp only [mul_assoc, mul_comm b] at hx ⊢
intro y hy
exact hx _ (mul_mem_mul hy hb)
-- It turns out the subalgebra consisting of all `p(x)` for `p : A[X]` works.
refine ⟨AlgHom.range (Polynomial.aeval x : A[X] →ₐ[A] K),
isNoetherian_submodule.mp (isNoetherian (I : FractionalIdeal A⁰ K)⁻¹) _ fun y hy => ?_,
⟨Polynomial.X, Polynomial.aeval_X x⟩⟩
obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp hy
rw [Polynomial.aeval_eq_sum_range]
refine Submodule.sum_mem _ fun i hi => Submodule.smul_mem _ _ ?_
clear hi
induction' i with i ih
· rw [pow_zero]; exact one_mem_inv_coe_ideal hI0
· show x ^ i.succ ∈ (I⁻¹ : FractionalIdeal A⁰ K)
rw [pow_succ']; exact x_mul_mem _ ih
/-- Nonzero fractional ideals in a Dedekind domain are units.
This is also available as `_root_.mul_inv_cancel`, using the
`Semifield` instance defined below.
-/
protected theorem mul_inv_cancel [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hne : I ≠ 0) :
I * I⁻¹ = 1 := by
obtain ⟨a, J, ha, hJ⟩ :
∃ (a : A) (aI : Ideal A), a ≠ 0 ∧ I = spanSingleton A⁰ (algebraMap A K a)⁻¹ * aI :=
exists_eq_spanSingleton_mul I
suffices h₂ : I * (spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹) = 1 by
rw [mul_inv_cancel_iff]
exact ⟨spanSingleton A⁰ (algebraMap _ _ a) * (J : FractionalIdeal A⁰ K)⁻¹, h₂⟩
subst hJ
rw [mul_assoc, mul_left_comm (J : FractionalIdeal A⁰ K), coe_ideal_mul_inv, mul_one,
spanSingleton_mul_spanSingleton, inv_mul_cancel₀, spanSingleton_one]
· exact mt ((injective_iff_map_eq_zero (algebraMap A K)).mp (IsFractionRing.injective A K) _) ha
· exact coeIdeal_ne_zero.mp (right_ne_zero_of_mul hne)
theorem mul_right_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) :
∀ {I I'}, I * J ≤ I' * J ↔ I ≤ I' := by
intro I I'
constructor
· intro h
convert mul_right_mono J⁻¹ h <;> dsimp only <;>
rw [mul_assoc, FractionalIdeal.mul_inv_cancel hJ, mul_one]
· exact fun h => mul_right_mono J h
theorem mul_left_le_iff [IsDedekindDomain A] {J : FractionalIdeal A⁰ K} (hJ : J ≠ 0) {I I'} :
J * I ≤ J * I' ↔ I ≤ I' := by convert mul_right_le_iff hJ using 1; simp only [mul_comm]
theorem mul_right_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) :
StrictMono (· * I) :=
strictMono_of_le_iff_le fun _ _ => (mul_right_le_iff hI).symm
theorem mul_left_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) :
StrictMono (I * ·) :=
strictMono_of_le_iff_le fun _ _ => (mul_left_le_iff hI).symm
/-- This is also available as `_root_.div_eq_mul_inv`, using the
`Semifield` instance defined below.
-/
protected theorem div_eq_mul_inv [IsDedekindDomain A] (I J : FractionalIdeal A⁰ K) :
I / J = I * J⁻¹ := by
by_cases hJ : J = 0
· rw [hJ, div_zero, inv_zero', mul_zero]
refine le_antisymm ((mul_right_le_iff hJ).mp ?_) ((le_div_iff_mul_le hJ).mpr ?_)
· rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one, mul_le]
intro x hx y hy
rw [mem_div_iff_of_nonzero hJ] at hx
exact hx y hy
rw [mul_assoc, mul_comm J⁻¹, FractionalIdeal.mul_inv_cancel hJ, mul_one]
end FractionalIdeal
/-- `IsDedekindDomain` and `IsDedekindDomainInv` are equivalent ways
to express that an integral domain is a Dedekind domain. -/
theorem isDedekindDomain_iff_isDedekindDomainInv [IsDomain A] :
IsDedekindDomain A ↔ IsDedekindDomainInv A :=
⟨fun _h _I hI => FractionalIdeal.mul_inv_cancel hI, fun h => h.isDedekindDomain⟩
end Inverse
section IsDedekindDomain
variable {R A}
variable [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K]
open FractionalIdeal
open Ideal
noncomputable instance FractionalIdeal.semifield : Semifield (FractionalIdeal A⁰ K) where
__ := coeIdeal_injective.nontrivial
inv_zero := inv_zero' _
div_eq_mul_inv := FractionalIdeal.div_eq_mul_inv
mul_inv_cancel _ := FractionalIdeal.mul_inv_cancel
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
#adaptation_note /-- 2025-03-29 for lean4#7717 had to add `mul_left_cancel_of_ne_zero` field.
TODO(kmill) There is trouble calculating the type of the `IsLeftCancelMulZero` parent. -/
/-- Fractional ideals have cancellative multiplication in a Dedekind domain.
Although this instance is a direct consequence of the instance
`FractionalIdeal.semifield`, we define this instance to provide
a computable alternative.
-/
instance FractionalIdeal.cancelCommMonoidWithZero :
CancelCommMonoidWithZero (FractionalIdeal A⁰ K) where
__ : CommSemiring (FractionalIdeal A⁰ K) := inferInstance
mul_left_cancel_of_ne_zero := mul_left_cancel₀
instance Ideal.cancelCommMonoidWithZero : CancelCommMonoidWithZero (Ideal A) :=
{ Function.Injective.cancelCommMonoidWithZero (coeIdealHom A⁰ (FractionRing A)) coeIdeal_injective
(RingHom.map_zero _) (RingHom.map_one _) (RingHom.map_mul _) (RingHom.map_pow _) with }
-- Porting note: Lean can infer all it needs by itself
instance Ideal.isDomain : IsDomain (Ideal A) := { }
/-- For ideals in a Dedekind domain, to divide is to contain. -/
theorem Ideal.dvd_iff_le {I J : Ideal A} : I ∣ J ↔ J ≤ I :=
⟨Ideal.le_of_dvd, fun h => by
by_cases hI : I = ⊥
· have hJ : J = ⊥ := by rwa [hI, ← eq_bot_iff] at h
rw [hI, hJ]
have hI' : (I : FractionalIdeal A⁰ (FractionRing A)) ≠ 0 := coeIdeal_ne_zero.mpr hI
have : (I : FractionalIdeal A⁰ (FractionRing A))⁻¹ * J ≤ 1 := by
rw [← inv_mul_cancel₀ hI']
exact mul_left_mono _ ((coeIdeal_le_coeIdeal _).mpr h)
obtain ⟨H, hH⟩ := le_one_iff_exists_coeIdeal.mp this
use H
refine coeIdeal_injective (show (J : FractionalIdeal A⁰ (FractionRing A)) = ↑(I * H) from ?_)
rw [coeIdeal_mul, hH, ← mul_assoc, mul_inv_cancel₀ hI', one_mul]⟩
theorem Ideal.dvdNotUnit_iff_lt {I J : Ideal A} : DvdNotUnit I J ↔ J < I :=
⟨fun ⟨hI, H, hunit, hmul⟩ =>
lt_of_le_of_ne (Ideal.dvd_iff_le.mp ⟨H, hmul⟩)
(mt
(fun h =>
have : H = 1 := mul_left_cancel₀ hI (by rw [← hmul, h, mul_one])
show IsUnit H from this.symm ▸ isUnit_one)
hunit),
fun h =>
dvdNotUnit_of_dvd_of_not_dvd (Ideal.dvd_iff_le.mpr (le_of_lt h))
(mt Ideal.dvd_iff_le.mp (not_le_of_lt h))⟩
instance : WfDvdMonoid (Ideal A) where
wf := by
have : WellFoundedGT (Ideal A) := inferInstance
convert this.wf
ext
rw [Ideal.dvdNotUnit_iff_lt]
instance Ideal.uniqueFactorizationMonoid : UniqueFactorizationMonoid (Ideal A) :=
{ irreducible_iff_prime := by
intro P
exact ⟨fun hirr => ⟨hirr.ne_zero, hirr.not_isUnit, fun I J => by
have : P.IsMaximal := by
refine ⟨⟨mt Ideal.isUnit_iff.mpr hirr.not_isUnit, ?_⟩⟩
intro J hJ
obtain ⟨_J_ne, H, hunit, P_eq⟩ := Ideal.dvdNotUnit_iff_lt.mpr hJ
exact Ideal.isUnit_iff.mp ((hirr.isUnit_or_isUnit P_eq).resolve_right hunit)
rw [Ideal.dvd_iff_le, Ideal.dvd_iff_le, Ideal.dvd_iff_le, SetLike.le_def, SetLike.le_def,
SetLike.le_def]
contrapose!
rintro ⟨⟨x, x_mem, x_not_mem⟩, ⟨y, y_mem, y_not_mem⟩⟩
exact
⟨x * y, Ideal.mul_mem_mul x_mem y_mem,
mt this.isPrime.mem_or_mem (not_or_intro x_not_mem y_not_mem)⟩⟩, Prime.irreducible⟩ }
instance Ideal.normalizationMonoid : NormalizationMonoid (Ideal A) := .ofUniqueUnits
@[simp]
theorem Ideal.dvd_span_singleton {I : Ideal A} {x : A} : I ∣ Ideal.span {x} ↔ x ∈ I :=
Ideal.dvd_iff_le.trans (Ideal.span_le.trans Set.singleton_subset_iff)
theorem Ideal.isPrime_of_prime {P : Ideal A} (h : Prime P) : IsPrime P := by
refine ⟨?_, fun hxy => ?_⟩
· rintro rfl
rw [← Ideal.one_eq_top] at h
exact h.not_unit isUnit_one
· simp only [← Ideal.dvd_span_singleton, ← Ideal.span_singleton_mul_span_singleton] at hxy ⊢
exact h.dvd_or_dvd hxy
theorem Ideal.prime_of_isPrime {P : Ideal A} (hP : P ≠ ⊥) (h : IsPrime P) : Prime P := by
refine ⟨hP, mt Ideal.isUnit_iff.mp h.ne_top, fun I J hIJ => ?_⟩
simpa only [Ideal.dvd_iff_le] using h.mul_le.mp (Ideal.le_of_dvd hIJ)
/-- In a Dedekind domain, the (nonzero) prime elements of the monoid with zero `Ideal A`
are exactly the prime ideals. -/
theorem Ideal.prime_iff_isPrime {P : Ideal A} (hP : P ≠ ⊥) : Prime P ↔ IsPrime P :=
⟨Ideal.isPrime_of_prime, Ideal.prime_of_isPrime hP⟩
/-- In a Dedekind domain, the prime ideals are the zero ideal together with the prime elements
of the monoid with zero `Ideal A`. -/
theorem Ideal.isPrime_iff_bot_or_prime {P : Ideal A} : IsPrime P ↔ P = ⊥ ∨ Prime P :=
⟨fun hp => (eq_or_ne P ⊥).imp_right fun hp0 => Ideal.prime_of_isPrime hp0 hp, fun hp =>
hp.elim (fun h => h.symm ▸ Ideal.bot_prime) Ideal.isPrime_of_prime⟩
@[simp]
theorem Ideal.prime_span_singleton_iff {a : A} : Prime (Ideal.span {a}) ↔ Prime a := by
rcases eq_or_ne a 0 with rfl | ha
· rw [Set.singleton_zero, span_zero, ← Ideal.zero_eq_bot, ← not_iff_not]
simp only [not_prime_zero, not_false_eq_true]
· have ha' : span {a} ≠ ⊥ := by simpa only [ne_eq, span_singleton_eq_bot] using ha
rw [Ideal.prime_iff_isPrime ha', Ideal.span_singleton_prime ha]
open Submodule.IsPrincipal in
theorem Ideal.prime_generator_of_prime {P : Ideal A} (h : Prime P) [P.IsPrincipal] :
Prime (generator P) :=
have : Ideal.IsPrime P := Ideal.isPrime_of_prime h
prime_generator_of_isPrime _ h.ne_zero
open UniqueFactorizationMonoid in
nonrec theorem Ideal.mem_normalizedFactors_iff {p I : Ideal A} (hI : I ≠ ⊥) :
p ∈ normalizedFactors I ↔ p.IsPrime ∧ I ≤ p := by
rw [← Ideal.dvd_iff_le]
by_cases hp : p = 0
· rw [← zero_eq_bot] at hI
simp only [hp, zero_not_mem_normalizedFactors, zero_dvd_iff, hI, false_iff, not_and,
not_false_eq_true, implies_true]
· rwa [mem_normalizedFactors_iff hI, prime_iff_isPrime]
theorem Ideal.pow_right_strictAnti (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) :
StrictAnti (I ^ · : ℕ → Ideal A) :=
strictAnti_nat_of_succ_lt fun e =>
Ideal.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero _ hI0, I, mt isUnit_iff.mp hI1, pow_succ I e⟩
theorem Ideal.pow_lt_self (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) (he : 2 ≤ e) :
I ^ e < I := by
convert I.pow_right_strictAnti hI0 hI1 he
dsimp only
rw [pow_one]
theorem Ideal.exists_mem_pow_not_mem_pow_succ (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) :
∃ x ∈ I ^ e, x ∉ I ^ (e + 1) :=
SetLike.exists_of_lt (I.pow_right_strictAnti hI0 hI1 e.lt_succ_self)
open UniqueFactorizationMonoid
theorem Ideal.eq_prime_pow_of_succ_lt_of_le {P I : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥)
{i : ℕ} (hlt : P ^ (i + 1) < I) (hle : I ≤ P ^ i) : I = P ^ i := by
refine le_antisymm hle ?_
have P_prime' := Ideal.prime_of_isPrime hP P_prime
have h1 : I ≠ ⊥ := (lt_of_le_of_lt bot_le hlt).ne'
have := pow_ne_zero i hP
have h3 := pow_ne_zero (i + 1) hP
rw [← Ideal.dvdNotUnit_iff_lt, dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors h1 h3,
normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible,
Multiset.nsmul_singleton, Multiset.lt_replicate_succ] at hlt
rw [← Ideal.dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_pow,
normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton]
all_goals assumption
theorem Ideal.pow_succ_lt_pow {P : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) (i : ℕ) :
P ^ (i + 1) < P ^ i :=
lt_of_le_of_ne (Ideal.pow_le_pow_right (Nat.le_succ _))
(mt (pow_inj_of_not_isUnit (mt Ideal.isUnit_iff.mp P_prime.ne_top) hP).mp i.succ_ne_self)
theorem Associates.le_singleton_iff (x : A) (n : ℕ) (I : Ideal A) :
Associates.mk I ^ n ≤ Associates.mk (Ideal.span {x}) ↔ x ∈ I ^ n := by
simp_rw [← Associates.dvd_eq_le, ← Associates.mk_pow, Associates.mk_dvd_mk,
Ideal.dvd_span_singleton]
variable {K}
lemma FractionalIdeal.le_inv_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) :
I ≤ J⁻¹ ↔ J ≤ I⁻¹ := by
rw [inv_eq, inv_eq, le_div_iff_mul_le hI, le_div_iff_mul_le hJ, mul_comm]
lemma FractionalIdeal.inv_le_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) :
I⁻¹ ≤ J ↔ J⁻¹ ≤ I := by
simpa using le_inv_comm (A := A) (K := K) (inv_ne_zero hI) (inv_ne_zero hJ)
open FractionalIdeal
/-- Strengthening of `IsLocalization.exist_integer_multiples`:
Let `J ≠ ⊤` be an ideal in a Dedekind domain `A`, and `f ≠ 0` a finite collection
of elements of `K = Frac(A)`, then we can multiply the elements of `f` by some `a : K`
to find a collection of elements of `A` that is not completely contained in `J`. -/
theorem Ideal.exist_integer_multiples_not_mem {J : Ideal A} (hJ : J ≠ ⊤) {ι : Type*} (s : Finset ι)
(f : ι → K) {j} (hjs : j ∈ s) (hjf : f j ≠ 0) :
∃ a : K,
(∀ i ∈ s, IsLocalization.IsInteger A (a * f i)) ∧
∃ i ∈ s, a * f i ∉ (J : FractionalIdeal A⁰ K) := by
-- Consider the fractional ideal `I` spanned by the `f`s.
let I : FractionalIdeal A⁰ K := spanFinset A s f
have hI0 : I ≠ 0 := spanFinset_ne_zero.mpr ⟨j, hjs, hjf⟩
-- We claim the multiplier `a` we're looking for is in `I⁻¹ \ (J / I)`.
suffices ↑J / I < I⁻¹ by
obtain ⟨_, a, hI, hpI⟩ := SetLike.lt_iff_le_and_exists.mp this
rw [mem_inv_iff hI0] at hI
refine ⟨a, fun i hi => ?_, ?_⟩
-- By definition, `a ∈ I⁻¹` multiplies elements of `I` into elements of `1`,
-- in other words, `a * f i` is an integer.
· exact (mem_one_iff _).mp (hI (f i) (Submodule.subset_span (Set.mem_image_of_mem f hi)))
· contrapose! hpI
-- And if all `a`-multiples of `I` are an element of `J`,
-- then `a` is actually an element of `J / I`, contradiction.
refine (mem_div_iff_of_nonzero hI0).mpr fun y hy => Submodule.span_induction ?_ ?_ ?_ ?_ hy
· rintro _ ⟨i, hi, rfl⟩; exact hpI i hi
· rw [mul_zero]; exact Submodule.zero_mem _
· intro x y _ _ hx hy; rw [mul_add]; exact Submodule.add_mem _ hx hy
· intro b x _ hx; rw [mul_smul_comm]; exact Submodule.smul_mem _ b hx
-- To show the inclusion of `J / I` into `I⁻¹ = 1 / I`, note that `J < I`.
calc
↑J / I = ↑J * I⁻¹ := div_eq_mul_inv (↑J) I
_ < 1 * I⁻¹ := mul_right_strictMono (inv_ne_zero hI0) ?_
_ = I⁻¹ := one_mul _
rw [← coeIdeal_top]
-- And multiplying by `I⁻¹` is indeed strictly monotone.
exact
strictMono_of_le_iff_le (fun _ _ => (coeIdeal_le_coeIdeal K).symm)
(lt_top_iff_ne_top.mpr hJ)
section Gcd
namespace Ideal
/-! ### GCD and LCM of ideals in a Dedekind domain
We show that the gcd of two ideals in a Dedekind domain is just their supremum,
and the lcm is their infimum, and use this to instantiate `NormalizedGCDMonoid (Ideal A)`.
-/
@[simp]
theorem sup_mul_inf (I J : Ideal A) : (I ⊔ J) * (I ⊓ J) = I * J := by
letI := UniqueFactorizationMonoid.toNormalizedGCDMonoid (Ideal A)
have hgcd : gcd I J = I ⊔ J := by
rw [gcd_eq_normalize _ _, normalize_eq]
· rw [dvd_iff_le, sup_le_iff, ← dvd_iff_le, ← dvd_iff_le]
exact ⟨gcd_dvd_left _ _, gcd_dvd_right _ _⟩
· rw [dvd_gcd_iff, dvd_iff_le, dvd_iff_le]
simp
have hlcm : lcm I J = I ⊓ J := by
rw [lcm_eq_normalize _ _, normalize_eq]
· rw [lcm_dvd_iff, dvd_iff_le, dvd_iff_le]
simp
· rw [dvd_iff_le, le_inf_iff, ← dvd_iff_le, ← dvd_iff_le]
exact ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩
rw [← hgcd, ← hlcm, associated_iff_eq.mp (gcd_mul_lcm _ _)]
/-- Ideals in a Dedekind domain have gcd and lcm operators that (trivially) are compatible with
the normalization operator. -/
instance : NormalizedGCDMonoid (Ideal A) :=
{ Ideal.normalizationMonoid with
gcd := (· ⊔ ·)
gcd_dvd_left := fun _ _ => by simpa only [dvd_iff_le] using le_sup_left
gcd_dvd_right := fun _ _ => by simpa only [dvd_iff_le] using le_sup_right
dvd_gcd := by
simp only [dvd_iff_le]
exact fun h1 h2 => @sup_le (Ideal A) _ _ _ _ h1 h2
lcm := (· ⊓ ·)
lcm_zero_left := fun _ => by simp only [zero_eq_bot, bot_inf_eq]
lcm_zero_right := fun _ => by simp only [zero_eq_bot, inf_bot_eq]
gcd_mul_lcm := fun _ _ => by rw [associated_iff_eq, sup_mul_inf]
normalize_gcd := fun _ _ => normalize_eq _
normalize_lcm := fun _ _ => normalize_eq _ }
-- In fact, any lawful gcd and lcm would equal sup and inf respectively.
@[simp]
theorem gcd_eq_sup (I J : Ideal A) : gcd I J = I ⊔ J := rfl
@[simp]
theorem lcm_eq_inf (I J : Ideal A) : lcm I J = I ⊓ J := rfl
theorem isCoprime_iff_gcd {I J : Ideal A} : IsCoprime I J ↔ gcd I J = 1 := by
rw [Ideal.isCoprime_iff_codisjoint, codisjoint_iff, one_eq_top, gcd_eq_sup]
theorem factors_span_eq {p : K[X]} : factors (span {p}) = (factors p).map (fun q ↦ span {q}) := by
rcases eq_or_ne p 0 with rfl | hp; · simpa [Set.singleton_zero] using normalizedFactors_zero
have : ∀ q ∈ (factors p).map (fun q ↦ span {q}), Prime q := fun q hq ↦ by
obtain ⟨r, hr, rfl⟩ := Multiset.mem_map.mp hq
exact prime_span_singleton_iff.mpr <| prime_of_factor r hr
rw [← span_singleton_eq_span_singleton.mpr (factors_prod hp), ← multiset_prod_span_singleton,
factors_eq_normalizedFactors, normalizedFactors_prod_of_prime this]
end Ideal
end Gcd
end IsDedekindDomain
section IsDedekindDomain
variable {T : Type*} [CommRing T] [IsDedekindDomain T] {I J : Ideal T}
open Multiset UniqueFactorizationMonoid Ideal
theorem prod_normalizedFactors_eq_self (hI : I ≠ ⊥) : (normalizedFactors I).prod = I :=
associated_iff_eq.1 (prod_normalizedFactors hI)
theorem count_le_of_ideal_ge [DecidableEq (Ideal T)]
{I J : Ideal T} (h : I ≤ J) (hI : I ≠ ⊥) (K : Ideal T) :
count K (normalizedFactors J) ≤ count K (normalizedFactors I) :=
le_iff_count.1 ((dvd_iff_normalizedFactors_le_normalizedFactors (ne_bot_of_le_ne_bot hI h) hI).1
(dvd_iff_le.2 h))
_
theorem sup_eq_prod_inf_factors [DecidableEq (Ideal T)] (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
I ⊔ J = (normalizedFactors I ∩ normalizedFactors J).prod := by
have H : normalizedFactors (normalizedFactors I ∩ normalizedFactors J).prod =
normalizedFactors I ∩ normalizedFactors J := by
apply normalizedFactors_prod_of_prime
intro p hp
rw [mem_inter] at hp
exact prime_of_normalized_factor p hp.left
have := Multiset.prod_ne_zero_of_prime (normalizedFactors I ∩ normalizedFactors J) fun _ h =>
prime_of_normalized_factor _ (Multiset.mem_inter.1 h).1
apply le_antisymm
· rw [sup_le_iff, ← dvd_iff_le, ← dvd_iff_le]
constructor
· rw [dvd_iff_normalizedFactors_le_normalizedFactors this hI, H]
exact inf_le_left
· rw [dvd_iff_normalizedFactors_le_normalizedFactors this hJ, H]
exact inf_le_right
· rw [← dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors,
normalizedFactors_prod_of_prime, le_iff_count]
· intro a
rw [Multiset.count_inter]
exact le_min (count_le_of_ideal_ge le_sup_left hI a) (count_le_of_ideal_ge le_sup_right hJ a)
· intro p hp
rw [mem_inter] at hp
exact prime_of_normalized_factor p hp.left
· exact ne_bot_of_le_ne_bot hI le_sup_left
· exact this
theorem irreducible_pow_sup [DecidableEq (Ideal T)] (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) :
J ^ n ⊔ I = J ^ min ((normalizedFactors I).count J) n := by
rw [sup_eq_prod_inf_factors (pow_ne_zero n hJ.ne_zero) hI, min_comm,
normalizedFactors_of_irreducible_pow hJ, normalize_eq J, replicate_inter, prod_replicate]
theorem irreducible_pow_sup_of_le (hJ : Irreducible J) (n : ℕ) (hn : n ≤ emultiplicity J I) :
J ^ n ⊔ I = J ^ n := by
classical
by_cases hI : I = ⊥
· simp_all
rw [irreducible_pow_sup hI hJ, min_eq_right]
rw [emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] at hn
exact_mod_cast hn
theorem irreducible_pow_sup_of_ge (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ)
(hn : emultiplicity J I ≤ n) : J ^ n ⊔ I = J ^ multiplicity J I := by
classical
rw [irreducible_pow_sup hI hJ, min_eq_left]
· congr
rw [← Nat.cast_inj (R := ℕ∞), ← FiniteMultiplicity.emultiplicity_eq_multiplicity,
emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J]
rw [← emultiplicity_lt_top]
apply hn.trans_lt
simp
· rw [emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] at hn
exact_mod_cast hn
theorem Ideal.eq_prime_pow_mul_coprime [DecidableEq (Ideal T)] {I : Ideal T} (hI : I ≠ ⊥)
(P : Ideal T) [hpm : P.IsMaximal] :
∃ Q : Ideal T, P ⊔ Q = ⊤ ∧ I = P ^ (Multiset.count P (normalizedFactors I)) * Q := by
use (filter (¬ P = ·) (normalizedFactors I)).prod
constructor
· refine P.sup_multiset_prod_eq_top (fun p hpi ↦ ?_)
have hp : Prime p := prime_of_normalized_factor p (filter_subset _ (normalizedFactors I) hpi)
exact hpm.coprime_of_ne ((isPrime_of_prime hp).isMaximal hp.ne_zero) (of_mem_filter hpi)
· nth_rw 1 [← prod_normalizedFactors_eq_self hI, ← filter_add_not (P = ·) (normalizedFactors I)]
rw [prod_add, pow_count]
end IsDedekindDomain
/-!
### Height one spectrum of a Dedekind domain
If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero
prime ideals.
We define `HeightOneSpectrum` and provide lemmas to recover the facts that prime ideals of height
one are prime and irreducible.
-/
namespace IsDedekindDomain
variable [IsDedekindDomain R]
/-- The height one prime spectrum of a Dedekind domain `R` is the type of nonzero prime ideals of
`R`. Note that this equals the maximal spectrum if `R` has Krull dimension 1. -/
@[ext, nolint unusedArguments]
structure HeightOneSpectrum where
asIdeal : Ideal R
isPrime : asIdeal.IsPrime
ne_bot : asIdeal ≠ ⊥
attribute [instance] HeightOneSpectrum.isPrime
variable (v : HeightOneSpectrum R) {R}
namespace HeightOneSpectrum
instance isMaximal : v.asIdeal.IsMaximal := v.isPrime.isMaximal v.ne_bot
theorem prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime
theorem irreducible : Irreducible v.asIdeal :=
UniqueFactorizationMonoid.irreducible_iff_prime.mpr v.prime
theorem associates_irreducible : Irreducible <| Associates.mk v.asIdeal :=
Associates.irreducible_mk.mpr v.irreducible
/-- An equivalence between the height one and maximal spectra for rings of Krull dimension 1. -/
def equivMaximalSpectrum (hR : ¬IsField R) : HeightOneSpectrum R ≃ MaximalSpectrum R where
toFun v := ⟨v.asIdeal, v.isPrime.isMaximal v.ne_bot⟩
invFun v :=
⟨v.asIdeal, v.isMaximal.isPrime, Ring.ne_bot_of_isMaximal_of_not_isField v.isMaximal hR⟩
left_inv := fun ⟨_, _, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
variable (R)
/-- A Dedekind domain is equal to the intersection of its localizations at all its height one
non-zero prime ideals viewed as subalgebras of its field of fractions. -/
theorem iInf_localization_eq_bot [Algebra R K] [hK : IsFractionRing R K] :
(⨅ v : HeightOneSpectrum R,
Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by
ext x
rw [Algebra.mem_iInf]
constructor
on_goal 1 => by_cases hR : IsField R
· rcases Function.bijective_iff_has_inverse.mp
(IsField.localization_map_bijective (Rₘ := K) (flip nonZeroDivisors.ne_zero rfl : 0 ∉ R⁰) hR)
with ⟨algebra_map_inv, _, algebra_map_right_inv⟩
exact fun _ => Algebra.mem_bot.mpr ⟨algebra_map_inv x, algebra_map_right_inv x⟩
all_goals rw [← MaximalSpectrum.iInf_localization_eq_bot, Algebra.mem_iInf]
· exact fun hx ⟨v, hv⟩ => hx ((equivMaximalSpectrum hR).symm ⟨v, hv⟩)
· exact fun hx ⟨v, hv, hbot⟩ => hx ⟨v, hv.isMaximal hbot⟩
end HeightOneSpectrum
end IsDedekindDomain
section
open Ideal
variable {R A}
variable [IsDedekindDomain A] {I : Ideal R} {J : Ideal A}
/-- The map from ideals of `R` dividing `I` to the ideals of `A` dividing `J` induced by
a homomorphism `f : R/I →+* A/J` -/
@[simps] -- Porting note: use `Subtype` instead of `Set` to make linter happy
def idealFactorsFunOfQuotHom {f : R ⧸ I →+* A ⧸ J} (hf : Function.Surjective f) :
{p : Ideal R // p ∣ I} →o {p : Ideal A // p ∣ J} where
toFun X := ⟨comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)), by
have : RingHom.ker (Ideal.Quotient.mk J) ≤
comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)) :=
ker_le_comap (Ideal.Quotient.mk J)
rw [mk_ker] at this
exact dvd_iff_le.mpr this⟩
monotone' := by
rintro ⟨X, hX⟩ ⟨Y, hY⟩ h
rw [← Subtype.coe_le_coe, Subtype.coe_mk, Subtype.coe_mk] at h ⊢
rw [Subtype.coe_mk, comap_le_comap_iff_of_surjective (Ideal.Quotient.mk J)
Ideal.Quotient.mk_surjective, map_le_iff_le_comap, Subtype.coe_mk,
comap_map_of_surjective _ hf (map (Ideal.Quotient.mk I) Y)]
suffices map (Ideal.Quotient.mk I) X ≤ map (Ideal.Quotient.mk I) Y by
exact le_sup_of_le_left this
rwa [map_le_iff_le_comap, comap_map_of_surjective (Ideal.Quotient.mk I)
Ideal.Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, mk_ker,
sup_eq_left.mpr <| le_of_dvd hY]
@[simp]
theorem idealFactorsFunOfQuotHom_id :
idealFactorsFunOfQuotHom (RingHom.id (A ⧸ J)).surjective = OrderHom.id :=
OrderHom.ext _ _
(funext fun X => by
simp only [idealFactorsFunOfQuotHom, map_id, OrderHom.coe_mk, OrderHom.id_coe, id,
comap_map_of_surjective (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective, ←
RingHom.ker_eq_comap_bot (Ideal.Quotient.mk J), mk_ker,
sup_eq_left.mpr (dvd_iff_le.mp X.prop), Subtype.coe_eta])
variable {B : Type*} [CommRing B] [IsDedekindDomain B] {L : Ideal B}
theorem idealFactorsFunOfQuotHom_comp {f : R ⧸ I →+* A ⧸ J} {g : A ⧸ J →+* B ⧸ L}
(hf : Function.Surjective f) (hg : Function.Surjective g) :
(idealFactorsFunOfQuotHom hg).comp (idealFactorsFunOfQuotHom hf) =
idealFactorsFunOfQuotHom (show Function.Surjective (g.comp f) from hg.comp hf) := by
refine OrderHom.ext _ _ (funext fun x => ?_)
rw [idealFactorsFunOfQuotHom, idealFactorsFunOfQuotHom, OrderHom.comp_coe, OrderHom.coe_mk,
OrderHom.coe_mk, Function.comp_apply, idealFactorsFunOfQuotHom, OrderHom.coe_mk,
Subtype.mk_eq_mk, Subtype.coe_mk, map_comap_of_surjective (Ideal.Quotient.mk J)
Ideal.Quotient.mk_surjective, map_map]
variable [IsDedekindDomain R] (f : R ⧸ I ≃+* A ⧸ J)
/-- The bijection between ideals of `R` dividing `I` and the ideals of `A` dividing `J` induced by
an isomorphism `f : R/I ≅ A/J`. -/
def idealFactorsEquivOfQuotEquiv : { p : Ideal R | p ∣ I } ≃o { p : Ideal A | p ∣ J } := by
have f_surj : Function.Surjective (f : R ⧸ I →+* A ⧸ J) := f.surjective
have fsym_surj : Function.Surjective (f.symm : A ⧸ J →+* R ⧸ I) := f.symm.surjective
refine OrderIso.ofHomInv (idealFactorsFunOfQuotHom f_surj) (idealFactorsFunOfQuotHom fsym_surj)
?_ ?_
· have := idealFactorsFunOfQuotHom_comp fsym_surj f_surj
simp only [RingEquiv.comp_symm, idealFactorsFunOfQuotHom_id] at this
rw [← this, OrderHom.coe_eq, OrderHom.coe_eq]
· have := idealFactorsFunOfQuotHom_comp f_surj fsym_surj
simp only [RingEquiv.symm_comp, idealFactorsFunOfQuotHom_id] at this
rw [← this, OrderHom.coe_eq, OrderHom.coe_eq]
theorem idealFactorsEquivOfQuotEquiv_symm :
(idealFactorsEquivOfQuotEquiv f).symm = idealFactorsEquivOfQuotEquiv f.symm := rfl
theorem idealFactorsEquivOfQuotEquiv_is_dvd_iso {L M : Ideal R} (hL : L ∣ I) (hM : M ∣ I) :
(idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ : Ideal A) ∣ idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ↔
L ∣ M := by
suffices
idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ≤ idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ ↔
(⟨M, hM⟩ : { p : Ideal R | p ∣ I }) ≤ ⟨L, hL⟩
by rw [dvd_iff_le, dvd_iff_le, Subtype.coe_le_coe, this, Subtype.mk_le_mk]
exact (idealFactorsEquivOfQuotEquiv f).le_iff_le
open UniqueFactorizationMonoid
theorem idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors (hJ : J ≠ ⊥)
{L : Ideal R} (hL : L ∈ normalizedFactors I) :
↑(idealFactorsEquivOfQuotEquiv f ⟨L, dvd_of_mem_normalizedFactors hL⟩)
∈ normalizedFactors J := by
have hI : I ≠ ⊥ := by
intro hI
rw [hI, bot_eq_zero, normalizedFactors_zero, ← Multiset.empty_eq_zero] at hL
exact Finset.not_mem_empty _ hL
refine mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors hI hJ hL
(d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_
rintro ⟨l, hl⟩ ⟨l', hl'⟩
rw [Subtype.coe_mk, Subtype.coe_mk]
apply idealFactorsEquivOfQuotEquiv_is_dvd_iso f
/-- The bijection between the sets of normalized factors of I and J induced by a ring
isomorphism `f : R/I ≅ A/J`. -/
def normalizedFactorsEquivOfQuotEquiv (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
{ L : Ideal R | L ∈ normalizedFactors I } ≃ { M : Ideal A | M ∈ normalizedFactors J } where
toFun j :=
⟨idealFactorsEquivOfQuotEquiv f ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩,
idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f hJ j.prop⟩
invFun j :=
⟨(idealFactorsEquivOfQuotEquiv f).symm ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, by
rw [idealFactorsEquivOfQuotEquiv_symm]
exact
idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f.symm hI
j.prop⟩
left_inv := fun ⟨j, hj⟩ => by simp
right_inv := fun ⟨j, hj⟩ => by simp [-Set.coe_setOf]
@[simp]
theorem normalizedFactorsEquivOfQuotEquiv_symm (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
(normalizedFactorsEquivOfQuotEquiv f hI hJ).symm =
normalizedFactorsEquivOfQuotEquiv f.symm hJ hI := rfl
/-- The map `normalizedFactorsEquivOfQuotEquiv` preserves multiplicities. -/
theorem normalizedFactorsEquivOfQuotEquiv_emultiplicity_eq_emultiplicity (hI : I ≠ ⊥) (hJ : J ≠ ⊥)
(L : Ideal R) (hL : L ∈ normalizedFactors I) :
emultiplicity (↑(normalizedFactorsEquivOfQuotEquiv f hI hJ ⟨L, hL⟩)) J = emultiplicity L I := by
rw [normalizedFactorsEquivOfQuotEquiv, Equiv.coe_fn_mk, Subtype.coe_mk]
refine emultiplicity_factor_dvd_iso_eq_emultiplicity_of_mem_normalizedFactors hI hJ hL
(d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_
exact fun ⟨l, hl⟩ ⟨l', hl'⟩ => idealFactorsEquivOfQuotEquiv_is_dvd_iso f hl hl'
end
section ChineseRemainder
open Ideal UniqueFactorizationMonoid
variable {R}
theorem Ring.DimensionLeOne.prime_le_prime_iff_eq [Ring.DimensionLEOne R] {P Q : Ideal R}
[hP : P.IsPrime] [hQ : Q.IsPrime] (hP0 : P ≠ ⊥) : P ≤ Q ↔ P = Q :=
⟨(hP.isMaximal hP0).eq_of_le hQ.ne_top, Eq.le⟩
theorem Ideal.coprime_of_no_prime_ge {I J : Ideal R} (h : ∀ P, I ≤ P → J ≤ P → ¬IsPrime P) :
| IsCoprime I J := by
rw [isCoprime_iff_sup_eq]
by_contra hIJ
obtain ⟨P, hP, hIJ⟩ := Ideal.exists_le_maximal _ hIJ
exact h P (le_trans le_sup_left hIJ) (le_trans le_sup_right hIJ) hP.isPrime
section DedekindDomain
| Mathlib/RingTheory/DedekindDomain/Ideal.lean | 1,149 | 1,156 |
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### mem -/
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
/-! ### bounded quantifiers over lists -/
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
/-! ### list subset -/
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### replicate -/
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [_], _ => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_getElem _).symm
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
map_map.symm
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self]
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction l with | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction l generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 1,381 | 1,382 | |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Jireh Loreaux
-/
import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Algebra.Group.Invertible.Basic
import Mathlib.Logic.Basic
import Mathlib.Data.Set.Basic
/-!
# Centers of magmas and semigroups
## Main definitions
* `Set.center`: the center of a magma
* `Set.addCenter`: the center of an additive magma
* `Set.centralizer`: the centralizer of a subset of a magma
* `Set.addCentralizer`: the centralizer of a subset of an additive magma
## See also
See `Mathlib.GroupTheory.Subsemigroup.Center` for the definition of the center as a subsemigroup:
* `Subsemigroup.center`: the center of a semigroup
* `AddSubsemigroup.center`: the center of an additive semigroup
We provide `Submonoid.center`, `AddSubmonoid.center`, `Subgroup.center`, `AddSubgroup.center`,
`Subsemiring.center`, and `Subring.center` in other files.
See `Mathlib.GroupTheory.Subsemigroup.Centralizer` for the definition of the centralizer
as a subsemigroup:
* `Subsemigroup.centralizer`: the centralizer of a subset of a semigroup
* `AddSubsemigroup.centralizer`: the centralizer of a subset of an additive semigroup
We provide `Monoid.centralizer`, `AddMonoid.centralizer`, `Subgroup.centralizer`, and
`AddSubgroup.centralizer` in other files.
-/
assert_not_exists RelIso Finset MonoidWithZero Subsemigroup
variable {M : Type*} {S T : Set M}
/-- Conditions for an element to be additively central -/
structure IsAddCentral [Add M] (z : M) : Prop where
/-- addition commutes -/
comm (a : M) : z + a = a + z
/-- associative property for left addition -/
left_assoc (b c : M) : z + (b + c) = (z + b) + c
/-- middle associative addition property -/
mid_assoc (a c : M) : (a + z) + c = a + (z + c)
/-- associative property for right addition -/
right_assoc (a b : M) : (a + b) + z = a + (b + z)
/-- Conditions for an element to be multiplicatively central -/
@[to_additive]
structure IsMulCentral [Mul M] (z : M) : Prop where
/-- multiplication commutes -/
comm (a : M) : z * a = a * z
/-- associative property for left multiplication -/
left_assoc (b c : M) : z * (b * c) = (z * b) * c
/-- middle associative multiplication property -/
mid_assoc (a c : M) : (a * z) * c = a * (z * c)
/-- associative property for right multiplication -/
right_assoc (a b : M) : (a * b) * z = a * (b * z)
attribute [mk_iff] IsMulCentral IsAddCentral
attribute [to_additive existing] isMulCentral_iff
namespace IsMulCentral
variable {a c : M} [Mul M]
-- cf. `Commute.left_comm`
@[to_additive]
protected theorem left_comm (h : IsMulCentral a) (b c) : a * (b * c) = b * (a * c) := by
simp only [h.comm, h.right_assoc]
-- cf. `Commute.right_comm`
@[to_additive]
protected theorem right_comm (h : IsMulCentral c) (a b) : a * b * c = a * c * b := by
simp only [h.right_assoc, h.mid_assoc, h.comm]
end IsMulCentral
namespace Set
/-! ### Center -/
section Mul
variable [Mul M]
variable (M) in
/-- The center of a magma. -/
@[to_additive addCenter " The center of an additive magma. "]
def center : Set M :=
{ z | IsMulCentral z }
variable (S) in
/-- The centralizer of a subset of a magma. -/
@[to_additive addCentralizer " The centralizer of a subset of an additive magma. "]
def centralizer : Set M := {c | ∀ m ∈ S, m * c = c * m}
@[to_additive mem_addCenter_iff]
theorem mem_center_iff {z : M} : z ∈ center M ↔ IsMulCentral z :=
Iff.rfl
@[to_additive mem_addCentralizer]
lemma mem_centralizer_iff {c : M} : c ∈ centralizer S ↔ ∀ m ∈ S, m * c = c * m := Iff.rfl
@[to_additive (attr := simp) add_mem_addCenter]
theorem mul_mem_center {z₁ z₂ : M} (hz₁ : z₁ ∈ Set.center M) (hz₂ : z₂ ∈ Set.center M) :
z₁ * z₂ ∈ Set.center M where
comm a := calc
z₁ * z₂ * a = z₂ * z₁ * a := by rw [hz₁.comm]
_ = z₂ * (z₁ * a) := by rw [hz₁.mid_assoc z₂]
_ = (a * z₁) * z₂ := by rw [hz₁.comm, hz₂.comm]
_ = a * (z₁ * z₂) := by rw [hz₂.right_assoc a z₁]
left_assoc (b c : M) := calc
z₁ * z₂ * (b * c) = z₁ * (z₂ * (b * c)) := by rw [hz₂.mid_assoc]
_ = z₁ * ((z₂ * b) * c) := by rw [hz₂.left_assoc]
_ = (z₁ * (z₂ * b)) * c := by rw [hz₁.left_assoc]
_ = z₁ * z₂ * b * c := by rw [hz₂.mid_assoc]
mid_assoc (a c : M) := calc
a * (z₁ * z₂) * c = ((a * z₁) * z₂) * c := by rw [hz₁.mid_assoc]
_ = (a * z₁) * (z₂ * c) := by rw [hz₂.mid_assoc]
_ = a * (z₁ * (z₂ * c)) := by rw [hz₁.mid_assoc]
_ = a * (z₁ * z₂ * c) := by rw [hz₂.mid_assoc]
right_assoc (a b : M) := calc
a * b * (z₁ * z₂) = ((a * b) * z₁) * z₂ := by rw [hz₂.right_assoc]
_ = (a * (b * z₁)) * z₂ := by rw [hz₁.right_assoc]
| _ = a * ((b * z₁) * z₂) := by rw [hz₂.right_assoc]
_ = a * (b * (z₁ * z₂)) := by rw [hz₁.mid_assoc]
@[to_additive addCenter_subset_addCentralizer]
| Mathlib/Algebra/Group/Center.lean | 131 | 134 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension
import Mathlib.Geometry.Manifold.ContMDiff.Atlas
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace
import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas
/-!
# Smooth bump functions on a smooth manifold
In this file we define `SmoothBumpFunction I c` to be a bundled smooth "bump" function centered at
`c`. It is a structure that consists of two real numbers `0 < rIn < rOut` with small enough `rOut`.
We define a coercion to function for this type, and for `f : SmoothBumpFunction I c`, the function
`⇑f` written in the extended chart at `c` has the following properties:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `c`;
* `0 ≤ f x ≤ 1` for all `x`.
The actual statements involve (pre)images under `extChartAt I f` and are given as lemmas in the
`SmoothBumpFunction` namespace.
## Tags
manifold, smooth bump function
-/
universe uE uF uH uM
variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E]
{H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M]
[ChartedSpace H M]
open Function Filter Module Set Metric
open scoped Topology Manifold ContDiff
noncomputable section
/-!
### Smooth bump function
In this section we define a structure for a bundled smooth bump function and prove its properties.
-/
variable (I) in
/-- Given a smooth manifold modelled on a finite dimensional space `E`,
`f : SmoothBumpFunction I M` is a smooth function on `M` such that in the extended chart `e` at
`f.c`:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `f.c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `f.c`;
* `0 ≤ f x ≤ 1` for all `x`.
The structure contains data required to construct a function with these properties. The function is
available as `⇑f` or `f x`. Formal statements of the properties listed above involve some
(pre)images under `extChartAt I f.c` and are given as lemmas in the `SmoothBumpFunction`
namespace. -/
structure SmoothBumpFunction (c : M) extends ContDiffBump (extChartAt I c c) where
closedBall_subset : closedBall (extChartAt I c c) rOut ∩ range I ⊆ (extChartAt I c).target
namespace SmoothBumpFunction
section FiniteDimensional
variable [FiniteDimensional ℝ E]
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
/-- The function defined by `f : SmoothBumpFunction c`. Use automatic coercion to function
instead. -/
@[coe] def toFun : M → ℝ :=
indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c)
instance : CoeFun (SmoothBumpFunction I c) fun _ => M → ℝ :=
⟨toFun⟩
theorem coe_def : ⇑f = indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) :=
rfl
end FiniteDimensional
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
theorem rOut_pos : 0 < f.rOut :=
f.toContDiffBump.rOut_pos
theorem ball_subset : ball (extChartAt I c c) f.rOut ∩ range I ⊆ (extChartAt I c).target :=
Subset.trans (inter_subset_inter_left _ ball_subset_closedBall) f.closedBall_subset
theorem ball_inter_range_eq_ball_inter_target :
ball (extChartAt I c c) f.rOut ∩ range I =
ball (extChartAt I c c) f.rOut ∩ (extChartAt I c).target :=
(subset_inter inter_subset_left f.ball_subset).antisymm <| inter_subset_inter_right _ <|
extChartAt_target_subset_range _
section FiniteDimensional
variable [FiniteDimensional ℝ E]
theorem eqOn_source : EqOn f (f.toContDiffBump ∘ extChartAt I c) (chartAt H c).source :=
eqOn_indicator
theorem eventuallyEq_of_mem_source (hx : x ∈ (chartAt H c).source) :
f =ᶠ[𝓝 x] f.toContDiffBump ∘ extChartAt I c :=
f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds hx
theorem one_of_dist_le (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) ≤ f.rIn) : f x = 1 := by
simp only [f.eqOn_source hs, (· ∘ ·), f.one_of_mem_closedBall hd]
theorem support_eq_inter_preimage :
support f = (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) f.rOut := by
rw [coe_def, support_indicator, support_comp_eq_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', ← (extChartAt I c).symm_image_target_inter_eq',
f.support_eq]
theorem isOpen_support : IsOpen (support f) := by
rw [support_eq_inter_preimage]
exact isOpen_extChartAt_preimage c isOpen_ball
theorem support_eq_symm_image :
support f = (extChartAt I c).symm '' (ball (extChartAt I c c) f.rOut ∩ range I) := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', inter_comm,
ball_inter_range_eq_ball_inter_target]
theorem support_subset_source : support f ⊆ (chartAt H c).source := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I]; exact inter_subset_left
theorem image_eq_inter_preimage_of_subset_support {s : Set M} (hs : s ⊆ support f) :
extChartAt I c '' s =
closedBall (extChartAt I c c) f.rOut ∩ range I ∩ (extChartAt I c).symm ⁻¹' s := by
rw [support_eq_inter_preimage, subset_inter_iff, ← extChartAt_source I, ← image_subset_iff] at hs
obtain ⟨hse, hsf⟩ := hs
apply Subset.antisymm
· refine subset_inter (subset_inter (hsf.trans ball_subset_closedBall) ?_) ?_
· rintro _ ⟨x, -, rfl⟩; exact mem_range_self _
· rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
exact inter_subset_right
· refine Subset.trans (inter_subset_inter_left _ f.closedBall_subset) ?_
rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
theorem mem_Icc : f x ∈ Icc (0 : ℝ) 1 := by
have : f x = 0 ∨ f x = _ := indicator_eq_zero_or_self _ _ _
rcases this with h | h <;> rw [h]
exacts [left_mem_Icc.2 zero_le_one, ⟨f.nonneg, f.le_one⟩]
theorem nonneg : 0 ≤ f x :=
f.mem_Icc.1
theorem le_one : f x ≤ 1 :=
f.mem_Icc.2
theorem eventuallyEq_one_of_dist_lt (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) < f.rIn) : f =ᶠ[𝓝 x] 1 := by
filter_upwards [IsOpen.mem_nhds (isOpen_extChartAt_preimage c isOpen_ball) ⟨hs, hd⟩]
rintro z ⟨hzs, hzd⟩
exact f.one_of_dist_le hzs <| le_of_lt hzd
theorem eventuallyEq_one : f =ᶠ[𝓝 c] 1 :=
f.eventuallyEq_one_of_dist_lt (mem_chart_source _ _) <| by rw [dist_self]; exact f.rIn_pos
@[simp]
theorem eq_one : f c = 1 :=
f.eventuallyEq_one.eq_of_nhds
|
theorem support_mem_nhds : support f ∈ 𝓝 c :=
| Mathlib/Geometry/Manifold/BumpFunction.lean | 170 | 171 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.Basis.Submodule
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Bases and matrices
This file defines the map `Basis.toMatrix` that sends a family of vectors to
the matrix of their coordinates with respect to some basis.
## Main definitions
* `Basis.toMatrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i`
* `basis.toMatrixEquiv` is `Basis.toMatrix` bundled as a linear equiv
## Main results
* `LinearMap.toMatrix_id_eq_basis_toMatrix`: `LinearMap.toMatrix b c id`
is equal to `Basis.toMatrix b c`
* `Basis.toMatrix_mul_toMatrix`: multiplying `Basis.toMatrix` with another
`Basis.toMatrix` gives a `Basis.toMatrix`
## Tags
matrix, basis
-/
noncomputable section
open LinearMap Matrix Set Submodule
open Matrix
section BasisToMatrix
variable {ι ι' κ κ' : Type*}
variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
variable {R₂ M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂]
open Function Matrix
/-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns
are the vectors `v i` written in the basis `e`. -/
def Basis.toMatrix (e : Basis ι R M) (v : ι' → M) : Matrix ι ι' R := fun i j => e.repr (v j) i
variable (e : Basis ι R M) (v : ι' → M) (i : ι) (j : ι')
namespace Basis
theorem toMatrix_apply : e.toMatrix v i j = e.repr (v j) i :=
rfl
theorem toMatrix_transpose_apply : (e.toMatrix v)ᵀ j = e.repr (v j) :=
funext fun _ => rfl
theorem toMatrix_eq_toMatrix_constr [Fintype ι] [DecidableEq ι] (v : ι → M) :
e.toMatrix v = LinearMap.toMatrix e e (e.constr ℕ v) := by
ext
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Basis.constr_basis]
-- TODO (maybe) Adjust the definition of `Basis.toMatrix` to eliminate the transpose.
theorem coePiBasisFun.toMatrix_eq_transpose [Finite ι] :
((Pi.basisFun R ι).toMatrix : Matrix ι ι R → Matrix ι ι R) = Matrix.transpose := by
ext M i j
rfl
@[simp]
theorem toMatrix_self [DecidableEq ι] : e.toMatrix e = 1 := by
unfold Basis.toMatrix
ext i j
simp [Basis.equivFun, Matrix.one_apply, Finsupp.single_apply, eq_comm]
theorem toMatrix_update [DecidableEq ι'] (x : M) :
e.toMatrix (Function.update v j x) = Matrix.updateCol (e.toMatrix v) j (e.repr x) := by
ext i' k
rw [Basis.toMatrix, Matrix.updateCol_apply, e.toMatrix_apply]
split_ifs with h
· rw [h, update_self j x v]
· rw [update_of_ne h]
/-- The basis constructed by `unitsSMul` has vectors given by a diagonal matrix. -/
@[simp]
theorem toMatrix_unitsSMul [DecidableEq ι] (e : Basis ι R₂ M₂) (w : ι → R₂ˣ) :
e.toMatrix (e.unitsSMul w) = diagonal ((↑) ∘ w) := by
ext i j
by_cases h : i = j
· simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def]
· simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def, Ne.symm h]
/-- The basis constructed by `isUnitSMul` has vectors given by a diagonal matrix. -/
@[simp]
theorem toMatrix_isUnitSMul [DecidableEq ι] (e : Basis ι R₂ M₂) {w : ι → R₂}
(hw : ∀ i, IsUnit (w i)) : e.toMatrix (e.isUnitSMul hw) = diagonal w :=
e.toMatrix_unitsSMul _
theorem toMatrix_smul_left {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) :
(g • e).toMatrix v = e.toMatrix (g⁻¹ • v) := rfl
@[simp]
theorem sum_toMatrix_smul_self [Fintype ι] : ∑ i : ι, e.toMatrix v i j • e i = v j := by
simp_rw [e.toMatrix_apply, e.sum_repr]
theorem toMatrix_smul {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S] [Fintype ι]
[DecidableEq ι] (x : S) (b : Basis ι R₁ S) (w : ι → S) :
(b.toMatrix (x • w)) = (Algebra.leftMulMatrix b x) * (b.toMatrix w) := by
ext
rw [Basis.toMatrix_apply, Pi.smul_apply, smul_eq_mul, ← Algebra.leftMulMatrix_mulVec_repr]
rfl
theorem toMatrix_map_vecMul {S : Type*} [Semiring S] [Algebra R S] [Fintype ι] (b : Basis ι R S)
(v : ι' → S) : b ᵥ* ((b.toMatrix v).map <| algebraMap R S) = v := by
ext i
simp_rw [vecMul, dotProduct, Matrix.map_apply, ← Algebra.commutes, ← Algebra.smul_def,
sum_toMatrix_smul_self]
@[simp]
theorem toLin_toMatrix [Finite ι] [Fintype ι'] [DecidableEq ι'] (v : Basis ι' R M) :
| Matrix.toLin v e (e.toMatrix v) = LinearMap.id :=
v.ext fun i => by cases nonempty_fintype ι; rw [toLin_self, id_apply, e.sum_toMatrix_smul_self]
/-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`,
and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/
| Mathlib/LinearAlgebra/Matrix/Basis.lean | 124 | 128 |
/-
Copyright (c) 2022 Apurva Nakade. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Apurva Nakade
-/
import Mathlib.Analysis.Convex.Cone.Closure
import Mathlib.Analysis.InnerProductSpace.Adjoint
/-!
# Proper cones
We define a *proper cone* as a closed, pointed cone. Proper cones are used in defining conic
programs which generalize linear programs. A linear program is a conic program for the positive
cone. We then prove Farkas' lemma for conic programs following the proof in the reference below.
Farkas' lemma is equivalent to strong duality. So, once we have the definitions of conic and
linear programs, the results from this file can be used to prove duality theorems.
## TODO
The next steps are:
- Add convex_cone_class that extends set_like and replace the below instance
- Define primal and dual cone programs and prove weak duality.
- Prove regular and strong duality for cone programs using Farkas' lemma (see reference).
- Define linear programs and prove LP duality as a special case of cone duality.
- Find a better reference (textbook instead of lecture notes).
## References
- [B. Gartner and J. Matousek, Cone Programming][gartnerMatousek]
-/
open ContinuousLinearMap Filter Set
/-- A proper cone is a pointed cone `K` that is closed. Proper cones have the nice property that
they are equal to their double dual, see `ProperCone.dual_dual`.
This makes them useful for defining cone programs and proving duality theorems. -/
structure ProperCone (𝕜 : Type*) (E : Type*)
[Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] [AddCommMonoid E]
[TopologicalSpace E] [Module 𝕜 E] extends Submodule {c : 𝕜 // 0 ≤ c} E where
isClosed' : IsClosed (carrier : Set E)
namespace ProperCone
section Module
variable {𝕜 : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜]
variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E]
/-- A `PointedCone` is defined as an alias of submodule. We replicate the abbreviation here and
define `toPointedCone` as an alias of `toSubmodule`. -/
abbrev toPointedCone (C : ProperCone 𝕜 E) := C.toSubmodule
attribute [coe] toPointedCone
instance : Coe (ProperCone 𝕜 E) (PointedCone 𝕜 E) :=
⟨toPointedCone⟩
theorem toPointedCone_injective : Function.Injective ((↑) : ProperCone 𝕜 E → PointedCone 𝕜 E) :=
fun S T h => by cases S; cases T; congr
-- TODO: add `ConvexConeClass` that extends `SetLike` and replace the below instance
instance : SetLike (ProperCone 𝕜 E) E where
coe K := K.carrier
coe_injective' _ _ h := ProperCone.toPointedCone_injective (SetLike.coe_injective h)
@[ext]
theorem ext {S T : ProperCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem mem_coe {x : E} {K : ProperCone 𝕜 E} : x ∈ (K : PointedCone 𝕜 E) ↔ x ∈ K :=
Iff.rfl
instance instZero (K : ProperCone 𝕜 E) : Zero K := PointedCone.instZero (K.toSubmodule)
protected theorem nonempty (K : ProperCone 𝕜 E) : (K : Set E).Nonempty :=
⟨0, by { simp_rw [SetLike.mem_coe, ← ProperCone.mem_coe, Submodule.zero_mem] }⟩
protected theorem isClosed (K : ProperCone 𝕜 E) : IsClosed (K : Set E) :=
K.isClosed'
end Module
section PositiveCone
variable (𝕜 E)
variable [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜]
[AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E]
[TopologicalSpace E] [OrderClosedTopology E]
/-- The positive cone is the proper cone formed by the set of nonnegative elements in an ordered
module. -/
def positive : ProperCone 𝕜 E where
toSubmodule := PointedCone.positive 𝕜 E
isClosed' := isClosed_Ici
@[simp]
theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x :=
Iff.rfl
@[simp]
theorem coe_positive : ↑(positive 𝕜 E) = ConvexCone.positive 𝕜 E :=
rfl
end PositiveCone
section Module
variable {𝕜 : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜]
variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [T1Space E] [Module 𝕜 E]
instance : Zero (ProperCone 𝕜 E) :=
⟨{ toSubmodule := 0
isClosed' := isClosed_singleton }⟩
instance : Inhabited (ProperCone 𝕜 E) :=
⟨0⟩
@[simp]
theorem mem_zero (x : E) : x ∈ (0 : ProperCone 𝕜 E) ↔ x = 0 :=
Iff.rfl
@[simp, norm_cast]
theorem coe_zero : ↑(0 : ProperCone 𝕜 E) = (0 : ConvexCone 𝕜 E) :=
rfl
theorem pointed_zero : ((0 : ProperCone 𝕜 E) : ConvexCone 𝕜 E).Pointed := by
simp [ConvexCone.pointed_zero]
end Module
section InnerProductSpace
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace ℝ G]
protected theorem pointed (K : ProperCone ℝ E) : (K : ConvexCone ℝ E).Pointed :=
(K : ConvexCone ℝ E).pointed_of_nonempty_of_isClosed K.nonempty K.isClosed
/-- The closure of image of a proper cone under a continuous `ℝ`-linear map is a proper cone. We
use continuous maps here so that the comap of f is also a map between proper cones. -/
noncomputable def map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ProperCone ℝ F where
toSubmodule := PointedCone.closure (PointedCone.map (f : E →ₗ[ℝ] F) ↑K)
isClosed' := isClosed_closure
@[simp, norm_cast]
theorem coe_map (f : E →L[ℝ] F) (K : ProperCone ℝ E) :
↑(K.map f) = (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure :=
rfl
@[simp]
theorem mem_map {f : E →L[ℝ] F} {K : ProperCone ℝ E} {y : F} :
y ∈ K.map f ↔ y ∈ (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure :=
Iff.rfl
@[simp]
theorem map_id (K : ProperCone ℝ E) : K.map (ContinuousLinearMap.id ℝ E) = K :=
ProperCone.toPointedCone_injective <| by simpa using IsClosed.closure_eq K.isClosed
/-- The inner dual cone of a proper cone is a proper cone. -/
def dual (K : ProperCone ℝ E) : ProperCone ℝ E where
toSubmodule := PointedCone.dual (K : PointedCone ℝ E)
isClosed' := isClosed_innerDualCone _
@[simp, norm_cast]
theorem coe_dual (K : ProperCone ℝ E) : K.dual = (K : Set E).innerDualCone :=
rfl
open scoped InnerProductSpace in
@[simp]
theorem mem_dual {K : ProperCone ℝ E} {y : E} : y ∈ dual K ↔ ∀ ⦃x⦄, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ := by
aesop
/-- The preimage of a proper cone under a continuous `ℝ`-linear map is a proper cone. -/
noncomputable def comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : ProperCone ℝ E where
toSubmodule := PointedCone.comap (f : E →ₗ[ℝ] F) S
isClosed' := by
rw [PointedCone.comap]
apply IsClosed.preimage f.2 S.isClosed
@[simp]
theorem coe_comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : (S.comap f : Set E) = f ⁻¹' S :=
rfl
@[simp]
theorem comap_id (S : ConvexCone ℝ E) : S.comap LinearMap.id = S :=
SetLike.coe_injective preimage_id
theorem comap_comap (g : F →L[ℝ] G) (f : E →L[ℝ] F) (S : ProperCone ℝ G) :
(S.comap g).comap f = S.comap (g.comp f) :=
SetLike.coe_injective <| by congr
@[simp]
theorem mem_comap {f : E →L[ℝ] F} {S : ProperCone ℝ F} {x : E} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
end InnerProductSpace
section CompleteSpace
open scoped InnerProductSpace
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E]
variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F]
/-- The dual of the dual of a proper cone is itself. -/
@[simp]
theorem dual_dual (K : ProperCone ℝ E) : K.dual.dual = K :=
ProperCone.toPointedCone_injective <| PointedCone.toConvexCone_injective <|
(K : ConvexCone ℝ E).innerDualCone_of_innerDualCone_eq_self K.nonempty K.isClosed
/-- This is a relative version of
`ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`, which we recover by setting
`f` to be the identity map. This is also a geometric interpretation of the Farkas' lemma
stated using proper cones. -/
theorem hyperplane_separation (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} :
b ∈ K.map f ↔ ∀ y : F, adjoint f y ∈ K.dual → 0 ≤ ⟪y, b⟫_ℝ :=
Iff.intro
(by
-- suppose `b ∈ K.map f`
simp_rw [mem_map, PointedCone.mem_closure, PointedCone.coe_map, coe_coe,
mem_closure_iff_seq_limit, mem_image, SetLike.mem_coe, mem_coe, mem_dual,
adjoint_inner_right, forall_exists_index, and_imp]
-- there is a sequence `seq : ℕ → F` in the image of `f` that converges to `b`
rintro seq hmem htends y hinner
suffices h : ∀ n, 0 ≤ ⟪y, seq n⟫_ℝ from
ge_of_tendsto'
(Continuous.seqContinuous (Continuous.inner (@continuous_const _ _ _ _ y) continuous_id)
htends)
h
intro n
obtain ⟨_, h, hseq⟩ := hmem n
simpa only [← hseq, real_inner_comm] using hinner h)
(by
-- proof by contradiction
-- suppose `b ∉ K.map f`
intro h
contrapose! h
-- as `b ∉ K.map f`, there is a hyperplane `y` separating `b` from `K.map f`
| let C := PointedCone.toConvexCone (𝕜 := ℝ) (E := F) (K.map f)
obtain ⟨y, hxy, hyb⟩ :=
@ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem
_ _ _ _ C (K.map f).nonempty (K.map f).isClosed b h
-- the rest of the proof is a straightforward algebraic manipulation
refine ⟨y, ?_, hyb⟩
simp_rw [ProperCone.mem_dual, adjoint_inner_right]
intro x hxK
apply hxy (f x)
simp_rw [C, coe_map]
apply subset_closure
simp_rw [PointedCone.toConvexCone_map, ConvexCone.coe_map, coe_coe, mem_image,
SetLike.mem_coe]
exact ⟨x, hxK, rfl⟩)
theorem hyperplane_separation_of_nmem (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F}
(disj : b ∉ K.map f) : ∃ y : F, adjoint f y ∈ K.dual ∧ ⟪y, b⟫_ℝ < 0 := by
contrapose! disj; rwa [K.hyperplane_separation]
end CompleteSpace
end ProperCone
| Mathlib/Analysis/Convex/Cone/Proper.lean | 243 | 283 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Set.Countable
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Tactic.FunProp.Attr
import Mathlib.Tactic.Measurability
/-!
# Measurable spaces and measurable functions
This file defines measurable spaces and measurable functions.
A measurable space is a set equipped with a σ-algebra, a collection of
subsets closed under complementation and countable union. A function
between measurable spaces is measurable if the preimage of each
measurable subset is measurable.
σ-algebras on a fixed set `α` form a complete lattice. Here we order
σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is
also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any
collection of subsets of `α` generates a smallest σ-algebra which
contains all of them.
## References
* <https://en.wikipedia.org/wiki/Measurable_space>
* <https://en.wikipedia.org/wiki/Sigma-algebra>
* <https://en.wikipedia.org/wiki/Dynkin_system>
## Tags
measurable space, σ-algebra, measurable function
-/
assert_not_exists Covariant MonoidWithZero
open Set Encodable Function Equiv
variable {α β γ δ δ' : Type*} {ι : Sort*} {s t u : Set α}
/-- A measurable space is a space equipped with a σ-algebra. -/
@[class] structure MeasurableSpace (α : Type*) where
/-- Predicate saying that a given set is measurable. Use `MeasurableSet` in the root namespace
instead. -/
MeasurableSet' : Set α → Prop
/-- The empty set is a measurable set. Use `MeasurableSet.empty` instead. -/
measurableSet_empty : MeasurableSet' ∅
/-- The complement of a measurable set is a measurable set. Use `MeasurableSet.compl` instead. -/
measurableSet_compl : ∀ s, MeasurableSet' s → MeasurableSet' sᶜ
/-- The union of a sequence of measurable sets is a measurable set. Use a more general
`MeasurableSet.iUnion` instead. -/
measurableSet_iUnion : ∀ f : ℕ → Set α, (∀ i, MeasurableSet' (f i)) → MeasurableSet' (⋃ i, f i)
instance [h : MeasurableSpace α] : MeasurableSpace αᵒᵈ := h
/-- `MeasurableSet s` means that `s` is measurable (in the ambient measure space on `α`) -/
def MeasurableSet [MeasurableSpace α] (s : Set α) : Prop :=
‹MeasurableSpace α›.MeasurableSet' s
/-- Notation for `MeasurableSet` with respect to a non-standard σ-algebra. -/
scoped[MeasureTheory] notation "MeasurableSet[" m "]" => @MeasurableSet _ m
open MeasureTheory
section
open scoped symmDiff
@[simp, measurability]
theorem MeasurableSet.empty [MeasurableSpace α] : MeasurableSet (∅ : Set α) :=
MeasurableSpace.measurableSet_empty _
variable {m : MeasurableSpace α}
@[measurability]
protected theorem MeasurableSet.compl : MeasurableSet s → MeasurableSet sᶜ :=
MeasurableSpace.measurableSet_compl _ s
protected theorem MeasurableSet.of_compl (h : MeasurableSet sᶜ) : MeasurableSet s :=
compl_compl s ▸ h.compl
@[simp]
theorem MeasurableSet.compl_iff : MeasurableSet sᶜ ↔ MeasurableSet s :=
⟨.of_compl, .compl⟩
@[simp, measurability]
protected theorem MeasurableSet.univ : MeasurableSet (univ : Set α) :=
.of_compl <| by simp
@[nontriviality, measurability]
theorem Subsingleton.measurableSet [Subsingleton α] {s : Set α} : MeasurableSet s :=
Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s
theorem MeasurableSet.congr {s t : Set α} (hs : MeasurableSet s) (h : s = t) : MeasurableSet t := by
rwa [← h]
@[measurability]
protected theorem MeasurableSet.iUnion [Countable ι] ⦃f : ι → Set α⦄
(h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋃ b, f b) := by
cases isEmpty_or_nonempty ι
· simp
· rcases exists_surjective_nat ι with ⟨e, he⟩
rw [← iUnion_congr_of_surjective _ he (fun _ => rfl)]
exact m.measurableSet_iUnion _ fun _ => h _
protected theorem MeasurableSet.biUnion {f : β → Set α} {s : Set β} (hs : s.Countable)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) := by
rw [biUnion_eq_iUnion]
have := hs.to_subtype
exact MeasurableSet.iUnion (by simpa using h)
theorem Set.Finite.measurableSet_biUnion {f : β → Set α} {s : Set β} (hs : s.Finite)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) :=
.biUnion hs.countable h
theorem Finset.measurableSet_biUnion {f : β → Set α} (s : Finset β)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) :=
s.finite_toSet.measurableSet_biUnion h
protected theorem MeasurableSet.sUnion {s : Set (Set α)} (hs : s.Countable)
(h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋃₀ s) := by
rw [sUnion_eq_biUnion]
exact .biUnion hs h
theorem Set.Finite.measurableSet_sUnion {s : Set (Set α)} (hs : s.Finite)
(h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋃₀ s) :=
MeasurableSet.sUnion hs.countable h
@[measurability]
theorem MeasurableSet.iInter [Countable ι] {f : ι → Set α} (h : ∀ b, MeasurableSet (f b)) :
MeasurableSet (⋂ b, f b) :=
.of_compl <| by rw [compl_iInter]; exact .iUnion fun b => (h b).compl
theorem MeasurableSet.biInter {f : β → Set α} {s : Set β} (hs : s.Countable)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) :=
.of_compl <| by rw [compl_iInter₂]; exact .biUnion hs fun b hb => (h b hb).compl
theorem Set.Finite.measurableSet_biInter {f : β → Set α} {s : Set β} (hs : s.Finite)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) :=
.biInter hs.countable h
theorem Finset.measurableSet_biInter {f : β → Set α} (s : Finset β)
(h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋂ b ∈ s, f b) :=
s.finite_toSet.measurableSet_biInter h
theorem MeasurableSet.sInter {s : Set (Set α)} (hs : s.Countable) (h : ∀ t ∈ s, MeasurableSet t) :
MeasurableSet (⋂₀ s) := by
rw [sInter_eq_biInter]
exact MeasurableSet.biInter hs h
theorem Set.Finite.measurableSet_sInter {s : Set (Set α)} (hs : s.Finite)
(h : ∀ t ∈ s, MeasurableSet t) : MeasurableSet (⋂₀ s) :=
MeasurableSet.sInter hs.countable h
@[simp, measurability]
protected theorem MeasurableSet.union {s₁ s₂ : Set α} (h₁ : MeasurableSet s₁)
(h₂ : MeasurableSet s₂) : MeasurableSet (s₁ ∪ s₂) := by
rw [union_eq_iUnion]
| exact .iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
@[simp, measurability]
| Mathlib/MeasureTheory/MeasurableSpace/Defs.lean | 162 | 164 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice.Prod
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Set.Lattice.Image
/-!
# N-ary images of finsets
This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of
`Set.image2`. This is mostly useful to define pointwise operations.
## Notes
This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please
keep them in sync.
We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂`
and `Set.image2` already fulfills this task.
-/
open Function Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*}
namespace Finset
variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ']
[DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ}
{s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ}
/-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ :=
(s ×ˢ t).image <| uncurry f
@[simp]
theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by
simp [image₂, and_assoc]
@[simp, norm_cast]
theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) :
(image₂ f s t : Set γ) = Set.image2 f s t :=
Set.ext fun _ => mem_image₂
theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) :
#(image₂ f s t) ≤ #s * #t :=
card_image_le.trans_eq <| card_product _ _
theorem card_image₂_iff :
#(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by
rw [← card_product, ← coe_product]
exact card_image_iff
theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) :
#(image₂ f s t) = #s * #t :=
(card_image_of_injective _ hf.uncurry).trans <| card_product _ _
theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t :=
mem_image₂.2 ⟨a, ha, b, hb, rfl⟩
theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by
rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe]
@[gcongr]
theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by
rw [← coe_subset, coe_image₂, coe_image₂]
exact image2_subset hs ht
@[gcongr]
theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' :=
image₂_subset Subset.rfl ht
@[gcongr]
theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t :=
image₂_subset hs Subset.rfl
theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb
theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ => mem_image₂_of_mem ha
lemma forall_mem_image₂ {p : γ → Prop} :
(∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, forall_mem_image2]
lemma exists_mem_image₂ {p : γ → Prop} :
(∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, exists_mem_image2]
@[deprecated (since := "2024-11-23")] alias forall_image₂_iff := forall_mem_image₂
@[simp]
theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image₂
theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff]
theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α]
@[simp]
theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
rw [← coe_nonempty, coe_image₂]
exact image2_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty :=
image₂_nonempty_iff.2 ⟨hs, ht⟩
theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty :=
(image₂_nonempty_iff.1 h).1
theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty :=
(image₂_nonempty_iff.1 h).2
@[simp]
theorem image₂_empty_left : image₂ f ∅ t = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_empty_right : image₂ f s ∅ = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or]
@[simp]
theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b :=
ext fun x => by simp
@[simp]
theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b :=
ext fun x => by simp
theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) :=
image₂_singleton_left
theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp
theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_union_left
theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_union_right
@[simp]
theorem image₂_insert_left [DecidableEq α] :
image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_left
@[simp]
theorem image₂_insert_right [DecidableEq β] :
image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_right
theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) :
image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_inter_left hf
theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) :
image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_inter_right hf
theorem image₂_inter_subset_left [DecidableEq α] :
image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_left
theorem image₂_inter_subset_right [DecidableEq β] :
image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_right
theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
coe_injective <| by
push_cast
exact image2_congr h
/-- A common special case of `image₂_congr` -/
theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
image₂_congr fun a _ b _ => h a b
variable (s t)
theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by
rw [image₂_singleton_left, card_image_of_injective _ hf]
theorem card_image₂_singleton_right (hf : Injective fun a => f a b) :
#(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf]
theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) :
image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by
simp_rw [image₂_singleton_left, image_inter _ _ hf]
|
theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) :
image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by
simp_rw [image₂_singleton_right, image_inter _ _ hf]
| Mathlib/Data/Finset/NAry.lean | 215 | 219 |
/-
Copyright (c) 2022 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang
-/
import Mathlib.Topology.MetricSpace.Antilipschitz
import Mathlib.Topology.MetricSpace.Isometry
import Mathlib.Topology.MetricSpace.Lipschitz
import Mathlib.Data.FunLike.Basic
/-!
# Dilations
We define dilations, i.e., maps between emetric spaces that satisfy
`edist (f x) (f y) = r * edist x y` for some `r ∉ {0, ∞}`.
The value `r = 0` is not allowed because we want dilations of (e)metric spaces to be automatically
injective. The value `r = ∞` is not allowed because this way we can define `Dilation.ratio f : ℝ≥0`,
not `Dilation.ratio f : ℝ≥0∞`. Also, we do not often need maps sending distinct points to points at
infinite distance.
## Main definitions
* `Dilation.ratio f : ℝ≥0`: the value of `r` in the relation above, defaulting to 1 in the case
where it is not well-defined.
## Notation
- `α →ᵈ β`: notation for `Dilation α β`.
## Implementation notes
The type of dilations defined in this file are also referred to as "similarities" or "similitudes"
by other authors. The name `Dilation` was chosen to match the Wikipedia name.
Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the
theory for `PseudoEMetricSpace` and we specialize to `PseudoMetricSpace` and `MetricSpace` when
needed.
## TODO
- Introduce dilation equivs.
- Refactor the `Isometry` API to match the `*HomClass` API below.
## References
- https://en.wikipedia.org/wiki/Dilation_(metric_space)
- [Marcel Berger, *Geometry*][berger1987]
-/
noncomputable section
open Bornology Function Set Topology
open scoped ENNReal NNReal
section Defs
variable (α : Type*) (β : Type*) [PseudoEMetricSpace α] [PseudoEMetricSpace β]
/-- A dilation is a map that uniformly scales the edistance between any two points. -/
structure Dilation where
toFun : α → β
edist_eq' : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, edist (toFun x) (toFun y) = r * edist x y
@[inherit_doc] infixl:25 " →ᵈ " => Dilation
/-- `DilationClass F α β r` states that `F` is a type of `r`-dilations.
You should extend this typeclass when you extend `Dilation`. -/
class DilationClass (F : Type*) (α β : outParam Type*) [PseudoEMetricSpace α] [PseudoEMetricSpace β]
[FunLike F α β] : Prop where
edist_eq' : ∀ f : F, ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, edist (f x) (f y) = r * edist x y
end Defs
namespace Dilation
variable {α : Type*} {β : Type*} {γ : Type*} {F : Type*}
section Setup
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β]
instance funLike : FunLike (α →ᵈ β) α β where
coe := toFun
coe_injective' f g h := by cases f; cases g; congr
instance toDilationClass : DilationClass (α →ᵈ β) α β where
edist_eq' f := edist_eq' f
@[simp]
theorem toFun_eq_coe {f : α →ᵈ β} : f.toFun = (f : α → β) :=
rfl
@[simp]
theorem coe_mk (f : α → β) (h) : ⇑(⟨f, h⟩ : α →ᵈ β) = f :=
rfl
protected theorem congr_fun {f g : α →ᵈ β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
protected theorem congr_arg (f : α →ᵈ β) {x y : α} (h : x = y) : f x = f y :=
DFunLike.congr_arg f h
@[ext]
theorem ext {f g : α →ᵈ β} (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp]
theorem mk_coe (f : α →ᵈ β) (h) : Dilation.mk f h = f :=
ext fun _ => rfl
/-- Copy of a `Dilation` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
@[simps -fullyApplied]
protected def copy (f : α →ᵈ β) (f' : α → β) (h : f' = ⇑f) : α →ᵈ β where
toFun := f'
edist_eq' := h.symm ▸ f.edist_eq'
theorem copy_eq_self (f : α →ᵈ β) {f' : α → β} (h : f' = f) : f.copy f' h = f :=
DFunLike.ext' h
variable [FunLike F α β]
open Classical in
/-- The ratio of a dilation `f`. If the ratio is undefined (i.e., the distance between any two
points in `α` is either zero or infinity), then we choose one as the ratio. -/
def ratio [DilationClass F α β] (f : F) : ℝ≥0 :=
if ∀ x y : α, edist x y = 0 ∨ edist x y = ⊤ then 1 else (DilationClass.edist_eq' f).choose
theorem ratio_of_trivial [DilationClass F α β] (f : F)
(h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞) : ratio f = 1 :=
if_pos h
@[nontriviality]
theorem ratio_of_subsingleton [Subsingleton α] [DilationClass F α β] (f : F) : ratio f = 1 :=
if_pos fun x y ↦ by simp [Subsingleton.elim x y]
theorem ratio_ne_zero [DilationClass F α β] (f : F) : ratio f ≠ 0 := by
rw [ratio]; split_ifs
· exact one_ne_zero
exact (DilationClass.edist_eq' f).choose_spec.1
theorem ratio_pos [DilationClass F α β] (f : F) : 0 < ratio f :=
(ratio_ne_zero f).bot_lt
@[simp]
theorem edist_eq [DilationClass F α β] (f : F) (x y : α) :
edist (f x) (f y) = ratio f * edist x y := by
rw [ratio]; split_ifs with key
· rcases DilationClass.edist_eq' f with ⟨r, hne, hr⟩
replace hr := hr x y
rcases key x y with h | h
· simp only [hr, h, mul_zero]
· simp [hr, h, hne]
exact (DilationClass.edist_eq' f).choose_spec.2 x y
@[simp]
theorem nndist_eq {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β]
[DilationClass F α β] (f : F) (x y : α) :
nndist (f x) (f y) = ratio f * nndist x y := by
simp only [← ENNReal.coe_inj, ← edist_nndist, ENNReal.coe_mul, edist_eq]
@[simp]
theorem dist_eq {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β] [FunLike F α β]
[DilationClass F α β] (f : F) (x y : α) :
dist (f x) (f y) = ratio f * dist x y := by
simp only [dist_nndist, nndist_eq, NNReal.coe_mul]
/-- The `ratio` is equal to the distance ratio for any two points with nonzero finite distance.
`dist` and `nndist` versions below -/
theorem ratio_unique [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (h₀ : edist x y ≠ 0)
(htop : edist x y ≠ ⊤) (hr : edist (f x) (f y) = r * edist x y) : r = ratio f := by
simpa only [hr, ENNReal.mul_left_inj h₀ htop, ENNReal.coe_inj] using edist_eq f x y
/-- The `ratio` is equal to the distance ratio for any two points
with nonzero finite distance; `nndist` version -/
theorem ratio_unique_of_nndist_ne_zero {α β F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β]
[FunLike F α β] [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (hxy : nndist x y ≠ 0)
(hr : nndist (f x) (f y) = r * nndist x y) : r = ratio f :=
ratio_unique (by rwa [edist_nndist, ENNReal.coe_ne_zero]) (edist_ne_top x y)
(by rw [edist_nndist, edist_nndist, hr, ENNReal.coe_mul])
/-- The `ratio` is equal to the distance ratio for any two points
with nonzero finite distance; `dist` version -/
theorem ratio_unique_of_dist_ne_zero {α β} {F : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β]
[FunLike F α β] [DilationClass F α β] {f : F} {x y : α} {r : ℝ≥0} (hxy : dist x y ≠ 0)
(hr : dist (f x) (f y) = r * dist x y) : r = ratio f :=
ratio_unique_of_nndist_ne_zero (NNReal.coe_ne_zero.1 hxy) <|
NNReal.eq <| by rw [coe_nndist, hr, NNReal.coe_mul, coe_nndist]
/-- Alternative `Dilation` constructor when the distance hypothesis is over `nndist` -/
def mkOfNNDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β)
(h : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, nndist (f x) (f y) = r * nndist x y) : α →ᵈ β where
toFun := f
edist_eq' := by
rcases h with ⟨r, hne, h⟩
refine ⟨r, hne, fun x y => ?_⟩
rw [edist_nndist, edist_nndist, ← ENNReal.coe_mul, h x y]
@[simp]
theorem coe_mkOfNNDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h) :
⇑(mkOfNNDistEq f h : α →ᵈ β) = f :=
rfl
@[simp]
theorem mk_coe_of_nndist_eq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α →ᵈ β)
(h) : Dilation.mkOfNNDistEq f h = f :=
ext fun _ => rfl
/-- Alternative `Dilation` constructor when the distance hypothesis is over `dist` -/
def mkOfDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β)
(h : ∃ r : ℝ≥0, r ≠ 0 ∧ ∀ x y : α, dist (f x) (f y) = r * dist x y) : α →ᵈ β :=
mkOfNNDistEq f <|
h.imp fun r hr =>
⟨hr.1, fun x y => NNReal.eq <| by rw [coe_nndist, hr.2, NNReal.coe_mul, coe_nndist]⟩
@[simp]
theorem coe_mkOfDistEq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α → β) (h) :
⇑(mkOfDistEq f h : α →ᵈ β) = f :=
rfl
@[simp]
theorem mk_coe_of_dist_eq {α β} [PseudoMetricSpace α] [PseudoMetricSpace β] (f : α →ᵈ β) (h) :
Dilation.mkOfDistEq f h = f :=
ext fun _ => rfl
end Setup
section PseudoEmetricDilation
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ]
variable [FunLike F α β] [DilationClass F α β]
variable (f : F)
/-- Every isometry is a dilation of ratio `1`. -/
@[simps]
def _root_.Isometry.toDilation (f : α → β) (hf : Isometry f) : α →ᵈ β where
toFun := f
edist_eq' := ⟨1, one_ne_zero, by simpa using hf⟩
@[simp]
lemma _root_.Isometry.toDilation_ratio {f : α → β} {hf : Isometry f} : ratio hf.toDilation = 1 := by
by_cases h : ∀ x y : α, edist x y = 0 ∨ edist x y = ⊤
· exact ratio_of_trivial hf.toDilation h
· push_neg at h
obtain ⟨x, y, h₁, h₂⟩ := h
exact ratio_unique h₁ h₂ (by simp [hf x y]) |>.symm
theorem lipschitz : LipschitzWith (ratio f) (f : α → β) := fun x y => (edist_eq f x y).le
theorem antilipschitz : AntilipschitzWith (ratio f)⁻¹ (f : α → β) := fun x y => by
have hr : ratio f ≠ 0 := ratio_ne_zero f
exact mod_cast
(ENNReal.mul_le_iff_le_inv (ENNReal.coe_ne_zero.2 hr) ENNReal.coe_ne_top).1 (edist_eq f x y).ge
/-- A dilation from an emetric space is injective -/
protected theorem injective {α : Type*} [EMetricSpace α] [FunLike F α β] [DilationClass F α β]
(f : F) :
Injective f :=
(antilipschitz f).injective
/-- The identity is a dilation -/
protected def id (α) [PseudoEMetricSpace α] : α →ᵈ α where
toFun := id
edist_eq' := ⟨1, one_ne_zero, fun x y => by simp only [id, ENNReal.coe_one, one_mul]⟩
instance : Inhabited (α →ᵈ α) :=
⟨Dilation.id α⟩
@[simp]
protected theorem coe_id : ⇑(Dilation.id α) = id :=
rfl
theorem ratio_id : ratio (Dilation.id α) = 1 := by
by_cases h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞
· rw [ratio, if_pos h]
· push_neg at h
rcases h with ⟨x, y, hne⟩
refine (ratio_unique hne.1 hne.2 ?_).symm
simp
/-- The composition of dilations is a dilation -/
def comp (g : β →ᵈ γ) (f : α →ᵈ β) : α →ᵈ γ where
toFun := g ∘ f
edist_eq' := ⟨ratio g * ratio f, mul_ne_zero (ratio_ne_zero g) (ratio_ne_zero f),
fun x y => by simp_rw [Function.comp, edist_eq, ENNReal.coe_mul, mul_assoc]⟩
theorem comp_assoc {δ : Type*} [PseudoEMetricSpace δ] (f : α →ᵈ β) (g : β →ᵈ γ)
(h : γ →ᵈ δ) : (h.comp g).comp f = h.comp (g.comp f) :=
rfl
@[simp]
theorem coe_comp (g : β →ᵈ γ) (f : α →ᵈ β) : (g.comp f : α → γ) = g ∘ f :=
rfl
theorem comp_apply (g : β →ᵈ γ) (f : α →ᵈ β) (x : α) : (g.comp f : α → γ) x = g (f x) :=
rfl
/-- Ratio of the composition `g.comp f` of two dilations is the product of their ratios. We assume
that there exist two points in `α` at extended distance neither `0` nor `∞` because otherwise
`Dilation.ratio (g.comp f) = Dilation.ratio f = 1` while `Dilation.ratio g` can be any number. This
version works for most general spaces, see also `Dilation.ratio_comp` for a version assuming that
`α` is a nontrivial metric space. -/
theorem ratio_comp' {g : β →ᵈ γ} {f : α →ᵈ β}
(hne : ∃ x y : α, edist x y ≠ 0 ∧ edist x y ≠ ⊤) : ratio (g.comp f) = ratio g * ratio f := by
rcases hne with ⟨x, y, hα⟩
have hgf := (edist_eq (g.comp f) x y).symm
simp_rw [coe_comp, Function.comp, edist_eq, ← mul_assoc, ENNReal.mul_left_inj hα.1 hα.2]
at hgf
rwa [← ENNReal.coe_inj, ENNReal.coe_mul]
@[simp]
theorem comp_id (f : α →ᵈ β) : f.comp (Dilation.id α) = f :=
ext fun _ => rfl
@[simp]
theorem id_comp (f : α →ᵈ β) : (Dilation.id β).comp f = f :=
ext fun _ => rfl
instance : Monoid (α →ᵈ α) where
one := Dilation.id α
mul := comp
mul_one := comp_id
one_mul := id_comp
mul_assoc _ _ _ := comp_assoc _ _ _
theorem one_def : (1 : α →ᵈ α) = Dilation.id α :=
rfl
theorem mul_def (f g : α →ᵈ α) : f * g = f.comp g :=
rfl
@[simp]
theorem coe_one : ⇑(1 : α →ᵈ α) = id :=
rfl
@[simp]
theorem coe_mul (f g : α →ᵈ α) : ⇑(f * g) = f ∘ g :=
rfl
@[simp] theorem ratio_one : ratio (1 : α →ᵈ α) = 1 := ratio_id
@[simp]
theorem ratio_mul (f g : α →ᵈ α) : ratio (f * g) = ratio f * ratio g := by
by_cases h : ∀ x y : α, edist x y = 0 ∨ edist x y = ∞
· simp [ratio_of_trivial, h]
push_neg at h
exact ratio_comp' h
/-- `Dilation.ratio` as a monoid homomorphism from `α →ᵈ α` to `ℝ≥0`. -/
@[simps]
def ratioHom : (α →ᵈ α) →* ℝ≥0 := ⟨⟨ratio, ratio_one⟩, ratio_mul⟩
@[simp]
theorem ratio_pow (f : α →ᵈ α) (n : ℕ) : ratio (f ^ n) = ratio f ^ n :=
ratioHom.map_pow _ _
@[simp]
theorem cancel_right {g₁ g₂ : β →ᵈ γ} {f : α →ᵈ β} (hf : Surjective f) :
g₁.comp f = g₂.comp f ↔ g₁ = g₂ :=
⟨fun h => Dilation.ext <| hf.forall.2 (Dilation.ext_iff.1 h), fun h => h ▸ rfl⟩
@[simp]
theorem cancel_left {g : β →ᵈ γ} {f₁ f₂ : α →ᵈ β} (hg : Injective g) :
g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ :=
⟨fun h => Dilation.ext fun x => hg <| by rw [← comp_apply, h, comp_apply], fun h => h ▸ rfl⟩
/-- A dilation from a metric space is a uniform inducing map -/
theorem isUniformInducing : IsUniformInducing (f : α → β) :=
(antilipschitz f).isUniformInducing (lipschitz f).uniformContinuous
theorem tendsto_nhds_iff {ι : Type*} {g : ι → α} {a : Filter ι} {b : α} :
Filter.Tendsto g a (𝓝 b) ↔ Filter.Tendsto ((f : α → β) ∘ g) a (𝓝 (f b)) :=
(Dilation.isUniformInducing f).isInducing.tendsto_nhds_iff
/-- A dilation is continuous. -/
theorem toContinuous : Continuous (f : α → β) :=
(lipschitz f).continuous
/-- Dilations scale the diameter by `ratio f` in pseudoemetric spaces. -/
theorem ediam_image (s : Set α) : EMetric.diam ((f : α → β) '' s) = ratio f * EMetric.diam s := by
refine ((lipschitz f).ediam_image_le s).antisymm ?_
apply ENNReal.mul_le_of_le_div'
rw [div_eq_mul_inv, mul_comm, ← ENNReal.coe_inv]
exacts [(antilipschitz f).le_mul_ediam_image s, ratio_ne_zero f]
/-- A dilation scales the diameter of the range by `ratio f`. -/
theorem ediam_range : EMetric.diam (range (f : α → β)) = ratio f * EMetric.diam (univ : Set α) := by
rw [← image_univ]; exact ediam_image f univ
/-- A dilation maps balls to balls and scales the radius by `ratio f`. -/
theorem mapsTo_emetric_ball (x : α) (r : ℝ≥0∞) :
MapsTo (f : α → β) (EMetric.ball x r) (EMetric.ball (f x) (ratio f * r)) :=
fun y hy => (edist_eq f y x).trans_lt <|
(ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 <| ratio_ne_zero f) ENNReal.coe_ne_top).2 hy
/-- A dilation maps closed balls to closed balls and scales the radius by `ratio f`. -/
theorem mapsTo_emetric_closedBall (x : α) (r' : ℝ≥0∞) :
MapsTo (f : α → β) (EMetric.closedBall x r') (EMetric.closedBall (f x) (ratio f * r')) :=
fun y hy => (edist_eq f y x).trans_le <| mul_le_mul_left' hy _
theorem comp_continuousOn_iff {γ} [TopologicalSpace γ] {g : γ → α} {s : Set γ} :
ContinuousOn ((f : α → β) ∘ g) s ↔ ContinuousOn g s :=
(Dilation.isUniformInducing f).isInducing.continuousOn_iff.symm
theorem comp_continuous_iff {γ} [TopologicalSpace γ] {g : γ → α} :
Continuous ((f : α → β) ∘ g) ↔ Continuous g :=
(Dilation.isUniformInducing f).isInducing.continuous_iff.symm
end PseudoEmetricDilation
section EmetricDilation
variable [EMetricSpace α]
variable [FunLike F α β]
/-- A dilation from a metric space is a uniform embedding -/
lemma isUniformEmbedding [PseudoEMetricSpace β] [DilationClass F α β] (f : F) :
IsUniformEmbedding f :=
(antilipschitz f).isUniformEmbedding (lipschitz f).uniformContinuous
/-- A dilation from a metric space is an embedding -/
theorem isEmbedding [PseudoEMetricSpace β] [DilationClass F α β] (f : F) :
IsEmbedding (f : α → β) :=
(Dilation.isUniformEmbedding f).isEmbedding
@[deprecated (since := "2024-10-26")]
alias embedding := isEmbedding
/-- A dilation from a complete emetric space is a closed embedding -/
lemma isClosedEmbedding [CompleteSpace α] [EMetricSpace β] [DilationClass F α β] (f : F) :
IsClosedEmbedding f :=
(antilipschitz f).isClosedEmbedding (lipschitz f).uniformContinuous
end EmetricDilation
/-- Ratio of the composition `g.comp f` of two dilations is the product of their ratios. We assume
that the domain `α` of `f` is a nontrivial metric space, otherwise
`Dilation.ratio f = Dilation.ratio (g.comp f) = 1` but `Dilation.ratio g` may have any value.
|
See also `Dilation.ratio_comp'` for a version that works for more general spaces. -/
@[simp]
theorem ratio_comp [MetricSpace α] [Nontrivial α] [PseudoEMetricSpace β]
[PseudoEMetricSpace γ] {g : β →ᵈ γ} {f : α →ᵈ β} : ratio (g.comp f) = ratio g * ratio f :=
| Mathlib/Topology/MetricSpace/Dilation.lean | 440 | 444 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Logic.Encodable.Pi
import Mathlib.Logic.Function.Iterate
/-!
# The primitive recursive functions
The primitive recursive functions are the least collection of functions
`ℕ → ℕ` which are closed under projections (using the `pair`
pairing function), composition, zero, successor, and primitive recursion
(i.e. `Nat.rec` where the motive is `C n := ℕ`).
We can extend this definition to a large class of basic types by
using canonical encodings of types as natural numbers (Gödel numbering),
which we implement through the type class `Encodable`. (More precisely,
we need that the composition of encode with decode yields a
primitive recursive function, so we have the `Primcodable` type class
for this.)
In the above, the pairing function is primitive recursive by definition.
This deviates from the textbook definition of primitive recursive functions,
which instead work with *`n`-ary* functions. We formalize the textbook
definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is
equivalent to our chosen formulation. For more discussionn of this and
other design choices in this formalization, see [carneiro2019].
## Main definitions
- `Nat.Primrec f`: `f` is primitive recursive, for functions `f : ℕ → ℕ`
- `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types
- `Primcodable α`: well-behaved encoding of `α` into `ℕ`, i.e. one such that roundtripping through
the encoding functions adds no computational power
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Denumerable Encodable Function
namespace Nat
/-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/
@[simp, reducible]
def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α :=
f n.unpair.1 n.unpair.2
/-- The primitive recursive functions `ℕ → ℕ`. -/
protected inductive Primrec : (ℕ → ℕ) → Prop
| zero : Nat.Primrec fun _ => 0
| protected succ : Nat.Primrec succ
| left : Nat.Primrec fun n => n.unpair.1
| right : Nat.Primrec fun n => n.unpair.2
| pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n)
| comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n)
| prec {f g} :
Nat.Primrec f →
Nat.Primrec g →
Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH)
namespace Primrec
theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g :=
(funext H : f = g) ▸ hf
theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n
| 0 => zero
| n + 1 => Primrec.succ.comp (const n)
protected theorem id : Nat.Primrec id :=
(left.pair right).of_eq fun n => by simp
theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) :
Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH :=
((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp
theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) :=
(prec1 m (hf.comp left)).of_eq <| by simp
-- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor.
theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) :
Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) :=
(prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp
protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) :=
(pair right left).of_eq fun n => by simp
theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) :=
(hf.comp .swap).of_eq fun n => by simp
theorem pred : Nat.Primrec pred :=
(casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*]
theorem add : Nat.Primrec (unpaired (· + ·)) :=
(prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc]
theorem sub : Nat.Primrec (unpaired (· - ·)) :=
(prec .id ((pred.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq]
theorem mul : Nat.Primrec (unpaired (· * ·)) :=
(prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst]
theorem pow : Nat.Primrec (unpaired (· ^ ·)) :=
(prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ]
end Primrec
end Nat
/-- A `Primcodable` type is, essentially, an `Encodable` type for which
the encode/decode functions are primitive recursive.
However, such a definition is circular.
Instead, we ask that the composition of `decode : ℕ → Option α` with
`encode : Option α → ℕ` is primitive recursive. Said composition is
the identity function, restricted to the image of `encode`.
Thus, in a way, the added requirement ensures that no predicates
can be smuggled in through a cunning choice of the subset of `ℕ` into
which the type is encoded. -/
class Primcodable (α : Type*) extends Encodable α where
-- Porting note: was `prim [] `.
-- This means that `prim` does not take the type explicitly in Lean 4
prim : Nat.Primrec fun n => Encodable.encode (decode n)
namespace Primcodable
open Nat.Primrec
instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α :=
⟨Nat.Primrec.succ.of_eq <| by simp⟩
/-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/
def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β :=
{ __ := Encodable.ofEquiv α e
prim := (@Primcodable.prim α _).of_eq fun n => by
rw [decode_ofEquiv]
cases (@decode α _ n) <;>
simp [encode_ofEquiv] }
instance empty : Primcodable Empty :=
⟨zero⟩
instance unit : Primcodable PUnit :=
⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩
instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) :=
⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by
cases n with
| zero => rfl
| succ n =>
rw [decode_option_succ]
cases H : @decode α _ n <;> simp [H]⟩
instance bool : Primcodable Bool :=
⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with
| 0 => rfl
| 1 => rfl
| (n + 2) => by rw [decode_ge_two] <;> simp⟩
end Primcodable
/-- `Primrec f` means `f` is primitive recursive (after
encoding its input and output as natural numbers). -/
def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop :=
Nat.Primrec fun n => encode ((@decode α _ n).map f)
namespace Primrec
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
open Nat.Primrec
protected theorem encode : Primrec (@encode α _) :=
(@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl
protected theorem decode : Primrec (@decode α _) :=
Nat.Primrec.succ.comp (@Primcodable.prim α _)
theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} :
Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) :=
⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h =>
(Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩
theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f :=
dom_denumerable
theorem encdec : Primrec fun n => encode (@decode α _ n) :=
nat_iff.2 Primcodable.prim
theorem option_some : Primrec (@some α) :=
((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> simp
theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g :=
(funext H : f = g) ▸ hf
theorem const (x : σ) : Primrec fun _ : α => x :=
((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> rfl
protected theorem id : Primrec (@id α) :=
(@Primcodable.prim α).of_eq <| by simp
theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) :=
((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> simp [encodek]
theorem succ : Primrec Nat.succ :=
nat_iff.2 Nat.Primrec.succ
theorem pred : Primrec Nat.pred :=
nat_iff.2 Nat.Primrec.pred
theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f :=
⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩
theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} :
Primrec f ↔ Primrec fun n => f (ofNat α n) :=
dom_denumerable.trans <| nat_iff.symm.trans encode_iff
protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) :=
ofNat_iff.1 Primrec.id
theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f :=
⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩
theorem of_equiv {β} {e : β ≃ α} :
haveI := Primcodable.ofEquiv α e
Primrec e :=
letI : Primcodable β := Primcodable.ofEquiv α e
encode_iff.1 Primrec.encode
theorem of_equiv_symm {β} {e : β ≃ α} :
haveI := Primcodable.ofEquiv α e
Primrec e.symm :=
letI := Primcodable.ofEquiv α e
encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode])
theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} :
haveI := Primcodable.ofEquiv α e
(Primrec fun a => e (f a)) ↔ Primrec f :=
letI := Primcodable.ofEquiv α e
⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩
theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} :
haveI := Primcodable.ofEquiv α e
(Primrec fun a => e.symm (f a)) ↔ Primrec f :=
letI := Primcodable.ofEquiv α e
⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩
end Primrec
namespace Primcodable
open Nat.Primrec
instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) :=
⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1; · simp
cases @decode β _ n.unpair.2 <;> simp⟩
end Primcodable
namespace Primrec
variable {α : Type*} [Primcodable α]
open Nat.Primrec
theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp left)).comp
(pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1 <;> simp
cases @decode β _ n.unpair.2 <;> simp
theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp right)).comp
(pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1 <;> simp
cases @decode β _ n.unpair.2 <;> simp
theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ}
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) :=
((casesOn1 0
(Nat.Primrec.succ.comp <|
.pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp
(@Primcodable.prim α _)).of_eq
fun n => by cases @decode α _ n <;> simp [encodek]
theorem unpair : Primrec Nat.unpair :=
(pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp
theorem list_getElem?₁ : ∀ l : List α, Primrec (l[·]? : ℕ → Option α)
| [] => dom_denumerable.2 zero
| a :: l =>
dom_denumerable.2 <|
(casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by
cases n <;> simp
@[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁
end Primrec
/-- `Primrec₂ f` means `f` is a binary primitive recursive function.
This is technically unnecessary since we can always curry all
the arguments together, but there are enough natural two-arg
functions that it is convenient to express this directly. -/
def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) :=
Primrec fun p : α × β => f p.1 p.2
/-- `PrimrecPred p` means `p : α → Prop` is a (decidable)
primitive recursive predicate, which is to say that
`decide ∘ p : α → Bool` is primitive recursive. -/
def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] :=
Primrec fun a => decide (p a)
/-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable)
primitive recursive relation, which is to say that
`decide ∘ p : α → β → Bool` is primitive recursive. -/
def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop)
[∀ a b, Decidable (s a b)] :=
Primrec₂ fun a b => decide (s a b)
namespace Primrec₂
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf
theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g :=
(by funext a b; apply H : f = g) ▸ hg
theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x :=
Primrec.const _
protected theorem pair : Primrec₂ (@Prod.mk α β) :=
Primrec.pair .fst .snd
theorem left : Primrec₂ fun (a : α) (_ : β) => a :=
.fst
theorem right : Primrec₂ fun (_ : α) (b : β) => b :=
.snd
theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor
theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f :=
⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩
theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f :=
Primrec.nat_iff.symm.trans unpaired
theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f :=
Primrec.encode_iff
theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f :=
Primrec.option_some_iff
theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} :
Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) :=
(Primrec.ofNat_iff.trans <| by simp).trans unpaired
theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by
rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl
theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by
rw [← uncurry, Function.uncurry_curry]
end Primrec₂
section Comp
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ]
theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a b => f (g a b) :=
hf.comp hg
theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g)
(hh : Primrec h) : Primrec fun a => f (g a) (h a) :=
Primrec.comp hf (hg.pair hh)
theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f)
(hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) :=
hf.comp hg hh
theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} :
PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) :=
Primrec.comp
theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} :
PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) :=
Primrec₂.comp
theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ}
{g : α → β → δ} :
PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) :=
PrimrecRel.comp
end Comp
theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q :=
Primrec.of_eq hp fun a => Bool.decide_congr (H a)
theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop}
[∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r)
(H : ∀ a b, r a b ↔ s a b) : PrimrecRel s :=
Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b)
namespace Primrec₂
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
open Nat.Primrec
theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) :=
h.comp₂ Primrec₂.right Primrec₂.left
theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec
(.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by
have :
∀ (a : Option α) (b : Option β),
Option.map (fun p : α × β => f p.1 p.2)
(Option.bind a fun a : α => Option.map (Prod.mk a) b) =
Option.bind a fun a => Option.map (f a) b := fun a b => by
cases a <;> cases b <;> rfl
simp [Primrec₂, Primrec, this]
theorem nat_iff' {f : α → β → σ} :
Primrec₂ f ↔
Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) :=
nat_iff.trans <| unpaired'.trans encode_iff
end Primrec₂
namespace Primrec
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) :=
hf.of_eq fun _ => rfl
theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) :=
Primrec₂.nat_iff.2 <|
((Nat.Primrec.casesOn' .zero <|
(Nat.Primrec.prec hf <|
.comp hg <|
Nat.Primrec.left.pair <|
(Nat.Primrec.left.comp .right).pair <|
Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <|
Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <|
Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq
fun n => by
simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat,
Option.some_bind, Option.map_map, Option.map_some']
rcases @decode α _ n.unpair.1 with - | a; · rfl
simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some',
Option.some_bind, Option.map_map]
induction' n.unpair.2 with m <;> simp [encodek]
simp [*, encodek]
theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β}
(hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) :=
(nat_rec hg hh).comp .id hf
theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) :=
nat_rec' .id (const a) <| comp₂ hf Primrec₂.right
theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) :=
nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right
theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g)
(hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) :=
(nat_casesOn' hg hh).comp .id hf
theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) :
Primrec (fun (n : ℕ) => (n.casesOn a f : α)) :=
nat_casesOn .id (const a) (comp₂ hf .right)
theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g)
(hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) :=
(nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by
induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ']
theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o)
(hf : Primrec f) (hg : Primrec₂ g) :
@Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) :=
encode_iff.1 <|
(nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <|
pred.comp₂ <|
Primrec₂.encode_iff.2 <|
(Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂
Primrec₂.right).of_eq
fun a => by rcases o a with - | b <;> simp [encodek]
theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun a => (f a).bind (g a) :=
(option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl
theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f :=
option_bind .id (hf.comp snd).to₂
theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun a => (f a).map (g a) :=
(option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl
theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) :=
option_map .id (hf.comp snd).to₂
theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) :=
(option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl
theorem option_isSome : Primrec (@Option.isSome α) :=
(option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl
theorem option_getD : Primrec₂ (@Option.getD α) :=
Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by
cases o <;> rfl
theorem bind_decode_iff {f : α → β → Option σ} :
(Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f :=
⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h =>
option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩
theorem map_decode_iff {f : α → β → σ} :
(Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by
simp only [Option.map_eq_bind]
exact bind_decode_iff.trans Primrec₂.option_some_iff
theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) :=
Primrec₂.unpaired'.1 Nat.Primrec.add
theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) :=
Primrec₂.unpaired'.1 Nat.Primrec.sub
theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) :=
Primrec₂.unpaired'.1 Nat.Primrec.mul
theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f)
(hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) :=
(nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl
theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c)
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by
simpa [Bool.cond_decide] using cond hc hf hg
theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) :=
(nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by
dsimp [swap]
rcases e : p.1 - p.2 with - | n
· simp [Nat.sub_eq_zero_iff_le.1 e]
· simp [not_le.2 (Nat.lt_of_sub_eq_succ e)]
theorem nat_min : Primrec₂ (@min ℕ _) :=
ite nat_le fst snd
theorem nat_max : Primrec₂ (@max ℕ _) :=
ite (nat_le.comp fst snd) snd fst
theorem dom_bool (f : Bool → α) : Primrec f :=
(cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl
theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f :=
(cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by
cases a <;> rfl
protected theorem not : Primrec not :=
dom_bool _
protected theorem and : Primrec₂ and :=
dom_bool₂ _
protected theorem or : Primrec₂ or :=
dom_bool₂ _
theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) :
PrimrecPred fun a => ¬p a :=
(Primrec.not.comp hp).of_eq fun n => by simp
theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a :=
(Primrec.and.comp hp hq).of_eq fun n => by simp
theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a :=
(Primrec.or.comp hp hq).of_eq fun n => by simp
protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) :=
have : PrimrecRel fun a b : ℕ => a = b :=
(PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff]
(this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq
fun _ _ => encode_injective.eq_iff
protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq
theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) :=
(nat_le.comp snd fst).not.of_eq fun p => by simp
theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β}
(hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) :=
ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none)
theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) :=
(option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl
protected theorem decode₂ : Primrec (decode₂ α) :=
option_bind .decode <|
option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd
theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) :
∀ l : List β, Primrec fun a => l.findIdx (p a)
| [] => const 0
| a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n =>
by simp [List.findIdx_cons]
theorem list_idxOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.idxOf a :=
list_findIdx₁ (.swap .beq) l
@[deprecated (since := "2025-01-30")] alias list_indexOf₁ := list_idxOf₁
theorem dom_fintype [Finite α] (f : α → σ) : Primrec f :=
let ⟨l, _, m⟩ := Finite.exists_univ_list α
option_some_iff.1 <| by
haveI := decidableEqOfEncodable α
refine ((list_getElem?₁ (l.map f)).comp (list_idxOf₁ l)).of_eq fun a => ?_
rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some']
-- Porting note: These are new lemmas
-- I added it because it actually simplified the proofs
-- and because I couldn't understand the original proof
/-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/
def PrimrecBounded (f : α → β) : Prop :=
∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x
theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)]
(hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) :=
(nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2)
hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp))
(snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by
induction f x <;> simp [Nat.findGreatest, *]
/-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function
is bounded by a primitive recursive function and that its graph is primitive recursive -/
theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f)
(h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by
rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩
refine (nat_findGreatest pg h₂).of_eq fun n => ?_
exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm
-- We show that division is primitive recursive by showing that the graph is
theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by
refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_
have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨
(0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) :=
PrimrecPred.or
(.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd))
(.and (nat_lt.comp (const 0) (fst |> snd.comp)) <|
.and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp))
(nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst))))
refine this.of_eq ?_
rintro ⟨a, k⟩ q
if H : k = 0 then simp [H, eq_comm]
else
have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by
rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H),
Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)]
simpa [H, zero_lt_iff, eq_comm (b := q)]
theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) :=
(nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by
apply Nat.sub_eq_of_eq_add
simp [add_comm (m % n), Nat.div_add_mod]
theorem nat_bodd : Primrec Nat.bodd :=
(Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by
cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H]
theorem nat_div2 : Primrec Nat.div2 :=
(nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm
theorem nat_double : Primrec (fun n : ℕ => 2 * n) :=
nat_mul.comp (const _) Primrec.id
theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) :=
nat_double |> Primrec.succ.comp
end Primrec
section
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n))
open Primrec
private def prim : Primcodable (List β) := ⟨H⟩
private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ}
(hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) :
@Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) :=
letI := prim H
have :
@Primrec _ (Option σ) _ _ fun a =>
(@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) :=
((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <|
to₂ <|
option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp
.id (encode_iff.2 hf)
option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | ⟨b, l⟩ <;> simp [encodek]
private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ}
(hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) :
Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by
letI := prim H
let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l)
have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <|
to₂ <|
pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd))
(snd.comp snd)
let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a)
have hF : Primrec fun a => (F a (encode (f a))).1 :=
(fst.comp <|
nat_iterate (encode_iff.2 hf) (pair hg hf) <|
hG)
suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by
refine hF.of_eq fun a => ?_
rw [this, List.take_of_length_le (length_le_encode _)]
introv
dsimp only [F]
generalize f a = l
generalize g a = x
induction n generalizing l x with
| zero => rfl
| succ n IH =>
simp only [iterate_succ, comp_apply]
rcases l with - | ⟨b, l⟩ <;> simp [G, IH]
private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) :=
letI := prim H
encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd))
private theorem list_reverse' :
haveI := prim H
Primrec (@List.reverse β) :=
letI := prim H
(list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq
(suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from
fun l => this l []
fun l => by induction l <;> simp [*, List.reverseAux])
end
namespace Primcodable
variable {α : Type*} {β : Type*}
variable [Primcodable α] [Primcodable β]
open Primrec
instance sum : Primcodable (α ⊕ β) :=
⟨Primrec.nat_iff.1 <|
(encode_iff.2
(cond nat_bodd
(((@Primrec.decode β _).comp nat_div2).option_map <|
to₂ <| nat_double_succ.comp (Primrec.encode.comp snd))
(((@Primrec.decode α _).comp nat_div2).option_map <|
to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq
fun n =>
show _ = encode (decodeSum n) by
simp only [decodeSum, Nat.boddDiv2_eq]
cases Nat.bodd n <;> simp [decodeSum]
· cases @decode α _ n.div2 <;> rfl
· cases @decode β _ n.div2 <;> rfl⟩
instance list : Primcodable (List α) :=
⟨letI H := @Primcodable.prim (List ℕ) _
have : Primrec₂ fun (a : α) (o : Option (List ℕ)) => o.map (List.cons (encode a)) :=
option_map snd <| (list_cons' H).comp ((@Primrec.encode α _).comp (fst.comp fst)) snd
have :
Primrec fun n =>
(ofNat (List ℕ) n).reverse.foldl
(fun o m => (@decode α _ m).bind fun a => o.map (List.cons (encode a))) (some []) :=
list_foldl' H ((list_reverse' H).comp (.ofNat (List ℕ))) (const (some []))
(Primrec.comp₂ (bind_decode_iff.2 <| .swap this) Primrec₂.right)
nat_iff.1 <|
(encode_iff.2 this).of_eq fun n => by
rw [List.foldl_reverse]
apply Nat.case_strong_induction_on n; · simp
intro n IH; simp
rcases @decode α _ n.unpair.1 with - | a; · rfl
simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some']
suffices ∀ (o : Option (List ℕ)) (p), encode o = encode p →
encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from
this _ _ (IH _ (Nat.unpair_right_le n))
intro o p IH
cases o <;> cases p
· rfl
· injection IH
· injection IH
· exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩
end Primcodable
namespace Primrec
variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ]
theorem sumInl : Primrec (@Sum.inl α β) :=
encode_iff.1 <| nat_double.comp Primrec.encode
theorem sumInr : Primrec (@Sum.inr α β) :=
encode_iff.1 <| nat_double_succ.comp Primrec.encode
@[deprecated (since := "2025-02-21")] alias sum_inl := Primrec.sumInl
@[deprecated (since := "2025-02-21")] alias sum_inr := Primrec.sumInr
theorem sumCasesOn {f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ} (hf : Primrec f)
(hg : Primrec₂ g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) :=
option_some_iff.1 <|
(cond (nat_bodd.comp <| encode_iff.2 hf)
(option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh)
(option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq
fun a => by rcases f a with b | c <;> simp [Nat.div2_val, encodek]
@[deprecated (since := "2025-02-21")] alias sum_casesOn := Primrec.sumCasesOn
theorem list_cons : Primrec₂ (@List.cons α) :=
list_cons' Primcodable.prim
theorem list_casesOn {f : α → List β} {g : α → σ} {h : α → β × List β → σ} :
Primrec f →
Primrec g →
Primrec₂ h → @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) :=
list_casesOn' Primcodable.prim
theorem list_foldl {f : α → List β} {g : α → σ} {h : α → σ × β → σ} :
Primrec f →
Primrec g → Primrec₂ h → Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) :=
list_foldl' Primcodable.prim
theorem list_reverse : Primrec (@List.reverse α) :=
list_reverse' Primcodable.prim
theorem list_foldr {f : α → List β} {g : α → σ} {h : α → β × σ → σ} (hf : Primrec f)
(hg : Primrec g) (hh : Primrec₂ h) :
Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) :=
(list_foldl (list_reverse.comp hf) hg <| to₂ <| hh.comp fst <| (pair snd fst).comp snd).of_eq
fun a => by simp [List.foldl_reverse]
theorem list_head? : Primrec (@List.head? α) :=
(list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).to₂).of_eq fun l => by
cases l <;> rfl
theorem list_headI [Inhabited α] : Primrec (@List.headI α _) :=
(option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm
theorem list_tail : Primrec (@List.tail α) :=
(list_casesOn .id (const []) (snd.comp snd).to₂).of_eq fun l => by cases l <;> rfl
theorem list_rec {f : α → List β} {g : α → σ} {h : α → β × List β × σ → σ} (hf : Primrec f)
(hg : Primrec g) (hh : Primrec₂ h) :
@Primrec _ σ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) :=
let F (a : α) := (f a).foldr (fun (b : β) (s : List β × σ) => (b :: s.1, h a (b, s))) ([], g a)
have : Primrec F :=
list_foldr hf (pair (const []) hg) <|
to₂ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh
(snd.comp this).of_eq fun a => by
suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this]
dsimp [F]
induction' f a with b l IH <;> simp [*]
theorem list_getElem? : Primrec₂ ((·[·]? : List α → ℕ → Option α)) :=
let F (l : List α) (n : ℕ) :=
l.foldl
(fun (s : ℕ ⊕ α) (a : α) =>
Sum.casesOn s (@Nat.casesOn (fun _ => ℕ ⊕ α) · (Sum.inr a) Sum.inl) Sum.inr)
(Sum.inl n)
have hF : Primrec₂ F :=
(list_foldl fst (sumInl.comp snd)
((sumCasesOn fst (nat_casesOn snd (sumInr.comp <| snd.comp fst) (sumInl.comp snd).to₂).to₂
(sumInr.comp snd).to₂).comp
snd).to₂).to₂
have :
@Primrec _ (Option α) _ _ fun p : List α × ℕ => Sum.casesOn (F p.1 p.2) (fun _ => none) some :=
sumCasesOn hF (const none).to₂ (option_some.comp snd).to₂
this.to₂.of_eq fun l n => by
dsimp; symm
induction' l with a l IH generalizing n; · rfl
rcases n with - | n
· dsimp [F]
clear IH
induction' l with _ l IH <;> simp_all
· simpa using IH ..
@[deprecated (since := "2025-02-14")] alias list_get? := list_getElem?
theorem list_getD (d : α) : Primrec₂ fun l n => List.getD l n d := by
simp only [List.getD_eq_getElem?_getD]
exact option_getD.comp₂ list_getElem? (const _)
theorem list_getI [Inhabited α] : Primrec₂ (@List.getI α _) :=
list_getD _
theorem list_append : Primrec₂ ((· ++ ·) : List α → List α → List α) :=
(list_foldr fst snd <| to₂ <| comp (@list_cons α _) snd).to₂.of_eq fun l₁ l₂ => by
induction l₁ <;> simp [*]
theorem list_concat : Primrec₂ fun l (a : α) => l ++ [a] :=
list_append.comp fst (list_cons.comp snd (const []))
theorem list_map {f : α → List β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun a => (f a).map (g a) :=
(list_foldr hf (const []) <|
to₂ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq
fun a => by induction f a <;> simp [*]
theorem list_range : Primrec List.range :=
(nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).to₂).of_eq fun n => by
simp; induction n <;> simp [*, List.range_succ]
theorem list_flatten : Primrec (@List.flatten α) :=
(list_foldr .id (const []) <| to₂ <| comp (@list_append α _) snd).of_eq fun l => by
dsimp; induction l <;> simp [*]
theorem list_flatMap {f : α → List β} {g : α → β → List σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec (fun a => (f a).flatMap (g a)) := list_flatten.comp (list_map hf hg)
theorem optionToList : Primrec (Option.toList : Option α → List α) :=
(option_casesOn Primrec.id (const [])
((list_cons.comp Primrec.id (const [])).comp₂ Primrec₂.right)).of_eq
(fun o => by rcases o <;> simp)
theorem listFilterMap {f : α → List β} {g : α → β → Option σ}
(hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).filterMap (g a) :=
(list_flatMap hf (comp₂ optionToList hg)).of_eq
fun _ ↦ Eq.symm <| List.filterMap_eq_flatMap_toList _ _
theorem list_length : Primrec (@List.length α) :=
(list_foldr (@Primrec.id (List α) _) (const 0) <| to₂ <| (succ.comp <| snd.comp snd).to₂).of_eq
fun l => by dsimp; induction l <;> simp [*]
theorem list_findIdx {f : α → List β} {p : α → β → Bool}
(hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) :=
(list_foldr hf (const 0) <|
to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq
fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *]
theorem list_idxOf [DecidableEq α] : Primrec₂ (@List.idxOf α _) :=
to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂
@[deprecated (since := "2025-01-30")] alias list_indexOf := list_idxOf
theorem nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g)
(H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f :=
suffices Primrec₂ fun a n => (List.range n).map (f a) from
Primrec₂.option_some_iff.1 <|
(list_getElem?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by
simp [List.getElem?_range (Nat.lt_succ_self n)]
Primrec₂.option_some_iff.1 <|
(nat_rec (const (some []))
(to₂ <|
option_bind (snd.comp snd) <|
to₂ <|
option_map (hg.comp (fst.comp fst) snd)
(to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq
fun a n => by
induction n with
| zero => rfl
| succ n IH => simp [IH, H, List.range_succ]
theorem listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) :=
(to₂ <| list_rec snd (const none) <|
to₂ <|
cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd))
(option_some.comp <| snd.comp <| fst.comp snd)
(snd.comp <| snd.comp snd)).of_eq
fun a ps => by
induction' ps with p ps ih <;> simp [List.lookup, *]
cases ha : a == p.1 <;> simp [ha]
theorem nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ}
(hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g)
(Ord : ∀ b, ∀ b' ∈ l b, m b' < m b)
(H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by
haveI : DecidableEq β := Encodable.decidableEqOfEncodable β
let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.flatMap (Option.toList <| M.lookup ·)
let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.flatMap l
let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦
(bindList b (m b - i)).filterMap fun b' ↦ (g b' <| mapGraph ih (l b')).map (b', ·)
have mapGraph_primrec : Primrec₂ mapGraph :=
to₂ <| list_flatMap snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left)
have bindList_primrec : Primrec₂ (bindList) :=
nat_rec' snd
(list_cons.comp fst (const []))
(to₂ <| list_flatMap (snd.comp snd) (hl.comp₂ .right))
have graph_primrec : Primrec₂ (graph) :=
to₂ <| nat_rec' snd (const []) <|
to₂ <| listFilterMap
(bindList_primrec.comp
(fst.comp fst)
(nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <|
to₂ <| option_map
(hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd)))
(Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)
have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) :=
option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0))
(snd.comp₂ Primrec₂.right)
exact option_some_iff.mp <| this.of_eq <| fun b ↦ by
have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) :
graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by
have bindList_eq_nil : bindList b (m b + 1) = [] :=
have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by
induction' k with k ih <;> simp [bindList]
intro a₂ a₁ ha₁ ha₂
have : k ≤ m b :=
Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub <| Nat.zero_lt_of_lt (ih a₁ ha₁))
have : m a₁ ≤ m b - k :=
Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁)
exact lt_of_lt_of_le (Ord a₁ a₂ ha₂) this
List.eq_nil_iff_forall_not_mem.mpr
(by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha')
have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) :
mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by
induction' bs' with b bs' ih <;> simp [mapGraph]
· have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has
rcases this with ⟨ha, has'⟩
simpa [List.lookup_graph f ha] using ih has'
have graph_succ : ∀ i, graph b (i + 1) =
(bindList b (m b - i)).filterMap fun b' =>
(g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl
have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl
induction' i with i ih
· symm; simpa [graph] using bindList_eq_nil
· simp only [graph_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi),
Nat.succ_eq_add_one, bindList_succ, Nat.reduceSubDiff]
apply List.filterMap_eq_map_iff_forall_eq_some.mpr
intro b' ha'; simp; rw [mapGraph_graph]
· exact H b'
· exact (List.infix_flatMap_of_mem ha' l).subset
simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList]
theorem nat_omega_rec (f : α → β → σ) {m : α → β → ℕ}
{l : α → β → List β} {g : α → β × List σ → Option σ}
(hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g)
(Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b)
(H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f :=
Primrec₂.uncurry.mp <|
nat_omega_rec' (Function.uncurry f)
(Primrec₂.uncurry.mpr hm)
(list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right))
(hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right))
(by simpa using Ord) (by simpa [Function.comp] using H)
end Primrec
namespace Primcodable
variable {α : Type*} [Primcodable α]
open Primrec
/-- A subtype of a primitive recursive predicate is `Primcodable`. -/
def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) :=
⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a :=
option_bind .decode (option_guard (hp.comp snd).to₂ snd)
nat_iff.1 <| (encode_iff.2 this).of_eq fun n =>
show _ = encode ((@decode α _ n).bind fun _ => _) by
rcases @decode α _ n with - | a; · rfl
dsimp [Option.guard]
by_cases h : p a <;> simp [h]; rfl⟩
instance fin {n} : Primcodable (Fin n) :=
@ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype
instance vector {n} : Primcodable (List.Vector α n) :=
subtype ((@Primrec.eq ℕ _ _).comp list_length (const _))
instance finArrow {n} : Primcodable (Fin n → α) :=
ofEquiv _ (Equiv.vectorEquivFin _ _).symm
section ULower
attribute [local instance] Encodable.decidableRangeEncode Encodable.decidableEqOfEncodable
theorem mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) :=
have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none :=
.not
(Primrec.eq.comp
(.option_bind .decode
(.ite (Primrec.eq.comp (Primrec.encode.comp .snd) .fst)
(Primrec.option_some.comp .snd) (.const _)))
(.const _))
this.of_eq fun _ => decode₂_ne_none_iff
instance ulower : Primcodable (ULower α) :=
Primcodable.subtype mem_range_encode
end ULower
end Primcodable
namespace Primrec
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
theorem subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} :
haveI := Primcodable.subtype hp
Primrec (@Subtype.val α p) := by
letI := Primcodable.subtype hp
refine (@Primcodable.prim (Subtype p)).of_eq fun n => ?_
rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl
theorem subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} :
haveI := Primcodable.subtype hp
(Primrec fun a => (f a).1) ↔ Primrec f := by
letI := Primcodable.subtype hp
refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩
refine Nat.Primrec.of_eq h fun n => ?_
rcases @decode α _ n with - | a; · rfl
simp; rfl
theorem subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β}
{h : ∀ a, p (f a)} (hf : Primrec f) :
haveI := Primcodable.subtype hp
Primrec fun a => @Subtype.mk β p (f a) (h a) :=
subtype_val_iff.1 hf
theorem option_get {f : α → Option β} {h : ∀ a, (f a).isSome} :
Primrec f → Primrec fun a => (f a).get (h a) := by
intro hf
refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_
generalize hx : @decode α _ n = x
cases x <;> simp
theorem ulower_down : Primrec (ULower.down : α → ULower α) :=
letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _
subtype_mk .encode
theorem ulower_up : Primrec (ULower.up : ULower α → α) :=
letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _
option_get (Primrec.decode₂.comp subtype_val)
theorem fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by
letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _))
exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _)
theorem fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) :=
fin_val_iff.2 .id
theorem fin_succ {n} : Primrec (@Fin.succ n) :=
fin_val_iff.1 <| by simp [succ.comp fin_val]
theorem vector_toList {n} : Primrec (@List.Vector.toList α n) :=
subtype_val
theorem vector_toList_iff {n} {f : α → List.Vector β n} :
(Primrec fun a => (f a).toList) ↔ Primrec f :=
subtype_val_iff
theorem vector_cons {n} : Primrec₂ (@List.Vector.cons α n) :=
vector_toList_iff.1 <| by simpa using list_cons.comp fst (vector_toList_iff.2 snd)
theorem vector_length {n} : Primrec (@List.Vector.length α n) :=
const _
theorem vector_head {n} : Primrec (@List.Vector.head α n) :=
option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl
theorem vector_tail {n} : Primrec (@List.Vector.tail α n) :=
vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl
theorem vector_get {n} : Primrec₂ (@List.Vector.get α n) :=
option_some_iff.1 <|
(list_getElem?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by
simp [Vector.get_eq_get_toList]
theorem list_ofFn :
∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a
| 0, _, _ => by simp only [List.ofFn_zero]; exact const []
| n + 1, f, hf => by
simpa [List.ofFn_succ] using list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ)
theorem vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) :
Primrec fun a => List.Vector.ofFn fun i => f i a :=
vector_toList_iff.1 <| by simp [list_ofFn hf]
theorem vector_get' {n} : Primrec (@List.Vector.get α n) :=
of_equiv_symm
theorem vector_ofFn' {n} : Primrec (@List.Vector.ofFn α n) :=
of_equiv
theorem fin_app {n} : Primrec₂ (@id (Fin n → σ)) :=
(vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp
theorem fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) :=
⟨fun h i => h.comp (const i) .id, fun h =>
(vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩
theorem fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f :=
⟨fun h => fin_app.comp (h.comp fst) snd, fun h =>
(vector_get'.comp
(vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq
fun a => by funext i; simp⟩
end Primrec
namespace Nat
open List.Vector
/-- An alternative inductive definition of `Primrec` which
does not use the pairing function on ℕ, and so has to
work with n-ary functions on ℕ instead of unary functions.
We prove that this is equivalent to the regular notion
in `to_prim` and `of_prim`. -/
inductive Primrec' : ∀ {n}, (List.Vector ℕ n → ℕ) → Prop
| zero : @Primrec' 0 fun _ => 0
| succ : @Primrec' 1 fun v => succ v.head
| get {n} (i : Fin n) : Primrec' fun v => v.get i
| comp {m n f} (g : Fin n → List.Vector ℕ m → ℕ) :
Primrec' f → (∀ i, Primrec' (g i)) → Primrec' fun a => f (List.Vector.ofFn fun i => g i a)
| prec {n f g} :
@Primrec' n f →
@Primrec' (n + 2) g →
Primrec' fun v : List.Vector ℕ (n + 1) =>
v.head.rec (f v.tail) fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)
end Nat
namespace Nat.Primrec'
open List.Vector Primrec
theorem to_prim {n f} (pf : @Nat.Primrec' n f) : Primrec f := by
induction pf with
| zero => exact .const 0
| succ => exact _root_.Primrec.succ.comp .vector_head
| get i => exact Primrec.vector_get.comp .id (.const i)
| comp _ _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i)
| @prec n f g _ _ hf hg =>
exact
.nat_rec' .vector_head (hf.comp Primrec.vector_tail)
(hg.comp <|
Primrec.vector_cons.comp (Primrec.fst.comp .snd) <|
Primrec.vector_cons.comp (Primrec.snd.comp .snd) <|
(@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂
theorem of_eq {n} {f g : List.Vector ℕ n → ℕ} (hf : Primrec' f) (H : ∀ i, f i = g i) :
Primrec' g :=
(funext H : f = g) ▸ hf
theorem const {n} : ∀ m, @Primrec' n fun _ => m
| 0 => zero.comp Fin.elim0 fun i => i.elim0
| m + 1 => succ.comp _ fun _ => const m
theorem head {n : ℕ} : @Primrec' n.succ head :=
(get 0).of_eq fun v => by simp [get_zero]
theorem tail {n f} (hf : @Primrec' n f) : @Primrec' n.succ fun v => f v.tail :=
(hf.comp _ fun i => @get _ i.succ).of_eq fun v => by
rw [← ofFn_get v.tail]; congr; funext i; simp
/-- A function from vectors to vectors is primitive recursive when all of its projections are. -/
def Vec {n m} (f : List.Vector ℕ n → List.Vector ℕ m) : Prop :=
∀ i, Primrec' fun v => (f v).get i
protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0
protected theorem cons {n m f g} (hf : @Primrec' n f) (hg : @Vec n m g) :
Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simp [*]) (fun i => by simp [hg i]) i
theorem idv {n} : @Vec n n id :=
get
theorem comp' {n m f g} (hf : @Primrec' m f) (hg : @Vec n m g) : Primrec' fun v => f (g v) :=
(hf.comp _ hg).of_eq fun v => by simp
theorem comp₁ (f : ℕ → ℕ) (hf : @Primrec' 1 fun v => f v.head) {n g} (hg : @Primrec' n g) :
Primrec' fun v => f (g v) :=
hf.comp _ fun _ => hg
theorem comp₂ (f : ℕ → ℕ → ℕ) (hf : @Primrec' 2 fun v => f v.head v.tail.head) {n g h}
(hg : @Primrec' n g) (hh : @Primrec' n h) : Primrec' fun v => f (g v) (h v) := by
simpa using hf.comp' (hg.cons <| hh.cons Primrec'.nil)
theorem prec' {n f g h} (hf : @Primrec' n f) (hg : @Primrec' n g) (hh : @Primrec' (n + 2) h) :
@Primrec' n fun v => (f v).rec (g v) fun y IH : ℕ => h (y ::ᵥ IH ::ᵥ v) := by
simpa using comp' (prec hg hh) (hf.cons idv)
theorem pred : @Primrec' 1 fun v => v.head.pred :=
(prec' head (const 0) head).of_eq fun v => by simp; cases v.head <;> rfl
theorem add : @Primrec' 2 fun v => v.head + v.tail.head :=
(prec head (succ.comp₁ _ (tail head))).of_eq fun v => by
simp; induction v.head <;> simp [*, Nat.succ_add]
theorem sub : @Primrec' 2 fun v => v.head - v.tail.head := by
have : @Primrec' 2 fun v ↦ (fun a b ↦ b - a) v.head v.tail.head := by
refine (prec head (pred.comp₁ _ (tail head))).of_eq fun v => ?_
simp; induction v.head <;> simp [*, Nat.sub_add_eq]
simpa using comp₂ (fun a b => b - a) this (tail head) head
theorem mul : @Primrec' 2 fun v => v.head * v.tail.head :=
(prec (const 0) (tail (add.comp₂ _ (tail head) head))).of_eq fun v => by
simp; induction v.head <;> simp [*, Nat.succ_mul]; rw [add_comm]
theorem if_lt {n a b f g} (ha : @Primrec' n a) (hb : @Primrec' n b) (hf : @Primrec' n f)
(hg : @Primrec' n g) : @Primrec' n fun v => if a v < b v then f v else g v :=
(prec' (sub.comp₂ _ hb ha) hg (tail <| tail hf)).of_eq fun v => by
cases e : b v - a v
· simp [not_lt.2 (Nat.sub_eq_zero_iff_le.mp e)]
· simp [Nat.lt_of_sub_eq_succ e]
theorem natPair : @Primrec' 2 fun v => v.head.pair v.tail.head :=
if_lt head (tail head) (add.comp₂ _ (tail <| mul.comp₂ _ head head) head)
(add.comp₂ _ (add.comp₂ _ (mul.comp₂ _ head head) head) (tail head))
protected theorem encode : ∀ {n}, @Primrec' n encode
| 0 => (const 0).of_eq fun v => by rw [v.eq_nil]; rfl
| _ + 1 =>
(succ.comp₁ _ (natPair.comp₂ _ head (tail Primrec'.encode))).of_eq fun ⟨_ :: _, _⟩ => rfl
theorem sqrt : @Primrec' 1 fun v => v.head.sqrt := by
suffices H : ∀ n : ℕ, n.sqrt =
n.rec 0 fun x y => if x.succ < y.succ * y.succ then y else y.succ by
simp only [H, succ_eq_add_one]
have :=
@prec' 1 _ _
(fun v => by
have x := v.head; have y := v.tail.head
exact if x.succ < y.succ * y.succ then y else y.succ)
head (const 0) ?_
· exact this
have x1 : @Primrec' 3 fun v => v.head.succ := succ.comp₁ _ head
have y1 : @Primrec' 3 fun v => v.tail.head.succ := succ.comp₁ _ (tail head)
exact if_lt x1 (mul.comp₂ _ y1 y1) (tail head) y1
introv; symm
induction' n with n IH; · simp
dsimp; rw [IH]; split_ifs with h
· exact le_antisymm (Nat.sqrt_le_sqrt (Nat.le_succ _)) (Nat.lt_succ_iff.1 <| Nat.sqrt_lt.2 h)
· exact
Nat.eq_sqrt.2 ⟨not_lt.1 h, Nat.sqrt_lt.1 <| Nat.lt_succ_iff.2 <| Nat.sqrt_succ_le_succ_sqrt _⟩
theorem unpair₁ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.1 := by
have s := sqrt.comp₁ _ hf
have fss := sub.comp₂ _ hf (mul.comp₂ _ s s)
refine (if_lt fss s fss s).of_eq fun v => ?_
simp [Nat.unpair]; split_ifs <;> rfl
theorem unpair₂ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.2 := by
have s := sqrt.comp₁ _ hf
have fss := sub.comp₂ _ hf (mul.comp₂ _ s s)
refine (if_lt fss s s (sub.comp₂ _ fss s)).of_eq fun v => ?_
simp [Nat.unpair]; split_ifs <;> rfl
theorem of_prim {n f} : Primrec f → @Primrec' n f :=
suffices ∀ f, Nat.Primrec f → @Primrec' 1 fun v => f v.head from fun hf =>
(pred.comp₁ _ <|
(this _ hf).comp₁ (fun m => Encodable.encode <| (@decode (List.Vector ℕ n) _ m).map f)
Primrec'.encode).of_eq
fun i => by simp [encodek]
fun f hf => by
induction hf with
| zero => exact const 0
| succ => exact succ
| left => exact unpair₁ head
| right => exact unpair₂ head
| pair _ _ hf hg => exact natPair.comp₂ _ hf hg
| comp _ _ hf hg => exact hf.comp₁ _ hg
| prec _ _ hf hg =>
simpa using
prec' (unpair₂ head) (hf.comp₁ _ (unpair₁ head))
(hg.comp₁ _ <|
natPair.comp₂ _ (unpair₁ <| tail <| tail head) (natPair.comp₂ _ head (tail head)))
theorem prim_iff {n f} : @Primrec' n f ↔ Primrec f :=
⟨to_prim, of_prim⟩
theorem prim_iff₁ {f : ℕ → ℕ} : (@Primrec' 1 fun v => f v.head) ↔ Primrec f :=
prim_iff.trans
⟨fun h => (h.comp <| .vector_ofFn fun _ => .id).of_eq fun v => by simp, fun h =>
h.comp .vector_head⟩
theorem prim_iff₂ {f : ℕ → ℕ → ℕ} : (@Primrec' 2 fun v => f v.head v.tail.head) ↔ Primrec₂ f :=
prim_iff.trans
⟨fun h => (h.comp <| Primrec.vector_cons.comp .fst <|
Primrec.vector_cons.comp .snd (.const nil)).of_eq fun v => by simp,
fun h => h.comp .vector_head (Primrec.vector_head.comp .vector_tail)⟩
theorem vec_iff {m n f} : @Vec m n f ↔ Primrec f :=
⟨fun h => by simpa using Primrec.vector_ofFn fun i => to_prim (h i), fun h i =>
of_prim <| Primrec.vector_get.comp h (.const i)⟩
end Nat.Primrec'
theorem Primrec.nat_sqrt : Primrec Nat.sqrt :=
Nat.Primrec'.prim_iff₁.1 Nat.Primrec'.sqrt
| Mathlib/Computability/Primrec.lean | 1,571 | 1,574 | |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
/-!
# Support of the derivative of a function
In this file we prove that the (topological) support of a function includes the support of its
derivative. As a corollary, we show that the derivative of a function with compact support has
compact support.
## Keywords
derivative, support
-/
universe u v
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {f : 𝕜 → E}
/-! ### Support of derivatives -/
section Support
open Function
theorem support_deriv_subset : support (deriv f) ⊆ tsupport f := by
intro x
| rw [← not_imp_not]
intro h2x
rw [not_mem_tsupport_iff_eventuallyEq] at h2x
exact nmem_support.mpr (h2x.deriv_eq.trans (deriv_const x 0))
protected theorem HasCompactSupport.deriv (hf : HasCompactSupport f) :
| Mathlib/Analysis/Calculus/Deriv/Support.lean | 36 | 41 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Joël Riou
-/
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Shift.Basic
import Mathlib.Data.Set.Subsingleton
import Mathlib.Algebra.Group.Int.Defs
/-!
# The category of graded objects
For any type `β`, a `β`-graded object over some category `C` is just
a function `β → C` into the objects of `C`.
We put the "pointwise" category structure on these, as the non-dependent specialization of
`CategoryTheory.Pi`.
We describe the `comap` functors obtained by precomposing with functions `β → γ`.
As a consequence a fixed element (e.g. `1`) in an additive group `β` provides a shift
functor on `β`-graded objects
When `C` has coproducts we construct the `total` functor `GradedObject β C ⥤ C`,
show that it is faithful, and deduce that when `C` is concrete so is `GradedObject β C`.
A covariant functoriality of `GradedObject β C` with respect to the index set `β` is also
introduced: if `p : I → J` is a map such that `C` has coproducts indexed by `p ⁻¹' {j}`, we
have a functor `map : GradedObject I C ⥤ GradedObject J C`.
-/
namespace CategoryTheory
open Category Limits
universe w v u
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`. -/
def GradedObject (β : Type w) (C : Type u) : Type max w u :=
β → C
-- Satisfying the inhabited linter...
instance inhabitedGradedObject (β : Type w) (C : Type u) [Inhabited C] :
Inhabited (GradedObject β C) :=
⟨fun _ => Inhabited.default⟩
-- `s` is here to distinguish type synonyms asking for different shifts
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`
with a shift functor given by translation by `s`.
-/
@[nolint unusedArguments]
abbrev GradedObjectWithShift {β : Type w} [AddCommGroup β] (_ : β) (C : Type u) : Type max w u :=
GradedObject β C
namespace GradedObject
variable {C : Type u} [Category.{v} C]
@[simps!]
instance categoryOfGradedObjects (β : Type w) : Category.{max w v} (GradedObject β C) :=
CategoryTheory.pi fun _ => C
@[ext]
lemma hom_ext {β : Type*} {X Y : GradedObject β C} (f g : X ⟶ Y) (h : ∀ x, f x = g x) : f = g := by
funext
apply h
/-- The projection of a graded object to its `i`-th component. -/
@[simps]
def eval {β : Type w} (b : β) : GradedObject β C ⥤ C where
obj X := X b
map f := f b
section
variable {β : Type*} (X Y : GradedObject β C)
/-- Constructor for isomorphisms in `GradedObject` -/
@[simps]
def isoMk (e : ∀ i, X i ≅ Y i) : X ≅ Y where
hom i := (e i).hom
inv i := (e i).inv
variable {X Y}
-- this lemma is not an instance as it may create a loop with `isIso_apply_of_isIso`
lemma isIso_of_isIso_apply (f : X ⟶ Y) [hf : ∀ i, IsIso (f i)] :
IsIso f := by
change IsIso (isoMk X Y (fun i => asIso (f i))).hom
infer_instance
instance isIso_apply_of_isIso (f : X ⟶ Y) [IsIso f] (i : β) : IsIso (f i) := by
change IsIso ((eval i).map f)
infer_instance
end
end GradedObject
namespace Iso
variable {C D E J : Type*} [Category C] [Category D] [Category E]
{X Y : GradedObject J C}
@[reassoc (attr := simp)]
lemma hom_inv_id_eval (e : X ≅ Y) (j : J) :
e.hom j ≫ e.inv j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma inv_hom_id_eval (e : X ≅ Y) (j : J) :
e.inv j ≫ e.hom j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.hom j) ≫ F.map (e.inv j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.inv j) ≫ F.map (e.hom j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.hom j)).app Y ≫ (F.map (e.inv j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, hom_inv_id_eval,
Functor.map_id, NatTrans.id_app]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.inv j)).app Y ≫ (F.map (e.hom j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, inv_hom_id_eval,
Functor.map_id, NatTrans.id_app]
end Iso
namespace GradedObject
variable {C : Type u} [Category.{v} C]
section
variable (C)
/-- Pull back an `I`-graded object in `C` to a `J`-graded object along a function `J → I`. -/
abbrev comap {I J : Type*} (h : J → I) : GradedObject I C ⥤ GradedObject J C :=
Pi.comap (fun _ => C) h
@[simp]
theorem eqToHom_proj {I : Type*} {x x' : GradedObject I C} (h : x = x') (i : I) :
(eqToHom h : x ⟶ x') i = eqToHom (funext_iff.mp h i) := by
subst h
rfl
/-- The natural isomorphism comparing between
pulling back along two propositionally equal functions.
-/
@[simps]
def comapEq {β γ : Type w} {f g : β → γ} (h : f = g) : comap C f ≅ comap C g where
hom := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
inv := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
theorem comapEq_symm {β γ : Type w} {f g : β → γ} (h : f = g) :
comapEq C h.symm = (comapEq C h).symm := by aesop_cat
theorem comapEq_trans {β γ : Type w} {f g h : β → γ} (k : f = g) (l : g = h) :
comapEq C (k.trans l) = comapEq C k ≪≫ comapEq C l := by aesop_cat
theorem eqToHom_apply {β : Type w} {X Y : β → C} (h : X = Y) (b : β) :
(eqToHom h : X ⟶ Y) b = eqToHom (by rw [h]) := by
subst h
rfl
/-- The equivalence between β-graded objects and γ-graded objects,
given an equivalence between β and γ.
-/
@[simps]
def comapEquiv {β γ : Type w} (e : β ≃ γ) : GradedObject β C ≌ GradedObject γ C where
functor := comap C (e.symm : γ → β)
inverse := comap C (e : β → γ)
counitIso :=
(Pi.comapComp (fun _ => C) _ _).trans (comapEq C (by ext; simp))
unitIso :=
(comapEq C (by ext; simp)).trans (Pi.comapComp _ _ _).symm
end
instance hasShift {β : Type*} [AddCommGroup β] (s : β) : HasShift (GradedObjectWithShift s C) ℤ :=
hasShiftMk _ _
{ F := fun n => comap C fun b : β => b + n • s
zero := comapEq C (by aesop_cat) ≪≫ Pi.comapId β fun _ => C
add := fun m n => comapEq C (by ext; dsimp; rw [add_comm m n, add_zsmul, add_assoc]) ≪≫
(Pi.comapComp _ _ _).symm }
@[simp]
theorem shiftFunctor_obj_apply {β : Type*} [AddCommGroup β] (s : β) (X : β → C) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).obj X t = X (t + n • s) :=
rfl
@[simp]
theorem shiftFunctor_map_apply {β : Type*} [AddCommGroup β] (s : β)
{X Y : GradedObjectWithShift s C} (f : X ⟶ Y) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).map f t = f (t + n • s) :=
rfl
instance [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) :
Zero (X ⟶ Y) := ⟨fun _ => 0⟩
@[simp]
theorem zero_apply [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) (b : β) :
(0 : X ⟶ Y) b = 0 :=
rfl
instance hasZeroMorphisms [HasZeroMorphisms C] (β : Type w) :
HasZeroMorphisms.{max w v} (GradedObject β C) where
section
open ZeroObject
instance hasZeroObject [HasZeroObject C] [HasZeroMorphisms C] (β : Type w) :
HasZeroObject.{max w v} (GradedObject β C) := by
refine ⟨⟨fun _ => 0, fun X => ⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩, fun X =>
⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩⟩⟩ <;> aesop_cat
end
end GradedObject
namespace GradedObject
-- The universes get a little hairy here, so we restrict the universe level for the grading to 0.
-- Since we're typically interested in grading by ℤ or a finite group, this should be okay.
-- If you're grading by things in higher universes, have fun!
variable (β : Type)
variable (C : Type u) [Category.{v} C]
variable [HasCoproducts.{0} C]
section
/-- The total object of a graded object is the coproduct of the graded components.
-/
noncomputable def total : GradedObject β C ⥤ C where
obj X := ∐ fun i : β => X i
map f := Limits.Sigma.map fun i => f i
end
variable [HasZeroMorphisms C]
/--
The `total` functor taking a graded object to the coproduct of its graded components is faithful.
To prove this, we need to know that the coprojections into the coproduct are monomorphisms,
which follows from the fact we have zero morphisms and decidable equality for the grading.
-/
instance : (total β C).Faithful where
map_injective {X Y} f g w := by
ext i
replace w := Sigma.ι (fun i : β => X i) i ≫= w
erw [colimit.ι_map, colimit.ι_map] at w
simp? at * says simp only [Discrete.functor_obj_eq_as, Discrete.natTrans_app] at *
exact Mono.right_cancellation _ _ w
end GradedObject
namespace GradedObject
noncomputable section
variable (β : Type)
variable (C : Type (u + 1)) [LargeCategory C] [HasForget C] [HasCoproducts.{0} C]
[HasZeroMorphisms C]
instance : HasForget (GradedObject β C) where forget := total β C ⋙ forget C
instance : HasForget₂ (GradedObject β C) C where forget₂ := total β C
end
end GradedObject
namespace GradedObject
variable {I J K : Type*} {C : Type*} [Category C]
(X Y Z : GradedObject I C) (φ : X ⟶ Y) (e : X ≅ Y) (ψ : Y ⟶ Z) (p : I → J)
/-- If `X : GradedObject I C` and `p : I → J`, `X.mapObjFun p j` is the family of objects `X i`
for `i : I` such that `p i = j`. -/
abbrev mapObjFun (j : J) (i : p ⁻¹' {j}) : C := X i
variable (j : J)
/-- Given `X : GradedObject I C` and `p : I → J`, `X.HasMap p` is the condition that
for all `j : J`, the coproduct of all `X i` such `p i = j` exists. -/
abbrev HasMap : Prop := ∀ (j : J), HasCoproduct (X.mapObjFun p j)
variable {X Y} in
lemma hasMap_of_iso (e : X ≅ Y) (p: I → J) [HasMap X p] : HasMap Y p := fun j => by
have α : Discrete.functor (X.mapObjFun p j) ≅ Discrete.functor (Y.mapObjFun p j) :=
Discrete.natIso (fun ⟨i, _⟩ => (GradedObject.eval i).mapIso e)
exact hasColimit_of_iso α.symm
section
variable [X.HasMap p] [Y.HasMap p]
/-- Given `X : GradedObject I C` and `p : I → J`, `X.mapObj p` is the graded object by `J`
which in degree `j` consists of the coproduct of the `X i` such that `p i = j`. -/
noncomputable def mapObj : GradedObject J C := fun j => ∐ (X.mapObjFun p j)
/-- The canonical inclusion `X i ⟶ X.mapObj p j` when `i : I` and `j : J` are such
that `p i = j`. -/
noncomputable def ιMapObj (i : I) (j : J) (hij : p i = j) : X i ⟶ X.mapObj p j :=
Sigma.ι (X.mapObjFun p j) ⟨i, hij⟩
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`,
`CofanMapObjFun X p j` is the type `Cofan (X.mapObjFun p j)`. The point object of
such colimits cofans are isomorphic to `X.mapObj p j`, see `CofanMapObjFun.iso`. -/
abbrev CofanMapObjFun (j : J) : Type _ := Cofan (X.mapObjFun p j)
-- in order to use the cofan API, some definitions below
-- have a `simp` attribute rather than `simps`
/-- Constructor for `CofanMapObjFun X p j`. -/
@[simp]
def CofanMapObjFun.mk (j : J) (pt : C) (ι' : ∀ (i : I) (_ : p i = j), X i ⟶ pt) :
CofanMapObjFun X p j :=
Cofan.mk pt (fun ⟨i, hi⟩ => ι' i hi)
/-- The tautological cofan corresponding to the coproduct decomposition of `X.mapObj p j`. -/
@[simp]
noncomputable def cofanMapObj (j : J) : CofanMapObjFun X p j :=
CofanMapObjFun.mk X p j (X.mapObj p j) (fun i hi => X.ιMapObj p i j hi)
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`, `X.mapObj p j` satisfies
the universal property of the coproduct of those `X i` such that `p i = j`. -/
noncomputable def isColimitCofanMapObj (j : J) : IsColimit (X.cofanMapObj p j) :=
colimit.isColimit _
@[ext]
lemma mapObj_ext {A : C} {j : J} (f g : X.mapObj p j ⟶ A)
(hfg : ∀ (i : I) (hij : p i = j), X.ιMapObj p i j hij ≫ f = X.ιMapObj p i j hij ≫ g) :
f = g :=
Cofan.IsColimit.hom_ext (X.isColimitCofanMapObj p j) _ _ (fun ⟨i, hij⟩ => hfg i hij)
/-- This is the morphism `X.mapObj p j ⟶ A` constructed from a family of
morphisms `X i ⟶ A` for all `i : I` such that `p i = j`. -/
noncomputable def descMapObj {A : C} {j : J} (φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) :
X.mapObj p j ⟶ A :=
Cofan.IsColimit.desc (X.isColimitCofanMapObj p j) (fun ⟨i, hi⟩ => φ i hi)
@[reassoc (attr := simp)]
lemma ι_descMapObj {A : C} {j : J}
(φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ X.descMapObj p φ = φ i hi := by
apply Cofan.IsColimit.fac
end
namespace CofanMapObjFun
lemma hasMap (c : ∀ j, CofanMapObjFun X p j) (hc : ∀ j, IsColimit (c j)) :
X.HasMap p := fun j => ⟨_, hc j⟩
variable {j X p}
variable [X.HasMap p]
variable {c : CofanMapObjFun X p j} (hc : IsColimit c)
/-- If `c : CofanMapObjFun X p j` is a colimit cofan, this is the induced
isomorphism `c.pt ≅ X.mapObj p j`. -/
noncomputable def iso : c.pt ≅ X.mapObj p j :=
IsColimit.coconePointUniqueUpToIso hc (X.isColimitCofanMapObj p j)
@[reassoc (attr := simp)]
lemma inj_iso_hom (i : I) (hi : p i = j) :
c.inj ⟨i, hi⟩ ≫ (c.iso hc).hom = X.ιMapObj p i j hi := by
apply IsColimit.comp_coconePointUniqueUpToIso_hom
@[reassoc (attr := simp)]
lemma ιMapObj_iso_inv (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ (c.iso hc).inv = c.inj ⟨i, hi⟩ := by
apply IsColimit.comp_coconePointUniqueUpToIso_inv
end CofanMapObjFun
variable {X Y}
variable [X.HasMap p] [Y.HasMap p]
/-- The canonical morphism of `J`-graded objects `X.mapObj p ⟶ Y.mapObj p` induced by
a morphism `X ⟶ Y` of `I`-graded objects and a map `p : I → J`. -/
noncomputable def mapMap : X.mapObj p ⟶ Y.mapObj p := fun j =>
X.descMapObj p (fun i hi => φ i ≫ Y.ιMapObj p i j hi)
@[reassoc (attr := simp)]
lemma ι_mapMap (i : I) (j : J) (hij : p i = j) :
X.ιMapObj p i j hij ≫ mapMap φ p j = φ i ≫ Y.ιMapObj p i j hij := by
simp only [mapMap, ι_descMapObj]
lemma congr_mapMap (φ₁ φ₂ : X ⟶ Y) (h : φ₁ = φ₂) : mapMap φ₁ p = mapMap φ₂ p := by
subst h
rfl
variable (X)
@[simp]
lemma mapMap_id : mapMap (𝟙 X) p = 𝟙 _ := by aesop_cat
variable {X Z}
@[simp, reassoc]
lemma mapMap_comp [Z.HasMap p] : mapMap (φ ≫ ψ) p = mapMap φ p ≫ mapMap ψ p := by aesop_cat
/-- The isomorphism of `J`-graded objects `X.mapObj p ≅ Y.mapObj p` induced by an
isomorphism `X ≅ Y` of graded objects and a map `p : I → J`. -/
@[simps]
noncomputable def mapIso : X.mapObj p ≅ Y.mapObj p where
hom := mapMap e.hom p
inv := mapMap e.inv p
variable (C)
/-- Given a map `p : I → J`, this is the functor `GradedObject I C ⥤ GradedObject J C` which
sends an `I`-object `X` to the graded object `X.mapObj p` which in degree `j : J` is given
by the coproduct of those `X i` such that `p i = j`. -/
@[simps]
noncomputable def map [∀ (j : J), HasColimitsOfShape (Discrete (p ⁻¹' {j})) C] :
GradedObject I C ⥤ GradedObject J C where
obj X := X.mapObj p
map φ := mapMap φ p
variable {C} (X Y)
variable (q : J → K) (r : I → K) (hpqr : ∀ i, q (p i) = r i)
|
section
| Mathlib/CategoryTheory/GradedObject.lean | 437 | 438 |
/-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Grading
import Mathlib.Algebra.Module.Opposite
/-!
# Conjugations
This file defines the grade reversal and grade involution functions on multivectors, `reverse` and
`involute`.
Together, these operations compose to form the "Clifford conjugate", hence the name of this file.
https://en.wikipedia.org/wiki/Clifford_algebra#Antiautomorphisms
## Main definitions
* `CliffordAlgebra.involute`: the grade involution, negating each basis vector
* `CliffordAlgebra.reverse`: the grade reversion, reversing the order of a product of vectors
## Main statements
* `CliffordAlgebra.involute_involutive`
* `CliffordAlgebra.reverse_involutive`
* `CliffordAlgebra.reverse_involute_commute`
* `CliffordAlgebra.involute_mem_evenOdd_iff`
* `CliffordAlgebra.reverse_mem_evenOdd_iff`
-/
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {Q : QuadraticForm R M}
namespace CliffordAlgebra
section Involute
/-- Grade involution, inverting the sign of each basis vector. -/
def involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q :=
CliffordAlgebra.lift Q ⟨-ι Q, fun m => by simp⟩
@[simp]
theorem involute_ι (m : M) : involute (ι Q m) = -ι Q m :=
lift_ι_apply _ _ m
@[simp]
theorem involute_comp_involute : involute.comp involute = AlgHom.id R (CliffordAlgebra Q) := by
ext; simp
theorem involute_involutive : Function.Involutive (involute : _ → CliffordAlgebra Q) :=
AlgHom.congr_fun involute_comp_involute
@[simp]
theorem involute_involute : ∀ a : CliffordAlgebra Q, involute (involute a) = a :=
involute_involutive
/-- `CliffordAlgebra.involute` as an `AlgEquiv`. -/
@[simps!]
def involuteEquiv : CliffordAlgebra Q ≃ₐ[R] CliffordAlgebra Q :=
AlgEquiv.ofAlgHom involute involute (AlgHom.ext <| involute_involute)
(AlgHom.ext <| involute_involute)
end Involute
section Reverse
open MulOpposite
/-- `CliffordAlgebra.reverse` as an `AlgHom` to the opposite algebra -/
def reverseOp : CliffordAlgebra Q →ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ :=
CliffordAlgebra.lift Q
⟨(MulOpposite.opLinearEquiv R).toLinearMap ∘ₗ ι Q, fun m => unop_injective <| by simp⟩
@[simp]
theorem reverseOp_ι (m : M) : reverseOp (ι Q m) = op (ι Q m) := lift_ι_apply _ _ _
/-- `CliffordAlgebra.reverseEquiv` as an `AlgEquiv` to the opposite algebra -/
@[simps! apply]
def reverseOpEquiv : CliffordAlgebra Q ≃ₐ[R] (CliffordAlgebra Q)ᵐᵒᵖ :=
AlgEquiv.ofAlgHom reverseOp (AlgHom.opComm reverseOp)
(AlgHom.unop.injective <| hom_ext <| LinearMap.ext fun _ => by simp)
(hom_ext <| LinearMap.ext fun _ => by simp)
@[simp]
theorem reverseOpEquiv_opComm :
AlgEquiv.opComm (reverseOpEquiv (Q := Q)) = reverseOpEquiv.symm := rfl
/-- Grade reversion, inverting the multiplication order of basis vectors.
Also called *transpose* in some literature. -/
def reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q :=
(opLinearEquiv R).symm.toLinearMap.comp reverseOp.toLinearMap
@[simp] theorem unop_reverseOp (x : CliffordAlgebra Q) : (reverseOp x).unop = reverse x := rfl
@[simp] theorem op_reverse (x : CliffordAlgebra Q) : op (reverse x) = reverseOp x := rfl
@[simp]
theorem reverse_ι (m : M) : reverse (ι Q m) = ι Q m := by simp [reverse]
@[simp]
theorem reverse.commutes (r : R) :
reverse (algebraMap R (CliffordAlgebra Q) r) = algebraMap R _ r :=
op_injective <| reverseOp.commutes r
@[simp]
protected theorem reverse.map_one : reverse (1 : CliffordAlgebra Q) = 1 :=
op_injective (map_one reverseOp)
@[simp]
protected theorem reverse.map_mul (a b : CliffordAlgebra Q) :
reverse (a * b) = reverse b * reverse a :=
op_injective (map_mul reverseOp a b)
@[simp]
theorem reverse_involutive : Function.Involutive (reverse (Q := Q)) :=
AlgHom.congr_fun reverseOpEquiv.symm_comp
@[simp]
theorem reverse_comp_reverse :
reverse.comp reverse = (LinearMap.id : _ →ₗ[R] CliffordAlgebra Q) :=
LinearMap.ext reverse_involutive
@[simp]
theorem reverse_reverse : ∀ a : CliffordAlgebra Q, reverse (reverse a) = a :=
reverse_involutive
/-- `CliffordAlgebra.reverse` as a `LinearEquiv`. -/
@[simps!]
def reverseEquiv : CliffordAlgebra Q ≃ₗ[R] CliffordAlgebra Q :=
LinearEquiv.ofInvolutive reverse reverse_involutive
theorem reverse_comp_involute :
reverse.comp involute.toLinearMap =
(involute.toLinearMap.comp reverse : _ →ₗ[R] CliffordAlgebra Q) := by
ext x
simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply]
induction x using CliffordAlgebra.induction with
| algebraMap => simp
| ι => simp
| mul a b ha hb => simp only [ha, hb, reverse.map_mul, map_mul]
| add a b ha hb => simp only [ha, hb, reverse.map_add, map_add]
/-- `CliffordAlgebra.reverse` and `CliffordAlgebra.involute` commute. Note that the composition
is sometimes referred to as the "clifford conjugate". -/
theorem reverse_involute_commute : Function.Commute (reverse (Q := Q)) involute :=
LinearMap.congr_fun reverse_comp_involute
theorem reverse_involute :
∀ a : CliffordAlgebra Q, reverse (involute a) = involute (reverse a) :=
reverse_involute_commute
end Reverse
/-!
### Statements about conjugations of products of lists
-/
section List
/-- Taking the reverse of the product a list of $n$ vectors lifted via `ι` is equivalent to
taking the product of the reverse of that list. -/
theorem reverse_prod_map_ι :
∀ l : List M, reverse (l.map <| ι Q).prod = (l.map <| ι Q).reverse.prod
| [] => by simp
| x::xs => by simp [reverse_prod_map_ι xs]
/-- Taking the involute of the product a list of $n$ vectors lifted via `ι` is equivalent to
premultiplying by ${-1}^n$. -/
theorem involute_prod_map_ι :
∀ l : List M, involute (l.map <| ι Q).prod = (-1 : R) ^ l.length • (l.map <| ι Q).prod
| [] => by simp
| x::xs => by simp [pow_succ, involute_prod_map_ι xs]
end List
/-!
### Statements about `Submodule.map` and `Submodule.comap`
-/
section Submodule
variable (Q)
section Involute
theorem submodule_map_involute_eq_comap (p : Submodule R (CliffordAlgebra Q)) :
p.map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
p.comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap :=
Submodule.map_equiv_eq_comap_symm involuteEquiv.toLinearEquiv _
@[simp]
theorem ι_range_map_involute :
(LinearMap.range (ι Q)).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
LinearMap.range (ι Q) :=
(ι_range_map_lift _ _).trans (LinearMap.range_neg _)
@[simp]
theorem ι_range_comap_involute :
(LinearMap.range (ι Q)).comap
(involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
LinearMap.range (ι Q) := by
rw [← submodule_map_involute_eq_comap, ι_range_map_involute]
@[simp]
theorem evenOdd_map_involute (n : ZMod 2) :
(evenOdd Q n).map (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
evenOdd Q n := by
simp_rw [evenOdd, Submodule.map_iSup, Submodule.map_pow, ι_range_map_involute]
@[simp]
theorem evenOdd_comap_involute (n : ZMod 2) :
(evenOdd Q n).comap (involute : CliffordAlgebra Q →ₐ[R] CliffordAlgebra Q).toLinearMap =
evenOdd Q n := by
rw [← submodule_map_involute_eq_comap, evenOdd_map_involute]
end Involute
section Reverse
theorem submodule_map_reverse_eq_comap (p : Submodule R (CliffordAlgebra Q)) :
p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) =
p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) :=
Submodule.map_equiv_eq_comap_symm (reverseEquiv : _ ≃ₗ[R] _) _
@[simp]
theorem ι_range_map_reverse :
(LinearMap.range (ι Q)).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q)
= LinearMap.range (ι Q) := by
rw [reverse, reverseOp, Submodule.map_comp, ι_range_map_lift, LinearMap.range_comp,
← Submodule.map_comp]
exact Submodule.map_id _
@[simp]
theorem ι_range_comap_reverse :
(LinearMap.range (ι Q)).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q)
= LinearMap.range (ι Q) := by
rw [← submodule_map_reverse_eq_comap, ι_range_map_reverse]
/-- Like `Submodule.map_mul`, but with the multiplication reversed. -/
theorem submodule_map_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) :
(p * q).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) =
q.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) *
p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by
simp_rw [reverse, Submodule.map_comp, Submodule.map_mul, Submodule.map_unop_mul]
theorem submodule_comap_mul_reverse (p q : Submodule R (CliffordAlgebra Q)) :
(p * q).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) =
q.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) *
p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) := by
simp_rw [← submodule_map_reverse_eq_comap, submodule_map_mul_reverse]
/-- Like `Submodule.map_pow` -/
theorem submodule_map_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) :
(p ^ n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) =
p.map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by
simp_rw [reverse, Submodule.map_comp, Submodule.map_pow, Submodule.map_unop_pow]
theorem submodule_comap_pow_reverse (p : Submodule R (CliffordAlgebra Q)) (n : ℕ) :
(p ^ n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) =
p.comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) ^ n := by
simp_rw [← submodule_map_reverse_eq_comap, submodule_map_pow_reverse]
@[simp]
theorem evenOdd_map_reverse (n : ZMod 2) :
(evenOdd Q n).map (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by
simp_rw [evenOdd, Submodule.map_iSup, submodule_map_pow_reverse, ι_range_map_reverse]
@[simp]
theorem evenOdd_comap_reverse (n : ZMod 2) :
(evenOdd Q n).comap (reverse : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q) = evenOdd Q n := by
rw [← submodule_map_reverse_eq_comap, evenOdd_map_reverse]
end Reverse
@[simp]
theorem involute_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} :
involute x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n :=
SetLike.ext_iff.mp (evenOdd_comap_involute Q n) x
@[simp]
theorem reverse_mem_evenOdd_iff {x : CliffordAlgebra Q} {n : ZMod 2} :
reverse x ∈ evenOdd Q n ↔ x ∈ evenOdd Q n :=
SetLike.ext_iff.mp (evenOdd_comap_reverse Q n) x
end Submodule
/-!
### Related properties of the even and odd submodules
|
TODO: show that these are `iff`s when `Invertible (2 : R)`.
-/
| Mathlib/LinearAlgebra/CliffordAlgebra/Conjugation.lean | 295 | 298 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Monotone.Basic
import Mathlib.Order.ULift
import Mathlib.Tactic.GCongr.CoreAttrs
/-!
# (Semi-)lattices
Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest
lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and
meet-semilattices.
Distributive lattices are lattices which satisfy any of four equivalent distributivity properties,
of `sup` over `inf`, on the left or on the right.
## Main declarations
* `SemilatticeSup`: a type class for join semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is
commutative, associative and idempotent.
* `SemilatticeInf`: a type class for meet semilattices
* `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is
commutative, associative and idempotent.
* `Lattice`: a type class for lattices
* `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are
commutative, associative and satisfy a pair of "absorption laws".
* `DistribLattice`: a type class for distributive lattices.
## Notations
* `a ⊔ b`: the supremum or join of `a` and `b`
* `a ⊓ b`: the infimum or meet of `a` and `b`
## TODO
* (Semi-)lattice homomorphisms
* Alternative constructors for distributive lattices from the other distributive properties
## Tags
semilattice, lattice
-/
/-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/
@[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where
eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h])
universe u v w
variable {α : Type u} {β : Type v}
/-!
### Join-semilattices
-/
-- TODO: automatic construction of dual definitions / theorems
/-- A `SemilatticeSup` is a join-semilattice, that is, a partial order
with a join (a.k.a. lub / least upper bound, sup / supremum) operation
`⊔` which is the least element larger than both factors. -/
class SemilatticeSup (α : Type u) extends PartialOrder α where
/-- The binary supremum, used to derive `Max α` -/
sup : α → α → α
/-- The supremum is an upper bound on the first argument -/
protected le_sup_left : ∀ a b : α, a ≤ sup a b
/-- The supremum is an upper bound on the second argument -/
protected le_sup_right : ∀ a b : α, b ≤ sup a b
/-- The supremum is the *least* upper bound -/
protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c
instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b
/--
A type with a commutative, associative and idempotent binary `sup` operation has the structure of a
join-semilattice.
The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`.
-/
def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a)
(sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) :
SemilatticeSup α where
sup := (· ⊔ ·)
le a b := a ⊔ b = b
le_refl := sup_idem
le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab]
le_antisymm a b hab hba := by rwa [← hba, sup_comm]
le_sup_left a b := by rw [← sup_assoc, sup_idem]
le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem]
sup_le a b c hac hbc := by rwa [sup_assoc, hbc]
section SemilatticeSup
variable [SemilatticeSup α] {a b c d : α}
@[simp]
theorem le_sup_left : a ≤ a ⊔ b :=
SemilatticeSup.le_sup_left a b
@[simp]
theorem le_sup_right : b ≤ a ⊔ b :=
SemilatticeSup.le_sup_right a b
theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b :=
le_trans h le_sup_left
theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b :=
le_trans h le_sup_right
theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b :=
h.trans_le le_sup_left
theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b :=
h.trans_le le_sup_right
theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c :=
SemilatticeSup.sup_le a b c
@[simp]
theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c :=
⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩,
fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩
@[simp]
theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b :=
le_antisymm_iff.trans <| by simp [le_rfl]
@[simp]
theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a :=
eq_comm.trans sup_eq_left
@[simp]
theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b :=
eq_comm.trans sup_eq_right
alias ⟨_, sup_of_le_left⟩ := sup_eq_left
alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right
attribute [simp] sup_of_le_left sup_of_le_right
@[simp]
theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a :=
le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup
@[simp]
theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b :=
le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup
theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2
theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by
constructor
· intro h
exact ⟨b, (sup_eq_right.mpr h).symm⟩
· rintro ⟨c, rfl : _ = _ ⊔ _⟩
exact le_sup_left
@[gcongr]
theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d :=
sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂)
@[gcongr]
theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b :=
sup_le_sup le_rfl h₁
@[gcongr]
theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c :=
sup_le_sup h₁ le_rfl
theorem sup_idem (a : α) : a ⊔ a = a := by simp
instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp
instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) :=
eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc]
instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩
theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by
rw [sup_comm, sup_comm a, sup_assoc]
theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp
theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp
theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by
rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a]
theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by
rw [sup_assoc, sup_assoc, sup_comm b]
theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by
rw [sup_assoc, sup_left_comm b, ← sup_assoc]
theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by
rw [sup_sup_sup_comm, sup_idem]
theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c :=
(sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc
theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c :=
(sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right
theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b :=
⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩
theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c :=
⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩
theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b :=
hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2
/-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/
theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f)
(hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n :=
calc
f m ≤ f (m ⊔ n) := hf le_sup_left
_ ≤ g (m ⊔ n) := h _
_ ≤ g n := hg le_sup_right
theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y)
| (x y : α) :
| Mathlib/Order/Lattice.lean | 242 | 242 |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Analysis.Normed.Group.Hom
import Mathlib.Analysis.Normed.Group.Completion
/-!
# Completion of normed group homs
Given two (semi) normed groups `G` and `H` and a normed group hom `f : NormedAddGroupHom G H`,
we build and study a normed group hom
`f.completion : NormedAddGroupHom (completion G) (completion H)` such that the diagram
```
f
G -----------> H
| |
| |
| |
V V
completion G -----------> completion H
f.completion
```
commutes. The map itself comes from the general theory of completion of uniform spaces, but here
we want a normed group hom, study its operator norm and kernel.
The vertical maps in the above diagrams are also normed group homs constructed in this file.
## Main definitions and results:
* `NormedAddGroupHom.completion`: see the discussion above.
* `NormedAddCommGroup.toCompl : NormedAddGroupHom G (completion G)`: the canonical map from
`G` to its completion, as a normed group hom
* `NormedAddGroupHom.completion_toCompl`: the above diagram indeed commutes.
* `NormedAddGroupHom.norm_completion`: `‖f.completion‖ = ‖f‖`
* `NormedAddGroupHom.ker_le_ker_completion`: the kernel of `f.completion` contains the image of
the kernel of `f`.
* `NormedAddGroupHom.ker_completion`: the kernel of `f.completion` is the closure of the image of
the kernel of `f` under an assumption that `f` is quantitatively surjective onto its image.
* `NormedAddGroupHom.extension` : if `H` is complete, the extension of
`f : NormedAddGroupHom G H` to a `NormedAddGroupHom (completion G) H`.
-/
noncomputable section
open Set NormedAddGroupHom UniformSpace
section Completion
variable {G : Type*} [SeminormedAddCommGroup G] {H : Type*} [SeminormedAddCommGroup H]
{K : Type*} [SeminormedAddCommGroup K]
/-- The normed group hom induced between completions. -/
def NormedAddGroupHom.completion (f : NormedAddGroupHom G H) :
NormedAddGroupHom (Completion G) (Completion H) :=
.ofLipschitz (f.toAddMonoidHom.completion f.continuous) f.lipschitz.completion_map
theorem NormedAddGroupHom.completion_def (f : NormedAddGroupHom G H) (x : Completion G) :
f.completion x = Completion.map f x :=
rfl
@[simp]
theorem NormedAddGroupHom.completion_coe_to_fun (f : NormedAddGroupHom G H) :
(f.completion : Completion G → Completion H) = Completion.map f := rfl
theorem NormedAddGroupHom.completion_coe (f : NormedAddGroupHom G H) (g : G) :
f.completion g = f g :=
Completion.map_coe f.uniformContinuous _
@[simp]
theorem NormedAddGroupHom.completion_coe' (f : NormedAddGroupHom G H) (g : G) :
Completion.map f g = f g :=
f.completion_coe g
/-- Completion of normed group homs as a normed group hom. -/
@[simps]
def normedAddGroupHomCompletionHom :
NormedAddGroupHom G H →+ NormedAddGroupHom (Completion G) (Completion H) where
toFun := NormedAddGroupHom.completion
map_zero' := toAddMonoidHom_injective AddMonoidHom.completion_zero
map_add' f g := toAddMonoidHom_injective <|
f.toAddMonoidHom.completion_add g.toAddMonoidHom f.continuous g.continuous
@[simp]
theorem NormedAddGroupHom.completion_id :
(NormedAddGroupHom.id G).completion = NormedAddGroupHom.id (Completion G) := by
ext x
rw [NormedAddGroupHom.completion_def, NormedAddGroupHom.coe_id, Completion.map_id]
rfl
theorem NormedAddGroupHom.completion_comp (f : NormedAddGroupHom G H) (g : NormedAddGroupHom H K) :
g.completion.comp f.completion = (g.comp f).completion := by
ext x
rw [NormedAddGroupHom.coe_comp, NormedAddGroupHom.completion_def,
NormedAddGroupHom.completion_coe_to_fun, NormedAddGroupHom.completion_coe_to_fun,
Completion.map_comp g.uniformContinuous f.uniformContinuous]
rfl
theorem NormedAddGroupHom.completion_neg (f : NormedAddGroupHom G H) :
(-f).completion = -f.completion :=
map_neg (normedAddGroupHomCompletionHom : NormedAddGroupHom G H →+ _) f
theorem NormedAddGroupHom.completion_add (f g : NormedAddGroupHom G H) :
(f + g).completion = f.completion + g.completion :=
normedAddGroupHomCompletionHom.map_add f g
theorem NormedAddGroupHom.completion_sub (f g : NormedAddGroupHom G H) :
(f - g).completion = f.completion - g.completion :=
map_sub (normedAddGroupHomCompletionHom : NormedAddGroupHom G H →+ _) f g
@[simp]
theorem NormedAddGroupHom.zero_completion : (0 : NormedAddGroupHom G H).completion = 0 :=
normedAddGroupHomCompletionHom.map_zero
/-- The map from a normed group to its completion, as a normed group hom. -/
@[simps]
def NormedAddCommGroup.toCompl : NormedAddGroupHom G (Completion G) where
toFun := (↑)
map_add' := Completion.toCompl.map_add
bound' := ⟨1, by simp [le_refl]⟩
open NormedAddCommGroup
theorem NormedAddCommGroup.norm_toCompl (x : G) : ‖toCompl x‖ = ‖x‖ :=
Completion.norm_coe x
theorem NormedAddCommGroup.denseRange_toCompl : DenseRange (toCompl : G → Completion G) :=
Completion.isDenseInducing_coe.dense
@[simp]
theorem NormedAddGroupHom.completion_toCompl (f : NormedAddGroupHom G H) :
f.completion.comp toCompl = toCompl.comp f := by ext x; simp
@[simp]
theorem NormedAddGroupHom.norm_completion (f : NormedAddGroupHom G H) : ‖f.completion‖ = ‖f‖ :=
le_antisymm (ofLipschitz_norm_le _ _) <| opNorm_le_bound _ (norm_nonneg _) fun x => by
simpa using f.completion.le_opNorm x
theorem NormedAddGroupHom.ker_le_ker_completion (f : NormedAddGroupHom G H) :
(toCompl.comp <| incl f.ker).range ≤ f.completion.ker := by
rintro _ ⟨⟨g, h₀ : f g = 0⟩, rfl⟩
simp [h₀, mem_ker, Completion.coe_zero]
theorem NormedAddGroupHom.ker_completion {f : NormedAddGroupHom G H} {C : ℝ}
(h : f.SurjectiveOnWith f.range C) :
(f.completion.ker : Set <| Completion G) = closure (toCompl.comp <| incl f.ker).range := by
refine le_antisymm ?_ (closure_minimal f.ker_le_ker_completion f.completion.isClosed_ker)
rintro hatg (hatg_in : f.completion hatg = 0)
rw [SeminormedAddCommGroup.mem_closure_iff]
intro ε ε_pos
rcases h.exists_pos with ⟨C', C'_pos, hC'⟩
rcases exists_pos_mul_lt ε_pos (1 + C' * ‖f‖) with ⟨δ, δ_pos, hδ⟩
obtain ⟨_, ⟨g : G, rfl⟩, hg : ‖hatg - g‖ < δ⟩ :=
SeminormedAddCommGroup.mem_closure_iff.mp (Completion.isDenseInducing_coe.dense hatg) δ δ_pos
obtain ⟨g' : G, hgg' : f g' = f g, hfg : ‖g'‖ ≤ C' * ‖f g‖⟩ := hC' (f g) (mem_range_self _ g)
have mem_ker : g - g' ∈ f.ker := by rw [f.mem_ker, map_sub, sub_eq_zero.mpr hgg'.symm]
refine ⟨_, ⟨⟨g - g', mem_ker⟩, rfl⟩, ?_⟩
have : ‖f g‖ ≤ ‖f‖ * δ := calc
| ‖f g‖ ≤ ‖f‖ * ‖hatg - g‖ := by
simpa [map_sub, hatg_in] using f.completion.le_opNorm (hatg - g)
_ ≤ ‖f‖ * δ := by gcongr
calc ‖hatg - ↑(g - g')‖ = ‖hatg - g + g'‖ := by rw [Completion.coe_sub, sub_add]
| Mathlib/Analysis/Normed/Group/HomCompletion.lean | 165 | 168 |
/-
Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Zhouhang Zhou
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable
import Mathlib.MeasureTheory.Integral.Lebesgue.Add
import Mathlib.Order.Filter.Germ.Basic
import Mathlib.Topology.ContinuousMap.Algebra
/-!
# Almost everywhere equal functions
We build a space of equivalence classes of functions, where two functions are treated as identical
if they are almost everywhere equal. We form the set of equivalence classes under the relation of
being almost everywhere equal, which is sometimes known as the `L⁰` space.
To use this space as a basis for the `L^p` spaces and for the Bochner integral, we consider
equivalence classes of strongly measurable functions (or, equivalently, of almost everywhere
strongly measurable functions.)
See `L1Space.lean` for `L¹` space.
## Notation
* `α →ₘ[μ] β` is the type of `L⁰` space, where `α` is a measurable space, `β` is a topological
space, and `μ` is a measure on `α`. `f : α →ₘ β` is a "function" in `L⁰`.
In comments, `[f]` is also used to denote an `L⁰` function.
`ₘ` can be typed as `\_m`. Sometimes it is shown as a box if font is missing.
## Main statements
* The linear structure of `L⁰` :
Addition and scalar multiplication are defined on `L⁰` in the natural way, i.e.,
`[f] + [g] := [f + g]`, `c • [f] := [c • f]`. So defined, `α →ₘ β` inherits the linear structure
of `β`. For example, if `β` is a module, then `α →ₘ β` is a module over the same ring.
See `mk_add_mk`, `neg_mk`, `mk_sub_mk`, `smul_mk`,
`add_toFun`, `neg_toFun`, `sub_toFun`, `smul_toFun`
* The order structure of `L⁰` :
`≤` can be defined in a similar way: `[f] ≤ [g]` if `f a ≤ g a` for almost all `a` in domain.
And `α →ₘ β` inherits the preorder and partial order of `β`.
TODO: Define `sup` and `inf` on `L⁰` so that it forms a lattice. It seems that `β` must be a
linear order, since otherwise `f ⊔ g` may not be a measurable function.
## Implementation notes
* `f.toFun` : To find a representative of `f : α →ₘ β`, use the coercion `(f : α → β)`, which
is implemented as `f.toFun`.
For each operation `op` in `L⁰`, there is a lemma called `coe_fn_op`,
characterizing, say, `(f op g : α → β)`.
* `ae_eq_fun.mk` : To constructs an `L⁰` function `α →ₘ β` from an almost everywhere strongly
measurable function `f : α → β`, use `ae_eq_fun.mk`
* `comp` : Use `comp g f` to get `[g ∘ f]` from `g : β → γ` and `[f] : α →ₘ γ` when `g` is
continuous. Use `comp_measurable` if `g` is only measurable (this requires the
target space to be second countable).
* `comp₂` : Use `comp₂ g f₁ f₂` to get `[fun a ↦ g (f₁ a) (f₂ a)]`.
For example, `[f + g]` is `comp₂ (+)`
## Tags
function space, almost everywhere equal, `L⁰`, ae_eq_fun
-/
-- Guard against import creep
assert_not_exists InnerProductSpace
noncomputable section
open Topology Set Filter TopologicalSpace ENNReal EMetric MeasureTheory Function
variable {α β γ δ : Type*} [MeasurableSpace α] {μ ν : Measure α}
namespace MeasureTheory
section MeasurableSpace
variable [TopologicalSpace β]
variable (β)
/-- The equivalence relation of being almost everywhere equal for almost everywhere strongly
measurable functions. -/
def Measure.aeEqSetoid (μ : Measure α) : Setoid { f : α → β // AEStronglyMeasurable f μ } :=
⟨fun f g => (f : α → β) =ᵐ[μ] g, fun {f} => ae_eq_refl f.val, fun {_ _} => ae_eq_symm,
fun {_ _ _} => ae_eq_trans⟩
variable (α)
/-- The space of equivalence classes of almost everywhere strongly measurable functions, where two
strongly measurable functions are equivalent if they agree almost everywhere, i.e.,
they differ on a set of measure `0`. -/
def AEEqFun (μ : Measure α) : Type _ :=
Quotient (μ.aeEqSetoid β)
variable {α β}
@[inherit_doc MeasureTheory.AEEqFun]
notation:25 α " →ₘ[" μ "] " β => AEEqFun α β μ
end MeasurableSpace
variable [TopologicalSpace δ]
namespace AEEqFun
section
variable [TopologicalSpace β]
/-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based
on the equivalence relation of being almost everywhere equal. -/
def mk {β : Type*} [TopologicalSpace β] (f : α → β) (hf : AEStronglyMeasurable f μ) : α →ₘ[μ] β :=
Quotient.mk'' ⟨f, hf⟩
open scoped Classical in
/-- Coercion from a space of equivalence classes of almost everywhere strongly measurable
functions to functions. We ensure that if `f` has a constant representative,
then we choose that one. -/
@[coe]
def cast (f : α →ₘ[μ] β) : α → β :=
if h : ∃ (b : β), f = mk (const α b) aestronglyMeasurable_const then
const α <| Classical.choose h else
AEStronglyMeasurable.mk _ (Quotient.out f : { f : α → β // AEStronglyMeasurable f μ }).2
/-- A measurable representative of an `AEEqFun` [f] -/
instance instCoeFun : CoeFun (α →ₘ[μ] β) fun _ => α → β := ⟨cast⟩
protected theorem stronglyMeasurable (f : α →ₘ[μ] β) : StronglyMeasurable f := by
simp only [cast]
split_ifs with h
· exact stronglyMeasurable_const
· apply AEStronglyMeasurable.stronglyMeasurable_mk
protected theorem aestronglyMeasurable (f : α →ₘ[μ] β) : AEStronglyMeasurable f μ :=
f.stronglyMeasurable.aestronglyMeasurable
protected theorem measurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(f : α →ₘ[μ] β) : Measurable f :=
f.stronglyMeasurable.measurable
protected theorem aemeasurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β]
(f : α →ₘ[μ] β) : AEMeasurable f μ :=
f.measurable.aemeasurable
@[simp]
theorem quot_mk_eq_mk (f : α → β) (hf) :
(Quot.mk (@Setoid.r _ <| μ.aeEqSetoid β) ⟨f, hf⟩ : α →ₘ[μ] β) = mk f hf :=
rfl
@[simp]
theorem mk_eq_mk {f g : α → β} {hf hg} : (mk f hf : α →ₘ[μ] β) = mk g hg ↔ f =ᵐ[μ] g :=
Quotient.eq''
@[simp]
theorem mk_coeFn (f : α →ₘ[μ] β) : mk f f.aestronglyMeasurable = f := by
conv_lhs => simp only [cast]
split_ifs with h
· exact Classical.choose_spec h |>.symm
conv_rhs => rw [← Quotient.out_eq' f]
rw [← mk, mk_eq_mk]
exact (AEStronglyMeasurable.ae_eq_mk _).symm
@[ext]
theorem ext {f g : α →ₘ[μ] β} (h : f =ᵐ[μ] g) : f = g := by
| rwa [← f.mk_coeFn, ← g.mk_coeFn, mk_eq_mk]
| Mathlib/MeasureTheory/Function/AEEqFun.lean | 170 | 171 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Fintype.Lattice
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Ideal.Basic
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# More operations on modules and ideals
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Submodule
lemma coe_span_smul {R' M' : Type*} [CommSemiring R'] [AddCommMonoid M'] [Module R' M']
(s : Set R') (N : Submodule R' M') :
(Ideal.span s : Set R') • N = s • N :=
set_smul_eq_of_le _ _ _
(by rintro r n hr hn
induction hr using Submodule.span_induction with
| mem _ h => exact mem_set_smul_of_mem_mem h hn
| zero => rw [zero_smul]; exact Submodule.zero_mem _
| add _ _ _ _ ihr ihs => rw [add_smul]; exact Submodule.add_mem _ ihr ihs
| smul _ _ hr =>
rw [mem_span_set] at hr
obtain ⟨c, hc, rfl⟩ := hr
rw [Finsupp.sum, Finset.smul_sum, Finset.sum_smul]
refine Submodule.sum_mem _ fun i hi => ?_
rw [← mul_smul, smul_eq_mul, mul_comm, mul_smul]
exact mem_set_smul_of_mem_mem (hc hi) <| Submodule.smul_mem _ _ hn) <|
set_smul_mono_left _ Submodule.subset_span
lemma span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
(span ℤ {a}).toAddSubgroup = AddSubgroup.zmultiples a := by
ext i
simp [Ideal.mem_span_singleton', AddSubgroup.mem_zmultiples_iff]
@[simp] lemma _root_.Ideal.span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) :
| (Ideal.span {a}).toAddSubgroup = AddSubgroup.zmultiples a :=
Submodule.span_singleton_toAddSubgroup_eq_zmultiples _
| Mathlib/RingTheory/Ideal/Operations.lean | 50 | 52 |
/-
Copyright (c) 2022 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts
/-!
# Limits involving zero objects
Binary products and coproducts with a zero object always exist,
and pullbacks/pushouts over a zero object are products/coproducts.
-/
noncomputable section
open CategoryTheory
variable {C : Type*} [Category C]
namespace CategoryTheory.Limits
variable [HasZeroObject C] [HasZeroMorphisms C]
open ZeroObject
/-- The limit cone for the product with a zero object. -/
def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X :=
BinaryFan.mk 0 (𝟙 X)
/-- The limit cone for the product with a zero object is limiting. -/
def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) :=
BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by aesop_cat) (by simp)
(fun s m _ h₂ => by simpa using h₂)
instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X :=
HasLimit.mk ⟨_, binaryFanZeroLeftIsLimit X⟩
/-- A zero object is a left unit for categorical product. -/
def zeroProdIso (X : C) : (0 : C) ⨯ X ≅ X :=
limit.isoLimitCone ⟨_, binaryFanZeroLeftIsLimit X⟩
@[simp]
theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd :=
rfl
@[simp]
theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv ≫ prod.snd = 𝟙 X := by
dsimp [zeroProdIso, binaryFanZeroLeft]
simp
/-- The limit cone for the product with a zero object. -/
def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) :=
BinaryFan.mk (𝟙 X) 0
/-- The limit cone for the product with a zero object is limiting. -/
def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) :=
BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by simp) (by aesop_cat)
(fun s m h₁ _ => by simpa using h₁)
instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) :=
HasLimit.mk ⟨_, binaryFanZeroRightIsLimit X⟩
/-- A zero object is a right unit for categorical product. -/
def prodZeroIso (X : C) : X ⨯ (0 : C) ≅ X :=
limit.isoLimitCone ⟨_, binaryFanZeroRightIsLimit X⟩
@[simp]
theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst :=
rfl
@[simp]
theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv ≫ prod.fst = 𝟙 X := by
dsimp [prodZeroIso, binaryFanZeroRight]
simp
/-- The colimit cocone for the coproduct with a zero object. -/
def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X :=
BinaryCofan.mk 0 (𝟙 X)
/-- The colimit cocone for the coproduct with a zero object is colimiting. -/
def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) :=
BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by aesop_cat) (by simp)
(fun s m _ h₂ => by simpa using h₂)
instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X :=
HasColimit.mk ⟨_, binaryCofanZeroLeftIsColimit X⟩
/-- A zero object is a left unit for categorical coproduct. -/
def zeroCoprodIso (X : C) : (0 : C) ⨿ X ≅ X :=
colimit.isoColimitCocone ⟨_, binaryCofanZeroLeftIsColimit X⟩
@[simp]
theorem inr_zeroCoprodIso_hom (X : C) : coprod.inr ≫ (zeroCoprodIso X).hom = 𝟙 X := by
dsimp [zeroCoprodIso, binaryCofanZeroLeft]
simp
@[simp]
theorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr :=
rfl
/-- The colimit cocone for the coproduct with a zero object. -/
def binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) :=
BinaryCofan.mk (𝟙 X) 0
/-- The colimit cocone for the coproduct with a zero object is colimiting. -/
def binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) :=
BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by simp) (by aesop_cat)
(fun s m h₁ _ => by simpa using h₁)
instance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) :=
HasColimit.mk ⟨_, binaryCofanZeroRightIsColimit X⟩
/-- A zero object is a right unit for categorical coproduct. -/
def coprodZeroIso (X : C) : X ⨿ (0 : C) ≅ X :=
colimit.isoColimitCocone ⟨_, binaryCofanZeroRightIsColimit X⟩
@[simp]
theorem inr_coprodZeroIso_hom (X : C) : coprod.inl ≫ (coprodZeroIso X).hom = 𝟙 X := by
dsimp [coprodZeroIso, binaryCofanZeroRight]
simp
@[simp]
theorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl :=
rfl
instance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] :
HasPullback (0 : X ⟶ 0) (0 : Y ⟶ 0) :=
HasLimit.mk
⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩
/-- The pullback over the zero object is the product. -/
def pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] :
pullback (0 : X ⟶ 0) (0 : Y ⟶ 0) ≅ X ⨯ Y :=
limit.isoLimitCone
⟨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)⟩
@[simp]
theorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).inv ≫ pullback.fst 0 0 = prod.fst := by
dsimp [pullbackZeroZeroIso]
simp
@[simp]
theorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).inv ≫ pullback.snd 0 0 = prod.snd := by
dsimp [pullbackZeroZeroIso]
simp
@[simp]
theorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).hom ≫ prod.fst = pullback.fst 0 0 := by simp [← Iso.eq_inv_comp]
@[simp]
theorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).hom ≫ prod.snd = pullback.snd 0 0 := by simp [← Iso.eq_inv_comp]
instance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] :
HasPushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) :=
HasColimit.mk
⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩
/-- The pushout over the zero object is the coproduct. -/
def pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] :
pushout (0 : 0 ⟶ X) (0 : 0 ⟶ Y) ≅ X ⨿ Y :=
colimit.isoColimitCocone
⟨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)⟩
@[simp]
theorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :
pushout.inl _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inl := by
dsimp [pushoutZeroZeroIso]
simp
@[simp]
theorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :
pushout.inr _ _ ≫ (pushoutZeroZeroIso X Y).hom = coprod.inr := by
dsimp [pushoutZeroZeroIso]
simp
@[simp]
theorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :
coprod.inl ≫ (pushoutZeroZeroIso X Y).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq]
@[simp]
theorem inr_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :
coprod.inr ≫ (pushoutZeroZeroIso X Y).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq]
end CategoryTheory.Limits
| Mathlib/CategoryTheory/Limits/Constructions/ZeroObjects.lean | 226 | 227 | |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.ContDiff.RCLike
import Mathlib.MeasureTheory.Measure.Hausdorff
/-!
# Hausdorff dimension
The Hausdorff dimension of a set `X` in an (extended) metric space is the unique number
`dimH s : ℝ≥0∞` such that for any `d : ℝ≥0` we have
- `μH[d] s = 0` if `dimH s < d`, and
- `μH[d] s = ∞` if `d < dimH s`.
In this file we define `dimH s` to be the Hausdorff dimension of `s`, then prove some basic
properties of Hausdorff dimension.
## Main definitions
* `MeasureTheory.dimH`: the Hausdorff dimension of a set. For the Hausdorff dimension of the whole
space we use `MeasureTheory.dimH (Set.univ : Set X)`.
## Main results
### Basic properties of Hausdorff dimension
* `hausdorffMeasure_of_lt_dimH`, `dimH_le_of_hausdorffMeasure_ne_top`,
`le_dimH_of_hausdorffMeasure_eq_top`, `hausdorffMeasure_of_dimH_lt`, `measure_zero_of_dimH_lt`,
`le_dimH_of_hausdorffMeasure_ne_zero`, `dimH_of_hausdorffMeasure_ne_zero_ne_top`: various forms
of the characteristic property of the Hausdorff dimension;
* `dimH_union`: the Hausdorff dimension of the union of two sets is the maximum of their Hausdorff
dimensions.
* `dimH_iUnion`, `dimH_bUnion`, `dimH_sUnion`: the Hausdorff dimension of a countable union of sets
is the supremum of their Hausdorff dimensions;
* `dimH_empty`, `dimH_singleton`, `Set.Subsingleton.dimH_zero`, `Set.Countable.dimH_zero` : `dimH s
= 0` whenever `s` is countable;
### (Pre)images under (anti)lipschitz and Hölder continuous maps
* `HolderWith.dimH_image_le` etc: if `f : X → Y` is Hölder continuous with exponent `r > 0`, then
for any `s`, `dimH (f '' s) ≤ dimH s / r`. We prove versions of this statement for `HolderWith`,
`HolderOnWith`, and locally Hölder maps, as well as for `Set.image` and `Set.range`.
* `LipschitzWith.dimH_image_le` etc: Lipschitz continuous maps do not increase the Hausdorff
dimension of sets.
* for a map that is known to be both Lipschitz and antilipschitz (e.g., for an `Isometry` or
a `ContinuousLinearEquiv`) we also prove `dimH (f '' s) = dimH s`.
### Hausdorff measure in `ℝⁿ`
* `Real.dimH_of_nonempty_interior`: if `s` is a set in a finite dimensional real vector space `E`
with nonempty interior, then the Hausdorff dimension of `s` is equal to the dimension of `E`.
* `dense_compl_of_dimH_lt_finrank`: if `s` is a set in a finite dimensional real vector space `E`
with Hausdorff dimension strictly less than the dimension of `E`, the `s` has a dense complement.
* `ContDiff.dense_compl_range_of_finrank_lt_finrank`: the complement to the range of a `C¹`
smooth map is dense provided that the dimension of the domain is strictly less than the dimension
of the codomain.
## Notations
We use the following notation localized in `MeasureTheory`. It is defined in
`MeasureTheory.Measure.Hausdorff`.
- `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d`
## Implementation notes
* The definition of `dimH` explicitly uses `borel X` as a measurable space structure. This way we
can formulate lemmas about Hausdorff dimension without assuming that the environment has a
`[MeasurableSpace X]` instance that is equal but possibly not defeq to `borel X`.
Lemma `dimH_def` unfolds this definition using whatever `[MeasurableSpace X]` instance we have in
the environment (as long as it is equal to `borel X`).
* The definition `dimH` is irreducible; use API lemmas or `dimH_def` instead.
## Tags
Hausdorff measure, Hausdorff dimension, dimension
-/
open scoped MeasureTheory ENNReal NNReal Topology
open MeasureTheory MeasureTheory.Measure Set TopologicalSpace Module Filter
variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y]
/-- Hausdorff dimension of a set in an (e)metric space. -/
@[irreducible] noncomputable def dimH (s : Set X) : ℝ≥0∞ := by
borelize X; exact ⨆ (d : ℝ≥0) (_ : @hausdorffMeasure X _ _ ⟨rfl⟩ d s = ∞), d
/-!
### Basic properties
-/
section Measurable
variable [MeasurableSpace X] [BorelSpace X]
/-- Unfold the definition of `dimH` using `[MeasurableSpace X] [BorelSpace X]` from the
environment. -/
theorem dimH_def (s : Set X) : dimH s = ⨆ (d : ℝ≥0) (_ : μH[d] s = ∞), (d : ℝ≥0∞) := by
borelize X; rw [dimH]
theorem hausdorffMeasure_of_lt_dimH {s : Set X} {d : ℝ≥0} (h : ↑d < dimH s) : μH[d] s = ∞ := by
simp only [dimH_def, lt_iSup_iff] at h
rcases h with ⟨d', hsd', hdd'⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hdd'
exact top_unique (hsd' ▸ hausdorffMeasure_mono hdd'.le _)
theorem dimH_le {s : Set X} {d : ℝ≥0∞} (H : ∀ d' : ℝ≥0, μH[d'] s = ∞ → ↑d' ≤ d) : dimH s ≤ d :=
(dimH_def s).trans_le <| iSup₂_le H
theorem dimH_le_of_hausdorffMeasure_ne_top {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ ∞) : dimH s ≤ d :=
le_of_not_lt <| mt hausdorffMeasure_of_lt_dimH h
theorem le_dimH_of_hausdorffMeasure_eq_top {s : Set X} {d : ℝ≥0} (h : μH[d] s = ∞) :
↑d ≤ dimH s := by
rw [dimH_def]; exact le_iSup₂ (α := ℝ≥0∞) d h
theorem hausdorffMeasure_of_dimH_lt {s : Set X} {d : ℝ≥0} (h : dimH s < d) : μH[d] s = 0 := by
rw [dimH_def] at h
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨d', hsd', hd'd⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at hd'd
exact (hausdorffMeasure_zero_or_top hd'd s).resolve_right fun h₂ => hsd'.not_le <|
le_iSup₂ (α := ℝ≥0∞) d' h₂
theorem measure_zero_of_dimH_lt {μ : Measure X} {d : ℝ≥0} (h : μ ≪ μH[d]) {s : Set X}
(hd : dimH s < d) : μ s = 0 :=
h <| hausdorffMeasure_of_dimH_lt hd
theorem le_dimH_of_hausdorffMeasure_ne_zero {s : Set X} {d : ℝ≥0} (h : μH[d] s ≠ 0) : ↑d ≤ dimH s :=
le_of_not_lt <| mt hausdorffMeasure_of_dimH_lt h
| theorem dimH_of_hausdorffMeasure_ne_zero_ne_top {d : ℝ≥0} {s : Set X} (h : μH[d] s ≠ 0)
(h' : μH[d] s ≠ ∞) : dimH s = d :=
le_antisymm (dimH_le_of_hausdorffMeasure_ne_top h') (le_dimH_of_hausdorffMeasure_ne_zero h)
end Measurable
| Mathlib/Topology/MetricSpace/HausdorffDimension.lean | 139 | 144 |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Powerset
import Mathlib.Algebra.NoZeroSMulDivisors.Pi
import Mathlib.Data.Finset.Sort
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Powerset
import Mathlib.LinearAlgebra.Pi
import Mathlib.Logic.Equiv.Fintype
import Mathlib.Tactic.Abel
/-!
# Multilinear maps
We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each
coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`.
* `f.map_update_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_update_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions.
See `Mathlib.LinearAlgebra.Multilinear.Curry` for the currying of multilinear maps.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : ∀j, M₁ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`Function.update` that allows to change the value of `m` at `i`.
Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the
statement of `MultilinearMap.map_update_add'` and `MultilinearMap.map_update_smul'`.
Three possible choices are:
1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally).
2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`.
3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and
`map_smul'`.
Option 1 works fine, but puts unnecessary constraints on the user
(the zero map certainly does not need decidability).
Option 2 looks great at first, but in the common case when `ι = Fin n`
it introduces non-defeq decidability instance diamonds
within the context of proving `map_update_add'` and `map_update_smul'`,
of the form `Fin.decidableEq n = Classical.decEq (Fin n)`.
Option 3 of course does something similar, but of the form `Fin.decidableEq n = _inst`,
which is much easier to clean up since `_inst` is a free variable
and so the equality can just be substituted.
-/
open Fin Function Finset Set
universe uR uS uι v v' v₁ v₂ v₃
variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ}
{M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
-- Don't generate injectivity lemmas, which the `simpNF` linter will time out on.
set_option genInjectivity false in
/-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules
over `R`. -/
structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R]
[∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where
/-- The underlying multivariate function of a multilinear map. -/
toFun : (∀ i, M₁ i) → M₂
/-- A multilinear map is additive in every argument. -/
map_update_add' :
∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i),
toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y)
/-- A multilinear map is compatible with scalar multiplication in every argument. -/
map_update_smul' :
∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i),
toFun (update m i (c • x)) = c • toFun (update m i x)
namespace MultilinearMap
section Semiring
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂]
[AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂]
[Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂)
instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where
coe f := f.toFun
coe_injective' f g h := by cases f; cases g; cases h; rfl
initialize_simps_projections MultilinearMap (toFun → apply)
/-- Constructor for `MultilinearMap R M₁ M₂` when the
index type `ι` is already endowed with a `DecidableEq` instance. -/
@[simps]
def mk' [DecidableEq ι] (f : (∀ i, M₁ i) → M₂)
(h₁ : ∀ (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i),
f (update m i (x + y)) = f (update m i x) + f (update m i y) := by aesop)
(h₂ : ∀ (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i),
f (update m i (c • x)) = c • f (update m i x) := by aesop) :
MultilinearMap R M₁ M₂ where
toFun := f
map_update_add' m i x y := by convert h₁ m i x y
map_update_smul' m i c x := by convert h₂ m i c x
@[simp]
theorem toFun_eq_coe : f.toFun = ⇑f :=
rfl
@[simp]
theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f :=
rfl
theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x :=
DFunLike.congr_fun h x
nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y :=
DFunLike.congr_arg f h
theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) :=
DFunLike.coe_injective
@[norm_cast]
theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[ext]
theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' :=
DFunLike.ext _ _ H
@[simp]
theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) :
(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl
@[simp]
protected theorem map_update_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_update_add' m i x y
@[deprecated (since := "2024-11-03")] protected alias map_add := MultilinearMap.map_update_add
@[deprecated (since := "2024-11-03")] protected alias map_add' := MultilinearMap.map_update_add
/-- Earlier, this name was used by what is now called `MultilinearMap.map_update_smul_left`. -/
@[simp]
protected theorem map_update_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update m i (c • x)) = c • f (update m i x) :=
f.map_update_smul' m i c x
@[deprecated (since := "2024-11-03")] protected alias map_smul := MultilinearMap.map_update_smul
@[deprecated (since := "2024-11-03")] protected alias map_smul' := MultilinearMap.map_update_smul
theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by
classical
have : (0 : R) • (0 : M₁ i) = 0 := by simp
rw [← update_eq_self i m, h, ← this, f.map_update_smul, zero_smul]
@[simp]
theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 :=
f.map_coord_zero i (update_self i 0 m)
@[simp]
theorem map_zero [Nonempty ι] : f 0 = 0 := by
obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι
exact map_coord_zero f i rfl
instance : Add (MultilinearMap R M₁ M₂) :=
⟨fun f f' =>
⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by
simp [smul_add]⟩⟩
@[simp]
theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m :=
rfl
instance : Zero (MultilinearMap R M₁ M₂) :=
⟨⟨fun _ => 0, fun _ _ _ _ => by simp, fun _ _ c _ => by simp⟩⟩
instance : Inhabited (MultilinearMap R M₁ M₂) :=
⟨0⟩
@[simp]
theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 :=
rfl
section SMul
variable [DistribSMul S M₂] [SMulCommClass R S M₂]
instance : SMul S (MultilinearMap R M₁ M₂) :=
⟨fun c f =>
⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by
simp [← smul_comm x c (_ : M₂)]⟩⟩
@[simp]
theorem smul_apply (f : MultilinearMap R M₁ M₂) (c : S) (m : ∀ i, M₁ i) : (c • f) m = c • f m :=
rfl
theorem coe_smul (c : S) (f : MultilinearMap R M₁ M₂) : ⇑(c • f) = c • (⇑ f) := rfl
end SMul
instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) :=
coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl
/-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/
@[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where
toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl
@[simp]
theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) :
⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) :=
map_sum coeAddMonoidHom f s
theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} :
(∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp
/-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
@[simps]
def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where
toFun x := f (update m i x)
map_add' x y := by simp
map_smul' c x := by simp
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
@[simps]
def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) :
MultilinearMap R M₁ (M₂ × M₃) where
toFun m := (f m, g m)
map_update_add' m i x y := by simp
map_update_smul' m i c x := by simp
/-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a
multilinear map taking values in the space of functions `∀ i, M' i`. -/
@[simps]
def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)]
(f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where
toFun m i := f i m
map_update_add' _ _ _ _ := funext fun j => (f j).map_update_add _ _ _ _
map_update_smul' _ _ _ _ := funext fun j => (f j).map_update_smul _ _ _ _
section
variable (R M₂ M₃)
/-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/
@[simps]
def ofSubsingleton [Subsingleton ι] (i : ι) :
(M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where
toFun f :=
{ toFun := fun x ↦ f (x i)
map_update_add' := by intros; simp [update_eq_const_of_subsingleton]
map_update_smul' := by intros; simp [update_eq_const_of_subsingleton] }
invFun f :=
{ toFun := fun x ↦ f fun _ ↦ x
map_add' := fun x y ↦ by
simpa [update_eq_const_of_subsingleton] using f.map_update_add 0 i x y
map_smul' := fun c x ↦ by
simpa [update_eq_const_of_subsingleton] using f.map_update_smul 0 i c x }
left_inv _ := rfl
right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm
variable (M₁) {M₂}
/-- The constant map is multilinear when `ι` is empty. -/
@[simps -fullyApplied]
def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where
toFun := Function.const _ m
map_update_add' _ := isEmptyElim
map_update_smul' _ := isEmptyElim
end
/-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that
we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n))
(hk : #s = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where
toFun v := f fun j => if h : j ∈ s then v ((s.orderIsoOfFin hk).symm ⟨j, h⟩) else z
/- Porting note: The proofs of the following two lemmas used to only use `erw` followed by `simp`,
but it seems `erw` no longer unfolds or unifies well enough to work without more help. -/
map_update_add' v i x y := by
erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv]
simp
map_update_smul' v i c x := by
erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv,
dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv]
simp
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) :
f (cons (x + y) m) = f (cons x m) + f (cons y m) := by
simp_rw [← update_cons_zero x m (x + y), f.map_update_add, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) :
f (cons (c • x) m) = c • f (cons x m) := by
simp_rw [← update_cons_zero x m (c • x), f.map_update_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
theorem snoc_add (f : MultilinearMap R M M₂)
(m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) :
f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by
simp_rw [← update_snoc_last x m (x + y), f.map_update_add, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build
an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R)
(x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by
simp_rw [← update_snoc_last x m (c • x), f.map_update_smul, update_snoc_last]
section
variable {M₁' : ι → Type*} [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)]
variable {M₁'' : ι → Type*} [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)]
/-- If `g` is a multilinear map and `f` is a collection of linear maps,
then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call
`g.compLinearMap f`. -/
def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) :
MultilinearMap R M₁ M₂ where
toFun m := g fun i => f i (m i)
map_update_add' m i x y := by
have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z =>
Function.apply_update (fun k => f k) _ _ _ _
simp [this]
map_update_smul' m i c x := by
have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z =>
Function.apply_update (fun k => f k) _ _ _ _
simp [this]
@[simp]
theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i)
(m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) :=
rfl
/-- Composing a multilinear map twice with a linear map in each argument is
the same as composing with their composition. -/
theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i)
(f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) :
(g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i :=
rfl
/-- Composing the zero multilinear map with a linear map in each argument. -/
@[simp]
theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) :
(0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 :=
ext fun _ => rfl
/-- Composing a multilinear map with the identity linear map in each argument. -/
@[simp]
theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) :
(g.compLinearMap fun _ => LinearMap.id) = g :=
ext fun _ => rfl
/-- Composing with a family of surjective linear maps is injective. -/
theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) :
Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h =>
ext fun x => by
simpa [fun i => surjInv_eq (hf i)]
using MultilinearMap.ext_iff.mp h fun i => surjInv (hf i) (x i)
theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i))
(g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ :=
(compLinearMap_injective _ hf).eq_iff
/-- Composing a multilinear map with a linear equiv on each argument gives the zero map
if and only if the multilinear map is the zero map. -/
@[simp]
theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) :
(g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by
set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i)
rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective]
end
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ι`
to be finite. -/
theorem map_piecewise_add [DecidableEq ι] (m m' : ∀ i, M₁ i) (t : Finset ι) :
f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := by
revert m'
refine Finset.induction_on t (by simp) ?_
intro i t hit Hrec m'
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m' := by
ext j
by_cases h : j = i
· rw [h]
simp [hit]
· simp [h]
let m'' := update m' i (m i)
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'' := by
ext j
by_cases h : j = i
· rw [h]
simp [m'', hit]
· by_cases h' : j ∈ t <;> simp [m'', h, hit, h']
rw [A, f.map_update_add, B, C, Finset.sum_powerset_insert hit, Hrec, Hrec, add_comm (_ : M₂)]
congr 1
refine Finset.sum_congr rfl fun s hs => ?_
have : (insert i s).piecewise m m' = s.piecewise m m'' := by
ext j
by_cases h : j = i
· rw [h]
simp [m'', Finset.not_mem_of_mem_powerset_of_not_mem hs hit]
· by_cases h' : j ∈ s <;> simp [m'', h, h']
rw [this]
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
theorem map_add_univ [DecidableEq ι] [Fintype ι] (m m' : ∀ i, M₁ i) :
f (m + m') = ∑ s : Finset ι, f (s.piecewise m m') := by
simpa using f.map_piecewise_add m m' Finset.univ
section ApplySum
variable {α : ι → Type*} (g : ∀ i, α i → M₁ i) (A : ∀ i, Finset (α i))
open Fintype Finset
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
theorem map_sum_finset_aux [DecidableEq ι] [Fintype ι] {n : ℕ} (h : (∑ i, #(A i)) = n) :
(f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) := by
letI := fun i => Classical.decEq (α i)
induction n using Nat.strong_induction_on generalizing A with | h n IH =>
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : ∃ i, A i = ∅
· obtain ⟨i, hi⟩ : ∃ i, ∑ j ∈ A i, g i j = 0 := Ai_empty.imp fun i hi ↦ by simp [hi]
have hpi : piFinset A = ∅ := by simpa
rw [f.map_coord_zero i hi, hpi, Finset.sum_empty]
push_neg at Ai_empty
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : ∀ i, #(A i) ≤ 1
· have Ai_card : ∀ i, #(A i) = 1 := by
intro i
have pos : #(A i) ≠ 0 := by simp [Finset.card_eq_zero, Ai_empty i]
have : #(A i) ≤ 1 := Ai_singleton i
exact le_antisymm this (Nat.succ_le_of_lt (_root_.pos_iff_ne_zero.mpr pos))
have :
∀ r : ∀ i, α i, r ∈ piFinset A → (f fun i => g i (r i)) = f fun i => ∑ j ∈ A i, g i j := by
intro r hr
congr with i
have : ∀ j ∈ A i, g i j = g i (r i) := by
intro j hj
congr
apply Finset.card_le_one_iff.1 (Ai_singleton i) hj
exact mem_piFinset.mp hr i
simp only [Finset.sum_congr rfl this, Finset.mem_univ, Finset.sum_const, Ai_card i, one_nsmul]
simp only [Finset.sum_congr rfl this, Ai_card, card_piFinset, prod_const_one, one_nsmul,
Finset.sum_const]
-- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2.
-- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i`
-- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton
obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < #(A i) := Ai_singleton
obtain ⟨j₁, j₂, _, hj₂, _⟩ : ∃ j₁ j₂, j₁ ∈ A i₀ ∧ j₂ ∈ A i₀ ∧ j₁ ≠ j₂ :=
Finset.one_lt_card_iff.1 hi₀
let B := Function.update A i₀ (A i₀ \ {j₂})
let C := Function.update A i₀ {j₂}
have B_subset_A : ∀ i, B i ⊆ A i := by
intro i
by_cases hi : i = i₀
· rw [hi]
simp only [B, sdiff_subset, update_self]
· simp only [B, hi, update_of_ne, Ne, not_false_iff, Finset.Subset.refl]
have C_subset_A : ∀ i, C i ⊆ A i := by
intro i
by_cases hi : i = i₀
· rw [hi]
simp only [C, hj₂, Finset.singleton_subset_iff, update_self]
· simp only [C, hi, update_of_ne, Ne, not_false_iff, Finset.Subset.refl]
-- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity.
have A_eq_BC :
(fun i => ∑ j ∈ A i, g i j) =
Function.update (fun i => ∑ j ∈ A i, g i j) i₀
((∑ j ∈ B i₀, g i₀ j) + ∑ j ∈ C i₀, g i₀ j) := by
ext i
by_cases hi : i = i₀
· rw [hi, update_self]
have : A i₀ = B i₀ ∪ C i₀ := by
simp only [B, C, Function.update_self, Finset.sdiff_union_self_eq_union]
symm
simp only [hj₂, Finset.singleton_subset_iff, Finset.union_eq_left]
rw [this]
refine Finset.sum_union <| Finset.disjoint_right.2 fun j hj => ?_
have : j = j₂ := by
simpa [C] using hj
rw [this]
simp only [B, mem_sdiff, eq_self_iff_true, not_true, not_false_iff, Finset.mem_singleton,
update_self, and_false]
· simp [hi]
have Beq :
Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ B i₀, g i₀ j) = fun i =>
∑ j ∈ B i, g i j := by
ext i
by_cases hi : i = i₀
· rw [hi]
simp only [update_self]
· simp only [B, hi, update_of_ne, Ne, not_false_iff]
have Ceq :
Function.update (fun i => ∑ j ∈ A i, g i j) i₀ (∑ j ∈ C i₀, g i₀ j) = fun i =>
∑ j ∈ C i, g i j := by
ext i
by_cases hi : i = i₀
· rw [hi]
simp only [update_self]
· simp only [C, hi, update_of_ne, Ne, not_false_iff]
-- Express the inductive assumption for `B`
have Brec : (f fun i => ∑ j ∈ B i, g i j) = ∑ r ∈ piFinset B, f fun i => g i (r i) := by
have : ∑ i, #(B i) < ∑ i, #(A i) := by
refine sum_lt_sum (fun i _ => card_le_card (B_subset_A i)) ⟨i₀, mem_univ _, ?_⟩
have : {j₂} ⊆ A i₀ := by simp [hj₂]
simp only [B, Finset.card_sdiff this, Function.update_self, Finset.card_singleton]
exact Nat.pred_lt (ne_of_gt (lt_trans Nat.zero_lt_one hi₀))
rw [h] at this
exact IH _ this B rfl
-- Express the inductive assumption for `C`
have Crec : (f fun i => ∑ j ∈ C i, g i j) = ∑ r ∈ piFinset C, f fun i => g i (r i) := by
have : (∑ i, #(C i)) < ∑ i, #(A i) :=
Finset.sum_lt_sum (fun i _ => Finset.card_le_card (C_subset_A i))
⟨i₀, Finset.mem_univ _, by simp [C, hi₀]⟩
rw [h] at this
exact IH _ this C rfl
have D : Disjoint (piFinset B) (piFinset C) :=
haveI : Disjoint (B i₀) (C i₀) := by simp [B, C]
piFinset_disjoint_of_disjoint B C this
have pi_BC : piFinset A = piFinset B ∪ piFinset C := by
apply Finset.Subset.antisymm
· intro r hr
by_cases hri₀ : r i₀ = j₂
· apply Finset.mem_union_right
refine mem_piFinset.2 fun i => ?_
by_cases hi : i = i₀
· have : r i₀ ∈ C i₀ := by simp [C, hri₀]
rwa [hi]
· simp [C, hi, mem_piFinset.1 hr i]
· apply Finset.mem_union_left
refine mem_piFinset.2 fun i => ?_
by_cases hi : i = i₀
· have : r i₀ ∈ B i₀ := by simp [B, hri₀, mem_piFinset.1 hr i₀]
rwa [hi]
· simp [B, hi, mem_piFinset.1 hr i]
· exact
Finset.union_subset (piFinset_subset _ _ fun i => B_subset_A i)
(piFinset_subset _ _ fun i => C_subset_A i)
rw [A_eq_BC]
simp only [MultilinearMap.map_update_add, Beq, Ceq, Brec, Crec, pi_BC]
rw [← Finset.sum_union D]
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
theorem map_sum_finset [DecidableEq ι] [Fintype ι] :
(f fun i => ∑ j ∈ A i, g i j) = ∑ r ∈ piFinset A, f fun i => g i (r i) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
theorem map_sum [DecidableEq ι] [Fintype ι] [∀ i, Fintype (α i)] :
(f fun i => ∑ j, g i j) = ∑ r : ∀ i, α i, f fun i => g i (r i) :=
f.map_sum_finset g fun _ => Finset.univ
theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M₁ i)
(m : ∀ i, M₁ i) : f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) := by
classical
induction t using Finset.induction with
| empty => simp
| insert _ _ has ih => simp [Finset.sum_insert has, ih]
end ApplySum
/-- Restrict the codomain of a multilinear map to a submodule.
This is the multilinear version of `LinearMap.codRestrict`. -/
@[simps]
def codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂) (h : ∀ v, f v ∈ p) :
MultilinearMap R M₁ p where
toFun v := ⟨f v, h v⟩
map_update_add' _ _ _ _ := Subtype.ext <| MultilinearMap.map_update_add _ _ _ _ _
map_update_smul' _ _ _ _ := Subtype.ext <| MultilinearMap.map_update_smul _ _ _ _ _
section RestrictScalar
variable (R)
variable {A : Type*} [Semiring A] [SMul R A] [∀ i : ι, Module A (M₁ i)] [Module A M₂]
[∀ i, IsScalarTower R A (M₁ i)] [IsScalarTower R A M₂]
/-- Reinterpret an `A`-multilinear map as an `R`-multilinear map, if `A` is an algebra over `R`
and their actions on all involved modules agree with the action of `R` on `A`. -/
def restrictScalars (f : MultilinearMap A M₁ M₂) : MultilinearMap R M₁ M₂ where
toFun := f
map_update_add' := f.map_update_add
map_update_smul' m i := (f.toLinearMap m i).map_smul_of_tower
@[simp]
theorem coe_restrictScalars (f : MultilinearMap A M₁ M₂) : ⇑(f.restrictScalars R) = f :=
rfl
end RestrictScalar
section
variable {ι₁ ι₂ ι₃ : Type*}
/-- Transfer the arguments to a map along an equivalence between argument indices.
The naming is derived from `Finsupp.domCongr`, noting that here the permutation applies to the
domain of the domain. -/
@[simps apply]
def domDomCongr (σ : ι₁ ≃ ι₂) (m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
MultilinearMap R (fun _ : ι₂ => M₂) M₃ where
toFun v := m fun i => v (σ i)
map_update_add' v i a b := by
letI := σ.injective.decidableEq
simp_rw [Function.update_apply_equiv_apply v]
rw [m.map_update_add]
map_update_smul' v i a b := by
letI := σ.injective.decidableEq
simp_rw [Function.update_apply_equiv_apply v]
rw [m.map_update_smul]
theorem domDomCongr_trans (σ₁ : ι₁ ≃ ι₂) (σ₂ : ι₂ ≃ ι₃)
(m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
m.domDomCongr (σ₁.trans σ₂) = (m.domDomCongr σ₁).domDomCongr σ₂ :=
rfl
theorem domDomCongr_mul (σ₁ : Equiv.Perm ι₁) (σ₂ : Equiv.Perm ι₁)
(m : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
m.domDomCongr (σ₂ * σ₁) = (m.domDomCongr σ₁).domDomCongr σ₂ :=
rfl
/-- `MultilinearMap.domDomCongr` as an equivalence.
This is declared separately because it does not work with dot notation. -/
@[simps apply symm_apply]
def domDomCongrEquiv (σ : ι₁ ≃ ι₂) :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃ where
toFun := domDomCongr σ
invFun := domDomCongr σ.symm
left_inv m := by
ext
simp [domDomCongr]
right_inv m := by
ext
simp [domDomCongr]
map_add' a b := by
ext
simp [domDomCongr]
/-- The results of applying `domDomCongr` to two maps are equal if
and only if those maps are. -/
@[simp]
theorem domDomCongr_eq_iff (σ : ι₁ ≃ ι₂) (f g : MultilinearMap R (fun _ : ι₁ => M₂) M₃) :
f.domDomCongr σ = g.domDomCongr σ ↔ f = g :=
(domDomCongrEquiv σ : _ ≃+ MultilinearMap R (fun _ => M₂) M₃).apply_eq_iff_eq
end
/-! If `{a // P a}` is a subtype of `ι` and if we fix an element `z` of `(i : {a // ¬ P a}) → M₁ i`,
then a multilinear map on `M₁` defines a multilinear map on the restriction of `M₁` to
`{a // P a}`, by fixing the arguments out of `{a // P a}` equal to the values of `z`. -/
lemma domDomRestrict_aux {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*}
[DecidableEq {a // P a}]
(x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // P a})
(c : M₁ i) : (fun j ↦ if h : P j then Function.update x i c ⟨j, h⟩ else z ⟨j, h⟩) =
Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by
ext j
by_cases h : j = i
· rw [h, Function.update_self]
simp only [i.2, update_self, dite_true]
· rw [Function.update_of_ne h]
by_cases h' : P j
· simp only [h', ne_eq, Subtype.mk.injEq, dite_true]
have h'' : ¬ ⟨j, h'⟩ = i :=
fun he => by apply_fun (fun x => x.1) at he; exact h he
rw [Function.update_of_ne h'']
· simp only [h', ne_eq, Subtype.mk.injEq, dite_false]
lemma domDomRestrict_aux_right {ι} [DecidableEq ι] (P : ι → Prop) [DecidablePred P] {M₁ : ι → Type*}
[DecidableEq {a // ¬ P a}]
(x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) (i : {a : ι // ¬ P a})
(c : M₁ i) : (fun j ↦ if h : P j then x ⟨j, h⟩ else Function.update z i c ⟨j, h⟩) =
Function.update (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) i c := by
simpa only [dite_not] using domDomRestrict_aux _ z (fun j ↦ x ⟨j.1, not_not.mp j.2⟩) i c
/-- Given a multilinear map `f` on `(i : ι) → M i`, a (decidable) predicate `P` on `ι` and
an element `z` of `(i : {a // ¬ P a}) → M₁ i`, construct a multilinear map on
`(i : {a // P a}) → M₁ i)` whose value at `x` is `f` evaluated at the vector with `i`th coordinate
`x i` if `P i` and `z i` otherwise.
The naming is similar to `MultilinearMap.domDomCongr`: here we are applying the restriction to the
domain of the domain.
For a linear map version, see `MultilinearMap.domDomRestrictₗ`.
-/
def domDomRestrict (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P]
(z : (i : {a : ι // ¬ P a}) → M₁ i) :
MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂ where
toFun x := f (fun j ↦ if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩)
map_update_add' x i a b := by
classical
repeat (rw [domDomRestrict_aux])
simp only [MultilinearMap.map_update_add]
map_update_smul' z i c a := by
classical
repeat (rw [domDomRestrict_aux])
simp only [MultilinearMap.map_update_smul]
@[simp]
lemma domDomRestrict_apply (f : MultilinearMap R M₁ M₂) (P : ι → Prop)
[DecidablePred P] (x : (i : {a // P a}) → M₁ i) (z : (i : {a // ¬ P a}) → M₁ i) :
f.domDomRestrict P z x = f (fun j => if h : P j then x ⟨j, h⟩ else z ⟨j, h⟩) := rfl
-- TODO: Should add a ref here when available.
/-- The "derivative" of a multilinear map, as a linear map from `(i : ι) → M₁ i` to `M₂`.
For continuous multilinear maps, this will indeed be the derivative. -/
def linearDeriv [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂)
(x : (i : ι) → M₁ i) : ((i : ι) → M₁ i) →ₗ[R] M₂ :=
∑ i : ι, (f.toLinearMap x i).comp (LinearMap.proj i)
@[simp]
lemma linearDeriv_apply [DecidableEq ι] [Fintype ι] (f : MultilinearMap R M₁ M₂)
(x y : (i : ι) → M₁ i) :
f.linearDeriv x y = ∑ i, f (update x i (y i)) := by
unfold linearDeriv
simp only [LinearMap.coeFn_sum, LinearMap.coe_comp, LinearMap.coe_proj, Finset.sum_apply,
Function.comp_apply, Function.eval, toLinearMap_apply]
end Semiring
end MultilinearMap
namespace LinearMap
variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃]
[AddCommMonoid M'] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M']
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) : MultilinearMap R M₁ M₃ where
toFun := g ∘ f
map_update_add' m i x y := by simp
map_update_smul' m i c x := by simp
@[simp]
theorem coe_compMultilinearMap (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) :
⇑(g.compMultilinearMap f) = g ∘ f :=
rfl
@[simp]
theorem compMultilinearMap_apply (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) :
g.compMultilinearMap f m = g (f m) :=
rfl
@[simp]
theorem compMultilinearMap_zero (g : M₂ →ₗ[R] M₃) :
g.compMultilinearMap (0 : MultilinearMap R M₁ M₂) = 0 :=
MultilinearMap.ext fun _ => map_zero g
@[simp]
theorem zero_compMultilinearMap (f : MultilinearMap R M₁ M₂) :
(0 : M₂ →ₗ[R] M₃).compMultilinearMap f = 0 := rfl
@[simp]
theorem compMultilinearMap_add (g : M₂ →ₗ[R] M₃) (f₁ f₂ : MultilinearMap R M₁ M₂) :
g.compMultilinearMap (f₁ + f₂) = g.compMultilinearMap f₁ + g.compMultilinearMap f₂ :=
MultilinearMap.ext fun _ => map_add g _ _
@[simp]
theorem add_compMultilinearMap (g₁ g₂ : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂) :
(g₁ + g₂).compMultilinearMap f = g₁.compMultilinearMap f + g₂.compMultilinearMap f := rfl
@[simp]
theorem compMultilinearMap_smul [DistribSMul S M₂] [DistribSMul S M₃]
[SMulCommClass R S M₂] [SMulCommClass R S M₃] [CompatibleSMul M₂ M₃ S R]
(g : M₂ →ₗ[R] M₃) (s : S) (f : MultilinearMap R M₁ M₂) :
g.compMultilinearMap (s • f) = s • g.compMultilinearMap f :=
MultilinearMap.ext fun _ => g.map_smul_of_tower _ _
@[simp]
theorem smul_compMultilinearMap [Monoid S] [DistribMulAction S M₃] [SMulCommClass R S M₃]
(g : M₂ →ₗ[R] M₃) (s : S) (f : MultilinearMap R M₁ M₂) :
(s • g).compMultilinearMap f = s • g.compMultilinearMap f := rfl
/-- The multilinear version of `LinearMap.subtype_comp_codRestrict` -/
@[simp]
theorem subtype_compMultilinearMap_codRestrict (f : MultilinearMap R M₁ M₂) (p : Submodule R M₂)
(h) : p.subtype.compMultilinearMap (f.codRestrict p h) = f :=
rfl
/-- The multilinear version of `LinearMap.comp_codRestrict` -/
@[simp]
theorem compMultilinearMap_codRestrict (g : M₂ →ₗ[R] M₃) (f : MultilinearMap R M₁ M₂)
(p : Submodule R M₃) (h) :
(g.codRestrict p h).compMultilinearMap f =
(g.compMultilinearMap f).codRestrict p fun v => h (f v) :=
rfl
variable {ι₁ ι₂ : Type*}
@[simp]
theorem compMultilinearMap_domDomCongr (σ : ι₁ ≃ ι₂) (g : M₂ →ₗ[R] M₃)
(f : MultilinearMap R (fun _ : ι₁ => M') M₂) :
(g.compMultilinearMap f).domDomCongr σ = g.compMultilinearMap (f.domDomCongr σ) := by
ext
simp [MultilinearMap.domDomCongr]
end LinearMap
namespace MultilinearMap
section Semiring
variable [Semiring R] [(i : ι) → AddCommMonoid (M₁ i)] [(i : ι) → Module R (M₁ i)]
[AddCommMonoid M₂] [Module R M₂]
instance [Monoid S] [DistribMulAction S M₂] [Module R M₂] [SMulCommClass R S M₂] :
DistribMulAction S (MultilinearMap R M₁ M₂) :=
coe_injective.distribMulAction coeAddMonoidHom fun _ _ ↦ rfl
section Module
variable [Semiring S] [Module S M₂] [SMulCommClass R S M₂]
/-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise
addition and scalar multiplication. -/
instance : Module S (MultilinearMap R M₁ M₂) :=
coe_injective.module _ coeAddMonoidHom fun _ _ ↦ rfl
instance [NoZeroSMulDivisors S M₂] : NoZeroSMulDivisors S (MultilinearMap R M₁ M₂) :=
coe_injective.noZeroSMulDivisors _ rfl coe_smul
variable [AddCommMonoid M₃] [Module S M₃] [Module R M₃] [SMulCommClass R S M₃]
variable (S) in
/-- `LinearMap.compMultilinearMap` as an `S`-linear map. -/
@[simps]
def _root_.LinearMap.compMultilinearMapₗ [Semiring S] [Module S M₂] [Module S M₃]
[SMulCommClass R S M₂] [SMulCommClass R S M₃] [LinearMap.CompatibleSMul M₂ M₃ S R]
(g : M₂ →ₗ[R] M₃) :
MultilinearMap R M₁ M₂ →ₗ[S] MultilinearMap R M₁ M₃ where
toFun := g.compMultilinearMap
map_add' := g.compMultilinearMap_add
map_smul' := g.compMultilinearMap_smul
variable (R S M₁ M₂ M₃)
section OfSubsingleton
/-- Linear equivalence between linear maps `M₂ →ₗ[R] M₃`
and one-multilinear maps `MultilinearMap R (fun _ : ι ↦ M₂) M₃`. -/
@[simps +simpRhs]
def ofSubsingletonₗ [Subsingleton ι] (i : ι) :
(M₂ →ₗ[R] M₃) ≃ₗ[S] MultilinearMap R (fun _ : ι ↦ M₂) M₃ :=
{ ofSubsingleton R M₂ M₃ i with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl }
end OfSubsingleton
/-- The dependent version of `MultilinearMap.domDomCongrLinearEquiv`. -/
@[simps apply symm_apply]
def domDomCongrLinearEquiv' {ι' : Type*} (σ : ι ≃ ι') :
MultilinearMap R M₁ M₂ ≃ₗ[S] MultilinearMap R (fun i => M₁ (σ.symm i)) M₂ where
toFun f :=
{ toFun := f ∘ (σ.piCongrLeft' M₁).symm
map_update_add' := fun m i => by
letI := σ.decidableEq
rw [← σ.apply_symm_apply i]
intro x y
simp only [comp_apply, piCongrLeft'_symm_update, f.map_update_add]
map_update_smul' := fun m i c => by
letI := σ.decidableEq
rw [← σ.apply_symm_apply i]
intro x
simp only [Function.comp, piCongrLeft'_symm_update, f.map_update_smul] }
invFun f :=
{ toFun := f ∘ σ.piCongrLeft' M₁
map_update_add' := fun m i => by
letI := σ.symm.decidableEq
rw [← σ.symm_apply_apply i]
intro x y
simp only [comp_apply, piCongrLeft'_update, f.map_update_add]
map_update_smul' := fun m i c => by
letI := σ.symm.decidableEq
rw [← σ.symm_apply_apply i]
intro x
simp only [Function.comp, piCongrLeft'_update, f.map_update_smul] }
map_add' f₁ f₂ := by
ext
simp only [Function.comp, coe_mk, add_apply]
map_smul' c f := by
ext
simp only [Function.comp, coe_mk, smul_apply, RingHom.id_apply]
left_inv f := by
ext
simp only [coe_mk, comp_apply, Equiv.symm_apply_apply]
right_inv f := by
ext
simp only [coe_mk, comp_apply, Equiv.apply_symm_apply]
/-- The space of constant maps is equivalent to the space of maps that are multilinear with respect
to an empty family. -/
@[simps]
def constLinearEquivOfIsEmpty [IsEmpty ι] : M₂ ≃ₗ[S] MultilinearMap R M₁ M₂ where
toFun := MultilinearMap.constOfIsEmpty R _
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := f 0
left_inv _ := rfl
right_inv f := ext fun _ => MultilinearMap.congr_arg f <| Subsingleton.elim _ _
/-- `MultilinearMap.domDomCongr` as a `LinearEquiv`. -/
@[simps apply symm_apply]
def domDomCongrLinearEquiv {ι₁ ι₂} (σ : ι₁ ≃ ι₂) :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃ₗ[S] MultilinearMap R (fun _ : ι₂ => M₂) M₃ :=
{ (domDomCongrEquiv σ :
MultilinearMap R (fun _ : ι₁ => M₂) M₃ ≃+ MultilinearMap R (fun _ : ι₂ => M₂) M₃) with
map_smul' := fun c f => by
ext
simp [MultilinearMap.domDomCongr] }
end Module
end Semiring
section CommSemiring
variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M₂]
[∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] (f f' : MultilinearMap R M₁ M₂)
section
variable {M₁' : ι → Type*} [Π i, AddCommMonoid (M₁' i)] [Π i, Module R (M₁' i)]
/-- Given a predicate `P`, one may associate to a multilinear map `f` a multilinear map
from the elements satisfying `P` to the multilinear maps on elements not satisfying `P`.
In other words, splitting the variables into two subsets one gets a multilinear map into
multilinear maps.
This is a linear map version of the function `MultilinearMap.domDomRestrict`. -/
def domDomRestrictₗ (f : MultilinearMap R M₁ M₂) (P : ι → Prop) [DecidablePred P] :
MultilinearMap R (fun (i : {a : ι // ¬ P a}) => M₁ i)
(MultilinearMap R (fun (i : {a : ι // P a}) => M₁ i) M₂) where
toFun := fun z ↦ domDomRestrict f P z
map_update_add' := by
intro h m i x y
classical
ext v
simp [domDomRestrict_aux_right]
map_update_smul' := by
intro h m i c x
classical
ext v
simp [domDomRestrict_aux_right]
lemma iteratedFDeriv_aux {ι} {M₁ : ι → Type*} {α : Type*} [DecidableEq α]
(s : Set ι) [DecidableEq { x // x ∈ s }] (e : α ≃ s)
(m : α → ((i : ι) → M₁ i)) (a : α) (z : (i : ι) → M₁ i) :
(fun i ↦ update m a z (e.symm i) i) =
(fun i ↦ update (fun j ↦ m (e.symm j) j) (e a) (z (e a)) i) := by
ext i
rcases eq_or_ne a (e.symm i) with rfl | hne
· rw [Equiv.apply_symm_apply e i, update_self, update_self]
· rw [update_of_ne hne.symm, update_of_ne fun h ↦ (Equiv.symm_apply_apply .. ▸ h ▸ hne) rfl]
/-- One of the components of the iterated derivative of a multilinear map. Given a bijection `e`
between a type `α` (typically `Fin k`) and a subset `s` of `ι`, this component is a multilinear map
of `k` vectors `v₁, ..., vₖ`, mapping them to `f (x₁, (v_{e.symm 2})₂, x₃, ...)`, where at
indices `i` in `s` one uses the `i`-th coordinate of the vector `v_{e.symm i}` and otherwise one
uses the `i`-th coordinate of a reference vector `x`.
This is multilinear in the components of `x` outside of `s`, and in the `v_j`. -/
noncomputable def iteratedFDerivComponent {α : Type*}
(f : MultilinearMap R M₁ M₂) {s : Set ι} (e : α ≃ s) [DecidablePred (· ∈ s)] :
MultilinearMap R (fun (i : {a : ι // a ∉ s}) ↦ M₁ i)
(MultilinearMap R (fun (_ : α) ↦ (∀ i, M₁ i)) M₂) where
toFun := fun z ↦
{ toFun := fun v ↦ domDomRestrictₗ f (fun i ↦ i ∈ s) z (fun i ↦ v (e.symm i) i)
map_update_add' := by classical simp [iteratedFDeriv_aux]
map_update_smul' := by classical simp [iteratedFDeriv_aux] }
map_update_add' := by intros; ext; simp
map_update_smul' := by intros; ext; simp
open Classical in
/-- The `k`-th iterated derivative of a multilinear map `f` at the point `x`. It is a multilinear
map of `k` vectors `v₁, ..., vₖ` (with the same type as `x`), mapping them
to `∑ f (x₁, (v_{i₁})₂, x₃, ...)`, where at each index `j` one uses either `xⱼ` or one
of the `(vᵢ)ⱼ`, and each `vᵢ` has to be used exactly once.
The sum is parameterized by the embeddings of `Fin k` in the index type `ι` (or, equivalently,
by the subsets `s` of `ι` of cardinality `k` and then the bijections between `Fin k` and `s`).
For the continuous version, see `ContinuousMultilinearMap.iteratedFDeriv`. -/
protected noncomputable def iteratedFDeriv [Fintype ι]
(f : MultilinearMap R M₁ M₂) (k : ℕ) (x : (i : ι) → M₁ i) :
MultilinearMap R (fun (_ : Fin k) ↦ (∀ i, M₁ i)) M₂ :=
∑ e : Fin k ↪ ι, iteratedFDerivComponent f e.toEquivRange (fun i ↦ x i)
/-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap`
sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g`. -/
@[simps] def compLinearMapₗ (f : Π (i : ι), M₁ i →ₗ[R] M₁' i) :
(MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂ where
toFun := fun g ↦ g.compLinearMap f
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
/-- If `f` is a collection of linear maps, then the construction `MultilinearMap.compLinearMap`
sending a multilinear map `g` to `g (f₁ ⬝ , ..., fₙ ⬝ )` is linear in `g` and multilinear in
`f₁, ..., fₙ`. -/
@[simps] def compLinearMapMultilinear :
@MultilinearMap R ι (fun i ↦ M₁ i →ₗ[R] M₁' i)
((MultilinearMap R M₁' M₂) →ₗ[R] MultilinearMap R M₁ M₂) _ _ _
(fun _ ↦ LinearMap.module) _ where
toFun := MultilinearMap.compLinearMapₗ
map_update_add' := by
intro _ f i f₁ f₂
ext g x
change (g fun j ↦ update f i (f₁ + f₂) j <| x j) =
(g fun j ↦ update f i f₁ j <|x j) + g fun j ↦ update f i f₂ j (x j)
let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i)
convert g.map_update_add (fun j ↦ f j (x j)) i (f₁ (x i)) (f₂ (x i)) with j j j
· exact Function.apply_update c f i (f₁ + f₂) j
· exact Function.apply_update c f i f₁ j
· exact Function.apply_update c f i f₂ j
map_update_smul' := by
intro _ f i a f₀
ext g x
change (g fun j ↦ update f i (a • f₀) j <| x j) = a • g fun j ↦ update f i f₀ j (x j)
let c : Π (i : ι), (M₁ i →ₗ[R] M₁' i) → M₁' i := fun i f ↦ f (x i)
convert g.map_update_smul (fun j ↦ f j (x j)) i a (f₀ (x i)) with j j j
· exact Function.apply_update c f i (a • f₀) j
· exact Function.apply_update c f i f₀ j
/--
Let `M₁ᵢ` and `M₁ᵢ'` be two families of `R`-modules and `M₂` an `R`-module.
Let us denote `Π i, M₁ᵢ` and `Π i, M₁ᵢ'` by `M` and `M'` respectively.
If `g` is a multilinear map `M' → M₂`, then `g` can be reinterpreted as a multilinear
map from `Π i, M₁ᵢ ⟶ M₁ᵢ'` to `M ⟶ M₂` via `(fᵢ) ↦ v ↦ g(fᵢ vᵢ)`.
-/
@[simps!] def piLinearMap :
MultilinearMap R M₁' M₂ →ₗ[R]
MultilinearMap R (fun i ↦ M₁ i →ₗ[R] M₁' i) (MultilinearMap R M₁ M₂) where
toFun g := (LinearMap.applyₗ g).compMultilinearMap compLinearMapMultilinear
map_add' := by simp
map_smul' := by simp
end
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `∏ i ∈ s, c i`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ι` to be finite. -/
theorem map_piecewise_smul [DecidableEq ι] (c : ι → R) (m : ∀ i, M₁ i) (s : Finset ι) :
f (s.piecewise (fun i => c i • m i) m) = (∏ i ∈ s, c i) • f m := by
refine s.induction_on (by simp) ?_
intro j s j_not_mem_s Hrec
have A :
Function.update (s.piecewise (fun i => c i • m i) m) j (m j) =
s.piecewise (fun i => c i • m i) m := by
ext i
by_cases h : i = j
· rw [h]
simp [j_not_mem_s]
· simp [h]
rw [s.piecewise_insert, f.map_update_smul, A, Hrec]
simp [j_not_mem_s, mul_smul]
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. -/
theorem map_smul_univ [Fintype ι] (c : ι → R) (m : ∀ i, M₁ i) :
(f fun i => c i • m i) = (∏ i, c i) • f m := by
classical simpa using map_piecewise_smul f c m Finset.univ
@[simp]
theorem map_update_smul_left [DecidableEq ι] [Fintype ι]
(m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update (c • m) i x) = c ^ (Fintype.card ι - 1) • f (update m i x) := by
have :
f ((Finset.univ.erase i).piecewise (c • update m i x) (update m i x)) =
(∏ _i ∈ Finset.univ.erase i, c) • f (update m i x) :=
map_piecewise_smul f _ _ _
simpa [← Function.update_smul c m] using this
section
variable (R ι)
variable (A : Type*) [CommSemiring A] [Algebra R A] [Fintype ι]
/-- Given an `R`-algebra `A`, `mkPiAlgebra` is the multilinear map on `A^ι` associating
to `m` the product of all the `m i`.
See also `MultilinearMap.mkPiAlgebraFin` for a version that works with a non-commutative
algebra `A` but requires `ι = Fin n`. -/
protected def mkPiAlgebra : MultilinearMap R (fun _ : ι => A) A where
toFun m := ∏ i, m i
map_update_add' m i x y := by simp [Finset.prod_update_of_mem, add_mul]
map_update_smul' m i c x := by simp [Finset.prod_update_of_mem]
variable {R A ι}
@[simp]
theorem mkPiAlgebra_apply (m : ι → A) : MultilinearMap.mkPiAlgebra R ι A m = ∏ i, m i :=
rfl
end
section
variable (R n)
variable (A : Type*) [Semiring A] [Algebra R A]
/-- Given an `R`-algebra `A`, `mkPiAlgebraFin` is the multilinear map on `A^n` associating
to `m` the product of all the `m i`.
See also `MultilinearMap.mkPiAlgebra` for a version that assumes `[CommSemiring A]` but works
for `A^ι` with any finite type `ι`. -/
protected def mkPiAlgebraFin : MultilinearMap R (fun _ : Fin n => A) A :=
MultilinearMap.mk' (fun m ↦ (List.ofFn m).prod)
(fun m i x y ↦ by
have : (List.finRange n).idxOf i < n := by simp
simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, add_mul, this,
mul_add, add_mul])
(fun m i c x ↦ by
have : (List.finRange n).idxOf i < n := by simp
simp [List.ofFn_eq_map, (List.nodup_finRange n).map_update, List.prod_set, this])
variable {R A n}
@[simp]
theorem mkPiAlgebraFin_apply (m : Fin n → A) :
MultilinearMap.mkPiAlgebraFin R n A m = (List.ofFn m).prod :=
rfl
theorem mkPiAlgebraFin_apply_const (a : A) :
(MultilinearMap.mkPiAlgebraFin R n A fun _ => a) = a ^ n := by simp
end
/-- Given an `R`-multilinear map `f` taking values in `R`, `f.smulRight z` is the map
sending `m` to `f m • z`. -/
def smulRight (f : MultilinearMap R M₁ R) (z : M₂) : MultilinearMap R M₁ M₂ :=
(LinearMap.smulRight LinearMap.id z).compMultilinearMap f
@[simp]
theorem smulRight_apply (f : MultilinearMap R M₁ R) (z : M₂) (m : ∀ i, M₁ i) :
f.smulRight z m = f m • z :=
rfl
variable (R ι)
/-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module). See also
`mkPiAlgebra` for a more general version. -/
protected def mkPiRing [Fintype ι] (z : M₂) : MultilinearMap R (fun _ : ι => R) M₂ :=
(MultilinearMap.mkPiAlgebra R ι R).smulRight z
variable {R ι}
@[simp]
theorem mkPiRing_apply [Fintype ι] (z : M₂) (m : ι → R) :
(MultilinearMap.mkPiRing R ι z : (ι → R) → M₂) m = (∏ i, m i) • z :=
rfl
theorem mkPiRing_apply_one_eq_self [Fintype ι] (f : MultilinearMap R (fun _ : ι => R) M₂) :
MultilinearMap.mkPiRing R ι (f fun _ => 1) = f := by
ext m
have : m = fun i => m i • (1 : R) := by
ext j
simp
conv_rhs => rw [this, f.map_smul_univ]
rfl
theorem mkPiRing_eq_iff [Fintype ι] {z₁ z₂ : M₂} :
MultilinearMap.mkPiRing R ι z₁ = MultilinearMap.mkPiRing R ι z₂ ↔ z₁ = z₂ := by
simp_rw [MultilinearMap.ext_iff, mkPiRing_apply]
constructor <;> intro h
· simpa using h fun _ => 1
· intro x
simp [h]
theorem mkPiRing_zero [Fintype ι] : MultilinearMap.mkPiRing R ι (0 : M₂) = 0 := by
ext; rw [mkPiRing_apply, smul_zero, MultilinearMap.zero_apply]
theorem mkPiRing_eq_zero_iff [Fintype ι] (z : M₂) : MultilinearMap.mkPiRing R ι z = 0 ↔ z = 0 := by
rw [← mkPiRing_zero, mkPiRing_eq_iff]
end CommSemiring
section RangeAddCommGroup
variable [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)]
[Module R M₂] (f g : MultilinearMap R M₁ M₂)
instance : Neg (MultilinearMap R M₁ M₂) :=
⟨fun f => ⟨fun m => -f m, fun m i x y => by simp [add_comm], fun m i c x => by simp⟩⟩
@[simp]
theorem neg_apply (m : ∀ i, M₁ i) : (-f) m = -f m :=
rfl
instance : Sub (MultilinearMap R M₁ M₂) :=
⟨fun f g =>
⟨fun m => f m - g m, fun m i x y => by
simp only [MultilinearMap.map_update_add, sub_eq_add_neg, neg_add]
abel,
fun m i c x => by simp only [MultilinearMap.map_update_smul, smul_sub]⟩⟩
@[simp]
theorem sub_apply (m : ∀ i, M₁ i) : (f - g) m = f m - g m :=
rfl
instance : AddCommGroup (MultilinearMap R M₁ M₂) :=
{ MultilinearMap.addCommMonoid with
neg_add_cancel := fun _ => MultilinearMap.ext fun _ => neg_add_cancel _
sub_eq_add_neg := fun _ _ => MultilinearMap.ext fun _ => sub_eq_add_neg _ _
zsmul := fun n f =>
{ toFun := fun m => n • f m
map_update_add' := fun m i x y => by simp [smul_add]
map_update_smul' := fun l i x d => by simp [← smul_comm x n (_ : M₂)] }
zsmul_zero' := fun _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_zero' _
zsmul_succ' := fun _ _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_succ' _ _
zsmul_neg' := fun _ _ => MultilinearMap.ext fun _ => SubNegMonoid.zsmul_neg' _ _ }
end RangeAddCommGroup
section AddCommGroup
variable [Semiring R] [∀ i, AddCommGroup (M₁ i)] [AddCommGroup M₂] [∀ i, Module R (M₁ i)]
[Module R M₂] (f : MultilinearMap R M₁ M₂)
@[simp]
theorem map_update_neg [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x : M₁ i) :
f (update m i (-x)) = -f (update m i x) :=
eq_neg_of_add_eq_zero_left <| by
rw [← MultilinearMap.map_update_add, neg_add_cancel, f.map_coord_zero i (update_self i 0 m)]
@[deprecated (since := "2024-11-03")] protected alias map_neg := MultilinearMap.map_update_neg
@[simp]
theorem map_update_sub [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) := by
rw [sub_eq_add_neg, sub_eq_add_neg, MultilinearMap.map_update_add, map_update_neg]
@[deprecated (since := "2024-11-03")] protected alias map_sub := MultilinearMap.map_update_sub
lemma map_update [DecidableEq ι] (x : (i : ι) → M₁ i) (i : ι) (v : M₁ i) :
f (update x i v) = f x - f (update x i (x i - v)) := by
rw [map_update_sub, update_eq_self, sub_sub_cancel]
open Finset in
lemma map_sub_map_piecewise [LinearOrder ι] (a b : (i : ι) → M₁ i) (s : Finset ι) :
f a - f (s.piecewise b a) =
∑ i ∈ s, f (fun j ↦ if j ∈ s → j < i then a j else if i = j then a j - b j else b j) := by
refine s.induction_on_min ?_ fun k s hk ih ↦ ?_
· rw [Finset.piecewise_empty, sum_empty, sub_self]
rw [Finset.piecewise_insert, map_update, ← sub_add, ih,
add_comm, sum_insert (lt_irrefl _ <| hk k ·)]
simp_rw [s.mem_insert]
congr 1
· congr; ext i; split_ifs with h₁ h₂
· rw [update_of_ne, Finset.piecewise_eq_of_not_mem]
· exact fun h ↦ (hk i h).not_lt (h₁ <| .inr h)
· exact fun h ↦ (h₁ <| .inl h).ne h
· cases h₂
rw [update_self, s.piecewise_eq_of_not_mem _ _ (lt_irrefl _ <| hk k ·)]
· push_neg at h₁
rw [update_of_ne (Ne.symm h₂), s.piecewise_eq_of_mem _ _ (h₁.1.resolve_left <| Ne.symm h₂)]
· apply sum_congr rfl; intro i hi; congr; ext j; congr 1; apply propext
simp_rw [imp_iff_not_or, not_or]; apply or_congr_left'
intro h; rw [and_iff_right]; rintro rfl; exact h (hk i hi)
/-- This calculates the differences between the values of a multilinear map at
two arguments that differ on a finset `s` of `ι`. It requires a
linear order on `ι` in order to express the result. -/
lemma map_piecewise_sub_map_piecewise [LinearOrder ι] (a b v : (i : ι) → M₁ i) (s : Finset ι) :
f (s.piecewise a v) - f (s.piecewise b v) = ∑ i ∈ s, f
fun j ↦ if j ∈ s then if j < i then a j else if j = i then a j - b j else b j else v j := by
rw [← s.piecewise_idem_right b a, map_sub_map_piecewise]
refine Finset.sum_congr rfl fun i hi ↦ congr_arg f <| funext fun j ↦ ?_
by_cases hjs : j ∈ s
· rw [if_pos hjs]; by_cases hji : j < i
· rw [if_pos fun _ ↦ hji, if_pos hji, s.piecewise_eq_of_mem _ _ hjs]
rw [if_neg (Classical.not_imp.mpr ⟨hjs, hji⟩), if_neg hji]
obtain rfl | hij := eq_or_ne i j
· rw [if_pos rfl, if_pos rfl, s.piecewise_eq_of_mem _ _ hi]
· rw [if_neg hij, if_neg hij.symm]
· rw [if_neg hjs, if_pos fun h ↦ (hjs h).elim, s.piecewise_eq_of_not_mem _ _ hjs]
open Finset in
lemma map_add_eq_map_add_linearDeriv_add [DecidableEq ι] [Fintype ι] (x h : (i : ι) → M₁ i) :
f (x + h) = f x + f.linearDeriv x h + ∑ s with 2 ≤ #s, f (s.piecewise h x) := by
rw [add_comm, map_add_univ, ← Finset.powerset_univ,
← sum_filter_add_sum_filter_not _ (2 ≤ #·)]
simp_rw [not_le, Nat.lt_succ, le_iff_lt_or_eq (b := 1), Nat.lt_one_iff, filter_or,
← powersetCard_eq_filter, sum_union (univ.pairwise_disjoint_powersetCard zero_ne_one),
powersetCard_zero, powersetCard_one, sum_singleton, Finset.piecewise_empty, sum_map,
Function.Embedding.coeFn_mk, Finset.piecewise_singleton, linearDeriv_apply, add_comm]
open Finset in
/-- This expresses the difference between the values of a multilinear map
at two points "close to `x`" in terms of the "derivative" of the multilinear map at `x`
and of "second-order" terms. -/
lemma map_add_sub_map_add_sub_linearDeriv [DecidableEq ι] [Fintype ι] (x h h' : (i : ι) → M₁ i) :
f (x + h) - f (x + h') - f.linearDeriv x (h - h') =
∑ s with 2 ≤ #s, (f (s.piecewise h x) - f (s.piecewise h' x)) := by
simp_rw [map_add_eq_map_add_linearDeriv_add, add_assoc, add_sub_add_comm, sub_self, zero_add,
← LinearMap.map_sub, add_sub_cancel_left, sum_sub_distrib]
end AddCommGroup
section CommSemiring
variable [CommSemiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)]
[Module R M₂]
/-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `MultilinearMap.piRingEquiv`. -/
protected def piRingEquiv [Fintype ι] : M₂ ≃ₗ[R] MultilinearMap R (fun _ : ι => R) M₂ where
toFun z := MultilinearMap.mkPiRing R ι z
invFun f := f fun _ => 1
map_add' z z' := by
ext m
simp [smul_add]
map_smul' c z := by
ext m
simp [smul_smul, mul_comm]
left_inv z := by simp
right_inv f := f.mkPiRing_apply_one_eq_self
end CommSemiring
section Submodule
variable [Ring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M'] [AddCommMonoid M₂]
[∀ i, Module R (M₁ i)] [Module R M'] [Module R M₂]
/-- The pushforward of an indexed collection of submodule `p i ⊆ M₁ i` by `f : M₁ → M₂`.
Note that this is not a submodule - it is not closed under addition. -/
def map [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) :
SubMulAction R M₂ where
carrier := f '' { v | ∀ i, v i ∈ p i }
smul_mem' := fun c _ ⟨x, hx, hf⟩ => by
let ⟨i⟩ := ‹Nonempty ι›
letI := Classical.decEq ι
refine ⟨update x i (c • x i), fun j => if hij : j = i then ?_ else ?_, hf ▸ ?_⟩
· rw [hij, update_self]
exact (p i).smul_mem _ (hx i)
· rw [update_of_ne hij]
exact hx j
· rw [f.map_update_smul, update_eq_self]
/-- The map is always nonempty. This lemma is needed to apply `SubMulAction.zero_mem`. -/
theorem map_nonempty [Nonempty ι] (f : MultilinearMap R M₁ M₂) (p : ∀ i, Submodule R (M₁ i)) :
(map f p : Set M₂).Nonempty :=
⟨f 0, 0, fun i => (p i).zero_mem, rfl⟩
/-- The range of a multilinear map, closed under scalar multiplication. -/
def range [Nonempty ι] (f : MultilinearMap R M₁ M₂) : SubMulAction R M₂ :=
f.map fun _ => ⊤
end Submodule
end MultilinearMap
| Mathlib/LinearAlgebra/Multilinear/Basic.lean | 1,847 | 1,853 | |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice.Prod
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Set.Lattice.Image
/-!
# N-ary images of finsets
This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of
`Set.image2`. This is mostly useful to define pointwise operations.
## Notes
This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please
keep them in sync.
We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂`
and `Set.image2` already fulfills this task.
-/
open Function Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*}
namespace Finset
variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ']
[DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ}
{s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ}
/-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ :=
(s ×ˢ t).image <| uncurry f
@[simp]
theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by
simp [image₂, and_assoc]
@[simp, norm_cast]
theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) :
(image₂ f s t : Set γ) = Set.image2 f s t :=
Set.ext fun _ => mem_image₂
theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) :
#(image₂ f s t) ≤ #s * #t :=
card_image_le.trans_eq <| card_product _ _
theorem card_image₂_iff :
#(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by
rw [← card_product, ← coe_product]
exact card_image_iff
theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) :
#(image₂ f s t) = #s * #t :=
(card_image_of_injective _ hf.uncurry).trans <| card_product _ _
theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t :=
mem_image₂.2 ⟨a, ha, b, hb, rfl⟩
theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by
rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe]
@[gcongr]
theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by
rw [← coe_subset, coe_image₂, coe_image₂]
exact image2_subset hs ht
@[gcongr]
theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' :=
image₂_subset Subset.rfl ht
@[gcongr]
theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t :=
image₂_subset hs Subset.rfl
theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb
theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ => mem_image₂_of_mem ha
lemma forall_mem_image₂ {p : γ → Prop} :
(∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, forall_mem_image2]
lemma exists_mem_image₂ {p : γ → Prop} :
(∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, exists_mem_image2]
@[deprecated (since := "2024-11-23")] alias forall_image₂_iff := forall_mem_image₂
@[simp]
theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image₂
theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff]
theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α]
@[simp]
theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
rw [← coe_nonempty, coe_image₂]
exact image2_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty :=
image₂_nonempty_iff.2 ⟨hs, ht⟩
theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty :=
(image₂_nonempty_iff.1 h).1
theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty :=
(image₂_nonempty_iff.1 h).2
@[simp]
theorem image₂_empty_left : image₂ f ∅ t = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_empty_right : image₂ f s ∅ = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or]
@[simp]
theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b :=
ext fun x => by simp
@[simp]
theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b :=
ext fun x => by simp
theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) :=
image₂_singleton_left
theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp
theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_union_left
theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_union_right
@[simp]
theorem image₂_insert_left [DecidableEq α] :
image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_left
@[simp]
theorem image₂_insert_right [DecidableEq β] :
image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_right
theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) :
image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_inter_left hf
theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) :
image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_inter_right hf
theorem image₂_inter_subset_left [DecidableEq α] :
image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_left
theorem image₂_inter_subset_right [DecidableEq β] :
image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_right
theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
coe_injective <| by
push_cast
exact image2_congr h
/-- A common special case of `image₂_congr` -/
theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
image₂_congr fun a _ b _ => h a b
variable (s t)
theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by
rw [image₂_singleton_left, card_image_of_injective _ hf]
theorem card_image₂_singleton_right (hf : Injective fun a => f a b) :
#(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf]
theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) :
image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by
simp_rw [image₂_singleton_left, image_inter _ _ hf]
theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) :
image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by
simp_rw [image₂_singleton_right, image_inter _ _ hf]
theorem card_le_card_image₂_left {s : Finset α} (hs : s.Nonempty) (hf : ∀ a, Injective (f a)) :
#t ≤ #(image₂ f s t) := by
obtain ⟨a, ha⟩ := hs
rw [← card_image₂_singleton_left _ (hf a)]
exact card_le_card (image₂_subset_right <| singleton_subset_iff.2 ha)
theorem card_le_card_image₂_right {t : Finset β} (ht : t.Nonempty)
(hf : ∀ b, Injective fun a => f a b) : #s ≤ #(image₂ f s t) := by
obtain ⟨b, hb⟩ := ht
rw [← card_image₂_singleton_right _ (hf b)]
exact card_le_card (image₂_subset_left <| singleton_subset_iff.2 hb)
variable {s t}
theorem biUnion_image_left : (s.biUnion fun a => t.image <| f a) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_left _
theorem biUnion_image_right : (t.biUnion fun b => s.image fun a => f a b) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_right _
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `Finset.image₂` of those operations.
The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that
`image₂ (*) f g = image₂ (*) g f` in a `CommSemigroup`.
-/
section
variable [DecidableEq δ]
theorem image_image₂ (f : α → β → γ) (g : γ → δ) :
(image₂ f s t).image g = image₂ (fun a b => g (f a b)) s t :=
coe_injective <| by
push_cast
exact image_image2 _ _
theorem image₂_image_left (f : γ → β → δ) (g : α → γ) :
image₂ f (s.image g) t = image₂ (fun a b => f (g a) b) s t :=
coe_injective <| by
push_cast
exact image2_image_left _ _
theorem image₂_image_right (f : α → γ → δ) (g : β → γ) :
image₂ f s (t.image g) = image₂ (fun a b => f a (g b)) s t :=
coe_injective <| by
push_cast
exact image2_image_right _ _
@[simp]
theorem image₂_mk_eq_product [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) :
image₂ Prod.mk s t = s ×ˢ t := by ext; simp [Prod.ext_iff]
@[simp]
theorem image₂_curry (f : α × β → γ) (s : Finset α) (t : Finset β) :
image₂ (curry f) s t = (s ×ˢ t).image f := rfl
@[simp]
theorem image_uncurry_product (f : α → β → γ) (s : Finset α) (t : Finset β) :
(s ×ˢ t).image (uncurry f) = image₂ f s t := rfl
theorem image₂_swap (f : α → β → γ) (s : Finset α) (t : Finset β) :
image₂ f s t = image₂ (fun a b => f b a) t s :=
coe_injective <| by
push_cast
exact image2_swap _ _ _
@[simp]
theorem image₂_left [DecidableEq α] (h : t.Nonempty) : image₂ (fun x _ => x) s t = s :=
coe_injective <| by
push_cast
exact image2_left h
@[simp]
theorem image₂_right [DecidableEq β] (h : s.Nonempty) : image₂ (fun _ y => y) s t = t :=
coe_injective <| by
push_cast
exact image2_right h
theorem image₂_assoc {γ : Type*} {u : Finset γ}
{f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε}
{g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) :=
coe_injective <| by
push_cast
exact image2_assoc h_assoc
theorem image₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image₂ f s t = image₂ g t s :=
(image₂_swap _ _ _).trans <| by simp_rw [h_comm]
theorem image₂_left_comm {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
image₂ f s (image₂ g t u) = image₂ g' t (image₂ f' s u) :=
coe_injective <| by
push_cast
exact image2_left_comm h_left_comm
theorem image₂_right_comm {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
image₂ f (image₂ g s t) u = image₂ g' (image₂ f' s u) t :=
coe_injective <| by
push_cast
exact image2_right_comm h_right_comm
theorem image₂_image₂_image₂_comm {γ δ : Type*} {u : Finset γ} {v : Finset δ} [DecidableEq ζ]
[DecidableEq ζ'] [DecidableEq ν] {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ}
{f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'}
(h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) :
image₂ f (image₂ g s t) (image₂ h u v) = image₂ f' (image₂ g' s u) (image₂ h' t v) :=
coe_injective <| by
push_cast
exact image2_image2_image2_comm h_comm
theorem image_image₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(image₂ f s t).image g = image₂ f' (s.image g₁) (t.image g₂) :=
coe_injective <| by
push_cast
exact image_image2_distrib h_distrib
/-- Symmetric statement to `Finset.image₂_image_left_comm`. -/
theorem image_image₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(image₂ f s t).image g = image₂ f' (s.image g') t :=
coe_injective <| by
push_cast
exact image_image2_distrib_left h_distrib
/-- Symmetric statement to `Finset.image_image₂_right_comm`. -/
theorem image_image₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
(image₂ f s t).image g = image₂ f' s (t.image g') :=
coe_injective <| by
push_cast
exact image_image2_distrib_right h_distrib
/-- Symmetric statement to `Finset.image_image₂_distrib_left`. -/
theorem image₂_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
image₂ f (s.image g) t = (image₂ f' s t).image g' :=
(image_image₂_distrib_left fun a b => (h_left_comm a b).symm).symm
/-- Symmetric statement to `Finset.image_image₂_distrib_right`. -/
theorem image_image₂_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
image₂ f s (t.image g) = (image₂ f' s t).image g' :=
(image_image₂_distrib_right fun a b => (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
theorem image₂_distrib_subset_left {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε}
(h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
image₂ f s (image₂ g t u) ⊆ image₂ g' (image₂ f₁ s t) (image₂ f₂ s u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_left h_distrib
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
theorem image₂_distrib_subset_right {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε}
(h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
image₂ f (image₂ g s t) u ⊆ image₂ g' (image₂ f₁ s u) (image₂ f₂ t u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_right h_distrib
theorem image_image₂_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
(image₂ f s t).image g = image₂ f' (t.image g₁) (s.image g₂) := by
rw [image₂_swap f]
exact image_image₂_distrib fun _ _ => h_antidistrib _ _
/-- Symmetric statement to `Finset.image₂_image_left_anticomm`. -/
theorem image_image₂_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) :
(image₂ f s t).image g = image₂ f' (t.image g') s :=
coe_injective <| by
push_cast
exact image_image2_antidistrib_left h_antidistrib
/-- Symmetric statement to `Finset.image_image₂_right_anticomm`. -/
theorem image_image₂_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) :
(image₂ f s t).image g = image₂ f' t (s.image g') :=
coe_injective <| by
push_cast
exact image_image2_antidistrib_right h_antidistrib
/-- Symmetric statement to `Finset.image_image₂_antidistrib_left`. -/
theorem image₂_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ}
(h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) :
image₂ f (s.image g) t = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `Finset.image_image₂_antidistrib_right`. -/
theorem image_image₂_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ}
(h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) :
image₂ f s (t.image g) = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm
/-- If `a` is a left identity for `f : α → β → β`, then `{a}` is a left identity for
| `Finset.image₂ f`. -/
theorem image₂_left_identity {f : α → γ → γ} {a : α} (h : ∀ b, f a b = b) (t : Finset γ) :
image₂ f {a} t = t :=
coe_injective <| by rw [coe_image₂, coe_singleton, Set.image2_left_identity h]
/-- If `b` is a right identity for `f : α → β → α`, then `{b}` is a right identity for
`Finset.image₂ f`. -/
| Mathlib/Data/Finset/NAry.lean | 427 | 433 |
/-
Copyright (c) 2021 Gabriel Moise. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Moise, Yaël Dillies, Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Finite
import Mathlib.Data.Finset.Sym
import Mathlib.Data.Matrix.Mul
/-!
# Incidence matrix of a simple graph
This file defines the unoriented incidence matrix of a simple graph.
## Main definitions
* `SimpleGraph.incMatrix`: `G.incMatrix R` is the incidence matrix of `G` over the ring `R`.
## Main results
* `SimpleGraph.incMatrix_mul_transpose_diag`: The diagonal entries of the product of
`G.incMatrix R` and its transpose are the degrees of the vertices.
* `SimpleGraph.incMatrix_mul_transpose`: Gives a complete description of the product of
`G.incMatrix R` and its transpose; the diagonal is the degrees of each vertex, and the
off-diagonals are 1 or 0 depending on whether or not the vertices are adjacent.
* `SimpleGraph.incMatrix_transpose_mul_diag`: The diagonal entries of the product of the
transpose of `G.incMatrix R` and `G.inc_matrix R` are `2` or `0` depending on whether or
not the unordered pair is an edge of `G`.
## Implementation notes
The usual definition of an incidence matrix has one row per vertex and one column per edge.
However, this definition has columns indexed by all of `Sym2 α`, where `α` is the vertex type.
This appears not to change the theory, and for simple graphs it has the nice effect that every
incidence matrix for each `SimpleGraph α` has the same type.
## TODO
* Define the oriented incidence matrices for oriented graphs.
* Define the graph Laplacian of a simple graph using the oriented incidence matrix from an
arbitrary orientation of a simple graph.
-/
assert_not_exists Field
open Finset Matrix SimpleGraph Sym2
namespace SimpleGraph
variable (R : Type*) {α : Type*} (G : SimpleGraph α)
/-- `G.incMatrix R` is the `α × Sym2 α` matrix whose `(a, e)`-entry is `1` if `e` is incident to
`a` and `0` otherwise. -/
noncomputable def incMatrix [Zero R] [One R] : Matrix α (Sym2 α) R := fun a =>
(G.incidenceSet a).indicator 1
variable {R}
theorem incMatrix_apply [Zero R] [One R] {a : α} {e : Sym2 α} :
G.incMatrix R a e = (G.incidenceSet a).indicator 1 e :=
rfl
/-- Entries of the incidence matrix can be computed given additional decidable instances. -/
theorem incMatrix_apply' [Zero R] [One R] [DecidableEq α] [DecidableRel G.Adj] {a : α}
{e : Sym2 α} : G.incMatrix R a e = if e ∈ G.incidenceSet a then 1 else 0 := by
simp only [incMatrix, Set.indicator, Pi.one_apply]
section MulZeroOneClass
variable [MulZeroOneClass R] {a b : α} {e : Sym2 α}
theorem incMatrix_apply_mul_incMatrix_apply : G.incMatrix R a e * G.incMatrix R b e =
(G.incidenceSet a ∩ G.incidenceSet b).indicator 1 e := by
classical simp only [incMatrix, Set.indicator_apply, ite_zero_mul_ite_zero, Pi.one_apply, mul_one,
Set.mem_inter_iff]
theorem incMatrix_apply_mul_incMatrix_apply_of_not_adj (hab : a ≠ b) (h : ¬G.Adj a b) :
G.incMatrix R a e * G.incMatrix R b e = 0 := by
rw [incMatrix_apply_mul_incMatrix_apply, Set.indicator_of_not_mem]
rw [G.incidenceSet_inter_incidenceSet_of_not_adj h hab]
exact Set.not_mem_empty e
theorem incMatrix_of_not_mem_incidenceSet (h : e ∉ G.incidenceSet a) : G.incMatrix R a e = 0 := by
rw [incMatrix_apply, Set.indicator_of_not_mem h]
theorem incMatrix_of_mem_incidenceSet (h : e ∈ G.incidenceSet a) : G.incMatrix R a e = 1 := by
rw [incMatrix_apply, Set.indicator_of_mem h, Pi.one_apply]
variable [Nontrivial R]
theorem incMatrix_apply_eq_zero_iff : G.incMatrix R a e = 0 ↔ e ∉ G.incidenceSet a := by
simp only [incMatrix_apply, Set.indicator_apply_eq_zero, Pi.one_apply, one_ne_zero]
theorem incMatrix_apply_eq_one_iff : G.incMatrix R a e = 1 ↔ e ∈ G.incidenceSet a := by
convert one_ne_zero.ite_eq_left_iff
infer_instance
end MulZeroOneClass
section NonAssocSemiring
variable [NonAssocSemiring R] {a : α} {e : Sym2 α}
theorem sum_incMatrix_apply [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
∑ e, G.incMatrix R a e = G.degree a := by
classical simp [incMatrix_apply', sum_boole, Set.filter_mem_univ_eq_toFinset]
theorem incMatrix_mul_transpose_diag [Fintype (Sym2 α)] [Fintype (neighborSet G a)] :
(G.incMatrix R * (G.incMatrix R)ᵀ) a a = G.degree a := by
classical
rw [← sum_incMatrix_apply]
simp only [mul_apply, incMatrix_apply', transpose_apply, mul_ite, mul_one, mul_zero]
simp_all only [ite_true, sum_boole]
theorem sum_incMatrix_apply_of_mem_edgeSet [Fintype α] :
e ∈ G.edgeSet → ∑ a, G.incMatrix R a e = 2 := by
classical
refine e.ind ?_
intro a b h
rw [mem_edgeSet] at h
rw [← Nat.cast_two, ← card_pair h.ne]
simp only [incMatrix_apply', sum_boole, mk'_mem_incidenceSet_iff, h]
congr 2
ext e
simp only [mem_filter, mem_univ, true_and, mem_insert, mem_singleton]
|
theorem sum_incMatrix_apply_of_not_mem_edgeSet [Fintype α] (h : e ∉ G.edgeSet) :
∑ a, G.incMatrix R a e = 0 :=
sum_eq_zero fun _ _ => G.incMatrix_of_not_mem_incidenceSet fun he => h he.1
theorem incMatrix_transpose_mul_diag [Fintype α] [Decidable (e ∈ G.edgeSet)] :
| Mathlib/Combinatorics/SimpleGraph/IncMatrix.lean | 126 | 131 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Eric Wieser, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# Basic facts about real (semi)normed spaces
In this file we prove some theorems about (semi)normed spaces over real numberes.
## Main results
- `closure_ball`, `frontier_ball`, `interior_closedBall`, `frontier_closedBall`, `interior_sphere`,
`frontier_sphere`: formulas for the closure/interior/frontier
of nontrivial balls and spheres in a real seminormed space;
- `interior_closedBall'`, `frontier_closedBall'`, `interior_sphere'`, `frontier_sphere'`:
similar lemmas assuming that the ambient space is separated and nontrivial instead of `r ≠ 0`.
-/
open Metric Set Function Filter
open scoped NNReal Topology
/-- If `E` is a nontrivial topological module over `ℝ`, then `E` has no isolated points.
This is a particular case of `Module.punctured_nhds_neBot`. -/
instance Real.punctured_nhds_module_neBot {E : Type*} [AddCommGroup E] [TopologicalSpace E]
[ContinuousAdd E] [Nontrivial E] [Module ℝ E] [ContinuousSMul ℝ E] (x : E) : NeBot (𝓝[≠] x) :=
Module.punctured_nhds_neBot ℝ E x
section Seminormed
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E]
theorem inv_norm_smul_mem_unitClosedBall (x : E) :
‖x‖⁻¹ • x ∈ closedBall (0 : E) 1 := by
simp only [mem_closedBall_zero_iff, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul,
div_self_le_one]
@[deprecated (since := "2024-12-01")]
alias inv_norm_smul_mem_closed_unit_ball := inv_norm_smul_mem_unitClosedBall
theorem norm_smul_of_nonneg {t : ℝ} (ht : 0 ≤ t) (x : E) : ‖t • x‖ = t * ‖x‖ := by
rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht]
theorem dist_smul_add_one_sub_smul_le {r : ℝ} {x y : E} (h : r ∈ Icc 0 1) :
dist (r • x + (1 - r) • y) x ≤ dist y x :=
| calc
dist (r • x + (1 - r) • y) x = ‖1 - r‖ * ‖x - y‖ := by
simp_rw [dist_eq_norm', ← norm_smul, sub_smul, one_smul, smul_sub, ← sub_sub, ← sub_add,
sub_right_comm]
_ = (1 - r) * dist y x := by
rw [Real.norm_eq_abs, abs_eq_self.mpr (sub_nonneg.mpr h.2), dist_eq_norm']
_ ≤ (1 - 0) * dist y x := by gcongr; exact h.1
_ = dist y x := by rw [sub_zero, one_mul]
theorem closure_ball (x : E) {r : ℝ} (hr : r ≠ 0) : closure (ball x r) = closedBall x r := by
| Mathlib/Analysis/NormedSpace/Real.lean | 50 | 59 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Field.IsField
import Mathlib.Algebra.Polynomial.Inductions
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Algebra.Ring.Regular
import Mathlib.RingTheory.Multiplicity
import Mathlib.Data.Nat.Lattice
/-!
# Division of univariate polynomials
The main defs are `divByMonic` and `modByMonic`.
The compatibility between these is given by `modByMonic_add_div`.
We also define `rootMultiplicity`.
-/
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section Semiring
variable [Semiring R]
theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 :=
⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf =>
⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩
theorem X_pow_dvd_iff {f : R[X]} {n : ℕ} : X ^ n ∣ f ↔ ∀ d < n, f.coeff d = 0 :=
⟨fun ⟨g, hgf⟩ d hd => by
simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff],
fun hd => by
induction n with
| zero => simp [pow_zero, one_dvd]
| succ n hn =>
obtain ⟨g, hgf⟩ := hn fun d : ℕ => fun H : d < n => hd _ (Nat.lt_succ_of_lt H)
have := coeff_X_pow_mul g n 0
rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this
obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm
use k
rwa [pow_succ, mul_assoc, ← hgk]⟩
variable {p q : R[X]}
theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot ℕ) < degree p) (hmp : Monic p)
(hq : q ≠ 0) : FiniteMultiplicity p q :=
have zn0 : (0 : R) ≠ 1 :=
haveI := Nontrivial.of_polynomial_ne hq
zero_ne_one
⟨natDegree q, fun ⟨r, hr⟩ => by
have hp0 : p ≠ 0 := fun hp0 => by simp [hp0] at hp
have hr0 : r ≠ 0 := fun hr0 => by subst hr0; simp [hq] at hr
have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp]
have hpn0' : leadingCoeff p ^ (natDegree q + 1) ≠ 0 := hpn1.symm ▸ zn0.symm
have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r ≠ 0 := by
simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne,
hr0, not_false_eq_true]
have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by
rw [← degree_eq_natDegree hp0]; exact hp
have := congr_arg natDegree hr
rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this
exact
ne_of_lt
(lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp)
(add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _)))
this⟩
@[deprecated (since := "2024-11-30")]
alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic
end Semiring
section Ring
variable [Ring R] {p q : R[X]}
theorem div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : Monic q) :
degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p :=
have hp : leadingCoeff p ≠ 0 := mt leadingCoeff_eq_zero.1 h.2
have hq0 : q ≠ 0 := hq.ne_zero_of_polynomial_ne h.2
have hlt : natDegree q ≤ natDegree p :=
(Nat.cast_le (α := WithBot ℕ)).1
(by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1)
degree_sub_lt
(by
rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2,
degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt])
h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C])
/-- See `divByMonic`. -/
noncomputable def divModByMonicAux : ∀ (_p : R[X]) {q : R[X]}, Monic q → R[X] × R[X]
| p, q, hq =>
letI := Classical.decEq R
if h : degree q ≤ degree p ∧ p ≠ 0 then
let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q)
have _wf := div_wf_lemma h hq
let dm := divModByMonicAux (p - q * z) hq
⟨z + dm.1, dm.2⟩
else ⟨0, p⟩
termination_by p => p
/-- `divByMonic`, denoted as `p /ₘ q`, gives the quotient of `p` by a monic polynomial `q`. -/
def divByMonic (p q : R[X]) : R[X] :=
letI := Classical.decEq R
if hq : Monic q then (divModByMonicAux p hq).1 else 0
/-- `modByMonic`, denoted as `p %ₘ q`, gives the remainder of `p` by a monic polynomial `q`. -/
def modByMonic (p q : R[X]) : R[X] :=
letI := Classical.decEq R
if hq : Monic q then (divModByMonicAux p hq).2 else p
@[inherit_doc]
infixl:70 " /ₘ " => divByMonic
@[inherit_doc]
infixl:70 " %ₘ " => modByMonic
theorem degree_modByMonic_lt [Nontrivial R] :
∀ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %ₘ q) < degree q
| p, q, hq =>
letI := Classical.decEq R
if h : degree q ≤ degree p ∧ p ≠ 0 then by
have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq
have :=
degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
unfold modByMonic at this ⊢
unfold divModByMonicAux
dsimp
rw [dif_pos hq] at this ⊢
rw [if_pos h]
exact this
else
Or.casesOn (not_and_or.1 h)
(by
unfold modByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_neg h]
exact lt_of_not_ge)
(by
intro hp
unfold modByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_neg h, Classical.not_not.1 hp]
exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero)))
termination_by p => p
theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q ≠ 1) :
natDegree (p %ₘ q) < q.natDegree := by
by_cases hpq : p %ₘ q = 0
· rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero]
contrapose! hq
exact eq_one_of_monic_natDegree_zero hmq hq
· haveI := Nontrivial.of_polynomial_ne hpq
exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq)
@[simp]
theorem zero_modByMonic (p : R[X]) : 0 %ₘ p = 0 := by
classical
unfold modByMonic divModByMonicAux
dsimp
by_cases hp : Monic p
· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero]
· rw [dif_neg hp]
@[simp]
theorem zero_divByMonic (p : R[X]) : 0 /ₘ p = 0 := by
classical
unfold divByMonic divModByMonicAux
dsimp
by_cases hp : Monic p
· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero]
· rw [dif_neg hp]
@[simp]
theorem modByMonic_zero (p : R[X]) : p %ₘ 0 = p :=
letI := Classical.decEq R
if h : Monic (0 : R[X]) then by
haveI := monic_zero_iff_subsingleton.mp h
simp [eq_iff_true_of_subsingleton]
else by unfold modByMonic divModByMonicAux; rw [dif_neg h]
@[simp]
theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 :=
letI := Classical.decEq R
if h : Monic (0 : R[X]) then by
haveI := monic_zero_iff_subsingleton.mp h
simp [eq_iff_true_of_subsingleton]
else by unfold divByMonic divModByMonicAux; rw [dif_neg h]
theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p /ₘ q = 0 :=
dif_neg hq
theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p %ₘ q = p :=
dif_neg hq
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
classical
have : ¬degree q ≤ degree p := not_le_of_gt h
unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩
theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by
nontriviality R
exact (degree_modByMonic_lt _ hq).le
theorem degree_modByMonic_le_left : degree (p %ₘ q) ≤ degree p := by
nontriviality R
by_cases hq : q.Monic
· cases lt_or_ge (degree p) (degree q)
· rw [(modByMonic_eq_self_iff hq).mpr ‹_›]
· exact (degree_modByMonic_le p hq).trans ‹_›
· rw [modByMonic_eq_of_not_monic p hq]
theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) :
natDegree (p %ₘ g) ≤ g.natDegree :=
natDegree_le_natDegree (degree_modByMonic_le p hg)
theorem natDegree_modByMonic_le_left : natDegree (p %ₘ q) ≤ natDegree p :=
natDegree_le_natDegree degree_modByMonic_le_left
theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by
simp [X_dvd_iff, coeff_C]
theorem modByMonic_eq_sub_mul_div :
∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
| p, q, hq =>
letI := Classical.decEq R
if h : degree q ≤ degree p ∧ p ≠ 0 then by
have _wf := div_wf_lemma h hq
have ih := modByMonic_eq_sub_mul_div
(p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
unfold modByMonic divByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_pos h]
rw [modByMonic, dif_pos hq] at ih
refine ih.trans ?_
unfold divByMonic
rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub]
else by
unfold modByMonic divByMonic divModByMonicAux
dsimp
rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero]
termination_by p => p
theorem modByMonic_add_div (p : R[X]) {q : R[X]} (hq : Monic q) : p %ₘ q + q * (p /ₘ q) = p :=
eq_sub_iff_add_eq.1 (modByMonic_eq_sub_mul_div p hq)
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
⟨fun h => by
have := modByMonic_add_div p hq
rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this,
fun h => by
classical
have : ¬degree q ≤ degree p := not_le_of_gt h
unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩
theorem degree_add_divByMonic (hq : Monic q) (h : degree q ≤ degree p) :
degree q + degree (p /ₘ q) = degree p := by
nontriviality R
have hdiv0 : p /ₘ q ≠ 0 := by rwa [Ne, divByMonic_eq_zero_iff hq, not_lt]
have hlc : leadingCoeff q * leadingCoeff (p /ₘ q) ≠ 0 := by
rwa [Monic.def.1 hq, one_mul, Ne, leadingCoeff_eq_zero]
have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) :=
calc
degree (p %ₘ q) < degree q := degree_modByMonic_lt _ hq
_ ≤ _ := by
rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree hdiv0, ←
Nat.cast_add, Nat.cast_le]
exact Nat.le_add_right _ _
calc
degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) := Eq.symm (degree_mul' hlc)
_ = degree (p %ₘ q + q * (p /ₘ q)) := (degree_add_eq_right_of_degree_lt hmod).symm
_ = _ := congr_arg _ (modByMonic_add_div _ hq)
theorem degree_divByMonic_le (p q : R[X]) : degree (p /ₘ q) ≤ degree p :=
letI := Classical.decEq R
if hp0 : p = 0 then by simp only [hp0, zero_divByMonic, le_refl]
else
if hq : Monic q then
if h : degree q ≤ degree p then by
haveI := Nontrivial.of_polynomial_ne hp0
rw [← degree_add_divByMonic hq h, degree_eq_natDegree hq.ne_zero,
degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 (not_lt.2 h))]
exact WithBot.coe_le_coe.2 (Nat.le_add_left _ _)
else by
unfold divByMonic divModByMonicAux
simp [dif_pos hq, h, if_false, degree_zero, bot_le]
else (divByMonic_eq_of_not_monic p hq).symm ▸ bot_le
theorem degree_divByMonic_lt (p : R[X]) {q : R[X]} (hq : Monic q) (hp0 : p ≠ 0)
(h0q : 0 < degree q) : degree (p /ₘ q) < degree p :=
if hpq : degree p < degree q then by
haveI := Nontrivial.of_polynomial_ne hp0
rw [(divByMonic_eq_zero_iff hq).2 hpq, degree_eq_natDegree hp0]
exact WithBot.bot_lt_coe _
else by
haveI := Nontrivial.of_polynomial_ne hp0
rw [← degree_add_divByMonic hq (not_lt.1 hpq), degree_eq_natDegree hq.ne_zero,
degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 hpq)]
exact
Nat.cast_lt.2
(Nat.lt_add_of_pos_left (Nat.cast_lt.1 <|
by simpa [degree_eq_natDegree hq.ne_zero] using h0q))
theorem natDegree_divByMonic (f : R[X]) {g : R[X]} (hg : g.Monic) :
natDegree (f /ₘ g) = natDegree f - natDegree g := by
nontriviality R
by_cases hfg : f /ₘ g = 0
· rw [hfg, natDegree_zero]
rw [divByMonic_eq_zero_iff hg] at hfg
rw [tsub_eq_zero_iff_le.mpr (natDegree_le_natDegree <| le_of_lt hfg)]
have hgf := hfg
rw [divByMonic_eq_zero_iff hg] at hgf
push_neg at hgf
have := degree_add_divByMonic hg hgf
have hf : f ≠ 0 := by
intro hf
apply hfg
rw [hf, zero_divByMonic]
rw [degree_eq_natDegree hf, degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hfg,
← Nat.cast_add, Nat.cast_inj] at this
rw [← this, add_tsub_cancel_left]
theorem div_modByMonic_unique {f g} (q r : R[X]) (hg : Monic g)
(h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r := by
nontriviality R
have h₁ : r - f %ₘ g = -g * (q - f /ₘ g) :=
eq_of_sub_eq_zero
(by
rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)]
simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc])
have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)) := by simp [h₁]
have h₄ : degree (r - f %ₘ g) < degree g :=
calc
degree (r - f %ₘ g) ≤ max (degree r) (degree (f %ₘ g)) := degree_sub_le _ _
_ < degree g := max_lt_iff.2 ⟨h.2, degree_modByMonic_lt _ hg⟩
have h₅ : q - f /ₘ g = 0 :=
_root_.by_contradiction fun hqf =>
not_le_of_gt h₄ <|
calc
degree g ≤ degree g + degree (q - f /ₘ g) := by
rw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf]
norm_cast
exact Nat.le_add_right _ _
_ = degree (r - f %ₘ g) := by rw [h₂, degree_mul']; simpa [Monic.def.1 hg]
exact ⟨Eq.symm <| eq_of_sub_eq_zero h₅, Eq.symm <| eq_of_sub_eq_zero <| by simpa [h₅] using h₁⟩
theorem map_mod_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f := by
nontriviality S
haveI : Nontrivial R := f.domain_nontrivial
have : map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q) :=
div_modByMonic_unique ((p /ₘ q).map f) _ (hq.map f)
⟨Eq.symm <| by rw [← Polynomial.map_mul, ← Polynomial.map_add, modByMonic_add_div _ hq],
calc
_ ≤ degree (p %ₘ q) := degree_map_le
_ < degree q := degree_modByMonic_lt _ hq
_ = _ :=
Eq.symm <|
degree_map_eq_of_leadingCoeff_ne_zero _
(by rw [Monic.def.1 hq, f.map_one]; exact one_ne_zero)⟩
exact ⟨this.1.symm, this.2.symm⟩
theorem map_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) :
(p /ₘ q).map f = p.map f /ₘ q.map f :=
(map_mod_divByMonic f hq).1
theorem map_modByMonic [Ring S] (f : R →+* S) (hq : Monic q) :
(p %ₘ q).map f = p.map f %ₘ q.map f :=
(map_mod_divByMonic f hq).2
theorem modByMonic_eq_zero_iff_dvd (hq : Monic q) : p %ₘ q = 0 ↔ q ∣ p :=
⟨fun h => by rw [← modByMonic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, fun h => by
nontriviality R
obtain ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h
by_contra hpq0
have hmod : p %ₘ q = q * (r - p /ₘ q) := by rw [modByMonic_eq_sub_mul_div _ hq, mul_sub, ← hr]
have : degree (q * (r - p /ₘ q)) < degree q := hmod ▸ degree_modByMonic_lt _ hq
have hrpq0 : leadingCoeff (r - p /ₘ q) ≠ 0 := fun h =>
hpq0 <|
leadingCoeff_eq_zero.1
(by rw [hmod, leadingCoeff_eq_zero.1 h, mul_zero, leadingCoeff_zero])
have hlc : leadingCoeff q * leadingCoeff (r - p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul]
rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero,
degree_eq_natDegree (mt leadingCoeff_eq_zero.2 hrpq0)] at this
exact not_lt_of_ge (Nat.le_add_right _ _) (WithBot.coe_lt_coe.1 this)⟩
/-- See `Polynomial.mul_self_modByMonic` for the other multiplication order. That version, unlike
this one, requires commutativity. -/
@[simp]
lemma self_mul_modByMonic (hq : q.Monic) : (q * p) %ₘ q = 0 := by
rw [modByMonic_eq_zero_iff_dvd hq]
exact dvd_mul_right q p
theorem map_dvd_map [Ring S] (f : R →+* S) (hf : Function.Injective f) {x y : R[X]}
(hx : x.Monic) : x.map f ∣ y.map f ↔ x ∣ y := by
rw [← modByMonic_eq_zero_iff_dvd hx, ← modByMonic_eq_zero_iff_dvd (hx.map f), ←
map_modByMonic f hx]
exact
⟨fun H => map_injective f hf <| by rw [H, Polynomial.map_zero], fun H => by
rw [H, Polynomial.map_zero]⟩
@[simp]
theorem modByMonic_one (p : R[X]) : p %ₘ 1 = 0 :=
(modByMonic_eq_zero_iff_dvd (by convert monic_one (R := R))).2 (one_dvd _)
@[simp]
theorem divByMonic_one (p : R[X]) : p /ₘ 1 = p := by
conv_rhs => rw [← modByMonic_add_div p monic_one]; simp
theorem sum_modByMonic_coeff (hq : q.Monic) {n : ℕ} (hn : q.degree ≤ n) :
(∑ i : Fin n, monomial i ((p %ₘ q).coeff i)) = p %ₘ q := by
nontriviality R
exact
(sum_fin (fun i c => monomial i c) (by simp) ((degree_modByMonic_lt _ hq).trans_le hn)).trans
(sum_monomial_eq _)
theorem mul_divByMonic_cancel_left (p : R[X]) {q : R[X]} (hmo : q.Monic) :
q * p /ₘ q = p := by
nontriviality R
refine (div_modByMonic_unique _ 0 hmo ⟨by rw [zero_add], ?_⟩).1
rw [degree_zero]
exact Ne.bot_lt fun h => hmo.ne_zero (degree_eq_bot.1 h)
lemma coeff_divByMonic_X_sub_C_rec (p : R[X]) (a : R) (n : ℕ) :
(p /ₘ (X - C a)).coeff n = coeff p (n + 1) + a * (p /ₘ (X - C a)).coeff (n + 1) := by
nontriviality R
have := monic_X_sub_C a
set q := p /ₘ (X - C a)
rw [← p.modByMonic_add_div this]
have : degree (p %ₘ (X - C a)) < ↑(n + 1) := degree_X_sub_C a ▸ p.degree_modByMonic_lt this
|>.trans_le <| WithBot.coe_le_coe.mpr le_add_self
simp [q, sub_mul, add_sub, coeff_eq_zero_of_degree_lt this]
theorem coeff_divByMonic_X_sub_C (p : R[X]) (a : R) (n : ℕ) :
(p /ₘ (X - C a)).coeff n = ∑ i ∈ Icc (n + 1) p.natDegree, a ^ (i - (n + 1)) * p.coeff i := by
wlog h : p.natDegree ≤ n generalizing n
· refine Nat.decreasingInduction' (fun n hn _ ih ↦ ?_) (le_of_not_le h) ?_
· rw [coeff_divByMonic_X_sub_C_rec, ih, eq_comm, Icc_eq_cons_Ioc (Nat.succ_le.mpr hn),
sum_cons, Nat.sub_self, pow_zero, one_mul, mul_sum]
congr 1; refine sum_congr ?_ fun i hi ↦ ?_
· ext; simp [Nat.succ_le]
rw [← mul_assoc, ← pow_succ', eq_comm, i.sub_succ', Nat.sub_add_cancel]
apply Nat.le_sub_of_add_le
rw [add_comm]; exact (mem_Icc.mp hi).1
· exact this _ le_rfl
rw [Icc_eq_empty (Nat.lt_succ.mpr h).not_le, sum_empty]
nontriviality R
by_cases hp : p.natDegree = 0
· rw [(divByMonic_eq_zero_iff <| monic_X_sub_C a).mpr, coeff_zero]
apply degree_lt_degree; rw [hp, natDegree_X_sub_C]; norm_num
· apply coeff_eq_zero_of_natDegree_lt
rw [natDegree_divByMonic p (monic_X_sub_C a), natDegree_X_sub_C]
exact (Nat.pred_lt hp).trans_le h
variable (R) in
theorem not_isField : ¬IsField R[X] := by
nontriviality R
intro h
letI := h.toField
simpa using congr_arg natDegree (monic_X.eq_one_of_isUnit <| monic_X (R := R).ne_zero.isUnit)
section multiplicity
/-- An algorithm for deciding polynomial divisibility.
The algorithm is "compute `p %ₘ q` and compare to `0`".
See `Polynomial.modByMonic` for the algorithm that computes `%ₘ`.
-/
def decidableDvdMonic [DecidableEq R] (p : R[X]) (hq : Monic q) : Decidable (q ∣ p) :=
decidable_of_iff (p %ₘ q = 0) (modByMonic_eq_zero_iff_dvd hq)
theorem finiteMultiplicity_X_sub_C (a : R) (h0 : p ≠ 0) : FiniteMultiplicity (X - C a) p := by
haveI := Nontrivial.of_polynomial_ne h0
refine finiteMultiplicity_of_degree_pos_of_monic ?_ (monic_X_sub_C _) h0
rw [degree_X_sub_C]
decide
@[deprecated (since := "2024-11-30")]
alias multiplicity_X_sub_C_finite := finiteMultiplicity_X_sub_C
/- Porting note: stripping out classical for decidability instance parameter might
make for better ergonomics -/
/-- The largest power of `X - C a` which divides `p`.
This *could be* computable via the divisibility algorithm `Polynomial.decidableDvdMonic`,
as shown by `Polynomial.rootMultiplicity_eq_nat_find_of_nonzero` which has a computable RHS. -/
def rootMultiplicity (a : R) (p : R[X]) : ℕ :=
letI := Classical.decEq R
if h0 : p = 0 then 0
else
let _ : DecidablePred fun n : ℕ => ¬(X - C a) ^ (n + 1) ∣ p := fun n =>
have := decidableDvdMonic p ((monic_X_sub_C a).pow (n + 1))
inferInstanceAs (Decidable ¬_)
Nat.find (finiteMultiplicity_X_sub_C a h0)
/- Porting note: added the following due to diamond with decidableProp and
decidableDvdMonic see also [Zulip]
(https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/non-defeq.20aliased.20instance) -/
| theorem rootMultiplicity_eq_nat_find_of_nonzero [DecidableEq R] {p : R[X]} (p0 : p ≠ 0) {a : R} :
letI : DecidablePred fun n : ℕ => ¬(X - C a) ^ (n + 1) ∣ p := fun n =>
have := decidableDvdMonic p ((monic_X_sub_C a).pow (n + 1))
inferInstanceAs (Decidable ¬_)
rootMultiplicity a p = Nat.find (finiteMultiplicity_X_sub_C a p0) := by
| Mathlib/Algebra/Polynomial/Div.lean | 511 | 515 |
/-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Riccardo Brasca, Eric Rodriguez
-/
import Mathlib.Data.PNat.Prime
import Mathlib.NumberTheory.Cyclotomic.Basic
import Mathlib.RingTheory.Adjoin.PowerBasis
import Mathlib.RingTheory.Norm.Basic
import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval
import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Primitive roots in cyclotomic fields
If `IsCyclotomicExtension {n} A B`, we define an element `zeta n A B : B` that is a primitive
`n`th-root of unity in `B` and we study its properties. We also prove related theorems under the
more general assumption of just being a primitive root, for reasons described in the implementation
details section.
## Main definitions
* `IsCyclotomicExtension.zeta n A B`: if `IsCyclotomicExtension {n} A B`, than `zeta n A B`
is a primitive `n`-th root of unity in `B`.
* `IsPrimitiveRoot.powerBasis`: if `K` and `L` are fields such that
`IsCyclotomicExtension {n} K L`, then `IsPrimitiveRoot.powerBasis`
gives a `K`-power basis for `L` given a primitive root `ζ`.
* `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A`
and `primitiveroots n A` given by the choice of `ζ`.
## Main results
* `IsCyclotomicExtension.zeta_spec`: `zeta n A B` is a primitive `n`-th root of unity.
* `IsCyclotomicExtension.finrank`: if `Irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the `finrank` of a cyclotomic extension is `n.totient`.
* `IsPrimitiveRoot.norm_eq_one`: if `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`),
the norm of a primitive root is `1` if `n ≠ 2`.
* `IsPrimitiveRoot.sub_one_norm_eq_eval_cyclotomic`: if `Irreducible (cyclotomic n K)`
(in particular for `K = ℚ`), then the norm of `ζ - 1` is `eval 1 (cyclotomic n ℤ)`, for a
primitive root `ζ`. We also prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.norm_pow_sub_one_of_prime_pow_ne_two` : if
`Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` `p ^ (k - s + 1) ≠ 2`. See the following
lemmas for similar results. We also prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.norm_sub_one_of_prime_ne_two` : if `Irreducible (cyclotomic (p ^ (k + 1)) K)`
(in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. We also
prove the analogous of this result for `zeta`.
* `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A`
and `primitiveRoots n A` given by the choice of `ζ`.
## Implementation details
`zeta n A B` is defined as any primitive root of unity in `B`, - this must exist, by definition of
`IsCyclotomicExtension`. It is not true in general that it is a root of `cyclotomic n B`,
but this holds if `isDomain B` and `NeZero (↑n : B)`.
`zeta n A B` is defined using `Exists.choose`, which means we cannot control it.
For example, in normal mathematics, we can demand that `(zeta p ℤ ℤ[ζₚ] : ℚ(ζₚ))` is equal to
`zeta p ℚ ℚ(ζₚ)`, as we are just choosing "an arbitrary primitive root" and we can internally
specify that our choices agree. This is not the case here, and it is indeed impossible to prove that
these two are equal. Therefore, whenever possible, we prove our results for any primitive root,
and only at the "final step", when we need to provide an "explicit" primitive root, we use `zeta`.
-/
open Polynomial Algebra Finset Module IsCyclotomicExtension Nat PNat Set
open scoped IntermediateField
universe u v w z
variable {p n : ℕ+} (A : Type w) (B : Type z) (K : Type u) {L : Type v} (C : Type w)
variable [CommRing A] [CommRing B] [Algebra A B] [IsCyclotomicExtension {n} A B]
section Zeta
namespace IsCyclotomicExtension
variable (n)
/-- If `B` is an `n`-th cyclotomic extension of `A`, then `zeta n A B` is a primitive root of
unity in `B`. -/
noncomputable def zeta : B :=
(exists_prim_root A <| Set.mem_singleton n : ∃ r : B, IsPrimitiveRoot r n).choose
/-- `zeta n A B` is a primitive `n`-th root of unity. -/
@[simp]
theorem zeta_spec : IsPrimitiveRoot (zeta n A B) n :=
Classical.choose_spec (exists_prim_root A (Set.mem_singleton n) : ∃ r : B, IsPrimitiveRoot r n)
theorem aeval_zeta [IsDomain B] [NeZero ((n : ℕ) : B)] :
aeval (zeta n A B) (cyclotomic n A) = 0 := by
rw [aeval_def, ← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff]
exact zeta_spec n A B
theorem zeta_isRoot [IsDomain B] [NeZero ((n : ℕ) : B)] : IsRoot (cyclotomic n B) (zeta n A B) := by
convert aeval_zeta n A B using 0
rw [IsRoot.def, aeval_def, eval₂_eq_eval_map, map_cyclotomic]
theorem zeta_pow : zeta n A B ^ (n : ℕ) = 1 :=
(zeta_spec n A B).pow_eq_one
end IsCyclotomicExtension
end Zeta
section NoOrder
variable [Field K] [CommRing L] [IsDomain L] [Algebra K L] [IsCyclotomicExtension {n} K L] {ζ : L}
(hζ : IsPrimitiveRoot ζ n)
namespace IsPrimitiveRoot
variable {C}
/-- The `PowerBasis` given by a primitive root `η`. -/
@[simps!]
protected noncomputable def powerBasis : PowerBasis K L :=
-- this is purely an optimization
letI pb := Algebra.adjoin.powerBasis <| (integral {n} K L).isIntegral ζ
pb.map <| (Subalgebra.equivOfEq _ _ (IsCyclotomicExtension.adjoin_primitive_root_eq_top hζ)).trans
Subalgebra.topEquiv
theorem powerBasis_gen_mem_adjoin_zeta_sub_one :
(hζ.powerBasis K).gen ∈ adjoin K ({ζ - 1} : Set L) := by
rw [powerBasis_gen, adjoin_singleton_eq_range_aeval, AlgHom.mem_range]
exact ⟨X + 1, by simp⟩
/-- The `PowerBasis` given by `η - 1`. -/
@[simps!]
noncomputable def subOnePowerBasis : PowerBasis K L :=
(hζ.powerBasis K).ofGenMemAdjoin
(((integral {n} K L).isIntegral ζ).sub isIntegral_one)
(hζ.powerBasis_gen_mem_adjoin_zeta_sub_one _)
variable {K} (C)
-- We are not using @[simps] to avoid a timeout.
/-- The equivalence between `L →ₐ[K] C` and `primitiveRoots n C` given by a primitive root `ζ`. -/
noncomputable def embeddingsEquivPrimitiveRoots (C : Type*) [CommRing C] [IsDomain C] [Algebra K C]
(hirr : Irreducible (cyclotomic n K)) : (L →ₐ[K] C) ≃ primitiveRoots n C :=
(hζ.powerBasis K).liftEquiv.trans
{ toFun := fun x => by
haveI := IsCyclotomicExtension.neZero' n K L
haveI hn := NeZero.of_faithfulSMul K C n
refine ⟨x.1, ?_⟩
cases x
rwa [mem_primitiveRoots n.pos, ← isRoot_cyclotomic_iff, IsRoot.def,
← map_cyclotomic _ (algebraMap K C), hζ.minpoly_eq_cyclotomic_of_irreducible hirr,
← eval₂_eq_eval_map, ← aeval_def]
invFun := fun x => by
haveI := IsCyclotomicExtension.neZero' n K L
haveI hn := NeZero.of_faithfulSMul K C n
refine ⟨x.1, ?_⟩
cases x
rwa [aeval_def, eval₂_eq_eval_map, hζ.powerBasis_gen K, ←
hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_cyclotomic, ← IsRoot.def,
isRoot_cyclotomic_iff, ← mem_primitiveRoots n.pos]
left_inv := fun _ => Subtype.ext rfl
right_inv := fun _ => Subtype.ext rfl }
-- Porting note: renamed argument `φ`: "expected '_' or identifier"
@[simp]
theorem embeddingsEquivPrimitiveRoots_apply_coe (C : Type*) [CommRing C] [IsDomain C] [Algebra K C]
(hirr : Irreducible (cyclotomic n K)) (φ' : L →ₐ[K] C) :
(hζ.embeddingsEquivPrimitiveRoots C hirr φ' : C) = φ' ζ :=
rfl
end IsPrimitiveRoot
namespace IsCyclotomicExtension
variable {K} (L)
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the `finrank` of a
cyclotomic extension is `n.totient`. -/
theorem finrank (hirr : Irreducible (cyclotomic n K)) : finrank K L = (n : ℕ).totient := by
haveI := IsCyclotomicExtension.neZero' n K L
rw [((zeta_spec n K L).powerBasis K).finrank, IsPrimitiveRoot.powerBasis_dim, ←
(zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic]
variable {L} in
/-- If `L` contains both a primitive `p`-th root of unity and `q`-th root of unity, and
`Irreducible (cyclotomic (lcm p q) K)` (in particular for `K = ℚ`), then the `finrank K L` is at
least `(lcm p q).totient`. -/
theorem _root_.IsPrimitiveRoot.lcm_totient_le_finrank [FiniteDimensional K L] {p q : ℕ} {x y : L}
(hx : IsPrimitiveRoot x p) (hy : IsPrimitiveRoot y q)
(hirr : Irreducible (cyclotomic (Nat.lcm p q) K)) :
(Nat.lcm p q).totient ≤ Module.finrank K L := by
rcases Nat.eq_zero_or_pos p with (rfl | hppos)
· simp
rcases Nat.eq_zero_or_pos q with (rfl | hqpos)
· simp
let z := x ^ (p / factorizationLCMLeft p q) * y ^ (q / factorizationLCMRight p q)
let k := PNat.lcm ⟨p, hppos⟩ ⟨q, hqpos⟩
have : IsPrimitiveRoot z k := hx.pow_mul_pow_lcm hy hppos.ne' hqpos.ne'
haveI := IsPrimitiveRoot.adjoin_isCyclotomicExtension K this
convert Submodule.finrank_le (Subalgebra.toSubmodule (adjoin K {z}))
rw [show Nat.lcm p q = (k : ℕ) from rfl] at hirr
simpa using (IsCyclotomicExtension.finrank (Algebra.adjoin K {z}) hirr).symm
end IsCyclotomicExtension
end NoOrder
section Norm
namespace IsPrimitiveRoot
section Field
variable {K} [Field K] [NumberField K]
variable (n) in
/-- If a `n`-th cyclotomic extension of `ℚ` contains a primitive `l`-th root of unity, then
`l ∣ 2 * n`. -/
theorem dvd_of_isCyclotomicExtension [IsCyclotomicExtension {n} ℚ K] {ζ : K}
{l : ℕ} (hζ : IsPrimitiveRoot ζ l) (hl : l ≠ 0) : l ∣ 2 * n := by
have hl : NeZero l := ⟨hl⟩
have hroot := IsCyclotomicExtension.zeta_spec n ℚ K
have key := IsPrimitiveRoot.lcm_totient_le_finrank hζ hroot
(cyclotomic.irreducible_rat <| Nat.lcm_pos (Nat.pos_of_ne_zero hl.1) n.2)
rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat n.2)] at key
rcases _root_.dvd_lcm_right l n with ⟨r, hr⟩
have ineq := Nat.totient_super_multiplicative n r
rw [← hr] at ineq
replace key := (mul_le_iff_le_one_right (Nat.totient_pos.2 n.2)).mp (le_trans ineq key)
have rpos : 0 < r := by
refine Nat.pos_of_ne_zero (fun h ↦ ?_)
simp only [h, mul_zero, _root_.lcm_eq_zero_iff, PNat.ne_zero, or_false] at hr
exact hl.1 hr
replace key := (Nat.dvd_prime Nat.prime_two).1 (Nat.dvd_two_of_totient_le_one rpos key)
rcases key with (key | key)
· rw [key, mul_one] at hr
rw [← hr]
exact dvd_mul_of_dvd_right (_root_.dvd_lcm_left l ↑n) 2
· rw [key, mul_comm] at hr
simpa [← hr] using _root_.dvd_lcm_left _ _
/-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of
`ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exist `r`
such that `x = (-ζ)^r`. -/
theorem exists_neg_pow_of_isOfFinOrder [IsCyclotomicExtension {n} ℚ K]
(hno : Odd (n : ℕ)) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) :
∃ r : ℕ, x = (-ζ) ^ r := by
have hnegζ : IsPrimitiveRoot (-ζ) (2 * n) := by
convert IsPrimitiveRoot.orderOf (-ζ)
rw [neg_eq_neg_one_mul, (Commute.all _ _).orderOf_mul_eq_mul_orderOf_of_coprime]
· simp [hζ.eq_orderOf]
· simp [← hζ.eq_orderOf, hno]
obtain ⟨k, hkpos, hkn⟩ := isOfFinOrder_iff_pow_eq_one.1 hx
obtain ⟨l, hl, hlroot⟩ := (isRoot_of_unity_iff hkpos _).1 hkn
have hlzero : NeZero l := ⟨fun h ↦ by simp [h] at hl⟩
have : NeZero (l : K) := ⟨NeZero.natCast_ne l K⟩
rw [isRoot_cyclotomic_iff] at hlroot
obtain ⟨a, ha⟩ := hlroot.dvd_of_isCyclotomicExtension n hlzero.1
replace hlroot : x ^ (2 * (n : ℕ)) = 1 := by rw [ha, pow_mul, hlroot.pow_eq_one, one_pow]
obtain ⟨s, -, hs⟩ := hnegζ.eq_pow_of_pow_eq_one hlroot
exact ⟨s, hs.symm⟩
/-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of
`ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exists `r < n`
such that `x = ζ^r` or `x = -ζ^r`. -/
theorem exists_pow_or_neg_mul_pow_of_isOfFinOrder [IsCyclotomicExtension {n} ℚ K]
(hno : Odd (n : ℕ)) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) :
∃ r : ℕ, r < n ∧ (x = ζ ^ r ∨ x = -ζ ^ r) := by
obtain ⟨r, hr⟩ := hζ.exists_neg_pow_of_isOfFinOrder hno hx
refine ⟨r % n, Nat.mod_lt _ n.2, ?_⟩
rw [show ζ ^ (r % ↑n) = ζ ^ r from (IsPrimitiveRoot.eq_orderOf hζ).symm ▸ pow_mod_orderOf .., hr]
rcases Nat.even_or_odd r with (h | h) <;> simp [neg_pow, h.neg_one_pow]
end Field
section CommRing
variable [CommRing L] {ζ : L}
variable {K} [Field K] [Algebra K L]
/-- This mathematically trivial result is complementary to `norm_eq_one` below. -/
theorem norm_eq_neg_one_pow (hζ : IsPrimitiveRoot ζ 2) [IsDomain L] :
norm K ζ = (-1 : K) ^ finrank K L := by
rw [hζ.eq_neg_one_of_two_right, show -1 = algebraMap K L (-1) by simp, Algebra.norm_algebraMap]
variable (hζ : IsPrimitiveRoot ζ n)
include hζ
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of a primitive root is
`1` if `n ≠ 2`. -/
theorem norm_eq_one [IsDomain L] [IsCyclotomicExtension {n} K L] (hn : n ≠ 2)
(hirr : Irreducible (cyclotomic n K)) : norm K ζ = 1 := by
haveI := IsCyclotomicExtension.neZero' n K L
by_cases h1 : n = 1
· rw [h1, one_coe, one_right_iff] at hζ
rw [hζ, show 1 = algebraMap K L 1 by simp, Algebra.norm_algebraMap, one_pow]
· replace h1 : 2 ≤ n := by
by_contra! h
exact h1 (PNat.eq_one_of_lt_two h)
-- Porting note: specifying the type of `cyclotomic_coeff_zero K h1` was not needed.
rw [← hζ.powerBasis_gen K, PowerBasis.norm_gen_eq_coeff_zero_minpoly, hζ.powerBasis_gen K, ←
hζ.minpoly_eq_cyclotomic_of_irreducible hirr,
(cyclotomic_coeff_zero K h1 : coeff (cyclotomic n K) 0 = 1), mul_one,
hζ.powerBasis_dim K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic]
exact (totient_even <| h1.lt_of_ne hn.symm).neg_one_pow
/-- If `K` is linearly ordered, the norm of a primitive root is `1` if `n` is odd. -/
theorem norm_eq_one_of_linearly_ordered {K : Type*}
[Field K] [LinearOrder K] [IsStrictOrderedRing K] [Algebra K L]
(hodd : Odd (n : ℕ)) : norm K ζ = 1 := by
have hz := congr_arg (norm K) ((IsPrimitiveRoot.iff_def _ n).1 hζ).1
rw [← (algebraMap K L).map_one, Algebra.norm_algebraMap, one_pow, map_pow, ← one_pow ↑n] at hz
exact StrictMono.injective hodd.strictMono_pow hz
theorem norm_of_cyclotomic_irreducible [IsDomain L] [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic n K)) : norm K ζ = ite (n = 2) (-1) 1 := by
split_ifs with hn
· subst hn
rw [norm_eq_neg_one_pow (K := K) hζ, IsCyclotomicExtension.finrank _ hirr]
norm_cast
· exact hζ.norm_eq_one hn hirr
end CommRing
section Field
variable [Field L] {ζ : L}
variable {K} [Field K] [Algebra K L]
section
variable (hζ : IsPrimitiveRoot ζ n)
include hζ
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of
`ζ - 1` is `eval 1 (cyclotomic n ℤ)`. -/
theorem sub_one_norm_eq_eval_cyclotomic [IsCyclotomicExtension {n} K L] (h : 2 < (n : ℕ))
(hirr : Irreducible (cyclotomic n K)) : norm K (ζ - 1) = ↑(eval 1 (cyclotomic n ℤ)) := by
haveI := IsCyclotomicExtension.neZero' n K L
let E := AlgebraicClosure L
obtain ⟨z, hz⟩ := IsAlgClosed.exists_root _ (degree_cyclotomic_pos n E n.pos).ne.symm
apply (algebraMap K E).injective
letI := IsCyclotomicExtension.finiteDimensional {n} K L
letI := IsCyclotomicExtension.isGalois n K L
rw [norm_eq_prod_embeddings]
conv_lhs =>
congr
rfl
ext
rw [← neg_sub, map_neg, map_sub, map_one, neg_eq_neg_one_mul]
rw [prod_mul_distrib, prod_const, Finset.card_univ, AlgHom.card,
IsCyclotomicExtension.finrank L hirr, (totient_even h).neg_one_pow, one_mul]
have Hprod : (Finset.univ.prod fun σ : L →ₐ[K] E => 1 - σ ζ) = eval 1 (cyclotomic' n E) := by
rw [cyclotomic', eval_prod, ← @Finset.prod_attach E E, ← univ_eq_attach]
refine Fintype.prod_equiv (hζ.embeddingsEquivPrimitiveRoots E hirr) _ _ fun σ => ?_
simp
haveI : NeZero ((n : ℕ) : E) := NeZero.of_faithfulSMul K _ (n : ℕ)
rw [Hprod, cyclotomic', ← cyclotomic_eq_prod_X_sub_primitiveRoots (isRoot_cyclotomic_iff.1 hz),
← map_cyclotomic_int, _root_.map_intCast, ← Int.cast_one, eval_intCast_map, eq_intCast,
Int.cast_id]
/-- If `IsPrimePow (n : ℕ)`, `n ≠ 2` and `Irreducible (cyclotomic n K)` (in particular for
`K = ℚ`), then the norm of `ζ - 1` is `(n : ℕ).minFac`. -/
theorem sub_one_norm_isPrimePow (hn : IsPrimePow (n : ℕ)) [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic (n : ℕ) K)) (h : n ≠ 2) : norm K (ζ - 1) = (n : ℕ).minFac := by
have :=
(coe_lt_coe 2 _).1
(lt_of_le_of_ne (succ_le_of_lt (IsPrimePow.one_lt hn))
(Function.Injective.ne PNat.coe_injective h).symm)
letI hprime : Fact (n : ℕ).minFac.Prime := ⟨minFac_prime (IsPrimePow.ne_one hn)⟩
rw [sub_one_norm_eq_eval_cyclotomic hζ this hirr]
nth_rw 1 [← IsPrimePow.minFac_pow_factorization_eq hn]
obtain ⟨k, hk⟩ : ∃ k, (n : ℕ).factorization (n : ℕ).minFac = k + 1 :=
exists_eq_succ_of_ne_zero
(((n : ℕ).factorization.mem_support_toFun (n : ℕ).minFac).1 <|
mem_primeFactors_iff_mem_primeFactorsList.2 <|
(mem_primeFactorsList (IsPrimePow.ne_zero hn)).2 ⟨hprime.out, minFac_dvd _⟩)
simp [hk, sub_one_norm_eq_eval_cyclotomic hζ this hirr]
end
variable {A}
theorem minpoly_sub_one_eq_cyclotomic_comp [Algebra K A] [IsDomain A] {ζ : A}
[IsCyclotomicExtension {n} K A] (hζ : IsPrimitiveRoot ζ n)
(h : Irreducible (Polynomial.cyclotomic n K)) :
minpoly K (ζ - 1) = (cyclotomic n K).comp (X + 1) := by
haveI := IsCyclotomicExtension.neZero' n K A
rw [show ζ - 1 = ζ + algebraMap K A (-1) by simp [sub_eq_add_neg],
minpoly.add_algebraMap ζ,
hζ.minpoly_eq_cyclotomic_of_irreducible h]
simp
open scoped Cyclotomic
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ^ (k - s + 1) ≠ 2`. See the next lemmas
for similar results. -/
theorem norm_pow_sub_one_of_prime_pow_ne_two {k s : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1)))
[hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) : norm K (ζ ^ (p : ℕ) ^ s - 1) = (p : K) ^ (p : ℕ) ^ s := by
have hirr₁ : Irreducible (cyclotomic ((p : ℕ) ^ (k - s + 1)) K) :=
cyclotomic_irreducible_pow_of_irreducible_pow hpri.1 (by omega) hirr
rw [← PNat.pow_coe] at hirr₁
set η := ζ ^ (p : ℕ) ^ s - 1
let η₁ : K⟮η⟯ := IntermediateField.AdjoinSimple.gen K η
have hη : IsPrimitiveRoot (η + 1) ((p : ℕ) ^ (k + 1 - s)) := by
rw [sub_add_cancel]
refine IsPrimitiveRoot.pow (p ^ (k + 1)).pos hζ ?_
rw [PNat.pow_coe, ← pow_add, add_comm s, Nat.sub_add_cancel (le_trans hs (Nat.le_succ k))]
have : IsCyclotomicExtension {p ^ (k - s + 1)} K K⟮η⟯ := by
have HKη : K⟮η⟯ = K⟮η + 1⟯ := by
refine le_antisymm ?_ ?_
all_goals rw [IntermediateField.adjoin_simple_le_iff]
· nth_rw 2 [← add_sub_cancel_right η 1]
exact sub_mem (IntermediateField.mem_adjoin_simple_self K (η + 1)) (one_mem _)
· exact add_mem (IntermediateField.mem_adjoin_simple_self K η) (one_mem _)
rw [HKη]
have H := IntermediateField.adjoin_simple_toSubalgebra_of_integral
((integral {p ^ (k + 1)} K L).isIntegral (η + 1))
refine IsCyclotomicExtension.equiv _ _ _ (h := ?_) (.refl : K⟮η + 1⟯.toSubalgebra ≃ₐ[K] _)
rw [H]
have hη' : IsPrimitiveRoot (η + 1) ↑(p ^ (k + 1 - s)) := by simpa using hη
convert hη'.adjoin_isCyclotomicExtension K using 1
rw [Nat.sub_add_comm hs]
replace hη : IsPrimitiveRoot (η₁ + 1) ↑(p ^ (k - s + 1)) := by
apply coe_submonoidClass_iff.1
convert hη using 1
rw [Nat.sub_add_comm hs, pow_coe]
have := IsCyclotomicExtension.finiteDimensional {p ^ (k + 1)} K L
have := IsCyclotomicExtension.isGalois (p ^ (k + 1)) K L
rw [norm_eq_norm_adjoin K]
have H := hη.sub_one_norm_isPrimePow ?_ hirr₁ htwo
swap; · rw [PNat.pow_coe]; exact hpri.1.isPrimePow.pow (Nat.succ_ne_zero _)
rw [add_sub_cancel_right] at H
rw [H]
congr
· rw [PNat.pow_coe, Nat.pow_minFac, hpri.1.minFac_eq]
exact Nat.succ_ne_zero _
have := Module.finrank_mul_finrank K K⟮η⟯ L
rw [IsCyclotomicExtension.finrank L hirr, IsCyclotomicExtension.finrank K⟮η⟯ hirr₁,
PNat.pow_coe, PNat.pow_coe, Nat.totient_prime_pow hpri.out (k - s).succ_pos,
Nat.totient_prime_pow hpri.out k.succ_pos, mul_comm _ ((p : ℕ) - 1), mul_assoc,
mul_comm ((p : ℕ) ^ (k.succ - 1))] at this
replace this := mul_left_cancel₀ (tsub_pos_iff_lt.2 hpri.out.one_lt).ne' this
have Hex : k.succ - 1 = (k - s).succ - 1 + s := by
simp only [Nat.succ_sub_succ_eq_sub, tsub_zero]
exact (Nat.sub_add_cancel hs).symm
rw [Hex, pow_add] at this
exact mul_left_cancel₀ (pow_ne_zero _ hpri.out.ne_zero) this
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ≠ 2`. -/
theorem norm_pow_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1)))
[hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) {s : ℕ} (hs : s ≤ k) (hodd : p ≠ 2) :
norm K (ζ ^ (p : ℕ) ^ s - 1) = (p : K) ^ (p : ℕ) ^ s := by
refine hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs fun h => ?_
have coe_two : ((2 : ℕ+) : ℕ) = 2 := by norm_cast
rw [← PNat.coe_inj, coe_two, PNat.pow_coe, ← pow_one 2] at h
replace h :=
eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (k - s).succ_pos h
exact hodd (PNat.coe_injective h)
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `ζ - 1` is `p`. -/
theorem norm_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1)))
[hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by
simpa using hζ.norm_pow_sub_one_of_prime_ne_two hirr k.zero_le h
/-- If `Irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `ζ - 1` is `p`. -/
theorem norm_sub_one_of_prime_ne_two' [hpri : Fact (p : ℕ).Prime]
[hcyc : IsCyclotomicExtension {p} K L] (hζ : IsPrimitiveRoot ζ p)
(hirr : Irreducible (cyclotomic p K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by
replace hirr : Irreducible (cyclotomic (p ^ (0 + 1) : ℕ) K) := by simp [hirr]
replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1) : ℕ) := by simp [hζ]
haveI : IsCyclotomicExtension {p ^ (0 + 1)} K L := by simp [hcyc]
simpa using norm_sub_one_of_prime_ne_two hζ hirr h
/-- If `Irreducible (cyclotomic (2 ^ (k + 1)) K)` (in particular for `K = ℚ`), then the norm of
`ζ ^ (2 ^ k) - 1` is `(-2) ^ (2 ^ k)`. -/
theorem norm_pow_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ (k + 1)))
[IsCyclotomicExtension {2 ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (2 ^ (k + 1)) K)) :
norm K (ζ ^ 2 ^ k - 1) = (-2 : K) ^ 2 ^ k := by
have := hζ.pow_of_dvd (fun h => two_ne_zero (pow_eq_zero h)) (pow_dvd_pow 2 (le_succ k))
| rw [Nat.pow_div (le_succ k) zero_lt_two, Nat.succ_sub (le_refl k), Nat.sub_self, pow_one] at this
have H : (-1 : L) - (1 : L) = algebraMap K L (-2) := by
simp only [map_neg, map_ofNat]
ring
| Mathlib/NumberTheory/Cyclotomic/PrimitiveRoots.lean | 484 | 487 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.GroupTheory.Perm.Finite
import Mathlib.GroupTheory.Perm.List
import Mathlib.GroupTheory.Perm.Sign
/-!
# Cycles of a permutation
This file starts the theory of cycles in permutations.
## Main definitions
In the following, `f : Equiv.Perm β`.
* `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`.
* `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated
applications of `f`, and `f` is not the identity.
* `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by
repeated applications of `f`.
## Notes
`Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways:
* `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set.
* `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton).
* `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-! ### `SameCycle` -/
section SameCycle
variable {f g : Perm α} {p : α → Prop} {x y z : α}
/-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/
def SameCycle (f : Perm α) (x y : α) : Prop :=
∃ i : ℤ, (f ^ i) x = y
@[refl]
theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x :=
⟨0, rfl⟩
theorem SameCycle.rfl : SameCycle f x x :=
SameCycle.refl _ _
protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h]
@[symm]
theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ =>
⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩
theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x :=
⟨SameCycle.symm, SameCycle.symm⟩
@[trans]
theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z :=
fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩
variable (f) in
theorem SameCycle.equivalence : Equivalence (SameCycle f) :=
⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩
/-- The setoid defined by the `SameCycle` relation. -/
def SameCycle.setoid (f : Perm α) : Setoid α where
r := f.SameCycle
iseqv := SameCycle.equivalence f
@[simp]
theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle]
@[simp]
theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y :=
(Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle]
alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv
@[simp]
theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) :=
exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq]
theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by
simp [sameCycle_conj]
theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by
rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply,
(f ^ i).injective.eq_iff]
theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y :=
let ⟨_, hn⟩ := h
(hx.perm_zpow _).eq.symm.trans hn
theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y :=
h.eq_of_left <| h.apply_eq_self_iff.2 hy
@[simp]
theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y :=
(Equiv.addRight 1).exists_congr_left.trans <| by
simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp]
@[simp]
theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm]
@[simp]
theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by
rw [← sameCycle_apply_left, apply_inv_self]
@[simp]
theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by
rw [← sameCycle_apply_right, apply_inv_self]
@[simp]
theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y :=
(Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add]
@[simp]
theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm]
@[simp]
theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_left]
@[simp]
theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_right]
alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left
alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right
alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left
alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right
alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left
alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right
alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left
alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right
theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
@[simp]
theorem sameCycle_subtypePerm {h} {x y : { x // p x }} :
(f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y :=
exists_congr fun n => by simp [Subtype.ext_iff]
alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm
@[simp]
theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} :
SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y :=
exists_congr fun n => by
rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff]
alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
rintro ⟨k, rfl⟩
use (k % orderOf f).natAbs
have h₀ := Int.natCast_pos.mpr (orderOf_pos f)
have h₁ := Int.emod_nonneg k h₀.ne'
rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf]
refine ⟨?_, by rfl⟩
rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁]
exact Int.emod_lt_of_pos _ h₀
theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by
obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq'
· refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩
rw [pow_orderOf_eq_one, pow_zero]
· exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩
theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by
obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h
exact ⟨⟨i, hi⟩, hx⟩
theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, (f ^ i) x = y := by
obtain ⟨i, _, hi⟩ := h.exists_pow_eq'
exact ⟨i, hi⟩
instance (f : Perm α) [DecidableRel (SameCycle f)] :
DecidableRel (SameCycle f⁻¹) := fun x y =>
decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm
instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y =>
decidable_of_iff (x = y) sameCycle_one.symm
end SameCycle
/-!
### `IsCycle`
-/
section IsCycle
variable {f g : Perm α} {x y : α}
/-- A cycle is a non identity permutation where any two nonfixed points of the permutation are
related by repeated application of the permutation. -/
def IsCycle (f : Perm α) : Prop :=
∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y
theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h
@[simp]
theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl
protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
SameCycle f x y :=
let ⟨g, hg⟩ := hf
let ⟨a, ha⟩ := hg.2 hx
let ⟨b, hb⟩ := hg.2 hy
⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩
theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y :=
IsCycle.sameCycle
theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ :=
hf.imp fun _ ⟨hx, h⟩ =>
⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩
@[simp]
theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f :=
⟨fun h => h.inv, IsCycle.inv⟩
theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by
rintro ⟨x, hx, h⟩
refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩
rw [← apply_inv_self g y]
exact (h <| eq_inv_iff_eq.not.2 hy).conj
protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) :
IsCycle g → IsCycle (g.extendDomain f) := by
rintro ⟨a, ha, ha'⟩
refine ⟨f a, ?_, fun b hb => ?_⟩
· rw [extendDomain_apply_image]
exact Subtype.coe_injective.ne (f.injective.ne ha)
have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by
rw [apply_symm_apply, Subtype.coe_mk]
rw [h] at hb ⊢
simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb
exact (ha' hb).extendDomain
theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y :=
⟨fun hf y =>
⟨fun ⟨i, hi⟩ hy =>
hx <| by
rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi
rw [hi, hy],
hf.exists_zpow_eq hx⟩,
fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩
section Finite
variable [Finite α]
theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
∃ i : ℕ, (f ^ i) x = y := by
let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy
classical exact
⟨(n % orderOf f).toNat, by
{have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f)))
rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩
end Finite
variable [DecidableEq α]
theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) :=
⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) =>
if hya : y = a then ⟨0, hya⟩
else
⟨1, by
rw [zpow_one, swap_apply_def]
split_ifs at * <;> tauto⟩⟩
protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by
rintro ⟨x, y, hxy, rfl⟩
exact isCycle_swap hxy
variable [Fintype α]
theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support :=
two_le_card_support_of_ne_one h.ne_one
/-- The subgroup generated by a cycle is in bijection with its support -/
noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) :
(Subgroup.zpowers σ) ≃ σ.support :=
Equiv.ofBijective
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
⟨(τ : Perm α) (Classical.choose hσ), by
obtain ⟨τ, n, rfl⟩ := τ
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
exact (Classical.choose_spec hσ).1⟩)
(by
constructor
· rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h
ext y
by_cases hy : σ y = y
· simp_rw [zpow_apply_eq_self_of_apply_eq_self hy]
· obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
exact congr_arg _ (Subtype.ext_iff.mp h)
· rintro ⟨y, hy⟩
rw [mem_support] at hy
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
@[simp]
theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} :
hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ =
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ :=
rfl
@[simp]
theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) :
hσ.zpowersEquivSupport.symm
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ =
⟨σ ^ n, n, rfl⟩ :=
(Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply
protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by
rw [← Fintype.card_zpowers, ← Fintype.card_coe]
convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf)
theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] :
∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
induction n with
| zero => exact fun _ h => ⟨0, h⟩
| succ n hn =>
intro b x f hb h
exact if hfbx : f x = b then ⟨0, hfbx⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ←
f.injective.eq_iff, apply_inv_self]
exact this.1
let ⟨i, hi⟩ := hn hb' (f.injective <| by
rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h)
⟨i + 1, by
rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩
theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] :
∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
cases n with
| ofNat n => exact isCycle_swap_mul_aux₁ n
| negSucc n =>
intro b x f hb h
exact if hfbx' : f x = b then ⟨0, hfbx'⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, swap_apply_def]
split_ifs <;>
simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at *
<;> tauto
let ⟨i, hi⟩ :=
isCycle_swap_mul_aux₁ n hb
(show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by
rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc,
← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_cancel, mul_one, zpow_natCast,
← pow_succ', ← pow_succ])
have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by
rw [mul_apply, inv_apply_self, swap_apply_left]
⟨-i, by
rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg,
← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x,
zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩
theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α}
(hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) :=
Equiv.ext fun y =>
let ⟨z, hz⟩ := hf
let ⟨i, hi⟩ := hz.2 hfx
if hyx : y = x then by simp [hyx]
else
if hfyx : y = f x then by simp [hfyx, hffx]
else by
rw [swap_apply_of_ne_of_ne hyx hfyx]
refine by_contradiction fun hy => ?_
obtain ⟨j, hj⟩ := hz.2 hy
rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj
rcases zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji | hji
· rw [← hj, hji] at hyx
tauto
· rw [← hj, hji] at hfyx
tauto
theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α}
(hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) :=
⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx],
fun y hy =>
let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1
have hi : (f ^ (i - 1)) (f x) = y :=
calc
(f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp
_ = y := by rwa [← zpow_add, sub_add_cancel]
isCycle_swap_mul_aux₂ (i - 1) hy hi⟩
theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ #f.support :=
let ⟨x, hx⟩ := hf
calc
Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by
{rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]}
_ = -(-1) ^ #f.support :=
if h1 : f (f x) = x then by
have h : swap x (f x) * f = 1 := by
simp only [mul_def, one_def]
rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap]
rw [sign_mul, sign_swap hx.1.symm, h, sign_one,
hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm]
rfl
else by
have h : #(swap x (f x) * f).support + 1 = #f.support := by
rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1,
card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase]
have : #(swap x (f x) * f).support < #f.support := card_support_swap_mul hx.1
rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h]
simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one]
termination_by #f.support
theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by
simp_rw [← mem_support, ← Finset.ext_iff]
exact (support_pow_le _ n).antisymm h2
obtain ⟨x, hx1, hx2⟩ := h1
refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩
obtain ⟨i, _⟩ := hx2 ((key y).mpr hy)
exact ⟨n * i, by rwa [zpow_mul]⟩
-- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to
-- `σ.support = (σ ^ n).support`, as well as to `#σ.support ≤ #(σ ^ n).support`.
theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
cases n
· exact h1.of_pow h2
· simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2
exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2
theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f)
(h2 : l.Pairwise Disjoint) : l.Nodup :=
nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2
/-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here
we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/
theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support)
(h' : ∀ x ∈ f.support, f x = g x) : f = g := by
have : f.support = g.support := by
refine le_antisymm h ?_
intro z hz
obtain ⟨x, hx, _⟩ := id hf
have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)]
obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz)
have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by
intro x hx
exact h' x (mem_of_mem_inter_left hx)
rwa [← hm, ←
pow_eq_on_of_mem_support h'' _ x
(mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')),
pow_apply_mem_support, mem_support]
refine Equiv.Perm.support_congr h ?_
simpa [← this] using h'
|
/-- If two cyclic permutations agree on all terms in their intersection,
and that intersection is not empty, then the two cyclic permutations must be equal. -/
theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g)
(h : ∀ x ∈ f.support ∩ g.support, f x = g x)
(hx : f x = g x) (hx' : x ∈ f.support) : f = g := by
have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support]
have : f.support ⊆ g.support := by
intro y hy
obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy)
rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support]
rw [inter_eq_left.mpr this] at h
| Mathlib/GroupTheory/Perm/Cycle/Basic.lean | 499 | 510 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Kim Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow' :
(kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by
rw [← kernelSubobject_arrow]
simp only [Category.assoc, kernel.condition, comp_zero]
theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
(kernelSubobject f).Factors h :=
⟨kernel.lift _ h w, by simp⟩
theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) :
(kernelSubobject f).Factors h ↔ h ≫ f = 0 :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp,
comp_zero],
kernelSubobject_factors f h⟩
/-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/
def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f :=
(kernelSubobject f).factorThru h (kernelSubobject_factors f h w)
@[simp]
theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by
dsimp [factorThruKernelSubobject]
simp
@[simp]
theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w :=
(cancel_mono (kernel.ι f)).1 <| by simp
section
variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f']
/-- A commuting square induces a morphism between the kernel subobjects. -/
def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobject f : C) ⟶ (kernelSubobject f' : C) :=
Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left)
(kernelSubobject_factors _ _ (by simp [sq.w]))
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by
simp [kernelSubobjectMap]
@[simp]
theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by aesop_cat
@[simp]
theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f'']
(sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') :
kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by
aesop_cat
@[reassoc]
theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv =
(kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by aesop_cat
@[reassoc]
theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm =
kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by
simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv]
end
@[simp]
theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ :=
(isIso_iff_mk_eq_top _).mp (by infer_instance)
instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow :=
(isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero
theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f :=
Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp)
/-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`,
when `f` is an isomorphism.
-/
def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobject (f ≫ g) : C) ≅ (kernelSubobject g : C) :=
kernelSubobjectIso _ ≪≫ kernelIsIsoComp f g ≪≫ (kernelSubobjectIso _).symm
@[simp]
theorem kernelSubobjectIsoComp_hom_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).hom ≫ (kernelSubobject g).arrow =
(kernelSubobject (f ≫ g)).arrow ≫ f := by
simp [kernelSubobjectIsoComp]
@[simp]
theorem kernelSubobjectIsoComp_inv_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).inv ≫ (kernelSubobject (f ≫ g)).arrow =
(kernelSubobject g).arrow ≫ inv f := by
simp [kernelSubobjectIsoComp]
/-- The kernel of `f` is always a smaller subobject than the kernel of `f ≫ h`. -/
theorem kernelSubobject_comp_le (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [HasKernel (f ≫ h)] :
kernelSubobject f ≤ kernelSubobject (f ≫ h) :=
le_kernelSubobject _ _ (by simp)
/-- Postcomposing by a monomorphism does not change the kernel subobject. -/
@[simp]
theorem kernelSubobject_comp_mono (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
kernelSubobject (f ≫ h) = kernelSubobject f :=
le_antisymm (le_kernelSubobject _ _ ((cancel_mono h).mp (by simp))) (kernelSubobject_comp_le f h)
instance kernelSubobject_comp_mono_isIso (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
IsIso (Subobject.ofLE _ _ (kernelSubobject_comp_le f h)) := by
rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv]
· infer_instance
· simp
/-- Taking cokernels is an order-reversing map from the subobjects of `X` to the quotient objects
of `X`. -/
@[simps]
def cokernelOrderHom [HasCokernels C] (X : C) : Subobject X →o (Subobject (op X))ᵒᵈ where
toFun :=
Subobject.lift (fun _ f _ => Subobject.mk (cokernel.π f).op)
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ (Iso.op ?_) (Quiver.Hom.unop_inj ?_)
· exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _)
(isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm
· simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op,
colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app,
coequalizer.cofork_π])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) ?_).op ?_
· rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero]
· exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _)
/-- Taking kernels is an order-reversing map from the quotient objects of `X` to the subobjects of
`X`. -/
@[simps]
def kernelOrderHom [HasKernels C] (X : C) : (Subobject (op X))ᵒᵈ →o Subobject X where
toFun :=
Subobject.lift (fun _ f _ => Subobject.mk (kernel.ι f.unop))
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ ?_ ?_
· exact
IsLimit.conePointUniqueUpToIso (limit.isLimit _)
(isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl)
· dsimp
simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp,
Fork.ofι_π_app])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) ?_) ?_
· rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp]
· exact Quiver.Hom.op_inj (by simp)
end Kernel
section Image
variable (f : X ⟶ Y) [HasImage f]
/-- The image of a morphism `f g : X ⟶ Y` as a `Subobject Y`. -/
abbrev imageSubobject : Subobject Y :=
Subobject.mk (image.ι f)
/-- The underlying object of `imageSubobject f` is (up to isomorphism!)
the same as the chosen object `image f`. -/
def imageSubobjectIso : (imageSubobject f : C) ≅ image f :=
Subobject.underlyingIso (image.ι f)
@[reassoc (attr := simp)]
theorem imageSubobject_arrow :
(imageSubobjectIso f).hom ≫ image.ι f = (imageSubobject f).arrow := by simp [imageSubobjectIso]
@[reassoc (attr := simp)]
theorem imageSubobject_arrow' :
(imageSubobjectIso f).inv ≫ (imageSubobject f).arrow = image.ι f := by simp [imageSubobjectIso]
/-- A factorisation of `f : X ⟶ Y` through `imageSubobject f`. -/
def factorThruImageSubobject : X ⟶ imageSubobject f :=
factorThruImage f ≫ (imageSubobjectIso f).inv
instance [HasEqualizers C] : Epi (factorThruImageSubobject f) := by
dsimp [factorThruImageSubobject]
apply epi_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem imageSubobject_arrow_comp : factorThruImageSubobject f ≫ (imageSubobject f).arrow = f := by
simp [factorThruImageSubobject, imageSubobject_arrow]
theorem imageSubobject_arrow_comp_eq_zero [HasZeroMorphisms C] {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
[HasImage f] [Epi (factorThruImageSubobject f)] (h : f ≫ g = 0) :
(imageSubobject f).arrow ≫ g = 0 :=
zero_of_epi_comp (factorThruImageSubobject f) <| by simp [h]
theorem imageSubobject_factors_comp_self {W : C} (k : W ⟶ X) : (imageSubobject f).Factors (k ≫ f) :=
⟨k ≫ factorThruImage f, by simp⟩
@[simp]
theorem factorThruImageSubobject_comp_self {W : C} (k : W ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ f) h = k ≫ factorThruImageSubobject f := by
ext
simp
@[simp]
theorem factorThruImageSubobject_comp_self_assoc {W W' : C} (k : W ⟶ W') (k' : W' ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ k' ≫ f) h = k ≫ k' ≫ factorThruImageSubobject f := by
ext
simp
/-- The image of `h ≫ f` is always a smaller subobject than the image of `f`. -/
theorem imageSubobject_comp_le {X' : C} (h : X' ⟶ X) (f : X ⟶ Y) [HasImage f] [HasImage (h ≫ f)] :
imageSubobject (h ≫ f) ≤ imageSubobject f :=
Subobject.mk_le_mk_of_comm (image.preComp h f) (by simp)
section
open ZeroObject
variable [HasZeroMorphisms C] [HasZeroObject C]
@[simp]
theorem imageSubobject_zero_arrow : (imageSubobject (0 : X ⟶ Y)).arrow = 0 := by
rw [← imageSubobject_arrow]
simp
@[simp]
theorem imageSubobject_zero {A B : C} : imageSubobject (0 : A ⟶ B) = ⊥ :=
| Subobject.eq_of_comm (imageSubobjectIso _ ≪≫ imageZero ≪≫ Subobject.botCoeIsoZero.symm) (by simp)
| Mathlib/CategoryTheory/Subobject/Limits.lean | 328 | 329 |
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Trifunctor
import Mathlib.CategoryTheory.Products.Basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensorObj : C → C → C`
* `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))`
and allow use of the overloaded notation `⊗` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`.
The unitors and associator are gathered together as natural
isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files after proving the coherence theorem,
e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`.
## Implementation notes
In the definition of monoidal categories, we also provide the whiskering operators:
* `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`,
* `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`.
These are products of an object and a morphism (the terminology "whiskering"
is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined
in terms of the whiskerings. There are two possible such definitions, which are related by
the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def`
and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds
definitionally.
If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it,
you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`.
The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories.
### Simp-normal form for morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal
form defined below. Rewriting into simp-normal form is especially useful in preprocessing
performed by the `coherence` tactic.
The simp-normal form of morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is
either a structural morphisms (morphisms made up only of identities, associators, unitors)
or non-structural morphisms, and
2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`,
where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural
morphisms that is not the identity or a composite.
Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`.
Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`,
respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* <https://stacks.math.columbia.edu/tag/0FFK>.
-/
universe v u
open CategoryTheory.Category
open CategoryTheory.Iso
namespace CategoryTheory
/-- Auxiliary structure to carry only the data fields of (and provide notation for)
`MonoidalCategory`. -/
class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where
/-- curried tensor product of objects -/
tensorObj : C → C → C
/-- left whiskering for morphisms -/
whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂
/-- right whiskering for morphisms -/
whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
-- By default, it is defined in terms of whiskerings.
tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) :=
whiskerRight f X₂ ≫ whiskerLeft Y₁ g
/-- The tensor unity in the monoidal structure `𝟙_ C` -/
tensorUnit (C) : C
/-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z)
/-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/
leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X
/-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/
rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X
namespace MonoidalCategory
export MonoidalCategoryStruct
(tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor)
end MonoidalCategory
namespace MonoidalCategory
/-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj
/-- Notation for the `whiskerLeft` operator of monoidal categories -/
scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft
/-- Notation for the `whiskerRight` operator of monoidal categories -/
scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight
/-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom
/-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/
scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
/-- The property that the pentagon relation is satisfied by four objects
in a category equipped with a `MonoidalCategoryStruct`. -/
def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C]
(Y₁ Y₂ Y₃ Y₄ : C) : Prop :=
(α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom =
(α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom
end MonoidalCategory
open MonoidalCategory
/--
In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`,
with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`.
These associators and unitors satisfy the pentagon and triangle equations. -/
@[stacks 0FFK]
-- Porting note: The Mathport did not translate the temporary notation
class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where
tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by
aesop_cat
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat
/--
Tensor product of compositions is composition of tensor products:
`(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)`
-/
tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by
aesop_cat
whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by
aesop_cat
id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by
aesop_cat
/-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/
associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by
aesop_cat
/--
Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y`
-/
leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by
aesop_cat
/--
Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y`
-/
rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by
aesop_cat
/--
The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W`
-/
pentagon :
∀ W X Y Z : C,
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by
aesop_cat
/--
The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y`
-/
triangle :
∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by
aesop_cat
attribute [reassoc] MonoidalCategory.tensorHom_def
attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id
attribute [reassoc, simp] MonoidalCategory.id_whiskerRight
attribute [reassoc] MonoidalCategory.tensor_comp
attribute [simp] MonoidalCategory.tensor_comp
attribute [reassoc] MonoidalCategory.associator_naturality
attribute [reassoc] MonoidalCategory.leftUnitor_naturality
attribute [reassoc] MonoidalCategory.rightUnitor_naturality
attribute [reassoc (attr := simp)] MonoidalCategory.pentagon
attribute [reassoc (attr := simp)] MonoidalCategory.triangle
namespace MonoidalCategory
variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C]
@[simp]
theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) :
𝟙 X ⊗ f = X ◁ f := by
simp [tensorHom_def]
@[simp]
theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
f ⊗ 𝟙 Y = f ▷ Y := by
simp [tensorHom_def]
@[reassoc, simp]
theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by
simp only [← id_tensorHom, ← tensor_comp, comp_id]
@[reassoc, simp]
theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) :
𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by
rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom]
@[reassoc, simp]
theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
(X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc, simp]
theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) :
(f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by
simp only [← tensorHom_id, ← tensor_comp, id_comp]
@[reassoc, simp]
theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) :
f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by
rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id]
@[reassoc, simp]
theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [associator_naturality]
simp [tensor_id]
@[reassoc, simp]
theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
(X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc]
theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) :
W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by
simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id]
@[reassoc]
theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ :=
whisker_exchange f g ▸ tensorHom_def f g
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) :
X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by
rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) :
f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by
rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) :
X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by
rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) :
f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by
rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by
rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) :
f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by
rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by
rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) :
inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by
rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight]
/-- The left whiskering of an isomorphism is an isomorphism. -/
@[simps]
def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where
hom := X ◁ f.hom
inv := X ◁ f.inv
instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) :=
(whiskerLeftIso X (asIso f)).isIso_hom
@[simp]
theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
inv (X ◁ f) = X ◁ inv f := by
aesop_cat
@[simp]
lemma whiskerLeftIso_refl (W X : C) :
whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) :=
Iso.ext (whiskerLeft_id W X)
@[simp]
lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) :
whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g :=
Iso.ext (whiskerLeft_comp W f.hom g.hom)
@[simp]
lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) :
(whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl
/-- The right whiskering of an isomorphism is an isomorphism. -/
@[simps!]
def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where
hom := f.hom ▷ Z
inv := f.inv ▷ Z
instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) :=
(whiskerRightIso (asIso f) Z).isIso_hom
@[simp]
theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] :
inv (f ▷ Z) = inv f ▷ Z := by
aesop_cat
@[simp]
lemma whiskerRightIso_refl (X W : C) :
whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) :=
Iso.ext (id_whiskerRight X W)
@[simp]
lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) :
whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W :=
Iso.ext (comp_whiskerRight f.hom g.hom W)
@[simp]
lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) :
(whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl
/-- The tensor product of two isomorphisms is an isomorphism. -/
@[simps]
def tensorIso {X Y X' Y' : C} (f : X ≅ Y)
(g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where
hom := f.hom ⊗ g.hom
inv := f.inv ⊗ g.inv
hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id]
inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id]
/-- Notation for `tensorIso`, the tensor product of isomorphisms -/
scoped infixr:70 " ⊗ " => tensorIso
theorem tensorIso_def {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') :
f ⊗ g = whiskerRightIso f X' ≪≫ whiskerLeftIso Y g :=
Iso.ext (tensorHom_def f.hom g.hom)
theorem tensorIso_def' {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') :
f ⊗ g = whiskerLeftIso X g ≪≫ whiskerRightIso f Y' :=
Iso.ext (tensorHom_def' f.hom g.hom)
instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) :=
(asIso f ⊗ asIso g).isIso_hom
@[simp]
theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] :
inv (f ⊗ g) = inv f ⊗ inv g := by
simp [tensorHom_def ,whisker_exchange]
variable {W X Y Z : C}
theorem whiskerLeft_dite {P : Prop} [Decidable P]
(X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) :
X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by
split_ifs <;> rfl
theorem dite_whiskerRight {P : Prop} [Decidable P]
{X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) :
(if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by
split_ifs <;> rfl
theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z))
(g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) =
if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl
theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z))
(g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f =
if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl
@[simp]
theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) :
X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by
cases f
simp only [whiskerLeft_id, eqToHom_refl]
@[simp]
theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) :
eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by
cases f
simp only [id_whiskerRight, eqToHom_refl]
@[reassoc]
theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp
@[reassoc]
theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp
@[reassoc]
theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp
@[reassoc]
theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
(X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp
@[reassoc]
theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp
@[reassoc]
theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp
@[reassoc]
theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
(X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp
@[reassoc]
theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp
@[reassoc]
theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp
@[reassoc]
theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) :
f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp
@[reassoc]
theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') :
f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by
simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc]
@[reassoc]
theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') :
f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp
@[reassoc]
theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) :
f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by
simp
theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp
theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp
/-! The lemmas in the next section are true by coherence,
but we prove them directly as they are used in proving the coherence theorem. -/
section
@[reassoc (attr := simp)]
theorem pentagon_inv :
W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z =
(α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_hom_inv :
(α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom =
W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by
rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv]
simp
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_inv :
(α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom =
(α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_inv :
W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv =
(α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by
simp [← cancel_epi (W ◁ (α_ X Y Z).inv)]
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_hom_hom :
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv =
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_hom :
(α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv =
(α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by
rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)]
simp
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_inv_hom :
(α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv =
(α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_hom :
(α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom =
(α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by
simp [← cancel_epi ((α_ W X Y).hom ▷ Z)]
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_inv_inv :
(α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z =
W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_right (X Y : C) :
(α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by
rw [← triangle, Iso.inv_hom_id_assoc]
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_right_inv (X Y : C) :
(ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by
simp [← cancel_mono (X ◁ (λ_ Y).hom)]
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_left_inv (X Y : C) :
(X ◁ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ▷ Y := by
simp [← cancel_mono ((ρ_ X).hom ▷ Y)]
/-- We state it as a simp lemma, which is regarded as an involved version of
`id_whiskerRight X Y : 𝟙 X ▷ Y = 𝟙 (X ⊗ Y)`.
-/
@[reassoc, simp]
theorem leftUnitor_whiskerRight (X Y : C) :
(λ_ X).hom ▷ Y = (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom := by
rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ←
cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ←
comp_whiskerRight_assoc, triangle, associator_naturality_left]
@[reassoc, simp]
theorem leftUnitor_inv_whiskerRight (X Y : C) :
(λ_ X).inv ▷ Y = (λ_ (X ⊗ Y)).inv ≫ (α_ (𝟙_ C) X Y).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc, simp]
theorem whiskerLeft_rightUnitor (X Y : C) :
X ◁ (ρ_ Y).hom = (α_ X Y (𝟙_ C)).inv ≫ (ρ_ (X ⊗ Y)).hom := by
rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ←
cancel_epi (X ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ←
associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right,
associator_inv_naturality_right]
@[reassoc, simp]
theorem whiskerLeft_rightUnitor_inv (X Y : C) :
X ◁ (ρ_ Y).inv = (ρ_ (X ⊗ Y)).inv ≫ (α_ X Y (𝟙_ C)).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc]
theorem leftUnitor_tensor (X Y : C) :
(λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ▷ Y := by simp
@[reassoc]
theorem leftUnitor_tensor_inv (X Y : C) :
(λ_ (X ⊗ Y)).inv = (λ_ X).inv ▷ Y ≫ (α_ (𝟙_ C) X Y).hom := by simp
@[reassoc]
theorem rightUnitor_tensor (X Y : C) :
(ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ X ◁ (ρ_ Y).hom := by simp
@[reassoc]
theorem rightUnitor_tensor_inv (X Y : C) :
(ρ_ (X ⊗ Y)).inv = X ◁ (ρ_ Y).inv ≫ (α_ X Y (𝟙_ C)).inv := by simp
end
@[reassoc]
theorem associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') :
(f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by
simp [tensorHom_def]
@[reassoc, simp]
theorem associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') :
(f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv := by
rw [associator_inv_naturality, hom_inv_id_assoc]
@[reassoc]
theorem associator_inv_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') :
f ⊗ g ⊗ h = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) ≫ (α_ X' Y' Z').hom := by
rw [associator_naturality, inv_hom_id_assoc]
-- TODO these next two lemmas aren't so fundamental, and perhaps could be removed
-- (replacing their usages by their proofs).
@[reassoc]
theorem id_tensor_associator_naturality {X Y Z Z' : C} (h : Z ⟶ Z') :
(𝟙 (X ⊗ Y) ⊗ h) ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ (𝟙 X ⊗ 𝟙 Y ⊗ h) := by
rw [← tensor_id, associator_naturality]
@[reassoc]
theorem id_tensor_associator_inv_naturality {X Y Z X' : C} (f : X ⟶ X') :
(f ⊗ 𝟙 (Y ⊗ Z)) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ ((f ⊗ 𝟙 Y) ⊗ 𝟙 Z) := by
rw [← tensor_id, associator_inv_naturality]
@[reassoc (attr := simp)]
theorem hom_inv_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) :
(f.hom ⊗ g) ≫ (f.inv ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by
rw [← tensor_comp, f.hom_inv_id]; simp [id_tensorHom]
@[reassoc (attr := simp)]
theorem inv_hom_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) :
(f.inv ⊗ g) ≫ (f.hom ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by
rw [← tensor_comp, f.inv_hom_id]; simp [id_tensorHom]
@[reassoc (attr := simp)]
theorem tensor_hom_inv_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) :
(g ⊗ f.hom) ≫ (h ⊗ f.inv) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by
rw [← tensor_comp, f.hom_inv_id]; simp [tensorHom_id]
@[reassoc (attr := simp)]
theorem tensor_inv_hom_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) :
(g ⊗ f.inv) ≫ (h ⊗ f.hom) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by
rw [← tensor_comp, f.inv_hom_id]; simp [tensorHom_id]
@[reassoc (attr := simp)]
theorem hom_inv_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) :
(f ⊗ g) ≫ (inv f ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by
rw [← tensor_comp, IsIso.hom_inv_id]; simp [id_tensorHom]
@[reassoc (attr := simp)]
theorem inv_hom_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) :
(inv f ⊗ g) ≫ (f ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by
rw [← tensor_comp, IsIso.inv_hom_id]; simp [id_tensorHom]
@[reassoc (attr := simp)]
theorem tensor_hom_inv_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) :
(g ⊗ f) ≫ (h ⊗ inv f) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by
rw [← tensor_comp, IsIso.hom_inv_id]; simp [tensorHom_id]
@[reassoc (attr := simp)]
theorem tensor_inv_hom_id' {V W X Y Z : C} (f : V ⟶ W) [IsIso f] (g : X ⟶ Y) (h : Y ⟶ Z) :
(g ⊗ inv f) ≫ (h ⊗ f) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by
rw [← tensor_comp, IsIso.inv_hom_id]; simp [tensorHom_id]
/--
A constructor for monoidal categories that requires `tensorHom` instead of `whiskerLeft` and
`whiskerRight`.
-/
abbrev ofTensorHom [MonoidalCategoryStruct C]
(tensor_id : ∀ X₁ X₂ : C, tensorHom (𝟙 X₁) (𝟙 X₂) = 𝟙 (tensorObj X₁ X₂) := by
aesop_cat)
(id_tensorHom : ∀ (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂), tensorHom (𝟙 X) f = whiskerLeft X f := by
aesop_cat)
(tensorHom_id : ∀ {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C), tensorHom f (𝟙 Y) = whiskerRight f Y := by
aesop_cat)
(tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
tensorHom (f₁ ≫ g₁) (f₂ ≫ g₂) = tensorHom f₁ f₂ ≫ tensorHom g₁ g₂ := by
aesop_cat)
(associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
tensorHom (tensorHom f₁ f₂) f₃ ≫ (associator Y₁ Y₂ Y₃).hom =
(associator X₁ X₂ X₃).hom ≫ tensorHom f₁ (tensorHom f₂ f₃) := by
aesop_cat)
(leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y),
tensorHom (𝟙 (𝟙_ C)) f ≫ (leftUnitor Y).hom = (leftUnitor X).hom ≫ f := by
aesop_cat)
(rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y),
tensorHom f (𝟙 (𝟙_ C)) ≫ (rightUnitor Y).hom = (rightUnitor X).hom ≫ f := by
aesop_cat)
(pentagon :
∀ W X Y Z : C,
tensorHom (associator W X Y).hom (𝟙 Z) ≫
(associator W (tensorObj X Y) Z).hom ≫ tensorHom (𝟙 W) (associator X Y Z).hom =
(associator (tensorObj W X) Y Z).hom ≫ (associator W X (tensorObj Y Z)).hom := by
aesop_cat)
(triangle :
∀ X Y : C,
(associator X (𝟙_ C) Y).hom ≫ tensorHom (𝟙 X) (leftUnitor Y).hom =
tensorHom (rightUnitor X).hom (𝟙 Y) := by
| aesop_cat) :
MonoidalCategory C where
tensorHom_def := by intros; simp [← id_tensorHom, ← tensorHom_id, ← tensor_comp]
| Mathlib/CategoryTheory/Monoidal/Category.lean | 720 | 722 |
/-
Copyright (c) 2019 Minchao Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Minchao Wu, Mario Carneiro
-/
import Mathlib.Computability.Halting
/-!
# Strong reducibility and degrees.
This file defines the notions of computable many-one reduction and one-one
reduction between sets, and shows that the corresponding degrees form a
semilattice.
## Notations
This file uses the local notation `⊕'` for `Sum.elim` to denote the disjoint union of two degrees.
## References
* [Robert Soare, *Recursively enumerable sets and degrees*][soare1987]
## Tags
computability, reducibility, reduction
-/
universe u v w
open Function
/--
`p` is many-one reducible to `q` if there is a computable function translating questions about `p`
to questions about `q`.
-/
def ManyOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) :=
∃ f, Computable f ∧ ∀ a, p a ↔ q (f a)
@[inherit_doc ManyOneReducible]
infixl:1000 " ≤₀ " => ManyOneReducible
theorem ManyOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop)
(h : Computable f) : (fun a => q (f a)) ≤₀ q :=
⟨f, h, fun _ => Iff.rfl⟩
@[refl]
theorem manyOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₀ p :=
⟨id, Computable.id, by simp⟩
@[trans]
theorem ManyOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ q → q ≤₀ r → p ≤₀ r
| ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ =>
⟨g ∘ f, c₂.comp c₁,
fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩
theorem reflexive_manyOneReducible {α} [Primcodable α] : Reflexive (@ManyOneReducible α α _ _) :=
manyOneReducible_refl
theorem transitive_manyOneReducible {α} [Primcodable α] : Transitive (@ManyOneReducible α α _ _) :=
fun _ _ _ => ManyOneReducible.trans
/--
`p` is one-one reducible to `q` if there is an injective computable function translating questions
about `p` to questions about `q`.
-/
def OneOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) :=
∃ f, Computable f ∧ Injective f ∧ ∀ a, p a ↔ q (f a)
@[inherit_doc OneOneReducible]
infixl:1000 " ≤₁ " => OneOneReducible
theorem OneOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop)
(h : Computable f) (i : Injective f) : (fun a => q (f a)) ≤₁ q :=
⟨f, h, i, fun _ => Iff.rfl⟩
@[refl]
theorem oneOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₁ p :=
⟨id, Computable.id, injective_id, by simp⟩
@[trans]
theorem OneOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop}
{q : β → Prop} {r : γ → Prop} : p ≤₁ q → q ≤₁ r → p ≤₁ r
| ⟨f, c₁, i₁, h₁⟩, ⟨g, c₂, i₂, h₂⟩ =>
⟨g ∘ f, c₂.comp c₁, i₂.comp i₁, fun a =>
⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩
theorem OneOneReducible.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop}
{q : β → Prop} : p ≤₁ q → p ≤₀ q
| ⟨f, c, _, h⟩ => ⟨f, c, h⟩
theorem OneOneReducible.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop)
(h : Computable e) : (q ∘ e) ≤₁ q :=
OneOneReducible.mk _ h e.injective
theorem OneOneReducible.of_equiv_symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β}
(q : β → Prop) (h : Computable e.symm) : q ≤₁ (q ∘ e) := by
convert OneOneReducible.of_equiv _ h; funext; simp
theorem reflexive_oneOneReducible {α} [Primcodable α] : Reflexive (@OneOneReducible α α _ _) :=
oneOneReducible_refl
theorem transitive_oneOneReducible {α} [Primcodable α] : Transitive (@OneOneReducible α α _ _) :=
fun _ _ _ => OneOneReducible.trans
namespace ComputablePred
variable {α : Type*} {β : Type*} [Primcodable α] [Primcodable β]
open Computable
theorem computable_of_manyOneReducible {p : α → Prop} {q : β → Prop} (h₁ : p ≤₀ q)
(h₂ : ComputablePred q) : ComputablePred p := by
rcases h₁ with ⟨f, c, hf⟩
rw [show p = fun a => q (f a) from Set.ext hf]
rcases computable_iff.1 h₂ with ⟨g, hg, rfl⟩
exact ⟨by infer_instance, by simpa using hg.comp c⟩
theorem computable_of_oneOneReducible {p : α → Prop} {q : β → Prop} (h : p ≤₁ q) :
ComputablePred q → ComputablePred p :=
computable_of_manyOneReducible h.to_many_one
end ComputablePred
/-- `p` and `q` are many-one equivalent if each one is many-one reducible to the other. -/
def ManyOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) :=
p ≤₀ q ∧ q ≤₀ p
/-- `p` and `q` are one-one equivalent if each one is one-one reducible to the other. -/
def OneOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) :=
p ≤₁ q ∧ q ≤₁ p
@[refl]
theorem manyOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : ManyOneEquiv p p :=
⟨manyOneReducible_refl _, manyOneReducible_refl _⟩
@[symm]
theorem ManyOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} :
ManyOneEquiv p q → ManyOneEquiv q p :=
And.symm
@[trans]
theorem ManyOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop}
{q : β → Prop} {r : γ → Prop} : ManyOneEquiv p q → ManyOneEquiv q r → ManyOneEquiv p r
| ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩
theorem equivalence_of_manyOneEquiv {α} [Primcodable α] : Equivalence (@ManyOneEquiv α α _ _) :=
⟨manyOneEquiv_refl, fun {_ _} => ManyOneEquiv.symm, fun {_ _ _} => ManyOneEquiv.trans⟩
@[refl]
theorem oneOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : OneOneEquiv p p :=
⟨oneOneReducible_refl _, oneOneReducible_refl _⟩
@[symm]
theorem OneOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} :
OneOneEquiv p q → OneOneEquiv q p :=
And.symm
@[trans]
theorem OneOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop}
{q : β → Prop} {r : γ → Prop} : OneOneEquiv p q → OneOneEquiv q r → OneOneEquiv p r
| ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩
theorem equivalence_of_oneOneEquiv {α} [Primcodable α] : Equivalence (@OneOneEquiv α α _ _) :=
⟨oneOneEquiv_refl, fun {_ _} => OneOneEquiv.symm, fun {_ _ _} => OneOneEquiv.trans⟩
theorem OneOneEquiv.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop}
{q : β → Prop} : OneOneEquiv p q → ManyOneEquiv p q
| ⟨pq, qp⟩ => ⟨pq.to_many_one, qp.to_many_one⟩
/-- a computable bijection -/
nonrec def Equiv.Computable {α β} [Primcodable α] [Primcodable β] (e : α ≃ β) :=
Computable e ∧ Computable e.symm
theorem Equiv.Computable.symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} :
e.Computable → e.symm.Computable :=
And.symm
theorem Equiv.Computable.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {e₁ : α ≃ β}
{e₂ : β ≃ γ} : e₁.Computable → e₂.Computable → (e₁.trans e₂).Computable
| ⟨l₁, r₁⟩, ⟨l₂, r₂⟩ => ⟨l₂.comp l₁, r₁.comp r₂⟩
theorem Computable.eqv (α) [Denumerable α] : (Denumerable.eqv α).Computable :=
⟨Computable.encode, Computable.ofNat _⟩
theorem Computable.equiv₂ (α β) [Denumerable α] [Denumerable β] :
(Denumerable.equiv₂ α β).Computable :=
(Computable.eqv _).trans (Computable.eqv _).symm
theorem OneOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable)
{p} : OneOneEquiv (p ∘ e) p :=
⟨OneOneReducible.of_equiv _ h.1, OneOneReducible.of_equiv_symm _ h.2⟩
theorem ManyOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable)
{p} : ManyOneEquiv (p ∘ e) p :=
(OneOneEquiv.of_equiv h).to_many_one
theorem ManyOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : p ≤₀ r ↔ q ≤₀ r :=
⟨h.2.trans, h.1.trans⟩
theorem ManyOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : p ≤₀ q ↔ p ≤₀ r :=
⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩
theorem OneOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : p ≤₁ r ↔ q ≤₁ r :=
⟨h.2.trans, h.1.trans⟩
theorem OneOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : p ≤₁ q ↔ p ≤₁ r :=
⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩
theorem ManyOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) :
ManyOneEquiv p r ↔ ManyOneEquiv q r :=
and_congr h.le_congr_left h.le_congr_right
theorem ManyOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) :
ManyOneEquiv p q ↔ ManyOneEquiv p r :=
and_congr h.le_congr_right h.le_congr_left
theorem OneOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) :
OneOneEquiv p r ↔ OneOneEquiv q r :=
and_congr h.le_congr_left h.le_congr_right
theorem OneOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) :
OneOneEquiv p q ↔ OneOneEquiv p r :=
and_congr h.le_congr_right h.le_congr_left
@[simp]
theorem ULower.down_computable {α} [Primcodable α] : (ULower.equiv α).Computable :=
⟨Primrec.ulower_down.to_comp, Primrec.ulower_up.to_comp⟩
theorem manyOneEquiv_up {α} [Primcodable α] {p : α → Prop} : ManyOneEquiv (p ∘ ULower.up) p :=
ManyOneEquiv.of_equiv ULower.down_computable.symm
local infixl:1001 " ⊕' " => Sum.elim
open Nat.Primrec
theorem OneOneReducible.disjoin_left {α β} [Primcodable α] [Primcodable β] {p : α → Prop}
{q : β → Prop} : p ≤₁ p ⊕' q :=
⟨Sum.inl, Computable.sumInl, fun _ _ => Sum.inl.inj_iff.1, fun _ => Iff.rfl⟩
theorem OneOneReducible.disjoin_right {α β} [Primcodable α] [Primcodable β] {p : α → Prop}
{q : β → Prop} : q ≤₁ p ⊕' q :=
⟨Sum.inr, Computable.sumInr, fun _ _ => Sum.inr.inj_iff.1, fun _ => Iff.rfl⟩
theorem disjoin_manyOneReducible {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ]
{p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ r → q ≤₀ r → (p ⊕' q) ≤₀ r
| ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ =>
⟨Sum.elim f g,
Computable.id.sumCasesOn (c₁.comp Computable.snd).to₂ (c₂.comp Computable.snd).to₂,
fun x => by cases x <;> [apply h₁; apply h₂]⟩
theorem disjoin_le {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop}
{q : β → Prop} {r : γ → Prop} : (p ⊕' q) ≤₀ r ↔ p ≤₀ r ∧ q ≤₀ r :=
⟨fun h =>
⟨OneOneReducible.disjoin_left.to_many_one.trans h,
OneOneReducible.disjoin_right.to_many_one.trans h⟩,
fun ⟨h₁, h₂⟩ => disjoin_manyOneReducible h₁ h₂⟩
variable {α : Type u} [Primcodable α] [Inhabited α] {β : Type v} [Primcodable β] [Inhabited β]
/-- Computable and injective mapping of predicates to sets of natural numbers.
-/
def toNat (p : Set α) : Set ℕ :=
{ n | p ((Encodable.decode (α := α) n).getD default) }
@[simp]
theorem toNat_manyOneReducible {p : Set α} : toNat p ≤₀ p :=
⟨fun n => (Encodable.decode (α := α) n).getD default,
Computable.option_getD Computable.decode (Computable.const _), fun _ => Iff.rfl⟩
@[simp]
theorem manyOneReducible_toNat {p : Set α} : p ≤₀ toNat p :=
⟨Encodable.encode, Computable.encode, by simp [toNat, setOf]⟩
@[simp]
theorem manyOneReducible_toNat_toNat {p : Set α} {q : Set β} : toNat p ≤₀ toNat q ↔ p ≤₀ q :=
⟨fun h => manyOneReducible_toNat.trans (h.trans toNat_manyOneReducible), fun h =>
toNat_manyOneReducible.trans (h.trans manyOneReducible_toNat)⟩
@[simp]
theorem toNat_manyOneEquiv {p : Set α} : ManyOneEquiv (toNat p) p := by simp [ManyOneEquiv]
@[simp]
theorem manyOneEquiv_toNat (p : Set α) (q : Set β) :
ManyOneEquiv (toNat p) (toNat q) ↔ ManyOneEquiv p q := by simp [ManyOneEquiv]
/-- A many-one degree is an equivalence class of sets up to many-one equivalence. -/
def ManyOneDegree : Type :=
Quotient (⟨ManyOneEquiv, equivalence_of_manyOneEquiv⟩ : Setoid (Set ℕ))
namespace ManyOneDegree
/-- The many-one degree of a set on a primcodable type. -/
def of (p : α → Prop) : ManyOneDegree :=
Quotient.mk'' (toNat p)
@[elab_as_elim]
protected theorem ind_on {C : ManyOneDegree → Prop} (d : ManyOneDegree)
(h : ∀ p : Set ℕ, C (of p)) : C d :=
Quotient.inductionOn' d h
/-- Lifts a function on sets of natural numbers to many-one degrees. -/
protected abbrev liftOn {φ} (d : ManyOneDegree) (f : Set ℕ → φ)
(h : ∀ p q, ManyOneEquiv p q → f p = f q) : φ :=
Quotient.liftOn' d f h
@[simp]
protected theorem liftOn_eq {φ} (p : Set ℕ) (f : Set ℕ → φ)
(h : ∀ p q, ManyOneEquiv p q → f p = f q) : (of p).liftOn f h = f p :=
rfl
/-- Lifts a binary function on sets of natural numbers to many-one degrees. -/
@[reducible, simp]
protected def liftOn₂ {φ} (d₁ d₂ : ManyOneDegree) (f : Set ℕ → Set ℕ → φ)
(h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) : φ :=
d₁.liftOn (fun p => d₂.liftOn (f p) fun _ _ hq => h _ _ _ _ (by rfl) hq)
(by
intro p₁ p₂ hp
induction d₂ using ManyOneDegree.ind_on
apply h
· assumption
· rfl)
@[simp]
protected theorem liftOn₂_eq {φ} (p q : Set ℕ) (f : Set ℕ → Set ℕ → φ)
(h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) :
(of p).liftOn₂ (of q) f h = f p q :=
rfl
@[simp]
theorem of_eq_of {p : α → Prop} {q : β → Prop} : of p = of q ↔ ManyOneEquiv p q := by
rw [of, of, Quotient.eq'']
simp
instance instInhabited : Inhabited ManyOneDegree :=
⟨of (∅ : Set ℕ)⟩
/-- For many-one degrees `d₁` and `d₂`, `d₁ ≤ d₂` if the sets in `d₁` are many-one reducible to the
| sets in `d₂`.
| Mathlib/Computability/Reduce.lean | 348 | 348 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by
classical
exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor.
TODO: deprecate this in favor of `Order.IsSuccLimit`. -/
def IsLimit (o : Ordinal) : Prop :=
IsSuccLimit o
theorem isLimit_iff {o} : IsLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by
simp [IsLimit, IsSuccLimit]
theorem IsLimit.isSuccPrelimit {o} (h : IsLimit o) : IsSuccPrelimit o :=
IsSuccLimit.isSuccPrelimit h
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
IsSuccLimit.succ_lt h
theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot
theorem not_zero_isLimit : ¬IsLimit 0 :=
not_isSuccLimit_bot
theorem not_succ_isLimit (o) : ¬IsLimit (succ o) :=
not_isSuccLimit_succ o
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
IsSuccLimit.succ_lt_iff h
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
@[simp]
theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o :=
liftInitialSeg.isSuccLimit_apply_iff
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
IsSuccLimit.bot_lt h
theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 :=
h.pos.ne'
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.succ_lt h.pos
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.succ_lt (IsLimit.nat_lt h n)
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by
simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o
theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) :
IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h
-- TODO: this is an iff with `IsSuccPrelimit`
theorem IsLimit.sSup_Iio {o : Ordinal} (h : IsLimit o) : sSup (Iio o) = o := by
apply (csSup_le' (fun a ha ↦ le_of_lt ha)).antisymm
apply le_of_forall_lt
intro a ha
exact (lt_succ a).trans_le (le_csSup bddAbove_Iio (h.succ_lt ha))
theorem IsLimit.iSup_Iio {o : Ordinal} (h : IsLimit o) : ⨆ a : Iio o, a.1 = o := by
rw [← sSup_eq_iSup', h.sSup_Iio]
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal)
(zero : motive 0) (succ : ∀ o, motive o → motive (succ o))
(isLimit : ∀ o, IsLimit o → (∀ o' < o, motive o') → motive o) : motive o := by
refine SuccOrder.limitRecOn o (fun a ha ↦ ?_) (fun a _ ↦ succ a) isLimit
convert zero
simpa using ha
@[simp]
theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ :=
SuccOrder.limitRecOn_isMin _ _ _ isMin_bot
@[simp]
theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) :
@limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) :=
SuccOrder.limitRecOn_succ ..
@[simp]
theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) :
@limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ :=
SuccOrder.limitRecOn_of_isSuccLimit ..
/-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l`
added to all cases. The final term's domain is the ordinals below `l`. -/
@[elab_as_elim]
def boundedLimitRecOn {l : Ordinal} (lLim : l.IsLimit) {motive : Iio l → Sort*} (o : Iio l)
(zero : motive ⟨0, lLim.pos⟩)
(succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩)
(isLimit : (o : Iio l) → IsLimit o → (Π o' < o, motive o') → motive o) : motive o :=
limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero)
(fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h)
(fun _o ho ih _ ↦ isLimit _ ho fun _o' h ↦ ih _ h _) o.2
@[simp]
theorem boundedLimitRec_zero {l} (lLim : l.IsLimit) {motive} (H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨0, lLim.pos⟩ H₁ H₂ H₃ = H₁ := by
rw [boundedLimitRecOn, limitRecOn_zero]
@[simp]
theorem boundedLimitRec_succ {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o
(@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_succ]
rfl
theorem boundedLimitRec_limit {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃ oLim) :
@boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦
@boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_limit]
rfl
instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
theorem enum_succ_eq_top {o : Ordinal} :
enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ :=
rfl
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩
convert enum_lt_enum.mpr _
· rw [enum_typein]
· rw [Subtype.mk_lt_mk, lt_succ_iff]
theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType :=
⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r, Subtype.mk_lt_mk]
apply lt_succ
@[simp]
theorem typein_ordinal (o : Ordinal.{u}) :
@typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm
theorem mk_Iio_ordinal (o : Ordinal.{u}) :
#(Iio o) = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← typein_ordinal]
rfl
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.succ_lt h))
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f :=
H.strictMono.id_le
theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a :=
H.strictMono.le_apply
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
H.le_apply.le_iff_eq
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
induction b using limitRecOn with
| zero =>
obtain ⟨x, px⟩ := p0
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| succ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| isLimit S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (ho : IsLimit o) : IsLimit (f o) := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
use (H.lt_iff.2 ho.pos).ne_bot
intro a ha
obtain ⟨b, hb, hab⟩ := (H.limit_lt ho).1 ha
rw [← succ_le_iff] at hab
apply hab.trans_lt
rwa [H.lt_iff]
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) :
a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h _ l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ ⟨_, l⟩) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; rcases enum _ ⟨_, l⟩ with x | x <;> intro this
· cases this (enum s ⟨0, h.pos⟩)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
theorem isLimit_add (a) {b} : IsLimit b → IsLimit (a + b) :=
(isNormal_add_right a).isLimit
alias IsLimit.add := isLimit_add
/-! ### Subtraction on ordinals -/
/-- The set in the definition of subtraction is nonempty. -/
private theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by
simpa using Ordinal.sub_eq_zero_iff_le.not
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by
rw [← add_le_add_iff_left b]
exact h.trans (le_add_sub a b)
theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by
obtain hab | hba := lt_or_le a b
· rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le]
· rwa [sub_lt_of_le hba]
theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by
use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩
rintro ⟨d, hd, ha⟩
exact ha.trans_lt (add_lt_add_left hd b)
theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by
simpa using (lt_add_iff hb).not
@[deprecated add_le_iff (since := "2024-12-08")]
theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) :
a + b ≤ c :=
(add_le_iff hb.ne').2 h
theorem isLimit_sub {a b} (ha : IsLimit a) (h : b < a) : IsLimit (a - b) := by
rw [isLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt]
refine ⟨h, fun c hc ↦ ?_⟩
rw [lt_sub] at hc ⊢
rw [add_succ]
exact ha.succ_lt hc
/-! ### Multiplication of ordinals -/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, _⟩ ⟨β, s, _⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨_, _, _⟩ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or]
simp only [eq_self_iff_true, true_and]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false, or_false]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr,
sumProdDistrib_apply_left, sumProdDistrib_apply_right, reduceCtorEq] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or, false_and, false_or]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
instance mulLeftMono : MulLeftMono Ordinal.{u} :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
instance mulRightMono : MulRightMono Ordinal.{u} :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ ⟨_, l⟩) by
obtain ⟨b, a⟩ := enum _ ⟨_, l⟩
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
obtain ⟨-, -, h⟩ | ⟨-, h⟩ := h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
obtain ⟨-, -, h⟩ | ⟨e, h⟩ := h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and, false_or,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and] at h ⊢
obtain ⟨-, -, h₂_h⟩ | e₂ := h₂ <;> [exact asymm h h₂_h; exact e₂ rfl]
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h _ l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
theorem isNormal_mul_right {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun _ l _ => mul_le_of_limit l⟩
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(isNormal_mul_right a0).lt_iff
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(isNormal_mul_right a0).le_iff
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(isNormal_mul_right a0).inj
theorem isLimit_mul {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(isNormal_mul_right a0).isLimit
theorem isLimit_mul_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact isLimit_add _ l
· exact isLimit_mul l.pos lb
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
private theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c)
(IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c :=
le_antisymm
((mul_le_of_limit l).2 fun c' h => by
apply (mul_le_mul_left' (le_succ c') _).trans
rw [IH _ h]
apply (add_le_add_left _ _).trans
· rw [← mul_succ]
exact mul_le_mul_left' (succ_le_of_lt <| l.succ_lt h) _
· rw [← ba]
exact le_add_right _ _)
(mul_le_mul_right' (le_add_right _ _) _)
theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by
induction c using limitRecOn with
| zero => simp only [succ_zero, mul_one]
| succ c IH =>
rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ]
| isLimit c l IH =>
rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc]
theorem add_mul_limit {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) : (a + b) * c = a * c :=
add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
private theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
private theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| zero => simp only [mul_zero, Ordinal.zero_le]
| succ _ _ => rw [succ_le_iff, lt_div c0]
| isLimit _ h₁ h₂ =>
revert h₁ h₂
simp +contextual only [mul_le_of_limit, limit_le, forall_true_iff]
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
theorem div_le_left {a b : Ordinal} (h : a ≤ b) (c : Ordinal) : a / c ≤ b / c := by
obtain rfl | hc := eq_or_ne c 0
· rw [div_zero, div_zero]
· rw [le_div hc]
exact (mul_div_le a c).trans h
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
theorem mul_add_div_mul {a c : Ordinal} (hc : c < a) (b d : Ordinal) :
(a * b + c) / (a * d) = b / d := by
have ha : a ≠ 0 := ((Ordinal.zero_le c).trans_lt hc).ne'
obtain rfl | hd := eq_or_ne d 0
· rw [mul_zero, div_zero, div_zero]
· have H := mul_ne_zero ha hd
apply le_antisymm
· rw [← lt_succ_iff, div_lt H, mul_assoc]
· apply (add_lt_add_left hc _).trans_le
rw [← mul_succ]
apply mul_le_mul_left'
rw [succ_le_iff]
exact lt_mul_succ_div b hd
· rw [le_div H, mul_assoc]
exact (mul_le_mul_left' (mul_div_le b d) a).trans (le_add_right _ c)
theorem mul_div_mul_cancel {a : Ordinal} (ha : a ≠ 0) (b c) : a * b / (a * c) = b / c := by
convert mul_add_div_mul (Ordinal.pos_iff_ne_zero.2 ha) b c using 1
rw [add_zero]
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply isLimit_sub h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact isLimit_add a h
· simpa only [add_zero]
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
theorem mul_add_mod_mul {w x : Ordinal} (hw : w < x) (y z : Ordinal) :
(x * y + w) % (x * z) = x * (y % z) + w := by
rw [mod_def, mul_add_div_mul hw]
apply sub_eq_of_add_eq
rw [← add_assoc, mul_assoc, ← mul_add, div_add_mod]
theorem mul_mod_mul (x y z : Ordinal) : (x * y) % (x * z) = x * (y % z) := by
obtain rfl | hx := Ordinal.eq_zero_or_pos x
· simp
· convert mul_add_mod_mul hx y z using 1 <;>
rw [add_zero]
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
/-! ### Casting naturals into ordinals, compatibility with operations -/
instance instCharZero : CharZero Ordinal := by
refine ⟨fun a b h ↦ ?_⟩
rwa [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_inj, Nat.cast_inj] at h
@[simp]
theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by
rw [← Nat.cast_one, ← Nat.cast_add, add_comm]
rfl
@[simp]
theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] :
1 + (ofNat(m) : Ordinal) = Order.succ (OfNat.ofNat m : Ordinal) :=
one_add_natCast m
@[simp, norm_cast]
theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n
| 0 => by simp
| n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one]
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by
rcases le_total m n with h | h
· rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (Nat.cast_le.2 h), Nat.cast_zero]
· rw [← add_left_cancel_iff (a := ↑n), ← Nat.cast_add, add_tsub_cancel_of_le h,
Ordinal.add_sub_cancel_of_le (Nat.cast_le.2 h)]
@[simp, norm_cast]
theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· have hn' : (n : Ordinal) ≠ 0 := Nat.cast_ne_zero.2 hn
apply le_antisymm
· rw [le_div hn', ← natCast_mul, Nat.cast_le, mul_comm]
apply Nat.div_mul_le_self
· rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, Nat.cast_lt, mul_comm,
← Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)]
apply Nat.lt_succ_self
@[simp, norm_cast]
theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by
rw [← add_left_cancel_iff, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add,
Nat.div_add_mod]
@[simp]
theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n
| 0 => by simp
| n + 1 => by simp [lift_natCast n]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u, v} ofNat(n) = OfNat.ofNat n :=
lift_natCast n
theorem lt_omega0 {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by
simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat]
theorem nat_lt_omega0 (n : ℕ) : ↑n < ω :=
lt_omega0.2 ⟨_, rfl⟩
theorem eq_nat_or_omega0_le (o : Ordinal) : (∃ n : ℕ, o = n) ∨ ω ≤ o := by
obtain ho | ho := lt_or_le o ω
· exact Or.inl <| lt_omega0.1 ho
· exact Or.inr ho
theorem omega0_pos : 0 < ω :=
nat_lt_omega0 0
theorem omega0_ne_zero : ω ≠ 0 :=
omega0_pos.ne'
theorem one_lt_omega0 : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega0 1
theorem isLimit_omega0 : IsLimit ω := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
refine ⟨omega0_ne_zero, fun o h => ?_⟩
obtain ⟨n, rfl⟩ := lt_omega0.1 h
exact nat_lt_omega0 (n + 1)
theorem omega0_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o :=
⟨fun h n => (nat_lt_omega0 _).le.trans h, fun H =>
le_of_forall_lt fun a h => by
let ⟨n, e⟩ := lt_omega0.1 h
rw [e, ← succ_le_iff]; exact H (n + 1)⟩
theorem nat_lt_limit {o} (h : IsLimit o) : ∀ n : ℕ, ↑n < o
| 0 => h.pos
| n + 1 => h.succ_lt (nat_lt_limit h n)
theorem omega0_le_of_isLimit {o} (h : IsLimit o) : ω ≤ o :=
omega0_le.2 fun n => le_of_lt <| nat_lt_limit h n
theorem natCast_add_omega0 (n : ℕ) : n + ω = ω := by
refine le_antisymm (le_of_forall_lt fun a ha ↦ ?_) (le_add_left _ _)
obtain ⟨b, hb', hb⟩ := (lt_add_iff omega0_ne_zero).1 ha
obtain ⟨m, rfl⟩ := lt_omega0.1 hb'
apply hb.trans_lt
exact_mod_cast nat_lt_omega0 (n + m)
theorem one_add_omega0 : 1 + ω = ω :=
mod_cast natCast_add_omega0 1
theorem add_omega0 {a : Ordinal} (h : a < ω) : a + ω = ω := by
obtain ⟨n, rfl⟩ := lt_omega0.1 h
exact natCast_add_omega0 n
@[simp]
theorem natCast_add_of_omega0_le {o} (h : ω ≤ o) (n : ℕ) : n + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, natCast_add_omega0]
@[simp]
theorem one_add_of_omega0_le {o} (h : ω ≤ o) : 1 + o = o :=
mod_cast natCast_add_of_omega0_le h 1
open Ordinal
theorem isLimit_iff_omega0_dvd {a : Ordinal} : IsLimit a ↔ a ≠ 0 ∧ ω ∣ a := by
refine ⟨fun l => ⟨l.ne_zero, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩
· refine (limit_le l).2 fun x hx => le_of_lt ?_
rw [← div_lt omega0_ne_zero, ← succ_le_iff, le_div omega0_ne_zero, mul_succ,
add_le_of_limit isLimit_omega0]
intro b hb
rcases lt_omega0.1 hb with ⟨n, rfl⟩
exact
(add_le_add_right (mul_div_le _ _) _).trans
(lt_sub.1 <| nat_lt_limit (isLimit_sub l hx) _).le
· rcases h with ⟨a0, b, rfl⟩
refine isLimit_mul_left isLimit_omega0 (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0)
intro e
simp only [e, mul_zero]
@[simp]
theorem natCast_mod_omega0 (n : ℕ) : n % ω = n :=
mod_eq_of_lt (nat_lt_omega0 n)
end Ordinal
namespace Cardinal
open Ordinal
@[simp]
theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by
rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega0_le]
rwa [← ord_aleph0, ord_le_ord]
theorem isLimit_ord {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact Ordinal.isLimit_omega0
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.toType :=
toType_noMax_of_succ_lt fun _ ↦ (isLimit_ord h).succ_lt
end Cardinal
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 1,424 | 1,428 | |
/-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.Data.Matrix.Kronecker
import Mathlib.LinearAlgebra.FiniteDimensional.Basic
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.Matrix.SemiringInverse
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.LinearAlgebra.Matrix.Trace
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible determinant.
For matrices that are not square or not of full rank, there is a more general notion of
pseudoinverses which we do not consider here.
The definition of inverse used in this file is the adjugate divided by the determinant.
We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`),
will result in a multiplicative inverse to `A`.
Note that there are at least three different inverses in mathlib:
* `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in
conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no
inverse exists.
* `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an
inverse exists.
* `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is
defined to be zero when no inverse exists.
We start by working with `Invertible`, and show the main results:
* `Matrix.invertibleOfDetInvertible`
* `Matrix.detInvertibleOfInvertible`
* `Matrix.isUnit_iff_isUnit_det`
* `Matrix.mul_eq_one_comm`
After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`.
The rest of the results in the file are then about `A⁻¹`
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u u' v
variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v}
open Matrix Equiv Equiv.Perm Finset
/-! ### Matrices are `Invertible` iff their determinants are -/
section Invertible
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
/-- If `A.det` has a constructive inverse, produce one for `A`. -/
def invertibleOfDetInvertible [Invertible A.det] : Invertible A where
invOf := ⅟ A.det • A.adjugate
mul_invOf_self := by
rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul]
invOf_mul_self := by
rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul]
theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by
letI := invertibleOfDetInvertible A
convert (rfl : ⅟ A = _)
/-- `A.det` is invertible if `A` has a left inverse. -/
def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one]
invOf_mul_self := by rw [← det_mul, h, det_one]
/-- `A.det` is invertible if `A` has a right inverse. -/
def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [← det_mul, h, det_one]
invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one]
/-- If `A` has a constructive inverse, produce one for `A.det`. -/
def detInvertibleOfInvertible [Invertible A] : Invertible A.det :=
detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _)
theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by
letI := detInvertibleOfInvertible A
convert (rfl : _ = ⅟ A.det)
/-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an
equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where
toFun := @detInvertibleOfInvertible _ _ _ _ _ A
invFun := @invertibleOfDetInvertible _ _ _ _ _ A
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ` -/
def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ A (invertibleOfDetInvertible A)
/-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/
theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by
simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr]
@[simp]
theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det :=
isUnit_iff_isUnit_det _ |>.mp A.isUnit
/-! #### Variants of the statements above with `IsUnit` -/
theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A)
variable {A B}
theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h)
theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h)
theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 :=
(isUnit_det_of_left_inverse h).ne_zero
theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 :=
(isUnit_det_of_right_inverse h).ne_zero
end Invertible
section Inv
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by
rw [det_transpose]
exact h
/-! ### A noncomputable `Inv` instance -/
/-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/
noncomputable instance inv : Inv (Matrix n n α) :=
⟨fun A => Ring.inverse A.det • A.adjugate⟩
theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate :=
rfl
theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by
rw [inv_def, Ring.inverse_non_unit _ h, zero_smul]
theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by
rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec]
/-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/
@[simp]
theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by
letI := detInvertibleOfInvertible A
rw [inv_def, Ring.inverse_invertible, invOf_eq]
/-- Coercing the result of `Units.instInv` is the same as coercing first and applying the
nonsingular inverse. -/
@[simp, norm_cast]
theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by
letI := A.invertible
rw [← invOf_eq_nonsing_inv, invOf_units]
/-- The nonsingular inverse is the same as the general `Ring.inverse`. -/
theorem nonsing_inv_eq_ringInverse : A⁻¹ = Ring.inverse A := by
by_cases h_det : IsUnit A.det
· cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible
rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible]
· have h := mt A.isUnit_iff_isUnit_det.mp h_det
rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det]
@[deprecated (since := "2025-04-22")]
alias nonsing_inv_eq_ring_inverse := nonsing_inv_eq_ringInverse
theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by
rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by
rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose,
Ring.inverse_star]
/-- The `nonsing_inv` of `A` is a right inverse. -/
@[simp]
theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, mul_invOf_self]
/-- The `nonsing_inv` of `A` is a left inverse. -/
@[simp]
theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, invOf_mul_self]
instance [Invertible A] : Invertible A⁻¹ := by
rw [← invOf_eq_nonsing_inv]
infer_instance
@[simp]
theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by
simp only [← invOf_eq_nonsing_inv, invOf_invOf]
@[simp]
theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by
simp [Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by
simp [← Matrix.mul_assoc, mul_nonsing_inv A h]
@[simp]
theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by
simp [Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by
simp [← Matrix.mul_assoc, nonsing_inv_mul A h]
@[simp]
theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 :=
mul_nonsing_inv A (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 :=
nonsing_inv_mul A (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B :=
mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B :=
mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B :=
nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A)
@[simp]
theorem inv_mul_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A⁻¹ * (A * B) = B :=
nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A)
theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
A⁻¹ * B = C ↔ B = A * C :=
⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible],
fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩
theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
B * A⁻¹ = C ↔ B = C * A :=
⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible],
fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩
lemma inv_mulVec_eq_vec {A : Matrix n n α} [Invertible A]
{u v : n → α} (hM : u = A.mulVec v) : A⁻¹.mulVec u = v := by
rw [hM, Matrix.mulVec_mulVec, Matrix.inv_mul_of_invertible, Matrix.one_mulVec]
lemma mul_right_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix n m α) => A * x) :=
fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * ·) h
lemma mul_left_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix m n α) => x * A) :=
fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (· * A⁻¹) hax
lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m α} : A * x = A * y ↔ x = y :=
(mul_right_injective_of_invertible A).eq_iff
lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n α} : x * A = y * A ↔ x = y :=
(mul_left_injective_of_invertible A).eq_iff
end Inv
section InjectiveMul
variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing α]
lemma mul_left_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix l m α => x * A) := fun _ _ g => by
simpa only [Matrix.mul_assoc, Matrix.mul_one, h] using congr_arg (· * B) g
lemma mul_right_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix m l α => B * x) :=
fun _ _ g => by simpa only [← Matrix.mul_assoc, Matrix.one_mul, h] using congr_arg (A * ·) g
end InjectiveMul
section vecMul
section Semiring
variable {R : Type*} [Semiring R]
theorem vecMul_surjective_iff_exists_left_inverse
[DecidableEq n] [Fintype m] [Finite n] {A : Matrix m n R} :
Function.Surjective A.vecMul ↔ ∃ B : Matrix n m R, B * A = 1 := by
cases nonempty_fintype n
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨y ᵥ* B, by simp [hBA]⟩⟩
choose rows hrows using (h <| Pi.single · 1)
refine ⟨Matrix.of rows, Matrix.ext fun i j => ?_⟩
rw [mul_apply_eq_vecMul, one_eq_pi_single, ← hrows]
rfl
theorem mulVec_surjective_iff_exists_right_inverse
[DecidableEq m] [Finite m] [Fintype n] {A : Matrix m n R} :
Function.Surjective A.mulVec ↔ ∃ B : Matrix n m R, A * B = 1 := by
cases nonempty_fintype m
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨B *ᵥ y, by simp [hBA]⟩⟩
choose cols hcols using (h <| Pi.single · 1)
refine ⟨(Matrix.of cols)ᵀ, Matrix.ext fun i j ↦ ?_⟩
rw [one_eq_pi_single, Pi.single_comm, ← hcols j]
rfl
end Semiring
variable [DecidableEq m] {R K : Type*} [CommRing R] [Field K] [Fintype m]
theorem vecMul_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.vecMul ↔ IsUnit A := by
rw [vecMul_surjective_iff_exists_left_inverse, exists_left_inverse_iff_isUnit]
theorem mulVec_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.mulVec ↔ IsUnit A := by
rw [mulVec_surjective_iff_exists_right_inverse, exists_right_inverse_iff_isUnit]
theorem vecMul_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.vecMul ↔ IsUnit A := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [← vecMul_surjective_iff_isUnit]
exact LinearMap.surjective_of_injective (f := A.vecMulLinear) h
change Function.Injective A.vecMulLinear
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
intro c hc
replace h := h.invertible
simpa using congr_arg A⁻¹.vecMulLinear hc
theorem mulVec_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.mulVec ↔ IsUnit A := by
rw [← isUnit_transpose, ← vecMul_injective_iff_isUnit]
simp_rw [vecMul_transpose]
theorem linearIndependent_rows_iff_isUnit {A : Matrix m m K} :
LinearIndependent K A.row ↔ IsUnit A := by
rw [← col_transpose, ← mulVec_injective_iff, ← coe_mulVecLin, mulVecLin_transpose,
← vecMul_injective_iff_isUnit, coe_vecMulLinear]
theorem linearIndependent_cols_iff_isUnit {A : Matrix m m K} :
LinearIndependent K A.col ↔ IsUnit A := by
rw [← row_transpose, linearIndependent_rows_iff_isUnit, isUnit_transpose]
theorem vecMul_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.vecMul :=
vecMul_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.mulVec :=
mulVec_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem vecMul_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.vecMul :=
vecMul_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.mulVec :=
mulVec_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_rows_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K A.row :=
linearIndependent_rows_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_cols_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K A.col :=
linearIndependent_cols_iff_isUnit.2 <| isUnit_of_invertible A
end vecMul
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem nonsing_inv_cancel_or_zero : A⁻¹ * A = 1 ∧ A * A⁻¹ = 1 ∨ A⁻¹ = 0 := by
by_cases h : IsUnit A.det
· exact Or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩
· exact Or.inr (nonsing_inv_apply_not_isUnit _ h)
theorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A⁻¹.det * A.det = 1 := by
rw [← det_mul, A.nonsing_inv_mul h, det_one]
@[simp]
theorem det_nonsing_inv : A⁻¹.det = Ring.inverse A.det := by
by_cases h : IsUnit A.det
· cases h.nonempty_invertible
letI := invertibleOfDetInvertible A
rw [Ring.inverse_invertible, ← invOf_eq_nonsing_inv, det_invOf]
cases isEmpty_or_nonempty n
· rw [det_isEmpty, det_isEmpty, Ring.inverse_one]
· rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit _ h, det_zero ‹_›]
theorem isUnit_nonsing_inv_det (h : IsUnit A.det) : IsUnit A⁻¹.det :=
isUnit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)
@[simp]
theorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A⁻¹⁻¹ = A :=
calc
A⁻¹⁻¹ = 1 * A⁻¹⁻¹ := by rw [Matrix.one_mul]
_ = A * A⁻¹ * A⁻¹⁻¹ := by rw [A.mul_nonsing_inv h]
_ = A := by
rw [Matrix.mul_assoc, A⁻¹.mul_nonsing_inv (A.isUnit_nonsing_inv_det h), Matrix.mul_one]
theorem isUnit_nonsing_inv_det_iff {A : Matrix n n α} : IsUnit A⁻¹.det ↔ IsUnit A.det := by
rw [Matrix.det_nonsing_inv, isUnit_ringInverse]
@[simp]
theorem isUnit_nonsing_inv_iff {A : Matrix n n α} : IsUnit A⁻¹ ↔ IsUnit A := by
simp_rw [isUnit_iff_isUnit_det, isUnit_nonsing_inv_det_iff]
-- `IsUnit.invertible` lifts the proposition `IsUnit A` to a constructive inverse of `A`.
/-- A version of `Matrix.invertibleOfDetInvertible` with the inverse defeq to `A⁻¹` that is
therefore noncomputable. -/
noncomputable def invertibleOfIsUnitDet (h : IsUnit A.det) : Invertible A :=
⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩
/-- A version of `Matrix.unitOfDetInvertible` with the inverse defeq to `A⁻¹` that is therefore
noncomputable. -/
noncomputable def nonsingInvUnit (h : IsUnit A.det) : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ _ (invertibleOfIsUnitDet A h)
theorem unitOfDetInvertible_eq_nonsingInvUnit [Invertible A.det] :
unitOfDetInvertible A = nonsingInvUnit A (isUnit_of_invertible _) := by
ext
rfl
variable {A} {B}
/-- If matrix A is left invertible, then its inverse equals its left inverse. -/
theorem inv_eq_left_inv (h : B * A = 1) : A⁻¹ = B :=
letI := invertibleOfLeftInverse _ _ h
invOf_eq_nonsing_inv A ▸ invOf_eq_left_inv h
/-- If matrix A is right invertible, then its inverse equals its right inverse. -/
theorem inv_eq_right_inv (h : A * B = 1) : A⁻¹ = B :=
inv_eq_left_inv (mul_eq_one_comm.2 h)
section InvEqInv
variable {C : Matrix n n α}
/-- The left inverse of matrix A is unique when existing. -/
theorem left_inv_eq_left_inv (h : B * A = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_left_inv h, ← inv_eq_left_inv g]
/-- The right inverse of matrix A is unique when existing. -/
theorem right_inv_eq_right_inv (h : A * B = 1) (g : A * C = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_right_inv g]
/-- The right inverse of matrix A equals the left inverse of A when they exist. -/
theorem right_inv_eq_left_inv (h : A * B = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_left_inv g]
theorem inv_inj (h : A⁻¹ = B⁻¹) (h' : IsUnit A.det) : A = B := by
refine left_inv_eq_left_inv (mul_nonsing_inv _ h') ?_
rw [h]
refine mul_nonsing_inv _ ?_
rwa [← isUnit_nonsing_inv_det_iff, ← h, isUnit_nonsing_inv_det_iff]
end InvEqInv
variable (A)
@[simp]
theorem inv_zero : (0 : Matrix n n α)⁻¹ = 0 := by
rcases subsingleton_or_nontrivial α with ht | ht
· simp [eq_iff_true_of_subsingleton]
rcases (Fintype.card n).zero_le.eq_or_lt with hc | hc
· rw [eq_comm, Fintype.card_eq_zero_iff] at hc
haveI := hc
ext i
exact (IsEmpty.false i).elim
· have hn : Nonempty n := Fintype.card_pos_iff.mp hc
refine nonsing_inv_apply_not_isUnit _ ?_
simp [hn]
noncomputable instance : InvOneClass (Matrix n n α) :=
{ Matrix.one, Matrix.inv with inv_one := inv_eq_left_inv (by simp) }
theorem inv_smul (k : α) [Invertible k] (h : IsUnit A.det) : (k • A)⁻¹ = ⅟ k • A⁻¹ :=
inv_eq_left_inv (by simp [h, smul_smul])
|
theorem inv_smul' (k : αˣ) (h : IsUnit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ :=
| Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean | 505 | 506 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
| theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 180 | 184 |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kim Morrison, Mario Carneiro, Andrew Yang
-/
import Mathlib.Topology.Category.TopCat.EpiMono
import Mathlib.Topology.Category.TopCat.Limits.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.ConcreteCategory.Basic
import Mathlib.Data.Set.Subsingleton
import Mathlib.Tactic.CategoryTheory.Elementwise
import Mathlib.Topology.Homeomorph.Lemmas
/-!
# Products and coproducts in the category of topological spaces
-/
open CategoryTheory Limits Set TopologicalSpace Topology
universe v u w
noncomputable section
namespace TopCat
variable {J : Type v} [Category.{w} J]
/-- The projection from the product as a bundled continuous map. -/
abbrev piπ {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : TopCat.of (∀ i, α i) ⟶ α i :=
ofHom ⟨fun f => f i, continuous_apply i⟩
/-- The explicit fan of a family of topological spaces given by the pi type. -/
@[simps! pt π_app]
def piFan {ι : Type v} (α : ι → TopCat.{max v u}) : Fan α :=
Fan.mk (TopCat.of (∀ i, α i)) (piπ.{v,u} α)
/-- The constructed fan is indeed a limit -/
def piFanIsLimit {ι : Type v} (α : ι → TopCat.{max v u}) : IsLimit (piFan α) where
lift S := ofHom
{ toFun := fun s i => S.π.app ⟨i⟩ s
continuous_toFun := continuous_pi (fun i => (S.π.app ⟨i⟩).hom.2) }
uniq := by
intro S m h
ext x
funext i
simp [ContinuousMap.coe_mk, ← h ⟨i⟩]
fac _ _ := rfl
/-- The product is homeomorphic to the product of the underlying spaces,
equipped with the product topology.
-/
def piIsoPi {ι : Type v} (α : ι → TopCat.{max v u}) : ∏ᶜ α ≅ TopCat.of (∀ i, α i) :=
(limit.isLimit _).conePointUniqueUpToIso (piFanIsLimit.{v, u} α)
@[reassoc (attr := simp)]
theorem piIsoPi_inv_π {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) :
(piIsoPi α).inv ≫ Pi.π α i = piπ α i := by simp [piIsoPi]
theorem piIsoPi_inv_π_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : ∀ i, α i) :
(Pi.π α i :) ((piIsoPi α).inv x) = x i :=
ConcreteCategory.congr_hom (piIsoPi_inv_π α i) x
theorem piIsoPi_hom_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι)
(x : (∏ᶜ α : TopCat.{max v u})) : (piIsoPi α).hom x i = (Pi.π α i :) x := by
have := piIsoPi_inv_π α i
rw [Iso.inv_comp_eq] at this
exact ConcreteCategory.congr_hom this x
/-- The inclusion to the coproduct as a bundled continuous map. -/
abbrev sigmaι {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : α i ⟶ TopCat.of (Σi, α i) := by
refine ofHom (ContinuousMap.mk ?_ ?_)
· dsimp
apply Sigma.mk i
· dsimp; continuity
/-- The explicit cofan of a family of topological spaces given by the sigma type. -/
@[simps! pt ι_app]
def sigmaCofan {ι : Type v} (α : ι → TopCat.{max v u}) : Cofan α :=
Cofan.mk (TopCat.of (Σi, α i)) (sigmaι α)
| /-- The constructed cofan is indeed a colimit -/
def sigmaCofanIsColimit {ι : Type v} (β : ι → TopCat.{max v u}) : IsColimit (sigmaCofan β) where
desc S := ofHom
{ toFun := fun (s : of (Σ i, β i)) => S.ι.app ⟨s.1⟩ s.2
continuous_toFun := by continuity }
| Mathlib/Topology/Category/TopCat/Limits/Products.lean | 81 | 85 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.BigOperators.Group.List.Basic
/-!
# Free groups
This file defines free groups over a type. Furthermore, it is shown that the free group construction
is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful
functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`.
## Main definitions
* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type
`α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`.
* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`.
* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`.
* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G`
given a group `G` and a function `f : α → G`.
## Main statements
* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word
reduction (also known as Newman's diamond lemma).
* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type
is isomorphic to the integers.
* The free group construction is an instance of a monad.
## Implementation details
First we introduce the one step reduction relation `FreeGroup.Red.Step`:
`w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans`
and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient
over `FreeGroup.Red.Step`.
For the additive version we introduce the same relation under a different name so that we can
distinguish the quotient types more easily.
## Tags
free group, Newman's diamond lemma, Church-Rosser theorem
-/
open Relation
open scoped List
universe u v w
variable {α : Type u}
attribute [local simp] List.append_eq_has_append
-- Porting note: to_additive.map_namespace is not supported yet
-- worked around it by putting a few extra manual mappings (but not too many all in all)
-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup
/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/
inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeAddGroup.Red.Step.not
/-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/
@[to_additive FreeAddGroup.Red.Step]
inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeGroup.Red.Step.not
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- Reflexive-transitive closure of `Red.Step` -/
@[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"]
def Red : List (α × Bool) → List (α × Bool) → Prop :=
ReflTransGen Red.Step
@[to_additive (attr := refl)]
theorem Red.refl : Red L L :=
ReflTransGen.refl
@[to_additive (attr := trans)]
theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ :=
ReflTransGen.trans
namespace Red
/-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words
`w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/
@[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there
are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"]
theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length
| _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl
@[to_additive (attr := simp)]
theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by
cases b <;> exact Step.not
@[to_additive (attr := simp)]
theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=
@Step.not _ [] _ _ _
@[to_additive (attr := simp)]
theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=
@Red.Step.not_rev _ [] _ _ _
@[to_additive]
theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃)
| _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor
@[to_additive]
theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) :=
@Step.append_left _ [x] _ _ H
@[to_additive]
theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃)
| _, _, _, Red.Step.not => by simp
@[to_additive]
theorem not_step_nil : ¬Step [] L := by
generalize h' : [] = L'
intro h
rcases h with - | ⟨L₁, L₂⟩
simp [List.nil_eq_append_iff] at h'
@[to_additive]
theorem Step.cons_left_iff {a : α} {b : Bool} :
Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by
constructor
· generalize hL : ((a, b) :: L₁ : List _) = L
rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all
· rintro (⟨L, h, rfl⟩ | rfl)
· exact Step.cons h
· exact Step.cons_not
@[to_additive]
theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L
| (a, b) => by simp [Step.cons_left_iff, not_step_nil]
@[to_additive]
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp +contextual [Step.cons_left_iff, iff_def, or_imp]
@[to_additive]
theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂
| [] => by simp
| p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]
@[to_additive]
theorem Step.diamond_aux :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2},
L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ →
L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅
| [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp
| [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by
injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩
| (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by
injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩
| (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H =>
let ⟨H1, H2⟩ := List.cons.inj H
match Step.diamond_aux H2 with
| Or.inl H3 => Or.inl <| by simp [H1, H3]
| Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩
@[to_additive]
theorem Step.diamond :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)},
Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅
| _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H
@[to_additive]
theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ :=
ReflTransGen.single
/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma. -/
@[to_additive
"**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma."]
theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ :=
Relation.church_rosser fun _ b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩
@[to_additive]
| theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) :=
ReflTransGen.lift (List.cons p) fun _ _ => Step.cons
@[to_additive]
theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ :=
Iff.intro
(by
generalize eq₁ : (p :: L₁ : List _) = LL₁
generalize eq₂ : (p :: L₂ : List _) = LL₂
intro h
induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with
| refl =>
subst_vars
cases eq₂
constructor
| head h₁₂ h ih =>
| Mathlib/GroupTheory/FreeGroup/Basic.lean | 197 | 212 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Kappelmann
-/
import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Floor.Semiring
deprecated_module (since := "2025-04-13")
| Mathlib/Algebra/Order/Floor.lean | 802 | 803 | |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Order properties of cast of integers
This file proves additional properties about the *canonical* homomorphism from
the integers into an additive group with a one (`Int.cast`),
particularly results involving algebraic homomorphisms or the order structure on `ℤ`
which were not available in the import dependencies of `Mathlib.Data.Int.Cast.Basic`.
## TODO
Move order lemmas about `Nat.cast`, `Rat.cast`, `NNRat.cast` here.
-/
open Function Nat
variable {R : Type*}
namespace Int
section OrderedAddCommGroupWithOne
variable [AddCommGroupWithOne R] [PartialOrder R] [AddLeftMono R]
variable [ZeroLEOneClass R]
|
lemma cast_mono : Monotone (Int.cast : ℤ → R) := by
intro m n h
rw [← sub_nonneg] at h
lift n - m to ℕ using h with k hk
rw [← sub_nonneg, ← cast_sub, ← hk, cast_natCast]
| Mathlib/Algebra/Order/Ring/Cast.lean | 32 | 37 |
/-
Copyright (c) 2024 Paul Reichert. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Reichert
-/
import Mathlib.CategoryTheory.Limits.Types.Colimits
import Mathlib.CategoryTheory.IsConnected
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.CategoryTheory.HomCongr
/-!
# Colimits of connected index categories
This file proves two characterizations of connected categories by means of colimits.
## Characterization of connected categories by means of the unit-valued functor
First, it is proved that a category `C` is connected if and only if `colim F` is a singleton,
where `F : C ⥤ Type w` and `F.obj _ = PUnit` (for arbitrary `w`).
See `isConnected_iff_colimit_constPUnitFunctor_iso_pUnit` for the proof of this characterization and
`constPUnitFunctor` for the definition of the constant functor used in the statement. A formulation
based on `IsColimit` instead of `colimit` is given in `isConnected_iff_isColimit_pUnitCocone`.
The `if` direction is also available directly in several formulations:
For connected index categories `C`, `PUnit.{w}` is a colimit of the `constPUnitFunctor`, where `w`
is arbitrary. See `instHasColimitConstPUnitFunctor`, `isColimitPUnitCocone` and
`colimitConstPUnitIsoPUnit`.
## Final functors preserve connectedness of categories (in both directions)
`isConnected_iff_of_final` proves that the domain of a final functor is connected if and only if
its codomain is connected.
## Tags
unit-valued, singleton, colimit
-/
universe w v u
namespace CategoryTheory
namespace Limits.Types
variable (C : Type u) [Category.{v} C]
/-- The functor mapping every object to `PUnit`. -/
def constPUnitFunctor : C ⥤ Type w := (Functor.const C).obj PUnit.{w + 1}
/-- The cocone on `constPUnitFunctor` with cone point `PUnit`. -/
@[simps]
def pUnitCocone : Cocone (constPUnitFunctor.{w} C) where
pt := PUnit
ι := { app := fun _ => id }
/-- If `C` is connected, the cocone on `constPUnitFunctor` with cone point `PUnit` is a colimit
cocone. -/
noncomputable def isColimitPUnitCocone [IsConnected C] : IsColimit (pUnitCocone.{w} C) where
desc s := s.ι.app Classical.ofNonempty
fac s j := by
ext ⟨⟩
apply constant_of_preserves_morphisms (s.ι.app · PUnit.unit)
intros X Y f
exact congrFun (s.ι.naturality f).symm PUnit.unit
uniq s m h := by
ext ⟨⟩
simp [← h Classical.ofNonempty]
instance instHasColimitConstPUnitFunctor [IsConnected C] : HasColimit (constPUnitFunctor.{w} C) :=
⟨_, isColimitPUnitCocone _⟩
instance instSubsingletonColimitPUnit
[IsPreconnected C] [HasColimit (constPUnitFunctor.{w} C)] :
Subsingleton (colimit (constPUnitFunctor.{w} C)) where
allEq a b := by
obtain ⟨c, ⟨⟩, rfl⟩ := jointly_surjective' a
obtain ⟨d, ⟨⟩, rfl⟩ := jointly_surjective' b
apply constant_of_preserves_morphisms (colimit.ι (constPUnitFunctor C) · PUnit.unit)
exact fun c d f => colimit_sound f rfl
/-- Given a connected index category, the colimit of the constant unit-valued functor is `PUnit`. -/
noncomputable def colimitConstPUnitIsoPUnit [IsConnected C] :
colimit (constPUnitFunctor.{w} C) ≅ PUnit.{w + 1} :=
IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) (isColimitPUnitCocone.{w} C)
/-- Let `F` be a `Type`-valued functor. If two elements `a : F c` and `b : F d` represent the same
element of `colimit F`, then `c` and `d` are related by a `Zigzag`. -/
theorem zigzag_of_eqvGen_quot_rel (F : C ⥤ Type w) (c d : Σ j, F.obj j)
(h : Relation.EqvGen (Quot.Rel F) c d) : Zigzag c.1 d.1 := by
induction h with
| rel _ _ h => exact Zigzag.of_hom <| Exists.choose h
| refl _ => exact Zigzag.refl _
| symm _ _ _ ih => exact zigzag_symmetric ih
| trans _ _ _ _ _ ih₁ ih₂ => exact ih₁.trans ih₂
| /-- An index category is connected iff the colimit of the constant singleton-valued functor is a
singleton. -/
theorem isConnected_iff_colimit_constPUnitFunctor_iso_pUnit
[HasColimit (constPUnitFunctor.{w} C)] :
IsConnected C ↔ Nonempty (colimit (constPUnitFunctor.{w} C) ≅ PUnit) := by
refine ⟨fun _ => ⟨colimitConstPUnitIsoPUnit.{w} C⟩, fun ⟨h⟩ => ?_⟩
have : Nonempty C := nonempty_of_nonempty_colimit <| Nonempty.map h.inv inferInstance
refine zigzag_isConnected <| fun c d => ?_
| Mathlib/CategoryTheory/Limits/IsConnected.lean | 97 | 104 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Tactic.ArithMult
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe]
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff]
simp [y1ne]
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro ⟨y₁, y₂⟩ ymem ynmem
have y2ne : y₂ ≠ 1 := by
intro con
simp_all
simp [y2ne]
mul_assoc := mul_smul' }
instance instSemiring : Semiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp
mul_zero := fun f => by
ext
simp
left_distrib := fun a b c => by
ext
simp [← sum_add_distrib, mul_add]
right_distrib := fun a b c => by
ext
simp [← sum_add_distrib, add_mul] }
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
neg_add_cancel := neg_add_cancel
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_zeta_mul_apply]
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_mul_zeta_apply]
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk]
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
namespace IsMultiplicative
section MonoidWithZero
variable [MonoidWithZero R]
@[simp, arith_mult]
theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 :=
h.1
@[simp]
theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ}
(h : m.Coprime n) : f (m * n) = f m * f n :=
hf.2 h
end MonoidWithZero
open scoped Function in -- required for scoped `on` notation
theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) :
f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by
classical
induction s using Finset.induction_on with
| empty => simp [hf]
| insert _ _ has ih =>
rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs
rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1]
exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm
theorem map_prod_of_prime [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f)
(t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy
theorem map_prod_of_subset_primeFactors [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ)
(t : Finset ℕ) (ht : t ⊆ l.primeFactors) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a)
theorem map_div_of_coprime [GroupWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {l d : ℕ} (hdl : d ∣ l) (hl : (l / d).Coprime d) (hd : f d ≠ 0) :
f (l / d) = f l / f d := by
apply (div_eq_of_eq_mul hd ..).symm
rw [← hf.right hl, Nat.div_mul_cancel hdl]
@[arith_mult]
theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by
refine ⟨by simp [hf.1, hg.1], ?_⟩
simp only [mul_apply]
intro m n cop
rw [sum_mul_sum, ← sum_product']
symm
apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l)
· rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h
simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne]
constructor
· ring
rw [Nat.mul_eq_zero] at *
apply not_or_intro ha hb
· simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk_inj]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h
simp only [Prod.mk_inj] at h
ext <;> dsimp only
· trans Nat.gcd (a1 * a2) (a1 * b1)
· rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.1, Nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· trans Nat.gcd (a1 * a2) (a2 * b2)
· rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a1 * b1)
· rw [mul_comm, Nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a2 * b2)
· rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one,
one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.2, Nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul]
· simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product,
Set.mem_image, exists_prop, Prod.mk_inj]
rintro ⟨b1, b2⟩ h
dsimp at h
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n))
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _]
· rw [Nat.mul_eq_zero, not_or] at h
simp [h.2.1, h.2.2]
rw [mul_comm n m, h.1]
· simp only [mem_divisorsAntidiagonal, Ne, mem_product]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
dsimp only
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right]
ring
@[arith_mult]
theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop]
ring⟩
@[arith_mult]
theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f)
(hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop,
div_eq_mul_inv, mul_inv]
apply mul_mul_mul_comm ⟩
/-- For any multiplicative function `f` and any `n > 0`,
we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/
theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) :
f n = n.factorization.prod fun p k => f (p ^ k) :=
Nat.multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn
/-- A recapitulation of the definition of multiplicative that is simpler for proofs -/
theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} :
IsMultiplicative f ↔
f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by
refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩)
rcases eq_or_ne m 0 with (rfl | hm)
· simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
exact h hm hn hmn
/-- Two multiplicative functions `f` and `g` are equal if and only if
they agree on prime powers -/
theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) :
f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by
constructor
· intro h p i _
rw [h]
intro h
ext n
by_cases hn : n = 0
· rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero]
rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn]
exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp)
@[arith_mult]
theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) :
IsMultiplicative (prodPrimeFactors f) := by
rw [iff_ne_zero]
simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one,
prod_empty, true_and]
intro x y hx hy hxy
have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy
rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy,
Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors]
theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R}
(hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) :
∏ᵖ p ∣ n, (f + g) p = (f * g) n := by
rw [prodPrimeFactors_apply hn.ne_zero]
simp_rw [add_apply (f := f) (g := g)]
rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·),
← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero,
factors_eq]
apply Finset.sum_congr rfl
intro t ht
rw [t.prod_val, Function.id_def,
← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht),
hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht),
← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset]
theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} :
f (x.lcm y) * f (x.gcd y) = f x * f y := by
by_cases hx : x = 0
· simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left]
by_cases hy : y = 0
· simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul]
have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx
have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy
have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by
intro i; rw [Nat.pow_zero, hf.1]
iterate 4 rw [hf.multiplicative_factorization f (by assumption),
Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero)
(s := (x.primeFactors ∪ y.primeFactors))]
· rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro p _
rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;>
simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right,
sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply,
inf_of_le_left, mul_comm]
· apply Finset.subset_union_right
· apply Finset.subset_union_left
· rw [factorization_gcd hx hy, Finsupp.support_inf]
apply Finset.inter_subset_union
· simp [factorization_lcm hx hy]
theorem map_gcd [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_lcm : f (x.lcm y) ≠ 0) :
f (x.gcd y) = f x * f y / f (x.lcm y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_left₀ _ hf_lcm]
theorem map_lcm [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_gcd : f (x.gcd y) ≠ 0) :
f (x.lcm y) = f x * f y / f (x.gcd y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_right₀ _ hf_gcd]
theorem eq_zero_of_squarefree_of_dvd_eq_zero [MonoidWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {m n : ℕ} (hn : Squarefree n) (hmn : m ∣ n)
(h_zero : f m = 0) :
f n = 0 := by
rcases hmn with ⟨k, rfl⟩
simp only [MulZeroClass.zero_mul, eq_self_iff_true, hf.map_mul_of_coprime
(coprime_of_squarefree_mul hn), h_zero]
end IsMultiplicative
section SpecialFunctions
/-- The identity on `ℕ` as an `ArithmeticFunction`. -/
def id : ArithmeticFunction ℕ :=
⟨_root_.id, rfl⟩
@[simp]
theorem id_apply {x : ℕ} : id x = x :=
rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : ArithmeticFunction ℕ :=
id.ppow k
|
@[simp]
theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by
cases k <;> simp [pow]
theorem pow_zero_eq_zeta : pow 0 = ζ := by
ext n
simp
| Mathlib/NumberTheory/ArithmeticFunction.lean | 788 | 796 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.GroupTheory.Perm.Finite
import Mathlib.GroupTheory.Perm.List
import Mathlib.GroupTheory.Perm.Sign
/-!
# Cycles of a permutation
This file starts the theory of cycles in permutations.
## Main definitions
In the following, `f : Equiv.Perm β`.
* `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`.
* `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated
applications of `f`, and `f` is not the identity.
* `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by
repeated applications of `f`.
## Notes
`Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways:
* `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set.
* `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton).
* `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-! ### `SameCycle` -/
section SameCycle
variable {f g : Perm α} {p : α → Prop} {x y z : α}
/-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/
def SameCycle (f : Perm α) (x y : α) : Prop :=
∃ i : ℤ, (f ^ i) x = y
@[refl]
theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x :=
⟨0, rfl⟩
theorem SameCycle.rfl : SameCycle f x x :=
SameCycle.refl _ _
protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h]
@[symm]
theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ =>
⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩
theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x :=
⟨SameCycle.symm, SameCycle.symm⟩
@[trans]
theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z :=
fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩
variable (f) in
theorem SameCycle.equivalence : Equivalence (SameCycle f) :=
⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩
/-- The setoid defined by the `SameCycle` relation. -/
def SameCycle.setoid (f : Perm α) : Setoid α where
r := f.SameCycle
iseqv := SameCycle.equivalence f
@[simp]
theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle]
@[simp]
theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y :=
(Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle]
alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv
@[simp]
theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) :=
exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq]
theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by
simp [sameCycle_conj]
theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by
rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply,
(f ^ i).injective.eq_iff]
theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y :=
let ⟨_, hn⟩ := h
(hx.perm_zpow _).eq.symm.trans hn
theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y :=
h.eq_of_left <| h.apply_eq_self_iff.2 hy
@[simp]
theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y :=
(Equiv.addRight 1).exists_congr_left.trans <| by
simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp]
@[simp]
theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm]
@[simp]
theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by
rw [← sameCycle_apply_left, apply_inv_self]
@[simp]
theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by
rw [← sameCycle_apply_right, apply_inv_self]
@[simp]
theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y :=
(Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add]
@[simp]
theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm]
@[simp]
theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_left]
@[simp]
theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_right]
alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left
alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right
alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left
alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right
alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left
alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right
alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left
alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right
theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
@[simp]
theorem sameCycle_subtypePerm {h} {x y : { x // p x }} :
(f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y :=
exists_congr fun n => by simp [Subtype.ext_iff]
alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm
@[simp]
theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} :
SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y :=
exists_congr fun n => by
rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff]
alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
rintro ⟨k, rfl⟩
use (k % orderOf f).natAbs
have h₀ := Int.natCast_pos.mpr (orderOf_pos f)
have h₁ := Int.emod_nonneg k h₀.ne'
rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf]
refine ⟨?_, by rfl⟩
rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁]
exact Int.emod_lt_of_pos _ h₀
theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by
obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq'
· refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩
rw [pow_orderOf_eq_one, pow_zero]
· exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩
theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by
obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h
exact ⟨⟨i, hi⟩, hx⟩
theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, (f ^ i) x = y := by
obtain ⟨i, _, hi⟩ := h.exists_pow_eq'
exact ⟨i, hi⟩
instance (f : Perm α) [DecidableRel (SameCycle f)] :
DecidableRel (SameCycle f⁻¹) := fun x y =>
decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm
instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y =>
decidable_of_iff (x = y) sameCycle_one.symm
end SameCycle
/-!
### `IsCycle`
-/
section IsCycle
variable {f g : Perm α} {x y : α}
/-- A cycle is a non identity permutation where any two nonfixed points of the permutation are
related by repeated application of the permutation. -/
def IsCycle (f : Perm α) : Prop :=
∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y
theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h
@[simp]
theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl
protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
SameCycle f x y :=
let ⟨g, hg⟩ := hf
let ⟨a, ha⟩ := hg.2 hx
let ⟨b, hb⟩ := hg.2 hy
⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩
theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y :=
IsCycle.sameCycle
theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ :=
hf.imp fun _ ⟨hx, h⟩ =>
⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩
@[simp]
theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f :=
⟨fun h => h.inv, IsCycle.inv⟩
theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by
rintro ⟨x, hx, h⟩
refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩
rw [← apply_inv_self g y]
exact (h <| eq_inv_iff_eq.not.2 hy).conj
protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) :
IsCycle g → IsCycle (g.extendDomain f) := by
rintro ⟨a, ha, ha'⟩
refine ⟨f a, ?_, fun b hb => ?_⟩
· rw [extendDomain_apply_image]
exact Subtype.coe_injective.ne (f.injective.ne ha)
have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by
rw [apply_symm_apply, Subtype.coe_mk]
rw [h] at hb ⊢
simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb
exact (ha' hb).extendDomain
theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y :=
⟨fun hf y =>
⟨fun ⟨i, hi⟩ hy =>
hx <| by
rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi
rw [hi, hy],
hf.exists_zpow_eq hx⟩,
fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩
section Finite
variable [Finite α]
theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
∃ i : ℕ, (f ^ i) x = y := by
let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy
classical exact
⟨(n % orderOf f).toNat, by
{have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f)))
rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩
end Finite
variable [DecidableEq α]
theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) :=
⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) =>
if hya : y = a then ⟨0, hya⟩
else
⟨1, by
rw [zpow_one, swap_apply_def]
split_ifs at * <;> tauto⟩⟩
protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by
rintro ⟨x, y, hxy, rfl⟩
exact isCycle_swap hxy
variable [Fintype α]
theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support :=
two_le_card_support_of_ne_one h.ne_one
/-- The subgroup generated by a cycle is in bijection with its support -/
noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) :
(Subgroup.zpowers σ) ≃ σ.support :=
Equiv.ofBijective
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
⟨(τ : Perm α) (Classical.choose hσ), by
obtain ⟨τ, n, rfl⟩ := τ
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
exact (Classical.choose_spec hσ).1⟩)
(by
constructor
· rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h
ext y
by_cases hy : σ y = y
· simp_rw [zpow_apply_eq_self_of_apply_eq_self hy]
· obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
exact congr_arg _ (Subtype.ext_iff.mp h)
· rintro ⟨y, hy⟩
rw [mem_support] at hy
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
@[simp]
theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} :
hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ =
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ :=
rfl
@[simp]
theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) :
hσ.zpowersEquivSupport.symm
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ =
⟨σ ^ n, n, rfl⟩ :=
(Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply
protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by
rw [← Fintype.card_zpowers, ← Fintype.card_coe]
convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf)
theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] :
∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
induction n with
| zero => exact fun _ h => ⟨0, h⟩
| succ n hn =>
intro b x f hb h
exact if hfbx : f x = b then ⟨0, hfbx⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ←
f.injective.eq_iff, apply_inv_self]
exact this.1
let ⟨i, hi⟩ := hn hb' (f.injective <| by
rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h)
⟨i + 1, by
rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩
theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] :
∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
cases n with
| ofNat n => exact isCycle_swap_mul_aux₁ n
| negSucc n =>
intro b x f hb h
exact if hfbx' : f x = b then ⟨0, hfbx'⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, swap_apply_def]
split_ifs <;>
simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at *
<;> tauto
let ⟨i, hi⟩ :=
isCycle_swap_mul_aux₁ n hb
(show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by
rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc,
← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_cancel, mul_one, zpow_natCast,
← pow_succ', ← pow_succ])
have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by
rw [mul_apply, inv_apply_self, swap_apply_left]
⟨-i, by
rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg,
← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x,
zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩
theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α}
(hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) :=
Equiv.ext fun y =>
let ⟨z, hz⟩ := hf
let ⟨i, hi⟩ := hz.2 hfx
if hyx : y = x then by simp [hyx]
else
if hfyx : y = f x then by simp [hfyx, hffx]
else by
rw [swap_apply_of_ne_of_ne hyx hfyx]
refine by_contradiction fun hy => ?_
obtain ⟨j, hj⟩ := hz.2 hy
rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj
rcases zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji | hji
· rw [← hj, hji] at hyx
tauto
· rw [← hj, hji] at hfyx
tauto
theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α}
(hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) :=
⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx],
fun y hy =>
let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1
have hi : (f ^ (i - 1)) (f x) = y :=
calc
(f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp
_ = y := by rwa [← zpow_add, sub_add_cancel]
isCycle_swap_mul_aux₂ (i - 1) hy hi⟩
theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ #f.support :=
let ⟨x, hx⟩ := hf
calc
Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by
{rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]}
_ = -(-1) ^ #f.support :=
if h1 : f (f x) = x then by
have h : swap x (f x) * f = 1 := by
simp only [mul_def, one_def]
rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap]
rw [sign_mul, sign_swap hx.1.symm, h, sign_one,
hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm]
rfl
else by
have h : #(swap x (f x) * f).support + 1 = #f.support := by
rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1,
card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase]
have : #(swap x (f x) * f).support < #f.support := card_support_swap_mul hx.1
rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h]
simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one]
termination_by #f.support
theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by
simp_rw [← mem_support, ← Finset.ext_iff]
exact (support_pow_le _ n).antisymm h2
obtain ⟨x, hx1, hx2⟩ := h1
refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩
obtain ⟨i, _⟩ := hx2 ((key y).mpr hy)
exact ⟨n * i, by rwa [zpow_mul]⟩
-- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to
-- `σ.support = (σ ^ n).support`, as well as to `#σ.support ≤ #(σ ^ n).support`.
theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
cases n
· exact h1.of_pow h2
· simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2
exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2
theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f)
(h2 : l.Pairwise Disjoint) : l.Nodup :=
nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2
/-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here
we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/
theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support)
(h' : ∀ x ∈ f.support, f x = g x) : f = g := by
have : f.support = g.support := by
refine le_antisymm h ?_
intro z hz
obtain ⟨x, hx, _⟩ := id hf
have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)]
obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz)
have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by
intro x hx
exact h' x (mem_of_mem_inter_left hx)
rwa [← hm, ←
pow_eq_on_of_mem_support h'' _ x
(mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')),
pow_apply_mem_support, mem_support]
refine Equiv.Perm.support_congr h ?_
simpa [← this] using h'
/-- If two cyclic permutations agree on all terms in their intersection,
and that intersection is not empty, then the two cyclic permutations must be equal. -/
theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g)
(h : ∀ x ∈ f.support ∩ g.support, f x = g x)
(hx : f x = g x) (hx' : x ∈ f.support) : f = g := by
have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support]
have : f.support ⊆ g.support := by
intro y hy
obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy)
rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support]
rw [inter_eq_left.mpr this] at h
exact hf.support_congr hg this h
theorem IsCycle.support_pow_eq_iff (hf : IsCycle f) {n : ℕ} :
support (f ^ n) = support f ↔ ¬orderOf f ∣ n := by
rw [orderOf_dvd_iff_pow_eq_one]
constructor
· intro h H
refine hf.ne_one ?_
rw [← support_eq_empty_iff, ← h, H, support_one]
· intro H
apply le_antisymm (support_pow_le _ n) _
intro x hx
contrapose! H
ext z
by_cases hz : f z = z
· rw [pow_apply_eq_self_of_apply_eq_self hz, one_apply]
· obtain ⟨k, rfl⟩ := hf.exists_pow_eq hz (mem_support.mp hx)
apply (f ^ k).injective
rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply]
simpa using H
theorem IsCycle.support_pow_of_pos_of_lt_orderOf (hf : IsCycle f) {n : ℕ} (npos : 0 < n)
(hn : n < orderOf f) : (f ^ n).support = f.support :=
hf.support_pow_eq_iff.2 <| Nat.not_dvd_of_pos_of_lt npos hn
theorem IsCycle.pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
IsCycle (f ^ n) ↔ n.Coprime (orderOf f) := by
classical
cases nonempty_fintype β
constructor
· intro h
have hr : support (f ^ n) = support f := by
rw [hf.support_pow_eq_iff]
rintro ⟨k, rfl⟩
refine h.ne_one ?_
simp [pow_mul, pow_orderOf_eq_one]
have : orderOf (f ^ n) = orderOf f := by rw [h.orderOf, hr, hf.orderOf]
rw [orderOf_pow, Nat.div_eq_self] at this
rcases this with h | _
· exact absurd h (orderOf_pos _).ne'
· rwa [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm]
· intro h
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h
have hf' : IsCycle ((f ^ n) ^ m) := by rwa [hm]
refine hf'.of_pow fun x hx => ?_
rw [hm]
exact support_pow_le _ n hx
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∃ x, f x ≠ x ∧ (f ^ n) x = x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
by_cases h : support (f ^ n) = support f
· rw [← mem_support, ← h, mem_support] at hx
contradiction
· rw [hf.support_pow_eq_iff, Classical.not_not] at h
obtain ⟨k, rfl⟩ := h
rw [pow_mul, pow_orderOf_eq_one, one_pow]
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} {x : β}
(hx : f x ≠ x) : f ^ n = 1 ↔ (f ^ n) x = x :=
⟨fun h => DFunLike.congr_fun h x, fun h => hf.pow_eq_one_iff.2 ⟨x, hx, h⟩⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff'' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∀ x, f x ≠ x → (f ^ n) x = x :=
⟨fun h _ hx => (hf.pow_eq_one_iff' hx).1 h, fun h =>
let ⟨_, hx, _⟩ := id hf
(hf.pow_eq_one_iff' hx).2 (h _ hx)⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {a b : ℕ} :
f ^ a = f ^ b ↔ ∃ x, f x ≠ x ∧ (f ^ a) x = (f ^ b) x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
wlog hab : a ≤ b generalizing a b
· exact (this hx'.symm (le_of_not_le hab)).symm
suffices f ^ (b - a) = 1 by
rw [pow_sub _ hab, mul_inv_eq_one] at this
rw [this]
rw [hf.pow_eq_one_iff]
by_cases hfa : (f ^ a) x ∈ f.support
· refine ⟨(f ^ a) x, mem_support.mp hfa, ?_⟩
simp only [pow_sub _ hab, Equiv.Perm.coe_mul, Function.comp_apply, inv_apply_self, ← hx']
· have h := @Equiv.Perm.zpow_apply_comm _ f 1 a x
simp only [zpow_one, zpow_natCast] at h
rw [not_mem_support, h, Function.Injective.eq_iff (f ^ a).injective] at hfa
contradiction
theorem IsCycle.isCycle_pow_pos_of_lt_prime_order [Finite β] {f : Perm β} (hf : IsCycle f)
(hf' : (orderOf f).Prime) (n : ℕ) (hn : 0 < n) (hn' : n < orderOf f) : IsCycle (f ^ n) := by
classical
cases nonempty_fintype β
have : n.Coprime (orderOf f) := by
refine Nat.Coprime.symm ?_
rw [Nat.Prime.coprime_iff_not_dvd hf']
exact Nat.not_dvd_of_pos_of_lt hn hn'
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime this
have hf'' := hf
rw [← hm] at hf''
refine hf''.of_pow ?_
rw [hm]
exact support_pow_le f n
end IsCycle
open Equiv
theorem _root_.Int.addLeft_one_isCycle : (Equiv.addLeft 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
theorem _root_.Int.addRight_one_isCycle : (Equiv.addRight 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
section Conjugation
variable [Fintype α] [DecidableEq α] {σ τ : Perm α}
theorem IsCycle.isConj (hσ : IsCycle σ) (hτ : IsCycle τ) (h : #σ.support = #τ.support) :
IsConj σ τ := by
refine
isConj_of_support_equiv
(hσ.zpowersEquivSupport.symm.trans <|
(zpowersEquivZPowers <| by rw [hσ.orderOf, h, hτ.orderOf]).trans hτ.zpowersEquivSupport)
?_
intro x hx
simp only [Perm.mul_apply, Equiv.trans_apply, Equiv.sumCongr_apply]
obtain ⟨n, rfl⟩ := hσ.exists_pow_eq (Classical.choose_spec hσ).1 (mem_support.1 hx)
simp [← Perm.mul_apply, ← pow_succ']
theorem IsCycle.isConj_iff (hσ : IsCycle σ) (hτ : IsCycle τ) :
IsConj σ τ ↔ #σ.support = #τ.support where
mp h := by
obtain ⟨π, rfl⟩ := (_root_.isConj_iff).1 h
refine Finset.card_bij (fun a _ => π a) (fun _ ha => ?_) (fun _ _ _ _ ab => π.injective ab)
fun b hb ↦ ⟨π⁻¹ b, ?_, π.apply_inv_self b⟩
· simp [mem_support.1 ha]
contrapose! hb
rw [mem_support, Classical.not_not] at hb
rw [mem_support, Classical.not_not, Perm.mul_apply, Perm.mul_apply, hb, Perm.apply_inv_self]
mpr := hσ.isConj hτ
end Conjugation
/-! ### `IsCycleOn` -/
section IsCycleOn
variable {f g : Perm α} {s t : Set α} {a b x y : α}
/-- A permutation is a cycle on `s` when any two points of `s` are related by repeated application
of the permutation. Note that this means the identity is a cycle of subsingleton sets. -/
def IsCycleOn (f : Perm α) (s : Set α) : Prop :=
Set.BijOn f s s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → f.SameCycle x y
@[simp]
theorem isCycleOn_empty : f.IsCycleOn ∅ := by simp [IsCycleOn, Set.bijOn_empty]
@[simp]
theorem isCycleOn_one : (1 : Perm α).IsCycleOn s ↔ s.Subsingleton := by
simp [IsCycleOn, Set.bijOn_id, Set.Subsingleton]
alias ⟨IsCycleOn.subsingleton, _root_.Set.Subsingleton.isCycleOn_one⟩ := isCycleOn_one
@[simp]
theorem isCycleOn_singleton : f.IsCycleOn {a} ↔ f a = a := by simp [IsCycleOn, SameCycle.rfl]
theorem isCycleOn_of_subsingleton [Subsingleton α] (f : Perm α) (s : Set α) : f.IsCycleOn s :=
⟨s.bijOn_of_subsingleton _, fun x _ y _ => (Subsingleton.elim x y).sameCycle _⟩
@[simp]
theorem isCycleOn_inv : f⁻¹.IsCycleOn s ↔ f.IsCycleOn s := by
simp only [IsCycleOn, sameCycle_inv, and_congr_left_iff]
exact fun _ ↦ ⟨fun h ↦ Set.BijOn.perm_inv h, fun h ↦ Set.BijOn.perm_inv h⟩
alias ⟨IsCycleOn.of_inv, IsCycleOn.inv⟩ := isCycleOn_inv
theorem IsCycleOn.conj (h : f.IsCycleOn s) : (g * f * g⁻¹).IsCycleOn ((g : Perm α) '' s) :=
⟨(g.bijOn_image.comp h.1).comp g.bijOn_symm_image, fun x hx y hy => by
rw [← preimage_inv] at hx hy
convert Equiv.Perm.SameCycle.conj (h.2 hx hy) (g := g) <;> rw [apply_inv_self]⟩
theorem isCycleOn_swap [DecidableEq α] (hab : a ≠ b) : (swap a b).IsCycleOn {a, b} :=
⟨bijOn_swap (by simp) (by simp), fun x hx y hy => by
rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hx hy
obtain rfl | rfl := hx <;> obtain rfl | rfl := hy
· exact ⟨0, by rw [zpow_zero, coe_one, id]⟩
· exact ⟨1, by rw [zpow_one, swap_apply_left]⟩
· exact ⟨1, by rw [zpow_one, swap_apply_right]⟩
· exact ⟨0, by rw [zpow_zero, coe_one, id]⟩⟩
protected theorem IsCycleOn.apply_ne (hf : f.IsCycleOn s) (hs : s.Nontrivial) (ha : a ∈ s) :
f a ≠ a := by
obtain ⟨b, hb, hba⟩ := hs.exists_ne a
obtain ⟨n, rfl⟩ := hf.2 ha hb
exact fun h => hba (IsFixedPt.perm_zpow h n)
protected theorem IsCycle.isCycleOn (hf : f.IsCycle) : f.IsCycleOn { x | f x ≠ x } :=
⟨f.bijOn fun _ => f.apply_eq_iff_eq.not, fun _ ha _ => hf.sameCycle ha⟩
/-- This lemma demonstrates the relation between `Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn`
in non-degenerate cases. -/
theorem isCycle_iff_exists_isCycleOn :
f.IsCycle ↔ ∃ s : Set α, s.Nontrivial ∧ f.IsCycleOn s ∧ ∀ ⦃x⦄, ¬IsFixedPt f x → x ∈ s := by
refine ⟨fun hf => ⟨{ x | f x ≠ x }, ?_, hf.isCycleOn, fun _ => id⟩, ?_⟩
· obtain ⟨a, ha⟩ := hf
exact ⟨f a, f.injective.ne ha.1, a, ha.1, ha.1⟩
· rintro ⟨s, hs, hf, hsf⟩
obtain ⟨a, ha⟩ := hs.nonempty
exact ⟨a, hf.apply_ne hs ha, fun b hb => hf.2 ha <| hsf hb⟩
theorem IsCycleOn.apply_mem_iff (hf : f.IsCycleOn s) : f x ∈ s ↔ x ∈ s :=
⟨fun hx => by
convert hf.1.perm_inv.1 hx
rw [inv_apply_self], fun hx => hf.1.mapsTo hx⟩
/-- Note that the identity satisfies `IsCycleOn` for any subsingleton set, but not `IsCycle`. -/
theorem IsCycleOn.isCycle_subtypePerm (hf : f.IsCycleOn s) (hs : s.Nontrivial) :
(f.subtypePerm fun _ => hf.apply_mem_iff.symm : Perm s).IsCycle := by
obtain ⟨a, ha⟩ := hs.nonempty
exact
⟨⟨a, ha⟩, ne_of_apply_ne ((↑) : s → α) (hf.apply_ne hs ha), fun b _ =>
(hf.2 (⟨a, ha⟩ : s).2 b.2).subtypePerm⟩
/-- Note that the identity is a cycle on any subsingleton set, but not a cycle. -/
protected theorem IsCycleOn.subtypePerm (hf : f.IsCycleOn s) :
(f.subtypePerm fun _ => hf.apply_mem_iff.symm : Perm s).IsCycleOn _root_.Set.univ := by
obtain hs | hs := s.subsingleton_or_nontrivial
· haveI := hs.coe_sort
exact isCycleOn_of_subsingleton _ _
convert (hf.isCycle_subtypePerm hs).isCycleOn
rw [eq_comm, Set.eq_univ_iff_forall]
exact fun x => ne_of_apply_ne ((↑) : s → α) (hf.apply_ne hs x.2)
-- TODO: Theory of order of an element under an action
theorem IsCycleOn.pow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) {n : ℕ} :
(f ^ n) a = a ↔ #s ∣ n := by
obtain rfl | hs := Finset.eq_singleton_or_nontrivial ha
· rw [coe_singleton, isCycleOn_singleton] at hf
simpa using IsFixedPt.iterate hf n
classical
have h (x : s) : ¬f x = x := hf.apply_ne hs x.2
have := (hf.isCycle_subtypePerm hs).orderOf
simp only [coe_sort_coe, support_subtype_perm, ne_eq, h, not_false_eq_true, univ_eq_attach,
mem_attach, imp_self, implies_true, filter_true_of_mem, card_attach] at this
rw [← this, orderOf_dvd_iff_pow_eq_one,
(hf.isCycle_subtypePerm hs).pow_eq_one_iff'
(ne_of_apply_ne ((↑) : s → α) <| hf.apply_ne hs (⟨a, ha⟩ : s).2)]
simp [-coe_sort_coe]
theorem IsCycleOn.zpow_apply_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) :
∀ {n : ℤ}, (f ^ n) a = a ↔ (#s : ℤ) ∣ n
| Int.ofNat _ => (hf.pow_apply_eq ha).trans Int.natCast_dvd_natCast.symm
| Int.negSucc n => by
rw [zpow_negSucc, ← inv_pow]
exact (hf.inv.pow_apply_eq ha).trans (dvd_neg.trans Int.natCast_dvd_natCast).symm
theorem IsCycleOn.pow_apply_eq_pow_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s)
{m n : ℕ} : (f ^ m) a = (f ^ n) a ↔ m ≡ n [MOD #s] := by
rw [Nat.modEq_iff_dvd, ← hf.zpow_apply_eq ha]
simp [sub_eq_neg_add, zpow_add, eq_inv_iff_eq, eq_comm]
theorem IsCycleOn.zpow_apply_eq_zpow_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s)
{m n : ℤ} : (f ^ m) a = (f ^ n) a ↔ m ≡ n [ZMOD #s] := by
rw [Int.modEq_iff_dvd, ← hf.zpow_apply_eq ha]
simp [sub_eq_neg_add, zpow_add, eq_inv_iff_eq, eq_comm]
theorem IsCycleOn.pow_card_apply {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) :
(f ^ #s) a = a :=
(hf.pow_apply_eq ha).2 dvd_rfl
theorem IsCycleOn.exists_pow_eq {s : Finset α} (hf : f.IsCycleOn s) (ha : a ∈ s) (hb : b ∈ s) :
∃ n < #s, (f ^ n) a = b := by
classical
obtain ⟨n, rfl⟩ := hf.2 ha hb
obtain ⟨k, hk⟩ := (Int.mod_modEq n #s).symm.dvd
refine ⟨n.natMod #s, Int.natMod_lt (Nonempty.card_pos ⟨a, ha⟩).ne', ?_⟩
rw [← zpow_natCast, Int.natMod,
Int.toNat_of_nonneg (Int.emod_nonneg _ <| Nat.cast_ne_zero.2
(Nonempty.card_pos ⟨a, ha⟩).ne'), sub_eq_iff_eq_add'.1 hk, zpow_add, zpow_mul]
simp only [zpow_natCast, coe_mul, comp_apply, EmbeddingLike.apply_eq_iff_eq]
exact IsFixedPt.perm_zpow (hf.pow_card_apply ha) _
theorem IsCycleOn.exists_pow_eq' (hs : s.Finite) (hf : f.IsCycleOn s) (ha : a ∈ s) (hb : b ∈ s) :
∃ n : ℕ, (f ^ n) a = b := by
lift s to Finset α using id hs
obtain ⟨n, -, hn⟩ := hf.exists_pow_eq ha hb
exact ⟨n, hn⟩
theorem IsCycleOn.range_pow (hs : s.Finite) (h : f.IsCycleOn s) (ha : a ∈ s) :
Set.range (fun n => (f ^ n) a : ℕ → α) = s :=
Set.Subset.antisymm (Set.range_subset_iff.2 fun _ => h.1.mapsTo.perm_pow _ ha) fun _ =>
h.exists_pow_eq' hs ha
theorem IsCycleOn.range_zpow (h : f.IsCycleOn s) (ha : a ∈ s) :
Set.range (fun n => (f ^ n) a : ℤ → α) = s :=
Set.Subset.antisymm (Set.range_subset_iff.2 fun _ => (h.1.perm_zpow _).mapsTo ha) <| h.2 ha
theorem IsCycleOn.of_pow {n : ℕ} (hf : (f ^ n).IsCycleOn s) (h : Set.BijOn f s s) : f.IsCycleOn s :=
⟨h, fun _ hx _ hy => (hf.2 hx hy).of_pow⟩
theorem IsCycleOn.of_zpow {n : ℤ} (hf : (f ^ n).IsCycleOn s) (h : Set.BijOn f s s) :
f.IsCycleOn s :=
⟨h, fun _ hx _ hy => (hf.2 hx hy).of_zpow⟩
theorem IsCycleOn.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p)
(h : g.IsCycleOn s) : (g.extendDomain f).IsCycleOn ((↑) ∘ f '' s) :=
⟨h.1.extendDomain, by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
exact (h.2 ha hb).extendDomain⟩
protected theorem IsCycleOn.countable (hs : f.IsCycleOn s) : s.Countable := by
obtain rfl | ⟨a, ha⟩ := s.eq_empty_or_nonempty
· exact Set.countable_empty
· exact (Set.countable_range fun n : ℤ => (⇑(f ^ n) : α → α) a).mono (hs.2 ha)
end IsCycleOn
end Equiv.Perm
namespace List
section
variable [DecidableEq α] {l : List α}
theorem Nodup.isCycleOn_formPerm (h : l.Nodup) :
l.formPerm.IsCycleOn { a | a ∈ l } := by
refine ⟨l.formPerm.bijOn fun _ => List.formPerm_mem_iff_mem, fun a ha b hb => ?_⟩
rw [Set.mem_setOf, ← List.idxOf_lt_length_iff] at ha hb
rw [← List.getElem_idxOf ha, ← List.getElem_idxOf hb]
refine ⟨l.idxOf b - l.idxOf a, ?_⟩
simp only [sub_eq_neg_add, zpow_add, zpow_neg, Equiv.Perm.inv_eq_iff_eq, zpow_natCast,
Equiv.Perm.coe_mul, List.formPerm_pow_apply_getElem _ h, Function.comp]
rw [add_comm]
end
end List
namespace Finset
variable [DecidableEq α] [Fintype α]
theorem exists_cycleOn (s : Finset α) :
∃ f : Perm α, f.IsCycleOn s ∧ f.support ⊆ s := by
refine ⟨s.toList.formPerm, ?_, fun x hx => by
simpa using List.mem_of_formPerm_apply_ne (Perm.mem_support.1 hx)⟩
convert s.nodup_toList.isCycleOn_formPerm
simp
end Finset
namespace Set
variable {f : Perm α} {s : Set α}
theorem Countable.exists_cycleOn (hs : s.Countable) :
∃ f : Perm α, f.IsCycleOn s ∧ { x | f x ≠ x } ⊆ s := by
classical
obtain hs' | hs' := s.finite_or_infinite
· refine ⟨hs'.toFinset.toList.formPerm, ?_, fun x hx => by
simpa using List.mem_of_formPerm_apply_ne hx⟩
convert hs'.toFinset.nodup_toList.isCycleOn_formPerm
simp
· haveI := hs.to_subtype
haveI := hs'.to_subtype
obtain ⟨f⟩ : Nonempty (ℤ ≃ s) := inferInstance
refine ⟨(Equiv.addRight 1).extendDomain f, ?_, fun x hx =>
of_not_not fun h => hx <| Perm.extendDomain_apply_not_subtype _ _ h⟩
convert Int.addRight_one_isCycle.isCycleOn.extendDomain f
rw [Set.image_comp, Equiv.image_eq_preimage]
ext
simp
theorem prod_self_eq_iUnion_perm (hf : f.IsCycleOn s) :
| s ×ˢ s = ⋃ n : ℤ, (fun a => (a, (f ^ n) a)) '' s := by
ext ⟨a, b⟩
simp only [Set.mem_prod, Set.mem_iUnion, Set.mem_image]
refine ⟨fun hx => ?_, ?_⟩
· obtain ⟨n, rfl⟩ := hf.2 hx.1 hx.2
exact ⟨_, _, hx.1, rfl⟩
| Mathlib/GroupTheory/Perm/Cycle/Basic.lean | 900 | 905 |
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Projection
import Mathlib.Analysis.Normed.Lp.lpSpace
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Hilbert sum of a family of inner product spaces
Given a family `(G : ι → Type*) [Π i, InnerProductSpace 𝕜 (G i)]` of inner product spaces, this
file equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those
dependent functions `f : Π i, G i` for which `∑' i, ‖f i‖ ^ 2`, the sum of the norms-squared, is
summable. This construction is sometimes called the *Hilbert sum* of the family `G`. By choosing
`G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction.
We also define a *predicate* `IsHilbertSum 𝕜 G V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that
`V` is an `OrthogonalFamily` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective.
## Main definitions
* `OrthogonalFamily.linearIsometry`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with
mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G`
into `E`.
* `IsHilbertSum`: Given a Hilbert space `E`, a family `G` of inner product
spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`,
`IsHilbertSum 𝕜 G V` means that `V` is an `OrthogonalFamily` and that the above
linear isometry is surjective.
* `IsHilbertSum.linearIsometryEquiv`: If a Hilbert space `E` is a Hilbert sum of the
inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the
corresponding `OrthogonalFamily.linearIsometry` can be upgraded to a `LinearIsometryEquiv`.
* `HilbertBasis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single
field `HilbertBasis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert
sum of `ι` copies of `𝕜`). This parallels the definition of `Basis`, in `LinearAlgebra.Basis`,
as an isomorphism of an `R`-module with `ι →₀ R`.
* `HilbertBasis.instCoeFun`: More conventionally a Hilbert basis is thought of as a family
`ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness). We obtain
this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image
under `b.repr` of `lp.single 2 i (1:𝕜)`. This parallels the definition `Basis.coeFun` in
`LinearAlgebra.Basis`.
* `HilbertBasis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors
in `E` whose span is dense. This parallels the definition `Basis.mk` in `LinearAlgebra.Basis`.
* `HilbertBasis.mkOfOrthogonalEqBot`: Make a Hilbert basis of `E` from an orthonormal family
`v : ι → E` of vectors in `E` whose span has trivial orthogonal complement.
## Main results
* `lp.instInnerProductSpace`: Construction of the inner product space instance on the Hilbert sum
`lp G 2`. Note that from the file `Analysis.Normed.Lp.lpSpace`, the space `lp G 2` already
held a normed space instance (`lp.normedSpace`), and if each `G i` is a Hilbert space (i.e.,
complete), then `lp G 2` was already known to be complete (`lp.completeSpace`). So the work
here is to define the inner product and show it is compatible.
* `OrthogonalFamily.range_linearIsometry`: Given a family `G` of inner product spaces and a family
`V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal
images, the image of the embedding `OrthogonalFamily.linearIsometry` of the Hilbert sum of `G`
into `E` is the closure of the span of the images of the `G i`.
* `HilbertBasis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of
`x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`.
* `HilbertBasis.hasSum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be
expressed as the "infinite linear combination" `∑' i, b.repr x i • b i` of the basis vectors
`b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`.
* `exists_hilbertBasis`: A Hilbert space admits a Hilbert basis.
## Keywords
Hilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism
-/
open RCLike Submodule Filter
open scoped NNReal ENNReal ComplexConjugate Topology
noncomputable section
variable {ι 𝕜 : Type*} [RCLike 𝕜] {E : Type*}
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable {G : ι → Type*} [∀ i, NormedAddCommGroup (G i)] [∀ i, InnerProductSpace 𝕜 (G i)]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- `ℓ²(ι, 𝕜)` is the Hilbert space of square-summable functions `ι → 𝕜`, herein implemented
as `lp (fun i : ι => 𝕜) 2`. -/
notation "ℓ²(" ι ", " 𝕜 ")" => lp (fun i : ι => 𝕜) 2
/-! ### Inner product space structure on `lp G 2` -/
namespace lp
theorem summable_inner (f g : lp G 2) : Summable fun i => ⟪f i, g i⟫ := by
-- Apply the Direct Comparison Test, comparing with ∑' i, ‖f i‖ * ‖g i‖ (summable by Hölder)
refine .of_norm_bounded (fun i => ‖f i‖ * ‖g i‖) (lp.summable_mul ?_ f g) ?_
· rw [Real.holderConjugate_iff]; norm_num
intro i
-- Then apply Cauchy-Schwarz pointwise
exact norm_inner_le_norm (𝕜 := 𝕜) _ _
instance instInnerProductSpace : InnerProductSpace 𝕜 (lp G 2) :=
{ lp.normedAddCommGroup (E := G) (p := 2) with
inner := fun f g => ∑' i, ⟪f i, g i⟫
norm_sq_eq_re_inner := fun f => by
calc
‖f‖ ^ 2 = ‖f‖ ^ (2 : ℝ≥0∞).toReal := by norm_cast
_ = ∑' i, ‖f i‖ ^ (2 : ℝ≥0∞).toReal := lp.norm_rpow_eq_tsum ?_ f
_ = ∑' i, ‖f i‖ ^ (2 : ℕ) := by norm_cast
_ = ∑' i, re ⟪f i, f i⟫ := by simp [norm_sq_eq_re_inner (𝕜 := 𝕜)]
_ = re (∑' i, ⟪f i, f i⟫) := (RCLike.reCLM.map_tsum ?_).symm
· norm_num
· exact summable_inner f f
conj_inner_symm := fun f g => by
calc
conj _ = conj (∑' i, ⟪g i, f i⟫) := by congr
_ = ∑' i, conj ⟪g i, f i⟫ := RCLike.conjCLE.map_tsum
_ = ∑' i, ⟪f i, g i⟫ := by simp only [inner_conj_symm]
_ = _ := by congr
add_left := fun f₁ f₂ g => by
calc
_ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ := ?_
_ = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) := by
simp only [inner_add_left, Pi.add_apply, coeFn_add]
_ = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ := Summable.tsum_add ?_ ?_
_ = _ := by congr
· congr
· exact summable_inner f₁ g
· exact summable_inner f₂ g
smul_left := fun f g c => by
calc
_ = ∑' i, ⟪c • f i, g i⟫ := ?_
_ = ∑' i, conj c * ⟪f i, g i⟫ := by simp only [inner_smul_left]
_ = conj c * ∑' i, ⟪f i, g i⟫ := tsum_mul_left
_ = _ := ?_
· simp only [coeFn_smul, Pi.smul_apply]
· congr }
theorem inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ :=
rfl
theorem hasSum_inner (f g : lp G 2) : HasSum (fun i => ⟪f i, g i⟫) ⟪f, g⟫ :=
(summable_inner f g).hasSum
theorem inner_single_left [DecidableEq ι] (i : ι) (a : G i) (f : lp G 2) :
⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ := by
refine (hasSum_inner (lp.single 2 i a) f).unique ?_
simp_rw [lp.coeFn_single]
convert hasSum_ite_eq i ⟪a, f i⟫ using 1
ext j
split_ifs with h
· subst h; rw [Pi.single_eq_same]
· simp [Pi.single_eq_of_ne h]
theorem inner_single_right [DecidableEq ι] (i : ι) (a : G i) (f : lp G 2) :
| ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ := by
simpa [inner_conj_symm] using congr_arg conj (inner_single_left (𝕜 := 𝕜) i a f)
end lp
/-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/
| Mathlib/Analysis/InnerProductSpace/l2Space.lean | 164 | 171 |
/-
Copyright (c) 2021 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno
-/
import Mathlib.CategoryTheory.NatIso
/-!
# Bicategories
In this file we define typeclass for bicategories.
A bicategory `B` consists of
* objects `a : B`,
* 1-morphisms `f : a ⟶ b` between objects `a b : B`, and
* 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`.
We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms,
respectively.
A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that
we have
* a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and
* an identity `𝟙 a : a ⟶ a` for each object `a : B`.
For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The
2-morphisms in the bicategory are implemented as the morphisms in this family of categories.
The composition of 1-morphisms is in fact an object part of a functor
`(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not
require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism
`f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a
2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g`
between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism
`whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law
`whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`,
which is required as an axiom in the definition here.
-/
namespace CategoryTheory
universe w v u
open Category Iso
-- intended to be used with explicit universe parameters
/-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain
a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative,
but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`.
There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor
isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`.
These associators and unitors satisfy the pentagon and triangle equations.
See https://ncatlab.org/nlab/show/bicategory.
-/
@[nolint checkUnivs]
class Bicategory (B : Type u) extends CategoryStruct.{v} B where
/-- The category structure on the collection of 1-morphisms -/
homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance
/-- Left whiskering for morphisms -/
whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h
/-- Right whiskering for morphisms -/
whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h
/-- The associator isomorphism: `(f ≫ g) ≫ h ≅ f ≫ g ≫ h` -/
associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h
/-- The left unitor: `𝟙 a ≫ f ≅ f` -/
leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f
/-- The right unitor: `f ≫ 𝟙 b ≅ f` -/
rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f
-- axioms for left whiskering:
whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by
aesop_cat
whiskerLeft_comp :
∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i),
whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by
aesop_cat
id_whiskerLeft :
∀ {a b} {f g : a ⟶ b} (η : f ⟶ g),
whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by
aesop_cat
comp_whiskerLeft :
∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'),
whiskerLeft (f ≫ g) η =
(associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by
aesop_cat
-- axioms for right whiskering:
id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by
aesop_cat
comp_whiskerRight :
∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c),
whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by
aesop_cat
whiskerRight_id :
∀ {a b} {f g : a ⟶ b} (η : f ⟶ g),
whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by
aesop_cat
whiskerRight_comp :
∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d),
whiskerRight η (g ≫ h) =
(associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by
aesop_cat
-- associativity of whiskerings:
whisker_assoc :
∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d),
whiskerRight (whiskerLeft f η) h =
(associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by
aesop_cat
-- exchange law of left and right whiskerings:
whisker_exchange :
∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i),
whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by
aesop_cat
-- pentagon identity:
pentagon :
∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e),
whiskerRight (associator f g h).hom i ≫
(associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom =
(associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by
aesop_cat
-- triangle identity:
triangle :
∀ {a b c} (f : a ⟶ b) (g : b ⟶ c),
(associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom
= whiskerRight (rightUnitor f).hom g := by
aesop_cat
namespace Bicategory
@[inherit_doc] scoped infixr:81 " ◁ " => Bicategory.whiskerLeft
@[inherit_doc] scoped infixl:81 " ▷ " => Bicategory.whiskerRight
@[inherit_doc] scoped notation "α_" => Bicategory.associator
@[inherit_doc] scoped notation "λ_" => Bicategory.leftUnitor
@[inherit_doc] scoped notation "ρ_" => Bicategory.rightUnitor
/-!
### Simp-normal form for 2-morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal
form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming)
`coherence` tactic.
The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is
either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors)
or non-structural 2-morphisms, and
2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`,
where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a
non-structural 2-morphisms that is also not the identity or a composite.
Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`.
-/
attribute [instance] homCategory
attribute [reassoc]
whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id
whiskerRight_comp whisker_assoc whisker_exchange
attribute [reassoc (attr := simp)] pentagon triangle
/-
The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There
are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`),
which at first glance look more complicated than the LHS, but they will be eventually reduced by
the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic.
-/
attribute [simp]
whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight
whiskerRight_id whiskerRight_comp whisker_assoc
variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B}
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) :
f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) :
η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) :
f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) :
η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight]
/-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/
@[simps]
def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where
hom := f ◁ η.hom
inv := f ◁ η.inv
instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) :=
(whiskerLeftIso f (asIso η)).isIso_hom
@[simp]
theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] :
inv (f ◁ η) = f ◁ inv η := by
apply IsIso.inv_eq_of_hom_inv_id
simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id]
/-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/
@[simps!]
def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where
hom := η.hom ▷ h
inv := η.inv ▷ h
instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) :=
(whiskerRightIso (asIso η) h).isIso_hom
@[simp]
theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] :
inv (η ▷ h) = inv η ▷ h := by
apply IsIso.inv_eq_of_hom_inv_id
simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id]
@[reassoc (attr := simp)]
theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i =
(α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom =
f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by
rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv]
simp
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom =
(α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv =
(α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by
simp [← cancel_epi (f ◁ (α_ g h i).inv)]
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv =
(α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv =
(α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by
rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)]
simp
@[reassoc (attr := simp)]
theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv =
(α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom :=
eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)]
theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom =
(α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by
simp [← cancel_epi ((α_ f g h).hom ▷ i)]
@[reassoc (attr := simp)]
theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
(α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i =
f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv :=
eq_of_inv_eq_inv (by simp)
theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) :
(α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g :=
triangle f g
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) :
(α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc]
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) :
(ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by
simp [← cancel_mono (f ◁ (λ_ g).hom)]
@[reassoc (attr := simp)]
theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) :
f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by
simp [← cancel_mono ((ρ_ f).hom ▷ g)]
@[reassoc]
theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) :
η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp
@[reassoc]
theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) :
η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp
@[reassoc]
theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) :
η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp
@[reassoc]
theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) :
(f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp
@[reassoc]
theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) :
f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp
@[reassoc]
theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) :
f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp
@[reassoc]
theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') :
(f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp
@[reassoc]
theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') :
f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp
@[reassoc]
theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') :
f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp
@[reassoc]
theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) :
𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by
simp
@[reassoc]
theorem leftUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) :
η ≫ (λ_ g).inv = (λ_ f).inv ≫ 𝟙 a ◁ η := by simp
theorem id_whiskerLeft_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (λ_ f).inv ≫ 𝟙 a ◁ η ≫ (λ_ g).hom := by
simp
@[reassoc]
theorem rightUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) :
η ▷ 𝟙 b ≫ (ρ_ g).hom = (ρ_ f).hom ≫ η := by simp
@[reassoc]
theorem rightUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) :
η ≫ (ρ_ g).inv = (ρ_ f).inv ≫ η ▷ 𝟙 b := by simp
theorem whiskerRight_id_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (ρ_ f).inv ≫ η ▷ 𝟙 b ≫ (ρ_ g).hom := by
simp
theorem whiskerLeft_iff {f g : a ⟶ b} (η θ : f ⟶ g) : 𝟙 a ◁ η = 𝟙 a ◁ θ ↔ η = θ := by simp
theorem whiskerRight_iff {f g : a ⟶ b} (η θ : f ⟶ g) : η ▷ 𝟙 b = θ ▷ 𝟙 b ↔ η = θ := by simp
/-- We state it as a simp lemma, which is regarded as an involved version of
`id_whiskerRight f g : 𝟙 f ▷ g = 𝟙 (f ≫ g)`.
-/
@[reassoc, simp]
theorem leftUnitor_whiskerRight (f : a ⟶ b) (g : b ⟶ c) :
(λ_ f).hom ▷ g = (α_ (𝟙 a) f g).hom ≫ (λ_ (f ≫ g)).hom := by
rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ←
cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ←
comp_whiskerRight_assoc, triangle, associator_naturality_left]
@[reassoc, simp]
theorem leftUnitor_inv_whiskerRight (f : a ⟶ b) (g : b ⟶ c) :
(λ_ f).inv ▷ g = (λ_ (f ≫ g)).inv ≫ (α_ (𝟙 a) f g).inv :=
eq_of_inv_eq_inv (by simp)
@[reassoc, simp]
theorem whiskerLeft_rightUnitor (f : a ⟶ b) (g : b ⟶ c) :
f ◁ (ρ_ g).hom = (α_ f g (𝟙 c)).inv ≫ (ρ_ (f ≫ g)).hom := by
rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ←
cancel_epi (f ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ←
associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right,
associator_inv_naturality_right]
@[reassoc, simp]
theorem whiskerLeft_rightUnitor_inv (f : a ⟶ b) (g : b ⟶ c) :
f ◁ (ρ_ g).inv = (ρ_ (f ≫ g)).inv ≫ (α_ f g (𝟙 c)).hom :=
eq_of_inv_eq_inv (by simp)
/-
It is not so obvious whether `leftUnitor_whiskerRight` or `leftUnitor_comp` should be a simp
lemma. Our choice is the former. One reason is that the latter yields the following loop:
[id_whiskerLeft] : 𝟙 a ◁ (ρ_ f).hom ==> (λ_ (f ≫ 𝟙 b)).hom ≫ (ρ_ f).hom ≫ (λ_ f).inv
[leftUnitor_comp] : (λ_ (f ≫ 𝟙 b)).hom ==> (α_ (𝟙 a) f (𝟙 b)).inv ≫ (λ_ f).hom ▷ 𝟙 b
[whiskerRight_id] : (λ_ f).hom ▷ 𝟙 b ==> (ρ_ (𝟙 a ≫ f)).hom ≫ (λ_ f).hom ≫ (ρ_ f).inv
[rightUnitor_comp] : (ρ_ (𝟙 a ≫ f)).hom ==> (α_ (𝟙 a) f (𝟙 b)).hom ≫ 𝟙 a ◁ (ρ_ f).hom
-/
@[reassoc]
theorem leftUnitor_comp (f : a ⟶ b) (g : b ⟶ c) :
(λ_ (f ≫ g)).hom = (α_ (𝟙 a) f g).inv ≫ (λ_ f).hom ▷ g := by simp
@[reassoc]
theorem leftUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) :
(λ_ (f ≫ g)).inv = (λ_ f).inv ▷ g ≫ (α_ (𝟙 a) f g).hom := by simp
@[reassoc]
theorem rightUnitor_comp (f : a ⟶ b) (g : b ⟶ c) :
(ρ_ (f ≫ g)).hom = (α_ f g (𝟙 c)).hom ≫ f ◁ (ρ_ g).hom := by simp
@[reassoc]
theorem rightUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) :
(ρ_ (f ≫ g)).inv = f ◁ (ρ_ g).inv ≫ (α_ f g (𝟙 c)).inv := by simp
@[simp]
theorem unitors_equal : (λ_ (𝟙 a)).hom = (ρ_ (𝟙 a)).hom := by
rw [← whiskerLeft_iff, ← cancel_epi (α_ _ _ _).hom, ← cancel_mono (ρ_ _).hom, triangle, ←
rightUnitor_comp, rightUnitor_naturality]
@[simp]
theorem unitors_inv_equal : (λ_ (𝟙 a)).inv = (ρ_ (𝟙 a)).inv := by simp [Iso.inv_eq_inv]
section
attribute [local simp] whisker_exchange
/-- Precomposition of a 1-morphism as a functor. -/
@[simps]
def precomp (c : B) (f : a ⟶ b) : (b ⟶ c) ⥤ (a ⟶ c) where
obj := (f ≫ ·)
map := (f ◁ ·)
/-- Precomposition of a 1-morphism as a functor from the category of 1-morphisms `a ⟶ b` into the
category of functors `(b ⟶ c) ⥤ (a ⟶ c)`. -/
@[simps]
def precomposing (a b c : B) : (a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c) where
obj f := precomp c f
map η := { app := (η ▷ ·) }
/-- Postcomposition of a 1-morphism as a functor. -/
| @[simps]
def postcomp (a : B) (f : b ⟶ c) : (a ⟶ b) ⥤ (a ⟶ c) where
obj := (· ≫ f)
map := (· ▷ f)
/-- Postcomposition of a 1-morphism as a functor from the category of 1-morphisms `b ⟶ c` into the
| Mathlib/CategoryTheory/Bicategory/Basic.lean | 436 | 441 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.List.Prime
import Mathlib.Data.List.Sort
import Mathlib.Data.List.Perm.Subperm
/-!
# Prime numbers
This file deals with the factors of natural numbers.
## Important declarations
- `Nat.factors n`: the prime factorization of `n`
- `Nat.factors_unique`: uniqueness of the prime factorisation
-/
assert_not_exists Multiset
open Bool Subtype
open Nat
namespace Nat
/-- `primeFactorsList n` is the prime factorization of `n`, listed in increasing order. -/
def primeFactorsList : ℕ → List ℕ
| 0 => []
| 1 => []
| k + 2 =>
let m := minFac (k + 2)
m :: primeFactorsList ((k + 2) / m)
decreasing_by exact factors_lemma
@[simp]
theorem primeFactorsList_zero : primeFactorsList 0 = [] := by rw [primeFactorsList]
@[simp]
theorem primeFactorsList_one : primeFactorsList 1 = [] := by rw [primeFactorsList]
@[simp]
theorem primeFactorsList_two : primeFactorsList 2 = [2] := by simp [primeFactorsList]
theorem prime_of_mem_primeFactorsList {n : ℕ} : ∀ {p : ℕ}, p ∈ primeFactorsList n → Prime p := by
match n with
| 0 => simp
| 1 => simp
| k + 2 =>
intro p h
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
have h₁ : p = m ∨ p ∈ primeFactorsList ((k + 2) / m) :=
List.mem_cons.1 (by rwa [primeFactorsList] at h)
exact Or.casesOn h₁ (fun h₂ => h₂.symm ▸ minFac_prime (by simp)) prime_of_mem_primeFactorsList
theorem pos_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ primeFactorsList n) : 0 < p :=
Prime.pos (prime_of_mem_primeFactorsList h)
theorem prod_primeFactorsList : ∀ {n}, n ≠ 0 → List.prod (primeFactorsList n) = n
| 0 => by simp
| 1 => by simp
| k + 2 => fun _ =>
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
show (primeFactorsList (k + 2)).prod = (k + 2) by
have h₁ : (k + 2) / m ≠ 0 := fun h => by
have : (k + 2) = 0 * m := (Nat.div_eq_iff_eq_mul_left (minFac_pos _) (minFac_dvd _)).1 h
rw [zero_mul] at this; exact (show k + 2 ≠ 0 by simp) this
rw [primeFactorsList, List.prod_cons, prod_primeFactorsList h₁,
Nat.mul_div_cancel' (minFac_dvd _)]
theorem primeFactorsList_prime {p : ℕ} (hp : Nat.Prime p) : p.primeFactorsList = [p] := by
have : p = p - 2 + 2 := Nat.eq_add_of_sub_eq hp.two_le rfl
rw [this, primeFactorsList]
simp only [Eq.symm this]
have : Nat.minFac p = p := (Nat.prime_def_minFac.mp hp).2
simp only [this, primeFactorsList, Nat.div_self (Nat.Prime.pos hp)]
theorem primeFactorsList_chain {n : ℕ} :
∀ {a}, (∀ p, Prime p → p ∣ n → a ≤ p) → List.Chain (· ≤ ·) a (primeFactorsList n) := by
match n with
| 0 => simp
| 1 => simp
| k + 2 =>
intro a h
let m := minFac (k + 2)
have : (k + 2) / m < (k + 2) := factors_lemma
rw [primeFactorsList]
refine List.Chain.cons ((le_minFac.2 h).resolve_left (by simp)) (primeFactorsList_chain ?_)
exact fun p pp d => minFac_le_of_dvd pp.two_le (d.trans <| div_dvd_of_dvd <| minFac_dvd _)
theorem primeFactorsList_chain_2 (n) : List.Chain (· ≤ ·) 2 (primeFactorsList n) :=
primeFactorsList_chain fun _ pp _ => pp.two_le
theorem primeFactorsList_chain' (n) : List.Chain' (· ≤ ·) (primeFactorsList n) :=
@List.Chain'.tail _ _ (_ :: _) (primeFactorsList_chain_2 _)
theorem primeFactorsList_sorted (n : ℕ) : List.Sorted (· ≤ ·) (primeFactorsList n) :=
List.chain'_iff_pairwise.1 (primeFactorsList_chain' _)
/-- `primeFactorsList` can be constructed inductively by extracting `minFac`, for sufficiently
large `n`. -/
theorem primeFactorsList_add_two (n : ℕ) :
primeFactorsList (n + 2) = minFac (n + 2) :: primeFactorsList ((n + 2) / minFac (n + 2)) := by
rw [primeFactorsList]
@[simp]
theorem primeFactorsList_eq_nil (n : ℕ) : n.primeFactorsList = [] ↔ n = 0 ∨ n = 1 := by
constructor <;> intro h
· rcases n with (_ | _ | n)
· exact Or.inl rfl
· exact Or.inr rfl
· rw [primeFactorsList] at h
injection h
· rcases h with (rfl | rfl)
· exact primeFactorsList_zero
· exact primeFactorsList_one
open scoped List in
theorem eq_of_perm_primeFactorsList {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0)
(h : a.primeFactorsList ~ b.primeFactorsList) : a = b := by
simpa [prod_primeFactorsList ha, prod_primeFactorsList hb] using List.Perm.prod_eq h
section
open List
theorem mem_primeFactorsList_iff_dvd {n p : ℕ} (hn : n ≠ 0) (hp : Prime p) :
p ∈ primeFactorsList n ↔ p ∣ n where
mp h := prod_primeFactorsList hn ▸ List.dvd_prod h
mpr h := mem_list_primes_of_dvd_prod (prime_iff.mp hp)
(fun _ h ↦ prime_iff.mp (prime_of_mem_primeFactorsList h)) ((prod_primeFactorsList hn).symm ▸ h)
theorem dvd_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ∣ n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· exact dvd_zero p
· rwa [← mem_primeFactorsList_iff_dvd hn.ne' (prime_of_mem_primeFactorsList h)]
theorem mem_primeFactorsList {n p} (hn : n ≠ 0) : p ∈ primeFactorsList n ↔ Prime p ∧ p ∣ n :=
⟨fun h => ⟨prime_of_mem_primeFactorsList h, dvd_of_mem_primeFactorsList h⟩, fun ⟨hprime, hdvd⟩ =>
(mem_primeFactorsList_iff_dvd hn hprime).mpr hdvd⟩
@[simp] lemma mem_primeFactorsList' {n p} : p ∈ n.primeFactorsList ↔ p.Prime ∧ p ∣ n ∧ n ≠ 0 := by
cases n <;> simp [mem_primeFactorsList, *]
theorem le_of_mem_primeFactorsList {n p : ℕ} (h : p ∈ n.primeFactorsList) : p ≤ n := by
rcases n.eq_zero_or_pos with (rfl | hn)
· rw [primeFactorsList_zero] at h
cases h
· exact le_of_dvd hn (dvd_of_mem_primeFactorsList h)
/-- **Fundamental theorem of arithmetic** -/
theorem primeFactorsList_unique {n : ℕ} {l : List ℕ} (h₁ : prod l = n) (h₂ : ∀ p ∈ l, Prime p) :
l ~ primeFactorsList n := by
refine perm_of_prod_eq_prod ?_ ?_ ?_
| · rw [h₁]
refine (prod_primeFactorsList ?_).symm
| Mathlib/Data/Nat/Factors.lean | 163 | 164 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Module.LinearMap.End
import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.Algebra.BigOperators.Group.Finset.Defs
/-!
# Linear maps involving submodules of a module
In this file we define a number of linear maps involving submodules of a module.
## Main declarations
* `Submodule.subtype`: Embedding of a submodule `p` to the ambient space `M` as a `Submodule`.
* `LinearMap.domRestrict`: The restriction of a semilinear map `f : M → M₂` to a submodule `p ⊆ M`
as a semilinear map `p → M₂`.
* `LinearMap.restrict`: The restriction of a linear map `f : M → M₁` to a submodule `p ⊆ M` and
`q ⊆ M₁` (if `q` contains the codomain).
* `Submodule.inclusion`: the inclusion `p ⊆ p'` of submodules `p` and `p'` as a linear map.
## Tags
submodule, subspace, linear map
-/
open Function Set
universe u'' u' u v w
section
variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w}
namespace SMulMemClass
variable [Semiring R] [AddCommMonoid M] [Module R M] {A : Type*} [SetLike A M]
[AddSubmonoidClass A M] [SMulMemClass A R M] (S' : A)
/-- The natural `R`-linear map from a submodule of an `R`-module `M` to `M`. -/
protected def subtype : S' →ₗ[R] M where
toFun := Subtype.val
map_add' _ _ := rfl
map_smul' _ _ := rfl
variable {S'} in
@[simp]
lemma subtype_apply (x : S') :
SMulMemClass.subtype S' x = x := rfl
lemma subtype_injective :
Function.Injective (SMulMemClass.subtype S') :=
Subtype.coe_injective
@[simp]
protected theorem coe_subtype : (SMulMemClass.subtype S' : S' → M) = Subtype.val :=
rfl
@[deprecated (since := "2025-02-18")]
protected alias coeSubtype := SMulMemClass.coe_subtype
end SMulMemClass
namespace Submodule
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M]
-- We can infer the module structure implicitly from the bundled submodule,
-- rather than via typeclass resolution.
variable {module_M : Module R M}
variable {p q : Submodule R M}
variable {r : R} {x y : M}
variable (p)
/-- Embedding of a submodule `p` to the ambient space `M`. -/
protected def subtype : p →ₗ[R] M where
toFun := Subtype.val
map_add' := by simp [coe_smul]
map_smul' := by simp [coe_smul]
variable {p} in
@[simp]
theorem subtype_apply (x : p) : p.subtype x = x :=
rfl
lemma subtype_injective :
Function.Injective p.subtype :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : (Submodule.subtype p : p → M) = Subtype.val :=
rfl
theorem injective_subtype : Injective p.subtype :=
Subtype.coe_injective
/-- Note the `AddSubmonoid` version of this lemma is called `AddSubmonoid.coe_finset_sum`. -/
theorem coe_sum (x : ι → p) (s : Finset ι) : ↑(∑ i ∈ s, x i) = ∑ i ∈ s, (x i : M) :=
map_sum p.subtype _ _
section AddAction
variable {α β : Type*}
/-- The action by a submodule is the action by the underlying module. -/
instance [AddAction M α] : AddAction p α :=
AddAction.compHom _ p.subtype.toAddMonoidHom
end AddAction
end AddCommMonoid
end Submodule
end
section
variable {R : Type*} {R₁ : Type*} {R₂ : Type*} {R₃ : Type*}
variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
variable {ι : Type*}
namespace LinearMap
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R M₁] [Module R₂ M₂] [Module R₃ M₃]
variable {σ₁₂ : R →+* R₂} {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₃] M₃)
/-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map
`p → M₂`. -/
def domRestrict (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) : p →ₛₗ[σ₁₂] M₂ :=
f.comp p.subtype
@[simp]
theorem domRestrict_apply (f : M →ₛₗ[σ₁₂] M₂) (p : Submodule R M) (x : p) :
f.domRestrict p x = f x :=
rfl
/-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a
linear map M₂ → p.
See also `LinearMap.codLift`. -/
def codRestrict (p : Submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) (h : ∀ c, f c ∈ p) : M →ₛₗ[σ₁₂] p where
toFun c := ⟨f c, h c⟩
map_add' _ _ := by simp
map_smul' _ _ := by simp
@[simp]
theorem codRestrict_apply (p : Submodule R₂ M₂) (f : M →ₛₗ[σ₁₂] M₂) {h} (x : M) :
(codRestrict p f h x : M₂) = f x :=
rfl
@[simp]
theorem comp_codRestrict (p : Submodule R₃ M₃) (h : ∀ b, g b ∈ p) :
((codRestrict p g h).comp f : M →ₛₗ[σ₁₃] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (p : Submodule R₂ M₂) (h : ∀ b, f b ∈ p) :
p.subtype.comp (codRestrict p f h) = f :=
ext fun _ => rfl
section
variable {M₂' : Type*} [AddCommMonoid M₂'] [Module R₂ M₂']
(p : M₂' →ₗ[R₂] M₂) (hp : Injective p) (h : ∀ c, f c ∈ range p)
/-- A linear map `f : M → M₂` whose values lie in the image of an injective linear map
`p : M₂' → M₂` admits a unique lift to a linear map `M → M₂'`. -/
noncomputable def codLift :
M →ₛₗ[σ₁₂] M₂' where
toFun c := (h c).choose
map_add' b c := by apply hp; simp_rw [map_add, (h _).choose_spec, ← map_add, (h _).choose_spec]
map_smul' r c := by apply hp; simp_rw [map_smul, (h _).choose_spec, LinearMap.map_smulₛₗ]
@[simp] theorem codLift_apply (x : M) :
(f.codLift p hp h x) = (h x).choose :=
rfl
@[simp]
theorem comp_codLift :
p.comp (f.codLift p hp h) = f := by
ext x
rw [comp_apply, codLift_apply, (h x).choose_spec]
end
/-- Restrict domain and codomain of a linear map. -/
def restrict (f : M →ₗ[R] M₁) {p : Submodule R M} {q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) :
p →ₗ[R] q :=
(f.domRestrict p).codRestrict q <| SetLike.forall.2 hf
@[simp]
theorem restrict_coe_apply (f : M →ₗ[R] M₁) {p : Submodule R M} {q : Submodule R M₁}
(hf : ∀ x ∈ p, f x ∈ q) (x : p) : ↑(f.restrict hf x) = f x :=
rfl
theorem restrict_apply {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁}
(hf : ∀ x ∈ p, f x ∈ q) (x : p) : f.restrict hf x = ⟨f x, hf x.1 x.2⟩ :=
rfl
lemma restrict_sub {R M M₁ : Type*}
[Ring R] [AddCommGroup M] [AddCommGroup M₁] [Module R M] [Module R M₁]
{p : Submodule R M} {q : Submodule R M₁} {f g : M →ₗ[R] M₁}
(hf : MapsTo f p q) (hg : MapsTo g p q)
(hfg : MapsTo (f - g) p q := fun _ hx ↦ q.sub_mem (hf hx) (hg hx)) :
f.restrict hf - g.restrict hg = (f - g).restrict hfg := by
ext; simp
lemma restrict_comp
{M₂ M₃ : Type*} [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₂] [Module R M₃]
{p : Submodule R M} {p₂ : Submodule R M₂} {p₃ : Submodule R M₃}
{f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃}
(hf : MapsTo f p p₂) (hg : MapsTo g p₂ p₃) (hfg : MapsTo (g ∘ₗ f) p p₃ := hg.comp hf) :
(g ∘ₗ f).restrict hfg = (g.restrict hg) ∘ₗ (f.restrict hf) :=
rfl
-- TODO Consider defining `Algebra R (p.compatibleMaps p)`, `AlgHom` version of `LinearMap.restrict`
lemma restrict_smul_one
{R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {p : Submodule R M}
(μ : R) (h : ∀ x ∈ p, (μ • (1 : Module.End R M)) x ∈ p := fun _ ↦ p.smul_mem μ) :
(μ • 1 : Module.End R M).restrict h = μ • (1 : Module.End R p) :=
rfl
lemma restrict_commute {f g : M →ₗ[R] M} (h : Commute f g) {p : Submodule R M}
(hf : MapsTo f p p) (hg : MapsTo g p p) :
Commute (f.restrict hf) (g.restrict hg) := by
change (f ∘ₗ g).restrict (hf.comp hg) = (g ∘ₗ f).restrict (hg.comp hf)
congr 1
theorem subtype_comp_restrict {f : M →ₗ[R] M₁} {p : Submodule R M} {q : Submodule R M₁}
| (hf : ∀ x ∈ p, f x ∈ q) : q.subtype.comp (f.restrict hf) = f.domRestrict p :=
rfl
theorem restrict_eq_codRestrict_domRestrict {f : M →ₗ[R] M₁} {p : Submodule R M}
{q : Submodule R M₁} (hf : ∀ x ∈ p, f x ∈ q) :
f.restrict hf = (f.domRestrict p).codRestrict q fun x => hf x.1 x.2 :=
rfl
| Mathlib/Algebra/Module/Submodule/LinearMap.lean | 243 | 249 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.DirectSum.LinearMap
import Mathlib.Algebra.Lie.InvariantForm
import Mathlib.Algebra.Lie.Weights.Cartan
import Mathlib.Algebra.Lie.Weights.Linear
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.LinearAlgebra.PID
/-!
# The trace and Killing forms of a Lie algebra.
Let `L` be a Lie algebra with coefficients in a commutative ring `R`. Suppose `M` is a finite, free
`R`-module and we have a representation `φ : L → End M`. This data induces a natural bilinear form
`B` on `L`, called the trace form associated to `M`; it is defined as `B(x, y) = Tr (φ x) (φ y)`.
In the special case that `M` is `L` itself and `φ` is the adjoint representation, the trace form
is known as the Killing form.
We define the trace / Killing form in this file and prove some basic properties.
## Main definitions
* `LieModule.traceForm`: a finite, free representation of a Lie algebra `L` induces a bilinear form
on `L` called the trace Form.
* `LieModule.traceForm_eq_zero_of_isNilpotent`: the trace form induced by a nilpotent
representation of a Lie algebra vanishes.
* `killingForm`: the adjoint representation of a (finite, free) Lie algebra `L` induces a bilinear
form on `L` via the trace form construction.
-/
variable (R K L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
local notation "φ" => LieModule.toEnd R L M
open LinearMap (trace)
open Set Module
namespace LieModule
/-- A finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called
the trace Form. See also `killingForm`. -/
noncomputable def traceForm : LinearMap.BilinForm R L :=
((LinearMap.mul _ _).compl₁₂ (φ).toLinearMap (φ).toLinearMap).compr₂ (trace R M)
lemma traceForm_apply_apply (x y : L) :
traceForm R L M x y = trace R _ (φ x ∘ₗ φ y) :=
rfl
lemma traceForm_comm (x y : L) : traceForm R L M x y = traceForm R L M y x :=
LinearMap.trace_mul_comm R (φ x) (φ y)
lemma traceForm_isSymm : LinearMap.IsSymm (traceForm R L M) := LieModule.traceForm_comm R L M
@[simp] lemma traceForm_flip : LinearMap.flip (traceForm R L M) = traceForm R L M :=
Eq.symm <| LinearMap.ext₂ <| traceForm_comm R L M
/-- The trace form of a Lie module is compatible with the action of the Lie algebra.
See also `LieModule.traceForm_apply_lie_apply'`. -/
lemma traceForm_apply_lie_apply (x y z : L) :
traceForm R L M ⁅x, y⁆ z = traceForm R L M x ⁅y, z⁆ := by
calc traceForm R L M ⁅x, y⁆ z
= trace R _ (φ ⁅x, y⁆ ∘ₗ φ z) := by simp only [traceForm_apply_apply]
_ = trace R _ ((φ x * φ y - φ y * φ x) * φ z) := ?_
_ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ y * (φ x * φ z)) := ?_
_ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ x * (φ z * φ y)) := ?_
_ = traceForm R L M x ⁅y, z⁆ := ?_
· simp only [LieHom.map_lie, Ring.lie_def, ← Module.End.mul_eq_comp]
· simp only [sub_mul, mul_sub, map_sub, mul_assoc]
· simp only [LinearMap.trace_mul_cycle' R (φ x) (φ z) (φ y)]
· simp only [traceForm_apply_apply, LieHom.map_lie, Ring.lie_def, mul_sub, map_sub,
← Module.End.mul_eq_comp]
/-- Given a representation `M` of a Lie algebra `L`, the action of any `x : L` is skew-adjoint wrt
the trace form. -/
lemma traceForm_apply_lie_apply' (x y z : L) :
traceForm R L M ⁅x, y⁆ z = - traceForm R L M y ⁅x, z⁆ :=
calc traceForm R L M ⁅x, y⁆ z
= - traceForm R L M ⁅y, x⁆ z := by rw [← lie_skew x y, map_neg, LinearMap.neg_apply]
_ = - traceForm R L M y ⁅x, z⁆ := by rw [traceForm_apply_lie_apply]
lemma traceForm_lieInvariant : (traceForm R L M).lieInvariant L := by
intro x y z
rw [← lie_skew, map_neg, LinearMap.neg_apply, LieModule.traceForm_apply_lie_apply R L M]
/-- This lemma justifies the terminology "invariant" for trace forms. -/
@[simp] lemma lie_traceForm_eq_zero (x : L) : ⁅x, traceForm R L M⁆ = 0 := by
ext y z
rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply,
LinearMap.zero_apply, traceForm_apply_lie_apply', sub_self]
@[simp] lemma traceForm_eq_zero_of_isNilpotent [IsReduced R] [IsNilpotent L M] :
traceForm R L M = 0 := by
ext x y
simp only [traceForm_apply_apply, LinearMap.zero_apply, ← isNilpotent_iff_eq_zero]
apply LinearMap.isNilpotent_trace_of_isNilpotent
exact isNilpotent_toEnd_of_isNilpotent₂ R L M x y
@[simp]
lemma traceForm_genWeightSpace_eq [Module.Free R M]
[IsDomain R] [IsPrincipalIdealRing R]
[LieRing.IsNilpotent L] [IsNoetherian R M] [LinearWeights R L M] (χ : L → R) (x y : L) :
traceForm R L (genWeightSpace M χ) x y = finrank R (genWeightSpace M χ) • (χ x * χ y) := by
set d := finrank R (genWeightSpace M χ)
have h₁ : χ y • d • χ x - χ y • χ x • (d : R) = 0 := by simp [mul_comm (χ x)]
have h₂ : χ x • d • χ y = d • (χ x * χ y) := by
simpa [nsmul_eq_mul, smul_eq_mul] using mul_left_comm (χ x) d (χ y)
have := traceForm_eq_zero_of_isNilpotent R L (shiftedGenWeightSpace R L M χ)
replace this := LinearMap.congr_fun (LinearMap.congr_fun this x) y
rwa [LinearMap.zero_apply, LinearMap.zero_apply, traceForm_apply_apply,
shiftedGenWeightSpace.toEnd_eq, shiftedGenWeightSpace.toEnd_eq,
← LinearEquiv.conj_comp, LinearMap.trace_conj', LinearMap.comp_sub, LinearMap.sub_comp,
LinearMap.sub_comp, map_sub, map_sub, map_sub, LinearMap.comp_smul, LinearMap.smul_comp,
LinearMap.comp_id, LinearMap.id_comp, LinearMap.map_smul, LinearMap.map_smul,
trace_toEnd_genWeightSpace, trace_toEnd_genWeightSpace,
LinearMap.comp_smul, LinearMap.smul_comp, LinearMap.id_comp, map_smul, map_smul,
LinearMap.trace_id, ← traceForm_apply_apply, h₁, h₂, sub_zero, sub_eq_zero] at this
/-- The upper and lower central series of `L` are orthogonal wrt the trace form of any Lie module
`M`. -/
lemma traceForm_eq_zero_if_mem_lcs_of_mem_ucs {x y : L} (k : ℕ)
(hx : x ∈ (⊤ : LieIdeal R L).lcs L k) (hy : y ∈ (⊥ : LieIdeal R L).ucs k) :
traceForm R L M x y = 0 := by
induction k generalizing x y with
| zero =>
replace hy : y = 0 := by simpa using hy
simp [hy]
| succ k ih =>
rw [LieSubmodule.ucs_succ, LieSubmodule.mem_normalizer] at hy
simp_rw [LieIdeal.lcs_succ, ← LieSubmodule.mem_toSubmodule,
LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.mem_top, true_and] at hx
refine Submodule.span_induction ?_ ?_ (fun z w _ _ hz hw ↦ ?_) (fun t z _ hz ↦ ?_) hx
· rintro - ⟨z, w, hw, rfl⟩
rw [← lie_skew, map_neg, LinearMap.neg_apply, neg_eq_zero, traceForm_apply_lie_apply]
exact ih hw (hy _)
· simp
· simp [hz, hw]
· simp [hz]
lemma traceForm_apply_eq_zero_of_mem_lcs_of_mem_center {x y : L}
(hx : x ∈ lowerCentralSeries R L L 1) (hy : y ∈ LieAlgebra.center R L) :
traceForm R L M x y = 0 := by
apply traceForm_eq_zero_if_mem_lcs_of_mem_ucs R L M 1
· simpa using hx
· simpa using hy
|
-- This is barely worth having: it usually follows from `LieModule.traceForm_eq_zero_of_isNilpotent`
@[simp] lemma traceForm_eq_zero_of_isTrivial [IsTrivial L M] :
traceForm R L M = 0 := by
ext x y
suffices φ x ∘ₗ φ y = 0 by simp [traceForm_apply_apply, this]
| Mathlib/Algebra/Lie/TraceForm.lean | 151 | 156 |
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes, Daniel Weber
-/
import Batteries.Data.Nat.Gcd
import Mathlib.Algebra.GroupWithZero.Associated
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.ENat.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Multiplicity of a divisor
For a commutative monoid, this file introduces the notion of multiplicity of a divisor and proves
several basic results on it.
## Main definitions
* `emultiplicity a b`: for two elements `a` and `b` of a commutative monoid returns the largest
number `n` such that `a ^ n ∣ b` or infinity, written `⊤`, if `a ^ n ∣ b` for all natural numbers
`n`.
* `multiplicity a b`: a `ℕ`-valued version of `multiplicity`, defaulting for `1` instead of `⊤`.
The reason for using `1` as a default value instead of `0` is to have `multiplicity_eq_zero_iff`.
* `FiniteMultiplicity a b`: a predicate denoting that the multiplicity of `a` in `b` is finite.
-/
assert_not_exists Field
variable {α β : Type*}
open Nat
/-- `multiplicity.Finite a b` indicates that the multiplicity of `a` in `b` is finite. -/
abbrev FiniteMultiplicity [Monoid α] (a b : α) : Prop :=
∃ n : ℕ, ¬a ^ (n + 1) ∣ b
@[deprecated (since := "2024-11-30")] alias multiplicity.Finite := FiniteMultiplicity
open scoped Classical in
/-- `emultiplicity a b` returns the largest natural number `n` such that
`a ^ n ∣ b`, as an `ℕ∞`. If `∀ n, a ^ n ∣ b` then it returns `⊤`. -/
noncomputable def emultiplicity [Monoid α] (a b : α) : ℕ∞ :=
if h : FiniteMultiplicity a b then Nat.find h else ⊤
/-- A `ℕ`-valued version of `emultiplicity`, returning `1` instead of `⊤`. -/
noncomputable def multiplicity [Monoid α] (a b : α) : ℕ :=
(emultiplicity a b).untopD 1
section Monoid
variable [Monoid α] [Monoid β] {a b : α}
@[simp]
theorem emultiplicity_eq_top :
emultiplicity a b = ⊤ ↔ ¬FiniteMultiplicity a b := by
simp [emultiplicity]
theorem emultiplicity_lt_top {a b : α} : emultiplicity a b < ⊤ ↔ FiniteMultiplicity a b := by
simp [lt_top_iff_ne_top, emultiplicity_eq_top]
theorem finiteMultiplicity_iff_emultiplicity_ne_top :
FiniteMultiplicity a b ↔ emultiplicity a b ≠ ⊤ := by simp
@[deprecated (since := "2024-11-30")]
alias finite_iff_emultiplicity_ne_top := finiteMultiplicity_iff_emultiplicity_ne_top
alias ⟨FiniteMultiplicity.emultiplicity_ne_top, _⟩ := finite_iff_emultiplicity_ne_top
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_ne_top := FiniteMultiplicity.emultiplicity_ne_top
@[deprecated (since := "2024-11-08")]
alias Finite.emultiplicity_ne_top := FiniteMultiplicity.emultiplicity_ne_top
theorem finiteMultiplicity_of_emultiplicity_eq_natCast {n : ℕ} (h : emultiplicity a b = n) :
FiniteMultiplicity a b := by
by_contra! nh
rw [← emultiplicity_eq_top, h] at nh
trivial
@[deprecated (since := "2024-11-30")]
alias finite_of_emultiplicity_eq_natCast := finiteMultiplicity_of_emultiplicity_eq_natCast
theorem multiplicity_eq_of_emultiplicity_eq_some {n : ℕ} (h : emultiplicity a b = n) :
multiplicity a b = n := by
simp [multiplicity, h]
rfl
theorem emultiplicity_ne_of_multiplicity_ne {n : ℕ} :
multiplicity a b ≠ n → emultiplicity a b ≠ n :=
mt multiplicity_eq_of_emultiplicity_eq_some
theorem FiniteMultiplicity.emultiplicity_eq_multiplicity (h : FiniteMultiplicity a b) :
emultiplicity a b = multiplicity a b := by
cases hm : emultiplicity a b
· simp [h] at hm
rw [multiplicity_eq_of_emultiplicity_eq_some hm]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_eq_multiplicity :=
FiniteMultiplicity.emultiplicity_eq_multiplicity
theorem FiniteMultiplicity.emultiplicity_eq_iff_multiplicity_eq {n : ℕ}
(h : FiniteMultiplicity a b) : emultiplicity a b = n ↔ multiplicity a b = n := by
simp [h.emultiplicity_eq_multiplicity]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_eq_iff_multiplicity_eq :=
FiniteMultiplicity.emultiplicity_eq_iff_multiplicity_eq
theorem emultiplicity_eq_iff_multiplicity_eq_of_ne_one {n : ℕ} (h : n ≠ 1) :
emultiplicity a b = n ↔ multiplicity a b = n := by
constructor
· exact multiplicity_eq_of_emultiplicity_eq_some
· intro h₂
simpa [multiplicity, WithTop.untopD_eq_iff, h] using h₂
theorem emultiplicity_eq_zero_iff_multiplicity_eq_zero :
emultiplicity a b = 0 ↔ multiplicity a b = 0 :=
emultiplicity_eq_iff_multiplicity_eq_of_ne_one zero_ne_one
@[simp]
theorem multiplicity_eq_one_of_not_finiteMultiplicity (h : ¬FiniteMultiplicity a b) :
multiplicity a b = 1 := by
simp [multiplicity, emultiplicity_eq_top.2 h]
@[deprecated (since := "2024-11-30")]
alias multiplicity_eq_one_of_not_finite :=
multiplicity_eq_one_of_not_finiteMultiplicity
@[simp]
theorem multiplicity_le_emultiplicity :
multiplicity a b ≤ emultiplicity a b := by
by_cases hf : FiniteMultiplicity a b
· simp [hf.emultiplicity_eq_multiplicity]
· simp [hf, emultiplicity_eq_top.2]
@[simp]
theorem multiplicity_eq_of_emultiplicity_eq {c d : β}
(h : emultiplicity a b = emultiplicity c d) : multiplicity a b = multiplicity c d := by
unfold multiplicity
rw [h]
theorem multiplicity_le_of_emultiplicity_le {n : ℕ} (h : emultiplicity a b ≤ n) :
multiplicity a b ≤ n := by
exact_mod_cast multiplicity_le_emultiplicity.trans h
theorem FiniteMultiplicity.emultiplicity_le_of_multiplicity_le (hfin : FiniteMultiplicity a b)
{n : ℕ} (h : multiplicity a b ≤ n) : emultiplicity a b ≤ n := by
rw [emultiplicity_eq_multiplicity hfin]
assumption_mod_cast
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_le_of_multiplicity_le :=
FiniteMultiplicity.emultiplicity_le_of_multiplicity_le
theorem le_emultiplicity_of_le_multiplicity {n : ℕ} (h : n ≤ multiplicity a b) :
n ≤ emultiplicity a b := by
exact_mod_cast (WithTop.coe_mono h).trans multiplicity_le_emultiplicity
theorem FiniteMultiplicity.le_multiplicity_of_le_emultiplicity (hfin : FiniteMultiplicity a b)
{n : ℕ} (h : n ≤ emultiplicity a b) : n ≤ multiplicity a b := by
rw [emultiplicity_eq_multiplicity hfin] at h
assumption_mod_cast
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.le_multiplicity_of_le_emultiplicity :=
FiniteMultiplicity.le_multiplicity_of_le_emultiplicity
theorem multiplicity_lt_of_emultiplicity_lt {n : ℕ} (h : emultiplicity a b < n) :
multiplicity a b < n := by
exact_mod_cast multiplicity_le_emultiplicity.trans_lt h
theorem FiniteMultiplicity.emultiplicity_lt_of_multiplicity_lt (hfin : FiniteMultiplicity a b)
{n : ℕ} (h : multiplicity a b < n) : emultiplicity a b < n := by
rw [emultiplicity_eq_multiplicity hfin]
assumption_mod_cast
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.emultiplicity_lt_of_multiplicity_lt :=
FiniteMultiplicity.emultiplicity_lt_of_multiplicity_lt
theorem lt_emultiplicity_of_lt_multiplicity {n : ℕ} (h : n < multiplicity a b) :
n < emultiplicity a b := by
exact_mod_cast (WithTop.coe_strictMono h).trans_le multiplicity_le_emultiplicity
theorem FiniteMultiplicity.lt_multiplicity_of_lt_emultiplicity (hfin : FiniteMultiplicity a b)
{n : ℕ} (h : n < emultiplicity a b) : n < multiplicity a b := by
rw [emultiplicity_eq_multiplicity hfin] at h
assumption_mod_cast
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.lt_multiplicity_of_lt_emultiplicity :=
FiniteMultiplicity.lt_multiplicity_of_lt_emultiplicity
theorem emultiplicity_pos_iff :
0 < emultiplicity a b ↔ 0 < multiplicity a b := by
simp [pos_iff_ne_zero, pos_iff_ne_zero, emultiplicity_eq_zero_iff_multiplicity_eq_zero]
theorem FiniteMultiplicity.def : FiniteMultiplicity a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b :=
Iff.rfl
@[deprecated (since := "2024-11-30")] alias multiplicity.Finite.def := FiniteMultiplicity.def
theorem FiniteMultiplicity.not_dvd_of_one_right : FiniteMultiplicity a 1 → ¬a ∣ 1 :=
fun ⟨n, hn⟩ ⟨d, hd⟩ => hn ⟨d ^ (n + 1), (pow_mul_pow_eq_one (n + 1) hd.symm).symm⟩
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_dvd_of_one_right := FiniteMultiplicity.not_dvd_of_one_right
@[norm_cast]
theorem Int.natCast_emultiplicity (a b : ℕ) :
emultiplicity (a : ℤ) (b : ℤ) = emultiplicity a b := by
unfold emultiplicity FiniteMultiplicity
congr! <;> norm_cast
@[norm_cast]
theorem Int.natCast_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b :=
multiplicity_eq_of_emultiplicity_eq (natCast_emultiplicity a b)
theorem FiniteMultiplicity.not_iff_forall : ¬FiniteMultiplicity a b ↔ ∀ n : ℕ, a ^ n ∣ b :=
⟨fun h n =>
Nat.casesOn n
(by
rw [_root_.pow_zero]
exact one_dvd _)
(by simpa [FiniteMultiplicity] using h),
by simp [FiniteMultiplicity, multiplicity]; tauto⟩
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_iff_forall := FiniteMultiplicity.not_iff_forall
theorem FiniteMultiplicity.not_unit (h : FiniteMultiplicity a b) : ¬IsUnit a :=
let ⟨n, hn⟩ := h
hn ∘ IsUnit.dvd ∘ IsUnit.pow (n + 1)
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_unit := FiniteMultiplicity.not_unit
theorem FiniteMultiplicity.mul_left {c : α} :
FiniteMultiplicity a (b * c) → FiniteMultiplicity a b := fun ⟨n, hn⟩ =>
⟨n, fun h => hn (h.trans (dvd_mul_right _ _))⟩
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.mul_left := FiniteMultiplicity.mul_left
theorem pow_dvd_of_le_emultiplicity {k : ℕ} (hk : k ≤ emultiplicity a b) :
a ^ k ∣ b := by classical
cases k
· simp
unfold emultiplicity at hk
split at hk
· norm_cast at hk
simpa using (Nat.find_min _ (lt_of_succ_le hk))
· apply FiniteMultiplicity.not_iff_forall.mp ‹_›
theorem pow_dvd_of_le_multiplicity {k : ℕ} (hk : k ≤ multiplicity a b) :
a ^ k ∣ b := pow_dvd_of_le_emultiplicity (le_emultiplicity_of_le_multiplicity hk)
@[simp]
theorem pow_multiplicity_dvd (a b : α) : a ^ (multiplicity a b) ∣ b :=
pow_dvd_of_le_multiplicity le_rfl
theorem not_pow_dvd_of_emultiplicity_lt {m : ℕ} (hm : emultiplicity a b < m) :
¬a ^ m ∣ b := fun nh => by
unfold emultiplicity at hm
split at hm
· simp only [cast_lt, find_lt_iff] at hm
obtain ⟨n, hn1, hn2⟩ := hm
exact hn2 ((pow_dvd_pow _ hn1).trans nh)
· simp at hm
theorem FiniteMultiplicity.not_pow_dvd_of_multiplicity_lt (hf : FiniteMultiplicity a b) {m : ℕ}
(hm : multiplicity a b < m) : ¬a ^ m ∣ b := by
apply not_pow_dvd_of_emultiplicity_lt
rw [hf.emultiplicity_eq_multiplicity]
norm_cast
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_pow_dvd_of_multiplicity_lt :=
FiniteMultiplicity.not_pow_dvd_of_multiplicity_lt
theorem multiplicity_pos_of_dvd (hdiv : a ∣ b) : 0 < multiplicity a b := by
refine Nat.pos_iff_ne_zero.2 fun h => ?_
simpa [hdiv] using FiniteMultiplicity.not_pow_dvd_of_multiplicity_lt
(by by_contra! nh; simp [nh] at h) (lt_one_iff.mpr h)
theorem emultiplicity_pos_of_dvd (hdiv : a ∣ b) : 0 < emultiplicity a b :=
lt_emultiplicity_of_lt_multiplicity (multiplicity_pos_of_dvd hdiv)
theorem emultiplicity_eq_of_dvd_of_not_dvd {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
emultiplicity a b = k := by classical
have : FiniteMultiplicity a b := ⟨k, hsucc⟩
simp only [emultiplicity, this, ↓reduceDIte, Nat.cast_inj, find_eq_iff, hsucc, not_false_eq_true,
Decidable.not_not, true_and]
exact fun n hn ↦ (pow_dvd_pow _ hn).trans hk
theorem multiplicity_eq_of_dvd_of_not_dvd {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) :
multiplicity a b = k :=
multiplicity_eq_of_emultiplicity_eq_some (emultiplicity_eq_of_dvd_of_not_dvd hk hsucc)
theorem le_emultiplicity_of_pow_dvd {k : ℕ} (hk : a ^ k ∣ b) :
k ≤ emultiplicity a b :=
le_of_not_gt fun hk' => not_pow_dvd_of_emultiplicity_lt hk' hk
theorem FiniteMultiplicity.le_multiplicity_of_pow_dvd (hf : FiniteMultiplicity a b)
{k : ℕ} (hk : a ^ k ∣ b) : k ≤ multiplicity a b :=
hf.le_multiplicity_of_le_emultiplicity (le_emultiplicity_of_pow_dvd hk)
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.le_multiplicity_of_pow_dvd :=
FiniteMultiplicity.le_multiplicity_of_pow_dvd
theorem pow_dvd_iff_le_emultiplicity {k : ℕ} :
a ^ k ∣ b ↔ k ≤ emultiplicity a b :=
⟨le_emultiplicity_of_pow_dvd, pow_dvd_of_le_emultiplicity⟩
theorem FiniteMultiplicity.pow_dvd_iff_le_multiplicity (hf : FiniteMultiplicity a b) {k : ℕ} :
a ^ k ∣ b ↔ k ≤ multiplicity a b := by
exact_mod_cast hf.emultiplicity_eq_multiplicity ▸ pow_dvd_iff_le_emultiplicity
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.pow_dvd_iff_le_multiplicity :=
FiniteMultiplicity.pow_dvd_iff_le_multiplicity
theorem emultiplicity_lt_iff_not_dvd {k : ℕ} :
emultiplicity a b < k ↔ ¬a ^ k ∣ b := by rw [pow_dvd_iff_le_emultiplicity, not_le]
theorem FiniteMultiplicity.multiplicity_lt_iff_not_dvd {k : ℕ} (hf : FiniteMultiplicity a b) :
multiplicity a b < k ↔ ¬a ^ k ∣ b := by rw [hf.pow_dvd_iff_le_multiplicity, not_le]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.multiplicity_lt_iff_not_dvd :=
FiniteMultiplicity.multiplicity_lt_iff_not_dvd
theorem emultiplicity_eq_coe {n : ℕ} :
emultiplicity a b = n ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
constructor
· intro h
constructor
· apply pow_dvd_of_le_emultiplicity
simp [h]
· apply not_pow_dvd_of_emultiplicity_lt
rw [h]
norm_cast
simp
· rw [and_imp]
apply emultiplicity_eq_of_dvd_of_not_dvd
theorem FiniteMultiplicity.multiplicity_eq_iff (hf : FiniteMultiplicity a b) {n : ℕ} :
multiplicity a b = n ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := by
simp [← emultiplicity_eq_coe, hf.emultiplicity_eq_multiplicity]
theorem emultiplicity_eq_ofNat {a b n : ℕ} [n.AtLeastTwo] :
emultiplicity a b = (ofNat(n) : ℕ∞) ↔ a ^ ofNat(n) ∣ b ∧ ¬a ^ (ofNat(n) + 1) ∣ b :=
emultiplicity_eq_coe
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.multiplicity_eq_iff := FiniteMultiplicity.multiplicity_eq_iff
@[simp]
theorem FiniteMultiplicity.not_of_isUnit_left (b : α) (ha : IsUnit a) : ¬FiniteMultiplicity a b :=
(·.not_unit ha)
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_of_isUnit_left := FiniteMultiplicity.not_of_isUnit_left
theorem FiniteMultiplicity.not_of_one_left (b : α) : ¬ FiniteMultiplicity 1 b := by simp
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_of_one_left := FiniteMultiplicity.not_of_one_left
@[simp]
theorem emultiplicity_one_left (b : α) : emultiplicity 1 b = ⊤ :=
emultiplicity_eq_top.2 (FiniteMultiplicity.not_of_one_left _)
@[simp]
theorem FiniteMultiplicity.one_right (ha : FiniteMultiplicity a 1) : multiplicity a 1 = 0 := by
simp [ha.multiplicity_eq_iff, ha.not_dvd_of_one_right]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.one_right := FiniteMultiplicity.one_right
theorem FiniteMultiplicity.not_of_unit_left (a : α) (u : αˣ) : ¬ FiniteMultiplicity (u : α) a :=
FiniteMultiplicity.not_of_isUnit_left a u.isUnit
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.not_of_unit_left := FiniteMultiplicity.not_of_unit_left
theorem emultiplicity_eq_zero :
emultiplicity a b = 0 ↔ ¬a ∣ b := by
by_cases hf : FiniteMultiplicity a b
· rw [← ENat.coe_zero, emultiplicity_eq_coe]
simp
· simpa [emultiplicity_eq_top.2 hf] using FiniteMultiplicity.not_iff_forall.1 hf 1
theorem multiplicity_eq_zero :
multiplicity a b = 0 ↔ ¬a ∣ b :=
(emultiplicity_eq_iff_multiplicity_eq_of_ne_one zero_ne_one).symm.trans emultiplicity_eq_zero
theorem emultiplicity_ne_zero :
emultiplicity a b ≠ 0 ↔ a ∣ b := by
simp [emultiplicity_eq_zero]
theorem multiplicity_ne_zero :
multiplicity a b ≠ 0 ↔ a ∣ b := by
simp [multiplicity_eq_zero]
theorem FiniteMultiplicity.exists_eq_pow_mul_and_not_dvd (hfin : FiniteMultiplicity a b) :
∃ c : α, b = a ^ multiplicity a b * c ∧ ¬a ∣ c := by
obtain ⟨c, hc⟩ := pow_multiplicity_dvd a b
refine ⟨c, hc, ?_⟩
rintro ⟨k, hk⟩
rw [hk, ← mul_assoc, ← _root_.pow_succ] at hc
have h₁ : a ^ (multiplicity a b + 1) ∣ b := ⟨k, hc⟩
exact (hfin.multiplicity_eq_iff.1 (by simp)).2 h₁
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.exists_eq_pow_mul_and_not_dvd :=
FiniteMultiplicity.exists_eq_pow_mul_and_not_dvd
theorem emultiplicity_le_emultiplicity_iff {c d : β} :
emultiplicity a b ≤ emultiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d := by classical
constructor
· exact fun h n hab ↦ pow_dvd_of_le_emultiplicity (le_trans (le_emultiplicity_of_pow_dvd hab) h)
· intro h
unfold emultiplicity
-- aesop? says
split
next h_1 =>
obtain ⟨w, h_1⟩ := h_1
split
next h_2 =>
simp_all only [cast_le, le_find_iff, lt_find_iff, Decidable.not_not, le_refl,
not_true_eq_false, not_false_eq_true, implies_true]
next h_2 => simp_all only [not_exists, Decidable.not_not, le_top]
next h_1 =>
simp_all only [not_exists, Decidable.not_not, not_true_eq_false, top_le_iff,
dite_eq_right_iff, ENat.coe_ne_top, imp_false, not_false_eq_true, implies_true]
theorem FiniteMultiplicity.multiplicity_le_multiplicity_iff {c d : β} (hab : FiniteMultiplicity a b)
(hcd : FiniteMultiplicity c d) :
multiplicity a b ≤ multiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d := by
rw [← WithTop.coe_le_coe, ENat.some_eq_coe, ← hab.emultiplicity_eq_multiplicity,
← hcd.emultiplicity_eq_multiplicity]
apply emultiplicity_le_emultiplicity_iff
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.multiplicity_le_multiplicity_iff :=
FiniteMultiplicity.multiplicity_le_multiplicity_iff
theorem emultiplicity_eq_emultiplicity_iff {c d : β} :
emultiplicity a b = emultiplicity c d ↔ ∀ n : ℕ, a ^ n ∣ b ↔ c ^ n ∣ d :=
⟨fun h n =>
⟨emultiplicity_le_emultiplicity_iff.1 h.le n, emultiplicity_le_emultiplicity_iff.1 h.ge n⟩,
fun h => le_antisymm (emultiplicity_le_emultiplicity_iff.2 fun n => (h n).mp)
(emultiplicity_le_emultiplicity_iff.2 fun n => (h n).mpr)⟩
theorem le_emultiplicity_map {F : Type*} [FunLike F α β] [MonoidHomClass F α β]
(f : F) {a b : α} :
emultiplicity a b ≤ emultiplicity (f a) (f b) :=
emultiplicity_le_emultiplicity_iff.2 fun n ↦ by rw [← map_pow]; exact map_dvd f
theorem emultiplicity_map_eq {F : Type*} [EquivLike F α β] [MulEquivClass F α β]
(f : F) {a b : α} : emultiplicity (f a) (f b) = emultiplicity a b := by
simp [emultiplicity_eq_emultiplicity_iff, ← map_pow, map_dvd_iff]
theorem multiplicity_map_eq {F : Type*} [EquivLike F α β] [MulEquivClass F α β]
(f : F) {a b : α} : multiplicity (f a) (f b) = multiplicity a b :=
multiplicity_eq_of_emultiplicity_eq (emultiplicity_map_eq f)
theorem emultiplicity_le_emultiplicity_of_dvd_right {a b c : α} (h : b ∣ c) :
emultiplicity a b ≤ emultiplicity a c :=
emultiplicity_le_emultiplicity_iff.2 fun _ hb => hb.trans h
theorem emultiplicity_eq_of_associated_right {a b c : α} (h : Associated b c) :
emultiplicity a b = emultiplicity a c :=
le_antisymm (emultiplicity_le_emultiplicity_of_dvd_right h.dvd)
(emultiplicity_le_emultiplicity_of_dvd_right h.symm.dvd)
theorem multiplicity_eq_of_associated_right {a b c : α} (h : Associated b c) :
multiplicity a b = multiplicity a c :=
multiplicity_eq_of_emultiplicity_eq (emultiplicity_eq_of_associated_right h)
theorem dvd_of_emultiplicity_pos {a b : α} (h : 0 < emultiplicity a b) : a ∣ b :=
pow_one a ▸ pow_dvd_of_le_emultiplicity (Order.add_one_le_of_lt h)
theorem dvd_of_multiplicity_pos {a b : α} (h : 0 < multiplicity a b) : a ∣ b :=
dvd_of_emultiplicity_pos (lt_emultiplicity_of_lt_multiplicity h)
theorem dvd_iff_multiplicity_pos {a b : α} : 0 < multiplicity a b ↔ a ∣ b :=
⟨dvd_of_multiplicity_pos, fun hdvd => Nat.pos_of_ne_zero (by simpa [multiplicity_eq_zero])⟩
theorem dvd_iff_emultiplicity_pos {a b : α} : 0 < emultiplicity a b ↔ a ∣ b :=
emultiplicity_pos_iff.trans dvd_iff_multiplicity_pos
theorem Nat.finiteMultiplicity_iff {a b : ℕ} : FiniteMultiplicity a b ↔ a ≠ 1 ∧ 0 < b := by
rw [← not_iff_not, FiniteMultiplicity.not_iff_forall, not_and_or, not_ne_iff, not_lt,
Nat.le_zero]
exact
⟨fun h =>
or_iff_not_imp_right.2 fun hb =>
have ha : a ≠ 0 := fun ha => hb <| zero_dvd_iff.mp <| by rw [ha] at h; exact h 1
Classical.by_contradiction fun ha1 : a ≠ 1 =>
have ha_gt_one : 1 < a :=
lt_of_not_ge fun _ =>
match a with
| 0 => ha rfl
| 1 => ha1 rfl
| b+2 => by omega
not_lt_of_ge (le_of_dvd (Nat.pos_of_ne_zero hb) (h b)) (b.lt_pow_self ha_gt_one),
fun h => by cases h <;> simp [*]⟩
@[deprecated (since := "2024-11-30")]
alias Nat.multiplicity_finite_iff := Nat.finiteMultiplicity_iff
alias ⟨_, Dvd.multiplicity_pos⟩ := dvd_iff_multiplicity_pos
end Monoid
section CommMonoid
variable [CommMonoid α]
theorem FiniteMultiplicity.mul_right {a b c : α} (hf : FiniteMultiplicity a (b * c)) :
FiniteMultiplicity a c := (mul_comm b c ▸ hf).mul_left
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.mul_right := FiniteMultiplicity.mul_right
theorem emultiplicity_of_isUnit_right {a b : α} (ha : ¬IsUnit a)
(hb : IsUnit b) : emultiplicity a b = 0 :=
emultiplicity_eq_zero.mpr fun h ↦ ha (isUnit_of_dvd_unit h hb)
theorem multiplicity_of_isUnit_right {a b : α} (ha : ¬IsUnit a)
(hb : IsUnit b) : multiplicity a b = 0 :=
multiplicity_eq_zero.mpr fun h ↦ ha (isUnit_of_dvd_unit h hb)
theorem emultiplicity_of_one_right {a : α} (ha : ¬IsUnit a) : emultiplicity a 1 = 0 :=
emultiplicity_of_isUnit_right ha isUnit_one
theorem multiplicity_of_one_right {a : α} (ha : ¬IsUnit a) : multiplicity a 1 = 0 :=
multiplicity_of_isUnit_right ha isUnit_one
theorem emultiplicity_of_unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : emultiplicity a u = 0 :=
emultiplicity_of_isUnit_right ha u.isUnit
theorem multiplicity_of_unit_right {a : α} (ha : ¬IsUnit a) (u : αˣ) : multiplicity a u = 0 :=
multiplicity_of_isUnit_right ha u.isUnit
theorem emultiplicity_le_emultiplicity_of_dvd_left {a b c : α} (hdvd : a ∣ b) :
emultiplicity b c ≤ emultiplicity a c :=
emultiplicity_le_emultiplicity_iff.2 fun n h => (pow_dvd_pow_of_dvd hdvd n).trans h
theorem emultiplicity_eq_of_associated_left {a b c : α} (h : Associated a b) :
emultiplicity b c = emultiplicity a c :=
le_antisymm (emultiplicity_le_emultiplicity_of_dvd_left h.dvd)
(emultiplicity_le_emultiplicity_of_dvd_left h.symm.dvd)
theorem multiplicity_eq_of_associated_left {a b c : α} (h : Associated a b) :
multiplicity b c = multiplicity a c :=
multiplicity_eq_of_emultiplicity_eq (emultiplicity_eq_of_associated_left h)
theorem emultiplicity_mk_eq_emultiplicity {a b : α} :
emultiplicity (Associates.mk a) (Associates.mk b) = emultiplicity a b := by
simp [emultiplicity_eq_emultiplicity_iff, ← Associates.mk_pow, Associates.mk_dvd_mk]
end CommMonoid
section MonoidWithZero
variable [MonoidWithZero α]
theorem FiniteMultiplicity.ne_zero {a b : α} (h : FiniteMultiplicity a b) : b ≠ 0 :=
let ⟨n, hn⟩ := h
fun hb => by simp [hb] at hn
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.ne_zero := FiniteMultiplicity.ne_zero
@[simp]
theorem emultiplicity_zero (a : α) : emultiplicity a 0 = ⊤ :=
emultiplicity_eq_top.2 (fun v ↦ v.ne_zero rfl)
@[simp]
theorem emultiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : emultiplicity 0 a = 0 :=
emultiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
@[simp]
theorem multiplicity_zero_eq_zero_of_ne_zero (a : α) (ha : a ≠ 0) : multiplicity 0 a = 0 :=
multiplicity_eq_zero.2 <| mt zero_dvd_iff.1 ha
end MonoidWithZero
section Semiring
variable [Semiring α]
theorem FiniteMultiplicity.or_of_add {p a b : α} (hf : FiniteMultiplicity p (a + b)) :
FiniteMultiplicity p a ∨ FiniteMultiplicity p b := by
by_contra! nh
obtain ⟨c, hc⟩ := hf
simp_all [dvd_add]
@[deprecated (since := "2024-11-30")]
alias multiplicity.Finite.or_of_add := FiniteMultiplicity.or_of_add
theorem min_le_emultiplicity_add {p a b : α} :
min (emultiplicity p a) (emultiplicity p b) ≤ emultiplicity p (a + b) := by
| cases hm : min (emultiplicity p a) (emultiplicity p b)
· simp only [top_le_iff, min_eq_top, emultiplicity_eq_top] at hm ⊢
contrapose hm
| Mathlib/RingTheory/Multiplicity.lean | 612 | 614 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file defines bundled ordered groups and develops a few basic results.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
/-
`NeZero` theory should not be needed at this point in the ordered algebraic hierarchy.
-/
assert_not_imported Mathlib.Algebra.NeZero
open Function
universe u
variable {α : Type u}
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
@[deprecated "Use `[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where
/-- Addition is monotone in an ordered additive commutative group. -/
protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b
set_option linter.existingAttributeWarning false in
/-- An ordered commutative group is a commutative group
with a partial order in which multiplication is strictly monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [PartialOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where
/-- Multiplication is monotone in an ordered commutative group. -/
protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b
alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left'
attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left'
alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left'
attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left
alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left'
attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left
-- See note [lower instance priority]
@[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid]
instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid
[CommGroup α] [PartialOrder α] [IsOrderedMonoid α] : IsOrderedCancelMonoid α where
le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
/-!
### Linearly ordered commutative groups
-/
set_option linter.deprecated false in
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
@[deprecated "Use `[AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedAddCommGroup (α : Type u) extends OrderedAddCommGroup α, LinearOrder α
set_option linter.existingAttributeWarning false in
set_option linter.deprecated false in
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [LinearOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommGroup (α : Type u) extends OrderedCommGroup α, LinearOrder α
attribute [nolint docBlame]
LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder
section LinearOrderedCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {a : α}
@[to_additive LinearOrderedAddCommGroup.add_lt_add_left]
theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b :=
_root_.mul_lt_mul_left' h c
@[to_additive eq_zero_of_neg_eq]
theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 :=
match lt_trichotomy a 1 with
| Or.inl h₁ =>
have : 1 < a := h ▸ one_lt_inv_of_inv h₁
absurd h₁ this.asymm
| Or.inr (Or.inl h₁) => h₁
| Or.inr (Or.inr h₁) =>
have : a < 1 := h ▸ inv_lt_one'.mpr h₁
absurd h₁ this.asymm
@[to_additive exists_zero_lt]
theorem exists_one_lt' [Nontrivial α] : ∃ a : α, 1 < a := by
obtain ⟨y, hy⟩ := Decidable.exists_ne (1 : α)
obtain h|h := hy.lt_or_lt
· exact ⟨y⁻¹, one_lt_inv'.mpr h⟩
· exact ⟨y, h⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial α] : NoMaxOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a * y, lt_mul_of_one_lt_right' a hy⟩⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial α] : NoMinOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a / y, (div_lt_self_iff a).mpr hy⟩⟩
@[to_additive (attr := simp)]
theorem inv_le_self_iff : a⁻¹ ≤ a ↔ 1 ≤ a := by simp [inv_le_iff_one_le_mul']
@[to_additive (attr := simp)]
theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul]
@[to_additive (attr := simp)]
theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by simp [← not_iff_not]
@[to_additive (attr := simp)]
theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not]
end LinearOrderedCommGroup
section NormNumLemmas
/- The following lemmas are stated so that the `norm_num` tactic can use them with the
expected signatures. -/
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {a b : α}
@[to_additive (attr := gcongr) neg_le_neg]
theorem inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ :=
inv_le_inv_iff.mpr
@[to_additive (attr := gcongr) neg_lt_neg]
theorem inv_lt_inv' : a < b → b⁻¹ < a⁻¹ :=
inv_lt_inv_iff.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 :=
inv_lt_one_iff_one_lt.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 :=
inv_le_one'.mpr
@[to_additive neg_nonneg_of_nonpos]
theorem one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ :=
one_le_inv'.mpr
end NormNumLemmas
| Mathlib/Algebra/Order/Group/Defs.lean | 343 | 345 | |
/-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhangir Azerbayev, Adam Topaz, Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Basic
import Mathlib.LinearAlgebra.Alternating.Basic
/-!
# Exterior Algebras
We construct the exterior algebra of a module `M` over a commutative semiring `R`.
## Notation
The exterior algebra of the `R`-module `M` is denoted as `ExteriorAlgebra R M`.
It is endowed with the structure of an `R`-algebra.
The `n`th exterior power of the `R`-module `M` is denoted by `exteriorPower R n M`;
it is of type `Submodule R (ExteriorAlgebra R M)` and defined as
`LinearMap.range (ExteriorAlgebra.ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n`.
We also introduce the notation `⋀[R]^n M` for `exteriorPower R n M`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m : M, f m * f m = 0`, there is a (unique) lift of `f` to an `R`-algebra morphism,
which is denoted `ExteriorAlgebra.lift R f cond`.
The canonical linear map `M → ExteriorAlgebra R M` is denoted `ExteriorAlgebra.ι R`.
## Theorems
The main theorems proved ensure that `ExteriorAlgebra R M` satisfies the universal property
of the exterior algebra.
1. `ι_comp_lift` is the fact that the composition of `ι R` with `lift R f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift R f cond` with respect to 1.
## Definitions
* `ιMulti` is the `AlternatingMap` corresponding to the wedge product of `ι R m` terms.
## Implementation details
The exterior algebra of `M` is constructed as simply `CliffordAlgebra (0 : QuadraticForm R M)`,
as this avoids us having to duplicate API.
-/
universe u1 u2 u3 u4 u5
variable (R : Type u1) [CommRing R]
variable (M : Type u2) [AddCommGroup M] [Module R M]
/-- The exterior algebra of an `R`-module `M`.
-/
abbrev ExteriorAlgebra :=
CliffordAlgebra (0 : QuadraticForm R M)
namespace ExteriorAlgebra
variable {M}
/-- The canonical linear map `M →ₗ[R] ExteriorAlgebra R M`.
-/
abbrev ι : M →ₗ[R] ExteriorAlgebra R M :=
CliffordAlgebra.ι _
section exteriorPower
-- New variables `n` and `M`, to get the correct order of variables in the notation.
variable (n : ℕ) (M : Type u2) [AddCommGroup M] [Module R M]
/-- Definition of the `n`th exterior power of a `R`-module `N`. We introduce the notation
`⋀[R]^n M` for `exteriorPower R n M`. -/
abbrev exteriorPower : Submodule R (ExteriorAlgebra R M) :=
LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M) ^ n
@[inherit_doc exteriorPower]
notation:max "⋀[" R "]^" n:arg => exteriorPower R n
end exteriorPower
variable {R}
/-- As well as being linear, `ι m` squares to zero. -/
theorem ι_sq_zero (m : M) : ι R m * ι R m = 0 :=
(CliffordAlgebra.ι_sq_scalar _ m).trans <| map_zero _
section
variable {A : Type*} [Semiring A] [Algebra R A]
theorem comp_ι_sq_zero (g : ExteriorAlgebra R M →ₐ[R] A) (m : M) : g (ι R m) * g (ι R m) = 0 := by
rw [← map_mul, ι_sq_zero, map_zero]
variable (R)
/-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = 0`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `ExteriorAlgebra R M` to `A`.
-/
@[simps! symm_apply]
def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = 0 } ≃ (ExteriorAlgebra R M →ₐ[R] A) :=
Equiv.trans (Equiv.subtypeEquiv (Equiv.refl _) <| by simp) <| CliffordAlgebra.lift _
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) :
(lift R ⟨f, cond⟩).toLinearMap.comp (ι R) = f :=
CliffordAlgebra.ι_comp_lift f _
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (x) :
lift R ⟨f, cond⟩ (ι R x) = f x :=
CliffordAlgebra.lift_ι_apply f _ x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = 0) (g : ExteriorAlgebra R M →ₐ[R] A) :
g.toLinearMap.comp (ι R) = f ↔ g = lift R ⟨f, cond⟩ :=
CliffordAlgebra.lift_unique f _ _
variable {R}
@[simp]
theorem lift_comp_ι (g : ExteriorAlgebra R M →ₐ[R] A) :
lift R ⟨g.toLinearMap.comp (ι R), comp_ι_sq_zero _⟩ = g :=
CliffordAlgebra.lift_comp_ι g
/-- See note [partially-applied ext lemmas]. -/
@[ext]
theorem hom_ext {f g : ExteriorAlgebra R M →ₐ[R] A}
(h : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g :=
CliffordAlgebra.hom_ext h
/-- If `C` holds for the `algebraMap` of `r : R` into `ExteriorAlgebra R M`, the `ι` of `x : M`,
and is preserved under addition and multiplication, then it holds for all of `ExteriorAlgebra R M`.
-/
@[elab_as_elim]
theorem induction {C : ExteriorAlgebra R M → Prop}
(algebraMap : ∀ r, C (algebraMap R (ExteriorAlgebra R M) r)) (ι : ∀ x, C (ι R x))
(mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b))
(a : ExteriorAlgebra R M) : C a :=
CliffordAlgebra.induction algebraMap ι mul add a
/-- The left-inverse of `algebraMap`. -/
def algebraMapInv : ExteriorAlgebra R M →ₐ[R] R :=
ExteriorAlgebra.lift R ⟨(0 : M →ₗ[R] R), fun _ => by simp⟩
variable (M)
theorem algebraMap_leftInverse :
Function.LeftInverse algebraMapInv (algebraMap R <| ExteriorAlgebra R M) := fun x => by
simp [algebraMapInv]
@[simp]
theorem algebraMap_inj (x y : R) :
algebraMap R (ExteriorAlgebra R M) x = algebraMap R (ExteriorAlgebra R M) y ↔ x = y :=
(algebraMap_leftInverse M).injective.eq_iff
@[simp]
theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 0 ↔ x = 0 :=
map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
@[simp]
theorem algebraMap_eq_one_iff (x : R) : algebraMap R (ExteriorAlgebra R M) x = 1 ↔ x = 1 :=
map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
@[instance]
theorem isLocalHom_algebraMap : IsLocalHom (algebraMap R (ExteriorAlgebra R M)) :=
isLocalHom_of_leftInverse _ (algebraMap_leftInverse M)
theorem isUnit_algebraMap (r : R) : IsUnit (algebraMap R (ExteriorAlgebra R M) r) ↔ IsUnit r :=
isUnit_map_of_leftInverse _ (algebraMap_leftInverse M)
/-- Invertibility in the exterior algebra is the same as invertibility of the base ring. -/
@[simps!]
def invertibleAlgebraMapEquiv (r : R) :
Invertible (algebraMap R (ExteriorAlgebra R M) r) ≃ Invertible r :=
invertibleEquivOfLeftInverse _ _ _ (algebraMap_leftInverse M)
variable {M}
/-- The canonical map from `ExteriorAlgebra R M` into `TrivSqZeroExt R M` that sends
`ExteriorAlgebra.ι` to `TrivSqZeroExt.inr`. -/
def toTrivSqZeroExt [Module Rᵐᵒᵖ M] [IsCentralScalar R M] :
ExteriorAlgebra R M →ₐ[R] TrivSqZeroExt R M :=
lift R ⟨TrivSqZeroExt.inrHom R M, fun m => TrivSqZeroExt.inr_mul_inr R m m⟩
@[simp]
theorem toTrivSqZeroExt_ι [Module Rᵐᵒᵖ M] [IsCentralScalar R M] (x : M) :
toTrivSqZeroExt (ι R x) = TrivSqZeroExt.inr x :=
lift_ι_apply _ _ _ _
/-- The left-inverse of `ι`.
As an implementation detail, we implement this using `TrivSqZeroExt` which has a suitable
algebra structure. -/
def ιInv : ExteriorAlgebra R M →ₗ[R] M := by
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
exact (TrivSqZeroExt.sndHom R M).comp toTrivSqZeroExt.toLinearMap
theorem ι_leftInverse : Function.LeftInverse ιInv (ι R : M → ExteriorAlgebra R M) := fun x => by
simp [ιInv]
variable (R) in
@[simp]
theorem ι_inj (x y : M) : ι R x = ι R y ↔ x = y :=
ι_leftInverse.injective.eq_iff
@[simp]
theorem ι_eq_zero_iff (x : M) : ι R x = 0 ↔ x = 0 := by rw [← ι_inj R x 0, LinearMap.map_zero]
@[simp]
theorem ι_eq_algebraMap_iff (x : M) (r : R) : ι R x = algebraMap R _ r ↔ x = 0 ∧ r = 0 := by
refine ⟨fun h => ?_, ?_⟩
· letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
have hf0 : toTrivSqZeroExt (ι R x) = (0, x) := toTrivSqZeroExt_ι _
rw [h, AlgHom.commutes] at hf0
have : r = 0 ∧ 0 = x := Prod.ext_iff.1 hf0
exact this.symm.imp_left Eq.symm
· rintro ⟨rfl, rfl⟩
rw [LinearMap.map_zero, RingHom.map_zero]
@[simp]
theorem ι_ne_one [Nontrivial R] (x : M) : ι R x ≠ 1 := by
rw [← (algebraMap R (ExteriorAlgebra R M)).map_one, Ne, ι_eq_algebraMap_iff]
exact one_ne_zero ∘ And.right
/-- The generators of the exterior algebra are disjoint from its scalars. -/
theorem ι_range_disjoint_one :
Disjoint (LinearMap.range (ι R : M →ₗ[R] ExteriorAlgebra R M))
(1 : Submodule R (ExteriorAlgebra R M)) := by
rw [Submodule.disjoint_def]
rintro _ ⟨x, hx⟩ h
obtain ⟨r, rfl : algebraMap R (ExteriorAlgebra R M) r = _⟩ := Submodule.mem_one.mp h
rw [ι_eq_algebraMap_iff x] at hx
rw [hx.2, RingHom.map_zero]
@[simp]
theorem ι_add_mul_swap (x y : M) : ι R x * ι R y + ι R y * ι R x = 0 :=
CliffordAlgebra.ι_mul_ι_add_swap_of_isOrtho <| .all _ _
theorem ι_mul_prod_list {n : ℕ} (f : Fin n → M) (i : Fin n) :
(ι R <| f i) * (List.ofFn fun i => ι R <| f i).prod = 0 := by
induction n with
| zero => exact i.elim0
| succ n hn =>
rw [List.ofFn_succ, List.prod_cons, ← mul_assoc]
by_cases h : i = 0
· rw [h, ι_sq_zero, zero_mul]
· replace hn :=
congr_arg (ι R (f 0) * ·) <| hn (fun i => f <| Fin.succ i) (i.pred h)
simp only at hn
rw [Fin.succ_pred, ← mul_assoc, mul_zero] at hn
refine (eq_zero_iff_eq_zero_of_add_eq_zero ?_).mp hn
rw [← add_mul, ι_add_mul_swap, zero_mul]
end
variable (R) in
/-- The product of `n` terms of the form `ι R m` is an alternating map.
This is a special case of `MultilinearMap.mkPiAlgebraFin`, and the exterior algebra version of
`TensorAlgebra.tprod`. -/
def ιMulti (n : ℕ) : M [⋀^Fin n]→ₗ[R] ExteriorAlgebra R M :=
let F := (MultilinearMap.mkPiAlgebraFin R n (ExteriorAlgebra R M)).compLinearMap fun _ => ι R
{ F with
map_eq_zero_of_eq' := fun f x y hfxy hxy => by
dsimp [F]
clear F
wlog h : x < y
· exact this R n f y x hfxy.symm hxy.symm (hxy.lt_or_lt.resolve_left h)
clear hxy
induction n with
| zero => exact x.elim0
| succ n hn =>
rw [List.ofFn_succ, List.prod_cons]
by_cases hx : x = 0
-- one of the repeated terms is on the left
· rw [hx] at hfxy h
rw [hfxy, ← Fin.succ_pred y (ne_of_lt h).symm]
exact ι_mul_prod_list (f ∘ Fin.succ) _
-- ignore the left-most term and induct on the remaining ones, decrementing indices
· convert mul_zero (ι R (f 0))
refine
hn
(fun i => f <| Fin.succ i) (x.pred hx)
(y.pred (ne_of_lt <| lt_of_le_of_lt x.zero_le h).symm) ?_
(Fin.pred_lt_pred_iff.mpr h)
simp only [Fin.succ_pred]
exact hfxy
toFun := F }
theorem ιMulti_apply {n : ℕ} (v : Fin n → M) : ιMulti R n v = (List.ofFn fun i => ι R (v i)).prod :=
rfl
@[simp]
theorem ιMulti_zero_apply (v : Fin 0 → M) : ιMulti R 0 v = 1 := by
simp [ιMulti]
@[simp]
theorem ιMulti_succ_apply {n : ℕ} (v : Fin n.succ → M) :
ιMulti R _ v = ι R (v 0) * ιMulti R _ (Matrix.vecTail v) := by
simp [ιMulti, Matrix.vecTail]
theorem ιMulti_succ_curryLeft {n : ℕ} (m : M) :
(ιMulti R n.succ).curryLeft m = (LinearMap.mulLeft R (ι R m)).compAlternatingMap (ιMulti R n) :=
AlternatingMap.ext fun v =>
(ιMulti_succ_apply _).trans <| by
simp_rw [Matrix.tail_cons]
rfl
variable (R)
/-- The image of `ExteriorAlgebra.ιMulti R n` is contained in the `n`th exterior power. -/
lemma ιMulti_range (n : ℕ) :
Set.range (ιMulti R n (M := M)) ⊆ ↑(⋀[R]^n M) := by
rw [Set.range_subset_iff]
intro v
rw [ιMulti_apply]
apply Submodule.pow_subset_pow
rw [Set.mem_pow]
exact ⟨fun i => ⟨ι R (v i), LinearMap.mem_range_self _ _⟩, rfl⟩
/-- The image of `ExteriorAlgebra.ιMulti R n` spans the `n`th exterior power, as a submodule
of the exterior algebra. -/
lemma ιMulti_span_fixedDegree (n : ℕ) :
Submodule.span R (Set.range (ιMulti R n)) = ⋀[R]^n M := by
refine le_antisymm (Submodule.span_le.2 (ιMulti_range R n)) ?_
rw [exteriorPower, Submodule.pow_eq_span_pow_set, Submodule.span_le]
refine fun u hu ↦ Submodule.subset_span ?_
obtain ⟨f, rfl⟩ := Set.mem_pow.mp hu
refine ⟨fun i => ιInv (f i).1, ?_⟩
rw [ιMulti_apply]
congr with i
obtain ⟨v, hv⟩ := (f i).prop
rw [← hv, ι_leftInverse]
/-- Given a linearly ordered family `v` of vectors of `M` and a natural number `n`, produce the
family of `n`fold exterior products of elements of `v`, seen as members of the exterior algebra. -/
abbrev ιMulti_family (n : ℕ) {I : Type*} [LinearOrder I] (v : I → M)
(s : {s : Finset I // Finset.card s = n}) : ExteriorAlgebra R M :=
ιMulti R n fun i => v (Finset.orderIsoOfFin _ s.prop i)
variable {R}
/-- An `ExteriorAlgebra` over a nontrivial ring is nontrivial. -/
instance [Nontrivial R] : Nontrivial (ExteriorAlgebra R M) :=
(algebraMap_leftInverse M).injective.nontrivial
/-! Functoriality of the exterior algebra. -/
variable {N : Type u4} {N' : Type u5} [AddCommGroup N] [Module R N] [AddCommGroup N'] [Module R N']
/-- The morphism of exterior algebras induced by a linear map. -/
def map (f : M →ₗ[R] N) : ExteriorAlgebra R M →ₐ[R] ExteriorAlgebra R N :=
CliffordAlgebra.map { f with map_app' := fun _ => rfl }
@[simp]
theorem map_comp_ι (f : M →ₗ[R] N) : (map f).toLinearMap ∘ₗ ι R = ι R ∘ₗ f :=
CliffordAlgebra.map_comp_ι _
@[simp]
theorem map_apply_ι (f : M →ₗ[R] N) (m : M) : map f (ι R m) = ι R (f m) :=
CliffordAlgebra.map_apply_ι _ m
@[simp]
theorem map_apply_ιMulti {n : ℕ} (f : M →ₗ[R] N) (m : Fin n → M) :
map f (ιMulti R n m) = ιMulti R n (f ∘ m) := by
rw [ιMulti_apply, ιMulti_apply, map_list_prod]
simp only [List.map_ofFn, Function.comp_def, map_apply_ι]
@[simp]
theorem map_comp_ιMulti {n : ℕ} (f : M →ₗ[R] N) :
(map f).toLinearMap.compAlternatingMap (ιMulti R n (M := M)) =
(ιMulti R n (M := N)).compLinearMap f := by
ext m
exact map_apply_ιMulti _ _
@[simp]
theorem map_id :
map LinearMap.id = AlgHom.id R (ExteriorAlgebra R M) :=
CliffordAlgebra.map_id 0
@[simp]
theorem map_comp_map (f : M →ₗ[R] N) (g : N →ₗ[R] N') :
AlgHom.comp (map g) (map f) = map (LinearMap.comp g f) :=
CliffordAlgebra.map_comp_map _ _
@[simp]
theorem ι_range_map_map (f : M →ₗ[R] N) :
Submodule.map (AlgHom.toLinearMap (map f)) (LinearMap.range (ι R (M := M))) =
Submodule.map (ι R) (LinearMap.range f) :=
CliffordAlgebra.ι_range_map_map _
theorem toTrivSqZeroExt_comp_map [Module Rᵐᵒᵖ M] [IsCentralScalar R M] [Module Rᵐᵒᵖ N]
[IsCentralScalar R N] (f : M →ₗ[R] N) :
toTrivSqZeroExt.comp (map f) = (TrivSqZeroExt.map f).comp toTrivSqZeroExt := by
apply hom_ext
apply LinearMap.ext
simp only [AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply,
AlgHom.toLinearMap_apply, map_apply_ι, toTrivSqZeroExt_ι, TrivSqZeroExt.map_inr, forall_const]
theorem ιInv_comp_map (f : M →ₗ[R] N) :
ιInv.comp (map f).toLinearMap = f.comp ιInv := by
letI : Module Rᵐᵒᵖ M := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R M := ⟨fun r m => rfl⟩
letI : Module Rᵐᵒᵖ N := Module.compHom _ ((RingHom.id R).fromOpposite mul_comm)
haveI : IsCentralScalar R N := ⟨fun r m => rfl⟩
unfold ιInv
conv_lhs => rw [LinearMap.comp_assoc, ← AlgHom.comp_toLinearMap, toTrivSqZeroExt_comp_map,
AlgHom.comp_toLinearMap, ← LinearMap.comp_assoc, TrivSqZeroExt.sndHom_comp_map]
rfl
open Function in
/-- For a linear map `f` from `M` to `N`,
`ExteriorAlgebra.map g` is a retraction of `ExteriorAlgebra.map f` iff
`g` is a retraction of `f`. -/
@[simp]
lemma leftInverse_map_iff {f : M →ₗ[R] N} {g : N →ₗ[R] M} :
LeftInverse (map g) (map f) ↔ LeftInverse g f := by
refine ⟨fun h x => ?_, fun h => CliffordAlgebra.leftInverse_map_of_leftInverse _ _ h⟩
simpa using h (ι _ x)
/-- A morphism of modules that admits a linear retraction induces an injective morphism of
exterior algebras. -/
lemma map_injective {f : M →ₗ[R] N} (hf : ∃ (g : N →ₗ[R] M), g.comp f = LinearMap.id) :
Function.Injective (map f) :=
let ⟨_, hgf⟩ := hf; (leftInverse_map_iff.mpr (DFunLike.congr_fun hgf)).injective
/-- A morphism of modules is surjective if and only the morphism of exterior algebras that it
induces is surjective. -/
@[simp]
lemma map_surjective_iff {f : M →ₗ[R] N} :
Function.Surjective (map f) ↔ Function.Surjective f := by
refine ⟨fun h y ↦ ?_, fun h ↦ CliffordAlgebra.map_surjective _ h⟩
obtain ⟨x, hx⟩ := h (ι R y)
existsi ιInv x
rw [← LinearMap.comp_apply, ← ιInv_comp_map, LinearMap.comp_apply]
erw [hx, ExteriorAlgebra.ι_leftInverse]
|
variable {K E F : Type*} [Field K] [AddCommGroup E]
[Module K E] [AddCommGroup F] [Module K F]
/-- An injective morphism of vector spaces induces an injective morphism of exterior algebras. -/
lemma map_injective_field {f : E →ₗ[K] F} (hf : LinearMap.ker f = ⊥) :
Function.Injective (map f) :=
map_injective (LinearMap.exists_leftInverse_of_injective f hf)
end ExteriorAlgebra
| Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean | 440 | 449 |
/-
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Mario Carneiro
-/
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Star.Basic
import Mathlib.Data.Real.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
import Mathlib.Tactic.Ring
/-!
# The complex numbers
The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field
of characteristic zero. The result that the complex numbers are algebraically closed, see
`FieldTheory.AlgebraicClosure`.
-/
assert_not_exists Multiset Algebra
open Set Function
/-! ### Definition and basic arithmetic -/
/-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/
structure Complex : Type where
/-- The real part of a complex number. -/
re : ℝ
/-- The imaginary part of a complex number. -/
im : ℝ
@[inherit_doc] notation "ℂ" => Complex
namespace Complex
open ComplexConjugate
noncomputable instance : DecidableEq ℂ :=
Classical.decEq _
/-- The equivalence between the complex numbers and `ℝ × ℝ`. -/
@[simps apply]
def equivRealProd : ℂ ≃ ℝ × ℝ where
toFun z := ⟨z.re, z.im⟩
invFun p := ⟨p.1, p.2⟩
left_inv := fun ⟨_, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
@[simp]
theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z
| ⟨_, _⟩ => rfl
-- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear.
theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w
| ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl
attribute [local ext] Complex.ext
lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop
lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop
theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩
theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩
@[simp]
theorem range_re : range re = univ :=
re_surjective.range_eq
@[simp]
theorem range_im : range im = univ :=
im_surjective.range_eq
/-- The natural inclusion of the real numbers into the complex numbers. -/
@[coe]
def ofReal (r : ℝ) : ℂ :=
⟨r, 0⟩
instance : Coe ℝ ℂ :=
⟨ofReal⟩
@[simp, norm_cast]
theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r :=
rfl
@[simp, norm_cast]
theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 :=
rfl
theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ :=
rfl
@[simp, norm_cast]
theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w :=
⟨congrArg re, by apply congrArg⟩
theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re
instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where
prf z hz := ⟨z.re, ext rfl hz.symm⟩
/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,
denoted by `s ×ℂ t`. -/
def reProdIm (s t : Set ℝ) : Set ℂ :=
re ⁻¹' s ∩ im ⁻¹' t
@[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm
@[inherit_doc]
infixl:72 " ×ℂ " => reProdIm
theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t :=
Iff.rfl
instance : Zero ℂ :=
⟨(0 : ℝ)⟩
instance : Inhabited ℂ :=
⟨0⟩
@[simp]
theorem zero_re : (0 : ℂ).re = 0 :=
rfl
@[simp]
theorem zero_im : (0 : ℂ).im = 0 :=
rfl
@[simp, norm_cast]
theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 :=
rfl
@[simp]
theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 :=
ofReal_inj
theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 :=
not_congr ofReal_eq_zero
instance : One ℂ :=
⟨(1 : ℝ)⟩
@[simp]
theorem one_re : (1 : ℂ).re = 1 :=
rfl
@[simp]
theorem one_im : (1 : ℂ).im = 0 :=
rfl
@[simp, norm_cast]
theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 :=
rfl
@[simp]
theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 :=
ofReal_inj
theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 :=
not_congr ofReal_eq_one
instance : Add ℂ :=
⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩
@[simp]
theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re :=
rfl
@[simp]
theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im :=
rfl
-- replaced by `re_ofNat`
-- replaced by `im_ofNat`
@[simp, norm_cast]
theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=
Complex.ext_iff.2 <| by simp [ofReal]
-- replaced by `Complex.ofReal_ofNat`
instance : Neg ℂ :=
⟨fun z => ⟨-z.re, -z.im⟩⟩
@[simp]
theorem neg_re (z : ℂ) : (-z).re = -z.re :=
rfl
@[simp]
theorem neg_im (z : ℂ) : (-z).im = -z.im :=
rfl
@[simp, norm_cast]
theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r :=
Complex.ext_iff.2 <| by simp [ofReal]
instance : Sub ℂ :=
⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩
instance : Mul ℂ :=
⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩
@[simp]
theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im :=
rfl
@[simp]
theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
@[simp, norm_cast]
theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s :=
Complex.ext_iff.2 <| by simp [ofReal]
theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal]
theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal]
lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal]
lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal]
theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ :=
ext (re_ofReal_mul _ _) (im_ofReal_mul _ _)
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
def I : ℂ :=
⟨0, 1⟩
@[simp]
theorem I_re : I.re = 0 :=
rfl
@[simp]
theorem I_im : I.im = 1 :=
rfl
@[simp]
theorem I_mul_I : I * I = -1 :=
Complex.ext_iff.2 <| by simp
theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ :=
Complex.ext_iff.2 <| by simp
@[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm
theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I :=
Complex.ext_iff.2 <| by simp [ofReal]
@[simp]
theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=
Complex.ext_iff.2 <| by simp [ofReal]
theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp
theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp
theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by simp
theorem I_mul_im (z : ℂ) : (I * z).im = z.re := by simp
@[simp]
theorem equivRealProd_symm_apply (p : ℝ × ℝ) : equivRealProd.symm p = p.1 + p.2 * I := by
ext <;> simp [Complex.equivRealProd, ofReal]
/-- The natural `AddEquiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps! +simpRhs apply symm_apply_re symm_apply_im]
def equivRealProdAddHom : ℂ ≃+ ℝ × ℝ :=
{ equivRealProd with map_add' := by simp }
theorem equivRealProdAddHom_symm_apply (p : ℝ × ℝ) :
equivRealProdAddHom.symm p = p.1 + p.2 * I := equivRealProd_symm_apply p
/-! ### Commutative ring instance and lemmas -/
/- We use a nonstandard formula for the `ℕ` and `ℤ` actions to make sure there is no
diamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity
defined in `Data.Complex.Module`. -/
instance : Nontrivial ℂ :=
domain_nontrivial re rfl rfl
namespace SMul
-- The useless `0` multiplication in `smul` is to make sure that
-- `RestrictScalars.module ℝ ℂ ℂ = Complex.module` definitionally.
-- instance made scoped to avoid situations like instance synthesis
-- of `SMul ℂ ℂ` trying to proceed via `SMul ℂ ℝ`.
/-- Scalar multiplication by `R` on `ℝ` extends to `ℂ`. This is used here and in
`Matlib.Data.Complex.Module` to transfer instances from `ℝ` to `ℂ`, but is not
needed outside, so we make it scoped. -/
scoped instance instSMulRealComplex {R : Type*} [SMul R ℝ] : SMul R ℂ where
smul r x := ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩
end SMul
open scoped SMul
section SMul
variable {R : Type*} [SMul R ℝ]
theorem smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(· • ·), SMul.smul]
theorem smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(· • ·), SMul.smul]
@[simp]
theorem real_smul {x : ℝ} {z : ℂ} : x • z = x * z :=
rfl
end SMul
instance addCommGroup : AddCommGroup ℂ :=
{ zero := (0 : ℂ)
add := (· + ·)
neg := Neg.neg
sub := Sub.sub
nsmul := fun n z => n • z
zsmul := fun n z => n • z
zsmul_zero' := by intros; ext <;> simp [smul_re, smul_im]
nsmul_zero := by intros; ext <;> simp [smul_re, smul_im]
nsmul_succ := by intros; ext <;> simp [smul_re, smul_im] <;> ring
zsmul_succ' := by intros; ext <;> simp [smul_re, smul_im] <;> ring
zsmul_neg' := by intros; ext <;> simp [smul_re, smul_im] <;> ring
add_assoc := by intros; ext <;> simp <;> ring
zero_add := by intros; ext <;> simp
add_zero := by intros; ext <;> simp
add_comm := by intros; ext <;> simp <;> ring
neg_add_cancel := by intros; ext <;> simp }
instance addGroupWithOne : AddGroupWithOne ℂ :=
{ Complex.addCommGroup with
natCast := fun n => ⟨n, 0⟩
natCast_zero := by
ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero]
natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ]
intCast := fun n => ⟨n, 0⟩
intCast_ofNat := fun _ => by ext <;> rfl
intCast_negSucc := fun n => by
ext
· simp [AddGroupWithOne.intCast_negSucc]
show -(1 : ℝ) + (-n) = -(↑(n + 1))
simp [Nat.cast_add, add_comm]
· simp [AddGroupWithOne.intCast_negSucc]
show im ⟨n, 0⟩ = 0
rfl
one := 1 }
instance commRing : CommRing ℂ :=
{ addGroupWithOne with
mul := (· * ·)
npow := @npowRec _ ⟨(1 : ℂ)⟩ ⟨(· * ·)⟩
add_comm := by intros; ext <;> simp <;> ring
left_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring
right_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring
zero_mul := by intros; ext <;> simp
mul_zero := by intros; ext <;> simp
mul_assoc := by intros; ext <;> simp <;> ring
one_mul := by intros; ext <;> simp
mul_one := by intros; ext <;> simp
mul_comm := by intros; ext <;> simp <;> ring }
/-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field`
instance. -/
instance : Ring ℂ := by infer_instance
/-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable
`Complex.field` instance. -/
instance : CommSemiring ℂ :=
inferInstance
/-- This shortcut instance ensures we do not find `Semiring` via the noncomputable
`Complex.field` instance. -/
instance : Semiring ℂ :=
inferInstance
/-- The "real part" map, considered as an additive group homomorphism. -/
def reAddGroupHom : ℂ →+ ℝ where
toFun := re
map_zero' := zero_re
map_add' := add_re
@[simp]
theorem coe_reAddGroupHom : (reAddGroupHom : ℂ → ℝ) = re :=
rfl
/-- The "imaginary part" map, considered as an additive group homomorphism. -/
def imAddGroupHom : ℂ →+ ℝ where
toFun := im
map_zero' := zero_im
map_add' := add_im
@[simp]
theorem coe_imAddGroupHom : (imAddGroupHom : ℂ → ℝ) = im :=
rfl
/-! ### Cast lemmas -/
instance instNNRatCast : NNRatCast ℂ where nnratCast q := ofReal q
instance instRatCast : RatCast ℂ where ratCast q := ofReal q
@[simp, norm_cast] lemma ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ofReal ofNat(n) = ofNat(n) := rfl
@[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ofReal n = n := rfl
@[simp, norm_cast] lemma ofReal_intCast (n : ℤ) : ofReal n = n := rfl
@[simp, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ofReal q = q := rfl
@[simp, norm_cast] lemma ofReal_ratCast (q : ℚ) : ofReal q = q := rfl
@[simp]
lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).re = ofNat(n) := rfl
@[simp] lemma im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma natCast_re (n : ℕ) : (n : ℂ).re = n := rfl
@[simp, norm_cast] lemma natCast_im (n : ℕ) : (n : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma intCast_re (n : ℤ) : (n : ℂ).re = n := rfl
@[simp, norm_cast] lemma intCast_im (n : ℤ) : (n : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℂ).re = q := rfl
@[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl
lemma re_nsmul (n : ℕ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_nsmul (n : ℕ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
lemma re_zsmul (n : ℤ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_zsmul (n : ℤ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
@[simp] lemma re_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).im = q • z.im := smul_im ..
@[simp] lemma re_qsmul (q : ℚ) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_qsmul (q : ℚ) (z : ℂ) : (q • z).im = q • z.im := smul_im ..
@[norm_cast] lemma ofReal_nsmul (n : ℕ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp
@[norm_cast] lemma ofReal_zsmul (n : ℤ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp
/-! ### Complex conjugation -/
/-- This defines the complex conjugate as the `star` operation of the `StarRing ℂ`. It
is recommended to use the ring endomorphism version `starRingEnd`, available under the
notation `conj` in the locale `ComplexConjugate`. -/
instance : StarRing ℂ where
star z := ⟨z.re, -z.im⟩
star_involutive x := by simp only [eta, neg_neg]
star_mul a b := by ext <;> simp [add_comm] <;> ring
star_add a b := by ext <;> simp [add_comm]
@[simp]
theorem conj_re (z : ℂ) : (conj z).re = z.re :=
rfl
@[simp]
theorem conj_im (z : ℂ) : (conj z).im = -z.im :=
rfl
@[simp]
theorem conj_ofReal (r : ℝ) : conj (r : ℂ) = r :=
Complex.ext_iff.2 <| by simp [star]
@[simp]
theorem conj_I : conj I = -I :=
Complex.ext_iff.2 <| by simp
theorem conj_natCast (n : ℕ) : conj (n : ℂ) = n := map_natCast _ _
theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (ofNat(n) : ℂ) = ofNat(n) :=
map_ofNat _ _
theorem conj_neg_I : conj (-I) = I := by simp
theorem conj_eq_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
⟨fun h => ⟨z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)⟩, fun ⟨h, e⟩ => by
rw [e, conj_ofReal]⟩
theorem conj_eq_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
conj_eq_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp [ofReal], fun h => ⟨_, h.symm⟩⟩
theorem conj_eq_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 :=
⟨fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h =>
ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩
@[simp]
theorem star_def : (Star.star : ℂ → ℂ) = conj :=
rfl
/-! ### Norm squared -/
/-- The norm squared function. -/
@[pp_nodot]
def normSq : ℂ →*₀ ℝ where
toFun z := z.re * z.re + z.im * z.im
map_zero' := by simp
map_one' := by simp
map_mul' z w := by
dsimp
ring
theorem normSq_apply (z : ℂ) : normSq z = z.re * z.re + z.im * z.im :=
rfl
@[simp]
theorem normSq_ofReal (r : ℝ) : normSq r = r * r := by
simp [normSq, ofReal]
@[simp]
theorem normSq_natCast (n : ℕ) : normSq n = n * n := normSq_ofReal _
@[simp]
theorem normSq_intCast (z : ℤ) : normSq z = z * z := normSq_ofReal _
@[simp]
theorem normSq_ratCast (q : ℚ) : normSq q = q * q := normSq_ofReal _
@[simp]
theorem normSq_ofNat (n : ℕ) [n.AtLeastTwo] :
normSq (ofNat(n) : ℂ) = ofNat(n) * ofNat(n) :=
normSq_natCast _
@[simp]
theorem normSq_mk (x y : ℝ) : normSq ⟨x, y⟩ = x * x + y * y :=
rfl
theorem normSq_add_mul_I (x y : ℝ) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by
rw [← mk_eq_add_mul_I, normSq_mk, sq, sq]
theorem normSq_eq_conj_mul_self {z : ℂ} : (normSq z : ℂ) = conj z * z := by
ext <;> simp [normSq, mul_comm, ofReal]
theorem normSq_zero : normSq 0 = 0 := by simp
theorem normSq_one : normSq 1 = 1 := by simp
@[simp]
theorem normSq_I : normSq I = 1 := by simp [normSq]
theorem normSq_nonneg (z : ℂ) : 0 ≤ normSq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
theorem normSq_eq_zero {z : ℂ} : normSq z = 0 ↔ z = 0 :=
⟨fun h =>
ext (eq_zero_of_mul_self_add_mul_self_eq_zero h)
(eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h),
fun h => h.symm ▸ normSq_zero⟩
@[simp]
theorem normSq_pos {z : ℂ} : 0 < normSq z ↔ z ≠ 0 :=
(normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero)
@[simp]
theorem normSq_neg (z : ℂ) : normSq (-z) = normSq z := by simp [normSq]
@[simp]
theorem normSq_conj (z : ℂ) : normSq (conj z) = normSq z := by simp [normSq]
theorem normSq_mul (z w : ℂ) : normSq (z * w) = normSq z * normSq w :=
normSq.map_mul z w
theorem normSq_add (z w : ℂ) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by
dsimp [normSq]; ring
theorem re_sq_le_normSq (z : ℂ) : z.re * z.re ≤ normSq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
theorem im_sq_le_normSq (z : ℂ) : z.im * z.im ≤ normSq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : ℂ) : z * conj z = normSq z :=
Complex.ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal]
theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
Complex.ext_iff.2 <| by simp [two_mul, ofReal]
/-- The coercion `ℝ → ℂ` as a `RingHom`. -/
def ofRealHom : ℝ →+* ℂ where
toFun x := (x : ℂ)
map_one' := ofReal_one
map_zero' := ofReal_zero
map_mul' := ofReal_mul
map_add' := ofReal_add
@[simp] lemma ofRealHom_eq_coe (r : ℝ) : ofRealHom r = r := rfl
variable {α : Type*}
@[simp] lemma ofReal_comp_add (f g : α → ℝ) : ofReal ∘ (f + g) = ofReal ∘ f + ofReal ∘ g :=
map_comp_add ofRealHom ..
@[simp] lemma ofReal_comp_sub (f g : α → ℝ) : ofReal ∘ (f - g) = ofReal ∘ f - ofReal ∘ g :=
map_comp_sub ofRealHom ..
@[simp] lemma ofReal_comp_neg (f : α → ℝ) : ofReal ∘ (-f) = -(ofReal ∘ f) :=
map_comp_neg ofRealHom _
lemma ofReal_comp_nsmul (n : ℕ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) :=
map_comp_nsmul ofRealHom ..
lemma ofReal_comp_zsmul (n : ℤ) (f : α → ℝ) : ofReal ∘ (n • f) = n • (ofReal ∘ f) :=
map_comp_zsmul ofRealHom ..
@[simp] lemma ofReal_comp_mul (f g : α → ℝ) : ofReal ∘ (f * g) = ofReal ∘ f * ofReal ∘ g :=
map_comp_mul ofRealHom ..
@[simp] lemma ofReal_comp_pow (f : α → ℝ) (n : ℕ) : ofReal ∘ (f ^ n) = (ofReal ∘ f) ^ n :=
map_comp_pow ofRealHom ..
@[simp]
theorem I_sq : I ^ 2 = -1 := by rw [sq, I_mul_I]
@[simp]
lemma I_pow_three : I ^ 3 = -I := by rw [pow_succ, I_sq, neg_one_mul]
@[simp]
theorem I_pow_four : I ^ 4 = 1 := by rw [(by norm_num : 4 = 2 * 2), pow_mul, I_sq, neg_one_sq]
lemma I_pow_eq_pow_mod (n : ℕ) : I ^ n = I ^ (n % 4) := by
conv_lhs => rw [← Nat.div_add_mod n 4]
simp [pow_add, pow_mul, I_pow_four]
@[simp]
theorem sub_re (z w : ℂ) : (z - w).re = z.re - w.re :=
rfl
@[simp]
theorem sub_im (z w : ℂ) : (z - w).im = z.im - w.im :=
rfl
@[simp, norm_cast]
theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s :=
Complex.ext_iff.2 <| by simp [ofReal]
@[simp, norm_cast]
theorem ofReal_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n := by
induction n <;> simp [*, ofReal_mul, pow_succ]
theorem sub_conj (z : ℂ) : z - conj z = (2 * z.im : ℝ) * I :=
Complex.ext_iff.2 <| by simp [two_mul, sub_eq_add_neg, ofReal]
theorem normSq_sub (z w : ℂ) : normSq (z - w) = normSq z + normSq w - 2 * (z * conj w).re := by
rw [sub_eq_add_neg, normSq_add]
simp only [RingHom.map_neg, mul_neg, neg_re, normSq_neg]
ring
/-! ### Inversion -/
noncomputable instance : Inv ℂ :=
⟨fun z => conj z * ((normSq z)⁻¹ : ℝ)⟩
theorem inv_def (z : ℂ) : z⁻¹ = conj z * ((normSq z)⁻¹ : ℝ) :=
rfl
@[simp]
theorem inv_re (z : ℂ) : z⁻¹.re = z.re / normSq z := by simp [inv_def, division_def, ofReal]
@[simp]
theorem inv_im (z : ℂ) : z⁻¹.im = -z.im / normSq z := by simp [inv_def, division_def, ofReal]
@[simp, norm_cast]
theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : ℂ) = (r : ℂ)⁻¹ :=
Complex.ext_iff.2 <| by simp [ofReal]
protected theorem inv_zero : (0⁻¹ : ℂ) = 0 := by
rw [← ofReal_zero, ← ofReal_inv, inv_zero]
protected theorem mul_inv_cancel {z : ℂ} (h : z ≠ 0) : z * z⁻¹ = 1 := by
rw [inv_def, ← mul_assoc, mul_conj, ← ofReal_mul, mul_inv_cancel₀ (mt normSq_eq_zero.1 h),
ofReal_one]
noncomputable instance instDivInvMonoid : DivInvMonoid ℂ where
lemma div_re (z w : ℂ) : (z / w).re = z.re * w.re / normSq w + z.im * w.im / normSq w := by
simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg]
lemma div_im (z w : ℂ) : (z / w).im = z.im * w.re / normSq w - z.re * w.im / normSq w := by
simp [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm]
/-! ### Field instance and lemmas -/
noncomputable instance instField : Field ℂ where
mul_inv_cancel := @Complex.mul_inv_cancel
inv_zero := Complex.inv_zero
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast_def q := by ext <;> simp [NNRat.cast_def, div_re, div_im, mul_div_mul_comm]
ratCast_def q := by ext <;> simp [Rat.cast_def, div_re, div_im, mul_div_mul_comm]
nnqsmul_def n z := Complex.ext_iff.2 <| by simp [NNRat.smul_def, smul_re, smul_im]
qsmul_def n z := Complex.ext_iff.2 <| by simp [Rat.smul_def, smul_re, smul_im]
@[simp, norm_cast]
lemma ofReal_nnqsmul (q : ℚ≥0) (r : ℝ) : ofReal (q • r) = q • r := by simp [NNRat.smul_def]
@[simp, norm_cast]
lemma ofReal_qsmul (q : ℚ) (r : ℝ) : ofReal (q • r) = q • r := by simp [Rat.smul_def]
theorem conj_inv (x : ℂ) : conj x⁻¹ = (conj x)⁻¹ :=
star_inv₀ _
@[simp, norm_cast]
theorem ofReal_div (r s : ℝ) : ((r / s : ℝ) : ℂ) = r / s := map_div₀ ofRealHom r s
@[simp, norm_cast]
theorem ofReal_zpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : ℂ) = (r : ℂ) ^ n := map_zpow₀ ofRealHom r n
@[simp]
theorem div_I (z : ℂ) : z / I = -(z * I) :=
(div_eq_iff_mul_eq I_ne_zero).2 <| by simp [mul_assoc]
@[simp]
theorem inv_I : I⁻¹ = -I := by
rw [inv_eq_one_div, div_I, one_mul]
theorem normSq_inv (z : ℂ) : normSq z⁻¹ = (normSq z)⁻¹ := by simp
theorem normSq_div (z w : ℂ) : normSq (z / w) = normSq z / normSq w := by simp
lemma div_ofReal (z : ℂ) (x : ℝ) : z / x = ⟨z.re / x, z.im / x⟩ := by
simp_rw [div_eq_inv_mul, ← ofReal_inv, ofReal_mul']
lemma div_natCast (z : ℂ) (n : ℕ) : z / n = ⟨z.re / n, z.im / n⟩ :=
mod_cast div_ofReal z n
lemma div_intCast (z : ℂ) (n : ℤ) : z / n = ⟨z.re / n, z.im / n⟩ :=
mod_cast div_ofReal z n
lemma div_ratCast (z : ℂ) (x : ℚ) : z / x = ⟨z.re / x, z.im / x⟩ :=
mod_cast div_ofReal z x
lemma div_ofNat (z : ℂ) (n : ℕ) [n.AtLeastTwo] :
z / ofNat(n) = ⟨z.re / ofNat(n), z.im / ofNat(n)⟩ :=
div_natCast z n
@[simp] lemma div_ofReal_re (z : ℂ) (x : ℝ) : (z / x).re = z.re / x := by rw [div_ofReal]
@[simp] lemma div_ofReal_im (z : ℂ) (x : ℝ) : (z / x).im = z.im / x := by rw [div_ofReal]
@[simp] lemma div_natCast_re (z : ℂ) (n : ℕ) : (z / n).re = z.re / n := by rw [div_natCast]
@[simp] lemma div_natCast_im (z : ℂ) (n : ℕ) : (z / n).im = z.im / n := by rw [div_natCast]
@[simp] lemma div_intCast_re (z : ℂ) (n : ℤ) : (z / n).re = z.re / n := by rw [div_intCast]
@[simp] lemma div_intCast_im (z : ℂ) (n : ℤ) : (z / n).im = z.im / n := by rw [div_intCast]
@[simp] lemma div_ratCast_re (z : ℂ) (x : ℚ) : (z / x).re = z.re / x := by rw [div_ratCast]
@[simp] lemma div_ratCast_im (z : ℂ) (x : ℚ) : (z / x).im = z.im / x := by rw [div_ratCast]
@[simp]
lemma div_ofNat_re (z : ℂ) (n : ℕ) [n.AtLeastTwo] :
(z / ofNat(n)).re = z.re / ofNat(n) := div_natCast_re z n
@[simp]
lemma div_ofNat_im (z : ℂ) (n : ℕ) [n.AtLeastTwo] :
(z / ofNat(n)).im = z.im / ofNat(n) := div_natCast_im z n
/-! ### Characteristic zero -/
|
instance instCharZero : CharZero ℂ :=
| Mathlib/Data/Complex/Basic.lean | 752 | 753 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.