filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
IsSmall.lean
|
/-
Copyright (c) 2025 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.MorphismProperty.Basic
import Mathlib.Logic.Small.Basic
/-!
# Small classes of morphisms
A class of morphisms `W : MorphismProperty C` is `w`-small
if the corresponding set in `Set (Arrow C)` is.
-/
universe w t v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
namespace MorphismProperty
variable (W : MorphismProperty C)
/-- A class of morphisms `W : MorphismProperty C` is `w`-small
if the corresponding set in `Set (Arrow C)` is. -/
@[pp_with_univ]
class IsSmall : Prop where
small_toSet : Small.{w} W.toSet
attribute [instance] IsSmall.small_toSet
instance isSmall_ofHoms {ι : Type t} [Small.{w} ι] {A B : ι → C} (f : ∀ i, A i ⟶ B i) :
IsSmall.{w} (ofHoms f) := by
let φ (i : ι) : (ofHoms f).toSet := ⟨Arrow.mk (f i), ⟨i⟩⟩
have hφ : Function.Surjective φ := by
rintro ⟨⟨_, _, f⟩, ⟨i⟩⟩
exact ⟨i, rfl⟩
exact ⟨small_of_surjective hφ⟩
lemma isSmall_iff_eq_ofHoms :
IsSmall.{w} W ↔ ∃ (ι : Type w) (A B : ι → C) (f : ∀ i, A i ⟶ B i),
W = ofHoms f := by
constructor
· intro
refine ⟨Shrink.{w} W.toSet, _, _, fun i ↦ ((equivShrink _).symm i).1.hom, ?_⟩
ext A B f
rw [ofHoms_iff]
constructor
· intro hf
exact ⟨equivShrink _ ⟨f, hf⟩, by simp⟩
· rintro ⟨i, hi⟩
simp only [← W.arrow_mk_mem_toSet_iff, hi, Arrow.mk_eq, Subtype.coe_prop]
· rintro ⟨_, _, _, _, rfl⟩
infer_instance
end MorphismProperty
end CategoryTheory
|
div.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq.
(******************************************************************************)
(* This file deals with divisibility for natural numbers. *)
(* It contains the definitions of: *)
(* edivn m d == the pair composed of the quotient and remainder *)
(* of the Euclidean division of m by d. *)
(* m %/ d == quotient of the Euclidean division of m by d. *)
(* m %% d == remainder of the Euclidean division of m by d. *)
(* m = n %[mod d] <-> m equals n modulo d. *)
(* m == n %[mod d] <=> m equals n modulo d (boolean version). *)
(* m <> n %[mod d] <-> m differs from n modulo d. *)
(* m != n %[mod d] <=> m differs from n modulo d (boolean version). *)
(* d %| m <=> d divides m. *)
(* gcdn m n == the GCD of m and n. *)
(* egcdn m n == the extended GCD (Bezout coefficient pair) of m and n. *)
(* If egcdn m n = (u, v), then gcdn m n = m * u - n * v. *)
(* lcmn m n == the LCM of m and n. *)
(* coprime m n <=> m and n are coprime (:= gcdn m n == 1). *)
(* chinese m n r s == witness of the chinese remainder theorem. *)
(* We adjoin an m to operator suffixes to indicate a nested %% (modn), as in *)
(* modnDml : m %% d + n = m + n %[mod d]. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(** Euclidean division *)
Definition edivn_rec d :=
fix loop m q := if m - d is m'.+1 then loop m' q.+1 else (q, m).
Definition edivn m d := if d > 0 then edivn_rec d.-1 m 0 else (0, m).
Variant edivn_spec m d : nat * nat -> Type :=
EdivnSpec q r of m = q * d + r & (d > 0) ==> (r < d) : edivn_spec m d (q, r).
Lemma edivnP m d : edivn_spec m d (edivn m d).
Proof.
rewrite -[m in edivn_spec m]/(0 * d + m) /edivn; case: d => //= d.
elim/ltn_ind: m 0 => -[|m] IHm q //=; rewrite subn_if_gt.
case: ltnP => // le_dm; rewrite -[in m.+1](subnKC le_dm) -addSn.
by rewrite addnA -mulSnr; apply/IHm/leq_subr.
Qed.
Lemma edivn_eq d q r : r < d -> edivn (q * d + r) d = (q, r).
Proof.
move=> lt_rd; have d_gt0: 0 < d by apply: leq_trans lt_rd.
case: edivnP lt_rd => q' r'; rewrite d_gt0 /=.
wlog: q q' r r' / q <= q' by case/orP: (leq_total q q'); last symmetry; eauto.
have [||-> _ /addnI ->] //= := ltngtP q q'.
rewrite -(leq_pmul2r d_gt0) => /leq_add lt_qr _ eq_qr _ /lt_qr {lt_qr}.
by rewrite addnS ltnNge mulSn -addnA eq_qr addnCA addnA leq_addr.
Qed.
Definition divn m d := (edivn m d).1.
Notation "m %/ d" := (divn m d) : nat_scope.
(* We redefine modn so that it is structurally decreasing. *)
Definition modn_rec d := fix loop m := if m - d is m'.+1 then loop m' else m.
Definition modn m d := if d > 0 then modn_rec d.-1 m else m.
Notation "m %% d" := (modn m d) : nat_scope.
Notation "m = n %[mod d ]" := (m %% d = n %% d) : nat_scope.
Notation "m == n %[mod d ]" := (m %% d == n %% d) : nat_scope.
Notation "m <> n %[mod d ]" := (m %% d <> n %% d) : nat_scope.
Notation "m != n %[mod d ]" := (m %% d != n %% d) : nat_scope.
Lemma modn_def m d : m %% d = (edivn m d).2.
Proof.
case: d => //= d; rewrite /modn /edivn /=; elim/ltn_ind: m 0 => -[|m] IHm q //=.
by rewrite !subn_if_gt; case: (d <= m) => //; apply/IHm/leq_subr.
Qed.
Lemma edivn_def m d : edivn m d = (m %/ d, m %% d).
Proof. by rewrite /divn modn_def; case: (edivn m d). Qed.
Lemma divn_eq m d : m = m %/ d * d + m %% d.
Proof. by rewrite /divn modn_def; case: edivnP. Qed.
Lemma div0n d : 0 %/ d = 0. Proof. by case: d. Qed.
Lemma divn0 m : m %/ 0 = 0. Proof. by []. Qed.
Lemma mod0n d : 0 %% d = 0. Proof. by case: d. Qed.
Lemma modn0 m : m %% 0 = m. Proof. by []. Qed.
Lemma divn_small m d : m < d -> m %/ d = 0.
Proof. by move=> lt_md; rewrite /divn (edivn_eq 0). Qed.
Lemma divnMDl q m d : 0 < d -> (q * d + m) %/ d = q + m %/ d.
Proof.
move=> d_gt0; rewrite [in LHS](divn_eq m d) addnA -mulnDl.
by rewrite /divn edivn_eq // modn_def; case: edivnP; rewrite d_gt0.
Qed.
Lemma mulnK m d : 0 < d -> m * d %/ d = m.
Proof. by move=> d_gt0; rewrite -[m * d]addn0 divnMDl // div0n addn0. Qed.
Lemma mulKn m d : 0 < d -> d * m %/ d = m.
Proof. by move=> d_gt0; rewrite mulnC mulnK. Qed.
Lemma expnB p m n : p > 0 -> m >= n -> p ^ (m - n) = p ^ m %/ p ^ n.
Proof.
by move=> p_gt0 /subnK-Dm; rewrite -[in RHS]Dm expnD mulnK // expn_gt0 p_gt0.
Qed.
Lemma modn1 m : m %% 1 = 0.
Proof. by rewrite modn_def; case: edivnP => ? []. Qed.
Lemma divn1 m : m %/ 1 = m.
Proof. by rewrite [RHS](@divn_eq m 1) // modn1 addn0 muln1. Qed.
Lemma divnn d : d %/ d = (0 < d).
Proof. by case: d => // d; rewrite -[n in n %/ _]muln1 mulKn. Qed.
Lemma divnMl p m d : p > 0 -> p * m %/ (p * d) = m %/ d.
Proof.
move=> p_gt0; have [->|d_gt0] := posnP d; first by rewrite muln0.
rewrite [RHS]/divn; case: edivnP; rewrite d_gt0 /= => q r ->{m} lt_rd.
rewrite mulnDr mulnCA divnMDl; last by rewrite muln_gt0 p_gt0.
by rewrite addnC divn_small // ltn_pmul2l.
Qed.
Arguments divnMl [p m d].
Lemma divnMr p m d : p > 0 -> m * p %/ (d * p) = m %/ d.
Proof. by move=> p_gt0; rewrite -!(mulnC p) divnMl. Qed.
Arguments divnMr [p m d].
Lemma ltn_mod m d : (m %% d < d) = (0 < d).
Proof. by case: d => // d; rewrite modn_def; case: edivnP. Qed.
Lemma ltn_pmod m d : 0 < d -> m %% d < d.
Proof. by rewrite ltn_mod. Qed.
Lemma leq_divM m d : m %/ d * d <= m.
Proof. by rewrite [leqRHS](divn_eq m d) leq_addr. Qed.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divM.")]
Notation leq_trunc_div := leq_divM.
Lemma leq_mod m d : m %% d <= m.
Proof. by rewrite [leqRHS](divn_eq m d) leq_addl. Qed.
Lemma leq_div m d : m %/ d <= m.
Proof.
by case: d => // d; apply: leq_trans (leq_pmulr _ _) (leq_divM _ _).
Qed.
Lemma ltn_ceil m d : 0 < d -> m < (m %/ d).+1 * d.
Proof.
by move=> d_gt0; rewrite [in m.+1](divn_eq m d) -addnS mulSnr leq_add2l ltn_mod.
Qed.
Lemma ltn_divLR m n d : d > 0 -> (m %/ d < n) = (m < n * d).
Proof.
move=> d_gt0; apply/idP/idP.
by rewrite -(leq_pmul2r d_gt0); apply: leq_trans (ltn_ceil _ _).
rewrite !ltnNge -(@leq_pmul2r d n) //; apply: contra => le_nd_floor.
exact: leq_trans le_nd_floor (leq_divM _ _).
Qed.
Lemma leq_divRL m n d : d > 0 -> (m <= n %/ d) = (m * d <= n).
Proof. by move=> d_gt0; rewrite leqNgt ltn_divLR // -leqNgt. Qed.
Lemma ltn_Pdiv m d : 1 < d -> 0 < m -> m %/ d < m.
Proof. by move=> d_gt1 m_gt0; rewrite ltn_divLR ?ltn_Pmulr // ltnW. Qed.
Lemma divn_gt0 d m : 0 < d -> (0 < m %/ d) = (d <= m).
Proof. by move=> d_gt0; rewrite leq_divRL ?mul1n. Qed.
Lemma leq_div2r d m n : m <= n -> m %/ d <= n %/ d.
Proof.
have [-> //| d_gt0 le_mn] := posnP d.
by rewrite leq_divRL // (leq_trans _ le_mn) -?leq_divRL.
Qed.
Lemma leq_div2l m d e : 0 < d -> d <= e -> m %/ e <= m %/ d.
Proof.
move/leq_divRL=> -> le_de.
by apply: leq_trans (leq_divM m e); apply: leq_mul.
Qed.
Lemma edivnD m n d (offset := m %% d + n %% d >= d) : 0 < d ->
edivn (m + n) d = (m %/ d + n %/ d + offset, m %% d + n %% d - offset * d).
Proof.
rewrite {}/offset; case: d => // d _; rewrite /divn !modn_def.
case: (edivnP m d.+1) (edivnP n d.+1) => [/= q r -> r_lt] [/= p s -> s_lt].
rewrite addnACA -mulnDl; have [r_le s_le] := (ltnW r_lt, ltnW s_lt).
have [d_ge|d_lt] := leqP; first by rewrite addn0 mul0n subn0 edivn_eq.
rewrite addn1 mul1n -[in LHS](subnKC d_lt) addnA -mulSnr edivn_eq//.
by rewrite ltn_subLR// -addnS leq_add.
Qed.
Lemma divnD m n d : 0 < d ->
(m + n) %/ d = (m %/ d) + (n %/ d) + (m %% d + n %% d >= d).
Proof. by move=> /(@edivnD m n); rewrite edivn_def => -[]. Qed.
Lemma modnD m n d : 0 < d ->
(m + n) %% d = m %% d + n %% d - (m %% d + n %% d >= d) * d.
Proof. by move=> /(@edivnD m n); rewrite edivn_def => -[]. Qed.
Lemma leqDmod m n d : 0 < d ->
(d <= m %% d + n %% d) = ((m + n) %% d < n %% d).
Proof.
move=> d_gt0; rewrite modnD//.
have [d_le|_] := leqP d; last by rewrite subn0 ltnNge leq_addl.
by rewrite -(ltn_add2r d) mul1n (subnK d_le) addnC ltn_add2l ltn_pmod.
Qed.
Lemma divnB n m d : 0 < d ->
(m - n) %/ d = (m %/ d) - (n %/ d) - (m %% d < n %% d).
Proof.
move=> d_gt0; have [mn|/ltnW nm] := leqP m n.
by rewrite (eqP mn) (eqP (leq_div2r _ _)) ?div0n.
by rewrite -[in m %/ d](subnK nm) divnD// addnAC addnK leqDmod ?subnK ?addnK.
Qed.
Lemma modnB m n d : 0 < d -> n <= m ->
(m - n) %% d = (m %% d < n %% d) * d + m %% d - n %% d.
Proof.
move=> d_gt0 nm; rewrite -[in m %% _](subnK nm) -leqDmod// modnD//.
have [d_le|_] := leqP d; last by rewrite mul0n add0n subn0 addnK.
by rewrite mul1n addnBA// addnC !addnK.
Qed.
Lemma edivnB m n d (offset := m %% d < n %% d) : 0 < d -> n <= m ->
edivn (m - n) d = (m %/ d - n %/ d - offset, offset * d + m %% d - n %% d).
Proof. by move=> d_gt0 le_nm; rewrite edivn_def divnB// modnB. Qed.
Lemma leq_divDl p m n : (m + n) %/ p <= m %/ p + n %/ p + 1.
Proof. by have [->//|p_gt0] := posnP p; rewrite divnD// !leq_add// leq_b1. Qed.
Lemma geq_divBl k m p : k %/ p - m %/ p <= (k - m) %/ p + 1.
Proof.
rewrite leq_subLR addnA; apply: leq_trans (leq_divDl _ _ _).
by rewrite -maxnE leq_div2r ?leq_maxr.
Qed.
Lemma divnMA m n p : m %/ (n * p) = m %/ n %/ p.
Proof.
case: n p => [|n] [|p]; rewrite ?muln0 ?div0n //.
rewrite [in RHS](divn_eq m (n.+1 * p.+1)) mulnA mulnAC !divnMDl //.
by rewrite [_ %/ p.+1]divn_small ?addn0 // ltn_divLR // mulnC ltn_mod.
Qed.
Lemma divnAC m n p : m %/ n %/ p = m %/ p %/ n.
Proof. by rewrite -!divnMA mulnC. Qed.
Lemma modn_small m d : m < d -> m %% d = m.
Proof. by move=> lt_md; rewrite [RHS](divn_eq m d) divn_small. Qed.
Lemma modn_mod m d : m %% d = m %[mod d].
Proof. by case: d => // d; apply: modn_small; rewrite ltn_mod. Qed.
Lemma modnMDl p m d : p * d + m = m %[mod d].
Proof.
have [->|d_gt0] := posnP d; first by rewrite muln0.
by rewrite [in LHS](divn_eq m d) addnA -mulnDl modn_def edivn_eq // ltn_mod.
Qed.
Lemma muln_modr p m d : p * (m %% d) = (p * m) %% (p * d).
Proof.
have [->//|p_gt0] := posnP p; apply: (@addnI (p * (m %/ d * d))).
by rewrite -mulnDr -divn_eq mulnCA -(divnMl p_gt0) -divn_eq.
Qed.
Lemma muln_modl p m d : (m %% d) * p = (m * p) %% (d * p).
Proof. by rewrite -!(mulnC p); apply: muln_modr. Qed.
Lemma modn_divl m n d : (m %/ d) %% n = m %% (n * d) %/ d.
Proof.
case: d n => [|d] [|n] //; rewrite [in LHS]/divn [in LHS]modn_def.
case: (edivnP m d.+1) edivnP => [/= _ r -> le_rd] [/= q s -> le_sn].
rewrite mulnDl -mulnA -addnA modnMDl modn_small ?divnMDl ?divn_small ?addn0//.
by rewrite mulSnr -addnS leq_add ?leq_mul2r.
Qed.
Lemma modnDl m d : d + m = m %[mod d].
Proof. by rewrite -[m %% _](modnMDl 1) mul1n. Qed.
Lemma modnDr m d : m + d = m %[mod d]. Proof. by rewrite addnC modnDl. Qed.
Lemma modnn d : d %% d = 0. Proof. by rewrite [d %% d](modnDr 0) mod0n. Qed.
Lemma modnMl p d : p * d %% d = 0.
Proof. by rewrite -[p * d]addn0 modnMDl mod0n. Qed.
Lemma modnMr p d : d * p %% d = 0. Proof. by rewrite mulnC modnMl. Qed.
Lemma modnDml m n d : m %% d + n = m + n %[mod d].
Proof. by rewrite [in RHS](divn_eq m d) -addnA modnMDl. Qed.
Lemma modnDmr m n d : m + n %% d = m + n %[mod d].
Proof. by rewrite !(addnC m) modnDml. Qed.
Lemma modnDm m n d : m %% d + n %% d = m + n %[mod d].
Proof. by rewrite modnDml modnDmr. Qed.
Lemma eqn_modDl p m n d : (p + m == p + n %[mod d]) = (m == n %[mod d]).
Proof.
case: d => [|d]; first by rewrite !modn0 eqn_add2l.
apply/eqP/eqP=> eq_mn; last by rewrite -modnDmr eq_mn modnDmr.
rewrite -(modnMDl p m) -(modnMDl p n) !mulnSr -!addnA.
by rewrite -modnDmr eq_mn modnDmr.
Qed.
Lemma eqn_modDr p m n d : (m + p == n + p %[mod d]) = (m == n %[mod d]).
Proof. by rewrite -!(addnC p) eqn_modDl. Qed.
Lemma modnMml m n d : m %% d * n = m * n %[mod d].
Proof. by rewrite [in RHS](divn_eq m d) mulnDl mulnAC modnMDl. Qed.
Lemma modnMmr m n d : m * (n %% d) = m * n %[mod d].
Proof. by rewrite !(mulnC m) modnMml. Qed.
Lemma modnMm m n d : m %% d * (n %% d) = m * n %[mod d].
Proof. by rewrite modnMml modnMmr. Qed.
Lemma modn2 m : m %% 2 = odd m.
Proof. by elim: m => //= m IHm; rewrite -addn1 -modnDml IHm; case odd. Qed.
Lemma divn2 m : m %/ 2 = m./2.
Proof. by rewrite [in RHS](divn_eq m 2) modn2 muln2 addnC half_bit_double. Qed.
Lemma odd_mod m d : odd d = false -> odd (m %% d) = odd m.
Proof.
by move=> d_even; rewrite [in RHS](divn_eq m d) oddD oddM d_even andbF.
Qed.
Lemma modnXm m n a : (a %% n) ^ m = a ^ m %[mod n].
Proof. by elim: m => // m IHm; rewrite !expnS -modnMmr IHm modnMml modnMmr. Qed.
Lemma modnMDXl p m n d : (p * d + m) ^ n = m ^ n %[mod d].
Proof. by elim: n => // n IH; rewrite !expnS -modnMm IH modnMDl modnMm. Qed.
(** Divisibility **)
Definition dvdn d m := m %% d == 0.
Notation "m %| d" := (dvdn m d) : nat_scope.
Lemma dvdnP d m : reflect (exists k, m = k * d) (d %| m).
Proof.
apply: (iffP eqP) => [md0 | [k ->]]; last by rewrite modnMl.
by exists (m %/ d); rewrite [LHS](divn_eq m d) md0 addn0.
Qed.
Arguments dvdnP {d m}.
Lemma dvdn0 d : d %| 0.
Proof. by case: d. Qed.
Lemma dvd0n n : (0 %| n) = (n == 0).
Proof. by case: n. Qed.
Lemma dvdn1 d : (d %| 1) = (d == 1).
Proof. by case: d => [|[|d]] //; rewrite /dvdn modn_small. Qed.
Lemma dvd1n m : 1 %| m.
Proof. by rewrite /dvdn modn1. Qed.
Lemma dvdn_gt0 d m : m > 0 -> d %| m -> d > 0.
Proof. by case: d => // /prednK <-. Qed.
Lemma dvdnn m : m %| m.
Proof. by rewrite /dvdn modnn. Qed.
Lemma dvdn_mull d m n : d %| n -> d %| m * n.
Proof. by case/dvdnP=> n' ->; rewrite /dvdn mulnA modnMl. Qed.
Lemma dvdn_mulr d m n : d %| m -> d %| m * n.
Proof. by move=> d_m; rewrite mulnC dvdn_mull. Qed.
#[global] Hint Resolve dvdn0 dvd1n dvdnn dvdn_mull dvdn_mulr : core.
Lemma dvdn_mul d1 d2 m1 m2 : d1 %| m1 -> d2 %| m2 -> d1 * d2 %| m1 * m2.
Proof.
by move=> /dvdnP[q1 ->] /dvdnP[q2 ->]; rewrite mulnCA -mulnA 2?dvdn_mull.
Qed.
Lemma dvdn_trans n d m : d %| n -> n %| m -> d %| m.
Proof. by move=> d_dv_n /dvdnP[n1 ->]; apply: dvdn_mull. Qed.
Lemma dvdn_eq d m : (d %| m) = (m %/ d * d == m).
Proof.
apply/eqP/eqP=> [modm0 | <-]; last exact: modnMl.
by rewrite [RHS](divn_eq m d) modm0 addn0.
Qed.
Lemma dvdn2 n : (2 %| n) = ~~ odd n.
Proof. by rewrite /dvdn modn2; case (odd n). Qed.
Lemma dvdn_odd m n : m %| n -> odd n -> odd m.
Proof. by move=> m_dv_n; apply: contraTT; rewrite -!dvdn2 => /dvdn_trans->. Qed.
Lemma divnK d m : d %| m -> m %/ d * d = m.
Proof. by rewrite dvdn_eq; move/eqP. Qed.
Lemma leq_divLR d m n : d %| m -> (m %/ d <= n) = (m <= n * d).
Proof. by case: d m => [|d] [|m] ///divnK=> {2}<-; rewrite leq_pmul2r. Qed.
Lemma ltn_divRL d m n : d %| m -> (n < m %/ d) = (n * d < m).
Proof. by move=> dv_d_m; rewrite !ltnNge leq_divLR. Qed.
Lemma eqn_div d m n : d > 0 -> d %| m -> (n == m %/ d) = (n * d == m).
Proof. by move=> d_gt0 dv_d_m; rewrite -(eqn_pmul2r d_gt0) divnK. Qed.
Lemma eqn_mul d m n : d > 0 -> d %| m -> (m == n * d) = (m %/ d == n).
Proof. by move=> d_gt0 dv_d_m; rewrite eq_sym -eqn_div // eq_sym. Qed.
Lemma divn_mulAC d m n : d %| m -> m %/ d * n = m * n %/ d.
Proof.
case: d m => [[] //| d m] dv_d_m; apply/eqP.
by rewrite eqn_div ?dvdn_mulr // mulnAC divnK.
Qed.
Lemma muln_divA d m n : d %| n -> m * (n %/ d) = m * n %/ d.
Proof. by move=> dv_d_m; rewrite !(mulnC m) divn_mulAC. Qed.
Lemma muln_divCA d m n : d %| m -> d %| n -> m * (n %/ d) = n * (m %/ d).
Proof. by move=> dv_d_m dv_d_n; rewrite mulnC divn_mulAC ?muln_divA. Qed.
Lemma divnA m n p : p %| n -> m %/ (n %/ p) = m * p %/ n.
Proof. by case: p => [|p] dv_n; rewrite -[in RHS](divnK dv_n) // divnMr. Qed.
Lemma modn_dvdm m n d : d %| m -> n %% m = n %[mod d].
Proof.
by case/dvdnP=> q def_m; rewrite [in RHS](divn_eq n m) def_m mulnA modnMDl.
Qed.
Lemma dvdn_leq d m : 0 < m -> d %| m -> d <= m.
Proof. by move=> m_gt0 /dvdnP[[|k] Dm]; rewrite Dm // leq_addr in m_gt0 *. Qed.
Lemma gtnNdvd n d : 0 < n -> n < d -> (d %| n) = false.
Proof. by move=> n_gt0 lt_nd; rewrite /dvdn eqn0Ngt modn_small ?n_gt0. Qed.
Lemma eqn_dvd m n : (m == n) = (m %| n) && (n %| m).
Proof.
case: m n => [|m] [|n] //; apply/idP/andP => [/eqP -> //| []].
by rewrite eqn_leq => Hmn Hnm; do 2 rewrite dvdn_leq //.
Qed.
Lemma dvdn_pmul2l p d m : 0 < p -> (p * d %| p * m) = (d %| m).
Proof. by case: p => // p _; rewrite /dvdn -muln_modr // muln_eq0. Qed.
Arguments dvdn_pmul2l [p d m].
Lemma dvdn_pmul2r p d m : 0 < p -> (d * p %| m * p) = (d %| m).
Proof. by move=> p_gt0; rewrite -!(mulnC p) dvdn_pmul2l. Qed.
Arguments dvdn_pmul2r [p d m].
Lemma dvdn_divLR p d m : 0 < p -> p %| d -> (d %/ p %| m) = (d %| m * p).
Proof. by move=> /(@dvdn_pmul2r p _ m) <- /divnK->. Qed.
Lemma dvdn_divRL p d m : p %| m -> (d %| m %/ p) = (d * p %| m).
Proof.
have [-> | /(@dvdn_pmul2r p d) <- /divnK-> //] := posnP p.
by rewrite divn0 muln0 dvdn0.
Qed.
Lemma dvdn_div d m : d %| m -> m %/ d %| m.
Proof. by move/divnK=> {2}<-; apply: dvdn_mulr. Qed.
Lemma dvdn_exp2l p m n : m <= n -> p ^ m %| p ^ n.
Proof. by move/subnK <-; rewrite expnD dvdn_mull. Qed.
Lemma dvdn_Pexp2l p m n : p > 1 -> (p ^ m %| p ^ n) = (m <= n).
Proof.
move=> p_gt1; case: leqP => [|gt_n_m]; first exact: dvdn_exp2l.
by rewrite gtnNdvd ?ltn_exp2l ?expn_gt0 // ltnW.
Qed.
Lemma dvdn_exp2r m n k : m %| n -> m ^ k %| n ^ k.
Proof. by case/dvdnP=> q ->; rewrite expnMn dvdn_mull. Qed.
Lemma divn_modl m n d : d %| n -> (m %% n) %/ d = (m %/ d) %% (n %/ d).
Proof. by move=> dvd_dn; rewrite modn_divl divnK. Qed.
Lemma dvdn_addr m d n : d %| m -> (d %| m + n) = (d %| n).
Proof. by case/dvdnP=> q ->; rewrite /dvdn modnMDl. Qed.
Lemma dvdn_addl n d m : d %| n -> (d %| m + n) = (d %| m).
Proof. by rewrite addnC; apply: dvdn_addr. Qed.
Lemma dvdn_add d m n : d %| m -> d %| n -> d %| m + n.
Proof. by move/dvdn_addr->. Qed.
Lemma dvdn_add_eq d m n : d %| m + n -> (d %| m) = (d %| n).
Proof. by move=> dv_d_mn; apply/idP/idP => [/dvdn_addr | /dvdn_addl] <-. Qed.
Lemma dvdn_subr d m n : n <= m -> d %| m -> (d %| m - n) = (d %| n).
Proof. by move=> le_n_m dv_d_m; apply: dvdn_add_eq; rewrite subnK. Qed.
Lemma dvdn_subl d m n : n <= m -> d %| n -> (d %| m - n) = (d %| m).
Proof. by move=> le_n_m dv_d_m; rewrite -(dvdn_addl _ dv_d_m) subnK. Qed.
Lemma dvdn_sub d m n : d %| m -> d %| n -> d %| m - n.
Proof.
by case: (leqP n m) => [le_nm /dvdn_subr <- // | /ltnW/eqnP ->]; rewrite dvdn0.
Qed.
Lemma dvdn_exp k d m : 0 < k -> d %| m -> d %| (m ^ k).
Proof. by case: k => // k _ d_dv_m; rewrite expnS dvdn_mulr. Qed.
Lemma dvdn_fact m n : 0 < m <= n -> m %| n`!.
Proof.
case: m => //= m; elim: n => //= n IHn; rewrite ltnS.
have [/IHn/dvdn_mull->||-> _] // := ltngtP m n; exact: dvdn_mulr.
Qed.
#[global] Hint Resolve dvdn_add dvdn_sub dvdn_exp : core.
Lemma eqn_mod_dvd d m n : n <= m -> (m == n %[mod d]) = (d %| m - n).
Proof.
by move/subnK=> Dm; rewrite -[n in LHS]add0n -[in LHS]Dm eqn_modDr mod0n.
Qed.
Lemma divnDMl q m d : 0 < d -> (m + q * d) %/ d = (m %/ d) + q.
Proof. by move=> d_gt0; rewrite addnC divnMDl// addnC. Qed.
Lemma divnMBl q m d : 0 < d -> (q * d - m) %/ d = q - (m %/ d) - (~~ (d %| m)).
Proof. by move=> d_gt0; rewrite divnB// mulnK// modnMl lt0n. Qed.
Lemma divnBMl q m d : (m - q * d) %/ d = (m %/ d) - q.
Proof. by case: d => [|d]//=; rewrite divnB// mulnK// modnMl ltn0 subn0. Qed.
Lemma divnDl m n d : d %| m -> (m + n) %/ d = m %/ d + n %/ d.
Proof. by case: d => // d /divnK-Dm; rewrite -[in LHS]Dm divnMDl. Qed.
Lemma divnDr m n d : d %| n -> (m + n) %/ d = m %/ d + n %/ d.
Proof. by move=> dv_n; rewrite addnC divnDl // addnC. Qed.
Lemma divnBl m n d : d %| m -> (m - n) %/ d = m %/ d - (n %/ d) - (~~ (d %| n)).
Proof. by case: d => [|d] // /divnK-Dm; rewrite -[in LHS]Dm divnMBl. Qed.
Lemma divnBr m n d : d %| n -> (m - n) %/ d = m %/ d - n %/ d.
Proof. by case: d => [|d]// /divnK-Dm; rewrite -[in LHS]Dm divnBMl. Qed.
Lemma edivnS m d : 0 < d -> edivn m.+1 d =
if d %| m.+1 then ((m %/ d).+1, 0) else (m %/ d, (m %% d).+1).
Proof.
case: d => [|[|d]] //= _; first by rewrite edivn_def modn1 dvd1n !divn1.
rewrite -addn1 /dvdn modn_def edivnD//= (@modn_small 1)// (@divn_small 1)//.
rewrite addn1 addn0 ltnS; have [||<-] := ltngtP d.+1.
- by rewrite ltnNge -ltnS ltn_pmod.
- by rewrite addn0 mul0n subn0.
- by rewrite addn1 mul1n subnn.
Qed.
Lemma modnS m d : m.+1 %% d = if d %| m.+1 then 0 else (m %% d).+1.
Proof. by case: d => [|d]//; rewrite modn_def edivnS//; case: ifP. Qed.
Lemma divnS m d : 0 < d -> m.+1 %/ d = (d %| m.+1) + m %/ d.
Proof. by move=> d_gt0; rewrite /divn edivnS//; case: ifP. Qed.
Lemma divn_pred m d : m.-1 %/ d = (m %/ d) - (d %| m).
Proof.
by case: d m => [|d] [|m]; rewrite ?divn1 ?dvd1n ?subn1//= divnS// addnC addnK.
Qed.
Lemma modn_pred m d : d != 1 -> 0 < m ->
m.-1 %% d = if d %| m then d.-1 else (m %% d).-1.
Proof.
rewrite -subn1; case: d m => [|[|d]] [|m]//= _ _.
by rewrite ?modn1 ?dvd1n ?modn0 ?subn1.
rewrite modnB// (@modn_small 1)// [_ < _]leqn0 /dvdn mulnbl/= subn1.
by case: eqP => // ->; rewrite addn0.
Qed.
Lemma edivn_pred m d : d != 1 -> 0 < m ->
edivn m.-1 d = if d %| m then ((m %/ d).-1, d.-1) else (m %/ d, (m %% d).-1).
Proof.
move=> d_neq1 m_gt0; rewrite edivn_def divn_pred modn_pred//.
by case: ifP; rewrite ?subn0 ?subn1.
Qed.
(***********************************************************************)
(* A function that computes the gcd of 2 numbers *)
(***********************************************************************)
Fixpoint gcdn m n :=
let n' := n %% m in if n' is 0 then m else
if m - n'.-1 is m'.+1 then gcdn (m' %% n') n' else n'.
Arguments gcdn : simpl never.
Lemma gcdnE m n : gcdn m n = if m == 0 then n else gcdn (n %% m) m.
Proof.
elim/ltn_ind: m n => -[|m] IHm [|n] //=; rewrite /gcdn -/gcdn.
case def_p: (_ %% _) => // [p].
have{def_p} lt_pm: p.+1 < m.+1 by rewrite -def_p ltn_pmod.
rewrite {}IHm // subn_if_gt ltnW //=; congr gcdn.
by rewrite -(subnK (ltnW lt_pm)) modnDr.
Qed.
Lemma gcdnn : idempotent_op gcdn.
Proof. by case=> // n; rewrite gcdnE modnn. Qed.
Lemma gcdnC : commutative gcdn.
Proof.
move=> m n; wlog lt_nm: m n / n < m by have [? ->|? <-|-> //] := ltngtP n m.
by rewrite gcdnE -[in m == 0](ltn_predK lt_nm) modn_small.
Qed.
Lemma gcd0n : left_id 0 gcdn. Proof. by case. Qed.
Lemma gcdn0 : right_id 0 gcdn. Proof. by case. Qed.
Lemma gcd1n : left_zero 1 gcdn.
Proof. by move=> n; rewrite gcdnE modn1. Qed.
Lemma gcdn1 : right_zero 1 gcdn.
Proof. by move=> n; rewrite gcdnC gcd1n. Qed.
Lemma dvdn_gcdr m n : gcdn m n %| n.
Proof.
elim/ltn_ind: m n => -[|m] IHm [|n] //=.
rewrite gcdnE; case def_p: (_ %% _) => [|p]; first by rewrite /dvdn def_p.
have lt_pm: p < m by rewrite -ltnS -def_p ltn_pmod.
rewrite /= (divn_eq n.+1 m.+1) def_p dvdn_addr ?dvdn_mull //; last exact: IHm.
by rewrite gcdnE /= IHm // (ltn_trans (ltn_pmod _ _)).
Qed.
Lemma dvdn_gcdl m n : gcdn m n %| m.
Proof. by rewrite gcdnC dvdn_gcdr. Qed.
Lemma gcdn_gt0 m n : (0 < gcdn m n) = (0 < m) || (0 < n).
Proof.
by case: m n => [|m] [|n] //; apply: (@dvdn_gt0 _ m.+1) => //; apply: dvdn_gcdl.
Qed.
Lemma gcdnMDl k m n : gcdn m (k * m + n) = gcdn m n.
Proof. by rewrite !(gcdnE m) modnMDl mulnC; case: m. Qed.
Lemma gcdnDl m n : gcdn m (m + n) = gcdn m n.
Proof. by rewrite -[m in m + n]mul1n gcdnMDl. Qed.
Lemma gcdnDr m n : gcdn m (n + m) = gcdn m n.
Proof. by rewrite addnC gcdnDl. Qed.
Lemma gcdnMl n m : gcdn n (m * n) = n.
Proof. by case: n => [|n]; rewrite gcdnE modnMl // muln0. Qed.
Lemma gcdnMr n m : gcdn n (n * m) = n.
Proof. by rewrite mulnC gcdnMl. Qed.
Lemma gcdn_idPl {m n} : reflect (gcdn m n = m) (m %| n).
Proof.
by apply: (iffP idP) => [/dvdnP[q ->] | <-]; rewrite (gcdnMl, dvdn_gcdr).
Qed.
Lemma gcdn_idPr {m n} : reflect (gcdn m n = n) (n %| m).
Proof. by rewrite gcdnC; apply: gcdn_idPl. Qed.
Lemma expn_min e m n : e ^ minn m n = gcdn (e ^ m) (e ^ n).
Proof. by case: leqP => [|/ltnW] /(dvdn_exp2l e) /gcdn_idPl; rewrite gcdnC. Qed.
Lemma gcdn_modr m n : gcdn m (n %% m) = gcdn m n.
Proof. by rewrite [in RHS](divn_eq n m) gcdnMDl. Qed.
Lemma gcdn_modl m n : gcdn (m %% n) n = gcdn m n.
Proof. by rewrite !(gcdnC _ n) gcdn_modr. Qed.
(* Extended gcd, which computes Bezout coefficients. *)
Fixpoint Bezout_rec km kn qs :=
if qs is q :: qs' then Bezout_rec kn (NatTrec.add_mul q kn km) qs'
else (km, kn).
Fixpoint egcdn_rec m n s qs :=
if s is s'.+1 then
let: (q, r) := edivn m n in
if r > 0 then egcdn_rec n r s' (q :: qs) else
if odd (size qs) then qs else q.-1 :: qs
else [::0].
Definition egcdn m n := Bezout_rec 0 1 (egcdn_rec m n n [::]).
Variant egcdn_spec m n : nat * nat -> Type :=
EgcdnSpec km kn of km * m = kn * n + gcdn m n & kn * gcdn m n < m :
egcdn_spec m n (km, kn).
Lemma egcd0n n : egcdn 0 n = (1, 0).
Proof. by case: n. Qed.
Lemma egcdnP m n : m > 0 -> egcdn_spec m n (egcdn m n).
Proof.
have [-> /= | n_gt0 m_gt0] := posnP n; first by split; rewrite // mul1n gcdn0.
rewrite /egcdn; set s := (s in egcdn_rec _ _ s); pose bz := Bezout_rec n m [::].
have: n < s.+1 by []; move defSpec: (egcdn_spec bz.2 bz.1) s => Spec s.
elim: s => [[]|s IHs] //= in n m (qs := [::]) bz defSpec n_gt0 m_gt0 *.
case: edivnP => q r def_m; rewrite n_gt0 ltnS /= => lt_rn le_ns1.
case: posnP => [r0 {s le_ns1 IHs lt_rn}|r_gt0]; last first.
by apply: IHs => //=; [rewrite natTrecE -def_m | rewrite (leq_trans lt_rn)].
rewrite {r}r0 addn0 in def_m; set b := odd _; pose d := gcdn m n.
pose km := ~~ b : nat; pose kn := if b then 1 else q.-1.
rewrite [bz in Spec bz](_ : _ = Bezout_rec km kn qs); last first.
by rewrite /kn /km; case: (b) => //=; rewrite natTrecE addn0 muln1.
have def_d: d = n by rewrite /d def_m gcdnC gcdnE modnMl gcd0n -[n]prednK.
have: km * m + 2 * b * d = kn * n + d.
rewrite {}/kn {}/km def_m def_d -mulSnr; case: b; rewrite //= addn0 mul1n.
by rewrite prednK //; apply: dvdn_gt0 m_gt0 _; rewrite def_m dvdn_mulr.
have{def_m}: kn * d <= m.
have q_gt0 : 0 < q by rewrite def_m muln_gt0 n_gt0 ?andbT in m_gt0.
by rewrite /kn; case b; rewrite def_d def_m leq_pmul2r // leq_pred.
have{def_d}: km * d <= n by rewrite -[n]mul1n def_d leq_pmul2r // leq_b1.
move: km {q}kn m_gt0 n_gt0 defSpec; rewrite {}/b {}/d {}/bz.
elim: qs m n => [|q qs IHq] n r kn kr n_gt0 r_gt0 /=.
set d := gcdn n r; rewrite mul0n addn0 => <- le_kn_r _ def_d; split=> //.
have d_gt0: 0 < d by rewrite gcdn_gt0 n_gt0.
have /ltn_pmul2l<-: 0 < kn by rewrite -(ltn_pmul2r n_gt0) def_d ltn_addl.
by rewrite def_d -addn1 leq_add // mulnCA leq_mul2l le_kn_r orbT.
rewrite !natTrecE; set m := _ + r; set km := _ + kn; pose d := gcdn m n.
have ->: gcdn n r = d by rewrite [d]gcdnC gcdnMDl.
have m_gt0: 0 < m by rewrite addn_gt0 r_gt0 orbT.
have d_gt0: 0 < d by rewrite gcdn_gt0 m_gt0.
move=> {}/IHq IHq le_kn_r le_kr_n def_d; apply: IHq => //; rewrite -/d.
by rewrite mulnDl leq_add // -mulnA leq_mul2l le_kr_n orbT.
apply: (@addIn d); rewrite mulnDr -addnA addnACA -def_d addnACA mulnA.
rewrite -!mulnDl -mulnDr -addnA [kr * _]mulnC; congr addn.
by rewrite addnC addn_negb muln1 mul2n addnn.
Qed.
Lemma Bezoutl m n : m > 0 -> {a | a < m & m %| gcdn m n + a * n}.
Proof.
move=> m_gt0; case: (egcdnP n m_gt0) => km kn def_d lt_kn_m.
exists kn; last by rewrite addnC -def_d dvdn_mull.
apply: leq_ltn_trans lt_kn_m.
by rewrite -{1}[kn]muln1 leq_mul2l gcdn_gt0 m_gt0 orbT.
Qed.
Lemma Bezoutr m n : n > 0 -> {a | a < n & n %| gcdn m n + a * m}.
Proof. by rewrite gcdnC; apply: Bezoutl. Qed.
(* Back to the gcd. *)
Lemma dvdn_gcd p m n : p %| gcdn m n = (p %| m) && (p %| n).
Proof.
apply/idP/andP=> [dv_pmn | [dv_pm dv_pn]].
by rewrite !(dvdn_trans dv_pmn) ?dvdn_gcdl ?dvdn_gcdr.
have [->|n_gt0] := posnP n; first by rewrite gcdn0.
case: (Bezoutr m n_gt0) => // km _ /(dvdn_trans dv_pn).
by rewrite dvdn_addl // dvdn_mull.
Qed.
Lemma gcdnAC : right_commutative gcdn.
Proof.
suffices dvd m n p: gcdn (gcdn m n) p %| gcdn (gcdn m p) n.
by move=> m n p; apply/eqP; rewrite eqn_dvd !dvd.
rewrite !dvdn_gcd dvdn_gcdr.
by rewrite !(dvdn_trans (dvdn_gcdl _ p)) ?dvdn_gcdl ?dvdn_gcdr.
Qed.
Lemma gcdnA : associative gcdn.
Proof. by move=> m n p; rewrite !(gcdnC m) gcdnAC. Qed.
Lemma gcdnCA : left_commutative gcdn.
Proof. by move=> m n p; rewrite !gcdnA (gcdnC m). Qed.
Lemma gcdnACA : interchange gcdn gcdn.
Proof. by move=> m n p q; rewrite -!gcdnA (gcdnCA n). Qed.
Lemma muln_gcdr : right_distributive muln gcdn.
Proof.
move=> p m n; have [-> //|p_gt0] := posnP p.
elim/ltn_ind: m n => m IHm n; rewrite gcdnE [RHS]gcdnE muln_eq0 (gtn_eqF p_gt0).
by case: posnP => // m_gt0; rewrite -muln_modr //=; apply/IHm/ltn_pmod.
Qed.
Lemma muln_gcdl : left_distributive muln gcdn.
Proof. by move=> m n p; rewrite -!(mulnC p) muln_gcdr. Qed.
Lemma gcdn_def d m n :
d %| m -> d %| n -> (forall d', d' %| m -> d' %| n -> d' %| d) ->
gcdn m n = d.
Proof.
move=> dv_dm dv_dn gdv_d; apply/eqP.
by rewrite eqn_dvd dvdn_gcd dv_dm dv_dn gdv_d ?dvdn_gcdl ?dvdn_gcdr.
Qed.
Lemma muln_divCA_gcd n m : n * (m %/ gcdn n m) = m * (n %/ gcdn n m).
Proof. by rewrite muln_divCA ?dvdn_gcdl ?dvdn_gcdr. Qed.
(* We derive the lcm directly. *)
Definition lcmn m n := m * n %/ gcdn m n.
Lemma lcmnC : commutative lcmn.
Proof. by move=> m n; rewrite /lcmn mulnC gcdnC. Qed.
Lemma lcm0n : left_zero 0 lcmn. Proof. by move=> n; apply: div0n. Qed.
Lemma lcmn0 : right_zero 0 lcmn. Proof. by move=> n; rewrite lcmnC lcm0n. Qed.
Lemma lcm1n : left_id 1 lcmn.
Proof. by move=> n; rewrite /lcmn gcd1n mul1n divn1. Qed.
Lemma lcmn1 : right_id 1 lcmn.
Proof. by move=> n; rewrite lcmnC lcm1n. Qed.
Lemma muln_lcm_gcd m n : lcmn m n * gcdn m n = m * n.
Proof. by apply/eqP; rewrite divnK ?dvdn_mull ?dvdn_gcdr. Qed.
Lemma lcmn_gt0 m n : (0 < lcmn m n) = (0 < m) && (0 < n).
Proof. by rewrite -muln_gt0 ltn_divRL ?dvdn_mull ?dvdn_gcdr. Qed.
Lemma muln_lcmr : right_distributive muln lcmn.
Proof.
case=> // m n p; rewrite /lcmn -muln_gcdr -!mulnA divnMl // mulnCA.
by rewrite muln_divA ?dvdn_mull ?dvdn_gcdr.
Qed.
Lemma muln_lcml : left_distributive muln lcmn.
Proof. by move=> m n p; rewrite -!(mulnC p) muln_lcmr. Qed.
Lemma lcmnA : associative lcmn.
Proof.
move=> m n p; rewrite [LHS]/lcmn [RHS]/lcmn mulnC.
rewrite !divn_mulAC ?dvdn_mull ?dvdn_gcdr // -!divnMA ?dvdn_mulr ?dvdn_gcdl //.
rewrite mulnC mulnA !muln_gcdr; congr (_ %/ _).
by rewrite ![_ * lcmn _ _]mulnC !muln_lcm_gcd !muln_gcdl -!(mulnC m) gcdnA.
Qed.
Lemma lcmnCA : left_commutative lcmn.
Proof. by move=> m n p; rewrite !lcmnA (lcmnC m). Qed.
Lemma lcmnAC : right_commutative lcmn.
Proof. by move=> m n p; rewrite -!lcmnA (lcmnC n). Qed.
Lemma lcmnACA : interchange lcmn lcmn.
Proof. by move=> m n p q; rewrite -!lcmnA (lcmnCA n). Qed.
Lemma dvdn_lcml d1 d2 : d1 %| lcmn d1 d2.
Proof. by rewrite /lcmn -muln_divA ?dvdn_gcdr ?dvdn_mulr. Qed.
Lemma dvdn_lcmr d1 d2 : d2 %| lcmn d1 d2.
Proof. by rewrite lcmnC dvdn_lcml. Qed.
Lemma dvdn_lcm d1 d2 m : lcmn d1 d2 %| m = (d1 %| m) && (d2 %| m).
Proof.
case: d1 d2 => [|d1] [|d2]; try by case: m => [|m]; rewrite ?lcmn0 ?andbF.
rewrite -(@dvdn_pmul2r (gcdn d1.+1 d2.+1)) ?gcdn_gt0 // muln_lcm_gcd.
by rewrite muln_gcdr dvdn_gcd {1}mulnC andbC !dvdn_pmul2r.
Qed.
Lemma lcmnMl m n : lcmn m (m * n) = m * n.
Proof. by case: m => // m; rewrite /lcmn gcdnMr mulKn. Qed.
Lemma lcmnMr m n : lcmn n (m * n) = m * n.
Proof. by rewrite mulnC lcmnMl. Qed.
Lemma lcmn_idPr {m n} : reflect (lcmn m n = n) (m %| n).
Proof.
by apply: (iffP idP) => [/dvdnP[q ->] | <-]; rewrite (lcmnMr, dvdn_lcml).
Qed.
Lemma lcmn_idPl {m n} : reflect (lcmn m n = m) (n %| m).
Proof. by rewrite lcmnC; apply: lcmn_idPr. Qed.
Lemma expn_max e m n : e ^ maxn m n = lcmn (e ^ m) (e ^ n).
Proof. by case: leqP => [|/ltnW] /(dvdn_exp2l e) /lcmn_idPl; rewrite lcmnC. Qed.
(* Coprime factors *)
Definition coprime m n := gcdn m n == 1.
Lemma coprime1n n : coprime 1 n.
Proof. by rewrite /coprime gcd1n. Qed.
Lemma coprimen1 n : coprime n 1.
Proof. by rewrite /coprime gcdn1. Qed.
Lemma coprime_sym m n : coprime m n = coprime n m.
Proof. by rewrite /coprime gcdnC. Qed.
Lemma coprime_modl m n : coprime (m %% n) n = coprime m n.
Proof. by rewrite /coprime gcdn_modl. Qed.
Lemma coprime_modr m n : coprime m (n %% m) = coprime m n.
Proof. by rewrite /coprime gcdn_modr. Qed.
Lemma coprime2n n : coprime 2 n = odd n.
Proof. by rewrite -coprime_modr modn2; case: (odd n). Qed.
Lemma coprimen2 n : coprime n 2 = odd n.
Proof. by rewrite coprime_sym coprime2n. Qed.
Lemma coprimeSn n : coprime n.+1 n.
Proof. by rewrite -coprime_modl (modnDr 1) coprime_modl coprime1n. Qed.
Lemma coprimenS n : coprime n n.+1.
Proof. by rewrite coprime_sym coprimeSn. Qed.
Lemma coprimePn n : n > 0 -> coprime n.-1 n.
Proof. by case: n => // n _; rewrite coprimenS. Qed.
Lemma coprimenP n : n > 0 -> coprime n n.-1.
Proof. by case: n => // n _; rewrite coprimeSn. Qed.
Lemma coprimeP n m :
n > 0 -> reflect (exists u, u.1 * n - u.2 * m = 1) (coprime n m).
Proof.
move=> n_gt0; apply: (iffP eqP) => [<-| [[kn km] /= kn_km_1]].
by have [kn km kg _] := egcdnP m n_gt0; exists (kn, km); rewrite kg addKn.
apply gcdn_def; rewrite ?dvd1n // => d dv_d_n dv_d_m.
by rewrite -kn_km_1 dvdn_subr ?dvdn_mull // ltnW // -subn_gt0 kn_km_1.
Qed.
Lemma modn_coprime k n : 0 < k -> (exists u, (k * u) %% n = 1) -> coprime k n.
Proof.
move=> k_gt0 [u Hu]; apply/coprimeP=> //.
by exists (u, k * u %/ n); rewrite /= mulnC {1}(divn_eq (k * u) n) addKn.
Qed.
Lemma Gauss_dvd m n p : coprime m n -> (m * n %| p) = (m %| p) && (n %| p).
Proof. by move=> co_mn; rewrite -muln_lcm_gcd (eqnP co_mn) muln1 dvdn_lcm. Qed.
Lemma Gauss_dvdr m n p : coprime m n -> (m %| n * p) = (m %| p).
Proof.
case: n => [|n] co_mn; first by case: m co_mn => [|[]] // _; rewrite !dvd1n.
by symmetry; rewrite mulnC -(@dvdn_pmul2r n.+1) ?Gauss_dvd // andbC dvdn_mull.
Qed.
Lemma Gauss_dvdl m n p : coprime m p -> (m %| n * p) = (m %| n).
Proof. by rewrite mulnC; apply: Gauss_dvdr. Qed.
Lemma dvdn_double_leq m n : m %| n -> odd m -> ~~ odd n -> 0 < n -> m.*2 <= n.
Proof.
move=> m_dv_n odd_m even_n n_gt0.
by rewrite -muln2 dvdn_leq // Gauss_dvd ?coprimen2 ?m_dv_n ?dvdn2.
Qed.
Lemma dvdn_double_ltn m n : m %| n.-1 -> odd m -> odd n -> 1 < n -> m.*2 < n.
Proof. by case: n => //; apply: dvdn_double_leq. Qed.
Lemma Gauss_gcdr p m n : coprime p m -> gcdn p (m * n) = gcdn p n.
Proof.
move=> co_pm; apply/eqP; rewrite eqn_dvd !dvdn_gcd !dvdn_gcdl /=.
rewrite andbC dvdn_mull ?dvdn_gcdr //= -(@Gauss_dvdr _ m) ?dvdn_gcdr //.
by rewrite /coprime gcdnAC (eqnP co_pm) gcd1n.
Qed.
Lemma Gauss_gcdl p m n : coprime p n -> gcdn p (m * n) = gcdn p m.
Proof. by move=> co_pn; rewrite mulnC Gauss_gcdr. Qed.
Lemma coprimeMr p m n : coprime p (m * n) = coprime p m && coprime p n.
Proof.
case co_pm: (coprime p m) => /=; first by rewrite /coprime Gauss_gcdr.
apply/eqP=> co_p_mn; case/eqnP: co_pm; apply gcdn_def => // d dv_dp dv_dm.
by rewrite -co_p_mn dvdn_gcd dv_dp dvdn_mulr.
Qed.
Lemma coprimeMl p m n : coprime (m * n) p = coprime m p && coprime n p.
Proof. by rewrite -!(coprime_sym p) coprimeMr. Qed.
Lemma coprime_pexpl k m n : 0 < k -> coprime (m ^ k) n = coprime m n.
Proof.
case: k => // k _; elim: k => [|k IHk]; first by rewrite expn1.
by rewrite expnS coprimeMl -IHk; case coprime.
Qed.
Lemma coprime_pexpr k m n : 0 < k -> coprime m (n ^ k) = coprime m n.
Proof. by move=> k_gt0; rewrite !(coprime_sym m) coprime_pexpl. Qed.
Lemma coprimeXl k m n : coprime m n -> coprime (m ^ k) n.
Proof. by case: k => [|k] co_pm; rewrite ?coprime1n // coprime_pexpl. Qed.
Lemma coprimeXr k m n : coprime m n -> coprime m (n ^ k).
Proof. by rewrite !(coprime_sym m); apply: coprimeXl. Qed.
Lemma coprime_dvdl m n p : m %| n -> coprime n p -> coprime m p.
Proof. by case/dvdnP=> d ->; rewrite coprimeMl => /andP[]. Qed.
Lemma coprime_dvdr m n p : m %| n -> coprime p n -> coprime p m.
Proof. by rewrite !(coprime_sym p); apply: coprime_dvdl. Qed.
Lemma coprime_egcdn n m : n > 0 -> coprime (egcdn n m).1 (egcdn n m).2.
Proof.
move=> n_gt0; case: (egcdnP m n_gt0) => kn km /= /eqP.
have [/dvdnP[u defn] /dvdnP[v defm]] := (dvdn_gcdl n m, dvdn_gcdr n m).
rewrite -[gcdn n m]mul1n {1}defm {1}defn !mulnA -mulnDl addnC.
rewrite eqn_pmul2r ?gcdn_gt0 ?n_gt0 //; case: kn => // kn /eqP def_knu _.
by apply/coprimeP=> //; exists (u, v); rewrite mulnC def_knu mulnC addnK.
Qed.
Lemma dvdn_pexp2r m n k : k > 0 -> (m ^ k %| n ^ k) = (m %| n).
Proof.
move=> k_gt0; apply/idP/idP=> [dv_mn_k|]; last exact: dvdn_exp2r.
have [->|n_gt0] := posnP n; first by rewrite dvdn0.
have [n' def_n] := dvdnP (dvdn_gcdr m n); set d := gcdn m n in def_n.
have [m' def_m] := dvdnP (dvdn_gcdl m n); rewrite -/d in def_m.
have d_gt0: d > 0 by rewrite gcdn_gt0 n_gt0 orbT.
rewrite def_m def_n !expnMn dvdn_pmul2r ?expn_gt0 ?d_gt0 // in dv_mn_k.
have: coprime (m' ^ k) (n' ^ k).
rewrite coprime_pexpl // coprime_pexpr // /coprime -(eqn_pmul2r d_gt0) mul1n.
by rewrite muln_gcdl -def_m -def_n.
rewrite /coprime -gcdn_modr (eqnP dv_mn_k) gcdn0 -(exp1n k).
by rewrite (inj_eq (expIn k_gt0)) def_m; move/eqP->; rewrite mul1n dvdn_gcdr.
Qed.
Section Chinese.
(***********************************************************************)
(* The chinese remainder theorem *)
(***********************************************************************)
Variables m1 m2 : nat.
Hypothesis co_m12 : coprime m1 m2.
Lemma chinese_remainder x y :
(x == y %[mod m1 * m2]) = (x == y %[mod m1]) && (x == y %[mod m2]).
Proof.
wlog le_yx : x y / y <= x; last by rewrite !eqn_mod_dvd // Gauss_dvd.
by have [?|/ltnW ?] := leqP y x; last rewrite !(eq_sym (x %% _)); apply.
Qed.
(***********************************************************************)
(* A function that solves the chinese remainder problem *)
(***********************************************************************)
Definition chinese r1 r2 :=
r1 * m2 * (egcdn m2 m1).1 + r2 * m1 * (egcdn m1 m2).1.
Lemma chinese_modl r1 r2 : chinese r1 r2 = r1 %[mod m1].
Proof.
rewrite /chinese; case: (posnP m2) co_m12 => [-> /eqnP | m2_gt0 _].
by rewrite gcdn0 => ->; rewrite !modn1.
case: egcdnP => // k2 k1 def_m1 _.
rewrite mulnAC -mulnA def_m1 gcdnC (eqnP co_m12) mulnDr mulnA muln1.
by rewrite addnAC (mulnAC _ m1) -mulnDl modnMDl.
Qed.
Lemma chinese_modr r1 r2 : chinese r1 r2 = r2 %[mod m2].
Proof.
rewrite /chinese; case: (posnP m1) co_m12 => [-> /eqnP | m1_gt0 _].
by rewrite gcd0n => ->; rewrite !modn1.
case: (egcdnP m2) => // k1 k2 def_m2 _.
rewrite addnC mulnAC -mulnA def_m2 (eqnP co_m12) mulnDr mulnA muln1.
by rewrite addnAC (mulnAC _ m2) -mulnDl modnMDl.
Qed.
Lemma chinese_mod x : x = chinese (x %% m1) (x %% m2) %[mod m1 * m2].
Proof.
apply/eqP; rewrite chinese_remainder //.
by rewrite chinese_modl chinese_modr !modn_mod !eqxx.
Qed.
End Chinese.
|
eqtype.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool.
(******************************************************************************)
(* Types with a decidable equality *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines two "base" combinatorial structures: *)
(* eqType == types with a decidable equality *)
(* The HB class is called Equality. *)
(* The equality operation on an eqType is proof-irrelevant *)
(* (lemma eq_irrelevance). *)
(* The main notation is the boolean equality "==", see below. *)
(* subType P == types isomorphic to {x : T | P x} *)
(* with P : pred T for some type T *)
(* The HB class is called SubType. *)
(* subEqType P == join of eqType and subType P *)
(* The HB class is called SubEquality. *)
(* *)
(* The eqType interface supports the following operations (in bool_scope): *)
(* x == y <=> x compares equal to y (this is a boolean test) *)
(* x == y :> T <=> x == y at type T *)
(* x != y <=> x and y compare unequal *)
(* x != y :> T <=> x and y compare unequal at type T *)
(* x =P y :: a proof of reflect (x = y) (x == y); x =P y coerces *)
(* to x == y -> x = y *)
(* eqbLHS := (X in (X == _))%pattern (for rewriting) *)
(* eqbRHS := (X in (_ == X))%pattern (for rewriting) *)
(* eq_op == the boolean relation behind the == notation *)
(* (see lemma eqE below for generic folding *)
(* of equality predicates) *)
(* eqP == proof of Equality.axiom eq_op behind the =P notation*)
(* Equality.axiom e <-> e : rel T is a valid comparison decision procedure *)
(* for type T: reflect (x = y) (e x y) for all x y : T *)
(* pred1 a == the singleton predicate [pred x | x == a] *)
(* pred2, pred3, pred4 == pair, triple, quad predicates *)
(* predC1 a == [pred x | x != a] *)
(* [predU1 a & A] == [pred x | (x == a) || (x \in A)] *)
(* [predD1 A & a] == [pred x | x != a & x \in A] *)
(* predU1 a P, predD1 P a == applicative versions of the above *)
(* frel f == the relation associated with f : T -> T *)
(* := [rel x y | f x == y] *)
(* invariant f k == elements of T whose k-class is f-invariant *)
(* := [pred x | k (f x) == k x] with f : T -> T *)
(* [fun x : T => e0 with a1 |-> e1, .., a_n |-> e_n] *)
(* [eta f with a1 |-> e1, .., a_n |-> e_n] == *)
(* the auto-expanding function that maps x = a_i to e_i, and other values *)
(* of x to e0 (resp. f x). In the first form the `: T' is optional and x *)
(* can occur in a_i or e_i *)
(* dfwith f x == fun j => x if j = i, and f j otherwise, given *)
(* f : forall k, T k and x : T i *)
(* We also define: *)
(* tagged_as u v == v cast as T_(tag u) if tag v == tag u, else u *)
(* so that u == v <=> (tag u == tag v) && (tagged u == tagged_as u v *)
(* etagged i u (p : tag u = i) == (tagged u) cast as T_ i *)
(* untag idx i (F : T_ i -> _) u == F (etagged i u _) if tag u = i, else idx *)
(* tagged_with i == [pred j | tag j == i], this pred {x : I & T_ x} is useful *)
(* to define the sigma type {x in tagged_with i} and the mutual bijections: *)
(* tag_with i : T_ i -> {x in tagged_with i} *)
(* untag_with i : {x in tagged_with i} -> T_ i *)
(* *)
(* The subType interface supports the following operations: *)
(* \val == the generic injection from a subType S of T into T *)
(* For example, if u : {x : T | P}, then val u : T *)
(* val is injective because P is proof-irrelevant (P is in bool, *)
(* and the is_true coercion expands to P = true). *)
(* valP == the generic proof of P (val u) for u : subType P *)
(* Sub x Px == The generic constructor for a subType P; Px is a proof of P x *)
(* and P should be inferred from the expected return type. *)
(* insub x == the generic partial projection of T into a subType S of T *)
(* This returns an option S; if S : subType P then *)
(* insub x = Some u with val u = x if P x, *)
(* None if ~~ P x *)
(* The insubP lemma encapsulates this dichotomy. *)
(* P should be inferred from the expected return type. *)
(* innew x == total (non-option) variant of insub when P = predT *)
(* {? x | P} == option {x | P} (syntax for casting insub x) *)
(* insubd u0 x == the generic projection with default value u0 *)
(* := odflt u0 (insub x) *)
(* insigd A0 x == special case of insubd for S == {x | x \in A}, where A0 is *)
(* a proof of x0 \in A *)
(* insub_eq x == transparent version of insub x that expands to Some/None *)
(* when P x can evaluate *)
(* *)
(* * Sub *)
(* ** Specific notations *)
(* [isSub of S for S_val] == subtype for S where S_val : S -> T is the *)
(* first projection of a type S isomorphic to {x : T | P}; if S_val is *)
(* specified, then it replaces the inferred projector. *)
(* [isSub for S_val] := [isSub of _ for S_val] *)
(* It clones the canonical subType structure for S. *)
(* [isNew of S for S_val] == subtype for S where S_val : S -> T is the *)
(* projection of a type S isomorphic to T; in this case P must be predT *)
(* [isNew for S_val] := [isNew of _ for S_val] *)
(* [isSub for S_val by Srect], [isNew for S_val by Srect] == *)
(* variants of the above where the eliminator is explicitly provided. *)
(* Here S no longer needs to be syntactically identical to {x | P x} or *)
(* wrapped T, but it must have a derived constructor S_Sub satisfying an *)
(* eliminator Srect identical to the one the Coq Inductive command would *)
(* have generated, and S_val (S_Sub x Px) (resp. S_val (S_sub x) for the *)
(* newType form) must be convertible to x. *)
(* variant of the above when S is a wrapper type for T (so P = predT). *)
(* Subtypes inherit the eqType structure of their base types; the generic *)
(* structure should be explicitly instantiated using the *)
(* [Equality of S by <:] *)
(* construct; this pattern is repeated for all the combinatorial interfaces *)
(* (Choice, Countable, Finite). *)
(* *)
(* List of factories with a dedicated alias (not generated automatically): *)
(* inj_type injf == alias of T to copy an interface from another T' already *)
(* equipped with it and injf : injective f with f : T -> T'*)
(* pcan_type fK == alias of T to similarly derive an interface from f and *)
(* a left inverse partial function g and fK : pcancel f g *)
(* can_type fK == alias of T to similarly derive an interface from f and *)
(* a left inverse function g and fK : cancel f g *)
(* sub_type sT == alias of sT : subType _ *)
(* *)
(* comparable T <-> equality on T is decidable. *)
(* := forall x y : T, decidable (x = y) *)
(* comparableMixin compT == equality mixin for compT : comparable T *)
(* *)
(* The eqType interface is implemented for most standard datatypes: *)
(* bool, unit, void, option, prod (denoted A * B), sum (denoted A + B), *)
(* sig (denoted {x | P}), sigT (denoted {i : I & T}). *)
(* *)
(* We add the following to the standard suffixes documented in ssrbool.v: *)
(* 1, 2, 3, 4 -- explicit enumeration predicate for 1 (singleton), 2, 3, or *)
(* 4 values *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope eq_scope.
Declare Scope fun_delta_scope.
Definition eq_axiom T (e : rel T) := forall x y, reflect (x = y) (e x y).
HB.mixin Record hasDecEq T := { eq_op : rel T; eqP : eq_axiom eq_op }.
#[mathcomp(axiom="eq_axiom"), short(type="eqType")]
HB.structure Definition Equality := { T of hasDecEq T }.
(* eqE is a generic lemma that can be used to fold back recursive comparisons *)
(* after using partial evaluation to simplify comparisons on concrete *)
(* instances. The eqE lemma can be used e.g. like so: rewrite !eqE /= -!eqE. *)
(* For instance, with the above rewrite, n.+1 == n.+1 gets simplified to *)
(* n == n. For this to work, we need to declare equality _mixins_ *)
(* as canonical. Canonical declarations remove the need for specific *)
(* inverses to eqE (like eqbE, eqnE, eqseqE, etc.) for new recursive *)
(* comparisons, but can only be used for manifest mixing with a bespoke *)
(* comparison function, and so is incompatible with PcanEqMixin and the like *)
(* - this is why the tree_hasDecEq for GenTree.tree in library choice is not *)
(* declared Canonical. *)
Lemma eqE (T : eqType) x : eq_op x = hasDecEq.eq_op (Equality.class T) x.
Proof. by []. Qed.
Arguments eqP {T x y} : rename.
Delimit Scope eq_scope with EQ.
Open Scope eq_scope.
Notation "x == y" := (eq_op x y) (no associativity) : bool_scope.
Notation "x == y :> T" := ((x : T) == (y : T)) : bool_scope.
Notation "x != y" := (~~ (x == y)) (no associativity) : bool_scope.
Notation "x != y :> T" := (~~ (x == y :> T)) : bool_scope.
Notation "x =P y" := (eqP : reflect (x = y) (x == y))
(at level 70, no associativity) : eq_scope.
Notation "x =P y :> T" := (eqP : reflect (x = y :> T) (x == y :> T))
(no associativity) : eq_scope.
Notation eqbLHS := (X in (X == _))%pattern.
Notation eqbRHS := (X in (_ == X))%pattern.
Lemma eq_refl (T : eqType) (x : T) : x == x. Proof. exact/eqP. Qed.
Notation eqxx := eq_refl.
Lemma eq_sym (T : eqType) (x y : T) : (x == y) = (y == x).
Proof. exact/eqP/eqP. Qed.
#[global] Hint Resolve eq_refl eq_sym : core.
Variant eq_xor_neq (T : eqType) (x y : T) : bool -> bool -> Set :=
| EqNotNeq of x = y : eq_xor_neq x y true true
| NeqNotEq of x != y : eq_xor_neq x y false false.
Lemma eqVneq (T : eqType) (x y : T) : eq_xor_neq x y (y == x) (x == y).
Proof. by rewrite eq_sym; case: (altP eqP); constructor. Qed.
Arguments eqVneq {T} x y, {T x y}.
Section Contrapositives.
Variables (T1 T2 : eqType).
Implicit Types (A : pred T1) (b : bool) (P : Prop) (x : T1) (z : T2).
Lemma contraTeq b x y : (x != y -> ~~ b) -> b -> x = y.
Proof. by move=> imp hyp; apply/eqP; apply: contraTT hyp. Qed.
Lemma contraNeq b x y : (x != y -> b) -> ~~ b -> x = y.
Proof. by move=> imp hyp; apply/eqP; apply: contraNT hyp. Qed.
Lemma contraFeq b x y : (x != y -> b) -> b = false -> x = y.
Proof. by move=> imp /negbT; apply: contraNeq. Qed.
Lemma contraPeq P x y : (x != y -> ~ P) -> P -> x = y.
Proof. by move=> imp HP; apply: contraTeq isT => /imp /(_ HP). Qed.
Lemma contra_not_eq P x y : (x != y -> P) -> ~ P -> x = y.
Proof. by move=> imp; apply: contraPeq => /imp HP /(_ HP). Qed.
Lemma contra_not_neq P x y : (x = y -> P) -> ~ P -> x != y.
Proof. by move=> imp; apply: contra_notN => /eqP. Qed.
Lemma contraTneq b x y : (x = y -> ~~ b) -> b -> x != y.
Proof. by move=> imp; apply: contraTN => /eqP. Qed.
Lemma contraNneq b x y : (x = y -> b) -> ~~ b -> x != y.
Proof. by move=> imp; apply: contraNN => /eqP. Qed.
Lemma contraFneq b x y : (x = y -> b) -> b = false -> x != y.
Proof. by move=> imp /negbT; apply: contraNneq. Qed.
Lemma contraPneq P x y : (x = y -> ~ P) -> P -> x != y.
Proof. by move=> imp; apply: contraPN => /eqP. Qed.
Lemma contra_eqN b x y : (b -> x != y) -> x = y -> ~~ b.
Proof. by move=> imp /eqP; apply: contraL. Qed.
Lemma contra_eqF b x y : (b -> x != y) -> x = y -> b = false.
Proof. by move=> imp /eqP; apply: contraTF. Qed.
Lemma contra_eqT b x y : (~~ b -> x != y) -> x = y -> b.
Proof. by move=> imp /eqP; apply: contraLR. Qed.
Lemma contra_neqN b x y : (b -> x = y) -> x != y -> ~~ b.
Proof. by move=> imp; apply: contraNN => /imp->. Qed.
Lemma contra_neqF b x y : (b -> x = y) -> x != y -> b = false.
Proof. by move=> imp; apply: contraNF => /imp->. Qed.
Lemma contra_neqT b x y : (~~ b -> x = y) -> x != y -> b.
Proof. by move=> imp; apply: contraNT => /imp->. Qed.
Lemma contra_eq_not P x y : (P -> x != y) -> x = y -> ~ P.
Proof. by move=> imp /eqP; apply: contraTnot. Qed.
Lemma contra_neq_not P x y : (P -> x = y) -> x != y -> ~ P.
Proof. by move=> imp;apply: contraNnot => /imp->. Qed.
Lemma contra_eq z1 z2 x1 x2 : (x1 != x2 -> z1 != z2) -> z1 = z2 -> x1 = x2.
Proof. by move=> imp /eqP; apply: contraTeq. Qed.
Lemma contra_neq z1 z2 x1 x2 : (x1 = x2 -> z1 = z2) -> z1 != z2 -> x1 != x2.
Proof. by move=> imp; apply: contraNneq => /imp->. Qed.
Lemma contra_neq_eq z1 z2 x1 x2 : (x1 != x2 -> z1 = z2) -> z1 != z2 -> x1 = x2.
Proof. by move=> imp; apply: contraNeq => /imp->. Qed.
Lemma contra_eq_neq z1 z2 x1 x2 : (z1 = z2 -> x1 != x2) -> x1 = x2 -> z1 != z2.
Proof. by move=> imp; apply: contra_eqN => /eqP /imp. Qed.
Lemma memPn A x : reflect {in A, forall y, y != x} (x \notin A).
Proof.
apply: (iffP idP) => [notDx y | notDx]; first by apply: contraTneq => ->.
exact: contraL (notDx x) _.
Qed.
Lemma memPnC A x : reflect {in A, forall y, x != y} (x \notin A).
Proof. by apply: (iffP (memPn A x)) => A'x y /A'x; rewrite eq_sym. Qed.
Lemma ifN_eq R x y vT vF : x != y -> (if x == y then vT else vF) = vF :> R.
Proof. exact: ifN. Qed.
Lemma ifN_eqC R x y vT vF : x != y -> (if y == x then vT else vF) = vF :> R.
Proof. by rewrite eq_sym; apply: ifN. Qed.
End Contrapositives.
Arguments memPn {T1 A x}.
Arguments memPnC {T1 A x}.
Theorem eq_irrelevance (T : eqType) x y : forall e1 e2 : x = y :> T, e1 = e2.
Proof.
pose proj z e := if x =P z is ReflectT e0 then e0 else e.
suff: injective (proj y) by rewrite /proj => injp e e'; apply: injp; case: eqP.
pose join (e : x = _) := etrans (esym e).
apply: can_inj (join x y (proj x (erefl x))) _.
by case: y /; case: _ / (proj x _).
Qed.
Corollary eq_axiomK (T : eqType) (x : T) : all_equal_to (erefl x).
Proof. by move=> eq_x_x; apply: eq_irrelevance. Qed.
(* We use the module system to circumvent a silly limitation that *)
(* forbids using the same constant to coerce to different targets. *)
Module Type EqTypePredSig.
Parameter sort : eqType -> predArgType.
End EqTypePredSig.
Module MakeEqTypePred (eqmod : EqTypePredSig).
Coercion eqmod.sort : eqType >-> predArgType.
End MakeEqTypePred.
Module Export EqTypePred := MakeEqTypePred eqtype.Equality.
Lemma unit_eqP : Equality.axiom (fun _ _ : unit => true).
Proof. by do 2!case; left. Qed.
HB.instance Definition _ := hasDecEq.Build unit unit_eqP.
(* Comparison for booleans. *)
(* This is extensionally equal, but not convertible to Bool.eqb. *)
Definition eqb b := addb (~~ b).
Lemma eqbP : Equality.axiom eqb.
Proof. by do 2!case; constructor. Qed.
HB.instance Definition _ := hasDecEq.Build bool eqbP.
Lemma eqbE : eqb = eq_op. Proof. by []. Qed.
Lemma bool_irrelevance (b : bool) (p1 p2 : b) : p1 = p2.
Proof. exact: eq_irrelevance. Qed.
Lemma negb_add b1 b2 : ~~ (b1 (+) b2) = (b1 == b2).
Proof. by rewrite -addNb. Qed.
Lemma negb_eqb b1 b2 : (b1 != b2) = b1 (+) b2.
Proof. by rewrite -addNb negbK. Qed.
Lemma eqb_id b : (b == true) = b.
Proof. by case: b. Qed.
Lemma eqbF_neg b : (b == false) = ~~ b.
Proof. by case: b. Qed.
Lemma eqb_negLR b1 b2 : (~~ b1 == b2) = (b1 == ~~ b2).
Proof. by case: b1; case: b2. Qed.
(* Equality-based predicates. *)
Notation xpred1 := (fun a1 x => x == a1).
Notation xpred2 := (fun a1 a2 x => (x == a1) || (x == a2)).
Notation xpred3 := (fun a1 a2 a3 x => [|| x == a1, x == a2 | x == a3]).
Notation xpred4 :=
(fun a1 a2 a3 a4 x => [|| x == a1, x == a2, x == a3 | x == a4]).
Notation xpredU1 := (fun a1 (p : pred _) x => (x == a1) || p x).
Notation xpredC1 := (fun a1 x => x != a1).
Notation xpredD1 := (fun (p : pred _) a1 x => (x != a1) && p x).
Section EqPred.
Variable T : eqType.
Definition pred1 (a1 : T) := SimplPred (xpred1 a1).
Definition pred2 (a1 a2 : T) := SimplPred (xpred2 a1 a2).
Definition pred3 (a1 a2 a3 : T) := SimplPred (xpred3 a1 a2 a3).
Definition pred4 (a1 a2 a3 a4 : T) := SimplPred (xpred4 a1 a2 a3 a4).
Definition predU1 (a1 : T) p := SimplPred (xpredU1 a1 p).
Definition predC1 (a1 : T) := SimplPred (xpredC1 a1).
Definition predD1 p (a1 : T) := SimplPred (xpredD1 p a1).
Lemma pred1E : pred1 =2 eq_op. Proof. by move=> x y; apply: eq_sym. Qed.
Variables (T2 : eqType) (x y : T) (z u : T2) (b : bool).
Lemma predU1P : reflect (x = y \/ b) ((x == y) || b).
Proof. by apply: (iffP orP); do [case=> [/eqP|]; [left | right]]. Qed.
Lemma pred2P : reflect (x = y \/ z = u) ((x == y) || (z == u)).
Proof. by apply: (iffP orP); do [case=> /eqP; [left | right]]. Qed.
Lemma predD1P : reflect (x <> y /\ b) ((x != y) && b).
Proof. by apply: (iffP andP)=> [] [] // /eqP. Qed.
Lemma predU1l : x = y -> (x == y) || b.
Proof. by move->; rewrite eqxx. Qed.
Lemma predU1r : b -> (x == y) || b.
Proof. by move->; rewrite orbT. Qed.
End EqPred.
Arguments predU1P {T x y b}.
Arguments pred2P {T T2 x y z u}.
Arguments predD1P {T x y b}.
Prenex Implicits pred1 pred2 pred3 pred4 predU1 predC1 predD1.
Notation "[ 'predU1' x & A ]" := (predU1 x [in A])
(format "[ 'predU1' x & A ]") : function_scope.
Notation "[ 'predD1' A & x ]" := (predD1 [in A] x)
(format "[ 'predD1' A & x ]") : function_scope.
(* Lemmas for reflected equality and functions. *)
Section EqFun.
Section Exo.
Variables (aT rT : eqType) (D : pred aT) (f : aT -> rT) (g : rT -> aT).
Lemma inj_eq : injective f -> forall x y, (f x == f y) = (x == y).
Proof. by move=> inj_f x y; apply/eqP/eqP=> [|-> //]; apply: inj_f. Qed.
Lemma can_eq : cancel f g -> forall x y, (f x == f y) = (x == y).
Proof. by move/can_inj; apply: inj_eq. Qed.
Lemma bij_eq : bijective f -> forall x y, (f x == f y) = (x == y).
Proof. by move/bij_inj; apply: inj_eq. Qed.
Lemma can2_eq : cancel f g -> cancel g f -> forall x y, (f x == y) = (x == g y).
Proof. by move=> fK gK x y; rewrite -[y in LHS]gK; apply: can_eq. Qed.
Lemma inj_in_eq :
{in D &, injective f} -> {in D &, forall x y, (f x == f y) = (x == y)}.
Proof. by move=> inj_f x y Dx Dy; apply/eqP/eqP=> [|-> //]; apply: inj_f. Qed.
Lemma can_in_eq :
{in D, cancel f g} -> {in D &, forall x y, (f x == f y) = (x == y)}.
Proof. by move/can_in_inj; apply: inj_in_eq. Qed.
End Exo.
Section Endo.
Variable T : eqType.
Definition frel f := [rel x y : T | f x == y].
Lemma inv_eq f : involutive f -> forall x y : T, (f x == y) = (x == f y).
Proof. by move=> fK; apply: can2_eq. Qed.
Lemma eq_frel f f' : f =1 f' -> frel f =2 frel f'.
Proof. by move=> eq_f x y; rewrite /= eq_f. Qed.
End Endo.
Variable aT : Type.
(* The invariant of a function f wrt a projection k is the pred of points *)
(* that have the same projection as their image. *)
Definition invariant (rT : eqType) f (k : aT -> rT) :=
[pred x | k (f x) == k x].
Variables (rT1 rT2 : eqType) (f : aT -> aT) (h : rT1 -> rT2) (k : aT -> rT1).
Lemma invariant_comp : subpred (invariant f k) (invariant f (h \o k)).
Proof. by move=> x eq_kfx; rewrite /= (eqP eq_kfx). Qed.
Lemma invariant_inj : injective h -> invariant f (h \o k) =1 invariant f k.
Proof. by move=> inj_h x; apply: (inj_eq inj_h). Qed.
End EqFun.
Prenex Implicits frel.
(* The coercion to rel must be explicit for derived Notations to unparse. *)
Notation coerced_frel f := (rel_of_simpl (frel f)) (only parsing).
Section FunWith.
Variables (aT : eqType) (rT : Type).
Variant fun_delta : Type := FunDelta of aT & rT.
Definition fwith x y (f : aT -> rT) := [fun z => if z == x then y else f z].
Definition app_fdelta df f z :=
let: FunDelta x y := df in if z == x then y else f z.
End FunWith.
Prenex Implicits fwith.
Notation "x |-> y" := (FunDelta x y)
(at level 190, no associativity,
format "'[hv' x '/ ' |-> y ']'") : fun_delta_scope.
Delimit Scope fun_delta_scope with FUN_DELTA.
Arguments app_fdelta {aT rT%_type} df%_FUN_DELTA f z.
Notation "[ 'fun' z : T => F 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun z : T =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA (fun _ => F)) ..))
(z name, only parsing) : function_scope.
Notation "[ 'fun' z => F 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun z =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA (fun _ => F)) ..))
(z name, format
"'[hv' [ '[' 'fun' z => '/ ' F ']' '/' 'with' '[' d1 , '/' .. , '/' dn ']' ] ']'"
) : function_scope.
Notation "[ 'eta' f 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun _ =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA f) ..))
(format
"'[hv' [ '[' 'eta' '/ ' f ']' '/' 'with' '[' d1 , '/' .. , '/' dn ']' ] ']'"
) : function_scope.
Section DFunWith.
Variables (I : eqType) (T : I -> Type) (f : forall i, T i).
Definition dfwith i (x : T i) (j : I) : T j :=
if (i =P j) is ReflectT ij then ecast j (T j) ij x else f j.
Lemma dfwith_in i x : dfwith x i = x.
Proof. by rewrite /dfwith; case: eqP => // ii; rewrite eq_axiomK. Qed.
Lemma dfwith_out i (x : T i) j : i != j -> dfwith x j = f j.
Proof. by rewrite /dfwith; case: eqP. Qed.
Variant dfwith_spec i (x : T i) : forall j, T j -> Type:=
| DFunWithIn : dfwith_spec x x
| DFunWithOut j : i != j -> dfwith_spec x (f j).
Lemma dfwithP i (x : T i) (j : I) : dfwith_spec x (dfwith x j).
Proof.
by case: (eqVneq i j) => [<-|nij];
[rewrite dfwith_in|rewrite dfwith_out//]; constructor.
Qed.
End DFunWith.
Arguments dfwith {I T} f [i] x.
(* Various EqType constructions. *)
Section ComparableType.
Variable T : Type.
Definition comparable := forall x y : T, decidable (x = y).
Hypothesis compare_T : comparable.
Definition compareb x y : bool := compare_T x y.
Lemma compareP : Equality.axiom compareb.
Proof. by move=> x y; apply: sumboolP. Qed.
Definition comparableMixin := hasDecEq.Build T compareP.
End ComparableType.
Definition eq_comparable (T : eqType) : comparable T :=
fun x y => decP (x =P y).
#[key="sub_sort"]
HB.mixin Record isSub (T : Type) (P : pred T) (sub_sort : Type) := {
val_subdef : sub_sort -> T;
Sub : forall x, P x -> sub_sort;
Sub_rect : forall K (_ : forall x Px, K (@Sub x Px)) u, K u;
SubK_subproof : forall x Px, val_subdef (@Sub x Px) = x
}.
#[short(type="subType")]
HB.structure Definition SubType (T : Type) (P : pred T) := { S of isSub T P S }.
Notation val := (isSub.val_subdef (SubType.on _)).
Notation "\val" := (isSub.val_subdef (SubType.on _)) (only parsing).
Notation "\val" := (isSub.val_subdef _) (only printing).
#[short(type="subEqType")]
HB.structure Definition SubEquality T (P : pred T) :=
{ sT of Equality sT & isSub T P sT}.
Section SubType.
Variables (T : Type) (P : pred T).
(* Generic proof that the second property holds by conversion. *)
(* The vrefl_rect alias is used to flag generic proofs of the first property. *)
Lemma vrefl : forall x, P x -> x = x. Proof. by []. Qed.
Definition vrefl_rect := vrefl.
Section Theory.
Variable sT : subType P.
Local Notation val := (isSub.val_subdef (SubType.on sT)).
Local Notation Sub := (@Sub _ _ sT).
Lemma SubK x Px : val (@Sub x Px) = x. Proof. exact: SubK_subproof. Qed.
Variant Sub_spec : sT -> Type := subSpec x Px : Sub_spec (Sub x Px).
Lemma SubP u : Sub_spec u.
Proof. by elim/(@Sub_rect _ _ sT) : u. Qed.
(* BUG in elim? sT could be inferred from u *)
Definition insub x := if idP is ReflectT Px then Some (Sub x Px) else None.
Definition insubd u0 x := odflt u0 (insub x).
Variant insub_spec x : option sT -> Type :=
| InsubSome u of P x & val u = x : insub_spec x (Some u)
| InsubNone of ~~ P x : insub_spec x None.
Lemma insubP x : insub_spec x (insub x).
Proof.
by rewrite /insub; case: {-}_ / idP; [left; rewrite ?SubK | right; apply/negP].
Qed.
Lemma insubT x Px : insub x = Some (Sub x Px).
Proof.
do [case: insubP => [/SubP[y Py] _ <- | /negP// ]; rewrite SubK] in Px *.
by rewrite (bool_irrelevance Px Py).
Qed.
Lemma insubF x : P x = false -> insub x = None.
Proof. by move/idP; case: insubP. Qed.
Lemma insubN x : ~~ P x -> insub x = None.
Proof. by move/negPf/insubF. Qed.
Lemma isSome_insub : ([eta insub] : pred T) =1 P.
Proof. by apply: fsym => x; case: insubP => // /negPf. Qed.
Lemma insubK : ocancel insub val.
Proof. by move=> x; case: insubP. Qed.
Lemma valP u : P (val u).
Proof. by case/SubP: u => x Px; rewrite SubK. Qed.
Lemma valK : pcancel val insub.
Proof. by case/SubP=> x Px; rewrite SubK; apply: insubT. Qed.
Lemma val_inj : injective val.
Proof. exact: pcan_inj valK. Qed.
Lemma valKd u0 : cancel val (insubd u0).
Proof. by move=> u; rewrite /insubd valK. Qed.
Lemma val_insubd u0 x : val (insubd u0 x) = if P x then x else val u0.
Proof. by rewrite /insubd; case: insubP => [u -> | /negPf->]. Qed.
Lemma insubdK u0 : {in P, cancel (insubd u0) val}.
Proof. by move=> x Px; rewrite val_insubd [P x]Px. Qed.
Let insub_eq_aux x isPx : P x = isPx -> option sT :=
if isPx as b return _ = b -> _ then fun Px => Some (Sub x Px) else fun=> None.
Definition insub_eq x := insub_eq_aux (erefl (P x)).
Lemma insub_eqE : insub_eq =1 insub.
Proof.
rewrite /insub_eq => x; set b := P x; rewrite [in LHS]/b in (Db := erefl b) *.
by case: b in Db *; [rewrite insubT | rewrite insubF].
Qed.
End Theory.
End SubType.
(* Arguments val {T P sT} u : rename. *)
Arguments Sub {T P sT} x Px : rename.
Arguments vrefl {T P} x Px.
Arguments vrefl_rect {T P} x Px.
Arguments insub {T P sT} x.
Arguments insubd {T P sT} u0 x.
Arguments insubT [T] P [sT x].
Arguments val_inj {T P sT} [u1 u2] eq_u12 : rename.
Arguments valK {T P sT} u : rename.
Arguments valKd {T P sT} u0 u : rename.
Arguments insubK {T P} sT x.
Arguments insubdK {T P sT} u0 [x] Px.
Local Notation inlined_sub_rect :=
(fun K K_S u => let (x, Px) as u return K u := u in K_S x Px).
Local Notation inlined_new_rect :=
(fun K K_S u => let (x) as u return K u := u in K_S x).
Reserved Notation "[ 'isSub' 'for' v ]" (format "[ 'isSub' 'for' v ]").
Notation "[ 'isSub' 'for' v ]" :=
(@isSub.phant_Build _ _ _ v _ inlined_sub_rect vrefl_rect)
(only parsing) : form_scope.
Notation "[ 'isSub' 'of' T 'for' v ]" :=
(@isSub.phant_Build _ _ T v _ inlined_sub_rect vrefl_rect)
(only parsing) : form_scope.
Notation "[ 'isSub' 'for' v 'by' rec ]" :=
(@isSub.phant_Build _ _ _ v _ rec vrefl)
(format "[ 'isSub' 'for' v 'by' rec ]") : form_scope.
Notation "[ 'isSub' 'for' v ]" := (@isSub.phant_Build _ _ _ v _ _ _)
(only printing, format "[ 'isSub' 'for' v ]") : form_scope.
Reserved Notation "[ 'isNew' 'for' v ]" (format "[ 'isNew' 'for' v ]").
Definition NewMixin T U v c Urec sk :=
let Urec' P IH := Urec P (fun x : T => IH x isT : P _) in
@isSub.phant_Build _ _ U v (fun x _ => c x) Urec' sk.
Notation "[ 'isNew' 'for' v ]" :=
(@NewMixin _ _ v _ inlined_new_rect vrefl_rect) (only parsing) : form_scope.
Notation "[ 'isNew' 'for' v ]" := (@NewMixin _ _ v _ _ _)
(only printing, format "[ 'isNew' 'for' v ]") : form_scope.
Notation "[ 'isNew' 'of' T 'for' v ]" :=
(@NewMixin _ T v _ inlined_new_rect vrefl_rect) (only parsing) : form_scope.
Definition innew T nT x := @Sub T predT nT x (erefl true).
Arguments innew {T nT}.
Lemma innew_val T nT : cancel val (@innew T nT).
Proof. by move=> u; apply: val_inj; apply: SubK. Qed.
HB.instance Definition _ T (P : pred T) := [isSub of sig P for sval].
(* Shorthand for sigma types over collective predicates. *)
Notation "{ x 'in' A }" := {x | x \in A}
(x at level 99, format "{ x 'in' A }") : type_scope.
Notation "{ x 'in' A | P }" := {x | (x \in A) && P}
(x at level 99, format "{ x 'in' A | P }") : type_scope.
(* Shorthand for the return type of insub. *)
Notation "{ ? x : T | P }" := (option {x : T | is_true P})
(x at level 99, only parsing) : type_scope.
Notation "{ ? x | P }" := {? x : _ | P}
(x at level 99, format "{ ? x | P }") : type_scope.
Notation "{ ? x 'in' A }" := {? x | x \in A}
(x at level 99, format "{ ? x 'in' A }") : type_scope.
Notation "{ ? x 'in' A | P }" := {? x | (x \in A) && P}
(x at level 99, format "{ ? x 'in' A | P }") : type_scope.
(* A variant of injection with default that infers a collective predicate *)
(* from the membership proof for the default value. *)
Definition insigd T (A : mem_pred T) x (Ax : in_mem x A) :=
insubd (exist [eta A] x Ax).
(* There should be a rel definition for the subType equality op, but this *)
(* seems to cause the simpl tactic to diverge on expressions involving == *)
(* on 4+ nested subTypes in a "strict" position (e.g., after ~~). *)
(* Definition feq f := [rel x y | f x == f y]. *)
Section TransferType.
Variables (T T' : Type) (f : T -> T').
Definition inj_type of injective f : Type := T.
Definition pcan_type g of pcancel f g : Type := T.
Definition can_type g of cancel f g : Type := T.
End TransferType.
Section TransferEqType.
Variables (T : Type) (eT : eqType) (f : T -> eT).
Lemma inj_eqAxiom : injective f -> Equality.axiom (fun x y => f x == f y).
Proof. by move=> f_inj x y; apply: (iffP eqP) => [|-> //]; apply: f_inj. Qed.
HB.instance Definition _ f_inj := hasDecEq.Build (inj_type f_inj)
(inj_eqAxiom f_inj).
HB.instance Definition _ g (fK : pcancel f g) := Equality.copy (pcan_type fK)
(inj_type (pcan_inj fK)).
HB.instance Definition _ g (fK : cancel f g) := Equality.copy (can_type fK)
(inj_type (can_inj fK)).
Definition deprecated_InjEqMixin f_inj := hasDecEq.Build T (inj_eqAxiom f_inj).
Definition deprecated_PcanEqMixin g (fK : pcancel f g) :=
deprecated_InjEqMixin (pcan_inj fK).
Definition deprecated_CanEqMixin g (fK : cancel f g) :=
deprecated_InjEqMixin (can_inj fK).
End TransferEqType.
Definition sub_type T (P : pred T) (sT : subType P) : Type := sT.
HB.instance Definition _ T (P : pred T) (sT : subType P) :=
SubType.on (sub_type sT).
Section SubEqType.
Variables (T : eqType) (P : pred T) (sT : subType P).
Local Notation ev_ax := (fun T v => @Equality.axiom T (fun x y => v x == v y)).
Lemma val_eqP : ev_ax sT val. Proof. exact: inj_eqAxiom val_inj. Qed.
#[hnf] HB.instance Definition _ := Equality.copy (sub_type sT) (pcan_type valK).
End SubEqType.
Lemma val_eqE (T : eqType) (P : pred T) (sT : subEqType P)
(u v : sT) : (val u == val v) = (u == v).
Proof. exact/val_eqP/eqP. Qed.
Arguments val_eqP {T P sT x y}.
Notation "[ 'Equality' 'of' T 'by' <: ]" := (Equality.copy T%type (sub_type T%type))
(format "[ 'Equality' 'of' T 'by' <: ]") : form_scope.
HB.instance Definition _ := Equality.copy void (pcan_type (of_voidK unit)).
HB.instance Definition _ (T : eqType) (P : pred T) :=
[Equality of {x | P x} by <:].
Section ProdEqType.
Variable T1 T2 : eqType.
Definition pair_eq : rel (T1 * T2) := fun u v => (u.1 == v.1) && (u.2 == v.2).
Lemma pair_eqP : Equality.axiom pair_eq.
Proof.
move=> [x1 x2] [y1 y2] /=; apply: (iffP andP) => [[]|[<- <-]] //=.
by do 2!move/eqP->.
Qed.
HB.instance Definition _ := hasDecEq.Build (T1 * T2)%type pair_eqP.
Lemma pair_eqE : pair_eq = eq_op :> rel _. Proof. by []. Qed.
Lemma xpair_eqE (x1 y1 : T1) (x2 y2 : T2) :
((x1, x2) == (y1, y2)) = ((x1 == y1) && (x2 == y2)).
Proof. by []. Qed.
Lemma pair_eq1 (u v : T1 * T2) : u == v -> u.1 == v.1.
Proof. by case/andP. Qed.
Lemma pair_eq2 (u v : T1 * T2) : u == v -> u.2 == v.2.
Proof. by case/andP. Qed.
End ProdEqType.
Arguments pair_eq {T1 T2} u v /.
Arguments pair_eqP {T1 T2}.
Definition predX T1 T2 (p1 : pred T1) (p2 : pred T2) :=
[pred z | p1 z.1 & p2 z.2].
Notation "[ 'predX' A1 & A2 ]" := (predX [in A1] [in A2])
(format "[ 'predX' A1 & A2 ]") : function_scope.
Section OptionEqType.
Variable T : eqType.
Definition opt_eq (u v : option T) : bool :=
oapp (fun x => oapp (eq_op x) false v) (~~ v) u.
Lemma opt_eqP : Equality.axiom opt_eq.
Proof.
case=> [x|] [y|] /=; by [constructor | apply: (iffP eqP) => [|[]] ->].
Qed.
HB.instance Definition _ := hasDecEq.Build (option T) opt_eqP.
End OptionEqType.
Arguments opt_eq {T} !u !v.
Section TaggedAs.
Variables (I : eqType) (T_ : I -> Type).
Implicit Types u v : {i : I & T_ i}.
Definition tagged_as u v :=
if tag u =P tag v is ReflectT eq_uv then
eq_rect_r T_ (tagged v) eq_uv
else tagged u.
Lemma tagged_asE u x : tagged_as u (Tagged T_ x) = x.
Proof.
by rewrite /tagged_as /=; case: eqP => // eq_uu; rewrite [eq_uu]eq_axiomK.
Qed.
End TaggedAs.
Section EqTagged.
Variables (I : eqType) (T_ : I -> Type).
Local Notation T := {i : I & T_ i}.
Definition etagged i u (p : tag u = i) := ecast i (T_ i) p (tagged u).
Implicit Types (i j : I) (u v : T).
Lemma eq_from_Tagged i (t s : T_ i) : Tagged T_ t = Tagged T_ s -> t = s.
Proof. by move=> /(congr1 (tagged_as (Tagged T_ t))); rewrite !tagged_asE. Qed.
Lemma etaggedK i u (p : tag u = i) : Tagged T_ (etagged p) = u.
Proof. by case: _ / p; apply: taggedK. Qed.
Definition tagged_with i : pred {i : I & T_ i} := [pred j | tag j == i].
Definition untag_with i (x : {x in tagged_with i}) : T_ i :=
etagged (eqP (valP x)).
Definition tag_with i (t : T_ i) : {x in tagged_with i} :=
exist _ (Tagged T_ t) (eq_refl i).
Lemma untag_withK i : cancel (@untag_with i) (@tag_with i).
Proof. by case=> -[j /= x eq_ji]; apply/val_inj=> /=; rewrite etaggedK. Qed.
#[local] Hint Resolve untag_withK : core.
Lemma tag_withK i : cancel (@tag_with i) (@untag_with i).
Proof. by move=> x; rewrite /untag_with/= eq_axiomK. Qed.
#[local] Hint Resolve tag_withK : core.
Lemma tag_with_bij i : bijective (@tag_with i).
Proof. by exists (@untag_with i). Qed.
Lemma untag_with_bij i : bijective (@untag_with i).
Proof. by exists (@tag_with i). Qed.
Definition untag (R : Type) (idx : R) (i : I) (F : T_ i -> R) u :=
if tag u =P i is ReflectT e then F (etagged e) else idx.
Lemma untagE (R : Type) (idx : R) (i : I) (F : T_ i -> R) u (e : tag u = i):
untag idx F u = F (etagged e).
Proof. by rewrite /untag; case: eqP => // p; rewrite (eq_irrelevance p e). Qed.
Lemma untag_dflt (R : Type) (idx : R) (i : I) (F : T_ i -> R) u : tag u != i ->
untag idx F u = idx.
Proof. by rewrite /untag; case: eqP. Qed.
Lemma untag_cst (R : Type) (idx : R) (i : I) u :
untag idx (fun _ : T_ i => idx) u = idx.
Proof. by rewrite /untag; case: eqP. Qed.
End EqTagged.
Arguments etagged {I T_ i u}.
Arguments untag {I T_ R} idx [i].
Arguments tagged_with {I}.
Arguments tag_with {I T_}.
Arguments untag_with {I T_}.
Section TagEqType.
Variables (I : eqType) (T_ : I -> eqType).
Implicit Types u v : {i : I & T_ i}.
Definition tag_eq u v := (tag u == tag v) && (tagged u == tagged_as u v).
Lemma tag_eqP : Equality.axiom tag_eq.
Proof.
rewrite /tag_eq => [] [i x] [j] /=.
case: eqP => [<-|Hij] y; last by right; case.
by apply: (iffP eqP) => [->|<-]; rewrite tagged_asE.
Qed.
HB.instance Definition _ := hasDecEq.Build {i : I & T_ i} tag_eqP.
Lemma tag_eqE : tag_eq = eq_op. Proof. by []. Qed.
Lemma eq_tag u v : u == v -> tag u = tag v.
Proof. by move/eqP->. Qed.
Lemma eq_Tagged u x :(u == Tagged _ x) = (tagged u == x).
Proof. by rewrite -tag_eqE /tag_eq eqxx tagged_asE. Qed.
End TagEqType.
Arguments tag_eq {I T_} !u !v.
Arguments tag_eqP {I T_ x y}.
Section SumEqType.
Variables T1 T2 : eqType.
Implicit Types u v : T1 + T2.
Definition sum_eq u v :=
match u, v with
| inl x, inl y | inr x, inr y => x == y
| _, _ => false
end.
Lemma sum_eqP : Equality.axiom sum_eq.
Proof. case=> x [] y /=; by [right | apply: (iffP eqP) => [->|[->]]]. Qed.
HB.instance Definition _ := hasDecEq.Build (T1 + T2)%type sum_eqP.
Lemma sum_eqE : sum_eq = eq_op. Proof. by []. Qed.
End SumEqType.
Arguments sum_eq {T1 T2} !u !v.
Arguments sum_eqP {T1 T2 x y}.
Section MonoHomoTheory.
Variables (aT rT : eqType) (f : aT -> rT).
Variables (aR aR' : rel aT) (rR rR' : rel rT).
Hypothesis aR_refl : reflexive aR.
Hypothesis rR_refl : reflexive rR.
Hypothesis aR'E : forall x y, aR' x y = (x != y) && (aR x y).
Hypothesis rR'E : forall x y, rR' x y = (x != y) && (rR x y).
Let aRE x y : aR x y = (x == y) || (aR' x y).
Proof. by rewrite aR'E; case: eqVneq => //= ->; apply: aR_refl. Qed.
Let rRE x y : rR x y = (x == y) || (rR' x y).
Proof. by rewrite rR'E; case: eqVneq => //= ->; apply: rR_refl. Qed.
Section InDom.
Variable D : pred aT.
Section DifferentDom.
Variable D' : pred aT.
Lemma homoW_in : {in D & D', {homo f : x y / aR' x y >-> rR' x y}} ->
{in D & D', {homo f : x y / aR x y >-> rR x y}}.
Proof.
by move=> mf x y xD yD /[!aRE]/orP[/eqP->|/mf]; rewrite rRE ?eqxx// orbC => ->.
Qed.
Lemma inj_homo_in : {in D & D', injective f} ->
{in D & D', {homo f : x y / aR x y >-> rR x y}} ->
{in D & D', {homo f : x y / aR' x y >-> rR' x y}}.
Proof.
move=> fI mf x y xD yD /[!(aR'E, rR'E)] /andP[neq_xy xy].
by rewrite mf ?andbT//; apply: contra_neq neq_xy; apply: fI.
Qed.
End DifferentDom.
Hypothesis aR_anti : antisymmetric aR.
Hypothesis rR_anti : antisymmetric rR.
Lemma mono_inj_in : {in D &, {mono f : x y / aR x y >-> rR x y}} ->
{in D &, injective f}.
Proof. by move=> mf x y ?? eqf; apply/aR_anti; rewrite -!mf// eqf rR_refl. Qed.
Lemma anti_mono_in : {in D &, {mono f : x y / aR x y >-> rR x y}} ->
{in D &, {mono f : x y / aR' x y >-> rR' x y}}.
Proof.
move=> mf x y ??; rewrite rR'E aR'E mf// (@inj_in_eq _ _ D)//.
exact: mono_inj_in.
Qed.
Lemma total_homo_mono_in : total aR ->
{in D &, {homo f : x y / aR' x y >-> rR' x y}} ->
{in D &, {mono f : x y / aR x y >-> rR x y}}.
Proof.
move=> aR_tot mf x y xD yD.
have [->|neq_xy] := eqVneq x y; first by rewrite ?eqxx ?aR_refl ?rR_refl.
have [xy|] := (boolP (aR x y)); first by rewrite rRE mf ?orbT// aR'E neq_xy.
have /orP [->//|] := aR_tot x y.
rewrite aRE eq_sym (negPf neq_xy) /= => /mf -/(_ yD xD).
rewrite rR'E => /andP[Nfxfy fyfx] _; apply: contra_neqF Nfxfy => fxfy.
by apply/rR_anti; rewrite fyfx fxfy.
Qed.
End InDom.
Let D := @predT aT.
Lemma homoW : {homo f : x y / aR' x y >-> rR' x y} ->
{homo f : x y / aR x y >-> rR x y}.
Proof. by move=> mf ???; apply: (@homoW_in D D) => // ????; apply: mf. Qed.
Lemma inj_homo : injective f ->
{homo f : x y / aR x y >-> rR x y} ->
{homo f : x y / aR' x y >-> rR' x y}.
Proof.
by move=> fI mf ???; apply: (@inj_homo_in D D) => //????; [apply: fI|apply: mf].
Qed.
Hypothesis aR_anti : antisymmetric aR.
Hypothesis rR_anti : antisymmetric rR.
Lemma mono_inj : {mono f : x y / aR x y >-> rR x y} -> injective f.
Proof. by move=> mf x y eqf; apply/aR_anti; rewrite -!mf eqf rR_refl. Qed.
Lemma anti_mono : {mono f : x y / aR x y >-> rR x y} ->
{mono f : x y / aR' x y >-> rR' x y}.
Proof. by move=> mf x y; rewrite rR'E aR'E mf inj_eq //; apply: mono_inj. Qed.
Lemma total_homo_mono : total aR ->
{homo f : x y / aR' x y >-> rR' x y} ->
{mono f : x y / aR x y >-> rR x y}.
Proof.
move=> /(@total_homo_mono_in D rR_anti) hmf hf => x y.
by apply: hmf => // ?? _ _; apply: hf.
Qed.
End MonoHomoTheory.
|
LieTheorem.lean
|
/-
Copyright (c) 2024 Lucas Whitfield. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lucas Whitfield, Johan Commelin
-/
import Mathlib.Algebra.Lie.Weights.Basic
import Mathlib.RingTheory.Finiteness.Nilpotent
/-!
# Lie's theorem for Solvable Lie algebras.
Lie's theorem asserts that Lie modules of solvable Lie algebras over fields of characteristic 0
have a common eigenvector for the action of all elements of the Lie algebra.
This result is named `LieModule.exists_forall_lie_eq_smul_of_isSolvable`.
-/
namespace LieModule
section
/-
The following variables generalize the setting where:
- `R` is a principal ideal domain of characteristic zero,
- `L` is a Lie algebra over `R`,
- `V` is a Lie algebra module over `L`
- `A` is a Lie ideal of `L`.
Besides generalizing, it also make the proof of `lie_stable` syntactically smoother.
-/
variable {R L A V : Type*} [CommRing R]
variable [IsPrincipalIdealRing R] [IsDomain R] [CharZero R]
variable [LieRing L] [LieAlgebra R L]
variable [LieRing A] [LieAlgebra R A]
variable [Bracket L A] [Bracket A L]
variable [AddCommGroup V] [Module R V] [Module.Free R V] [Module.Finite R V]
variable [LieRingModule L V] [LieModule R L V]
variable [LieRingModule A V] [LieModule R A V]
variable [IsLieTower L A V] [IsLieTower A L V]
variable (χ : A → R)
open Module (finrank)
open LieModule
local notation "π" => LieModule.toEnd R _ V
private abbrev T (w : A) : Module.End R V := (π w) - χ w • 1
/-- An auxiliary lemma used only in the definition `LieModule.weightSpaceOfIsLieTower` below. -/
private lemma weightSpaceOfIsLieTower_aux (z : L) (v : V) (hv : v ∈ weightSpace V χ) :
⁅z, v⁆ ∈ weightSpace V χ := by
rw [mem_weightSpace] at hv ⊢
intro a
rcases eq_or_ne v 0 with (rfl | hv')
· simp only [lie_zero, smul_zero]
suffices χ ⁅z, a⁆ = 0 by
rw [leibniz_lie, hv a, lie_smul, lie_swap_lie, hv, this, zero_smul, neg_zero, zero_add]
let U' : ℕ →o Submodule R V :=
{ toFun n := Submodule.span R {((π z)^i) v | i < n},
monotone' i j h := Submodule.span_mono (fun _ ⟨c, hc, hw⟩ ↦ ⟨c, lt_of_lt_of_le hc h, hw⟩) }
have map_U'_le (n : ℕ) : Submodule.map (π z) (U' n) ≤ U' (n + 1) := by
simp only [OrderHom.coe_mk, Submodule.map_span, toEnd_apply_apply, U']
apply Submodule.span_mono
suffices ∀ a < n, ∃ b < n + 1, ((π z) ^ b) v = ((π z) ^ (a + 1)) v by simpa [pow_succ']
aesop
have T_apply_succ (w : A) (n : ℕ) :
Submodule.map (T χ w) (U' (n + 1)) ≤ U' n := by
simp only [OrderHom.coe_mk, U', Submodule.map_span, Submodule.span_le, Set.image_subset_iff]
simp only [Set.subset_def, Set.mem_setOf_eq, Set.mem_preimage, SetLike.mem_coe,
forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
induction n generalizing w
· simp only [zero_add, Nat.lt_one_iff, LinearMap.sub_apply, LieModule.toEnd_apply_apply,
LinearMap.smul_apply, Module.End.one_apply, forall_eq, pow_zero, hv w, sub_self, zero_mem]
· next n hn =>
intro m hm
obtain (hm | rfl) : m < n + 1 ∨ m = n + 1 := by omega
· exact U'.mono (Nat.le_succ n) (hn w m hm)
have H : ∀ w, ⁅w, (π z ^ n) v⁆ = (T χ w) ((π z ^ n) v) + χ w • ((π z ^ n) v) := by simp
rw [T, LinearMap.sub_apply, pow_succ', Module.End.mul_apply, LieModule.toEnd_apply_apply,
LieModule.toEnd_apply_apply, LinearMap.smul_apply, Module.End.one_apply, leibniz_lie,
lie_swap_lie w z, H, H, lie_add, lie_smul, add_sub_assoc, add_sub_assoc, sub_self, add_zero]
refine add_mem (neg_mem <| add_mem ?_ ?_) ?_
· exact U'.mono n.le_succ (hn _ n n.lt_succ_self)
· exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨n, n.lt_succ_self, rfl⟩)
· exact map_U'_le _ <| Submodule.mem_map_of_mem <| hn w n n.lt_succ_self
set U : LieSubmodule R A V :=
{ toSubmodule := ⨆ k : ℕ, U' k
lie_mem {w} x hx := by
rw [show ⁅w, x⁆ = (T χ w) x + χ w • x by simp]
apply add_mem _ (Submodule.smul_mem _ _ hx)
set U := ⨆ k : ℕ, U' k
suffices Submodule.map (T χ w) U ≤ U from this <| Submodule.mem_map_of_mem hx
rw [Submodule.map_iSup, iSup_le_iff]
rintro (_ | i)
· simp [U']
· exact (T_apply_succ w i).trans (le_iSup _ _) }
have hzU (x : V) (hx : x ∈ U) : (π z) x ∈ U := by
suffices Submodule.map (π z) U ≤ U from this <| Submodule.mem_map_of_mem hx
simp only [U, Submodule.map_iSup, iSup_le_iff]
exact fun i ↦ (map_U'_le i).trans (le_iSup _ _)
have trace_za_zero : (LieModule.toEnd R A _ ⁅z, a⁆).trace R U = 0 := by
have hres : LieModule.toEnd R A U ⁅z, a⁆ = ⁅(π z).restrict hzU, LieModule.toEnd R A U a⁆ := by
ext ⟨x, hx⟩
change ⁅⁅z, a⁆, x⁆ = ⁅z, ⁅a, x⁆⁆ - ⁅a, ⁅z, x⁆⁆
simp only [leibniz_lie z a, add_sub_cancel_right]
rw [hres, LinearMap.trace_lie]
have trace_T_U_zero (w : A) : (T χ w).trace R U = 0 := by
have key (i : ℕ) (hi : i ≠ 0) : ∃ j < i, Submodule.map (T χ w) (U' i) ≤ U' j := by
obtain ⟨j, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hi
exact ⟨j, j.lt_succ_self, T_apply_succ w j⟩
apply IsNilpotent.eq_zero
apply LinearMap.isNilpotent_trace_of_isNilpotent
rw [Module.End.isNilpotent_iff_of_finite]
suffices ⨆ i, U' i ≤ Module.End.maxGenEigenspace (T χ w) 0 by
intro x
specialize this x.2
simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero] at this
peel this with n hn
ext
simp only [ZeroMemClass.coe_zero, ← hn]; clear hn
induction n <;> simp_all [pow_succ']
apply iSup_le
intro i x hx
simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero]
induction i using Nat.strong_induction_on generalizing x
next i ih =>
obtain rfl | hi := eq_or_ne i 0
· simp_all [U']
obtain ⟨j, hj, hj'⟩ := key i hi
obtain ⟨k, hk⟩ := ih j hj (hj' <| Submodule.mem_map_of_mem hx)
use k+1
rw [pow_succ, Module.End.mul_apply, hk]
have trace_za : (toEnd R A _ ⁅z, a⁆).trace R U = χ ⁅z, a⁆ • (finrank R U) := by
simpa [T, sub_eq_zero] using trace_T_U_zero ⁅z, a⁆
suffices finrank R U ≠ 0 by simp_all
suffices Nontrivial U from Module.finrank_pos.ne'
have hvU : v ∈ U := by
apply Submodule.mem_iSup_of_mem 1
apply Submodule.subset_span
use 0, zero_lt_one
rw [pow_zero, Module.End.one_apply]
exact nontrivial_of_ne ⟨v, hvU⟩ 0 <| by simp [hv']
variable (R V) in
/-- The weight space of `V` with respect to `χ : A → R`, a priori a Lie submodule for `A`, is also a
Lie submodule for `L`. -/
def weightSpaceOfIsLieTower (χ : A → R) : LieSubmodule R L V :=
{ toSubmodule := weightSpace V χ
lie_mem {z v} hv := weightSpaceOfIsLieTower_aux χ z v hv }
end
section
variable {k : Type*} [Field k]
variable {L : Type*} [LieRing L] [LieAlgebra k L]
variable {V : Type*} [AddCommGroup V] [Module k V] [LieRingModule L V] [LieModule k L V]
variable [CharZero k] [Module.Finite k V]
open Submodule in
theorem exists_nontrivial_weightSpace_of_lieIdeal [LieModule.IsTriangularizable k L V]
(A : LieIdeal k L) (hA : IsCoatom A.toSubmodule)
(χ₀ : Module.Dual k A) [Nontrivial (weightSpace V χ₀)] :
∃ (χ : Module.Dual k L), Nontrivial (weightSpace V χ) := by
obtain ⟨z, -, hz⟩ := SetLike.exists_of_lt (hA.lt_top)
let e : (k ∙ z) ≃ₗ[k] k := (LinearEquiv.toSpanNonzeroSingleton k L z <| by aesop).symm
have he : ∀ x, e x • z = x := by simp [e]
have hA : IsCompl A.toSubmodule (k ∙ z) := isCompl_span_singleton_of_isCoatom_of_notMem hA hz
let π₁ : L →ₗ[k] A := A.toSubmodule.linearProjOfIsCompl (k ∙ z) hA
let π₂ : L →ₗ[k] (k ∙ z) := (k ∙ z).linearProjOfIsCompl ↑A hA.symm
set W : LieSubmodule k L V := weightSpaceOfIsLieTower k V χ₀
obtain ⟨c, hc⟩ : ∃ c, (toEnd k _ W z).HasEigenvalue c := by
have : Nontrivial W := inferInstanceAs (Nontrivial (weightSpace V χ₀))
apply Module.End.exists_hasEigenvalue_of_genEigenspace_eq_top
exact LieModule.IsTriangularizable.maxGenEigenspace_eq_top z
obtain ⟨⟨v, hv⟩, hvc⟩ := hc.exists_hasEigenvector
have hv' : ∀ (x : ↥A), ⁅x, v⁆ = χ₀ x • v := by
simpa [W, weightSpaceOfIsLieTower, mem_weightSpace] using hv
use (χ₀.comp π₁) + c • (e.comp π₂)
refine nontrivial_of_ne ⟨v, ?_⟩ 0 ?_
· rw [mem_weightSpace]
intro x
have hπ : (π₁ x : L) + π₂ x = x := linearProjOfIsCompl_add_linearProjOfIsCompl_eq_self hA x
suffices ⁅(π₂ x : L), v⁆ = (c • e (π₂ x)) • v by
calc ⁅x, v⁆
= ⁅π₁ x, v⁆ + ⁅(π₂ x : L), v⁆ := congr(⁅$hπ.symm, v⁆) ▸ add_lie _ _ _
_ = χ₀ (π₁ x) • v + (c • e (π₂ x)) • v := by rw [hv' (π₁ x), this]
_ = _ := by simp [add_smul]
calc ⁅(π₂ x : L), v⁆
= e (π₂ x) • ↑(c • ⟨v, hv⟩ : W) := by rw [← he, smul_lie, ← hvc.apply_eq_smul]; rfl
_ = (c • e (π₂ x)) • v := by rw [smul_assoc, smul_comm]; rfl
· simpa [ne_eq, LieSubmodule.mk_eq_zero] using hvc.right
variable (k L V)
variable [Nontrivial V]
open LieAlgebra
-- This lemma is the central inductive argument in the proof of Lie's theorem below.
-- The statement is identical to `LieModule.exists_forall_lie_eq_smul_of_isSolvable`
-- except that it additionally assumes a finiteness hypothesis.
private lemma exists_forall_lie_eq_smul_of_isSolvable_of_finite
(L : Type*) [LieRing L] [LieAlgebra k L] [LieRingModule L V] [LieModule k L V]
[IsSolvable L] [LieModule.IsTriangularizable k L V] [Module.Finite k L] :
∃ χ : Module.Dual k L, Nontrivial (weightSpace V χ) := by
obtain H|⟨A, hA, hAL⟩ := eq_top_or_exists_le_coatom (derivedSeries k L 1).toSubmodule
· obtain _ | _ := subsingleton_or_nontrivial L
· use 0
simpa [mem_weightSpace, nontrivial_iff] using exists_pair_ne V
· rw [LieSubmodule.toSubmodule_eq_top] at H
exact ((derivedSeries_lt_top_of_solvable k L).ne H).elim
lift A to LieIdeal k L
· intros
exact hAL <| LieSubmodule.lie_mem_lie (LieSubmodule.mem_top _) (LieSubmodule.mem_top _)
change LieIdeal k L at A -- remove this line when bug in `lift` is fixed (#15865)
obtain ⟨χ', _⟩ := exists_forall_lie_eq_smul_of_isSolvable_of_finite A
exact exists_nontrivial_weightSpace_of_lieIdeal A hA χ'
termination_by Module.finrank k L
decreasing_by
simp_wf
rw [← finrank_top k L]
apply Submodule.finrank_lt_finrank_of_lt
exact hA.lt_top
/-- **Lie's theorem**: Lie modules of solvable Lie algebras over fields of characteristic 0
have a common eigenvector for the action of all elements of the Lie algebra.
See `LieModule.exists_nontrivial_weightSpace_of_isNilpotent` for the variant that
assumes that `L` is nilpotent and drops the condition that `k` is of characteristic zero. -/
theorem exists_nontrivial_weightSpace_of_isSolvable
[IsSolvable L] [LieModule.IsTriangularizable k L V] :
∃ χ : Module.Dual k L, Nontrivial (weightSpace V χ) := by
let imL := (toEnd k L V).range
let toEndo : L →ₗ[k] imL := LinearMap.codRestrict imL.toSubmodule (toEnd k L V)
(fun x ↦ LinearMap.mem_range.mpr ⟨x, rfl⟩ : ∀ x : L, (toEnd k L V) x ∈ imL)
have ⟨χ, h⟩ := exists_forall_lie_eq_smul_of_isSolvable_of_finite k V imL
use χ.comp toEndo
obtain ⟨⟨v, hv⟩, hv0⟩ := exists_ne (0 : weightSpace V χ)
refine nontrivial_of_ne ⟨v, ?_⟩ 0 ?_
· rw [mem_weightSpace] at hv ⊢
intro x
apply hv (toEndo x)
· simpa using hv0
end
end LieModule
|
LinearMap.lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Analysis.InnerProductSpace.Continuous
/-!
# Linear maps on inner product spaces
This file studies linear maps on inner product spaces.
## Main results
- We define `innerSL` as the inner product bundled as a continuous sesquilinear map, and
`innerₛₗ` for the non-continuous version.
- We prove a general polarization identity for linear maps (`inner_map_polarization`)
- We show that a linear map preserving the inner product is an isometry
(`LinearMap.isometryOfInner`) and conversely an isometry preserves the inner product
(`LinearIsometry.inner_map_map`).
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => inner 𝕜 x y
section Complex_Seminormed
variable {V : Type*} [SeminormedAddCommGroup V] [InnerProductSpace ℂ V]
/-- A complex polarization identity, with a linear map. -/
theorem inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V) :
⟪T y, x⟫_ℂ =
(⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ +
Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ -
Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) /
4 := by
simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left,
inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right,
mul_add, ← mul_assoc, mul_neg, neg_neg, one_mul, neg_one_mul, mul_sub, sub_sub]
ring
theorem inner_map_polarization' (T : V →ₗ[ℂ] V) (x y : V) :
⟪T x, y⟫_ℂ =
(⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ -
Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ +
Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) /
4 := by
simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left,
inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right,
mul_add, ← mul_assoc, mul_neg, neg_neg, one_mul, neg_one_mul, mul_sub, sub_sub]
ring
end Complex_Seminormed
section Complex
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V]
/-- A linear map `T` is zero, if and only if the identity `⟪T x, x⟫_ℂ = 0` holds for all `x`.
-/
theorem inner_map_self_eq_zero (T : V →ₗ[ℂ] V) : (∀ x : V, ⟪T x, x⟫_ℂ = 0) ↔ T = 0 := by
constructor
· intro hT
ext x
rw [LinearMap.zero_apply, ← @inner_self_eq_zero ℂ V, inner_map_polarization]
simp only [hT]
norm_num
· rintro rfl x
simp only [LinearMap.zero_apply, inner_zero_left]
/--
Two linear maps `S` and `T` are equal, if and only if the identity `⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ` holds
for all `x`.
-/
theorem ext_inner_map (S T : V →ₗ[ℂ] V) : (∀ x : V, ⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ) ↔ S = T := by
rw [← sub_eq_zero, ← inner_map_self_eq_zero]
refine forall_congr' fun x => ?_
rw [LinearMap.sub_apply, inner_sub_left, sub_eq_zero]
end Complex
section
variable {ι : Type*} {ι' : Type*} {ι'' : Type*}
variable {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace 𝕜 E']
variable {E'' : Type*} [SeminormedAddCommGroup E''] [InnerProductSpace 𝕜 E'']
/-- A linear isometry preserves the inner product. -/
@[simp]
theorem LinearIsometry.inner_map_map (f : E →ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ := by
simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map]
/-- A linear isometric equivalence preserves the inner product. -/
@[simp]
theorem LinearIsometryEquiv.inner_map_map (f : E ≃ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ :=
f.toLinearIsometry.inner_map_map x y
/-- The adjoint of a linear isometric equivalence is its inverse. -/
theorem LinearIsometryEquiv.inner_map_eq_flip (f : E ≃ₗᵢ[𝕜] E') (x : E) (y : E') :
⟪f x, y⟫_𝕜 = ⟪x, f.symm y⟫_𝕜 := by
conv_lhs => rw [← f.apply_symm_apply y, f.inner_map_map]
/-- A linear map that preserves the inner product is a linear isometry. -/
def LinearMap.isometryOfInner (f : E →ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E →ₗᵢ[𝕜] E' :=
⟨f, fun x => by simp only [@norm_eq_sqrt_re_inner 𝕜, h]⟩
@[simp]
theorem LinearMap.coe_isometryOfInner (f : E →ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f :=
rfl
@[simp]
theorem LinearMap.isometryOfInner_toLinearMap (f : E →ₗ[𝕜] E') (h) :
(f.isometryOfInner h).toLinearMap = f :=
rfl
/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/
def LinearEquiv.isometryOfInner (f : E ≃ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E ≃ₗᵢ[𝕜] E' :=
⟨f, ((f : E →ₗ[𝕜] E').isometryOfInner h).norm_map⟩
@[simp]
theorem LinearEquiv.coe_isometryOfInner (f : E ≃ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f :=
rfl
@[simp]
theorem LinearEquiv.isometryOfInner_toLinearEquiv (f : E ≃ₗ[𝕜] E') (h) :
(f.isometryOfInner h).toLinearEquiv = f :=
rfl
/-- A linear map is an isometry if and it preserves the inner product. -/
theorem LinearMap.norm_map_iff_inner_map_map {F : Type*} [FunLike F E E'] [LinearMapClass F 𝕜 E E']
(f : F) : (∀ x, ‖f x‖ = ‖x‖) ↔ (∀ x y, ⟪f x, f y⟫_𝕜 = ⟪x, y⟫_𝕜) :=
⟨({ toLinearMap := LinearMapClass.linearMap f, norm_map' := · : E →ₗᵢ[𝕜] E' }.inner_map_map),
(LinearMapClass.linearMap f |>.isometryOfInner · |>.norm_map)⟩
end
variable (𝕜)
/-- The inner product as a sesquilinear map. -/
def innerₛₗ : E →ₗ⋆[𝕜] E →ₗ[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ _ _ (fun v w => ⟪v, w⟫) inner_add_left (fun _ _ _ => inner_smul_left _ _ _)
inner_add_right fun _ _ _ => inner_smul_right _ _ _
@[simp]
theorem innerₛₗ_apply_coe (v : E) : ⇑(innerₛₗ 𝕜 v) = fun w => ⟪v, w⟫ :=
rfl
@[simp]
theorem innerₛₗ_apply (v w : E) : innerₛₗ 𝕜 v w = ⟪v, w⟫ :=
rfl
variable (F)
/-- The inner product as a bilinear map in the real case. -/
def innerₗ : F →ₗ[ℝ] F →ₗ[ℝ] ℝ := innerₛₗ ℝ
@[simp] lemma flip_innerₗ : (innerₗ F).flip = innerₗ F := by
ext v w
exact real_inner_comm v w
variable {F}
@[simp] lemma innerₗ_apply (v w : F) : innerₗ F v w = ⟪v, w⟫_ℝ := rfl
/-- The inner product as a continuous sesquilinear map. Note that `toDualMap` (resp. `toDual`)
in `InnerProductSpace.Dual` is a version of this given as a linear isometry (resp. linear
isometric equivalence). -/
def innerSL : E →L⋆[𝕜] E →L[𝕜] 𝕜 :=
LinearMap.mkContinuous₂ (innerₛₗ 𝕜) 1 fun x y => by
simp only [norm_inner_le_norm, one_mul, innerₛₗ_apply]
@[simp]
theorem innerSL_apply_coe (v : E) : ⇑(innerSL 𝕜 v) = fun w => ⟪v, w⟫ :=
rfl
@[simp]
theorem innerSL_apply (v w : E) : innerSL 𝕜 v w = ⟪v, w⟫ :=
rfl
/-- The inner product as a continuous sesquilinear map, with the two arguments flipped. -/
def innerSLFlip : E →L[𝕜] E →L⋆[𝕜] 𝕜 :=
@ContinuousLinearMap.flipₗᵢ' 𝕜 𝕜 𝕜 E E 𝕜 _ _ _ _ _ _ _ _ _ (RingHom.id 𝕜) (starRingEnd 𝕜) _ _
(innerSL 𝕜)
@[simp]
theorem innerSLFlip_apply (x y : E) : innerSLFlip 𝕜 x y = ⟪y, x⟫ :=
rfl
variable (F) in
@[simp] lemma innerSL_real_flip : (innerSL ℝ (E := F)).flip = innerSL ℝ (E := F) := by
ext v w
exact real_inner_comm _ _
variable {𝕜}
namespace ContinuousLinearMap
variable {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace 𝕜 E']
-- Note: odd and expensive build behavior is explicitly turned off using `noncomputable`
/-- Given `f : E →L[𝕜] E'`, construct the continuous sesquilinear form `fun x y ↦ ⟪x, A y⟫`, given
as a continuous linear map. -/
noncomputable def toSesqForm : (E →L[𝕜] E') →L[𝕜] E' →L⋆[𝕜] E →L[𝕜] 𝕜 :=
(ContinuousLinearMap.flipₗᵢ' E E' 𝕜 (starRingEnd 𝕜) (RingHom.id 𝕜)).toContinuousLinearEquiv ∘L
ContinuousLinearMap.compSL E E' (E' →L⋆[𝕜] 𝕜) (RingHom.id 𝕜) (RingHom.id 𝕜) (innerSLFlip 𝕜)
@[simp]
theorem toSesqForm_apply_coe (f : E →L[𝕜] E') (x : E') : toSesqForm f x = (innerSL 𝕜 x).comp f :=
rfl
theorem toSesqForm_apply_norm_le {f : E →L[𝕜] E'} {v : E'} : ‖toSesqForm f v‖ ≤ ‖f‖ * ‖v‖ := by
refine opNorm_le_bound _ (by positivity) fun x ↦ ?_
have h₁ : ‖f x‖ ≤ ‖f‖ * ‖x‖ := le_opNorm _ _
have h₂ := @norm_inner_le_norm 𝕜 E' _ _ _ v (f x)
calc
‖⟪v, f x⟫‖ ≤ ‖v‖ * ‖f x‖ := h₂
_ ≤ ‖v‖ * (‖f‖ * ‖x‖) := mul_le_mul_of_nonneg_left h₁ (norm_nonneg v)
_ = ‖f‖ * ‖v‖ * ‖x‖ := by ring
end ContinuousLinearMap
variable (𝕜)
/-- `innerSL` is an isometry. Note that the associated `LinearIsometry` is defined in
`InnerProductSpace.Dual` as `toDualMap`. -/
@[simp]
theorem innerSL_apply_norm (x : E) : ‖innerSL 𝕜 x‖ = ‖x‖ := by
refine
le_antisymm ((innerSL 𝕜 x).opNorm_le_bound (norm_nonneg _) fun y => norm_inner_le_norm _ _) ?_
rcases (norm_nonneg x).eq_or_lt' with (h | h)
· simp [h]
· refine (mul_le_mul_right h).mp ?_
calc
‖x‖ * ‖x‖ = ‖(⟪x, x⟫ : 𝕜)‖ := by
rw [← sq, inner_self_eq_norm_sq_to_K, norm_pow, norm_ofReal, abs_norm]
_ ≤ ‖innerSL 𝕜 x‖ * ‖x‖ := (innerSL 𝕜 x).le_opNorm _
lemma norm_innerSL_le : ‖innerSL 𝕜 (E := E)‖ ≤ 1 :=
ContinuousLinearMap.opNorm_le_bound _ zero_le_one (by simp)
end Norm_Seminormed
section RCLikeToReal
open scoped InnerProductSpace
variable {G : Type*}
/-- The inner product on an inner product space of dimension 2 can be evaluated in terms
of a complex-number representation of the space. -/
theorem inner_map_complex [SeminormedAddCommGroup G] [InnerProductSpace ℝ G] (f : G ≃ₗᵢ[ℝ] ℂ)
(x y : G) : ⟪x, y⟫_ℝ = (f y * conj (f x)).re := by rw [← Complex.inner, f.inner_map_map]
end RCLikeToReal
section ReApplyInnerSelf
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => inner 𝕜 x y
/-- Extract a real bilinear form from an operator `T`,
by taking the pairing `fun x ↦ re ⟪T x, x⟫`. -/
def ContinuousLinearMap.reApplyInnerSelf (T : E →L[𝕜] E) (x : E) : ℝ :=
re ⟪T x, x⟫
theorem ContinuousLinearMap.reApplyInnerSelf_apply (T : E →L[𝕜] E) (x : E) :
T.reApplyInnerSelf x = re ⟪T x, x⟫ :=
rfl
end ReApplyInnerSelf
section ReApplyInnerSelf_Seminormed
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => inner 𝕜 x y
theorem ContinuousLinearMap.reApplyInnerSelf_continuous (T : E →L[𝕜] E) :
Continuous T.reApplyInnerSelf :=
reCLM.continuous.comp <| T.continuous.inner continuous_id
theorem ContinuousLinearMap.reApplyInnerSelf_smul (T : E →L[𝕜] E) (x : E) {c : 𝕜} :
T.reApplyInnerSelf (c • x) = ‖c‖ ^ 2 * T.reApplyInnerSelf x := by
simp only [ContinuousLinearMap.map_smul, ContinuousLinearMap.reApplyInnerSelf_apply,
inner_smul_left, inner_smul_right, ← mul_assoc, mul_conj, ← ofReal_pow, ← smul_re,
Algebra.smul_def (‖c‖ ^ 2) ⟪T x, x⟫, algebraMap_eq_ofReal]
end ReApplyInnerSelf_Seminormed
|
AB.lean
|
/-
Copyright (c) 2024 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.Algebra.Category.Grp.AB
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Module.Shrink
import Mathlib.CategoryTheory.Abelian.GrothendieckCategory.Basic
/-!
# AB axioms in module categories
This file proves that the category of modules over a ring satisfies Grothendieck's axioms AB5, AB4,
and AB4*. Further, it proves that `R` is a separator in the category of modules over `R`, and
concludes that this category is Grothendieck abelian.
-/
universe u v
open CategoryTheory Limits
variable (R : Type u) [Ring R]
instance : AB5 (ModuleCat.{u} R) where
ofShape J _ _ :=
HasExactColimitsOfShape.domain_of_functor J (forget₂ (ModuleCat R) AddCommGrp)
attribute [local instance] Abelian.hasFiniteBiproducts
instance : AB4 (ModuleCat.{u} R) := AB4.of_AB5 _
instance : AB4Star (ModuleCat.{u} R) where
ofShape J :=
HasExactLimitsOfShape.domain_of_functor (Discrete J) (forget₂ (ModuleCat R) AddCommGrp.{u})
lemma ModuleCat.isSeparator [Small.{v} R] : IsSeparator (ModuleCat.of.{v} R (Shrink.{v} R)) :=
fun X Y f g h ↦ by
simp only [Set.mem_singleton_iff, forall_eq, ModuleCat.hom_ext_iff, LinearMap.ext_iff] at h
ext x
simpa [Shrink.linearEquiv, Equiv.linearEquiv] using
h (ModuleCat.ofHom ((LinearMap.toSpanSingleton R X x).comp
(Shrink.linearEquiv R R : Shrink R →ₗ[R] R))) 1
instance [Small.{v} R] : HasSeparator (ModuleCat.{v} R) where
hasSeparator := ⟨ModuleCat.of R (Shrink.{v} R), ModuleCat.isSeparator R⟩
instance : IsGrothendieckAbelian.{u} (ModuleCat.{u} R) where
|
Away.lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Localizing commutative monoids away from an element
We treat the special case of localizing away from an element in the sections
`AwayMap` and `Away`.
## Tags
localization, monoid localization, quotient monoid, congruence relation, characteristic predicate,
commutative monoid, grothendieck group
-/
assert_not_exists MonoidWithZero
open Function
section CommMonoid
variable {M : Type*} [CommMonoid M] {S : Submonoid M} {N : Type*} [CommMonoid N] {P : Type*}
[CommMonoid P]
namespace Submonoid
namespace LocalizationMap
section AwayMap
variable {g : M →* P} (hg : ∀ y : S, IsUnit (g y))
variable (x : M)
/-- Given `x : M`, the type of `CommMonoid` homomorphisms `f : M →* N` such that `N`
is isomorphic to the Localization of `M` at the Submonoid generated by `x`. -/
@[to_additive
/-- Given `x : M`, the type of `AddCommMonoid` homomorphisms `f : M →+ N` such that `N` is
isomorphic to the localization of `M` at the AddSubmonoid generated by `x`. -/]
abbrev AwayMap (N' : Type*) [CommMonoid N'] := LocalizationMap (powers x) N'
variable (F : AwayMap x N)
/-- Given `x : M` and a Localization map `F : M →* N` away from `x`, `invSelf` is `(F x)⁻¹`. -/
noncomputable def AwayMap.invSelf : N := F.mk' 1 ⟨x, mem_powers _⟩
/-- Given `x : M`, a Localization map `F : M →* N` away from `x`, and a map of `CommMonoid`s
`g : M →* P` such that `g x` is invertible, the homomorphism induced from `N` to `P` sending
`z : N` to `g y * (g x)⁻ⁿ`, where `y : M, n : ℕ` are such that `z = F y * (F x)⁻ⁿ`. -/
noncomputable def AwayMap.lift (hg : IsUnit (g x)) : N →* P :=
Submonoid.LocalizationMap.lift F fun y ↦
show IsUnit (g y.1) by
obtain ⟨n, hn⟩ := y.2
rw [← hn, g.map_pow]
exact IsUnit.pow n hg
@[simp]
theorem AwayMap.lift_eq (hg : IsUnit (g x)) (a : M) : F.lift x hg (F a) = g a :=
Submonoid.LocalizationMap.lift_eq _ _ _
@[simp]
theorem AwayMap.lift_comp (hg : IsUnit (g x)) : (F.lift x hg).comp F = g :=
Submonoid.LocalizationMap.lift_comp _ _
/-- Given `x y : M` and Localization maps `F : M →* N, G : M →* P` away from `x` and `x * y`
respectively, the homomorphism induced from `N` to `P`. -/
noncomputable def awayToAwayRight (y : M) (G : AwayMap (x * y) P) : N →* P :=
F.lift x <|
show IsUnit (G x) from
isUnit_of_mul_eq_one (G x) (G.mk' y ⟨x * y, mem_powers _⟩) <| by
rw [mul_mk'_eq_mk'_of_mul, mk'_self]
end AwayMap
end LocalizationMap
end Submonoid
namespace AddSubmonoid
namespace LocalizationMap
section AwayMap
variable {A : Type*} [AddCommMonoid A] (x : A) {B : Type*} [AddCommMonoid B] (F : AwayMap x B)
{C : Type*} [AddCommMonoid C] {g : A →+ C}
/-- Given `x : A` and a Localization map `F : A →+ B` away from `x`, `neg_self` is `- (F x)`. -/
noncomputable def AwayMap.negSelf : B :=
F.mk' 0 ⟨x, mem_multiples _⟩
/-- Given `x : A`, a localization map `F : A →+ B` away from `x`, and a map of `AddCommMonoid`s
`g : A →+ C` such that `g x` is invertible, the homomorphism induced from `B` to `C` sending
`z : B` to `g y - n • g x`, where `y : A, n : ℕ` are such that `z = F y - n • F x`. -/
noncomputable def AwayMap.lift (hg : IsAddUnit (g x)) : B →+ C :=
AddSubmonoid.LocalizationMap.lift F fun y ↦
show IsAddUnit (g y.1) by
obtain ⟨n, hn⟩ := y.2
rw [← hn]
dsimp
rw [g.map_nsmul]
exact IsAddUnit.map (nsmulAddMonoidHom n : C →+ C) hg
@[simp]
theorem AwayMap.lift_eq (hg : IsAddUnit (g x)) (a : A) : F.lift x hg (F a) = g a :=
AddSubmonoid.LocalizationMap.lift_eq _ _ _
@[simp]
theorem AwayMap.lift_comp (hg : IsAddUnit (g x)) : (F.lift x hg).comp F = g :=
AddSubmonoid.LocalizationMap.lift_comp _ _
/-- Given `x y : A` and Localization maps `F : A →+ B, G : A →+ C` away from `x` and `x + y`
respectively, the homomorphism induced from `B` to `C`. -/
noncomputable def awayToAwayRight (y : A) (G : AwayMap (x + y) C) : B →+ C :=
F.lift x <|
show IsAddUnit (G x) from
isAddUnit_of_add_eq_zero (G x) (G.mk' y ⟨x + y, mem_multiples _⟩) <| by
rw [add_mk'_eq_mk'_of_add, mk'_self]
end AwayMap
end LocalizationMap
end AddSubmonoid
namespace Localization
section Away
variable (x : M)
/-- Given `x : M`, the Localization of `M` at the Submonoid generated by `x`, as a quotient. -/
@[to_additive
/-- Given `x : M`, the Localization of `M` at the Submonoid generated by `x`, as a quotient. -/]
abbrev Away :=
Localization (Submonoid.powers x)
/-- Given `x : M`, `invSelf` is `x⁻¹` in the Localization (as a quotient type) of `M` at the
Submonoid generated by `x`. -/
@[to_additive
/-- Given `x : M`, `negSelf` is `-x` in the Localization (as a quotient type) of `M` at the
Submonoid generated by `x`. -/]
def Away.invSelf : Away x :=
mk 1 ⟨x, Submonoid.mem_powers _⟩
/-- Given `x : M`, the natural hom sending `y : M`, `M` a `CommMonoid`, to the equivalence class
of `(y, 1)` in the Localization of `M` at the Submonoid generated by `x`. -/
@[to_additive
/-- Given `x : M`, the natural hom sending `y : M`, `M` an `AddCommMonoid`, to the equivalence
class of `(y, 0)` in the Localization of `M` at the Submonoid generated by `x`. -/]
abbrev Away.monoidOf : Submonoid.LocalizationMap.AwayMap x (Away x) :=
Localization.monoidOf (Submonoid.powers x)
@[to_additive]
theorem Away.mk_eq_monoidOf_mk' : mk = (Away.monoidOf x).mk' := by
simp [Localization.mk_eq_monoidOf_mk']
/-- Given `x : M` and a Localization map `f : M →* N` away from `x`, we get an isomorphism between
the Localization of `M` at the Submonoid generated by `x` as a quotient type and `N`. -/
@[to_additive
/-- Given `x : M` and a Localization map `f : M →+ N` away from `x`, we get an isomorphism between
the Localization of `M` at the Submonoid generated by `x` as a quotient type and `N`. -/]
noncomputable def Away.mulEquivOfQuotient (f : Submonoid.LocalizationMap.AwayMap x N) :
Away x ≃* N :=
Localization.mulEquivOfQuotient f
end Away
end Localization
end CommMonoid
|
Opposite.lean
|
/-
Copyright (c) 2022 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.Equivalence
/-!
# Localization of the opposite category
If a functor `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`, it
is shown in this file that `L.op : Cᵒᵖ ⥤ Dᵒᵖ` is also a localization functor.
-/
noncomputable section
open CategoryTheory CategoryTheory.Category
namespace CategoryTheory
variable {C D : Type*} [Category C] [Category D] {L : C ⥤ D} {W : MorphismProperty C}
namespace Localization
/-- If `L : C ⥤ D` satisfies the universal property of the localisation
for `W : MorphismProperty C`, then `L.op` also does. -/
def StrictUniversalPropertyFixedTarget.op {E : Type*} [Category E]
(h : StrictUniversalPropertyFixedTarget L W Eᵒᵖ) :
StrictUniversalPropertyFixedTarget L.op W.op E where
inverts := h.inverts.op
lift F hF := (h.lift F.rightOp hF.rightOp).leftOp
fac F hF := by
convert congr_arg Functor.leftOp (h.fac F.rightOp hF.rightOp)
uniq F₁ F₂ eq := by
suffices F₁.rightOp = F₂.rightOp by
rw [← F₁.rightOp_leftOp_eq, ← F₂.rightOp_leftOp_eq, this]
have eq' := congr_arg Functor.rightOp eq
exact h.uniq _ _ eq'
instance isLocalization_op : W.Q.op.IsLocalization W.op :=
Functor.IsLocalization.mk' W.Q.op W.op (strictUniversalPropertyFixedTargetQ W _).op
(strictUniversalPropertyFixedTargetQ W _).op
end Localization
variable (L W)
variable [L.IsLocalization W]
namespace Functor
instance IsLocalization.op : L.op.IsLocalization W.op :=
IsLocalization.of_equivalence_target W.Q.op W.op L.op (Localization.equivalenceFromModel L W).op
(NatIso.op (Localization.qCompEquivalenceFromModelFunctorIso L W).symm)
instance IsLocalization.unop (L : Cᵒᵖ ⥤ Dᵒᵖ) (W : MorphismProperty Cᵒᵖ)
[L.IsLocalization W] : L.unop.IsLocalization W.unop :=
have : CatCommSq (opOpEquivalence C).functor L.op L.unop
(opOpEquivalence D).functor := ⟨Iso.refl _⟩
of_equivalences L.op W.op L.unop W.unop
(opOpEquivalence C) (opOpEquivalence D)
(fun _ _ _ hf ↦ MorphismProperty.le_isoClosure _ _ hf)
(fun _ _ _ hf ↦ by
have := Localization.inverts L W _ hf
dsimp
infer_instance)
@[simp]
lemma op_iff (L : C ⥤ D) (W : MorphismProperty C) :
L.op.IsLocalization W.op ↔ L.IsLocalization W :=
⟨fun _ ↦ inferInstanceAs (L.op.unop.IsLocalization W.op.unop),
fun _ ↦ inferInstance⟩
end Functor
namespace Localization
lemma isoOfHom_unop {X Y : Cᵒᵖ} (w : X ⟶ Y) (hw : W.op w) :
(isoOfHom L.op W.op w hw).unop = (isoOfHom L W w.unop hw) := by ext; rfl
lemma isoOfHom_op_inv {X Y : Cᵒᵖ} (w : X ⟶ Y) (hw : W.op w) :
(isoOfHom L.op W.op w hw).inv = (isoOfHom L W w.unop hw).inv.op :=
congr_arg Quiver.Hom.op (congr_arg Iso.inv (isoOfHom_unop L W w hw))
end Localization
end CategoryTheory
|
center.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import fintype bigop finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action gproduct gfunctor.
From mathcomp Require Import cyclic.
(******************************************************************************)
(* Definition of the center of a group and of external central products: *)
(* 'Z(G) == the center of the group G, i.e., 'C_G(G). *)
(* cprod_by isoZ == the finGroupType for the central product of H and K *)
(* with centers identified by the isomorphism gz on 'Z(H); *)
(* here isoZ : isom 'Z(H) 'Z(K) gz. Note that the actual *)
(* central product is [set: cprod_by isoZ]. *)
(* cpairg1 isoZ == the isomorphism from H to cprod_by isoZ, isoZ as above. *)
(* cpair1g isoZ == the isomorphism from K to cprod_by isoZ, isoZ as above. *)
(* xcprod H K == the finGroupType for the external central product of H *)
(* and K with identified centers, provided the dynamically *)
(* tested condition 'Z(H) \isog 'Z(K) holds. *)
(* ncprod H n == the finGroupType for the central product of n copies of *)
(* H with their centers identified; [set: ncprod H 0] is *)
(* isomorphic to 'Z(H). *)
(* xcprodm cf eqf == the morphism induced on cprod_by isoZ, where as above *)
(* isoZ : isom 'Z(H) 'Z(K) gz, by fH : {morphism H >-> rT} *)
(* and fK : {morphism K >-> rT}, given both *)
(* cf : fH @* H \subset 'C(fK @* K) and *)
(* eqf : {in 'Z(H), fH =1 fK \o gz}. *)
(* Following Aschbacher, we only provide external central products with *)
(* identified centers, as these are well defined provided the local center *)
(* isomorphism group of one of the subgroups is full. Nevertheless the *)
(* entire construction could be carried out under the weaker assumption that *)
(* gz is an isomorphism between subgroups of 'Z(H) and 'Z(K), and even the *)
(* uniqueness theorem holds under the weaker assumption that gz map 'Z(H) to *)
(* a characteristic subgroup of 'Z(K) not isomorphic to any other subgroup of *)
(* 'Z(K), a condition that holds for example when K is cyclic, as in the *)
(* structure theorem for p-groups of symplectic type. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Defs.
Variable gT : finGroupType.
Definition center (A : {set gT}) := 'C_A(A).
Canonical center_group (G : {group gT}) : {group gT} :=
Eval hnf in [group of center G].
End Defs.
Arguments center {gT} A%_g.
Notation "''Z' ( A )" := (center A) : group_scope.
Notation "''Z' ( H )" := (center_group H) : Group_scope.
Lemma morphim_center : GFunctor.pcontinuous (@center).
Proof. by move=> gT rT G D f; apply: morphim_subcent. Qed.
Canonical center_igFun := [igFun by fun _ _ => subsetIl _ _ & morphim_center].
Canonical center_gFun := [gFun by morphim_center].
Canonical center_pgFun := [pgFun by morphim_center].
Section Center.
Variables gT : finGroupType.
Implicit Type rT : finGroupType.
Implicit Types (x y : gT) (A B : {set gT}) (G H K D : {group gT}).
Lemma subcentP A B x : reflect (x \in A /\ centralises x B) (x \in 'C_A(B)).
Proof.
rewrite inE. case: (x \in A); last by right; case.
by apply: (iffP centP) => [|[]].
Qed.
Lemma subcent_sub A B : 'C_A(B) \subset 'N_A(B).
Proof. by rewrite setIS ?cent_sub. Qed.
Lemma subcent_norm G B : 'N_G(B) \subset 'N('C_G(B)).
Proof. by rewrite normsI ?subIset ?normG // orbC cent_norm. Qed.
Lemma subcent_normal G B : 'C_G(B) <| 'N_G(B).
Proof. by rewrite /normal subcent_sub subcent_norm. Qed.
Lemma subcent_char G H K : H \char G -> K \char G -> 'C_H(K) \char G.
Proof.
case/charP=> sHG chHG /charP[sKG chKG]; apply/charP.
split=> [|f injf Gf]; first by rewrite subIset ?sHG.
by rewrite injm_subcent ?chHG ?chKG.
Qed.
Lemma centerP A x : reflect (x \in A /\ centralises x A) (x \in 'Z(A)).
Proof. exact: subcentP. Qed.
Lemma center_sub A : 'Z(A) \subset A.
Proof. exact: subsetIl. Qed.
Lemma center1 : 'Z(1) = 1 :> {set gT}.
Proof. exact: gF1. Qed.
Lemma centerC A : {in A, centralised 'Z(A)}.
Proof. by apply/centsP; rewrite centsC subsetIr. Qed.
Lemma center_normal G : 'Z(G) <| G.
Proof. exact: gFnormal. Qed.
Lemma sub_center_normal H G : H \subset 'Z(G) -> H <| G.
Proof. by rewrite subsetI centsC /normal => /andP[-> /cents_norm]. Qed.
Lemma center_abelian G : abelian 'Z(G).
Proof. by rewrite /abelian subIset // centsC subIset // subxx orbT. Qed.
Lemma center_char G : 'Z(G) \char G.
Proof. exact: gFchar. Qed.
Lemma center_idP A : reflect ('Z(A) = A) (abelian A).
Proof. exact: setIidPl. Qed.
Lemma center_class_formula G :
#|G| = #|'Z(G)| + \sum_(xG in [set x ^: G | x in G :\: 'C(G)]) #|xG|.
Proof.
by rewrite acts_sum_card_orbit ?cardsID // astabsJ normsD ?norms_cent ?normG.
Qed.
Lemma subcent1P A x y : reflect (y \in A /\ commute x y) (y \in 'C_A[x]).
Proof.
rewrite inE; case: (y \in A); last by right; case.
by apply: (iffP cent1P) => [|[]].
Qed.
Lemma subcent1_id x G : x \in G -> x \in 'C_G[x].
Proof. by move=> Gx; rewrite inE Gx; apply/cent1P. Qed.
Lemma subcent1_sub x G : 'C_G[x] \subset G.
Proof. exact: subsetIl. Qed.
Lemma subcent1C x y G : x \in G -> y \in 'C_G[x] -> x \in 'C_G[y].
Proof. by move=> Gx /subcent1P[_ cxy]; apply/subcent1P. Qed.
Lemma subcent1_cycle_sub x G : x \in G -> <[x]> \subset 'C_G[x].
Proof. by move=> Gx; rewrite cycle_subG ?subcent1_id. Qed.
Lemma subcent1_cycle_norm x G : 'C_G[x] \subset 'N(<[x]>).
Proof. by rewrite cents_norm // cent_gen cent_set1 subsetIr. Qed.
Lemma subcent1_cycle_normal x G : x \in G -> <[x]> <| 'C_G[x].
Proof.
by move=> Gx; rewrite /normal subcent1_cycle_norm subcent1_cycle_sub.
Qed.
(* Gorenstein. 1.3.4 *)
Lemma cyclic_center_factor_abelian G : cyclic (G / 'Z(G)) -> abelian G.
Proof.
case/cyclicP=> a Ga; case: (cosetP a) => /= z Nz def_a.
have G_Zz: G :=: 'Z(G) * <[z]>.
rewrite -quotientK ?cycle_subG ?quotient_cycle //=.
by rewrite -def_a -Ga quotientGK // center_normal.
rewrite G_Zz abelianM cycle_abelian center_abelian centsC /= G_Zz.
by rewrite subIset ?centS ?orbT ?mulG_subr.
Qed.
Lemma cyclic_factor_abelian H G :
H \subset 'Z(G) -> cyclic (G / H) -> abelian G.
Proof.
move=> sHZ cycGH; apply: cyclic_center_factor_abelian.
have /andP[_ nHG]: H <| G := sub_center_normal sHZ.
have [f <-]:= homgP (homg_quotientS nHG (gFnorm _ G) sHZ).
exact: morphim_cyclic cycGH.
Qed.
Section Injm.
Variables (rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_center G : G \subset D -> f @* 'Z(G) = 'Z(f @* G).
Proof. exact: injm_subcent. Qed.
End Injm.
End Center.
Arguments center_idP {gT A}.
Lemma isog_center (aT rT : finGroupType) (G : {group aT}) (H : {group rT}) :
G \isog H -> 'Z(G) \isog 'Z(H).
Proof. exact: gFisog. Qed.
Section Product.
Variable gT : finGroupType.
Implicit Types (A B C : {set gT}) (G H K : {group gT}).
Lemma center_prod H K : K \subset 'C(H) -> 'Z(H) * 'Z(K) = 'Z(H * K).
Proof.
move=> cHK; apply/setP=> z; rewrite {3}/center centM !inE.
have cKH: H \subset 'C(K) by rewrite centsC.
apply/imset2P/and3P=> [[x y /setIP[Hx cHx] /setIP[Ky cKy] ->{z}]| []].
by rewrite imset2_f ?groupM // ?(subsetP cHK) ?(subsetP cKH).
case/imset2P=> x y Hx Ky ->{z}.
rewrite groupMr => [cHx|]; last exact: subsetP Ky.
rewrite groupMl => [cKy|]; last exact: subsetP Hx.
by exists x y; rewrite ?inE ?Hx ?Ky.
Qed.
Lemma center_cprod A B G : A \* B = G -> 'Z(A) \* 'Z(B) = 'Z(G).
Proof.
case/cprodP => [[H K -> ->] <- cHK].
rewrite cprodE ?center_prod //= subIset ?(subset_trans cHK) //.
by rewrite centS ?center_sub.
Qed.
Lemma center_bigcprod I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/cprodP: dG IHA IHB (dG) => [[H K -> ->] _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_cprod dG).
Qed.
Lemma cprod_center_id G : G \* 'Z(G) = G.
Proof. by rewrite cprodE ?subsetIr // mulGSid ?center_sub. Qed.
Lemma center_dprod A B G : A \x B = G -> 'Z(A) \x 'Z(B) = 'Z(G).
Proof.
case/dprodP=> [[H1 H2 -> ->] defG cH12 trH12].
move: defG; rewrite -cprodE // => /center_cprod/cprodP[_ /= <- cZ12].
by apply: dprodE; rewrite //= setIAC setIA -setIA trH12 (setIidPl _) ?sub1G.
Qed.
Lemma center_bigdprod I r P (F: I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/dprodP: dG IHA IHB (dG) => [[H K -> ->] _ _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_dprod dG).
Qed.
Lemma Aut_cprod_full G H K :
H \* K = G -> 'Z(H) = 'Z(K) ->
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G).
Proof.
move=> defG eqZHK; have [_ defHK cHK] := cprodP defG.
have defZ: 'Z(G) = 'Z(H) by rewrite -defHK -center_prod // eqZHK mulGid.
have ziHK: H :&: K = 'Z(K).
by apply/eqP; rewrite eqEsubset subsetI -{1 2}eqZHK !center_sub setIS.
have AutZP := Aut_sub_fullP (@center_sub gT _).
move/AutZP=> AutZHfull /AutZP AutZKfull; apply/AutZP=> g injg gZ.
have [gH [def_gH ker_gH _ im_gH]] := domP g defZ.
have [gK [def_gK ker_gK _ im_gK]] := domP g (etrans defZ eqZHK).
have [injgH injgK]: 'injm gH /\ 'injm gK by rewrite ker_gH ker_gK.
have [gHH gKK]: gH @* 'Z(H) = 'Z(H) /\ gK @* 'Z(K) = 'Z(K).
by rewrite im_gH im_gK -eqZHK -defZ.
have [|fH [injfH im_fH fHZ]] := AutZHfull gH injgH.
by rewrite im_gH /= -defZ.
have [|fK [injfK im_fK fKZ]] := AutZKfull gK injgK.
by rewrite im_gK /= -eqZHK -defZ.
have cfHK: fK @* K \subset 'C(fH @* H) by rewrite im_fH im_fK.
have eq_fHK: {in H :&: K, fH =1 fK}.
by move=> z; rewrite ziHK => Zz; rewrite fHZ ?fKZ /= ?eqZHK // def_gH def_gK.
exists (cprodm_morphism defG cfHK eq_fHK).
rewrite injm_cprodm injfH injfK im_cprodm im_fH im_fK defHK.
rewrite -morphimIdom ziHK -eqZHK injm_center // im_fH eqxx.
split=> //= z; rewrite {1}defZ => Zz; have [Hz _] := setIP Zz.
by rewrite cprodmEl // fHZ // def_gH.
Qed.
End Product.
Section CprodBy.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}) (gz : {morphism 'Z(H) >-> gTK}).
Definition ker_cprod_by of isom 'Z(H) 'Z(K) gz :=
[set xy | let: (x, y) := xy in (x \in 'Z(H)) && (y == (gz x)^-1)].
Hypothesis isoZ : isom 'Z(H) 'Z(K) gz.
Let kerHK := ker_cprod_by isoZ.
Let injgz : 'injm gz. Proof. by case/isomP: isoZ. Qed.
Let gzZ : gz @* 'Z(H) = 'Z(K). Proof. by case/isomP: isoZ. Qed.
Let gzZchar : gz @* 'Z(H) \char 'Z(K). Proof. by rewrite gzZ. Qed.
Let sgzZZ : gz @* 'Z(H) \subset 'Z(K) := char_sub gzZchar.
Let sZH := center_sub H.
Let sZK := center_sub K.
Let sgzZG : gz @* 'Z(H) \subset K := subset_trans sgzZZ sZK.
Lemma ker_cprod_by_is_group : group_set kerHK.
Proof.
apply/group_setP; rewrite inE /= group1 morph1 invg1 /=.
split=> // [[x1 y1] [x2 y2]].
rewrite inE /= => /andP[Zx1 /eqP->]; have [_ cGx1] := setIP Zx1.
rewrite inE /= => /andP[Zx2 /eqP->]; have [Gx2 _] := setIP Zx2.
by rewrite inE /= groupM //= -invMg (centP cGx1) // morphM.
Qed.
Canonical ker_cprod_by_group := Group ker_cprod_by_is_group.
Lemma ker_cprod_by_central : kerHK \subset 'Z(setX H K).
Proof.
rewrite -(center_dprod (setX_dprod H K)) -morphim_pairg1 -morphim_pair1g.
rewrite -!injm_center ?subsetT ?injm_pair1g ?injm_pairg1 //=.
rewrite morphim_pairg1 morphim_pair1g setX_dprod.
apply/subsetP=> [[x y]] /[1!inE] /andP[Zx /eqP->].
by rewrite inE /= Zx groupV (subsetP sgzZZ) ?mem_morphim.
Qed.
Fact cprod_by_key : unit. Proof. by []. Qed.
Definition cprod_by_def : finGroupType := subg_of (setX H K / kerHK).
Definition cprod_by := locked_with cprod_by_key cprod_by_def.
Local Notation C := [set: FinGroup.sort cprod_by].
(*FIXME : Check if we need arg_sort instead of sort*)
Definition in_cprod : gTH * gTK -> cprod_by :=
let: tt as k := cprod_by_key return _ -> locked_with k cprod_by_def in
subg _ \o coset kerHK.
Lemma in_cprodM : {in setX H K &, {morph in_cprod : u v / u * v}}.
Proof.
rewrite /in_cprod /cprod_by; case: cprod_by_key => /= u v Gu Gv.
have nkerHKG := normal_norm (sub_center_normal ker_cprod_by_central).
by rewrite -!morphM ?mem_quotient // (subsetP nkerHKG).
Qed.
Canonical in_cprod_morphism := Morphism in_cprodM.
Lemma ker_in_cprod : 'ker in_cprod = kerHK.
Proof.
transitivity ('ker (subg [group of setX H K / kerHK] \o coset kerHK)).
rewrite /ker /morphpre /= /in_cprod /cprod_by; case: cprod_by_key => /=.
by rewrite ['N(_) :&: _]quotientGK ?sub_center_normal ?ker_cprod_by_central.
by rewrite ker_comp ker_subg -kerE ker_coset.
Qed.
Lemma cpairg1_dom : H \subset 'dom (in_cprod \o @pairg1 gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pairg1 setXS ?sub1G. Qed.
Lemma cpair1g_dom : K \subset 'dom (in_cprod \o @pair1g gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pair1g setXS ?sub1G. Qed.
Definition cpairg1 := tag (restrmP _ cpairg1_dom).
Definition cpair1g := tag (restrmP _ cpair1g_dom).
Local Notation CH := (mfun cpairg1 @* gval H).
Local Notation CK := (mfun cpair1g @* gval K).
Lemma injm_cpairg1 : 'injm cpairg1.
Proof.
rewrite /cpairg1; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> x; rewrite !inE /=.
by case/and3P=> _ Zx; rewrite eq_sym (inv_eq invgK) invg1 morph_injm_eq1.
Qed.
Let injH := injm_cpairg1.
Lemma injm_cpair1g : 'injm cpair1g.
Proof.
rewrite /cpair1g; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> y; rewrite !inE /= morph1 invg1.
by case/and3P.
Qed.
Let injK := injm_cpair1g.
Lemma im_cpair_cent : CK \subset 'C(CH).
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp morphim_cents // morphim_pair1g morphim_pairg1.
by case/dprodP: (setX_dprod H K).
Qed.
Hint Resolve im_cpair_cent : core.
Lemma im_cpair : CH * CK = C.
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp -morphimMl morphim_pairg1 ?setXS ?sub1G //.
rewrite morphim_pair1g setX_prod morphimEdom /= /in_cprod /cprod_by.
by case: cprod_by_key; rewrite /= imset_comp imset_coset -morphimEdom im_subg.
Qed.
Lemma im_cpair_cprod : CH \* CK = C. Proof. by rewrite cprodE ?im_cpair. Qed.
Lemma eq_cpairZ : {in 'Z(H), cpairg1 =1 cpair1g \o gz}.
Proof.
rewrite /cpairg1 /cpair1g => z1 Zz1; set z2 := gz z1.
have Zz2: z2 \in 'Z(K) by rewrite (subsetP sgzZZ) ?mem_morphim.
have [[Gz1 _] [/= Gz2 _]]:= (setIP Zz1, setIP Zz2).
do 2![case: restrmP => f /= [df _ _ _]; rewrite {f}df].
apply/rcoset_kerP; rewrite ?inE ?group1 ?andbT //.
by rewrite ker_in_cprod mem_rcoset inE /= invg1 mulg1 mul1g Zz1 /=.
Qed.
Lemma setI_im_cpair : CH :&: CK = 'Z(CH).
Proof.
apply/eqP; rewrite eqEsubset setIS //=.
rewrite subsetI center_sub -injm_center //.
rewrite (eq_in_morphim _ eq_cpairZ); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
Lemma cpair1g_center : cpair1g @* 'Z(K) = 'Z(C).
Proof.
case/cprodP: (center_cprod im_cpair_cprod) => _ <- _.
by rewrite injm_center // -setI_im_cpair mulSGid //= setIC setIS 1?centsC.
Qed.
(* Uses gzZ. *)
Lemma cpair_center_id : 'Z(CH) = 'Z(CK).
Proof.
rewrite -!injm_center // -gzZ -morphim_comp; apply: eq_in_morphim eq_cpairZ.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
(* Uses gzZ. *)
Lemma cpairg1_center : cpairg1 @* 'Z(H) = 'Z(C).
Proof. by rewrite -cpair1g_center !injm_center // cpair_center_id. Qed.
Section ExtCprodm.
Variable rT : finGroupType.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Hypothesis eq_fHK : {in 'Z(H), fH =1 fK \o gz}.
Let gH := ifactm fH injm_cpairg1.
Let gK := ifactm fK injm_cpair1g.
Lemma xcprodm_cent : gK @* CK \subset 'C(gH @* CH).
Proof. by rewrite !im_ifactm. Qed.
Lemma xcprodmI : {in CH :&: CK, gH =1 gK}.
Proof.
rewrite setI_im_cpair -injm_center // => fHx; case/morphimP=> x Gx Zx ->{fHx}.
by rewrite {2}eq_cpairZ //= ?ifactmE ?eq_fHK //= (subsetP sgzZG) ?mem_morphim.
Qed.
Definition xcprodm := cprodm im_cpair_cprod xcprodm_cent xcprodmI.
Canonical xcprod_morphism := [morphism of xcprodm].
Lemma xcprodmEl : {in H, forall x, xcprodm (cpairg1 x) = fH x}.
Proof. by move=> x Hx; rewrite /xcprodm cprodmEl ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmEr : {in K, forall y, xcprodm (cpair1g y) = fK y}.
Proof. by move=> y Ky; rewrite /xcprodm cprodmEr ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmE :
{in H & K, forall x y, xcprodm (cpairg1 x * cpair1g y) = fH x * fK y}.
Proof.
by move=> x y Hx Ky; rewrite /xcprodm cprodmE ?mem_morphim ?ifactmE.
Qed.
Lemma im_xcprodm : xcprodm @* C = fH @* H * fK @* K.
Proof. by rewrite -im_cpair morphim_cprodm // !im_ifactm. Qed.
Lemma im_xcprodml A : xcprodm @* (cpairg1 @* A) = fH @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodml ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma im_xcprodmr A : xcprodm @* (cpair1g @* A) = fK @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodmr ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma injm_xcprodm : 'injm xcprodm = 'injm fH && 'injm fK.
Proof.
rewrite injm_cprodm !ker_ifactm !subG1 !morphim_injm_eq1 ?subsetIl // -!subG1.
apply: andb_id2l => /= injfH; apply: andb_idr => _.
rewrite !im_ifactm // -(morphimIdom gH) setI_im_cpair -injm_center //.
rewrite morphim_ifactm // eqEsubset subsetI morphimS //=.
rewrite {1}injm_center // setIS //=.
rewrite (eq_in_morphim _ eq_fHK); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
End ExtCprodm.
(* Uses gzZchar. *)
Lemma Aut_cprod_by_full :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut C) 'Z(C) \isog Aut 'Z(C).
Proof.
move=> AutZinH AutZinK.
have Cfull:= Aut_cprod_full im_cpair_cprod cpair_center_id.
by rewrite Cfull // -injm_center // injm_Aut_full ?center_sub.
Qed.
Section Isomorphism.
Let gzZ_lone (Y : {group gTK}) :
Y \subset 'Z(K) -> gz @* 'Z(H) \isog Y -> gz @* 'Z(H) = Y.
Proof.
move=> sYZ isoY; apply/eqP.
by rewrite eq_sym eqEcard (card_isog isoY) gzZ sYZ /=.
Qed.
Variables (rT : finGroupType) (GH GK G : {group rT}).
Hypotheses (defG : GH \* GK = G) (ziGHK : GH :&: GK = 'Z(GH)).
Hypothesis AutZHfull : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H).
Hypotheses (isoGH : GH \isog H) (isoGK : GK \isog K).
(* Uses gzZ_lone *)
Lemma cprod_by_uniq :
exists f : {morphism G >-> cprod_by},
[/\ isom G C f, f @* GH = CH & f @* GK = CK].
Proof.
have [_ defGHK cGKH] := cprodP defG.
have AutZinH := Aut_sub_fullP sZH AutZHfull.
have [fH injfH defGH]:= isogP (isog_symr isoGH).
have [fK injfK defGK]:= isogP (isog_symr isoGK).
have sfHZfK: fH @* 'Z(H) \subset fK @* K.
by rewrite injm_center //= defGH defGK -ziGHK subsetIr.
have gzZ_id: gz @* 'Z(H) = invm injfK @* (fH @* 'Z(H)).
apply: gzZ_lone => /=.
rewrite injm_center // defGH -ziGHK sub_morphim_pre /= ?defGK ?subsetIr //.
by rewrite setIC morphpre_invm injm_center // defGK setIS 1?centsC.
rewrite -morphim_comp.
apply: isog_trans (sub_isog _ _); first by rewrite isog_sym sub_isog.
by rewrite -sub_morphim_pre.
by rewrite !injm_comp ?injm_invm.
have: 'dom (invm injfH \o fK \o gz) = 'Z(H).
rewrite /dom /= -(morphpreIdom gz); apply/setIidPl.
by rewrite -2?sub_morphim_pre // gzZ_id morphim_invmE morphpreK ?morphimS.
case/domP=> gzH [def_gzH ker_gzH _ im_gzH].
have{ker_gzH} injgzH: 'injm gzH by rewrite ker_gzH !injm_comp ?injm_invm.
have{AutZinH} [|gH [injgH gH_H def_gH]] := AutZinH _ injgzH.
by rewrite im_gzH !morphim_comp /= gzZ_id !morphim_invmE morphpreK ?injmK.
have: 'dom (fH \o gH) = H by rewrite /dom /= -{3}gH_H injmK.
case/domP=> gfH [def_gfH ker_gfH _ im_gfH].
have{im_gfH} gfH_H: gfH @* H = GH by rewrite im_gfH morphim_comp gH_H.
have cgfHfK: fK @* K \subset 'C(gfH @* H) by rewrite gfH_H defGK.
have eq_gfHK: {in 'Z(H), gfH =1 fK \o gz}.
move=> z Zz; rewrite def_gfH /= def_gH //= def_gzH /= invmK //.
have {Zz}: gz z \in gz @* 'Z(H) by rewrite mem_morphim.
rewrite gzZ_id morphim_invmE; case/morphpreP=> _.
exact: (subsetP (morphimS _ _)).
pose f := xcprodm cgfHfK eq_gfHK.
have injf: 'injm f by rewrite injm_xcprodm ker_gfH injm_comp.
have fCH: f @* CH = GH by rewrite im_xcprodml gfH_H.
have fCK: f @* CK = GK by rewrite im_xcprodmr defGK.
have fC: f @* C = G by rewrite im_xcprodm gfH_H defGK defGHK.
have [f' [_ ker_f' _ im_f']] := domP (invm_morphism injf) fC.
exists f'; rewrite -fCH -fCK !{1}im_f' !{1}morphim_invm ?subsetT //.
by split=> //; apply/isomP; rewrite ker_f' injm_invm im_f' -fC im_invm.
Qed.
Lemma isog_cprod_by : G \isog C.
Proof. by have [f [isoG _ _]] := cprod_by_uniq; apply: isom_isog isoG. Qed.
End Isomorphism.
End CprodBy.
Section ExtCprod.
Import finfun.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}).
Let gt_ b := if b then gTK else gTH.
Local Notation isob := ('Z(H) \isog 'Z(K)) (only parsing).
Let G_ b := if b as b' return {group gt_ b'} then K else H.
Lemma xcprod_subproof :
{gz : {morphism 'Z(H) >-> gt_ isob} | isom 'Z(H) 'Z(G_ isob) gz}.
Proof.
case: (pickP [pred f : {ffun _} | misom 'Z(H) 'Z(K) f]) => [f isoZ | no_f].
rewrite (misom_isog isoZ); case/andP: isoZ => fM isoZ.
by exists [morphism of morphm fM].
move/pred0P: no_f => not_isoZ; rewrite [isob](congr1 negb not_isoZ).
by exists (idm_morphism _); apply/isomP; rewrite injm_idm im_idm.
Qed.
Definition xcprod := cprod_by (svalP xcprod_subproof).
Inductive xcprod_spec : finGroupType -> Prop :=
XcprodSpec gz isoZ : xcprod_spec (@cprod_by gTH gTK H K gz isoZ).
Lemma xcprodP : 'Z(H) \isog 'Z(K) -> xcprod_spec xcprod.
Proof. by rewrite /xcprod => isoZ; move: xcprod_subproof; rewrite isoZ. Qed.
Lemma isog_xcprod (rT : finGroupType) (GH GK G : {group rT}) :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
GH \isog H -> GK \isog K -> GH \* GK = G -> 'Z(GH) = 'Z(GK) ->
G \isog [set: xcprod].
Proof.
move=> AutZinH isoGH isoGK defG eqZGHK; have [_ _ cGHK] := cprodP defG.
have [|gz isoZ] := xcprodP.
have [[fH injfH <-] [fK injfK <-]] := (isogP isoGH, isogP isoGK).
rewrite -!injm_center -?(isog_transl _ (sub_isog _ _)) ?center_sub //=.
by rewrite eqZGHK sub_isog ?center_sub.
rewrite (isog_cprod_by _ defG) //.
by apply/eqP; rewrite eqEsubset setIS // subsetI {2}eqZGHK !center_sub.
Qed.
End ExtCprod.
Section IterCprod.
Variables (gT : finGroupType) (G : {group gT}).
Fixpoint ncprod_def n : finGroupType :=
if n is n'.+1 then xcprod G [set: ncprod_def n']
else subg_of 'Z(G).
Fact ncprod_key : unit. Proof. by []. Qed.
Definition ncprod := locked_with ncprod_key ncprod_def.
Local Notation G_ n := [set: gsort (ncprod n)].
Lemma ncprod0 : G_ 0 \isog 'Z(G).
Proof. by rewrite [ncprod]unlock isog_sym isog_subg. Qed.
Lemma center_ncprod0 : 'Z(G_ 0) = G_ 0.
Proof. by apply: center_idP; rewrite (isog_abelian ncprod0) center_abelian. Qed.
Lemma center_ncprod n : 'Z(G_ n) \isog 'Z(G).
Proof.
elim: n => [|n]; first by rewrite center_ncprod0 ncprod0.
rewrite [ncprod]unlock=> /isog_symr/xcprodP[gz isoZ] /=.
by rewrite -cpairg1_center isog_sym sub_isog ?center_sub ?injm_cpairg1.
Qed.
Lemma ncprodS n : xcprod_spec G [set: ncprod n] (ncprod n.+1).
Proof.
by have:= xcprodP (isog_symr (center_ncprod n)); rewrite [ncprod]unlock.
Qed.
Lemma ncprod1 : G_ 1 \isog G.
Proof.
case: ncprodS => gz isoZ; rewrite isog_sym /= -im_cpair.
rewrite mulGSid /=; first by rewrite sub_isog ?injm_cpairg1.
rewrite -{3}center_ncprod0 injm_center ?injm_cpair1g //.
by rewrite -cpair_center_id center_sub.
Qed.
Lemma Aut_ncprod_full n :
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G) ->
Aut_in (Aut (G_ n)) 'Z(G_ n) \isog Aut 'Z(G_ n).
Proof.
move=> AutZinG; elim: n => [|n IHn].
by rewrite center_ncprod0; apply/Aut_sub_fullP=> // g injg gG0; exists g.
by case: ncprodS => gz isoZ; apply: Aut_cprod_by_full.
Qed.
End IterCprod.
|
Injective.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Algebra.Module.Shrink
import Mathlib.LinearAlgebra.LinearPMap
import Mathlib.Logic.Small.Basic
import Mathlib.RingTheory.Ideal.Defs
/-!
# Injective modules
## Main definitions
* `Module.Injective`: an `R`-module `Q` is injective if and only if every injective `R`-linear
map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there
is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f`
```
X --- f ---> Y
|
| g
v
Q
```
* `Module.Baer`: an `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an
`Ideal R` extends to an `R`-linear map `R ⟶ Q`
## Main statements
* `Module.Baer.injective`: an `R`-module is injective if it is Baer.
-/
assert_not_exists ModuleCat
noncomputable section
universe u v v'
variable (R : Type u) [Ring R] (Q : Type v) [AddCommGroup Q] [Module R Q]
/--
An `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear
map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map
`h : Y ⟶ Q` such that `g = h ∘ f`
```
X --- f ---> Y
|
| g
v
Q
```
-/
@[mk_iff] class Module.Injective : Prop where
out : ∀ ⦃X Y : Type v⦄ [AddCommGroup X] [AddCommGroup Y] [Module R X] [Module R Y]
(f : X →ₗ[R] Y) (_ : Function.Injective f) (g : X →ₗ[R] Q),
∃ h : Y →ₗ[R] Q, ∀ x, h (f x) = g x
/-- An `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to
an `R`-linear map `R ⟶ Q` -/
def Module.Baer : Prop :=
∀ (I : Ideal R) (g : I →ₗ[R] Q), ∃ g' : R →ₗ[R] Q, ∀ (x : R) (mem : x ∈ I), g' x = g ⟨x, mem⟩
namespace Module.Baer
variable {R Q} {M N : Type*} [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] (i : M →ₗ[R] N) (f : M →ₗ[R] Q)
lemma of_equiv (e : Q ≃ₗ[R] M) (h : Module.Baer R Q) : Module.Baer R M := fun I g ↦
have ⟨g', h'⟩ := h I (e.symm ∘ₗ g)
⟨e ∘ₗ g', by simpa [LinearEquiv.eq_symm_apply] using h'⟩
lemma congr (e : Q ≃ₗ[R] M) : Module.Baer R Q ↔ Module.Baer R M := ⟨of_equiv e, of_equiv e.symm⟩
/-- If we view `M` as a submodule of `N` via the injective linear map `i : M ↪ N`, then a submodule
between `M` and `N` is a submodule `N'` of `N`. To prove Baer's criterion, we need to consider
pairs of `(N', f')` such that `M ≤ N' ≤ N` and `f'` extends `f`. -/
structure ExtensionOf extends LinearPMap R N Q where
le : LinearMap.range i ≤ domain
is_extension : ∀ m : M, f m = toLinearPMap ⟨i m, le ⟨m, rfl⟩⟩
section Ext
variable {i f}
@[ext (iff := false)]
theorem ExtensionOf.ext {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain)
(to_fun_eq : ∀ ⦃x : N⦄ ⦃ha : x ∈ a.domain⦄ ⦃hb : x ∈ b.domain⦄,
a.toLinearPMap ⟨x, ha⟩ = b.toLinearPMap ⟨x, hb⟩) :
a = b := by
rcases a with ⟨a, a_le, e1⟩
rcases b with ⟨b, b_le, e2⟩
congr
exact LinearPMap.ext domain_eq to_fun_eq
/-- A dependent version of `ExtensionOf.ext` -/
theorem ExtensionOf.dExt {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain)
(to_fun_eq :
∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y) :
a = b :=
ext domain_eq fun _ _ _ ↦ to_fun_eq rfl
theorem ExtensionOf.dExt_iff {a b : ExtensionOf i f} :
a = b ↔ ∃ _ : a.domain = b.domain, ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄,
(x : N) = y → a.toLinearPMap x = b.toLinearPMap y :=
⟨fun r => r ▸ ⟨rfl, fun _ _ h => congr_arg a.toFun <| mod_cast h⟩, fun ⟨h1, h2⟩ =>
ExtensionOf.dExt h1 h2⟩
end Ext
instance : Min (ExtensionOf i f) where
min X1 X2 :=
{ X1.toLinearPMap ⊓ X2.toLinearPMap with
le := fun x hx =>
(by
rcases hx with ⟨x, rfl⟩
refine ⟨X1.le (Set.mem_range_self _), X2.le (Set.mem_range_self _), ?_⟩
rw [← X1.is_extension x, ← X2.is_extension x] :
x ∈ X1.toLinearPMap.eqLocus X2.toLinearPMap)
is_extension := fun _ => X1.is_extension _ }
instance : SemilatticeInf (ExtensionOf i f) :=
Function.Injective.semilatticeInf ExtensionOf.toLinearPMap
(fun X Y h ↦
ExtensionOf.ext (by rw [h]) <| by
rw [h]
intros
rfl)
fun X Y ↦ LinearPMap.ext rfl fun x y h => by congr
variable {i f}
theorem chain_linearPMap_of_chain_extensionOf {c : Set (ExtensionOf i f)}
(hchain : IsChain (· ≤ ·) c) :
IsChain (· ≤ ·) <| (fun x : ExtensionOf i f => x.toLinearPMap) '' c := by
rintro _ ⟨a, a_mem, rfl⟩ _ ⟨b, b_mem, rfl⟩ neq
exact hchain a_mem b_mem (ne_of_apply_ne _ neq)
/-- The maximal element of every nonempty chain of `extension_of i f`. -/
def ExtensionOf.max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c)
(hnonempty : c.Nonempty) : ExtensionOf i f :=
{ LinearPMap.sSup _
(IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) with
le := by
refine le_trans hnonempty.some.le <|
(LinearPMap.le_sSup _ <|
(Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩).1
is_extension := fun m => by
refine Eq.trans (hnonempty.some.is_extension m) ?_
symm
generalize_proofs _ _ h1
exact
LinearPMap.sSup_apply (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain)
((Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩) ⟨i m, h1⟩ }
theorem ExtensionOf.le_max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c)
(hnonempty : c.Nonempty) (a : ExtensionOf i f) (ha : a ∈ c) :
a ≤ ExtensionOf.max hchain hnonempty :=
LinearPMap.le_sSup (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) <|
(Set.mem_image _ _ _).mpr ⟨a, ha, rfl⟩
variable (i f) [Fact <| Function.Injective i]
instance ExtensionOf.inhabited : Inhabited (ExtensionOf i f) where
default :=
{ domain := LinearMap.range i
toFun :=
{ toFun := fun x => f x.2.choose
map_add' := fun x y => by
have eq1 : _ + _ = (x + y).1 := congr_arg₂ (· + ·) x.2.choose_spec y.2.choose_spec
rw [← map_add, ← (x + y).2.choose_spec] at eq1
dsimp
rw [← Fact.out (p := Function.Injective i) eq1, map_add]
map_smul' := fun r x => by
have eq1 : r • _ = (r • x).1 := congr_arg (r • ·) x.2.choose_spec
rw [← LinearMap.map_smul, ← (r • x).2.choose_spec] at eq1
dsimp
rw [← Fact.out (p := Function.Injective i) eq1, LinearMap.map_smul] }
le := le_refl _
is_extension := fun m => by
simp only [LinearPMap.mk_apply, LinearMap.coe_mk]
dsimp
apply congrArg
exact Fact.out (p := Function.Injective i)
(⟨i m, ⟨_, rfl⟩⟩ : LinearMap.range i).2.choose_spec.symm }
/-- Since every nonempty chain has a maximal element, by Zorn's lemma, there is a maximal
`extension_of i f`. -/
def extensionOfMax : ExtensionOf i f :=
(@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty =>
⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose
theorem extensionOfMax_is_max :
∀ (a : ExtensionOf i f), extensionOfMax i f ≤ a → a = extensionOfMax i f :=
fun _ ↦ (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty =>
⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose_spec.eq_of_ge
-- Porting note: helper function. Lean looks for an instance of `Sup (Type u)` when the
-- right hand side is substituted in directly
abbrev supExtensionOfMaxSingleton (y : N) : Submodule R N :=
(extensionOfMax i f).domain ⊔ (Submodule.span R {y})
variable {f}
private theorem extensionOfMax_adjoin.aux1 {y : N} (x : supExtensionOfMaxSingleton i f y) :
∃ (a : (extensionOfMax i f).domain) (b : R), x.1 = a.1 + b • y := by
have mem1 : x.1 ∈ (_ : Set _) := x.2
rw [Submodule.coe_sup] at mem1
rcases mem1 with ⟨a, a_mem, b, b_mem : b ∈ (Submodule.span R _ : Submodule R N), eq1⟩
rw [Submodule.mem_span_singleton] at b_mem
rcases b_mem with ⟨z, eq2⟩
exact ⟨⟨a, a_mem⟩, z, by rw [← eq1, ← eq2]⟩
/-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `fst` pick an arbitrary such `m`. -/
def ExtensionOfMaxAdjoin.fst {y : N} (x : supExtensionOfMaxSingleton i f y) :
(extensionOfMax i f).domain :=
(extensionOfMax_adjoin.aux1 i x).choose
/-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `snd` pick an arbitrary such `r`. -/
def ExtensionOfMaxAdjoin.snd {y : N} (x : supExtensionOfMaxSingleton i f y) : R :=
(extensionOfMax_adjoin.aux1 i x).choose_spec.choose
theorem ExtensionOfMaxAdjoin.eqn {y : N} (x : supExtensionOfMaxSingleton i f y) :
↑x = ↑(ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.snd i x • y :=
(extensionOfMax_adjoin.aux1 i x).choose_spec.choose_spec
variable (f)
-- TODO: refactor to use colon ideals?
/-- The ideal `I = {r | r • y ∈ N}` -/
def ExtensionOfMaxAdjoin.ideal (y : N) : Ideal R :=
(extensionOfMax i f).domain.comap ((LinearMap.id : R →ₗ[R] R).smulRight y)
/-- A linear map `I ⟶ Q` by `x ↦ f' (x • y)` where `f'` is the maximal extension -/
def ExtensionOfMaxAdjoin.idealTo (y : N) : ExtensionOfMaxAdjoin.ideal i f y →ₗ[R] Q where
toFun (z : { x // x ∈ ideal i f y }) := (extensionOfMax i f).toLinearPMap ⟨(↑z : R) • y, z.prop⟩
map_add' (z1 z2 : { x // x ∈ ideal i f y }) := by
simp_rw [← (extensionOfMax i f).toLinearPMap.map_add]
congr
apply add_smul
map_smul' z1 (z2 : {x // x ∈ ideal i f y}) := by
simp_rw [← (extensionOfMax i f).toLinearPMap.map_smul]
congr 2
apply mul_smul
/-- Since we assumed `Q` being Baer, the linear map `x ↦ f' (x • y) : I ⟶ Q` extends to `R ⟶ Q`,
call this extended map `φ` -/
def ExtensionOfMaxAdjoin.extendIdealTo (h : Module.Baer R Q) (y : N) : R →ₗ[R] Q :=
(h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose
theorem ExtensionOfMaxAdjoin.extendIdealTo_is_extension (h : Module.Baer R Q) (y : N) :
∀ (x : R) (mem : x ∈ ExtensionOfMaxAdjoin.ideal i f y),
ExtensionOfMaxAdjoin.extendIdealTo i f h y x = ExtensionOfMaxAdjoin.idealTo i f y ⟨x, mem⟩ :=
(h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose_spec
theorem ExtensionOfMaxAdjoin.extendIdealTo_wd' (h : Module.Baer R Q) {y : N} (r : R)
(eq1 : r • y = 0) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = 0 := by
have : r ∈ ideal i f y := by
change (r • y) ∈ (extensionOfMax i f).toLinearPMap.domain
rw [eq1]
apply Submodule.zero_mem _
rw [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h y r this]
dsimp [ExtensionOfMaxAdjoin.idealTo]
simp only [eq1, ← ZeroMemClass.zero_def, (extensionOfMax i f).toLinearPMap.map_zero]
theorem ExtensionOfMaxAdjoin.extendIdealTo_wd (h : Module.Baer R Q) {y : N} (r r' : R)
(eq1 : r • y = r' • y) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r =
ExtensionOfMaxAdjoin.extendIdealTo i f h y r' := by
rw [← sub_eq_zero, ← map_sub]
convert ExtensionOfMaxAdjoin.extendIdealTo_wd' i f h (r - r') _
rw [sub_smul, sub_eq_zero, eq1]
theorem ExtensionOfMaxAdjoin.extendIdealTo_eq (h : Module.Baer R Q) {y : N} (r : R)
(hr : r • y ∈ (extensionOfMax i f).domain) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r =
(extensionOfMax i f).toLinearPMap ⟨r • y, hr⟩ := by
simp only [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h _ _ hr,
ExtensionOfMaxAdjoin.idealTo, LinearMap.coe_mk, AddHom.coe_mk]
/-- We can finally define a linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r`
-/
def ExtensionOfMaxAdjoin.extensionToFun (h : Module.Baer R Q) {y : N} :
supExtensionOfMaxSingleton i f y → Q := fun x =>
(extensionOfMax i f).toLinearPMap (ExtensionOfMaxAdjoin.fst i x) +
ExtensionOfMaxAdjoin.extendIdealTo i f h y (ExtensionOfMaxAdjoin.snd i x)
theorem ExtensionOfMaxAdjoin.extensionToFun_wd (h : Module.Baer R Q) {y : N}
(x : supExtensionOfMaxSingleton i f y) (a : (extensionOfMax i f).domain)
(r : R) (eq1 : ↑x = ↑a + r • y) :
ExtensionOfMaxAdjoin.extensionToFun i f h x =
(extensionOfMax i f).toLinearPMap a + ExtensionOfMaxAdjoin.extendIdealTo i f h y r := by
obtain ⟨a, ha⟩ := a
have eq2 :
(ExtensionOfMaxAdjoin.fst i x - a : N) = (r - ExtensionOfMaxAdjoin.snd i x) • y := by
change x = a + r • y at eq1
rwa [ExtensionOfMaxAdjoin.eqn, ← sub_eq_zero, ← sub_sub_sub_eq, sub_eq_zero, ← sub_smul]
at eq1
have eq3 :=
ExtensionOfMaxAdjoin.extendIdealTo_eq i f h (r - ExtensionOfMaxAdjoin.snd i x)
(by rw [← eq2]; exact Submodule.sub_mem _ (ExtensionOfMaxAdjoin.fst i x).2 ha)
simp only [map_sub, sub_smul, sub_eq_iff_eq_add] at eq3
unfold ExtensionOfMaxAdjoin.extensionToFun
rw [eq3, ← add_assoc, ← (extensionOfMax i f).toLinearPMap.map_add, AddMemClass.mk_add_mk]
congr
ext
dsimp
rw [Subtype.coe_mk, add_sub, ← eq1]
exact eq_sub_of_add_eq (ExtensionOfMaxAdjoin.eqn i x).symm
/-- The linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` is an extension of `f` -/
def extensionOfMaxAdjoin (h : Module.Baer R Q) (y : N) : ExtensionOf i f where
domain := supExtensionOfMaxSingleton i f y -- (extensionOfMax i f).domain ⊔ Submodule.span R {y}
le := le_trans (extensionOfMax i f).le le_sup_left
toFun :=
{ toFun := ExtensionOfMaxAdjoin.extensionToFun i f h
map_add' := fun a b => by
have eq1 :
↑a + ↑b =
↑(ExtensionOfMaxAdjoin.fst i a + ExtensionOfMaxAdjoin.fst i b) +
(ExtensionOfMaxAdjoin.snd i a + ExtensionOfMaxAdjoin.snd i b) • y := by
rw [ExtensionOfMaxAdjoin.eqn, ExtensionOfMaxAdjoin.eqn, add_smul, Submodule.coe_add]
ac_rfl
rw [ExtensionOfMaxAdjoin.extensionToFun_wd (y := y) i f h (a + b) _ _ eq1,
LinearPMap.map_add, map_add]
unfold ExtensionOfMaxAdjoin.extensionToFun
abel
map_smul' := fun r a => by
dsimp
have eq1 :
r • (a : N) =
↑(r • ExtensionOfMaxAdjoin.fst i a) + (r • ExtensionOfMaxAdjoin.snd i a) • y := by
rw [ExtensionOfMaxAdjoin.eqn, smul_add, smul_eq_mul, mul_smul]
rfl
rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h (r • a :) _ _ eq1, LinearMap.map_smul,
LinearPMap.map_smul, ← smul_add]
congr }
is_extension m := by
dsimp
rw [(extensionOfMax i f).is_extension,
ExtensionOfMaxAdjoin.extensionToFun_wd i f h _ ⟨i m, _⟩ 0 _, map_zero, add_zero]
simp
theorem extensionOfMax_le (h : Module.Baer R Q) {y : N} :
extensionOfMax i f ≤ extensionOfMaxAdjoin i f h y :=
⟨le_sup_left, fun x x' EQ => by
symm
change ExtensionOfMaxAdjoin.extensionToFun i f h _ = _
rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h x' x 0 (by simp [EQ]), map_zero,
add_zero]⟩
theorem extensionOfMax_to_submodule_eq_top (h : Module.Baer R Q) :
(extensionOfMax i f).domain = ⊤ := by
refine Submodule.eq_top_iff'.mpr fun y => ?_
dsimp
rw [← extensionOfMax_is_max i f _ (extensionOfMax_le i f h), extensionOfMaxAdjoin,
Submodule.mem_sup]
exact ⟨0, Submodule.zero_mem _, y, Submodule.mem_span_singleton_self _, zero_add _⟩
protected theorem extension_property (h : Module.Baer R Q)
(f : M →ₗ[R] N) (hf : Function.Injective f) (g : M →ₗ[R] Q) : ∃ h, h ∘ₗ f = g :=
haveI : Fact (Function.Injective f) := ⟨hf⟩
Exists.intro
{ toFun := ((extensionOfMax f g).toLinearPMap
⟨·, (extensionOfMax_to_submodule_eq_top f g h).symm ▸ ⟨⟩⟩)
map_add' := fun x y ↦ by rw [← LinearPMap.map_add]; congr
map_smul' := fun r x ↦ by rw [← LinearPMap.map_smul]; dsimp } <|
LinearMap.ext fun x ↦ ((extensionOfMax f g).is_extension x).symm
theorem extension_property_addMonoidHom (h : Module.Baer ℤ Q)
(f : M →+ N) (hf : Function.Injective f) (g : M →+ Q) : ∃ h : N →+ Q, h.comp f = g :=
have ⟨g', hg'⟩ := h.extension_property f.toIntLinearMap hf g.toIntLinearMap
⟨g', congr(LinearMap.toAddMonoidHom $hg')⟩
/-- **Baer's criterion** for injective module : a Baer module is an injective module, i.e. if every
linear map from an ideal can be extended, then the module is injective. -/
protected theorem injective (h : Module.Baer R Q) : Module.Injective R Q where
out X Y _ _ _ _ i hi f := by
obtain ⟨h, H⟩ := Module.Baer.extension_property h i hi f
exact ⟨h, DFunLike.congr_fun H⟩
protected theorem of_injective [Small.{v} R] (inj : Module.Injective R Q) : Module.Baer R Q := by
intro I g
let eI := Shrink.linearEquiv R I
let eR := Shrink.linearEquiv R R
obtain ⟨g', hg'⟩ := Module.Injective.out (eR.symm.toLinearMap ∘ₗ I.subtype ∘ₗ eI.toLinearMap)
(eR.symm.injective.comp <| Subtype.val_injective.comp eI.injective) (g ∘ₗ eI.toLinearMap)
exact ⟨g' ∘ₗ eR.symm.toLinearMap, fun x mx ↦ by simpa [eI, eR] using hg' (equivShrink I ⟨x, mx⟩)⟩
protected theorem iff_injective [Small.{v} R] : Module.Baer R Q ↔ Module.Injective R Q :=
⟨Module.Baer.injective, Module.Baer.of_injective⟩
end Module.Baer
section ULift
variable {M : Type v} [AddCommGroup M] [Module R M]
lemma Module.ulift_injective_of_injective [Small.{v} R]
(inj : Module.Injective R M) :
Module.Injective R (ULift.{v'} M) := Module.Baer.injective fun I g ↦
have ⟨g', hg'⟩ := Module.Baer.iff_injective.mpr inj I (ULift.moduleEquiv.toLinearMap ∘ₗ g)
⟨ULift.moduleEquiv.symm.toLinearMap ∘ₗ g', fun r hr ↦ ULift.ext _ _ <| hg' r hr⟩
lemma Module.injective_of_ulift_injective
(inj : Module.Injective R (ULift.{v'} M)) :
Module.Injective R M where
out X Y _ _ _ _ f hf g :=
let eX := ULift.moduleEquiv.{_,_,v'} (R := R) (M := X)
have ⟨g', hg'⟩ := inj.out (ULift.moduleEquiv.{_,_,v'}.symm.toLinearMap ∘ₗ f ∘ₗ eX.toLinearMap)
(by exact ULift.moduleEquiv.symm.injective.comp <| hf.comp eX.injective)
(ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ eX.toLinearMap)
⟨ULift.moduleEquiv.toLinearMap ∘ₗ g' ∘ₗ ULift.moduleEquiv.symm.toLinearMap,
fun x ↦ by exact congr(ULift.down $(hg' ⟨x⟩))⟩
variable (M) [Small.{v} R]
lemma Module.injective_iff_ulift_injective :
Module.Injective R M ↔ Module.Injective R (ULift.{v'} M) :=
⟨Module.ulift_injective_of_injective R,
Module.injective_of_ulift_injective R⟩
end ULift
section lifting_property
universe uR uM uP uP'
variable (R : Type uR) [Ring R] [Small.{uM} R]
variable (M : Type uM) [AddCommGroup M] [Module R M] [inj : Module.Injective R M]
variable (P : Type uP) [AddCommGroup P] [Module R P]
variable (P' : Type uP') [AddCommGroup P'] [Module R P']
lemma Module.Injective.extension_property
(f : P →ₗ[R] P') (hf : Function.Injective f)
(g : P →ₗ[R] M) : ∃ h : P' →ₗ[R] M, h ∘ₗ f = g :=
(Module.Baer.of_injective inj).extension_property f hf g
end lifting_property
|
ring_quotient.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat.
From mathcomp Require Import seq ssralg generic_quotient.
(******************************************************************************)
(* Quotients of algebraic structures *)
(* *)
(* This file defines a join hierarchy mixing the structures defined in file *)
(* ssralg (up to unit ring type) and the quotType quotient structure defined *)
(* in generic_quotient.v. Every structure in that (join) hierarchy is *)
(* parametrized by a base type T and the constants and operations on the *)
(* base type that will be used to confer its algebraic structure to the *)
(* quotient. Note that T itself is in general not an instance of an *)
(* algebraic structure. The canonical surjection from T onto its quotient *)
(* should be compatible with the parameter operations. *)
(* *)
(* The second part of the file provides a definition of (non trivial) *)
(* decidable ideals (resp. prime ideals) of an arbitrary instance of ring *)
(* structure and a construction of the quotient of a ring by such an ideal. *)
(* These definitions extend the hierarchy of sub-structures defined in file *)
(* ssralg (see Module Pred in ssralg), following a similar methodology. *)
(* Although the definition of the (structure of) quotient of a ring by an *)
(* ideal is a general one, we do not provide infrastructure for the case of *)
(* non commutative ring and left or two-sided ideals. *)
(* *)
(* The file defines the following Structures: *)
(* zmodQuotType T e z n a == Z-module obtained by quotienting type T *)
(* with the relation e and whose neutral, *)
(* opposite and addition are the images in the *)
(* quotient of the parameters z, n and a, *)
(* respectively *)
(* The HB class is called ZmodQuotient. *)
(* nzRingQuotType T e z n a o m == non trivial ring obtained by quotienting *)
(* type T with the relation e and whose zero *)
(* opposite, addition, one, and multiplication *)
(* are the images in the quotient of the *)
(* parameters z, n, a, o, m, respectively *)
(* The HB class is called NzRingQuotient. *)
(* unitRingQuotType ... u i == As in the previous cases, instance of unit *)
(* ring whose unit predicate is obtained from *)
(* u and the inverse from i *)
(* The HB class is called UnitRingQuotient. *)
(* idealr R == {pred R} is a non-trivial, decidable, *)
(* right ideal of the ring R *)
(* (join of GRing.ZmodClosed and ProperIdeal) *)
(* The HB class is called Idealr. *)
(* prime_idealr R == {pred R} is a non-trivial, decidable, *)
(* right, prime ideal of the ring R *)
(* The HB class is called PrimeIdealr. *)
(* *)
(* The formalization of ideals features the following constructions: *)
(* proper_ideal R == the collective predicate (S : pred R) on the *)
(* ring R is stable by the ring product and does *)
(* contain R's one *)
(* The HB class is called ProperIdeal. *)
(* idealr R == join of GRing.ZmodClosed and ProperIdeal *)
(* prime_idealr_closed S := u * v \in S -> (u \in S) || (v \in S) *)
(* idealr_closed S == the collective predicate (S : pred R) on the *)
(* ring R represents a (right) ideal *)
(* This implies its being a proper_ideal. *)
(* {ideal_quot kI} == quotient by the keyed (right) ideal predicate *)
(* kI of a commutative ring R. Note that we only *)
(* provide canonical structures of ring quotients *)
(* for commutative rings, in which a right ideal *)
(* is obviously a two-sided ideal *)
(******************************************************************************)
Import GRing.Theory.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Local Open Scope quotient_scope.
Reserved Notation "{ 'ideal_quot' I }" (format "{ 'ideal_quot' I }").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "m = n %[ 'mod_ideal' I ]"
(format "'[hv ' m '/' = n '/' %[ 'mod_ideal' I ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "m == n %[ 'mod_ideal' I ]"
(format "'[hv ' m '/' == n '/' %[ 'mod_ideal' I ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "m <> n %[ 'mod_ideal' I ]"
(format "'[hv ' m '/' <> n '/' %[ 'mod_ideal' I ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "m != n %[ 'mod_ideal' I ]"
(format "'[hv ' m '/' != n '/' %[ 'mod_ideal' I ] ']'").
(* Variable (T : Type).
Variable eqT : rel T.
Variables (zeroT : T) (oppT : T -> T) (addT : T -> T -> T). *)
HB.mixin Record isZmodQuotient T eqT (zeroT : T) (oppT : T -> T) (addT : T -> T -> T)
(Q : Type) of GRing.Zmodule Q & EqQuotient T eqT Q := {
pi_zeror : \pi_Q zeroT = 0;
pi_oppr : {morph \pi_Q : x / oppT x >-> - x};
pi_addr : {morph \pi_Q : x y / addT x y >-> x + y}
}.
#[short(type="zmodQuotType")]
HB.structure Definition ZmodQuotient T eqT zeroT oppT addT :=
{Q of isZmodQuotient T eqT zeroT oppT addT Q &
GRing.Zmodule Q & EqQuotient T eqT Q}.
Section ZModQuotient.
Variable (T : Type).
Variable eqT : rel T.
Variables (zeroT : T) (oppT : T -> T) (addT : T -> T -> T).
Implicit Type zqT : ZmodQuotient.type eqT zeroT oppT addT.
Canonical pi_zero_quot_morph zqT := PiMorph (@pi_zeror _ _ _ _ _ zqT).
Canonical pi_opp_quot_morph zqT := PiMorph1 (@pi_oppr _ _ _ _ _ zqT).
Canonical pi_add_quot_morph zqT := PiMorph2 (@pi_addr _ _ _ _ _ zqT).
End ZModQuotient.
Section PiAdditive.
Variables (V : zmodType) (equivV : rel V) (zeroV : V).
Variable Q : @zmodQuotType V equivV zeroV -%R +%R.
Lemma pi_is_zmod_morphism : zmod_morphism \pi_Q.
Proof. by move=> x y /=; rewrite !piE. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `pi_is_monoid_morphism` instead")]
Definition pi_is_additive := pi_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build V Q \pi_Q pi_is_zmod_morphism.
End PiAdditive.
(* Variable (T : Type).
Variable eqT : rel T.
Variables (zeroT : T) (oppT : T -> T) (addT : T -> T -> T).
Variables (oneT : T) (mulT : T -> T -> T).
*)
HB.mixin Record isNzRingQuotient T eqT zeroT oppT
addT (oneT : T) (mulT : T -> T -> T) (Q : Type)
of ZmodQuotient T eqT zeroT oppT addT Q & GRing.NzRing Q:=
{
pi_oner : \pi_Q oneT = 1;
pi_mulr : {morph \pi_Q : x y / mulT x y >-> x * y}
}.
Module isRingQuotient.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzRingQuotient.Build instead.")]
Notation Build T eqT zeroT oppT addT oneT mulT Q :=
(isNzRingQuotient.Build T eqT zeroT oppT addT oneT mulT Q) (only parsing).
End isRingQuotient.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzRingQuotient instead.")]
Notation isRingQuotient T eqT zeroT oppT addT oneT mulT Q :=
(isNzRingQuotient T eqT zeroT oppT addT oneT mulT Q) (only parsing).
#[short(type="nzRingQuotType")]
HB.structure Definition NzRingQuotient T eqT zeroT oppT addT oneT mulT :=
{Q of isNzRingQuotient T eqT zeroT oppT addT oneT mulT Q &
ZmodQuotient T eqT zeroT oppT addT Q & GRing.NzRing Q }.
#[deprecated(since="mathcomp 2.4.0",
note="Use nzRingQuotType instead.")]
Notation ringQuotType := (nzRingQuotType) (only parsing).
Section nzRingQuotient.
(*Clash with the module name NzRingQuotient*)
Variable (T : Type).
Variable eqT : rel T.
Variables (zeroT : T) (oppT : T -> T) (addT : T -> T -> T) (oneT : T) (mulT : T -> T -> T).
Implicit Type rqT : NzRingQuotient.type eqT zeroT oppT addT oneT mulT.
Canonical pi_one_quot_morph rqT := PiMorph (@pi_oner _ _ _ _ _ _ _ rqT).
Canonical pi_mul_quot_morph rqT := PiMorph2 (@pi_mulr _ _ _ _ _ _ _ rqT).
End nzRingQuotient.
Section PiRMorphism.
Variables (R : nzRingType) (equivR : rel R) (zeroR : R).
Variable Q : @nzRingQuotType R equivR zeroR -%R +%R 1 *%R.
Lemma pi_is_monoid_morphism : monoid_morphism \pi_Q.
Proof. by split; do ?move=> x y /=; rewrite !piE. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `pi_is_monoid_morphism` instead")]
Definition pi_is_multiplicative :=
(fun g => (g.2,g.1)) pi_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R Q \pi_Q
pi_is_monoid_morphism.
End PiRMorphism.
HB.mixin Record isUnitRingQuotient T eqT zeroT oppT addT oneT mulT (unitT : pred T) (invT : T -> T)
(Q : Type) of NzRingQuotient T eqT zeroT oppT addT oneT mulT Q & GRing.UnitRing Q :=
{
pi_unitr : {mono \pi_Q : x / unitT x >-> x \in GRing.unit};
pi_invr : {morph \pi_Q : x / invT x >-> x^-1}
}.
#[short(type="unitRingQuotType")]
HB.structure Definition UnitRingQuotient T eqT zeroT oppT addT oneT mulT unitT invT :=
{Q of isUnitRingQuotient T eqT zeroT oppT addT oneT mulT unitT invT Q & GRing.UnitRing Q & isQuotient T Q & isEqQuotient T eqT Q & isZmodQuotient T eqT zeroT oppT addT Q & isNzRingQuotient T eqT zeroT oppT addT oneT mulT Q}.
Section UnitRingQuot.
Variable (T : Type).
Variable eqT : rel T.
Variables (zeroT : T) (oppT : T -> T) (addT : T -> T -> T).
Variables (oneT : T) (mulT : T -> T -> T).
Variables (unitT : pred T) (invT : T -> T).
Implicit Type urqT : UnitRingQuotient.type eqT zeroT oppT addT oneT mulT unitT invT.
Canonical pi_unit_quot_morph urqT := PiMono1 (@pi_unitr _ _ _ _ _ _ _ _ _ urqT).
Canonical pi_inv_quot_morph urqT := PiMorph1 (@pi_invr _ _ _ _ _ _ _ _ _ urqT).
End UnitRingQuot.
Definition proper_ideal (R : nzRingType) (S : {pred R}) : Prop :=
1 \notin S /\ forall a, {in S, forall u, a * u \in S}.
Definition prime_idealr_closed (R : nzRingType) (S : {pred R}) : Prop :=
forall u v, u * v \in S -> (u \in S) || (v \in S).
Definition idealr_closed (R : nzRingType) (S : {pred R}) :=
[/\ 0 \in S, 1 \notin S & forall a, {in S &, forall u v, a * u + v \in S}].
Lemma idealr_closed_nontrivial R S : @idealr_closed R S -> proper_ideal S.
Proof. by case=> S0 S1 hS; split => // a x xS; rewrite -[_ * _]addr0 hS. Qed.
Lemma idealr_closedB R S : @idealr_closed R S -> zmod_closed S.
Proof. by case=> S0 _ hS; split=> // x y xS yS; rewrite -mulN1r addrC hS. Qed.
HB.mixin Record isProperIdeal (R : nzRingType) (S : R -> bool) := {
proper_ideal_subproof : proper_ideal S
}.
#[short(type="proper_ideal")]
HB.structure Definition ProperIdeal R := {S of isProperIdeal R S}.
#[short(type="idealr")]
HB.structure Definition Idealr (R : nzRingType) :=
{S of GRing.ZmodClosed R S & ProperIdeal R S}.
HB.mixin Record isPrimeIdealrClosed (R : nzRingType) (S : R -> bool) := {
prime_idealr_closed_subproof : prime_idealr_closed S
}.
#[short(type="prime_idealr")]
HB.structure Definition PrimeIdealr (R : nzRingType) :=
{S of Idealr R S & isPrimeIdealrClosed R S}.
HB.factory Record isIdealr (R : nzRingType) (S : R -> bool) := {
idealr_closed_subproof : idealr_closed S
}.
HB.builders Context R S of isIdealr R S.
HB.instance Definition _ := GRing.isZmodClosed.Build R S
(idealr_closedB idealr_closed_subproof).
HB.instance Definition _ := isProperIdeal.Build R S
(idealr_closed_nontrivial idealr_closed_subproof).
HB.end.
Section IdealTheory.
Variables (R : nzRingType) (idealrI : idealr R).
Local Notation I := (idealrI : pred R).
Lemma idealr1 : 1 \in I = false.
Proof. apply: negPf; exact: proper_ideal_subproof.1. Qed.
Lemma idealMr a u : u \in I -> a * u \in I.
Proof. exact: proper_ideal_subproof.2. Qed.
Lemma idealr0 : 0 \in I. Proof. exact: rpred0. Qed.
End IdealTheory.
Section PrimeIdealTheory.
Variables (R : comNzRingType) (pidealI : prime_idealr R).
Local Notation I := (pidealI : pred R).
Lemma prime_idealrM u v : (u * v \in I) = (u \in I) || (v \in I).
Proof.
apply/idP/idP; last by case/orP => /idealMr hI; rewrite // mulrC.
exact: prime_idealr_closed_subproof.
Qed.
End PrimeIdealTheory.
Module Quotient.
Section ZmodQuotient.
Variables (R : zmodType) (I : zmodClosed R).
Definition equiv (x y : R) := (x - y) \in I.
Lemma equivE x y : (equiv x y) = (x - y \in I). Proof. by []. Qed.
Lemma equiv_is_equiv : equiv_class_of equiv.
Proof.
split=> [x|x y|y x z]; rewrite !equivE ?subrr ?rpred0 //.
by rewrite -opprB rpredN.
by move=> *; rewrite -[x](addrNK y) -addrA rpredD.
Qed.
Canonical equiv_equiv := EquivRelPack equiv_is_equiv.
Canonical equiv_encModRel := defaultEncModRel equiv.
Definition quot := {eq_quot equiv}.
#[export]
HB.instance Definition _ : EqQuotient R equiv quot := EqQuotient.on quot.
#[export]
HB.instance Definition _ := Choice.on quot.
Lemma idealrBE x y : (x - y) \in I = (x == y %[mod quot]).
Proof. by rewrite piE equivE. Qed.
Lemma idealrDE x y : (x + y) \in I = (x == - y %[mod quot]).
Proof. by rewrite -idealrBE opprK. Qed.
Definition zero : quot := lift_cst quot 0.
Definition add := lift_op2 quot +%R.
Definition opp := lift_op1 quot -%R.
Canonical pi_zero_morph := PiConst zero.
Lemma pi_opp : {morph \pi : x / - x >-> opp x}.
Proof.
move=> x; unlock opp; apply/eqP; rewrite piE equivE.
by rewrite -opprD rpredN idealrDE opprK reprK.
Qed.
Canonical pi_opp_morph := PiMorph1 pi_opp.
Lemma pi_add : {morph \pi : x y / x + y >-> add x y}.
Proof.
move=> x y /=; unlock add; apply/eqP; rewrite piE equivE.
rewrite opprD addrAC addrA -addrA.
by rewrite rpredD // (idealrBE, idealrDE) ?pi_opp ?reprK.
Qed.
Canonical pi_add_morph := PiMorph2 pi_add.
Lemma addqA: associative add.
Proof. by move=> x y z; rewrite -[x]reprK -[y]reprK -[z]reprK !piE addrA. Qed.
Lemma addqC: commutative add.
Proof. by move=> x y; rewrite -[x]reprK -[y]reprK !piE addrC. Qed.
Lemma add0q: left_id zero add.
Proof. by move=> x; rewrite -[x]reprK !piE add0r. Qed.
Lemma addNq: left_inverse zero opp add.
Proof. by move=> x; rewrite -[x]reprK !piE addNr. Qed.
#[export]
HB.instance Definition _ := GRing.isZmodule.Build quot addqA addqC add0q addNq.
#[export]
HB.instance Definition _ := @isZmodQuotient.Build R equiv 0 -%R +%R quot
(lock _) pi_opp pi_add.
End ZmodQuotient.
Arguments quot R%_type I%_type.
Notation "{ 'quot' I }" := (quot I) : type_scope.
Section RingQuotient.
Variables (R : comNzRingType) (idealI : idealr R).
Local Notation I := (idealI : pred R).
Definition one : {quot idealI} := lift_cst {quot idealI} 1.
Definition mul := lift_op2 {quot idealI} *%R.
Canonical pi_one_morph := PiConst one.
Lemma pi_mul: {morph \pi : x y / x * y >-> mul x y}.
Proof.
move=> x y; unlock mul; apply/eqP; rewrite piE equivE.
rewrite -[_ * _](addrNK (x * repr (\pi_{quot idealI} y))) -mulrBr.
rewrite -addrA -mulrBl rpredD //.
by rewrite idealMr // idealrDE opprK reprK.
by rewrite mulrC idealMr // idealrDE opprK reprK.
Qed.
Canonical pi_mul_morph := PiMorph2 pi_mul.
Lemma mulqA: associative mul.
Proof. by move=> x y z; rewrite -[x]reprK -[y]reprK -[z]reprK !piE mulrA. Qed.
Lemma mulqC: commutative mul.
Proof. by move=> x y; rewrite -[x]reprK -[y]reprK !piE mulrC. Qed.
Lemma mul1q: left_id one mul.
Proof. by move=> x; rewrite -[x]reprK !piE mul1r. Qed.
Lemma mulq_addl: left_distributive mul +%R.
Proof.
move=> x y z; rewrite -[x]reprK -[y]reprK -[z]reprK.
by apply/eqP; rewrite piE /= mulrDl equiv_refl.
Qed.
Lemma nonzero1q: one != 0.
Proof. by rewrite piE equivE subr0 idealr1. Qed.
#[export]
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build (quot idealI)
mulqA mulqC mul1q mulq_addl nonzero1q.
#[export]
HB.instance Definition _ := @isNzRingQuotient.Build
R (equiv idealI) 0 -%R +%R 1%R *%R (quot idealI) (lock _) pi_mul.
End RingQuotient.
Section IDomainQuotient.
Variables (R : comNzRingType) (I : prime_idealr R).
Lemma rquot_IdomainAxiom (x y : {quot I}): x * y = 0 -> (x == 0) || (y == 0).
Proof.
by move=> /eqP; rewrite -[x]reprK -[y]reprK !piE !equivE !subr0 prime_idealrM.
Qed.
End IDomainQuotient.
Module Exports. HB.reexport. End Exports.
End Quotient.
Export Quotient.Exports.
Notation "{ 'ideal_quot' I }" := (@Quotient.quot _ I) : type_scope.
Notation "x == y %[ 'mod_ideal' I ]" :=
(x == y %[mod {ideal_quot I}]) : quotient_scope.
Notation "x = y %[ 'mod_ideal' I ]" :=
(x = y %[mod {ideal_quot I}]) : quotient_scope.
Notation "x != y %[ 'mod_ideal' I ]" :=
(x != y %[mod {ideal_quot I}]) : quotient_scope.
Notation "x <> y %[ 'mod_ideal' I ]" :=
(x <> y %[mod {ideal_quot I}]) : quotient_scope.
|
Limit.lean
|
/-
Copyright (c) 2022 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.Order.SuccPred.Archimedean
import Mathlib.Order.BoundedOrder.Lattice
/-!
# Successor and predecessor limits
We define the predicate `Order.IsSuccPrelimit` for "successor pre-limits", values that don't cover
any others. They are so named since they can't be the successors of anything smaller. We define
`Order.IsPredPrelimit` analogously, and prove basic results.
For some applications, it is desirable to exclude minimal elements from being successor limits, or
maximal elements from being predecessor limits. As such, we also provide `Order.IsSuccLimit` and
`Order.IsPredLimit`, which exclude these cases.
-/
variable {α : Type*} {a b : α}
namespace Order
open Function Set OrderDual
/-! ### Successor limits -/
section LT
variable [LT α]
/-- A successor pre-limit is a value that doesn't cover any other.
It's so named because in a successor order, a successor pre-limit can't be the successor of anything
smaller.
Use `IsSuccLimit` if you want to exclude the case of a minimal element. -/
def IsSuccPrelimit (a : α) : Prop :=
∀ b, ¬b ⋖ a
theorem not_isSuccPrelimit_iff_exists_covBy (a : α) : ¬IsSuccPrelimit a ↔ ∃ b, b ⋖ a := by
simp [IsSuccPrelimit]
@[simp]
theorem IsSuccPrelimit.of_dense [DenselyOrdered α] (a : α) : IsSuccPrelimit a := fun _ => not_covBy
end LT
section Preorder
variable [Preorder α]
/-- A successor limit is a value that isn't minimal and doesn't cover any other.
It's so named because in a successor order, a successor limit can't be the successor of anything
smaller.
This previously allowed the element to be minimal. This usage is now covered by `IsSuccPrelimit`. -/
def IsSuccLimit (a : α) : Prop :=
¬ IsMin a ∧ IsSuccPrelimit a
protected theorem IsSuccLimit.not_isMin (h : IsSuccLimit a) : ¬ IsMin a := h.1
protected theorem IsSuccLimit.isSuccPrelimit (h : IsSuccLimit a) : IsSuccPrelimit a := h.2
theorem IsSuccPrelimit.isSuccLimit_of_not_isMin (h : IsSuccPrelimit a) (ha : ¬ IsMin a) :
IsSuccLimit a :=
⟨ha, h⟩
theorem IsSuccPrelimit.isSuccLimit [NoMinOrder α] (h : IsSuccPrelimit a) : IsSuccLimit a :=
h.isSuccLimit_of_not_isMin (not_isMin a)
theorem isSuccPrelimit_iff_isSuccLimit_of_not_isMin (h : ¬ IsMin a) :
IsSuccPrelimit a ↔ IsSuccLimit a :=
⟨fun ha ↦ ha.isSuccLimit_of_not_isMin h, IsSuccLimit.isSuccPrelimit⟩
theorem isSuccPrelimit_iff_isSuccLimit [NoMinOrder α] : IsSuccPrelimit a ↔ IsSuccLimit a :=
isSuccPrelimit_iff_isSuccLimit_of_not_isMin (not_isMin a)
protected theorem _root_.IsMin.not_isSuccLimit (h : IsMin a) : ¬ IsSuccLimit a :=
fun ha ↦ ha.not_isMin h
protected theorem _root_.IsMin.isSuccPrelimit : IsMin a → IsSuccPrelimit a := fun h _ hab =>
not_isMin_of_lt hab.lt h
theorem isSuccPrelimit_bot [OrderBot α] : IsSuccPrelimit (⊥ : α) :=
isMin_bot.isSuccPrelimit
theorem not_isSuccLimit_bot [OrderBot α] : ¬ IsSuccLimit (⊥ : α) :=
isMin_bot.not_isSuccLimit
theorem IsSuccLimit.ne_bot [OrderBot α] (h : IsSuccLimit a) : a ≠ ⊥ := by
rintro rfl
exact not_isSuccLimit_bot h
theorem not_isSuccLimit_iff : ¬ IsSuccLimit a ↔ IsMin a ∨ ¬ IsSuccPrelimit a := by
rw [IsSuccLimit, not_and_or, not_not]
variable [SuccOrder α]
protected theorem IsSuccPrelimit.isMax (h : IsSuccPrelimit (succ a)) : IsMax a := by
by_contra H
exact h a (covBy_succ_of_not_isMax H)
protected theorem IsSuccLimit.isMax (h : IsSuccLimit (succ a)) : IsMax a :=
h.isSuccPrelimit.isMax
theorem not_isSuccPrelimit_succ_of_not_isMax (ha : ¬ IsMax a) : ¬ IsSuccPrelimit (succ a) :=
mt IsSuccPrelimit.isMax ha
theorem not_isSuccLimit_succ_of_not_isMax (ha : ¬ IsMax a) : ¬ IsSuccLimit (succ a) :=
mt IsSuccLimit.isMax ha
/-- Given `j < i` with `i` a prelimit, `IsSuccPrelimit.mid` picks an arbitrary element strictly
between `j` and `i`. -/
noncomputable def IsSuccPrelimit.mid {i j : α} (hi : IsSuccPrelimit i) (hj : j < i) :
Ioo j i :=
Classical.indefiniteDescription _ ((not_covBy_iff hj).mp <| hi j)
section NoMaxOrder
variable [NoMaxOrder α]
theorem IsSuccPrelimit.succ_ne (h : IsSuccPrelimit a) (b : α) : succ b ≠ a := by
rintro rfl
exact not_isMax _ h.isMax
theorem IsSuccLimit.succ_ne (h : IsSuccLimit a) (b : α) : succ b ≠ a :=
h.isSuccPrelimit.succ_ne b
@[simp]
theorem not_isSuccPrelimit_succ (a : α) : ¬IsSuccPrelimit (succ a) := fun h => h.succ_ne _ rfl
@[simp]
theorem not_isSuccLimit_succ (a : α) : ¬IsSuccLimit (succ a) := fun h => h.succ_ne _ rfl
end NoMaxOrder
section IsSuccArchimedean
variable [IsSuccArchimedean α] [NoMaxOrder α]
theorem IsSuccPrelimit.isMin_of_noMax (h : IsSuccPrelimit a) : IsMin a := by
intro b hb
rcases hb.exists_succ_iterate with ⟨_ | n, rfl⟩
· exact le_rfl
· rw [iterate_succ_apply'] at h
exact (not_isSuccPrelimit_succ _ h).elim
@[simp]
theorem isSuccPrelimit_iff_of_noMax : IsSuccPrelimit a ↔ IsMin a :=
⟨IsSuccPrelimit.isMin_of_noMax, IsMin.isSuccPrelimit⟩
@[simp]
theorem not_isSuccLimit_of_noMax : ¬ IsSuccLimit a :=
fun h ↦ h.not_isMin h.isSuccPrelimit.isMin_of_noMax
theorem not_isSuccPrelimit_of_noMax [NoMinOrder α] : ¬ IsSuccPrelimit a := by simp
end IsSuccArchimedean
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem isSuccLimit_iff [OrderBot α] : IsSuccLimit a ↔ a ≠ ⊥ ∧ IsSuccPrelimit a := by
rw [IsSuccLimit, isMin_iff_eq_bot]
theorem IsSuccLimit.bot_lt [OrderBot α] (h : IsSuccLimit a) : ⊥ < a :=
h.ne_bot.bot_lt
variable [SuccOrder α]
theorem isSuccPrelimit_of_succ_ne (h : ∀ b, succ b ≠ a) : IsSuccPrelimit a := fun b hba =>
h b (CovBy.succ_eq hba)
theorem not_isSuccPrelimit_iff : ¬ IsSuccPrelimit a ↔ ∃ b, ¬ IsMax b ∧ succ b = a := by
rw [not_isSuccPrelimit_iff_exists_covBy]
refine exists_congr fun b => ⟨fun hba => ⟨hba.lt.not_isMax, (CovBy.succ_eq hba)⟩, ?_⟩
rintro ⟨h, rfl⟩
exact covBy_succ_of_not_isMax h
/-- See `not_isSuccPrelimit_iff` for a version that states that `a` is a successor of a value other
than itself. -/
theorem mem_range_succ_of_not_isSuccPrelimit (h : ¬ IsSuccPrelimit a) :
a ∈ range (succ : α → α) := by
obtain ⟨b, hb⟩ := not_isSuccPrelimit_iff.1 h
exact ⟨b, hb.2⟩
theorem mem_range_succ_or_isSuccPrelimit (a) : a ∈ range (succ : α → α) ∨ IsSuccPrelimit a :=
or_iff_not_imp_right.2 <| mem_range_succ_of_not_isSuccPrelimit
theorem isMin_or_mem_range_succ_or_isSuccLimit (a) :
IsMin a ∨ a ∈ range (succ : α → α) ∨ IsSuccLimit a := by
rw [IsSuccLimit]
have := mem_range_succ_or_isSuccPrelimit a
tauto
theorem isSuccPrelimit_of_succ_lt (H : ∀ a < b, succ a < b) : IsSuccPrelimit b := fun a hab =>
(H a hab.lt).ne (CovBy.succ_eq hab)
theorem IsSuccPrelimit.succ_lt (hb : IsSuccPrelimit b) (ha : a < b) : succ a < b := by
by_cases h : IsMax a
· rwa [h.succ_eq]
· rw [lt_iff_le_and_ne, succ_le_iff_of_not_isMax h]
refine ⟨ha, fun hab => ?_⟩
subst hab
exact (h hb.isMax).elim
theorem IsSuccLimit.succ_lt (hb : IsSuccLimit b) (ha : a < b) : succ a < b :=
hb.isSuccPrelimit.succ_lt ha
theorem IsSuccPrelimit.succ_lt_iff (hb : IsSuccPrelimit b) : succ a < b ↔ a < b :=
⟨fun h => (le_succ a).trans_lt h, hb.succ_lt⟩
theorem IsSuccLimit.succ_lt_iff (hb : IsSuccLimit b) : succ a < b ↔ a < b :=
hb.isSuccPrelimit.succ_lt_iff
theorem isSuccPrelimit_iff_succ_lt : IsSuccPrelimit b ↔ ∀ a < b, succ a < b :=
⟨fun hb _ => hb.succ_lt, isSuccPrelimit_of_succ_lt⟩
section NoMaxOrder
variable [NoMaxOrder α]
theorem isSuccPrelimit_iff_succ_ne : IsSuccPrelimit a ↔ ∀ b, succ b ≠ a :=
⟨IsSuccPrelimit.succ_ne, isSuccPrelimit_of_succ_ne⟩
theorem not_isSuccPrelimit_iff' : ¬ IsSuccPrelimit a ↔ a ∈ range (succ : α → α) := by
simp_rw [isSuccPrelimit_iff_succ_ne, not_forall, not_ne_iff, mem_range]
end NoMaxOrder
section IsSuccArchimedean
variable [IsSuccArchimedean α]
protected theorem IsSuccPrelimit.isMin (h : IsSuccPrelimit a) : IsMin a := fun b hb => by
revert h
refine Succ.rec (fun _ => le_rfl) (fun c _ H hc => ?_) hb
have := hc.isMax.succ_eq
rw [this] at hc ⊢
exact H hc
@[simp]
theorem isSuccPrelimit_iff : IsSuccPrelimit a ↔ IsMin a :=
⟨IsSuccPrelimit.isMin, IsMin.isSuccPrelimit⟩
@[simp]
theorem not_isSuccLimit : ¬ IsSuccLimit a :=
fun h ↦ h.not_isMin <| h.isSuccPrelimit.isMin
theorem not_isSuccPrelimit [NoMinOrder α] : ¬ IsSuccPrelimit a := by simp
end IsSuccArchimedean
end PartialOrder
section LinearOrder
variable [LinearOrder α]
theorem IsSuccPrelimit.le_iff_forall_le (h : IsSuccPrelimit a) : a ≤ b ↔ ∀ c < a, c ≤ b := by
use fun ha c hc ↦ hc.le.trans ha
intro H
by_contra! ha
exact h b ⟨ha, fun c hb hc ↦ (H c hc).not_gt hb⟩
theorem IsSuccLimit.le_iff_forall_le (h : IsSuccLimit a) : a ≤ b ↔ ∀ c < a, c ≤ b :=
h.isSuccPrelimit.le_iff_forall_le
theorem IsSuccPrelimit.lt_iff_exists_lt (h : IsSuccPrelimit b) : a < b ↔ ∃ c < b, a < c := by
rw [← not_iff_not]
simp [h.le_iff_forall_le]
theorem IsSuccLimit.lt_iff_exists_lt (h : IsSuccLimit b) : a < b ↔ ∃ c < b, a < c :=
h.isSuccPrelimit.lt_iff_exists_lt
lemma _root_.IsLUB.isSuccPrelimit_of_notMem {s : Set α} (hs : IsLUB s a) (ha : a ∉ s) :
IsSuccPrelimit a := by
intro b hb
obtain ⟨c, hc, hbc, hca⟩ := hs.exists_between hb.lt
obtain rfl := (hb.ge_of_gt hbc).antisymm hca
contradiction
@[deprecated (since := "2025-05-23")]
alias _root_.IsLUB.isSuccPrelimit_of_not_mem := _root_.IsLUB.isSuccPrelimit_of_notMem
lemma _root_.IsLUB.mem_of_not_isSuccPrelimit {s : Set α} (hs : IsLUB s a) (ha : ¬IsSuccPrelimit a) :
a ∈ s :=
ha.imp_symm hs.isSuccPrelimit_of_notMem
lemma _root_.IsLUB.isSuccLimit_of_notMem {s : Set α} (hs : IsLUB s a) (hs' : s.Nonempty)
(ha : a ∉ s) : IsSuccLimit a := by
refine ⟨?_, hs.isSuccPrelimit_of_notMem ha⟩
obtain ⟨b, hb⟩ := hs'
obtain rfl | hb := (hs.1 hb).eq_or_lt
· contradiction
· exact hb.not_isMin
@[deprecated (since := "2025-05-23")]
alias _root_.IsLUB.isSuccLimit_of_not_mem := _root_.IsLUB.isSuccLimit_of_notMem
lemma _root_.IsLUB.mem_of_not_isSuccLimit {s : Set α} (hs : IsLUB s a) (hs' : s.Nonempty)
(ha : ¬IsSuccLimit a) : a ∈ s :=
ha.imp_symm <| hs.isSuccLimit_of_notMem hs'
theorem IsSuccPrelimit.isLUB_Iio (ha : IsSuccPrelimit a) : IsLUB (Iio a) a := by
refine ⟨fun _ ↦ le_of_lt, fun b hb ↦ le_of_forall_lt fun c hc ↦ ?_⟩
obtain ⟨d, hd, hd'⟩ := ha.lt_iff_exists_lt.1 hc
exact hd'.trans_le (hb hd)
theorem IsSuccLimit.isLUB_Iio (ha : IsSuccLimit a) : IsLUB (Iio a) a :=
ha.isSuccPrelimit.isLUB_Iio
theorem isLUB_Iio_iff_isSuccPrelimit : IsLUB (Iio a) a ↔ IsSuccPrelimit a := by
refine ⟨fun ha b hb ↦ ?_, IsSuccPrelimit.isLUB_Iio⟩
rw [hb.Iio_eq] at ha
obtain rfl := isLUB_Iic.unique ha
cases hb.lt.false
variable [SuccOrder α]
theorem IsSuccPrelimit.le_succ_iff (hb : IsSuccPrelimit b) : b ≤ succ a ↔ b ≤ a :=
le_iff_le_iff_lt_iff_lt.2 hb.succ_lt_iff
theorem IsSuccLimit.le_succ_iff (hb : IsSuccLimit b) : b ≤ succ a ↔ b ≤ a :=
hb.isSuccPrelimit.le_succ_iff
end LinearOrder
/-! ### Predecessor limits -/
section LT
variable [LT α]
/-- A predecessor pre-limit is a value that isn't covered by any other.
It's so named because in a predecessor order, a predecessor pre-limit can't be the predecessor of
anything smaller.
Use `IsPredLimit` to exclude the case of a maximal element. -/
def IsPredPrelimit (a : α) : Prop :=
∀ b, ¬ a ⋖ b
theorem not_isPredPrelimit_iff_exists_covBy (a : α) : ¬IsPredPrelimit a ↔ ∃ b, a ⋖ b := by
simp [IsPredPrelimit]
@[simp]
theorem IsPredPrelimit.of_dense [DenselyOrdered α] (a : α) : IsPredPrelimit a := fun _ => not_covBy
@[simp]
theorem isSuccPrelimit_toDual_iff : IsSuccPrelimit (toDual a) ↔ IsPredPrelimit a := by
simp [IsSuccPrelimit, IsPredPrelimit]
@[simp]
theorem isPredPrelimit_toDual_iff : IsPredPrelimit (toDual a) ↔ IsSuccPrelimit a := by
simp [IsSuccPrelimit, IsPredPrelimit]
alias ⟨_, IsPredPrelimit.dual⟩ := isSuccPrelimit_toDual_iff
alias ⟨_, IsSuccPrelimit.dual⟩ := isPredPrelimit_toDual_iff
end LT
section Preorder
variable [Preorder α]
/-- A predecessor limit is a value that isn't maximal and doesn't cover any other.
It's so named because in a predecessor order, a predecessor limit can't be the predecessor of
anything larger.
This previously allowed the element to be maximal. This usage is now covered by `IsPredPreLimit`. -/
def IsPredLimit (a : α) : Prop :=
¬ IsMax a ∧ IsPredPrelimit a
protected theorem IsPredLimit.not_isMax (h : IsPredLimit a) : ¬ IsMax a := h.1
protected theorem IsPredLimit.isPredPrelimit (h : IsPredLimit a) : IsPredPrelimit a := h.2
@[simp]
theorem isSuccLimit_toDual_iff : IsSuccLimit (toDual a) ↔ IsPredLimit a := by
simp [IsSuccLimit, IsPredLimit]
@[simp]
theorem isPredLimit_toDual_iff : IsPredLimit (toDual a) ↔ IsSuccLimit a := by
simp [IsSuccLimit, IsPredLimit]
alias ⟨_, IsPredLimit.dual⟩ := isSuccLimit_toDual_iff
alias ⟨_, IsSuccLimit.dual⟩ := isPredLimit_toDual_iff
theorem IsPredPrelimit.isPredLimit_of_not_isMax (h : IsPredPrelimit a) (ha : ¬ IsMax a) :
IsPredLimit a :=
⟨ha, h⟩
theorem IsPredPrelimit.isPredLimit [NoMaxOrder α] (h : IsPredPrelimit a) : IsPredLimit a :=
h.isPredLimit_of_not_isMax (not_isMax a)
theorem isPredPrelimit_iff_isPredLimit_of_not_isMax (h : ¬ IsMax a) :
IsPredPrelimit a ↔ IsPredLimit a :=
⟨fun ha ↦ ha.isPredLimit_of_not_isMax h, IsPredLimit.isPredPrelimit⟩
theorem isPredPrelimit_iff_isPredLimit [NoMaxOrder α] : IsPredPrelimit a ↔ IsPredLimit a :=
isPredPrelimit_iff_isPredLimit_of_not_isMax (not_isMax a)
protected theorem _root_.IsMax.not_isPredLimit (h : IsMax a) : ¬ IsPredLimit a :=
fun ha ↦ ha.not_isMax h
protected theorem _root_.IsMax.isPredPrelimit : IsMax a → IsPredPrelimit a := fun h _ hab =>
not_isMax_of_lt hab.lt h
theorem isPredPrelimit_top [OrderTop α] : IsPredPrelimit (⊤ : α) :=
isMax_top.isPredPrelimit
theorem not_isPredLimit_top [OrderTop α] : ¬ IsPredLimit (⊤ : α) :=
isMax_top.not_isPredLimit
theorem IsPredLimit.ne_top [OrderTop α] (h : IsPredLimit a) : a ≠ ⊤ :=
h.dual.ne_bot
theorem not_isPredLimit_iff : ¬ IsPredLimit a ↔ IsMax a ∨ ¬ IsPredPrelimit a := by
rw [IsPredLimit, not_and_or, not_not]
theorem not_isPredLimit_of_not_isPredPrelimit (h : ¬ IsPredPrelimit a) : ¬ IsPredLimit a :=
not_isPredLimit_iff.2 (Or.inr h)
variable [PredOrder α]
protected theorem IsPredPrelimit.isMin (h : IsPredPrelimit (pred a)) : IsMin a :=
h.dual.isMax
protected theorem IsPredLimit.isMin (h : IsPredLimit (pred a)) : IsMin a :=
h.dual.isMax
theorem not_isPredPrelimit_pred_of_not_isMin (ha : ¬ IsMin a) : ¬ IsPredPrelimit (pred a) :=
mt IsPredPrelimit.isMin ha
theorem not_isPredLimit_pred_of_not_isMin (ha : ¬ IsMin a) : ¬ IsPredLimit (pred a) :=
mt IsPredLimit.isMin ha
section NoMinOrder
variable [NoMinOrder α]
theorem IsPredPrelimit.pred_ne (h : IsPredPrelimit a) (b : α) : pred b ≠ a :=
h.dual.succ_ne b
theorem IsPredLimit.pred_ne (h : IsPredLimit a) (b : α) : pred b ≠ a :=
h.isPredPrelimit.pred_ne b
@[simp]
theorem not_isPredPrelimit_pred (a : α) : ¬ IsPredPrelimit (pred a) := fun h => h.pred_ne _ rfl
@[simp]
theorem not_isPredLimit_pred (a : α) : ¬ IsPredLimit (pred a) := fun h => h.pred_ne _ rfl
end NoMinOrder
section IsPredArchimedean
variable [IsPredArchimedean α] [NoMinOrder α]
theorem IsPredPrelimit.isMax_of_noMin (h : IsPredPrelimit a) : IsMax a :=
h.dual.isMin_of_noMax
@[simp]
theorem isPredPrelimit_iff_of_noMin : IsPredPrelimit a ↔ IsMax a :=
⟨IsPredPrelimit.isMax_of_noMin, IsMax.isPredPrelimit⟩
theorem not_isPredPrelimit_of_noMin [NoMaxOrder α] : ¬ IsPredPrelimit a := by simp
@[simp]
theorem not_isPredLimit_of_noMin : ¬ IsPredLimit a :=
fun h ↦ h.not_isMax h.isPredPrelimit.isMax_of_noMin
end IsPredArchimedean
end Preorder
section PartialOrder
variable [PartialOrder α]
theorem isPredLimit_iff [OrderTop α] : IsPredLimit a ↔ a ≠ ⊤ ∧ IsPredPrelimit a := by
rw [IsPredLimit, isMax_iff_eq_top]
theorem IsPredLimit.lt_top [OrderTop α] (h : IsPredLimit a) : a < ⊤ :=
h.ne_top.lt_top
variable [PredOrder α]
theorem isPredPrelimit_of_pred_ne (h : ∀ b, pred b ≠ a) : IsPredPrelimit a := fun b hba =>
h b (CovBy.pred_eq hba)
theorem not_isPredPrelimit_iff : ¬ IsPredPrelimit a ↔ ∃ b, ¬ IsMin b ∧ pred b = a := by
rw [← isSuccPrelimit_toDual_iff]
exact not_isSuccPrelimit_iff
/-- See `not_isPredPrelimit_iff` for a version that states that `a` is a successor of a value other
than itself. -/
theorem mem_range_pred_of_not_isPredPrelimit (h : ¬ IsPredPrelimit a) :
a ∈ range (pred : α → α) := by
obtain ⟨b, hb⟩ := not_isPredPrelimit_iff.1 h
exact ⟨b, hb.2⟩
theorem mem_range_pred_or_isPredPrelimit (a) : a ∈ range (pred : α → α) ∨ IsPredPrelimit a :=
or_iff_not_imp_right.2 <| mem_range_pred_of_not_isPredPrelimit
theorem isPredPrelimit_of_pred_lt (H : ∀ b > a, a < pred b) : IsPredPrelimit a := fun a hab =>
(H a hab.lt).ne (CovBy.pred_eq hab).symm
theorem IsPredPrelimit.lt_pred (ha : IsPredPrelimit a) (hb : a < b) : a < pred b :=
ha.dual.succ_lt hb
theorem IsPredLimit.lt_pred (ha : IsPredLimit a) (hb : a < b) : a < pred b :=
ha.isPredPrelimit.lt_pred hb
theorem IsPredPrelimit.lt_pred_iff (ha : IsPredPrelimit a) : a < pred b ↔ a < b :=
ha.dual.succ_lt_iff
theorem IsPredLimit.lt_pred_iff (ha : IsPredLimit a) : a < pred b ↔ a < b :=
ha.dual.succ_lt_iff
theorem isPredPrelimit_iff_lt_pred : IsPredPrelimit a ↔ ∀ b > a, a < pred b :=
⟨fun hb _ => hb.lt_pred, isPredPrelimit_of_pred_lt⟩
section NoMinOrder
variable [NoMinOrder α]
theorem isPredPrelimit_iff_pred_ne : IsPredPrelimit a ↔ ∀ b, pred b ≠ a :=
⟨IsPredPrelimit.pred_ne, isPredPrelimit_of_pred_ne⟩
theorem not_isPredPrelimit_iff' : ¬ IsPredPrelimit a ↔ a ∈ range (pred : α → α) := by
simp_rw [isPredPrelimit_iff_pred_ne, not_forall, not_ne_iff, mem_range]
end NoMinOrder
section IsPredArchimedean
variable [IsPredArchimedean α]
protected theorem IsPredPrelimit.isMax (h : IsPredPrelimit a) : IsMax a :=
h.dual.isMin
@[simp]
theorem isPredPrelimit_iff : IsPredPrelimit a ↔ IsMax a :=
⟨IsPredPrelimit.isMax, IsMax.isPredPrelimit⟩
@[simp]
theorem not_isPredLimit : ¬ IsPredLimit a :=
fun h ↦ h.not_isMax <| h.isPredPrelimit.isMax
theorem not_isPredPrelimit [NoMaxOrder α] : ¬ IsPredPrelimit a := by simp
end IsPredArchimedean
end PartialOrder
section LinearOrder
variable [LinearOrder α]
theorem IsPredPrelimit.le_iff_forall_le (h : IsPredPrelimit a) : b ≤ a ↔ ∀ ⦃c⦄, a < c → b ≤ c :=
h.dual.le_iff_forall_le
theorem IsPredLimit.le_iff_forall_le (h : IsPredLimit a) : b ≤ a ↔ ∀ ⦃c⦄, a < c → b ≤ c :=
h.dual.le_iff_forall_le
theorem IsPredPrelimit.lt_iff_exists_lt (h : IsPredPrelimit b) : b < a ↔ ∃ c, b < c ∧ c < a :=
h.dual.lt_iff_exists_lt
theorem IsPredLimit.lt_iff_exists_lt (h : IsPredLimit b) : b < a ↔ ∃ c, b < c ∧ c < a :=
h.dual.lt_iff_exists_lt
lemma _root_.IsGLB.isPredPrelimit_of_notMem {s : Set α} (hs : IsGLB s a) (ha : a ∉ s) :
IsPredPrelimit a := by
simpa using (IsGLB.dual hs).isSuccPrelimit_of_notMem ha
@[deprecated (since := "2025-05-23")]
alias _root_.IsGLB.isPredPrelimit_of_not_mem := _root_.IsGLB.isPredPrelimit_of_notMem
lemma _root_.IsGLB.mem_of_not_isPredPrelimit {s : Set α} (hs : IsGLB s a) (ha : ¬IsPredPrelimit a) :
a ∈ s :=
ha.imp_symm hs.isPredPrelimit_of_notMem
lemma _root_.IsGLB.isPredLimit_of_notMem {s : Set α} (hs : IsGLB s a) (hs' : s.Nonempty)
(ha : a ∉ s) : IsPredLimit a := by
simpa using (IsGLB.dual hs).isSuccLimit_of_notMem hs' ha
@[deprecated (since := "2025-05-23")]
alias _root_.IsGLB.isPredLimit_of_not_mem := _root_.IsGLB.isPredLimit_of_notMem
lemma _root_.IsGLB.mem_of_not_isPredLimit {s : Set α} (hs : IsGLB s a) (hs' : s.Nonempty)
(ha : ¬IsPredLimit a) : a ∈ s :=
ha.imp_symm <| hs.isPredLimit_of_notMem hs'
theorem IsPredPrelimit.isGLB_Ioi (ha : IsPredPrelimit a) : IsGLB (Ioi a) a :=
ha.dual.isLUB_Iio
theorem IsPredLimit.isGLB_Ioi (ha : IsPredLimit a) : IsGLB (Ioi a) a :=
ha.dual.isLUB_Iio
theorem isGLB_Ioi_iff_isPredPrelimit : IsGLB (Ioi a) a ↔ IsPredPrelimit a := by
simpa using isLUB_Iio_iff_isSuccPrelimit (a := toDual a)
variable [PredOrder α]
theorem IsPredPrelimit.pred_le_iff (hb : IsPredPrelimit b) : pred a ≤ b ↔ a ≤ b :=
hb.dual.le_succ_iff
theorem IsPredLimit.pred_le_iff (hb : IsPredLimit b) : pred a ≤ b ↔ a ≤ b :=
hb.dual.le_succ_iff
end LinearOrder
end Order
/-! ### Induction principles -/
variable {motive : α → Sort*}
namespace Order
section isSuccPrelimitRecOn
section PartialOrder
variable [PartialOrder α] [SuccOrder α]
(succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → motive a)
variable (b) in
open Classical in
/-- A value can be built by building it on successors and successor pre-limits. -/
@[elab_as_elim]
noncomputable def isSuccPrelimitRecOn : motive b :=
if hb : IsSuccPrelimit b then isSuccPrelimit b hb else
haveI H := Classical.choose_spec (not_isSuccPrelimit_iff.1 hb)
cast (congr_arg motive H.2) (succ _ H.1)
theorem isSuccPrelimitRecOn_of_isSuccPrelimit (hb : IsSuccPrelimit b) :
isSuccPrelimitRecOn b succ isSuccPrelimit = isSuccPrelimit b hb :=
dif_pos hb
end PartialOrder
section LinearOrder
variable [LinearOrder α] [SuccOrder α]
(succ : ∀ a, ¬IsMax a → motive (succ a)) (isSuccPrelimit : ∀ a, IsSuccPrelimit a → motive a)
theorem isSuccPrelimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) :
isSuccPrelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b hb := by
have hb' := not_isSuccPrelimit_succ_of_not_isMax hb
have H := Classical.choose_spec (not_isSuccPrelimit_iff.1 hb')
rw [isSuccPrelimitRecOn, dif_neg hb', cast_eq_iff_heq]
congr
exacts [(succ_eq_succ_iff_of_not_isMax H.1 hb).1 H.2, proof_irrel_heq _ _]
@[simp]
theorem isSuccPrelimitRecOn_succ [NoMaxOrder α] (b : α) :
isSuccPrelimitRecOn (Order.succ b) succ isSuccPrelimit = succ b (not_isMax b) :=
isSuccPrelimitRecOn_succ_of_not_isMax _ _ _
end LinearOrder
end isSuccPrelimitRecOn
section isPredPrelimitRecOn
section PartialOrder
variable [PartialOrder α] [PredOrder α]
(pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → motive a)
variable (b) in
/-- A value can be built by building it on predecessors and predecessor pre-limits. -/
@[elab_as_elim]
noncomputable def isPredPrelimitRecOn : motive b :=
isSuccPrelimitRecOn (α := αᵒᵈ) b pred (fun a ha ↦ isPredPrelimit a ha.dual)
theorem isPredPrelimitRecOn_of_isPredPrelimit (hb : IsPredPrelimit b) :
isPredPrelimitRecOn b pred isPredPrelimit = isPredPrelimit b hb :=
isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.dual
end PartialOrder
section LinearOrder
variable [LinearOrder α] [PredOrder α]
(pred : ∀ a, ¬IsMin a → motive (pred a)) (isPredPrelimit : ∀ a, IsPredPrelimit a → motive a)
theorem isPredPrelimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) :
isPredPrelimitRecOn (Order.pred b) pred isPredPrelimit = pred b hb :=
isSuccPrelimitRecOn_succ_of_not_isMax (α := αᵒᵈ) _ _ _
@[simp]
theorem isPredPrelimitRecOn_pred [NoMinOrder α] (b : α) :
isPredPrelimitRecOn (Order.pred b) pred isPredPrelimit = pred b (not_isMin b) :=
isPredPrelimitRecOn_pred_of_not_isMin _ _ _
end LinearOrder
end isPredPrelimitRecOn
section isSuccLimitRecOn
section PartialOrder
variable [PartialOrder α] [SuccOrder α]
(isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive (succ a))
(isSuccLimit : ∀ a, IsSuccLimit a → motive a)
variable (b) in
open Classical in
/-- A value can be built by building it on minimal elements, successors, and successor limits. -/
@[elab_as_elim]
noncomputable def isSuccLimitRecOn : motive b :=
isSuccPrelimitRecOn b succ fun a ha ↦
if h : IsMin a then isMin a h else isSuccLimit a (ha.isSuccLimit_of_not_isMin h)
@[simp]
theorem isSuccLimitRecOn_of_isSuccLimit (hb : IsSuccLimit b) :
isSuccLimitRecOn b isMin succ isSuccLimit = isSuccLimit b hb := by
rw [isSuccLimitRecOn, isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit,
dif_neg hb.not_isMin]
end PartialOrder
section LinearOrder
variable [LinearOrder α] [SuccOrder α]
(isMin : ∀ a, IsMin a → motive a) (succ : ∀ a, ¬IsMax a → motive (succ a))
(isSuccLimit : ∀ a, IsSuccLimit a → motive a)
theorem isSuccLimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) :
isSuccLimitRecOn (Order.succ b) isMin succ isSuccLimit = succ b hb := by
rw [isSuccLimitRecOn, isSuccPrelimitRecOn_succ_of_not_isMax]
@[simp]
theorem isSuccLimitRecOn_succ [NoMaxOrder α] (b : α) :
isSuccLimitRecOn (Order.succ b) isMin succ isSuccLimit = succ b (not_isMax b) :=
isSuccLimitRecOn_succ_of_not_isMax isMin succ isSuccLimit _
theorem isSuccLimitRecOn_of_isMin (hb : IsMin b) :
isSuccLimitRecOn b isMin succ isSuccLimit = isMin b hb := by
rw [isSuccLimitRecOn, isSuccPrelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_pos hb]
end LinearOrder
end isSuccLimitRecOn
section isPredLimitRecOn
section PartialOrder
variable [PartialOrder α] [PredOrder α]
(isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive (pred a))
(isPredLimit : ∀ a, IsPredLimit a → motive a)
variable (b) in
/-- A value can be built by building it on maximal elements, predecessors,
and predecessor limits. -/
@[elab_as_elim]
noncomputable def isPredLimitRecOn : motive b :=
isSuccLimitRecOn (α := αᵒᵈ) b isMax pred (fun a ha => isPredLimit a ha.dual)
@[simp]
theorem isPredLimitRecOn_of_isPredLimit (hb : IsPredLimit b) :
isPredLimitRecOn b isMax pred isPredLimit = isPredLimit b hb :=
isSuccLimitRecOn_of_isSuccLimit (α := αᵒᵈ) isMax pred _ hb.dual
end PartialOrder
section LinearOrder
variable [LinearOrder α] [PredOrder α]
(isMax : ∀ a, IsMax a → motive a) (pred : ∀ a, ¬IsMin a → motive (pred a))
(isPredLimit : ∀ a, IsPredLimit a → motive a)
theorem isPredLimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) :
isPredLimitRecOn (Order.pred b) isMax pred isPredLimit = pred b hb :=
isSuccLimitRecOn_succ_of_not_isMax (α := αᵒᵈ) isMax pred _ hb
@[simp]
theorem isPredLimitRecOn_pred [NoMinOrder α] :
isPredLimitRecOn (Order.pred b) isMax pred isPredLimit = pred b (not_isMin b) :=
isSuccLimitRecOn_succ (α := αᵒᵈ) isMax pred _ b
theorem isPredLimitRecOn_of_isMax (hb : IsMax b) :
isPredLimitRecOn b isMax pred isPredLimit = isMax b hb :=
isSuccLimitRecOn_of_isMin (α := αᵒᵈ) isMax pred _ hb
end LinearOrder
end isPredLimitRecOn
end Order
open Order
namespace SuccOrder
section prelimitRecOn
section PartialOrder
variable [PartialOrder α] [SuccOrder α] [WellFoundedLT α]
(succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a))
(isSuccPrelimit : ∀ a, IsSuccPrelimit a → (∀ b < a, motive b) → motive a)
variable (b) in
open Classical in
/-- Recursion principle on a well-founded partial `SuccOrder`. -/
@[elab_as_elim] noncomputable def prelimitRecOn : motive b :=
wellFounded_lt.fix
(fun a IH ↦ if h : IsSuccPrelimit a then isSuccPrelimit a h IH else
haveI H := Classical.choose_spec (not_isSuccPrelimit_iff.1 h)
cast (congr_arg motive H.2) (succ _ H.1 <| IH _ <| H.2.subst <| lt_succ_of_not_isMax H.1))
b
@[simp]
theorem prelimitRecOn_of_isSuccPrelimit (hb : IsSuccPrelimit b) :
prelimitRecOn b succ isSuccPrelimit =
isSuccPrelimit b hb fun x _ ↦ SuccOrder.prelimitRecOn x succ isSuccPrelimit := by
rw [prelimitRecOn, WellFounded.fix_eq, dif_pos hb]; rfl
end PartialOrder
section LinearOrder
variable [LinearOrder α] [SuccOrder α] [WellFoundedLT α]
(succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a))
(isSuccPrelimit : ∀ a, IsSuccPrelimit a → (∀ b < a, motive b) → motive a)
theorem prelimitRecOn_succ_of_not_isMax (hb : ¬IsMax b) :
prelimitRecOn (Order.succ b) succ isSuccPrelimit =
succ b hb (prelimitRecOn b succ isSuccPrelimit) := by
have h := not_isSuccPrelimit_succ_of_not_isMax hb
have H := Classical.choose_spec (not_isSuccPrelimit_iff.1 h)
rw [prelimitRecOn, WellFounded.fix_eq, dif_neg h]
have {a c : α} {ha hc} {x : ∀ a, motive a} (h : a = c) :
cast (congr_arg (motive ∘ Order.succ) h) (succ a ha (x a)) = succ c hc (x c) := by subst h; rfl
exact this <| (succ_eq_succ_iff_of_not_isMax H.1 hb).1 H.2
@[simp]
theorem prelimitRecOn_succ [NoMaxOrder α] (b : α) :
prelimitRecOn (Order.succ b) succ isSuccPrelimit =
succ b (not_isMax b) (prelimitRecOn b succ isSuccPrelimit) :=
prelimitRecOn_succ_of_not_isMax _ _ _
end LinearOrder
end prelimitRecOn
section limitRecOn
section PartialOrder
variable [PartialOrder α] [SuccOrder α] [WellFoundedLT α] (isMin : ∀ a, IsMin a → motive a)
(succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a))
(isSuccLimit : ∀ a, IsSuccLimit a → (∀ b < a, motive b) → motive a)
variable (b) in
open Classical in
/-- Recursion principle on a well-founded partial `SuccOrder`, separating out the case of a
minimal element. -/
@[elab_as_elim] noncomputable def limitRecOn : motive b :=
prelimitRecOn b succ fun a ha IH ↦
if h : IsMin a then isMin a h else isSuccLimit a (ha.isSuccLimit_of_not_isMin h) IH
@[simp]
theorem limitRecOn_isMin (hb : IsMin b) : limitRecOn b isMin succ isSuccLimit = isMin b hb := by
rw [limitRecOn, prelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_pos hb]
@[simp]
theorem limitRecOn_of_isSuccLimit (hb : IsSuccLimit b) :
limitRecOn b isMin succ isSuccLimit =
isSuccLimit b hb fun x _ ↦ limitRecOn x isMin succ isSuccLimit := by
rw [limitRecOn, prelimitRecOn_of_isSuccPrelimit _ _ hb.isSuccPrelimit, dif_neg hb.not_isMin]; rfl
end PartialOrder
section LinearOrder
variable [LinearOrder α] [SuccOrder α] [WellFoundedLT α] (isMin : ∀ a, IsMin a → motive a)
(succ : ∀ a, ¬IsMax a → motive a → motive (Order.succ a))
(isSuccLimit : ∀ a, IsSuccLimit a → (∀ b < a, motive b) → motive a)
theorem limitRecOn_succ_of_not_isMax (hb : ¬IsMax b) :
limitRecOn (Order.succ b) isMin succ isSuccLimit =
succ b hb (limitRecOn b isMin succ isSuccLimit) := by
rw [limitRecOn, prelimitRecOn_succ_of_not_isMax]; rfl
@[simp]
theorem limitRecOn_succ [NoMaxOrder α] (b : α) :
limitRecOn (Order.succ b) isMin succ isSuccLimit =
succ b (not_isMax b) (limitRecOn b isMin succ isSuccLimit) :=
limitRecOn_succ_of_not_isMax isMin succ isSuccLimit _
end LinearOrder
end limitRecOn
end SuccOrder
namespace PredOrder
section prelimitRecOn
section PartialOrder
variable [PartialOrder α] [PredOrder α] [WellFoundedGT α]
(pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a))
(isPredPrelimit : ∀ a, IsPredPrelimit a → (∀ b > a, motive b) → motive a)
variable (b) in
/-- Recursion principle on a well-founded partial `PredOrder`. -/
@[elab_as_elim] noncomputable def prelimitRecOn : motive b :=
SuccOrder.prelimitRecOn (α := αᵒᵈ) b pred (fun a ha => isPredPrelimit a ha.dual)
@[simp]
theorem prelimitRecOn_of_isPredPrelimit (hb : IsPredPrelimit b) :
prelimitRecOn b pred isPredPrelimit =
isPredPrelimit b hb fun x _ ↦ prelimitRecOn x pred isPredPrelimit :=
SuccOrder.prelimitRecOn_of_isSuccPrelimit _ _ hb.dual
end PartialOrder
section LinearOrder
variable [LinearOrder α] [PredOrder α] [WellFoundedGT α]
(pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a))
(isPredPrelimit : ∀ a, IsPredPrelimit a → (∀ b > a, motive b) → motive a)
theorem prelimitRecOn_pred_of_not_isMin (hb : ¬IsMin b) :
prelimitRecOn (Order.pred b) pred isPredPrelimit =
pred b hb (prelimitRecOn b pred isPredPrelimit) :=
SuccOrder.prelimitRecOn_succ_of_not_isMax _ _ _
@[simp]
theorem prelimitRecOn_pred [NoMinOrder α] (b : α) :
prelimitRecOn (Order.pred b) pred isPredPrelimit =
pred b (not_isMin b) (prelimitRecOn b pred isPredPrelimit) :=
prelimitRecOn_pred_of_not_isMin _ _ _
end LinearOrder
end prelimitRecOn
section limitRecOn
section PartialOrder
variable [PartialOrder α] [PredOrder α] [WellFoundedGT α] (isMax : ∀ a, IsMax a → motive a)
(pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a))
(isPredLimit : ∀ a, IsPredLimit a → (∀ b > a, motive b) → motive a)
variable (b) in
open Classical in
/-- Recursion principle on a well-founded partial `PredOrder`, separating out the case of a
maximal element. -/
@[elab_as_elim] noncomputable def limitRecOn : motive b :=
SuccOrder.limitRecOn (α := αᵒᵈ) b isMax pred (fun a ha => isPredLimit a ha.dual)
@[simp]
theorem limitRecOn_isMax (hb : IsMax b) : limitRecOn b isMax pred isPredLimit = isMax b hb :=
SuccOrder.limitRecOn_isMin (α := αᵒᵈ) isMax pred _ hb
@[simp]
theorem limitRecOn_of_isPredLimit (hb : IsPredLimit b) :
limitRecOn b isMax pred isPredLimit =
isPredLimit b hb fun x _ ↦ limitRecOn x isMax pred isPredLimit :=
SuccOrder.limitRecOn_of_isSuccLimit (α := αᵒᵈ) isMax pred _ hb.dual
end PartialOrder
section LinearOrder
variable [LinearOrder α] [PredOrder α] [WellFoundedGT α] (isMax : ∀ a, IsMax a → motive a)
(pred : ∀ a, ¬IsMin a → motive a → motive (Order.pred a))
(isPredLimit : ∀ a, IsPredLimit a → (∀ b > a, motive b) → motive a)
theorem limitRecOn_pred_of_not_isMin (hb : ¬IsMin b) :
limitRecOn (Order.pred b) isMax pred isPredLimit =
pred b hb (limitRecOn b isMax pred isPredLimit) :=
SuccOrder.limitRecOn_succ_of_not_isMax (α := αᵒᵈ) isMax pred _ hb
@[simp]
theorem limitRecOn_pred [NoMinOrder α] (b : α) :
limitRecOn (Order.pred b) isMax pred isPredLimit =
pred b (not_isMin b) (limitRecOn b isMax pred isPredLimit) :=
SuccOrder.limitRecOn_succ (α := αᵒᵈ) isMax pred _ b
end LinearOrder
end limitRecOn
end PredOrder
|
Internal.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.TensorProduct.Graded.External
import Mathlib.RingTheory.GradedAlgebra.Basic
/-!
# Graded tensor products over graded algebras
The graded tensor product $A \hat\otimes_R B$ is imbued with a multiplication defined on homogeneous
tensors by:
$$(a \otimes b) \cdot (a' \otimes b') = (-1)^{\deg a' \deg b} (a \cdot a') \otimes (b \cdot b')$$
where $A$ and $B$ are algebras graded by `ℕ`, `ℤ`, or `ι` (or more generally, any index
that satisfies `Module ι (Additive ℤˣ)`).
## Main results
* `GradedTensorProduct R 𝒜 ℬ`: for families of submodules of `A` and `B` that form a graded algebra,
this is a type alias for `A ⊗[R] B` with the appropriate multiplication.
* `GradedTensorProduct.instAlgebra`: the ring structure induced by this multiplication.
* `GradedTensorProduct.liftEquiv`: a universal property for graded tensor products
## Notation
* `𝒜 ᵍ⊗[R] ℬ` is notation for `GradedTensorProduct R 𝒜 ℬ`.
* `a ᵍ⊗ₜ b` is notation for `GradedTensorProduct.tmul _ a b`.
## References
* https://math.stackexchange.com/q/202718/1896
* [*Algebra I*, Bourbaki : Chapter III, §4.7, example (2)][bourbaki1989]
## Implementation notes
We cannot put the multiplication on `A ⊗[R] B` directly as it would conflict with the existing
multiplication defined without the $(-1)^{\deg a' \deg b}$ term. Furthermore, the ring `A` may not
have a unique graduation, and so we need the chosen graduation `𝒜` to appear explicitly in the
type.
## TODO
* Show that the tensor product of graded algebras is itself a graded algebra.
* Determine if replacing the synonym with a single-field structure improves performance.
-/
suppress_compilation
open scoped TensorProduct
variable {R ι A B : Type*}
variable [CommSemiring ι] [DecidableEq ι]
variable [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B]
variable (𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B)
variable [GradedAlgebra 𝒜] [GradedAlgebra ℬ]
open DirectSum
variable (R) in
/-- A Type synonym for `A ⊗[R] B`, but with multiplication as `TensorProduct.gradedMul`.
This has notation `𝒜 ᵍ⊗[R] ℬ`. -/
@[nolint unusedArguments]
def GradedTensorProduct
(𝒜 : ι → Submodule R A) (ℬ : ι → Submodule R B)
[GradedAlgebra 𝒜] [GradedAlgebra ℬ] :
Type _ :=
A ⊗[R] B
namespace GradedTensorProduct
open TensorProduct
@[inherit_doc GradedTensorProduct]
scoped[TensorProduct] notation:100 𝒜 " ᵍ⊗[" R "] " ℬ:100 => GradedTensorProduct R 𝒜 ℬ
instance instAddCommGroupWithOne : AddCommGroupWithOne (𝒜 ᵍ⊗[R] ℬ) :=
Algebra.TensorProduct.instAddCommGroupWithOne
instance : Module R (𝒜 ᵍ⊗[R] ℬ) := TensorProduct.leftModule
variable (R) in
/-- The casting equivalence to move between regular and graded tensor products. -/
def of : A ⊗[R] B ≃ₗ[R] 𝒜 ᵍ⊗[R] ℬ := LinearEquiv.refl _ _
@[simp]
theorem of_one : of R 𝒜 ℬ 1 = 1 := rfl
@[simp]
theorem of_symm_one : (of R 𝒜 ℬ).symm 1 = 1 := rfl
@[simp]
theorem of_symm_of (x : A ⊗[R] B) : (of R 𝒜 ℬ).symm (of R 𝒜 ℬ x) = x := rfl
@[simp]
theorem symm_of_of (x : 𝒜 ᵍ⊗[R] ℬ) : of R 𝒜 ℬ ((of R 𝒜 ℬ).symm x) = x := rfl
/-- Two linear maps from the graded tensor product agree if they agree on the underlying tensor
product. -/
@[ext]
theorem hom_ext {M} [AddCommMonoid M] [Module R M] ⦃f g : 𝒜 ᵍ⊗[R] ℬ →ₗ[R] M⦄
(h : f ∘ₗ of R 𝒜 ℬ = (g ∘ₗ of R 𝒜 ℬ : A ⊗[R] B →ₗ[R] M)) :
f = g :=
h
variable (R) {𝒜 ℬ} in
/-- The graded tensor product of two elements of graded rings. -/
abbrev tmul (a : A) (b : B) : 𝒜 ᵍ⊗[R] ℬ := of R 𝒜 ℬ (a ⊗ₜ b)
@[inherit_doc]
notation:100 x " ᵍ⊗ₜ" y:100 => tmul _ x y
@[inherit_doc]
notation:100 x " ᵍ⊗ₜ[" R "] " y:100 => tmul R x y
variable (R) in
/-- An auxiliary construction to move between the graded tensor product of internally-graded objects
and the tensor product of direct sums. -/
noncomputable def auxEquiv : (𝒜 ᵍ⊗[R] ℬ) ≃ₗ[R] (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i) :=
let fA := (decomposeAlgEquiv 𝒜).toLinearEquiv
let fB := (decomposeAlgEquiv ℬ).toLinearEquiv
(of R 𝒜 ℬ).symm.trans (TensorProduct.congr fA fB)
theorem auxEquiv_tmul (a : A) (b : B) :
auxEquiv R 𝒜 ℬ (a ᵍ⊗ₜ b) = decompose 𝒜 a ⊗ₜ decompose ℬ b := rfl
theorem auxEquiv_one : auxEquiv R 𝒜 ℬ 1 = 1 := by
rw [← of_one, Algebra.TensorProduct.one_def, auxEquiv_tmul 𝒜 ℬ, DirectSum.decompose_one,
DirectSum.decompose_one, Algebra.TensorProduct.one_def]
theorem auxEquiv_symm_one : (auxEquiv R 𝒜 ℬ).symm 1 = 1 :=
(LinearEquiv.symm_apply_eq _).mpr (auxEquiv_one _ _).symm
variable [Module ι (Additive ℤˣ)]
/-- Auxiliary construction used to build the `Mul` instance and get distributivity of `+` and
`\smul`. -/
noncomputable def mulHom : (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) →ₗ[R] (𝒜 ᵍ⊗[R] ℬ) := by
letI fAB1 := auxEquiv R 𝒜 ℬ
have := ((gradedMul R (𝒜 ·) (ℬ ·)).compl₁₂ fAB1.toLinearMap fAB1.toLinearMap).compr₂
fAB1.symm.toLinearMap
exact this
theorem mulHom_apply (x y : 𝒜 ᵍ⊗[R] ℬ) :
mulHom 𝒜 ℬ x y
= (auxEquiv R 𝒜 ℬ).symm (gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y)) :=
rfl
/-- The multiplication on the graded tensor product.
See `GradedTensorProduct.coe_mul_coe` for a characterization on pure tensors. -/
instance : Mul (𝒜 ᵍ⊗[R] ℬ) where mul x y := mulHom 𝒜 ℬ x y
theorem mul_def (x y : 𝒜 ᵍ⊗[R] ℬ) : x * y = mulHom 𝒜 ℬ x y := rfl
-- Before https://github.com/leanprover-community/mathlib4/pull/8386 this was `@[simp]` but it times out when we try to apply it.
theorem auxEquiv_mul (x y : 𝒜 ᵍ⊗[R] ℬ) :
auxEquiv R 𝒜 ℬ (x * y) = gradedMul R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) (auxEquiv R 𝒜 ℬ y) :=
LinearEquiv.eq_symm_apply _ |>.mp rfl
instance instMonoid : Monoid (𝒜 ᵍ⊗[R] ℬ) where
mul_one x := by
rw [mul_def, mulHom_apply, auxEquiv_one, gradedMul_one, LinearEquiv.symm_apply_apply]
one_mul x := by
rw [mul_def, mulHom_apply, auxEquiv_one, one_gradedMul, LinearEquiv.symm_apply_apply]
mul_assoc x y z := by
simp_rw [mul_def, mulHom_apply, LinearEquiv.apply_symm_apply]
rw [gradedMul_assoc]
instance instRing : Ring (𝒜 ᵍ⊗[R] ℬ) where
__ := instAddCommGroupWithOne 𝒜 ℬ
__ := instMonoid 𝒜 ℬ
right_distrib x y z := by simp_rw [mul_def, LinearMap.map_add₂]
left_distrib x y z := by simp_rw [mul_def, map_add]
mul_zero x := by simp_rw [mul_def, map_zero]
zero_mul x := by simp_rw [mul_def, LinearMap.map_zero₂]
/-- The characterization of this multiplication on partially homogeneous elements. -/
theorem tmul_coe_mul_coe_tmul {j₁ i₂ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
(-1 : ℤˣ)^(j₁ * i₂) • ((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by
dsimp only [mul_def, mulHom_apply, of_symm_of]
dsimp [auxEquiv, tmul]
rw [decompose_coe, decompose_coe]
simp_rw [← lof_eq_of R]
rw [tmul_of_gradedMul_of_tmul]
simp_rw [lof_eq_of R]
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to `LinearEquiv.map_smul`
rw [@Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, map_smul,
Int.cast_smul_eq_zsmul R, ← @Units.smul_def _ _ (_) (_)]
rw [congr_symm_tmul]
dsimp
simp_rw [decompose_symm_mul, decompose_symm_of, Equiv.symm_apply_apply]
/-- A special case for when `b₁` has grade 0. -/
theorem tmul_zero_coe_mul_coe_tmul {i₂ : ι} (a₁ : A) (b₁ : ℬ 0) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by
rw [tmul_coe_mul_coe_tmul, zero_mul, uzpow_zero, one_smul]
/-- A special case for when `a₂` has grade 0. -/
theorem tmul_coe_mul_zero_coe_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (a₂ : 𝒜 0) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) =
((a₁ * a₂ : A) ᵍ⊗ₜ (b₁ * b₂ : B)) := by
rw [tmul_coe_mul_coe_tmul, mul_zero, uzpow_zero, one_smul]
theorem tmul_one_mul_coe_tmul {i₂ : ι} (a₁ : A) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (1 : B) * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ * a₂ : A) ᵍ⊗ₜ (b₂ : B) := by
convert tmul_zero_coe_mul_coe_tmul 𝒜 ℬ a₁ (@GradedMonoid.GOne.one _ (ℬ ·) _ _) a₂ b₂
rw [SetLike.coe_gOne, one_mul]
theorem tmul_coe_mul_one_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * (1 : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ : A) ᵍ⊗ₜ (b₁ * b₂ : B) := by
convert tmul_coe_mul_zero_coe_tmul 𝒜 ℬ a₁ b₁ (@GradedMonoid.GOne.one _ (𝒜 ·) _ _) b₂
rw [SetLike.coe_gOne, mul_one]
theorem tmul_one_mul_one_tmul (a₁ : A) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (1 : B) * (1 : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ) = (a₁ : A) ᵍ⊗ₜ (b₂ : B) := by
convert tmul_coe_mul_zero_coe_tmul 𝒜 ℬ
a₁ (GradedMonoid.GOne.one (A := (ℬ ·))) (GradedMonoid.GOne.one (A := (𝒜 ·))) b₂
· rw [SetLike.coe_gOne, mul_one]
· rw [SetLike.coe_gOne, one_mul]
/-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
@[simps]
def includeLeftRingHom : A →+* 𝒜 ᵍ⊗[R] ℬ where
toFun a := a ᵍ⊗ₜ 1
map_zero' := by simp
map_add' := by simp [tmul, TensorProduct.add_tmul]
map_one' := rfl
map_mul' a₁ a₂ := by
classical
rw [← DirectSum.sum_support_decompose 𝒜 a₂, Finset.mul_sum]
simp_rw [tmul, sum_tmul, map_sum, Finset.mul_sum]
congr
ext i
rw [← SetLike.coe_gOne ℬ, tmul_coe_mul_coe_tmul, zero_mul, uzpow_zero, one_smul,
SetLike.coe_gOne, one_mul]
instance instAlgebra : Algebra R (𝒜 ᵍ⊗[R] ℬ) where
algebraMap := (includeLeftRingHom 𝒜 ℬ).comp (algebraMap R A)
commutes' r x := by
dsimp [mul_def, mulHom_apply, auxEquiv_tmul]
simp_rw [DirectSum.decompose_algebraMap, DirectSum.decompose_one, algebraMap_gradedMul,
gradedMul_algebraMap]
smul_def' r x := by
dsimp [mul_def, mulHom_apply, auxEquiv_tmul]
simp_rw [DirectSum.decompose_algebraMap, DirectSum.decompose_one, algebraMap_gradedMul]
-- Qualified `map_smul` to avoid a TC timeout https://github.com/leanprover-community/mathlib4/pull/8386
rw [LinearEquiv.map_smul]
simp
lemma algebraMap_def (r : R) : algebraMap R (𝒜 ᵍ⊗[R] ℬ) r = algebraMap R A r ᵍ⊗ₜ[R] 1 := rfl
theorem tmul_algebraMap_mul_coe_tmul {i₂ : ι} (a₁ : A) (r : R) (a₂ : 𝒜 i₂) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] algebraMap R B r * (a₂ : A) ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ)
= (a₁ * a₂ : A) ᵍ⊗ₜ (algebraMap R B r * b₂ : B) :=
tmul_zero_coe_mul_coe_tmul 𝒜 ℬ a₁ (GAlgebra.toFun (A := (ℬ ·)) r) a₂ b₂
theorem tmul_coe_mul_algebraMap_tmul {j₁ : ι} (a₁ : A) (b₁ : ℬ j₁) (r : R) (b₂ : B) :
(a₁ ᵍ⊗ₜ[R] (b₁ : B) * algebraMap R A r ᵍ⊗ₜ[R] b₂ : 𝒜 ᵍ⊗[R] ℬ)
= (a₁ * algebraMap R A r : A) ᵍ⊗ₜ (b₁ * b₂ : B) :=
tmul_coe_mul_zero_coe_tmul 𝒜 ℬ a₁ b₁ (GAlgebra.toFun (A := (𝒜 ·)) r) b₂
/-- The algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
@[simps!]
def includeLeft : A →ₐ[R] 𝒜 ᵍ⊗[R] ℬ where
toRingHom := includeLeftRingHom 𝒜 ℬ
commutes' _ := rfl
/-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/
@[simps!]
def includeRight : B →ₐ[R] (𝒜 ᵍ⊗[R] ℬ) :=
AlgHom.ofLinearMap (R := R) (A := B) (B := 𝒜 ᵍ⊗[R] ℬ)
(f := {
toFun := fun b => 1 ᵍ⊗ₜ b
map_add' := by simp [tmul, TensorProduct.tmul_add]
map_smul' := by simp [tmul, TensorProduct.tmul_smul] })
(map_one := rfl)
(map_mul := by
rw [LinearMap.map_mul_iff]
refine DirectSum.decompose_lhom_ext ℬ fun i₁ => ?_
ext b₁ b₂ : 2
dsimp
rw [tmul_coe_mul_one_tmul])
lemma algebraMap_def' (r : R) : algebraMap R (𝒜 ᵍ⊗[R] ℬ) r = 1 ᵍ⊗ₜ[R] algebraMap R B r :=
(includeRight 𝒜 ℬ).commutes r |>.symm
variable {C} [Ring C] [Algebra R C]
/-- The forwards direction of the universal property; an algebra morphism out of the graded tensor
product can be assembled from maps on each component that (anti)commute on pure elements of the
corresponding graded algebras. -/
def lift (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(h_anti_commutes : ∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), f a * g b = (-1 : ℤˣ) ^ (j * i) • (g b * f a)) :
(𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C :=
AlgHom.ofLinearMap
(LinearMap.mul' R C
∘ₗ (TensorProduct.map f.toLinearMap g.toLinearMap)
∘ₗ ((of R 𝒜 ℬ).symm : 𝒜 ᵍ⊗[R] ℬ →ₗ[R] A ⊗[R] B))
(by
dsimp [Algebra.TensorProduct.one_def]
simp only [map_one, mul_one])
(by
rw [LinearMap.map_mul_iff]
ext a₁ : 3
refine DirectSum.decompose_lhom_ext ℬ fun j₁ => ?_
ext b₁ : 3
refine DirectSum.decompose_lhom_ext 𝒜 fun i₂ => ?_
ext a₂ b₂ : 2
dsimp
rw [tmul_coe_mul_coe_tmul]
rw [@Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R, map_smul, map_smul, map_smul]
rw [Int.cast_smul_eq_zsmul R, ← @Units.smul_def _ _ (_) (_)]
rw [of_symm_of, map_tmul, LinearMap.mul'_apply]
simp_rw [AlgHom.toLinearMap_apply, map_mul]
simp_rw [mul_assoc (f a₁), ← mul_assoc _ _ (g b₂), h_anti_commutes, mul_smul_comm,
smul_mul_assoc, smul_smul, Int.units_mul_self, one_smul])
@[simp]
theorem lift_tmul (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(h_anti_commutes : ∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), f a * g b = (-1 : ℤˣ) ^ (j * i) • (g b * f a))
(a : A) (b : B) :
lift 𝒜 ℬ f g h_anti_commutes (a ᵍ⊗ₜ b) = f a * g b :=
rfl
/-- The universal property of the graded tensor product; every algebra morphism uniquely factors
as a pair of algebra morphisms that anticommute with respect to the grading. -/
def liftEquiv :
{ fg : (A →ₐ[R] C) × (B →ₐ[R] C) //
∀ ⦃i j⦄ (a : 𝒜 i) (b : ℬ j), fg.1 a * fg.2 b = (-1 : ℤˣ)^(j * i) • (fg.2 b * fg.1 a)} ≃
((𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C) where
toFun fg := lift 𝒜 ℬ _ _ fg.prop
invFun F := ⟨(F.comp (includeLeft 𝒜 ℬ), F.comp (includeRight 𝒜 ℬ)), fun i j a b => by
dsimp
rw [← map_mul, ← map_mul F, tmul_coe_mul_coe_tmul, one_mul, mul_one, AlgHom.map_smul_of_tower,
tmul_one_mul_one_tmul, smul_smul, Int.units_mul_self, one_smul]⟩
left_inv fg := by ext <;> (dsimp; simp only [map_one, mul_one, one_mul])
right_inv F := by
apply AlgHom.toLinearMap_injective
ext
dsimp
rw [← map_mul, tmul_one_mul_one_tmul]
/-- Two algebra morphism from the graded tensor product agree if their compositions with the left
and right inclusions agree. -/
@[ext]
lemma algHom_ext ⦃f g : (𝒜 ᵍ⊗[R] ℬ) →ₐ[R] C⦄
(ha : f.comp (includeLeft 𝒜 ℬ) = g.comp (includeLeft 𝒜 ℬ))
(hb : f.comp (includeRight 𝒜 ℬ) = g.comp (includeRight 𝒜 ℬ)) : f = g :=
(liftEquiv 𝒜 ℬ).symm.injective <| Subtype.ext <| Prod.ext ha hb
/-- The non-trivial symmetric braiding, sending $a \otimes b$ to
$(-1)^{\deg a' \deg b} (b \otimes a)$. -/
def comm : (𝒜 ᵍ⊗[R] ℬ) ≃ₐ[R] (ℬ ᵍ⊗[R] 𝒜) :=
AlgEquiv.ofLinearEquiv
(auxEquiv R 𝒜 ℬ ≪≫ₗ gradedComm R _ _ ≪≫ₗ (auxEquiv R ℬ 𝒜).symm)
(by
dsimp
simp_rw [auxEquiv_one, gradedComm_one, auxEquiv_symm_one])
(fun x y => by
dsimp
simp_rw [auxEquiv_mul, gradedComm_gradedMul, LinearEquiv.symm_apply_eq,
← gradedComm_gradedMul, auxEquiv_mul, LinearEquiv.apply_symm_apply, gradedComm_gradedMul])
lemma auxEquiv_comm (x : 𝒜 ᵍ⊗[R] ℬ) :
auxEquiv R ℬ 𝒜 (comm 𝒜 ℬ x) = gradedComm R (𝒜 ·) (ℬ ·) (auxEquiv R 𝒜 ℬ x) :=
LinearEquiv.eq_symm_apply _ |>.mp rfl
@[simp] lemma comm_coe_tmul_coe {i j : ι} (a : 𝒜 i) (b : ℬ j) :
comm 𝒜 ℬ (a ᵍ⊗ₜ b) = (-1 : ℤˣ)^(j * i) • (b ᵍ⊗ₜ a : ℬ ᵍ⊗[R] 𝒜) :=
(auxEquiv R ℬ 𝒜).injective <| by
simp_rw [auxEquiv_comm, auxEquiv_tmul, decompose_coe, ← lof_eq_of R, gradedComm_of_tmul_of,
@Units.smul_def _ _ (_) (_), ← Int.cast_smul_eq_zsmul R]
-- Qualified `map_smul` to avoid a TC timeout https://github.com/leanprover-community/mathlib4/pull/8386
rw [LinearEquiv.map_smul, auxEquiv_tmul]
simp_rw [decompose_coe, lof_eq_of]
end GradedTensorProduct
|
mxpoly.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq.
From mathcomp Require Import div fintype tuple finfun bigop fingroup perm.
From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv.
(******************************************************************************)
(* This file provides basic support for formal computation with matrices, *)
(* mainly results combining matrices and univariate polynomials, such as the *)
(* Cayley-Hamilton theorem; it also contains an extension of the first order *)
(* representation of algebra introduced in ssralg (GRing.term/formula). *)
(* rVpoly v == the little-endian decoding of the row vector v as a *)
(* polynomial p = \sum_i (v 0 i)%:P * 'X^i. *)
(* poly_rV p == the partial inverse to rVpoly, for polynomials of degree *)
(* less than d to 'rV_d (d is inferred from the context). *)
(* Sylvester_mx p q == the Sylvester matrix of p and q. *)
(* resultant p q == the resultant of p and q, i.e., \det (Sylvester_mx p q). *)
(* horner_mx A == the morphism from {poly R} to 'M_n (n of the form n'.+1) *)
(* mapping a (scalar) polynomial p to the value of its *)
(* scalar matrix interpretation at A (this is an instance of *)
(* the generic horner_morph construct defined in poly). *)
(* powers_mx A d == the d x (n ^ 2) matrix whose rows are the mxvec encodings *)
(* of the first d powers of A (n of the form n'.+1). Thus, *)
(* vec_mx (v *m powers_mx A d) = horner_mx A (rVpoly v). *)
(* char_poly A == the characteristic polynomial of A. *)
(* char_poly_mx A == a matrix whose determinant is char_poly A. *)
(* companionmx p == a matrix whose char_poly is p *)
(* mxminpoly A == the minimal polynomial of A, i.e., the smallest monic *)
(* polynomial that annihilates A (A must be nontrivial). *)
(* degree_mxminpoly A == the (positive) degree of mxminpoly A. *)
(* mx_inv_horner A == the inverse of horner_mx A for polynomials of degree *)
(* smaller than degree_mxminpoly A. *)
(* kermxpoly g p == the kernel of p(g) *)
(* geigenspace g a == the generalized eigenspace of g for eigenvalue a *)
(* := kermxpoly g ('X ^ n - a%:P) where g : 'M_n *)
(* eigenpoly g p <=> p is an eigen polynomial for g, i.e. kermxpoly g p != 0 *)
(* integralOver RtoK u <-> u is in the integral closure of the image of R *)
(* under RtoK : R -> K, i.e. u is a root of the image of a *)
(* monic polynomial in R. *)
(* algebraicOver FtoE u <-> u : E is algebraic over E; it is a root of the *)
(* image of a nonzero polynomial under FtoE; as F must be a *)
(* fieldType, this is equivalent to integralOver FtoE u. *)
(* integralRange RtoK <-> the integral closure of the image of R contains *)
(* all of K (:= forall u, integralOver RtoK u). *)
(* This toolkit for building formal matrix expressions is packaged in the *)
(* MatrixFormula submodule, and comprises the following: *)
(* eval_mx e == GRing.eval lifted to matrices (:= map_mx (GRing.eval e)). *)
(* mx_term A == GRing.Const lifted to matrices. *)
(* mulmx_term A B == the formal product of two matrices of terms. *)
(* mxrank_form m A == a GRing.formula asserting that the interpretation of *)
(* the term matrix A has rank m. *)
(* submx_form A B == a GRing.formula asserting that the row space of the *)
(* interpretation of the term matrix A is included in the *)
(* row space of the interpretation of B. *)
(* seq_of_rV v == the seq corresponding to a row vector. *)
(* row_env e == the flattening of a tensored environment e : seq 'rV_d. *)
(* row_var F d k == the term vector of width d such that for e : seq 'rV[F]_d *)
(* we have eval e 'X_k = eval_mx (row_env e) (row_var d k). *)
(* conjmx V f := V *m f *m pinvmx V *)
(* == the conjugation of f by V, i.e. "the" matrix of f *)
(* in the basis of row vectors of V. *)
(* Although this makes sense only when f stabilizes V, *)
(* the definition can be stated more generally. *)
(* restrictmx V := conjmx (row_base V) *)
(* A ~_P {in S'} == where P is a base change matrix, A is a matrix, and S *)
(* is a boolean predicate representing a set of matrices, *)
(* this states that conjmx P A is in S, *)
(* which means A is similar to a matrix in S. *)
(* From the latter, we derive several related notions: *)
(* A ~_P B := A ~_P {in pred1 B} *)
(* A is similar to B, with base change matrix P *)
(* A ~_{in S} B := exists P, P \in S /\ A ~_P B *)
(* == A is similar to B, with a base change matrix in S *)
(* A ~_{in S} {in S'} := exists P, P \in S /\ A ~_P {in S'} *)
(* == A is similar to a matrix in the class S', *)
(* with a base change matrix in S *)
(* all_simmx_in S As S' == all the matrices in the sequence As are *)
(* similar to some matrix in the predicate S', *)
(* with a base change matrix in S. *)
(* *)
(* We also specialize the class S' to diagonalizability: *)
(* diagonalizable_for P A := A ~_P {in is_diag_mx}. *)
(* diagonalizable_in S A := A ~_{in S} {in is_diag_mx}. *)
(* diagonalizable A := diagonalizable_in unitmx A. *)
(* codiagonalizable_in S As := all_simmx_in S As is_diag_mx. *)
(* codiagonalizable As := codiagonalizable_in unitmx As. *)
(* *)
(* The main results in diagnonalization theory are: *)
(* - diagonalizablePeigen: *)
(* a matrix is diagonalizable iff there is a sequence *)
(* of scalars r, such that the sum of the associated *)
(* eigenspaces is full. *)
(* - diagonalizableP: *)
(* a matrix is diagonalizable iff its minimal polynomial *)
(* divides a split polynomial with simple roots. *)
(* - codiagonalizableP: *)
(* a sequence of matrices are diagonalizable in the same basis *)
(* iff they are all diagonalizable and commute pairwize. *)
(* *)
(* Naming conventions: *)
(* - p, q are polynomials *)
(* - A, B, C are matrices *)
(* - f, g are matrices that are viewed as linear maps *)
(* - V, W are matrices that are viewed as subspaces *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory.
Import Monoid.Theory.
Local Open Scope ring_scope.
Import Pdiv.Idomain.
(* Row vector <-> bounded degree polynomial bijection *)
Section RowPoly.
Variables (R : nzRingType) (d : nat).
Implicit Types u v : 'rV[R]_d.
Implicit Types p q : {poly R}.
Definition rVpoly v := \poly_(k < d) (if insub k is Some i then v 0 i else 0).
Definition poly_rV p := \row_(i < d) p`_i.
Lemma coef_rVpoly v k : (rVpoly v)`_k = if insub k is Some i then v 0 i else 0.
Proof. by rewrite coef_poly; case: insubP => [i ->|]; rewrite ?if_same. Qed.
Lemma coef_rVpoly_ord v (i : 'I_d) : (rVpoly v)`_i = v 0 i.
Proof. by rewrite coef_rVpoly valK. Qed.
Lemma rVpoly_delta i : rVpoly (delta_mx 0 i) = 'X^i.
Proof.
apply/polyP=> j; rewrite coef_rVpoly coefXn.
case: insubP => [k _ <- | j_ge_d]; first by rewrite mxE.
by case: eqP j_ge_d => // ->; rewrite ltn_ord.
Qed.
Lemma rVpolyK : cancel rVpoly poly_rV.
Proof. by move=> u; apply/rowP=> i; rewrite mxE coef_rVpoly_ord. Qed.
Lemma poly_rV_K p : size p <= d -> rVpoly (poly_rV p) = p.
Proof.
move=> le_p_d; apply/polyP=> k; rewrite coef_rVpoly.
case: insubP => [i _ <- | ]; first by rewrite mxE.
by rewrite -ltnNge => le_d_l; rewrite nth_default ?(leq_trans le_p_d).
Qed.
Lemma poly_rV_is_linear : linear poly_rV.
Proof. by move=> a p q; apply/rowP=> i; rewrite !mxE coefD coefZ. Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} 'rV_d _ poly_rV
(GRing.semilinear_linear poly_rV_is_linear).
Lemma rVpoly_is_linear : linear rVpoly.
Proof.
move=> a u v; apply/polyP=> k; rewrite coefD coefZ !coef_rVpoly.
by case: insubP => [i _ _ | _]; rewrite ?mxE // mulr0 addr0.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R 'rV_d {poly R} _ rVpoly
(GRing.semilinear_linear rVpoly_is_linear).
End RowPoly.
Prenex Implicits rVpoly rVpolyK.
Arguments poly_rV {R d}.
Arguments poly_rV_K {R d} [p] le_p_d.
Section Resultant.
Variables (R : nzRingType) (p q : {poly R}).
Let dS := ((size q).-1 + (size p).-1)%N.
Local Notation band r := (lin1_mx (poly_rV \o r \o* rVpoly)).
Definition Sylvester_mx : 'M[R]_dS := col_mx (band p) (band q).
Lemma Sylvester_mxE (i j : 'I_dS) :
let S_ r k := r`_(j - k) *+ (k <= j) in
Sylvester_mx i j = match split i with inl k => S_ p k | inr k => S_ q k end.
Proof.
move=> S_ /[1!mxE]; case: {i}(split i) => i /[!mxE]/=;
by rewrite rVpoly_delta coefXnM ltnNge if_neg -mulrb.
Qed.
Definition resultant := \det Sylvester_mx.
End Resultant.
Prenex Implicits Sylvester_mx resultant.
Lemma resultant_in_ideal (R : comNzRingType) (p q : {poly R}) :
size p > 1 -> size q > 1 ->
{uv : {poly R} * {poly R} | size uv.1 < size q /\ size uv.2 < size p
& (resultant p q)%:P = uv.1 * p + uv.2 * q}.
Proof.
move=> p_nc q_nc; pose dp := (size p).-1; pose dq := (size q).-1.
pose S := Sylvester_mx p q; pose dS := (dq + dp)%N.
have dS_gt0: dS > 0 by rewrite /dS /dq -(subnKC q_nc).
pose j0 := Ordinal dS_gt0.
pose Ss0 := col_mx (p *: \col_(i < dq) 'X^i) (q *: \col_(i < dp) 'X^i).
pose Ss := \matrix_(i, j) (if j == j0 then Ss0 i 0 else (S i j)%:P).
pose u ds s := \sum_(i < ds) cofactor Ss (s i) j0 * 'X^i.
exists (u _ (lshift dp), u _ ((rshift dq) _)).
suffices sz_u ds s: ds > 1 -> size (u ds.-1 s) < ds by rewrite !sz_u.
move/ltn_predK=> {2}<-; apply: leq_trans (size_sum _ _ _) _.
apply/bigmax_leqP=> i _.
have ->: cofactor Ss (s i) j0 = (cofactor S (s i) j0)%:P.
rewrite rmorphM /= rmorph_sign -det_map_mx; congr (_ * \det _).
by apply/matrixP=> i' j'; rewrite !mxE.
apply: leq_trans (size_polyMleq _ _) (leq_trans _ (valP i)).
by rewrite size_polyC size_polyXn addnS /= -add1n leq_add2r leq_b1.
transitivity (\det Ss); last first.
rewrite (expand_det_col Ss j0) big_split_ord !big_distrl /=.
by congr (_ + _); apply: eq_bigr => i _;
rewrite mxE eqxx (col_mxEu, col_mxEd) !mxE mulrC mulrA mulrAC.
pose S_ j1 := map_mx polyC (\matrix_(i, j) S i (if j == j0 then j1 else j)).
pose Ss0_ i dj := \poly_(j < dj) S i (insubd j0 j).
pose Ss_ dj := \matrix_(i, j) (if j == j0 then Ss0_ i dj else (S i j)%:P).
have{Ss u} ->: Ss = Ss_ dS.
apply/matrixP=> i j; rewrite mxE [in RHS]mxE; case: (j == j0) => {j}//.
apply/polyP=> k; rewrite coef_poly Sylvester_mxE mxE.
have [k_ge_dS | k_lt_dS] := leqP dS k.
case: (split i) => {}i; rewrite !mxE coefMXn;
case: ifP => // /negbT; rewrite -ltnNge ltnS => hi.
apply: (leq_sizeP _ _ (leqnn (size p))); rewrite -(ltn_predK p_nc).
by rewrite ltn_subRL (leq_trans _ k_ge_dS) // ltn_add2r.
- apply: (leq_sizeP _ _ (leqnn (size q))); rewrite -(ltn_predK q_nc).
by rewrite ltn_subRL (leq_trans _ k_ge_dS) // addnC ltn_add2l.
by rewrite insubdK //; case: (split i) => {}i;
rewrite !mxE coefMXn; case: leqP.
case: (ubnPgeq dS) (dS_gt0); elim=> // dj IHj ltjS _; pose j1 := Ordinal ltjS.
pose rj0T (A : 'M[{poly R}]_dS) := row j0 A^T.
have: rj0T (Ss_ dj.+1) = 'X^dj *: rj0T (S_ j1) + 1 *: rj0T (Ss_ dj).
apply/rowP=> i; apply/polyP=> k; rewrite scale1r !(Sylvester_mxE, mxE) eqxx.
rewrite coefD coefXnM coefC !coef_poly ltnS subn_eq0 ltn_neqAle andbC.
have [k_le_dj | k_gt_dj] /= := leqP k dj; last by rewrite addr0.
rewrite Sylvester_mxE insubdK; last exact: leq_ltn_trans (ltjS).
by have [->|] := eqP; rewrite (addr0, add0r).
rewrite -det_tr => /determinant_multilinear->;
try by apply/matrixP=> i j; rewrite !mxE lift_eqF.
have [dj0 | dj_gt0] := posnP dj; rewrite ?dj0 !mul1r.
rewrite !det_tr det_map_mx addrC (expand_det_col _ j0) big1 => [|i _].
rewrite add0r; congr (\det _)%:P.
apply/matrixP=> i j; rewrite [in RHS]mxE; case: eqP => // ->.
by congr (S i _); apply: val_inj.
by rewrite mxE /= [Ss0_ _ _]poly_def big_ord0 mul0r.
have /determinant_alternate->: j1 != j0 by rewrite -val_eqE -lt0n.
by rewrite mulr0 add0r det_tr IHj // ltnW.
by move=> i; rewrite !mxE if_same.
Qed.
Lemma resultant_eq0 (R : idomainType) (p q : {poly R}) :
(resultant p q == 0) = (size (gcdp p q) > 1).
Proof.
have dvdpp := dvdpp; set r := gcdp p q.
pose dp := (size p).-1; pose dq := (size q).-1.
have /andP[r_p r_q]: (r %| p) && (r %| q) by rewrite -dvdp_gcd.
apply/det0P/idP=> [[uv nz_uv] | r_nonC].
have [p0 _ | p_nz] := eqVneq p 0.
have: dq + dp > 0.
rewrite lt0n; apply: contraNneq nz_uv => dqp0.
by rewrite dqp0 in uv *; rewrite [uv]thinmx0.
by rewrite /dp /dq /r p0 size_poly0 addn0 gcd0p -subn1 subn_gt0.
do [rewrite -[uv]hsubmxK -{1}row_mx0 mul_row_col !mul_rV_lin1 /=] in nz_uv *.
set u := rVpoly _; set v := rVpoly _; pose m := gcdp (v * p) (v * q).
have lt_vp: size v < size p by rewrite (polySpred p_nz) ltnS size_poly.
move/(congr1 rVpoly)/eqP; rewrite -linearD linear0 poly_rV_K; last first.
rewrite (leq_trans (size_polyD _ _)) // geq_max.
rewrite !(leq_trans (size_polyMleq _ _)) // -subn1 leq_subLR.
by rewrite addnC addnA leq_add ?leqSpred ?size_poly.
by rewrite addnCA leq_add ?leqSpred ?size_poly.
rewrite addrC addr_eq0 => /eqP vq_up.
have nz_v: v != 0.
apply: contraNneq nz_uv => v0; apply/eqP.
congr row_mx; apply: (can_inj rVpolyK); rewrite linear0 // -/u.
by apply: contra_eq vq_up; rewrite v0 mul0r -addr_eq0 add0r => /mulf_neq0->.
have r_nz: r != 0 := dvdpN0 r_p p_nz.
have /dvdpP [[c w] /= nz_c wv]: v %| m by rewrite dvdp_gcd !dvdp_mulr.
have m_wd d: m %| v * d -> w %| d.
case/dvdpP=> [[k f]] /= nz_k /(congr1 ( *:%R c)).
rewrite mulrC scalerA scalerAl scalerAr wv mulrA => /(mulIf nz_v)def_fw.
by apply/dvdpP; exists (c * k, f); rewrite //= mulf_neq0.
have w_r: w %| r by rewrite dvdp_gcd !m_wd ?dvdp_gcdl ?dvdp_gcdr.
have w_nz: w != 0 := dvdpN0 w_r r_nz.
have p_m: p %| m by rewrite dvdp_gcd vq_up -mulNr !dvdp_mull.
rewrite (leq_trans _ (dvdp_leq r_nz w_r)) // -(ltn_add2l (size v)).
rewrite addnC -ltn_subRL subn1 -size_mul // mulrC -wv size_scale //.
rewrite (leq_trans lt_vp) // dvdp_leq // -size_poly_eq0.
by rewrite -(size_scale _ nz_c) size_poly_eq0 wv mulf_neq0.
have [[c p'] /= nz_c p'r] := dvdpP _ _ r_p.
have [[k q'] /= nz_k q'r] := dvdpP _ _ r_q.
have def_r := subnKC r_nonC; have r_nz: r != 0 by rewrite -size_poly_eq0 -def_r.
have le_p'_dp: size p' <= dp.
have [-> | nz_p'] := eqVneq p' 0; first by rewrite size_poly0.
by rewrite /dp -(size_scale p nz_c) p'r size_mul // addnC -def_r leq_addl.
have le_q'_dq: size q' <= dq.
have [-> | nz_q'] := eqVneq q' 0; first by rewrite size_poly0.
by rewrite /dq -(size_scale q nz_k) q'r size_mul // addnC -def_r leq_addl.
exists (row_mx (- c *: poly_rV q') (k *: poly_rV p')); last first.
rewrite mul_row_col scaleNr mulNmx !mul_rV_lin1 /= 2!linearZ /= !poly_rV_K //.
by rewrite !scalerCA p'r q'r mulrCA addNr.
apply: contraNneq r_nz; rewrite -row_mx0 => /eq_row_mx[/eqP].
rewrite scaleNr oppr_eq0 gcdp_eq0 -!size_poly_eq0 => /eqP q0 p0.
rewrite -(size_scale p nz_c) -(size_scale (c *: p) nz_k) p'r.
rewrite -(size_scale q nz_k) -(size_scale (k *: q) nz_c) q'r !scalerAl.
rewrite -(poly_rV_K le_p'_dp) -(poly_rV_K le_q'_dq).
by rewrite -2![_ *: rVpoly _]linearZ p0 q0 !linear0 mul0r size_poly0.
Qed.
Section HornerMx.
Variables (R : comNzRingType) (n' : nat).
Local Notation n := n'.+1.
Implicit Types (A B : 'M[R]_n) (p q : {poly R}).
Section OneMatrix.
Variable A : 'M[R]_n.
Definition horner_mx := horner_morph (comm_mx_scalar^~ A).
HB.instance Definition _ := GRing.RMorphism.on horner_mx.
Lemma horner_mx_C a : horner_mx a%:P = a%:M.
Proof. exact: horner_morphC. Qed.
Lemma horner_mx_X : horner_mx 'X = A. Proof. exact: horner_morphX. Qed.
Lemma horner_mxZ : scalable horner_mx.
Proof.
move=> a p /=; rewrite -mul_polyC rmorphM /=.
by rewrite horner_mx_C [_ * _]mul_scalar_mx.
Qed.
HB.instance Definition _ := GRing.isScalable.Build R _ _ *:%R horner_mx
horner_mxZ.
Definition powers_mx d := \matrix_(i < d) mxvec (A ^+ i).
Lemma horner_rVpoly m (u : 'rV_m) :
horner_mx (rVpoly u) = vec_mx (u *m powers_mx m).
Proof.
rewrite mulmx_sum_row [rVpoly u]poly_def 2!linear_sum; apply: eq_bigr => i _.
by rewrite valK /= 2!linearZ rmorphXn/= horner_mx_X rowK mxvecK.
Qed.
End OneMatrix.
Lemma horner_mx_diag (d : 'rV[R]_n) (p : {poly R}) :
horner_mx (diag_mx d) p = diag_mx (map_mx (horner p) d).
Proof.
apply/matrixP => i j; rewrite !mxE.
elim/poly_ind: p => [|p c ihp]; first by rewrite rmorph0 horner0 mxE mul0rn.
rewrite !hornerE mulrnDl rmorphD rmorphM /= horner_mx_X horner_mx_C !mxE.
rewrite (bigD1 j)//= ihp mxE eqxx mulr1n -mulrnAl big1 ?addr0.
by have [->|_] := eqVneq; rewrite /= !(mulr1n, addr0, mul0r).
by move=> k /negPf nkF; rewrite mxE nkF mulr0.
Qed.
Lemma comm_mx_horner A B p : comm_mx A B -> comm_mx A (horner_mx B p).
Proof.
move=> fg; apply: commr_horner => // i.
by rewrite coef_map; apply/comm_scalar_mx.
Qed.
Lemma comm_horner_mx A B p : comm_mx A B -> comm_mx (horner_mx A p) B.
Proof. by move=> ?; apply/comm_mx_sym/comm_mx_horner/comm_mx_sym. Qed.
Lemma comm_horner_mx2 A p q : GRing.comm (horner_mx A p) (horner_mx A q).
Proof. exact/comm_mx_horner/comm_horner_mx. Qed.
End HornerMx.
Lemma horner_mx_stable (K : fieldType) m n p
(V : 'M[K]_(n.+1, m.+1)) (f : 'M_m.+1) :
stablemx V f -> stablemx V (horner_mx f p).
Proof.
move=> V_fstab; elim/poly_ind: p => [|p c]; first by rewrite rmorph0 stablemx0.
move=> fp_stable; rewrite rmorphD rmorphM/= horner_mx_X horner_mx_C.
by rewrite stablemxD ?stablemxM ?fp_stable ?stablemxC.
Qed.
Prenex Implicits horner_mx powers_mx.
Section CharPoly.
Variables (R : nzRingType) (n : nat) (A : 'M[R]_n).
Implicit Types p q : {poly R}.
Definition char_poly_mx := 'X%:M - map_mx (@polyC R) A.
Definition char_poly := \det char_poly_mx.
Let diagA := [seq A i i | i <- index_enum _ & true].
Let size_diagA : size diagA = n.
Proof. by rewrite -[n]card_ord size_map; have [e _ _ []] := big_enumP. Qed.
Let split_diagA :
exists2 q, \prod_(x <- diagA) ('X - x%:P) + q = char_poly & size q <= n.-1.
Proof.
rewrite [char_poly](bigD1 1%g) //=; set q := \sum_(s | _) _; exists q.
congr (_ + _); rewrite odd_perm1 mul1r big_map big_filter /=.
by apply: eq_bigr => i _; rewrite !mxE perm1 eqxx.
apply: leq_trans {q}(size_sum _ _ _) _; apply/bigmax_leqP=> s nt_s.
have{nt_s} [i nfix_i]: exists i, s i != i.
apply/existsP; rewrite -negb_forall; apply: contra nt_s => s_1.
by apply/eqP/permP=> i; apply/eqP; rewrite perm1 (forallP s_1).
apply: leq_trans (_ : #|[pred j | s j == j]|.+1 <= n.-1).
rewrite -sum1_card (@big_mkcond nat) /= size_Msign.
apply: (big_ind2 (fun p m => size p <= m.+1)) => [| p mp q mq IHp IHq | j _].
- by rewrite size_poly1.
- apply: leq_trans (size_polyMleq _ _) _.
by rewrite -subn1 -addnS leq_subLR addnA leq_add.
rewrite !mxE eq_sym !inE; case: (s j == j); first by rewrite polyseqXsubC.
by rewrite sub0r size_polyN size_polyC leq_b1.
rewrite -[n in n.-1]card_ord -(cardC (pred2 (s i) i)) card2 nfix_i !ltnS.
apply/subset_leq_card/subsetP=> j /(_ =P j) fix_j.
rewrite !inE -{1}fix_j (inj_eq perm_inj) orbb.
by apply: contraNneq nfix_i => <-; rewrite fix_j.
Qed.
Lemma size_char_poly : size char_poly = n.+1.
Proof.
have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n).
by rewrite size_polyDl size_prod_XsubC size_diagA.
Qed.
Lemma char_poly_monic : char_poly \is monic.
Proof.
rewrite monicE -(monicP (monic_prod_XsubC diagA xpredT id)).
rewrite !lead_coefE size_char_poly.
have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n).
by rewrite size_prod_XsubC size_diagA coefD (nth_default 0 le_q_n) addr0.
Qed.
Lemma char_poly_trace : n > 0 -> char_poly`_n.-1 = - \tr A.
Proof.
move=> n_gt0; have [q <- lt_q_n] := split_diagA; set p := \prod_(x <- _) _.
rewrite coefD {q lt_q_n}(nth_default 0 lt_q_n) addr0.
have{n_gt0} ->: p`_n.-1 = ('X * p)`_n by rewrite coefXM eqn0Ngt n_gt0.
have ->: \tr A = \sum_(x <- diagA) x by rewrite big_map big_filter.
rewrite -size_diagA {}/p; elim: diagA => [|x d IHd].
by rewrite !big_nil mulr1 coefX oppr0.
rewrite !big_cons coefXM mulrBl coefB IHd opprD addrC; congr (- _ + _).
rewrite mul_polyC coefZ [size _]/= -(size_prod_XsubC _ id) -lead_coefE.
by rewrite (monicP _) ?monic_prod_XsubC ?mulr1.
Qed.
Lemma char_poly_det : char_poly`_0 = (- 1) ^+ n * \det A.
Proof.
rewrite big_distrr coef_sum [0%N]lock /=; apply: eq_bigr => s _.
rewrite -{1}rmorphN -rmorphXn mul_polyC coefZ /=.
rewrite mulrA -exprD addnC exprD -mulrA -lock; congr (_ * _).
transitivity (\prod_(i < n) - A i (s i)); last by rewrite prodrN card_ord.
elim: (index_enum _) => [|i e IHe]; rewrite !(big_nil, big_cons) ?coef1 //.
by rewrite coefM big_ord1 IHe !mxE coefB coefC coefMn coefX mul0rn sub0r.
Qed.
End CharPoly.
Prenex Implicits char_poly_mx char_poly.
Lemma mx_poly_ring_isom (R : nzRingType) n' (n := n'.+1) :
exists phi : {rmorphism 'M[{poly R}]_n -> {poly 'M[R]_n}},
[/\ bijective phi,
forall p, phi p%:M = map_poly scalar_mx p,
forall A, phi (map_mx polyC A) = A%:P
& forall A i j k, (phi A)`_k i j = (A i j)`_k].
Proof.
set M_RX := 'M[{poly R}]_n; set MR_X := ({poly 'M[R]_n}).
pose Msize (A : M_RX) := \max_i \max_j size (A i j).
pose phi (A : M_RX) := \poly_(k < Msize A) \matrix_(i, j) (A i j)`_k.
have coef_phi A i j k: (phi A)`_k i j = (A i j)`_k.
rewrite coef_poly; case: (ltnP k _) => le_m_k; rewrite mxE // nth_default //.
by apply: leq_trans (leq_trans (leq_bigmax i) le_m_k); apply: (leq_bigmax j).
have phi_is_zmod_morphism : zmod_morphism phi.
move=> A B; apply/polyP => k; apply/matrixP => i j.
by rewrite !(coef_phi, mxE, coefD, coefN).
have phi_is_monoid_morphism : monoid_morphism phi.
split=> [|A B]; apply/polyP => k; apply/matrixP => i j.
by rewrite coef_phi mxE coefMn !coefC; case: (k == _); rewrite ?mxE ?mul0rn.
rewrite !coef_phi !mxE !coefM summxE coef_sum.
pose F k1 k2 := (A i k1)`_k2 * (B k1 j)`_(k - k2).
transitivity (\sum_k1 \sum_(k2 < k.+1) F k1 k2); rewrite {}/F.
by apply: eq_bigr=> k1 _; rewrite coefM.
rewrite exchange_big /=; apply: eq_bigr => k2 _.
by rewrite mxE; apply: eq_bigr => k1 _; rewrite !coef_phi.
have bij_phi: bijective phi.
exists (fun P : MR_X => \matrix_(i, j) \poly_(k < size P) P`_k i j) => [A|P].
apply/matrixP=> i j; rewrite mxE; apply/polyP=> k.
rewrite coef_poly -coef_phi.
by case: leqP => // P_le_k; rewrite nth_default ?mxE.
apply/polyP=> k; apply/matrixP=> i j; rewrite coef_phi mxE coef_poly.
by case: leqP => // P_le_k; rewrite nth_default ?mxE.
pose phiaM := GRing.isZmodMorphism.Build _ _ phi phi_is_zmod_morphism.
pose phimM := GRing.isMonoidMorphism.Build _ _ phi phi_is_monoid_morphism.
pose phiRM : {rmorphism _ -> _} := HB.pack phi phiaM phimM.
exists phiRM; split=> // [p | A]; apply/polyP=> k; apply/matrixP=> i j.
by rewrite coef_phi coef_map !mxE coefMn.
by rewrite coef_phi !mxE !coefC; case k; last rewrite /= mxE.
Qed.
Theorem Cayley_Hamilton (R : comNzRingType) n' (A : 'M[R]_n'.+1) :
horner_mx A (char_poly A) = 0.
Proof.
have [phi [_ phiZ phiC _]] := mx_poly_ring_isom R n'.
apply/rootP/factor_theorem; rewrite -phiZ -mul_adj_mx rmorphM /=.
by move: (phi _) => q; exists q; rewrite rmorphB phiC phiZ map_polyX.
Qed.
Lemma eigenvalue_root_char (F : fieldType) n (A : 'M[F]_n) a :
eigenvalue A a = root (char_poly A) a.
Proof.
transitivity (\det (a%:M - A) == 0).
apply/eigenvalueP/det0P=> [[v Av_av v_nz] | [v v_nz Av_av]]; exists v => //.
by rewrite mulmxBr Av_av mul_mx_scalar subrr.
by apply/eqP; rewrite -mul_mx_scalar eq_sym -subr_eq0 -mulmxBr Av_av.
congr (_ == 0); rewrite horner_sum; apply: eq_bigr => s _.
rewrite hornerM horner_exp !hornerE; congr (_ * _).
rewrite (big_morph _ (fun p q => hornerM p q a) (hornerC 1 a)).
by apply: eq_bigr => i _; rewrite !mxE !(hornerE, hornerMn).
Qed.
Lemma char_poly_trig {R : comNzRingType} n (A : 'M[R]_n) : is_trig_mx A ->
char_poly A = \prod_(i < n) ('X - (A i i)%:P).
Proof.
move=> /is_trig_mxP Atrig; rewrite /char_poly det_trig.
by apply: eq_bigr => i; rewrite !mxE eqxx.
by apply/is_trig_mxP => i j lt_ij; rewrite !mxE -val_eqE ltn_eqF ?Atrig ?subrr.
Qed.
Definition companionmx {R : nzRingType} (p : seq R) (d := (size p).-1) :=
\matrix_(i < d, j < d)
if (i == d.-1 :> nat) then - p`_j else (i.+1 == j :> nat)%:R.
Lemma companionmxK {R : comNzRingType} (p : {poly R}) :
p \is monic -> char_poly (companionmx p) = p.
Proof.
pose D n : 'M[{poly R}]_n := \matrix_(i, j)
('X *+ (i == j.+1 :> nat) - ((i == j)%:R)%:P).
have detD n : \det (D n) = (-1) ^+ n.
elim: n => [|n IHn]; first by rewrite det_mx00.
rewrite (expand_det_row _ ord0) big_ord_recl !mxE /= sub0r.
rewrite big1 ?addr0; last by move=> i _; rewrite !mxE /= subrr mul0r.
rewrite /cofactor mul1r [X in \det X](_ : _ = D _) ?IHn ?exprS//.
by apply/matrixP=> i j; rewrite !mxE /= /bump !add1n eqSS.
elim/poly_ind: p => [|p c IHp].
by rewrite monicE lead_coef0 eq_sym oner_eq0.
have [->|p_neq0] := eqVneq p 0.
rewrite mul0r add0r monicE lead_coefC => /eqP->.
by rewrite /companionmx /char_poly size_poly1 det_mx00.
rewrite monicE lead_coefDl ?lead_coefMX => [p_monic|]; last first.
rewrite size_polyC size_mulX ?polyX_eq0// ltnS.
by rewrite (leq_trans (leq_b1 _)) ?size_poly_gt0.
rewrite -[in RHS]IHp // /companionmx size_MXaddC (negPf p_neq0) /=.
rewrite /char_poly polySpred //.
have [->|spV1_gt0] := posnP (size p).-1.
rewrite [X in \det X]mx11_scalar det_scalar1 !mxE ?eqxx det_mx00.
by rewrite mul1r -horner_coef0 hornerMXaddC mulr0 add0r rmorphN opprK.
rewrite (expand_det_col _ ord0) /= -[(size p).-1]prednK //.
rewrite big_ord_recr big_ord_recl/= big1 ?add0r //=; last first.
move=> i _; rewrite !mxE -val_eqE /= /bump leq0n add1n eqSS.
by rewrite ltn_eqF ?subrr ?mul0r.
rewrite !mxE ?subnn -horner_coef0 /= hornerMXaddC.
rewrite !(eqxx, mulr0, add0r, addr0, subr0, rmorphN, opprK)/=.
rewrite mulrC /cofactor; congr (_ * 'X + _).
rewrite /cofactor -signr_odd oddD addbb mul1r; congr (\det _).
apply/matrixP => i j; rewrite !mxE -val_eqE coefD coefMX coefC.
by rewrite /= /bump /= !add1n !eqSS addr0.
rewrite /cofactor [X in \det X](_ : _ = D _).
by rewrite detD /= addn0 -signr_odd -signr_addb addbb mulr1.
apply/matrixP=> i j; rewrite !mxE -!val_eqE /= /bump /=.
by rewrite leqNgt ltn_ord add0n add1n [_ == _.-2.+1]ltn_eqF.
Qed.
Lemma mulmx_delta_companion (R : nzRingType) (p : seq R)
(i: 'I_(size p).-1) (i_small : i.+1 < (size p).-1):
delta_mx 0 i *m companionmx p = delta_mx 0 (Ordinal i_small) :> 'rV__.
Proof.
apply/rowP => j; rewrite !mxE (bigD1 i) //= ?(=^~val_eqE, mxE) /= eqxx mul1r.
rewrite ltn_eqF ?big1 ?addr0 1?eq_sym //; last first.
by rewrite -ltnS prednK // (leq_trans _ i_small).
by move=> k /negPf ki_eqF; rewrite !mxE eqxx ki_eqF mul0r.
Qed.
Lemma row'_col'_char_poly_mx {R : nzRingType} m i (M : 'M[R]_m) :
row' i (col' i (char_poly_mx M)) = char_poly_mx (row' i (col' i M)).
Proof. by apply/matrixP => k l; rewrite !mxE (inj_eq lift_inj). Qed.
Lemma char_block_diag_mx {R : nzRingType} m n (A : 'M[R]_m) (B : 'M[R]_n) :
char_poly_mx (block_mx A 0 0 B) =
block_mx (char_poly_mx A) 0 0 (char_poly_mx B).
Proof.
rewrite /char_poly_mx map_block_mx/= !map_mx0.
by rewrite scalar_mx_block opp_block_mx add_block_mx !subr0.
Qed.
Section MinPoly.
Variables (F : fieldType) (n' : nat).
Local Notation n := n'.+1.
Variable A : 'M[F]_n.
Implicit Types p q : {poly F}.
Fact degree_mxminpoly_proof : exists d, \rank (powers_mx A d.+1) <= d.
Proof. by exists (n ^ 2)%N; rewrite rank_leq_col. Qed.
Definition degree_mxminpoly := ex_minn degree_mxminpoly_proof.
Local Notation d := degree_mxminpoly.
Local Notation Ad := (powers_mx A d).
Lemma mxminpoly_nonconstant : d > 0.
Proof.
rewrite /d; case: ex_minnP => -[] //; rewrite leqn0 mxrank_eq0; move/eqP.
by move/row_matrixP/(_ 0)/eqP; rewrite rowK row0 mxvec_eq0 -mxrank_eq0 mxrank1.
Qed.
Lemma minpoly_mx1 : (1%:M \in Ad)%MS.
Proof.
by apply: (eq_row_sub (Ordinal mxminpoly_nonconstant)); rewrite rowK.
Qed.
Lemma minpoly_mx_free : row_free Ad.
Proof.
have:= mxminpoly_nonconstant; rewrite /d; case: ex_minnP => -[] // d' _ /(_ d').
by move/implyP; rewrite ltnn implybF -ltnS ltn_neqAle rank_leq_row andbT negbK.
Qed.
Lemma horner_mx_mem p : (horner_mx A p \in Ad)%MS.
Proof.
elim/poly_ind: p => [|p a IHp]; first by rewrite rmorph0 // linear0 sub0mx.
rewrite rmorphD rmorphM /= horner_mx_C horner_mx_X.
rewrite addrC -scalemx1 linearP /= -(mul_vec_lin (mulmxr A)).
case/submxP: IHp => u ->{p}.
have: (powers_mx A (1 + d) <= Ad)%MS.
rewrite -(geq_leqif (mxrank_leqif_sup _)).
by rewrite (eqnP minpoly_mx_free) /d; case: ex_minnP.
rewrite addnC; apply/row_subP=> i.
by apply: eq_row_sub (lshift 1 i) _; rewrite !rowK.
apply: submx_trans; rewrite addmx_sub ?scalemx_sub //.
by apply: (eq_row_sub 0); rewrite rowK.
rewrite -mulmxA mulmx_sub {u}//; apply/row_subP=> i.
rewrite row_mul rowK mul_vec_lin /= mulmxE -exprSr.
by apply: (eq_row_sub (rshift 1 i)); rewrite rowK.
Qed.
Definition mx_inv_horner B := rVpoly (mxvec B *m pinvmx Ad).
Lemma mx_inv_horner0 : mx_inv_horner 0 = 0.
Proof. by rewrite /mx_inv_horner !(linear0, mul0mx). Qed.
Lemma mx_inv_hornerK B : (B \in Ad)%MS -> horner_mx A (mx_inv_horner B) = B.
Proof. by move=> sBAd; rewrite horner_rVpoly mulmxKpV ?mxvecK. Qed.
Lemma minpoly_mxM B C : (B \in Ad -> C \in Ad -> B * C \in Ad)%MS.
Proof.
move=> AdB AdC; rewrite -(mx_inv_hornerK AdB) -(mx_inv_hornerK AdC).
by rewrite -rmorphM ?horner_mx_mem.
Qed.
Lemma minpoly_mx_ring : mxring Ad.
Proof.
apply/andP; split; first exact/mulsmx_subP/minpoly_mxM.
apply/mxring_idP; exists 1%:M; split=> *; rewrite ?mulmx1 ?mul1mx //.
by rewrite -mxrank_eq0 mxrank1.
exact: minpoly_mx1.
Qed.
Definition mxminpoly := 'X^d - mx_inv_horner (A ^+ d).
Local Notation p_A := mxminpoly.
Lemma size_mxminpoly : size p_A = d.+1.
Proof. by rewrite size_polyDl ?size_polyXn // size_polyN ltnS size_poly. Qed.
Lemma mxminpoly_monic : p_A \is monic.
Proof.
rewrite monicE /lead_coef size_mxminpoly coefB coefXn eqxx /=.
by rewrite nth_default ?size_poly // subr0.
Qed.
Lemma size_mod_mxminpoly p : size (p %% p_A) <= d.
Proof.
by rewrite -ltnS -size_mxminpoly ltn_modp // -size_poly_eq0 size_mxminpoly.
Qed.
Lemma mx_root_minpoly : horner_mx A p_A = 0.
Proof.
rewrite rmorphB -{3}(horner_mx_X A) -rmorphXn /=.
by rewrite mx_inv_hornerK ?subrr ?horner_mx_mem.
Qed.
Lemma horner_rVpolyK (u : 'rV_d) :
mx_inv_horner (horner_mx A (rVpoly u)) = rVpoly u.
Proof.
congr rVpoly; rewrite horner_rVpoly vec_mxK.
by apply: (row_free_inj minpoly_mx_free); rewrite mulmxKpV ?submxMl.
Qed.
Lemma horner_mxK p : mx_inv_horner (horner_mx A p) = p %% p_A.
Proof.
rewrite {1}(Pdiv.IdomainMonic.divp_eq mxminpoly_monic p) rmorphD rmorphM /=.
rewrite mx_root_minpoly mulr0 add0r.
by rewrite -(poly_rV_K (size_mod_mxminpoly _)) horner_rVpolyK.
Qed.
Lemma mxminpoly_min p : horner_mx A p = 0 -> p_A %| p.
Proof. by move=> pA0; rewrite /dvdp -horner_mxK pA0 mx_inv_horner0. Qed.
Lemma mxminpoly_minP p : reflect (horner_mx A p = 0) (p_A %| p).
Proof.
apply: (iffP idP); last exact: mxminpoly_min.
by move=> /Pdiv.Field.dvdpP[q ->]; rewrite rmorphM/= mx_root_minpoly mulr0.
Qed.
Lemma dvd_mxminpoly p : (p_A %| p) = (horner_mx A p == 0).
Proof. exact/mxminpoly_minP/eqP. Qed.
Lemma horner_rVpoly_inj : injective (horner_mx A \o rVpoly : 'rV_d -> 'M_n).
Proof.
apply: can_inj (poly_rV \o mx_inv_horner) _ => u /=.
by rewrite horner_rVpolyK rVpolyK.
Qed.
Lemma mxminpoly_linear_is_scalar : (d <= 1) = is_scalar_mx A.
Proof.
have scalP := has_non_scalar_mxP minpoly_mx1.
rewrite leqNgt -(eqnP minpoly_mx_free); apply/scalP/idP=> [|[[B]]].
case scalA: (is_scalar_mx A); [by right | left].
by exists A; rewrite ?scalA // -{1}(horner_mx_X A) horner_mx_mem.
move/mx_inv_hornerK=> <- nsB; case/is_scalar_mxP=> a defA; case/negP: nsB.
move: {B}(_ B); apply: poly_ind => [|p c].
by rewrite rmorph0 ?mx0_is_scalar.
rewrite rmorphD ?rmorphM /= horner_mx_X defA; case/is_scalar_mxP=> b ->.
by rewrite -rmorphM horner_mx_C -rmorphD /= scalar_mx_is_scalar.
Qed.
Lemma mxminpoly_dvd_char : p_A %| char_poly A.
Proof. exact/mxminpoly_min/Cayley_Hamilton. Qed.
Lemma eigenvalue_root_min a : eigenvalue A a = root p_A a.
Proof.
apply/idP/idP=> Aa; last first.
rewrite eigenvalue_root_char !root_factor_theorem in Aa *.
exact: dvdp_trans Aa mxminpoly_dvd_char.
have{Aa} [v Av_av v_nz] := eigenvalueP Aa.
apply: contraR v_nz => pa_nz; rewrite -{pa_nz}(eqmx_eq0 (eqmx_scale _ pa_nz)).
apply/eqP; rewrite -(mulmx0 _ v) -mx_root_minpoly.
elim/poly_ind: p_A => [|p c IHp].
by rewrite rmorph0 horner0 scale0r mulmx0.
rewrite !hornerE rmorphD rmorphM /= horner_mx_X horner_mx_C scalerDl.
by rewrite -scalerA mulmxDr mul_mx_scalar mulmxA -IHp -scalemxAl Av_av.
Qed.
Lemma root_mxminpoly a : root p_A a = root (char_poly A) a.
Proof. by rewrite -eigenvalue_root_min eigenvalue_root_char. Qed.
End MinPoly.
Lemma mxminpoly_diag {F : fieldType} {n} (d : 'rV[F]_n.+1)
(u := undup [seq d 0 i | i <- enum 'I_n.+1]) :
mxminpoly (diag_mx d) = \prod_(r <- u) ('X - r%:P).
Proof.
apply/eqP; rewrite -eqp_monic ?mxminpoly_monic ?monic_prod_XsubC// /eqp.
rewrite mxminpoly_min/=; last first.
rewrite horner_mx_diag; apply/matrixP => i j; rewrite !mxE horner_prod.
case: (altP (i =P j)) => [->|neq_ij//]; rewrite mulr1n.
rewrite (bigD1_seq (d 0 j)) ?undup_uniq ?mem_undup ?map_f// /=.
by rewrite hornerD hornerN hornerX hornerC subrr mul0r.
apply: uniq_roots_dvdp; last by rewrite uniq_rootsE undup_uniq.
apply/allP => x; rewrite mem_undup root_mxminpoly char_poly_trig//.
rewrite -(big_map _ predT (fun x => _ - x%:P)) root_prod_XsubC.
by move=> /mapP[i _ ->]; apply/mapP; exists i; rewrite ?(mxE, eqxx).
Qed.
Prenex Implicits degree_mxminpoly mxminpoly mx_inv_horner.
Arguments mx_inv_hornerK {F n' A} [B] AnB.
Arguments horner_rVpoly_inj {F n' A} [u1 u2] eq_u12A : rename.
(* Parametricity. *)
Section MapRingMatrix.
Variables (aR rR : nzRingType) (f : {rmorphism aR -> rR}).
Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope.
Local Notation fp := (map_poly (GRing.RMorphism.sort f)).
Variables (d n : nat) (A : 'M[aR]_n).
Lemma map_rVpoly (u : 'rV_d) : fp (rVpoly u) = rVpoly u^f.
Proof.
apply/polyP=> k; rewrite coef_map !coef_rVpoly.
by case: (insub k) => [i|]; rewrite /= ?rmorph0 // mxE.
Qed.
Lemma map_poly_rV p : (poly_rV p)^f = poly_rV (fp p) :> 'rV_d.
Proof. by apply/rowP=> j; rewrite !mxE coef_map. Qed.
Lemma map_char_poly_mx : map_mx fp (char_poly_mx A) = char_poly_mx A^f.
Proof.
rewrite raddfB /= map_scalar_mx /= map_polyX; congr (_ - _).
by apply/matrixP=> i j; rewrite !mxE map_polyC.
Qed.
Lemma map_char_poly : fp (char_poly A) = char_poly A^f.
Proof. by rewrite -det_map_mx map_char_poly_mx. Qed.
End MapRingMatrix.
Section MapResultant.
Lemma map_resultant (aR rR : nzRingType) (f : {rmorphism {poly aR} -> rR}) p q :
f (lead_coef p) != 0 -> f (lead_coef q) != 0 ->
f (resultant p q)= resultant (map_poly f p) (map_poly f q).
Proof.
move=> nz_fp nz_fq; rewrite /resultant /Sylvester_mx !size_map_poly_id0 //.
rewrite -det_map_mx /= map_col_mx; congr (\det (col_mx _ _));
by apply: map_lin1_mx => v; rewrite map_poly_rV rmorphM /= map_rVpoly.
Qed.
End MapResultant.
Section MapComRing.
Variables (aR rR : comNzRingType) (f : {rmorphism aR -> rR}).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Local Notation fp := (map_poly f).
Variables (n' : nat) (A : 'M[aR]_n'.+1).
Lemma map_powers_mx e : (powers_mx A e)^f = powers_mx A^f e.
Proof. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec rmorphXn. Qed.
Lemma map_horner_mx p : (horner_mx A p)^f = horner_mx A^f (fp p).
Proof.
rewrite -[p](poly_rV_K (leqnn _)) map_rVpoly.
by rewrite !horner_rVpoly map_vec_mx map_mxM map_powers_mx.
Qed.
End MapComRing.
Section MapField.
Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Local Notation fp := (map_poly f).
Variables (n' : nat) (A : 'M[aF]_n'.+1) (p : {poly aF}).
Lemma map_mx_companion (e := congr1 predn (size_map_poly _ _)) :
(companionmx p)^f = castmx (e, e) (companionmx (fp p)).
Proof.
apply/matrixP => i j; rewrite !(castmxE, mxE) /= (fun_if f).
by rewrite rmorphN coef_map size_map_poly rmorph_nat.
Qed.
Lemma companion_map_poly (e := esym (congr1 predn (size_map_poly _ _))) :
companionmx (fp p) = castmx (e, e) (companionmx p)^f.
Proof. by rewrite map_mx_companion castmx_comp castmx_id. Qed.
Lemma degree_mxminpoly_map : degree_mxminpoly A^f = degree_mxminpoly A.
Proof. by apply: eq_ex_minn => e; rewrite -map_powers_mx mxrank_map. Qed.
Lemma mxminpoly_map : mxminpoly A^f = fp (mxminpoly A).
Proof.
rewrite rmorphB; congr (_ - _).
by rewrite /= map_polyXn degree_mxminpoly_map.
rewrite degree_mxminpoly_map -rmorphXn /=.
apply/polyP=> i; rewrite coef_map //= !coef_rVpoly degree_mxminpoly_map.
case/insub: i => [i|]; last by rewrite rmorph0.
by rewrite -map_powers_mx -map_pinvmx // -map_mxvec -map_mxM // mxE.
Qed.
Lemma map_mx_inv_horner u : fp (mx_inv_horner A u) = mx_inv_horner A^f u^f.
Proof.
rewrite map_rVpoly map_mxM map_mxvec map_pinvmx map_powers_mx.
by rewrite /mx_inv_horner degree_mxminpoly_map.
Qed.
End MapField.
Section KernelLemmas.
Variable K : fieldType.
(* convertible to kermx (horner_mx g p) when n = n.+1 *)
Definition kermxpoly n (g : 'M_n) (p : {poly K}) : 'M_n :=
kermx ((if n is n.+1 then horner_mx^~ p : 'M_n.+1 -> 'M_n.+1 else \0) g).
Lemma kermxpolyC n (g : 'M_n) c : c != 0 -> kermxpoly g c%:P = 0.
Proof.
move=> c_neq0; case: n => [|n] in g *; first by rewrite thinmx0.
apply/eqP; rewrite /kermxpoly horner_mx_C kermx_eq0 row_free_unit.
by rewrite -scalemx1 scaler_unit ?unitmx1// unitfE.
Qed.
Lemma kermxpoly1 n (g : 'M_n) : kermxpoly g 1 = 0.
Proof. by rewrite kermxpolyC ?oner_eq0. Qed.
Lemma kermxpolyX n (g : 'M_n) : kermxpoly g 'X = kermx g.
Proof.
case: n => [|n] in g *; first by rewrite !thinmx0.
by rewrite /kermxpoly horner_mx_X.
Qed.
Lemma kermxpoly_min n (g : 'M[K]_n.+1) p :
mxminpoly g %| p -> (kermxpoly g p :=: 1)%MS.
Proof. by rewrite /kermxpoly => /mxminpoly_minP ->; apply: kermx0. Qed.
Lemma comm_mx_stable_kermxpoly n (f g : 'M_n) (p : {poly K}) : comm_mx f g ->
stablemx (kermxpoly f p) g.
Proof.
case: n => [|n] in f g *; first by rewrite !thinmx0.
move=> fg; rewrite /kermxpoly; apply: comm_mx_stable_ker.
by apply/comm_mx_sym/comm_mx_horner/comm_mx_sym.
Qed.
Lemma mxdirect_kermxpoly n (g : 'M_n) (p q : {poly K}) :
coprimep p q -> (kermxpoly g p :&: kermxpoly g q = 0)%MS.
Proof.
case: n => [|n] in g *; first by rewrite thinmx0 ?cap0mx ?submx_refl.
move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq.
apply/eqP/rowV0P => x.
rewrite sub_capmx => /andP[/sub_kermxP xgp0 /sub_kermxP xgq0].
move: cpq => /(congr1 (mulmx x \o horner_mx g))/=.
rewrite !(rmorphM, rmorphD, rmorph1, mulmx1, mulmxDr, mulmxA).
by rewrite xgp0 xgq0 !mul0mx add0r.
Qed.
Lemma kermxpolyM n (g : 'M_n) (p q : {poly K}) : coprimep p q ->
(kermxpoly g (p * q) :=: kermxpoly g p + kermxpoly g q)%MS.
Proof.
case: n => [|n] in g *; first by rewrite !thinmx0.
move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq.
apply/eqmxP/andP; split; last first.
apply/sub_kermxP/eqmx0P; rewrite !addsmxMr [in X in (_ + X)%MS]mulrC.
by rewrite !rmorphM/= !mulmxA !mulmx_ker !mul0mx !addsmx0 submx_refl.
move: cpq => /(congr1 (horner_mx g))/=; rewrite rmorph1 rmorphD/=.
rewrite -[X in (X <= _)%MS]mulr1 => <-; rewrite mulrDr [p * u]mulrC addrC.
rewrite addmx_sub_adds//; apply/sub_kermxP; rewrite mulmxE -mulrA -rmorphM.
by rewrite mulrAC [q * p]mulrC rmorphM/= mulrA -!mulmxE mulmx_ker mul0mx.
rewrite -[_ * _ * q]mulrA [u * _]mulrC.
by rewrite rmorphM mulrA -!mulmxE mulmx_ker mul0mx.
Qed.
Lemma kermxpoly_prod n (g : 'M_n)
(I : finType) (P : {pred I}) (p_ : I -> {poly K}) :
{in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} ->
(kermxpoly g (\prod_(i | P i) p_ i) :=: \sum_(i | P i) kermxpoly g (p_ i))%MS.
Proof.
move=> p_coprime; elim: index_enum (index_enum_uniq I).
by rewrite !big_nil ?kermxpoly1 ?submx_refl//.
move=> j js ihjs /= /andP[jNjs js_uniq]; apply/eqmxP.
rewrite !big_cons; case: ifP => [Pj|PNj]; rewrite ?ihjs ?submx_refl//.
suff cjjs: coprimep (p_ j) (\prod_(i <- js | P i) p_ i).
by rewrite !kermxpolyM// !(adds_eqmx (eqmx_refl _) (ihjs _)) ?submx_refl.
rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first.
by move=> p q; rewrite coprimepMr.
apply/allP => i i_js; apply/implyP => Pi; apply: p_coprime => //.
by apply: contraNneq jNjs => <-.
Qed.
Lemma mxdirect_sum_kermx n (g : 'M_n)
(I : finType) (P : {pred I}) (p_ : I -> {poly K}) :
{in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} ->
mxdirect (\sum_(i | P i) kermxpoly g (p_ i))%MS.
Proof.
move=> p_coprime; apply/mxdirect_sumsP => i Pi; apply/eqmx0P.
have cpNi : {in [pred j | P j && (j != i)] &,
forall j k : I, k != j -> coprimep (p_ j) (p_ k)}.
by move=> j k /andP[Pj _] /andP[Pk _]; apply: p_coprime.
rewrite -!(cap_eqmx (eqmx_refl _) (kermxpoly_prod g _))//.
rewrite mxdirect_kermxpoly ?submx_refl//.
rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first.
by move=> p q; rewrite coprimepMr.
by apply/allP => j _; apply/implyP => /andP[Pj neq_ji]; apply: p_coprime.
Qed.
Lemma eigenspace_poly n a (f : 'M_n) :
eigenspace f a = kermxpoly f ('X - a%:P).
Proof.
case: n => [|m] in a f *; first by rewrite !thinmx0.
by congr (kermx _); rewrite rmorphB /= ?horner_mx_X ?horner_mx_C.
Qed.
Definition geigenspace n (g : 'M_n) a := kermxpoly g (('X - a%:P) ^+ n).
Lemma geigenspaceE n' (g : 'M_n'.+1) a :
geigenspace g a = kermx ((g - a%:M) ^+ n'.+1).
Proof.
by rewrite /geigenspace /kermxpoly rmorphXn/= rmorphB/= horner_mx_X horner_mx_C.
Qed.
Lemma eigenspace_sub_geigen n (g : 'M_n) a :
(eigenspace g a <= geigenspace g a)%MS.
Proof.
case: n => [|n] in g *; rewrite ?thinmx0 ?sub0mx// geigenspaceE.
by apply/sub_kermxP; rewrite exprS mulmxA mulmx_ker mul0mx.
Qed.
Lemma mxdirect_sum_geigenspace
(I : finType) (n : nat) (g : 'M_n) (P : {pred I}) (a_ : I -> K) :
{in P &, injective a_} -> mxdirect (\sum_(i | P i) geigenspace g (a_ i)).
Proof.
move=> /inj_in_eq eq_a; apply: mxdirect_sum_kermx => i j Pi Pj Nji.
by rewrite coprimep_expr ?coprimep_expl// coprimep_XsubC root_XsubC eq_a.
Qed.
Definition eigenpoly n (g : 'M_n) : pred {poly K} :=
(fun p => kermxpoly g p != 0).
Lemma eigenpolyP n (g : 'M_n) (p : {poly K}) :
reflect (exists2 v : 'rV_n, (v <= kermxpoly g p)%MS & v != 0) (eigenpoly g p).
Proof. exact: rowV0Pn. Qed.
Lemma eigenvalue_poly n a (f : 'M_n) : eigenvalue f a = eigenpoly f ('X - a%:P).
Proof. by rewrite /eigenpoly /eigenvalue eigenspace_poly. Qed.
Lemma comm_mx_stable_geigenspace n (f g : 'M_n) a : comm_mx f g ->
stablemx (geigenspace f a) g.
Proof. exact: comm_mx_stable_kermxpoly. Qed.
End KernelLemmas.
Section MapKermxPoly.
Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}).
Lemma map_kermxpoly (n : nat) (g : 'M_n) (p : {poly aF}) :
map_mx f (kermxpoly g p) = kermxpoly (map_mx f g) (map_poly f p).
Proof.
by case: n => [|n] in g *; rewrite ?thinmx0// map_kermx map_horner_mx.
Qed.
Lemma map_geigenspace (n : nat) (g : 'M_n) (a : aF) :
map_mx f (geigenspace g a) = geigenspace (map_mx f g) (f a).
Proof. by rewrite map_kermxpoly rmorphXn/= rmorphB /= map_polyX map_polyC. Qed.
Lemma eigenpoly_map n (g : 'M_n) (p : {poly aF}) :
eigenpoly (map_mx f g) (map_poly f p) = eigenpoly g p.
Proof. by rewrite /eigenpoly -map_kermxpoly map_mx_eq0. Qed.
End MapKermxPoly.
Section IntegralOverRing.
Definition integralOver (R K : nzRingType) (RtoK : R -> K) (z : K) :=
exists2 p, p \is monic & root (map_poly RtoK p) z.
Definition integralRange R K RtoK := forall z, @integralOver R K RtoK z.
Variables (B R K : nzRingType) (BtoR : B -> R) (RtoK : {rmorphism R -> K}).
Lemma integral_rmorph x :
integralOver BtoR x -> integralOver (RtoK \o BtoR) (RtoK x).
Proof. by case=> p; exists p; rewrite // map_poly_comp rmorph_root. Qed.
Lemma integral_id x : integralOver RtoK (RtoK x).
Proof. by exists ('X - x%:P); rewrite ?monicXsubC ?rmorph_root ?root_XsubC. Qed.
Lemma integral_nat n : integralOver RtoK n%:R.
Proof. by rewrite -(rmorph_nat RtoK); apply: integral_id. Qed.
Lemma integral0 : integralOver RtoK 0. Proof. exact: (integral_nat 0). Qed.
Lemma integral1 : integralOver RtoK 1. Proof. exact: (integral_nat 1). Qed.
Lemma integral_poly (p : {poly K}) :
(forall i, integralOver RtoK p`_i) <-> {in p : seq K, integralRange RtoK}.
Proof.
split=> intRp => [_ /(nthP 0)[i _ <-] // | i]; rewrite -[p]coefK coef_poly.
by case: ifP => [ltip | _]; [apply/intRp/mem_nth | apply: integral0].
Qed.
End IntegralOverRing.
Section IntegralOverComRing.
Variables (R K : comNzRingType) (RtoK : {rmorphism R -> K}).
Lemma integral_horner_root w (p q : {poly K}) :
p \is monic -> root p w ->
{in p : seq K, integralRange RtoK} -> {in q : seq K, integralRange RtoK} ->
integralOver RtoK q.[w].
Proof.
move=> mon_p pw0 intRp intRq.
pose memR y := exists x, y = RtoK x.
have memRid x: memR (RtoK x) by exists x.
have memR_nat n: memR n%:R by rewrite -(rmorph_nat RtoK) /=.
have [memR0 memR1]: memR 0 * memR 1 := (memR_nat 0, memR_nat 1).
have memRN1: memR (- 1) by exists (- 1); rewrite rmorphN1.
pose rVin (E : K -> Prop) n (a : 'rV[K]_n) := forall i, E (a 0 i).
pose pXin (E : K -> Prop) (r : {poly K}) := forall i, E r`_i.
pose memM E n (X : 'rV_n) y := exists a, rVin E n a /\ y = (a *m X^T) 0 0.
pose finM E S := exists n, exists X, forall y, memM E n X y <-> S y.
have tensorM E n1 n2 X Y: finM E (memM (memM E n2 Y) n1 X).
exists (n1 * n2)%N, (mxvec (X^T *m Y)) => y.
split=> [[a [Ea Dy]] | [a1 [/fin_all_exists[a /all_and2[Ea Da1]] ->]]].
exists (Y *m (vec_mx a)^T); split=> [i|].
exists (row i (vec_mx a)); split=> [j|]; first by rewrite !mxE; apply: Ea.
by rewrite -row_mul -{1}[Y]trmxK -trmx_mul !mxE.
by rewrite -[Y]trmxK -!trmx_mul mulmxA -mxvec_dotmul trmx_mul trmxK vec_mxK.
exists (mxvec (\matrix_i a i)); split.
by case/mxvec_indexP=> i j; rewrite mxvecE mxE; apply: Ea.
rewrite -[mxvec _]trmxK -trmx_mul mxvec_dotmul -mulmxA trmx_mul !mxE.
apply: eq_bigr => i _; rewrite Da1 !mxE; congr (_ * _).
by apply: eq_bigr => j _; rewrite !mxE.
suffices [m [X [[u [_ Du]] idealM]]]: exists m,
exists X, let M := memM memR m X in M 1 /\ forall y, M y -> M (q.[w] * y).
- do [set M := memM _ m X; move: q.[w] => z] in idealM *.
have MX i: M (X 0 i).
by exists (delta_mx 0 i); split=> [j|]; rewrite -?rowE !mxE.
have /fin_all_exists[a /all_and2[Fa Da1]] i := idealM _ (MX i).
have /fin_all_exists[r Dr] i := fin_all_exists (Fa i).
pose A := \matrix_(i, j) r j i; pose B := z%:M - map_mx RtoK A.
have XB0: X *m B = 0.
apply/eqP; rewrite mulmxBr mul_mx_scalar subr_eq0; apply/eqP/rowP=> i.
by rewrite !mxE Da1 mxE; apply: eq_bigr=> j _; rewrite !mxE mulrC Dr.
exists (char_poly A); first exact: char_poly_monic.
have: (\det B *: (u *m X^T)) 0 0 == 0.
rewrite scalemxAr -linearZ -mul_mx_scalar -mul_mx_adj mulmxA XB0 /=.
by rewrite mul0mx trmx0 mulmx0 mxE.
rewrite mxE -Du mulr1 rootE -horner_evalE -2!det_map_mx; congr (\det _ == 0).
rewrite raddfB/= map_scalar_mx; apply/matrixP=> i j.
by rewrite !mxE raddfB raddfMn/= map_polyX map_polyC /horner_eval !hornerE.
pose gen1 x E y := exists2 r, pXin E r & y = r.[x]; pose gen := foldr gen1 memR.
have gen1S (E : K -> Prop) x y: E 0 -> E y -> gen1 x E y.
by exists y%:P => [i|]; rewrite ?hornerC ?coefC //; case: ifP.
have genR S y: memR y -> gen S y.
by elim: S => //= x S IH in y * => /IH; apply/gen1S/IH.
have gen0 := genR _ 0 memR0; have gen_1 := genR _ 1 memR1.
have{gen1S} genS S y: y \in S -> gen S y.
elim: S => //= x S IH /predU1P[-> | /IH//]; last exact: gen1S.
by exists 'X => [i|]; rewrite ?hornerX // coefX; apply: genR.
pose propD (R : K -> Prop) := forall x y, R x -> R y -> R (x + y).
have memRD: propD memR.
by move=> _ _ [a ->] [b ->]; exists (a + b); rewrite rmorphD.
have genD S: propD (gen S).
elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerD.
by exists (r1 + r2) => // i; rewrite coefD; apply: IH.
have gen_sum S := big_ind _ (gen0 S) (genD S).
pose propM (R : K -> Prop) := forall x y, R x -> R y -> R (x * y).
have memRM: propM memR.
by move=> _ _ [a ->] [b ->]; exists (a * b); rewrite rmorphM.
have genM S: propM (gen S).
elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerM.
by exists (r1 * r2) => // i; rewrite coefM; apply: gen_sum => j _; apply: IH.
have gen_horner S r y: pXin (gen S) r -> gen S y -> gen S r.[y].
move=> Sq Sy; rewrite horner_coef; apply: gen_sum => [[i _] /= _].
by elim: {2}i => [|n IHn]; rewrite ?mulr1 // exprSr mulrA; apply: genM.
pose S := w :: q ++ p; suffices [m [X defX]]: finM memR (gen S).
exists m, X => M; split=> [|y /defX Xy]; first exact/defX.
apply/defX/genM => //; apply: gen_horner => // [i|]; last exact/genS/mem_head.
rewrite -[q]coefK coef_poly; case: ifP => // lt_i_q.
by apply: genS; rewrite inE mem_cat mem_nth ?orbT.
pose intR R y := exists r, [/\ r \is monic, root r y & pXin R r].
pose fix genI s := if s is y :: s1 then intR (gen s1) y /\ genI s1 else True.
have{mon_p pw0 intRp intRq}: genI S.
split; set S1 := _ ++ _; first exists p.
split=> // i; rewrite -[p]coefK coef_poly; case: ifP => // lt_i_p.
by apply: genS; rewrite mem_cat orbC mem_nth.
set S2 := S1; have: all [in S1] S2 by apply/allP.
elim: S2 => //= y S2 IH /andP[S1y S12]; split; last exact: IH.
have{q S S1 IH S1y S12 intRp intRq} [q mon_q qx0]: integralOver RtoK y.
by move: S1y; rewrite mem_cat => /orP[]; [apply: intRq | apply: intRp].
exists (map_poly RtoK q); split=> // [|i]; first exact: monic_map.
by rewrite coef_map /=; apply: genR.
elim: {w p q}S => /= [_|x S IH [[p [mon_p px0 Sp]] /IH{IH}[m2 [X2 defS]]]].
exists 1, 1 => y; split=> [[a [Fa ->]] | Fy].
by rewrite tr_scalar_mx mulmx1; apply: Fa.
by exists y%:M; split=> [i|]; rewrite 1?ord1 ?tr_scalar_mx ?mulmx1 mxE.
pose m1 := (size p).-1; pose X1 := \row_(i < m1) x ^+ i.
have [m [X defM]] := tensorM memR m1 m2 X1 X2; set M := memM _ _ _ in defM.
exists m, X => y; rewrite -/M; split=> [/defM[a [M2a]] | [q Sq]] -> {y}.
exists (rVpoly a) => [i|].
by rewrite coef_rVpoly; case/insub: i => // i; apply/defS/M2a.
rewrite mxE (horner_coef_wide _ (size_poly _ _)) -/(rVpoly a).
by apply: eq_bigr => i _; rewrite coef_rVpoly_ord !mxE.
have M_0: M 0 by exists 0; split=> [i|]; rewrite ?mul0mx mxE.
have M_D: propD M.
move=> _ _ [a [Fa ->]] [b [Fb ->]]; exists (a + b).
by rewrite mulmxDl !mxE; split=> // i /[1!mxE]; apply: memRD.
have{M_0 M_D} Msum := big_ind _ M_0 M_D.
rewrite horner_coef; apply: (Msum) => i _; case: i q`_i {Sq}(Sq i) => /=.
elim: {q}(size q) => // n IHn i i_le_n y Sy.
have [i_lt_m1 | m1_le_i] := ltnP i m1.
apply/defM; exists (y *: delta_mx 0 (Ordinal i_lt_m1)); split=> [j|].
by apply/defS; rewrite !mxE /= mulr_natr; case: eqP.
by rewrite -scalemxAl -rowE !mxE.
rewrite -(subnK m1_le_i) exprD -[x ^+ m1]subr0 -(rootP px0) horner_coef.
rewrite polySpred ?monic_neq0 // -/m1 big_ord_recr /= -lead_coefE.
rewrite opprD addrC (monicP mon_p) mul1r subrK !mulrN -mulNr !mulr_sumr.
apply: Msum => j _; rewrite [X in M X]mulrA mulrACA -exprD; apply: IHn.
by rewrite -addnS addnC addnBA // leq_subLR leq_add.
by rewrite -mulN1r; do 2!apply: (genM) => //; apply: genR.
Qed.
Lemma integral_root_monic u p :
p \is monic -> root p u -> {in p : seq K, integralRange RtoK} ->
integralOver RtoK u.
Proof.
move=> mon_p pu0 intRp; rewrite -[u]hornerX.
apply: integral_horner_root mon_p pu0 intRp _.
by apply/integral_poly => i; rewrite coefX; apply: integral_nat.
Qed.
Let integral0_RtoK := integral0 RtoK.
Let integral1_RtoK := integral1 RtoK.
Let monicXsubC_K := @monicXsubC K.
Hint Resolve integral0_RtoK integral1_RtoK monicXsubC_K : core.
Let XsubC0 (u : K) : root ('X - u%:P) u. Proof. by rewrite root_XsubC. Qed.
Let intR_XsubC u :
integralOver RtoK (- u) -> {in 'X - u%:P : seq K, integralRange RtoK}.
Proof. by move=> intRu v; rewrite polyseqXsubC !inE => /pred2P[]->. Qed.
Lemma integral_opp u : integralOver RtoK u -> integralOver RtoK (- u).
Proof. by rewrite -{1}[u]opprK => /intR_XsubC/integral_root_monic; apply. Qed.
Lemma integral_horner (p : {poly K}) u :
{in p : seq K, integralRange RtoK} -> integralOver RtoK u ->
integralOver RtoK p.[u].
Proof. by move=> ? /integral_opp/intR_XsubC/integral_horner_root; apply. Qed.
Lemma integral_sub u v :
integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u - v).
Proof.
move=> intRu /integral_opp/intR_XsubC/integral_horner/(_ intRu).
by rewrite !hornerE.
Qed.
Lemma integral_add u v :
integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u + v).
Proof. by rewrite -{2}[v]opprK => intRu /integral_opp; apply: integral_sub. Qed.
Lemma integral_mul u v :
integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u * v).
Proof.
rewrite -{2}[v]hornerX -hornerZ => intRu; apply: integral_horner.
by apply/integral_poly=> i; rewrite coefZ coefX mulr_natr mulrb; case: ifP.
Qed.
End IntegralOverComRing.
Section IntegralOverField.
Variables (F E : fieldType) (FtoE : {rmorphism F -> E}).
Definition algebraicOver (fFtoE : F -> E) u :=
exists2 p, p != 0 & root (map_poly fFtoE p) u.
Notation mk_mon p := ((lead_coef p)^-1 *: p).
Lemma integral_algebraic u : algebraicOver FtoE u <-> integralOver FtoE u.
Proof.
split=> [] [p p_nz pu0]; last by exists p; rewrite ?monic_neq0.
exists (mk_mon p); first by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0.
by rewrite linearZ rootE hornerZ (rootP pu0) mulr0.
Qed.
Lemma algebraic_id a : algebraicOver FtoE (FtoE a).
Proof. exact/integral_algebraic/integral_id. Qed.
Lemma algebraic0 : algebraicOver FtoE 0.
Proof. exact/integral_algebraic/integral0. Qed.
Lemma algebraic1 : algebraicOver FtoE 1.
Proof. exact/integral_algebraic/integral1. Qed.
Lemma algebraic_opp x : algebraicOver FtoE x -> algebraicOver FtoE (- x).
Proof. by move/integral_algebraic/integral_opp/integral_algebraic. Qed.
Lemma algebraic_add x y :
algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x + y).
Proof.
move/integral_algebraic=> intFx /integral_algebraic intFy.
exact/integral_algebraic/integral_add.
Qed.
Lemma algebraic_sub x y :
algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x - y).
Proof. by move=> algFx /algebraic_opp; apply: algebraic_add. Qed.
Lemma algebraic_mul x y :
algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x * y).
Proof.
move/integral_algebraic=> intFx /integral_algebraic intFy.
exact/integral_algebraic/integral_mul.
Qed.
Lemma algebraic_inv u : algebraicOver FtoE u -> algebraicOver FtoE u^-1.
Proof.
have [-> | /expf_neq0 nz_u_n] := eqVneq u 0; first by rewrite invr0.
case=> p nz_p pu0; exists (Poly (rev p)).
apply/eqP=> /polyP/(_ 0); rewrite coef_Poly coef0 nth_rev ?size_poly_gt0 //.
by apply/eqP; rewrite subn1 lead_coef_eq0.
apply/eqP/(mulfI (nz_u_n (size p).-1)); rewrite mulr0 -(rootP pu0).
rewrite (@horner_coef_wide _ (size p)); last first.
by rewrite size_map_poly -(size_rev p) size_Poly.
rewrite horner_coef mulr_sumr size_map_poly.
rewrite [rhs in _ = rhs](reindex_inj rev_ord_inj) /=.
apply: eq_bigr => i _; rewrite !coef_map coef_Poly nth_rev // mulrCA.
by congr (_ * _); rewrite -{1}(subnKC (valP i)) addSn addnC exprD exprVn ?mulfK.
Qed.
Lemma algebraic_div x y :
algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x / y).
Proof. by move=> algFx /algebraic_inv; apply: algebraic_mul. Qed.
Lemma integral_inv x : integralOver FtoE x -> integralOver FtoE x^-1.
Proof. by move/integral_algebraic/algebraic_inv/integral_algebraic. Qed.
Lemma integral_div x y :
integralOver FtoE x -> integralOver FtoE y -> integralOver FtoE (x / y).
Proof. by move=> algFx /integral_inv; apply: integral_mul. Qed.
Lemma integral_root p u :
p != 0 -> root p u -> {in p : seq E, integralRange FtoE} ->
integralOver FtoE u.
Proof.
move=> nz_p pu0 algFp.
have mon_p1: mk_mon p \is monic.
by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0.
have p1u0: root (mk_mon p) u by rewrite rootE hornerZ (rootP pu0) mulr0.
apply: integral_root_monic mon_p1 p1u0 _ => _ /(nthP 0)[i ltip <-].
rewrite coefZ mulrC; rewrite size_scale ?invr_eq0 ?lead_coef_eq0 // in ltip.
by apply: integral_div; apply/algFp/mem_nth; rewrite -?polySpred.
Qed.
End IntegralOverField.
(* Lifting term, formula, envs and eval to matrices. Wlog, and for the sake *)
(* of simplicity, we only lift (tensor) envs to row vectors; we can always *)
(* use mxvec/vec_mx to store and retrieve matrices. *)
(* We don't provide definitions for addition, subtraction, scaling, etc, *)
(* because they have simple matrix expressions. *)
Module MatrixFormula.
Section MatrixFormula.
Variable F : fieldType.
Local Notation False := GRing.False.
Local Notation True := GRing.True.
Local Notation And := GRing.And (only parsing).
Local Notation Add := GRing.Add (only parsing).
Local Notation Bool b := (GRing.Bool b%bool).
Local Notation term := (GRing.term F).
Local Notation form := (GRing.formula F).
Local Notation eval := GRing.eval.
Local Notation holds := GRing.holds.
Local Notation qf_form := GRing.qf_form.
Local Notation qf_eval := GRing.qf_eval.
Definition eval_mx (e : seq F) := @map_mx term F (eval e).
Definition mx_term := @map_mx F term GRing.Const.
Lemma eval_mx_term e m n (A : 'M_(m, n)) : eval_mx e (mx_term A) = A.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Definition mulmx_term m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) :=
\matrix_(i, k) (\big[Add/0]_j (A i j * B j k))%T.
Lemma eval_mulmx e m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) :
eval_mx e (mulmx_term A B) = eval_mx e A *m eval_mx e B.
Proof.
apply/matrixP=> i k; rewrite !mxE /= ((big_morph (eval e)) 0 +%R) //=.
by apply: eq_bigr => j _; rewrite /= !mxE.
Qed.
Local Notation morphAnd f := ((big_morph f) true andb).
Let Schur m n (A : 'M[term]_(1 + m, 1 + n)) (a := A 0 0) :=
\matrix_(i, j) (drsubmx A i j - a^-1 * dlsubmx A i 0%R * ursubmx A 0%R j)%T.
Fixpoint mxrank_form (r m n : nat) : 'M_(m, n) -> form :=
match m, n return 'M_(m, n) -> form with
| m'.+1, n'.+1 => fun A : 'M_(1 + m', 1 + n') =>
let nzA k := A k.1 k.2 != 0 in
let xSchur k := Schur (xrow k.1 0%R (xcol k.2 0%R A)) in
let recf k := Bool (r > 0) /\ mxrank_form r.-1 (xSchur k) in
GRing.Pick nzA recf (Bool (r == 0%N))
| _, _ => fun _ => Bool (r == 0%N)
end%T.
Lemma mxrank_form_qf r m n (A : 'M_(m, n)) : qf_form (mxrank_form r A).
Proof.
by elim: m r n A => [|m IHm] r [|n] A //=; rewrite GRing.Pick_form_qf /=.
Qed.
Lemma eval_mxrank e r m n (A : 'M_(m, n)) :
qf_eval e (mxrank_form r A) = (\rank (eval_mx e A) == r).
Proof.
elim: m r n A => [|m IHm] r [|n] A /=; try by case r; rewrite unlock.
rewrite GRing.eval_Pick !unlock /=; set pf := fun _ => _.
rewrite -(@eq_pick _ pf) => [|k]; rewrite {}/pf ?mxE // eq_sym.
case: pick => [[i j]|] //=; set B := _ - _; have:= mxrankE B.
case: (Gaussian_elimination_ B) r => [[_ _] _] [|r] //= <-; rewrite {}IHm eqSS.
by congr (\rank _ == r); apply/matrixP=> k l; rewrite !(mxE, big_ord1) !tpermR.
Qed.
Lemma eval_vec_mx e m n (u : 'rV_(m * n)) :
eval_mx e (vec_mx u) = vec_mx (eval_mx e u).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma eval_mxvec e m n (A : 'M_(m, n)) :
eval_mx e (mxvec A) = mxvec (eval_mx e A).
Proof. by rewrite -{2}[A]mxvecK eval_vec_mx vec_mxK. Qed.
Section Subsetmx.
Variables (m1 m2 n : nat) (A : 'M[term]_(m1, n)) (B : 'M[term]_(m2, n)).
Definition submx_form :=
\big[And/True]_(r < n.+1) (mxrank_form r (col_mx A B) ==> mxrank_form r B)%T.
Lemma eval_col_mx e :
eval_mx e (col_mx A B) = col_mx (eval_mx e A) (eval_mx e B).
Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed.
Lemma submx_form_qf : qf_form submx_form.
Proof.
by rewrite (morphAnd (@qf_form _)) ?big1 //= => r _; rewrite !mxrank_form_qf.
Qed.
Lemma eval_submx e : qf_eval e submx_form = (eval_mx e A <= eval_mx e B)%MS.
Proof.
rewrite (morphAnd (qf_eval e)) //= big_andE /=.
apply/forallP/idP=> /= [|sAB d]; last first.
rewrite !eval_mxrank eval_col_mx -addsmxE; apply/implyP=> /eqP <-.
by rewrite mxrank_leqif_sup ?addsmxSr // addsmx_sub sAB /=.
move/(_ (inord (\rank (eval_mx e (col_mx A B))))).
rewrite inordK ?ltnS ?rank_leq_col // !eval_mxrank eqxx /= eval_col_mx.
by rewrite -addsmxE mxrank_leqif_sup ?addsmxSr // addsmx_sub; case/andP.
Qed.
End Subsetmx.
Section Env.
Variable d : nat.
Definition seq_of_rV (v : 'rV_d) : seq F := fgraph [ffun i => v 0 i].
Lemma size_seq_of_rV v : size (seq_of_rV v) = d.
Proof. by rewrite tuple.size_tuple card_ord. Qed.
Lemma nth_seq_of_rV x0 v (i : 'I_d) : nth x0 (seq_of_rV v) i = v 0 i.
Proof. by rewrite nth_fgraph_ord ffunE. Qed.
Definition row_var k : 'rV[term]_d := \row_i ('X_(k * d + i))%T.
Definition row_env (e : seq 'rV_d) := flatten (map seq_of_rV e).
Lemma nth_row_env e k (i : 'I_d) : (row_env e)`_(k * d + i) = e`_k 0 i.
Proof.
elim: e k => [|v e IHe] k; first by rewrite !nth_nil mxE.
rewrite /row_env /= nth_cat size_seq_of_rV.
case: k => [|k]; first by rewrite (valP i) nth_seq_of_rV.
by rewrite mulSn -addnA -if_neg -leqNgt leq_addr addKn IHe.
Qed.
Lemma eval_row_var e k : eval_mx (row_env e) (row_var k) = e`_k :> 'rV_d.
Proof. by apply/rowP=> i; rewrite !mxE /= nth_row_env. Qed.
Definition Exists_row_form k (f : form) :=
foldr GRing.Exists f (codom (fun i : 'I_d => k * d + i)%N).
Lemma Exists_rowP e k f :
d > 0 ->
((exists v : 'rV[F]_d, holds (row_env (set_nth 0 e k v)) f)
<-> holds (row_env e) (Exists_row_form k f)).
Proof.
move=> d_gt0; pose i_ j := Ordinal (ltn_pmod j d_gt0).
have d_eq j: (j = j %/ d * d + i_ j)%N := divn_eq j d.
split=> [[v f_v] | ]; last case/GRing.foldExistsP=> e' ee' f_e'.
apply/GRing.foldExistsP; exists (row_env (set_nth 0 e k v)) => {f f_v}// j.
rewrite [j]d_eq !nth_row_env nth_set_nth /=; case: eqP => // ->.
by case/imageP; exists (i_ j).
exists (\row_i e'`_(k * d + i)); apply: eq_holds f_e' => j /=.
move/(_ j): ee'; rewrite [j]d_eq !nth_row_env nth_set_nth /=.
case: eqP => [-> | ne_j_k -> //]; first by rewrite mxE.
apply/mapP=> [[r lt_r_d]]; rewrite -d_eq => def_j; case: ne_j_k.
by rewrite def_j divnMDl // divn_small ?addn0.
Qed.
End Env.
End MatrixFormula.
End MatrixFormula.
Section ConjMx.
Context {F : fieldType}.
Definition conjmx (m n : nat)
(V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V.
Notation restrictmx V := (conjmx (row_base V)).
Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) :
stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f.
Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed.
Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)):
stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A.
Proof.
move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA.
rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //.
by rewrite mulmx_sub ?stablemx_row_base.
Qed.
Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) :
{in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}.
Proof.
move=> f g; rewrite !inE => Vf Vg /=.
by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base.
Qed.
Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) :
row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//.
by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA.
Qed.
Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) :
V \in unitmx -> row_free W -> stablemx W f ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//.
by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit.
Qed.
Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) :
W \in unitmx -> row_free V -> stablemx V (conjmx W f) ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//.
by rewrite /row_free mxrankMfree ?row_free_unit.
Qed.
Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) :
V \in unitmx -> W \in unitmx ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed.
Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) :
row_free V -> conjmx V a%:M = a%:M.
Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed.
Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0.
Proof. by rewrite /conjmx !mul0mx. Qed.
Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0.
Proof. by rewrite /conjmx mulmx0 mul0mx. Qed.
Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx ->
conjmx V f = V *m f *m invmx V.
Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed.
Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f.
Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed.
Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx ->
conjmx (invmx V) f = invmx V *m f *m V.
Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed.
Lemma conjmxK (n : nat) (V f : 'M[F]_n) :
V \in unitmx -> conjmx (invmx V) (conjmx V f) = f.
Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed.
Lemma conjmxVK (n : nat) (V f : 'M[F]_n) :
V \in unitmx -> conjmx V (conjmx (invmx V) f) = f.
Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed.
Lemma horner_mx_conj m n p (V : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) :
row_free V -> stablemx V f ->
horner_mx (conjmx V f) p = conjmx V (horner_mx f p).
Proof.
move=> V_free V_stab; rewrite/conjmx; elim/poly_ind: p => [|p c].
by rewrite !rmorph0 mulmx0 mul0mx.
rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->.
rewrite [_ * _]mulmxA [_ *m (V *m _)]mulmxA mulmxKpV ?horner_mx_stable//.
apply: (row_free_inj V_free); rewrite [_ *m V]mulmxDl.
pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable).
by rewrite !mulmxKpV -?[V *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC.
Qed.
Lemma horner_mx_uconj n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) :
V \is a GRing.unit ->
horner_mx (V *m f *m invmx V) p = V *m horner_mx f p *m invmx V.
Proof.
move=> V_unit; rewrite -!conjumx//.
by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit.
Qed.
Lemma horner_mx_uconjC n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) :
V \is a GRing.unit ->
horner_mx (invmx V *m f *m V) p = invmx V *m horner_mx f p *m V.
Proof.
move=> V_unit; rewrite -[X in _ *m X](invmxK V).
by rewrite horner_mx_uconj ?invmxK ?unitmx_inv.
Qed.
Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) :
row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f.
Proof.
by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0.
Qed.
Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) :
V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f.
Proof.
have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1).
move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp.
apply/andP; split; first by rewrite mxminpoly_conj ?simp.
by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp.
Qed.
Section fixed_stablemx_space.
Variables (m n : nat).
Implicit Types (V : 'M[F]_(m, n)) (A : 'M[F]_n).
Implicit Types (a : F) (p : {poly F}).
Section Sub.
Variable (k : nat).
Implicit Types (W : 'M[F]_(k, m)).
Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V ->
(W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS.
Proof.
case: n m => [|n'] [|m'] in V f W * => fV rfV; rewrite ?thinmx0//.
by rewrite /row_free mxrank.unlock in rfV.
by rewrite mul0mx !sub0mx.
apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first.
by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA.
move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//.
by rewrite -mulmxA mulmx_sub// horner_mx_stable//.
Qed.
Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V ->
(W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS.
Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed.
End Sub.
Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V ->
{subset eigenpoly (conjmx V f) <= eigenpoly f}.
Proof.
move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//.
move=> xV_le_fa x_neq0; apply/eigenpolyP.
by exists (x *m V); rewrite ?mulmx_free_eq0.
Qed.
Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V ->
{subset eigenvalue (conjmx V f) <= eigenvalue f}.
Proof.
by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx.
Qed.
Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V ->
conjmx V f = a%:M.
Proof.
by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp.
Qed.
End fixed_stablemx_space.
End ConjMx.
Notation restrictmx V := (conjmx (row_base V)).
Definition simmx_to_for {F : fieldType} {m n}
(P : 'M_(m, n)) A (S : {pred 'M[F]_m}) := S (conjmx P A).
Notation "A ~_ P '{' 'in' S '}'" := (simmx_to_for P A S)
(at level 70, P at level 0, format "A ~_ P '{' 'in' S '}'") :
ring_scope.
Notation simmx_for P A B := (A ~_P {in PredOfSimpl.coerce (pred1 B)}).
Notation "A ~_ P B" := (simmx_for P A B) (format "A ~_ P B").
Notation simmx_in S A B := (exists2 P, P \in S & A ~_P B).
Notation "A '~_{in' S '}' B" := (simmx_in S A B)
(at level 70, format "A '~_{in' S '}' B").
Notation simmx_in_to S A S' := (exists2 P, P \in S & A ~_P {in S'}).
Notation "A '~_{in' S '}' '{' 'in' S' '}'" := (simmx_in_to S A S')
(format "A '~_{in' S '}' '{' 'in' S' '}'").
Notation all_simmx_in S As S' :=
(exists2 P, P \in S & all [pred A | A ~_P {in S'}] As).
Notation diagonalizable_for P A := (A ~_P {in is_diag_mx}).
Notation diagonalizable_in S A := (A ~_{in S} {in is_diag_mx}).
Notation diagonalizable A := (diagonalizable_in unitmx A).
Notation codiagonalizable_in S As := (all_simmx_in S As is_diag_mx).
Notation codiagonalizable As := (codiagonalizable_in unitmx As).
Section Simmxity.
Context {F : fieldType}.
Lemma simmxPp m n {P : 'M[F]_(m, n)} {A B} :
stablemx P A -> A ~_P B -> P *m A = B *m P.
Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed.
Lemma simmxW m n {P : 'M[F]_(m, n)} {A B} : row_free P ->
P *m A = B *m P -> A ~_P B.
Proof. by rewrite /(_ ~__ _)/= /conjmx => fP ->; rewrite mulmxKp. Qed.
Section Simmx.
Context {n : nat}.
Implicit Types (A B P : 'M[F]_n) (As : seq 'M[F]_n) (d : 'rV[F]_n).
Lemma simmxP {P A B} : P \in unitmx ->
reflect (P *m A = B *m P) (A ~_P B).
Proof.
move=> p_unit; apply: (iffP idP); first exact/simmxPp/stablemx_unit.
by apply: simmxW; rewrite row_free_unit.
Qed.
Lemma simmxRL {P A B} : P \in unitmx ->
reflect (B = P *m A *m invmx P) (A ~_P B).
Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed.
Lemma simmxLR {P A B} : P \in unitmx ->
reflect (A = conjmx (invmx P) B) (A ~_P B).
Proof.
by move=> Pu; rewrite conjVmx//; apply: (iffP (simmxRL Pu)) => ->;
rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1).
Qed.
End Simmx.
Lemma simmx_minpoly {n} {P A B : 'M[F]_n.+1} : P \in unitmx ->
A ~_P B -> mxminpoly A = mxminpoly B.
Proof. by move=> Pu /eqP<-; rewrite mxminpoly_uconj. Qed.
Lemma diagonalizable_for_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) :
diagonalizable_for (row_base P) A = is_diag_mx (restrictmx P A).
Proof. by []. Qed.
Lemma diagonalizable_forPp m n (P : 'M[F]_(m, n)) A :
reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0)
(diagonalizable_for P A).
Proof. exact: @is_diag_mxP. Qed.
Lemma diagonalizable_forP n (P : 'M[F]_n) A : P \in unitmx ->
reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0)
(diagonalizable_for P A).
Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed.
Lemma diagonalizable_forPex {m} {n} {P : 'M[F]_(m, n)} {A} :
reflect (exists D, A ~_P (diag_mx D)) (diagonalizable_for P A).
Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed.
Lemma diagonalizable_forLR n {P : 'M[F]_n} {A} : P \in unitmx ->
reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (diagonalizable_for P A).
Proof.
by move=> Punit; apply: (iffP diagonalizable_forPex) => -[D /(simmxLR Punit)]; exists D.
Qed.
Lemma diagonalizable_for_mxminpoly {n} {P A : 'M[F]_n.+1}
(rs := undup [seq conjmx P A i i | i <- enum 'I_n.+1]) :
P \in unitmx -> diagonalizable_for P A ->
mxminpoly A = \prod_(r <- rs) ('X - r%:P).
Proof.
rewrite /rs => pu /(diagonalizable_forLR pu)[d {A rs}->].
rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag.
by rewrite [in X in _ = X](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx.
Qed.
End Simmxity.
Lemma diagonalizable_for_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat)
(V_ : forall i, 'M[F]_(p_ i, m)) (A : 'M[F]_m) :
mxdirect (\sum_i <<V_ i>>) ->
(forall i, stablemx (V_ i) A) ->
(forall i, row_free (V_ i)) ->
diagonalizable_for (\mxcol_i V_ i) A = [forall i, diagonalizable_for (V_ i) A].
Proof.
move=> Vd VA rAV; have aVA : stablemx (\mxcol_i V_ i) A.
rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//.
by move=> i; rewrite (eqmx_stable _ (genmxE _)).
apply/diagonalizable_forPex/'forall_diagonalizable_forPex => /=
[[D /(simmxPp aVA) +] i|/(_ _)/sigW DoA].
rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol.
move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq.
by exists D0; apply/simmxW.
exists (\mxrow_i tag (DoA i)); apply/simmxW.
rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=.
by under [leqRHS]eq_bigr do rewrite genmxE (eqP (rAV _)).
rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i.
by case: DoA => /= k /(simmxPp); rewrite VA => /(_ isT) ->.
Qed.
Section Diag.
Variable (F : fieldType).
Lemma codiagonalizable1 n (A : 'M[F]_n) :
codiagonalizable [:: A] <-> diagonalizable A.
Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed.
Definition codiagonalizablePfull n (As : seq 'M[F]_n) :
codiagonalizable As
<-> exists m, exists2 P : 'M_(m, n), row_full P &
all [pred A | diagonalizable_for P A] As.
Proof.
split => [[P Punit SPA]|[m [P Pfull SPA]]].
by exists n => //; exists P; rewrite ?row_full_unit.
have Qfull := fullrowsub_unit Pfull.
exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=.
have /allP /(_ _ AAs)/= /diagonalizable_forPex[d /simmxPp] := SPA.
rewrite submx_full// => /(_ isT) PA_eq.
apply/diagonalizable_forPex; exists (colsub (fullrankfun Pfull) d).
apply/simmxP => //; apply/row_matrixP => i.
rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE.
have /(congr1 (row (fullrankfun Pfull i))) := PA_eq.
by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->.
Qed.
Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) :
(\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) ->
(forall i, all (fun A => stablemx (V_ i) A) As) ->
(forall i, codiagonalizable (map (restrictmx (V_ i)) As)) ->
codiagonalizable As.
Proof.
move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof.
pose P_ i := tag (Pof i).
have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof.
have P_diag i A : A \in As -> diagonalizable_for (P_ i *m row_base (V_ i)) A.
move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit.
rewrite all_map => /allP/(_ A AAs); rewrite /= !/(diagonalizable_for _ _).
by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV.
pose P := \mxcol_i (P_ i *m row_base (V_ i)).
have P_full i : row_full (P_ i) by rewrite row_full_unit.
have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS.
exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull.
apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=.
- rewrite -sub1mx eqmx_col.
by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1.
apply/allP => A AAs /=; rewrite diagonalizable_for_sum.
- by apply/forallP => i; apply: P_diag.
- rewrite mxdirectE/=.
under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1.
by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1.
- by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV.
- by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit.
Qed.
Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d).
Proof.
exists 1%:M; rewrite ?unitmx1// /(diagonalizable_for _ _).
by rewrite conj1mx diag_mx_is_diag.
Qed.
Hint Resolve diagonalizable_diag : core.
Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n).
Proof. by rewrite -diag_const_mx. Qed.
Hint Resolve diagonalizable_scalar : core.
Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n).
Proof.
by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn.
Qed.
Hint Resolve diagonalizable0 : core.
Lemma diagonalizablePeigen {n} {A : 'M[F]_n} :
diagonalizable A <->
exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS.
Proof.
split=> [df|[rs urs rsP]].
suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS.
exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP.
elim: rs => //= r rs IHrs; rewrite big_cons.
case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx.
apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr.
have rrs : (index r rs < size rs)%N by rewrite index_mem.
rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//.
move: df => [P Punit /(diagonalizable_forLR Punit)[d ->]].
exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=.
apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP;
rewrite ?sub1mx ?submx1 ?row_full_unit//.
rewrite submx_full ?row_full_unit//=.
apply/row_subP => i; rewrite rowE (sumsmx_sup i)//.
apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//.
by rewrite -rowE row_diag_mx scalemxAl.
have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace A rs`_i).
apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj.
by apply: uniqP rsij; rewrite ?inE.
rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1.
apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=.
case: n => [|n] in A {mxdirect_eigenspaces} rsP *.
by rewrite thinmx0 sub0mx.
by rewrite comm_mx_stable_eigenspace.
apply/codiagonalizable1.
rewrite (@conjmx_eigenvalue _ _ _ rs`_i); first exact: diagonalizable_scalar.
by rewrite eq_row_base.
by rewrite row_base_free.
Qed.
Lemma diagonalizableP n' (n := n'.+1) (A : 'M[F]_n) :
diagonalizable A <->
exists2 rs, uniq rs & mxminpoly A %| \prod_(x <- rs) ('X - x%:P).
Proof.
split=> [[P Punit /diagonalizable_forPex[d /(simmxLR Punit)->]]|].
rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag.
by eexists; [|by []]; rewrite undup_uniq.
move=> + /ltac:(apply/diagonalizablePeigen) => -[rs rsu rsP]; exists rs => //.
rewrite (big_nth 0) [X in (X :=: _)%MS](big_nth 0) !big_mkord in rsP *.
rewrite (eq_bigr _ (fun _ _ => eigenspace_poly _ _)).
apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)) => //.
by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq.
Qed.
Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) :
stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)).
Proof.
case: m n => [|m] [|n] in V d * => Vd rdV; rewrite ?thinmx0.
- by [].
- by [].
- by exfalso; move: rdV; rewrite /row_free mxrank.unlock eqxx orbT.
apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1].
exists u; first by rewrite undup_uniq.
by rewrite (dvdp_trans (mxminpoly_conj (f:=diag_mx d) _ _))// mxminpoly_diag.
Qed.
Lemma codiagonalizableP n (As : seq 'M[F]_n) :
{in As &, forall A B, comm_mx A B} /\ {in As, forall A, diagonalizable A}
<-> codiagonalizable As.
Proof.
split => [cdAs|[P Punit /allP/= AsD]]/=; last first.
split; last by exists P; rewrite // AsD.
move=> A B AAs BAs; move=> /(_ _ _)/diagonalizable_forPex/sigW in AsD.
have [[dA /simmxLR->//] [dB /simmxLR->//]] := (AsD _ AAs, AsD _ BAs).
by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv.
move: cdAs => -[]; move/(rwP (all_comm_mxP _)) => cdAs cdAs'.
have [k] := ubnP (size As); elim: k => [|k IHk]//= in n As cdAs cdAs' *.
case: As cdAs cdAs' => [|A As]//=; first by exists 1%:M; rewrite ?unitmx1.
rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP AAsC AsC dAAs] Ask.
have /diagonalizablePeigen [rs urs rs1] := dAAs _ (mem_head _ _).
rewrite (big_nth 0) big_mkord in rs1.
have eAB (i : 'I_(size rs)) B : B \in A :: As -> stablemx (eigenspace A rs`_i) B.
case: n => [|n'] in B A As AAsC AsC {dAAs rs1 Ask} * => B_AAs.
by rewrite thinmx0 sub0mx.
rewrite comm_mx_stable_eigenspace//.
by move: B_AAs; rewrite !inE => /predU1P [->//|/AAsC].
apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=].
- apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj.
by apply: uniqP rsij; rewrite ?inE.
- by apply/allP => B B_AAs; rewrite eAB.
rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//.
set Bs := map _ _; suff [P Punit /= PBs] : codiagonalizable Bs.
exists P; rewrite /= ?PBs ?andbT// /(diagonalizable_for _ _).
by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit.
apply: IHk; rewrite ?size_map/= ?ltnS//.
apply/all_comm_mxP => _ _ /mapP[/= B BAs ->] /mapP[/= h hAs ->].
rewrite -!conjmxM ?inE ?stablemx_row_base ?eAB ?inE ?BAs ?hAs ?orbT//.
by rewrite (all_comm_mxP _ AsC).
move=> _ /mapP[/= B BAs ->].
have: stablemx (row_base (eigenspace A rs`_i)) B.
by rewrite stablemx_row_base eAB// inE BAs orbT.
have := dAAs B; rewrite inE BAs orbT => /(_ isT) [P Punit].
move=> /diagonalizable_forPex[D /(simmxLR Punit)->] sePD.
have rAeP : row_free (row_base (eigenspace A rs`_i) *m invmx P).
by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base.
rewrite -conjMumx ?unitmx_inv ?row_base_free => [|//|//|//].
apply/diagonalizable_conj_diag => //.
by rewrite stablemx_comp// stablemx_unit ?unitmx_inv.
Qed.
End Diag.
|
gproduct.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import choice fintype bigop finset fingroup morphism.
From mathcomp Require Import quotient action finfun.
(******************************************************************************)
(* Partial, semidirect, central, and direct products. *)
(* ++ Internal products, with A, B : {set gT}, are partial operations : *)
(* partial_product A B == A * B if A is a group normalised by the group B, *)
(* and the empty set otherwise. *)
(* A ><| B == A * B if this is a semi-direct product (i.e., if A *)
(* is normalised by B and intersects it trivially). *)
(* A \* B == A * B if this is a central product ([A, B] = 1). *)
(* A \x B == A * B if this is a direct product. *)
(* [complements to K in G] == set of groups H s.t. K * H = G and K :&: H = 1. *)
(* [splits G, over K] == [complements to K in G] is not empty. *)
(* remgr A B x == the right remainder in B of x mod A, i.e., *)
(* some element of (A :* x) :&: B. *)
(* divgr A B x == the "division" in B of x by A: for all x, *)
(* x = divgr A B x * remgr A B x. *)
(* ++ External products : *)
(* pairg1, pair1g == the isomorphisms aT1 -> aT1 * aT2, aT2 -> aT1 * aT2. *)
(* (aT1 * aT2 has a direct product group structure.) *)
(* dfung1 i == the morphism gT i -> {dffun forall j, gt j} where *)
(* gT : I -> finGroupType is a family of finite groups. *)
(* sdprod_by to == the semidirect product defined by to : groupAction H K. *)
(* This is a finGroupType; the actual semidirect product is *)
(* the total set [set: sdprod_by to] on that type. *)
(* sdpair[12] to == the isomorphisms injecting K and H into *)
(* sdprod_by to = sdpair1 to @* K ><| sdpair2 to @* H. *)
(* External central products (with identified centers) will be defined later *)
(* in file center.v. *)
(* ++ Morphisms on product groups: *)
(* pprodm nAB fJ fAB == the morphism extending fA and fB on A <*> B when *)
(* nAB : B \subset 'N(A), *)
(* fJ : {in A & B, morph_act 'J 'J fA fB}, and *)
(* fAB : {in A :&: B, fA =1 fB}. *)
(* sdprodm defG fJ == the morphism extending fA and fB on G, given *)
(* defG : A ><| B = G and *)
(* fJ : {in A & B, morph_act 'J 'J fA fB}. *)
(* xsdprodm fHKact == the total morphism on sdprod_by to induced by *)
(* fH : {morphism H >-> rT}, fK : {morphism K >-> rT}, *)
(* with to : groupAction K H, *)
(* given fHKact : morph_act to 'J fH fK. *)
(* cprodm defG cAB fAB == the morphism extending fA and fB on G, when *)
(* defG : A \* B = G, *)
(* cAB : fB @* B \subset 'C(fB @* A), *)
(* and fAB : {in A :&: B, fA =1 fB}. *)
(* dprodm defG cAB == the morphism extending fA and fB on G, when *)
(* defG : A \x B = G and *)
(* cAB : fA @* B \subset 'C(fA @* A) *)
(* mulgm (x, y) == x * y; mulgm is an isomorphism from setX A B to G *)
(* iff A \x B = G . *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Defs.
Variables gT : finGroupType.
Implicit Types A B C : {set gT}.
Definition partial_product A B :=
if A == 1 then B else if B == 1 then A else
if [&& group_set A, group_set B & B \subset 'N(A)] then A * B else set0.
Definition semidirect_product A B :=
if A :&: B \subset 1%G then partial_product A B else set0.
Definition central_product A B :=
if B \subset 'C(A) then partial_product A B else set0.
Definition direct_product A B :=
if A :&: B \subset 1%G then central_product A B else set0.
Definition complements_to_in A B :=
[set K : {group gT} | A :&: K == 1 & A * K == B].
Definition splits_over B A := complements_to_in A B != set0.
(* Product remainder functions -- right variant only. *)
Definition remgr A B x := repr (A :* x :&: B).
Definition divgr A B x := x * (remgr A B x)^-1.
End Defs.
Arguments partial_product _ _%_g _%_g : clear implicits.
Arguments semidirect_product _ _%_g _%_g : clear implicits.
Arguments central_product _ _%_g _%_g : clear implicits.
Arguments complements_to_in _ _%_g _%_g.
Arguments splits_over _ _%_g _%_g.
Arguments remgr _ _%_g _%_g _%_g.
Arguments divgr _ _%_g _%_g _%_g.
Arguments direct_product : clear implicits.
Notation pprod := (partial_product _).
Notation sdprod := (semidirect_product _).
Notation cprod := (central_product _).
Notation dprod := (direct_product _).
Notation "G ><| H" := (sdprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "G \* H" := (cprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "G \x H" := (dprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "[ 'complements' 'to' A 'in' B ]" := (complements_to_in A B)
(format "[ 'complements' 'to' A 'in' B ]") : group_scope.
Notation "[ 'splits' B , 'over' A ]" := (splits_over B A)
(format "[ 'splits' B , 'over' A ]") : group_scope.
(* Prenex Implicits remgl divgl. *)
Prenex Implicits remgr divgr.
Section InternalProd.
Variable gT : finGroupType.
Implicit Types A B C : {set gT}.
Implicit Types G H K L M : {group gT}.
Local Notation pprod := (partial_product gT).
Local Notation sdprod := (semidirect_product gT) (only parsing).
Local Notation cprod := (central_product gT) (only parsing).
Local Notation dprod := (direct_product gT) (only parsing).
Lemma pprod1g : left_id 1 pprod.
Proof. by move=> A; rewrite /pprod eqxx. Qed.
Lemma pprodg1 : right_id 1 pprod.
Proof. by move=> A; rewrite /pprod eqxx; case: eqP. Qed.
Variant are_groups A B : Prop := AreGroups K H of A = K & B = H.
Lemma group_not0 G : set0 <> G.
Proof. by move/setP/(_ 1); rewrite inE group1. Qed.
Lemma mulg0 : right_zero (@set0 gT) mulg.
Proof.
by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE.
Qed.
Lemma mul0g : left_zero (@set0 gT) mulg.
Proof.
by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE.
Qed.
Lemma pprodP A B G :
pprod A B = G -> [/\ are_groups A B, A * B = G & B \subset 'N(A)].
Proof.
have Gnot0 := @group_not0 G; rewrite /pprod; do 2?case: eqP => [-> ->| _].
- by rewrite mul1g norms1; split; first exists 1%G G.
- by rewrite mulg1 sub1G; split; first exists G 1%G.
by case: and3P => // [[gA gB ->]]; split; first exists (Group gA) (Group gB).
Qed.
Lemma pprodE K H : H \subset 'N(K) -> pprod K H = K * H.
Proof.
move=> nKH; rewrite /pprod nKH !groupP /=.
by do 2?case: eqP => [-> | _]; rewrite ?mulg1 ?mul1g.
Qed.
Lemma pprodEY K H : H \subset 'N(K) -> pprod K H = K <*> H.
Proof. by move=> nKH; rewrite pprodE ?norm_joinEr. Qed.
Lemma pprodW A B G : pprod A B = G -> A * B = G. Proof. by case/pprodP. Qed.
Lemma pprodWC A B G : pprod A B = G -> B * A = G.
Proof. by case/pprodP=> _ <- /normC. Qed.
Lemma pprodWY A B G : pprod A B = G -> A <*> B = G.
Proof. by case/pprodP=> [[K H -> ->] <- /norm_joinEr]. Qed.
Lemma pprodJ A B x : pprod A B :^ x = pprod (A :^ x) (B :^ x).
Proof.
rewrite /pprod !conjsg_eq1 !group_setJ normJ conjSg -conjsMg.
by do 3?case: ifP => // _; apply: conj0g.
Qed.
(* Properties of the remainders *)
Lemma remgrMl K B x y : y \in K -> remgr K B (y * x) = remgr K B x.
Proof. by move=> Ky; rewrite {1}/remgr rcosetM rcoset_id. Qed.
Lemma remgrP K B x : (remgr K B x \in K :* x :&: B) = (x \in K * B).
Proof.
set y := _ x; apply/idP/mulsgP=> [|[g b Kg Bb x_gb]].
rewrite inE rcoset_sym mem_rcoset => /andP[Kxy' By].
by exists (x * y^-1) y; rewrite ?mulgKV.
by apply: (mem_repr b); rewrite inE rcoset_sym mem_rcoset x_gb mulgK Kg.
Qed.
Lemma remgr1 K H x : x \in K -> remgr K H x = 1.
Proof. by move=> Kx; rewrite /remgr rcoset_id ?repr_group. Qed.
Lemma divgr_eq A B x : x = divgr A B x * remgr A B x.
Proof. by rewrite mulgKV. Qed.
Lemma divgrMl K B x y : x \in K -> divgr K B (x * y) = x * divgr K B y.
Proof. by move=> Hx; rewrite /divgr remgrMl ?mulgA. Qed.
Lemma divgr_id K H x : x \in K -> divgr K H x = x.
Proof. by move=> Kx; rewrite /divgr remgr1 // invg1 mulg1. Qed.
Lemma mem_remgr K B x : x \in K * B -> remgr K B x \in B.
Proof. by rewrite -remgrP => /setIP[]. Qed.
Lemma mem_divgr K B x : x \in K * B -> divgr K B x \in K.
Proof. by rewrite -remgrP inE rcoset_sym mem_rcoset => /andP[]. Qed.
Section DisjointRem.
Variables K H : {group gT}.
Hypothesis tiKH : K :&: H = 1.
Lemma remgr_id x : x \in H -> remgr K H x = x.
Proof.
move=> Hx; apply/eqP; rewrite eq_mulgV1 (sameP eqP set1gP) -tiKH inE.
rewrite -mem_rcoset groupMr ?groupV // -in_setI remgrP.
by apply: subsetP Hx; apply: mulG_subr.
Qed.
Lemma remgrMid x y : x \in K -> y \in H -> remgr K H (x * y) = y.
Proof. by move=> Kx Hy; rewrite remgrMl ?remgr_id. Qed.
Lemma divgrMid x y : x \in K -> y \in H -> divgr K H (x * y) = x.
Proof. by move=> Kx Hy; rewrite /divgr remgrMid ?mulgK. Qed.
End DisjointRem.
(* Intersection of a centraliser with a disjoint product. *)
Lemma subcent_TImulg K H A :
K :&: H = 1 -> A \subset 'N(K) :&: 'N(H) -> 'C_K(A) * 'C_H(A) = 'C_(K * H)(A).
Proof.
move=> tiKH /subsetIP[nKA nHA]; apply/eqP.
rewrite group_modl ?subsetIr // eqEsubset setSI ?mulSg ?subsetIl //=.
apply/subsetP=> _ /setIP[/mulsgP[x y Kx Hy ->] cAxy].
rewrite inE cAxy mem_mulg // inE Kx /=.
apply/centP=> z Az; apply/commgP/conjg_fixP.
move/commgP/conjg_fixP/(congr1 (divgr K H)): (centP cAxy z Az).
by rewrite conjMg !divgrMid ?memJ_norm // (subsetP nKA, subsetP nHA).
Qed.
(* Complements, and splitting. *)
Lemma complP H A B :
reflect (A :&: H = 1 /\ A * H = B) (H \in [complements to A in B]).
Proof. by apply: (iffP setIdP); case; split; apply/eqP. Qed.
Lemma splitsP B A :
reflect (exists H, H \in [complements to A in B]) [splits B, over A].
Proof. exact: set0Pn. Qed.
Lemma complgC H K G :
(H \in [complements to K in G]) = (K \in [complements to H in G]).
Proof.
rewrite !inE setIC; congr (_ && _).
by apply/eqP/eqP=> defG; rewrite -(comm_group_setP _) // defG groupP.
Qed.
Section NormalComplement.
Variables K H G : {group gT}.
Hypothesis complH_K : H \in [complements to K in G].
Lemma remgrM : K <| G -> {in G &, {morph remgr K H : x y / x * y}}.
Proof.
case/normalP=> _; case/complP: complH_K => tiKH <- nK_KH x y KHx KHy.
rewrite {1}(divgr_eq K H y) mulgA (conjgCV x) {2}(divgr_eq K H x) -2!mulgA.
rewrite mulgA remgrMid //; last by rewrite groupMl mem_remgr.
by rewrite groupMl !(=^~ mem_conjg, nK_KH, mem_divgr).
Qed.
Lemma divgrM : H \subset 'C(K) -> {in G &, {morph divgr K H : x y / x * y}}.
Proof.
move=> cKH; have /complP[_ defG] := complH_K.
have nsKG: K <| G by rewrite -defG -cent_joinEr // normalYl cents_norm.
move=> x y Gx Gy; rewrite {1}/divgr remgrM // invMg -!mulgA (mulgA y).
by congr (_ * _); rewrite -(centsP cKH) ?groupV ?(mem_remgr, mem_divgr, defG).
Qed.
End NormalComplement.
(* Semi-direct product *)
Lemma sdprod1g : left_id 1 sdprod.
Proof. by move=> A; rewrite /sdprod subsetIl pprod1g. Qed.
Lemma sdprodg1 : right_id 1 sdprod.
Proof. by move=> A; rewrite /sdprod subsetIr pprodg1. Qed.
Lemma sdprodP A B G :
A ><| B = G -> [/\ are_groups A B, A * B = G, B \subset 'N(A) & A :&: B = 1].
Proof.
rewrite /sdprod; case: ifP => [trAB | _ /group_not0[] //].
case/pprodP=> gAB defG nBA; split=> {defG nBA}//.
by case: gAB trAB => H K -> -> /trivgP.
Qed.
Lemma sdprodE K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K * H.
Proof. by move=> nKH tiKH; rewrite /sdprod tiKH subxx pprodE. Qed.
Lemma sdprodEY K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K <*> H.
Proof. by move=> nKH tiKH; rewrite sdprodE ?norm_joinEr. Qed.
Lemma sdprodWpp A B G : A ><| B = G -> pprod A B = G.
Proof. by case/sdprodP=> [[K H -> ->] <- /pprodE]. Qed.
Lemma sdprodW A B G : A ><| B = G -> A * B = G.
Proof. by move/sdprodWpp/pprodW. Qed.
Lemma sdprodWC A B G : A ><| B = G -> B * A = G.
Proof. by move/sdprodWpp/pprodWC. Qed.
Lemma sdprodWY A B G : A ><| B = G -> A <*> B = G.
Proof. by move/sdprodWpp/pprodWY. Qed.
Lemma sdprodJ A B x : (A ><| B) :^ x = A :^ x ><| B :^ x.
Proof.
rewrite /sdprod -conjIg sub_conjg conjs1g -pprodJ.
by case: ifP => _ //; apply: imset0.
Qed.
Lemma sdprod_context G K H : K ><| H = G ->
[/\ K <| G, H \subset G, K * H = G, H \subset 'N(K) & K :&: H = 1].
Proof.
case/sdprodP=> _ <- nKH tiKH.
by rewrite /normal mulG_subl mulG_subr mulG_subG normG.
Qed.
Lemma sdprod_compl G K H : K ><| H = G -> H \in [complements to K in G].
Proof. by case/sdprodP=> _ mulKH _ tiKH; apply/complP. Qed.
Lemma sdprod_normal_complP G K H :
K <| G -> reflect (K ><| H = G) (K \in [complements to H in G]).
Proof.
case/andP=> _ nKG; rewrite complgC.
apply: (iffP idP); [case/complP=> tiKH mulKH | exact: sdprod_compl].
by rewrite sdprodE ?(subset_trans _ nKG) // -mulKH mulG_subr.
Qed.
Lemma sdprod_card G A B : A ><| B = G -> (#|A| * #|B|)%N = #|G|.
Proof. by case/sdprodP=> [[H K -> ->] <- _ /TI_cardMg]. Qed.
Lemma sdprod_isom G A B :
A ><| B = G ->
{nAB : B \subset 'N(A) | isom B (G / A) (restrm nAB (coset A))}.
Proof.
case/sdprodP=> [[K H -> ->] <- nKH tiKH].
by exists nKH; rewrite quotientMidl quotient_isom.
Qed.
Lemma sdprod_isog G A B : A ><| B = G -> B \isog G / A.
Proof. by case/sdprod_isom=> nAB; apply: isom_isog. Qed.
Lemma sdprod_subr G A B M : A ><| B = G -> M \subset B -> A ><| M = A <*> M.
Proof.
case/sdprodP=> [[K H -> ->] _ nKH tiKH] sMH.
by rewrite sdprodEY ?(subset_trans sMH) //; apply/trivgP; rewrite -tiKH setIS.
Qed.
Lemma index_sdprod G A B : A ><| B = G -> #|B| = #|G : A|.
Proof.
case/sdprodP=> [[K H -> ->] <- _ tiHK].
by rewrite indexMg -indexgI setIC tiHK indexg1.
Qed.
Lemma index_sdprodr G A B M :
A ><| B = G -> M \subset B -> #|B : M| = #|G : A <*> M|.
Proof.
move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] mulKH nKH _] defG sMH.
rewrite -!divgS //=; last by rewrite -genM_join gen_subG -mulKH mulgS.
by rewrite -(sdprod_card defG) -(sdprod_card (sdprod_subr defG sMH)) divnMl.
Qed.
Lemma quotient_sdprodr_isom G A B M :
A ><| B = G -> M <| B ->
{f : {morphism B / M >-> coset_of (A <*> M)} |
isom (B / M) (G / (A <*> M)) f
& forall L, L \subset B -> f @* (L / M) = A <*> L / (A <*> M)}.
Proof.
move=> defG nsMH; have [defA defB]: A = <<A>>%G /\ B = <<B>>%G.
by have [[K1 H1 -> ->] _ _ _] := sdprodP defG; rewrite /= !genGid.
do [rewrite {}defA {}defB; move: {A}<<A>>%G {B}<<B>>%G => K H] in defG nsMH *.
have [[nKH /isomP[injKH imKH]] sMH] := (sdprod_isom defG, normal_sub nsMH).
have [[nsKG sHG mulKH _ _] nKM] := (sdprod_context defG, subset_trans sMH nKH).
have nsKMG: K <*> M <| G.
by rewrite -quotientYK // -mulKH -quotientK ?cosetpre_normal ?quotient_normal.
have [/= f inj_f im_f] := third_isom (joing_subl K M) nsKG nsKMG.
rewrite quotientYidl //= -imKH -(restrm_quotientE nKH sMH) in f inj_f im_f.
have /domP[h [_ ker_h _ im_h]]: 'dom (f \o quotm _ nsMH) = H / M.
by rewrite ['dom _]morphpre_quotm injmK.
have{} im_h L: L \subset H -> h @* (L / M) = K <*> L / (K <*> M).
move=> sLH; have [sLG sKKM] := (subset_trans sLH sHG, joing_subl K M).
rewrite im_h morphim_comp morphim_quotm [_ @* L]restrm_quotientE ?im_f //.
rewrite quotientY ?(normsG sKKM) ?(subset_trans sLG) ?normal_norm //.
by rewrite (quotientS1 sKKM) joing1G.
exists h => //; apply/isomP; split; last by rewrite im_h //= (sdprodWY defG).
by rewrite ker_h injm_comp ?injm_quotm.
Qed.
Lemma quotient_sdprodr_isog G A B M :
A ><| B = G -> M <| B -> B / M \isog G / (A <*> M).
Proof.
move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] _ _ _] => defG nsMH.
by have [h /isom_isog->] := quotient_sdprodr_isom defG nsMH.
Qed.
Lemma sdprod_modl A B G H :
A ><| B = G -> A \subset H -> A ><| (B :&: H) = G :&: H.
Proof.
case/sdprodP=> {A B} [[A B -> ->]] <- nAB tiAB sAH.
rewrite -group_modl ?sdprodE ?subIset ?nAB //.
by rewrite setIA tiAB (setIidPl _) ?sub1G.
Qed.
Lemma sdprod_modr A B G H :
A ><| B = G -> B \subset H -> (H :&: A) ><| B = H :&: G.
Proof.
case/sdprodP=> {A B}[[A B -> ->]] <- nAB tiAB sAH.
rewrite -group_modr ?sdprodE ?normsI // ?normsG //.
by rewrite -setIA tiAB (setIidPr _) ?sub1G.
Qed.
Lemma subcent_sdprod B C G A :
B ><| C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) ><| 'C_C(A) = 'C_G(A).
Proof.
case/sdprodP=> [[H K -> ->] <- nHK tiHK] nHKA {B C G}.
rewrite sdprodE ?subcent_TImulg ?normsIG //.
by rewrite -setIIl tiHK (setIidPl (sub1G _)).
Qed.
Lemma sdprod_recl n G K H K1 :
#|G| <= n -> K ><| H = G -> K1 \proper K -> H \subset 'N(K1) ->
exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K1 ><| H = G1].
Proof.
move=> leGn; case/sdprodP=> _ defG nKH tiKH ltK1K nK1H.
have tiK1H: K1 :&: H = 1 by apply/trivgP; rewrite -tiKH setSI ?proper_sub.
exists (K1 <*> H)%G; rewrite /= -defG sdprodE // norm_joinEr //.
rewrite ?mulSg ?proper_sub ?(leq_trans _ leGn) //=.
by rewrite -defG ?TI_cardMg // ltn_pmul2r ?proper_card.
Qed.
Lemma sdprod_recr n G K H H1 :
#|G| <= n -> K ><| H = G -> H1 \proper H ->
exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K ><| H1 = G1].
Proof.
move=> leGn; case/sdprodP=> _ defG nKH tiKH ltH1H.
have [sH1H _] := andP ltH1H; have nKH1 := subset_trans sH1H nKH.
have tiKH1: K :&: H1 = 1 by apply/trivgP; rewrite -tiKH setIS.
exists (K <*> H1)%G; rewrite /= -defG sdprodE // norm_joinEr //.
rewrite ?mulgS // ?(leq_trans _ leGn) //=.
by rewrite -defG ?TI_cardMg // ltn_pmul2l ?proper_card.
Qed.
Lemma mem_sdprod G A B x : A ><| B = G -> x \in G ->
exists y, exists z,
[/\ y \in A, z \in B, x = y * z &
{in A & B, forall u t, x = u * t -> u = y /\ t = z}].
Proof.
case/sdprodP=> [[K H -> ->{A B}] <- _ tiKH] /mulsgP[y z Ky Hz ->{x}].
exists y; exists z; split=> // u t Ku Ht eqyzut.
move: (congr1 (divgr K H) eqyzut) (congr1 (remgr K H) eqyzut).
by rewrite !remgrMid // !divgrMid.
Qed.
(* Central product *)
Lemma cprod1g : left_id 1 cprod.
Proof. by move=> A; rewrite /cprod cents1 pprod1g. Qed.
Lemma cprodg1 : right_id 1 cprod.
Proof. by move=> A; rewrite /cprod sub1G pprodg1. Qed.
Lemma cprodP A B G :
A \* B = G -> [/\ are_groups A B, A * B = G & B \subset 'C(A)].
Proof. by rewrite /cprod; case: ifP => [cAB /pprodP[] | _ /group_not0[]]. Qed.
Lemma cprodE G H : H \subset 'C(G) -> G \* H = G * H.
Proof. by move=> cGH; rewrite /cprod cGH pprodE ?cents_norm. Qed.
Lemma cprodEY G H : H \subset 'C(G) -> G \* H = G <*> H.
Proof. by move=> cGH; rewrite cprodE ?cent_joinEr. Qed.
Lemma cprodWpp A B G : A \* B = G -> pprod A B = G.
Proof. by case/cprodP=> [[K H -> ->] <- /cents_norm/pprodE]. Qed.
Lemma cprodW A B G : A \* B = G -> A * B = G.
Proof. by move/cprodWpp/pprodW. Qed.
Lemma cprodWC A B G : A \* B = G -> B * A = G.
Proof. by move/cprodWpp/pprodWC. Qed.
Lemma cprodWY A B G : A \* B = G -> A <*> B = G.
Proof. by move/cprodWpp/pprodWY. Qed.
Lemma cprodJ A B x : (A \* B) :^ x = A :^ x \* B :^ x.
Proof.
by rewrite /cprod centJ conjSg -pprodJ; case: ifP => _ //; apply: imset0.
Qed.
Lemma cprod_normal2 A B G : A \* B = G -> A <| G /\ B <| G.
Proof.
case/cprodP=> [[K H -> ->] <- cKH]; rewrite -cent_joinEr //.
by rewrite normalYl normalYr !cents_norm // centsC.
Qed.
Lemma bigcprodW I (r : seq I) P F G :
\big[cprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G.
Proof.
elim/big_rec2: _ G => // i A B _ IH G /cprodP[[_ H _ defB] <- _].
by rewrite (IH H) defB.
Qed.
Lemma bigcprodWY I (r : seq I) P F G :
\big[cprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G.
Proof.
elim/big_rec2: _ G => [|i A B _ IH G]; first by rewrite gen0.
case/cprodP => [[K H -> defB] <- cKH].
by rewrite -[<<_>>]joing_idr (IH H) ?cent_joinEr -?defB.
Qed.
Lemma triv_cprod A B : (A \* B == 1) = (A == 1) && (B == 1).
Proof.
case A1: (A == 1); first by rewrite (eqP A1) cprod1g.
apply/eqP=> /cprodP[[G H defA ->]] /eqP.
by rewrite defA trivMg -defA A1.
Qed.
Lemma cprod_ntriv A B : A != 1 -> B != 1 ->
A \* B =
if [&& group_set A, group_set B & B \subset 'C(A)] then A * B else set0.
Proof.
move=> A1 B1; rewrite /cprod; case: ifP => cAB; rewrite ?cAB ?andbF //=.
by rewrite /pprod -if_neg A1 -if_neg B1 cents_norm.
Qed.
Lemma trivg0 : (@set0 gT == 1) = false.
Proof. by rewrite eqEcard cards0 cards1 andbF. Qed.
Lemma group0 : group_set (@set0 gT) = false.
Proof. by rewrite /group_set inE. Qed.
Lemma cprod0g A : set0 \* A = set0.
Proof. by rewrite /cprod centsC sub0set /pprod group0 trivg0 !if_same. Qed.
Lemma cprodC : commutative cprod.
Proof.
rewrite /cprod => A B; case: ifP => cAB; rewrite centsC cAB // /pprod.
by rewrite andbCA normC !cents_norm // 1?centsC //; do 2!case: eqP => // ->.
Qed.
Lemma cprodA : associative cprod.
Proof.
move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !cprod1g.
case B1: (B == 1); first by rewrite (eqP B1) cprod1g cprodg1.
case C1: (C == 1); first by rewrite (eqP C1) !cprodg1.
rewrite !(triv_cprod, cprod_ntriv) ?{}A1 ?{}B1 ?{}C1 //.
case: isgroupP => [[G ->{A}] | _]; last by rewrite group0.
case: (isgroupP B) => [[H ->{B}] | _]; last by rewrite group0.
case: (isgroupP C) => [[K ->{C}] | _]; last by rewrite group0 !andbF.
case cGH: (H \subset 'C(G)); case cHK: (K \subset 'C(H)); last first.
- by rewrite group0.
- by rewrite group0 /= mulG_subG cGH andbF.
- by rewrite group0 /= centM subsetI cHK !andbF.
rewrite /= mulgA mulG_subG centM subsetI cGH cHK andbT -(cent_joinEr cHK).
by rewrite -(cent_joinEr cGH) !groupP.
Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {set gT} 1 cprod
cprodA cprodC cprod1g.
Lemma cprod_modl A B G H :
A \* B = G -> A \subset H -> A \* (B :&: H) = G :&: H.
Proof.
case/cprodP=> [[U V -> -> {A B}]] defG cUV sUH.
by rewrite cprodE; [rewrite group_modl ?defG | rewrite subIset ?cUV].
Qed.
Lemma cprod_modr A B G H :
A \* B = G -> B \subset H -> (H :&: A) \* B = H :&: G.
Proof. by rewrite -!(cprodC B) !(setIC H); apply: cprod_modl. Qed.
Lemma bigcprodYP (I : finType) (P : pred I) (H : I -> {group gT}) :
reflect (forall i j, P i -> P j -> i != j -> H i \subset 'C(H j))
(\big[cprod/1]_(i | P i) H i == (\prod_(i | P i) H i)%G).
Proof.
apply: (iffP eqP) => [defG i j Pi Pj neq_ij | cHH].
rewrite (bigD1 j) // (bigD1 i) /= ?cprodA in defG; last exact/andP.
by case/cprodP: defG => [[K _ /cprodP[//]]].
set Q := P; have sQP: subpred Q P by []; have [n leQn] := ubnP #|Q|.
elim: n => // n IHn in (Q) leQn sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0.
rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *.
rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]].
rewrite bigprodGE cprodEY // gen_subG; apply/bigcupsP=> j /andP[neq_ji Qj].
by rewrite cHH ?sQP.
Qed.
Lemma bigcprodEY I r (P : pred I) (H : I -> {group gT}) G :
abelian G -> (forall i, P i -> H i \subset G) ->
\big[cprod/1]_(i <- r | P i) H i = (\prod_(i <- r | P i) H i)%G.
Proof.
move=> cGG sHG; apply/eqP; rewrite !(big_tnth _ _ r).
by apply/bigcprodYP=> i j Pi Pj _; rewrite (sub_abelian_cent2 cGG) ?sHG.
Qed.
Lemma perm_bigcprod (I : eqType) r1 r2 (A : I -> {set gT}) G x :
\big[cprod/1]_(i <- r1) A i = G -> {in r1, forall i, x i \in A i} ->
perm_eq r1 r2 ->
\prod_(i <- r1) x i = \prod_(i <- r2) x i.
Proof.
elim: r1 r2 G => [|i r1 IHr] r2 G defG Ax eq_r12.
by rewrite perm_sym in eq_r12; rewrite (perm_small_eq _ eq_r12) ?big_nil.
have /rot_to[n r3 Dr2]: i \in r2 by rewrite -(perm_mem eq_r12) mem_head.
transitivity (\prod_(j <- rot n r2) x j).
rewrite Dr2 !big_cons in defG Ax *; have [[_ G1 _ defG1] _ _] := cprodP defG.
rewrite (IHr r3 G1) //; first by case/allP/andP: Ax => _ /allP.
by rewrite -(perm_cons i) -Dr2 perm_sym perm_rot perm_sym.
rewrite -(cat_take_drop n r2) [in LHS]cat_take_drop in eq_r12 *.
rewrite (perm_big _ eq_r12) !big_cat /= !(big_nth i) !big_mkord in defG *.
have /cprodP[[G1 G2 defG1 defG2] _ /centsP-> //] := defG.
rewrite defG2 -(bigcprodW defG2) mem_prodg // => k _; apply: Ax.
by rewrite (perm_mem eq_r12) mem_cat orbC mem_nth.
rewrite defG1 -(bigcprodW defG1) mem_prodg // => k _; apply: Ax.
by rewrite (perm_mem eq_r12) mem_cat mem_nth.
Qed.
Lemma reindex_bigcprod (I J : finType) (h : J -> I) P (A : I -> {set gT}) G x :
{on SimplPred P, bijective h} -> \big[cprod/1]_(i | P i) A i = G ->
{in SimplPred P, forall i, x i \in A i} ->
\prod_(i | P i) x i = \prod_(j | P (h j)) x (h j).
Proof.
case=> h1 hK h1K defG Ax; have [e big_e [Ue mem_e] _] := big_enumP P.
rewrite -!big_e in defG *; rewrite -(big_map h P x) -[RHS]big_filter filter_map.
apply: perm_bigcprod defG _ _ => [i|]; first by rewrite mem_e => /Ax.
have [r _ [Ur /= mem_r] _] := big_enumP; apply: uniq_perm Ue _ _ => [|i].
by rewrite map_inj_in_uniq // => i j; rewrite !mem_r ; apply: (can_in_inj hK).
rewrite mem_e; apply/idP/mapP=> [Pi|[j r_j ->]]; last by rewrite -mem_r.
by exists (h1 i); rewrite ?mem_r h1K.
Qed.
(* Direct product *)
Lemma dprod1g : left_id 1 dprod.
Proof. by move=> A; rewrite /dprod subsetIl cprod1g. Qed.
Lemma dprodg1 : right_id 1 dprod.
Proof. by move=> A; rewrite /dprod subsetIr cprodg1. Qed.
Lemma dprodP A B G :
A \x B = G -> [/\ are_groups A B, A * B = G, B \subset 'C(A) & A :&: B = 1].
Proof.
rewrite /dprod; case: ifP => trAB; last by case/group_not0.
by case/cprodP=> gAB; split=> //; case: gAB trAB => ? ? -> -> /trivgP.
Qed.
Lemma dprodE G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G * H.
Proof. by move=> cGH trGH; rewrite /dprod trGH sub1G cprodE. Qed.
Lemma dprodEY G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G <*> H.
Proof. by move=> cGH trGH; rewrite /dprod trGH subxx cprodEY. Qed.
Lemma dprodEcp A B : A :&: B = 1 -> A \x B = A \* B.
Proof. by move=> trAB; rewrite /dprod trAB subxx. Qed.
Lemma dprodEsd A B : B \subset 'C(A) -> A \x B = A ><| B.
Proof. by rewrite /dprod /cprod => ->. Qed.
Lemma dprodWcp A B G : A \x B = G -> A \* B = G.
Proof. by move=> defG; have [_ _ _ /dprodEcp <-] := dprodP defG. Qed.
Lemma dprodWsd A B G : A \x B = G -> A ><| B = G.
Proof. by move=> defG; have [_ _ /dprodEsd <-] := dprodP defG. Qed.
Lemma dprodW A B G : A \x B = G -> A * B = G.
Proof. by move/dprodWsd/sdprodW. Qed.
Lemma dprodWC A B G : A \x B = G -> B * A = G.
Proof. by move/dprodWsd/sdprodWC. Qed.
Lemma dprodWY A B G : A \x B = G -> A <*> B = G.
Proof. by move/dprodWsd/sdprodWY. Qed.
Lemma cprod_card_dprod G A B :
A \* B = G -> #|A| * #|B| <= #|G| -> A \x B = G.
Proof. by case/cprodP=> [[K H -> ->] <- cKH] /cardMg_TI; apply: dprodE. Qed.
Lemma dprodJ A B x : (A \x B) :^ x = A :^ x \x B :^ x.
Proof.
rewrite /dprod -conjIg sub_conjg conjs1g -cprodJ.
by case: ifP => _ //; apply: imset0.
Qed.
Lemma dprod_normal2 A B G : A \x B = G -> A <| G /\ B <| G.
Proof. by move/dprodWcp/cprod_normal2. Qed.
Lemma dprodYP K H : reflect (K \x H = K <*> H) (H \subset 'C(K) :\: K^#).
Proof.
rewrite subsetD -setI_eq0 setIDA setD_eq0 setIC subG1 /=.
by apply: (iffP andP) => [[cKH /eqP/dprodEY->] | /dprodP[_ _ -> ->]].
Qed.
Lemma dprodC : commutative dprod.
Proof. by move=> A B; rewrite /dprod setIC cprodC. Qed.
Lemma dprodWsdC A B G : A \x B = G -> B ><| A = G.
Proof. by rewrite dprodC => /dprodWsd. Qed.
Lemma dprodA : associative dprod.
Proof.
move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !dprod1g.
case B1: (B == 1); first by rewrite (eqP B1) dprod1g dprodg1.
case C1: (C == 1); first by rewrite (eqP C1) !dprodg1.
rewrite /dprod (fun_if (cprod A)) (fun_if (cprod^~ C)) -cprodA.
rewrite -(cprodC set0) !cprod0g cprod_ntriv ?B1 ?{}C1 //.
case: and3P B1 => [[] | _ _]; last by rewrite cprodC cprod0g !if_same.
case/isgroupP=> H ->; case/isgroupP=> K -> {B C}; move/cent_joinEr=> eHK H1.
rewrite cprod_ntriv ?trivMg ?{}A1 ?{}H1 // mulG_subG.
case: and4P => [[] | _]; last by rewrite !if_same.
case/isgroupP=> G ->{A} _ cGH _; rewrite cprodEY // -eHK.
case trGH: (G :&: H \subset _); case trHK: (H :&: K \subset _); last first.
- by rewrite !if_same.
- rewrite if_same; case: ifP => // trG_HK; case/negP: trGH.
by apply: subset_trans trG_HK; rewrite setIS ?joing_subl.
- rewrite if_same; case: ifP => // trGH_K; case/negP: trHK.
by apply: subset_trans trGH_K; rewrite setSI ?joing_subr.
do 2![case: ifP] => // trGH_K trG_HK; [case/negP: trGH_K | case/negP: trG_HK].
apply: subset_trans trHK; rewrite subsetI subsetIr -{2}(mulg1 H) -mulGS.
rewrite setIC group_modl ?joing_subr //= cent_joinEr // -eHK.
by rewrite -group_modr ?joing_subl //= setIC -(normC (sub1G _)) mulSg.
apply: subset_trans trGH; rewrite subsetI subsetIl -{2}(mul1g H) -mulSG.
rewrite setIC group_modr ?joing_subl //= eHK -(cent_joinEr cGH).
by rewrite -group_modl ?joing_subr //= setIC (normC (sub1G _)) mulgS.
Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {set gT} 1 dprod
dprodA dprodC dprod1g.
Lemma bigdprodWcp I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) F i = G.
Proof.
elim/big_rec2: _ G => // i A B _ IH G /dprodP[[K H -> defB] <- cKH _].
by rewrite (IH H) // cprodE -defB.
Qed.
Lemma bigdprodW I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G.
Proof. by move/bigdprodWcp; apply: bigcprodW. Qed.
Lemma bigdprodWY I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G.
Proof. by move/bigdprodWcp; apply: bigcprodWY. Qed.
Lemma bigdprodYP (I : finType) (P : pred I) (F : I -> {group gT}) :
reflect (forall i, P i ->
(\prod_(j | P j && (j != i)) F j)%G \subset 'C(F i) :\: (F i)^#)
(\big[dprod/1]_(i | P i) F i == (\prod_(i | P i) F i)%G).
Proof.
apply: (iffP eqP) => [defG i Pi | dxG].
rewrite !(bigD1 i Pi) /= in defG; have [[_ G' _ defG'] _ _ _] := dprodP defG.
by apply/dprodYP; rewrite -defG defG' bigprodGE (bigdprodWY defG').
set Q := P; have sQP: subpred Q P by []; have [n leQn] := ubnP #|Q|.
elim: n => // n IHn in (Q) leQn sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0.
rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *.
rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]].
apply/dprodYP; apply: subset_trans (dxG i (sQP i Qi)); rewrite !bigprodGE.
by apply: genS; apply/bigcupsP=> j /andP[Qj ne_ji]; rewrite (bigcup_max j) ?sQP.
Qed.
Lemma dprod_modl A B G H :
A \x B = G -> A \subset H -> A \x (B :&: H) = G :&: H.
Proof.
case/dprodP=> [[U V -> -> {A B}]] defG cUV trUV sUH.
rewrite dprodEcp; first by apply: cprod_modl; rewrite ?cprodE.
by rewrite setIA trUV (setIidPl _) ?sub1G.
Qed.
Lemma dprod_modr A B G H :
A \x B = G -> B \subset H -> (H :&: A) \x B = H :&: G.
Proof. by rewrite -!(dprodC B) !(setIC H); apply: dprod_modl. Qed.
Lemma subcent_dprod B C G A :
B \x C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) \x 'C_C(A) = 'C_G(A).
Proof.
move=> defG; have [_ _ cBC _] := dprodP defG; move: defG.
by rewrite !dprodEsd 1?(centSS _ _ cBC) ?subsetIl //; apply: subcent_sdprod.
Qed.
Lemma dprod_card A B G : A \x B = G -> (#|A| * #|B|)%N = #|G|.
Proof. by case/dprodP=> [[H K -> ->] <- _]; move/TI_cardMg. Qed.
Lemma bigdprod_card I r (P : pred I) E G :
\big[dprod/1]_(i <- r | P i) E i = G ->
(\prod_(i <- r | P i) #|E i|)%N = #|G|.
Proof.
elim/big_rec2: _ G => [G <- | i A B _ IH G defG]; first by rewrite cards1.
have [[_ H _ defH] _ _ _] := dprodP defG.
by rewrite -(dprod_card defG) (IH H) defH.
Qed.
Lemma bigcprod_card_dprod I r (P : pred I) (A : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) A i = G ->
\prod_(i <- r | P i) #|A i| <= #|G| ->
\big[dprod/1]_(i <- r | P i) A i = G.
Proof.
elim: r G => [|i r IHr]; rewrite !(big_nil, big_cons) //; case: ifP => _ // G.
case/cprodP=> [[K H -> defH]]; rewrite defH => <- cKH leKH_G.
have /implyP := leq_trans leKH_G (dvdn_leq _ (dvdn_cardMg K H)).
rewrite muln_gt0 leq_pmul2l !cardG_gt0 //= => /(IHr H defH){}defH.
by rewrite defH dprodE // cardMg_TI // -(bigdprod_card defH).
Qed.
Lemma bigcprod_coprime_dprod (I : finType) (P : pred I) (A : I -> {set gT}) G :
\big[cprod/1]_(i | P i) A i = G ->
(forall i j, P i -> P j -> i != j -> coprime #|A i| #|A j|) ->
\big[dprod/1]_(i | P i) A i = G.
Proof.
move=> defG coA; set Q := P in defG *; have sQP: subpred Q P by [].
have [m leQm] := ubnP #|Q|; elim: m => // m IHm in (Q) leQm G defG sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0 in defG *.
move: defG; rewrite !(bigD1 i Qi) /= => /cprodP[[Hi Gi defAi defGi] <-].
rewrite defAi defGi => cHGi.
have{} defGi: \big[dprod/1]_(j | Q j && (j != i)) A j = Gi.
by apply: IHm => [||j /andP[/sQP]] //; rewrite (cardD1x Qi) in leQm.
rewrite defGi dprodE // coprime_TIg // -defAi -(bigdprod_card defGi).
elim/big_rec: _ => [|j n /andP[neq_ji Qj] IHn]; first exact: coprimen1.
by rewrite coprimeMr coprime_sym coA ?sQP.
Qed.
Lemma mem_dprod G A B x : A \x B = G -> x \in G ->
exists y, exists z,
[/\ y \in A, z \in B, x = y * z &
{in A & B, forall u t, x = u * t -> u = y /\ t = z}].
Proof.
move=> defG; have [_ _ cBA _] := dprodP defG.
by apply: mem_sdprod; rewrite -dprodEsd.
Qed.
Lemma mem_bigdprod (I : finType) (P : pred I) F G x :
\big[dprod/1]_(i | P i) F i = G -> x \in G ->
exists c, [/\ forall i, P i -> c i \in F i, x = \prod_(i | P i) c i
& forall e, (forall i, P i -> e i \in F i) ->
x = \prod_(i | P i) e i ->
forall i, P i -> e i = c i].
Proof.
move=> defG; rewrite -(bigdprodW defG) => /prodsgP[c Fc ->].
have [r big_r [_ mem_r] _] := big_enumP P.
exists c; split=> // e Fe eq_ce i Pi; rewrite -!{}big_r in defG eq_ce.
have{Pi}: i \in r by rewrite mem_r.
have{mem_r}: all P r by apply/allP=> j; rewrite mem_r.
elim: r G defG eq_ce => // j r IHr G.
rewrite !big_cons inE /= => /dprodP[[K H defK defH] _ _].
rewrite defK defH => tiFjH eq_ce /andP[Pj Pr].
suffices{i IHr} eq_cej: c j = e j.
case/predU1P=> [-> //|]; apply: IHr defH _ Pr.
by apply: (mulgI (c j)); rewrite eq_ce eq_cej.
rewrite !(big_nth j) !big_mkord in defH eq_ce.
move/(congr1 (divgr K H)): eq_ce; move/bigdprodW: defH => defH.
move/(all_nthP j) in Pr.
by rewrite !divgrMid // -?defK -?defH ?mem_prodg // => *; rewrite ?Fc ?Fe ?Pr.
Qed.
Lemma comm_prodG I r (G : I -> {group gT}) (P : {pred I}) :
{in P &, forall i j, commute (G i) (G j)} ->
(\prod_(i <- r | P i) G i)%G = \prod_(i <- r | P i) G i :> {set gT}.
Proof.
elim: r => /= [|i {}r IHr]; rewrite !(big_nil, big_cons)//=.
case: ifP => //= Pi Gcomm; rewrite comm_joingE {}IHr// /commute.
elim: r => [|j r IHr]; first by rewrite big_nil mulg1 mul1g.
by rewrite big_cons; case: ifP => //= Pj; rewrite mulgA Gcomm// -!mulgA IHr.
Qed.
End InternalProd.
Arguments complP {gT H A B}.
Arguments splitsP {gT B A}.
Arguments sdprod_normal_complP {gT G K H}.
Arguments dprodYP {gT K H}.
Arguments bigdprodYP {gT I P F}.
Section MorphimInternalProd.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Section OneProd.
Variables G H K : {group gT}.
Hypothesis sGD : G \subset D.
Lemma morphim_pprod : pprod K H = G -> pprod (f @* K) (f @* H) = f @* G.
Proof.
case/pprodP=> _ defG mKH; rewrite pprodE ?morphim_norms //.
by rewrite -morphimMl ?(subset_trans _ sGD) -?defG // mulG_subl.
Qed.
Lemma morphim_coprime_sdprod :
K ><| H = G -> coprime #|K| #|H| -> f @* K ><| f @* H = f @* G.
Proof.
rewrite /sdprod => defG coHK; move: defG.
by rewrite !coprime_TIg ?coprime_morph // !subxx; apply: morphim_pprod.
Qed.
Lemma injm_sdprod : 'injm f -> K ><| H = G -> f @* K ><| f @* H = f @* G.
Proof.
move=> inj_f; case/sdprodP=> _ defG nKH tiKH.
by rewrite /sdprod -injmI // tiKH morphim1 subxx morphim_pprod // pprodE.
Qed.
Lemma morphim_cprod : K \* H = G -> f @* K \* f @* H = f @* G.
Proof.
case/cprodP=> _ defG cKH; rewrite /cprod morphim_cents // morphim_pprod //.
by rewrite pprodE // cents_norm // centsC.
Qed.
Lemma injm_dprod : 'injm f -> K \x H = G -> f @* K \x f @* H = f @* G.
Proof.
move=> inj_f; case/dprodP=> _ defG cHK tiKH.
by rewrite /dprod -injmI // tiKH morphim1 subxx morphim_cprod // cprodE.
Qed.
Lemma morphim_coprime_dprod :
K \x H = G -> coprime #|K| #|H| -> f @* K \x f @* H = f @* G.
Proof.
rewrite /dprod => defG coHK; move: defG.
by rewrite !coprime_TIg ?coprime_morph // !subxx; apply: morphim_cprod.
Qed.
End OneProd.
Implicit Type G : {group gT}.
Lemma morphim_bigcprod I r (P : pred I) (H : I -> {group gT}) G :
G \subset D -> \big[cprod/1]_(i <- r | P i) H i = G ->
\big[cprod/1]_(i <- r | P i) f @* H i = f @* G.
Proof.
elim/big_rec2: _ G => [|i fB B Pi def_fB] G sGD defG.
by rewrite -defG morphim1.
case/cprodP: defG (defG) => [[Hi Gi -> defB] _ _]; rewrite defB => defG.
rewrite (def_fB Gi) //; first exact: morphim_cprod.
by apply: subset_trans sGD; case/cprod_normal2: defG => _ /andP[].
Qed.
Lemma injm_bigdprod I r (P : pred I) (H : I -> {group gT}) G :
G \subset D -> 'injm f -> \big[dprod/1]_(i <- r | P i) H i = G ->
\big[dprod/1]_(i <- r | P i) f @* H i = f @* G.
Proof.
move=> sGD injf; elim/big_rec2: _ G sGD => [|i fB B Pi def_fB] G sGD defG.
by rewrite -defG morphim1.
case/dprodP: defG (defG) => [[Hi Gi -> defB] _ _ _]; rewrite defB => defG.
rewrite (def_fB Gi) //; first exact: injm_dprod.
by apply: subset_trans sGD; case/dprod_normal2: defG => _ /andP[].
Qed.
Lemma morphim_coprime_bigdprod (I : finType) P (H : I -> {group gT}) G :
G \subset D -> \big[dprod/1]_(i | P i) H i = G ->
(forall i j, P i -> P j -> i != j -> coprime #|H i| #|H j|) ->
\big[dprod/1]_(i | P i) f @* H i = f @* G.
Proof.
move=> sGD /bigdprodWcp defG coH; have def_fG := morphim_bigcprod sGD defG.
by apply: bigcprod_coprime_dprod => // i j *; rewrite coprime_morph ?coH.
Qed.
End MorphimInternalProd.
Section QuotientInternalProd.
Variables (gT : finGroupType) (G K H M : {group gT}).
Hypothesis nMG: G \subset 'N(M).
Lemma quotient_pprod : pprod K H = G -> pprod (K / M) (H / M) = G / M.
Proof. exact: morphim_pprod. Qed.
Lemma quotient_coprime_sdprod :
K ><| H = G -> coprime #|K| #|H| -> (K / M) ><| (H / M) = G / M.
Proof. exact: morphim_coprime_sdprod. Qed.
Lemma quotient_cprod : K \* H = G -> (K / M) \* (H / M) = G / M.
Proof. exact: morphim_cprod. Qed.
Lemma quotient_coprime_dprod :
K \x H = G -> coprime #|K| #|H| -> (K / M) \x (H / M) = G / M.
Proof. exact: morphim_coprime_dprod. Qed.
End QuotientInternalProd.
Section ExternalDirProd.
Variables gT1 gT2 : finGroupType.
Definition extprod_mulg (x y : gT1 * gT2) := (x.1 * y.1, x.2 * y.2).
Definition extprod_invg (x : gT1 * gT2) := (x.1^-1, x.2^-1).
Lemma extprod_mul1g : left_id (1, 1) extprod_mulg.
Proof. by case=> x1 x2; congr (_, _); apply: mul1g. Qed.
Lemma extprod_mulVg : left_inverse (1, 1) extprod_invg extprod_mulg.
Proof. by move=> x; congr (_, _); apply: mulVg. Qed.
Lemma extprod_mulgA : associative extprod_mulg.
Proof. by move=> x y z; congr (_, _); apply: mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build (gT1 * gT2)%type
extprod_mulgA extprod_mul1g extprod_mulVg.
Lemma group_setX (H1 : {group gT1}) (H2 : {group gT2}) : group_set (setX H1 H2).
Proof.
apply/group_setP; split; first by rewrite !inE !group1.
by case=> [x1 x2] [y1 y2] /[!inE] /andP[Hx1 Hx2] /andP[Hy1 Hy2] /[!groupM].
Qed.
Canonical setX_group H1 H2 := Group (group_setX H1 H2).
Definition pairg1 x : gT1 * gT2 := (x, 1).
Definition pair1g x : gT1 * gT2 := (1, x).
Lemma pairg1_morphM : {morph pairg1 : x y / x * y}.
Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed.
Canonical pairg1_morphism := @Morphism _ _ setT _ (in2W pairg1_morphM).
Lemma pair1g_morphM : {morph pair1g : x y / x * y}.
Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed.
Canonical pair1g_morphism := @Morphism _ _ setT _ (in2W pair1g_morphM).
Lemma fst_morphM : {morph (@fst gT1 gT2) : x y / x * y}.
Proof. by move=> x y. Qed.
Lemma snd_morphM : {morph (@snd gT1 gT2) : x y / x * y}.
Proof. by move=> x y. Qed.
Canonical fst_morphism := @Morphism _ _ setT _ (in2W fst_morphM).
Canonical snd_morphism := @Morphism _ _ setT _ (in2W snd_morphM).
Lemma injm_pair1g : 'injm pair1g.
Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; apply: set11. Qed.
Lemma injm_pairg1 : 'injm pairg1.
Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; apply: set11. Qed.
Lemma morphim_pairg1 (H1 : {set gT1}) : pairg1 @* H1 = setX H1 1.
Proof. by rewrite -imset2_pair imset2_set1r morphimEsub ?subsetT. Qed.
Lemma morphim_pair1g (H2 : {set gT2}) : pair1g @* H2 = setX 1 H2.
Proof. by rewrite -imset2_pair imset2_set1l morphimEsub ?subsetT. Qed.
Lemma morphim_fstX (H1: {set gT1}) (H2 : {group gT2}) :
[morphism of fun x => x.1] @* setX H1 H2 = H1.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP=> x0 /[1!inE] /andP[Hx1 _] ->.
move=> Hx1; apply/imsetP; exists (x, 1); last by trivial.
by rewrite in_setX Hx1 /=.
Qed.
Lemma morphim_sndX (H1: {group gT1}) (H2 : {set gT2}) :
[morphism of fun x => x.2] @* setX H1 H2 = H2.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP=> x0 /[1!inE] /andP[_ Hx2] ->.
move=> Hx2; apply/imsetP; exists (1, x); last by [].
by rewrite in_setX Hx2 andbT.
Qed.
Lemma setX_prod (H1 : {set gT1}) (H2 : {set gT2}) :
setX H1 1 * setX 1 H2 = setX H1 H2.
Proof.
apply/setP=> [[x y]]; rewrite !inE /=.
apply/imset2P/andP=> [[[x1 u1] [v1 y1]] | [Hx Hy]].
rewrite !inE /= => /andP[Hx1 /eqP->] /andP[/eqP-> Hx] [-> ->].
by rewrite mulg1 mul1g.
exists (x, 1 : gT2) (1 : gT1, y); rewrite ?inE ?Hx ?eqxx //.
by rewrite /mulg /= /extprod_mulg /= mulg1 mul1g.
Qed.
Lemma setX_dprod (H1 : {group gT1}) (H2 : {group gT2}) :
setX H1 1 \x setX 1 H2 = setX H1 H2.
Proof.
rewrite dprodE ?setX_prod //.
apply/centsP=> [[x u]] /[!inE]/= /andP[/eqP-> _] [v y].
by rewrite !inE /= => /andP[_ /eqP->]; congr (_, _); rewrite ?mul1g ?mulg1.
apply/trivgP; apply/subsetP=> [[x y]]; rewrite !inE /= -!andbA.
by case/and4P=> _ /eqP-> /eqP->; rewrite eqxx.
Qed.
Lemma isog_setX1 (H1 : {group gT1}) : isog H1 (setX H1 1).
Proof.
apply/isogP; exists [morphism of restrm (subsetT H1) pairg1].
by rewrite injm_restrm ?injm_pairg1.
by rewrite morphim_restrm morphim_pairg1 setIid.
Qed.
Lemma isog_set1X (H2 : {group gT2}) : isog H2 (setX 1 H2).
Proof.
apply/isogP; exists [morphism of restrm (subsetT H2) pair1g].
by rewrite injm_restrm ?injm_pair1g.
by rewrite morphim_restrm morphim_pair1g setIid.
Qed.
Lemma setX_gen (H1 : {set gT1}) (H2 : {set gT2}) :
1 \in H1 -> 1 \in H2 -> <<setX H1 H2>> = setX <<H1>> <<H2>>.
Proof.
move=> H1_1 H2_1; apply/eqP.
rewrite eqEsubset gen_subG setXS ?subset_gen //.
(* TODO: investigate why the occurrence selection changed *)
rewrite -[in X in X \subset _]setX_prod.
rewrite -morphim_pair1g -morphim_pairg1 !morphim_gen ?subsetT //.
by rewrite morphim_pair1g morphim_pairg1 mul_subG // genS // setXS ?sub1set.
Qed.
End ExternalDirProd.
Section ExternalDirDepProd.
Variables (I : finType) (gT : I -> finGroupType).
Notation gTn := {dffun forall i, gT i}.
Implicit Types (H : forall i, {group gT i}) (x y : {dffun forall i, gT i}).
Definition extnprod_mulg (x y : gTn) : gTn := [ffun i => (x i * y i)%g].
Definition extnprod_invg (x : gTn) : gTn := [ffun i => (x i)^-1%g].
Lemma extnprod_mul1g : left_id [ffun=> 1%g] extnprod_mulg.
Proof. by move=> x; apply/ffunP => i; rewrite !ffunE mul1g. Qed.
Lemma extnprod_mulVg : left_inverse [ffun=> 1%g] extnprod_invg extnprod_mulg.
Proof. by move=> x; apply/ffunP => i; rewrite !ffunE mulVg. Qed.
Lemma extnprod_mulgA : associative extnprod_mulg.
Proof. by move=> x y z; apply/ffunP => i; rewrite !ffunE mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build {dffun forall i : I, gT i}
extnprod_mulgA extnprod_mul1g extnprod_mulVg.
Lemma oneg_ffun i : (1 : gTn) i = 1. Proof. by rewrite ffunE. Qed.
Lemma mulg_ffun i (x y : gTn) : (x * y) i = x i * y i.
Proof. by rewrite ffunE. Qed.
Lemma invg_ffun i (x : gTn) : x^-1 i = (x i)^-1.
Proof. by rewrite ffunE. Qed.
Lemma prodg_ffun T (r : seq T) (F : T -> gTn) (P : {pred T}) i :
(\prod_(t <- r | P t) F t) i = \prod_(t <- r | P t) F t i.
Proof. exact: (big_morph _ (@mulg_ffun i) (@oneg_ffun i)). Qed.
Lemma group_setXn H : group_set (setXn H).
Proof.
by apply/group_setP; split=> [|x y] /[!inE]/= => [|/forallP xH /forallP yH];
apply/forallP => i; rewrite ?ffunE (group1, groupM)// ?xH ?yH.
Qed.
Canonical setXn_group H := Group (group_setXn H).
Definition dfung1 i (g : gT i) : gTn := finfun (dfwith (fun=> 1 : gT _) g).
Lemma dfung1_id i (g : gT i) : dfung1 g i = g.
Proof. by rewrite ffunE dfwith_in. Qed.
Lemma dfung1_dflt i (g : gT i) j : i != j -> dfung1 g j = 1.
Proof. by move=> ij; rewrite ffunE dfwith_out. Qed.
Lemma dfung1_morphM i : {morph @dfung1 i : g h / g * h}.
Proof.
move=> g h; apply/ffunP=> j; have [{j}<-|nij] := eqVneq i j.
by rewrite !(dfung1_id, ffunE).
by rewrite !(dfung1_dflt, ffunE)// mulg1.
Qed.
Canonical dfung1_morphism i := @Morphism _ _ setT _ (in2W (@dfung1_morphM i)).
Lemma dffunM i : {morph (fun x => x i) : x y / x * y}.
Proof. by move=> x y; rewrite !ffunE. Qed.
Canonical dffun_morphism i := @Morphism _ _ setT _ (in2W (@dffunM i)).
Lemma injm_dfung1 i : 'injm (@dfung1 i).
Proof.
apply/subsetP => x /morphpreP[_ /set1P /ffunP/=/(_ i)].
by rewrite !(ffunE, dfung1_id) => ->; apply: set11.
Qed.
Lemma group_set_dfwith H i (G : {group gT i}) j :
group_set (dfwith (H : forall k, {set gT k}) (G : {set _}) j).
Proof.
have [<-|ij] := eqVneq i j; first by rewrite !dfwith_in// groupP.
by rewrite !dfwith_out // groupP.
Qed.
Canonical group_dfwith H i G j := Group (@group_set_dfwith H i G j).
Lemma group_dfwithE H i G j : @group_dfwith H i G j = dfwith H G j.
Proof.
by apply/val_inj; have [<-|nij]/= := eqVneq i j;
[rewrite !dfwith_in|rewrite !dfwith_out].
Qed.
Fact set1gXn_key : unit. Proof. by []. Qed.
Definition set1gXn {i} (H : {set gT i}) : {set {dffun forall i : I, gT i}} :=
locked_with set1gXn_key (setXn (dfwith (fun i0 : I => [1 gT _]%g) H)).
Lemma set1gXnE {i} (H : {set gT i}) :
set1gXn H = setXn (dfwith (fun i0 : I => [1 gT _]%g) H).
Proof. by rewrite /set1gXn unlock. Qed.
Lemma set1gXnP {i} (H : {set gT i}) x :
reflect (exists2 h, h \in H & x = dfung1 h) (x \in set1gXn H).
Proof.
rewrite set1gXnE/=; apply: (iffP setXnP) => [xP|[h hH ->] j]; last first.
by rewrite ffunE; case: dfwithP => [|k ?]; rewrite (dfwith_in, dfwith_out).
exists (x i); first by have := xP i; rewrite dfwith_in.
apply/ffunP => j; have := xP j; rewrite ffunE.
case: dfwithP => // [xiH|k neq_ik]; first by rewrite dfwith_in.
by move=> /set1gP->; rewrite dfwith_out.
Qed.
Lemma morphim_dfung1 i (G : {set gT i}) : @dfung1 i @* G = set1gXn G.
Proof.
by rewrite morphimEsub//=; apply/setP=> /= x; apply/imsetP/set1gXnP.
Qed.
Lemma morphim_dffunXn i H : dffun_morphism i @* setXn H = H i.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP => x0 /[1!inE] /forallP/(_ i)/= ? ->.
move=> Hx1; apply/imsetP; exists (dfung1 x); last by rewrite dfung1_id.
by rewrite in_setXn; apply/forallP => j /[!ffunE]; case: dfwithP.
Qed.
Lemma set1gXn_group_set {i} (H : {group gT i}) : group_set (set1gXn H).
Proof. by rewrite set1gXnE; exact: group_setXn. Qed.
Canonical groupXn1 {i} (H : {group gT i}) := Group (set1gXn_group_set H).
Lemma setXn_prod H : \prod_i set1gXn (H i) = setXn H.
Proof.
apply/setP => /= x; apply/prodsgP /setXnP => [[/= f fH {x}-> i]|xH /=].
rewrite prodg_ffun group_prod// => j _.
by have /set1gXnP[x xH ->] := fH j isT; rewrite ffunE; case: dfwithP.
exists (fun i => dfung1 (x i)) => [i _|]; first by apply/set1gXnP; exists (x i).
apply/ffunP => i; rewrite prodg_ffun (big_only1 i) ?dfung1_id//.
by move=> j ij _; rewrite dfung1_dflt.
Qed.
Lemma set1gXn_commute (H : forall i, {group gT i}) i j :
commute (set1gXn (H i)) (set1gXn (H j)).
Proof.
have [-> //|neqij] := eqVneq j i.
apply/centC/centsP => _ /set1gXnP [hi hiH ->] _ /set1gXnP [hj hjH ->].
apply/ffunP => k; rewrite !ffunE.
by case: dfwithP => [|?]; rewrite ?mulg1 ?mul1g// dfwith_out// mulg1 mul1g.
Qed.
Lemma setXn_dprod H : \big[dprod/1]_i set1gXn (H i) = setXn H.
Proof.
rewrite -setXn_prod//=.
suff -> : \big[dprod/1]_i groupXn1 (H i) = (\prod_i groupXn1 (H i))%G.
by rewrite comm_prodG//=; apply: in2W; apply: set1gXn_commute.
apply/eqP; apply/bigdprodYP => i //= _; rewrite subsetD.
apply/andP; split.
rewrite comm_prodG; last by apply: in2W; apply: set1gXn_commute.
apply/centsP => _ /prodsgP[/= h_ h_P ->] _ /set1gXnP [h hH ->].
apply/ffunP => j; rewrite !ffunE/=.
rewrite (big_morph _ (@dffunM j) (_ : _ = 1)) ?ffunE//.
case: dfwithP => {j} [|? ?]; last by rewrite mulg1 mul1g.
rewrite big1 ?mulg1 ?mul1g// => j neq_ji.
by have /set1gXnP[? _ ->] := h_P j neq_ji; rewrite ffunE dfwith_out.
rewrite -setI_eq0 -subset0; apply/subsetP => /= x; rewrite !inE.
rewrite comm_prodG; last by apply: in2W; apply: set1gXn_commute.
move=> /and3P[+ + /set1gXnP [h _ x_h]]; rewrite {x}x_h.
move=> /prodsgP[x_ x_P /ffunP/(_ i)]; rewrite ffunE dfwith_in => {h}->.
apply: contra_neqT => _; apply/ffunP => j; rewrite !ffunE/=.
case: dfwithP => // {j}; rewrite (big_morph _ (@dffunM i) (_ : _ = 1)) ?ffunE//.
rewrite big1// => j neq_ji.
by have /set1gXnP[g gH /ffunP->] := x_P _ neq_ji; rewrite ffunE dfwith_out.
Qed.
Lemma isog_setXn i (G : {group gT i}) : G \isog set1gXn G.
Proof.
apply/(@isogP _ _ G); exists [morphism of restrm (subsetT G) (@dfung1 i)].
by rewrite injm_restrm ?injm_dfung1.
by rewrite morphim_restrm morphim_dfung1 setIid.
Qed.
Lemma setXn_gen H : (forall i, 1 \in H i) ->
<<setXn H>> = setXn (fun i => <<H i>>).
Proof.
move=> H1; apply/eqP; rewrite eqEsubset gen_subG setXnS/=; last first.
by move=> ?; rewrite subset_gen.
rewrite -[in X in X \subset _]setXn_prod; under eq_bigr do
rewrite -morphim_dfung1 morphim_gen ?subsetT// morphim_dfung1.
rewrite prod_subG// => i; rewrite genS // set1gXnE setXnS // => j.
by case: dfwithP => // k _; rewrite sub1set.
Qed.
End ExternalDirDepProd.
Lemma groupX0 (gT : 'I_0 -> finGroupType) (G : forall i, {group gT i}) :
setXn G = 1%g.
Proof.
by apply/setP => ?; apply/setXnP/set1P => [_|_ []//]; apply/ffunP => -[].
Qed.
Section ExternalSDirProd.
Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}).
(* The pair (a, x) denotes the product sdpair2 a * sdpair1 x *)
Inductive sdprod_by (to : groupAction D R) : predArgType :=
SdPair (ax : aT * rT) of ax \in setX D R.
Coercion pair_of_sd to (u : sdprod_by to) := let: SdPair ax _ := u in ax.
Variable to : groupAction D R.
Notation sdT := (sdprod_by to).
Notation sdval := (@pair_of_sd to).
HB.instance Definition _ := [isSub for sdval].
#[hnf] HB.instance Definition _ := [Finite of sdT by <:].
Definition sdprod_one := SdPair to (group1 _).
Lemma sdprod_inv_proof (u : sdT) : (u.1^-1, to u.2^-1 u.1^-1) \in setX D R.
Proof.
by case: u => [[a x]] /= /setXP[Da Rx]; rewrite inE gact_stable !groupV ?Da.
Qed.
Definition sdprod_inv u := SdPair to (sdprod_inv_proof u).
Lemma sdprod_mul_proof (u v : sdT) :
(u.1 * v.1, to u.2 v.1 * v.2) \in setX D R.
Proof.
case: u v => [[a x] /= /setXP[Da Rx]] [[b y] /= /setXP[Db Ry]].
by rewrite inE !groupM //= gact_stable.
Qed.
Definition sdprod_mul u v := SdPair to (sdprod_mul_proof u v).
Lemma sdprod_mul1g : left_id sdprod_one sdprod_mul.
Proof.
move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _.
by rewrite gact1 // !mul1g.
Qed.
Lemma sdprod_mulVg : left_inverse sdprod_one sdprod_inv sdprod_mul.
Proof.
move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _.
by rewrite actKVin ?mulVg.
Qed.
Lemma sdprod_mulgA : associative sdprod_mul.
Proof.
move=> u v w; apply: val_inj; case: u => [[a x]] /=; case/setXP=> Da Rx.
case: v w => [[b y]] /=; case/setXP=> Db Ry [[c z]] /=; case/setXP=> Dc Rz.
by rewrite !(actMin to) // gactM ?gact_stable // !mulgA.
Qed.
HB.instance Definition _ := isMulGroup.Build sdT
sdprod_mulgA sdprod_mul1g sdprod_mulVg.
Definition sdprod_groupType : finGroupType := sdT.
Definition sdpair1 x := insubd sdprod_one (1, x) : sdT.
Definition sdpair2 a := insubd sdprod_one (a, 1) : sdT.
Lemma sdpair1_morphM : {in R &, {morph sdpair1 : x y / x * y}}.
Proof.
move=> x y Rx Ry; apply: val_inj.
by rewrite /= !val_insubd !inE !group1 !groupM ?Rx ?Ry //= mulg1 act1.
Qed.
Lemma sdpair2_morphM : {in D &, {morph sdpair2 : a b / a * b}}.
Proof.
move=> a b Da Db; apply: val_inj.
by rewrite /= !val_insubd !inE !group1 !groupM ?Da ?Db //= mulg1 gact1.
Qed.
Canonical sdpair1_morphism := Morphism sdpair1_morphM.
Canonical sdpair2_morphism := Morphism sdpair2_morphM.
Lemma injm_sdpair1 : 'injm sdpair1.
Proof.
apply/subsetP=> x /setIP[Rx].
by rewrite !inE -val_eqE val_insubd inE Rx group1 /=; case/andP.
Qed.
Lemma injm_sdpair2 : 'injm sdpair2.
Proof.
apply/subsetP=> a /setIP[Da].
by rewrite !inE -val_eqE val_insubd inE Da group1 /=; case/andP.
Qed.
Lemma sdpairE (u : sdT) : u = sdpair2 u.1 * sdpair1 u.2.
Proof.
apply: val_inj; case: u => [[a x] /= /setXP[Da Rx]].
by rewrite !val_insubd !inE Da Rx !(group1, gact1) // mulg1 mul1g.
Qed.
Lemma sdpair_act : {in R & D,
forall x a, sdpair1 (to x a) = sdpair1 x ^ sdpair2 a}.
Proof.
move=> x a Rx Da; apply: val_inj.
rewrite /= !val_insubd !inE !group1 gact_stable ?Da ?Rx //=.
by rewrite !mul1g mulVg invg1 mulg1 actKVin ?mul1g.
Qed.
Lemma sdpair_setact (G : {set rT}) a : G \subset R -> a \in D ->
sdpair1 @* (to^~ a @: G) = (sdpair1 @* G) :^ sdpair2 a.
Proof.
move=> sGR Da; have GtoR := subsetP sGR; apply/eqP.
rewrite eqEcard cardJg !(card_injm injm_sdpair1) //; last first.
by apply/subsetP=> _ /imsetP[x Gx ->]; rewrite gact_stable ?GtoR.
rewrite (card_imset _ (act_inj _ _)) leqnn andbT.
apply/subsetP=> _ /morphimP[xa Rxa /imsetP[x Gx def_xa ->]].
rewrite mem_conjg -morphV // -sdpair_act ?groupV // def_xa actKin //.
by rewrite mem_morphim ?GtoR.
Qed.
Lemma im_sdpair_norm : sdpair2 @* D \subset 'N(sdpair1 @* R).
Proof.
apply/subsetP=> _ /morphimP[a _ Da ->].
rewrite inE -sdpair_setact // morphimS //.
by apply/subsetP=> _ /imsetP[x Rx ->]; rewrite gact_stable.
Qed.
Lemma im_sdpair_TI : (sdpair1 @* R) :&: (sdpair2 @* D) = 1.
Proof.
apply/trivgP; apply/subsetP=> _ /setIP[/morphimP[x _ Rx ->]].
case/morphimP=> a _ Da /eqP; rewrite inE -!val_eqE.
by rewrite !val_insubd !inE Da Rx !group1 /eq_op /= eqxx; case/andP.
Qed.
Lemma im_sdpair : (sdpair1 @* R) * (sdpair2 @* D) = setT.
Proof.
apply/eqP; rewrite -subTset -(normC im_sdpair_norm).
apply/subsetP=> /= u _; rewrite [u]sdpairE.
by case: u => [[a x] /= /setXP[Da Rx]]; rewrite mem_mulg ?mem_morphim.
Qed.
Lemma sdprod_sdpair : sdpair1 @* R ><| sdpair2 @* D = setT.
Proof. by rewrite sdprodE ?(im_sdpair_norm, im_sdpair, im_sdpair_TI). Qed.
Variables (A : {set aT}) (G : {set rT}).
Lemma gacentEsd : 'C_(|to)(A) = sdpair1 @*^-1 'C(sdpair2 @* A).
Proof.
apply/setP=> x; apply/idP/idP.
case/setIP=> Rx /afixP cDAx; rewrite mem_morphpre //.
apply/centP=> _ /morphimP[a Da Aa ->]; red.
by rewrite conjgC -sdpair_act // cDAx // inE Da.
case/morphpreP=> Rx cAx; rewrite inE Rx; apply/afixP=> a /setIP[Da Aa].
apply: (injmP injm_sdpair1); rewrite ?gact_stable /= ?sdpair_act //=.
by rewrite /conjg (centP cAx) ?mulKg ?mem_morphim.
Qed.
Hypotheses (sAD : A \subset D) (sGR : G \subset R).
Lemma astabEsd : 'C(G | to) = sdpair2 @*^-1 'C(sdpair1 @* G).
Proof.
have ssGR := subsetP sGR; apply/setP=> a; apply/idP/idP=> [cGa|].
rewrite mem_morphpre ?(astab_dom cGa) //.
apply/centP=> _ /morphimP[x Rx Gx ->]; symmetry.
by rewrite conjgC -sdpair_act ?(astab_act cGa) ?(astab_dom cGa).
case/morphpreP=> Da cGa; rewrite !inE Da; apply/subsetP=> x Gx; rewrite inE.
apply/eqP; apply: (injmP injm_sdpair1); rewrite ?gact_stable ?ssGR //=.
by rewrite sdpair_act ?ssGR // /conjg -(centP cGa) ?mulKg ?mem_morphim ?ssGR.
Qed.
Lemma astabsEsd : 'N(G | to) = sdpair2 @*^-1 'N(sdpair1 @* G).
Proof.
apply/setP=> a; apply/idP/idP=> [nGa|].
have Da := astabs_dom nGa; rewrite mem_morphpre // inE sub_conjg.
apply/subsetP=> _ /morphimP[x Rx Gx ->].
by rewrite mem_conjgV -sdpair_act // mem_morphim ?gact_stable ?astabs_act.
case/morphpreP=> Da nGa; rewrite !inE Da; apply/subsetP=> x Gx.
have Rx := subsetP sGR _ Gx; have Rxa: to x a \in R by rewrite gact_stable.
rewrite inE -sub1set -(injmSK injm_sdpair1) ?morphim_set1 ?sub1set //=.
by rewrite sdpair_act ?memJ_norm ?mem_morphim.
Qed.
Lemma actsEsd : [acts A, on G | to] = (sdpair2 @* A \subset 'N(sdpair1 @* G)).
Proof. by rewrite sub_morphim_pre -?astabsEsd. Qed.
End ExternalSDirProd.
Section ProdMorph.
Variables gT rT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H K : {group gT}.
Implicit Types C D : {set rT}.
Implicit Type L : {group rT}.
Section defs.
Variables (A B : {set gT}) (fA fB : gT -> FinGroup.sort rT).
Definition pprodm of B \subset 'N(A) & {in A & B, morph_act 'J 'J fA fB}
& {in A :&: B, fA =1 fB} :=
fun x => fA (divgr A B x) * fB (remgr A B x).
End defs.
Section Props.
Variables H K : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis nHK : K \subset 'N(H).
Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}.
Hypothesis eqfHK : {in H :&: K, fH =1 fK}.
Local Notation f := (pprodm nHK actf eqfHK).
Lemma pprodmE x a : x \in H -> a \in K -> f (x * a) = fH x * fK a.
Proof.
move=> Hx Ka; have: x * a \in H * K by rewrite mem_mulg.
rewrite -remgrP inE /f rcoset_sym mem_rcoset /divgr -mulgA groupMl //.
case/andP; move: (remgr H K _) => b Hab Kb; rewrite morphM // -mulgA.
have Kab: a * b^-1 \in K by rewrite groupM ?groupV.
by congr (_ * _); rewrite eqfHK 1?inE ?Hab // -morphM // mulgKV.
Qed.
Lemma pprodmEl : {in H, f =1 fH}.
Proof. by move=> x Hx; rewrite -(mulg1 x) pprodmE // morph1 !mulg1. Qed.
Lemma pprodmEr : {in K, f =1 fK}.
Proof. by move=> a Ka; rewrite -(mul1g a) pprodmE // morph1 !mul1g. Qed.
Lemma pprodmM : {in H <*> K &, {morph f: x y / x * y}}.
Proof.
move=> xa yb; rewrite norm_joinEr //.
move=> /imset2P[x a Ha Ka ->{xa}] /imset2P[y b Hy Kb ->{yb}].
have Hya: y ^ a^-1 \in H by rewrite -mem_conjg (normsP nHK).
rewrite mulgA -(mulgA x) (conjgCV a y) (mulgA x) -mulgA !pprodmE 1?groupMl //.
by rewrite morphM // actf ?groupV ?morphV // morphM // !mulgA mulgKV invgK.
Qed.
Canonical pprodm_morphism := Morphism pprodmM.
Lemma morphim_pprodm A B :
A \subset H -> B \subset K -> f @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite [f @* _]morphimEsub /=; last first.
by rewrite norm_joinEr // mulgSS.
apply/setP=> y; apply/imsetP/idP=> [[_ /mulsgP[x a Ax Ba ->] ->{y}] |].
have Hx := subsetP sAH x Ax; have Ka := subsetP sBK a Ba.
by rewrite pprodmE // imset2_f ?mem_morphim.
case/mulsgP=> _ _ /morphimP[x Hx Ax ->] /morphimP[a Ka Ba ->] ->{y}.
by exists (x * a); rewrite ?mem_mulg ?pprodmE.
Qed.
Lemma morphim_pprodml A : A \subset H -> f @* A = fH @* A.
Proof.
by move=> sAH; rewrite -{1}(mulg1 A) morphim_pprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_pprodmr B : B \subset K -> f @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_pprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_pprodm : 'ker f = [set x * a^-1 | x in H, a in K & fH x == fK a].
Proof.
apply/setP=> y; rewrite 3!inE {1}norm_joinEr //=.
apply/andP/imset2P=> [[/mulsgP[x a Hx Ka ->{y}]]|[x a Hx]].
rewrite pprodmE // => fxa1.
by exists x a^-1; rewrite ?invgK // inE groupVr ?morphV // eq_mulgV1 invgK.
case/setIdP=> Kx /eqP fx ->{y}.
by rewrite imset2_f ?pprodmE ?groupV ?morphV // fx mulgV.
Qed.
Lemma injm_pprodm :
'injm f = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K].
Proof.
apply/idP/and3P=> [injf | [injfH injfK]].
rewrite eq_sym -{1}morphimIdom -(morphim_pprodml (subsetIl _ _)) injmI //.
rewrite morphim_pprodml // morphim_pprodmr //=; split=> //.
apply/injmP=> x y Hx Hy /=; rewrite -!pprodmEl //.
by apply: (injmP injf); rewrite ?mem_gen ?inE ?Hx ?Hy.
apply/injmP=> a b Ka Kb /=; rewrite -!pprodmEr //.
by apply: (injmP injf); rewrite ?mem_gen //; apply/setUP; right.
move/eqP=> fHK; rewrite ker_pprodm; apply/subsetP=> y.
case/imset2P=> x a Hx /setIdP[Ka /eqP fxa] ->.
have: fH x \in fH @* K by rewrite -fHK inE {2}fxa !mem_morphim.
case/morphimP=> z Hz Kz /(injmP injfH) def_x.
rewrite def_x // eqfHK ?inE ?Hz // in fxa.
by rewrite def_x // (injmP injfK _ _ Kz Ka fxa) mulgV set11.
Qed.
End Props.
Section Sdprodm.
Variables H K G : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H ><| K = G.
Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}.
Lemma sdprodm_norm : K \subset 'N(H).
Proof. by case/sdprodP: eqHK_G. Qed.
Lemma sdprodm_sub : G \subset H <*> K.
Proof. by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr. Qed.
Lemma sdprodm_eqf : {in H :&: K, fH =1 fK}.
Proof.
by case/sdprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1.
Qed.
Definition sdprodm :=
restrm sdprodm_sub (pprodm sdprodm_norm actf sdprodm_eqf).
Canonical sdprodm_morphism := Eval hnf in [morphism of sdprodm].
Lemma sdprodmE a b : a \in H -> b \in K -> sdprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma sdprodmEl a : a \in H -> sdprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma sdprodmEr b : b \in K -> sdprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_sdprodm A B :
A \subset H -> B \subset K -> sdprodm @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite /sdprodm morphim_restrm /= (setIidPr _) ?morphim_pprodm //.
by case/sdprodP: eqHK_G => _ <- _ _; apply: mulgSS.
Qed.
Lemma im_sdprodm : sdprodm @* G = fH @* H * fK @* K.
Proof. by rewrite -morphim_sdprodm //; case/sdprodP: eqHK_G => _ ->. Qed.
Lemma morphim_sdprodml A : A \subset H -> sdprodm @* A = fH @* A.
Proof.
by move=> sHA; rewrite -{1}(mulg1 A) morphim_sdprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_sdprodmr B : B \subset K -> sdprodm @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_sdprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_sdprodm :
'ker sdprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof.
rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left.
by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr.
Qed.
Lemma injm_sdprodm :
'injm sdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite ker_sdprodm -(ker_pprodm sdprodm_norm actf sdprodm_eqf) injm_pprodm.
congr [&& _, _ & _ == _]; have [_ _ _ tiHK] := sdprodP eqHK_G.
by rewrite -morphimIdom tiHK morphim1.
Qed.
End Sdprodm.
Section Cprodm.
Variables H K G : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H \* K = G.
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Hypothesis eqfHK : {in H :&: K, fH =1 fK}.
Lemma cprodm_norm : K \subset 'N(H).
Proof. by rewrite cents_norm //; case/cprodP: eqHK_G. Qed.
Lemma cprodm_sub : G \subset H <*> K.
Proof. by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr. Qed.
Lemma cprodm_actf : {in H & K, morph_act 'J 'J fH fK}.
Proof.
case/cprodP: eqHK_G => _ _ cHK a b Ha Kb /=.
by rewrite /conjg -(centsP cHK b) // -(centsP cfHK (fK b)) ?mulKg ?mem_morphim.
Qed.
Definition cprodm := restrm cprodm_sub (pprodm cprodm_norm cprodm_actf eqfHK).
Canonical cprodm_morphism := Eval hnf in [morphism of cprodm].
Lemma cprodmE a b : a \in H -> b \in K -> cprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma cprodmEl a : a \in H -> cprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma cprodmEr b : b \in K -> cprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_cprodm A B :
A \subset H -> B \subset K -> cprodm @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite [LHS]morphim_restrm /= (setIidPr _) ?morphim_pprodm //.
by case/cprodP: eqHK_G => _ <- _; apply: mulgSS.
Qed.
Lemma im_cprodm : cprodm @* G = fH @* H * fK @* K.
Proof.
by have [_ defHK _] := cprodP eqHK_G; rewrite -{2}defHK morphim_cprodm.
Qed.
Lemma morphim_cprodml A : A \subset H -> cprodm @* A = fH @* A.
Proof.
by move=> sHA; rewrite -{1}(mulg1 A) morphim_cprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_cprodmr B : B \subset K -> cprodm @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_cprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_cprodm : 'ker cprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof.
rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left.
by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr.
Qed.
Lemma injm_cprodm :
'injm cprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K].
Proof.
by rewrite ker_cprodm -(ker_pprodm cprodm_norm cprodm_actf eqfHK) injm_pprodm.
Qed.
End Cprodm.
Section Dprodm.
Variables G H K : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H \x K = G.
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Lemma dprodm_cprod : H \* K = G.
Proof.
by rewrite -eqHK_G /dprod; case/dprodP: eqHK_G => _ _ _ ->; rewrite subxx.
Qed.
Lemma dprodm_eqf : {in H :&: K, fH =1 fK}.
Proof. by case/dprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1. Qed.
Definition dprodm := cprodm dprodm_cprod cfHK dprodm_eqf.
Canonical dprodm_morphism := Eval hnf in [morphism of dprodm].
Lemma dprodmE a b : a \in H -> b \in K -> dprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma dprodmEl a : a \in H -> dprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma dprodmEr b : b \in K -> dprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_dprodm A B :
A \subset H -> B \subset K -> dprodm @* (A * B) = fH @* A * fK @* B.
Proof. exact: morphim_cprodm. Qed.
Lemma im_dprodm : dprodm @* G = fH @* H * fK @* K.
Proof. exact: im_cprodm. Qed.
Lemma morphim_dprodml A : A \subset H -> dprodm @* A = fH @* A.
Proof. exact: morphim_cprodml. Qed.
Lemma morphim_dprodmr B : B \subset K -> dprodm @* B = fK @* B.
Proof. exact: morphim_cprodmr. Qed.
Lemma ker_dprodm : 'ker dprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof. exact: ker_cprodm. Qed.
Lemma injm_dprodm :
'injm dprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite injm_cprodm -(morphimIdom fH K).
by case/dprodP: eqHK_G => _ _ _ ->; rewrite morphim1.
Qed.
End Dprodm.
Lemma isog_dprod A B G C D L :
A \x B = G -> C \x D = L -> isog A C -> isog B D -> isog G L.
Proof.
move=> defG {C D} /dprodP[[C D -> ->] defL cCD trCD].
case/dprodP: defG (defG) => {A B} [[A B -> ->] defG _ _] dG defC defD.
case/isogP: defC defL cCD trCD => fA injfA <-{C}.
case/isogP: defD => fB injfB <-{D} defL cCD trCD.
apply/isogP; exists (dprodm_morphism dG cCD).
by rewrite injm_dprodm injfA injfB trCD eqxx.
by rewrite /= -{2}defG morphim_dprodm.
Qed.
End ProdMorph.
Section ExtSdprodm.
Variables gT aT rT : finGroupType.
Variables (H : {group gT}) (K : {group aT}) (to : groupAction K H).
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis actf : {in H & K, morph_act to 'J fH fK}.
Local Notation fsH := (fH \o invm (injm_sdpair1 to)).
Local Notation fsK := (fK \o invm (injm_sdpair2 to)).
Let DgH := sdpair1 to @* H.
Let DgK := sdpair2 to @* K.
Lemma xsdprodm_dom1 : DgH \subset 'dom fsH.
Proof. by rewrite ['dom _]morphpre_invm. Qed.
Local Notation gH := (restrm xsdprodm_dom1 fsH).
Lemma xsdprodm_dom2 : DgK \subset 'dom fsK.
Proof. by rewrite ['dom _]morphpre_invm. Qed.
Local Notation gK := (restrm xsdprodm_dom2 fsK).
Lemma im_sdprodm1 : gH @* DgH = fH @* H.
Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed.
Lemma im_sdprodm2 : gK @* DgK = fK @* K.
Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed.
Lemma xsdprodm_act : {in DgH & DgK, morph_act 'J 'J gH gK}.
Proof.
move=> fh fk; case/morphimP=> h _ Hh ->{fh}; case/morphimP=> k _ Kk ->{fk}.
by rewrite /= -sdpair_act // /restrm /= !invmE ?actf ?gact_stable.
Qed.
Definition xsdprodm := sdprodm (sdprod_sdpair to) xsdprodm_act.
Canonical xsdprod_morphism := [morphism of xsdprodm].
Lemma im_xsdprodm : xsdprodm @* setT = fH @* H * fK @* K.
Proof. by rewrite -im_sdpair morphim_sdprodm // im_sdprodm1 im_sdprodm2. Qed.
Lemma injm_xsdprodm :
'injm xsdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite injm_sdprodm im_sdprodm1 im_sdprodm2 !subG1 /=.
rewrite (ker_restrm xsdprodm_dom1) (ker_restrm xsdprodm_dom2) /= !ker_comp.
rewrite !morphpre_invm !morphimIim.
by rewrite !morphim_injm_eq1 ?subsetIl ?injm_sdpair1 ?injm_sdpair2.
Qed.
End ExtSdprodm.
Section DirprodIsom.
Variable gT : finGroupType.
Implicit Types G H : {group gT}.
Definition mulgm : gT * gT -> _ := uncurry mulg.
Lemma imset_mulgm (A B : {set gT}) : mulgm @: setX A B = A * B.
Proof. by rewrite -curry_imset2X. Qed.
Lemma mulgmP H1 H2 G : reflect (H1 \x H2 = G) (misom (setX H1 H2) G mulgm).
Proof.
apply: (iffP misomP) => [[pM /isomP[injf /= <-]] | ].
have /dprodP[_ /= defX cH12] := setX_dprod H1 H2.
rewrite -{4}defX {}defX => /(congr1 (fun A => morphm pM @* A)).
move/(morphimS (morphm_morphism pM)): cH12 => /=.
have sH1H: setX H1 1 \subset setX H1 H2 by rewrite setXS ?sub1G.
have sH2H: setX 1 H2 \subset setX H1 H2 by rewrite setXS ?sub1G.
rewrite morphim1 injm_cent ?injmI //= subsetI => /andP[_].
by rewrite !morphimEsub //= !imset_mulgm mulg1 mul1g; apply: dprodE.
case/dprodP=> _ defG cH12 trH12.
have fM: morphic (setX H1 H2) mulgm.
apply/morphicP=> [[x1 x2] [y1 y2] /setXP[_ Hx2] /setXP[Hy1 _]].
by rewrite /= mulgA -(mulgA x1) -(centsP cH12 x2) ?mulgA.
exists fM; apply/isomP; split; last by rewrite morphimEsub //= imset_mulgm.
apply/subsetP=> [[x1 x2]]; rewrite !inE /= andbC -eq_invg_mul.
case: eqP => //= <-; rewrite groupV -in_setI trH12 => /set1P->.
by rewrite invg1 eqxx.
Qed.
End DirprodIsom.
Arguments mulgmP {gT H1 H2 G}.
Prenex Implicits mulgm.
|
Basic.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.Algebra.Ring.ULift
import Mathlib.Algebra.Ring.Opposite
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Cast.Prod
import Mathlib.Data.ULift
import Mathlib.Order.Interval.Set.Defs
import Mathlib.Algebra.Ring.GrindInstances
/-!
# Characteristic of semirings
This file collects some fundamental results on the characteristic of rings that don't need the extra
imports of `CharP/Lemmas.lean`.
As such, we can probably reorganize and find a better home for most of these lemmas.
-/
assert_not_exists Finset TwoSidedIdeal
open Set
variable (R : Type*)
namespace CharP
section AddMonoidWithOne
variable [AddMonoidWithOne R] (p : ℕ)
variable [CharP R p] {a b : ℕ}
lemma natCast_eq_natCast' (h : a ≡ b [MOD p]) : (a : R) = b := by
wlog hle : a ≤ b
· exact (this R p h.symm (le_of_not_ge hle)).symm
rw [Nat.modEq_iff_dvd' hle] at h
rw [← Nat.sub_add_cancel hle, Nat.cast_add, (cast_eq_zero_iff R p _).mpr h, zero_add]
lemma natCast_eq_natCast_mod (a : ℕ) : (a : R) = a % p :=
natCast_eq_natCast' R p (Nat.mod_modEq a p).symm
variable [IsRightCancelAdd R]
lemma natCast_eq_natCast : (a : R) = b ↔ a ≡ b [MOD p] := by
wlog hle : a ≤ b
· rw [eq_comm, this R p (le_of_not_ge hle), Nat.ModEq.comm]
rw [Nat.modEq_iff_dvd' hle, ← cast_eq_zero_iff R p (b - a),
← add_right_cancel_iff (G := R) (a := a) (b := b - a), zero_add, ← Nat.cast_add,
Nat.sub_add_cancel hle, eq_comm]
lemma natCast_injOn_Iio : (Set.Iio p).InjOn ((↑) : ℕ → R) :=
fun _a ha _b hb hab ↦ ((natCast_eq_natCast _ _).1 hab).eq_of_lt_of_lt ha hb
end AddMonoidWithOne
section AddGroupWithOne
variable [AddGroupWithOne R] (p : ℕ) [CharP R p] {a b : ℤ}
lemma intCast_eq_intCast : (a : R) = b ↔ a ≡ b [ZMOD p] := by
rw [eq_comm, ← sub_eq_zero, ← Int.cast_sub, CharP.intCast_eq_zero_iff R p, Int.modEq_iff_dvd]
lemma intCast_eq_intCast_mod : (a : R) = a % (p : ℤ) :=
(CharP.intCast_eq_intCast R p).mpr (Int.mod_modEq a p).symm
lemma intCast_injOn_Ico [IsRightCancelAdd R] : InjOn (Int.cast : ℤ → R) (Ico 0 p) := by
rintro a ⟨ha₀, ha⟩ b ⟨hb₀, hb⟩ hab
lift a to ℕ using ha₀
lift b to ℕ using hb₀
norm_cast at *
exact natCast_injOn_Iio _ _ ha hb hab
end AddGroupWithOne
end CharP
namespace CharP
section NonAssocSemiring
variable {R} [NonAssocSemiring R]
variable (R) in
/-- If a ring `R` is of characteristic `p`, then for any prime number `q` different from `p`,
it is not zero in `R`. -/
lemma cast_ne_zero_of_ne_of_prime [Nontrivial R]
{p q : ℕ} [CharP R p] (hq : q.Prime) (hneq : p ≠ q) : (q : R) ≠ 0 := fun h ↦ by
rw [cast_eq_zero_iff R p q] at h
rcases hq.eq_one_or_self_of_dvd _ h with h | h
· subst h
exact false_of_nontrivial_of_char_one (R := R)
· exact hneq h
lemma ringChar_of_prime_eq_zero [Nontrivial R] {p : ℕ} (hprime : Nat.Prime p)
(hp0 : (p : R) = 0) : ringChar R = p :=
Or.resolve_left ((Nat.dvd_prime hprime).1 (ringChar.dvd hp0)) ringChar_ne_one
lemma charP_iff_prime_eq_zero [Nontrivial R] {p : ℕ} (hp : p.Prime) :
CharP R p ↔ (p : R) = 0 :=
⟨fun _ => cast_eq_zero R p,
fun hp0 => (ringChar_of_prime_eq_zero hp hp0) ▸ inferInstance⟩
end NonAssocSemiring
end CharP
section
/-- We have `2 ≠ 0` in a nontrivial ring whose characteristic is not `2`. -/
protected lemma Ring.two_ne_zero {R : Type*} [NonAssocSemiring R] [Nontrivial R]
(hR : ringChar R ≠ 2) : (2 : R) ≠ 0 := by
rw [Ne, (by norm_cast : (2 : R) = (2 : ℕ)), ringChar.spec, Nat.dvd_prime Nat.prime_two]
exact mt (or_iff_left hR).mp CharP.ringChar_ne_one
-- We have `CharP.neg_one_ne_one`, which assumes `[Ring R] (p : ℕ) [CharP R p] [Fact (2 < p)]`.
-- This is a version using `ringChar` instead.
/-- Characteristic `≠ 2` and nontrivial implies that `-1 ≠ 1`. -/
lemma Ring.neg_one_ne_one_of_char_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
(hR : ringChar R ≠ 2) : (-1 : R) ≠ 1 := fun h =>
Ring.two_ne_zero hR (one_add_one_eq_two (R := R) ▸ neg_eq_iff_add_eq_zero.mp h)
/-- Characteristic `≠ 2` in a domain implies that `-a = a` iff `a = 0`. -/
lemma Ring.eq_self_iff_eq_zero_of_char_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
[NoZeroDivisors R] (hR : ringChar R ≠ 2) {a : R} : -a = a ↔ a = 0 :=
⟨fun h =>
(mul_eq_zero.mp <| (two_mul a).trans <| neg_eq_iff_add_eq_zero.mp h).resolve_left
(Ring.two_ne_zero hR),
fun h => ((congr_arg (fun x => -x) h).trans neg_zero).trans h.symm⟩
end
section Prod
variable (S : Type*) [AddMonoidWithOne R] [AddMonoidWithOne S] (p q : ℕ) [CharP R p]
/-- The characteristic of the product of rings is the least common multiple of the
characteristics of the two rings. -/
instance Nat.lcm.charP [CharP S q] : CharP (R × S) (Nat.lcm p q) where
cast_eq_zero_iff := by
simp [Prod.ext_iff, CharP.cast_eq_zero_iff R p, CharP.cast_eq_zero_iff S q, Nat.lcm_dvd_iff]
/-- The characteristic of the product of two rings of the same characteristic
is the same as the characteristic of the rings -/
instance Prod.charP [CharP S p] : CharP (R × S) p := by
convert Nat.lcm.charP R S p p; simp
instance Prod.charZero_of_left [CharZero R] : CharZero (R × S) where
cast_injective _ _ h := CharZero.cast_injective congr(Prod.fst $h)
instance Prod.charZero_of_right [CharZero S] : CharZero (R × S) where
cast_injective _ _ h := CharZero.cast_injective congr(Prod.snd $h)
end Prod
instance ULift.charP [AddMonoidWithOne R] (p : ℕ) [CharP R p] : CharP (ULift R) p where
cast_eq_zero_iff n := Iff.trans ULift.ext_iff <| CharP.cast_eq_zero_iff R p n
instance MulOpposite.charP [AddMonoidWithOne R] (p : ℕ) [CharP R p] : CharP Rᵐᵒᵖ p where
cast_eq_zero_iff n := MulOpposite.unop_inj.symm.trans <| CharP.cast_eq_zero_iff R p n
section
/-- If two integers from `{0, 1, -1}` result in equal elements in a ring `R`
that is nontrivial and of characteristic not `2`, then they are equal. -/
lemma Int.cast_injOn_of_ringChar_ne_two {R : Type*} [NonAssocRing R] [Nontrivial R]
(hR : ringChar R ≠ 2) : ({0, 1, -1} : Set ℤ).InjOn ((↑) : ℤ → R) := by
rintro _ (rfl | rfl | rfl) _ (rfl | rfl | rfl) h <;>
simp only
[cast_neg, cast_one, cast_zero, neg_eq_zero, one_ne_zero, zero_ne_one, zero_eq_neg] at h ⊢
· exact ((Ring.neg_one_ne_one_of_char_ne_two hR).symm h).elim
· exact ((Ring.neg_one_ne_one_of_char_ne_two hR) h).elim
end
namespace CharZero
lemma charZero_iff_forall_prime_ne_zero [NonAssocRing R] [NoZeroDivisors R] [Nontrivial R] :
CharZero R ↔ ∀ p : ℕ, p.Prime → (p : R) ≠ 0 := by
refine ⟨fun h p hp => by simp [hp.ne_zero], fun h => ?_⟩
let p := ringChar R
cases CharP.char_is_prime_or_zero R p with
| inl hp => simpa using h p hp
| inr h => have : CharP R 0 := h ▸ inferInstance; exact CharP.charP_to_charZero R
end CharZero
namespace Fin
open Fin.NatCast
/-- The characteristic of `F_p` is `p`. -/
@[stacks 09FS "First part. We don't require `p` to be a prime in mathlib."]
instance charP (n : ℕ) [NeZero n] : CharP (Fin n) n where cast_eq_zero_iff _ := natCast_eq_zero
end Fin
section AddMonoidWithOne
variable [AddMonoidWithOne R]
instance (S : Type*) [Semiring S] (p) [ExpChar R p] [ExpChar S p] : ExpChar (R × S) p := by
obtain hp | ⟨hp⟩ := ‹ExpChar R p›
· constructor
obtain _ | _ := ‹ExpChar S p›
· exact (Nat.not_prime_one hp).elim
· have := Prod.charP R S p; exact .prime hp
end AddMonoidWithOne
section CommRing
instance (α : Type*) [Semiring α] [IsLeftCancelAdd α] (n : ℕ) [CharP α n] :
Lean.Grind.IsCharP α n where
ofNat_ext_iff {a b} := by
rw [Lean.Grind.Semiring.ofNat_eq_natCast, Lean.Grind.Semiring.ofNat_eq_natCast]
exact CharP.cast_eq_iff_mod_eq α n
end CommRing
|
IntegralClosure.lean
|
/-
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.LinearAlgebra.FreeModule.PID
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.BilinearForm.DualLattice
import Mathlib.RingTheory.DedekindDomain.Basic
import Mathlib.RingTheory.Localization.Module
import Mathlib.RingTheory.Trace.Basic
import Mathlib.RingTheory.RingHom.Finite
/-!
# Integral closure of Dedekind domains
This file shows the integral closure of a Dedekind domain (in particular, the ring of integers
of a number field) is a Dedekind domain.
## 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
-/
open Algebra Module
open scoped nonZeroDivisors Polynomial
variable (A K : Type*) [CommRing A] [Field K]
section IsIntegralClosure
/-! ### `IsIntegralClosure` section
We show that an integral closure of a Dedekind domain in a finite separable
field extension is again a Dedekind domain. This implies the ring of integers
of a number field is a Dedekind domain. -/
variable [Algebra A K] [IsFractionRing A K]
variable (L : Type*) [Field L] (C : Type*) [CommRing C]
variable [Algebra K L] [Algebra A L] [IsScalarTower A K L]
variable [Algebra C L] [IsIntegralClosure C A L] [Algebra A C] [IsScalarTower A C L]
include K L
/-- If `L` is an algebraic extension of `K = Frac(A)` and `L` has no zero smul divisors by `A`,
then `L` is the localization of the integral closure `C` of `A` in `L` at `A⁰`. -/
theorem IsIntegralClosure.isLocalization [IsDomain A] [Algebra.IsAlgebraic K L] :
IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L := by
haveI : IsDomain C :=
(IsIntegralClosure.equiv A C L (integralClosure A L)).toMulEquiv.isDomain (integralClosure A L)
haveI : NoZeroSMulDivisors A L := NoZeroSMulDivisors.trans_faithfulSMul A K L
haveI : NoZeroSMulDivisors A C := IsIntegralClosure.noZeroSMulDivisors A L
refine ⟨?_, fun z => ?_, fun {x y} h => ⟨1, ?_⟩⟩
· rintro ⟨_, x, hx, rfl⟩
rw [isUnit_iff_ne_zero, map_ne_zero_iff _ (IsIntegralClosure.algebraMap_injective C A L),
Subtype.coe_mk, map_ne_zero_iff _ (FaithfulSMul.algebraMap_injective A C)]
exact mem_nonZeroDivisors_iff_ne_zero.mp hx
· obtain ⟨m, hm⟩ :=
IsIntegral.exists_multiple_integral_of_isLocalization A⁰ z
(Algebra.IsIntegral.isIntegral (R := K) z)
obtain ⟨x, hx⟩ : ∃ x, algebraMap C L x = m • z := IsIntegralClosure.isIntegral_iff.mp hm
refine ⟨⟨x, algebraMap A C m, m, SetLike.coe_mem m, rfl⟩, ?_⟩
rw [Subtype.coe_mk, ← IsScalarTower.algebraMap_apply, hx, mul_comm, Submonoid.smul_def,
smul_def]
· simp only [IsIntegralClosure.algebraMap_injective C A L h]
theorem IsIntegralClosure.isLocalization_of_isSeparable [IsDomain A] [Algebra.IsSeparable K L] :
IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L :=
IsIntegralClosure.isLocalization A K L C
variable [FiniteDimensional K L]
variable {A K L}
theorem IsIntegralClosure.range_le_span_dualBasis [Algebra.IsSeparable K L] {ι : Type*} [Fintype ι]
[DecidableEq ι] (b : Basis ι K L) (hb_int : ∀ i, IsIntegral A (b i)) [IsIntegrallyClosed A] :
LinearMap.range ((Algebra.linearMap C L).restrictScalars A) ≤
Submodule.span A (Set.range <| (traceForm K L).dualBasis (traceForm_nondegenerate K L) b) := by
rw [← LinearMap.BilinForm.dualSubmodule_span_of_basis,
← LinearMap.BilinForm.le_flip_dualSubmodule, Submodule.span_le]
rintro _ ⟨i, rfl⟩ _ ⟨y, rfl⟩
simp only [LinearMap.coe_restrictScalars, linearMap_apply, LinearMap.BilinForm.flip_apply,
traceForm_apply]
refine Submodule.mem_one.mpr <| IsIntegrallyClosed.isIntegral_iff.mp ?_
exact isIntegral_trace ((IsIntegralClosure.isIntegral A L y).algebraMap.mul (hb_int i))
theorem integralClosure_le_span_dualBasis [Algebra.IsSeparable K L] {ι : Type*} [Fintype ι]
[DecidableEq ι] (b : Basis ι K L) (hb_int : ∀ i, IsIntegral A (b i)) [IsIntegrallyClosed A] :
Subalgebra.toSubmodule (integralClosure A L) ≤
Submodule.span A (Set.range <| (traceForm K L).dualBasis (traceForm_nondegenerate K L) b) := by
refine le_trans ?_ (IsIntegralClosure.range_le_span_dualBasis (integralClosure A L) b hb_int)
intro x hx
exact ⟨⟨x, hx⟩, rfl⟩
variable [IsDomain A]
variable (A K)
/-- Send a set of `x`s in a finite extension `L` of the fraction field of `R`
to `(y : R) • x ∈ integralClosure R L`. -/
theorem exists_integral_multiples (s : Finset L) :
∃ y ≠ (0 : A), ∀ x ∈ s, IsIntegral A (y • x) :=
have := IsLocalization.isAlgebraic K (nonZeroDivisors A)
have := Algebra.IsAlgebraic.trans A K L
Algebra.IsAlgebraic.exists_integral_multiples ..
variable (L)
/-- If `L` is a finite extension of `K = Frac(A)`,
then `L` has a basis over `A` consisting of integral elements. -/
theorem FiniteDimensional.exists_is_basis_integral :
∃ (s : Finset L) (b : Basis s K L), ∀ x, IsIntegral A (b x) := by
letI := Classical.decEq L
letI : IsNoetherian K L := IsNoetherian.iff_fg.2 inferInstance
let s' := IsNoetherian.finsetBasisIndex K L
let bs' := IsNoetherian.finsetBasis K L
obtain ⟨y, hy, his'⟩ := exists_integral_multiples A K (Finset.univ.image bs')
have hy' : algebraMap A L y ≠ 0 := by
refine mt ((injective_iff_map_eq_zero (algebraMap A L)).mp ?_ _) hy
rw [IsScalarTower.algebraMap_eq A K L]
exact (algebraMap K L).injective.comp (IsFractionRing.injective A K)
refine ⟨s', bs'.map {Algebra.lmul _ _ (algebraMap A L y) with
toFun := fun x => algebraMap A L y * x
invFun := fun x => (algebraMap A L y)⁻¹ * x
left_inv := ?_
right_inv := ?_}, ?_⟩
· intro x; simp only [inv_mul_cancel_left₀ hy']
· intro x; simp only [mul_inv_cancel_left₀ hy']
· rintro ⟨x', hx'⟩
simp only [Algebra.smul_def, Finset.mem_image, Finset.mem_univ,
true_and] at his'
simp only [Basis.map_apply, LinearEquiv.coe_mk]
exact his' _ ⟨_, rfl⟩
variable [Algebra.IsSeparable K L]
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is
integrally closed and Noetherian, the integral closure `C` of `A` in `L` is
Noetherian over `A`. -/
theorem IsIntegralClosure.isNoetherian [IsIntegrallyClosed A] [IsNoetherianRing A] :
IsNoetherian A C := by
haveI := Classical.decEq L
obtain ⟨s, b, hb_int⟩ := FiniteDimensional.exists_is_basis_integral A K L
let b' := (traceForm K L).dualBasis (traceForm_nondegenerate K L) b
letI := isNoetherian_span_of_finite A (Set.finite_range b')
let f : C →ₗ[A] Submodule.span A (Set.range b') :=
(Submodule.inclusion (IsIntegralClosure.range_le_span_dualBasis C b hb_int)).comp
((Algebra.linearMap C L).restrictScalars A).rangeRestrict
refine isNoetherian_of_ker_bot f ?_
rw [LinearMap.ker_comp, Submodule.ker_inclusion, Submodule.comap_bot, LinearMap.ker_codRestrict]
exact LinearMap.ker_eq_bot_of_injective (IsIntegralClosure.algebraMap_injective C A L)
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is
integrally closed and Noetherian, the integral closure `C` of `A` in `L` is
Noetherian. -/
theorem IsIntegralClosure.isNoetherianRing [IsIntegrallyClosed A] [IsNoetherianRing A] :
IsNoetherianRing C :=
isNoetherianRing_iff.mpr <| isNoetherian_of_tower A (IsIntegralClosure.isNoetherian A K L C)
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is
integrally closed and Noetherian, the integral closure `C` of `A` in `L` is
finite over `A`. -/
theorem IsIntegralClosure.finite [IsIntegrallyClosed A] [IsNoetherianRing A] :
Module.Finite A C := by
haveI := IsIntegralClosure.isNoetherian A K L C
exact Module.IsNoetherian.finite A C
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a principal ring
and `L` has no zero smul divisors by `A`, the integral closure `C` of `A` in `L` is
a free `A`-module. -/
theorem IsIntegralClosure.module_free [NoZeroSMulDivisors A L] [IsPrincipalIdealRing A] :
Module.Free A C :=
haveI : NoZeroSMulDivisors A C := IsIntegralClosure.noZeroSMulDivisors A L
haveI : IsNoetherian A C := IsIntegralClosure.isNoetherian A K L _
inferInstance
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a principal ring
and `L` has no zero smul divisors by `A`, the `A`-rank of the integral closure `C` of `A` in `L`
is equal to the `K`-rank of `L`. -/
theorem IsIntegralClosure.rank [IsPrincipalIdealRing A] [NoZeroSMulDivisors A L] :
Module.finrank A C = Module.finrank K L := by
haveI : Module.Free A C := IsIntegralClosure.module_free A K L C
haveI : IsNoetherian A C := IsIntegralClosure.isNoetherian A K L C
haveI : IsLocalization (Algebra.algebraMapSubmonoid C A⁰) L :=
IsIntegralClosure.isLocalization A K L C
let b := Basis.localizationLocalization K A⁰ L (Module.Free.chooseBasis A C)
rw [Module.finrank_eq_card_chooseBasisIndex, Module.finrank_eq_card_basis b]
variable {A K}
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is
integrally closed and Noetherian, the integral closure of `A` in `L` is
Noetherian. -/
theorem integralClosure.isNoetherianRing [IsIntegrallyClosed A] [IsNoetherianRing A] :
IsNoetherianRing (integralClosure A L) :=
IsIntegralClosure.isNoetherianRing A K L (integralClosure A L)
variable (A K) [IsDomain C]
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a Dedekind domain,
the integral closure `C` of `A` in `L` is a Dedekind domain.
This cannot be an instance since `A`, `K` or `L` can't be inferred. See also the instance
`integralClosure.isDedekindDomain_fractionRing` where `K := FractionRing A`
and `C := integralClosure A L`. -/
theorem IsIntegralClosure.isDedekindDomain [IsDedekindDomain A] : IsDedekindDomain C :=
have : IsFractionRing C L := IsIntegralClosure.isFractionRing_of_finite_extension A K L C
have : Algebra.IsIntegral A C := IsIntegralClosure.isIntegral_algebra A L
{ IsIntegralClosure.isNoetherianRing A K L C,
Ring.DimensionLEOne.isIntegralClosure A L C,
(isIntegrallyClosed_iff L).mpr fun {x} hx =>
⟨IsIntegralClosure.mk' C x (isIntegral_trans (R := A) _ hx),
IsIntegralClosure.algebraMap_mk' _ _ _⟩ with : IsDedekindDomain C }
/-- If `L` is a finite separable extension of `K = Frac(A)`, where `A` is a Dedekind domain,
the integral closure of `A` in `L` is a Dedekind domain.
This cannot be an instance since `K` can't be inferred. See also the instance
`integralClosure.isDedekindDomain_fractionRing` where `K := FractionRing A`. -/
theorem integralClosure.isDedekindDomain [IsDedekindDomain A] :
IsDedekindDomain (integralClosure A L) :=
IsIntegralClosure.isDedekindDomain A K L (integralClosure A L)
variable [Algebra (FractionRing A) L] [IsScalarTower A (FractionRing A) L]
variable [FiniteDimensional (FractionRing A) L] [Algebra.IsSeparable (FractionRing A) L]
/-- If `L` is a finite separable extension of `Frac(A)`, where `A` is a Dedekind domain,
the integral closure of `A` in `L` is a Dedekind domain.
See also the lemma `integralClosure.isDedekindDomain` where you can choose
the field of fractions yourself. -/
instance integralClosure.isDedekindDomain_fractionRing [IsDedekindDomain A] :
IsDedekindDomain (integralClosure A L) :=
integralClosure.isDedekindDomain A (FractionRing A) L
attribute [local instance] FractionRing.liftAlgebra in
instance [Module.Finite A C] [NoZeroSMulDivisors A C] :
FiniteDimensional (FractionRing A) (FractionRing C) :=
.of_isLocalization A C A⁰
end IsIntegralClosure
|
Basic.lean
|
/-
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.Category.Preorder
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Preorder.HasIterationOfShape
import Mathlib.CategoryTheory.Limits.Shapes.Preorder.PrincipalSeg
import Mathlib.CategoryTheory.Limits.Comma
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.SuccPred.Limit
import Mathlib.Order.Interval.Set.InitialSeg
/-! # Transfinite iterations of a successor structure
In this file, we introduce the structure `SuccStruct` on a category `C`.
It consists of the data of an object `X₀ : C`, a successor map `succ : C → C`
and a morphism `toSucc : X ⟶ succ X` for any `X : C`. The map `toSucc`
does not have to be natural in `X`. For any element `j : J` in a
well-ordered type `J`, we would like to define
the iteration of `Φ : SuccStruct C`, as a functor `F : J ⥤ C`
such that `F.obj ⊥ = X₀`, `F.obj j ⟶ F.obj (Order.succ j)` is `toSucc (F.obj j)`
when `j` is not maximal, and when `j` is limit, `F.obj j` should be the
colimit of the `F.obj k` for `k < j`.
In the small object argument, we shall apply this to the iteration of
a functor `F : C ⥤ C` equipped with a natural transformation `ε : 𝟭 C ⟶ F`:
this will correspond to the case of
`SuccStruct.ofNatTrans ε : SuccStruct (C ⥤ C)`, for which `X₀ := 𝟭 C`,
`succ G := G ⋙ F` and `toSucc G : G ⟶ G ⋙ F` is given by `whiskerLeft G ε`.
The construction of the iteration of `Φ : SuccStruct C` is done
by transfinite induction, under an assumption `HasIterationOfShape C J`.
However, for a limit element `j : J`, the definition of `F.obj j`
does not involve only the objects `F.obj i` for `i < j`, but it also
involves the maps `F.obj i₁ ⟶ F.obj i₂` for `i₁ ≤ i₂ < j`.
Then, this is not a straightforward application of definitions by
transfinite induction. In order to solve this technical difficulty,
we introduce a structure `Φ.Iteration j` for any `j : J`. This
structure contains all the expected data and properties for
all the indices that are `≤ j`. In this file, we show that
`Φ.Iteration j` is a subsingleton. The existence shall be
obtained in the file `SmallObject.Iteration.Nonempty`, and
the construction of the functor `Φ.iterationFunctor J : J ⥤ C`
and of its colimit `Φ.iteration J : C` will done in the
file `SmallObject.TransfiniteIteration`.
The map `Φ.toSucc X : X ⟶ Φ.succ X` does not have to be natural
(and it is not in certain applications). Then, two isomorphic
objects `X` and `Y` may have non isomorphic successors. This is
the reason why we make an extensive use of equalities in
`C` and in `Arrow C` in the definitions.
## Note
The iteration was first introduced in mathlib by Joël Riou, using
a different approach as the one described above. After refactoring
his code, he found that the approach described above had already
been used in the pioneering formalization work in Lean 3 by
Reid Barton in 2018 towards the model category structure on
topological spaces.
-/
universe w v v' u u'
namespace CategoryTheory
open Category Limits
namespace SmallObject
variable {C : Type u} [Category.{v} C] {J : Type w}
section
variable [PartialOrder J] {j : J} (F : Set.Iic j ⥤ C) {i : J} (hi : i ≤ j)
/-- The functor `Set.Iio i ⥤ C` obtained by "restriction" of `F : Set.Iic j ⥤ C`
when `i ≤ j`. -/
def restrictionLT : Set.Iio i ⥤ C :=
(Set.principalSegIioIicOfLE hi).monotone.functor ⋙ F
@[simp]
lemma restrictionLT_obj (k : J) (hk : k < i) :
(restrictionLT F hi).obj ⟨k, hk⟩ = F.obj ⟨k, hk.le.trans hi⟩ := rfl
@[simp]
lemma restrictionLT_map {k₁ k₂ : Set.Iio i} (φ : k₁ ⟶ k₂) :
(restrictionLT F hi).map φ = F.map (homOfLE (by simpa using leOfHom φ)) := rfl
/-- Given `F : Set.Iic j ⥤ C`, `i : J` such that `hi : i ≤ j`, this is the
cocone consisting of all maps `F.obj ⟨k, hk⟩ ⟶ F.obj ⟨i, hi⟩` for `k : J` such that `k < i`. -/
@[simps!]
def coconeOfLE : Cocone (restrictionLT F hi) :=
(Set.principalSegIioIicOfLE hi).cocone F
/-- The functor `Set.Iic i ⥤ C` obtained by "restriction" of `F : Set.Iic j ⥤ C`
when `i ≤ j`. -/
def restrictionLE : Set.Iic i ⥤ C :=
(Set.initialSegIicIicOfLE hi).monotone.functor ⋙ F
@[simp]
lemma restrictionLE_obj (k : J) (hk : k ≤ i) :
(restrictionLE F hi).obj ⟨k, hk⟩ = F.obj ⟨k, hk.trans hi⟩ := rfl
@[simp]
lemma restrictionLE_map {k₁ k₂ : Set.Iic i} (φ : k₁ ⟶ k₂) :
(restrictionLE F hi).map φ = F.map (homOfLE (by simpa using leOfHom φ)) := rfl
end
variable (C) in
/-- A successor structure on a category consists of the
data of an object `succ X` for any `X : C`, a map `toSucc X : X ⟶ toSucc X`
(which does not need to be natural), and a zeroth object `X₀`.
-/
structure SuccStruct where
/-- the zeroth object -/
X₀ : C
/-- the successor of an object -/
succ (X : C) : C
/-- the map to the successor -/
toSucc (X : C) : X ⟶ succ X
namespace SuccStruct
/-- Given a functor `Φ : C ⥤ C`, a natural transformation of the form `𝟭 C ⟶ Φ`
induces a successor structure on `C ⥤ C`. -/
@[simps]
def ofNatTrans {F : C ⥤ C} (ε : 𝟭 C ⟶ F) : SuccStruct (C ⥤ C) where
succ G := G ⋙ F
toSucc G := Functor.whiskerLeft G ε
X₀ := 𝟭 C
variable (Φ : SuccStruct C)
/-- The class of morphisms that are of the form `toSucc X : X ⟶ succ X`. -/
def prop : MorphismProperty C := .ofHoms (fun (X : C) ↦ Φ.toSucc X)
lemma prop_toSucc (X : C) : Φ.prop (Φ.toSucc X) := ⟨_⟩
/-- The map `Φ.toSucc X : X ⟶ Φ.Succ X`, as an element in `Arrow C`. -/
@[simps!]
def toSuccArrow (X : C) : Arrow C := Arrow.mk (Φ.toSucc X)
lemma prop_iff {X Y : C} (f : X ⟶ Y) :
Φ.prop f ↔ Arrow.mk f = Φ.toSuccArrow X := by
constructor
· rintro ⟨_⟩
rfl
· intro h
rw [← Φ.prop.arrow_mk_mem_toSet_iff, h]
apply prop_toSucc
variable {Φ}
lemma prop.succ_eq {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) :
Φ.succ X = Y := by
cases hf
rfl
@[reassoc]
lemma prop.fac {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) :
f = Φ.toSucc X ≫ eqToHom hf.succ_eq := by
cases hf
simp
/-- If `Φ : SuccStruct C` and `f` is a morphism in `C` which
satisfies `Φ.prop f`, then this is the isomorphism of arrows
between `f` and `Φ.toSuccArrow X`. -/
@[simps!]
def prop.arrowIso {X Y : C} {f : X ⟶ Y} (hf : Φ.prop f) :
Arrow.mk f ≅ Φ.toSuccArrow X :=
Arrow.isoMk (Iso.refl _) (eqToIso hf.succ_eq.symm) (by simp [hf.fac])
variable (Φ)
variable [LinearOrder J]
/-- Given a functor `F : Set.Iic ⥤ C`, this is the morphism in `C`, as an element
in `Arrow C`, that is obtained by applying `F.map` to an inequality. -/
def arrowMap {j : J} (F : Set.Iic j ⥤ C) (i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ ≤ j) :
Arrow C :=
Arrow.mk (F.map (homOfLE h₁₂ : ⟨i₁, h₁₂.trans h₂⟩ ⟶ ⟨i₂, h₂⟩))
@[simp]
lemma arrowMap_refl {j : J} (F : Set.Iic j ⥤ C) (i : J) (hi : i ≤ j) :
arrowMap F i i (by simp) hi = Arrow.mk (𝟙 (F.obj ⟨i, hi⟩)) := by
simp [arrowMap]
lemma arrowMap_restrictionLE {j : J} (F : Set.Iic j ⥤ C) {j' : J} (hj' : j' ≤ j)
(i₁ i₂ : J) (h₁₂ : i₁ ≤ i₂) (h₂ : i₂ ≤ j') :
arrowMap (restrictionLE F hj') i₁ i₂ h₁₂ h₂ =
arrowMap F i₁ i₂ h₁₂ (h₂.trans hj') := rfl
section
variable [SuccOrder J] {j : J} (F : Set.Iic j ⥤ C) (i : J) (hi : i < j)
/-- Given a functor `F : Set.Iic j ⥤ C` and `i : J` such that `i < j`,
this is the arrow `F.obj ⟨i, _⟩ ⟶ F.obj ⟨Order.succ i, _⟩`. -/
def arrowSucc : Arrow C :=
arrowMap F i (Order.succ i) (Order.le_succ i) (Order.succ_le_of_lt hi)
lemma arrowSucc_def :
arrowSucc F i hi = arrowMap F i (Order.succ i) (Order.le_succ i) (Order.succ_le_of_lt hi) :=
rfl
end
section
variable [HasIterationOfShape J C]
{i : J} (F : Set.Iio i ⥤ C) (hi : Order.IsSuccLimit i) (k : J) (hk : k < i)
/-- Given `F : Set.Iio i ⥤ C`, with `i` a limit element, and `k` such that `hk : k < i`,
this is the map `colimit.ι F ⟨k, hk⟩`, as an element in `Arrow C`. -/
noncomputable def arrowι : Arrow C :=
letI := hasColimitsOfShape_of_isSuccLimit C i hi
Arrow.mk (colimit.ι F ⟨k, hk⟩)
lemma arrowι_def :
letI := hasColimitsOfShape_of_isSuccLimit C i hi
arrowι F hi k hk = Arrow.mk (colimit.ι F ⟨k, hk⟩) := rfl
end
variable [SuccOrder J] [OrderBot J] [HasIterationOfShape J C]
/-- The category of `j`th iterations of a successor structure `Φ : SuccStruct C`.
An object consists of the data of all iterations of `Φ` for `i : J` such
that `i ≤ j` (this is the field `F`). Such objects are
equipped with data and properties which characterizes uniquely the iterations
on three types of elements: `⊥`, successors, limit elements. -/
@[ext]
structure Iteration [WellFoundedLT J] (j : J) where
/-- The data of all `i`th iterations for `i : J` such that `i ≤ j`. -/
F : Set.Iic j ⥤ C
/-- The zeroth iteration is the zeroth object . -/
obj_bot : F.obj ⟨⊥, bot_le⟩ = Φ.X₀
/-- The iteration on a successor element is the successor. -/
arrowSucc_eq (i : J) (hi : i < j) : arrowSucc F i hi = Φ.toSuccArrow (F.obj ⟨i, hi.le⟩)
/-- The iteration on a limit element identifies to the colimit of the
value on smaller elements, see `Iteration.isColimit`. -/
arrowMap_limit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) (k : J) (hk : k < i) :
arrowMap F k i hk.le hij = arrowι (restrictionLT F hij) hi k hk
variable [WellFoundedLT J]
namespace Iteration
variable {Φ}
variable {j : J}
section
variable (iter : Φ.Iteration j)
lemma obj_succ (i : J) (hi : i < j) :
iter.F.obj ⟨Order.succ i, Order.succ_le_of_lt hi⟩ = Φ.succ (iter.F.obj ⟨i, hi.le⟩) :=
congr_arg Comma.right (iter.arrowSucc_eq i hi)
lemma prop_map_succ (i : J) (hi : i < j) :
Φ.prop (iter.F.map (homOfLE (Order.le_succ i) :
⟨i, hi.le⟩ ⟶ ⟨Order.succ i, Order.succ_le_of_lt hi⟩)) := by
rw [prop_iff, ← arrowMap, ← arrowSucc_def _ _ hi, iter.arrowSucc_eq]
lemma obj_limit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) :
letI := hasColimitsOfShape_of_isSuccLimit C i hi
iter.F.obj ⟨i, hij⟩ = colimit (restrictionLT iter.F hij) :=
congr_arg Comma.right (iter.arrowMap_limit i hi hij ⊥ (Order.IsSuccLimit.bot_lt hi))
/-- The iteration on a limit element identifies to the colimit of the
value on smaller elements. -/
noncomputable def isColimit (i : J) (hi : Order.IsSuccLimit i) (hij : i ≤ j) :
IsColimit (coconeOfLE iter.F hij) := by
letI := hasColimitsOfShape_of_isSuccLimit C i hi
refine IsColimit.ofIsoColimit (colimit.isColimit (restrictionLT iter.F hij))
(Cocones.ext (eqToIso (iter.obj_limit i hi hij).symm) ?_)
rintro ⟨k, hk⟩
apply Arrow.mk_injective
dsimp
rw [← arrowMap]
simp [iter.arrowMap_limit i hi hij k hk, arrowι_def]
/-- The element in `Φ.Iteration i` that is deduced from an element
in `Φ.Iteration j` when `i ≤ j`. -/
@[simps F]
def trunc (iter : Φ.Iteration j) {j' : J} (hj' : j' ≤ j) : Φ.Iteration j' where
F := restrictionLE iter.F hj'
obj_bot := iter.obj_bot
arrowSucc_eq i hi := iter.arrowSucc_eq i (lt_of_lt_of_le hi hj')
arrowMap_limit i hi hij k hk := iter.arrowMap_limit i hi (hij.trans hj') k hk
end
namespace subsingleton
variable {K : Type w} [LinearOrder K] {x : K} (F G : Set.Iic x ⥤ C)
section
variable (k₁ k₂ : K) (h₁₂ : k₁ ≤ k₂) (h₂ : k₂ ≤ x)
/-- Auxiliary definition for the proof of `Subsingleton (Φ.Iteration j)`. -/
def MapEq : Prop := arrowMap F k₁ k₂ h₁₂ h₂ = arrowMap G k₁ k₂ h₁₂ h₂
namespace MapEq
variable {k₁ k₂ h₁₂ h₂} (h : MapEq F G k₁ k₂ h₁₂ h₂)
include h
lemma src : F.obj ⟨k₁, h₁₂.trans h₂⟩ = G.obj ⟨k₁, h₁₂.trans h₂⟩ :=
congr_arg Comma.left h
lemma tgt : F.obj ⟨k₂, h₂⟩ = G.obj ⟨k₂, h₂⟩ :=
congr_arg Comma.right h
lemma w :
F.map (homOfLE h₁₂ : ⟨k₁, h₁₂.trans h₂⟩ ⟶ ⟨k₂, h₂⟩) =
eqToHom (by rw [h.src]) ≫ G.map (homOfLE h₁₂ : ⟨k₁, h₁₂.trans h₂⟩ ⟶ ⟨k₂, h₂⟩) ≫
eqToHom (by rw [h.tgt]) := by
have := (Arrow.mk_eq_mk_iff _ _).1 h
tauto
end MapEq
end
variable {F G}
lemma mapEq_refl (k : K) (hk : k ≤ x) (h : F.obj ⟨k, hk⟩ = G.obj ⟨k, hk⟩) :
MapEq F G k k (by simp) hk := by
rw [MapEq, arrowMap_refl, arrowMap_refl, h]
lemma mapEq_trans {i₁ i₂ i₃ : K} (h₁₂ : i₁ ≤ i₂) (h₂₃ : i₂ ≤ i₃) {h₃ : i₃ ≤ x}
(m₁₂ : MapEq F G i₁ i₂ h₁₂ (h₂₃.trans h₃)) (m₂₃ : MapEq F G i₂ i₃ h₂₃ h₃) :
MapEq F G i₁ i₃ (h₁₂.trans h₂₃) h₃ := by
simp only [MapEq, arrowMap, Arrow.mk_eq_mk_iff]
refine ⟨m₁₂.src, m₂₃.tgt, ?_⟩
rw [← homOfLE_comp (y := ⟨i₂, h₂₃.trans h₃⟩) h₁₂ h₂₃]
simp [-homOfLE_comp, m₁₂.w, m₂₃.w]
lemma ext (h : ∀ (k₁ k₂ : K) (h₁₂ : k₁ ≤ k₂) (h₂ : k₂ ≤ x),
MapEq F G k₁ k₂ h₁₂ h₂) :
F = G := by
apply Arrow.functor_ext
rintro ⟨k₁, _⟩ ⟨k₂, h₂⟩ f
apply h
end subsingleton
open subsingleton in
instance subsingleton : Subsingleton (Φ.Iteration j) where
allEq iter₁ iter₂ := by
suffices iter₁.F = iter₂.F by aesop
revert iter₁ iter₂
induction j using SuccOrder.limitRecOn with
| isMin j h =>
obtain rfl := h.eq_bot
intro iter₁ iter₂
refine ext (fun k₁ k₂ h₁₂ h₂ ↦ ?_)
obtain rfl : k₂ = ⊥ := by simpa using h₂
obtain rfl : k₁ = ⊥ := by simpa using h₁₂
apply mapEq_refl _ _ (by simp only [obj_bot])
| succ j hj₁ hj₂ =>
intro iter₁ iter₂
refine ext (fun k₁ k₂ h₁₂ h₂ ↦ ?_)
have h₀ := Order.le_succ j
replace hj₂ := hj₂ (iter₁.trunc h₀) (iter₂.trunc h₀)
have hsucc := Functor.congr_obj hj₂ ⟨j, by simp⟩
dsimp at hj₂ hsucc
wlog h : k₂ ≤ j generalizing k₁ k₂
· obtain h₂ | rfl := h₂.lt_or_eq
· exact this _ _ _ _ ((Order.lt_succ_iff_of_not_isMax hj₁).1 h₂)
· by_cases h' : k₁ ≤ j
· apply mapEq_trans _ h₀ (this k₁ j h' h₀ (by simp))
simp only [MapEq, ← arrowSucc_def _ _ (Order.lt_succ_of_not_isMax hj₁),
arrowSucc_eq, hsucc]
· simp only [not_le] at h'
obtain rfl : k₁ = Order.succ j := le_antisymm h₁₂
((Order.succ_le_iff_of_not_isMax hj₁).2 h')
rw [MapEq, arrowMap_refl, arrowMap_refl,
obj_succ _ _ h', obj_succ _ _ h', hsucc]
simp only [MapEq, ← arrowMap_restrictionLE _ (Order.le_succ j) _ _ _ h, hj₂]
| isSuccLimit j h₁ h₂ =>
intro iter₁ iter₂
refine ext (fun k₁ k₂ h₁₂ h₃ ↦ ?_)
wlog h₄ : k₂ < j generalizing k₁ k₂; swap
· have := h₂ k₂ h₄ (iter₁.trunc h₄.le) (iter₂.trunc h₄.le)
simp at this
simp only [MapEq, ← arrowMap_restrictionLE _ h₄.le _ _ _ (by rfl), this]
· obtain rfl : j = k₂ := le_antisymm (by simpa using h₄) h₃
have : restrictionLT iter₁.F le_rfl = restrictionLT iter₂.F le_rfl :=
Arrow.functor_ext (fun _ l _ ↦ this _ _ _ _ l.2)
by_cases h₅ : k₁ < j
· dsimp [MapEq]
simp_rw [arrowMap_limit _ _ h₁ _ _ h₅, this]
· obtain rfl : k₁ = j := le_antisymm h₁₂ (by simpa using h₅)
apply mapEq_refl
simp only [obj_limit _ _ h₁, this]
lemma congr_obj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
(k : J) (h₁ : k ≤ j₁) (h₂ : k ≤ j₂) :
iter₁.F.obj ⟨k, h₁⟩ = iter₂.F.obj ⟨k, h₂⟩ := by
wlog h : j₁ ≤ j₂ generalizing j₁ j₂
· exact (this iter₂ iter₁ h₂ h₁ (le_of_lt (by simpa using h))).symm
rw [Subsingleton.elim iter₁ (iter₂.trunc h)]
dsimp
lemma congr_arrowMap {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
{k₁ k₂ : J} (h : k₁ ≤ k₂) (h₁ : k₂ ≤ j₁) (h₂ : k₂ ≤ j₂) :
arrowMap iter₁.F k₁ k₂ h h₁ = arrowMap iter₂.F k₁ k₂ h h₂ := by
wlog hj : j₁ ≤ j₂ generalizing j₁ j₂
· simp [this iter₂ iter₁ h₂ h₁ ((not_le.1 hj).le)]
rw [Subsingleton.elim iter₁ (iter₂.trunc hj)]
rfl
lemma congr_map {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
{k₁ k₂ : J} (h : k₁ ≤ k₂) (h₁ : k₂ ≤ j₁) (h₂ : k₂ ≤ j₂) :
iter₁.F.map (homOfLE h : ⟨k₁, h.trans h₁⟩ ⟶ ⟨k₂, h₁⟩) =
eqToHom (congr_obj iter₁ iter₂ k₁ (h.trans h₁) (h.trans h₂)) ≫
iter₂.F.map (homOfLE h) ≫
eqToHom (congr_obj iter₁ iter₂ k₂ h₁ h₂).symm := by
have := (Arrow.mk_eq_mk_iff _ _).1 (congr_arrowMap iter₁ iter₂ h h₁ h₂)
tauto
/-- Given `iter₁ : Φ.Iteration j₁` and `iter₂ : Φ.Iteration j₂`, with `j₁ ≤ j₂`,
if `k₁ ≤ k₂` are elements such that `k₁ ≤ j₁` and `k₂ ≤ k₂`, then this
is the canonical map `iter₁.F.obj ⟨k₁, h₁⟩ ⟶ iter₂.F.obj ⟨k₂, h₂⟩`. -/
def mapObj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
{k₁ k₂ : J} (h₁₂ : k₁ ≤ k₂) (h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (hj : j₁ ≤ j₂) :
iter₁.F.obj ⟨k₁, h₁⟩ ⟶ iter₂.F.obj ⟨k₂, h₂⟩ :=
eqToHom (congr_obj iter₁ iter₂ k₁ h₁ (h₁.trans hj)) ≫
iter₂.F.map (homOfLE h₁₂)
lemma arrow_mk_mapObj {j₁ j₂ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
{k₁ k₂ : J} (h₁₂ : k₁ ≤ k₂) (h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (hj : j₁ ≤ j₂) :
Arrow.mk (mapObj iter₁ iter₂ h₁₂ h₁ h₂ hj) =
arrowMap iter₂.F k₁ k₂ h₁₂ h₂ := by
simp [mapObj, arrowMap]
@[simp]
lemma mapObj_refl {j : J} (iter : Φ.Iteration j)
{k l : J} (h : k ≤ l) (h' : l ≤ j) :
mapObj iter iter h (h.trans h') h' (by rfl) = iter.F.map (homOfLE h) := by
simp [mapObj]
@[reassoc (attr := simp)]
lemma mapObj_trans {j₁ j₂ j₃ : J} (iter₁ : Φ.Iteration j₁) (iter₂ : Φ.Iteration j₂)
(iter₃ : Φ.Iteration j₃) {k₁ k₂ k₃ : J} (h₁₂ : k₁ ≤ k₂) (h₂₃ : k₂ ≤ k₃)
(h₁ : k₁ ≤ j₁) (h₂ : k₂ ≤ j₂) (h₃ : k₃ ≤ j₃) (h₁₂' : j₁ ≤ j₂) (h₂₃' : j₂ ≤ j₃) :
mapObj iter₁ iter₂ h₁₂ h₁ h₂ h₁₂' ≫ mapObj iter₂ iter₃ h₂₃ h₂ h₃ h₂₃' =
mapObj iter₁ iter₃ (h₁₂.trans h₂₃) h₁ h₃ (h₁₂'.trans h₂₃') := by
simp [mapObj, congr_map iter₂ iter₃ h₁₂ h₂ (h₂.trans h₂₃'), ← Functor.map_comp]
end Iteration
end SuccStruct
end SmallObject
end CategoryTheory
|
Fold.lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
/-!
# Recursive computation rules for the Clifford algebra
This file provides API for a special case `CliffordAlgebra.foldr` of the universal property
`CliffordAlgebra.lift` with `A = Module.End R N` for some arbitrary module `N`. This specialization
resembles the `list.foldr` operation, allowing a bilinear map to be "folded" along the generators.
For convenience, this file also provides `CliffordAlgebra.foldl`, implemented via
`CliffordAlgebra.reverse`
## Main definitions
* `CliffordAlgebra.foldr`: a computation rule for building linear maps out of the clifford
algebra starting on the right, analogous to using `list.foldr` on the generators.
* `CliffordAlgebra.foldl`: a computation rule for building linear maps out of the clifford
algebra starting on the left, analogous to using `list.foldl` on the generators.
## Main statements
* `CliffordAlgebra.right_induction`: an induction rule that adds generators from the right.
* `CliffordAlgebra.left_induction`: an induction rule that adds generators from the left.
-/
universe u1 u2 u3
variable {R M N : Type*}
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
section Foldr
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr Q f hf n (ι Q m * x) = f m (foldr Q f hf n x)`.
For example, `foldr f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldr (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
(CliffordAlgebra.lift Q ⟨f, fun v => LinearMap.ext <| hf v⟩).toLinearMap.flip
@[simp]
theorem foldr_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldr Q f hf n (ι Q m) = f m n :=
LinearMap.congr_fun (lift_ι_apply _ _ _) n
@[simp]
theorem foldr_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldr Q f hf n (algebraMap R _ r) = r • n :=
LinearMap.congr_fun (AlgHom.commutes _ r) n
@[simp]
theorem foldr_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldr Q f hf n 1 = n :=
LinearMap.congr_fun (map_one (lift Q _)) n
@[simp]
theorem foldr_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldr Q f hf n (a * b) = foldr Q f hf (foldr Q f hf n b) a :=
LinearMap.congr_fun (map_mul (lift Q _) _ _) n
/-- This lemma demonstrates the origin of the `foldr` name. -/
theorem foldr_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldr Q f hf n (l.map <| ι Q).prod = List.foldr (fun m n => f m n) n l := by
induction l with
| nil => rw [List.map_nil, List.prod_nil, List.foldr_nil, foldr_one]
| cons hd tl ih => rw [List.map_cons, List.prod_cons, List.foldr_cons, foldr_mul, foldr_ι, ih]
end Foldr
section Foldl
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldl Q f hf n (ι Q m * x) = f m (foldl Q f hf n x)`.
For example, `foldl f hf n (r • ι R u + ι R v * ι R w) = r • f u n + f v (f w n)`. -/
def foldl (f : M →ₗ[R] N →ₗ[R] N) (hf : ∀ m x, f m (f m x) = Q m • x) :
N →ₗ[R] CliffordAlgebra Q →ₗ[R] N :=
LinearMap.compl₂ (foldr Q f hf) reverse
@[simp]
theorem foldl_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldl Q f hf n (reverse x) = foldr Q f hf n x :=
DFunLike.congr_arg (foldr Q f hf n) <| reverse_reverse _
@[simp]
theorem foldr_reverse (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (x : CliffordAlgebra Q) :
foldr Q f hf n (reverse x) = foldl Q f hf n x :=
rfl
@[simp]
theorem foldl_ι (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (m : M) : foldl Q f hf n (ι Q m) = f m n := by
rw [← foldr_reverse, reverse_ι, foldr_ι]
@[simp]
theorem foldl_algebraMap (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (r : R) :
foldl Q f hf n (algebraMap R _ r) = r • n := by
rw [← foldr_reverse, reverse.commutes, foldr_algebraMap]
@[simp]
theorem foldl_one (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) : foldl Q f hf n 1 = n := by
rw [← foldr_reverse, reverse.map_one, foldr_one]
@[simp]
theorem foldl_mul (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) (a b : CliffordAlgebra Q) :
foldl Q f hf n (a * b) = foldl Q f hf (foldl Q f hf n a) b := by
rw [← foldr_reverse, ← foldr_reverse, ← foldr_reverse, reverse.map_mul, foldr_mul]
/-- This lemma demonstrates the origin of the `foldl` name. -/
theorem foldl_prod_map_ι (l : List M) (f : M →ₗ[R] N →ₗ[R] N) (hf) (n : N) :
foldl Q f hf n (l.map <| ι Q).prod = List.foldl (fun m n => f n m) n l := by
rw [← foldr_reverse, reverse_prod_map_ι, ← List.map_reverse, foldr_prod_map_ι, List.foldr_reverse]
end Foldl
@[elab_as_elim]
theorem right_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (mul_ι : ∀ m x, P x → P (x * ι Q m)) : ∀ x, P x := by
/- It would be neat if we could prove this via `foldr` like how we prove
`CliffordAlgebra.induction`, but going via the grading seems easier. -/
intro x
have : x ∈ ⊤ := Submodule.mem_top (R := R)
rw [← iSup_ι_range_eq_top] at this
induction this using Submodule.iSup_induction' with
| mem i x hx =>
induction hx using Submodule.pow_induction_on_right' with
| algebraMap r => exact algebraMap r
| add _x _y _i _ _ ihx ihy => exact add _ _ ihx ihy
| mul_mem _i x _hx px m hm =>
obtain ⟨m, rfl⟩ := hm
exact mul_ι _ _ px
| zero => simpa only [map_zero] using algebraMap 0
| add _x _y _ _ ihx ihy =>
exact add _ _ ihx ihy
@[elab_as_elim]
theorem left_induction {P : CliffordAlgebra Q → Prop} (algebraMap : ∀ r : R, P (algebraMap _ _ r))
(add : ∀ x y, P x → P y → P (x + y)) (ι_mul : ∀ x m, P x → P (ι Q m * x)) : ∀ x, P x := by
refine reverse_involutive.surjective.forall.2 ?_
intro x
induction x using CliffordAlgebra.right_induction with
| algebraMap r => simpa only [reverse.commutes] using algebraMap r
| add _ _ hx hy => simpa only [map_add] using add _ _ hx hy
| mul_ι _ _ hx => simpa only [reverse.map_mul, reverse_ι] using ι_mul _ _ hx
/-! ### Versions with extra state -/
/-- Auxiliary definition for `CliffordAlgebra.foldr'` -/
def foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) :
M →ₗ[R] Module.End R (CliffordAlgebra Q × N) := by
have v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
have l := v_mul.compl₂ (LinearMap.fst _ _ N)
exact
{ toFun := fun m => (l m).prod (f m)
map_add' := fun v₂ v₂ =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_add _ _) x) (LinearMap.congr_fun (f.map_add _ _) x)
map_smul' := fun c v =>
LinearMap.ext fun x =>
Prod.ext (LinearMap.congr_fun (l.map_smul _ _) x)
(LinearMap.congr_fun (f.map_smul _ _) x) }
theorem foldr'Aux_apply_apply (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N) (m : M) (x_fx) :
foldr'Aux Q f m x_fx = (ι Q m * x_fx.1, f m x_fx) :=
rfl
theorem foldr'Aux_foldr'Aux (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (v : M) (x_fx) :
foldr'Aux Q f v (foldr'Aux Q f v x_fx) = Q v • x_fx := by
obtain ⟨x, fx⟩ := x_fx
simp only [foldr'Aux_apply_apply]
rw [← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, hf, Prod.smul_mk]
/-- Fold a bilinear map along the generators of a term of the clifford algebra, with the rule
given by `foldr' Q f hf n (ι Q m * x) = f m (x, foldr' Q f hf n x)`.
Note this is like `CliffordAlgebra.foldr`, but with an extra `x` argument.
Implement the recursion scheme `F[n0](m * x) = f(m, (x, F[n0](x)))`. -/
def foldr' (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n : N) : CliffordAlgebra Q →ₗ[R] N :=
LinearMap.snd _ _ _ ∘ₗ foldr Q (foldr'Aux Q f) (foldr'Aux_foldr'Aux Q _ hf) (1, n)
theorem foldr'_algebraMap (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n r) :
foldr' Q f hf n (algebraMap R _ r) = r • n :=
congr_arg Prod.snd (foldr_algebraMap _ _ _ _ _)
theorem foldr'_ι (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n m) :
foldr' Q f hf n (ι Q m) = f m (1, n) :=
congr_arg Prod.snd (foldr_ι _ _ _ _ _)
theorem foldr'_ι_mul (f : M →ₗ[R] CliffordAlgebra Q × N →ₗ[R] N)
(hf : ∀ m x fx, f m (ι Q m * x, f m (x, fx)) = Q m • fx) (n m) (x) :
foldr' Q f hf n (ι Q m * x) = f m (x, foldr' Q f hf n x) := by
dsimp [foldr']
rw [foldr_mul, foldr_ι, foldr'Aux_apply_apply]
refine congr_arg (f m) (Prod.mk.eta.symm.trans ?_)
congr 1
induction x using CliffordAlgebra.left_induction with
| algebraMap r => simp_rw [foldr_algebraMap, Prod.smul_mk, Algebra.algebraMap_eq_smul_one]
| add x y hx hy => rw [map_add, Prod.fst_add, hx, hy]
| ι_mul m x hx => rw [foldr_mul, foldr_ι, foldr'Aux_apply_apply, hx]
end CliffordAlgebra
|
FourierTransform.lean
|
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Algebra.Group.AddChar
import Mathlib.Analysis.Complex.Circle
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Integral.Bochner.Set
import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
/-!
# The Fourier transform
We set up the Fourier transform for complex-valued functions on finite-dimensional spaces.
## Design choices
In namespace `VectorFourier`, we define the Fourier integral in the following context:
* `𝕜` is a commutative ring.
* `V` and `W` are `𝕜`-modules.
* `e` is a unitary additive character of `𝕜`, i.e. an `AddChar 𝕜 Circle`.
* `μ` is a measure on `V`.
* `L` is a `𝕜`-bilinear form `V × W → 𝕜`.
* `E` is a complete normed `ℂ`-vector space.
With these definitions, we define `fourierIntegral` to be the map from functions `V → E` to
functions `W → E` that sends `f` to
`fun w ↦ ∫ v in V, e (-L v w) • f v ∂μ`,
This includes the cases `W` is the dual of `V` and `L` is the canonical pairing, or `W = V` and `L`
is a bilinear form (e.g. an inner product).
In namespace `Fourier`, we consider the more familiar special case when `V = W = 𝕜` and `L` is the
multiplication map (but still allowing `𝕜` to be an arbitrary ring equipped with a measure).
The most familiar case of all is when `V = W = 𝕜 = ℝ`, `L` is multiplication, `μ` is volume, and
`e` is `Real.fourierChar`, i.e. the character `fun x ↦ exp ((2 * π * x) * I)` (for which we
introduced the notation `𝐞` in the locale `FourierTransform`).
Another familiar case (which generalizes the previous one) is when `V = W` is an inner product space
over `ℝ` and `L` is the scalar product. We introduce two notations `𝓕` for the Fourier transform in
this case and `𝓕⁻ f (v) = 𝓕 f (-v)` for the inverse Fourier transform. These notations make
in particular sense for `V = W = ℝ`.
## Main results
At present the only nontrivial lemma we prove is `fourierIntegral_continuous`, stating that the
Fourier transform of an integrable function is continuous (under mild assumptions).
-/
noncomputable section
local notation "𝕊" => Circle
open MeasureTheory Filter
open scoped Topology
/-! ## Fourier theory for functions on general vector spaces -/
namespace VectorFourier
variable {𝕜 : Type*} [CommRing 𝕜] {V : Type*} [AddCommGroup V] [Module 𝕜 V] [MeasurableSpace V]
{W : Type*} [AddCommGroup W] [Module 𝕜 W]
{E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [NormedAddCommGroup F] [NormedSpace ℂ F]
[NormedAddCommGroup G] [NormedSpace ℂ G]
section Defs
/-- The Fourier transform integral for `f : V → E`, with respect to a bilinear form `L : V × W → 𝕜`
and an additive character `e`. -/
def fourierIntegral (e : AddChar 𝕜 𝕊) (μ : Measure V) (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E)
(w : W) : E :=
∫ v, e (-L v w) • f v ∂μ
theorem fourierIntegral_const_smul (e : AddChar 𝕜 𝕊) (μ : Measure V)
(L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (r : ℂ) :
fourierIntegral e μ L (r • f) = r • fourierIntegral e μ L f := by
ext1 w
simp only [Pi.smul_apply, fourierIntegral, smul_comm _ r, integral_smul]
/-- The uniform norm of the Fourier integral of `f` is bounded by the `L¹` norm of `f`. -/
theorem norm_fourierIntegral_le_integral_norm (e : AddChar 𝕜 𝕊) (μ : Measure V)
(L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (w : W) :
‖fourierIntegral e μ L f w‖ ≤ ∫ v : V, ‖f v‖ ∂μ := by
refine (norm_integral_le_integral_norm _).trans (le_of_eq ?_)
simp_rw [Circle.norm_smul]
/-- The Fourier integral converts right-translation into scalar multiplication by a phase factor. -/
theorem fourierIntegral_comp_add_right [MeasurableAdd V] (e : AddChar 𝕜 𝕊) (μ : Measure V)
[μ.IsAddRightInvariant] (L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜) (f : V → E) (v₀ : V) :
fourierIntegral e μ L (f ∘ fun v ↦ v + v₀) =
fun w ↦ e (L v₀ w) • fourierIntegral e μ L f w := by
ext1 w
dsimp only [fourierIntegral, Function.comp_apply, Circle.smul_def]
conv in L _ => rw [← add_sub_cancel_right v v₀]
rw [integral_add_right_eq_self fun v : V ↦ (e (-L (v - v₀) w) : ℂ) • f v, ← integral_smul]
congr 1 with v
rw [← smul_assoc, smul_eq_mul, ← Circle.coe_mul, ← e.map_add_eq_mul, ← LinearMap.neg_apply,
← sub_eq_add_neg, ← LinearMap.sub_apply, LinearMap.map_sub, neg_sub]
end Defs
section Continuous
/-!
In this section we assume 𝕜, `V`, `W` have topologies,
and `L`, `e` are continuous (but `f` needn't be).
This is used to ensure that `e (-L v w)` is (a.e. strongly) measurable. We could get away with
imposing only a measurable-space structure on 𝕜 (it doesn't have to be the Borel sigma-algebra of
a topology); but it seems hard to imagine cases where this extra generality would be useful, and
allowing it would complicate matters in the most important use cases.
-/
variable [TopologicalSpace 𝕜] [IsTopologicalRing 𝕜] [TopologicalSpace V] [BorelSpace V]
[TopologicalSpace W] {e : AddChar 𝕜 𝕊} {μ : Measure V} {L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜}
/-- For any `w`, the Fourier integral is convergent iff `f` is integrable. -/
theorem fourierIntegral_convergent_iff (he : Continuous e)
(hL : Continuous fun p : V × W ↦ L p.1 p.2) {f : V → E} (w : W) :
Integrable (fun v : V ↦ e (-L v w) • f v) μ ↔ Integrable f μ := by
-- first prove one-way implication
have aux {g : V → E} (hg : Integrable g μ) (x : W) :
Integrable (fun v : V ↦ e (-L v x) • g v) μ := by
have c : Continuous fun v ↦ e (-L v x) := he.comp (hL.comp (.prodMk_left _)).neg
simp_rw [← integrable_norm_iff (c.aestronglyMeasurable.smul hg.1), Circle.norm_smul]
exact hg.norm
-- then use it for both directions
refine ⟨fun hf ↦ ?_, fun hf ↦ aux hf w⟩
have := aux hf (-w)
simp_rw [← mul_smul (e _) (e _) (f _), ← e.map_add_eq_mul, LinearMap.map_neg, neg_add_cancel,
e.map_zero_eq_one, one_smul] at this -- the `(e _)` speeds up elaboration considerably
exact this
theorem fourierIntegral_add (he : Continuous e) (hL : Continuous fun p : V × W ↦ L p.1 p.2)
{f g : V → E} (hf : Integrable f μ) (hg : Integrable g μ) :
fourierIntegral e μ L (f + g) = fourierIntegral e μ L f + fourierIntegral e μ L g := by
ext1 w
dsimp only [Pi.add_apply, fourierIntegral]
simp_rw [smul_add]
rw [integral_add]
· exact (fourierIntegral_convergent_iff he hL w).2 hf
· exact (fourierIntegral_convergent_iff he hL w).2 hg
/-- The Fourier integral of an `L^1` function is a continuous function. -/
theorem fourierIntegral_continuous [FirstCountableTopology W] (he : Continuous e)
(hL : Continuous fun p : V × W ↦ L p.1 p.2) {f : V → E} (hf : Integrable f μ) :
Continuous (fourierIntegral e μ L f) := by
apply continuous_of_dominated
· exact fun w ↦ ((fourierIntegral_convergent_iff he hL w).2 hf).1
· exact fun w ↦ ae_of_all _ fun v ↦ le_of_eq (Circle.norm_smul _ _)
· exact hf.norm
· refine ae_of_all _ fun v ↦ (he.comp ?_).smul continuous_const
exact (hL.comp (.prodMk_right _)).neg
end Continuous
section Fubini
variable [TopologicalSpace 𝕜] [IsTopologicalRing 𝕜] [TopologicalSpace V] [BorelSpace V]
[TopologicalSpace W] [MeasurableSpace W] [BorelSpace W]
{e : AddChar 𝕜 𝕊} {μ : Measure V} {L : V →ₗ[𝕜] W →ₗ[𝕜] 𝕜}
{ν : Measure W} [SigmaFinite μ] [SigmaFinite ν] [SecondCountableTopology V]
variable [CompleteSpace E] [CompleteSpace F]
/-- The Fourier transform satisfies `∫ 𝓕 f * g = ∫ f * 𝓕 g`, i.e., it is self-adjoint.
Version where the multiplication is replaced by a general bilinear form `M`. -/
theorem integral_bilin_fourierIntegral_eq_flip
{f : V → E} {g : W → F} (M : E →L[ℂ] F →L[ℂ] G) (he : Continuous e)
(hL : Continuous fun p : V × W ↦ L p.1 p.2) (hf : Integrable f μ) (hg : Integrable g ν) :
∫ ξ, M (fourierIntegral e μ L f ξ) (g ξ) ∂ν =
∫ x, M (f x) (fourierIntegral e ν L.flip g x) ∂μ := by
by_cases hG : CompleteSpace G; swap; · simp [integral, hG]
calc
_ = ∫ ξ, M.flip (g ξ) (∫ x, e (-L x ξ) • f x ∂μ) ∂ν := rfl
_ = ∫ ξ, (∫ x, M.flip (g ξ) (e (-L x ξ) • f x) ∂μ) ∂ν := by
congr with ξ
apply (ContinuousLinearMap.integral_comp_comm _ _).symm
exact (fourierIntegral_convergent_iff he hL _).2 hf
_ = ∫ x, (∫ ξ, M.flip (g ξ) (e (-L x ξ) • f x) ∂ν) ∂μ := by
rw [integral_integral_swap]
have : Integrable (fun (p : W × V) ↦ ‖M‖ * (‖g p.1‖ * ‖f p.2‖)) (ν.prod μ) :=
(hg.norm.mul_prod hf.norm).const_mul _
apply this.mono
· -- This proof can be golfed but becomes very slow; breaking it up into steps
-- speeds up compilation.
change AEStronglyMeasurable (fun p : W × V ↦ (M (e (-(L p.2) p.1) • f p.2) (g p.1))) _
have A : AEStronglyMeasurable (fun (p : W × V) ↦ e (-L p.2 p.1) • f p.2) (ν.prod μ) := by
refine (Continuous.aestronglyMeasurable ?_).smul hf.1.comp_snd
exact he.comp (hL.comp continuous_swap).neg
have A' : AEStronglyMeasurable (fun p ↦ (g p.1, e (-(L p.2) p.1) • f p.2) : W × V → F × E)
(Measure.prod ν μ) := hg.1.comp_fst.prodMk A
have B : Continuous (fun q ↦ M q.2 q.1 : F × E → G) := M.flip.continuous₂
apply B.comp_aestronglyMeasurable A' -- `exact` works, but `apply` is 10x faster!
· filter_upwards with ⟨ξ, x⟩
rw [Function.uncurry_apply_pair, Submonoid.smul_def, (M.flip (g ξ)).map_smul,
← Submonoid.smul_def, Circle.norm_smul, ContinuousLinearMap.flip_apply,
norm_mul, norm_norm M, norm_mul, norm_norm, norm_norm, mul_comm (‖g _‖), ← mul_assoc]
exact M.le_opNorm₂ (f x) (g ξ)
_ = ∫ x, (∫ ξ, M (f x) (e (-L.flip ξ x) • g ξ) ∂ν) ∂μ := by
simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.map_smul_of_tower,
ContinuousLinearMap.coe_smul', Pi.smul_apply, LinearMap.flip_apply]
_ = ∫ x, M (f x) (∫ ξ, e (-L.flip ξ x) • g ξ ∂ν) ∂μ := by
congr with x
apply ContinuousLinearMap.integral_comp_comm
apply (fourierIntegral_convergent_iff he _ _).2 hg
exact hL.comp continuous_swap
/-- The Fourier transform satisfies `∫ 𝓕 f * g = ∫ f * 𝓕 g`, i.e., it is self-adjoint. -/
theorem integral_fourierIntegral_smul_eq_flip
{f : V → ℂ} {g : W → F} (he : Continuous e)
(hL : Continuous fun p : V × W ↦ L p.1 p.2) (hf : Integrable f μ) (hg : Integrable g ν) :
∫ ξ, (fourierIntegral e μ L f ξ) • (g ξ) ∂ν =
∫ x, (f x) • (fourierIntegral e ν L.flip g x) ∂μ :=
integral_bilin_fourierIntegral_eq_flip (ContinuousLinearMap.lsmul ℂ ℂ) he hL hf hg
end Fubini
lemma fourierIntegral_probChar {V W : Type*} {_ : MeasurableSpace V}
[AddCommGroup V] [Module ℝ V] [AddCommGroup W] [Module ℝ W]
(L : V →ₗ[ℝ] W →ₗ[ℝ] ℝ) (μ : Measure V) (f : V → E) (w : W) :
fourierIntegral Real.probChar μ L f w =
∫ v : V, Complex.exp (- L v w * Complex.I) • f v ∂μ := by
simp_rw [fourierIntegral, Circle.smul_def, Real.probChar_apply, Complex.ofReal_neg]
end VectorFourier
namespace VectorFourier
variable {𝕜 ι E F V W : Type*} [Fintype ι] [NontriviallyNormedField 𝕜]
[NormedAddCommGroup V] [NormedSpace 𝕜 V] [MeasurableSpace V] [BorelSpace V]
[NormedAddCommGroup W] [NormedSpace 𝕜 W]
{e : AddChar 𝕜 𝕊} {μ : Measure V} {L : V →L[𝕜] W →L[𝕜] 𝕜}
[NormedAddCommGroup F] [NormedSpace ℝ F]
[NormedAddCommGroup E] [NormedSpace ℂ E]
{M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace ℝ (M i)]
theorem fourierIntegral_continuousLinearMap_apply
{f : V → (F →L[ℝ] E)} {a : F} {w : W} (he : Continuous e) (hf : Integrable f μ) :
fourierIntegral e μ L.toLinearMap₁₂ f w a =
fourierIntegral e μ L.toLinearMap₁₂ (fun x ↦ f x a) w := by
rw [fourierIntegral, ContinuousLinearMap.integral_apply]
· rfl
· apply (fourierIntegral_convergent_iff he _ _).2 hf
exact L.continuous₂
theorem fourierIntegral_continuousMultilinearMap_apply
{f : V → (ContinuousMultilinearMap ℝ M E)} {m : (i : ι) → M i} {w : W} (he : Continuous e)
(hf : Integrable f μ) :
fourierIntegral e μ L.toLinearMap₁₂ f w m =
fourierIntegral e μ L.toLinearMap₁₂ (fun x ↦ f x m) w := by
rw [fourierIntegral, ContinuousMultilinearMap.integral_apply]
· rfl
· apply (fourierIntegral_convergent_iff he _ _).2 hf
exact L.continuous₂
end VectorFourier
/-! ## Fourier theory for functions on `𝕜` -/
namespace Fourier
variable {𝕜 : Type*} [CommRing 𝕜] [MeasurableSpace 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℂ E]
section Defs
/-- The Fourier transform integral for `f : 𝕜 → E`, with respect to the measure `μ` and additive
character `e`. -/
def fourierIntegral (e : AddChar 𝕜 𝕊) (μ : Measure 𝕜) (f : 𝕜 → E) (w : 𝕜) : E :=
VectorFourier.fourierIntegral e μ (LinearMap.mul 𝕜 𝕜) f w
theorem fourierIntegral_def (e : AddChar 𝕜 𝕊) (μ : Measure 𝕜) (f : 𝕜 → E) (w : 𝕜) :
fourierIntegral e μ f w = ∫ v : 𝕜, e (-(v * w)) • f v ∂μ :=
rfl
theorem fourierIntegral_const_smul (e : AddChar 𝕜 𝕊) (μ : Measure 𝕜) (f : 𝕜 → E) (r : ℂ) :
fourierIntegral e μ (r • f) = r • fourierIntegral e μ f :=
VectorFourier.fourierIntegral_const_smul _ _ _ _ _
/-- The uniform norm of the Fourier transform of `f` is bounded by the `L¹` norm of `f`. -/
theorem norm_fourierIntegral_le_integral_norm (e : AddChar 𝕜 𝕊) (μ : Measure 𝕜)
(f : 𝕜 → E) (w : 𝕜) : ‖fourierIntegral e μ f w‖ ≤ ∫ x : 𝕜, ‖f x‖ ∂μ :=
VectorFourier.norm_fourierIntegral_le_integral_norm _ _ _ _ _
/-- The Fourier transform converts right-translation into scalar multiplication by a phase
factor. -/
theorem fourierIntegral_comp_add_right [MeasurableAdd 𝕜] (e : AddChar 𝕜 𝕊) (μ : Measure 𝕜)
[μ.IsAddRightInvariant] (f : 𝕜 → E) (v₀ : 𝕜) :
fourierIntegral e μ (f ∘ fun v ↦ v + v₀) = fun w ↦ e (v₀ * w) • fourierIntegral e μ f w :=
VectorFourier.fourierIntegral_comp_add_right _ _ _ _ _
end Defs
end Fourier
open scoped Real
namespace Real
open FourierTransform
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
theorem vector_fourierIntegral_eq_integral_exp_smul {V : Type*} [AddCommGroup V] [Module ℝ V]
[MeasurableSpace V] {W : Type*} [AddCommGroup W] [Module ℝ W] (L : V →ₗ[ℝ] W →ₗ[ℝ] ℝ)
(μ : Measure V) (f : V → E) (w : W) :
VectorFourier.fourierIntegral fourierChar μ L f w =
∫ v : V, Complex.exp (↑(-2 * π * L v w) * Complex.I) • f v ∂μ := by
simp_rw [VectorFourier.fourierIntegral, Circle.smul_def, Real.fourierChar_apply, mul_neg,
neg_mul]
/-- The Fourier integral is well defined iff the function is integrable. Version with a general
continuous bilinear function `L`. For the specialization to the inner product in an inner product
space, see `Real.fourierIntegral_convergent_iff`. -/
@[simp]
theorem fourierIntegral_convergent_iff' {V W : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V]
[NormedAddCommGroup W] [NormedSpace ℝ W] [MeasurableSpace V] [BorelSpace V] {μ : Measure V}
{f : V → E} (L : V →L[ℝ] W →L[ℝ] ℝ) (w : W) :
Integrable (fun v : V ↦ 𝐞 (- L v w) • f v) μ ↔ Integrable f μ :=
VectorFourier.fourierIntegral_convergent_iff (E := E) (L := L.toLinearMap₁₂)
continuous_fourierChar L.continuous₂ _
section Apply
variable {ι F V W : Type*} [Fintype ι]
[NormedAddCommGroup V] [NormedSpace ℝ V] [MeasurableSpace V] [BorelSpace V]
[NormedAddCommGroup W] [NormedSpace ℝ W]
{μ : Measure V} {L : V →L[ℝ] W →L[ℝ] ℝ}
[NormedAddCommGroup F] [NormedSpace ℝ F]
{M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace ℝ (M i)]
theorem fourierIntegral_continuousLinearMap_apply'
{f : V → (F →L[ℝ] E)} {a : F} {w : W} (hf : Integrable f μ) :
VectorFourier.fourierIntegral 𝐞 μ L.toLinearMap₁₂ f w a =
VectorFourier.fourierIntegral 𝐞 μ L.toLinearMap₁₂ (fun x ↦ f x a) w :=
VectorFourier.fourierIntegral_continuousLinearMap_apply continuous_fourierChar hf
theorem fourierIntegral_continuousMultilinearMap_apply'
{f : V → ContinuousMultilinearMap ℝ M E} {m : (i : ι) → M i} {w : W} (hf : Integrable f μ) :
VectorFourier.fourierIntegral 𝐞 μ L.toLinearMap₁₂ f w m =
VectorFourier.fourierIntegral 𝐞 μ L.toLinearMap₁₂ (fun x ↦ f x m) w :=
VectorFourier.fourierIntegral_continuousMultilinearMap_apply continuous_fourierChar hf
end Apply
variable {V : Type*} [NormedAddCommGroup V]
[InnerProductSpace ℝ V] [MeasurableSpace V] [BorelSpace V]
{W : Type*} [NormedAddCommGroup W]
[InnerProductSpace ℝ W] [MeasurableSpace W] [BorelSpace W] [FiniteDimensional ℝ W]
open scoped RealInnerProductSpace
@[simp] theorem fourierIntegral_convergent_iff {μ : Measure V} {f : V → E} (w : V) :
Integrable (fun v : V ↦ 𝐞 (- ⟪v, w⟫) • f v) μ ↔ Integrable f μ :=
fourierIntegral_convergent_iff' (innerSL ℝ) w
variable [FiniteDimensional ℝ V]
/-- The Fourier transform of a function on an inner product space, with respect to the standard
additive character `ω ↦ exp (2 i π ω)`.
Denoted as `𝓕` within the `Real.FourierTransform` namespace. -/
def fourierIntegral (f : V → E) (w : V) : E :=
VectorFourier.fourierIntegral 𝐞 volume (innerₗ V) f w
/-- The inverse Fourier transform of a function on an inner product space, defined as the Fourier
transform but with opposite sign in the exponential.
Denoted as `𝓕⁻¹` within the `Real.FourierTransform` namespace. -/
def fourierIntegralInv (f : V → E) (w : V) : E :=
VectorFourier.fourierIntegral 𝐞 volume (-innerₗ V) f w
@[inherit_doc] scoped[FourierTransform] notation "𝓕" => Real.fourierIntegral
@[inherit_doc] scoped[FourierTransform] notation "𝓕⁻" => Real.fourierIntegralInv
lemma fourierIntegral_eq (f : V → E) (w : V) :
𝓕 f w = ∫ v, 𝐞 (-⟪v, w⟫) • f v := rfl
lemma fourierIntegral_eq' (f : V → E) (w : V) :
𝓕 f w = ∫ v, Complex.exp ((↑(-2 * π * ⟪v, w⟫) * Complex.I)) • f v := by
simp_rw [fourierIntegral_eq, Circle.smul_def, Real.fourierChar_apply, mul_neg, neg_mul]
lemma fourierIntegralInv_eq (f : V → E) (w : V) :
𝓕⁻ f w = ∫ v, 𝐞 ⟪v, w⟫ • f v := by
simp [fourierIntegralInv, VectorFourier.fourierIntegral]
lemma fourierIntegralInv_eq' (f : V → E) (w : V) :
𝓕⁻ f w = ∫ v, Complex.exp ((↑(2 * π * ⟪v, w⟫) * Complex.I)) • f v := by
simp_rw [fourierIntegralInv_eq, Circle.smul_def, Real.fourierChar_apply]
lemma fourierIntegral_comp_linearIsometry (A : W ≃ₗᵢ[ℝ] V) (f : V → E) (w : W) :
𝓕 (f ∘ A) w = (𝓕 f) (A w) := by
simp only [fourierIntegral_eq, ← A.inner_map_map, Function.comp_apply,
← MeasurePreserving.integral_comp A.measurePreserving A.toHomeomorph.measurableEmbedding]
lemma fourierIntegralInv_eq_fourierIntegral_neg (f : V → E) (w : V) :
𝓕⁻ f w = 𝓕 f (-w) := by
simp [fourierIntegral_eq, fourierIntegralInv_eq]
lemma fourierIntegralInv_eq_fourierIntegral_comp_neg (f : V → E) :
𝓕⁻ f = 𝓕 (fun x ↦ f (-x)) := by
ext y
rw [fourierIntegralInv_eq_fourierIntegral_neg]
change 𝓕 f (LinearIsometryEquiv.neg ℝ y) = 𝓕 (f ∘ LinearIsometryEquiv.neg ℝ) y
exact (fourierIntegral_comp_linearIsometry _ _ _).symm
lemma fourierIntegralInv_comm (f : V → E) :
𝓕 (𝓕⁻ f) = 𝓕⁻ (𝓕 f) := by
conv_rhs => rw [fourierIntegralInv_eq_fourierIntegral_comp_neg]
simp_rw [← fourierIntegralInv_eq_fourierIntegral_neg]
lemma fourierIntegralInv_comp_linearIsometry (A : W ≃ₗᵢ[ℝ] V) (f : V → E) (w : W) :
𝓕⁻ (f ∘ A) w = (𝓕⁻ f) (A w) := by
simp [fourierIntegralInv_eq_fourierIntegral_neg, fourierIntegral_comp_linearIsometry]
theorem fourierIntegral_real_eq (f : ℝ → E) (w : ℝ) :
fourierIntegral f w = ∫ v : ℝ, 𝐞 (-(v * w)) • f v := by
simp_rw [mul_comm _ w]
rfl
theorem fourierIntegral_real_eq_integral_exp_smul (f : ℝ → E) (w : ℝ) :
𝓕 f w = ∫ v : ℝ, Complex.exp (↑(-2 * π * v * w) * Complex.I) • f v := by
simp_rw [fourierIntegral_real_eq, Circle.smul_def, Real.fourierChar_apply, mul_neg, neg_mul,
mul_assoc]
theorem fourierIntegral_continuousLinearMap_apply
{F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
{f : V → (F →L[ℝ] E)} {a : F} {v : V} (hf : Integrable f) :
𝓕 f v a = 𝓕 (fun x ↦ f x a) v :=
fourierIntegral_continuousLinearMap_apply' (L := innerSL ℝ) hf
theorem fourierIntegral_continuousMultilinearMap_apply {ι : Type*} [Fintype ι]
{M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace ℝ (M i)]
{f : V → ContinuousMultilinearMap ℝ M E} {m : (i : ι) → M i} {v : V} (hf : Integrable f) :
𝓕 f v m = 𝓕 (fun x ↦ f x m) v :=
fourierIntegral_continuousMultilinearMap_apply' (L := innerSL ℝ) hf
end Real
|
Interval.lean
|
/-
Copyright (c) 2021 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.Fintype.BigOperators
import Mathlib.Data.DFinsupp.BigOperators
import Mathlib.Data.DFinsupp.Order
import Mathlib.Order.Interval.Finset.Basic
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
/-!
# Finite intervals of finitely supported functions
This file provides the `LocallyFiniteOrder` instance for `Π₀ i, α i` when `α` itself is locally
finite and calculates the cardinality of its finite intervals.
-/
open DFinsupp Finset
open Pointwise
variable {ι : Type*} {α : ι → Type*}
namespace Finset
variable [DecidableEq ι] [∀ i, Zero (α i)] {s : Finset ι} {f : Π₀ i, α i} {t : ∀ i, Finset (α i)}
/-- Finitely supported product of finsets. -/
def dfinsupp (s : Finset ι) (t : ∀ i, Finset (α i)) : Finset (Π₀ i, α i) :=
(s.pi t).map
⟨fun f => DFinsupp.mk s fun i => f i i.2, by
refine (mk_injective _).comp fun f g h => ?_
ext i hi
convert congr_fun h ⟨i, hi⟩⟩
@[simp]
theorem card_dfinsupp (s : Finset ι) (t : ∀ i, Finset (α i)) : #(s.dfinsupp t) = ∏ i ∈ s, #(t i) :=
(card_map _).trans <| card_pi _ _
variable [∀ i, DecidableEq (α i)]
theorem mem_dfinsupp_iff : f ∈ s.dfinsupp t ↔ f.support ⊆ s ∧ ∀ i ∈ s, f i ∈ t i := by
refine mem_map.trans ⟨?_, ?_⟩
· rintro ⟨f, hf, rfl⟩
rw [Function.Embedding.coeFn_mk]
refine ⟨support_mk_subset, fun i hi => ?_⟩
convert mem_pi.1 hf i hi
exact mk_of_mem hi
· refine fun h => ⟨fun i _ => f i, mem_pi.2 h.2, ?_⟩
ext i
dsimp
exact ite_eq_left_iff.2 fun hi => (notMem_support_iff.1 fun H => hi <| h.1 H).symm
/-- When `t` is supported on `s`, `f ∈ s.dfinsupp t` precisely means that `f` is pointwise in `t`.
-/
@[simp]
theorem mem_dfinsupp_iff_of_support_subset {t : Π₀ i, Finset (α i)} (ht : t.support ⊆ s) :
f ∈ s.dfinsupp t ↔ ∀ i, f i ∈ t i := by
refine mem_dfinsupp_iff.trans (forall_and.symm.trans <| forall_congr' fun i =>
⟨ fun h => ?_,
fun h => ⟨fun hi => ht <| mem_support_iff.2 fun H => mem_support_iff.1 hi ?_, fun _ => h⟩⟩)
· by_cases hi : i ∈ s
· exact h.2 hi
· rw [notMem_support_iff.1 (mt h.1 hi), notMem_support_iff.1 (notMem_mono ht hi)]
exact zero_mem_zero
· rwa [H, mem_zero] at h
end Finset
namespace DFinsupp
section BundledSingleton
variable [∀ i, Zero (α i)] {f : Π₀ i, α i} {i : ι} {a : α i}
/-- Pointwise `Finset.singleton` bundled as a `DFinsupp`. -/
def singleton (f : Π₀ i, α i) : Π₀ i, Finset (α i) where
toFun i := {f i}
support' := f.support'.map fun s => ⟨s.1, fun i => (s.prop i).imp id (congr_arg _)⟩
theorem mem_singleton_apply_iff : a ∈ f.singleton i ↔ a = f i :=
mem_singleton
end BundledSingleton
section BundledIcc
variable [∀ i, Zero (α i)] [∀ i, PartialOrder (α i)] [∀ i, LocallyFiniteOrder (α i)]
{f g : Π₀ i, α i} {i : ι} {a : α i}
/-- Pointwise `Finset.Icc` bundled as a `DFinsupp`. -/
def rangeIcc (f g : Π₀ i, α i) : Π₀ i, Finset (α i) where
toFun i := Icc (f i) (g i)
support' := f.support'.bind fun fs => g.support'.map fun gs =>
⟨ fs.1 + gs.1,
fun i => or_iff_not_imp_left.2 fun h => by
have hf : f i = 0 := (fs.prop i).resolve_left
(Multiset.notMem_mono (Multiset.Le.subset <| Multiset.le_add_right _ _) h)
have hg : g i = 0 := (gs.prop i).resolve_left
(Multiset.notMem_mono (Multiset.Le.subset <| Multiset.le_add_left _ _) h)
simp_rw [hf, hg]
exact Icc_self _⟩
@[simp]
theorem rangeIcc_apply (f g : Π₀ i, α i) (i : ι) : f.rangeIcc g i = Icc (f i) (g i) := rfl
theorem mem_rangeIcc_apply_iff : a ∈ f.rangeIcc g i ↔ f i ≤ a ∧ a ≤ g i := mem_Icc
theorem support_rangeIcc_subset [DecidableEq ι] [∀ i, DecidableEq (α i)] :
(f.rangeIcc g).support ⊆ f.support ∪ g.support := by
refine fun x hx => ?_
by_contra h
refine notMem_support_iff.2 ?_ hx
rw [rangeIcc_apply, notMem_support_iff.1 (notMem_mono subset_union_left h),
notMem_support_iff.1 (notMem_mono subset_union_right h)]
exact Icc_self _
end BundledIcc
section Pi
variable [∀ i, Zero (α i)] [DecidableEq ι] [∀ i, DecidableEq (α i)]
/-- Given a finitely supported function `f : Π₀ i, Finset (α i)`, one can define the finset
`f.pi` of all finitely supported functions whose value at `i` is in `f i` for all `i`. -/
def pi (f : Π₀ i, Finset (α i)) : Finset (Π₀ i, α i) := f.support.dfinsupp f
@[simp]
theorem mem_pi {f : Π₀ i, Finset (α i)} {g : Π₀ i, α i} : g ∈ f.pi ↔ ∀ i, g i ∈ f i :=
mem_dfinsupp_iff_of_support_subset <| Subset.refl _
@[simp]
theorem card_pi (f : Π₀ i, Finset (α i)) : #f.pi = f.prod fun i ↦ #(f i) := by
rw [pi, card_dfinsupp]
exact Finset.prod_congr rfl fun i _ => by simp only [Pi.natCast_apply, Nat.cast_id]
end Pi
section PartialOrder
variable [DecidableEq ι] [∀ i, DecidableEq (α i)]
variable [∀ i, PartialOrder (α i)] [∀ i, Zero (α i)] [∀ i, LocallyFiniteOrder (α i)]
instance instLocallyFiniteOrder : LocallyFiniteOrder (Π₀ i, α i) :=
LocallyFiniteOrder.ofIcc (Π₀ i, α i)
(fun f g => (f.support ∪ g.support).dfinsupp <| f.rangeIcc g)
(fun f g x => by
refine (mem_dfinsupp_iff_of_support_subset <| support_rangeIcc_subset).trans ?_
simp_rw [mem_rangeIcc_apply_iff, forall_and]
rfl)
variable (f g : Π₀ i, α i)
theorem Icc_eq : Icc f g = (f.support ∪ g.support).dfinsupp (f.rangeIcc g) := rfl
lemma card_Icc : #(Icc f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) :=
card_dfinsupp _ _
lemma 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]
lemma 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]
lemma 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 [DecidableEq ι] [∀ i, DecidableEq (α i)] [∀ i, Lattice (α i)] [∀ i, Zero (α i)]
[∀ i, LocallyFiniteOrder (α i)] (f g : Π₀ i, α i)
lemma 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
section CanonicallyOrdered
variable [DecidableEq ι] [∀ i, DecidableEq (α i)]
variable [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, CanonicallyOrderedAdd (α i)]
[∀ i, OrderBot (α i)] [∀ i, LocallyFiniteOrder (α i)]
variable (f : Π₀ i, α i)
lemma card_Iic : #(Iic f) = ∏ i ∈ f.support, #(Iic (f i)) := by
simp_rw [Iic_eq_Icc, card_Icc, DFinsupp.bot_eq_zero, support_zero, empty_union, zero_apply,
bot_eq_zero]
lemma card_Iio : #(Iio f) = (∏ i ∈ f.support, #(Iic (f i))) - 1 := by
rw [card_Iio_eq_card_Iic_sub_one, card_Iic]
end CanonicallyOrdered
end DFinsupp
|
BinaryRec.lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Praneeth Kolichala, Yuyang Zhao
-/
import Batteries.Tactic.Alias
import Mathlib.Init
/-!
# Binary recursion on `Nat`
This file defines binary recursion on `Nat`.
## Main results
* `Nat.binaryRec`: A recursion principle for `bit` representations of natural numbers.
* `Nat.binaryRec'`: The same as `binaryRec`, but the induction step can assume that if `n=0`,
the bit being appended is `true`.
* `Nat.binaryRecFromOne`: The same as `binaryRec`, but special casing both 0 and 1 as base cases.
-/
universe u
namespace Nat
/-- `bit b` appends the digit `b` to the little end of the binary representation of
its natural number input. -/
def bit (b : Bool) (n : Nat) : Nat :=
cond b (2 * n + 1) (2 * n)
theorem shiftRight_one (n) : n >>> 1 = n / 2 := rfl
@[simp]
theorem bit_decide_mod_two_eq_one_shiftRight_one (n : Nat) : bit (n % 2 = 1) (n >>> 1) = n := by
simp only [bit, shiftRight_one]
cases mod_two_eq_zero_or_one n with | _ h => simpa [h] using Nat.div_add_mod n 2
theorem bit_testBit_zero_shiftRight_one (n : Nat) : bit (n.testBit 0) (n >>> 1) = n := by
simp
@[simp]
theorem bit_eq_zero_iff {n : Nat} {b : Bool} : bit b n = 0 ↔ n = 0 ∧ b = false := by
cases n <;> cases b <;> simp [bit, Nat.two_mul, ← Nat.add_assoc]
/-- For a predicate `motive : Nat → Sort u`, if instances can be
constructed for natural numbers of the form `bit b n`,
they can be constructed for any given natural number. -/
@[inline]
def bitCasesOn {motive : Nat → Sort u} (n) (h : ∀ b n, motive (bit b n)) : motive n :=
-- `1 &&& n != 0` is faster than `n.testBit 0`. This may change when we have faster `testBit`.
let x := h (1 &&& n != 0) (n >>> 1)
-- `congrArg motive _ ▸ x` is defeq to `x` in non-dependent case
congrArg motive n.bit_testBit_zero_shiftRight_one ▸ x
/-- A recursion principle for `bit` representations of natural numbers.
For a predicate `motive : Nat → Sort u`, if instances can be
constructed for natural numbers of the form `bit b n`,
they can be constructed for all natural numbers. -/
@[elab_as_elim, specialize]
def binaryRec {motive : Nat → Sort u} (z : motive 0) (f : ∀ b n, motive n → motive (bit b n))
(n : Nat) : motive n :=
if n0 : n = 0 then congrArg motive n0 ▸ z
else
let x := f (1 &&& n != 0) (n >>> 1) (binaryRec z f (n >>> 1))
congrArg motive n.bit_testBit_zero_shiftRight_one ▸ x
decreasing_by exact bitwise_rec_lemma n0
/-- The same as `binaryRec`, but the induction step can assume that if `n=0`,
the bit being appended is `true` -/
@[elab_as_elim, specialize]
def binaryRec' {motive : Nat → Sort u} (z : motive 0)
(f : ∀ b n, (n = 0 → b = true) → motive n → motive (bit b n)) :
∀ n, motive n :=
binaryRec z fun b n ih =>
if h : n = 0 → b = true then f b n h ih
else
have : bit b n = 0 := by
rw [bit_eq_zero_iff]
cases n <;> cases b <;> simp at h ⊢
congrArg motive this ▸ z
/-- The same as `binaryRec`, but special casing both 0 and 1 as base cases -/
@[elab_as_elim, specialize]
def binaryRecFromOne {motive : Nat → Sort u} (z₀ : motive 0) (z₁ : motive 1)
(f : ∀ b n, n ≠ 0 → motive n → motive (bit b n)) :
∀ n, motive n :=
binaryRec' z₀ fun b n h ih =>
if h' : n = 0 then
have : bit b n = bit true 0 := by
rw [h', h h']
congrArg motive this ▸ z₁
else f b n h' ih
theorem bit_val (b n) : bit b n = 2 * n + b.toNat := by
cases b <;> rfl
@[simp]
theorem bit_div_two (b n) : bit b n / 2 = n := by
rw [bit_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
· cases b <;> decide
· decide
@[simp]
theorem bit_mod_two (b n) : bit b n % 2 = b.toNat := by
cases b <;> simp [bit_val]
@[simp]
theorem bit_shiftRight_one (b n) : bit b n >>> 1 = n :=
bit_div_two b n
theorem testBit_bit_zero (b n) : (bit b n).testBit 0 = b := by
simp
variable {motive : Nat → Sort u}
@[simp]
theorem bitCasesOn_bit (h : ∀ b n, motive (bit b n)) (b : Bool) (n : Nat) :
bitCasesOn (bit b n) h = h b n := by
change congrArg motive (bit b n).bit_testBit_zero_shiftRight_one ▸ h _ _ = h b n
generalize congrArg motive (bit b n).bit_testBit_zero_shiftRight_one = e; revert e
rw [testBit_bit_zero, bit_shiftRight_one]
intros; rfl
@[simp]
theorem binaryRec_zero (z : motive 0) (f : ∀ b n, motive n → motive (bit b n)) :
binaryRec z f 0 = z := by
rw [binaryRec]
simp
@[simp]
theorem binaryRec_one (z : motive 0) (f : ∀ b n, motive n → motive (bit b n)) :
binaryRec (motive := motive) z f 1 = f true 0 z := by
rw [binaryRec]
simp only [add_one_ne_zero, ↓reduceDIte, Nat.reduceShiftRight, binaryRec_zero]
rfl
theorem binaryRec_eq {z : motive 0} {f : ∀ b n, motive n → motive (bit b n)}
(b n) (h : f false 0 z = z ∨ (n = 0 → b = true)) :
binaryRec z f (bit b n) = f b n (binaryRec z f n) := by
by_cases h' : bit b n = 0
case pos =>
obtain ⟨rfl, rfl⟩ := bit_eq_zero_iff.mp h'
simp only [Bool.false_eq_true, imp_false, not_true_eq_false, or_false] at h
unfold binaryRec
exact h.symm
case neg =>
rw [binaryRec, dif_neg h']
change congrArg motive (bit b n).bit_testBit_zero_shiftRight_one ▸ f _ _ _ = _
generalize congrArg motive (bit b n).bit_testBit_zero_shiftRight_one = e; revert e
rw [testBit_bit_zero, bit_shiftRight_one]
intros; rfl
end Nat
|
Basic.lean
|
/-
Copyright (c) 2025 Stefan Kebekus. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stefan Kebekus
-/
import Mathlib.Analysis.InnerProductSpace.Laplacian
/-!
# Harmonic Functions
This file defines harmonic functions on real, finite-dimensional, inner product spaces `E`.
-/
variable
{E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
{G : Type*} [NormedAddCommGroup G] [NormedSpace ℝ G]
{f f₁ f₂ : E → F}
{x : E} {s t : Set E} {c : ℝ}
open Topology
namespace InnerProductSpace
/-!
## Definition
-/
variable (f x) in
/--
Let `E` be a real, finite-dimensional, inner product space and `x` be a point of `E`. A function `f`
on `E` is harmonic at `x` if it is two times continuously `ℝ`-differentiable and if its Laplacian
vanishes in a neighborhood of `x`.
-/
def HarmonicAt := (ContDiffAt ℝ 2 f x) ∧ (Δ f =ᶠ[𝓝 x] 0)
variable (f s) in
/--
Let `E` be a real, finite-dimensional, inner product space and `s` be a subset of `E`. A function
`f` on `E` is harmonic in a neighborhood of `s` if it is harmonic at every point of `s`.
-/
def HarmonicOnNhd := ∀ x ∈ s, HarmonicAt f x
/-!
## Elementary Properties
-/
/--
If two functions agree in a neighborhood of `x`, then one is harmonic at `x` iff so is the other.
-/
theorem harmonicAt_congr_nhds {f₁ f₂ : E → F} {x : E} (h : f₁ =ᶠ[𝓝 x] f₂) :
HarmonicAt f₁ x ↔ HarmonicAt f₂ x := by
constructor <;> intro hf
· exact ⟨hf.1.congr_of_eventuallyEq h.symm, (laplacian_congr_nhds h.symm).trans hf.2⟩
· exact ⟨hf.1.congr_of_eventuallyEq h, (laplacian_congr_nhds h).trans hf.2⟩
/--
If `f` is harmonic at `x`, then it is harmonic at all points in a neighborhood of `x`.
-/
theorem HarmonicAt.eventually {f : E → F} {x : E} (h : HarmonicAt f x) :
∀ᶠ y in 𝓝 x, HarmonicAt f y := by
filter_upwards [h.1.eventually (by simp), h.2.eventually_nhds] with a h₁a h₂a
exact ⟨h₁a, h₂a⟩
variable (f) in
/--
Harmonicity is an open property.
-/
theorem isOpen_setOf_harmonicAt : IsOpen { x : E | HarmonicAt f x } :=
isOpen_iff_mem_nhds.2 (fun _ hx ↦ hx.eventually)
/--
If `f` is harmonic in a neighborhood of `s`, it is harmonic in a neighborhood of every subset.
-/
lemma HarmonicOnNhd.mono (h : HarmonicOnNhd f s) (hst : t ⊆ s) :
HarmonicOnNhd f t := fun x hx ↦ h x (hst hx)
/-!
## Vector Space Structure
-/
/--
Sums of harmonic functions are harmonic.
-/
theorem HarmonicAt.add (h₁ : HarmonicAt f₁ x) (h₂ : HarmonicAt f₂ x) :
HarmonicAt (f₁ + f₂) x := by
constructor
· exact h₁.1.add h₂.1
· filter_upwards [h₁.1.laplacian_add_nhds h₂.1, h₁.2, h₂.2]
simp_all
/--
Sums of harmonic functions are harmonic.
-/
theorem HarmonicOnNhd.add (h₁ : HarmonicOnNhd f₁ s) (h₂ : HarmonicOnNhd f₂ s) :
HarmonicOnNhd (f₁ + f₂) s := fun x hx ↦ (h₁ x hx).add (h₂ x hx)
/--
Scalar multiples of harmonic functions are harmonic.
-/
theorem HarmonicAt.const_smul (h : HarmonicAt f x) :
HarmonicAt (c • f) x := by
constructor
· exact h.1.const_smul c
· filter_upwards [laplacian_smul_nhds c h.1, h.2]
simp_all
/--
Scalar multiples of harmonic functions are harmonic.
-/
theorem HarmonicOnNhd.const_smul (h : HarmonicOnNhd f s) :
HarmonicOnNhd (c • f) s := fun x hx ↦ (h x hx).const_smul
/-!
## Compatibility with Linear Maps
-/
/--
Compositions of continuous `ℝ`-linear maps with harmonic functions are harmonic.
-/
theorem HarmonicAt.comp_CLM (h : HarmonicAt f x) (l : F →L[ℝ] G) :
HarmonicAt (l ∘ f) x := by
constructor
· exact h.1.continuousLinearMap_comp l
· filter_upwards [h.1.laplacian_CLM_comp_left_nhds (l := l), h.2]
simp_all
/--
Compositions of continuous linear maps with harmonic functions are harmonic.
-/
theorem HarmonicOnNhd.comp_CLM (h : HarmonicOnNhd f s) (l : F →L[ℝ] G) :
HarmonicOnNhd (l ∘ f) s := fun x hx ↦ (h x hx).comp_CLM l
/--
Functions are harmonic iff their compositions with continuous linear equivalences are harmonic.
-/
theorem harmonicAt_comp_CLE_iff (l : F ≃L[ℝ] G) :
HarmonicAt (l ∘ f) x ↔ HarmonicAt f x := by
constructor <;> intro h
· simpa [Function.comp_def] using h.comp_CLM l.symm.toContinuousLinearMap
· exact h.comp_CLM l.toContinuousLinearMap
/--
Functions are harmonic iff their compositions with continuous linear equivalences are harmonic.
-/
theorem harmonicOnNhd_comp_CLE_iff (l : F ≃L[ℝ] G) :
HarmonicOnNhd (l ∘ f) s ↔ HarmonicOnNhd f s :=
forall₂_congr fun _ _ ↦ harmonicAt_comp_CLE_iff l
end InnerProductSpace
|
integral_char.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action countalg finalg zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow gseries.
From mathcomp Require Import nilpotent abelian ssrnum ssrint archimedean.
From mathcomp Require Import polydiv rat matrix mxalgebra intdiv mxpoly vector.
From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic.
From mathcomp Require Import algnum mxrepresentation classfun character.
(******************************************************************************)
(* This file provides some standard results based on integrality properties *)
(* of characters, such as theorem asserting that the degree of an irreducible *)
(* character of G divides the order of G (Isaacs 3.11), or the famous p^a.q^b *)
(* solvability theorem of Burnside. *)
(* Defined here: *)
(* 'K_k == the kth class sum in gring F G, where k : 'I_#|classes G|, and *)
(* F is inferred from the context. *)
(* := gset_mx F G (enum_val k) (see mxrepresentation.v). *)
(* --> The 'K_k form a basis of 'Z(group_ring F G)%MS. *)
(* gring_classM_coef i j k == the coordinate of 'K_i *m 'K_j on 'K_k; this *)
(* is usually abbreviated as a i j k. *)
(* gring_classM_coef_set A B z == the set of all (x, y) in setX A B such *)
(* that x * y = z; if A and B are respectively the ith and jth *)
(* conjugacy class of G, and z is in the kth conjugacy class, then *)
(* gring_classM_coef i j k is exactly the cardinal of this set. *)
(* 'omega_i[A] == the mode of 'chi[G]_i on (A \in 'Z(group_ring algC G))%MS, *)
(* i.e., the z such that gring_op 'Chi_i A = z%:M. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Lemma group_num_field_exists (gT : finGroupType) (G : {group gT}) :
{Qn : splittingFieldType rat & galois 1 {:Qn} &
{QnC : {rmorphism Qn -> algC}
& forall nuQn : argumentType [in 'Gal({:Qn} / 1)],
{nu : {rmorphism algC -> algC} |
{morph QnC: a / nuQn a >-> nu a}}
& {w : Qn & #|G|.-primitive_root w /\ <<1; w>>%VS = fullv
& forall (hT : finGroupType) (H : {group hT}) (phi : 'CF(H)),
phi \is a character ->
forall x, (#[x] %| #|G|)%N -> {a | QnC a = phi x}}}}.
Proof.
have [z prim_z] := C_prim_root_exists (cardG_gt0 G); set n := #|G| in prim_z *.
have [Qn [QnC [[|w []] // [Dz] genQn]]] := num_field_exists [:: z].
have prim_w: n.-primitive_root w by rewrite -Dz fmorph_primitive_root in prim_z.
have Q_Xn1: ('X^n - 1 : {poly Qn}) \is a polyOver 1%AS.
by rewrite rpredB ?rpred1 ?rpredX //= polyOverX.
have splitXn1: splittingFieldFor 1 ('X^n - 1) {:Qn}.
pose r := codom (fun i : 'I_n => w ^+ i).
have Dr: 'X^n - 1 = \prod_(y <- r) ('X - y%:P).
by rewrite -(factor_Xn_sub_1 prim_w) big_mkord big_image.
exists r; first by rewrite -Dr eqpxx.
apply/eqP; rewrite eqEsubv subvf -genQn adjoin_seqSr //; apply/allP=> /=.
by rewrite andbT -root_prod_XsubC -Dr; apply/unity_rootP/prim_expr_order.
have Qn_ax : FieldExt_isSplittingField _ Qn by constructor; exists ('X^n - 1).
exists (HB.pack_for (splittingFieldType rat) Qn Qn_ax).
apply/splitting_galoisField.
exists ('X^n - 1); split => //.
apply: separable_Xn_sub_1; rewrite -(fmorph_eq0 QnC) rmorph_nat.
by rewrite pnatr_eq0 -lt0n cardG_gt0.
exists QnC => [// nuQn|]; first exact: (extend_algC_subfield_aut QnC nuQn).
rewrite span_seq1 in genQn.
exists w => // hT H phi Nphi x x_dv_n.
apply: sig_eqW; have [rH ->] := char_reprP Nphi.
have [Hx | /cfun0->] := boolP (x \in H); last by exists 0; rewrite rmorph0.
have [e [_ [enx1 _] [-> _] _]] := repr_rsim_diag rH Hx.
have /fin_all_exists[k Dk] i: exists k, e 0 i = z ^+ k.
have [|k ->] := (prim_rootP prim_z) (e 0 i); last by exists k.
by have /dvdnP[q ->] := x_dv_n; rewrite mulnC exprM enx1 expr1n.
exists (\sum_i w ^+ k i); rewrite rmorph_sum; apply/eq_bigr => i _.
by rewrite rmorphXn /= Dz Dk.
Qed.
Section GenericClassSums.
(* This is Isaacs, Theorem (2.4), generalized to an arbitrary field, and with *)
(* the combinatorial definition of the coefficients exposed. *)
(* This part could move to mxrepresentation.*)
Variable (gT : finGroupType) (G : {group gT}) (F : fieldType).
Definition gring_classM_coef_set (Ki Kj : {set gT}) g :=
[set xy in [predX Ki & Kj] | let: (x, y) := xy in x * y == g]%g.
Definition gring_classM_coef (i j k : 'I_#|classes G|) :=
#|gring_classM_coef_set (enum_val i) (enum_val j) (repr (enum_val k))|.
Definition gring_class_sum (i : 'I_#|classes G|) := gset_mx F G (enum_val i).
Local Notation "''K_' i" := (gring_class_sum i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Local Notation a := gring_classM_coef.
Lemma gring_class_sum_central i : ('K_i \in 'Z(group_ring F G))%MS.
Proof. by rewrite -classg_base_center (eq_row_sub i) // rowK. Qed.
Lemma set_gring_classM_coef (i j k : 'I_#|classes G|) g :
g \in enum_val k ->
a i j k = #|gring_classM_coef_set (enum_val i) (enum_val j) g|.
Proof.
rewrite /a; have /repr_classesP[] := enum_valP k; move: (repr _) => g1 Gg1 ->.
have [/imsetP[zi Gzi ->] /imsetP[zj Gzj ->]] := (enum_valP i, enum_valP j).
move=> g1Gg; have Gg := subsetP (class_subG Gg1 (subxx _)) _ g1Gg.
set Aij := gring_classM_coef_set _ _.
without loss suffices IH: g g1 Gg Gg1 g1Gg / (#|Aij g1| <= #|Aij g|)%N.
by apply/eqP; rewrite eqn_leq !IH // class_sym.
have [w Gw Dg] := imsetP g1Gg; pose J2 (v : gT) xy := (xy.1 ^ v, xy.2 ^ v)%g.
have J2inj: injective (J2 w).
by apply: can_inj (J2 w^-1)%g _ => [[x y]]; rewrite /J2 /= !conjgK.
rewrite -(card_imset _ J2inj) subset_leq_card //; apply/subsetP.
move=> _ /imsetP[[x y] /setIdP[/andP[/= x1Gx y1Gy] Dxy1] ->] /[!inE]/=.
rewrite !(class_sym _ (_ ^ _)) !classGidl // class_sym x1Gx class_sym y1Gy.
by rewrite -conjMg (eqP Dxy1) /= -Dg.
Qed.
Theorem gring_classM_expansion i j : 'K_i *m 'K_j = \sum_k (a i j k)%:R *: 'K_k.
Proof.
have [/imsetP[zi Gzi dKi] /imsetP[zj Gzj dKj]] := (enum_valP i, enum_valP j).
pose aG := regular_repr F G; have sKG := subsetP (class_subG _ (subxx G)).
transitivity (\sum_(x in zi ^: G) \sum_(y in zj ^: G) aG (x * y)%g).
rewrite mulmx_suml -/aG dKi; apply: eq_bigr => x /sKG Gx.
rewrite mulmx_sumr -/aG dKj; apply: eq_bigr => y /sKG Gy.
by rewrite repr_mxM ?Gx ?Gy.
pose h2 xy : gT := (xy.1 * xy.2)%g.
pose h1 xy := enum_rank_in (classes1 G) (h2 xy ^: G).
rewrite pair_big (partition_big h1 xpredT) //=; apply: eq_bigr => k _.
rewrite (partition_big h2 [in enum_val k]) /= => [|[x y]]; last first.
case/andP=> /andP[/= /sKG Gx /sKG Gy] /eqP <-.
by rewrite enum_rankK_in ?class_refl ?mem_classes ?groupM ?Gx ?Gy.
rewrite scaler_sumr; apply: eq_bigr => g Kk_g; rewrite scaler_nat.
rewrite (set_gring_classM_coef _ _ Kk_g) -sumr_const; apply: eq_big => [] [x y].
rewrite !inE /= dKi dKj /h1 /h2 /=; apply: andb_id2r => /eqP ->.
have /imsetP[zk Gzk dKk] := enum_valP k; rewrite dKk in Kk_g.
by rewrite (class_eqP Kk_g) -dKk enum_valK_in eqxx andbT.
by rewrite /h2 /= => /andP[_ /eqP->].
Qed.
End GenericClassSums.
HB.lock Definition gring_irr_mode (gT : finGroupType) (G : {group gT})
(i : Iirr G) := ('chi_i 1%g)^-1 *: 'chi_i.
Canonical gring_irr_mode_unlockable := Unlockable gring_irr_mode.unlock.
Arguments gring_irr_mode {gT G%_G} i%_R _%_g : extra scopes.
Notation "''K_' i" := (gring_class_sum _ i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Notation "''omega_' i [ A ]" := (xcfun (gring_irr_mode i) A)
(i at level 2, format "''omega_' i [ A ]") : ring_scope.
Section IntegralChar.
Variables (gT : finGroupType) (G : {group gT}).
(* This is Isaacs, Corollary (3.6). *)
Lemma Aint_char (chi : 'CF(G)) x : chi \is a character -> chi x \in Aint.
Proof.
have [Gx /char_reprP[rG ->] {chi} | /cfun0->//] := boolP (x \in G).
have [e [_ [unit_e _] [-> _] _]] := repr_rsim_diag rG Gx.
rewrite rpred_sum // => i _; apply: (@Aint_unity_root #[x]) => //.
exact/unity_rootP.
Qed.
Lemma Aint_irr i x : 'chi[G]_i x \in Aint.
Proof. exact/Aint_char/irr_char. Qed.
Local Notation R_G := (group_ring algCfield G).
Local Notation a := gring_classM_coef.
(* This is Isaacs (2.25). *)
Lemma mx_irr_gring_op_center_scalar n (rG : mx_representation algCfield G n) A :
mx_irreducible rG -> (A \in 'Z(R_G))%MS -> is_scalar_mx (gring_op rG A).
Proof.
move/groupC=> irrG /center_mxP[R_A cGA].
apply: mx_abs_irr_cent_scalar irrG _ _; apply/centgmxP => x Gx.
by rewrite -(gring_opG rG Gx) -!gring_opM ?cGA // envelop_mx_id.
Qed.
Section GringIrrMode.
Variable i : Iirr G.
Let n := irr_degree (socle_of_Iirr i).
Let mxZn_inj: injective (@scalar_mx algCfield n).
Proof. by rewrite -[n]prednK ?irr_degree_gt0 //; apply: fmorph_inj. Qed.
Lemma cfRepr_gring_center n1 (rG : mx_representation algCfield G n1) A :
cfRepr rG = 'chi_i -> (A \in 'Z(R_G))%MS -> gring_op rG A = 'omega_i[A]%:M.
Proof.
move=> def_rG Z_A; rewrite unlock xcfunZl -{2}def_rG xcfun_repr.
have irr_rG: mx_irreducible rG.
have sim_rG: mx_rsim 'Chi_i rG by apply: cfRepr_inj; rewrite irrRepr.
exact: mx_rsim_irr sim_rG (socle_irr _).
have /is_scalar_mxP[e ->] := mx_irr_gring_op_center_scalar irr_rG Z_A.
congr _%:M; apply: (canRL (mulKf (irr1_neq0 i))).
by rewrite mulrC -def_rG cfunE repr_mx1 group1 -mxtraceZ scalemx1.
Qed.
Lemma irr_gring_center A :
(A \in 'Z(R_G))%MS -> gring_op 'Chi_i A = 'omega_i[A]%:M.
Proof. exact: cfRepr_gring_center (irrRepr i). Qed.
Lemma gring_irr_modeM A B :
(A \in 'Z(R_G))%MS -> (B \in 'Z(R_G))%MS ->
'omega_i[A *m B] = 'omega_i[A] * 'omega_i[B].
Proof.
move=> Z_A Z_B; have [[R_A cRA] [R_B cRB]] := (center_mxP Z_A, center_mxP Z_B).
apply: mxZn_inj; rewrite scalar_mxM -!irr_gring_center ?gring_opM //.
apply/center_mxP; split=> [|C R_C]; first exact: envelop_mxM.
by rewrite mulmxA cRA // -!mulmxA cRB.
Qed.
Lemma gring_mode_class_sum_eq (k : 'I_#|classes G|) g :
g \in enum_val k -> 'omega_i['K_k] = #|g ^: G|%:R * 'chi_i g / 'chi_i 1%g.
Proof.
have /imsetP[x Gx DxG] := enum_valP k; rewrite DxG => /imsetP[u Gu ->{g}].
rewrite unlock classGidl ?cfunJ {u Gu}// mulrC mulr_natl.
rewrite xcfunZl raddf_sum DxG -sumr_const /=; congr (_ * _).
by apply: eq_bigr => _ /imsetP[u Gu ->]; rewrite xcfunG ?groupJ ?cfunJ.
Qed.
(* This is Isaacs, Theorem (3.7). *)
Lemma Aint_gring_mode_class_sum k : 'omega_i['K_k] \in Aint.
Proof.
move: k; pose X := [tuple 'omega_i['K_k] | k < #|classes G| ].
have memX k: 'omega_i['K_k] \in X by apply: image_f.
have S_P := Cint_spanP X; set S := Cint_span X in S_P.
have S_X: {subset X <= S} by apply: mem_Cint_span.
have S_1: 1 \in S.
apply: S_X; apply/codomP; exists (enum_rank_in (classes1 G) 1%g).
rewrite (@gring_mode_class_sum_eq _ 1%g) ?enum_rankK_in ?classes1 //.
by rewrite mulfK ?irr1_neq0 // class1G cards1.
suffices Smul: mulr_closed S.
by move=> k; apply: fin_Csubring_Aint S_P _ _; rewrite ?S_X.
split=> // _ _ /S_P[x ->] /S_P[y ->].
rewrite mulr_sumr rpred_sum // => j _.
rewrite mulrzAr mulr_suml rpredMz ?rpred_sum // => k _.
rewrite mulrzAl rpredMz {x y}// !nth_mktuple.
rewrite -gring_irr_modeM ?gring_class_sum_central //.
rewrite gring_classM_expansion raddf_sum rpred_sum // => jk _.
by rewrite scaler_nat raddfMn rpredMn ?S_X ?memX.
Qed.
(* A more usable reformulation that does not involve the class sums. *)
Corollary Aint_class_div_irr1 x :
x \in G -> #|x ^: G|%:R * 'chi_i x / 'chi_i 1%g \in Aint.
Proof.
move=> Gx; have clGxG := mem_classes Gx; pose k := enum_rank_in clGxG (x ^: G).
have k_x: x \in enum_val k by rewrite enum_rankK_in // class_refl.
by rewrite -(gring_mode_class_sum_eq k_x) Aint_gring_mode_class_sum.
Qed.
(* This is Isaacs, Theorem (3.8). *)
Theorem coprime_degree_support_cfcenter g :
coprime (Num.truncn ('chi_i 1%g)) #|g ^: G| -> g \notin ('Z('chi_i))%CF ->
'chi_i g = 0.
Proof.
set m := Num.truncn _ => co_m_gG notZg.
have [Gg | /cfun0-> //] := boolP (g \in G).
have Dm: 'chi_i 1%g = m%:R by rewrite truncnK ?Cnat_irr1.
have m_gt0: (0 < m)%N by rewrite -ltC_nat -Dm irr1_gt0.
have nz_m: m%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n.
pose alpha := 'chi_i g / m%:R.
have a_lt1: `|alpha| < 1.
rewrite normrM normfV normr_nat -{2}(divff nz_m).
rewrite lt_def (can_eq (mulfVK nz_m)) eq_sym -{1}Dm -irr_cfcenterE // notZg.
by rewrite ler_pM2r ?invr_gt0 ?ltr0n // -Dm char1_ge_norm ?irr_char.
have Za: alpha \in Aint.
have [u _ /dvdnP[v eq_uv]] := Bezoutl #|g ^: G| m_gt0.
suffices ->: alpha = v%:R * 'chi_i g - u%:R * (alpha * #|g ^: G|%:R).
rewrite rpredB // rpredM ?rpred_nat ?Aint_irr //.
by rewrite mulrC mulrA -Dm Aint_class_div_irr1.
rewrite -mulrCA -[v%:R](mulfK nz_m) -!natrM -eq_uv (eqnP co_m_gG).
by rewrite mulrAC -mulrA -/alpha mulr_natl mulr_natr mulrS addrK.
have [Qn galQn [QnC gQnC [_ _ Qn_g]]] := group_num_field_exists <[g]>.
have{Qn_g} [a Da]: exists a, QnC a = alpha.
rewrite /alpha; have [a <-] := Qn_g _ G _ (irr_char i) g (dvdnn _).
by exists (a / m%:R); rewrite fmorph_div rmorph_nat.
have Za_nu nu: sval (gQnC nu) alpha \in Aint by rewrite Aint_aut.
have norm_a_nu nu: `|sval (gQnC nu) alpha| <= 1.
move: {nu}(sval _) => nu; rewrite fmorph_div rmorph_nat normrM normfV.
rewrite normr_nat -Dm -(ler_pM2r (irr1_gt0 (aut_Iirr nu i))) mul1r.
congr (_ <= _): (char1_ge_norm g (irr_char (aut_Iirr nu i))).
by rewrite !aut_IirrE !cfunE Dm rmorph_nat divfK.
pose beta := QnC (galNorm 1 {:Qn} a).
have Dbeta: beta = \prod_(nu in 'Gal({:Qn} / 1)) sval (gQnC nu) alpha.
rewrite /beta rmorph_prod. apply: eq_bigr => nu _.
by case: (gQnC nu) => f /= ->; rewrite Da.
have Zbeta: beta \in Num.int.
apply: Cint_rat_Aint; last by rewrite Dbeta rpred_prod.
rewrite /beta; have /vlineP[/= c ->] := mem_galNorm galQn (memvf a).
by rewrite alg_num_field fmorph_rat rpred_rat.
have [|nz_a] := boolP (alpha == 0).
by rewrite (can2_eq (divfK _) (mulfK _)) // mul0r => /eqP.
have: beta != 0 by rewrite Dbeta; apply/prodf_neq0 => nu _; rewrite fmorph_eq0.
move/(norm_intr_ge1 Zbeta); rewrite lt_geF //; apply: le_lt_trans a_lt1.
rewrite -[`|alpha|]mulr1 Dbeta (bigD1 1%g) ?group1 //= -Da.
case: (gQnC _) => /= _ <-.
rewrite gal_id normrM -subr_ge0 -mulrBr mulr_ge0 // Da subr_ge0.
elim/big_rec: _ => [|nu c _]; first by rewrite normr1 lexx.
apply: le_trans; rewrite -subr_ge0 -{1}[`|c|]mul1r normrM -mulrBl.
by rewrite mulr_ge0 // subr_ge0 norm_a_nu.
Qed.
End GringIrrMode.
(* This is Isaacs, Theorem (3.9). *)
Theorem primes_class_simple_gt1 C :
simple G -> ~~ abelian G -> C \in (classes G)^# -> (size (primes #|C|) > 1)%N.
Proof.
move=> simpleG not_cGG /setD1P[ntC /imsetP[g Gg defC]].
have{ntC} nt_g: g != 1%g by rewrite defC classG_eq1 in ntC.
rewrite ltnNge {C}defC; set m := #|_|; apply/negP=> p_natC.
have{p_natC} [p p_pr [a Dm]]: {p : nat & prime p & {a | m = p ^ a}%N}.
have /prod_prime_decomp->: (0 < m)%N by rewrite /m -index_cent1.
rewrite prime_decompE; case Dpr: (primes _) p_natC => [|p []] // _.
by exists 2%N => //; rewrite big_nil; exists 0.
rewrite big_seq1; exists p; last by exists (logn p m).
by have:= mem_primes p m; rewrite Dpr mem_head => /esym/and3P[].
have{simpleG} [ntG minG] := simpleP _ simpleG.
pose p_dv1 i := (p %| 'chi[G]_i 1%g)%C.
have p_dvd_supp_g i: ~~ p_dv1 i && (i != 0) -> 'chi_i g = 0.
rewrite /p_dv1 irr1_degree dvdC_nat -prime_coprime // => /andP[co_p_i1 nz_i].
have fful_i: cfker 'chi_i = [1].
have /minG[//|/eqP] := cfker_normal 'chi_i.
by rewrite eqEsubset subGcfker (negPf nz_i) andbF.
have trivZ: 'Z(G) = [1] by have /minG[|/center_idP/idPn] := center_normal G.
have trivZi: ('Z('chi_i))%CF = [1].
apply/trivgP; rewrite -quotient_sub1 ?norms1 //= -fful_i cfcenter_eq_center.
rewrite fful_i subG1 -(isog_eq1 (isog_center (quotient1_isog G))) /=.
by rewrite trivZ.
rewrite coprime_degree_support_cfcenter ?trivZi ?inE //.
by rewrite -/m Dm irr1_degree natrK coprime_sym coprimeXl.
pose alpha := \sum_(i | p_dv1 i && (i != 0)) 'chi_i 1%g / p%:R * 'chi_i g.
have nz_p: p%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n prime_gt0.
have Dalpha: alpha = - 1 / p%:R.
apply/(canRL (mulfK nz_p))/eqP; rewrite -addr_eq0 addrC; apply/eqP/esym.
transitivity (cfReg G g); first by rewrite cfRegE (negPf nt_g).
rewrite cfReg_sum sum_cfunE (bigD1 0) //= irr0 !cfunE cfun11 cfun1E Gg.
rewrite mulr1; congr (1 + _); rewrite (bigID p_dv1) /= addrC big_andbC.
rewrite big1 => [|i /p_dvd_supp_g chig0]; last by rewrite cfunE chig0 mulr0.
rewrite add0r big_andbC mulr_suml; apply: eq_bigr => i _.
by rewrite mulrAC divfK // cfunE.
suffices: (p %| 1)%C by rewrite (dvdC_nat p 1) dvdn1 -(subnKC (prime_gt1 p_pr)).
rewrite unfold_in (negPf nz_p).
rewrite Cint_rat_Aint ?rpred_div ?rpred1 ?rpred_nat //.
rewrite -rpredN // -mulNr -Dalpha rpred_sum // => i /andP[/dvdCP[c Zc ->] _].
by rewrite mulfK // rpredM ?Aint_irr ?Aint_Cint.
Qed.
End IntegralChar.
Section MoreIntegralChar.
Implicit Type gT : finGroupType.
(* This is Burnside's famous p^a.q^b theorem (Isaacs, Theorem (3.10)). *)
Theorem Burnside_p_a_q_b gT (G : {group gT}) :
(size (primes #|G|) <= 2)%N -> solvable G.
Proof.
move: {2}_.+1 (ltnSn #|G|) => n; elim: n => // n IHn in gT G *.
rewrite ltnS => leGn piGle2; have [simpleG | ] := boolP (simple G); last first.
rewrite negb_forall_in => /exists_inP[N sNG]; rewrite eq_sym.
have [->|] := eqVneq N G.
rewrite groupP /= genGid normG andbT eqb_id negbK => /eqP->.
exact: solvable1.
rewrite [N == G]eqEproper sNG eqbF_neg !negbK => ltNG /and3P[grN].
case/isgroupP: grN => {}N -> in sNG ltNG *; rewrite /= genGid => ntN nNG.
have nsNG: N <| G by apply/andP.
have dv_le_pi m: (m %| #|G| -> size (primes m) <= 2)%N.
move=> m_dv_G; apply: leq_trans piGle2.
by rewrite uniq_leq_size ?primes_uniq //; apply: pi_of_dvd.
rewrite (series_sol nsNG) !IHn ?dv_le_pi ?cardSg ?dvdn_quotient //.
by apply: leq_trans leGn; apply: ltn_quotient.
by apply: leq_trans leGn; apply: proper_card.
have [->|[p p_pr p_dv_G]] := trivgVpdiv G; first exact: solvable1.
have piGp: p \in \pi(G) by rewrite mem_primes p_pr cardG_gt0.
have [P sylP] := Sylow_exists p G; have [sPG pP p'GP] := and3P sylP.
have ntP: P :!=: 1%g by rewrite -rank_gt0 (rank_Sylow sylP) p_rank_gt0.
have /trivgPn[g /setIP[Pg cPg] nt_g]: 'Z(P) != 1%g.
by rewrite center_nil_eq1 // (pgroup_nil pP).
apply: abelian_sol; have: (size (primes #|g ^: G|) <= 1)%N.
rewrite -ltnS -[_.+1]/(size (p :: _)) (leq_trans _ piGle2) //.
rewrite -index_cent1 uniq_leq_size // => [/= | q].
rewrite primes_uniq -p'natEpi ?(pnat_dvd _ p'GP) ?indexgS //.
by rewrite subsetI sPG sub_cent1.
by rewrite inE => /predU1P[-> // |]; apply: pi_of_dvd; rewrite ?dvdn_indexg.
rewrite leqNgt; apply: contraR => /primes_class_simple_gt1-> //.
by rewrite !inE classG_eq1 nt_g mem_classes // (subsetP sPG).
Qed.
(* This is Isaacs, Theorem (3.11). *)
Theorem dvd_irr1_cardG gT (G : {group gT}) i : ('chi[G]_i 1%g %| #|G|)%C.
Proof.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //=.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite -[n in n / _]/(_ *+ true) -(eqxx i) -mulr_natr.
rewrite -first_orthogonality_relation mulVKf ?neq0CG //.
rewrite sum_by_classes => [|x y Gx Gy]; rewrite -?conjVg ?cfunJ //.
rewrite mulr_suml rpred_sum // => K /repr_classesP[Gx {1}->].
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
Qed.
(* This is Isaacs, Theorem (3.12). *)
Theorem dvd_irr1_index_center gT (G : {group gT}) i :
('chi[G]_i 1%g %| #|G : 'Z('chi_i)%CF|)%C.
Proof.
without loss fful: gT G i / cfaithful 'chi_i.
rewrite -{2}[i](quo_IirrK _ (subxx _)) 1?mod_IirrE ?cfModE ?cfker_normal //.
rewrite morph1; set i1 := quo_Iirr _ i => /(_ _ _ i1) IH.
have fful_i1: cfaithful 'chi_i1.
by rewrite quo_IirrE ?cfker_normal ?cfaithful_quo.
have:= IH fful_i1; rewrite cfcenter_fful_irr // -cfcenter_eq_center.
rewrite index_quotient_eq ?cfcenter_sub ?cfker_norm //.
by rewrite setIC subIset // normal_sub ?cfker_center_normal.
have [lambda lin_lambda Dlambda] := cfcenter_Res 'chi_i.
have DchiZ: {in G & 'Z(G), forall x y, 'chi_i (x * y)%g = 'chi_i x * lambda y}.
rewrite -(cfcenter_fful_irr fful) => x y Gx Zy.
apply: (mulfI (irr1_neq0 i)); rewrite mulrCA.
transitivity ('chi_i x * ('chi_i 1%g *: lambda) y); last by rewrite !cfunE.
rewrite -Dlambda cfResE ?cfcenter_sub //.
rewrite -irrRepr cfcenter_repr !cfunE in Zy *.
case/setIdP: Zy => Gy /is_scalar_mxP[e De].
rewrite repr_mx1 group1 (groupM Gx Gy) (repr_mxM _ Gx Gy) Gx Gy De.
by rewrite mul_mx_scalar mxtraceZ mulrCA mulrA mulrC -mxtraceZ scalemx1.
have inj_lambda: {in 'Z(G) &, injective lambda}.
rewrite -(cfcenter_fful_irr fful) => x y Zx Zy eq_xy.
apply/eqP; rewrite eq_mulVg1 -in_set1 (subsetP fful) // cfkerEirr inE.
apply/eqP; transitivity ('Res['Z('chi_i)%CF] 'chi_i (x^-1 * y)%g).
by rewrite cfResE ?cfcenter_sub // groupM ?groupV.
rewrite Dlambda !cfunE lin_charM ?groupV // -eq_xy -lin_charM ?groupV //.
by rewrite mulrC mulVg lin_char1 ?mul1r.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite (cfcenter_fful_irr fful) nCdivE natf_indexg ?center_sub //=.
have ->: #|G|%:R = \sum_(x in G) 'chi_i x * 'chi_i (x^-1)%g.
rewrite -[_%:R]mulr1; apply: canLR (mulVKf (neq0CG G)) _.
by rewrite first_orthogonality_relation eqxx.
rewrite (big_setID [set x | 'chi_i x == 0]) /= -setIdE.
rewrite big1 ?add0r => [| x /setIdP[_ /eqP->]]; last by rewrite mul0r.
pose h x := (x ^: G * 'Z(G))%g; rewrite (partition_big_imset h).
rewrite !mulr_suml rpred_sum //= => _ /imsetP[x /setDP[Gx nz_chi_x] ->].
have: #|x ^: G|%:R * ('chi_i x * 'chi_i x^-1%g) / 'chi_i 1%g \in Aint.
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
congr 2 (_ * _ \in Aint); apply: canRL (mulfK (neq0CG _)) _.
rewrite inE in nz_chi_x.
transitivity ('chi_i x * 'chi_i (x^-1)%g *+ #|h x|); last first.
rewrite -sumr_const.
apply: eq_big => [y | _ /mulsgP[_ z /imsetP[u Gu ->] Zz] ->].
rewrite !inE -andbA; apply/idP/and3P=> [|[_ _ /eqP <-]]; last first.
by rewrite -{1}[y]mulg1 mem_mulg ?class_refl.
case/mulsgP=> _ z /imsetP[u Gu ->] Zz ->; have /centerP[Gz cGz] := Zz.
rewrite groupM 1?DchiZ ?groupJ ?cfunJ //; split=> //.
by rewrite mulf_neq0 // lin_char_neq0 /= ?cfcenter_fful_irr.
rewrite -[z](mulKg u) -cGz // -conjMg /h classGidl {u Gu}//.
apply/eqP/setP=> w; apply/mulsgP/mulsgP=> [][_ z1 /imsetP[v Gv ->] Zz1 ->].
exists (x ^ v)%g (z * z1)%g; rewrite ?imset_f ?groupM //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg.
exists ((x * z) ^ v)%g (z^-1 * z1)%g; rewrite ?imset_f ?groupM ?groupV //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg mulKVg.
rewrite !irr_inv DchiZ ?groupJ ?cfunJ // rmorphM mulrACA -!normCK -exprMn.
by rewrite (normC_lin_char lin_lambda) ?mulr1 //= cfcenter_fful_irr.
rewrite mulrAC -natrM mulr_natl; congr (_ *+ _).
symmetry; rewrite /h /mulg /= /set_mulg [in _ @2: (_, _)]unlock cardsE.
rewrite -cardX card_in_image // => [] [y1 z1] [y2 z2] /=.
move=> /andP[/=/imsetP[u1 Gu1 ->] Zz1] /andP[/=/imsetP[u2 Gu2 ->] Zz2] {y1 y2}.
move=> eq12; have /eqP := congr1 'chi_i eq12.
rewrite !(cfunJ, DchiZ) ?groupJ // (can_eq (mulKf nz_chi_x)).
rewrite (inj_in_eq inj_lambda) // => /eqP eq_z12; rewrite eq_z12 in eq12 *.
by rewrite (mulIg _ _ _ eq12).
Qed.
(* This is Isaacs, Problem (3.7). *)
Lemma gring_classM_coef_sum_eq gT (G : {group gT}) j1 j2 k g1 g2 g :
let a := @gring_classM_coef gT G j1 j2 in let a_k := a k in
g1 \in enum_val j1 -> g2 \in enum_val j2 -> g \in enum_val k ->
let sum12g := \sum_i 'chi[G]_i g1 * 'chi_i g2 * ('chi_i g)^* / 'chi_i 1%g in
a_k%:R = (#|enum_val j1| * #|enum_val j2|)%:R / #|G|%:R * sum12g.
Proof.
move=> a /= Kg1 Kg2 Kg; rewrite mulrAC; apply: canRL (mulfK (neq0CG G)) _.
transitivity (\sum_j (#|G| * a j)%:R *+ (j == k) : algC).
by rewrite (bigD1 k) //= eqxx -natrM mulnC big1 ?addr0 // => j /negPf->.
have defK (j : 'I_#|classes G|) x: x \in enum_val j -> enum_val j = x ^: G.
by have /imsetP[y Gy ->] := enum_valP j => /class_eqP.
have Gg: g \in G.
by case/imsetP: (enum_valP k) Kg => x Gx -> /imsetP[y Gy ->]; apply: groupJ.
transitivity (\sum_j \sum_i 'omega_i['K_j] * 'chi_i 1%g * ('chi_i g)^* *+ a j).
apply: eq_bigr => j _; have /imsetP[z Gz Dj] := enum_valP j.
have Kz: z \in enum_val j by rewrite Dj class_refl.
rewrite -(Lagrange (subsetIl G 'C[z])) index_cent1 -mulnA natrM -mulrnAl.
have ->: (j == k) = (z \in enum_val k).
by rewrite -(inj_eq enum_val_inj); apply/eqP/idP=> [<-|/defK->].
rewrite (defK _ g) // -second_orthogonality_relation // mulr_suml.
apply: eq_bigr=> i _; rewrite natrM mulrA mulr_natr mulrC mulrA.
by rewrite (gring_mode_class_sum_eq i Kz) divfK ?irr1_neq0.
rewrite exchange_big /= mulr_sumr; apply: eq_bigr => i _.
transitivity ('omega_i['K_j1 *m 'K_j2] * 'chi_i 1%g * ('chi_i g)^*).
rewrite gring_classM_expansion -/a raddf_sum !mulr_suml /=.
by apply: eq_bigr => j _; rewrite xcfunZr -!mulrA mulr_natl.
rewrite !mulrA 2![_ / _]mulrAC (defK _ _ Kg1) (defK _ _ Kg2); congr (_ * _).
rewrite gring_irr_modeM ?gring_class_sum_central // mulnC natrM.
rewrite (gring_mode_class_sum_eq i Kg2) !mulrA divfK ?irr1_neq0 //.
by congr (_ * _); rewrite [_ * _]mulrC (gring_mode_class_sum_eq i Kg1) !mulrA.
Qed.
(* This is Isaacs, Problem (2.16). *)
Lemma index_support_dvd_degree gT (G H : {group gT}) chi :
H \subset G -> chi \is a character -> chi \in 'CF(G, H) ->
(H :==: 1%g) || abelian G ->
(#|G : H| %| chi 1%g)%C.
Proof.
move=> sHG Nchi Hchi ZHG.
suffices: (#|G : H| %| 'Res[H] chi 1%g)%C by rewrite cfResE ?group1.
rewrite ['Res _]cfun_sum_cfdot sum_cfunE rpred_sum // => i _.
rewrite cfunE dvdC_mulr ?intr_nat ?Cnat_irr1 //.
have [j ->]: exists j, 'chi_i = 'Res 'chi[G]_j.
case/predU1P: ZHG => [-> | cGG] in i *.
suffices ->: i = 0 by exists 0; rewrite !irr0 cfRes_cfun1 ?sub1G.
apply/val_inj; case: i => [[|i] //=]; rewrite ltnNge NirrE.
by rewrite (@leq_trans 1) // leqNgt classes_gt1 eqxx.
have linG := char_abelianP G cGG; have linG1 j := eqP (proj2 (andP (linG j))).
have /fin_all_exists[rH DrH] j: exists k, 'Res[H, G] 'chi_j = 'chi_k.
apply/irrP/lin_char_irr/andP.
by rewrite cfRes_char ?irr_char // cfRes1 ?linG1.
suffices{i} all_rH: codom rH =i Iirr H.
by exists (iinv (all_rH i)); rewrite DrH f_iinv.
apply/subset_cardP; last exact/subsetP; apply/esym/eqP.
rewrite card_Iirr_abelian ?(abelianS sHG) //.
rewrite -(eqn_pmul2r (indexg_gt0 G H)) Lagrange //; apply/eqP.
rewrite -sum_nat_const -card_Iirr_abelian // -sum1_card.
rewrite (partition_big rH [in codom rH]) /=; last exact: image_f.
have nsHG: H <| G by rewrite -sub_abelian_normal.
apply: eq_bigr => _ /codomP[i ->]; rewrite -card_quotient ?normal_norm //.
rewrite -card_Iirr_abelian ?quotient_abelian //.
have Mlin j1 j2: exists k, 'chi_j1 * 'chi_j2 = 'chi[G]_k.
exact/irrP/lin_char_irr/rpredM.
have /fin_all_exists[rQ DrQ] (j : Iirr (G / H)) := Mlin i (mod_Iirr j).
have mulJi: ('chi[G]_i)^*%CF * 'chi_i = 1.
apply/cfun_inP=> x Gx; rewrite !cfunE /= -lin_charV_conj ?linG // cfun1E Gx.
by rewrite lin_charV ?mulVf ?lin_char_neq0 ?linG.
have inj_rQ: injective rQ.
move=> j1 j2 /(congr1 (fun k => (('chi_i)^*%CF * 'chi_k) / H)%CF).
by rewrite -!DrQ !mulrA mulJi !mul1r !mod_IirrE ?cfModK // => /irr_inj.
rewrite -(card_imset _ inj_rQ) -sum1_card; apply: eq_bigl => j.
rewrite -(inj_eq irr_inj) -!DrH; apply/eqP/imsetP=> [eq_ij | [k _ ->]].
have [k Dk] := Mlin (conjC_Iirr i) j; exists (quo_Iirr H k) => //.
apply/irr_inj; rewrite -DrQ quo_IirrK //.
by rewrite -Dk conjC_IirrE mulrCA mulrA mulJi mul1r.
apply/subsetP=> x Hx; have Gx := subsetP sHG x Hx.
rewrite cfkerEirr inE linG1 -Dk conjC_IirrE; apply/eqP.
transitivity ((1 : 'CF(G)) x); last by rewrite cfun1E Gx.
by rewrite -mulJi !cfunE -!(cfResE _ sHG Hx) eq_ij.
rewrite -DrQ; apply/cfun_inP=> x Hx; rewrite !cfResE // cfunE mulrC.
by rewrite cfker1 ?linG1 ?mul1r ?(subsetP _ x Hx) // mod_IirrE ?cfker_mod.
have: (#|G : H| %| #|G : H|%:R * '[chi, 'chi_j])%C.
by rewrite dvdC_mulr ?intr_nat ?Cnat_cfdot_char_irr.
congr (_ %| _)%C; rewrite (cfdotEl _ Hchi) -(Lagrange sHG) mulnC natrM.
rewrite invfM -mulrA mulVKf ?neq0CiG //; congr (_ * _).
by apply: eq_bigr => x Hx; rewrite !cfResE.
Qed.
(* This is Isaacs, Theorem (3.13). *)
Theorem faithful_degree_p_part gT (p : nat) (G P : {group gT}) i :
cfaithful 'chi[G]_i -> p.-nat (Num.truncn ('chi_i 1%g)) ->
p.-Sylow(G) P -> abelian P ->
'chi_i 1%g = (#|G : 'Z(G)|`_p)%:R.
Proof.
have [p_pr | pr'p] := boolP (prime p); last first.
have p'n n: (n > 0)%N -> p^'.-nat n.
by move/p'natEpi->; rewrite mem_primes (negPf pr'p).
rewrite irr1_degree natrK => _ /pnat_1-> => [_ _|].
by rewrite part_p'nat ?p'n.
by rewrite p'n ?irr_degree_gt0.
move=> fful_i /p_natP[a Dchi1] sylP cPP.
have Dchi1C: 'chi_i 1%g = (p ^ a)%:R by rewrite -Dchi1 irr1_degree natrK.
have pa_dv_ZiG: (p ^ a %| #|G : 'Z(G)|)%N.
rewrite -dvdC_nat -[pa in (pa %| _)%C]Dchi1C -(cfcenter_fful_irr fful_i).
exact: dvd_irr1_index_center.
have [sPG pP p'PiG] := and3P sylP.
have ZchiP: 'Res[P] 'chi_i \in 'CF(P, P :&: 'Z(G)).
apply/cfun_onP=> x /[1!inE]; have [Px | /cfun0->//] := boolP (x \in P).
rewrite /= -(cfcenter_fful_irr fful_i) cfResE //.
apply: coprime_degree_support_cfcenter.
rewrite Dchi1 coprimeXl // prime_coprime // -p'natE //.
apply: pnat_dvd p'PiG; rewrite -index_cent1 indexgS // subsetI sPG.
by rewrite sub_cent1 (subsetP cPP).
have /andP[_ nZG] := center_normal G; have nZP := subset_trans sPG nZG.
apply/eqP; rewrite Dchi1C eqr_nat eqn_dvd -{1}(pfactorK a p_pr) -p_part.
rewrite partn_dvd //= -dvdC_nat -[pa in (_ %| pa)%C]Dchi1C -card_quotient //=.
rewrite -(card_Hall (quotient_pHall nZP sylP)) card_quotient // -indexgI.
rewrite -(cfResE _ sPG) // index_support_dvd_degree ?subsetIl ?cPP ?orbT //.
by rewrite cfRes_char ?irr_char.
Qed.
(* This is Isaacs, Lemma (3.14). *)
(* Note that the assumption that G be cyclic is unnecessary, as S will be *)
(* empty if this is not the case. *)
Lemma sum_norm2_char_generators gT (G : {group gT}) (chi : 'CF(G)) :
let S := [pred s | generator G s] in
chi \is a character -> {in S, forall s, chi s != 0} ->
\sum_(s in S) `|chi s| ^+ 2 >= #|S|%:R.
Proof.
move=> S Nchi nz_chi_S; pose n := #|G|.
have [g Sg | S_0] := pickP (generator G); last first.
by rewrite eq_card0 // big_pred0 ?lerr.
have defG: <[g]> = G by apply/esym/eqP.
have [cycG Gg]: cyclic G /\ g \in G by rewrite -defG cycle_cyclic cycle_id.
pose I := {k : 'I_n | coprime n k}; pose ItoS (k : I) := (g ^+ sval k)%g.
have imItoS: codom ItoS =i S.
move=> s; rewrite inE /= /ItoS /I /n /S -defG -orderE.
apply/codomP/idP=> [[[i cogi] ->] | Ss]; first by rewrite generator_coprime.
have [m ltmg Ds] := cyclePmin (cycle_generator Ss).
by rewrite Ds generator_coprime in Ss; apply: ex_intro (Sub (Sub m _) _) _.
have /injectiveP injItoS: injective ItoS.
move=> k1 k2 /eqP; apply: contraTeq.
by rewrite eq_expg_mod_order orderE defG -/n !modn_small.
have [Qn galQn [QnC gQnC [eps [pr_eps defQn] QnG]]] := group_num_field_exists G.
have{QnG} QnGg := QnG _ G _ _ g (order_dvdG Gg).
pose calG := 'Gal({:Qn} / 1).
have /fin_all_exists2[ItoQ inItoQ defItoQ] (k : I):
exists2 nu, nu \in calG & nu eps = eps ^+ val k.
- case: k => [[m _] /=]; rewrite coprime_sym => /Qn_aut_exists[nuC DnuC].
have [nuQ DnuQ] := restrict_aut_to_normal_num_field QnC nuC.
have hom_nu: kHom 1 {:Qn} (linfun nuQ).
rewrite k1HomE; apply/ahom_inP.
by split=> [u v | ]; rewrite !lfunE ?rmorphM ?rmorph1.
have [|nu cGnu Dnu] := kHom_to_gal _ (normalFieldf 1) hom_nu.
by rewrite !subvf.
exists nu => //; apply: (fmorph_inj QnC).
rewrite -Dnu ?memvf // lfunE DnuQ rmorphXn DnuC //.
by rewrite prim_expr_order // fmorph_primitive_root.
have{defQn} imItoQ: calG = ItoQ @: {:I}.
apply/setP=> nu; apply/idP/imsetP=> [cGnu | [k _ ->] //].
have pr_nu_e: n.-primitive_root (nu eps) by rewrite fmorph_primitive_root.
have [i Dnue] := prim_rootP pr_eps (prim_expr_order pr_nu_e).
rewrite Dnue prim_root_exp_coprime // coprime_sym in pr_nu_e.
apply: ex_intro2 (Sub i _) _ _ => //; apply/eqP.
rewrite /calG /= -defQn in ItoQ inItoQ defItoQ nu cGnu Dnue *.
by rewrite gal_adjoin_eq // defItoQ -Dnue.
have injItoQ: {in {:I} &, injective ItoQ}.
move=> k1 k2 _ _ /(congr1 (fun nu : gal_of _ => nu eps))/eqP.
by apply: contraTeq; rewrite !defItoQ (eq_prim_root_expr pr_eps) !modn_small.
pose pi1 := \prod_(s in S) chi s; pose pi2 := \prod_(s in S) `|chi s| ^+ 2.
have Qpi1: pi1 \in Crat.
have [a Da] := QnGg _ Nchi; suffices ->: pi1 = QnC (galNorm 1 {:Qn} a).
have /vlineP[q ->] := mem_galNorm galQn (memvf a).
by rewrite rmorphZ_num rmorph1 mulr1 Crat_rat.
rewrite /galNorm rmorph_prod -/calG imItoQ big_imset //=.
rewrite /pi1 -(eq_bigl _ _ imItoS) -big_uniq // big_image /=.
apply: eq_bigr => k _; have [nuC DnuC] := gQnC (ItoQ k); rewrite DnuC Da.
have [r ->] := char_sum_irr Nchi; rewrite !sum_cfunE rmorph_sum.
apply: eq_bigr => i _; have /QnGg[b Db] := irr_char i.
have Lchi_i: 'chi_i \is a linear_char by rewrite irr_cyclic_lin.
have /(prim_rootP pr_eps)[m Dem]: b ^+ n = 1.
apply/eqP; rewrite -(fmorph_eq1 QnC) rmorphXn /= Db -lin_charX //.
by rewrite -expg_mod_order orderE defG modnn lin_char1.
rewrite -Db /= -DnuC Dem rmorphXn /= defItoQ exprAC -{m}Dem rmorphXn /= {b}Db.
by rewrite lin_charX.
clear I ItoS imItoS injItoS ItoQ inItoQ defItoQ imItoQ injItoQ.
clear Qn galQn QnC gQnC eps pr_eps QnGg calG.
have{Qpi1} Zpi1: pi1 \in Num.int.
by rewrite Cint_rat_Aint // rpred_prod // => s _; apply: Aint_char.
have{pi1 Zpi1} pi2_ge1: 1 <= pi2.
have ->: pi2 = `|pi1| ^+ 2.
by rewrite (big_morph Num.norm (@normrM _) (@normr1 _)) -prodrXl.
by rewrite intr_normK // sqr_intr_ge1 //; apply/prodf_neq0.
have Sgt0: (#|S| > 0)%N by rewrite (cardD1 g) [g \in S]Sg.
rewrite -mulr_natr -ler_pdivlMr ?ltr0n //.
have n2chi_ge0 s: s \in S -> 0 <= `|chi s| ^+ 2 by rewrite exprn_ge0.
rewrite -(expr_ge1 Sgt0); last by rewrite divr_ge0 ?ler0n ?sumr_ge0.
by rewrite (le_trans pi2_ge1) // leif_AGM.
Qed.
(* This is Burnside's vanishing theorem (Isaacs, Theorem (3.15)). *)
Theorem nonlinear_irr_vanish gT (G : {group gT}) i :
'chi[G]_i 1%g > 1 -> exists2 x, x \in G & 'chi_i x = 0.
Proof.
move=> chi1gt1; apply/exists_eq_inP; apply: contraFT (lt_geF chi1gt1).
move=> /exists_inPn-nz_chi.
rewrite -(norm_natr (Cnat_irr1 i)) -(@expr_le1 _ 2)//.
rewrite -(lerD2r (#|G|%:R * '['chi_i])) {1}cfnorm_irr mulr1.
rewrite (cfnormE (cfun_onG _)) mulVKf ?neq0CG // (big_setD1 1%g) //=.
rewrite addrCA lerD2l (cardsD1 1%g) group1 mulrS lerD2l.
rewrite -sumr_const !(partition_big_imset (fun s => <[s]>)) /=.
apply: ler_sum => _ /imsetP[g /setD1P[ntg Gg] ->].
have sgG: <[g]> \subset G by rewrite cycle_subG.
pose S := [pred s | generator <[g]> s]; pose chi := 'Res[<[g]>] 'chi_i.
have defS: [pred s in G^# | <[s]> == <[g]>] =i S.
move=> s; rewrite inE /= eq_sym andb_idl // !inE -cycle_eq1 -cycle_subG.
by move/eqP <-; rewrite cycle_eq1 ntg.
have resS: {in S, 'chi_i =1 chi}.
by move=> s /cycle_generator=> g_s; rewrite cfResE ?cycle_subG.
rewrite !(eq_bigl _ _ defS) sumr_const.
rewrite (eq_bigr (fun s => `|chi s| ^+ 2)) => [|s /resS-> //].
apply: sum_norm2_char_generators => [|s Ss].
by rewrite cfRes_char ?irr_char.
by rewrite -resS // nz_chi ?(subsetP sgG) ?cycle_generator.
Qed.
End MoreIntegralChar.
|
Integral.lean
|
/-
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, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Integral.Bochner.Set
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-! # Properties of integration with respect to the Lebesgue measure -/
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace
section regionBetween
variable {α : Type*}
variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α}
theorem volume_regionBetween_eq_integral' [SigmaFinite μ] (f_int : IntegrableOn f s μ)
(g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : f ≤ᵐ[μ.restrict s] g) :
μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) := by
have h : g - f =ᵐ[μ.restrict s] fun x => Real.toNNReal (g x - f x) :=
hfg.mono fun x hx => (Real.coe_toNNReal _ <| sub_nonneg.2 hx).symm
rw [volume_regionBetween_eq_lintegral f_int.aemeasurable g_int.aemeasurable hs,
integral_congr_ae h, lintegral_congr_ae,
lintegral_coe_eq_integral _ ((integrable_congr h).mp (g_int.sub f_int))]
dsimp only
rfl
/-- If two functions are integrable on a measurable set, and one function is less than
or equal to the other on that set, then the volume of the region
between the two functions can be represented as an integral. -/
theorem volume_regionBetween_eq_integral [SigmaFinite μ] (f_int : IntegrableOn f s μ)
(g_int : IntegrableOn g s μ) (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) :
μ.prod volume (regionBetween f g s) = ENNReal.ofReal (∫ y in s, (g - f) y ∂μ) :=
volume_regionBetween_eq_integral' f_int g_int hs
((ae_restrict_iff' hs).mpr (Eventually.of_forall hfg))
end regionBetween
section SummableNormIcc
open ContinuousMap
/- The following lemma is a minor variation on `integrable_of_summable_norm_restrict` in
`Mathlib/MeasureTheory/Integral/SetIntegral.lean`, but it is placed here because it needs to know
that `Icc a b` has volume `b - a`. -/
/-- If the sequence with `n`-th term the sup norm of `fun x ↦ f (x + n)` on the interval `Icc 0 1`,
for `n ∈ ℤ`, is summable, then `f` is integrable on `ℝ`. -/
theorem Real.integrable_of_summable_norm_Icc {E : Type*} [NormedAddCommGroup E] {f : C(ℝ, E)}
(hf : Summable fun n : ℤ => ‖(f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)‖) :
Integrable f := by
refine integrable_of_summable_norm_restrict (.of_nonneg_of_le
(fun n : ℤ => mul_nonneg (norm_nonneg
(f.restrict (⟨Icc (n : ℝ) ((n : ℝ) + 1), isCompact_Icc⟩ : Compacts ℝ)))
ENNReal.toReal_nonneg) (fun n => ?_) hf) ?_
· simp only [Compacts.coe_mk, le_add_iff_nonneg_right, zero_le_one, volume_real_Icc_of_le,
add_sub_cancel_left, mul_one, norm_le _ (norm_nonneg _), ContinuousMap.restrict_apply]
intro x
have := ((f.comp <| ContinuousMap.addRight n).restrict (Icc 0 1)).norm_coe_le_norm
⟨x - n, ⟨sub_nonneg.mpr x.2.1, sub_le_iff_le_add'.mpr x.2.2⟩⟩
simpa only [ContinuousMap.restrict_apply, comp_apply, coe_addRight, Subtype.coe_mk,
sub_add_cancel] using this
· exact iUnion_Icc_intCast ℝ
end SummableNormIcc
/-!
### Substituting `-x` for `x`
These lemmas are stated in terms of either `Iic` or `Ioi` (neglecting `Iio` and `Ici`) to match
mathlib's conventions for integrals over finite intervals (see `intervalIntegral`). For the case
of finite integrals, see `intervalIntegral.integral_comp_neg`.
-/
/- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to
itself, it does not apply when `f` is more complicated -/
theorem integral_comp_neg_Iic {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(c : ℝ) (f : ℝ → E) : (∫ x in Iic c, f (-x)) = ∫ x in Ioi (-c), f x := by
have A : MeasurableEmbedding fun x : ℝ => -x :=
(Homeomorph.neg ℝ).isClosedEmbedding.measurableEmbedding
have := MeasurableEmbedding.setIntegral_map (μ := volume) A f (Ici (-c))
rw [Measure.map_neg_eq_self (volume : Measure ℝ)] at this
simp_rw [← integral_Ici_eq_integral_Ioi, this, neg_preimage, neg_Ici, neg_neg]
/- @[simp] Porting note: Linter complains it does not apply to itself. Although it does apply to
itself, it does not apply when `f` is more complicated -/
theorem integral_comp_neg_Ioi {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(c : ℝ) (f : ℝ → E) : (∫ x in Ioi c, f (-x)) = ∫ x in Iic (-c), f x := by
rw [← neg_neg c, ← integral_comp_neg_Iic]
simp only [neg_neg]
theorem integral_comp_abs {f : ℝ → ℝ} :
∫ x, f |x| = 2 * ∫ x in Ioi (0 : ℝ), f x := by
have eq : ∫ (x : ℝ) in Ioi 0, f |x| = ∫ (x : ℝ) in Ioi 0, f x := by
refine setIntegral_congr_fun measurableSet_Ioi (fun _ hx => ?_)
rw [abs_eq_self.mpr (le_of_lt (by exact hx))]
by_cases hf : IntegrableOn (fun x => f |x|) (Ioi 0)
· have int_Iic : IntegrableOn (fun x ↦ f |x|) (Iic 0) := by
rw [← Measure.map_neg_eq_self (volume : Measure ℝ)]
let m : MeasurableEmbedding fun x : ℝ => -x := (Homeomorph.neg ℝ).measurableEmbedding
rw [m.integrableOn_map_iff]
simp_rw [Function.comp_def, abs_neg, neg_preimage, neg_Iic, neg_zero]
exact Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi hf
calc
_ = (∫ x in Iic 0, f |x|) + ∫ x in Ioi 0, f |x| := by
rw [← setIntegral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi int_Iic hf,
Iic_union_Ioi, restrict_univ]
_ = 2 * ∫ x in Ioi 0, f x := by
rw [two_mul, eq]
congr! 1
rw [← neg_zero, ← integral_comp_neg_Iic, neg_zero]
refine setIntegral_congr_fun measurableSet_Iic (fun _ hx => ?_)
rw [abs_eq_neg_self.mpr (by exact hx)]
· have : ¬ Integrable (fun x => f |x|) := by
contrapose! hf
exact hf.integrableOn
rw [← eq, integral_undef hf, integral_undef this, mul_zero]
|
HomologySequenceLemmas.lean
|
/-
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.HomologySequence
import Mathlib.Algebra.Homology.QuasiIso
import Mathlib.CategoryTheory.Abelian.DiagramLemmas.Four
/-!
# Consequences of the homology sequence
Given a morphism `φ : S₁ ⟶ S₂` between two short exact sequences
of homological complexes in an abelian category, we show the naturality
of the homology sequence of `S₁` and `S₂` with respect to `φ`
(see `HomologicalComplex.HomologySequence.δ_naturality`).
Then, we shall show in this file that if two out of the three maps `φ.τ₁`,
`φ.τ₂`, `φ.τ₃` are quasi-isomorphisms, then the third is. We also obtain
more specific separate lemmas which gives sufficient condition for one
of these three morphisms to induce a mono/epi/iso in a given degree
in terms of properties of the two others in the same or neighboring degrees.
So far, we state only four lemmas for `φ.τ₃`. Eight more similar lemmas
for `φ.τ₁` and `φ.τ₂` shall be also obtained (TODO).
-/
open CategoryTheory ComposableArrows Abelian
namespace HomologicalComplex
variable {C ι : Type*} [Category C] [Abelian C] {c : ComplexShape ι}
{S S₁ S₂ : ShortComplex (HomologicalComplex C c)} (φ : S₁ ⟶ S₂)
(hS₁ : S₁.ShortExact) (hS₂ : S₂.ShortExact)
namespace HomologySequence
/-- The morphism `snakeInput hS₁ i j hij ⟶ snakeInput hS₂ i j hij` induced by
a morphism `φ : S₁ ⟶ S₂` of short complexes of homological complexes, that
are short exact (`hS₁ : S₁.ShortExact` and `hS₂ : S₁.ShortExact`). -/
@[simps]
noncomputable def mapSnakeInput (i j : ι) (hij : c.Rel i j) :
snakeInput hS₁ i j hij ⟶ snakeInput hS₂ i j hij where
f₀ := (homologyFunctor C c i).mapShortComplex.map φ
f₁ := (opcyclesFunctor C c i).mapShortComplex.map φ
f₂ := (cyclesFunctor C c j).mapShortComplex.map φ
f₃ := (homologyFunctor C c j).mapShortComplex.map φ
@[reassoc]
lemma δ_naturality (i j : ι) (hij : c.Rel i j) :
hS₁.δ i j hij ≫ HomologicalComplex.homologyMap φ.τ₁ _ =
HomologicalComplex.homologyMap φ.τ₃ _ ≫ hS₂.δ i j hij :=
ShortComplex.SnakeInput.naturality_δ (mapSnakeInput φ hS₁ hS₂ i j hij)
variable (S)
/-- The (exact) sequence `S.X₁.homology i ⟶ S.X₂.homology i ⟶ S.X₃.homology i` -/
@[simp]
noncomputable def composableArrows₂ (i : ι) : ComposableArrows C 2 :=
mk₂ (homologyMap S.f i) (homologyMap S.g i)
lemma composableArrows₂_exact (hS₁ : S₁.ShortExact) (i : ι) :
(composableArrows₂ S₁ i).Exact :=
(hS₁.homology_exact₂ i).exact_toComposableArrows
/-- The (exact) sequence
`H_i(S.X₁) ⟶ H_i(S.X₂) ⟶ H_i(S.X₃) ⟶ H_j(S.X₁) ⟶ H_j(S.X₂) ⟶ H_j(S.X₃)` when `c.Rel i j`
and `S` is a short exact short complex of homological complexes in an abelian category. -/
@[simp]
noncomputable def composableArrows₅ (i j : ι) (hij : c.Rel i j) : ComposableArrows C 5 :=
mk₅ (homologyMap S₁.f i) (homologyMap S₁.g i) (hS₁.δ i j hij)
(homologyMap S₁.f j) (homologyMap S₁.g j)
lemma composableArrows₅_exact (i j : ι) (hij : c.Rel i j) :
(composableArrows₅ hS₁ i j hij).Exact :=
exact_of_δ₀ (hS₁.homology_exact₂ i).exact_toComposableArrows
(exact_of_δ₀ (hS₁.homology_exact₃ i j hij).exact_toComposableArrows
(exact_of_δ₀ (hS₁.homology_exact₁ i j hij).exact_toComposableArrows
(hS₁.homology_exact₂ j).exact_toComposableArrows))
/-- The map between the exact sequences `S₁.X₁.homology i ⟶ S₁.X₂.homology i ⟶ S₁.X₃.homology i`
and `S₂.X₁.homology i ⟶ S₂.X₂.homology i ⟶ S₂.X₃.homology i` that is induced by `φ : S₁ ⟶ S₂`. -/
@[simp]
noncomputable def mapComposableArrows₂ (i : ι) : composableArrows₂ S₁ i ⟶ composableArrows₂ S₂ i :=
homMk₂ (homologyMap φ.τ₁ i) (homologyMap φ.τ₂ i) (homologyMap φ.τ₃ i) (by
dsimp
simp only [← homologyMap_comp, φ.comm₁₂]) (by
dsimp [Precomp.map]
simp only [← homologyMap_comp, φ.comm₂₃])
/-- The map `composableArrows₅ hS₁ i j hij ⟶ composableArrows₅ hS₂ i j hij` of exact
sequences induced by a morphism `φ : S₁ ⟶ S₂` between short exact short complexes of
homological complexes. -/
@[simp]
noncomputable def mapComposableArrows₅ (i j : ι) (hij : c.Rel i j) :
composableArrows₅ hS₁ i j hij ⟶ composableArrows₅ hS₂ i j hij :=
homMk₅ (homologyMap φ.τ₁ i) (homologyMap φ.τ₂ i) (homologyMap φ.τ₃ i)
(homologyMap φ.τ₁ j) (homologyMap φ.τ₂ j) (homologyMap φ.τ₃ j)
(naturality' (mapComposableArrows₂ φ i) 0 1)
(naturality' (mapComposableArrows₂ φ i) 1 2)
(δ_naturality φ hS₁ hS₂ i j hij)
(naturality' (mapComposableArrows₂ φ j) 0 1)
(naturality' (mapComposableArrows₂ φ j) 1 2)
include hS₁ hS₂
lemma mono_homologyMap_τ₃ (i : ι)
(h₁ : Epi (homologyMap φ.τ₁ i))
(h₂ : Mono (homologyMap φ.τ₂ i))
(h₃ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₁ j)) :
Mono (homologyMap φ.τ₃ i) := by
by_cases hi : ∃ j, c.Rel i j
· obtain ⟨j, hij⟩ := hi
apply mono_of_epi_of_mono_of_mono
((δlastFunctor ⋙ δlastFunctor).map (mapComposableArrows₅ φ hS₁ hS₂ i j hij))
· exact (composableArrows₅_exact hS₁ i j hij).δlast.δlast
· exact (composableArrows₅_exact hS₂ i j hij).δlast.δlast
· exact h₁
· exact h₂
· exact h₃ _ hij
· refine mono_of_epi_of_epi_of_mono (mapComposableArrows₂ φ i)
(composableArrows₂_exact hS₁ i) (composableArrows₂_exact hS₂ i) ?_ h₁ h₂
have := hS₁.epi_g
apply epi_homologyMap_of_epi_of_not_rel
simpa using hi
lemma epi_homologyMap_τ₃ (i : ι)
(h₁ : Epi (homologyMap φ.τ₂ i))
(h₂ : ∀ j, c.Rel i j → Epi (homologyMap φ.τ₁ j))
(h₃ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₂ j)) :
Epi (homologyMap φ.τ₃ i) := by
by_cases hi : ∃ j, c.Rel i j
· obtain ⟨j, hij⟩ := hi
apply epi_of_epi_of_epi_of_mono
((δ₀Functor ⋙ δlastFunctor).map (mapComposableArrows₅ φ hS₁ hS₂ i j hij))
· exact (composableArrows₅_exact hS₁ i j hij).δ₀.δlast
· exact (composableArrows₅_exact hS₂ i j hij).δ₀.δlast
· exact h₁
· exact h₂ j hij
· exact h₃ j hij
· have := hS₂.epi_g
have eq := (homologyFunctor C _ i).congr_map φ.comm₂₃
dsimp at eq
simp only [homologyMap_comp] at eq
have := epi_homologyMap_of_epi_of_not_rel S₂.g i (by simpa using hi)
exact epi_of_epi_fac eq.symm
lemma isIso_homologyMap_τ₃ (i : ι)
(h₁ : Epi (homologyMap φ.τ₁ i))
(h₂ : IsIso (homologyMap φ.τ₂ i))
(h₃ : ∀ j, c.Rel i j → IsIso (homologyMap φ.τ₁ j))
(h₄ : ∀ j, c.Rel i j → Mono (homologyMap φ.τ₂ j)) :
IsIso (homologyMap φ.τ₃ i) := by
have := mono_homologyMap_τ₃ φ hS₁ hS₂ i h₁ (IsIso.mono_of_iso _) (fun j hij => by
have := h₃ j hij
infer_instance)
have := epi_homologyMap_τ₃ φ hS₁ hS₂ i inferInstance (fun j hij => by
have := h₃ j hij
infer_instance) h₄
apply isIso_of_mono_of_epi
lemma quasiIso_τ₃ (h₁ : QuasiIso φ.τ₁) (h₂ : QuasiIso φ.τ₂) :
QuasiIso φ.τ₃ := by
rw [quasiIso_iff]
intro i
rw [quasiIsoAt_iff_isIso_homologyMap]
apply isIso_homologyMap_τ₃ φ hS₁ hS₂
all_goals infer_instance
end HomologySequence
end HomologicalComplex
|
Defs.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Group.Defs
/-!
# The integers form a group
This file contains the additive group and multiplicative monoid instances on the integers.
See note [foundational algebra order theory].
-/
assert_not_exists Ring DenselyOrdered
open Nat
namespace Int
/-! ### Instances -/
instance instCommMonoid : CommMonoid ℤ where
mul_comm := Int.mul_comm
mul_one := Int.mul_one
one_mul := Int.one_mul
npow n x := x ^ n
npow_zero _ := rfl
npow_succ _ _ := rfl
mul_assoc := Int.mul_assoc
instance instAddCommGroup : AddCommGroup ℤ where
add_comm := Int.add_comm
add_assoc := Int.add_assoc
add_zero := Int.add_zero
zero_add := Int.zero_add
neg_add_cancel := Int.add_left_neg
nsmul := (·*·)
nsmul_zero := Int.zero_mul
nsmul_succ n x :=
show (n + 1 : ℤ) * x = n * x + x
by rw [Int.add_mul, Int.one_mul]
zsmul := (·*·)
zsmul_zero' := Int.zero_mul
zsmul_succ' m n := by
simp only [natCast_succ, Int.add_mul, Int.add_comm, Int.one_mul]
zsmul_neg' m n := by simp only [negSucc_eq, natCast_succ, Int.neg_mul]
sub_eq_add_neg _ _ := Int.sub_eq_add_neg
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances like `Int.instNormedCommRing` being used to construct
these instances non-computably.
-/
set_option linter.style.commandStart false
instance instAddCommMonoid : AddCommMonoid ℤ := by infer_instance
instance instAddMonoid : AddMonoid ℤ := by infer_instance
instance instMonoid : Monoid ℤ := by infer_instance
instance instCommSemigroup : CommSemigroup ℤ := by infer_instance
instance instSemigroup : Semigroup ℤ := by infer_instance
instance instAddGroup : AddGroup ℤ := by infer_instance
instance instAddCommSemigroup : AddCommSemigroup ℤ := by infer_instance
instance instAddSemigroup : AddSemigroup ℤ := by infer_instance
-- This lemma is higher priority than later `_root_.nsmul_eq_mul` so that the `simpNF` is happy
@[simp high] protected lemma nsmul_eq_mul (n : ℕ) (a : ℤ) : n • a = n * a := rfl
-- This lemma is higher priority than later `_root_.zsmul_eq_mul` so that the `simpNF` is happy
@[simp high] protected lemma zsmul_eq_mul (n a : ℤ) : n • a = n * a := rfl
end Int
-- TODO: Do we really need this lemma? This is just `smul_eq_mul`
lemma zsmul_int_int (a b : ℤ) : a • b = a * b := rfl
lemma zsmul_int_one (n : ℤ) : n • (1 : ℤ) = n := mul_one _
|
SmoothSeries.lean
|
/-
Copyright (c) 2022 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.Analysis.Calculus.ContDiff.Operations
import Mathlib.Analysis.Calculus.UniformLimitsDeriv
import Mathlib.Topology.Algebra.InfiniteSum.Module
import Mathlib.Analysis.NormedSpace.FunctionSeries
/-!
# Smoothness of series
We show that series of functions are differentiable, or smooth, when each individual
function in the series is and additionally suitable uniform summable bounds are satisfied.
More specifically,
* `differentiable_tsum` ensures that a series of differentiable functions is differentiable.
* `contDiff_tsum` ensures that a series of `C^n` functions is `C^n`.
We also give versions of these statements which are localized to a set.
-/
open Set Metric TopologicalSpace Function Asymptotics Filter
open scoped Topology NNReal
variable {α β 𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜]
[NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ}
/-! ### Differentiability -/
variable [NormedSpace 𝕜 F]
variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ}
{s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞}
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series converges everywhere on the set. -/
theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s)
(h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀))
(hx : x ∈ s) : Summable fun n => f n x := by
haveI := Classical.decEq α
rw [summable_iff_cauchySeq_finset] at hf0 ⊢
have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s :=
(tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn
refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↦ ∑ i ∈ t, f i x)
hs h's A (fun t y hy => ?_) hx₀ hx hf0
exact HasFDerivAt.fun_sum fun i _ => hf i y hy
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series converges everywhere on the set. -/
theorem summable_of_summable_hasDerivAt_of_isPreconnected (hu : Summable u) (ht : IsOpen t)
(h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable (g · y₀))
(hy : y ∈ t) : Summable fun n => g n y := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg
refine summable_of_summable_hasFDerivAt_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy
simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series is differentiable on the set and its derivative is the sum of the
derivatives. -/
theorem hasFDerivAt_tsum_of_isPreconnected (hu : Summable u) (hs : IsOpen s)
(h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable fun n => f n x₀)
(hx : x ∈ s) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by
classical
have A :
∀ x : E, x ∈ s → Tendsto (fun t : Finset α => ∑ n ∈ t, f n x) atTop (𝓝 (∑' n, f n x)) := by
intro y hy
apply Summable.hasSum
exact summable_of_summable_hasFDerivAt_of_isPreconnected hu hs h's hf hf' hx₀ hf0 hy
refine hasFDerivAt_of_tendstoUniformlyOn hs (tendstoUniformlyOn_tsum hu hf')
(fun t y hy => ?_) A hx
exact HasFDerivAt.fun_sum fun n _ => hf n y hy
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series is differentiable on the set and its derivative is the sum of the
derivatives. -/
theorem hasDerivAt_tsum_of_isPreconnected (hu : Summable u) (ht : IsOpen t)
(h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable fun n => g n y₀)
(hy : y ∈ t) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg ⊢
convert hasFDerivAt_tsum_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy
· exact (ContinuousLinearMap.smulRightL 𝕜 𝕜 F 1).map_tsum <|
.of_norm_bounded hu fun n ↦ hg' n y hy
· simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series converges everywhere. -/
theorem summable_of_summable_hasFDerivAt (hu : Summable u)
(hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n)
(hf0 : Summable fun n => f n x₀) (x : E) : Summable fun n => f n x := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _
exact summable_of_summable_hasFDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series converges everywhere. -/
theorem summable_of_summable_hasDerivAt (hu : Summable u)
(hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n)
(hg0 : Summable fun n => g n y₀) (y : 𝕜) : Summable fun n => g n y := by
exact summable_of_summable_hasDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hg n x) (fun n x _ => hg' n x) (mem_univ _) hg0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series is differentiable and its derivative is the sum of the derivatives. -/
theorem hasFDerivAt_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) :
HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _
exact hasFDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series is differentiable and its derivative is the sum of the derivatives. -/
theorem hasDerivAt_tsum (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, ‖g' n y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) :
HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by
exact hasDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n y _ => hg n y) (fun n y _ => hg' n y) (mem_univ _) hg0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable
with a summable bound on the derivatives, then the series is differentiable.
Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise
convergence then the series is zero everywhere so the result still holds. -/
theorem differentiable_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, ‖f' n x‖ ≤ u n) : Differentiable 𝕜 fun y => ∑' n, f n y := by
by_cases h : ∃ x₀, Summable fun n => f n x₀
· rcases h with ⟨x₀, hf0⟩
intro x
exact (hasFDerivAt_tsum hu hf hf' hf0 x).differentiableAt
· push_neg at h
have : (fun x => ∑' n, f n x) = 0 := by ext1 x; exact tsum_eq_zero_of_not_summable (h x)
rw [this]
exact differentiable_const 0
/-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable
with a summable bound on the derivatives, then the series is differentiable.
Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise
convergence then the series is zero everywhere so the result still holds. -/
theorem differentiable_tsum' (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, ‖g' n y‖ ≤ u n) : Differentiable 𝕜 fun z => ∑' n, g n z := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg
refine differentiable_tsum hu hg ?_
simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
theorem fderiv_tsum_apply (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n))
(hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) :
fderiv 𝕜 (fun y => ∑' n, f n y) x = ∑' n, fderiv 𝕜 (f n) x :=
(hasFDerivAt_tsum hu (fun n x => (hf n x).hasFDerivAt) hf' hf0 _).fderiv
theorem deriv_tsum_apply (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n))
(hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) :
deriv (fun z => ∑' n, g n z) y = ∑' n, deriv (g n) y :=
(hasDerivAt_tsum hu (fun n y => (hg n y).hasDerivAt) hg' hg0 _).deriv
theorem fderiv_tsum (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n))
(hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) :
(fderiv 𝕜 fun y => ∑' n, f n y) = fun x => ∑' n, fderiv 𝕜 (f n) x := by
ext1 x
exact fderiv_tsum_apply hu hf hf' hf0 x
theorem deriv_tsum (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n))
(hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) :
(deriv fun y => ∑' n, g n y) = fun y => ∑' n, deriv (g n) y := by
ext1 x
exact deriv_tsum_apply hu hg hg' hg0 x
/-! ### Higher smoothness -/
/-- Consider a series of `C^n` functions, with summable uniform bounds on the successive
derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/
theorem iteratedFDeriv_tsum (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) {k : ℕ}
(hk : (k : ℕ∞) ≤ N) :
(iteratedFDeriv 𝕜 k fun y => ∑' n, f n y) = fun x => ∑' n, iteratedFDeriv 𝕜 k (f n) x := by
induction' k with k IH
· ext1 x
simp_rw [iteratedFDeriv_zero_eq_comp]
exact (continuousMultilinearCurryFin0 𝕜 E F).symm.toContinuousLinearEquiv.map_tsum
· have h'k : (k : ℕ∞) < N := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (Nat.lt_succ_self _)) hk
have A : Summable fun n => iteratedFDeriv 𝕜 k (f n) 0 :=
.of_norm_bounded (hv k h'k.le) fun n ↦ h'f k n 0 h'k.le
simp_rw [iteratedFDeriv_succ_eq_comp_left, IH h'k.le]
rw [fderiv_tsum (hv _ hk) (fun n => (hf n).differentiable_iteratedFDeriv
(mod_cast h'k)) _ A]
· ext1 x
exact (continuousMultilinearCurryLeftEquiv 𝕜
(fun _ : Fin (k + 1) => E) F).symm.toContinuousLinearEquiv.map_tsum
· intro n x
simpa only [iteratedFDeriv_succ_eq_comp_left, LinearIsometryEquiv.norm_map, comp_apply]
using h'f k.succ n x hk
/-- Consider a series of smooth functions, with summable uniform bounds on the successive
derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/
theorem iteratedFDeriv_tsum_apply (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) {k : ℕ}
(hk : (k : ℕ∞) ≤ N) (x : E) :
iteratedFDeriv 𝕜 k (fun y => ∑' n, f n y) x = ∑' n, iteratedFDeriv 𝕜 k (f n) x := by
rw [iteratedFDeriv_tsum hf hv h'f hk]
/-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of
class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative
for each `k ≤ N`. Then the series is also `C^N`. -/
theorem contDiff_tsum (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), k ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) :
ContDiff 𝕜 N fun x => ∑' i, f i x := by
rw [contDiff_iff_continuous_differentiable]
constructor
· intro m hm
rw [iteratedFDeriv_tsum hf hv h'f hm]
refine continuous_tsum ?_ (hv m hm) ?_
· intro i
exact ContDiff.continuous_iteratedFDeriv (mod_cast hm) (hf i)
· intro n x
exact h'f _ _ _ hm
· intro m hm
have h'm : ((m + 1 : ℕ) : ℕ∞) ≤ N := by
simpa only [ENat.coe_add, ENat.coe_one] using Order.add_one_le_of_lt hm
rw [iteratedFDeriv_tsum hf hv h'f hm.le]
have A n x : HasFDerivAt (iteratedFDeriv 𝕜 m (f n)) (fderiv 𝕜 (iteratedFDeriv 𝕜 m (f n)) x) x :=
(ContDiff.differentiable_iteratedFDeriv (mod_cast hm)
(hf n)).differentiableAt.hasFDerivAt
refine differentiable_tsum (hv _ h'm) A fun n x => ?_
rw [fderiv_iteratedFDeriv, comp_apply, LinearIsometryEquiv.norm_map]
exact h'f _ _ _ h'm
/-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of
class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative
for each `k ≤ N` (except maybe for finitely many `i`s). Then the series is also `C^N`. -/
theorem contDiff_tsum_of_eventually (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, k ≤ N → Summable (v k))
(h'f : ∀ k : ℕ, k ≤ N →
∀ᶠ i in (Filter.cofinite : Filter α), ∀ x : E, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) :
ContDiff 𝕜 N fun x => ∑' i, f i x := by
classical
refine contDiff_iff_forall_nat_le.2 fun m hm => ?_
let t : Set α :=
{ i : α | ¬∀ k : ℕ, k ∈ Finset.range (m + 1) → ∀ x, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i }
have ht : Set.Finite t :=
haveI A :
∀ᶠ i in (Filter.cofinite : Filter α),
∀ k : ℕ, k ∈ Finset.range (m + 1) → ∀ x : E, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i := by
rw [eventually_all_finset]
intro i hi
apply h'f
simp only [Finset.mem_range_succ_iff] at hi
exact (WithTop.coe_le_coe.2 hi).trans hm
eventually_cofinite.2 A
let T : Finset α := ht.toFinset
have : (fun x => ∑' i, f i x) = (fun x => ∑ i ∈ T, f i x) +
fun x => ∑' i : { i // i ∉ T }, f i x := by
ext1 x
refine (Summable.sum_add_tsum_subtype_compl ?_ T).symm
refine .of_norm_bounded_eventually (hv 0 (zero_le _)) ?_
filter_upwards [h'f 0 (zero_le _)] with i hi
simpa only [norm_iteratedFDeriv_zero] using hi x
rw [this]
apply (ContDiff.sum fun i _ => (hf i).of_le (mod_cast hm)).add
have h'u : ∀ k : ℕ, (k : ℕ∞) ≤ m → Summable (v k ∘ ((↑) : { i // i ∉ T } → α)) := fun k hk =>
(hv k (hk.trans hm)).subtype _
refine contDiff_tsum (fun i => (hf i).of_le (mod_cast hm)) h'u ?_
rintro k ⟨i, hi⟩ x hk
simp only [t, T, Finite.mem_toFinset, mem_setOf_eq, Finset.mem_range, not_forall, not_le,
exists_prop, not_exists, not_and, not_lt] at hi
exact hi k (Nat.lt_succ_iff.2 (WithTop.coe_le_coe.1 hk)) x
|
Rectangles.lean
|
/-
Copyright (c) 2024 Lean FRO. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
/-!
# Finding the maximal rectangles in a list of points.
-/
/--
A rectangle `r` is a product of the left-closed, right-open intervals
`[r.left, r.right) × [r.bottom, r.top)`, whose corners are indexed by natural numbers.
-/
structure Rectangle where
left : Nat
right : Nat
bottom : Nat
top : Nat
deriving DecidableEq, Repr
namespace Rectangle
def width (r : Rectangle) : Nat := r.right - r.left
def height (r : Rectangle) : Nat := r.top - r.bottom
def toString (r : Rectangle) : String :=
s!"[{r.left}, {r.right}) × [{r.bottom}, {r.top})"
instance : ToString Rectangle where
toString := toString
instance instPointMembership : Membership (Nat × Nat) Rectangle where
mem r x := r.left ≤ x.1 ∧ x.1 < r.right ∧ r.bottom ≤ x.2 ∧ x.2 < r.top
instance (x : Nat × Nat) (r : Rectangle) : Decidable (x ∈ r) := by
dsimp [Membership.mem]
infer_instance
/--
We say `r₁ ≤ r₂` if and only if every point in `r₁` is contained in `r₂`.
-/
instance instLE : LE Rectangle where
le r₁ r₂ := r₁.width = 0 ∨ r₁.height = 0 ∨ ((r₁.left, r₁.bottom) ∈ r₂ ∧ (r₁.right - 1, r₁.top - 1) ∈ r₂)
instance : DecidableLE Rectangle := by
dsimp [DecidableLE, LE.le, instLE]
infer_instance
instance : Membership Rectangle (List (Nat × Nat)) where
mem xs r := (List.range' r.left r.width).all fun x => (List.range' r.bottom r.height).all fun y => (x, y) ∈ xs
instance (r : Rectangle) (xs : List (Nat × Nat)) : Decidable (r ∈ xs) := by
dsimp [Membership.mem]
infer_instance
/--
Given a rectangle `r`, return the up to four four rectangles obtained from `r` by
- shifting the bottom left corner one coordinate to the left resp. bottom (if possible), or
- shifting the top right corner one coordinate to the right resp. top.
-/
def expansions (r : Rectangle) : List Rectangle :=
(if r.left = 0 then [] else [{ r with left := r.left - 1 }]) ++
(if r.bottom = 0 then [] else [{ r with bottom := r.bottom - 1 }]) ++
[{ r with right := r.right + 1 }, { r with top := r.top + 1 }]
def area (r : Rectangle) : Nat := r.width * r.height
/--
The number of points in `r`, weighted by the function `w`.
-/
def weightedArea (r : Rectangle) (w : Nat × Nat → Nat) : Nat :=
List.sum <|
(List.range' r.left r.width).flatMap
fun x => (List.range' r.bottom r.height).map fun y => w (x, y)
end Rectangle
/-- Find all (inclusion-)maximal rectangles contained within `xs`. -/
partial def maximalRectangles (xs : List (Nat × Nat)) : List Rectangle :=
go [] (xs.map fun (x, y) => Rectangle.mk x (x+1) y (y+1))
where
go (maximal : List Rectangle) (queue : List Rectangle) : List Rectangle :=
match queue with
| [] => maximal
| r :: rs =>
if maximal.any (r ≤ ·) then
go maximal rs
else
match r.expansions.filter (· ∈ xs) with
| [] => go (r :: maximal) rs
| rs' => go maximal (rs' ++ rs)
/--
info: [{ left := 2, right := 3, bottom := 0, top := 3 },
{ left := 0, right := 1, bottom := 0, top := 3 },
{ left := 0, right := 3, bottom := 0, top := 2 }]
-/
#guard_msgs in
#eval maximalRectangles [(0, 0), (1, 0), (0, 1), (1, 1), (2, 0), (0, 2), (2, 1), (2, 2)]
|
AdjMatrix.lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Lu-Ming Zhang
-/
import Mathlib.Combinatorics.SimpleGraph.Connectivity.WalkCounting
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.LinearAlgebra.Matrix.Trace
/-!
# Adjacency Matrices
This module defines the adjacency matrix of a graph, and provides theorems connecting graph
properties to computational properties of the matrix.
## Main definitions
* `Matrix.IsAdjMatrix`: `A : Matrix V V α` is qualified as an "adjacency matrix" if
(1) every entry of `A` is `0` or `1`,
(2) `A` is symmetric,
(3) every diagonal entry of `A` is `0`.
* `Matrix.IsAdjMatrix.to_graph`: for `A : Matrix V V α` and `h : A.IsAdjMatrix`,
`h.to_graph` is the simple graph induced by `A`.
* `Matrix.compl`: for `A : Matrix V V α`, `A.compl` is supposed to be
the adjacency matrix of the complement graph of the graph induced by `A`.
* `SimpleGraph.adjMatrix`: the adjacency matrix of a `SimpleGraph`.
* `SimpleGraph.adjMatrix_pow_apply_eq_card_walk`: each entry of the `n`th power of
a graph's adjacency matrix counts the number of length-`n` walks between the corresponding
pair of vertices.
-/
open Matrix
open Finset SimpleGraph
variable {V α : Type*}
namespace Matrix
/-- `A : Matrix V V α` is qualified as an "adjacency matrix" if
(1) every entry of `A` is `0` or `1`,
(2) `A` is symmetric,
(3) every diagonal entry of `A` is `0`. -/
structure IsAdjMatrix [Zero α] [One α] (A : Matrix V V α) : Prop where
zero_or_one : ∀ i j, A i j = 0 ∨ A i j = 1 := by aesop
symm : A.IsSymm := by aesop
apply_diag : ∀ i, A i i = 0 := by aesop
namespace IsAdjMatrix
variable {A : Matrix V V α}
@[simp]
theorem apply_diag_ne [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i : V) :
¬A i i = 1 := by simp [h.apply_diag i]
@[simp]
theorem apply_ne_one_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) :
¬A i j = 1 ↔ A i j = 0 := by obtain h | h := h.zero_or_one i j <;> simp [h]
@[simp]
theorem apply_ne_zero_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) :
¬A i j = 0 ↔ A i j = 1 := by rw [← apply_ne_one_iff h, Classical.not_not]
/-- For `A : Matrix V V α` and `h : IsAdjMatrix A`,
`h.toGraph` is the simple graph whose adjacency matrix is `A`. -/
@[simps]
def toGraph [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) : SimpleGraph V where
Adj i j := A i j = 1
symm i j hij := by simp only; rwa [h.symm.apply i j]
loopless i := by simp [h]
instance [MulZeroOneClass α] [Nontrivial α] [DecidableEq α] (h : IsAdjMatrix A) :
DecidableRel h.toGraph.Adj := by
simp only [toGraph]
infer_instance
end IsAdjMatrix
/-- For `A : Matrix V V α`, `A.compl` is supposed to be the adjacency matrix of
the complement graph of the graph induced by `A.adjMatrix`. -/
def compl [Zero α] [One α] [DecidableEq α] [DecidableEq V] (A : Matrix V V α) : Matrix V V α :=
fun i j => ite (i = j) 0 (ite (A i j = 0) 1 0)
section Compl
variable [DecidableEq α] [DecidableEq V] (A : Matrix V V α)
@[simp]
theorem compl_apply_diag [Zero α] [One α] (i : V) : A.compl i i = 0 := by simp [compl]
@[simp]
theorem compl_apply [Zero α] [One α] (i j : V) : A.compl i j = 0 ∨ A.compl i j = 1 := by
unfold compl
split_ifs <;> simp
@[simp]
theorem isSymm_compl [Zero α] [One α] (h : A.IsSymm) : A.compl.IsSymm := by
ext
simp [compl, h.apply, eq_comm]
@[simp]
theorem isAdjMatrix_compl [Zero α] [One α] (h : A.IsSymm) : IsAdjMatrix A.compl :=
{ symm := by simp [h] }
namespace IsAdjMatrix
variable {A}
@[simp]
theorem compl [Zero α] [One α] (h : IsAdjMatrix A) : IsAdjMatrix A.compl :=
isAdjMatrix_compl A h.symm
theorem toGraph_compl_eq [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) :
h.compl.toGraph = h.toGraphᶜ := by
ext v w
rcases h.zero_or_one v w with h | h <;> by_cases hvw : v = w <;> simp [Matrix.compl, h, hvw]
end IsAdjMatrix
end Compl
end Matrix
namespace SimpleGraph
variable (G : SimpleGraph V) [DecidableRel G.Adj]
variable (α) in
/-- `adjMatrix G α` is the matrix `A` such that `A i j = (1 : α)` if `i` and `j` are
adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/
def adjMatrix [Zero α] [One α] : Matrix V V α :=
of fun i j => if G.Adj i j then (1 : α) else 0
-- TODO: set as an equation lemma for `adjMatrix`, see https://github.com/leanprover-community/mathlib4/pull/3024
@[simp]
theorem adjMatrix_apply (v w : V) [Zero α] [One α] :
G.adjMatrix α v w = if G.Adj v w then 1 else 0 :=
rfl
@[simp]
theorem transpose_adjMatrix [Zero α] [One α] : (G.adjMatrix α)ᵀ = G.adjMatrix α := by
ext
simp [adj_comm]
@[simp]
theorem isSymm_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsSymm :=
transpose_adjMatrix G
variable (α)
/-- The adjacency matrix of `G` is an adjacency matrix. -/
@[simp]
theorem isAdjMatrix_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsAdjMatrix :=
{ zero_or_one := fun i j => by by_cases h : G.Adj i j <;> simp [h] }
/-- The graph induced by the adjacency matrix of `G` is `G` itself. -/
theorem toGraph_adjMatrix_eq [MulZeroOneClass α] [Nontrivial α] :
(G.isAdjMatrix_adjMatrix α).toGraph = G := by
ext
simp only [IsAdjMatrix.toGraph_adj, adjMatrix_apply, ite_eq_left_iff, zero_ne_one]
apply Classical.not_not
variable {α}
/-- The sum of the identity, the adjacency matrix, and its complement is the all-ones matrix. -/
theorem one_add_adjMatrix_add_compl_adjMatrix_eq_allOnes [DecidableEq V] [DecidableEq α]
[AddMonoidWithOne α] : 1 + G.adjMatrix α + (G.adjMatrix α).compl = Matrix.of fun _ _ ↦ 1 := by
ext i j
unfold Matrix.compl
rw [of_apply, add_apply, adjMatrix_apply, add_apply, adjMatrix_apply, one_apply]
by_cases h : G.Adj i j
· aesop
· split_ifs <;> simp_all
variable [Fintype V]
@[simp]
theorem adjMatrix_dotProduct [NonAssocSemiring α] (v : V) (vec : V → α) :
G.adjMatrix α v ⬝ᵥ vec = ∑ u ∈ G.neighborFinset v, vec u := by
simp [neighborFinset_eq_filter, dotProduct, sum_filter]
@[simp]
theorem dotProduct_adjMatrix [NonAssocSemiring α] (v : V) (vec : V → α) :
vec ⬝ᵥ G.adjMatrix α v = ∑ u ∈ G.neighborFinset v, vec u := by
simp [neighborFinset_eq_filter, dotProduct, sum_filter]
@[simp]
theorem adjMatrix_mulVec_apply [NonAssocSemiring α] (v : V) (vec : V → α) :
(G.adjMatrix α *ᵥ vec) v = ∑ u ∈ G.neighborFinset v, vec u := by
rw [mulVec, adjMatrix_dotProduct]
@[simp]
theorem adjMatrix_vecMul_apply [NonAssocSemiring α] (v : V) (vec : V → α) :
(vec ᵥ* G.adjMatrix α) v = ∑ u ∈ G.neighborFinset v, vec u := by
simp only [← dotProduct_adjMatrix, vecMul]
refine congr rfl ?_; ext x
rw [← transpose_apply (adjMatrix α G) x v, transpose_adjMatrix]
@[simp]
theorem adjMatrix_mul_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) :
(G.adjMatrix α * M) v w = ∑ u ∈ G.neighborFinset v, M u w := by
simp [mul_apply, neighborFinset_eq_filter, sum_filter]
@[simp]
theorem mul_adjMatrix_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) :
(M * G.adjMatrix α) v w = ∑ u ∈ G.neighborFinset w, M v u := by
simp [mul_apply, neighborFinset_eq_filter, sum_filter, adj_comm]
variable (α) in
@[simp]
theorem trace_adjMatrix [AddCommMonoid α] [One α] : Matrix.trace (G.adjMatrix α) = 0 := by
simp [Matrix.trace]
theorem adjMatrix_mul_self_apply_self [NonAssocSemiring α] (i : V) :
(G.adjMatrix α * G.adjMatrix α) i i = degree G i := by simp [filter_true_of_mem]
variable {G}
theorem adjMatrix_mulVec_const_apply [NonAssocSemiring α] {a : α} {v : V} :
(G.adjMatrix α *ᵥ Function.const _ a) v = G.degree v * a := by simp
theorem adjMatrix_mulVec_const_apply_of_regular [NonAssocSemiring α] {d : ℕ} {a : α}
(hd : G.IsRegularOfDegree d) {v : V} : (G.adjMatrix α *ᵥ Function.const _ a) v = d * a := by
simp [hd v]
theorem adjMatrix_pow_apply_eq_card_walk [DecidableEq V] [Semiring α] (n : ℕ) (u v : V) :
(G.adjMatrix α ^ n) u v = Fintype.card { p : G.Walk u v | p.length = n } := by
rw [card_set_walk_length_eq]
induction n generalizing u v with
| zero => obtain rfl | h := eq_or_ne u v <;> simp [finsetWalkLength, *]
| succ n ih =>
simp only [pow_succ', finsetWalkLength, ih, adjMatrix_mul_apply]
rw [Finset.card_biUnion]
· norm_cast
simp only [Nat.cast_sum, card_map, neighborFinset_def]
apply Finset.sum_toFinset_eq_subtype
-- Disjointness for card_bUnion
· rintro ⟨x, hx⟩ - ⟨y, hy⟩ - hxy
rw [Function.onFun, disjoint_iff_inf_le]
intro p hp
simp only [inf_eq_inter, mem_inter, mem_map, Function.Embedding.coeFn_mk] at hp
obtain ⟨⟨px, _, rfl⟩, ⟨py, hpy, hp⟩⟩ := hp
cases hp
simp at hxy
theorem dotProduct_mulVec_adjMatrix [NonAssocSemiring α] (x y : V → α) :
x ⬝ᵥ G.adjMatrix α *ᵥ y = ∑ i : V, ∑ j : V, if G.Adj i j then x i * y j else 0 := by
simp only [dotProduct, mulVec, adjMatrix_apply, ite_mul, one_mul, zero_mul, mul_sum, mul_ite,
mul_zero]
end SimpleGraph
namespace Matrix.IsAdjMatrix
variable [MulZeroOneClass α] [Nontrivial α]
variable {A : Matrix V V α} (h : IsAdjMatrix A)
/-- If `A` is qualified as an adjacency matrix,
then the adjacency matrix of the graph induced by `A` is itself. -/
theorem adjMatrix_toGraph_eq [DecidableEq α] : h.toGraph.adjMatrix α = A := by
ext i j
obtain h' | h' := h.zero_or_one i j <;> simp [h']
end Matrix.IsAdjMatrix
|
binomial.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path.
From mathcomp Require Import div fintype tuple finfun bigop prime finset.
(******************************************************************************)
(* This files contains the definition of: *)
(* 'C(n, m) == the binomial coefficient n choose m. *)
(* n ^_ m == the falling (or lower) factorial of n with m terms, i.e., *)
(* the product n * (n - 1) * ... * (n - m + 1). *)
(* Note that n ^_ m = 0 if m > n, and 'C(n, m) = n ^_ m %/ m`!. *)
(* *)
(* In additions to the properties of these functions, we prove a few seminal *)
(* results such as bin2_sum, Wilson and expnDn; their proofs are good *)
(* examples of how to manipulate expressions with bigops. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(** More properties of the factorial **)
Lemma fact_prod n : n`! = \prod_(1 <= i < n.+1) i.
Proof.
elim: n => [|n IHn] //; first by rewrite big_nil.
by apply/esym; rewrite factS IHn // !big_add1 big_nat_recr //= mulnC.
Qed.
Lemma fact_split n m : m <= n -> n`! = m`! * \prod_(m.+1 <= k < n.+1) k.
Proof. by move=> leq_mn; rewrite !fact_prod -big_cat_nat. Qed.
Lemma logn_fact p n : prime p -> logn p n`! = \sum_(1 <= k < n.+1) n %/ p ^ k.
Proof.
move=> p_prime; transitivity (\sum_(1 <= i < n.+1) logn p i).
rewrite big_add1; elim: n => /= [|n IHn]; first by rewrite logn1 big_geq.
by rewrite big_nat_recr // -IHn /= factS mulnC lognM ?fact_gt0.
transitivity (\sum_(1 <= i < n.+1) \sum_(1 <= k < n.+1) (p ^ k %| i)).
apply: eq_big_nat => i /andP[i_gt0 le_i_n]; rewrite logn_count_dvd //.
rewrite -!big_mkcond (big_nat_widen _ _ n.+1) 1?ltnW //; apply: eq_bigl => k.
by apply: andb_idr => /dvdn_leq/(leq_trans (ltn_expl _ (prime_gt1 _)))->.
by rewrite exchange_big_nat; apply: eq_bigr => i _; rewrite divn_count_dvd.
Qed.
Theorem Wilson p : p > 1 -> prime p = (p %| ((p.-1)`!).+1).
Proof.
have dFact n: 0 < n -> (n.-1)`! = \prod_(0 <= i < n | i != 0) i.
move=> n_gt0; rewrite -big_filter fact_prod; symmetry; apply: congr_big => //.
rewrite /index_iota subn1 -[n]prednK //=; apply/all_filterP.
by rewrite all_predC has_pred1 mem_iota.
move=> lt1p; have p_gt0 := ltnW lt1p.
apply/idP/idP=> [pr_p | dv_pF]; last first.
apply/primeP; split=> // d dv_dp; have: d <= p by apply: dvdn_leq.
rewrite orbC leq_eqVlt => /orP[-> // | ltdp].
have:= dvdn_trans dv_dp dv_pF; rewrite dFact // big_mkord.
rewrite (bigD1 (Ordinal ltdp)) /=; last by rewrite -lt0n (dvdn_gt0 p_gt0).
by rewrite orbC -addn1 dvdn_addr ?dvdn_mulr // dvdn1 => ->.
pose Fp1 := Ordinal lt1p; pose Fp0 := Ordinal p_gt0.
have ltp1p: p.-1 < p by [rewrite prednK]; pose Fpn1 := Ordinal ltp1p.
case eqF1n1: (Fp1 == Fpn1); first by rewrite -{1}[p]prednK -1?((1 =P p.-1) _).
have toFpP m: m %% p < p by rewrite ltn_mod.
pose toFp := Ordinal (toFpP _); pose mFp (i j : 'I_p) := toFp (i * j).
have Fp_mod (i : 'I_p) : i %% p = i by apply: modn_small.
have mFpA: associative mFp.
by move=> i j k; apply: val_inj; rewrite /= modnMml modnMmr mulnA.
have mFpC: commutative mFp by move=> i j; apply: val_inj; rewrite /= mulnC.
have mFp1: left_id Fp1 mFp by move=> i; apply: val_inj; rewrite /= mul1n.
have mFp1r: right_id Fp1 mFp by move=> i; apply: val_inj; rewrite /= muln1.
pose mFpcM := Monoid.isComLaw.Build 'I_p Fp1 mFp mFpA mFpC mFp1.
pose mFpCL : Monoid.com_law _ := HB.pack mFp mFpcM.
pose mFpM := Monoid.Law.sort mFpCL.
pose vFp (i : 'I_p) := toFp (egcdn i p).1.
have vFpV i: i != Fp0 -> mFp (vFp i) i = Fp1.
rewrite -val_eqE /= -lt0n => i_gt0; apply: val_inj => /=.
rewrite modnMml; case: egcdnP => //= _ km -> _; rewrite {km}modnMDl.
suffices: coprime i p by move/eqnP->; rewrite modn_small.
rewrite coprime_sym prime_coprime //; apply/negP=> /(dvdn_leq i_gt0).
by rewrite leqNgt ltn_ord.
have vFp0 i: i != Fp0 -> vFp i != Fp0.
by move/vFpV; apply/contra_eq_neq => ->; rewrite -val_eqE /= mul0n mod0n.
have vFpK: {in predC1 Fp0, involutive vFp}.
move=> i n0i; rewrite /= -[vFp _]mFp1r -(vFpV _ n0i) mFpA.
by rewrite vFpV (vFp0, mFp1).
have le_pmFp (i : 'I_p) m: i <= p + m.
by apply: leq_trans (ltnW _) (leq_addr _ _).
have eqFp (i j : 'I_p): (i == j) = (p %| p + i - j).
by rewrite -eqn_mod_dvd ?(modnDl, Fp_mod).
have vFpId i: (vFp i == i :> nat) = xpred2 Fp1 Fpn1 i.
have [->{i} | ni0] := eqVneq i Fp0.
by rewrite -!val_eqE /= egcd0n modn_small //= -(subnKC lt1p).
rewrite 2![i == _]eqFp -Euclid_dvdM // -[_ - p.-1]subSS prednK //.
have lt0i: 0 < i by rewrite lt0n.
rewrite -addnS addKn -addnBA // mulnDl -{2}(addn1 i) -subn_sqr.
rewrite addnBA ?leq_sqr // mulnS -addnA -mulnn -mulnDl.
rewrite -(subnK (le_pmFp (vFp i) i)) mulnDl addnCA.
rewrite -[1 ^ 2]/(Fp1 : nat) -addnBA // dvdn_addl.
by rewrite Euclid_dvdM // -eqFp eq_sym orbC /dvdn Fp_mod eqn0Ngt lt0i.
by rewrite -eqn_mod_dvd // Fp_mod modnDl -(vFpV _ ni0).
suffices [mod_fact]: toFp (p.-1)`! = Fpn1.
by rewrite /dvdn -addn1 -modnDml mod_fact addn1 prednK // modnn.
rewrite dFact //; rewrite ((big_morph toFp) Fp1 mFpM) //; first last.
- by apply: val_inj; rewrite /= modn_small.
- by move=> i j; apply: val_inj; rewrite /= modnMm.
rewrite big_mkord (eq_bigr id) => [|i _]; last by apply: val_inj => /=.
pose ltv i := vFp i < i; rewrite (bigID ltv) -/mFpM [mFpM _ _]mFpC.
rewrite (bigD1 Fp1) -/mFpM; last by rewrite [ltv _]ltn_neqAle vFpId.
rewrite [mFpM _ _]mFp1 (bigD1 Fpn1) -?mFpA -/mFpM; last first.
rewrite -lt0n -ltnS prednK // lt1p.
by rewrite [ltv _]ltn_neqAle vFpId eqxx orbT eq_sym eqF1n1.
rewrite (reindex_onto vFp vFp) -/mFpM => [|i]; last by do 3!case/andP; auto.
rewrite (eq_bigl (xpredD1 ltv Fp0)) => [|i]; last first.
rewrite andbC -!andbA -2!negb_or -vFpId orbC -leq_eqVlt -ltnNge.
have [->|ni0] := eqVneq i; last by rewrite vFpK // eqxx vFp0.
by case: eqP => // ->; rewrite !andbF.
rewrite -{2}[mFp]/mFpM -[mFpM _ _]big_split -/mFpM.
by rewrite big1 ?mFp1r //= => i /andP [/vFpV].
Qed.
(** The falling factorial *)
Fixpoint ffact_rec n m := if m is m'.+1 then n * ffact_rec n.-1 m' else 1.
Definition falling_factorial := ffact_rec.
Arguments falling_factorial : simpl never.
Notation "n ^_ m" := (falling_factorial n m)
(at level 30, right associativity) : nat_scope.
Lemma ffactE : falling_factorial = ffact_rec. Proof. by []. Qed.
Lemma ffactn0 n : n ^_ 0 = 1. Proof. by []. Qed.
Lemma ffact0n m : 0 ^_ m = (m == 0). Proof. by case: m. Qed.
Lemma ffactnS n m : n ^_ m.+1 = n * n.-1 ^_ m. Proof. by []. Qed.
Lemma ffactSS n m : n.+1 ^_ m.+1 = n.+1 * n ^_ m. Proof. by []. Qed.
Lemma ffactn1 n : n ^_ 1 = n. Proof. exact: muln1. Qed.
Lemma ffactnSr n m : n ^_ m.+1 = n ^_ m * (n - m).
Proof.
elim: n m => [|n IHn] [|m] //=; first by rewrite ffactn1 mul1n.
by rewrite !ffactSS IHn mulnA.
Qed.
Lemma ffact_prod n m : n ^_ m = \prod_(i < m) (n - i).
Proof.
elim: m n => [n | m IH [|n] //]; first by rewrite ffactn0 big_ord0.
by rewrite big_ord_recr /= sub0n muln0.
by rewrite ffactSS IH big_ord_recl subn0.
Qed.
Lemma ffact_gt0 n m : (0 < n ^_ m) = (m <= n).
Proof. by elim: n m => [|n IHn] [|m] //=; rewrite ffactSS muln_gt0 IHn. Qed.
Lemma ffact_small n m : n < m -> n ^_ m = 0.
Proof. by rewrite ltnNge -ffact_gt0; case: posnP. Qed.
Lemma ffactnn n : n ^_ n = n`!.
Proof. by elim: n => [|n IHn] //; rewrite ffactnS IHn. Qed.
Lemma ffact_fact n m : m <= n -> n ^_ m * (n - m)`! = n`!.
Proof.
by elim: n m => [|n IHn] [|m] //= le_m_n; rewrite ?mul1n // -mulnA IHn.
Qed.
Lemma ffact_factd n m : m <= n -> n ^_ m = n`! %/ (n - m)`!.
Proof. by move/ffact_fact <-; rewrite mulnK ?fact_gt0. Qed.
(** Binomial coefficients *)
Fixpoint binomial n m :=
match n, m with
| n'.+1, m'.+1 => binomial n' m + binomial n' m'
| _, 0 => 1
| 0, _.+1 => 0
end.
Arguments binomial : simpl never.
Notation "''C' ( n , m )" := (binomial n m) : nat_scope.
Lemma binE n m : binomial n m =
match n, m with
| n'.+1, m'.+1 => binomial n' m + binomial n' m'
| _, 0 => 1
| 0, _.+1 => 0
end.
Proof. by case: n. Qed.
Lemma bin0 n : 'C(n, 0) = 1. Proof. by case: n. Qed.
Lemma bin0n m : 'C(0, m) = (m == 0). Proof. by case: m. Qed.
Lemma binS n m : 'C(n.+1, m.+1) = 'C(n, m.+1) + 'C(n, m). Proof. by []. Qed.
Lemma bin1 n : 'C(n, 1) = n.
Proof. by elim: n => //= n IHn; rewrite binS bin0 IHn addn1. Qed.
Lemma bin_gt0 n m : (0 < 'C(n, m)) = (m <= n).
Proof.
by elim: n m => [|n IHn] [|m] //; rewrite addn_gt0 !IHn orbC ltn_neqAle andKb.
Qed.
Lemma leq_bin2l n1 n2 m : n1 <= n2 -> 'C(n1, m) <= 'C(n2, m).
Proof.
by elim: n1 n2 m => [|n1 IHn] [|n2] [|n] le_n12 //; rewrite leq_add ?IHn.
Qed.
Lemma bin_small n m : n < m -> 'C(n, m) = 0.
Proof. by rewrite ltnNge -bin_gt0; case: posnP. Qed.
Lemma binn n : 'C(n, n) = 1.
Proof. by elim: n => [|n IHn] //; rewrite binS bin_small. Qed.
(* Multiply to move diagonally down and right in the Pascal triangle. *)
Lemma mul_bin_diag n m : n * 'C(n.-1, m) = m.+1 * 'C(n, m.+1).
Proof.
rewrite [RHS]mulnC; elim: n m => [|[|n] IHn] [|m] //=; first by rewrite bin1.
by rewrite mulSn [in _ * _]binS mulnDr addnCA !IHn -mulnS -mulnDl -binS.
Qed.
Lemma bin_fact n m : m <= n -> 'C(n, m) * (m`! * (n - m)`!) = n`!.
Proof.
elim: n m => [|n IHn] [|m] // le_m_n; first by rewrite bin0 !mul1n.
by rewrite !factS -!mulnA mulnCA mulnA -mul_bin_diag -mulnA IHn.
Qed.
(* In fact the only exception for bin_factd is n = 0 and m = 1 *)
Lemma bin_factd n m : 0 < n -> 'C(n, m) = n`! %/ (m`! * (n - m)`!).
Proof.
have [/bin_fact<-|*] := leqP m n; first by rewrite mulnK ?muln_gt0 ?fact_gt0.
by rewrite divnMA bin_small ?divn_small ?fact_gt0 ?ltn_fact.
Qed.
Lemma bin_ffact n m : 'C(n, m) * m`! = n ^_ m.
Proof.
have [lt_n_m | le_m_n] := ltnP n m; first by rewrite bin_small ?ffact_small.
by rewrite ffact_factd // -(bin_fact le_m_n) mulnA mulnK ?fact_gt0.
Qed.
Lemma bin_ffactd n m : 'C(n, m) = n ^_ m %/ m`!.
Proof. by rewrite -bin_ffact mulnK ?fact_gt0. Qed.
Lemma bin_sub n m : m <= n -> 'C(n, n - m) = 'C(n, m).
Proof.
by move=> le_m_n; rewrite !bin_ffactd !ffact_factd ?leq_subr // divnAC subKn.
Qed.
(* Multiply to move down in the Pascal triangle. *)
Lemma mul_bin_down n m : n * 'C(n.-1, m) = (n - m) * 'C(n, m).
Proof.
case: n => //= n; have [lt_n_m | le_m_n] := ltnP n m.
by rewrite (eqnP lt_n_m) mulnC bin_small.
by rewrite -!['C(_, m)]bin_sub ?leqW ?subSn ?mul_bin_diag.
Qed.
(* Multiply to move left in the Pascal triangle. *)
Lemma mul_bin_left n m : m.+1 * 'C(n, m.+1) = (n - m) * 'C(n, m).
Proof. by rewrite -mul_bin_diag mul_bin_down. Qed.
Lemma binSn n : 'C(n.+1, n) = n.+1.
Proof. by rewrite -bin_sub ?leqnSn // subSnn bin1. Qed.
Lemma bin2 n : 'C(n, 2) = (n * n.-1)./2.
Proof. by rewrite -[n.-1]bin1 mul_bin_diag -divn2 mulKn. Qed.
Lemma bin2odd n : odd n -> 'C(n, 2) = n * n.-1./2.
Proof. by case: n => // n oddn; rewrite bin2 -!divn2 muln_divA ?dvdn2. Qed.
Lemma prime_dvd_bin k p : prime p -> 0 < k < p -> p %| 'C(p, k).
Proof.
move=> p_pr /andP[k_gt0 lt_k_p].
suffices /Gauss_dvdr<-: coprime p (p - k) by rewrite -mul_bin_down dvdn_mulr.
by rewrite prime_coprime // dvdn_subr 1?ltnW // gtnNdvd.
Qed.
Lemma bin2_sum n : \sum_(0 <= i < n) i = 'C(n, 2).
Proof.
elim: n => [|n IHn]; first by rewrite big_geq.
by rewrite big_nat_recr // IHn binS bin1.
Qed.
#[deprecated(since="mathcomp 2.3.0", note="Use bin2_sum instead.")]
Notation triangular_sum := bin2_sum (only parsing).
(* textbook proof of `bin2_sum`. Should be moved out of the main
library, to a dedicated "showcase" library.
Lemma textbook_triangular_sum n : \sum_(0 <= i < n) i = 'C(n, 2).
Proof.
rewrite bin2; apply: canRL half_double _.
rewrite -addnn {1}big_nat_rev -big_split big_mkord /= ?add0n.
rewrite (eq_bigr (fun _ => n.-1)); first by rewrite sum_nat_const card_ord.
by case: n => [|n] [i le_i_n] //=; rewrite subSS subnK.
Qed. *)
Theorem expnDn a b n :
(a + b) ^ n = \sum_(i < n.+1) 'C(n, i) * (a ^ (n - i) * b ^ i).
Proof.
elim: n => [|n IHn]; rewrite big_ord_recl muln1 ?big_ord0 //.
rewrite expnS {}IHn /= mulnDl !big_distrr /= big_ord_recl muln1 subn0.
rewrite !big_ord_recr /= !binn !subnn bin0 !subn0 !mul1n -!expnS -addnA.
congr (_ + _); rewrite addnA -big_split /=; congr (_ + _).
apply: eq_bigr => i _; rewrite mulnCA (mulnA a) -expnS subnSK //=.
by rewrite (mulnC b) -2!mulnA -expnSr -mulnDl.
Qed.
#[deprecated(since="mathcomp 2.3.0", note="Use expnDn instead.")]
Definition Pascal := expnDn.
Lemma Vandermonde k l i :
\sum_(j < i.+1) 'C(k, j) * 'C(l, i - j) = 'C(k + l , i).
Proof.
pose f k i := \sum_(j < i.+1) 'C(k, j) * 'C(l, i - j).
suffices{k i} fxx k i: f k.+1 i.+1 = f k i.+1 + f k i.
elim: k i => [i | k IHk [|i]]; last by rewrite -/(f _ _) fxx /f !IHk -binS.
by rewrite big_ord_recl big1_eq addn0 mul1n subn0.
by rewrite big_ord_recl big_ord0 addn0 !bin0 muln1.
rewrite {}/f big_ord_recl (big_ord_recl (i.+1)) !bin0 !mul1n.
rewrite -addnA -big_split /=; congr (_ + _).
by apply: eq_bigr => j _; rewrite -mulnDl.
Qed.
Lemma subn_exp m n k :
m ^ k - n ^ k = (m - n) * (\sum_(i < k) m ^ (k.-1 -i) * n ^ i).
Proof.
case: k => [|k]; first by rewrite big_ord0 muln0.
rewrite mulnBl !big_distrr big_ord_recl big_ord_recr /= subn0 muln1.
rewrite subnn mul1n -!expnS subnDA; congr (_ - _); apply: canRL (addnK _) _.
congr (_ + _); apply: eq_bigr => i _.
by rewrite (mulnCA n) -expnS mulnA -expnS subnSK /=.
Qed.
Lemma predn_exp m k : (m ^ k).-1 = m.-1 * (\sum_(i < k) m ^ i).
Proof.
rewrite -!subn1 -[in LHS](exp1n k) subn_exp; congr (_ * _).
symmetry; rewrite (reindex_inj rev_ord_inj); apply: eq_bigr => i _ /=.
by rewrite -subn1 -subnDA exp1n muln1.
Qed.
Lemma dvdn_pred_predX n e : (n.-1 %| (n ^ e).-1)%N.
Proof. by rewrite predn_exp dvdn_mulr. Qed.
Lemma modn_summ I r (P : pred I) F d :
\sum_(i <- r | P i) F i %% d = \sum_(i <- r | P i) F i %[mod d].
Proof.
by apply/eqP; elim/big_rec2: _ => // i m n _; rewrite modnDml eqn_modDl.
Qed.
Lemma prime_modn_expSn p n : prime p -> n.+1 ^ p = (n ^ p).+1 %[mod p].
Proof.
case: p => // p pP.
rewrite -[(_ ^ _).+1]addn0 (expnDn 1) big_ord_recr big_ord_recl /=.
rewrite subnn binn exp1n !mul1n addnAC -modnDmr; congr ((_ + _) %% _).
apply/eqP/dvdn_sum => -[i ?] _; exact/dvdn_mulr/prime_dvd_bin.
Qed.
Lemma fermat_little a p : prime p -> a ^ p = a %[mod p].
Proof.
move=> pP.
elim: a => [|a IH]; first by rewrite exp0n // prime_gt0.
by rewrite prime_modn_expSn // -addn1 -modnDml IH modnDml addn1.
Qed.
(* Combinatorial characterizations. *)
Section Combinations.
Implicit Types T D : finType.
Lemma card_uniq_tuples T n (A : pred T) :
#|[set t : n.-tuple T | all A t & uniq t]| = #|A| ^_ n.
Proof.
elim: n A => [|n IHn] A.
by rewrite (@eq_card1 _ [tuple]) // => t; rewrite [t]tuple0 inE.
rewrite -sum1dep_card (partition_big (@thead _ _) A) /= => [|t]; last first.
by case/tupleP: t => x t; do 2!case/andP.
rewrite ffactnS -sum_nat_const; apply: eq_bigr => x Ax.
rewrite (cardD1 x) [x \in A]Ax /= -(IHn [predD1 A & x]) -sum1dep_card.
rewrite (reindex (fun t : n.-tuple T => [tuple of x :: t])) /=; last first.
pose ttail (t : n.+1.-tuple T) := [tuple of behead t].
exists ttail => [t _ | t /andP[_ /eqP <-]]; first exact: val_inj.
by rewrite -tuple_eta.
apply: eq_bigl=> t; rewrite Ax theadE eqxx andbT /= andbA; congr (_ && _).
by rewrite all_predI all_predC has_pred1 andbC.
Qed.
Lemma card_inj_ffuns_on D T (R : pred T) :
#|[set f : {ffun D -> T} in ffun_on R | injectiveb f]| = #|R| ^_ #|D|.
Proof.
rewrite -card_uniq_tuples.
have bijFF: {on (_ : pred _), bijective (@Finfun D T)}.
by exists fgraph => x _; [apply: FinfunK | apply: fgraphK].
rewrite -(on_card_preimset (bijFF _)); apply: eq_card => /= t.
rewrite !inE -(big_andE predT) -big_image /= big_all.
by rewrite -[t in RHS]FinfunK -codom_ffun.
Qed.
Lemma card_inj_ffuns D T :
#|[set f : {ffun D -> T} | injectiveb f]| = #|T| ^_ #|D|.
Proof.
rewrite -card_inj_ffuns_on; apply: eq_card => f.
by rewrite 2!inE; case: ffun_onP.
Qed.
Lemma cards_draws T (B : {set T}) k :
#|[set A : {set T} | A \subset B & #|A| == k]| = 'C(#|B|, k).
Proof.
have [ltTk | lekT] := ltnP #|B| k.
rewrite bin_small // eq_card0 // => A.
rewrite inE eqn_leq [k <= _]leqNgt.
have [AsubB /=|//] := boolP (A \subset B).
by rewrite (leq_ltn_trans (subset_leq_card AsubB)) ?andbF.
apply/eqP; rewrite -(eqn_pmul2r (fact_gt0 k)) bin_ffact // eq_sym.
rewrite -sum_nat_cond_const -{1 3}(card_ord k).
rewrite -card_inj_ffuns_on -sum1dep_card.
pose imIk (f : {ffun 'I_k -> T}) := f @: 'I_k.
rewrite (partition_big imIk (fun A => (A \subset B) && (#|A| == k))) /=
=> [|f]; last first.
move=> /andP [/ffun_onP f_ffun /injectiveP inj_f].
rewrite card_imset ?card_ord // eqxx andbT.
by apply/subsetP => x /imsetP [i _ ->]; rewrite f_ffun.
apply/eqP; apply: eq_bigr => A /andP [AsubB /eqP cardAk].
have [f0 inj_f0 im_f0]: exists2 f, injective f & f @: 'I_k = A.
rewrite -cardAk; exists enum_val; first exact: enum_val_inj.
apply/setP=> a; apply/imsetP/idP=> [[i _ ->] | Aa]; first exact: enum_valP.
by exists (enum_rank_in Aa a); rewrite ?enum_rankK_in.
rewrite (reindex (fun p : {ffun _} => [ffun i => f0 (p i)])) /=; last first.
pose ff0' f i := odflt i [pick j | f i == f0 j].
exists (fun f => [ffun i => ff0' f i]) => [p _ | f].
apply/ffunP=> i; rewrite ffunE /ff0'; case: pickP => [j | /(_ (p i))].
by rewrite ffunE (inj_eq inj_f0) => /eqP.
by rewrite ffunE eqxx.
rewrite -im_f0 => /andP[/andP[/ffun_onP f_ffun /injectiveP injf] /eqP im_f].
apply/ffunP=> i; rewrite !ffunE /ff0'; case: pickP => [y /eqP //|].
have /imsetP[j _ eq_f0j_fi]: f i \in f0 @: 'I_k by rewrite -im_f imset_f.
by move/(_ j)/eqP.
rewrite -ffactnn -card_inj_ffuns -sum1dep_card; apply: eq_bigl => p.
rewrite -andbA.
apply/and3P/injectiveP=> [[_ /injectiveP inj_f0p _] i j eq_pij | inj_p].
by apply: inj_f0p; rewrite !ffunE eq_pij.
set f := finfun _.
have injf: injective f by move=> i j /[!ffunE] /inj_f0; apply: inj_p.
have imIkf : imIk f == A.
rewrite eqEcard card_imset // cardAk card_ord leqnn andbT -im_f0.
by apply/subsetP=> x /imsetP[i _ ->]; rewrite ffunE imset_f.
split; [|exact/injectiveP|exact: imIkf].
by apply/ffun_onP => x; apply: (subsetP AsubB); rewrite -(eqP imIkf) imset_f.
Qed.
Lemma card_draws T k : #|[set A : {set T} | #|A| == k]| = 'C(#|T|, k).
Proof.
by rewrite -cardsT -cards_draws; apply: eq_card => A; rewrite !inE subsetT.
Qed.
Lemma card_ltn_sorted_tuples m n :
#|[set t : m.-tuple 'I_n | sorted ltn (map val t)]| = 'C(n, m).
Proof.
have [-> | n_gt0] := posnP n; last pose i0 := Ordinal n_gt0.
case: m => [|m]; last by apply: eq_card0; case/tupleP=> [[]].
by apply: (@eq_card1 _ [tuple]) => t; rewrite [t]tuple0 inE.
rewrite -[n in RHS]card_ord -card_draws.
pose f_t (t : m.-tuple 'I_n) := [set i in t].
pose f_A (A : {set 'I_n}) := [tuple of mkseq (nth i0 (enum A)) m].
have val_fA (A : {set 'I_n}) : #|A| = m -> val (f_A A) = enum A.
by move=> Am; rewrite -[enum _](mkseq_nth i0) -cardE Am.
have inc_A (A : {set 'I_n}) : sorted ltn (map val (enum A)).
rewrite -[enum _](eq_filter (mem_enum _)).
rewrite -(eq_filter (mem_map val_inj _)) -filter_map.
by rewrite (sorted_filter ltn_trans) // unlock val_ord_enum iota_ltn_sorted.
rewrite -!sum1dep_card (reindex_onto f_t f_A) /= => [|A]; last first.
by move/eqP=> cardAm; apply/setP=> x; rewrite inE -(mem_enum A) -val_fA.
apply: eq_bigl => t.
apply/idP/idP => [inc_t|/andP [/eqP t_m /eqP <-]]; last by rewrite val_fA.
have ft_m: #|f_t t| = m.
rewrite cardsE (card_uniqP _) ?size_tuple // -(map_inj_uniq val_inj).
exact: (sorted_uniq ltn_trans ltnn).
rewrite ft_m eqxx -val_eqE val_fA // -(inj_eq (inj_map val_inj)) /=.
apply/eqP/(irr_sorted_eq ltn_trans ltnn) => // y.
by apply/mapP/mapP=> [] [x t_x ->]; exists x; rewrite // mem_enum inE in t_x *.
Qed.
Lemma card_sorted_tuples m n :
#|[set t : m.-tuple 'I_n.+1 | sorted leq (map val t)]| = 'C(m + n, m).
Proof.
set In1 := 'I_n.+1; pose x0 : In1 := ord0.
have add_mnP (i : 'I_m) (x : In1) : i + x < m + n.
by rewrite -ltnS -addSn -!addnS leq_add.
pose add_mn t i := Ordinal (add_mnP i (tnth t i)).
pose add_mn_nat (t : m.-tuple In1) i := i + nth x0 t i.
have add_mnC t: val \o add_mn t =1 add_mn_nat t \o val.
by move=> i; rewrite /= (tnth_nth x0).
pose f_add t := [tuple of map (add_mn t) (ord_tuple m)].
rewrite -card_ltn_sorted_tuples -!sum1dep_card (reindex f_add) /=.
apply: eq_bigl => t; rewrite -map_comp (eq_map (add_mnC t)) map_comp.
rewrite enumT unlock val_ord_enum -[in LHS](drop0 t).
have [m0 | m_gt0] := posnP m.
by rewrite {2}m0 /= drop_oversize // size_tuple m0.
have def_m := subnK m_gt0; rewrite -{2}def_m addn1 /= {1}/add_mn_nat.
move: 0 (m - 1) def_m => i k; rewrite -[in RHS](size_tuple t) => def_m.
rewrite (drop_nth x0) /=; last by rewrite -def_m leq_addl.
elim: k i (nth x0 t i) def_m => [|k IHk] i x /=.
by rewrite add0n => ->; rewrite drop_size.
rewrite addSnnS => def_m; rewrite -addSn leq_add2l -IHk //.
by rewrite (drop_nth x0) // -def_m leq_addl.
pose sub_mn (t : m.-tuple 'I_(m + n)) i : In1 := inord (tnth t i - i).
exists (fun t => [tuple of map (sub_mn t) (ord_tuple m)]) => [t _ | t].
apply: eq_from_tnth => i; apply: val_inj.
by rewrite /sub_mn !(tnth_ord_tuple, tnth_map) addKn inord_val.
rewrite inE /= => inc_t; apply: eq_from_tnth => i; apply: val_inj.
rewrite tnth_map tnth_ord_tuple /= tnth_map tnth_ord_tuple.
suffices [le_i_ti le_ti_ni]: i <= tnth t i /\ tnth t i <= i + n.
by rewrite /sub_mn inordK ?subnKC // ltnS leq_subLR.
pose y0 := tnth t i; rewrite (tnth_nth y0) -(nth_map _ (val i)) ?size_tuple //.
case def_e: (map _ _) => [|x e] /=; first by rewrite nth_nil ?leq_addr.
set nth_i := nth (i : nat); rewrite def_e in inc_t; split.
have: i < size (x :: e) by rewrite -def_e size_map size_tuple ltn_ord.
elim: (val i) => //= j IHj lt_j_e.
by apply: leq_trans (pathP (val i) inc_t _ lt_j_e); rewrite ltnS IHj 1?ltnW.
move: (_ - _) (subnK (valP i)) => k /=.
elim: k (val i) => /= [|k IHk] j; rewrite -ltnS -addSn ?add0n => def_m.
by rewrite def_m -def_e /nth_i (nth_map y0) ?ltn_ord // size_tuple -def_m.
rewrite (leq_trans _ (IHk _ _)) -1?addSnnS //; apply: (pathP _ inc_t).
rewrite -ltnS (leq_trans (leq_addl k _)) // -addSnnS def_m.
by rewrite -(size_tuple t) -(size_map val) def_e.
Qed.
Lemma card_partial_ord_partitions m n :
#|[set t : m.-tuple 'I_n.+1 | \sum_(i <- t) i <= n]| = 'C(m + n, m).
Proof.
symmetry; set In1 := 'I_n.+1; pose x0 : In1 := ord0.
pose add_mn (i j : In1) : In1 := inord (i + j).
pose f_add (t : m.-tuple In1) := [tuple of scanl add_mn x0 t].
rewrite -card_sorted_tuples -!sum1dep_card (reindex f_add) /=.
apply: eq_bigl => t; rewrite -[\sum_(i <- t) i]add0n.
transitivity (path leq x0 (map val (f_add t))) => /=; first by case: map.
rewrite -{1 2}[0]/(val x0); elim: {t}(val t) (x0) => /= [|x t IHt] s.
by rewrite big_nil addn0 -ltnS ltn_ord.
rewrite big_cons addnA IHt /= val_insubd ltnS.
have [_ | ltn_n_sx] := leqP (s + x) n; first by rewrite leq_addr.
rewrite -(leq_add2r x) leqNgt (leq_trans (valP x)) //=.
by rewrite leqNgt (leq_trans ltn_n_sx) ?leq_addr.
pose sub_mn (i j : In1) := Ordinal (leq_ltn_trans (leq_subr i j) (valP j)).
exists (fun t : m.-tuple In1 => [tuple of pairmap sub_mn x0 t]) => /= t inc_t.
apply: val_inj => /=; have{inc_t}: path leq x0 (map val (f_add t)).
by move: inc_t; rewrite inE /=; case: map.
rewrite [map _ _]/=; elim: {t}(val t) (x0) => //= x t IHt s.
case/andP=> le_s_sx /IHt->; congr (_ :: _); apply: val_inj => /=.
move: le_s_sx; rewrite val_insubd.
case le_sx_n: (_ < n.+1); first by rewrite addKn.
by case: (val s) le_sx_n; rewrite ?ltn_ord.
apply: val_inj => /=; have{inc_t}: path leq x0 (map val t).
by move: inc_t; rewrite inE /=; case: map.
elim: {t}(val t) (x0) => //= x t IHt s /andP[le_s_sx inc_t].
suffices ->: add_mn s (sub_mn s x) = x by rewrite IHt.
by apply: val_inj; rewrite /add_mn /= subnKC ?inord_val.
Qed.
Lemma card_ord_partitions m n :
#|[set t : m.+1.-tuple 'I_n.+1 | \sum_(i <- t) i == n]| = 'C(m + n, m).
Proof.
symmetry; set In1 := 'I_n.+1; pose x0 : In1 := ord0.
pose f_add (t : m.-tuple In1) := [tuple of sub_ord (\sum_(x <- t) x) :: t].
rewrite -card_partial_ord_partitions -!sum1dep_card (reindex f_add) /=.
by apply: eq_bigl => t; rewrite big_cons /= addnC (sameP maxn_idPr eqP) maxnE.
exists (fun t : m.+1.-tuple In1 => [tuple of behead t]) => [t _|].
exact: val_inj.
case/tupleP=> x t /[!(inE, big_cons)] /eqP def_n.
by apply: val_inj; congr (_ :: _); apply: val_inj; rewrite /= -{1}def_n addnK.
Qed.
End Combinations.
|
interval_inference.v
|
(* mathcomp analysis (c) 2017 Inria and AIST. License: CeCILL-C. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat eqtype choice.
From mathcomp Require Import order ssralg ssrnum ssrint interval.
(**md**************************************************************************)
(* # Numbers within an interval *)
(* *)
(* This file develops tools to make the manipulation of numbers within *)
(* a known interval easier, thanks to canonical structures. This adds types *)
(* like {itv R & `[a, b]}, a notation e%:itv that infers an enclosing *)
(* interval for expression e according to existing canonical instances and *)
(* %:num to cast back from type {itv R & i} to R. *)
(* For instance, for x : {i01 R}, we have (1 - x%:num)%:itv : {i01 R} *)
(* automatically inferred. *)
(* *)
(* ## types for values within known interval *)
(* *)
(* ``` *)
(* {itv R & i} == generic type of values in interval i : interval int *)
(* See interval.v for notations that can be used for i. *)
(* R must have a numDomainType structure. This type is shown *)
(* to be a porderType. *)
(* {i01 R} := {itv R & `[0, 1]} *)
(* Allows to solve automatically goals of the form x >= 0 *)
(* and x <= 1 when x is canonically a {i01 R}. *)
(* {i01 R} is canonically stable by common operations. *)
(* {posnum R} := {itv R & `]0, +oo[) *)
(* {nonneg R} := {itv R & `[0, +oo[) *)
(* ``` *)
(* *)
(* ## casts from/to values within known interval *)
(* *)
(* Explicit casts of x to some {itv R & i} according to existing canonical *)
(* instances: *)
(* ``` *)
(* x%:itv == cast to the most precisely known {itv R & i} *)
(* x%:i01 == cast to {i01 R}, or fail *)
(* x%:pos == cast to {posnum R}, or fail *)
(* x%:nng == cast to {nonneg R}, or fail *)
(* ``` *)
(* *)
(* Explicit casts of x from some {itv R & i} to R: *)
(* ``` *)
(* x%:num == cast from {itv R & i} *)
(* x%:posnum == cast from {posnum R} *)
(* x%:nngnum == cast from {nonneg R} *)
(* ``` *)
(* *)
(* ## sign proofs *)
(* *)
(* ``` *)
(* [itv of x] == proof that x is in the interval inferred by x%:itv *)
(* [gt0 of x] == proof that x > 0 *)
(* [lt0 of x] == proof that x < 0 *)
(* [ge0 of x] == proof that x >= 0 *)
(* [le0 of x] == proof that x <= 0 *)
(* [cmp0 of x] == proof that 0 >=< x *)
(* [neq0 of x] == proof that x != 0 *)
(* ``` *)
(* *)
(* ## constructors *)
(* *)
(* ``` *)
(* ItvNum xr lx xu == builds a {itv R & i} from proofs xr : x \in Num.real, *)
(* lx : map_itv_bound (Itv.num_sem R) l <= BLeft x *)
(* xu : BRight x <= map_itv_bound (Itv.num_sem R) u *)
(* where x : R with R : numDomainType *)
(* and l u : itv_bound int *)
(* ItvReal lx xu == builds a {itv R & i} from proofs *)
(* lx : map_itv_bound (Itv.num_sem R) l <= BLeft x *)
(* xu : BRight x <= map_itv_bound (Itv.num_sem R) u *)
(* where x : R with R : realDomainType *)
(* and l u : itv_bound int *)
(* Itv01 x0 x1 == builds a {i01 R} from proofs x0 : 0 <= x and x1 : x <= 1*)
(* where x : R with R : numDomainType *)
(* PosNum x0 == builds a {posnum R} from a proof x0 : x > 0 where x : R *)
(* NngNum x0 == builds a {posnum R} from a proof x0 : x >= 0 where x : R*)
(* ``` *)
(* *)
(* A number of canonical instances are provided for common operations, if *)
(* your favorite operator is missing, look below for examples on how to add *)
(* the appropriate Canonical. *)
(* Also note that all provided instances aren't necessarily optimal, *)
(* improvements welcome! *)
(* Canonical instances are also provided according to types, as a *)
(* fallback when no known operator appears in the expression. Look to top_typ *)
(* below for an example on how to add your favorite type. *)
(* *)
(******************************************************************************)
Reserved Notation "{ 'itv' R & i }"
(R at level 200, i at level 200, format "{ 'itv' R & i }").
Reserved Notation "{ 'i01' R }"
(R at level 200, format "{ 'i01' R }").
Reserved Notation "{ 'posnum' R }" (format "{ 'posnum' R }").
Reserved Notation "{ 'nonneg' R }" (format "{ 'nonneg' R }").
Reserved Notation "x %:itv" (format "x %:itv").
Reserved Notation "x %:i01" (format "x %:i01").
Reserved Notation "x %:pos" (format "x %:pos").
Reserved Notation "x %:nng" (format "x %:nng").
Reserved Notation "x %:inum" (format "x %:inum").
Reserved Notation "x %:num" (format "x %:num").
Reserved Notation "x %:posnum" (format "x %:posnum").
Reserved Notation "x %:nngnum" (format "x %:nngnum").
Reserved Notation "[ 'itv' 'of' x ]" (format "[ 'itv' 'of' x ]").
Reserved Notation "[ 'gt0' 'of' x ]" (format "[ 'gt0' 'of' x ]").
Reserved Notation "[ 'lt0' 'of' x ]" (format "[ 'lt0' 'of' x ]").
Reserved Notation "[ 'ge0' 'of' x ]" (format "[ 'ge0' 'of' x ]").
Reserved Notation "[ 'le0' 'of' x ]" (format "[ 'le0' 'of' x ]").
Reserved Notation "[ 'cmp0' 'of' x ]" (format "[ 'cmp0' 'of' x ]").
Reserved Notation "[ 'neq0' 'of' x ]" (format "[ 'neq0' 'of' x ]").
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory Order.Syntax.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Local Open Scope order_scope.
Definition map_itv_bound S T (f : S -> T) (b : itv_bound S) : itv_bound T :=
match b with
| BSide b x => BSide b (f x)
| BInfty b => BInfty _ b
end.
Lemma map_itv_bound_comp S T U (f : T -> S) (g : U -> T) (b : itv_bound U) :
map_itv_bound (f \o g) b = map_itv_bound f (map_itv_bound g b).
Proof. by case: b. Qed.
Definition map_itv S T (f : S -> T) (i : interval S) : interval T :=
let 'Interval l u := i in Interval (map_itv_bound f l) (map_itv_bound f u).
Lemma map_itv_comp S T U (f : T -> S) (g : U -> T) (i : interval U) :
map_itv (f \o g) i = map_itv f (map_itv g i).
Proof. by case: i => l u /=; rewrite -!map_itv_bound_comp. Qed.
(* First, the interval arithmetic operations we will later use *)
Module IntItv.
Implicit Types (b : itv_bound int) (i j : interval int).
Definition opp_bound b :=
match b with
| BSide b x => BSide (~~ b) (intZmod.oppz x)
| BInfty b => BInfty _ (~~ b)
end.
Lemma opp_bound_ge0 b : (BLeft 0%R <= opp_bound b)%O = (b <= BRight 0%R)%O.
Proof. by case: b => [[] b | []//]; rewrite /= !bnd_simp oppr_ge0. Qed.
Lemma opp_bound_gt0 b : (BRight 0%R <= opp_bound b)%O = (b <= BLeft 0%R)%O.
Proof.
by case: b => [[] b | []//]; rewrite /= !bnd_simp ?oppr_ge0 ?oppr_gt0.
Qed.
Definition opp i :=
let: Interval l u := i in Interval (opp_bound u) (opp_bound l).
Arguments opp /.
Definition add_boundl b1 b2 :=
match b1, b2 with
| BSide b1 x1, BSide b2 x2 => BSide (b1 && b2) (intZmod.addz x1 x2)
| _, _ => BInfty _ true
end.
Definition add_boundr b1 b2 :=
match b1, b2 with
| BSide b1 x1, BSide b2 x2 => BSide (b1 || b2) (intZmod.addz x1 x2)
| _, _ => BInfty _ false
end.
Definition add i1 i2 :=
let: Interval l1 u1 := i1 in let: Interval l2 u2 := i2 in
Interval (add_boundl l1 l2) (add_boundr u1 u2).
Arguments add /.
Variant signb := EqZero | NonNeg | NonPos.
Definition sign_boundl b :=
let: b0 := BLeft 0%Z in
if b == b0 then EqZero else if (b <= b0)%O then NonPos else NonNeg.
Definition sign_boundr b :=
let: b0 := BRight 0%Z in
if b == b0 then EqZero else if (b <= b0)%O then NonPos else NonNeg.
Variant signi := Known of signb | Unknown | Empty.
Definition sign i : signi :=
let: Interval l u := i in
match sign_boundl l, sign_boundr u with
| EqZero, NonPos
| NonNeg, EqZero
| NonNeg, NonPos => Empty
| EqZero, EqZero => Known EqZero
| NonPos, EqZero
| NonPos, NonPos => Known NonPos
| EqZero, NonNeg
| NonNeg, NonNeg => Known NonNeg
| NonPos, NonNeg => Unknown
end.
Definition mul_boundl b1 b2 :=
match b1, b2 with
| BInfty _, _
| _, BInfty _
| BLeft 0%Z, _
| _, BLeft 0%Z => BLeft 0%Z
| BSide b1 x1, BSide b2 x2 => BSide (b1 && b2) (intRing.mulz x1 x2)
end.
Definition mul_boundr b1 b2 :=
match b1, b2 with
| BLeft 0%Z, _
| _, BLeft 0%Z => BLeft 0%Z
| BRight 0%Z, _
| _, BRight 0%Z => BRight 0%Z
| BSide b1 x1, BSide b2 x2 => BSide (b1 || b2) (intRing.mulz x1 x2)
| _, BInfty _
| BInfty _, _ => +oo%O
end.
Lemma mul_boundrC b1 b2 : mul_boundr b1 b2 = mul_boundr b2 b1.
Proof.
by move: b1 b2 => [[] [[|?]|?] | []] [[] [[|?]|?] | []] //=; rewrite mulnC.
Qed.
Lemma mul_boundr_gt0 b1 b2 :
(BRight 0%Z <= b1 -> BRight 0%Z <= b2 -> BRight 0%Z <= mul_boundr b1 b2)%O.
Proof.
case: b1 b2 => [b1b b1 | []] [b2b b2 | []]//=.
- by case: b1b b2b => -[]; case: b1 b2 => [[|b1] | b1] [[|b2] | b2].
- by case: b1b b1 => -[[] |].
- by case: b2b b2 => -[[] |].
Qed.
Definition mul i1 i2 :=
let: Interval l1 u1 := i1 in let: Interval l2 u2 := i2 in
let: opp := opp_bound in
let: mull := mul_boundl in let: mulr := mul_boundr in
match sign i1, sign i2 with
| Empty, _ | _, Empty => `[1, 0]
| Known EqZero, _ | _, Known EqZero => `[0, 0]
| Known NonNeg, Known NonNeg =>
Interval (mull l1 l2) (mulr u1 u2)
| Known NonPos, Known NonPos =>
Interval (mull (opp u1) (opp u2)) (mulr (opp l1) (opp l2))
| Known NonNeg, Known NonPos =>
Interval (opp (mulr u1 (opp l2))) (opp (mull l1 (opp u2)))
| Known NonPos, Known NonNeg =>
Interval (opp (mulr (opp l1) u2)) (opp (mull (opp u1) l2))
| Known NonNeg, Unknown =>
Interval (opp (mulr u1 (opp l2))) (mulr u1 u2)
| Known NonPos, Unknown =>
Interval (opp (mulr (opp l1) u2)) (mulr (opp l1) (opp l2))
| Unknown, Known NonNeg =>
Interval (opp (mulr (opp l1) u2)) (mulr u1 u2)
| Unknown, Known NonPos =>
Interval (opp (mulr u1 (opp l2))) (mulr (opp l1) (opp l2))
| Unknown, Unknown =>
Interval
(Order.min (opp (mulr (opp l1) u2)) (opp (mulr u1 (opp l2))))
(Order.max (mulr (opp l1) (opp l2)) (mulr u1 u2))
end.
Arguments mul /.
Definition min i j :=
let: Interval li ui := i in let: Interval lj uj := j in
Interval (Order.min li lj) (Order.min ui uj).
Arguments min /.
Definition max i j :=
let: Interval li ui := i in let: Interval lj uj := j in
Interval (Order.max li lj) (Order.max ui uj).
Arguments max /.
Definition keep_nonneg_bound b :=
match b with
| BSide _ (Posz _) => BLeft 0%Z
| BSide _ (Negz _) => -oo%O
| BInfty _ => -oo%O
end.
Arguments keep_nonneg_bound /.
Definition keep_pos_bound b :=
match b with
| BSide b 0%Z => BSide b 0%Z
| BSide _ (Posz (S _)) => BRight 0%Z
| BSide _ (Negz _) => -oo
| BInfty _ => -oo
end.
Arguments keep_pos_bound /.
Definition keep_nonpos_bound b :=
match b with
| BSide _ (Negz _) | BSide _ (Posz 0) => BRight 0%Z
| BSide _ (Posz (S _)) => +oo%O
| BInfty _ => +oo%O
end.
Arguments keep_nonpos_bound /.
Definition keep_neg_bound b :=
match b with
| BSide b 0%Z => BSide b 0%Z
| BSide _ (Negz _) => BLeft 0%Z
| BSide _ (Posz _) => +oo
| BInfty _ => +oo
end.
Arguments keep_neg_bound /.
Definition inv i :=
let: Interval l u := i in
Interval (keep_pos_bound l) (keep_neg_bound u).
Arguments inv /.
Definition exprn_le1_bound b1 b2 :=
if b2 isn't BSide _ 1%Z then +oo
else if (BLeft (-1)%Z <= b1)%O then BRight 1%Z else +oo.
Arguments exprn_le1_bound /.
Definition exprn i :=
let: Interval l u := i in
Interval (keep_pos_bound l) (exprn_le1_bound l u).
Arguments exprn /.
Definition exprz i1 i2 :=
let: Interval l2 _ := i2 in
if l2 is BSide _ (Posz _) then exprn i1 else
let: Interval l u := i1 in
Interval (keep_pos_bound l) +oo.
Arguments exprz /.
Definition keep_sign i :=
let: Interval l u := i in
Interval (keep_nonneg_bound l) (keep_nonpos_bound u).
(* used in ereal.v *)
Definition keep_nonpos i :=
let 'Interval l u := i in
Interval -oo%O (keep_nonpos_bound u).
Arguments keep_nonpos /.
(* used in ereal.v *)
Definition keep_nonneg i :=
let 'Interval l u := i in
Interval (keep_nonneg_bound l) +oo%O.
Arguments keep_nonneg /.
End IntItv.
Module Itv.
Variant t := Top | Real of interval int.
Definition sub (x y : t) :=
match x, y with
| _, Top => true
| Top, Real _ => false
| Real xi, Real yi => subitv xi yi
end.
Section Itv.
Context T (sem : interval int -> T -> bool).
Definition spec (i : t) (x : T) := if i is Real i then sem i x else true.
Record def (i : t) := Def {
r : T;
#[canonical=no]
P : spec i r
}.
End Itv.
Record typ i := Typ {
sort : Type;
#[canonical=no]
sort_sem : interval int -> sort -> bool;
#[canonical=no]
allP : forall x : sort, spec sort_sem i x
}.
Definition mk {T f} i x P : @def T f i := @Def T f i x P.
Definition from {T f i} {x : @def T f i} (phx : phantom T (r x)) := x.
Definition fromP {T f i} {x : @def T f i} (phx : phantom T (r x)) := P x.
Definition num_sem (R : numDomainType) (i : interval int) (x : R) : bool :=
(x \in Num.real) && (x \in map_itv intr i).
Definition nat_sem (i : interval int) (x : nat) : bool := Posz x \in i.
Definition posnum (R : numDomainType) of phant R :=
def (@num_sem R) (Real `]0, +oo[).
Definition nonneg (R : numDomainType) of phant R :=
def (@num_sem R) (Real `[0, +oo[).
(* a few lifting helper functions *)
Definition real1 (op1 : interval int -> interval int) (x : Itv.t) : Itv.t :=
match x with Itv.Top => Itv.Top | Itv.Real x => Itv.Real (op1 x) end.
Definition real2 (op2 : interval int -> interval int -> interval int)
(x y : Itv.t) : Itv.t :=
match x, y with
| Itv.Top, _ | _, Itv.Top => Itv.Top
| Itv.Real x, Itv.Real y => Itv.Real (op2 x y)
end.
Lemma spec_real1 T f (op1 : T -> T) (op1i : interval int -> interval int) :
forall (x : T), (forall xi, f xi x = true -> f (op1i xi) (op1 x) = true) ->
forall xi, spec f xi x -> spec f (real1 op1i xi) (op1 x).
Proof. by move=> x + [//| xi]; apply. Qed.
Lemma spec_real2 T f (op2 : T -> T -> T)
(op2i : interval int -> interval int -> interval int) (x y : T) :
(forall xi yi, f xi x = true -> f yi y = true ->
f (op2i xi yi) (op2 x y) = true) ->
forall xi yi, spec f xi x -> spec f yi y ->
spec f (real2 op2i xi yi) (op2 x y).
Proof. by move=> + [//| xi] [//| yi]; apply. Qed.
Module Exports.
Arguments r {T sem i}.
Notation "{ 'itv' R & i }" := (def (@num_sem R) (Itv.Real i%Z)) : type_scope.
Notation "{ 'i01' R }" := {itv R & `[0, 1]} : type_scope.
Notation "{ 'posnum' R }" := (@posnum _ (Phant R)) : ring_scope.
Notation "{ 'nonneg' R }" := (@nonneg _ (Phant R)) : ring_scope.
Notation "x %:itv" := (from (Phantom _ x)) : ring_scope.
Notation "[ 'itv' 'of' x ]" := (fromP (Phantom _ x)) : ring_scope.
Notation num := r.
Notation "x %:inum" := (r x) (only parsing) : ring_scope.
Notation "x %:num" := (r x) : ring_scope.
Notation "x %:posnum" := (@r _ _ (Real `]0%Z, +oo[) x) : ring_scope.
Notation "x %:nngnum" := (@r _ _ (Real `[0%Z, +oo[) x) : ring_scope.
End Exports.
End Itv.
Export Itv.Exports.
Local Notation num_spec := (Itv.spec (@Itv.num_sem _)).
Local Notation num_def R := (Itv.def (@Itv.num_sem R)).
Local Notation num_itv_bound R := (@map_itv_bound _ R intr).
Local Notation nat_spec := (Itv.spec Itv.nat_sem).
Local Notation nat_def := (Itv.def Itv.nat_sem).
Section POrder.
Context d (T : porderType d) (f : interval int -> T -> bool) (i : Itv.t).
Local Notation itv := (Itv.def f i).
HB.instance Definition _ := [isSub for @Itv.r T f i].
HB.instance Definition _ : Order.POrder d itv := [POrder of itv by <:].
End POrder.
Section Order.
Variables (R : numDomainType) (i : interval int).
Local Notation nR := (num_def R (Itv.Real i)).
Lemma itv_le_total_subproof : total (<=%O : rel nR).
Proof.
move=> x y; apply: real_comparable.
- by case: x => [x /=/andP[]].
- by case: y => [y /=/andP[]].
Qed.
HB.instance Definition _ := Order.POrder_isTotal.Build ring_display nR
itv_le_total_subproof.
End Order.
Module TypInstances.
Lemma top_typ_spec T f (x : T) : Itv.spec f Itv.Top x.
Proof. by []. Qed.
Canonical top_typ T f := Itv.Typ (@top_typ_spec T f).
Lemma real_domain_typ_spec (R : realDomainType) (x : R) :
num_spec (Itv.Real `]-oo, +oo[) x.
Proof. by rewrite /Itv.num_sem/= num_real. Qed.
Canonical real_domain_typ (R : realDomainType) :=
Itv.Typ (@real_domain_typ_spec R).
Lemma real_field_typ_spec (R : realFieldType) (x : R) :
num_spec (Itv.Real `]-oo, +oo[) x.
Proof. exact: real_domain_typ_spec. Qed.
Canonical real_field_typ (R : realFieldType) :=
Itv.Typ (@real_field_typ_spec R).
Lemma nat_typ_spec (x : nat) : nat_spec (Itv.Real `[0, +oo[) x.
Proof. by []. Qed.
Canonical nat_typ := Itv.Typ nat_typ_spec.
Lemma typ_inum_spec (i : Itv.t) (xt : Itv.typ i) (x : Itv.sort xt) :
Itv.spec (@Itv.sort_sem _ xt) i x.
Proof. by move: xt x => []. Qed.
(* This adds _ <- Itv.r ( typ_inum )
to canonical projections (c.f., Print Canonical Projections
Itv.r) meaning that if no other canonical instance (with a
registered head symbol) is found, a canonical instance of
Itv.typ, like the ones above, will be looked for. *)
Canonical typ_inum (i : Itv.t) (xt : Itv.typ i) (x : Itv.sort xt) :=
Itv.mk (typ_inum_spec x).
End TypInstances.
Export (canonicals) TypInstances.
Class unify {T} f (x y : T) := Unify : f x y = true.
#[export] Hint Mode unify + + + + : typeclass_instances.
Class unify' {T} f (x y : T) := Unify' : f x y = true.
#[export] Instance unify'P {T} f (x y : T) : unify' f x y -> unify f x y := id.
#[export]
Hint Extern 0 (unify' _ _ _) => vm_compute; reflexivity : typeclass_instances.
Notation unify_itv ix iy := (unify Itv.sub ix iy).
#[export] Instance top_wider_anything i : unify_itv i Itv.Top.
Proof. by case: i. Qed.
#[export] Instance real_wider_anyreal i :
unify_itv (Itv.Real i) (Itv.Real `]-oo, +oo[).
Proof. by case: i => [l u]; apply/andP; rewrite !bnd_simp. Qed.
Section NumDomainTheory.
Context {R : numDomainType} {i : Itv.t}.
Implicit Type x : num_def R i.
Lemma le_num_itv_bound (x y : itv_bound int) :
(num_itv_bound R x <= num_itv_bound R y)%O = (x <= y)%O.
Proof.
by case: x y => [[] x | x] [[] y | y]//=; rewrite !bnd_simp ?ler_int ?ltr_int.
Qed.
Lemma num_itv_bound_le_BLeft (x : itv_bound int) (y : int) :
(num_itv_bound R x <= BLeft (y%:~R : R))%O = (x <= BLeft y)%O.
Proof.
rewrite -[BLeft y%:~R]/(map_itv_bound intr (BLeft y)).
by rewrite le_num_itv_bound.
Qed.
Lemma BRight_le_num_itv_bound (x : int) (y : itv_bound int) :
(BRight (x%:~R : R) <= num_itv_bound R y)%O = (BRight x <= y)%O.
Proof.
rewrite -[BRight x%:~R]/(map_itv_bound intr (BRight x)).
by rewrite le_num_itv_bound.
Qed.
Lemma num_spec_sub (x y : Itv.t) : Itv.sub x y ->
forall z : R, num_spec x z -> num_spec y z.
Proof.
case: x y => [| x] [| y] //= x_sub_y z /andP[rz]; rewrite /Itv.num_sem rz/=.
move: x y x_sub_y => [lx ux] [ly uy] /andP[lel leu] /=.
move=> /andP[lxz zux]; apply/andP; split.
- by apply: le_trans lxz; rewrite le_num_itv_bound.
- by apply: le_trans zux _; rewrite le_num_itv_bound.
Qed.
Definition empty_itv := Itv.Real `[1, 0]%Z.
Lemma bottom x : ~ unify_itv i empty_itv.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= => /andP[] /le_trans /[apply]; rewrite ler10.
Qed.
Lemma gt0 x : unify_itv i (Itv.Real `]0%Z, +oo[) -> 0 < x%:num :> R.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_].
by rewrite /= in_itv/= andbT.
Qed.
Lemma le0F x : unify_itv i (Itv.Real `]0%Z, +oo[) -> x%:num <= 0 :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= andbT => /lt_geF.
Qed.
Lemma lt0 x : unify_itv i (Itv.Real `]-oo, 0%Z[) -> x%:num < 0 :> R.
Proof.
by case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=; rewrite in_itv.
Qed.
Lemma ge0F x : unify_itv i (Itv.Real `]-oo, 0%Z[) -> 0 <= x%:num :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= => /lt_geF.
Qed.
Lemma ge0 x : unify_itv i (Itv.Real `[0%Z, +oo[) -> 0 <= x%:num :> R.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= andbT.
Qed.
Lemma lt0F x : unify_itv i (Itv.Real `[0%Z, +oo[) -> x%:num < 0 :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= andbT => /le_gtF.
Qed.
Lemma le0 x : unify_itv i (Itv.Real `]-oo, 0%Z]) -> x%:num <= 0 :> R.
Proof.
by case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=; rewrite in_itv.
Qed.
Lemma gt0F x : unify_itv i (Itv.Real `]-oo, 0%Z]) -> 0 < x%:num :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= => /le_gtF.
Qed.
Lemma cmp0 x : unify_itv i (Itv.Real `]-oo, +oo[) -> 0 >=< x%:num.
Proof. by case: i x => [//| i' [x /=/andP[]]]. Qed.
Lemma neq0 x :
unify (fun ix iy => ~~ Itv.sub ix iy) (Itv.Real `[0%Z, 0%Z]) i ->
x%:num != 0 :> R.
Proof.
case: i x => [//| [l u] [x /= Px]]; apply: contra => /eqP x0 /=.
move: Px; rewrite x0 => /and3P[_ /= l0 u0]; apply/andP; split.
- by case: l l0 => [[] l /= |//]; rewrite !bnd_simp ?lerz0 ?ltrz0.
- by case: u u0 => [[] u /= |//]; rewrite !bnd_simp ?ler0z ?ltr0z.
Qed.
Lemma eq0F x :
unify (fun ix iy => ~~ Itv.sub ix iy) (Itv.Real `[0%Z, 0%Z]) i ->
x%:num == 0 :> R = false.
Proof. by move=> u; apply/negbTE/neq0. Qed.
Lemma lt1 x : unify_itv i (Itv.Real `]-oo, 1%Z[) -> x%:num < 1 :> R.
Proof.
by case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=; rewrite in_itv.
Qed.
Lemma ge1F x : unify_itv i (Itv.Real `]-oo, 1%Z[) -> 1 <= x%:num :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= => /lt_geF.
Qed.
Lemma le1 x : unify_itv i (Itv.Real `]-oo, 1%Z]) -> x%:num <= 1 :> R.
Proof.
by case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=; rewrite in_itv.
Qed.
Lemma gt1F x : unify_itv i (Itv.Real `]-oo, 1%Z]) -> 1 < x%:num :> R = false.
Proof.
case: x => x /= /[swap] /num_spec_sub /[apply] /andP[_] /=.
by rewrite in_itv/= => /le_gtF.
Qed.
Lemma widen_itv_subproof x i' : Itv.sub i i' -> num_spec i' x%:num.
Proof. by case: x => x /= /[swap] /num_spec_sub; apply. Qed.
Definition widen_itv x i' (uni : unify_itv i i') :=
Itv.mk (widen_itv_subproof x uni).
Lemma widen_itvE x (uni : unify_itv i i) : @widen_itv x i uni = x.
Proof. exact/val_inj. Qed.
Lemma posE x (uni : unify_itv i (Itv.Real `]0%Z, +oo[)) :
(widen_itv x%:num%:itv uni)%:num = x%:num.
Proof. by []. Qed.
Lemma nngE x (uni : unify_itv i (Itv.Real `[0%Z, +oo[)) :
(widen_itv x%:num%:itv uni)%:num = x%:num.
Proof. by []. Qed.
End NumDomainTheory.
Arguments bottom {R i} _ {_}.
Arguments gt0 {R i} _ {_}.
Arguments le0F {R i} _ {_}.
Arguments lt0 {R i} _ {_}.
Arguments ge0F {R i} _ {_}.
Arguments ge0 {R i} _ {_}.
Arguments lt0F {R i} _ {_}.
Arguments le0 {R i} _ {_}.
Arguments gt0F {R i} _ {_}.
Arguments cmp0 {R i} _ {_}.
Arguments neq0 {R i} _ {_}.
Arguments eq0F {R i} _ {_}.
Arguments lt1 {R i} _ {_}.
Arguments ge1F {R i} _ {_}.
Arguments le1 {R i} _ {_}.
Arguments gt1F {R i} _ {_}.
Arguments widen_itv {R i} _ {_ _}.
Arguments widen_itvE {R i} _ {_}.
Arguments posE {R i} _ {_}.
Arguments nngE {R i} _ {_}.
Notation "[ 'gt0' 'of' x ]" := (ltac:(refine (gt0 x%:itv))) (only parsing).
Notation "[ 'lt0' 'of' x ]" := (ltac:(refine (lt0 x%:itv))) (only parsing).
Notation "[ 'ge0' 'of' x ]" := (ltac:(refine (ge0 x%:itv))) (only parsing).
Notation "[ 'le0' 'of' x ]" := (ltac:(refine (le0 x%:itv))) (only parsing).
Notation "[ 'cmp0' 'of' x ]" := (ltac:(refine (cmp0 x%:itv))) (only parsing).
Notation "[ 'neq0' 'of' x ]" := (ltac:(refine (neq0 x%:itv))) (only parsing).
#[export] Hint Extern 0 (is_true (0%R < _)%R) => solve [apply: gt0] : core.
#[export] Hint Extern 0 (is_true (_ < 0%R)%R) => solve [apply: lt0] : core.
#[export] Hint Extern 0 (is_true (0%R <= _)%R) => solve [apply: ge0] : core.
#[export] Hint Extern 0 (is_true (_ <= 0%R)%R) => solve [apply: le0] : core.
#[export] Hint Extern 0 (is_true (_ \is Num.real)) => solve [apply: cmp0]
: core.
#[export] Hint Extern 0 (is_true (0%R >=< _)%R) => solve [apply: cmp0] : core.
#[export] Hint Extern 0 (is_true (_ != 0%R)) => solve [apply: neq0] : core.
#[export] Hint Extern 0 (is_true (_ < 1%R)%R) => solve [apply: lt1] : core.
#[export] Hint Extern 0 (is_true (_ <= 1%R)%R) => solve [apply: le1] : core.
Notation "x %:i01" := (widen_itv x%:itv : {i01 _}) (only parsing) : ring_scope.
Notation "x %:i01" := (@widen_itv _ _
(@Itv.from _ _ _ (Phantom _ x)) (Itv.Real `[0, 1]%Z) _)
(only printing) : ring_scope.
Notation "x %:pos" := (widen_itv x%:itv : {posnum _}) (only parsing)
: ring_scope.
Notation "x %:pos" := (@widen_itv _ _
(@Itv.from _ _ _ (Phantom _ x)) (Itv.Real `]0%Z, +oo[) _)
(only printing) : ring_scope.
Notation "x %:nng" := (widen_itv x%:itv : {nonneg _}) (only parsing)
: ring_scope.
Notation "x %:nng" := (@widen_itv _ _
(@Itv.from _ _ _ (Phantom _ x)) (Itv.Real `[0%Z, +oo[) _)
(only printing) : ring_scope.
Local Open Scope ring_scope.
Module Instances.
Import IntItv.
Section NumDomainInstances.
Context {R : numDomainType}.
Lemma num_spec_zero : num_spec (Itv.Real `[0, 0]) (0 : R).
Proof. by apply/andP; split; [exact: real0 | rewrite /= in_itv/= lexx]. Qed.
Canonical zero_inum := Itv.mk num_spec_zero.
Lemma num_spec_one : num_spec (Itv.Real `[1, 1]) (1 : R).
Proof. by apply/andP; split; [exact: real1 | rewrite /= in_itv/= lexx]. Qed.
Canonical one_inum := Itv.mk num_spec_one.
Lemma opp_boundr (x : R) b :
(BRight (- x)%R <= num_itv_bound R (opp_bound b))%O
= (num_itv_bound R b <= BLeft x)%O.
Proof.
by case: b => [[] b | []//]; rewrite /= !bnd_simp mulrNz ?lerN2 // ltrN2.
Qed.
Lemma opp_boundl (x : R) b :
(num_itv_bound R (opp_bound b) <= BLeft (- x)%R)%O
= (BRight x <= num_itv_bound R b)%O.
Proof.
by case: b => [[] b | []//]; rewrite /= !bnd_simp mulrNz ?lerN2 // ltrN2.
Qed.
Lemma num_spec_opp (i : Itv.t) (x : num_def R i) (r := Itv.real1 opp i) :
num_spec r (- x%:num).
Proof.
apply: Itv.spec_real1 (Itv.P x).
case: x => x /= _ [l u] /and3P[xr lx xu].
rewrite /Itv.num_sem/= realN xr/=; apply/andP.
by rewrite opp_boundl opp_boundr.
Qed.
Canonical opp_inum (i : Itv.t) (x : num_def R i) := Itv.mk (num_spec_opp x).
Lemma num_itv_add_boundl (x1 x2 : R) b1 b2 :
(num_itv_bound R b1 <= BLeft x1)%O -> (num_itv_bound R b2 <= BLeft x2)%O ->
(num_itv_bound R (add_boundl b1 b2) <= BLeft (x1 + x2)%R)%O.
Proof.
case: b1 b2 => [bb1 b1 |//] [bb2 b2 |//].
case: bb1; case: bb2; rewrite /= !bnd_simp mulrzDr.
- exact: lerD.
- exact: ler_ltD.
- exact: ltr_leD.
- exact: ltrD.
Qed.
Lemma num_itv_add_boundr (x1 x2 : R) b1 b2 :
(BRight x1 <= num_itv_bound R b1)%O -> (BRight x2 <= num_itv_bound R b2)%O ->
(BRight (x1 + x2)%R <= num_itv_bound R (add_boundr b1 b2))%O.
Proof.
case: b1 b2 => [bb1 b1 |//] [bb2 b2 |//].
case: bb1; case: bb2; rewrite /= !bnd_simp mulrzDr.
- exact: ltrD.
- exact: ltr_leD.
- exact: ler_ltD.
- exact: lerD.
Qed.
Lemma num_spec_add (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi)
(r := Itv.real2 add xi yi) :
num_spec r (x%:num + y%:num).
Proof.
apply: Itv.spec_real2 (Itv.P x) (Itv.P y).
case: x y => [x /= _] [y /= _] => {xi yi r} -[lx ux] [ly uy]/=.
move=> /andP[xr /=/andP[lxx xux]] /andP[yr /=/andP[lyy yuy]].
rewrite /Itv.num_sem realD//=; apply/andP.
by rewrite num_itv_add_boundl ?num_itv_add_boundr.
Qed.
Canonical add_inum (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi) :=
Itv.mk (num_spec_add x y).
Variant sign_spec (l u : itv_bound int) (x : R) : signi -> Set :=
| ISignEqZero : l = BLeft 0 -> u = BRight 0 -> x = 0 ->
sign_spec l u x (Known EqZero)
| ISignNonNeg : (BLeft 0%:Z <= l)%O -> (BRight 0%:Z < u)%O -> 0 <= x ->
sign_spec l u x (Known NonNeg)
| ISignNonPos : (l < BLeft 0%:Z)%O -> (u <= BRight 0%:Z)%O -> x <= 0 ->
sign_spec l u x (Known NonPos)
| ISignBoth : (l < BLeft 0%:Z)%O -> (BRight 0%:Z < u)%O -> x \in Num.real ->
sign_spec l u x Unknown.
Lemma signP (l u : itv_bound int) (x : R) :
(num_itv_bound R l <= BLeft x)%O -> (BRight x <= num_itv_bound R u)%O ->
x \in Num.real ->
sign_spec l u x (sign (Interval l u)).
Proof.
move=> + + xr; rewrite /sign/sign_boundl/sign_boundr.
have [lneg|lpos|->] := ltgtP l; have [uneg|upos|->] := ltgtP u => lx xu.
- apply: ISignNonPos => //; first exact: ltW.
have:= le_trans xu (eqbRL (le_num_itv_bound _ _) (ltW uneg)).
by rewrite bnd_simp.
- exact: ISignBoth.
- exact: ISignNonPos.
- have:= @ltxx _ _ (num_itv_bound R l).
rewrite (le_lt_trans lx) -?leBRight_ltBLeft ?(le_trans xu)//.
by rewrite le_num_itv_bound (le_trans (ltW uneg)).
- apply: ISignNonNeg => //; first exact: ltW.
have:= le_trans (eqbRL (le_num_itv_bound _ _) (ltW lpos)) lx.
by rewrite bnd_simp.
- have:= @ltxx _ _ (num_itv_bound R l).
rewrite (le_lt_trans lx) -?leBRight_ltBLeft ?(le_trans xu)//.
by rewrite le_num_itv_bound ?leBRight_ltBLeft.
- have:= @ltxx _ _ (num_itv_bound R (BLeft 0%Z)).
rewrite (le_lt_trans lx) -?leBRight_ltBLeft ?(le_trans xu)//.
by rewrite le_num_itv_bound -?ltBRight_leBLeft.
- exact: ISignNonNeg.
- apply: ISignEqZero => //.
by apply/le_anti/andP; move: lx xu; rewrite !bnd_simp.
Qed.
Lemma num_itv_mul_boundl b1 b2 (x1 x2 : R) :
(BLeft 0%:Z <= b1 -> BLeft 0%:Z <= b2 ->
num_itv_bound R b1 <= BLeft x1 ->
num_itv_bound R b2 <= BLeft x2 ->
num_itv_bound R (mul_boundl b1 b2) <= BLeft (x1 * x2))%O.
Proof.
move: b1 b2 => [[] b1 | []//] [[] b2 | []//] /=; rewrite 4!bnd_simp.
- set bl := match b1 with 0%Z => _ | _ => _ end.
have -> : bl = BLeft (b1 * b2).
rewrite {}/bl; move: b1 b2 => [[|p1]|p1] [[|p2]|p2]; congr BLeft.
by rewrite mulr0.
by rewrite bnd_simp intrM -2!(ler0z R); apply: ler_pM.
- case: b1 => [[|b1] | b1]; rewrite !bnd_simp// => b1p b2p sx1 sx2.
+ by rewrite mulr_ge0 ?(le_trans _ (ltW sx2)) ?ler0z.
+ rewrite intrM (@lt_le_trans _ _ (b1.+1%:~R * x2)) ?ltr_pM2l//.
by rewrite ler_pM2r// (le_lt_trans _ sx2) ?ler0z.
- case: b2 => [[|b2] | b2]; rewrite !bnd_simp// => b1p b2p sx1 sx2.
+ by rewrite mulr_ge0 ?(le_trans _ (ltW sx1)) ?ler0z.
+ rewrite intrM (@le_lt_trans _ _ (b1%:~R * x2)) ?ler_wpM2l ?ler0z//.
by rewrite ltr_pM2r ?(lt_le_trans _ sx2).
- by rewrite -2!(ler0z R) bnd_simp intrM; apply: ltr_pM.
Qed.
Lemma num_itv_mul_boundr b1 b2 (x1 x2 : R) :
(0 <= x1 -> 0 <= x2 ->
BRight x1 <= num_itv_bound R b1 ->
BRight x2 <= num_itv_bound R b2 ->
BRight (x1 * x2) <= num_itv_bound R (mul_boundr b1 b2))%O.
Proof.
case: b1 b2 => [b1b b1 | []] [b2b b2 | []] //= x1p x2p; last first.
- case: b2b b2 => -[[|//] | //] _ x20.
+ have:= @ltxx _ (itv_bound R) (BLeft 0%:~R).
by rewrite (lt_le_trans _ x20).
+ have -> : x2 = 0 by apply/le_anti/andP.
by rewrite mulr0.
- case: b1b b1 => -[[|//] |//] x10 _.
+ have:= @ltxx _ (itv_bound R) (BLeft 0%Z%:~R).
by rewrite (lt_le_trans _ x10).
+ by have -> : x1 = 0; [apply/le_anti/andP | rewrite mul0r].
case: b1b b2b => -[]; rewrite -[intRing.mulz]/GRing.mul.
- case: b1 => [[|b1] | b1]; rewrite !bnd_simp => x1b x2b.
+ by have:= @ltxx _ R 0; rewrite (le_lt_trans x1p x1b).
+ case: b2 x2b => [[| b2] | b2] => x2b; rewrite bnd_simp.
* by have:= @ltxx _ R 0; rewrite (le_lt_trans x2p x2b).
* by rewrite intrM ltr_pM.
* have:= @ltxx _ R 0; rewrite (le_lt_trans x2p)//.
by rewrite (lt_le_trans x2b) ?lerz0.
+ have:= @ltxx _ R 0; rewrite (le_lt_trans x1p)//.
by rewrite (lt_le_trans x1b) ?lerz0.
- case: b1 => [[|b1] | b1]; rewrite !bnd_simp => x1b x2b.
+ by have:= @ltxx _ R 0; rewrite (le_lt_trans x1p x1b).
+ case: b2 x2b => [[| b2] | b2] x2b; rewrite bnd_simp.
* exact: mulr_ge0_le0.
* by rewrite intrM (le_lt_trans (ler_wpM2l x1p x2b)) ?ltr_pM2r.
* have:= @ltxx _ _ x2.
by rewrite (le_lt_trans x2b) ?(lt_le_trans _ x2p) ?ltrz0.
+ have:= @ltxx _ _ x1.
by rewrite (lt_le_trans x1b) ?(le_trans _ x1p) ?lerz0.
- case: b1 => [[|b1] | b1]; rewrite !bnd_simp => x1b x2b.
+ case: b2 x2b => [[|b2] | b2] x2b; rewrite bnd_simp.
* by have:= @ltxx _ _ x2; rewrite (lt_le_trans x2b).
* by have -> : x1 = 0; [apply/le_anti/andP | rewrite mul0r].
* have:= @ltxx _ _ x2.
by rewrite (lt_le_trans x2b) ?(le_trans _ x2p) ?lerz0.
+ case: b2 x2b => [[|b2] | b2] x2b; rewrite bnd_simp.
* by have:= @ltxx _ _ x2; rewrite (lt_le_trans x2b).
* by rewrite intrM (le_lt_trans (ler_wpM2r x2p x1b)) ?ltr_pM2l.
* have:= @ltxx _ _ x2.
by rewrite (lt_le_trans x2b) ?(le_trans _ x2p) ?lerz0.
+ have:= @ltxx _ _ x1.
by rewrite (le_lt_trans x1b) ?(lt_le_trans _ x1p) ?ltrz0.
- case: b1 => [[|b1] | b1]; rewrite !bnd_simp => x1b x2b.
+ by have -> : x1 = 0; [apply/le_anti/andP | rewrite mul0r].
+ case: b2 x2b => [[| b2] | b2] x2b; rewrite bnd_simp.
* by have -> : x2 = 0; [apply/le_anti/andP | rewrite mulr0].
* by rewrite intrM ler_pM.
* have:= @ltxx _ _ x2.
by rewrite (le_lt_trans x2b) ?(lt_le_trans _ x2p) ?ltrz0.
+ have:= @ltxx _ _ x1.
by rewrite (le_lt_trans x1b) ?(lt_le_trans _ x1p) ?ltrz0.
Qed.
Lemma BRight_le_mul_boundr b1 b2 (x1 x2 : R) :
(0 <= x1 -> x2 \in Num.real -> BRight 0%Z <= b2 ->
BRight x1 <= num_itv_bound R b1 ->
BRight x2 <= num_itv_bound R b2 ->
BRight (x1 * x2) <= num_itv_bound R (mul_boundr b1 b2))%O.
Proof.
move=> x1ge0 x2r b2ge0 lex1b1 lex2b2.
have /orP[x2ge0 | x2le0] := x2r; first exact: num_itv_mul_boundr.
have lem0 : (BRight (x1 * x2) <= BRight 0%R)%O.
by rewrite bnd_simp mulr_ge0_le0 // ltW.
apply: le_trans lem0 _.
rewrite -(mulr0z 1) BRight_le_num_itv_bound.
apply: mul_boundr_gt0 => //.
by rewrite -(@BRight_le_num_itv_bound R) (le_trans _ lex1b1).
Qed.
Lemma comparable_num_itv_bound (x y : itv_bound int) :
(num_itv_bound R x >=< num_itv_bound R y)%O.
Proof.
by case: x y => [[] x | []] [[] y | []]//; apply/orP;
rewrite !bnd_simp ?ler_int ?ltr_int;
case: leP => xy; apply/orP => //; rewrite ltW ?orbT.
Qed.
Lemma num_itv_bound_min (x y : itv_bound int) :
num_itv_bound R (Order.min x y)
= Order.min (num_itv_bound R x) (num_itv_bound R y).
Proof.
have [lexy | ltyx] := leP x y; [by rewrite !minEle le_num_itv_bound lexy|].
rewrite minElt -if_neg -comparable_leNgt ?le_num_itv_bound ?ltW//.
exact: comparable_num_itv_bound.
Qed.
Lemma num_itv_bound_max (x y : itv_bound int) :
num_itv_bound R (Order.max x y)
= Order.max (num_itv_bound R x) (num_itv_bound R y).
Proof.
have [lexy | ltyx] := leP x y; [by rewrite !maxEle le_num_itv_bound lexy|].
rewrite maxElt -if_neg -comparable_leNgt ?le_num_itv_bound ?ltW//.
exact: comparable_num_itv_bound.
Qed.
Lemma num_spec_mul (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi)
(r := Itv.real2 mul xi yi) :
num_spec r (x%:num * y%:num).
Proof.
rewrite {}/r; case: xi yi x y => [//| [xl xu]] [//| [yl yu]].
case=> [x /=/and3P[xr /= xlx xxu]] [y /=/and3P[yr /= yly yyu]].
rewrite -/(sign (Interval xl xu)) -/(sign (Interval yl yu)).
have ns000 : @Itv.num_sem R `[0, 0] 0 by apply/and3P.
have xyr : x * y \in Num.real by exact: realM.
case: (signP xlx xxu xr) => xlb xub xs.
- by rewrite xs mul0r; case: (signP yly yyu yr).
- case: (signP yly yyu yr) => ylb yub ys.
+ by rewrite ys mulr0.
+ apply/and3P; split=> //=.
* exact: num_itv_mul_boundl xlx yly.
* exact: num_itv_mul_boundr xxu yyu.
+ apply/and3P; split=> //=; rewrite -[x * y]opprK -mulrN.
* by rewrite opp_boundl num_itv_mul_boundr ?oppr_ge0// opp_boundr.
* by rewrite opp_boundr num_itv_mul_boundl ?opp_boundl// opp_bound_ge0.
+ apply/and3P; split=> //=.
* rewrite -[x * y]opprK -mulrN opp_boundl.
by rewrite BRight_le_mul_boundr ?realN ?opp_boundr// opp_bound_gt0 ltW.
* by rewrite BRight_le_mul_boundr// ltW.
- case: (signP yly yyu yr) => ylb yub ys.
+ by rewrite ys mulr0.
+ apply/and3P; split=> //=; rewrite -[x * y]opprK -mulNr.
* rewrite opp_boundl.
by rewrite num_itv_mul_boundr ?oppr_ge0 ?opp_boundr.
* by rewrite opp_boundr num_itv_mul_boundl ?opp_boundl// opp_bound_ge0.
+ apply/and3P; split=> //=; rewrite -mulrNN.
* by rewrite num_itv_mul_boundl ?opp_bound_ge0 ?opp_boundl.
* by rewrite num_itv_mul_boundr ?oppr_ge0 ?opp_boundr.
+ apply/and3P; split=> //=; rewrite -[x * y]opprK.
* rewrite -mulNr opp_boundl BRight_le_mul_boundr ?oppr_ge0 ?opp_boundr//.
exact: ltW.
* rewrite opprK -mulrNN.
by rewrite BRight_le_mul_boundr ?opp_boundr
?oppr_ge0 ?realN ?opp_bound_gt0// ltW.
- case: (signP yly yyu yr) => ylb yub ys.
+ by rewrite ys mulr0.
+ apply/and3P; split=> //=; rewrite mulrC mul_boundrC.
* rewrite -[y * x]opprK -mulrN opp_boundl.
rewrite BRight_le_mul_boundr ?oppr_ge0 ?realN ?opp_boundr//.
by rewrite opp_bound_gt0 ltW.
* by rewrite BRight_le_mul_boundr// ltW.
+ apply/and3P; split=> //=; rewrite mulrC mul_boundrC.
* rewrite -[y * x]opprK -mulNr opp_boundl.
by rewrite BRight_le_mul_boundr ?oppr_ge0 ?opp_boundr// ltW.
* rewrite -mulrNN BRight_le_mul_boundr ?oppr_ge0 ?realN ?opp_boundr//.
by rewrite opp_bound_gt0 ltW.
apply/and3P; rewrite xyr/= num_itv_bound_min num_itv_bound_max.
rewrite (comparable_ge_min _ (comparable_num_itv_bound _ _)).
rewrite (comparable_le_max _ (comparable_num_itv_bound _ _)).
case: (comparable_leP xr) => [x0 | /ltW x0]; split=> //.
- apply/orP; right; rewrite -[x * y]opprK -mulrN opp_boundl.
by rewrite BRight_le_mul_boundr ?realN ?opp_boundr// opp_bound_gt0 ltW.
- by apply/orP; right; rewrite BRight_le_mul_boundr// ltW.
- apply/orP; left; rewrite -[x * y]opprK -mulNr opp_boundl.
by rewrite BRight_le_mul_boundr ?oppr_ge0 ?opp_boundr// ltW.
- apply/orP; left; rewrite -mulrNN.
rewrite BRight_le_mul_boundr ?oppr_ge0 ?realN ?opp_boundr//.
by rewrite opp_bound_gt0 ltW.
Qed.
Canonical mul_inum (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi) :=
Itv.mk (num_spec_mul x y).
Lemma num_spec_min (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi)
(r := Itv.real2 min xi yi) :
num_spec r (Order.min x%:num y%:num).
Proof.
apply: Itv.spec_real2 (Itv.P x) (Itv.P y).
case: x y => [x /= _] [y /= _] => {xi yi r} -[lx ux] [ly uy]/=.
move=> /andP[xr /=/andP[lxx xux]] /andP[yr /=/andP[lyy yuy]].
apply/and3P; split; rewrite ?min_real//= num_itv_bound_min real_BSide_min//.
- apply: (comparable_le_min2 (comparable_num_itv_bound _ _)) => //.
exact: real_comparable.
- apply: (comparable_le_min2 _ (comparable_num_itv_bound _ _)) => //.
exact: real_comparable.
Qed.
Lemma num_spec_max (xi yi : Itv.t) (x : num_def R xi) (y : num_def R yi)
(r := Itv.real2 max xi yi) :
num_spec r (Order.max x%:num y%:num).
Proof.
apply: Itv.spec_real2 (Itv.P x) (Itv.P y).
case: x y => [x /= _] [y /= _] => {xi yi r} -[lx ux] [ly uy]/=.
move=> /andP[xr /=/andP[lxx xux]] /andP[yr /=/andP[lyy yuy]].
apply/and3P; split; rewrite ?max_real//= num_itv_bound_max real_BSide_max//.
- apply: (comparable_le_max2 (comparable_num_itv_bound _ _)) => //.
exact: real_comparable.
- apply: (comparable_le_max2 _ (comparable_num_itv_bound _ _)) => //.
exact: real_comparable.
Qed.
(* We can't directly put an instance on Order.min for R : numDomainType
since we may want instances for other porderType
(typically \bar R or even nat). So we resort on this additional
canonical structure. *)
Record min_max_typ d := MinMaxTyp {
min_max_sort : porderType d;
#[canonical=no]
min_max_sem : interval int -> min_max_sort -> bool;
#[canonical=no]
min_max_minP : forall (xi yi : Itv.t) (x : Itv.def min_max_sem xi)
(y : Itv.def min_max_sem yi),
let: r := Itv.real2 min xi yi in
Itv.spec min_max_sem r (Order.min x%:num y%:num);
#[canonical=no]
min_max_maxP : forall (xi yi : Itv.t) (x : Itv.def min_max_sem xi)
(y : Itv.def min_max_sem yi),
let: r := Itv.real2 max xi yi in
Itv.spec min_max_sem r (Order.max x%:num y%:num);
}.
(* The default instances on porderType, for min... *)
Canonical min_typ_inum d (t : min_max_typ d) (xi yi : Itv.t)
(x : Itv.def (@min_max_sem d t) xi) (y : Itv.def (@min_max_sem d t) yi)
(r := Itv.real2 min xi yi) :=
Itv.mk (min_max_minP x y).
(* ...and for max *)
Canonical max_typ_inum d (t : min_max_typ d) (xi yi : Itv.t)
(x : Itv.def (@min_max_sem d t) xi) (y : Itv.def (@min_max_sem d t) yi)
(r := Itv.real2 min xi yi) :=
Itv.mk (min_max_maxP x y).
(* Instance of the above structure for numDomainType *)
Canonical num_min_max_typ := MinMaxTyp num_spec_min num_spec_max.
Lemma nat_num_spec (i : Itv.t) (n : nat) : nat_spec i n = num_spec i (n%:R : R).
Proof.
case: i => [//| [l u]]; rewrite /= /Itv.num_sem realn/=; congr (_ && _).
- by case: l => [[] l |//]; rewrite !bnd_simp ?pmulrn ?ler_int ?ltr_int.
- by case: u => [[] u |//]; rewrite !bnd_simp ?pmulrn ?ler_int ?ltr_int.
Qed.
Definition natmul_itv (i1 i2 : Itv.t) : Itv.t :=
match i1, i2 with
| Itv.Top, _ => Itv.Top
| _, Itv.Top => Itv.Real `]-oo, +oo[
| Itv.Real i1, Itv.Real i2 => Itv.Real (mul i1 i2)
end.
Arguments natmul_itv /.
Lemma num_spec_natmul (xi ni : Itv.t) (x : num_def R xi) (n : nat_def ni)
(r := natmul_itv xi ni) :
num_spec r (x%:num *+ n%:num).
Proof.
rewrite {}/r; case: xi x ni n => [//| xi] x [| ni] n.
by apply/and3P; case: n%:num => [|?]; rewrite ?mulr0n ?realrMn.
have Pn : num_spec (Itv.Real ni) (n%:num%:R : R).
by case: n => /= n; rewrite [Itv.nat_sem ni n](nat_num_spec (Itv.Real ni)).
rewrite -mulr_natr -[n%:num%:R]/((Itv.Def Pn)%:num).
by rewrite (@num_spec_mul (Itv.Real xi) (Itv.Real ni)).
Qed.
Canonical natmul_inum (xi ni : Itv.t) (x : num_def R xi) (n : nat_def ni) :=
Itv.mk (num_spec_natmul x n).
Lemma num_spec_int (i : Itv.t) (n : int) :
num_spec i n = num_spec i (n%:~R : R).
Proof.
case: i => [//| [l u]]; rewrite /= /Itv.num_sem num_real realz/=.
congr (andb _ _).
- by case: l => [[] l |//]; rewrite !bnd_simp intz ?ler_int ?ltr_int.
- by case: u => [[] u |//]; rewrite !bnd_simp intz ?ler_int ?ltr_int.
Qed.
Lemma num_spec_intmul (xi ii : Itv.t) (x : num_def R xi) (i : num_def int ii)
(r := natmul_itv xi ii) :
num_spec r (x%:num *~ i%:num).
Proof.
rewrite {}/r; case: xi x ii i => [//| xi] x [| ii] i.
by apply/and3P; case: i%:inum => [[|n] | n]; rewrite ?mulr0z ?realN ?realrMn.
have Pi : num_spec (Itv.Real ii) (i%:num%:~R : R).
by case: i => /= i; rewrite [Itv.num_sem ii i](num_spec_int (Itv.Real ii)).
rewrite -mulrzr -[i%:num%:~R]/((Itv.Def Pi)%:num).
by rewrite (@num_spec_mul (Itv.Real xi) (Itv.Real ii)).
Qed.
Canonical intmul_inum (xi ni : Itv.t) (x : num_def R xi) (n : num_def int ni) :=
Itv.mk (num_spec_intmul x n).
Lemma num_itv_bound_keep_pos (op : R -> R) (x : R) b :
{homo op : x / 0 <= x} -> {homo op : x / 0 < x} ->
(num_itv_bound R b <= BLeft x)%O ->
(num_itv_bound R (keep_pos_bound b) <= BLeft (op x))%O.
Proof.
case: b => [[] [] [| b] // | []//] hle hlt; rewrite !bnd_simp.
- exact: hle.
- by move=> blex; apply: le_lt_trans (hlt _ _) => //; apply: lt_le_trans blex.
- exact: hlt.
- by move=> bltx; apply: le_lt_trans (hlt _ _) => //; apply: le_lt_trans bltx.
Qed.
Lemma num_itv_bound_keep_neg (op : R -> R) (x : R) b :
{homo op : x / x <= 0} -> {homo op : x / x < 0} ->
(BRight x <= num_itv_bound R b)%O ->
(BRight (op x) <= num_itv_bound R (keep_neg_bound b))%O.
Proof.
case: b => [[] [[|//] | b] | []//] hge hgt; rewrite !bnd_simp.
- exact: hgt.
- by move=> xltb; apply: hgt; apply: lt_le_trans xltb _; rewrite lerz0.
- exact: hge.
- by move=> xleb; apply: hgt; apply: le_lt_trans xleb _; rewrite ltrz0.
Qed.
Lemma num_spec_inv (i : Itv.t) (x : num_def R i) (r := Itv.real1 inv i) :
num_spec r (x%:num^-1).
Proof.
apply: Itv.spec_real1 (Itv.P x).
case: x => x /= _ [l u] /and3P[xr /= lx xu].
rewrite /Itv.num_sem/= realV xr/=; apply/andP; split.
- apply: num_itv_bound_keep_pos lx.
+ by move=> ?; rewrite invr_ge0.
+ by move=> ?; rewrite invr_gt0.
- apply: num_itv_bound_keep_neg xu.
+ by move=> ?; rewrite invr_le0.
+ by move=> ?; rewrite invr_lt0.
Qed.
Canonical inv_inum (i : Itv.t) (x : num_def R i) := Itv.mk (num_spec_inv x).
Lemma num_itv_bound_exprn_le1 (x : R) n l u :
(num_itv_bound R l <= BLeft x)%O ->
(BRight x <= num_itv_bound R u)%O ->
(BRight (x ^+ n) <= num_itv_bound R (exprn_le1_bound l u))%O.
Proof.
case: u => [bu [[//|[|//]] |//] | []//].
rewrite /exprn_le1_bound; case: (leP _ l) => [lge1 /= |//] lx xu.
rewrite bnd_simp; case: n => [| n]; rewrite ?expr0//.
have xN1 : -1 <= x.
case: l lge1 lx => [[] l | []//]; rewrite !bnd_simp -(@ler_int R).
- exact: le_trans.
- by move=> + /ltW; apply: le_trans.
have x1 : x <= 1 by case: bu xu; rewrite bnd_simp// => /ltW.
have xr : x \is Num.real by exact: ler1_real.
case: (real_ge0P xr) => x0; first by rewrite expr_le1.
rewrite -[x]opprK exprNn; apply: le_trans (ler_piMl _ _) _.
- by rewrite exprn_ge0 ?oppr_ge0 1?ltW.
- suff: -1 <= (-1) ^+ n.+1 :> R /\ (-1) ^+ n.+1 <= 1 :> R => [[]//|].
elim: n => [|n [IHn1 IHn2]]; rewrite ?expr1// ![_ ^+ n.+2]exprS !mulN1r.
by rewrite lerNl opprK lerNl.
- by rewrite expr_le1 ?oppr_ge0 1?lerNl// ltW.
Qed.
Lemma num_spec_exprn (i : Itv.t) (x : num_def R i) n (r := Itv.real1 exprn i) :
num_spec r (x%:num ^+ n).
Proof.
apply: (@Itv.spec_real1 _ _ (fun x => x^+n) _ _ _ _ (Itv.P x)).
case: x => x /= _ [l u] /and3P[xr /= lx xu].
rewrite /Itv.num_sem realX//=; apply/andP; split.
- apply: (@num_itv_bound_keep_pos (fun x => x^+n)) lx.
+ exact: exprn_ge0.
+ exact: exprn_gt0.
- exact: num_itv_bound_exprn_le1 lx xu.
Qed.
Canonical exprn_inum (i : Itv.t) (x : num_def R i) n :=
Itv.mk (num_spec_exprn x n).
Lemma num_spec_exprz (xi ki : Itv.t) (x : num_def R xi) (k : num_def int ki)
(r := Itv.real2 exprz xi ki) :
num_spec r (x%:num ^ k%:num).
Proof.
rewrite {}/r; case: ki k => [|[lk uk]] k; first by case: xi x.
case: xi x => [//|xi x]; rewrite /Itv.real2.
have P : Itv.num_sem
(let 'Interval l _ := xi in Interval (keep_pos_bound l) +oo)
(x%:num ^ k%:num).
case: xi x => lx ux x; apply/and3P; split=> [||//].
have xr : x%:num \is Num.real by case: x => x /=/andP[].
by case: k%:num => n; rewrite ?realV realX.
apply: (@num_itv_bound_keep_pos (fun x => x ^ k%:num));
[exact: exprz_ge0 | exact: exprz_gt0 |].
by case: x => x /=/and3P[].
case: lk k P => [slk [lk | lk] | slk] k P; [|exact: P..].
case: k P => -[k | k] /= => [_ _|]; rewrite -/(exprn xi); last first.
by move=> /and3P[_ /=]; case: slk; rewrite bnd_simp -pmulrn natz.
exact: (@num_spec_exprn (Itv.Real xi)).
Qed.
Canonical exprz_inum (xi ki : Itv.t) (x : num_def R xi) (k : num_def int ki) :=
Itv.mk (num_spec_exprz x k).
Lemma num_spec_norm {V : normedZmodType R} (x : V) :
num_spec (Itv.Real `[0, +oo[) `|x|.
Proof. by apply/and3P; split; rewrite //= ?normr_real ?bnd_simp ?normr_ge0. Qed.
Canonical norm_inum {V : normedZmodType R} (x : V) := Itv.mk (num_spec_norm x).
End NumDomainInstances.
Section RcfInstances.
Context {R : rcfType}.
Definition sqrt_itv (i : Itv.t) : Itv.t :=
match i with
| Itv.Top => Itv.Real `[0%Z, +oo[
| Itv.Real (Interval l u) =>
match l with
| BSide b 0%Z => Itv.Real (Interval (BSide b 0%Z) +oo)
| BSide b (Posz (S _)) => Itv.Real `]0%Z, +oo[
| _ => Itv.Real `[0, +oo[
end
end.
Arguments sqrt_itv /.
Lemma num_spec_sqrt (i : Itv.t) (x : num_def R i) (r := sqrt_itv i) :
num_spec r (Num.sqrt x%:num).
Proof.
have: Itv.num_sem `[0%Z, +oo[ (Num.sqrt x%:num).
by apply/and3P; rewrite /= num_real !bnd_simp sqrtr_ge0.
rewrite {}/r; case: i x => [//| [[bl [l |//] |//] u]] [x /= +] _.
case: bl l => -[| l] /and3P[xr /= bx _]; apply/and3P; split=> //=;
move: bx; rewrite !bnd_simp ?sqrtr_ge0// sqrtr_gt0;
[exact: lt_le_trans | exact: le_lt_trans..].
Qed.
Canonical sqrt_inum (i : Itv.t) (x : num_def R i) := Itv.mk (num_spec_sqrt x).
End RcfInstances.
Section NumClosedFieldInstances.
Context {R : numClosedFieldType}.
Definition sqrtC_itv (i : Itv.t) : Itv.t :=
match i with
| Itv.Top => Itv.Top
| Itv.Real (Interval l u) =>
match l with
| BSide b (Posz _) => Itv.Real (Interval (BSide b 0%Z) +oo)
| _ => Itv.Top
end
end.
Arguments sqrtC_itv /.
Lemma num_spec_sqrtC (i : Itv.t) (x : num_def R i) (r := sqrtC_itv i) :
num_spec r (sqrtC x%:num).
Proof.
rewrite {}/r; case: i x => [//| [l u] [x /=/and3P[xr /= lx xu]]].
case: l lx => [bl [l |//] |[]//] lx; apply/and3P; split=> //=.
by apply: sqrtC_real; case: bl lx => /[!bnd_simp] [|/ltW]; apply: le_trans.
case: bl lx => /[!bnd_simp] lx.
- by rewrite sqrtC_ge0; apply: le_trans lx.
- by rewrite sqrtC_gt0; apply: le_lt_trans lx.
Qed.
Canonical sqrtC_inum (i : Itv.t) (x : num_def R i) := Itv.mk (num_spec_sqrtC x).
End NumClosedFieldInstances.
Section NatInstances.
Local Open Scope nat_scope.
Implicit Type (n : nat).
Lemma nat_spec_zero : nat_spec (Itv.Real `[0, 0]%Z) 0. Proof. by []. Qed.
Canonical zeron_inum := Itv.mk nat_spec_zero.
Lemma nat_spec_add (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi)
(r := Itv.real2 add xi yi) :
nat_spec r (x%:num + y%:num).
Proof.
have Px : num_spec xi (x%:num%:R : int).
by case: x => /= x; rewrite (@nat_num_spec int).
have Py : num_spec yi (y%:num%:R : int).
by case: y => /= y; rewrite (@nat_num_spec int).
rewrite (@nat_num_spec int) natrD.
rewrite -[x%:num%:R]/((Itv.Def Px)%:num) -[y%:num%:R]/((Itv.Def Py)%:num).
exact: num_spec_add.
Qed.
Canonical addn_inum (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi) :=
Itv.mk (nat_spec_add x y).
Lemma nat_spec_succ (i : Itv.t) (n : nat_def i)
(r := Itv.real2 add i (Itv.Real `[1, 1]%Z)) :
nat_spec r (S n%:num).
Proof.
pose i1 := Itv.Real `[1, 1]%Z; have P1 : nat_spec i1 1 by [].
by rewrite -addn1 -[1%N]/((Itv.Def P1)%:num); apply: nat_spec_add.
Qed.
Canonical succn_inum (i : Itv.t) (n : nat_def i) := Itv.mk (nat_spec_succ n).
Lemma nat_spec_double (i : Itv.t) (n : nat_def i) (r := Itv.real2 add i i) :
nat_spec r (n%:num.*2).
Proof. by rewrite -addnn nat_spec_add. Qed.
Canonical double_inum (i : Itv.t) (x : nat_def i) := Itv.mk (nat_spec_double x).
Lemma nat_spec_mul (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi)
(r := Itv.real2 mul xi yi) :
nat_spec r (x%:num * y%:num).
Proof.
have Px : num_spec xi (x%:num%:R : int).
by case: x => /= x; rewrite (@nat_num_spec int).
have Py : num_spec yi (y%:num%:R : int).
by case: y => /= y; rewrite (@nat_num_spec int).
rewrite (@nat_num_spec int) natrM.
rewrite -[x%:num%:R]/((Itv.Def Px)%:num) -[y%:num%:R]/((Itv.Def Py)%:num).
exact: num_spec_mul.
Qed.
Canonical muln_inum (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi) :=
Itv.mk (nat_spec_mul x y).
Lemma nat_spec_exp (i : Itv.t) (x : nat_def i) n (r := Itv.real1 exprn i) :
nat_spec r (x%:num ^ n).
Proof.
have Px : num_spec i (x%:num%:R : int).
by case: x => /= x; rewrite (@nat_num_spec int).
rewrite (@nat_num_spec int) natrX -[x%:num%:R]/((Itv.Def Px)%:num).
exact: num_spec_exprn.
Qed.
Canonical expn_inum (i : Itv.t) (x : nat_def i) n := Itv.mk (nat_spec_exp x n).
Lemma nat_spec_min (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi)
(r := Itv.real2 min xi yi) :
nat_spec r (minn x%:num y%:num).
Proof.
have Px : num_spec xi (x%:num%:R : int).
by case: x => /= x; rewrite (@nat_num_spec int).
have Py : num_spec yi (y%:num%:R : int).
by case: y => /= y; rewrite (@nat_num_spec int).
rewrite (@nat_num_spec int) -minEnat natr_min.
rewrite -[x%:num%:R]/((Itv.Def Px)%:num) -[y%:num%:R]/((Itv.Def Py)%:num).
exact: num_spec_min.
Qed.
Canonical minn_inum (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi) :=
Itv.mk (nat_spec_min x y).
Lemma nat_spec_max (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi)
(r := Itv.real2 max xi yi) :
nat_spec r (maxn x%:num y%:num).
Proof.
have Px : num_spec xi (x%:num%:R : int).
by case: x => /= x; rewrite (@nat_num_spec int).
have Py : num_spec yi (y%:num%:R : int).
by case: y => /= y; rewrite (@nat_num_spec int).
rewrite (@nat_num_spec int) -maxEnat natr_max.
rewrite -[x%:num%:R]/((Itv.Def Px)%:num) -[y%:num%:R]/((Itv.Def Py)%:num).
exact: num_spec_max.
Qed.
Canonical maxn_inum (xi yi : Itv.t) (x : nat_def xi) (y : nat_def yi) :=
Itv.mk (nat_spec_max x y).
Canonical nat_min_max_typ := MinMaxTyp nat_spec_min nat_spec_max.
Lemma nat_spec_factorial (n : nat) : nat_spec (Itv.Real `[1%Z, +oo[) n`!.
Proof. by apply/andP; rewrite bnd_simp lez_nat fact_gt0. Qed.
Canonical factorial_inum n := Itv.mk (nat_spec_factorial n).
End NatInstances.
Section IntInstances.
Lemma num_spec_Posz n : num_spec (Itv.Real `[0, +oo[) (Posz n).
Proof. by apply/and3P; rewrite /= num_real !bnd_simp. Qed.
Canonical Posz_inum n := Itv.mk (num_spec_Posz n).
Lemma num_spec_Negz n : num_spec (Itv.Real `]-oo, (-1)]) (Negz n).
Proof. by apply/and3P; rewrite /= num_real !bnd_simp. Qed.
Canonical Negz_inum n := Itv.mk (num_spec_Negz n).
End IntInstances.
End Instances.
Export (canonicals) Instances.
Section Morph.
Context {R : numDomainType} {i : Itv.t}.
Local Notation nR := (num_def R i).
Implicit Types x y : nR.
Local Notation num := (@num R (@Itv.num_sem R) i).
Lemma num_eq : {mono num : x y / x == y}. Proof. by []. Qed.
Lemma num_le : {mono num : x y / (x <= y)%O}. Proof. by []. Qed.
Lemma num_lt : {mono num : x y / (x < y)%O}. Proof. by []. Qed.
Lemma num_min : {morph num : x y / Order.min x y}.
Proof. by move=> x y; rewrite !minEle num_le -fun_if. Qed.
Lemma num_max : {morph num : x y / Order.max x y}.
Proof. by move=> x y; rewrite !maxEle num_le -fun_if. Qed.
End Morph.
Section MorphNum.
Context {R : numDomainType}.
Lemma num_abs_eq0 (a : R) : (`|a|%:nng == 0%:nng) = (a == 0).
Proof. by rewrite -normr_eq0. Qed.
End MorphNum.
Section MorphReal.
Context {R : numDomainType} {i : interval int}.
Local Notation nR := (num_def R (Itv.Real i)).
Implicit Type x y : nR.
Local Notation num := (@num R (@Itv.num_sem R) i).
Lemma num_le_max a x y :
a <= Num.max x%:num y%:num = (a <= x%:num) || (a <= y%:num).
Proof. by rewrite -comparable_le_max// real_comparable. Qed.
Lemma num_ge_max a x y :
Num.max x%:num y%:num <= a = (x%:num <= a) && (y%:num <= a).
Proof. by rewrite -comparable_ge_max// real_comparable. Qed.
Lemma num_le_min a x y :
a <= Num.min x%:num y%:num = (a <= x%:num) && (a <= y%:num).
Proof. by rewrite -comparable_le_min// real_comparable. Qed.
Lemma num_ge_min a x y :
Num.min x%:num y%:num <= a = (x%:num <= a) || (y%:num <= a).
Proof. by rewrite -comparable_ge_min// real_comparable. Qed.
Lemma num_lt_max a x y :
a < Num.max x%:num y%:num = (a < x%:num) || (a < y%:num).
Proof. by rewrite -comparable_lt_max// real_comparable. Qed.
Lemma num_gt_max a x y :
Num.max x%:num y%:num < a = (x%:num < a) && (y%:num < a).
Proof. by rewrite -comparable_gt_max// real_comparable. Qed.
Lemma num_lt_min a x y :
a < Num.min x%:num y%:num = (a < x%:num) && (a < y%:num).
Proof. by rewrite -comparable_lt_min// real_comparable. Qed.
Lemma num_gt_min a x y :
Num.min x%:num y%:num < a = (x%:num < a) || (y%:num < a).
Proof. by rewrite -comparable_gt_min// real_comparable. Qed.
End MorphReal.
Section MorphGe0.
Context {R : numDomainType}.
Local Notation nR := (num_def R (Itv.Real `[0%Z, +oo[)).
Implicit Type x y : nR.
Local Notation num := (@num R (@Itv.num_sem R) (Itv.Real `[0%Z, +oo[)).
Lemma num_abs_le a x : 0 <= a -> (`|a|%:nng <= x) = (a <= x%:num).
Proof. by move=> a0; rewrite -num_le//= ger0_norm. Qed.
Lemma num_abs_lt a x : 0 <= a -> (`|a|%:nng < x) = (a < x%:num).
Proof. by move=> a0; rewrite -num_lt/= ger0_norm. Qed.
End MorphGe0.
Section ItvNum.
Context (R : numDomainType).
Context (x : R) (l u : itv_bound int).
Context (x_real : x \in Num.real).
Context (l_le_x : (num_itv_bound R l <= BLeft x)%O).
Context (x_le_u : (BRight x <= num_itv_bound R u)%O).
Lemma itvnum_subdef : num_spec (Itv.Real (Interval l u)) x.
Proof. by apply/and3P. Qed.
Definition ItvNum : num_def R (Itv.Real (Interval l u)) := Itv.mk itvnum_subdef.
End ItvNum.
Section ItvReal.
Context (R : realDomainType).
Context (x : R) (l u : itv_bound int).
Context (l_le_x : (num_itv_bound R l <= BLeft x)%O).
Context (x_le_u : (BRight x <= num_itv_bound R u)%O).
Lemma itvreal_subdef : num_spec (Itv.Real (Interval l u)) x.
Proof. by apply/and3P; split; first exact: num_real. Qed.
Definition ItvReal : num_def R (Itv.Real (Interval l u)) :=
Itv.mk itvreal_subdef.
End ItvReal.
Section Itv01.
Context (R : numDomainType).
Context (x : R) (x_ge0 : 0 <= x) (x_le1 : x <= 1).
Lemma itv01_subdef : num_spec (Itv.Real `[0%Z, 1%Z]) x.
Proof. by apply/and3P; split; rewrite ?bnd_simp// ger0_real. Qed.
Definition Itv01 : num_def R (Itv.Real `[0%Z, 1%Z]) := Itv.mk itv01_subdef.
End Itv01.
Section Posnum.
Context (R : numDomainType) (x : R) (x_gt0 : 0 < x).
Lemma posnum_subdef : num_spec (Itv.Real `]0, +oo[) x.
Proof. by apply/and3P; rewrite /= gtr0_real. Qed.
Definition PosNum : {posnum R} := Itv.mk posnum_subdef.
End Posnum.
Section Nngnum.
Context (R : numDomainType) (x : R) (x_ge0 : 0 <= x).
Lemma nngnum_subdef : num_spec (Itv.Real `[0, +oo[) x.
Proof. by apply/and3P; rewrite /= ger0_real. Qed.
Definition NngNum : {nonneg R} := Itv.mk nngnum_subdef.
End Nngnum.
Variant posnum_spec (R : numDomainType) (x : R) :
R -> bool -> bool -> bool -> Type :=
| IsPosnum (p : {posnum R}) : posnum_spec x (p%:num) false true true.
Lemma posnumP (R : numDomainType) (x : R) : 0 < x ->
posnum_spec x x (x == 0) (0 <= x) (0 < x).
Proof.
move=> x_gt0; case: real_ltgt0P (x_gt0) => []; rewrite ?gtr0_real // => _ _.
by rewrite -[x]/(PosNum x_gt0)%:num; constructor.
Qed.
Variant nonneg_spec (R : numDomainType) (x : R) : R -> bool -> Type :=
| IsNonneg (p : {nonneg R}) : nonneg_spec x (p%:num) true.
Lemma nonnegP (R : numDomainType) (x : R) : 0 <= x -> nonneg_spec x x (0 <= x).
Proof. by move=> xge0; rewrite xge0 -[x]/(NngNum xge0)%:num; constructor. Qed.
Section Test1.
Variable R : numDomainType.
Variable x : {i01 R}.
Goal 0%:i01 = 1%:i01 :> {i01 R}.
Proof.
Abort.
Goal (- x%:num)%:itv = (- x%:num)%:itv :> {itv R & `[-1, 0]}.
Proof.
Abort.
Goal (1 - x%:num)%:i01 = x.
Proof.
Abort.
End Test1.
Section Test2.
Variable R : realDomainType.
Variable x y : {i01 R}.
Goal (x%:num * y%:num)%:i01 = x%:num%:i01.
Proof.
Abort.
End Test2.
Module Test3.
Section Test3.
Variable R : realDomainType.
Definition s_of_pq (p q : {i01 R}) : {i01 R} :=
(1 - ((1 - p%:num)%:i01%:num * (1 - q%:num)%:i01%:num))%:i01.
Lemma s_of_p0 (p : {i01 R}) : s_of_pq p 0%:i01 = p.
Proof. by apply/val_inj; rewrite /= subr0 mulr1 subKr. Qed.
End Test3.
End Test3.
|
Smooth.lean
|
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.AlgebraicGeometry.Morphisms.RingHomProperties
import Mathlib.AlgebraicGeometry.Morphisms.FinitePresentation
import Mathlib.RingTheory.RingHom.StandardSmooth
/-!
# Smooth morphisms
A morphism of schemes `f : X ⟶ Y` is smooth (of relative dimension `n`) if for each `x : X` there
exists an affine open neighborhood `V` of `x` and an affine open neighborhood `U` of
`f.base x` with `V ≤ f ⁻¹ᵁ U` such that the induced map `Γ(Y, U) ⟶ Γ(X, V)` is
standard smooth (of relative dimension `n`).
In other words, smooth (resp. smooth of relative dimension `n`) for scheme morphisms is associated
to the property of ring homomorphisms `Locally IsStandardSmooth`
(resp. `Locally (IsStandardSmoothOfRelativeDimension n)`).
## Implementation details
- Our definition is equivalent to defining `IsSmooth` as the associated scheme morphism property of
the property of ring maps induced by `Algebra.Smooth`. The equivalence will follow from the
equivalence of `Locally IsStandardSmooth` and `Algebra.IsSmooth`, but the latter is a (hard) TODO.
The reason why we choose the definition via `IsStandardSmooth`, is because verifying that
`Algebra.IsSmooth` is local in the sense of `RingHom.PropertyIsLocal` is a (hard) TODO.
## Notes
This contribution was created as part of the AIM workshop "Formalizing algebraic geometry" in
June 2024.
-/
noncomputable section
open CategoryTheory
universe t w v u
namespace AlgebraicGeometry
open RingHom
variable (n m : ℕ) {X Y : Scheme.{u}} (f : X ⟶ Y)
/--
A morphism of schemes `f : X ⟶ Y` is smooth if for each `x : X` there
exists an affine open neighborhood `V` of `x` and an affine open neighborhood `U` of
`f.base x` with `V ≤ f ⁻¹ᵁ U` such that the induced map `Γ(Y, U) ⟶ Γ(X, V)` is
standard smooth.
-/
@[mk_iff]
class IsSmooth : Prop where
exists_isStandardSmooth : ∀ (x : X), ∃ (U : Y.affineOpens) (V : X.affineOpens) (_ : x ∈ V.1)
(e : V.1 ≤ f ⁻¹ᵁ U.1), IsStandardSmooth (f.appLE U V e).hom
/-- The property of scheme morphisms `IsSmooth` is associated with the ring
homomorphism property `Locally IsStandardSmooth`. -/
instance : HasRingHomProperty @IsSmooth (Locally IsStandardSmooth) := by
apply HasRingHomProperty.locally_of_iff
· exact isStandardSmooth_localizationPreserves.away
· exact isStandardSmooth_stableUnderCompositionWithLocalizationAway
· intro X Y f
rw [isSmooth_iff]
/-- Being smooth is stable under composition. -/
instance : MorphismProperty.IsStableUnderComposition @IsSmooth :=
HasRingHomProperty.stableUnderComposition <| locally_stableUnderComposition
isStandardSmooth_respectsIso isStandardSmooth_localizationPreserves
isStandardSmooth_stableUnderComposition
/-- The composition of smooth morphisms is smooth. -/
instance isSmooth_comp {Z : Scheme.{u}} (g : Y ⟶ Z) [IsSmooth f] [IsSmooth g] :
IsSmooth (f ≫ g) :=
MorphismProperty.comp_mem _ f g ‹IsSmooth f› ‹IsSmooth g›
/-- Smooth of relative dimension `n` is stable under base change. -/
lemma isSmooth_isStableUnderBaseChange : MorphismProperty.IsStableUnderBaseChange @IsSmooth :=
HasRingHomProperty.isStableUnderBaseChange <| locally_isStableUnderBaseChange
isStandardSmooth_respectsIso isStandardSmooth_isStableUnderBaseChange
/--
A morphism of schemes `f : X ⟶ Y` is smooth of relative dimension `n` if for each `x : X` there
exists an affine open neighborhood `V` of `x` and an affine open neighborhood `U` of
`f.base x` with `V ≤ f ⁻¹ᵁ U` such that the induced map `Γ(Y, U) ⟶ Γ(X, V)` is
standard smooth of relative dimension `n`.
-/
@[mk_iff]
class IsSmoothOfRelativeDimension : Prop where
exists_isStandardSmoothOfRelativeDimension : ∀ (x : X), ∃ (U : Y.affineOpens)
(V : X.affineOpens) (_ : x ∈ V.1) (e : V.1 ≤ f ⁻¹ᵁ U.1),
IsStandardSmoothOfRelativeDimension n (f.appLE U V e).hom
/-- If `f` is smooth of any relative dimension, it is smooth. -/
lemma IsSmoothOfRelativeDimension.isSmooth [IsSmoothOfRelativeDimension n f] : IsSmooth f where
exists_isStandardSmooth x := by
obtain ⟨U, V, hx, e, hf⟩ := exists_isStandardSmoothOfRelativeDimension (n := n) (f := f) x
exact ⟨U, V, hx, e, hf.isStandardSmooth⟩
/-- The property of scheme morphisms `IsSmoothOfRelativeDimension n` is associated with the ring
homomorphism property `Locally (IsStandardSmoothOfRelativeDimension n)`. -/
instance : HasRingHomProperty (@IsSmoothOfRelativeDimension n)
(Locally (IsStandardSmoothOfRelativeDimension n)) := by
apply HasRingHomProperty.locally_of_iff
· exact (isStandardSmoothOfRelativeDimension_localizationPreserves n).away
· exact isStandardSmoothOfRelativeDimension_stableUnderCompositionWithLocalizationAway n
· intro X Y f
rw [isSmoothOfRelativeDimension_iff]
/-- Smooth of relative dimension `n` is stable under base change. -/
lemma isSmoothOfRelativeDimension_isStableUnderBaseChange :
MorphismProperty.IsStableUnderBaseChange (@IsSmoothOfRelativeDimension n) :=
HasRingHomProperty.isStableUnderBaseChange <| locally_isStableUnderBaseChange
isStandardSmoothOfRelativeDimension_respectsIso
(isStandardSmoothOfRelativeDimension_isStableUnderBaseChange n)
/-- Open immersions are smooth of relative dimension `0`. -/
instance (priority := 900) [IsOpenImmersion f] : IsSmoothOfRelativeDimension 0 f :=
HasRingHomProperty.of_isOpenImmersion
(locally_holdsForLocalizationAway <|
isStandardSmoothOfRelativeDimension_holdsForLocalizationAway).containsIdentities
/-- Open immersions are smooth. -/
instance (priority := 900) [IsOpenImmersion f] : IsSmooth f :=
IsSmoothOfRelativeDimension.isSmooth 0 f
/-- If `f` is smooth of relative dimension `n` and `g` is smooth of relative dimension
`m`, then `f ≫ g` is smooth of relative dimension `n + m`. -/
instance isSmoothOfRelativeDimension_comp {Z : Scheme.{u}} (g : Y ⟶ Z)
[hf : IsSmoothOfRelativeDimension n f] [hg : IsSmoothOfRelativeDimension m g] :
IsSmoothOfRelativeDimension (n + m) (f ≫ g) where
exists_isStandardSmoothOfRelativeDimension x := by
obtain ⟨U₂, V₂, hfx₂, e₂, hf₂⟩ := hg.exists_isStandardSmoothOfRelativeDimension (f.base x)
obtain ⟨U₁', V₁', hx₁', e₁', hf₁'⟩ := hf.exists_isStandardSmoothOfRelativeDimension x
obtain ⟨r, s, hx₁, e₁, hf₁⟩ := exists_basicOpen_le_appLE_of_appLE_of_isAffine
(isStandardSmoothOfRelativeDimension_stableUnderCompositionWithLocalizationAway n).right
(isStandardSmoothOfRelativeDimension_localizationPreserves n).away
x V₂ U₁' V₁' V₁' hx₁' hx₁' e₁' hf₁' hfx₂
have e : X.basicOpen s ≤ (f ≫ g) ⁻¹ᵁ U₂ :=
le_trans e₁ <| f.preimage_le_preimage_of_le <| le_trans (Y.basicOpen_le r) e₂
have heq : (f ≫ g).appLE U₂ (X.basicOpen s) e = g.appLE U₂ V₂ e₂ ≫
CommRingCat.ofHom (algebraMap Γ(Y, V₂) Γ(Y, Y.basicOpen r)) ≫
f.appLE (Y.basicOpen r) (X.basicOpen s) e₁ := by
rw [RingHom.algebraMap_toAlgebra, CommRingCat.ofHom_hom,
g.appLE_map_assoc, Scheme.appLE_comp_appLE]
refine ⟨U₂, ⟨X.basicOpen s, V₁'.2.basicOpen s⟩, hx₁, e, heq ▸ ?_⟩
apply IsStandardSmoothOfRelativeDimension.comp ?_ hf₂
haveI : IsLocalization.Away r Γ(Y, Y.basicOpen r) := V₂.2.isLocalization_basicOpen r
exact (isStandardSmoothOfRelativeDimension_stableUnderCompositionWithLocalizationAway n).left
_ r _ hf₁
instance {Z : Scheme.{u}} (g : Y ⟶ Z) [IsSmoothOfRelativeDimension 0 f]
[IsSmoothOfRelativeDimension 0 g] :
IsSmoothOfRelativeDimension 0 (f ≫ g) :=
inferInstanceAs <| IsSmoothOfRelativeDimension (0 + 0) (f ≫ g)
/-- Smooth of relative dimension `0` is multiplicative. -/
instance : MorphismProperty.IsMultiplicative (@IsSmoothOfRelativeDimension 0) where
id_mem _ := inferInstance
comp_mem _ _ _ _ := inferInstance
/-- Smooth morphisms are locally of finite presentation. -/
instance (priority := 100) [hf : IsSmooth f] : LocallyOfFinitePresentation f := by
rw [HasRingHomProperty.eq_affineLocally @LocallyOfFinitePresentation]
rw [HasRingHomProperty.eq_affineLocally @IsSmooth] at hf
refine affineLocally_le (fun hf ↦ ?_) f hf
apply RingHom.locally_of_locally (Q := RingHom.FinitePresentation) at hf
· rwa [RingHom.locally_iff_of_localizationSpanTarget finitePresentation_respectsIso
finitePresentation_ofLocalizationSpanTarget] at hf
· introv hf
algebraize [f]
-- TODO: why is `algebraize` not generating the following instance?
haveI : Algebra.IsStandardSmooth R S := hf
exact this.finitePresentation
end AlgebraicGeometry
|
Imo2024Q3.lean
|
/-
Copyright (c) 2024 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.Order.Sub.Basic
import Mathlib.Algebra.Ring.Parity
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Data.Nat.Nth
import Mathlib.Tactic.ApplyFun
/-!
# IMO 2024 Q3
Let $a_1, a_2, a_3, \ldots$ be an infinite sequence of positive integers, and let $N$ be a
positive integer. Suppose that, for each $n > N$, $a_n$ is equal to the number of times
$a_{n-1}$ appears in the list $a_1, a_2, \ldots, a_{n-1}$.
Prove that at least one of the sequences $a_1, a_3, a_5, \ldots$ and $a_2, a_4, a_6, \ldots$
is eventually periodic.
We follow Solution 1 from the
[official solutions](https://www.imo2024.uk/s/IMO2024-solutions-updated.pdf). We show that
the positive integers up to some positive integer $k$ (referred to as small numbers) all appear
infinitely often in the given sequence while all larger positive integers appear only finitely
often and then that the sequence eventually alternates between small numbers and larger integers.
A further detailed analysis of the eventual behavior of the sequence ends up showing that the
sequence of small numbers is eventually periodic with period at most $k$ (in fact exactly $k$).
-/
open scoped Finset
namespace Imo2024Q3
/-- The condition of the problem. Following usual Lean conventions, this is expressed with
indices starting from 0, rather than from 1 as in the informal statement (but `N` remains as the
index of the last term for which `a n` is not defined in terms of previous terms). -/
def Condition (a : ℕ → ℕ) (N : ℕ) : Prop :=
(∀ i, 0 < a i) ∧ ∀ n, N < n → a n = #{i ∈ Finset.range n | a i = a (n - 1)}
/-- The property of a sequence being eventually periodic. -/
def EventuallyPeriodic (b : ℕ → ℕ) : Prop := ∃ p M, 0 < p ∧ ∀ m, M ≤ m → b (m + p) = b m
/-! ### Definitions and lemmas about the sequence that do not actually need the condition of
the problem -/
/-- A number greater than any of the initial terms `a 0` through `a N` (otherwise arbitrary). -/
def M (a : ℕ → ℕ) (N : ℕ) : ℕ := (Finset.range (N + 1)).sup a + 1
lemma M_pos (a : ℕ → ℕ) (N : ℕ) : 0 < M a N :=
Nat.add_one_pos _
lemma one_le_M (a : ℕ → ℕ) (N : ℕ) : 1 ≤ M a N :=
Nat.lt_iff_add_one_le.1 (M_pos a N)
lemma apply_lt_M_of_le_N (a : ℕ → ℕ) {N i : ℕ} (h : i ≤ N) : a i < M a N :=
Nat.lt_add_one_iff.2 (Finset.le_sup (by grind))
lemma N_lt_of_M_le_apply {a : ℕ → ℕ} {N i : ℕ} (h : M a N ≤ a i) : N < i := by
by_contra! hi
exact Nat.not_succ_le_self _ (h.trans (Finset.le_sup (by grind)))
lemma ne_zero_of_M_le_apply {a : ℕ → ℕ} {N i : ℕ} (h : M a N ≤ a i) : i ≠ 0 :=
Nat.ne_zero_of_lt (N_lt_of_M_le_apply h)
lemma apply_lt_of_M_le_apply {a : ℕ → ℕ} {N i j : ℕ} (hi : M a N ≤ a i) (hj : j ≤ N) :
a j < a i :=
(apply_lt_M_of_le_N a hj).trans_le hi
lemma apply_ne_of_M_le_apply {a : ℕ → ℕ} {N i j : ℕ} (hi : M a N ≤ a i) (hj : j ≤ N) :
a j ≠ a i :=
(apply_lt_of_M_le_apply hi hj).ne
lemma toFinset_card_pos {a : ℕ → ℕ} {i : ℕ} (hf : {j | a j = a i}.Finite) : 0 < #hf.toFinset :=
Finset.card_pos.mpr ((Set.Finite.toFinset_nonempty _).mpr ⟨i, rfl⟩)
lemma apply_nth_zero (a : ℕ → ℕ) (i : ℕ) : a (Nat.nth (a · = a i) 0) = a i :=
Nat.nth_mem (p := (a · = a i)) 0 toFinset_card_pos
lemma map_add_one_range (p : ℕ → Prop) [DecidablePred p] (n : ℕ) (h0 : ¬ p 0) :
{x ∈ Finset.range n | p (x + 1)}.map ⟨(· + 1), add_left_injective 1⟩ =
{x ∈ Finset.range (n + 1) | p x } := by
ext x
simp only [Finset.mem_map]
constructor
· aesop
· intro hx
use x - 1
cases x <;> simp_all
namespace Condition
/-! ### The basic structure of the sequence, eventually alternating small and large numbers -/
variable {a : ℕ → ℕ} {N : ℕ} (hc : Condition a N)
include hc
protected lemma pos (n : ℕ) : 0 < a n := hc.1 n
@[simp] lemma apply_ne_zero (n : ℕ) : a n ≠ 0 :=
(hc.pos _).ne'
lemma one_le_apply (n : ℕ) : 1 ≤ a n :=
Nat.one_le_iff_ne_zero.2 (hc.apply_ne_zero n)
lemma apply_eq_card {n : ℕ} (h : N < n) : a n = #{i ∈ Finset.range n | a i = a (n - 1)} :=
hc.2 n h
lemma apply_add_one_eq_card {n : ℕ} (h : N ≤ n) :
a (n + 1) = #{i ∈ Finset.range (n + 1) | a i = a n} := by
rw [hc.apply_eq_card (Nat.lt_add_one_of_le h)]
simp
@[simp] lemma nth_apply_eq_zero (n : ℕ) : Nat.nth (a · = 0) n = 0 := by
convert Nat.nth_false _ with i
simp only [(hc.pos i).ne']
lemma nth_apply_add_one_eq {n : ℕ} (h : N ≤ n) : Nat.nth (a · = a n) (a (n + 1) - 1) = n := by
rw [hc.apply_add_one_eq_card h]
nth_rw 5 [← Nat.nth_count (p := (a · = a n)) rfl]
simp [Finset.range_add_one, Finset.filter_insert, Nat.count_eq_card_filter_range]
lemma apply_nth_add_one_eq {m n : ℕ} (hfc : ∀ hf : {i | a i = m}.Finite, n < #hf.toFinset)
(hn : N ≤ Nat.nth (a · = m) n) : a (Nat.nth (a · = m) n + 1) = n + 1 := by
rw [hc.apply_eq_card (Nat.lt_add_one_of_le hn), add_tsub_cancel_right,
← Nat.count_eq_card_filter_range, Nat.nth_mem n hfc, Nat.count_nth_succ hfc]
lemma apply_nth_add_one_eq_of_infinite {m n : ℕ} (hi : {i | a i = m}.Infinite)
(hn : N ≤ Nat.nth (a · = m) n) : a (Nat.nth (a · = m) n + 1) = n + 1 :=
hc.apply_nth_add_one_eq (fun hf ↦ absurd hf hi) hn
lemma apply_nth_add_one_eq_of_lt {m n : ℕ} (hn : N < Nat.nth (a · = m) n) :
a (Nat.nth (a · = m) n + 1) = n + 1 := by
refine hc.apply_nth_add_one_eq ?_ hn.le
by_contra! hf
have := Nat.nth_eq_zero.2 (.inr hf)
omega
lemma lt_toFinset_card {j : ℕ} (h : M a N ≤ a (j + 1)) (hf : {i | a i = a j}.Finite) :
M a N - 1 < #hf.toFinset := by
rw [Nat.sub_lt_iff_lt_add' (M_pos _ _), Nat.lt_one_add_iff]
exact (hc.apply_eq_card (N_lt_of_M_le_apply h) ▸ h).trans (Finset.card_le_card (by simp))
lemma nth_ne_zero_of_M_le_of_lt {i k : ℕ} (hi : M a N ≤ a i) (hk : k < a (i + 1)) :
Nat.nth (a · = a i) k ≠ 0 :=
Nat.nth_ne_zero_anti (apply_ne_of_M_le_apply hi (Nat.zero_le _)) (by omega)
(hc.nth_apply_add_one_eq (N_lt_of_M_le_apply hi).le ▸ ne_zero_of_M_le_apply hi)
lemma apply_add_one_lt_of_apply_eq {i j : ℕ} (hi : N ≤ i) (hij : i < j) (ha : a i = a j) :
a (i + 1) < a (j + 1) := by
rw [hc.apply_add_one_eq_card hi, hc.apply_add_one_eq_card (by omega), ha]
refine Finset.card_lt_card (Finset.ssubset_def.mp ⟨Finset.filter_subset_filter _
(by simp [hij.le]), Finset.not_subset.mpr ⟨j, ?_⟩⟩)
simp only [Finset.mem_filter, Finset.mem_range, lt_add_iff_pos_right, and_true]
omega
lemma apply_add_one_ne_of_apply_eq {i j : ℕ} (hi : N ≤ i) (hj : N ≤ j) (hij : i ≠ j)
(ha : a i = a j) : a (i + 1) ≠ a (j + 1) :=
hij.lt_or_gt.elim (fun h ↦ (hc.apply_add_one_lt_of_apply_eq hi h ha).ne) fun h ↦
(hc.apply_add_one_lt_of_apply_eq hj h ha.symm).ne'
lemma exists_infinite_setOf_apply_eq : ∃ m, {i | a i = m}.Infinite := by
by_contra hi
have hr : (Set.range a).Infinite := by
contrapose! hi with hr
rw [Set.not_infinite, ← Set.finite_coe_iff] at hr
obtain ⟨n, hn⟩ := Finite.exists_infinite_fiber (Set.rangeFactorization a)
rw [Set.infinite_coe_iff, Set.preimage] at hn
simp only [Set.mem_singleton_iff, Set.rangeFactorization, Subtype.ext_iff] at hn
exact ⟨↑n, hn⟩
simp only [not_exists, Set.not_infinite] at hi
have hinj : Set.InjOn (fun i ↦ Nat.nth (a · = i) 0 + 1) (Set.range a \ Set.Ico 0 (M a N)) := by
rintro _ ⟨⟨_, rfl⟩, hi⟩ _ ⟨⟨_, rfl⟩, hj⟩ h
simp only [Set.mem_Ico, zero_le, true_and, not_lt] at hi hj
simp only [add_left_inj] at h
convert congr(a $h) using 1 <;> simp [apply_nth_zero]
refine Set.not_infinite.2 (hi 1) (Set.infinite_of_injOn_mapsTo hinj (fun i hi ↦ ?_)
(hr.diff (Set.finite_Ico _ _)))
simp only [Set.mem_diff, Set.mem_range, Set.mem_Ico, zero_le, true_and, not_lt] at hi
rcases hi with ⟨⟨_, rfl⟩, hi⟩
exact hc.apply_nth_add_one_eq toFinset_card_pos
(N_lt_of_M_le_apply (a := a) (by simp only [apply_nth_zero, hi])).le
lemma nonempty_setOf_infinite_setOf_apply_eq : {m | {i | a i = m}.Infinite}.Nonempty :=
hc.exists_infinite_setOf_apply_eq
lemma injOn_setOf_apply_add_one_eq_of_M_le {n : ℕ} (h : M a N ≤ n) :
Set.InjOn a {i | a (i + 1) = n} := by
intro i hi j hj hij
have hi' := hi ▸ hc.nth_apply_add_one_eq (Nat.lt_add_one_iff.mp (N_lt_of_M_le_apply (hi ▸ h)))
have hj' := hj ▸ hc.nth_apply_add_one_eq (Nat.lt_add_one_iff.mp (N_lt_of_M_le_apply (hj ▸ h)))
rw [← hi', ← hj', hij]
lemma empty_consecutive_apply_ge_M : {i | M a N ≤ a i ∧ M a N ≤ a (i + 1)} = ∅ := by
rw [Set.eq_empty_iff_forall_notMem]
intro i
induction i using Nat.strong_induction_on with | h i ih =>
-- Let i be the first index where both `a i` and `a (i + 1)` are at least M.
rintro ⟨hi1, hi2⟩
have hi : ∀ j < i, M a N ≤ a j → a (j + 1) < M a N := by simp_all
-- t is the set of indices before an appearance of the integer (a i). For each j ∈ t, (a j)
-- is the (a i)th appearance of that value, so each such value before index i appears at least
-- M times before that index; since (a i) is the (at least) Mth appearance of that value, there
-- are at least M positive integers appearing M times before (a i), a contradiction because one of
-- those must be at least M.
let t : Finset ℕ := {j ∈ Finset.range i | a (j + 1) = a i}
let t' : Finset ℕ := {j ∈ Finset.range (i + 1) | a j = a i}
have t_map_eq_t' : t.map ⟨(· + 1), add_left_injective 1⟩ = t' := by
refine map_add_one_range (a · = a i) i ?_
intro H
rw [←H, M] at hi1
have a0_le : a 0 ≤ (Finset.range (N + 1)).sup a := Finset.le_sup (by simp)
omega
have card_t_eq_card_t' : #t = #t' := by simp [← t_map_eq_t', t]
have htM : ∀ j ∈ t, a j < M a N := by
intro j hj
simp only [t, Finset.mem_filter, Finset.mem_range] at hj
grind
have N_le_i : N ≤ i := by
unfold M at hi1
by_contra! HH
have i_in_range : i ∈ Finset.range (N + 1) := by rw [Finset.mem_range]; omega
have ai_le_sup : a i ≤ (Finset.range (N + 1)).sup a := Finset.le_sup i_in_range
omega
have ht' : a (i + 1) = #t' := hc.apply_add_one_eq_card N_le_i
rw [← card_t_eq_card_t'] at ht'
have ht'inj : Set.InjOn a t := by
refine (hc.injOn_setOf_apply_add_one_eq_of_M_le hi1).mono ?_
simp_all [t, t']
have card_image_eq_card_t : #(Finset.image a t) = #t := Finset.card_image_of_injOn ht'inj
have card_image_lt_M : #(Finset.image a t) < M a N := by
refine (Finset.card_le_card (t := Finset.Ico 1 (M a N)) ?_).trans_lt ?_
· simp only [Finset.subset_iff, Finset.mem_image, Finset.mem_Ico, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
exact fun j hj ↦ ⟨hc.pos _, htM j hj⟩
· simpa using M_pos a N
omega
lemma card_lt_M_of_M_le {n : ℕ} (h : M a N ≤ n) :
∃ hf : {i | a i = n}.Finite, #hf.toFinset < M a N := by
have := empty_consecutive_apply_ge_M hc
contrapose! this with hin
use Nat.nth (a · = n) (M a N - 1)
have hin' := fun hf ↦ Nat.sub_one_lt_of_le (M_pos a N) (hin hf)
have ha : M a N ≤ a (Nat.nth (a · = n) (M a N - 1)) := (Nat.nth_mem _ hin').symm ▸ h
refine ⟨ha, ?_⟩
suffices H : a (Nat.nth (fun x ↦ a x = n) (M a N - 1) + 1) = M a N from Nat.le_of_eq H.symm
convert hc.apply_nth_add_one_eq hin' (N_lt_of_M_le_apply ha).le using 1
lemma bddAbove_setOf_infinite_setOf_apply_eq : BddAbove {m | {i | a i = m}.Infinite} := by
refine ⟨M a N, fun x hi ↦ ?_⟩
by_contra hx
exact hi (hc.card_lt_M_of_M_le (not_le.mp hx).le).1
lemma infinite_setOf_apply_eq_anti {j k : ℕ} (hj : 0 < j) (hk : {i | a i = k}.Infinite)
(hjk : j ≤ k) : {i | a i = j}.Infinite := by
have hk' : {i | a (i + 1) = k}.Infinite := by
have hinj : Set.InjOn (· + 1) {i | a (i + 1) = k} := (add_left_injective _).injOn
rw [← Set.infinite_image_iff hinj]
have hk0 : ({i | a i = k} \ {0}).Infinite := hk.diff (Set.finite_singleton _)
convert hk0 using 1
ext i
simp only [Set.mem_image, Set.mem_setOf_eq, Set.mem_diff, Set.mem_singleton_iff]
refine ⟨?_, ?_⟩
· rintro ⟨j, rfl, rfl⟩
simp
· rintro ⟨rfl, h⟩
exact ⟨i - 1, by simp [(by omega : i - 1 + 1 = i)]⟩
have hinj : Set.InjOn (fun x ↦ Nat.nth (a · = a x) (j - 1) + 1)
({i | a (i + 1) = k} \ Set.Ico 0 N) := by
intro x hx y hy h
simp only [Set.mem_diff, Set.mem_setOf_eq, Set.mem_Ico, zero_le, true_and, not_lt] at hx hy
rcases hx with ⟨hxk, hNx⟩
rcases hy with ⟨hyk, hNy⟩
simp only [add_left_inj] at h
have hxk' : Nat.nth (a · = a x) (k - 1) = x := by rw [← hxk, hc.nth_apply_add_one_eq hNx]
have hyk' : Nat.nth (a · = a y) (k - 1) = y := by rw [← hyk, hc.nth_apply_add_one_eq hNy]
have hjk' : j - 1 ≤ k - 1 := by omega
apply_fun a at hxk' hyk'
have hyj : a (Nat.nth (a · = a y) (j - 1)) = a y :=
Nat.nth_mem_anti (p := (a · = a y)) hjk' hyk'
rw [← h, Nat.nth_mem_anti (p := (a · = a x)) hjk' hxk'] at hyj
by_contra hxy
exact hc.apply_add_one_ne_of_apply_eq hNx hNy hxy hyj (hyk ▸ hxk)
have hk'' : (_ \ Set.Ico 0 (N + 2)).Infinite :=
((Set.infinite_image_iff hinj).mpr (hk'.diff (Set.finite_Ico _ _))).diff (Set.finite_Ico _ _)
refine hk''.mono fun _ hi ↦ ?_
simp only [Set.mem_image, Set.mem_diff, Set.mem_setOf_eq, Set.mem_Ico, zero_le, true_and,
not_lt] at hi
rcases hi with ⟨⟨x, -, rfl⟩, _⟩
rw [Set.mem_setOf_eq, hc.apply_nth_add_one_eq_of_lt (by omega), Nat.sub_add_cancel hj]
/-! ### The definitions of small, medium and big numbers and the eventual alternation -/
variable (a)
/-- The largest number to appear infinitely often. -/
noncomputable def k : ℕ := sSup {m | {i | a i = m}.Infinite}
/-- Small numbers are those that are at most `k` (that is, those that appear infinitely often). -/
def Small (j : ℕ) : Prop := j ≤ k a
variable {a}
lemma infinite_setOf_apply_eq_k : {i | a i = k a}.Infinite :=
Nat.sSup_mem hc.nonempty_setOf_infinite_setOf_apply_eq hc.bddAbove_setOf_infinite_setOf_apply_eq
lemma infinite_setOf_apply_eq_iff_small {j : ℕ} (hj : 0 < j) :
{i | a i = j}.Infinite ↔ Small a j :=
⟨fun h ↦ le_csSup hc.bddAbove_setOf_infinite_setOf_apply_eq h,
fun h ↦ hc.infinite_setOf_apply_eq_anti hj hc.infinite_setOf_apply_eq_k h⟩
lemma finite_setOf_apply_eq_iff_not_small {j : ℕ} (hj : 0 < j) :
{i | a i = j}.Finite ↔ ¬Small a j := by
simpa only [Set.not_infinite] using (hc.infinite_setOf_apply_eq_iff_small hj).not
lemma finite_setOf_apply_eq_k_add_one : {i | a i = k a + 1}.Finite := by
rw [hc.finite_setOf_apply_eq_iff_not_small (by omega), Small]
omega
/-- There are only finitely many `m` that appear more than `k` times. -/
lemma finite_setOf_k_lt_card : {m | ∀ hf : {i | a i = m}.Finite, k a < #hf.toFinset}.Finite := by
rw [← Set.finite_image_iff]
· refine Set.Finite.of_diff (hc.finite_setOf_apply_eq_k_add_one.subset fun i hi ↦ ?_)
(Set.finite_Iic N)
simp only [Set.mem_diff, Set.mem_image, Set.mem_setOf_eq, Set.mem_Iic, not_le] at hi
rcases hi with ⟨⟨j, hjf, rfl⟩, hNi⟩
rw [Set.mem_setOf_eq, hc.apply_nth_add_one_eq hjf (by omega)]
· intro i hi j hj hij
simp only [add_left_inj] at hij
apply_fun a at hij
rwa [Nat.nth_mem _ hi, Nat.nth_mem _ hj] at hij
lemma bddAbove_setOf_k_lt_card : BddAbove {m | ∀ hf : {i | a i = m}.Finite, k a < #hf.toFinset} :=
hc.finite_setOf_k_lt_card.bddAbove
lemma k_pos : 0 < k a := by
by_contra! hn
apply nonpos_iff_eq_zero.mp hn ▸ hc.infinite_setOf_apply_eq_k
convert Set.finite_empty
ext i
simp [(hc.pos i).ne']
lemma small_one : Small a 1 := by
by_contra hns
simp only [Small, not_le, Nat.lt_one_iff, hc.k_pos.ne'] at hns
lemma infinite_setOf_apply_eq_one : {i | a i = 1}.Infinite :=
(hc.infinite_setOf_apply_eq_iff_small (by decide)).mpr hc.small_one
variable (a)
/-- The largest number to appear more than `k` times. -/
noncomputable def l : ℕ := sSup {m | ∀ hf : {i | a i = m}.Finite, k a < #hf.toFinset}
/-- Medium numbers are those that are more than `k` but at most `l` (and include all numbers
appearing finitely often but more than `k` times). -/
def Medium (j : ℕ) : Prop := k a < j ∧ j ≤ l a
/-- Big numbers are those greater than `l` (thus, appear at most `k` times). -/
def Big (j : ℕ) : Prop := l a < j
variable {a}
lemma k_le_l : k a ≤ l a :=
le_csSup hc.bddAbove_setOf_k_lt_card (fun hf ↦ absurd hf hc.infinite_setOf_apply_eq_k)
lemma k_lt_of_big {j : ℕ} (h : Big a j) : k a < j :=
hc.k_le_l.trans_lt h
lemma pos_of_big {j : ℕ} (h : Big a j) : 0 < j :=
(Nat.zero_le _).trans_lt (hc.k_lt_of_big h)
lemma not_small_of_big {j : ℕ} (h : Big a j) : ¬Small a j := by simp [Small, hc.k_lt_of_big h]
lemma exists_card_le_of_big {j : ℕ} (h : Big a j) :
∃ hf : {i | a i = j}.Finite, #hf.toFinset ≤ k a := by
have hns := hc.not_small_of_big h
rw [← hc.finite_setOf_apply_eq_iff_not_small (hc.pos_of_big h)] at hns
use hns
by_contra! hlt
exact notMem_of_csSup_lt h hc.bddAbove_setOf_k_lt_card fun _ ↦ hlt
variable (a N)
/-- `N'aux` is such that, by position `N'aux`, every medium number has made all its appearances
and every small number has appeared more than max(k, N+1) times. -/
noncomputable def N'aux : ℕ :=
sSup {i | Medium a (a i)} ⊔ sSup ((fun i ↦ Nat.nth (a · = i) (k a ⊔ (N + 1))) '' Set.Iic (k a))
/-- `N'` is such that, by position `N'`, every medium number has made all its appearances
and every small number has appeared more than max(k, N+1) times; furthermore, `a N'` is small
(which means that every subsequent big number is preceded by a small number). -/
noncomputable def N' : ℕ := by
classical
exact N'aux a N + (if Small a (a (N'aux a N + 1)) then 1 else 2)
variable {a N}
lemma not_medium_of_N'aux_lt {j : ℕ} (h : N'aux a N < j) : ¬Medium a (a j) := by
let s : Set ℕ := ⋃ i ∈ Set.Ioc (k a) (l a), {j | a j = i}
have hf : s.Finite := by
refine (Set.finite_Ioc _ _).biUnion ?_
rintro i ⟨hk, -⟩
rwa [hc.finite_setOf_apply_eq_iff_not_small (by omega), Small, not_le]
exact fun hm ↦ notMem_of_csSup_lt (le_sup_left.trans_lt h)
(hf.subset fun i hi ↦ (by simpa [s] using hi)).bddAbove hm
lemma small_or_big_of_N'aux_lt {j : ℕ} (h : N'aux a N < j) : Small a (a j) ∨ Big a (a j) := by
have _ := hc.not_medium_of_N'aux_lt h
rw [Small, Medium, Big] at *
omega
lemma small_or_big_of_N'_le {j : ℕ} (h : N' a N ≤ j) : Small a (a j) ∨ Big a (a j) := by
refine hc.small_or_big_of_N'aux_lt ?_
rw [N'] at h
split_ifs at h <;> omega
omit hc
lemma nth_sup_k_N_add_one_le_N'aux_of_small {j : ℕ} (h : Small a j) :
Nat.nth (a · = j) (k a ⊔ (N + 1)) ≤ N'aux a N := by
by_contra! hn
exact notMem_of_csSup_lt (le_sup_right.trans_lt hn) ((Set.finite_Iic _).image _).bddAbove
⟨j, h, rfl⟩
include hc
lemma nth_sup_k_le_N'aux_of_small {j : ℕ} (h : Small a j) :
Nat.nth (a · = j) (k a) ≤ N'aux a N :=
match j with
| 0 => by simp only [hc.nth_apply_eq_zero, zero_le]
| j + 1 => ((Nat.nth_le_nth ((hc.infinite_setOf_apply_eq_iff_small (Nat.zero_lt_succ j)).mpr h)).2
le_sup_left).trans (nth_sup_k_N_add_one_le_N'aux_of_small h)
lemma nth_sup_N_add_one_le_N'aux_of_small {j : ℕ} (h : Small a j) :
Nat.nth (a · = j) (N + 1) ≤ N'aux a N :=
match j with
| 0 => by simp only [hc.nth_apply_eq_zero, zero_le]
| j + 1 => ((Nat.nth_le_nth ((hc.infinite_setOf_apply_eq_iff_small (Nat.zero_lt_succ j)).mpr h)).2
le_sup_right).trans (nth_sup_k_N_add_one_le_N'aux_of_small h)
lemma N_lt_N'aux : N < N'aux a N :=
Nat.add_one_le_iff.mp ((Nat.le_nth fun hf ↦ absurd hf hc.infinite_setOf_apply_eq_one).trans
(hc.nth_sup_N_add_one_le_N'aux_of_small hc.small_one))
/-- `N` is less than `N'`. -/
lemma N_lt_N' : N < N' a N := hc.N_lt_N'aux.trans_le (Nat.le_add_right _ _)
lemma lt_card_filter_eq_of_small_nth_lt {i j t : ℕ} (hj0 : 0 < j) (h : Small a j)
(ht : Nat.nth (a · = j) t < i) : t < #{m ∈ Finset.range i | a m = j} := by
rw [← hc.infinite_setOf_apply_eq_iff_small hj0] at h
rw [← Nat.count_eq_card_filter_range]
exact (Nat.nth_lt_nth h).mp (ht.trans_le (Nat.le_nth_count h _))
lemma k_lt_card_filter_eq_of_small_of_N'aux_le {i j : ℕ} (hj0 : 0 < j) (h : Small a j)
(hN'aux : N'aux a N < i) : k a < #{m ∈ Finset.range i | a m = j} :=
hc.lt_card_filter_eq_of_small_nth_lt hj0 h ((hc.nth_sup_k_le_N'aux_of_small h).trans_lt hN'aux)
lemma N_add_one_lt_card_filter_eq_of_small_of_N'aux_le {i j : ℕ} (hj0 : 0 < j) (h : Small a j)
(hN'aux : N'aux a N < i) : N + 1 < #{m ∈ Finset.range i | a m = j} :=
hc.lt_card_filter_eq_of_small_nth_lt hj0 h
((hc.nth_sup_N_add_one_le_N'aux_of_small h).trans_lt hN'aux)
lemma N_add_one_lt_card_filter_eq_of_small_of_N'_le {i j : ℕ} (hj0 : 0 < j) (h : Small a j)
(hN' : N' a N < i) : N + 1 < #{m ∈ Finset.range i | a m = j} := by
refine hc.N_add_one_lt_card_filter_eq_of_small_of_N'aux_le hj0 h ?_
rw [N'] at hN'
split_ifs at hN' <;> omega
lemma apply_add_one_big_of_apply_small_of_N'aux_le {i : ℕ} (h : Small a (a i))
(hN'aux : N'aux a N ≤ i) : Big a (a (i + 1)) := by
have hN'' : N'aux a N < i + 1 := by omega
suffices ¬Small a (a (i + 1)) by simpa [this] using hc.small_or_big_of_N'aux_lt hN''
rw [hc.apply_add_one_eq_card (hc.N_lt_N'aux.le.trans hN'aux), Small, not_le]
exact hc.k_lt_card_filter_eq_of_small_of_N'aux_le (hc.pos _) h hN''
lemma apply_add_one_big_of_apply_small_of_N'_le {i : ℕ} (h : Small a (a i)) (hN' : N' a N ≤ i) :
Big a (a (i + 1)) :=
hc.apply_add_one_big_of_apply_small_of_N'aux_le h ((Nat.le_add_right _ _).trans hN')
lemma apply_add_one_small_of_apply_big_of_N'aux_le {i : ℕ} (h : Big a (a i))
(hN'aux : N'aux a N ≤ i) : Small a (a (i + 1)) := by
obtain ⟨hf, hfc⟩ := hc.exists_card_le_of_big h
rw [hc.apply_add_one_eq_card (hc.N_lt_N'aux.le.trans hN'aux)]
exact (Finset.card_le_card (by simp)).trans hfc
lemma apply_add_one_small_of_apply_big_of_N'_le {i : ℕ} (h : Big a (a i)) (hN' : N' a N ≤ i) :
Small a (a (i + 1)) :=
hc.apply_add_one_small_of_apply_big_of_N'aux_le h ((Nat.le_add_right _ _).trans hN')
lemma apply_add_two_small_of_apply_small_of_N'_le {i : ℕ} (h : Small a (a i)) (hN' : N' a N ≤ i) :
Small a (a (i + 2)) :=
hc.apply_add_one_small_of_apply_big_of_N'_le (hc.apply_add_one_big_of_apply_small_of_N'_le h hN')
(by omega)
/-- `a (N' a N)` is a small number. -/
lemma small_apply_N' : Small a (a (N' a N)) := by
rw [N']
split_ifs with hi
· exact hi
· have hb : Big a (a (N'aux a N + 1)) := by
simpa [hi] using hc.small_or_big_of_N'aux_lt (Nat.lt_add_one (N'aux a N))
exact hc.apply_add_one_small_of_apply_big_of_N'aux_le hb (by omega)
lemma small_apply_N'_add_iff_even {n : ℕ} : Small a (a (N' a N + n)) ↔ Even n := by
induction n with
| zero => simpa using hc.small_apply_N'
| succ n ih =>
by_cases he : Even n <;> rw [← add_assoc] <;> simp only [he, iff_true, iff_false] at ih
· have hne : ¬ Even (n + 1) := by simp [Nat.not_even_iff_odd, he]
simp only [hne, iff_false]
exact hc.not_small_of_big (hc.apply_add_one_big_of_apply_small_of_N'_le ih (by omega))
· have hb : Big a (a (N' a N + n)) := by
simpa [ih] using hc.small_or_big_of_N'_le (j := N' a N + n) (by omega)
simp [hc.apply_add_one_small_of_apply_big_of_N'_le hb (by omega), Nat.not_even_iff_odd.mp he]
lemma small_apply_add_two_mul_iff_small {n : ℕ} (m : ℕ) (hN' : N' a N ≤ n) :
Small a (a (n + 2 * m)) ↔ Small a (a n) := by
rw [show n = N' a N + (n - N' a N) by omega, add_assoc, hc.small_apply_N'_add_iff_even,
hc.small_apply_N'_add_iff_even]
simp [Nat.even_add]
lemma apply_sub_one_small_of_apply_big_of_N'_le {i : ℕ} (h : Big a (a i)) (hN' : N' a N ≤ i) :
Small a (a (i - 1)) := by
have h0i : 1 ≤ i := by
have := hc.N_lt_N'
omega
have h' : N' a N ≤ i - 1 := by
by_contra hi
have hi' : i = N' a N := by omega
exact hc.not_small_of_big (hi' ▸ h) hc.small_apply_N'
exact (hc.small_or_big_of_N'_le h').elim id fun hb ↦
False.elim (hc.not_small_of_big h (Nat.sub_add_cancel h0i ▸
(hc.apply_add_one_small_of_apply_big_of_N'_le hb h')))
lemma apply_sub_one_big_of_apply_small_of_N'_lt {i : ℕ} (h : Small a (a i)) (hN' : N' a N < i) :
Big a (a (i - 1)) := by
have h0i : 1 ≤ i := by omega
have h' : N' a N ≤ i - 1 := by omega
exact (hc.small_or_big_of_N'_le h').elim (fun hs ↦ False.elim (hc.not_small_of_big
(Nat.sub_add_cancel h0i ▸ hc.apply_add_one_big_of_apply_small_of_N'_le hs h') h)) id
lemma apply_sub_two_small_of_apply_small_of_N'_lt {i : ℕ} (h : Small a (a i)) (hN' : N' a N < i) :
Small a (a (i - 2)) := by
convert hc.apply_sub_one_small_of_apply_big_of_N'_le
(hc.apply_sub_one_big_of_apply_small_of_N'_lt h hN') (by omega) using 1
lemma N_add_one_lt_apply_of_apply_big_of_N'_le {i : ℕ} (h : Big a (a i)) (hN' : N' a N ≤ i) :
N + 1 < a i := by
refine hc.apply_eq_card (hc.N_lt_N'.trans_le hN') ▸
hc.N_add_one_lt_card_filter_eq_of_small_of_N'_le (hc.pos _)
(hc.apply_sub_one_small_of_apply_big_of_N'_le h hN') ?_
by_contra
exact hc.not_small_of_big ((by omega : i = N' a N) ▸ h) hc.small_apply_N'
lemma setOf_apply_eq_of_apply_big_of_N'_le {i : ℕ} (h : Big a (a i)) (hN' : N' a N ≤ i) :
{j | a j = a i} = {j | N < j ∧ Small a (a (j - 1)) ∧
a i = #{t ∈ Finset.range j | a t = a (j - 1)}} := by
have hs : {j | N < j ∧ Small a (a (j - 1)) ∧ a i = #{t ∈ Finset.range j | a t = a (j - 1)}} ⊆
{j | a j = a i} := by
rintro _ ⟨hNj, -, hj⟩
exact hj ▸ hc.apply_eq_card hNj
rcases hc.exists_card_le_of_big h with ⟨hf, hck⟩
have hf' : {j | N < j ∧ Small a (a (j - 1)) ∧
a i = #{t ∈ Finset.range j | a t = a (j - 1)}}.Finite := hf.subset hs
suffices hf.toFinset = hf'.toFinset by simpa using this
rw [← Set.Finite.toFinset_subset_toFinset (hs := hf') (ht := hf)] at hs
refine (Finset.eq_of_subset_of_card_le hs (hck.trans ?_)).symm
have hs : #((Finset.Icc 1 (k a)).image (fun t ↦ Nat.nth (a · = t) (a i - 1) + 1)) = k a := by
convert Finset.card_image_of_injOn fun t ht u hu htu ↦ ?_
· simp only [Nat.card_Icc, add_tsub_cancel_right]
· simp only [add_left_inj] at htu
simp only [Finset.coe_Icc, Set.mem_Icc] at ht hu
rw [← Small, ← hc.infinite_setOf_apply_eq_iff_small (by omega)] at ht hu
apply_fun a at htu
rwa [Nat.nth_mem_of_infinite ht.2, Nat.nth_mem_of_infinite hu.2] at htu
refine hs ▸ Finset.card_le_card (Finset.subset_iff.2 fun j hj ↦ ?_)
simp only [Set.Finite.mem_toFinset, Set.mem_setOf_eq]
simp only [Finset.mem_image, Finset.mem_Icc] at hj
rcases hj with ⟨t, ⟨ht1, htk⟩, rfl⟩
have hN1 : N < a i - 1 := by
have := hc.N_add_one_lt_apply_of_apply_big_of_N'_le h hN'
omega
simp only [add_tsub_cancel_right]
rw [← Small] at htk
have htki := htk
rw [← hc.infinite_setOf_apply_eq_iff_small (by omega)] at htki
rw [Nat.nth_mem_of_infinite htki]
simp only [htk, true_and]
refine ⟨Nat.lt_add_one_iff.mpr ((Nat.le_nth (fun hf ↦ absurd hf htki)).trans
((Nat.nth_le_nth htki).2 hN1.le)), ?_⟩
rw [← Nat.count_eq_card_filter_range, Nat.count_nth_succ_of_infinite htki]
omega
lemma N_lt_of_apply_eq_of_apply_big_of_N'_le {i j : ℕ} (hj : a j = a i) (h : Big a (a i))
(hN' : N' a N ≤ i) : N < j :=
have hj' : j ∈ {t | a t = a i} := by simpa using hj
(hc.setOf_apply_eq_of_apply_big_of_N'_le h hN' ▸ hj').1
lemma small_apply_sub_one_of_apply_eq_of_apply_big_of_N'_le {i j : ℕ} (hj : a j = a i)
(h : Big a (a i)) (hN' : N' a N ≤ i) : Small a (a (j - 1)) :=
have hj' : j ∈ {t | a t = a i} := by simpa using hj
(hc.setOf_apply_eq_of_apply_big_of_N'_le h hN' ▸ hj').2.1
/-! ### The main lemmas leading to the required result -/
/-- Lemma 1 from the informal solution. -/
lemma apply_add_one_eq_card_small_le_card_eq {i : ℕ} (hi : N' a N < i) (hib : Big a (a i)) :
a (i + 1) = #{m ∈ Finset.range (k a + 1) | a i ≤ #{j ∈ Finset.range i | a j = m}} := by
rw [hc.apply_add_one_eq_card (hc.N_lt_N'.trans hi).le]
convert Finset.card_image_of_injOn (f := fun j ↦ Nat.nth (a · = j) (a i - 1) + 1) ?_ using 1
· congr
ext j
simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_image]
refine ⟨fun ⟨hj, hji⟩ ↦ ⟨a (j - 1), hji ▸ ?_⟩, fun ⟨t, ⟨hts, htr⟩, ht⟩ ↦ ?_⟩
· have hjN : N < j := hc.N_lt_of_apply_eq_of_apply_big_of_N'_le hji hib hi.le
refine ⟨⟨Nat.lt_add_one_iff.mpr (hc.small_apply_sub_one_of_apply_eq_of_apply_big_of_N'_le
hji hib hi.le), ?_⟩, ?_⟩
· rw [hc.apply_eq_card hjN]
have : j ≤ i := by omega
gcongr
· have hj1 : j = j - 1 + 1 := by omega
nth_rw 2 [hj1]
rw [hc.nth_apply_add_one_eq (by omega), hj1.symm]
· subst ht
rw [Nat.lt_add_one_iff, ← Small] at hts
have ht0 : 0 < t := by
by_contra! h0
simp [nonpos_iff_eq_zero.mp h0, hc.apply_ne_zero] at htr
rw [← hc.infinite_setOf_apply_eq_iff_small ht0] at hts
rw [← Nat.count_eq_card_filter_range] at htr
constructor
· rwa [add_lt_add_iff_right, ← Nat.lt_nth_iff_count_lt hts,
Nat.sub_lt_iff_lt_add' (hc.one_le_apply _), Nat.lt_one_add_iff]
· rw [hc.apply_nth_add_one_eq_of_infinite hts]
· exact Nat.sub_add_cancel (hc.one_le_apply _)
· refine (Nat.le_nth fun hf ↦ absurd hf hts).trans ((Nat.nth_le_nth hts).2 ?_)
have := hc.N_add_one_lt_apply_of_apply_big_of_N'_le hib hi.le
omega
· intro t ht u hu htu
simp only [Finset.coe_filter, Finset.mem_range, Set.mem_setOf_eq, Nat.lt_add_one_iff] at ht hu
rw [← Small] at ht hu
have ht0 : 0 < t := by
by_contra! h0
simp only [nonpos_iff_eq_zero] at h0
simp [h0, hc.apply_ne_zero] at ht
have hu0 : 0 < u := by
by_contra! h0
simp only [nonpos_iff_eq_zero] at h0
simp [h0, hc.apply_ne_zero] at hu
rw [← hc.infinite_setOf_apply_eq_iff_small ht0] at ht
rw [← hc.infinite_setOf_apply_eq_iff_small hu0] at hu
simp only [add_left_inj] at htu
apply_fun a at htu
rwa [Nat.nth_mem_of_infinite ht.1, Nat.nth_mem_of_infinite hu.1] at htu
/-- Similar to Lemma 1 from the informal solution, but with a `Small` hypothesis instead of `Big`
and considering a range one larger (the form needed for Lemma 2). -/
lemma apply_eq_card_small_le_card_eq_of_small {i : ℕ} (hi : N' a N + 1 < i)
(his : Small a (a i)) :
a i = #{m ∈ Finset.range (k a + 1) | a (i - 1) ≤ #{j ∈ Finset.range i | a j = m}} := by
have hib : Big a (a (i - 1)) := hc.apply_sub_one_big_of_apply_small_of_N'_lt his (by omega)
nth_rw 1 [show i = i - 1 + 1 by omega]
rw [hc.apply_add_one_eq_card_small_le_card_eq (by omega) hib]
congr 1
ext j
simp only [Finset.mem_filter, Finset.mem_range, and_congr_right_iff]
intro hj
convert Iff.rfl using 2
congr 1
ext t
simp only [Finset.mem_filter, Finset.mem_range]
refine ⟨fun ⟨hti, rfl⟩ ↦ ⟨?_, rfl⟩, fun ⟨_, rfl⟩ ↦ ⟨by omega, rfl⟩⟩
by_contra hti1
have htieq : t = i - 1 := by omega
subst htieq
exact hc.not_small_of_big hib (Nat.lt_add_one_iff.mp hj)
/-- Lemma 2 from the informal solution. -/
lemma exists_apply_sub_two_eq_of_apply_eq {i j : ℕ} (hi : N' a N + 2 < i) (hijlt : i < j)
(his : Small a (a i)) (hijeq : a i = a j)
(hij1 : ∀ t, Small a t → #{x ∈ Finset.Ico i j | a x = t} ≤ 1) :
∃ t, t ∈ Finset.Ico i j ∧ a (i - 2) = a t := by
let I : Finset ℕ := {t ∈ Finset.range (k a + 1) | a (i - 1) ≤ #{u ∈ Finset.range i | a u = t}}
let J : Finset ℕ := {t ∈ Finset.range (k a + 1) | a (j - 1) ≤ #{u ∈ Finset.range j | a u = t}}
have hIc : a i = #I := hc.apply_eq_card_small_le_card_eq_of_small (by omega) his
have hJc : a j = #J := hc.apply_eq_card_small_le_card_eq_of_small (by omega) (hijeq ▸ his)
have hIJc : #I = #J := hIc ▸ hJc ▸ hijeq
have := hc.N_lt_N'
have hiju : Finset.range i ∪ Finset.Ico i j = Finset.range j := by
rw [Finset.range_eq_Ico, Finset.Ico_union_Ico' (by omega) (by omega)]
simp [hijlt.le]
have hi2s : a (i - 2) < k a + 1 :=
Nat.lt_add_one_iff.mpr (hc.apply_sub_two_small_of_apply_small_of_N'_lt his (by omega))
have hiI : a (i - 2) ∈ I := by
simp only [I, Finset.mem_filter, Finset.mem_range, hi2s, true_and]
rw [hc.apply_eq_card (by omega), show i - 1 - 1 = i - 2 by omega]
exact Finset.card_le_card (Finset.filter_subset_filter _ (by simp))
have hj2s : a (j - 2) < k a + 1 :=
Nat.lt_add_one_iff.mpr (hc.apply_sub_two_small_of_apply_small_of_N'_lt (hijeq ▸ his) (by omega))
have hjJ : a (j - 2) ∈ J := by
simp only [J, Finset.mem_filter, Finset.mem_range, hj2s, true_and]
rw [hc.apply_eq_card (by omega), show j - 1 - 1 = j - 2 by omega]
exact Finset.card_le_card (Finset.filter_subset_filter _ (by simp))
have hjI : a (j - 2) ∈ I := by
by_contra hjI
have hjIf := hjI
simp only [Finset.mem_filter, Finset.mem_range, hj2s, true_and, not_le, I,
Nat.lt_iff_add_one_le] at hjIf
have hjI' : a (j - 1) ≤ a (i - 1) := by
calc a (j - 1) ≤ #{u ∈ Finset.range j | a u = a (j - 2)} :=
(Finset.mem_filter.mp hjJ).2
_ = #{u ∈ Finset.range i ∪ Finset.Ico i j | a u = a (j - 2)} := by rw [hiju]
_ ≤ #{u ∈ Finset.range i | a u = a (j - 2)} + #{u ∈ Finset.Ico i j | a u = a (j - 2)} := by
rw [Finset.filter_union]
exact Finset.card_union_le _ _
_ ≤ #{u ∈ Finset.range i | a u = a (j - 2)} + 1 := by
gcongr
exact hij1 _ (by rwa [Nat.lt_add_one_iff, ← Small] at hj2s)
_ ≤ a (i - 1) := hjIf
refine hjI (Finset.eq_of_subset_of_card_le (fun x hxI ↦ ?_) hIJc.symm.le ▸ hjJ)
simp only [Finset.mem_filter, I, J] at *
refine ⟨hxI.1, ?_⟩
calc a (j - 1) ≤ a (i - 1) := hjI'
_ ≤ #{u ∈ Finset.range i | a u = x} := hxI.2
_ ≤ #{u ∈ Finset.range j | a u = x} :=
Finset.card_le_card (Finset.filter_subset_filter _ (by simp [hijlt.le]))
have hi1j1 : a (i - 1) + 1 ≤ a (j - 1) := by
calc a (i - 1) + 1 ≤ #{u ∈ Finset.range i | a u = a (j - 2)} + 1 := by grind
_ ≤ #{u ∈ Finset.range i | a u = a (j - 2)} + #{u ∈ Finset.Ico i j | a u = a (j - 2)} := by
gcongr
simp only [Finset.one_le_card]
refine ⟨j - 2, ?_⟩
simp only [Finset.mem_filter, Finset.mem_Ico, and_true]
refine ⟨?_, by omega⟩
by_contra hj
have hj' : j = i + 1 := by omega
subst hj'
exact hc.not_small_of_big (hc.apply_add_one_big_of_apply_small_of_N'_le his (by omega))
(hijeq ▸ his)
_ = #({u ∈ Finset.range i | a u = a (j - 2)} ∪ {u ∈ Finset.Ico i j | a u = a (j - 2)}) := by
refine (Finset.card_union_of_disjoint ?_).symm
simp only [Finset.disjoint_iff_ne, Finset.mem_filter, Finset.mem_range, Finset.mem_Ico,
and_imp]
rintro t hti - u hiu - -
omega
_ = #{u ∈ Finset.range j | a u = a (j - 2)} := by
rw [← Finset.filter_union, hiju]
_ = a (j - 1) := by
rw [hc.apply_eq_card (show N < j - 1 by omega)]
congr 1
ext t
simp only [Finset.mem_filter, Finset.mem_range]
refine ⟨fun ⟨htj, htj'⟩ ↦ ⟨?_, by convert htj' using 1⟩,
fun ⟨htj, htj'⟩ ↦ ⟨by omega, by convert htj' using 1⟩⟩
by_contra htj''
have ht1 : t = j - 1 := by omega
subst ht1
exact hc.not_small_of_big (htj' ▸ hc.apply_sub_one_big_of_apply_small_of_N'_lt
(hijeq ▸ his) (by omega)) (hc.apply_sub_two_small_of_apply_small_of_N'_lt
(hijeq ▸ his) (by omega))
have hIJ : I = J := by
refine (Finset.eq_of_subset_of_card_le (Finset.subset_iff.mp fun x hxJ ↦ ?_) hIJc.le).symm
simp only [Finset.mem_filter, Finset.mem_range, I, J, Nat.lt_add_one_iff] at *
refine ⟨hxJ.1, (add_le_add_iff_right 1).mp ?_⟩
calc a (i - 1) + 1 ≤ a (j - 1) := hi1j1
_ ≤ #{u ∈ Finset.range j | a u = x} := hxJ.2
_ = #({u ∈ Finset.range i | a u = x} ∪ {u ∈ Finset.Ico i j | a u = x}) := by
rw [← Finset.filter_union, hiju]
_ ≤ #{u ∈ Finset.range i | a u = x} + #{u ∈ Finset.Ico i j | a u = x} :=
Finset.card_union_le _ _
_ ≤ #{u ∈ Finset.range i | a u = x} + 1 := by
gcongr
exact hij1 _ hxJ.1
simp only [hIJ, J, Finset.mem_filter] at hiI
have hiI' := hi1j1.trans hiI.2
rw [hc.apply_eq_card (by omega), show i - 1 - 1 = i - 2 by omega, Nat.add_one_le_iff,
← not_le] at hiI'
rcases Finset.not_subset.mp (mt Finset.card_le_card hiI') with ⟨t, htj, hti⟩
simp only [Finset.mem_filter, Finset.mem_range] at htj hti
simp only [htj.2, and_true, not_lt, tsub_le_iff_right] at hti
refine ⟨t, Finset.mem_Ico.mpr ⟨?_, htj.1⟩, htj.2.symm⟩
by_contra
have hti' : t = i - 1 := by omega
subst hti'
exact hc.not_small_of_big (hc.apply_sub_one_big_of_apply_small_of_N'_lt his (by omega)) (htj.2 ▸
(hc.apply_sub_two_small_of_apply_small_of_N'_lt his (by omega)))
variable (a)
/-- The indices, minus `n`, of small numbers appearing for the second or subsequent time at or
after `a n`. -/
def pSet (n : ℕ) : Set ℕ := {t | ∃ i ∈ Finset.Ico n (n + t), Small a (a i) ∧ a (n + t) = a i}
/-- The index, minus `n`, of the second appearance of the first small number to appear twice at
or after `a n`. This is only used for small `a n` with `N' a N + 2 < n`. -/
noncomputable def p (n : ℕ) : ℕ := sInf (pSet a n)
variable {a}
lemma nonempty_pSet (n : ℕ) : (pSet a n).Nonempty := by
rcases hc.infinite_setOf_apply_eq_one.exists_gt n with ⟨i, hi1, hni⟩
rcases hc.infinite_setOf_apply_eq_one.exists_gt i with ⟨j, hj1, hij⟩
refine ⟨j - n, ?_⟩
simp only [pSet, Finset.mem_Ico, Set.mem_setOf_eq]
exact ⟨i, ⟨hni.le, by omega⟩, hi1 ▸ ⟨hc.small_one, hj1 ▸ (by congr; omega)⟩⟩
lemma exists_mem_Ico_small_and_apply_add_p_eq (n : ℕ) :
∃ i ∈ Finset.Ico n (n + p a n), Small a (a i) ∧ a (n + p a n) = a i :=
csInf_mem (hc.nonempty_pSet _)
lemma p_pos (n : ℕ) : 0 < p a n := by
by_contra! h
have hn := hc.exists_mem_Ico_small_and_apply_add_p_eq n
simp [h] at hn
lemma card_filter_apply_eq_Ico_add_p_le_one (n : ℕ) {j : ℕ} (hjs : Small a j) :
#{i ∈ Finset.Ico n (n + p a n) | a i = j} ≤ 1 := by
have h : IsLeast (pSet a n) (p a n) := isLeast_csInf (hc.nonempty_pSet n)
simp only [IsLeast, pSet, Set.mem_setOf_eq, mem_lowerBounds, forall_exists_index, and_imp,
Finset.mem_Ico] at h
rw [Finset.card_le_one_iff]
intro x y hx hy
simp only [Finset.mem_filter, Finset.mem_Ico] at hx hy
rcases lt_trichotomy x y with hxy | rfl | hxy
· replace h := h.2 (y - n) x hx.1.1 (by omega) (hx.2 ▸ hjs)
rw [show n + (y - n) = y by omega, hx.2, hy.2] at h
omega
· rfl
· replace h := h.2 (x - n) y hy.1.1 (by omega) (hy.2 ▸ hjs)
rw [show n + (x - n) = x by omega, hx.2, hy.2] at h
omega
lemma apply_add_p_eq {n : ℕ} (hn : N' a N + 2 < n) (hs : Small a (a n)) : a (n + p a n) = a n := by
rcases hc.exists_mem_Ico_small_and_apply_add_p_eq n with ⟨i, hiIco, his, hin⟩
suffices i = n by rw [hin, this]
simp only [Finset.mem_Ico] at hiIco
by_contra hin'
have hf (t : ℕ) (hts : Small a t) : #{x ∈ Finset.Ico i (n + p a n) | a x = t} ≤ 1 :=
calc #{x ∈ Finset.Ico i (n + p a n) | a x = t} ≤ #{x ∈ Finset.Ico n (n + p a n) | a x = t} :=
Finset.card_le_card (Finset.filter_subset_filter _ (Finset.Ico_subset_Ico hiIco.1 le_rfl))
_ ≤ 1 := hc.card_filter_apply_eq_Ico_add_p_le_one _ hts
obtain ⟨t, hti, hi2t⟩ := hc.exists_apply_sub_two_eq_of_apply_eq (j := n + p a n) (by omega)
(by omega) his hin.symm hf
have h1 := hc.card_filter_apply_eq_Ico_add_p_le_one n
(hi2t ▸ hc.apply_sub_two_small_of_apply_small_of_N'_lt his (by omega))
revert h1
simp only [imp_false, not_le, Finset.one_lt_card_iff, Finset.mem_filter, Finset.mem_Ico, ne_eq,
exists_and_left]
simp only [Finset.mem_Ico] at hti
refine ⟨i - 2, ⟨⟨?_, by omega⟩, hi2t⟩, t, by omega⟩
by_contra hi2
have hi1 : n = i - 1 := by omega
subst hi1
exact hc.not_small_of_big (hc.apply_sub_one_big_of_apply_small_of_N'_lt his (by omega)) hs
lemma even_p {n : ℕ} (hn : N' a N + 2 < n) (hs : Small a (a n)) : Even (p a n) := by
have hna : n = N' a N + (n - (N' a N)) := by omega
have hs' := hc.apply_add_p_eq hn hs ▸ hs
rw [hna, hc.small_apply_N'_add_iff_even] at hs
nth_rw 1 [hna] at hs'
rw [add_assoc, hc.small_apply_N'_add_iff_even] at hs'
simpa [Nat.even_add, hs] using hs'
lemma p_le_two_mul_k {n : ℕ} (hn : N' a N + 2 < n) (hs : Small a (a n)) : p a n ≤ 2 * k a := by
by_contra hlt
obtain ⟨x, hx, y, hy, hxyne, hxy⟩ : ∃ x ∈ Finset.range (k a + 1), ∃ y ∈ Finset.range (k a + 1),
x ≠ y ∧ a (n + 2 * x) = a (n + 2 * y) := by
convert Finset.exists_ne_map_eq_of_card_lt_of_maps_to (t := Finset.Icc 1 (k a)) ?_ ?_
· simp
· rintro i -
simp only [Finset.coe_Icc, Set.mem_Icc]
rw [← Small, hc.small_apply_add_two_mul_iff_small i (by omega)]
simp [hs, hc.one_le_apply]
have hs' : Small a (a (n + 2 * x)) := by rwa [hc.small_apply_add_two_mul_iff_small x (by omega)]
have hj := hc.card_filter_apply_eq_Ico_add_p_le_one n hs'
revert hj
simp only [imp_false, not_le, Finset.one_lt_card_iff, Finset.mem_filter, Finset.mem_Ico, ne_eq,
exists_and_left]
simp only [Finset.mem_range] at hx hy
exact ⟨n + 2 * x, by omega, n + 2 * y, by omega⟩
lemma p_apply_sub_two_le_p_apply {n : ℕ} (hn : N' a N + 4 < n) (hs : Small a (a n)) :
p a (n - 2) ≤ p a n := by
obtain ⟨t, hti, _⟩ := hc.exists_apply_sub_two_eq_of_apply_eq (j := n + p a n) (by omega)
((lt_add_iff_pos_right n).mpr (hc.p_pos n)) hs
(hc.apply_add_p_eq (by omega) hs).symm (fun _ ↦ hc.card_filter_apply_eq_Ico_add_p_le_one _)
by_contra
have hn2 := (hc.apply_sub_two_small_of_apply_small_of_N'_lt hs (by omega))
have : p a n ≤ p a (n - 2) - 2 := by
obtain ⟨_, _⟩ := hc.even_p (by omega) hs
obtain ⟨_, _⟩ := hc.even_p (by omega) hn2
omega
have h := hc.card_filter_apply_eq_Ico_add_p_le_one (n - 2) hn2
revert h
simp only [imp_false, not_le, Finset.one_lt_card_iff, Finset.mem_filter, Finset.mem_Ico,
ne_eq, exists_and_left]
simp only [Finset.mem_Ico] at hti
exact ⟨n - 2, ⟨⟨le_rfl, by omega⟩, rfl⟩, t, by omega⟩
lemma p_apply_le_p_apply_add_two {n : ℕ} (hn : N' a N + 2 < n) (hs : Small a (a n)) :
p a n ≤ p a (n + 2) :=
hc.p_apply_sub_two_le_p_apply (n := n + 2) (by omega)
(hc.apply_add_two_small_of_apply_small_of_N'_le hs (by omega))
variable (a N)
lemma exists_p_eq : ∃ b c, ∀ n, b < n → p a (N' a N + 2 * n) = c := by
let c : ℕ := sSup (Set.range (fun i ↦ p a (N' a N + 2 * (2 + i))))
have hk : 2 * k a ∈ upperBounds (Set.range (fun i ↦ p a (N' a N + 2 * (2 + i)))) := by
simp only [mem_upperBounds, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff]
exact fun i ↦ hc.p_le_two_mul_k (by omega) (hc.small_apply_N'_add_iff_even.mpr (by simp))
have hlec : ∀ j ∈ Set.range (fun i ↦ p a (N' a N + 2 * (2 + i))), j ≤ c :=
fun _ hj ↦ le_csSup ⟨_, hk⟩ hj
obtain ⟨t, ht⟩ := Set.Nonempty.csSup_mem (Set.range_nonempty _) (BddAbove.finite ⟨2 * k a, hk⟩)
have heqc (u : ℕ) : p a (N' a N + 2 * (2 + t + u)) = c := by
induction u with
| zero => simpa using ht
| succ u ih =>
refine le_antisymm ?_ (ih ▸ ?_)
· simp only [Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] at hlec
exact add_assoc _ _ (u + 1) ▸ hlec (t + (u + 1))
· have hs : Small a (a (N' a N + 2 * (2 + t + u))) := by
rw [hc.small_apply_N'_add_iff_even]
simp
convert hc.p_apply_le_p_apply_add_two (by omega) hs using 1
refine ⟨1 + t, c, fun n hn ↦ ?_⟩
rw [show n = 2 + t + (n - (2 + t)) by omega]
exact heqc _
lemma exists_a_apply_add_eq : ∃ b c, 0 < c ∧ ∀ n, b < n →
a (N' a N + 2 * n + 2 * c) = a (N' a N + 2 * n) := by
obtain ⟨b, c', hbc'⟩ := hc.exists_p_eq a N
have hs (n : ℕ) : Small a (a (N' a N + 2 * n)) := hc.small_apply_N'_add_iff_even.mpr (by simp)
refine ⟨b + 2, c' / 2, ?_, fun n hbn ↦ hbc' n (by omega) ▸ ?_⟩
· have := hbc' (b + 2) (by omega)
have := hc.p_pos (N' a N + 2 * (b + 2))
rcases hc.even_p (by omega) (hs (b + 2)) with ⟨_, _⟩
omega
· convert hc.apply_add_p_eq (by omega) (hs n) using 3
rcases hc.even_p (by omega) (hs n) with ⟨_, ht⟩
simp [ht, ← two_mul]
variable {a N}
end Condition
theorem result {a : ℕ → ℕ} {N : ℕ} (h : Condition a N) :
EventuallyPeriodic (fun i ↦ a (2 * i)) ∨ EventuallyPeriodic (fun i ↦ a (2 * i + 1)) := by
obtain ⟨b, c, hc, hbc⟩ := h.exists_a_apply_add_eq a N
obtain ⟨t, _⟩ | ⟨t, _⟩ := Nat.even_or_odd (Condition.N' a N)
· refine .inl ⟨c, Condition.N' a N / 2 + b + 1, hc, fun m hm ↦ ?_⟩
convert hbc (m - t) (by omega) using 1 <;> dsimp only <;> congr <;> omega
· refine .inr ⟨c, Condition.N' a N / 2 + b + 1, hc, fun m hm ↦ ?_⟩
convert hbc (m - t) (by omega) using 1 <;> dsimp only <;> congr 1 <;> omega
end Imo2024Q3
|
Card.lean
|
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Violeta Hernández Palacios
-/
import Mathlib.MeasureTheory.MeasurableSpace.Defs
import Mathlib.SetTheory.Cardinal.Regular
import Mathlib.SetTheory.Cardinal.Continuum
import Mathlib.SetTheory.Cardinal.Ordinal
/-!
# Cardinal of sigma-algebras
If a sigma-algebra is generated by a set of sets `s`, then the cardinality of the sigma-algebra is
bounded by `(max #s 2) ^ ℵ₀`. This is stated in `MeasurableSpace.cardinal_generate_measurable_le`
and `MeasurableSpace.cardinalMeasurableSet_le`.
In particular, if `#s ≤ 𝔠`, then the generated sigma-algebra has cardinality at most `𝔠`, see
`MeasurableSpace.cardinal_measurableSet_le_continuum`.
For the proof, we rely on an explicit inductive construction of the sigma-algebra generated by
`s` (instead of the inductive predicate `GenerateMeasurable`). This transfinite inductive
construction is parameterized by an ordinal `< ω₁`, and the cardinality bound is preserved along
each step of the construction. We show in `MeasurableSpace.generateMeasurable_eq_rec` that this
indeed generates this sigma-algebra.
-/
universe u v
variable {α : Type u}
open Cardinal Ordinal Set MeasureTheory
namespace MeasurableSpace
/-- Transfinite induction construction of the sigma-algebra generated by a set of sets `s`. At each
step, we add all elements of `s`, the empty set, the complements of already constructed sets, and
countable unions of already constructed sets.
We index this construction by an arbitrary ordinal for simplicity, but by `ω₁` we will have
generated all the sets in the sigma-algebra.
This construction is very similar to that of the Borel hierarchy. -/
def generateMeasurableRec (s : Set (Set α)) (i : Ordinal) : Set (Set α) :=
let S := ⋃ j < i, generateMeasurableRec s j
s ∪ {∅} ∪ compl '' S ∪ Set.range fun f : ℕ → S => ⋃ n, (f n).1
termination_by i
theorem self_subset_generateMeasurableRec (s : Set (Set α)) (i : Ordinal) :
s ⊆ generateMeasurableRec s i := by
unfold generateMeasurableRec
apply_rules [subset_union_of_subset_left]
exact subset_rfl
theorem empty_mem_generateMeasurableRec (s : Set (Set α)) (i : Ordinal) :
∅ ∈ generateMeasurableRec s i := by
unfold generateMeasurableRec
exact mem_union_left _ (mem_union_left _ (mem_union_right _ (mem_singleton ∅)))
theorem compl_mem_generateMeasurableRec {s : Set (Set α)} {i j : Ordinal} (h : j < i) {t : Set α}
(ht : t ∈ generateMeasurableRec s j) : tᶜ ∈ generateMeasurableRec s i := by
unfold generateMeasurableRec
exact mem_union_left _ (mem_union_right _ ⟨t, mem_iUnion₂.2 ⟨j, h, ht⟩, rfl⟩)
theorem iUnion_mem_generateMeasurableRec {s : Set (Set α)} {i : Ordinal} {f : ℕ → Set α}
(hf : ∀ n, ∃ j < i, f n ∈ generateMeasurableRec s j) :
⋃ n, f n ∈ generateMeasurableRec s i := by
unfold generateMeasurableRec
exact mem_union_right _ ⟨fun n => ⟨f n, let ⟨j, hj, hf⟩ := hf n; mem_iUnion₂.2 ⟨j, hj, hf⟩⟩, rfl⟩
theorem generateMeasurableRec_mono (s : Set (Set α)) : Monotone (generateMeasurableRec s) := by
intro i j h x hx
rcases h.eq_or_lt with (rfl | h)
· exact hx
· convert iUnion_mem_generateMeasurableRec fun _ => ⟨i, h, hx⟩
exact (iUnion_const x).symm
/-- An inductive principle for the elements of `generateMeasurableRec`. -/
@[elab_as_elim]
theorem generateMeasurableRec_induction {s : Set (Set α)} {i : Ordinal} {t : Set α}
{p : Set α → Prop} (hs : ∀ t ∈ s, p t) (h0 : p ∅)
(hc : ∀ u, p u → (∃ j < i, u ∈ generateMeasurableRec s j) → p uᶜ)
(hn : ∀ f : ℕ → Set α,
(∀ n, p (f n) ∧ ∃ j < i, f n ∈ generateMeasurableRec s j) → p (⋃ n, f n)) :
t ∈ generateMeasurableRec s i → p t := by
suffices H : ∀ k ≤ i, ∀ t ∈ generateMeasurableRec s k, p t from H i le_rfl t
intro k
apply WellFoundedLT.induction k
intro k IH hk t
replace IH := fun j hj => IH j hj (hj.le.trans hk)
unfold generateMeasurableRec
rintro (((ht | rfl) | ht) | ⟨f, rfl⟩)
· exact hs t ht
· exact h0
· simp_rw [mem_image, mem_iUnion₂] at ht
obtain ⟨u, ⟨⟨j, hj, hj'⟩, rfl⟩⟩ := ht
exact hc u (IH j hj u hj') ⟨j, hj.trans_le hk, hj'⟩
· apply hn
intro n
obtain ⟨j, hj, hj'⟩ := mem_iUnion₂.1 (f n).2
use IH j hj _ hj', j, hj.trans_le hk
theorem generateMeasurableRec_omega1 (s : Set (Set α)) :
generateMeasurableRec s (ω₁ : Ordinal.{v}) =
⋃ i < (ω₁ : Ordinal.{v}), generateMeasurableRec s i := by
apply (iUnion₂_subset fun i h => generateMeasurableRec_mono s h.le).antisymm'
intro t ht
rw [mem_iUnion₂]
refine generateMeasurableRec_induction ?_ ?_ ?_ ?_ ht
· intro t ht
exact ⟨0, omega_pos 1, self_subset_generateMeasurableRec s 0 ht⟩
· exact ⟨0, omega_pos 1, empty_mem_generateMeasurableRec s 0⟩
· rintro u - ⟨j, hj, hj'⟩
exact ⟨_, (isSuccLimit_omega 1).succ_lt hj,
compl_mem_generateMeasurableRec (Order.lt_succ j) hj'⟩
· intro f H
choose I hI using fun n => (H n).1
simp_rw [exists_prop] at hI
refine ⟨_, Ordinal.lsub_lt_ord_lift ?_ fun n => (hI n).1,
iUnion_mem_generateMeasurableRec fun n => ⟨_, Ordinal.lt_lsub I n, (hI n).2⟩⟩
rw [mk_nat, lift_aleph0, isRegular_aleph_one.cof_omega_eq]
exact aleph0_lt_aleph_one
theorem generateMeasurableRec_subset (s : Set (Set α)) (i : Ordinal) :
generateMeasurableRec s i ⊆ { t | GenerateMeasurable s t } := by
apply WellFoundedLT.induction i
exact fun i IH t ht => generateMeasurableRec_induction .basic .empty
(fun u _ ⟨j, hj, hj'⟩ => .compl _ (IH j hj hj')) (fun f H => .iUnion _ fun n => (H n).1) ht
/-- `generateMeasurableRec s ω₁` generates precisely the smallest sigma-algebra containing `s`. -/
theorem generateMeasurable_eq_rec (s : Set (Set α)) :
{ t | GenerateMeasurable s t } = generateMeasurableRec s ω₁ := by
apply (generateMeasurableRec_subset s _).antisymm'
intro t ht
induction ht with
| basic u hu => exact self_subset_generateMeasurableRec s _ hu
| empty => exact empty_mem_generateMeasurableRec s _
| compl u _ IH =>
rw [generateMeasurableRec_omega1, mem_iUnion₂] at IH
obtain ⟨i, hi, hi'⟩ := IH
exact generateMeasurableRec_mono _ ((isSuccLimit_omega 1).succ_lt hi).le
(compl_mem_generateMeasurableRec (Order.lt_succ i) hi')
| iUnion f _ IH =>
simp_rw [generateMeasurableRec_omega1, mem_iUnion₂, exists_prop] at IH
exact iUnion_mem_generateMeasurableRec IH
/-- `generateMeasurableRec` is constant for ordinals `≥ ω₁`. -/
theorem generateMeasurableRec_of_omega1_le (s : Set (Set α)) {i : Ordinal.{v}} (hi : ω₁ ≤ i) :
generateMeasurableRec s i = generateMeasurableRec s (ω₁ : Ordinal.{v}) := by
apply (generateMeasurableRec_mono s hi).antisymm'
rw [← generateMeasurable_eq_rec]
exact generateMeasurableRec_subset s i
/-- At each step of the inductive construction, the cardinality bound `≤ #s ^ ℵ₀` holds. -/
theorem cardinal_generateMeasurableRec_le (s : Set (Set α)) (i : Ordinal.{v}) :
#(generateMeasurableRec s i) ≤ max #s 2 ^ ℵ₀ := by
suffices ∀ i ≤ ω₁, #(generateMeasurableRec s i) ≤ max #s 2 ^ ℵ₀ by
obtain hi | hi := le_or_gt i ω₁
· exact this i hi
· rw [generateMeasurableRec_of_omega1_le s hi.le]
exact this _ le_rfl
intro i
apply WellFoundedLT.induction i
intro i IH hi
have A : 𝔠 ≤ max #s 2 ^ ℵ₀ := power_le_power_right (le_max_right _ _)
have B := aleph0_le_continuum.trans A
have C : #(⋃ j < i, generateMeasurableRec s j) ≤ max #s 2 ^ ℵ₀ := by
apply mk_iUnion_Ordinal_lift_le_of_le _ B _
· intro j hj
exact IH j hj (hj.trans_le hi).le
· rw [lift_power, lift_aleph0]
rw [← Ordinal.lift_le.{u}, lift_omega, Ordinal.lift_one, ← ord_aleph] at hi
have H := card_le_of_le_ord hi
rw [← Ordinal.lift_card] at H
apply H.trans <| aleph_one_le_continuum.trans <| power_le_power_right _
rw [lift_max, Cardinal.lift_ofNat]
exact le_max_right _ _
rw [generateMeasurableRec]
apply_rules [(mk_union_le _ _).trans, add_le_of_le (aleph_one_le_continuum.trans A),
mk_image_le.trans]
· exact (self_le_power _ one_le_aleph0).trans (power_le_power_right (le_max_left _ _))
· rw [mk_singleton]
exact one_lt_aleph0.le.trans B
· apply mk_range_le.trans
simp only [mk_pi, prod_const, Cardinal.lift_uzero, mk_denumerable, lift_aleph0]
have := @power_le_power_right _ _ ℵ₀ C
rwa [← power_mul, aleph0_mul_aleph0] at this
/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma-algebra has cardinality at
most `max #s 2 ^ ℵ₀`. -/
theorem cardinal_generateMeasurable_le (s : Set (Set α)) :
#{ t | GenerateMeasurable s t } ≤ max #s 2 ^ ℵ₀ := by
rw [generateMeasurable_eq_rec.{u, 0}]
exact cardinal_generateMeasurableRec_le s _
/-- If a sigma-algebra is generated by a set of sets `s`, then the sigma
algebra has cardinality at most `max #s 2 ^ ℵ₀`. -/
theorem cardinal_measurableSet_le (s : Set (Set α)) :
#{ t | @MeasurableSet α (generateFrom s) t } ≤ max #s 2 ^ ℵ₀ :=
cardinal_generateMeasurable_le s
/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,
then the sigma algebra has the same cardinality bound. -/
theorem cardinal_generateMeasurable_le_continuum {s : Set (Set α)} (hs : #s ≤ 𝔠) :
#{ t | GenerateMeasurable s t } ≤ 𝔠 := by
apply (cardinal_generateMeasurable_le s).trans
rw [← continuum_power_aleph0]
exact_mod_cast power_le_power_right (max_le hs (nat_lt_continuum 2).le)
/-- If a sigma-algebra is generated by a set of sets `s` with cardinality at most the continuum,
then the sigma algebra has the same cardinality bound. -/
theorem cardinal_measurableSet_le_continuum {s : Set (Set α)} :
#s ≤ 𝔠 → #{ t | @MeasurableSet α (generateFrom s) t } ≤ 𝔠 :=
cardinal_generateMeasurable_le_continuum
end MeasurableSpace
|
SingleObj.lean
|
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.CategoryTheory.Limits.Types.Colimits
import Mathlib.CategoryTheory.Limits.Types.Limits
import Mathlib.CategoryTheory.SingleObj
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Defs
/-!
# (Co)limits of functors out of `SingleObj M`
We characterise (co)limits of shape `SingleObj M`. Currently only in the category of types.
## Main results
* `SingleObj.Types.limitEquivFixedPoints`: The limit of `J : SingleObj G ⥤ Type u` is the fixed
points of `J.obj (SingleObj.star G)` under the induced action.
* `SingleObj.Types.colimitEquivQuotient`: The colimit of `J : SingleObj G ⥤ Type u` is the
quotient of `J.obj (SingleObj.star G)` by the induced action.
-/
assert_not_exists MonoidWithZero
universe u v
namespace CategoryTheory
namespace Limits
namespace SingleObj
variable {M G : Type v} [Monoid M] [Group G]
/-- The induced `G`-action on the target of `J : SingleObj G ⥤ Type u`. -/
instance (J : SingleObj M ⥤ Type u) : MulAction M (J.obj (SingleObj.star M)) where
smul g x := J.map g x
one_smul x := by
change J.map (𝟙 _) x = x
simp only [FunctorToTypes.map_id_apply]
mul_smul g h x := by
change J.map (g * h) x = (J.map h ≫ J.map g) x
rw [← SingleObj.comp_as_mul]
· simp only [FunctorToTypes.map_comp_apply, types_comp_apply]
rfl
section Limits
variable (J : SingleObj M ⥤ Type u)
/-- The equivalence between sections of `J : SingleObj M ⥤ Type u` and fixed points of the
induced action on `J.obj (SingleObj.star M)`. -/
@[simps]
def Types.sections.equivFixedPoints :
J.sections ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) where
toFun s := ⟨s.val _, s.property⟩
invFun p := ⟨fun _ ↦ p.val, p.property⟩
/-- The limit of `J : SingleObj M ⥤ Type u` is equivalent to the fixed points of the
induced action on `J.obj (SingleObj.star M)`. -/
@[simps!]
noncomputable def Types.limitEquivFixedPoints :
limit J ≃ MulAction.fixedPoints M (J.obj (SingleObj.star M)) :=
(Types.limitEquivSections J).trans (Types.sections.equivFixedPoints J)
end Limits
section Colimits
variable {G : Type v} [Group G] (J : SingleObj G ⥤ Type u)
/-- The relation used to construct colimits in types for `J : SingleObj G ⥤ Type u` is
equivalent to the `MulAction.orbitRel` equivalence relation on `J.obj (SingleObj.star G)`. -/
lemma colimitTypeRel_iff_orbitRel (x y : J.obj (SingleObj.star G)) :
J.ColimitTypeRel ⟨SingleObj.star G, x⟩ ⟨SingleObj.star G, y⟩ ↔
MulAction.orbitRel G (J.obj (SingleObj.star G)) x y := by
have h (g : G) : y = g • x ↔ g • x = y := ⟨symm, symm⟩
conv => rhs; rw [Setoid.comm']
change (∃ g : G, y = g • x) ↔ (∃ g : G, g • x = y)
grind
@[deprecated (since := "2025-06-22")] alias Types.Quot.Rel.iff_orbitRel :=
colimitTypeRel_iff_orbitRel
/-- The explicit quotient construction of the colimit of `J : SingleObj G ⥤ Type u` is
equivalent to the quotient of `J.obj (SingleObj.star G)` by the induced action. -/
@[simps]
def colimitTypeRelEquivOrbitRelQuotient :
J.ColimitType ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) where
toFun := Quot.lift (fun p => ⟦p.2⟧) <| fun a b h => Quotient.sound <|
(colimitTypeRel_iff_orbitRel J a.2 b.2).mp h
invFun := Quot.lift (fun x => Quot.mk _ ⟨SingleObj.star G, x⟩) <| fun a b h =>
Quot.sound <| (colimitTypeRel_iff_orbitRel J a b).mpr h
left_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl)
right_inv := fun x => Quot.inductionOn x (fun _ ↦ rfl)
@[deprecated (since := "2025-06-22")] alias Types.Quot.equivOrbitRelQuotient :=
colimitTypeRelEquivOrbitRelQuotient
/-- The colimit of `J : SingleObj G ⥤ Type u` is equivalent to the quotient of
`J.obj (SingleObj.star G)` by the induced action. -/
@[simps!]
noncomputable def Types.colimitEquivQuotient :
colimit J ≃ MulAction.orbitRel.Quotient G (J.obj (SingleObj.star G)) :=
(Types.colimitEquivColimitType J).trans (colimitTypeRelEquivOrbitRelQuotient J)
end Colimits
end SingleObj
end Limits
end CategoryTheory
|
BooleanSubalgebra.lean
|
/-
Copyright (c) 2024 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Sublattice
/-!
# Boolean subalgebras
This file defines boolean subalgebras.
-/
open Function Set
variable {ι : Sort*} {α β γ : Type*}
variable (α) in
/-- A boolean subalgebra of a boolean algebra is a set containing the bottom and top elements, and
closed under suprema, infima and complements. -/
structure BooleanSubalgebra [BooleanAlgebra α] extends Sublattice α where
compl_mem' {a} : a ∈ carrier → aᶜ ∈ carrier
bot_mem' : ⊥ ∈ carrier
namespace BooleanSubalgebra
section BooleanAlgebra
variable [BooleanAlgebra α] [BooleanAlgebra β] [BooleanAlgebra γ] {L M : BooleanSubalgebra α}
{f : BoundedLatticeHom α β} {s t : Set α} {a b : α}
initialize_simps_projections BooleanSubalgebra (carrier → coe, as_prefix coe)
instance instSetLike : SetLike (BooleanSubalgebra α) α where
coe L := L.carrier
coe_injective' L M h := by obtain ⟨⟨_, _⟩, _⟩ := L; congr
lemma coe_inj : (L : Set α) = M ↔ L = M := SetLike.coe_set_eq
@[simp] lemma supClosed (L : BooleanSubalgebra α) : SupClosed (L : Set α) := L.supClosed'
@[simp] lemma infClosed (L : BooleanSubalgebra α) : InfClosed (L : Set α) := L.infClosed'
lemma compl_mem (ha : a ∈ L) : aᶜ ∈ L := L.compl_mem' ha
@[simp] lemma compl_mem_iff : aᶜ ∈ L ↔ a ∈ L := ⟨fun ha ↦ by simpa using compl_mem ha, compl_mem⟩
@[simp] lemma bot_mem : ⊥ ∈ L := L.bot_mem'
@[simp] lemma top_mem : ⊤ ∈ L := by simpa using compl_mem L.bot_mem
lemma sup_mem (ha : a ∈ L) (hb : b ∈ L) : a ⊔ b ∈ L := L.supClosed ha hb
lemma inf_mem (ha : a ∈ L) (hb : b ∈ L) : a ⊓ b ∈ L := L.infClosed ha hb
lemma sdiff_mem (ha : a ∈ L) (hb : b ∈ L) : a \ b ∈ L := by
simpa [sdiff_eq] using L.infClosed ha (compl_mem hb)
lemma himp_mem (ha : a ∈ L) (hb : b ∈ L) : a ⇨ b ∈ L := by
simpa [himp_eq] using L.supClosed hb (compl_mem ha)
lemma mem_carrier : a ∈ L.carrier ↔ a ∈ L := .rfl
@[simp] lemma mem_toSublattice : a ∈ L.toSublattice ↔ a ∈ L := .rfl
@[simp] lemma mem_mk {L : Sublattice α} (h_compl h_bot) : a ∈ mk L h_compl h_bot ↔ a ∈ L := .rfl
@[simp] lemma coe_mk (L : Sublattice α) (h_compl h_bot) : (mk L h_compl h_bot : Set α) = L := rfl
@[simp] lemma mk_le_mk {L M : Sublattice α} (hL_compl hL_bot hM_compl hM_bot) :
mk L hL_compl hL_bot ≤ mk M hM_compl hM_bot ↔ L ≤ M := .rfl
@[simp] lemma mk_lt_mk {L M : Sublattice α} (hL_compl hL_bot hM_compl hM_bot) :
mk L hL_compl hL_bot < mk M hM_compl hM_bot ↔ L < M := .rfl
/-- Copy of a boolean subalgebra with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (L : BooleanSubalgebra α) (s : Set α) (hs : s = L) : BooleanSubalgebra α where
toSublattice := L.toSublattice.copy s <| by subst hs; rfl
compl_mem' := by subst hs; exact L.compl_mem'
bot_mem' := by subst hs; exact L.bot_mem'
@[simp, norm_cast]
lemma coe_copy (L : BooleanSubalgebra α) (s : Set α) (hs) : L.copy s hs = s := rfl
lemma copy_eq (L : BooleanSubalgebra α) (s : Set α) (hs) : L.copy s hs = L :=
SetLike.coe_injective hs
/-- Two boolean subalgebras are equal if they have the same elements. -/
lemma ext : (∀ a, a ∈ L ↔ a ∈ M) → L = M := SetLike.ext
/-- A boolean subalgebra of a lattice inherits a bottom element. -/
instance instBotCoe : Bot L where bot := ⟨⊥, bot_mem⟩
/-- A boolean subalgebra of a lattice inherits a top element. -/
instance instTopCoe : Top L where top := ⟨⊤, top_mem⟩
/-- A boolean subalgebra of a lattice inherits a supremum. -/
instance instSupCoe : Max L where max a b := ⟨a ⊔ b, L.supClosed a.2 b.2⟩
/-- A boolean subalgebra of a lattice inherits an infimum. -/
instance instInfCoe : Min L where min a b := ⟨a ⊓ b, L.infClosed a.2 b.2⟩
/-- A boolean subalgebra of a lattice inherits a complement. -/
instance instHasComplCoe : HasCompl L where compl a := ⟨aᶜ, compl_mem a.2⟩
/-- A boolean subalgebra of a lattice inherits a difference. -/
instance instSDiffCoe : SDiff L where sdiff a b := ⟨a \ b, sdiff_mem a.2 b.2⟩
/-- A boolean subalgebra of a lattice inherits a Heyting implication. -/
instance instHImpCoe : HImp L where himp a b := ⟨a ⇨ b, himp_mem a.2 b.2⟩
@[simp, norm_cast] lemma val_bot : (⊥ : L) = (⊥ : α) := rfl
@[simp, norm_cast] lemma val_top : (⊤ : L) = (⊤ : α) := rfl
@[simp, norm_cast] lemma val_sup (a b : L) : a ⊔ b = (a : α) ⊔ b := rfl
@[simp, norm_cast] lemma val_inf (a b : L) : a ⊓ b = (a : α) ⊓ b := rfl
@[simp, norm_cast] lemma val_compl (a : L) : aᶜ = (a : α)ᶜ := rfl
@[simp, norm_cast] lemma val_sdiff (a b : L) : a \ b = (a : α) \ b := rfl
@[simp, norm_cast] lemma val_himp (a b : L) : a ⇨ b = (a : α) ⇨ b := rfl
@[simp] lemma mk_bot : (⟨⊥, bot_mem⟩ : L) = ⊥ := rfl
@[simp] lemma mk_top : (⟨⊤, top_mem⟩ : L) = ⊤ := rfl
@[simp] lemma mk_sup_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊔ ⟨b, hb⟩ : L) = ⟨a ⊔ b, L.supClosed ha hb⟩ :=
rfl
@[simp] lemma mk_inf_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⊓ ⟨b, hb⟩ : L) = ⟨a ⊓ b, L.infClosed ha hb⟩ :=
rfl
@[simp] lemma compl_mk (a : α) (ha) : (⟨a, ha⟩ : L)ᶜ = ⟨aᶜ, compl_mem ha⟩ := rfl
@[simp] lemma mk_sdiff_mk (a b : α) (ha hb) : (⟨a, ha⟩ \ ⟨b, hb⟩ : L) = ⟨a \ b, sdiff_mem ha hb⟩ :=
rfl
@[simp] lemma mk_himp_mk (a b : α) (ha hb) : (⟨a, ha⟩ ⇨ ⟨b, hb⟩ : L) = ⟨a ⇨ b, himp_mem ha hb⟩ :=
rfl
/-- A boolean subalgebra of a lattice inherits a boolean algebra structure. -/
instance instBooleanAlgebraCoe (L : BooleanSubalgebra α) : BooleanAlgebra L :=
Subtype.coe_injective.booleanAlgebra _ val_sup val_inf val_top val_bot val_compl val_sdiff
val_himp
/-- The natural lattice hom from a boolean subalgebra to the original lattice. -/
def subtype (L : BooleanSubalgebra α) : BoundedLatticeHom L α where
toFun := ((↑) : L → α)
map_bot' := L.val_bot
map_top' := L.val_top
map_sup' := val_sup
map_inf' := val_inf
@[simp, norm_cast] lemma coe_subtype (L : BooleanSubalgebra α) : L.subtype = ((↑) : L → α) := rfl
lemma subtype_apply (L : BooleanSubalgebra α) (a : L) : L.subtype a = a := rfl
lemma subtype_injective (L : BooleanSubalgebra α) : Injective <| subtype L := Subtype.coe_injective
/-- The inclusion homomorphism from a boolean subalgebra `L` to a bigger boolean subalgebra `M`. -/
def inclusion (h : L ≤ M) : BoundedLatticeHom L M where
toFun := Set.inclusion h
map_bot' := rfl
map_top' := rfl
map_sup' _ _ := rfl
map_inf' _ _ := rfl
@[simp] lemma coe_inclusion (h : L ≤ M) : inclusion h = Set.inclusion h := rfl
lemma inclusion_apply (h : L ≤ M) (a : L) : inclusion h a = Set.inclusion h a := rfl
lemma inclusion_injective (h : L ≤ M) : Injective <| inclusion h := Set.inclusion_injective h
@[simp] lemma inclusion_rfl (L : BooleanSubalgebra α) : inclusion le_rfl = .id L := rfl
@[simp] lemma subtype_comp_inclusion (h : L ≤ M) : M.subtype.comp (inclusion h) = L.subtype := rfl
/-- The maximum boolean subalgebra of a lattice. -/
instance instTop : Top (BooleanSubalgebra α) where
top.carrier := univ
top.bot_mem' := mem_univ _
top.compl_mem' _ := mem_univ _
top.supClosed' := supClosed_univ
top.infClosed' := infClosed_univ
/-- The trivial boolean subalgebra of a lattice. -/
instance instBot : Bot (BooleanSubalgebra α) where
bot.carrier := {⊥, ⊤}
bot.bot_mem' := by simp
bot.compl_mem' := by simp
bot.supClosed' _ := by simp
bot.infClosed' _ := by simp
/-- The inf of two boolean subalgebras is their intersection. -/
instance instInf : Min (BooleanSubalgebra α) where
min L M := { carrier := L ∩ M
bot_mem' := ⟨bot_mem, bot_mem⟩
compl_mem' := fun ha ↦ ⟨compl_mem ha.1, compl_mem ha.2⟩
supClosed' := L.supClosed.inter M.supClosed
infClosed' := L.infClosed.inter M.infClosed }
/-- The inf of boolean subalgebras is their intersection. -/
instance instInfSet : InfSet (BooleanSubalgebra α) where
sInf S := { carrier := ⋂ L ∈ S, L
bot_mem' := mem_iInter₂.2 fun _ _ ↦ bot_mem
compl_mem' := fun ha ↦ mem_iInter₂.2 fun L hL ↦ compl_mem <| mem_iInter₂.1 ha L hL
supClosed' := supClosed_sInter <| forall_mem_range.2 fun L ↦ supClosed_sInter <|
forall_mem_range.2 fun _ ↦ L.supClosed
infClosed' := infClosed_sInter <| forall_mem_range.2 fun L ↦ infClosed_sInter <|
forall_mem_range.2 fun _ ↦ L.infClosed }
instance instInhabited : Inhabited (BooleanSubalgebra α) := ⟨⊥⟩
/-- The top boolean subalgebra is isomorphic to the original boolean algebra.
This is the boolean subalgebra version of `Equiv.Set.univ α`. -/
def topEquiv : (⊤ : BooleanSubalgebra α) ≃o α where
toEquiv := Equiv.Set.univ _
map_rel_iff' := .rfl
@[simp, norm_cast] lemma coe_top : (⊤ : BooleanSubalgebra α) = (univ : Set α) := rfl
@[simp, norm_cast] lemma coe_bot : (⊥ : BooleanSubalgebra α) = ({⊥, ⊤} : Set α) := rfl
@[simp, norm_cast] lemma coe_inf (L M : BooleanSubalgebra α) : L ⊓ M = (L : Set α) ∩ M := rfl
@[simp, norm_cast]
lemma coe_sInf (S : Set (BooleanSubalgebra α)) : sInf S = ⋂ L ∈ S, (L : Set α) := rfl
@[simp, norm_cast]
lemma coe_iInf (f : ι → BooleanSubalgebra α) : ⨅ i, f i = ⋂ i, (f i : Set α) := by simp [iInf]
@[simp, norm_cast] lemma coe_eq_univ : L = (univ : Set α) ↔ L = ⊤ := by rw [← coe_top, coe_inj]
@[simp] lemma mem_bot : a ∈ (⊥ : BooleanSubalgebra α) ↔ a = ⊥ ∨ a = ⊤ := .rfl
@[simp] lemma mem_top : a ∈ (⊤ : BooleanSubalgebra α) := mem_univ _
@[simp] lemma mem_inf : a ∈ L ⊓ M ↔ a ∈ L ∧ a ∈ M := .rfl
@[simp] lemma mem_sInf {S : Set (BooleanSubalgebra α)} : a ∈ sInf S ↔ ∀ L ∈ S, a ∈ L := by
rw [← SetLike.mem_coe]; simp
@[simp] lemma mem_iInf {f : ι → BooleanSubalgebra α} : a ∈ ⨅ i, f i ↔ ∀ i, a ∈ f i := by
rw [← SetLike.mem_coe]; simp
/-- BooleanSubalgebras of a lattice form a complete lattice. -/
instance instCompleteLattice : CompleteLattice (BooleanSubalgebra α) where
bot := ⊥
bot_le _S _a := by aesop
top := ⊤
le_top _S a _ha := mem_top
inf := (· ⊓ ·)
le_inf _L _M _N hM hN _a ha := ⟨hM ha, hN ha⟩
inf_le_left _L _M _a := And.left
inf_le_right _L _M _a := And.right
__ := completeLatticeOfInf (BooleanSubalgebra α)
fun _s ↦ IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf
instance [IsEmpty α] : Subsingleton (BooleanSubalgebra α) := SetLike.coe_injective.subsingleton
instance [IsEmpty α] : Unique (BooleanSubalgebra α) := uniqueOfSubsingleton ⊤
/-- The preimage of a boolean subalgebra along a bounded lattice homomorphism. -/
def comap (f : BoundedLatticeHom α β) (L : BooleanSubalgebra β) : BooleanSubalgebra α where
carrier := f ⁻¹' L
bot_mem' := by simp
compl_mem' := by simp [map_compl']
supClosed' := L.supClosed.preimage _
infClosed' := L.infClosed.preimage _
@[simp, norm_cast]
lemma coe_comap (L : BooleanSubalgebra β) (f : BoundedLatticeHom α β) : L.comap f = f ⁻¹' L := rfl
@[simp] lemma mem_comap {L : BooleanSubalgebra β} : a ∈ L.comap f ↔ f a ∈ L := .rfl
lemma comap_mono : Monotone (comap f) := fun _ _ ↦ preimage_mono
@[simp] lemma comap_id (L : BooleanSubalgebra α) : L.comap (BoundedLatticeHom.id _) = L := rfl
@[simp] lemma comap_comap (L : BooleanSubalgebra γ) (g : BoundedLatticeHom β γ)
(f : BoundedLatticeHom α β) : (L.comap g).comap f = L.comap (g.comp f) := rfl
/-- The image of a boolean subalgebra along a monoid homomorphism is a boolean subalgebra. -/
def map (f : BoundedLatticeHom α β) (L : BooleanSubalgebra α) : BooleanSubalgebra β where
carrier := f '' L
bot_mem' := ⟨⊥, by simp⟩
compl_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨aᶜ, by simpa [map_compl']⟩
supClosed' := L.supClosed.image f
infClosed' := L.infClosed.image f
@[simp] lemma coe_map (f : BoundedLatticeHom α β) (L : BooleanSubalgebra α) :
(L.map f : Set β) = f '' L := rfl
@[simp] lemma mem_map {b : β} : b ∈ L.map f ↔ ∃ a ∈ L, f a = b := .rfl
lemma mem_map_of_mem (f : BoundedLatticeHom α β) {a : α} : a ∈ L → f a ∈ L.map f :=
mem_image_of_mem f
lemma apply_coe_mem_map (f : BoundedLatticeHom α β) (a : L) : f a ∈ L.map f :=
mem_map_of_mem f a.prop
lemma map_mono : Monotone (map f) := fun _ _ ↦ image_mono
@[simp] lemma map_id : L.map (.id α) = L := SetLike.coe_injective <| image_id _
@[simp] lemma map_map (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) :
(L.map f).map g = L.map (g.comp f) := SetLike.coe_injective <| image_image _ _ _
lemma mem_map_equiv {f : α ≃o β} {a : β} : a ∈ L.map f ↔ f.symm a ∈ L := Set.mem_image_equiv
lemma apply_mem_map_iff (hf : Injective f) : f a ∈ L.map f ↔ a ∈ L := hf.mem_set_image
lemma map_equiv_eq_comap_symm (f : α ≃o β) (L : BooleanSubalgebra α) :
L.map f = L.comap (f.symm : BoundedLatticeHom β α) :=
SetLike.coe_injective <| f.toEquiv.image_eq_preimage L
lemma comap_equiv_eq_map_symm (f : β ≃o α) (L : BooleanSubalgebra α) :
L.comap f = L.map (f.symm : BoundedLatticeHom α β) := (map_equiv_eq_comap_symm f.symm L).symm
lemma map_symm_eq_iff_eq_map {M : BooleanSubalgebra β} {e : β ≃o α} :
L.map ↑e.symm = M ↔ L = M.map ↑e := by
simp_rw [← coe_inj]; exact (Equiv.eq_image_iff_symm_image_eq _ _ _).symm
lemma map_le_iff_le_comap {f : BoundedLatticeHom α β} {M : BooleanSubalgebra β} :
L.map f ≤ M ↔ L ≤ M.comap f := image_subset_iff
lemma gc_map_comap (f : BoundedLatticeHom α β) : GaloisConnection (map f) (comap f) :=
fun _ _ ↦ map_le_iff_le_comap
@[simp] lemma map_bot (f : BoundedLatticeHom α β) : (⊥ : BooleanSubalgebra α).map f = ⊥ :=
(gc_map_comap f).l_bot
lemma map_sup (f : BoundedLatticeHom α β) (L M : BooleanSubalgebra α) :
(L ⊔ M).map f = L.map f ⊔ M.map f := (gc_map_comap f).l_sup
lemma map_iSup (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra α) :
(⨆ i, L i).map f = ⨆ i, (L i).map f := (gc_map_comap f).l_iSup
@[simp] lemma comap_top (f : BoundedLatticeHom α β) : (⊤ : BooleanSubalgebra β).comap f = ⊤ :=
(gc_map_comap f).u_top
lemma comap_inf (L M : BooleanSubalgebra β) (f : BoundedLatticeHom α β) :
(L ⊓ M).comap f = L.comap f ⊓ M.comap f := (gc_map_comap f).u_inf
lemma comap_iInf (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra β) :
(⨅ i, L i).comap f = ⨅ i, (L i).comap f := (gc_map_comap f).u_iInf
lemma map_inf_le (L M : BooleanSubalgebra α) (f : BoundedLatticeHom α β) :
map f (L ⊓ M) ≤ map f L ⊓ map f M := map_mono.map_inf_le _ _
lemma le_comap_sup (L M : BooleanSubalgebra β) (f : BoundedLatticeHom α β) :
comap f L ⊔ comap f M ≤ comap f (L ⊔ M) := comap_mono.le_map_sup _ _
lemma le_comap_iSup (f : BoundedLatticeHom α β) (L : ι → BooleanSubalgebra β) :
⨆ i, (L i).comap f ≤ (⨆ i, L i).comap f := comap_mono.le_map_iSup
lemma map_inf (L M : BooleanSubalgebra α) (f : BoundedLatticeHom α β) (hf : Injective f) :
map f (L ⊓ M) = map f L ⊓ map f M := by
rw [← SetLike.coe_set_eq]
simp [Set.image_inter hf]
lemma map_top (f : BoundedLatticeHom α β) (h : Surjective f) : BooleanSubalgebra.map f ⊤ = ⊤ :=
SetLike.coe_injective <| by simp [h.range_eq]
/-- The minimum boolean subalgebra containing a given set. -/
def closure (s : Set α) : BooleanSubalgebra α := sInf {L | s ⊆ L}
variable {s : Set α}
lemma mem_closure {x : α} : x ∈ closure s ↔ ∀ ⦃L : BooleanSubalgebra α⦄, s ⊆ L → x ∈ L := mem_sInf
@[simp, aesop safe 20 (rule_sets := [SetLike])]
lemma subset_closure : s ⊆ closure s := fun _ hx ↦ mem_closure.2 fun _ hK ↦ hK hx
@[aesop 80% (rule_sets := [SetLike])]
theorem mem_closure_of_mem {s : Set α} {x : α} (hx : x ∈ s) : x ∈ closure s := subset_closure hx
@[simp] lemma closure_le : closure s ≤ L ↔ s ⊆ L := ⟨subset_closure.trans, fun h ↦ sInf_le h⟩
lemma closure_mono (hst : s ⊆ t) : closure s ≤ closure t := sInf_le_sInf fun _L ↦ hst.trans
lemma latticeClosure_subset_closure : latticeClosure s ⊆ closure s :=
latticeClosure_min subset_closure (closure s).isSublattice
@[simp] lemma closure_latticeClosure (s : Set α) : closure (latticeClosure s) = closure s :=
le_antisymm (closure_le.2 latticeClosure_subset_closure) (closure_mono subset_latticeClosure)
/-- An induction principle for closure membership. If `p` holds for `⊥` and all elements of `s`, and
is preserved under suprema and complement, then `p` holds for all elements of the closure of `s`. -/
@[elab_as_elim]
lemma closure_bot_sup_induction {p : ∀ g ∈ closure s, Prop} (mem : ∀ x hx, p x (subset_closure hx))
(bot : p ⊥ bot_mem)
(sup : ∀ x hx y hy, p x hx → p y hy → p (x ⊔ y) (supClosed _ hx hy))
(compl : ∀ x hx, p x hx → p xᶜ (compl_mem hx)) {x} (hx : x ∈ closure s) : p x hx :=
have inf ⦃x hx y hy⦄ (hx' : p x hx) (hy' : p y hy) : p (x ⊓ y) (infClosed _ hx hy) := by
simpa using compl _ _ <| sup _ _ _ _ (compl _ _ hx') (compl _ _ hy')
let L : BooleanSubalgebra α :=
{ carrier := { x | ∃ hx, p x hx }
supClosed' := fun _a ⟨_, ha⟩ _b ⟨_, hb⟩ ↦ ⟨_, sup _ _ _ _ ha hb⟩
infClosed' := fun _a ⟨_, ha⟩ _b ⟨_, hb⟩ ↦ ⟨_, inf ha hb⟩
bot_mem' := ⟨_, bot⟩
compl_mem' := fun ⟨_, hb⟩ ↦ ⟨_, compl _ _ hb⟩ }
closure_le (L := L).mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id
section sdiff_sup
variable (isSublattice : IsSublattice s) (bot_mem : ⊥ ∈ s) (top_mem : ⊤ ∈ s)
include isSublattice bot_mem top_mem
theorem mem_closure_iff_sup_sdiff {a : α} :
a ∈ closure s ↔ ∃ t : Finset (s × s), a = t.sup fun x ↦ x.1.1 \ x.2.1 := by
classical
refine ⟨closure_bot_sup_induction
(fun x h ↦ ⟨{(⟨x, h⟩, ⟨⊥, bot_mem⟩)}, by simp⟩) ⟨∅, by simp⟩ ?_ ?_, ?_⟩
· rintro ⟨t, rfl⟩
exact t.sup_mem _ (subset_closure bot_mem) (fun _ h _ ↦ sup_mem h) _
fun x hx ↦ sdiff_mem (subset_closure x.1.2) (subset_closure x.2.2)
· rintro _ - _ - ⟨t₁, rfl⟩ ⟨t₂, rfl⟩
exact ⟨t₁ ∪ t₂, by rw [Finset.sup_union]⟩
rintro x - ⟨t, rfl⟩
refine t.induction ⟨{(⟨⊤, top_mem⟩, ⟨⊥, bot_mem⟩)}, by simp⟩ fun ⟨x, y⟩ t _ ⟨tc, eq⟩ ↦ ?_
simp_rw [Finset.sup_insert, compl_sup, eq]
refine tc.induction ⟨∅, by simp⟩ fun ⟨z, w⟩ tc _ ⟨t, eq⟩ ↦ ?_
simp_rw [Finset.sup_insert, inf_sup_left, eq]
use {(z, ⟨_, isSublattice.supClosed x.2 w.2⟩), (⟨_, isSublattice.infClosed y.2 z.2⟩, w)} ∪ t
simp_rw [Finset.sup_union, Finset.sup_insert, Finset.sup_singleton, sdiff_eq,
compl_sup, inf_left_comm z.1, compl_inf, compl_compl, inf_sup_right, inf_assoc]
@[elab_as_elim] theorem closure_sdiff_sup_induction {p : ∀ g ∈ closure s, Prop}
(sdiff : ∀ x hx y hy, p (x \ y) (sdiff_mem (subset_closure hx) (subset_closure hy)))
(sup : ∀ x hx y hy, p x hx → p y hy → p (x ⊔ y) (sup_mem hx hy))
(x) (hx : x ∈ closure s) : p x hx := by
obtain ⟨t, rfl⟩ := (mem_closure_iff_sup_sdiff isSublattice bot_mem top_mem).mp hx
revert hx
classical
refine t.induction (by simpa using sdiff _ bot_mem _ bot_mem) fun x t _ ih hxt ↦ ?_
simp only [Finset.sup_insert] at hxt ⊢
exact sup _ _ _ ((mem_closure_iff_sup_sdiff isSublattice bot_mem top_mem).mpr ⟨_, rfl⟩)
(sdiff _ x.1.2 _ x.2.2) (ih _)
end sdiff_sup
end BooleanAlgebra
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] {L : BooleanSubalgebra α} {f : ι → α} {s : Set α}
lemma iSup_mem [Finite ι] (hf : ∀ i, f i ∈ L) : ⨆ i, f i ∈ L := L.supClosed.iSup_mem bot_mem hf
lemma iInf_mem [Finite ι] (hf : ∀ i, f i ∈ L) : ⨅ i, f i ∈ L := L.infClosed.iInf_mem top_mem hf
lemma sSup_mem (hs : s.Finite) (hsL : s ⊆ L) : sSup s ∈ L := L.supClosed.sSup_mem hs bot_mem hsL
lemma sInf_mem (hs : s.Finite) (hsL : s ⊆ L) : sInf s ∈ L := L.infClosed.sInf_mem hs top_mem hsL
lemma biSup_mem {ι : Type*} {t : Set ι} {f : ι → α} (ht : t.Finite) (hf : ∀ i ∈ t, f i ∈ L) :
⨆ i ∈ t, f i ∈ L := L.supClosed.biSup_mem ht bot_mem hf
lemma biInf_mem {ι : Type*} {t : Set ι} {f : ι → α} (ht : t.Finite) (hf : ∀ i ∈ t, f i ∈ L) :
⨅ i ∈ t, f i ∈ L := L.infClosed.biInf_mem ht top_mem hf
end CompleteBooleanAlgebra
end BooleanSubalgebra
|
Injectivity.lean
|
/-
Copyright (c) 2024 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Analysis.InnerProductSpace.Basic
import Mathlib.Analysis.Normed.Group.Tannery
import Mathlib.NumberTheory.LSeries.Convergence
import Mathlib.NumberTheory.LSeries.Linearity
/-!
# A converging L-series determines its coefficients
We show that two functions `f` and `g : ℕ → ℂ` whose L-series agree and both converge somewhere
must agree on all nonzero arguments. See `LSeries_eq_iff_of_abscissaOfAbsConv_lt_top`
and `LSeries_injOn`.
-/
open LSeries Complex
-- The following two lemmas need both `LSeries.Linearity` and `LSeries.Convergence`,
-- so cannot live in either of these files.
/-- The abscissa of absolute convergence of `f + g` is at most the maximum of those
of `f` and `g`. -/
lemma LSeries.abscissaOfAbsConv_add_le (f g : ℕ → ℂ) :
abscissaOfAbsConv (f + g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) :=
abscissaOfAbsConv_binop_le LSeriesSummable.add f g
/-- The abscissa of absolute convergence of `f - g` is at most the maximum of those
of `f` and `g`. -/
lemma LSeries.abscissaOfAbsConv_sub_le (f g : ℕ → ℂ) :
abscissaOfAbsConv (f - g) ≤ max (abscissaOfAbsConv f) (abscissaOfAbsConv g) :=
abscissaOfAbsConv_binop_le LSeriesSummable.sub f g
private
lemma cpow_mul_div_cpow_eq_div_div_cpow (m n : ℕ) (z : ℂ) (x : ℝ) :
(n + 1) ^ (x : ℂ) * (z / m ^ (x : ℂ)) = z / (m / (n + 1)) ^ (x : ℂ) := by
have Hn : (0 : ℝ) ≤ (n + 1 : ℝ)⁻¹ := by positivity
rw [← mul_div_assoc, mul_comm, div_eq_mul_inv z, mul_div_assoc]
congr
simp_rw [div_eq_mul_inv]
rw [show (n + 1 : ℂ)⁻¹ = (n + 1 : ℝ)⁻¹ by simp,
show (n + 1 : ℂ) = (n + 1 : ℝ) by norm_cast, show (m : ℂ) = (m : ℝ) by norm_cast,
mul_cpow_ofReal_nonneg m.cast_nonneg Hn, mul_inv, mul_comm]
congr
rw [← cpow_neg, show (-x : ℂ) = (-1 : ℝ) * x by simp, cpow_mul_ofReal_nonneg Hn,
Real.rpow_neg_one, inv_inv]
open Filter Real in
/-- If the coefficients `f m` of an L-series are zero for `m ≤ n` and the L-series converges
at some point, then `f (n+1)` is the limit of `(n+1)^x * LSeries f x` as `x → ∞`. -/
lemma LSeries.tendsto_cpow_mul_atTop {f : ℕ → ℂ} {n : ℕ} (h : ∀ m ≤ n, f m = 0)
(ha : abscissaOfAbsConv f < ⊤) :
Tendsto (fun x : ℝ ↦ (n + 1) ^ (x : ℂ) * LSeries f x) atTop (nhds (f (n + 1))) := by
obtain ⟨y, hay, hyt⟩ := exists_between ha
lift y to ℝ using ⟨hyt.ne, ((OrderBot.bot_le _).trans_lt hay).ne'⟩
-- `F x m` is the `m`th term of `(n+1)^x * LSeries f x`, except that `F x (n+1) = 0`
let F := fun (x : ℝ) ↦ {m | n + 1 < m}.indicator (fun m ↦ f m / (m / (n + 1) : ℂ) ^ (x : ℂ))
have hF₀ (x : ℝ) {m : ℕ} (hm : m ≤ n + 1) : F x m = 0 := by simp [F, not_lt_of_ge hm]
have hF (x : ℝ) {m : ℕ} (hm : m ≠ n + 1) : F x m = ((n + 1) ^ (x : ℂ)) * term f x m := by
rcases lt_trichotomy m (n + 1) with H | rfl | H
· simp [Nat.not_lt_of_gt H, term, h m <| Nat.lt_succ_iff.mp H, F]
· exact (hm rfl).elim
· simp [H, term, (n.zero_lt_succ.trans H).ne', F, cpow_mul_div_cpow_eq_div_div_cpow]
have hs {x : ℝ} (hx : x ≥ y) : Summable fun m ↦ (n + 1) ^ (x : ℂ) * term f x m := by
refine (summable_mul_left_iff <| natCast_add_one_cpow_ne_zero n _).mpr <|
LSeriesSummable_of_abscissaOfAbsConv_lt_re ?_
simpa only [ofReal_re] using hay.trans_le <| EReal.coe_le_coe_iff.mpr hx
-- we can write `(n+1)^x * LSeries f x` as `f (n+1)` plus the series over `F x`
have key : ∀ x ≥ y, (n + 1) ^ (x : ℂ) * LSeries f x = f (n + 1) + ∑' m : ℕ, F x m := by
intro x hx
rw [LSeries, ← tsum_mul_left, (hs hx).tsum_eq_add_tsum_ite (n + 1), pow_mul_term_eq f x n]
congr
ext1 m
rcases eq_or_ne m (n + 1) with rfl | hm
· simp [hF₀ x le_rfl]
· simp [hm, hF]
-- reduce to showing that `∑' m, F x m → 0` as `x → ∞`
conv => enter [3, 1]; rw [← add_zero (f _)]
refine Tendsto.congr'
(eventuallyEq_of_mem (s := {x | y ≤ x}) (mem_atTop y) key).symm <| tendsto_const_nhds.add ?_
-- get the prerequisites for applying dominated convergence
have hys : Summable (F y) := by
refine ((hs le_rfl).indicator {m | n + 1 < m}).congr fun m ↦ ?_
by_cases hm : n + 1 < m
· simp [hF, hm, hm.ne']
· simp [hm, hF₀ _ (le_of_not_gt hm)]
have hc (k : ℕ) : Tendsto (F · k) atTop (nhds 0) := by
rcases lt_or_ge (n + 1) k with H | H
· have H₀ : (0 : ℝ) ≤ k / (n + 1) := by positivity
have H₀' : (0 : ℝ) ≤ (n + 1) / k := by positivity
have H₁ : (k / (n + 1) : ℂ) = (k / (n + 1) : ℝ) := by push_cast; rfl
have H₂ : (n + 1) / k < (1 : ℝ) :=
(div_lt_one <| mod_cast n.succ_pos.trans H).mpr <| mod_cast H
simp only [Set.mem_setOf_eq, H, Set.indicator_of_mem, F]
conv =>
enter [1, x]
rw [div_eq_mul_inv, H₁, ← ofReal_cpow H₀, ← ofReal_inv, ← Real.inv_rpow H₀, inv_div]
conv => enter [3, 1]; rw [← mul_zero (f k)]
exact
(tendsto_rpow_atTop_of_base_lt_one _ (neg_one_lt_zero.trans_le H₀') H₂).ofReal.const_mul _
· simp [hF₀ _ H]
rw [show (0 : ℂ) = tsum (fun _ : ℕ ↦ 0) from tsum_zero.symm]
refine tendsto_tsum_of_dominated_convergence hys.norm hc <| eventually_iff.mpr ?_
filter_upwards [mem_atTop y] with y' hy' k
-- it remains to show that `‖F y' k‖ ≤ ‖F y k‖` (for `y' ≥ y`)
rcases lt_or_ge (n + 1) k with H | H
· simp only [Set.mem_setOf_eq, H, Set.indicator_of_mem, norm_div, norm_cpow_real,
Complex.norm_natCast, F]
rw [← Nat.cast_one, ← Nat.cast_add, Complex.norm_natCast]
have hkn : 1 ≤ (k / (n + 1 :) : ℝ) :=
(one_le_div (by positivity)).mpr <| mod_cast Nat.le_of_succ_le H
gcongr
assumption
· simp [hF₀ _ H]
open Filter in
/-- If the L-series of `f` converges at some point, then `f 1` is the limit of `LSeries f x`
as `x → ∞`. -/
lemma LSeries.tendsto_atTop {f : ℕ → ℂ} (ha : abscissaOfAbsConv f < ⊤) :
Tendsto (fun x : ℝ ↦ LSeries f x) atTop (nhds (f 1)) := by
let F (n : ℕ) : ℂ := if n = 0 then 0 else f n
have hF₀ : F 0 = 0 := rfl
have hF {n : ℕ} (hn : n ≠ 0) : F n = f n := if_neg hn
have ha' : abscissaOfAbsConv F < ⊤ := (abscissaOfAbsConv_congr hF).symm ▸ ha
simp_rw [← LSeries_congr _ hF]
convert LSeries.tendsto_cpow_mul_atTop (n := 0) (fun _ hm ↦ Nat.le_zero.mp hm ▸ hF₀) ha' using 1
simp
lemma LSeries_eq_zero_of_abscissaOfAbsConv_eq_top {f : ℕ → ℂ} (h : abscissaOfAbsConv f = ⊤) :
LSeries f = 0 := by
ext1 s
exact LSeries.eq_zero_of_not_LSeriesSummable f s <| mt LSeriesSummable.abscissaOfAbsConv_le <|
h ▸ fun H ↦ (H.trans_lt <| EReal.coe_lt_top _).false
open Filter Nat in
/-- The `LSeries` of `f` is zero for large real arguments if and only if either `f n = 0`
for all `n ≠ 0` or the L-series converges nowhere. -/
lemma LSeries_eventually_eq_zero_iff' {f : ℕ → ℂ} :
(fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] 0 ↔ (∀ n ≠ 0, f n = 0) ∨ abscissaOfAbsConv f = ⊤ := by
by_cases h : abscissaOfAbsConv f = ⊤
· simpa [h] using
Eventually.of_forall <| by simp [LSeries_eq_zero_of_abscissaOfAbsConv_eq_top h]
· simp only [ne_eq, h, or_false]
refine ⟨fun H ↦ ?_, fun H ↦ Eventually.of_forall fun x ↦ ?_⟩
· let F (n : ℕ) : ℂ := if n = 0 then 0 else f n
have hF₀ : F 0 = 0 := rfl
have hF {n : ℕ} (hn : n ≠ 0) : F n = f n := if_neg hn
suffices ∀ n, F n = 0 from fun n hn ↦ (hF hn).symm.trans (this n)
have ha : ¬ abscissaOfAbsConv F = ⊤ := abscissaOfAbsConv_congr hF ▸ h
have h' (x : ℝ) : LSeries F x = LSeries f x := LSeries_congr x hF
have H' (n : ℕ) : (fun x : ℝ ↦ n ^ (x : ℂ) * LSeries F x) =ᶠ[atTop] fun _ ↦ 0 := by
simp only [h']
rw [eventuallyEq_iff_exists_mem] at H ⊢
obtain ⟨s, hs⟩ := H
exact ⟨s, hs.1, fun x hx ↦ by simp [hs.2 hx]⟩
intro n
induction n using Nat.strongRecOn with | ind n ih =>
-- it suffices to show that `n ^ x * LSeries F x` tends to `F n` as `x` tends to `∞`
suffices Tendsto (fun x : ℝ ↦ n ^ (x : ℂ) * LSeries F x) atTop (nhds (F n)) by
replace this := this.congr' <| H' n
simp only [tendsto_const_nhds_iff] at this
exact this.symm
cases n with
| zero => exact Tendsto.congr' (H' 0).symm <| by simp [hF₀]
| succ n =>
simpa using LSeries.tendsto_cpow_mul_atTop (fun m hm ↦ ih m <| lt_succ_of_le hm) <|
Ne.lt_top ha
· simp [LSeries_congr x fun {n} ↦ H n, show (fun _ : ℕ ↦ (0 : ℂ)) = 0 from rfl]
open Nat in
/-- Assuming `f 0 = 0`, the `LSeries` of `f` is zero if and only if either `f = 0` or the
L-series converges nowhere. -/
lemma LSeries_eq_zero_iff {f : ℕ → ℂ} (hf : f 0 = 0) :
LSeries f = 0 ↔ f = 0 ∨ abscissaOfAbsConv f = ⊤ := by
by_cases h : abscissaOfAbsConv f = ⊤
· simpa [h] using LSeries_eq_zero_of_abscissaOfAbsConv_eq_top h
· simp only [h, or_false]
refine ⟨fun H ↦ ?_, fun H ↦ H ▸ LSeries_zero⟩
convert (LSeries_eventually_eq_zero_iff'.mp ?_).resolve_right h
· refine ⟨fun H' _ _ ↦ by rw [H', Pi.zero_apply], fun H' ↦ ?_⟩
ext (- | m)
· simp [hf]
· simp [H']
· simpa only [H] using Filter.EventuallyEq.rfl
open Filter in
/-- If the `LSeries` of `f` and of `g` converge somewhere and agree on large real arguments,
then the L-series of `f - g` is zero for large real arguments. -/
lemma LSeries_sub_eventuallyEq_zero_of_LSeries_eventually_eq {f g : ℕ → ℂ}
(hf : abscissaOfAbsConv f < ⊤) (hg : abscissaOfAbsConv g < ⊤)
(h : (fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] fun x ↦ LSeries g x) :
(fun x : ℝ ↦ LSeries (f - g) x) =ᶠ[atTop] (0 : ℝ → ℂ) := by
rw [EventuallyEq, eventually_atTop] at h ⊢
obtain ⟨x₀, hx₀⟩ := h
obtain ⟨yf, hyf₁, hyf₂⟩ := exists_between hf
obtain ⟨yg, hyg₁, hyg₂⟩ := exists_between hg
lift yf to ℝ using ⟨hyf₂.ne, ((OrderBot.bot_le _).trans_lt hyf₁).ne'⟩
lift yg to ℝ using ⟨hyg₂.ne, ((OrderBot.bot_le _).trans_lt hyg₁).ne'⟩
refine ⟨max x₀ (max yf yg), fun x hx ↦ ?_⟩
have Hf : LSeriesSummable f x := by
refine LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ hyf₁.trans_le (EReal.coe_le_coe_iff.mpr ?_)
exact (le_max_left _ yg).trans <| (le_max_right x₀ _).trans hx
have Hg : LSeriesSummable g x := by
refine LSeriesSummable_of_abscissaOfAbsConv_lt_re <|
(ofReal_re x).symm ▸ hyg₁.trans_le (EReal.coe_le_coe_iff.mpr ?_)
exact (le_max_right yf _).trans <| (le_max_right x₀ _).trans hx
rw [LSeries_sub Hf Hg, hx₀ x <| (le_max_left ..).trans hx, sub_self, Pi.zero_apply]
open Filter in
/-- If the `LSeries` of `f` and of `g` converge somewhere and agree on large real arguments,
then `f n = g n` whenever `n ≠ 0`. -/
lemma LSeries.eq_of_LSeries_eventually_eq {f g : ℕ → ℂ} (hf : abscissaOfAbsConv f < ⊤)
(hg : abscissaOfAbsConv g < ⊤) (h : (fun x : ℝ ↦ LSeries f x) =ᶠ[atTop] fun x ↦ LSeries g x)
{n : ℕ} (hn : n ≠ 0) :
f n = g n := by
have hsub : (fun x : ℝ ↦ LSeries (f - g) x) =ᶠ[atTop] (0 : ℝ → ℂ) :=
LSeries_sub_eventuallyEq_zero_of_LSeries_eventually_eq hf hg h
have ha : abscissaOfAbsConv (f - g) ≠ ⊤ :=
lt_top_iff_ne_top.mp <| (abscissaOfAbsConv_sub_le f g).trans_lt <| max_lt hf hg
simpa only [Pi.sub_apply, sub_eq_zero]
using (LSeries_eventually_eq_zero_iff'.mp hsub).resolve_right ha n hn
/-- If the `LSeries` of `f` and of `g` both converge somewhere, then they are equal if and only
if `f n = g n` whenever `n ≠ 0`. -/
lemma LSeries_eq_iff_of_abscissaOfAbsConv_lt_top {f g : ℕ → ℂ} (hf : abscissaOfAbsConv f < ⊤)
(hg : abscissaOfAbsConv g < ⊤) :
LSeries f = LSeries g ↔ ∀ n ≠ 0, f n = g n := by
refine ⟨fun H n hn ↦ ?_, fun H ↦ funext (LSeries_congr · fun {n} ↦ H n)⟩
refine eq_of_LSeries_eventually_eq hf hg ?_ hn
exact Filter.Eventually.of_forall fun x ↦ congr_fun H x
/-- The map `f ↦ LSeries f` is injective on functions `f` such that `f 0 = 0` and the L-series
of `f` converges somewhere. -/
lemma LSeries_injOn : Set.InjOn LSeries {f | f 0 = 0 ∧ abscissaOfAbsConv f < ⊤} := by
intro f hf g hg h
simp only [Set.mem_setOf] at hf hg
replace h := (LSeries_eq_iff_of_abscissaOfAbsConv_lt_top hf.2 hg.2).mp h
ext1 n
cases n with
| zero => exact hf.1.trans hg.1.symm
| succ n => exact h _ n.zero_ne_add_one.symm
|
Ideal.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Submodule
/-!
# Lie Ideals
This file defines Lie ideals, which are Lie submodules of a Lie algebra over itself.
They are defined as a special case of `LieSubmodule`, and inherit much of their structure from it.
We also prove some basic properties of Lie ideals, including how they behave under
Lie algebra homomorphisms (`map`, `comap`) and how they relate to the lattice structure
on Lie submodules.
## Main definitions
* `LieIdeal`
* `LieIdeal.map`
* `LieIdeal.comap`
## Tags
Lie algebra, ideal, submodule, Lie submodule
-/
universe u v w w₁ w₂
section LieSubmodule
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
section LieIdeal
variable [LieAlgebra R L] [LieModule R L M]
/-- An ideal of a Lie algebra is a Lie submodule of the Lie algebra as a Lie module over itself. -/
abbrev LieIdeal :=
LieSubmodule R L L
theorem lie_mem_right (I : LieIdeal R L) (x y : L) (h : y ∈ I) : ⁅x, y⁆ ∈ I :=
I.lie_mem h
theorem lie_mem_left (I : LieIdeal R L) (x y : L) (h : x ∈ I) : ⁅x, y⁆ ∈ I := by
rw [← lie_skew, ← neg_lie]; apply lie_mem_right; assumption
/-- An ideal of a Lie algebra is a Lie subalgebra. -/
def LieIdeal.toLieSubalgebra (I : LieIdeal R L) : LieSubalgebra R L :=
{ I.toSubmodule with lie_mem' := by intro x y _ hy; apply lie_mem_right; exact hy }
instance : Coe (LieIdeal R L) (LieSubalgebra R L) :=
⟨LieIdeal.toLieSubalgebra R L⟩
@[simp]
theorem LieIdeal.coe_toLieSubalgebra (I : LieIdeal R L) : ((I : LieSubalgebra R L) : Set L) = I :=
rfl
@[simp]
theorem LieIdeal.toLieSubalgebra_toSubmodule (I : LieIdeal R L) :
((I : LieSubalgebra R L) : Submodule R L) = LieSubmodule.toSubmodule I :=
rfl
/-- An ideal of `L` is a Lie subalgebra of `L`, so it is a Lie ring. -/
instance LieIdeal.lieRing (I : LieIdeal R L) : LieRing I :=
LieSubalgebra.lieRing R L ↑I
/-- Transfer the `LieAlgebra` instance from the coercion `LieIdeal → LieSubalgebra`. -/
instance LieIdeal.lieAlgebra (I : LieIdeal R L) : LieAlgebra R I :=
LieSubalgebra.lieAlgebra R L ↑I
/-- Transfer the `LieRingModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/
instance LieIdeal.lieRingModule {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
(I : LieIdeal R L) [LieRingModule L M] : LieRingModule I M :=
LieSubalgebra.lieRingModule (I : LieSubalgebra R L)
@[simp]
theorem LieIdeal.coe_bracket_of_module {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
(I : LieIdeal R L) [LieRingModule L M] (x : I) (m : M) :
⁅x, m⁆ = ⁅(↑x : L), m⁆ :=
LieSubalgebra.coe_bracket_of_module (I : LieSubalgebra R L) x m
/-- Transfer the `LieModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/
instance LieIdeal.lieModule (I : LieIdeal R L) : LieModule R I M :=
LieSubalgebra.lieModule (I : LieSubalgebra R L)
instance (I : LieIdeal R L) : IsLieTower I L M where
leibniz_lie x y m := leibniz_lie x.val y m
instance (I : LieIdeal R L) : IsLieTower L I M where
leibniz_lie x y m := leibniz_lie x y.val m
end LieIdeal
namespace LieSubalgebra
variable {L}
variable [LieAlgebra R L]
variable (K : LieSubalgebra R L)
theorem exists_lieIdeal_coe_eq_iff :
(∃ I : LieIdeal R L, ↑I = K) ↔ ∀ x y : L, y ∈ K → ⁅x, y⁆ ∈ K := by
simp only [← toSubmodule_inj, LieIdeal.toLieSubalgebra_toSubmodule,
Submodule.exists_lieSubmodule_coe_eq_iff L, mem_toSubmodule]
theorem exists_nested_lieIdeal_coe_eq_iff {K' : LieSubalgebra R L} (h : K ≤ K') :
(∃ I : LieIdeal R K', ↑I = ofLe h) ↔ ∀ x y : L, x ∈ K' → y ∈ K → ⁅x, y⁆ ∈ K := by
simp only [exists_lieIdeal_coe_eq_iff, coe_bracket, mem_ofLe]
constructor
· intro h' x y hx hy; exact h' ⟨x, hx⟩ ⟨y, h hy⟩ hy
· rintro h' ⟨x, hx⟩ ⟨y, hy⟩ hy'; exact h' x y hx hy'
end LieSubalgebra
end LieSubmodule
section LieSubmoduleMapAndComap
variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁}
variable [CommRing R] [LieRing L] [LieRing L'] [LieAlgebra R L']
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup M'] [Module R M'] [LieRingModule L M']
namespace LieIdeal
variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M']
variable (f : L →ₗ⁅R⁆ L') (I I₂ : LieIdeal R L) (J : LieIdeal R L')
@[simp]
theorem top_toLieSubalgebra : ((⊤ : LieIdeal R L) : LieSubalgebra R L) = ⊤ :=
rfl
/-- A morphism of Lie algebras `f : L → L'` pushes forward Lie ideals of `L` to Lie ideals of `L'`.
Note that unlike `LieSubmodule.map`, we must take the `lieSpan` of the image. Mathematically
this is because although `f` makes `L'` into a Lie module over `L`, in general the `L` submodules of
`L'` are not the same as the ideals of `L'`. -/
def map : LieIdeal R L' :=
LieSubmodule.lieSpan R L' <| (I : Submodule R L).map (f : L →ₗ[R] L')
/-- A morphism of Lie algebras `f : L → L'` pulls back Lie ideals of `L'` to Lie ideals of `L`.
Note that `f` makes `L'` into a Lie module over `L` (turning `f` into a morphism of Lie modules)
and so this is a special case of `LieSubmodule.comap` but we do not exploit this fact. -/
def comap : LieIdeal R L :=
{ (J : Submodule R L').comap (f : L →ₗ[R] L') with
lie_mem := fun {x y} h ↦ by
suffices ⁅f x, f y⁆ ∈ J by
simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
Submodule.mem_toAddSubmonoid, Submodule.mem_comap, LieHom.coe_toLinearMap, LieHom.map_lie,
LieSubalgebra.mem_toSubmodule]
exact this
apply J.lie_mem h }
@[simp]
theorem map_toSubmodule (h : ↑(map f I) = f '' I) :
LieSubmodule.toSubmodule (map f I) = (LieSubmodule.toSubmodule I).map (f : L →ₗ[R] L') := by
rw [SetLike.ext'_iff, LieSubmodule.coe_toSubmodule, h, Submodule.map_coe]; rfl
@[simp]
theorem comap_toSubmodule :
(LieSubmodule.toSubmodule (comap f J)) = (LieSubmodule.toSubmodule J).comap (f : L →ₗ[R] L') :=
rfl
theorem map_le : map f I ≤ J ↔ f '' I ⊆ J :=
LieSubmodule.lieSpan_le
variable {f I I₂ J}
theorem mem_map {x : L} (hx : x ∈ I) : f x ∈ map f I := by
apply LieSubmodule.subset_lieSpan
use x
exact ⟨hx, rfl⟩
@[simp]
theorem mem_comap {x : L} : x ∈ comap f J ↔ f x ∈ J :=
Iff.rfl
theorem map_le_iff_le_comap : map f I ≤ J ↔ I ≤ comap f J := by
rw [map_le]
exact Set.image_subset_iff
variable (f) in
theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap
@[simp]
theorem map_sup : (I ⊔ I₂).map f = I.map f ⊔ I₂.map f :=
(gc_map_comap f).l_sup
theorem map_comap_le : map f (comap f J) ≤ J := by rw [map_le_iff_le_comap]
/-- See also `LieIdeal.map_comap_eq`. -/
theorem comap_map_le : I ≤ comap f (map f I) := by rw [← map_le_iff_le_comap]
@[mono]
theorem map_mono : Monotone (map f) := fun I₁ I₂ h ↦ by
unfold map
gcongr; exact h
@[mono]
theorem comap_mono : Monotone (comap f) := fun J₁ J₂ h ↦ by
rw [← SetLike.coe_subset_coe] at h ⊢
dsimp only [SetLike.coe]
exact Set.preimage_mono h
theorem map_of_image (h : f '' I = J) : I.map f = J := by
apply le_antisymm
· rw [map, LieSubmodule.lieSpan_le, Submodule.map_coe]
/- I'm uncertain how to best resolve this `erw`.
```
have : (↑(toLieSubalgebra R L I).toSubmodule : Set L) = I := rfl
rw [this]
simp [h]
```
works, but still feels awkward. There are missing `simp` lemmas here.`
-/
erw [h]
· rw [← SetLike.coe_subset_coe, ← h]; exact LieSubmodule.subset_lieSpan
/-- Note that this is not a special case of `LieSubmodule.subsingleton_of_bot`. Indeed, given
`I : LieIdeal R L`, in general the two lattices `LieIdeal R I` and `LieSubmodule R L I` are
different (though the latter does naturally inject into the former).
In other words, in general, ideals of `I`, regarded as a Lie algebra in its own right, are not the
same as ideals of `L` contained in `I`. -/
instance subsingleton_of_bot : Subsingleton (LieIdeal R (⊥ : LieIdeal R L)) := by
apply subsingleton_of_bot_eq_top
subsingleton
end LieIdeal
namespace LieHom
variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M']
variable (f : L →ₗ⁅R⁆ L') (I : LieIdeal R L) (J : LieIdeal R L')
/-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/
def ker : LieIdeal R L :=
LieIdeal.comap f ⊥
/-- The range of a morphism of Lie algebras as an ideal in the codomain. -/
def idealRange : LieIdeal R L' :=
LieSubmodule.lieSpan R L' f.range
theorem idealRange_eq_lieSpan_range : f.idealRange = LieSubmodule.lieSpan R L' f.range :=
rfl
theorem idealRange_eq_map : f.idealRange = LieIdeal.map f ⊤ := by
ext
simp only [idealRange, range_eq_map]
rfl
/-- The condition that the range of a morphism of Lie algebras is an ideal. -/
def IsIdealMorphism : Prop :=
(f.idealRange : LieSubalgebra R L') = f.range
theorem isIdealMorphism_def : f.IsIdealMorphism ↔ (f.idealRange : LieSubalgebra R L') = f.range :=
Iff.rfl
variable {f} in
theorem IsIdealMorphism.eq (hf : f.IsIdealMorphism) : f.idealRange = f.range := hf
theorem isIdealMorphism_iff : f.IsIdealMorphism ↔ ∀ (x : L') (y : L), ∃ z : L, ⁅x, f y⁆ = f z := by
simp only [isIdealMorphism_def, idealRange_eq_lieSpan_range, ←
LieSubalgebra.toSubmodule_inj, ← f.range.coe_toSubmodule,
LieIdeal.toLieSubalgebra_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff,
LieSubalgebra.mem_toSubmodule, mem_range, exists_imp,
Submodule.exists_lieSubmodule_coe_eq_iff]
constructor
· intro h x y; obtain ⟨z, hz⟩ := h x (f y) y rfl; use z; exact hz.symm
· intro h x y z hz; obtain ⟨w, hw⟩ := h x z; use w; rw [← hw, hz]
theorem range_subset_idealRange : (f.range : Set L') ⊆ f.idealRange :=
LieSubmodule.subset_lieSpan
theorem map_le_idealRange : I.map f ≤ f.idealRange := by
rw [f.idealRange_eq_map]
exact LieIdeal.map_mono le_top
theorem ker_le_comap : f.ker ≤ J.comap f :=
LieIdeal.comap_mono bot_le
@[simp]
theorem ker_toSubmodule : LieSubmodule.toSubmodule (ker f) = LinearMap.ker (f : L →ₗ[R] L') :=
rfl
variable {f} in
@[simp]
theorem mem_ker {x : L} : x ∈ ker f ↔ f x = 0 :=
show x ∈ LieSubmodule.toSubmodule (f.ker) ↔ _ by
simp only [ker_toSubmodule, LinearMap.mem_ker, coe_toLinearMap]
theorem mem_idealRange (x : L) : f x ∈ idealRange f := by
rw [idealRange_eq_map]
exact LieIdeal.mem_map (LieSubmodule.mem_top x)
@[simp]
theorem mem_idealRange_iff (h : IsIdealMorphism f) {y : L'} :
y ∈ idealRange f ↔ ∃ x : L, f x = y := by
rw [f.isIdealMorphism_def] at h
rw [← LieSubmodule.mem_coe, ← LieIdeal.coe_toLieSubalgebra, h, f.range_coe, Set.mem_range]
theorem le_ker_iff : I ≤ f.ker ↔ ∀ x, x ∈ I → f x = 0 := by
constructor <;> intro h x hx
· specialize h hx; rw [mem_ker] at h; exact h
· rw [mem_ker]; apply h x hx
theorem ker_eq_bot : f.ker = ⊥ ↔ Function.Injective f := by
rw [← LieSubmodule.toSubmodule_inj, ker_toSubmodule, LieSubmodule.bot_toSubmodule,
LinearMap.ker_eq_bot, coe_toLinearMap]
@[simp]
theorem range_toSubmodule : (f.range : Submodule R L') = LinearMap.range (f : L →ₗ[R] L') :=
rfl
theorem range_eq_top : f.range = ⊤ ↔ Function.Surjective f := by
rw [← LieSubalgebra.toSubmodule_inj, range_toSubmodule, LieSubalgebra.top_toSubmodule]
exact LinearMap.range_eq_top
@[simp]
theorem idealRange_eq_top_of_surjective (h : Function.Surjective f) : f.idealRange = ⊤ := by
rw [← f.range_eq_top] at h
rw [idealRange_eq_lieSpan_range, h, ← LieSubalgebra.coe_toSubmodule, ←
LieSubmodule.toSubmodule_inj, LieSubmodule.top_toSubmodule,
LieSubalgebra.top_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff]
use ⊤
exact LieSubmodule.top_toSubmodule
theorem isIdealMorphism_of_surjective (h : Function.Surjective f) : f.IsIdealMorphism := by
rw [isIdealMorphism_def, f.idealRange_eq_top_of_surjective h, f.range_eq_top.mpr h,
LieIdeal.top_toLieSubalgebra]
end LieHom
namespace LieIdeal
variable [LieAlgebra R L] [LieModule R L M] [LieModule R L M']
variable {f : L →ₗ⁅R⁆ L'} {I I₂ : LieIdeal R L} {J : LieIdeal R L'}
@[simp]
theorem map_eq_bot_iff : I.map f = ⊥ ↔ I ≤ f.ker := by
rw [← le_bot_iff]
exact LieIdeal.map_le_iff_le_comap
theorem coe_map_of_surjective (h : Function.Surjective f) :
LieSubmodule.toSubmodule (I.map f) = (LieSubmodule.toSubmodule I).map (f : L →ₗ[R] L') := by
let J : LieIdeal R L' :=
{ (I : Submodule R L).map (f : L →ₗ[R] L') with
lie_mem := fun {x y} hy ↦ by
have hy' : ∃ x : L, x ∈ I ∧ f x = y := by simpa [hy]
obtain ⟨z₂, hz₂, rfl⟩ := hy'
obtain ⟨z₁, rfl⟩ := h x
simp only [LieHom.coe_toLinearMap, SetLike.mem_coe, Set.mem_image, Submodule.mem_carrier,
Submodule.map_coe]
use ⁅z₁, z₂⁆
exact ⟨I.lie_mem hz₂, f.map_lie z₁ z₂⟩ }
rw [map, toLieSubalgebra_toSubmodule, LieSubmodule.coe_lieSpan_submodule_eq_iff]
exact ⟨J, rfl⟩
theorem mem_map_of_surjective {y : L'} (h₁ : Function.Surjective f) (h₂ : y ∈ I.map f) :
∃ x : I, f x = y := by
rw [← LieSubmodule.mem_toSubmodule, coe_map_of_surjective h₁, Submodule.mem_map] at h₂
obtain ⟨x, hx, rfl⟩ := h₂
use ⟨x, hx⟩
rw [LieHom.coe_toLinearMap]
theorem bot_of_map_eq_bot {I : LieIdeal R L} (h₁ : Function.Injective f) (h₂ : I.map f = ⊥) :
I = ⊥ := by
rw [← f.ker_eq_bot, LieHom.ker] at h₁
rw [eq_bot_iff, map_le_iff_le_comap, h₁] at h₂
rw [eq_bot_iff]; exact h₂
/-- Given two nested Lie ideals `I₁ ⊆ I₂`, the inclusion `I₁ ↪ I₂` is a morphism of Lie algebras. -/
def inclusion {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) : I₁ →ₗ⁅R⁆ I₂ where
__ := Submodule.inclusion (show I₁.toSubmodule ≤ I₂.toSubmodule from h)
map_lie' := rfl
@[simp]
theorem coe_inclusion {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) (x : I₁) : (inclusion h x : L) = x :=
rfl
theorem inclusion_apply {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) (x : I₁) :
inclusion h x = ⟨x.1, h x.2⟩ :=
rfl
theorem inclusion_injective {I₁ I₂ : LieIdeal R L} (h : I₁ ≤ I₂) :
Function.Injective (inclusion h) :=
fun x y ↦ by
simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe]
theorem map_sup_ker_eq_map : LieIdeal.map f (I ⊔ f.ker) = LieIdeal.map f I := by
refine le_antisymm ?_ (LieIdeal.map_mono le_sup_left)
apply LieSubmodule.lieSpan_mono
rintro x ⟨y, hy₁, hy₂⟩
rw [← hy₂]
erw [LieSubmodule.mem_sup] at hy₁
obtain ⟨z₁, hz₁, z₂, hz₂, hy⟩ := hy₁
rw [← hy]
rw [f.coe_toLinearMap, f.map_add, LieHom.mem_ker.mp hz₂, add_zero]; exact ⟨z₁, hz₁, rfl⟩
@[simp]
theorem map_sup_ker_eq_map' :
LieIdeal.map f I ⊔ LieIdeal.map f (LieHom.ker f) = LieIdeal.map f I := by
simpa using map_sup_ker_eq_map (f := f)
@[simp]
theorem map_comap_eq (h : f.IsIdealMorphism) : map f (comap f J) = f.idealRange ⊓ J := by
apply le_antisymm
· rw [le_inf_iff]; exact ⟨f.map_le_idealRange _, map_comap_le⟩
· rw [f.isIdealMorphism_def] at h
rw [← SetLike.coe_subset_coe, LieSubmodule.inf_coe, ← coe_toLieSubalgebra, h]
rintro y ⟨⟨x, h₁⟩, h₂⟩; rw [← h₁] at h₂ ⊢; exact mem_map h₂
@[simp]
theorem comap_map_eq (h : ↑(map f I) = f '' I) : comap f (map f I) = I ⊔ f.ker := by
rw [← LieSubmodule.toSubmodule_inj, comap_toSubmodule, I.map_toSubmodule f h,
LieSubmodule.sup_toSubmodule, f.ker_toSubmodule, Submodule.comap_map_eq]
variable (f I J)
/-- Regarding an ideal `I` as a subalgebra, the inclusion map into its ambient space is a morphism
of Lie algebras. -/
def incl : I →ₗ⁅R⁆ L :=
(I : LieSubalgebra R L).incl
@[simp]
theorem incl_range : I.incl.range = I :=
(I : LieSubalgebra R L).incl_range
@[simp]
theorem incl_apply (x : I) : I.incl x = x :=
rfl
@[simp]
theorem incl_coe : (I.incl.toLinearMap : I →ₗ[R] L) = (I : Submodule R L).subtype :=
rfl
lemma incl_injective (I : LieIdeal R L) : Function.Injective I.incl :=
Subtype.val_injective
@[simp]
theorem comap_incl_self : comap I.incl I = ⊤ := by ext; simp
@[simp]
theorem ker_incl : I.incl.ker = ⊥ := by ext; simp
@[simp]
theorem incl_idealRange : I.incl.idealRange = I := by
rw [LieHom.idealRange_eq_lieSpan_range, ← LieSubalgebra.coe_toSubmodule, ←
LieSubmodule.toSubmodule_inj, incl_range, toLieSubalgebra_toSubmodule,
LieSubmodule.coe_lieSpan_submodule_eq_iff]
use I
theorem incl_isIdealMorphism : I.incl.IsIdealMorphism := by
rw [I.incl.isIdealMorphism_def, incl_idealRange]
exact (I : LieSubalgebra R L).incl_range.symm
variable {I}
@[simp] theorem comap_incl_eq_top : I₂.comap I.incl = ⊤ ↔ I ≤ I₂ := by
rw [← LieSubmodule.toSubmodule_inj, LieIdeal.comap_toSubmodule, LieSubmodule.top_toSubmodule,
incl_coe]
simp_rw [toLieSubalgebra_toSubmodule]
rw [Submodule.comap_subtype_eq_top, LieSubmodule.toSubmodule_le_toSubmodule]
@[simp] theorem comap_incl_eq_bot : I₂.comap I.incl = ⊥ ↔ Disjoint I I₂ := by
rw [disjoint_iff, ←LieSubmodule.toSubmodule_inj, LieIdeal.comap_toSubmodule,
LieSubmodule.bot_toSubmodule, ← LieSubmodule.toSubmodule_inj, LieSubmodule.inf_toSubmodule,
LieSubmodule.bot_toSubmodule, incl_coe]
simp_rw [toLieSubalgebra_toSubmodule]
rw [← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff]
end LieIdeal
end LieSubmoduleMapAndComap
section TopEquiv
variable (R : Type u) (L : Type v)
variable [CommRing R] [LieRing L]
variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M]
variable {R L}
variable [LieAlgebra R L] [LieModule R L M]
/-- The natural equivalence between the 'top' Lie ideal and the enclosing Lie algebra.
This is the Lie ideal version of `Submodule.topEquiv`. -/
def LieIdeal.topEquiv : (⊤ : LieIdeal R L) ≃ₗ⁅R⁆ L :=
LieSubalgebra.topEquiv
theorem LieIdeal.topEquiv_apply (x : (⊤ : LieIdeal R L)) : LieIdeal.topEquiv x = x :=
rfl
end TopEquiv
|
PathObject.lean
|
/-
Copyright (c) 2025 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.AlgebraicTopology.ModelCategory.Basic
import Mathlib.AlgebraicTopology.ModelCategory.IsCofibrant
/-!
# Path objects
We introduce a notion of path object for an object `A : C` in a model category.
It consists of an object `P`, a weak equivalence `ι : A ⟶ P` equipped with two retractions
`p₀` and `p₁`. This notion shall be important in the definition of "right homotopies"
in model categories.
This file dualizes the definitions in the file `AlgebraicTopology.ModelCategory.Cylinder`.
## Implementation notes
The most important definition in this file is `PathObject A`. This structure
extends another structure `PrepathObject A` (which does not assume that `C`
has a notion of weak equivalences, which can be interesting in situations
where we have not yet obtained the model category axioms).
The good properties of path objects are stated as typeclasses `PathObject.IsGood`
and `PathObject.IsVeryGood`.
The existence of very good path objects in model categories is stated
in the lemma `PathObject.exists_very_good`.
## References
* [Daniel G. Quillen, Homotopical algebra][Quillen1967]
* https://ncatlab.org/nlab/show/path+space+object
-/
universe v u
open CategoryTheory Category Limits
namespace HomotopicalAlgebra
variable {C : Type u} [Category.{v} C]
/-- A pre-path object for `A : C` is the data of a morphism
`ι : A ⟶ P` equipped with two retractions. -/
structure PrepathObject (A : C) where
/-- the underlying object of a (pre)path object -/
P : C
/-- the first "projection" from the (pre)path object -/
p₀ : P ⟶ A
/-- the second "projection" from the (pre)path object -/
p₁ : P ⟶ A
/-- the diagonal of the (pre)path object -/
ι : A ⟶ P
ι_p₀ : ι ≫ p₀ = 𝟙 A := by aesop_cat
ι_p₁ : ι ≫ p₁ = 𝟙 A := by aesop_cat
namespace PrepathObject
attribute [reassoc (attr := simp)] ι_p₀ ι_p₁
variable {A : C} (P : PrepathObject A)
/-- The pre-path object obtained by switching the two projections. -/
@[simps]
def symm : PrepathObject A where
P := P.P
p₀ := P.p₁
p₁ := P.p₀
ι := P.ι
/-- The gluing of two pre-path objects. -/
@[simps]
noncomputable def trans (P' : PrepathObject A) [HasPullback P.p₁ P'.p₀] :
PrepathObject A where
P := pullback P.p₁ P'.p₀
p₀ := pullback.fst _ _ ≫ P.p₀
p₁ := pullback.snd _ _ ≫ P'.p₁
ι := pullback.lift P.ι P'.ι (by simp)
section
variable [HasBinaryProduct A A]
/-- The map from `P.P` to the product of two copies of `A`, when `P` is
a pre-path object for `A`. `P` shall be a *good* path object
when this morphism is a fibration. -/
noncomputable def p : P.P ⟶ A ⨯ A := prod.lift P.p₀ P.p₁
@[reassoc (attr := simp)]
lemma p_fst : P.p ≫ prod.fst = P.p₀ := by simp [p]
@[reassoc (attr := simp)]
lemma p_snd : P.p ≫ prod.snd = P.p₁ := by simp [p]
end
@[simp, reassoc]
lemma symm_p [HasBinaryProducts C] :
P.symm.p = P.p ≫ (prod.braiding A A).hom := by aesop_cat
end PrepathObject
/-- In a category with weak equivalences, a path object is the
data of a weak equivalence `ι : A ⟶ P` equipped with two retractions. -/
structure PathObject [CategoryWithWeakEquivalences C] (A : C) extends PrepathObject A where
weakEquivalence_ι : WeakEquivalence ι := by infer_instance
namespace PathObject
attribute [instance] weakEquivalence_ι
section
variable {A : C} [CategoryWithWeakEquivalences C] (P : PathObject A)
/-- The path object obtained by switching the two projections. -/
@[simps!]
def symm : PathObject A where
__ := P.toPrepathObject.symm
weakEquivalence_ι := by dsimp; infer_instance
@[simp, reassoc]
lemma symm_p [HasBinaryProducts C] :
P.symm.p = P.p ≫ (prod.braiding A A).hom :=
P.toPrepathObject.symm_p
section
variable [(weakEquivalences C).HasTwoOutOfThreeProperty]
[(weakEquivalences C).ContainsIdentities]
instance : WeakEquivalence P.p₀ :=
weakEquivalence_of_precomp_of_fac P.ι_p₀
instance : WeakEquivalence P.p₁ :=
weakEquivalence_of_precomp_of_fac P.ι_p₁
end
/-- A path object `P` is good if the morphism
`P.p : P.P ⟶ A ⨯ A` is a fibration. -/
class IsGood [HasBinaryProduct A A] [CategoryWithFibrations C] : Prop where
fibration_p : Fibration P.p := by infer_instance
/-- A good path object `P` is very good if `P.ι` is a (trivial) cofibration. -/
class IsVeryGood [HasBinaryProduct A A] [CategoryWithFibrations C]
[CategoryWithCofibrations C] : Prop extends P.IsGood where
cofibration_ι : Cofibration P.ι := by infer_instance
attribute [instance] IsGood.fibration_p IsVeryGood.cofibration_ι
section
variable [HasBinaryProduct A A] [CategoryWithFibrations C]
[HasTerminal C] [(fibrations C).IsStableUnderComposition]
[(fibrations C).IsStableUnderBaseChange]
[IsFibrant A] [P.IsGood]
instance : Fibration P.p₀ := by
rw [← P.p_fst]
infer_instance
instance : Fibration P.p₁ := by
rw [← P.p_snd]
infer_instance
instance : IsFibrant P.P :=
isFibrant_of_fibration P.p₀
end
instance [HasBinaryProducts C] [CategoryWithFibrations C] [P.IsGood]
[(fibrations C).RespectsIso] : P.symm.IsGood where
fibration_p := by
have hp : fibrations C P.p := by rw [← fibration_iff]; infer_instance
rw [P.symm_p, fibration_iff]
refine ((fibrations C).arrow_mk_iso_iff ?_).2 hp
exact Arrow.isoMk (Iso.refl _) (prod.braiding A A)
section
variable [CategoryWithFibrations C] [CategoryWithCofibrations C]
[(cofibrations C).IsStableUnderComposition]
instance [HasBinaryProduct A A] [HasInitial C] [IsCofibrant A] [P.IsVeryGood] : IsCofibrant P.P :=
isCofibrant_of_cofibration P.ι
instance [(fibrations C).RespectsIso] [HasBinaryProducts C] [P.IsVeryGood] :
P.symm.IsVeryGood where
cofibration_ι := by dsimp; infer_instance
end
end
variable [ModelCategory C] {A : C} (P : PathObject A)
section
variable (h : MorphismProperty.MapFactorizationData
(trivialCofibrations C) (fibrations C) (diag A))
/-- A path object for `A` can be obtained from a factorization of the obvious
map `A ⟶ A ⨯ A` as a trivial cofibration followed by a fibration. -/
@[simps]
noncomputable def ofFactorizationData : PathObject A where
P := h.Z
p₀ := h.p ≫ prod.fst
p₁ := h.p ≫ prod.snd
ι := h.i
@[simp]
lemma ofFactorizationData_p : (ofFactorizationData h).p = h.p := by aesop_cat
instance : (ofFactorizationData h).IsVeryGood where
fibration_p := by simpa using inferInstanceAs (Fibration h.p)
cofibration_ι := by dsimp; infer_instance
instance [HasInitial C] [IsCofibrant A] [(cofibrations C).IsStableUnderComposition] :
IsCofibrant (ofFactorizationData h).P :=
isCofibrant_of_cofibration (ofFactorizationData h).ι
end
variable (A) in
lemma exists_very_good :
∃ (P : PathObject A), P.IsVeryGood :=
⟨ofFactorizationData (MorphismProperty.factorizationData _ _ _),
inferInstance⟩
instance : Nonempty (PathObject A) := ⟨(exists_very_good A).choose⟩
/-- The gluing of two good path objects. -/
@[simps!]
noncomputable def trans [IsFibrant A] (P P' : PathObject A) [P'.IsGood] :
PathObject A where
__ := P.toPrepathObject.trans P'.toPrepathObject
weakEquivalence_ι := by
have : WeakEquivalence (pullback.lift P.ι P'.ι (by simp) ≫
pullback.fst P.p₁ P'.p₀ ≫ P.p₀) := by
rw [pullback.lift_fst_assoc, PrepathObject.ι_p₀]
infer_instance
dsimp
apply weakEquivalence_of_postcomp _ (pullback.fst P.p₁ P'.p₀ ≫ P.p₀)
instance [IsFibrant A] (P P' : PathObject A) [P.IsGood] [P'.IsGood] :
(P.trans P').IsGood where
fibration_p := by
let ψ : (P.trans P').P ⟶ P.P ⨯ A := prod.lift (pullback.fst _ _) (pullback.snd _ _ ≫ P'.p₁)
rw [show (P.trans P').p = ψ ≫ prod.map P.p₀ (𝟙 A) by simp [PrepathObject.p, ψ]]
have fac : ψ ≫ prod.map P.p₁ (𝟙 A) = pullback.snd _ _ ≫ P'.p := by
ext
· simp [ψ, pullback.condition]
· simp [ψ]
have sq : IsPullback (ψ ≫ prod.fst) (pullback.snd P.p₁ P'.p₀) P.p₁ (P'.p ≫ prod.fst) := by
simpa [ψ] using IsPullback.of_hasPullback P.p₁ P'.p₀
have : Fibration ψ := by
rw [fibration_iff]
exact (fibrations C).of_isPullback
(IsPullback.of_right sq fac (IsPullback.of_prod_fst_with_id P.p₁ A)).flip
(by rw [← fibration_iff]; infer_instance)
infer_instance
end PathObject
end HomotopicalAlgebra
|
StoneWeierstrass.lean
|
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Heather Macbeth
-/
import Mathlib.Algebra.Algebra.Subalgebra.Tower
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Algebra.Star.Real
import Mathlib.Topology.Algebra.StarSubalgebra
import Mathlib.Topology.ContinuousMap.ContinuousMapZero
import Mathlib.Topology.ContinuousMap.Lattice
import Mathlib.Topology.ContinuousMap.Weierstrass
/-!
# The Stone-Weierstrass theorem
If a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
separates points, then it is dense.
We argue as follows.
* In any subalgebra `A` of `C(X, ℝ)`, if `f ∈ A`, then `abs f ∈ A.topologicalClosure`.
This follows from the Weierstrass approximation theorem on `[-‖f‖, ‖f‖]` by
approximating `abs` uniformly thereon by polynomials.
* This ensures that `A.topologicalClosure` is actually a sublattice:
if it contains `f` and `g`, then it contains the pointwise supremum `f ⊔ g`
and the pointwise infimum `f ⊓ g`.
* Any nonempty sublattice `L` of `C(X, ℝ)` which separates points is dense,
by a nice argument approximating a given `f` above and below using separating functions.
For each `x y : X`, we pick a function `g x y ∈ L` so `g x y x = f x` and `g x y y = f y`.
By continuity these functions remain close to `f` on small patches around `x` and `y`.
We use compactness to identify a certain finitely indexed infimum of finitely indexed supremums
which is then close to `f` everywhere, obtaining the desired approximation.
* Finally we put these pieces together. `L = A.topologicalClosure` is a nonempty sublattice
which separates points since `A` does, and so is dense (in fact equal to `⊤`).
We then prove the complex version for star subalgebras `A`, by separately approximating
the real and imaginary parts using the real subalgebra of real-valued functions in `A`
(which still separates points, by taking the norm-square of a separating function).
## Future work
Extend to cover the case of subalgebras of the continuous functions vanishing at infinity,
on non-compact spaces.
-/
assert_not_exists Unitization
noncomputable section
namespace ContinuousMap
variable {X : Type*} [TopologicalSpace X] [CompactSpace X]
open scoped Polynomial
/-- Turn a function `f : C(X, ℝ)` into a continuous map into `Set.Icc (-‖f‖) (‖f‖)`,
thereby explicitly attaching bounds.
-/
def attachBound (f : C(X, ℝ)) : C(X, Set.Icc (-‖f‖) ‖f‖) where
toFun x := ⟨f x, ⟨neg_norm_le_apply f x, apply_le_norm f x⟩⟩
@[simp]
theorem attachBound_apply_coe (f : C(X, ℝ)) (x : X) : ((attachBound f) x : ℝ) = f x :=
rfl
theorem polynomial_comp_attachBound (A : Subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.toContinuousMapOn (Set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attachBound =
Polynomial.aeval f g := by
ext
simp only [Polynomial.aeval_subalgebra_coe, Polynomial.aeval_continuousMap_apply]
simp
/-- Given a continuous function `f` in a subalgebra of `C(X, ℝ)`, postcomposing by a polynomial
gives another function in `A`.
This lemma proves something slightly more subtle than this:
we take `f`, and think of it as a function into the restricted target `Set.Icc (-‖f‖) ‖f‖)`,
and then postcompose with a polynomial function on that interval.
This is in fact the same situation as above, and so also gives a function in `A`.
-/
theorem polynomial_comp_attachBound_mem (A : Subalgebra ℝ C(X, ℝ)) (f : A) (g : ℝ[X]) :
(g.toContinuousMapOn (Set.Icc (-‖f‖) ‖f‖)).comp (f : C(X, ℝ)).attachBound ∈ A := by
rw [polynomial_comp_attachBound]
apply SetLike.coe_mem
theorem comp_attachBound_mem_closure (A : Subalgebra ℝ C(X, ℝ)) (f : A)
(p : C(Set.Icc (-‖f‖) ‖f‖, ℝ)) : p.comp (attachBound (f : C(X, ℝ))) ∈ A.topologicalClosure := by
-- `p` itself is in the closure of polynomials, by the Weierstrass theorem,
have mem_closure : p ∈ (polynomialFunctions (Set.Icc (-‖f‖) ‖f‖)).topologicalClosure :=
continuousMap_mem_polynomialFunctions_closure _ _ p
-- and so there are polynomials arbitrarily close.
have frequently_mem_polynomials := mem_closure_iff_frequently.mp mem_closure
-- To prove `p.comp (attachBound f)` is in the closure of `A`,
-- we show there are elements of `A` arbitrarily close.
apply mem_closure_iff_frequently.mpr
-- To show that, we pull back the polynomials close to `p`,
refine
((compRightContinuousMap ℝ (attachBound (f : C(X, ℝ)))).continuousAt
p).tendsto.frequently_map
_ ?_ frequently_mem_polynomials
-- but need to show that those pullbacks are actually in `A`.
rintro _ ⟨g, ⟨-, rfl⟩⟩
simp only [SetLike.mem_coe, AlgHom.coe_toRingHom, compRightContinuousMap_apply,
Polynomial.toContinuousMapOnAlgHom_apply]
apply polynomial_comp_attachBound_mem
theorem abs_mem_subalgebra_closure (A : Subalgebra ℝ C(X, ℝ)) (f : A) :
|(f : C(X, ℝ))| ∈ A.topologicalClosure := by
let f' := attachBound (f : C(X, ℝ))
let abs : C(Set.Icc (-‖f‖) ‖f‖, ℝ) := { toFun := fun x : Set.Icc (-‖f‖) ‖f‖ => |(x : ℝ)| }
change abs.comp f' ∈ A.topologicalClosure
apply comp_attachBound_mem_closure
theorem inf_mem_subalgebra_closure (A : Subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A.topologicalClosure := by
rw [inf_eq_half_smul_add_sub_abs_sub' ℝ]
refine
A.topologicalClosure.smul_mem
(A.topologicalClosure.sub_mem
(A.topologicalClosure.add_mem (A.le_topologicalClosure f.property)
(A.le_topologicalClosure g.property))
?_)
_
exact mod_cast abs_mem_subalgebra_closure A _
theorem inf_mem_closed_subalgebra (A : Subalgebra ℝ C(X, ℝ)) (h : IsClosed (A : Set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊓ (g : C(X, ℝ)) ∈ A := by
convert inf_mem_subalgebra_closure A f g
apply SetLike.ext'
symm
rw [Subalgebra.topologicalClosure_coe, closure_eq_iff_isClosed]
exact h
theorem sup_mem_subalgebra_closure (A : Subalgebra ℝ C(X, ℝ)) (f g : A) :
(f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A.topologicalClosure := by
rw [sup_eq_half_smul_add_add_abs_sub' ℝ]
refine
A.topologicalClosure.smul_mem
(A.topologicalClosure.add_mem
(A.topologicalClosure.add_mem (A.le_topologicalClosure f.property)
(A.le_topologicalClosure g.property))
?_)
_
exact mod_cast abs_mem_subalgebra_closure A _
theorem sup_mem_closed_subalgebra (A : Subalgebra ℝ C(X, ℝ)) (h : IsClosed (A : Set C(X, ℝ)))
(f g : A) : (f : C(X, ℝ)) ⊔ (g : C(X, ℝ)) ∈ A := by
convert sup_mem_subalgebra_closure A f g
apply SetLike.ext'
symm
dsimp
rw [closure_eq_iff_isClosed]
exact h
open scoped Topology
-- Here's the fun part of Stone-Weierstrass!
theorem sublattice_closure_eq_top (L : Set C(X, ℝ)) (nA : L.Nonempty)
(inf_mem : ∀ᵉ (f ∈ L) (g ∈ L), f ⊓ g ∈ L)
(sup_mem : ∀ᵉ (f ∈ L) (g ∈ L), f ⊔ g ∈ L) (sep : L.SeparatesPointsStrongly) :
closure L = ⊤ := by
-- We start by boiling down to a statement about close approximation.
rw [eq_top_iff]
rintro f -
refine
Filter.Frequently.mem_closure
((Filter.HasBasis.frequently_iff Metric.nhds_basis_ball).mpr fun ε pos => ?_)
simp only [Metric.mem_ball]
-- It will be helpful to assume `X` is nonempty later,
-- so we get that out of the way here.
by_cases nX : Nonempty X
swap
· exact ⟨nA.some, (dist_lt_iff pos).mpr fun x => False.elim (nX ⟨x⟩), nA.choose_spec⟩
/-
The strategy now is to pick a family of continuous functions `g x y` in `A`
with the property that `g x y x = f x` and `g x y y = f y`
(this is immediate from `h : SeparatesPointsStrongly`)
then use continuity to see that `g x y` is close to `f` near both `x` and `y`,
and finally using compactness to produce the desired function `h`
as a maximum over finitely many `x` of a minimum over finitely many `y` of the `g x y`.
-/
dsimp only [Set.SeparatesPointsStrongly] at sep
choose g hg w₁ w₂ using sep f
-- For each `x y`, we define `U x y` to be `{z | f z - ε < g x y z}`,
-- and observe this is a neighbourhood of `y`.
let U : X → X → Set X := fun x y => {z | f z - ε < g x y z}
have U_nhds_y : ∀ x y, U x y ∈ 𝓝 y := by
intro x y
refine IsOpen.mem_nhds ?_ ?_
· apply isOpen_lt <;> fun_prop
· rw [Set.mem_setOf_eq, w₂]
exact sub_lt_self _ pos
-- Fixing `x` for a moment, we have a family of functions `fun y ↦ g x y`
-- which on different patches (the `U x y`) are greater than `f z - ε`.
-- Taking the supremum of these functions
-- indexed by a finite collection of patches which cover `X`
-- will give us an element of `A` that is globally greater than `f z - ε`
-- and still equal to `f x` at `x`.
-- Since `X` is compact, for every `x` there is some finset `ys t`
-- so the union of the `U x y` for `y ∈ ys x` still covers everything.
let ys : X → Finset X := fun x => (CompactSpace.elim_nhds_subcover (U x) (U_nhds_y x)).choose
let ys_w : ∀ x, ⋃ y ∈ ys x, U x y = ⊤ := fun x =>
(CompactSpace.elim_nhds_subcover (U x) (U_nhds_y x)).choose_spec
have ys_nonempty : ∀ x, (ys x).Nonempty := fun x =>
Set.nonempty_of_union_eq_top_of_nonempty _ _ nX (ys_w x)
-- Thus for each `x` we have the desired `h x : A` so `f z - ε < h x z` everywhere
-- and `h x x = f x`.
let h : X → L := fun x =>
⟨(ys x).sup' (ys_nonempty x) fun y => (g x y : C(X, ℝ)),
Finset.sup'_mem _ sup_mem _ _ _ fun y _ => hg x y⟩
have lt_h : ∀ x z, f z - ε < (h x : X → ℝ) z := by
intro x z
obtain ⟨y, ym, zm⟩ := Set.exists_set_mem_of_union_eq_top _ _ (ys_w x) z
dsimp [h]
simp only [coe_sup', Finset.sup'_apply, Finset.lt_sup'_iff]
exact ⟨y, ym, zm⟩
have h_eq : ∀ x, (h x : X → ℝ) x = f x := by intro x; simp [h, w₁]
-- For each `x`, we define `W x` to be `{z | h x z < f z + ε}`,
let W : X → Set X := fun x => {z | (h x : X → ℝ) z < f z + ε}
-- This is still a neighbourhood of `x`.
have W_nhds : ∀ x, W x ∈ 𝓝 x := by
intro x
refine IsOpen.mem_nhds ?_ ?_
· apply isOpen_lt <;> fun_prop
· dsimp only [W, Set.mem_setOf_eq]
rw [h_eq]
exact lt_add_of_pos_right _ pos
-- Since `X` is compact, there is some finset `ys t`
-- so the union of the `W x` for `x ∈ xs` still covers everything.
let xs : Finset X := (CompactSpace.elim_nhds_subcover W W_nhds).choose
let xs_w : ⋃ x ∈ xs, W x = ⊤ := (CompactSpace.elim_nhds_subcover W W_nhds).choose_spec
have xs_nonempty : xs.Nonempty := Set.nonempty_of_union_eq_top_of_nonempty _ _ nX xs_w
-- Finally our candidate function is the infimum over `x ∈ xs` of the `h x`.
-- This function is then globally less than `f z + ε`.
let k : (L : Type _) :=
⟨xs.inf' xs_nonempty fun x => (h x : C(X, ℝ)),
Finset.inf'_mem _ inf_mem _ _ _ fun x _ => (h x).2⟩
refine ⟨k.1, ?_, k.2⟩
-- We just need to verify the bound, which we do pointwise.
rw [dist_lt_iff pos]
intro z
-- We rewrite into this particular form,
-- so that simp lemmas about inequalities involving `Finset.inf'` can fire.
rw [show ∀ a b ε : ℝ, dist a b < ε ↔ a < b + ε ∧ b - ε < a by
intros; simp only [← Metric.mem_ball, Real.ball_eq_Ioo, Set.mem_Ioo, and_comm]]
fconstructor
· dsimp
simp only [k, Finset.inf'_lt_iff, ContinuousMap.inf'_apply]
exact Set.exists_set_mem_of_union_eq_top _ _ xs_w z
· dsimp
simp only [k, Finset.lt_inf'_iff, ContinuousMap.inf'_apply]
rintro x -
apply lt_h
/-- The **Stone-Weierstrass Approximation Theorem**,
that a subalgebra `A` of `C(X, ℝ)`, where `X` is a compact topological space,
is dense if it separates points.
-/
theorem subalgebra_topologicalClosure_eq_top_of_separatesPoints (A : Subalgebra ℝ C(X, ℝ))
(w : A.SeparatesPoints) : A.topologicalClosure = ⊤ := by
-- The closure of `A` is closed under taking `sup` and `inf`,
-- and separates points strongly (since `A` does),
-- so we can apply `sublattice_closure_eq_top`.
apply SetLike.ext'
let L := A.topologicalClosure
have n : Set.Nonempty (L : Set C(X, ℝ)) := ⟨(1 : C(X, ℝ)), A.le_topologicalClosure A.one_mem⟩
convert
sublattice_closure_eq_top (L : Set C(X, ℝ)) n
(fun f fm g gm => inf_mem_closed_subalgebra L A.isClosed_topologicalClosure ⟨f, fm⟩ ⟨g, gm⟩)
(fun f fm g gm => sup_mem_closed_subalgebra L A.isClosed_topologicalClosure ⟨f, fm⟩ ⟨g, gm⟩)
(Subalgebra.SeparatesPoints.strongly
(Subalgebra.separatesPoints_monotone A.le_topologicalClosure w))
simp [L]
/-- An alternative statement of the Stone-Weierstrass theorem.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is a uniform limit of elements of `A`.
-/
theorem continuousMap_mem_subalgebra_closure_of_separatesPoints (A : Subalgebra ℝ C(X, ℝ))
(w : A.SeparatesPoints) (f : C(X, ℝ)) : f ∈ A.topologicalClosure := by
rw [subalgebra_topologicalClosure_eq_top_of_separatesPoints A w]
simp
/-- An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuousMap_of_separatesPoints (A : Subalgebra ℝ C(X, ℝ))
(w : A.SeparatesPoints) (f : C(X, ℝ)) (ε : ℝ) (pos : 0 < ε) :
∃ g : A, ‖(g : C(X, ℝ)) - f‖ < ε := by
have w :=
mem_closure_iff_frequently.mp (continuousMap_mem_subalgebra_closure_of_separatesPoints A w f)
rw [Metric.nhds_basis_ball.frequently_iff] at w
obtain ⟨g, H, m⟩ := w ε pos
rw [Metric.mem_ball, dist_eq_norm] at H
exact ⟨⟨g, m⟩, H⟩
/-- An alternative statement of the Stone-Weierstrass theorem,
for those who like their epsilons and don't like bundled continuous functions.
If `A` is a subalgebra of `C(X, ℝ)` which separates points (and `X` is compact),
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A`.
-/
theorem exists_mem_subalgebra_near_continuous_of_separatesPoints (A : Subalgebra ℝ C(X, ℝ))
(w : A.SeparatesPoints) (f : X → ℝ) (c : Continuous f) (ε : ℝ) (pos : 0 < ε) :
∃ g : A, ∀ x, ‖(g : X → ℝ) x - f x‖ < ε := by
obtain ⟨g, b⟩ := exists_mem_subalgebra_near_continuousMap_of_separatesPoints A w ⟨f, c⟩ ε pos
use g
rwa [norm_lt_iff _ pos] at b
/-- A variant of the Stone-Weierstrass theorem where `X` need not be compact:
If `A` is a subalgebra of `C(X, ℝ)` which separates points, then, for any compact set `K ⊆ X`,
every real-valued continuous function on `X` is within any `ε > 0` of some element of `A` on `K`. -/
theorem exists_mem_subalgebra_near_continuous_of_isCompact_of_separatesPoints
{X : Type*} [TopologicalSpace X] {A : Subalgebra ℝ C(X, ℝ)} (hA : A.SeparatesPoints)
(f : C(X, ℝ)) {K : Set X} (hK : IsCompact K) {ε : ℝ} (pos : 0 < ε) :
∃ g ∈ A, ∀ x ∈ K, ‖(g : X → ℝ) x - f x‖ < ε := by
let restrict_on_K : C(X, ℝ) →⋆ₐ[ℝ] C(K, ℝ) :=
ContinuousMap.compStarAlgHom' ℝ ℝ ⟨(Subtype.val), continuous_subtype_val⟩
--consider the subalgebra AK of functions with domain K
let AK : Subalgebra ℝ C(K, ℝ) := Subalgebra.map (restrict_on_K) A
have hsep : AK.SeparatesPoints := by
intro x y hxy
obtain ⟨_, ⟨g, hg1, hg2⟩, hg_sep⟩ := hA (Subtype.coe_ne_coe.mpr hxy)
simp only [Set.mem_image, SetLike.mem_coe, exists_exists_and_eq_and]
use restrict_on_K g
refine ⟨Subalgebra.mem_map.mpr ?_,
by simpa only [compStarAlgHom'_apply, comp_apply, coe_mk, ne_eq, restrict_on_K, hg2]⟩
use g, hg1
simp [AlgHom.coe_coe]
obtain ⟨⟨gK, hgKAK⟩, hgapprox⟩ :=
@ContinuousMap.exists_mem_subalgebra_near_continuous_of_separatesPoints _ _
(isCompact_iff_compactSpace.mp hK) AK hsep (K.restrict f)
(ContinuousOn.restrict (Continuous.continuousOn f.continuous)) ε pos
obtain ⟨g, hgA, hgKAK⟩ := Subalgebra.mem_map.mp hgKAK
use g, hgA
intro x hxK
have eqg : g x = gK ⟨x, hxK⟩ := by
rw [← hgKAK]; rfl
rw [eqg]
exact hgapprox ⟨x, hxK⟩
end ContinuousMap
section RCLike
open RCLike
-- Redefine `X`, since for the next lemma it need not be compact
variable {𝕜 : Type*} {X : Type*} [RCLike 𝕜] [TopologicalSpace X]
open ContinuousMap
/- a post-port refactor eliminated `conjInvariantSubalgebra`, which was only used to
state and prove the Stone-Weierstrass theorem, in favor of using `StarSubalgebra`s,
which didn't exist at the time Stone-Weierstrass was written. -/
/-- If a star subalgebra of `C(X, 𝕜)` separates points, then the real subalgebra
of its purely real-valued elements also separates points. -/
theorem Subalgebra.SeparatesPoints.rclike_to_real {A : StarSubalgebra 𝕜 C(X, 𝕜)}
(hA : A.SeparatesPoints) :
((A.restrictScalars ℝ).comap
(ofRealAm.compLeftContinuous ℝ continuous_ofReal)).SeparatesPoints := by
intro x₁ x₂ hx
-- Let `f` in the subalgebra `A` separate the points `x₁`, `x₂`
obtain ⟨_, ⟨f, hfA, rfl⟩, hf⟩ := hA hx
let F : C(X, 𝕜) := f - const _ (f x₂)
-- Subtract the constant `f x₂` from `f`; this is still an element of the subalgebra
have hFA : F ∈ A := by
refine A.sub_mem hfA (@Eq.subst _ (· ∈ A) _ _ ?_ <| A.smul_mem A.one_mem <| f x₂)
ext1
simp only [smul_apply, one_apply, Algebra.id.smul_eq_mul, mul_one,
const_apply]
-- Consider now the function `fun x ↦ |f x - f x₂| ^ 2`
refine ⟨_, ⟨⟨(‖F ·‖ ^ 2), by fun_prop⟩, ?_, rfl⟩, ?_⟩
· -- This is also an element of the subalgebra, and takes only real values
rw [SetLike.mem_coe, Subalgebra.mem_comap]
convert (A.restrictScalars ℝ).mul_mem hFA (star_mem hFA : star F ∈ A)
ext1
simp [← RCLike.mul_conj]
· -- And it also separates the points `x₁`, `x₂`
simpa [F] using sub_ne_zero.mpr hf
variable [CompactSpace X]
/-- The Stone-Weierstrass approximation theorem, `RCLike` version, that a star subalgebra `A` of
`C(X, 𝕜)`, where `X` is a compact topological space and `RCLike 𝕜`, is dense if it separates
points. -/
theorem ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints
(A : StarSubalgebra 𝕜 C(X, 𝕜)) (hA : A.SeparatesPoints) : A.topologicalClosure = ⊤ := by
rw [StarSubalgebra.eq_top_iff]
-- Let `I` be the natural inclusion of `C(X, ℝ)` into `C(X, 𝕜)`
let I : C(X, ℝ) →L[ℝ] C(X, 𝕜) := ofRealCLM.compLeftContinuous ℝ X
-- The main point of the proof is that its range (i.e., every real-valued function) is contained
-- in the closure of `A`
have key : LinearMap.range I ≤ (A.toSubmodule.restrictScalars ℝ).topologicalClosure := by
-- Let `A₀` be the subalgebra of `C(X, ℝ)` consisting of `A`'s purely real elements; it is the
-- preimage of `A` under `I`. In this argument we only need its submodule structure.
let A₀ : Submodule ℝ C(X, ℝ) := (A.toSubmodule.restrictScalars ℝ).comap I
-- By `Subalgebra.SeparatesPoints.rclike_to_real`, this subalgebra also separates points, so
-- we may apply the real Stone-Weierstrass result to it.
have SW : A₀.topologicalClosure = ⊤ :=
haveI := subalgebra_topologicalClosure_eq_top_of_separatesPoints _ hA.rclike_to_real
congr_arg Subalgebra.toSubmodule this
rw [← Submodule.map_top, ← SW]
-- So it suffices to prove that the image under `I` of the closure of `A₀` is contained in the
-- closure of `A`, which follows by abstract nonsense
have h₁ := A₀.topologicalClosure_map I
have h₂ := (A.toSubmodule.restrictScalars ℝ).map_comap_le I
exact h₁.trans (Submodule.topologicalClosure_mono h₂)
-- In particular, for a function `f` in `C(X, 𝕜)`, the real and imaginary parts of `f` are in the
-- closure of `A`
intro f
let f_re : C(X, ℝ) := (⟨RCLike.re, RCLike.reCLM.continuous⟩ : C(𝕜, ℝ)).comp f
let f_im : C(X, ℝ) := (⟨RCLike.im, RCLike.imCLM.continuous⟩ : C(𝕜, ℝ)).comp f
have h_f_re : I f_re ∈ A.topologicalClosure := key ⟨f_re, rfl⟩
have h_f_im : I f_im ∈ A.topologicalClosure := key ⟨f_im, rfl⟩
-- So `f_re + I • f_im` is in the closure of `A`
have := A.topologicalClosure.add_mem h_f_re (A.topologicalClosure.smul_mem h_f_im RCLike.I)
rw [StarSubalgebra.mem_toSubalgebra] at this
convert this
-- And this, of course, is just `f`
ext
apply Eq.symm
simp [I, f_re, f_im, mul_comm RCLike.I _]
end RCLike
section PolynomialFunctions
open StarSubalgebra Polynomial
open scoped Polynomial
/-- Polynomial functions in are dense in `C(s, ℝ)` when `s` is compact.
See `polynomialFunctions_closure_eq_top` for the special case `s = Set.Icc a b` which does not use
the full Stone-Weierstrass theorem. Of course, that version could be used to prove this one as
well. -/
theorem polynomialFunctions.topologicalClosure (s : Set ℝ)
[CompactSpace s] : (polynomialFunctions s).topologicalClosure = ⊤ :=
ContinuousMap.subalgebra_topologicalClosure_eq_top_of_separatesPoints _
(polynomialFunctions_separatesPoints s)
/-- The star subalgebra generated by polynomials functions is dense in `C(s, 𝕜)` when `s` is
compact and `𝕜` is either `ℝ` or `ℂ`. -/
theorem polynomialFunctions.starClosure_topologicalClosure {𝕜 : Type*} [RCLike 𝕜] (s : Set 𝕜)
[CompactSpace s] : (polynomialFunctions s).starClosure.topologicalClosure = ⊤ :=
ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints _
(Subalgebra.separatesPoints_monotone le_sup_left (polynomialFunctions_separatesPoints s))
/-- An induction principle for `C(s, 𝕜)`. -/
@[elab_as_elim]
theorem ContinuousMap.induction_on {𝕜 : Type*} [RCLike 𝕜] {s : Set 𝕜}
{p : C(s, 𝕜) → Prop} (const : ∀ r, p (.const s r)) (id : p (.restrict s <| .id 𝕜))
(star_id : p (star (.restrict s <| .id 𝕜)))
(add : ∀ f g, p f → p g → p (f + g)) (mul : ∀ f g, p f → p g → p (f * g))
(closure : (∀ f ∈ (polynomialFunctions s).starClosure, p f) → ∀ f, p f) (f : C(s, 𝕜)) :
p f := by
refine closure (fun f hf => ?_) f
rw [polynomialFunctions.starClosure_eq_adjoin_X] at hf
induction hf using Algebra.adjoin_induction with
| mem f hf =>
simp only [Set.mem_union, Set.mem_singleton_iff, Set.mem_star] at hf
rw [star_eq_iff_star_eq, eq_comm (b := f)] at hf
obtain (rfl | rfl) := hf
all_goals simpa only [toContinuousMapOnAlgHom_apply, toContinuousMapOn_X_eq_restrict_id]
| algebraMap r => exact const r
| add _ _ _ _ hf hg => exact add _ _ hf hg
| mul _ _ _ _ hf hg => exact mul _ _ hf hg
open Topology in
@[elab_as_elim]
theorem ContinuousMap.induction_on_of_compact {𝕜 : Type*} [RCLike 𝕜] {s : Set 𝕜} [CompactSpace s]
{p : C(s, 𝕜) → Prop} (const : ∀ r, p (.const s r)) (id : p (.restrict s <| .id 𝕜))
(star_id : p (star (.restrict s <| .id 𝕜)))
(add : ∀ f g, p f → p g → p (f + g)) (mul : ∀ f g, p f → p g → p (f * g))
(frequently : ∀ f, (∃ᶠ g in 𝓝 f, p g) → p f) (f : C(s, 𝕜)) :
p f := by
refine f.induction_on const id star_id add mul fun h f ↦ frequently f ?_
have := polynomialFunctions.starClosure_topologicalClosure s ▸ mem_top (x := f)
rw [← SetLike.mem_coe, topologicalClosure_coe, mem_closure_iff_frequently] at this
exact this.mp <| .of_forall h
/-- Continuous algebra homomorphisms from `C(s, ℝ)` into an `ℝ`-algebra `A` which agree
at `X : 𝕜[X]` (interpreted as a continuous map) are, in fact, equal. -/
@[ext (iff := false)]
theorem ContinuousMap.algHom_ext_map_X {A : Type*} [Semiring A]
[Algebra ℝ A] [TopologicalSpace A] [T2Space A] {s : Set ℝ} [CompactSpace s]
{φ ψ : C(s, ℝ) →ₐ[ℝ] A} (hφ : Continuous φ) (hψ : Continuous ψ)
(h : φ (toContinuousMapOnAlgHom s X) = ψ (toContinuousMapOnAlgHom s X)) : φ = ψ := by
suffices (⊤ : Subalgebra ℝ C(s, ℝ)) ≤ AlgHom.equalizer φ ψ from
AlgHom.ext fun x => this (by trivial)
rw [← polynomialFunctions.topologicalClosure s]
exact Subalgebra.topologicalClosure_minimal (polynomialFunctions s)
(polynomialFunctions.le_equalizer s φ ψ h) (isClosed_eq hφ hψ)
/-- Continuous star algebra homomorphisms from `C(s, 𝕜)` into a star `𝕜`-algebra `A` which agree
at `X : 𝕜[X]` (interpreted as a continuous map) are, in fact, equal. -/
@[ext (iff := false)]
theorem ContinuousMap.starAlgHom_ext_map_X {𝕜 A : Type*} [RCLike 𝕜] [Ring A] [StarRing A]
[Algebra 𝕜 A] [TopologicalSpace A] [T2Space A] {s : Set 𝕜} [CompactSpace s]
{φ ψ : C(s, 𝕜) →⋆ₐ[𝕜] A} (hφ : Continuous φ) (hψ : Continuous ψ)
(h : φ (toContinuousMapOnAlgHom s X) = ψ (toContinuousMapOnAlgHom s X)) : φ = ψ := by
suffices (⊤ : StarSubalgebra 𝕜 C(s, 𝕜)) ≤ StarAlgHom.equalizer φ ψ from
StarAlgHom.ext fun x => this mem_top
rw [← polynomialFunctions.starClosure_topologicalClosure s]
exact StarSubalgebra.topologicalClosure_minimal
(polynomialFunctions.starClosure_le_equalizer s φ ψ h) (isClosed_eq hφ hψ)
end PolynomialFunctions
/-! ### Continuous maps sending zero to zero -/
section ContinuousMapZero
variable {𝕜 : Type*} [RCLike 𝕜]
open NonUnitalStarAlgebra Submodule
namespace ContinuousMap
lemma adjoin_id_eq_span_one_union (s : Set 𝕜) :
((StarAlgebra.adjoin 𝕜 {(restrict s (.id 𝕜) : C(s, 𝕜))}) : Set C(s, 𝕜)) =
span 𝕜 ({(1 : C(s, 𝕜))} ∪ (adjoin 𝕜 {(restrict s (.id 𝕜) : C(s, 𝕜))})) := by
ext x
rw [SetLike.mem_coe, SetLike.mem_coe, ← StarAlgebra.adjoin_nonUnitalStarSubalgebra,
← StarSubalgebra.mem_toSubalgebra, ← Subalgebra.mem_toSubmodule,
StarAlgebra.adjoin_nonUnitalStarSubalgebra_eq_span, span_union, span_eq_toSubmodule]
open Pointwise in
lemma adjoin_id_eq_span_one_add (s : Set 𝕜) :
((StarAlgebra.adjoin 𝕜 {(restrict s (.id 𝕜) : C(s, 𝕜))}) : Set C(s, 𝕜)) =
(span 𝕜 {(1 : C(s, 𝕜))} : Set C(s, 𝕜)) + (adjoin 𝕜 {(restrict s (.id 𝕜) : C(s, 𝕜))}) := by
ext x
rw [SetLike.mem_coe, ← StarAlgebra.adjoin_nonUnitalStarSubalgebra,
← StarSubalgebra.mem_toSubalgebra, ← Subalgebra.mem_toSubmodule,
StarAlgebra.adjoin_nonUnitalStarSubalgebra_eq_span, mem_sup]
simp [Set.mem_add]
lemma nonUnitalStarAlgebraAdjoin_id_subset_ker_evalStarAlgHom {s : Set 𝕜} (h0 : 0 ∈ s) :
(adjoin 𝕜 {restrict s (.id 𝕜)} : Set C(s, 𝕜)) ⊆
RingHom.ker (evalStarAlgHom 𝕜 𝕜 (⟨0, h0⟩ : s)) := by
intro f hf
induction hf using adjoin_induction with
| mem f hf =>
obtain rfl := Set.mem_singleton_iff.mp hf
rfl
| add f g _ _ hf hg => exact add_mem hf hg
| zero => exact zero_mem _
| mul f g _ _ _ hg => exact Ideal.mul_mem_left _ f hg
| smul r f _ hf =>
rw [SetLike.mem_coe, RingHom.mem_ker] at hf ⊢
rw [map_smul, hf, smul_zero]
| star f _ hf =>
rw [SetLike.mem_coe, RingHom.mem_ker] at hf ⊢
rw [map_star, hf, star_zero]
lemma ker_evalStarAlgHom_inter_adjoin_id (s : Set 𝕜) (h0 : 0 ∈ s) :
(StarAlgebra.adjoin 𝕜 {restrict s (.id 𝕜)} : Set C(s, 𝕜)) ∩
RingHom.ker (evalStarAlgHom 𝕜 𝕜 (⟨0, h0⟩ : s)) = adjoin 𝕜 {restrict s (.id 𝕜)} := by
ext f
constructor
· rintro ⟨hf₁, hf₂⟩
rw [SetLike.mem_coe] at hf₂ ⊢
simp_rw [adjoin_id_eq_span_one_add, Set.mem_add, SetLike.mem_coe, mem_span_singleton] at hf₁
obtain ⟨-, ⟨r, rfl⟩, f, hf, rfl⟩ := hf₁
have := nonUnitalStarAlgebraAdjoin_id_subset_ker_evalStarAlgHom h0 hf
simp only [SetLike.mem_coe, RingHom.mem_ker, evalStarAlgHom_apply] at hf₂ this
rw [add_apply, this, add_zero, smul_apply, one_apply, smul_eq_mul, mul_one] at hf₂
rwa [hf₂, zero_smul, zero_add]
· simp only [Set.mem_inter_iff, SetLike.mem_coe]
refine fun hf ↦ ⟨?_, nonUnitalStarAlgebraAdjoin_id_subset_ker_evalStarAlgHom h0 hf⟩
exact adjoin_le_starAlgebra_adjoin _ _ hf
-- the statement should be in terms of non unital subalgebras, but we lack API
open RingHom Filter Topology in
theorem AlgHom.closure_ker_inter {F S K A : Type*} [CommRing K] [Ring A] [Algebra K A]
[TopologicalSpace K] [T1Space K] [TopologicalSpace A] [ContinuousSub A] [ContinuousSMul K A]
[FunLike F A K] [AlgHomClass F K A K] [SetLike S A] [OneMemClass S A] [AddSubgroupClass S A]
[SMulMemClass S K A] (φ : F) (hφ : Continuous φ) (s : S) :
closure (s ∩ RingHom.ker φ) = closure s ∩ (ker φ : Set A) := by
refine subset_antisymm ?_ ?_
· simpa only [ker_eq, (isClosed_singleton.preimage hφ).closure_eq]
using closure_inter_subset_inter_closure s (ker φ : Set A)
· intro x ⟨hxs, (hxφ : φ x = 0)⟩
rw [mem_closure_iff_clusterPt, ClusterPt] at hxs
have : Tendsto (fun y ↦ y - φ y • 1) (𝓝 x ⊓ 𝓟 s) (𝓝 x) := by
conv => congr; rfl; rfl; rw [← sub_zero x, ← zero_smul K 1, ← hxφ]
exact Filter.tendsto_inf_left (Continuous.tendsto (by fun_prop) x)
refine mem_closure_of_tendsto this <| eventually_inf_principal.mpr ?_
filter_upwards [] with g hg using
⟨sub_mem hg (SMulMemClass.smul_mem _ <| one_mem _), by simp [RingHom.mem_ker]⟩
lemma ker_evalStarAlgHom_eq_closure_adjoin_id (s : Set 𝕜) (h0 : 0 ∈ s) [CompactSpace s] :
(RingHom.ker (evalStarAlgHom 𝕜 𝕜 (⟨0, h0⟩ : s)) : Set C(s, 𝕜)) =
closure (adjoin 𝕜 {(restrict s (.id 𝕜))}) := by
rw [← ker_evalStarAlgHom_inter_adjoin_id s h0,
AlgHom.closure_ker_inter (φ := evalStarAlgHom 𝕜 𝕜 (X := s) ⟨0, h0⟩) (continuous_eval_const _) _]
convert (Set.univ_inter _).symm
rw [← Polynomial.toContinuousMapOn_X_eq_restrict_id, ← Polynomial.toContinuousMapOnAlgHom_apply,
← polynomialFunctions.starClosure_eq_adjoin_X s]
congrm(($(polynomialFunctions.starClosure_topologicalClosure s) : Set C(s, 𝕜)))
end ContinuousMap
open scoped ContinuousMapZero
/-- If `s : Set 𝕜` with `RCLike 𝕜` is compact and contains `0`, then the non-unital star subalgebra
generated by the identity function in `C(s, 𝕜)₀` is dense. This can be seen as a version of the
Weierstrass approximation theorem. -/
lemma ContinuousMapZero.adjoin_id_dense {s : Set 𝕜} [Zero s] (h0 : ((0 : s) : 𝕜) = 0)
[CompactSpace s] : Dense (adjoin 𝕜 {(.id h0 : C(s, 𝕜)₀)} : Set C(s, 𝕜)₀) := by
have h0' : 0 ∈ s := h0 ▸ (0 : s).property
rw [dense_iff_closure_eq,
← isClosedEmbedding_toContinuousMap.injective.preimage_image (closure _),
← isClosedEmbedding_toContinuousMap.closure_image_eq, ← coe_toContinuousMapHom,
← NonUnitalStarSubalgebra.coe_map, NonUnitalStarAlgHom.map_adjoin_singleton,
toContinuousMapHom_apply, toContinuousMap_id h0,
← ContinuousMap.ker_evalStarAlgHom_eq_closure_adjoin_id s h0']
apply Set.eq_univ_of_forall fun f ↦ ?_
simp only [Set.mem_preimage, toContinuousMapHom_apply, SetLike.mem_coe, RingHom.mem_ker,
ContinuousMap.evalStarAlgHom_apply, ContinuousMap.coe_coe]
rw [show ⟨0, h0'⟩ = (0 : s) by ext; exact h0.symm, map_zero f]
/-- An induction principle for `C(s, 𝕜)₀`. -/
@[elab_as_elim]
lemma ContinuousMapZero.induction_on {s : Set 𝕜} [Zero s] (h0 : ((0 : s) : 𝕜) = 0)
{p : C(s, 𝕜)₀ → Prop} (zero : p 0) (id : p (.id h0)) (star_id : p (star (.id h0)))
(add : ∀ f g, p f → p g → p (f + g)) (mul : ∀ f g, p f → p g → p (f * g))
(smul : ∀ (r : 𝕜) f, p f → p (r • f))
(closure : (∀ f ∈ adjoin 𝕜 {(.id h0 : C(s, 𝕜)₀)}, p f) → ∀ f, p f) (f : C(s, 𝕜)₀) :
p f := by
refine closure (fun f hf => ?_) f
induction hf using NonUnitalAlgebra.adjoin_induction with
| mem f hf =>
simp only [Set.mem_union, Set.mem_singleton_iff, Set.mem_star] at hf
rw [star_eq_iff_star_eq, eq_comm (b := f)] at hf
obtain (rfl | rfl) := hf
all_goals assumption
| zero => exact zero
| add _ _ _ _ hf hg => exact add _ _ hf hg
| mul _ _ _ _ hf hg => exact mul _ _ hf hg
| smul _ _ _ hf => exact smul _ _ hf
open Topology in
@[elab_as_elim]
theorem ContinuousMapZero.induction_on_of_compact {s : Set 𝕜} [Zero s] (h0 : ((0 : s) : 𝕜) = 0)
[CompactSpace s] {p : C(s, 𝕜)₀ → Prop} (zero : p 0) (id : p (.id h0))
(star_id : p (star (.id h0))) (add : ∀ f g, p f → p g → p (f + g))
(mul : ∀ f g, p f → p g → p (f * g)) (smul : ∀ (r : 𝕜) f, p f → p (r • f))
(frequently : ∀ f, (∃ᶠ g in 𝓝 f, p g) → p f) (f : C(s, 𝕜)₀) :
p f := by
refine f.induction_on h0 zero id star_id add mul smul fun h f ↦ frequently f ?_
have := (ContinuousMapZero.adjoin_id_dense h0).closure_eq ▸ Set.mem_univ (x := f)
exact mem_closure_iff_frequently.mp this |>.mp <| .of_forall h
lemma ContinuousMapZero.nonUnitalStarAlgHom_apply_mul_eq_zero {𝕜 A : Type*}
[RCLike 𝕜] [NonUnitalSemiring A] [Star A] [TopologicalSpace A] [ContinuousMul A]
[T2Space A] [DistribMulAction 𝕜 A] [IsScalarTower 𝕜 A A] {s : Set 𝕜} [Zero s] [CompactSpace s]
(h0 : (0 : s) = (0 : 𝕜)) (φ : C(s, 𝕜)₀ →⋆ₙₐ[𝕜] A) (a : A) (hmul_id : φ (.id h0) * a = 0)
(hmul_star_id : φ (star (.id h0)) * a = 0) (hφ : Continuous φ) (f : C(s, 𝕜)₀) :
φ f * a = 0 := by
induction f using ContinuousMapZero.induction_on_of_compact h0 with
| zero => simp [map_zero]
| id => exact hmul_id
| star_id => exact hmul_star_id
| add _ _ h₁ h₂ => simp only [map_add, add_mul, h₁, h₂, zero_add]
| mul _ _ _ h => simp only [map_mul, mul_assoc, h, mul_zero]
| smul _ _ h => rw [map_smul, smul_mul_assoc, h, smul_zero]
| frequently f h => exact h.mem_of_closed <| isClosed_eq (by fun_prop) continuous_zero
lemma ContinuousMapZero.mul_nonUnitalStarAlgHom_apply_eq_zero {𝕜 A : Type*}
[RCLike 𝕜] [NonUnitalSemiring A] [Star A] [TopologicalSpace A] [ContinuousMul A]
[T2Space A] [DistribMulAction 𝕜 A] [SMulCommClass 𝕜 A A] {s : Set 𝕜} [Zero s] [CompactSpace s]
(h0 : (0 : s) = (0 : 𝕜)) (φ : C(s, 𝕜)₀ →⋆ₙₐ[𝕜] A) (a : A) (hmul_id : a * φ (.id h0) = 0)
(hmul_star_id : a * φ (star (.id h0)) = 0) (hφ : Continuous φ) (f : C(s, 𝕜)₀) :
a * φ f = 0 := by
induction f using ContinuousMapZero.induction_on_of_compact h0 with
| zero => simp [map_zero]
| id => exact hmul_id
| star_id => exact hmul_star_id
| add _ _ h₁ h₂ => simp only [map_add, mul_add, h₁, h₂, zero_add]
| mul _ _ h _ => simp only [map_mul, ← mul_assoc, h, zero_mul]
| smul _ _ h => rw [map_smul, mul_smul_comm, h, smul_zero]
| frequently f h => exact h.mem_of_closed <| isClosed_eq (by fun_prop) continuous_zero
end ContinuousMapZero
|
IsHomeomorphicTrivialBundle.lean
|
/-
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.Topology.Constructions.SumProd
/-!
# Maps equivariantly-homeomorphic to projection in a product
This file contains the definition `IsHomeomorphicTrivialFiberBundle F p`, a Prop saying that a
map `p : Z → B` between topological spaces is a "trivial fiber bundle" in the sense that there
exists a homeomorphism `h : Z ≃ₜ B × F` such that `proj x = (h x).1`. This is an abstraction which
is occasionally convenient in showing that a map is open, a quotient map, etc.
This material was formerly linked to the main definition of fiber bundles, but after a series of
refactors, there is no longer a direct connection.
-/
open Topology
variable {B : Type*} (F : Type*) {Z : Type*} [TopologicalSpace B] [TopologicalSpace F]
[TopologicalSpace Z]
/-- A trivial fiber bundle with fiber `F` over a base `B` is a space `Z`
projecting on `B` for which there exists a homeomorphism to `B × F` that sends `proj`
to `Prod.fst`. -/
def IsHomeomorphicTrivialFiberBundle (proj : Z → B) : Prop :=
∃ e : Z ≃ₜ B × F, ∀ x, (e x).1 = proj x
namespace IsHomeomorphicTrivialFiberBundle
variable {F} {proj : Z → B}
protected theorem proj_eq (h : IsHomeomorphicTrivialFiberBundle F proj) :
∃ e : Z ≃ₜ B × F, proj = Prod.fst ∘ e :=
⟨h.choose, (funext h.choose_spec).symm⟩
/-- The projection from a trivial fiber bundle to its base is surjective. -/
protected theorem surjective_proj [Nonempty F] (h : IsHomeomorphicTrivialFiberBundle F proj) :
Function.Surjective proj := by
obtain ⟨e, rfl⟩ := h.proj_eq
exact Prod.fst_surjective.comp e.surjective
/-- The projection from a trivial fiber bundle to its base is continuous. -/
protected theorem continuous_proj (h : IsHomeomorphicTrivialFiberBundle F proj) :
Continuous proj := by
obtain ⟨e, rfl⟩ := h.proj_eq; exact continuous_fst.comp e.continuous
/-- The projection from a trivial fiber bundle to its base is open. -/
protected theorem isOpenMap_proj (h : IsHomeomorphicTrivialFiberBundle F proj) :
IsOpenMap proj := by
obtain ⟨e, rfl⟩ := h.proj_eq; exact isOpenMap_fst.comp e.isOpenMap
/-- The projection from a trivial fiber bundle to its base is open. -/
protected theorem isQuotientMap_proj [Nonempty F] (h : IsHomeomorphicTrivialFiberBundle F proj) :
IsQuotientMap proj :=
h.isOpenMap_proj.isQuotientMap h.continuous_proj h.surjective_proj
end IsHomeomorphicTrivialFiberBundle
/-- The first projection in a product is a trivial fiber bundle. -/
theorem isHomeomorphicTrivialFiberBundle_fst :
IsHomeomorphicTrivialFiberBundle F (Prod.fst : B × F → B) :=
⟨Homeomorph.refl _, fun _x => rfl⟩
/-- The second projection in a product is a trivial fiber bundle. -/
theorem isHomeomorphicTrivialFiberBundle_snd :
IsHomeomorphicTrivialFiberBundle F (Prod.snd : F × B → B) :=
⟨Homeomorph.prodComm _ _, fun _x => rfl⟩
|
Basic.lean
|
/-
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]
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_mono (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
refine mem_orbit _ (⟨gv, ?_⟩ : Subgroup.map K.subtype (H.subgroupOf K))
simpa using gp
· rcases h with ⟨⟨gv, gp⟩, rfl⟩
simp only
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]
variable {g h k : G} {a b c : α}
/-- The natural group equivalence between the stabilizers of two elements in the same orbit. -/
def stabilizerEquivStabilizer (hg : b = g • a) : stabilizer G a ≃* stabilizer G b :=
((MulAut.conj g).subgroupMap (stabilizer G a)).trans
(MulEquiv.subgroupCongr (by
rw [hg, stabilizer_smul_eq_stabilizer_map_conj g a, ← MulEquiv.toMonoidHom_eq_coe]))
theorem stabilizerEquivStabilizer_apply (hg : b = g • a) (x : stabilizer G a) :
stabilizerEquivStabilizer hg x = MulAut.conj g x := by
simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_symm_apply (hg : b = g • a) (x : stabilizer G b) :
(stabilizerEquivStabilizer hg).symm x = MulAut.conj g⁻¹ x := by
simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_trans (hg : b = g • a) (hh : c = h • b) (hk : c = k • a)
(H : k = h * g) :
(stabilizerEquivStabilizer hg).trans (stabilizerEquivStabilizer hh) =
stabilizerEquivStabilizer hk := by
ext; simp [stabilizerEquivStabilizer_apply, H]
theorem stabilizerEquivStabilizer_one :
stabilizerEquivStabilizer (one_smul G a).symm = MulEquiv.refl (stabilizer G a) := by
ext; simp [stabilizerEquivStabilizer_apply]
theorem stabilizerEquivStabilizer_symm (hg : b = g • a) :
(stabilizerEquivStabilizer hg).symm =
stabilizerEquivStabilizer (eq_inv_smul_iff.mpr hg.symm) := by
ext x; simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_inv (hg : b = g⁻¹ • a) :
stabilizerEquivStabilizer hg =
(stabilizerEquivStabilizer (inv_smul_eq_iff.mp hg.symm)).symm := by
ext; simp [stabilizerEquivStabilizer]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel (h : orbitRel G α a b) :
stabilizer G a ≃* stabilizer G b :=
(stabilizerEquivStabilizer (Classical.choose_spec h).symm).symm
end Stabilizer
end MulAction
namespace AddAction
variable {G α : Type*} [AddGroup G] [AddAction G α]
variable {g h k : G} {a b c : α}
/-- 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]
variable {g h k : G} {a b c : α}
/-- The natural group equivalence between the stabilizers of two elements in the same orbit. -/
def stabilizerEquivStabilizer (hg : b = g +ᵥ a) : stabilizer G a ≃+ stabilizer G b :=
AddEquiv.trans ((AddAut.conj g).toMul.addSubgroupMap _)
(AddEquiv.addSubgroupCongr (by
rw [hg, stabilizer_vadd_eq_stabilizer_map_conj g a, ← AddEquiv.toAddMonoidHom_eq_coe]))
theorem stabilizerEquivStabilizer_apply (hg : b = g +ᵥ a) (x : stabilizer G a) :
stabilizerEquivStabilizer hg x = (AddAut.conj g).toMul x := by
simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_symm_apply (hg : b = g +ᵥ b) (x : stabilizer G b) :
(stabilizerEquivStabilizer hg).symm x = (AddAut.conj (-g)).toMul x := by
simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_trans
(hg : b = g +ᵥ a) (hh : c = h +ᵥ b) (hk : c = k +ᵥ a) (H : k = h + g) :
(stabilizerEquivStabilizer hg).trans (stabilizerEquivStabilizer hh)
= stabilizerEquivStabilizer hk := by
ext; simp [stabilizerEquivStabilizer_apply, H]
theorem stabilizerEquivStabilizer_zero :
stabilizerEquivStabilizer (zero_vadd G a).symm = AddEquiv.refl (stabilizer G a) := by
ext; simp [stabilizerEquivStabilizer_apply]
theorem stabilizerEquivStabilizer_symm (hg : b = g +ᵥ a) :
(stabilizerEquivStabilizer hg).symm =
stabilizerEquivStabilizer (eq_neg_vadd_iff.mpr hg.symm) := by
ext; simp [stabilizerEquivStabilizer]
theorem stabilizerEquivStabilizer_neg (hg : b = -g +ᵥ a) :
stabilizerEquivStabilizer hg =
(stabilizerEquivStabilizer (neg_vadd_eq_iff.mp hg.symm)).symm := by
ext; simp [stabilizerEquivStabilizer]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel (h : orbitRel G α a b) :
stabilizer G a ≃+ stabilizer G b :=
(stabilizerEquivStabilizer (Classical.choose_spec h).symm).symm
end AddAction
attribute [to_additive existing] MulAction.stabilizerEquivStabilizer
attribute [to_additive existing] MulAction.stabilizerEquivStabilizer_trans
attribute [to_additive existing] MulAction.stabilizerEquivStabilizer_one
attribute [to_additive existing] MulAction.stabilizerEquivStabilizer_inv
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
|
StacksAttribute.lean
|
/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Lean.Elab.Command
import Mathlib.Init
/-!
# The `stacks` and `kerodon` attributes
This allows tagging of mathlib results with the corresponding
tags from the [Stacks Project](https://stacks.math.columbia.edu/tags) and
[Kerodon](https://kerodon.net/tag/).
While the Stacks Project is the main focus, because the tag format at Kerodon is
compatible, the attribute can be used to tag results with Kerodon tags as well.
-/
open Lean Elab
namespace Mathlib.StacksTag
/-- Web database users of projects tags -/
inductive Database where
| kerodon
| stacks
deriving BEq, Hashable
/-- `Tag` is the structure that carries the data of a project tag and a corresponding
Mathlib declaration. -/
structure Tag where
/-- The name of the declaration with the given tag. -/
declName : Name
/-- The online database where the tag is found. -/
database : Database
/-- The database tag. -/
tag : String
/-- The (optional) comment that comes with the given tag. -/
comment : String
deriving BEq, Hashable
/-- Defines the `tagExt` extension for adding a `HashSet` of `Tag`s
to the environment. -/
initialize tagExt : SimplePersistentEnvExtension Tag (Std.HashSet Tag) ←
registerSimplePersistentEnvExtension {
addImportedFn := fun as => as.foldl Std.HashSet.insertMany {}
addEntryFn := .insert
}
/--
`addTagEntry declName tag comment` takes as input the `Name` `declName` of a declaration and
the `String`s `tag` and `comment` of the `stacks` attribute.
It extends the `Tag` environment extension with the data `declName, tag, comment`.
-/
def addTagEntry {m : Type → Type} [MonadEnv m]
(declName : Name) (db : Database) (tag comment : String) : m Unit :=
modifyEnv (tagExt.addEntry ·
{ declName := declName, database := db, tag := tag, comment := comment })
open Parser
/-- `stacksTag` is the node kind of Stacks Project Tags: a sequence of digits and
uppercase letters. -/
abbrev stacksTagKind : SyntaxNodeKind := `stacksTag
/-- The main parser for Stacks Project Tags: it accepts any sequence of 4 digits or
uppercase letters. -/
def stacksTagFn : ParserFn := fun c s =>
let i := s.pos
let s := takeWhileFn (fun c => c.isAlphanum) c s
if s.hasError then
s
else if s.pos == i then
ParserState.mkError s "stacks tag"
else
let tag := Substring.mk c.input i s.pos |>.toString
if !tag.all fun c => c.isDigit || c.isUpper then
ParserState.mkUnexpectedError s
"Stacks tags must consist only of digits and uppercase letters."
else if tag.length != 4 then
ParserState.mkUnexpectedError s "Stacks tags must be exactly 4 characters"
else
mkNodeToken stacksTagKind i c s
@[inherit_doc stacksTagFn]
def stacksTagNoAntiquot : Parser := {
fn := stacksTagFn
info := mkAtomicInfo "stacksTag"
}
@[inherit_doc stacksTagFn]
def stacksTagParser : Parser :=
withAntiquot (mkAntiquot "stacksTag" stacksTagKind) stacksTagNoAntiquot
end Mathlib.StacksTag
open Mathlib.StacksTag
/-- Extract the underlying tag as a string from a `stacksTag` node. -/
def Lean.TSyntax.getStacksTag (stx : TSyntax stacksTagKind) : CoreM String := do
let some val := Syntax.isLit? stacksTagKind stx | throwError "Malformed Stacks tag"
return val
namespace Lean.PrettyPrinter
namespace Formatter
/-- The formatter for Stacks Project Tags syntax. -/
@[combinator_formatter stacksTagNoAntiquot] def stacksTagNoAntiquot.formatter :=
visitAtom stacksTagKind
end Formatter
namespace Parenthesizer
/-- The parenthesizer for Stacks Project Tags syntax. -/
@[combinator_parenthesizer stacksTagNoAntiquot] def stacksTagAntiquot.parenthesizer := visitToken
end Lean.PrettyPrinter.Parenthesizer
namespace Mathlib.StacksTag
/-- The syntax category for the database name. -/
declare_syntax_cat stacksTagDB
/-- The syntax for a "kerodon" database identifier in a `@[kerodon]` attribute. -/
syntax "kerodon" : stacksTagDB
/-- The syntax for a "stacks" database identifier in a `@[stacks]` attribute. -/
syntax "stacks" : stacksTagDB
/-- The `stacksTag` attribute.
Use it as `@[kerodon TAG "Optional comment"]` or `@[stacks TAG "Optional comment"]`
depending on the database you are referencing.
The `TAG` is mandatory and should be a sequence of 4 digits or uppercase letters.
See the [Tags page](https://stacks.math.columbia.edu/tags) in the Stacks project or
[Tags page](https://kerodon.net/tag/) in the Kerodon project for more details.
-/
syntax (name := stacksTag) stacksTagDB stacksTagParser (ppSpace str)? : attr
initialize Lean.registerBuiltinAttribute {
name := `stacksTag
descr := "Apply a Stacks or Kerodon project tag to a theorem."
add := fun decl stx _attrKind => do
let oldDoc := (← findDocString? (← getEnv) decl).getD ""
let (SorK, database, url, tag, comment) := ← match stx with
| `(attr| stacks $tag $[$comment]?) =>
return ("Stacks", Database.stacks, "https://stacks.math.columbia.edu/tag", tag, comment)
| `(attr| kerodon $tag $[$comment]?) =>
return ("Kerodon", Database.kerodon, "https://kerodon.net/tag", tag, comment)
| _ => throwUnsupportedSyntax
let tagStr ← tag.getStacksTag
let comment := (comment.map (·.getString)).getD ""
let commentInDoc := if comment = "" then "" else s!" ({comment})"
let newDoc := [oldDoc, s!"[{SorK} Tag {tagStr}]({url}/{tagStr}){commentInDoc}"]
addDocStringCore decl <| "\n\n".intercalate (newDoc.filter (· != ""))
addTagEntry decl database tagStr <| comment
-- docstrings are immutable once an asynchronous elaboration task has been started
applicationTime := .beforeElaboration
}
end Mathlib.StacksTag
/--
`getSortedStackProjectTags env` returns the array of `Tags`, sorted by alphabetical order of tag.
-/
private def Lean.Environment.getSortedStackProjectTags (env : Environment) : Array Tag :=
tagExt.getState env |>.toArray.qsort (·.tag < ·.tag)
/--
`getSortedStackProjectDeclNames env tag` returns the array of declaration names of results
with Stacks Project tag equal to `tag`.
-/
private def Lean.Environment.getSortedStackProjectDeclNames (env : Environment) (tag : String) :
Array Name :=
let tags := env.getSortedStackProjectTags
tags.filterMap fun d => if d.tag == tag then some d.declName else none
namespace Mathlib.StacksTag
private def databaseURL (db : Database) : String :=
match db with
| .kerodon => "https://kerodon.net/tag/"
| .stacks => "https://stacks.math.columbia.edu/tag/"
/--
`traceStacksTags db verbose` prints the tags of the database `db` to the user and
inlines the theorem statements if `verbose` is `true`.
-/
def traceStacksTags (db : Database) (verbose : Bool := false) :
Command.CommandElabM Unit := do
let env ← getEnv
let entries := env.getSortedStackProjectTags |>.filter (·.database == db)
if entries.isEmpty then logInfo "No tags found." else
let mut msgs := #[m!""]
for d in entries do
let (parL, parR) := if d.comment.isEmpty then ("", "") else (" (", ")")
let cmt := parL ++ d.comment ++ parR
msgs := msgs.push
m!"[Stacks Tag {d.tag}]({databaseURL db ++ d.tag}) \
corresponds to declaration '{.ofConstName d.declName}'.{cmt}"
if verbose then
let dType := ((env.find? d.declName).getD default).type
msgs := (msgs.push m!"{dType}").push ""
let msg := MessageData.joinSep msgs.toList "\n"
logInfo msg
/--
`#stacks_tags` retrieves all declarations that have the `stacks` attribute.
For each found declaration, it prints a line
```
'declaration_name' corresponds to tag 'declaration_tag'.
```
The variant `#stacks_tags!` also adds the theorem statement after each summary line.
-/
elab (name := stacksTags) "#stacks_tags" tk:("!")?: command =>
traceStacksTags .stacks (tk.isSome)
/-- The `#kerodon_tags` command retrieves all declarations that have the `kerodon` attribute.
For each found declaration, it prints a line
```
'declaration_name' corresponds to tag 'declaration_tag'.
```
The variant `#kerodon_tags!` also adds the theorem statement after each summary line.
-/
elab (name := kerodonTags) "#kerodon_tags" tk:("!")?: command =>
traceStacksTags .kerodon (tk.isSome)
end Mathlib.StacksTag
|
Basic.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Johan Commelin
-/
import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Module.Rat
import Mathlib.LinearAlgebra.TensorProduct.Tower
/-!
# The tensor product of R-algebras
This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a
commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products,
multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`.
## Main declarations
- `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`.
- `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is
additionally an `S` algebra.
- the structure isomorphisms
* `Algebra.TensorProduct.lid : R ⊗[R] A ≃ₐ[R] A`
* `Algebra.TensorProduct.rid : A ⊗[R] R ≃ₐ[S] A` (usually used with `S = R` or `S = A`)
* `Algebra.TensorProduct.comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A`
* `Algebra.TensorProduct.assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))`
- `Algebra.TensorProduct.liftEquiv`: a universal property for the tensor product of algebras.
## References
* [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995]
-/
assert_not_exists Equiv.Perm.cycleType
open scoped TensorProduct
open TensorProduct
namespace LinearMap
section liftBaseChange
variable {R M N} (A) [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M]
variable [AddCommMonoid N] [Module R M] [Module R N] [Module A N] [IsScalarTower R A N]
/--
If `M` is an `R`-module and `N` is an `A`-module, then `A`-linear maps `A ⊗[R] M →ₗ[A] N`
correspond to `R` linear maps `M →ₗ[R] N` by composing with `M → A ⊗ M`, `x ↦ 1 ⊗ x`.
-/
def liftBaseChangeEquiv : (M →ₗ[R] N) ≃ₗ[A] (A ⊗[R] M →ₗ[A] N) :=
(LinearMap.ringLmapEquivSelf _ _ _).symm.trans (AlgebraTensorModule.lift.equiv _ _ _ _ _ _)
/-- If `N` is an `A` module, we may lift a linear map `M →ₗ[R] N` to `A ⊗[R] M →ₗ[A] N` -/
abbrev liftBaseChange (l : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] N :=
LinearMap.liftBaseChangeEquiv A l
@[simp]
lemma liftBaseChange_tmul (l : M →ₗ[R] N) (x y) : l.liftBaseChange A (x ⊗ₜ y) = x • l y := rfl
lemma liftBaseChange_one_tmul (l : M →ₗ[R] N) (y) : l.liftBaseChange A (1 ⊗ₜ y) = l y := by simp
@[simp]
lemma liftBaseChangeEquiv_symm_apply (l : A ⊗[R] M →ₗ[A] N) (x) :
(liftBaseChangeEquiv A).symm l x = l (1 ⊗ₜ x) := rfl
lemma liftBaseChange_comp {P} [AddCommMonoid P] [Module A P] [Module R P] [IsScalarTower R A P]
(l : M →ₗ[R] N) (l' : N →ₗ[A] P) :
l' ∘ₗ l.liftBaseChange A = (l'.restrictScalars R ∘ₗ l).liftBaseChange A := by
ext
simp
@[simp]
lemma range_liftBaseChange (l : M →ₗ[R] N) :
LinearMap.range (l.liftBaseChange A) = Submodule.span A (LinearMap.range l) := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩
induction x using TensorProduct.induction_on
· simp
· rw [LinearMap.liftBaseChange_tmul]
exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨_, rfl⟩)
· rw [map_add]
exact add_mem ‹_› ‹_›
· rw [Submodule.span_le]
rintro _ ⟨x, rfl⟩
exact ⟨1 ⊗ₜ x, by simp⟩
end liftBaseChange
end LinearMap
namespace Module.End
open LinearMap
variable (R M N : Type*)
[CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
/-- The map `LinearMap.lTensorHom` which sends `f ↦ 1 ⊗ f` as a morphism of algebras. -/
@[simps!]
def lTensorAlgHom : Module.End R M →ₐ[R] Module.End R (N ⊗[R] M) :=
.ofLinearMap (lTensorHom (M := N)) (lTensor_id N M) (lTensor_mul N)
/-- The map `LinearMap.rTensorHom` which sends `f ↦ f ⊗ 1` as a morphism of algebras. -/
@[simps!]
def rTensorAlgHom : Module.End R M →ₐ[R] Module.End R (M ⊗[R] N) :=
.ofLinearMap (rTensorHom (M := N)) (rTensor_id N M) (rTensor_mul N)
end Module.End
namespace Algebra
namespace TensorProduct
universe uR uS uA uB uC uD uE uF
variable {R : Type uR} {R' : Type*} {S : Type uS} {T : Type*}
variable {A : Type uA} {B : Type uB} {C : Type uC} {D : Type uD} {E : Type uE} {F : Type uF}
/-!
### The `R`-algebra structure on `A ⊗[R] B`
-/
section AddCommMonoidWithOne
variable [CommSemiring R]
variable [AddCommMonoidWithOne A] [Module R A]
variable [AddCommMonoidWithOne B] [Module R B]
instance : One (A ⊗[R] B) where one := 1 ⊗ₜ 1
theorem one_def : (1 : A ⊗[R] B) = (1 : A) ⊗ₜ (1 : B) :=
rfl
instance instAddCommMonoidWithOne : AddCommMonoidWithOne (A ⊗[R] B) where
natCast n := n ⊗ₜ 1
natCast_zero := by simp
natCast_succ n := by simp [add_tmul, one_def]
add_comm := add_comm
theorem natCast_def (n : ℕ) : (n : A ⊗[R] B) = (n : A) ⊗ₜ (1 : B) := rfl
theorem natCast_def' (n : ℕ) : (n : A ⊗[R] B) = (1 : A) ⊗ₜ (n : B) := by
rw [natCast_def, ← nsmul_one, smul_tmul, nsmul_one]
end AddCommMonoidWithOne
section NonUnitalNonAssocSemiring
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
/-- (Implementation detail)
The multiplication map on `A ⊗[R] B`,
as an `R`-bilinear map.
-/
@[irreducible]
def mul : A ⊗[R] B →ₗ[R] A ⊗[R] B →ₗ[R] A ⊗[R] B :=
TensorProduct.map₂ (LinearMap.mul R A) (LinearMap.mul R B)
unseal mul in
@[simp]
theorem mul_apply (a₁ a₂ : A) (b₁ b₂ : B) :
mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
-- providing this instance separately makes some downstream code substantially faster
instance instMul : Mul (A ⊗[R] B) where
mul a b := mul a b
unseal mul in
@[simp]
theorem tmul_mul_tmul (a₁ a₂ : A) (b₁ b₂ : B) :
a₁ ⊗ₜ[R] b₁ * a₂ ⊗ₜ[R] b₂ = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
unseal mul in
theorem _root_.SemiconjBy.tmul {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B}
(ha : SemiconjBy a₁ a₂ a₃) (hb : SemiconjBy b₁ b₂ b₃) :
SemiconjBy (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) (a₃ ⊗ₜ[R] b₃) :=
congr_arg₂ (· ⊗ₜ[R] ·) ha.eq hb.eq
nonrec theorem _root_.Commute.tmul {a₁ a₂ : A} {b₁ b₂ : B}
(ha : Commute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) :=
ha.tmul hb
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
-- we want `isScalarTower_right` to take priority since it's better for unification elsewhere
instance (priority := 100) isScalarTower_right [Monoid S] [DistribMulAction S A]
[IsScalarTower S A A] [SMulCommClass R S A] : IsScalarTower S (A ⊗[R] B) (A ⊗[R] B) where
smul_assoc r x y := by
change r • x * y = r • (x * y)
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, smul_mul_assoc]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
-- we want `Algebra.to_smulCommClass` to take priority since it's better for unification elsewhere
instance (priority := 100) sMulCommClass_right [Monoid S] [DistribMulAction S A]
[SMulCommClass S A A] [SMulCommClass R S A] : SMulCommClass S (A ⊗[R] B) (A ⊗[R] B) where
smul_comm r x y := by
change r • (x * y) = x * r • y
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, mul_smul_comm]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [CommSemiring R]
variable [NonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
protected theorem one_mul (x : A ⊗[R] B) : mul (1 ⊗ₜ 1) x = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual
protected theorem mul_one (x : A ⊗[R] B) : mul x (1 ⊗ₜ 1) = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual
instance instNonAssocSemiring : NonAssocSemiring (A ⊗[R] B) where
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
toNonUnitalNonAssocSemiring := instNonUnitalNonAssocSemiring
__ := instAddCommMonoidWithOne
end NonAssocSemiring
section NonUnitalSemiring
variable [CommSemiring R]
variable [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
unseal mul in
protected theorem mul_assoc (x y z : A ⊗[R] B) : mul (mul x y) z = mul x (mul y z) := by
-- restate as an equality of morphisms so that we can use `ext`
suffices LinearMap.llcomp R _ _ _ mul ∘ₗ mul =
(LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <|
LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by
exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z
ext xa xb ya yb za zb
exact congr_arg₂ (· ⊗ₜ ·) (mul_assoc xa ya za) (mul_assoc xb yb zb)
instance instNonUnitalSemiring : NonUnitalSemiring (A ⊗[R] B) where
mul_assoc := Algebra.TensorProduct.mul_assoc
end NonUnitalSemiring
section Semiring
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra R C]
instance instSemiring : Semiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
mul_assoc := Algebra.TensorProduct.mul_assoc
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
natCast_zero := AddMonoidWithOne.natCast_zero
natCast_succ := AddMonoidWithOne.natCast_succ
@[simp]
theorem tmul_pow (a : A) (b : B) (k : ℕ) : a ⊗ₜ[R] b ^ k = (a ^ k) ⊗ₜ[R] (b ^ k) := by
induction' k with k ih
· simp [one_def]
· simp [pow_succ, ih]
/-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
@[simps]
def includeLeftRingHom : A →+* A ⊗[R] B where
toFun a := a ⊗ₜ 1
map_zero' := by simp
map_add' := by simp [add_tmul]
map_one' := rfl
map_mul' := by simp
variable [CommSemiring S] [Algebra S A]
instance leftAlgebra [SMulCommClass R S A] : Algebra S (A ⊗[R] B) :=
{ commutes' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', ← one_def, mul_smul_comm, smul_mul_assoc, mul_one,
one_mul]
smul_def' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', smul_mul_assoc, ← one_def, one_mul]
algebraMap := TensorProduct.includeLeftRingHom.comp (algebraMap S A) }
example : (Semiring.toNatAlgebra : Algebra ℕ (ℕ ⊗[ℕ] B)) = leftAlgebra := rfl
-- This is for the `undergrad.yaml` list.
/-- The tensor product of two `R`-algebras is an `R`-algebra. -/
instance instAlgebra : Algebra R (A ⊗[R] B) :=
inferInstance
@[simp]
theorem algebraMap_apply [SMulCommClass R S A] (r : S) :
algebraMap S (A ⊗[R] B) r = (algebraMap S A) r ⊗ₜ 1 :=
rfl
theorem algebraMap_apply' (r : R) :
algebraMap R (A ⊗[R] B) r = 1 ⊗ₜ algebraMap R B r := by
rw [algebraMap_apply, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul]
/-- The `R`-algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
def includeLeft [SMulCommClass R S A] : A →ₐ[S] A ⊗[R] B :=
{ includeLeftRingHom with commutes' := by simp }
@[simp]
theorem includeLeft_apply [SMulCommClass R S A] (a : A) :
(includeLeft : A →ₐ[S] A ⊗[R] B) a = a ⊗ₜ 1 :=
rfl
/-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/
def includeRight : B →ₐ[R] A ⊗[R] B where
toFun b := 1 ⊗ₜ b
map_zero' := by simp
map_add' := by simp [tmul_add]
map_one' := rfl
map_mul' := by simp
commutes' r := by simp only [algebraMap_apply']
@[simp]
theorem includeRight_apply (b : B) : (includeRight : B →ₐ[R] A ⊗[R] B) b = 1 ⊗ₜ b :=
rfl
theorem includeLeftRingHom_comp_algebraMap :
(includeLeftRingHom.comp (algebraMap R A) : R →+* A ⊗[R] B) =
includeRight.toRingHom.comp (algebraMap R B) := by
ext
simp
section ext
variable [Algebra R S] [Algebra S C] [IsScalarTower R S A] [IsScalarTower R S C]
/-- A version of `TensorProduct.ext` for `AlgHom`.
Using this as the `@[ext]` lemma instead of `Algebra.TensorProduct.ext'` allows `ext` to apply
lemmas specific to `A →ₐ[S] _` and `B →ₐ[R] _`; notably this allows recursion into nested tensor
products of algebras.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ext ⦃f g : (A ⊗[R] B) →ₐ[S] C⦄
(ha : f.comp includeLeft = g.comp includeLeft)
(hb : (f.restrictScalars R).comp includeRight = (g.restrictScalars R).comp includeRight) :
f = g := by
apply AlgHom.toLinearMap_injective
ext a b
have := congr_arg₂ HMul.hMul (AlgHom.congr_fun ha a) (AlgHom.congr_fun hb b)
dsimp at *
rwa [← map_mul, ← map_mul, tmul_mul_tmul, one_mul, mul_one] at this
theorem ext' {g h : A ⊗[R] B →ₐ[S] C} (H : ∀ a b, g (a ⊗ₜ b) = h (a ⊗ₜ b)) : g = h :=
ext (AlgHom.ext fun _ => H _ _) (AlgHom.ext fun _ => H _ _)
end ext
end Semiring
section AddCommGroupWithOne
variable [CommSemiring R]
variable [AddCommGroupWithOne A] [Module R A]
variable [AddCommGroupWithOne B] [Module R B]
instance instAddCommGroupWithOne : AddCommGroupWithOne (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instAddCommMonoidWithOne
intCast z := z ⊗ₜ (1 : B)
intCast_ofNat n := by simp [natCast_def]
intCast_negSucc n := by simp [natCast_def, add_tmul, neg_tmul, one_def]
theorem intCast_def (z : ℤ) : (z : A ⊗[R] B) = (z : A) ⊗ₜ (1 : B) := rfl
end AddCommGroupWithOne
section NonUnitalNonAssocRing
variable [CommRing R]
variable [NonUnitalNonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalNonAssocRing : NonUnitalNonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalNonAssocSemiring
end NonUnitalNonAssocRing
section NonAssocRing
variable [CommRing R]
variable [NonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonAssocRing : NonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonAssocSemiring
__ := instAddCommGroupWithOne
end NonAssocRing
section NonUnitalRing
variable [CommRing R]
variable [NonUnitalRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalRing : NonUnitalRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalSemiring
end NonUnitalRing
section CommSemiring
variable [CommSemiring R]
variable [CommSemiring A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
instance instCommSemiring : CommSemiring (A ⊗[R] B) where
toSemiring := inferInstance
mul_comm x y := by
refine TensorProduct.induction_on x ?_ ?_ ?_
· simp
· intro a₁ b₁
refine TensorProduct.induction_on y ?_ ?_ ?_
· simp
· intro a₂ b₂
simp [mul_comm]
· intro a₂ b₂ ha hb
simp [mul_add, add_mul, ha, hb]
· intro x₁ x₂ h₁ h₂
simp [mul_add, add_mul, h₁, h₂]
end CommSemiring
section Ring
variable [CommRing R]
variable [Ring A] [Algebra R A]
variable [Ring B] [Algebra R B]
instance instRing : Ring (A ⊗[R] B) where
toSemiring := instSemiring
__ := TensorProduct.addCommGroup
__ := instNonAssocRing
theorem intCast_def' (z : ℤ) : (z : A ⊗[R] B) = (1 : A) ⊗ₜ (z : B) := by
rw [intCast_def, ← zsmul_one, smul_tmul, zsmul_one]
-- verify there are no diamonds
example : (instRing : Ring (A ⊗[R] B)).toAddCommGroup = addCommGroup := by
with_reducible_and_instances rfl
-- fails at `with_reducible_and_instances rfl` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (ℤ ⊗[ℤ] B)) = leftAlgebra := rfl
end Ring
section CommRing
variable [CommRing R]
variable [CommRing A] [Algebra R A]
variable [CommRing B] [Algebra R B]
instance instCommRing : CommRing (A ⊗[R] B) :=
{ toRing := inferInstance
mul_comm := mul_comm }
end CommRing
section RightAlgebra
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
/-- `S ⊗[R] T` has a `T`-algebra structure. This is not a global instance or else the action of
`S` on `S ⊗[R] S` would be ambiguous. -/
abbrev rightAlgebra : Algebra B (A ⊗[R] B) :=
includeRight.toRingHom.toAlgebra' fun b x => by
suffices LinearMap.mulLeft R (includeRight b) = LinearMap.mulRight R (includeRight b) from
congr($this x)
ext xa xb
simp [mul_comm]
attribute [local instance] TensorProduct.rightAlgebra
instance right_isScalarTower : IsScalarTower R B (A ⊗[R] B) :=
IsScalarTower.of_algebraMap_eq fun r => (Algebra.TensorProduct.includeRight.commutes r).symm
lemma right_algebraMap_apply (b : B) : algebraMap B (A ⊗[R] B) b = 1 ⊗ₜ b := rfl
instance : SMulCommClass A B (A ⊗[R] B) where
smul_comm a b x := x.induction_on (by simp)
(fun _ _ ↦ by simp [Algebra.smul_def, right_algebraMap_apply, smul_tmul'])
fun _ _ h₁ h₂ ↦ by simpa using congr($h₁ + $h₂)
instance : SMulCommClass B A (A ⊗[R] B) := .symm ..
end RightAlgebra
/-- Verify that typeclass search finds the ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely rings, by treating both as `ℤ`-algebras.
-/
example [Ring A] [Ring B] : Ring (A ⊗[ℤ] B) := by infer_instance
/-- Verify that typeclass search finds the comm_ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely comm_rings, by treating both as `ℤ`-algebras.
-/
example [CommRing A] [CommRing B] : CommRing (A ⊗[ℤ] B) := by infer_instance
/-!
We now build the structure maps for the symmetric monoidal category of `R`-algebras.
-/
section Monoidal
section
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra S C]
variable [Semiring D] [Algebra R D]
/-- To check a linear map preserves multiplication, it suffices to check it on pure tensors. See
`algHomOfLinearMapTensorProduct` for a bundled version. -/
lemma _root_.LinearMap.map_mul_of_map_mul_tmul {f : A ⊗[R] B →ₗ[S] C}
(hf : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(x y : A ⊗[R] B) : f (x * y) = f x * f y :=
f.map_mul_iff.2 (by
-- these instances are needed by the statement of `ext`, but not by the current definition.
letI : Algebra R C := RestrictScalars.algebra R S C
letI : IsScalarTower R S C := RestrictScalars.isScalarTower R S C
ext
dsimp
exact hf _ _ _ _) x y
/-- Build an algebra morphism from a linear map out of a tensor product, and evidence that on pure
tensors, it preserves multiplication and the identity.
Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure
tensors can be directly applied by the caller (without needing `TensorProduct.one_def`).
-/
def algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C)
(h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B →ₐ[S] C :=
AlgHom.ofLinearMap f h_one (f.map_mul_of_map_mul_tmul h_mul)
@[simp]
theorem algHomOfLinearMapTensorProduct_apply (f h_mul h_one x) :
(algHomOfLinearMapTensorProduct f h_mul h_one : A ⊗[R] B →ₐ[S] C) x = f x :=
rfl
/-- Build an algebra equivalence from a linear equivalence out of a tensor product, and evidence
that on pure tensors, it preserves multiplication and the identity.
Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure
tensors can be directly applied by the caller (without needing `TensorProduct.one_def`).
-/
def algEquivOfLinearEquivTensorProduct (f : A ⊗[R] B ≃ₗ[S] C)
(h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B ≃ₐ[S] C :=
{ algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C) h_mul h_one, f with }
@[simp]
theorem algEquivOfLinearEquivTensorProduct_apply (f h_mul h_one x) :
(algEquivOfLinearEquivTensorProduct f h_mul h_one : A ⊗[R] B ≃ₐ[S] C) x = f x :=
rfl
variable [Algebra R C]
/-- Build an algebra equivalence from a linear equivalence out of a triple tensor product,
and evidence of multiplicativity on pure tensors.
-/
def algEquivOfLinearEquivTripleTensorProduct (f : A ⊗[R] B ⊗[R] C ≃ₗ[R] D)
(h_mul :
∀ (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C),
f ((a₁ * a₂) ⊗ₜ (b₁ * b₂) ⊗ₜ (c₁ * c₂)) = f (a₁ ⊗ₜ b₁ ⊗ₜ c₁) * f (a₂ ⊗ₜ b₂ ⊗ₜ c₂))
(h_one : f (((1 : A) ⊗ₜ[R] (1 : B)) ⊗ₜ[R] (1 : C)) = 1) :
A ⊗[R] B ⊗[R] C ≃ₐ[R] D :=
AlgEquiv.ofLinearEquiv f h_one <| f.map_mul_iff.2 <| by
ext
dsimp
exact h_mul _ _ _ _ _ _
@[simp]
theorem algEquivOfLinearEquivTripleTensorProduct_apply (f h_mul h_one x) :
(algEquivOfLinearEquivTripleTensorProduct f h_mul h_one : A ⊗[R] B ⊗[R] C ≃ₐ[R] D) x = f x :=
rfl
section lift
variable [IsScalarTower R S C]
/-- The forward direction of the universal property of tensor products of algebras; any algebra
morphism from the tensor product can be factored as the product of two algebra morphisms that
commute.
See `Algebra.TensorProduct.liftEquiv` for the fact that every morphism factors this way. -/
def lift (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) : (A ⊗[R] B) →ₐ[S] C :=
algHomOfLinearMapTensorProduct
(AlgebraTensorModule.lift <|
letI restr : (C →ₗ[S] C) →ₗ[S] _ :=
{ toFun := (·.restrictScalars R)
map_add' := fun _ _ => LinearMap.ext fun _ => rfl
map_smul' := fun _ _ => LinearMap.ext fun _ => rfl }
LinearMap.flip <| (restr ∘ₗ LinearMap.mul S C ∘ₗ f.toLinearMap).flip ∘ₗ g)
(fun a₁ a₂ b₁ b₂ => show f (a₁ * a₂) * g (b₁ * b₂) = f a₁ * g b₁ * (f a₂ * g b₂) by
rw [map_mul, map_mul, (hfg a₂ b₁).mul_mul_mul_comm])
(show f 1 * g 1 = 1 by rw [map_one, map_one, one_mul])
@[simp]
theorem lift_tmul (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y))
(a : A) (b : B) :
lift f g hfg (a ⊗ₜ b) = f a * g b :=
rfl
@[simp]
theorem lift_includeLeft_includeRight :
lift includeLeft includeRight (fun _ _ => (Commute.one_right _).tmul (Commute.one_left _)) =
.id S (A ⊗[R] B) := by
ext <;> simp
@[simp]
theorem lift_comp_includeLeft (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) :
(lift f g hfg).comp includeLeft = f :=
AlgHom.ext <| by simp
@[simp]
theorem lift_comp_includeRight (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) :
((lift f g hfg).restrictScalars R).comp includeRight = g :=
AlgHom.ext <| by simp
/-- The universal property of the tensor product of algebras.
Pairs of algebra morphisms that commute are equivalent to algebra morphisms from the tensor product.
This is `Algebra.TensorProduct.lift` as an equivalence.
See also `GradedTensorProduct.liftEquiv` for an alternative commutativity requirement for graded
algebra. -/
@[simps]
def liftEquiv : {fg : (A →ₐ[S] C) × (B →ₐ[R] C) // ∀ x y, Commute (fg.1 x) (fg.2 y)}
≃ ((A ⊗[R] B) →ₐ[S] C) where
toFun fg := lift fg.val.1 fg.val.2 fg.prop
invFun f' := ⟨(f'.comp includeLeft, (f'.restrictScalars R).comp includeRight), fun _ _ =>
((Commute.one_right _).tmul (Commute.one_left _)).map f'⟩
left_inv fg := by ext <;> simp
right_inv f' := by ext <;> simp
end lift
end
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra R C] [Algebra S C] [IsScalarTower R S C]
variable [Semiring D] [Algebra R D]
variable [Semiring E] [Algebra R E] [Algebra S E] [IsScalarTower R S E]
variable [Semiring F] [Algebra R F]
section
variable (R A)
/-- The base ring is a left identity for the tensor product of algebra, up to algebra isomorphism.
-/
protected nonrec def lid : R ⊗[R] A ≃ₐ[R] A :=
algEquivOfLinearEquivTensorProduct (TensorProduct.lid R A) (by
simp only [mul_smul, lid_tmul, Algebra.smul_mul_assoc, Algebra.mul_smul_comm]
simp_rw [← mul_smul, mul_comm]
simp)
(by simp [Algebra.smul_def])
@[simp] theorem lid_toLinearEquiv :
(TensorProduct.lid R A).toLinearEquiv = _root_.TensorProduct.lid R A := rfl
variable {R} {A} in
@[simp]
theorem lid_tmul (r : R) (a : A) : TensorProduct.lid R A (r ⊗ₜ a) = r • a := rfl
variable {A} in
@[simp]
theorem lid_symm_apply (a : A) : (TensorProduct.lid R A).symm a = 1 ⊗ₜ a := rfl
variable (S)
/-- The base ring is a right identity for the tensor product of algebra, up to algebra isomorphism.
Note that if `A` is commutative this can be instantiated with `S = A`.
-/
protected nonrec def rid : A ⊗[R] R ≃ₐ[S] A :=
algEquivOfLinearEquivTensorProduct (AlgebraTensorModule.rid R S A)
(fun a₁ a₂ r₁ r₂ => smul_mul_smul_comm r₁ a₁ r₂ a₂ |>.symm)
(one_smul R _)
@[simp] theorem rid_toLinearEquiv :
(TensorProduct.rid R S A).toLinearEquiv = AlgebraTensorModule.rid R S A := rfl
variable {R A} in
@[simp]
theorem rid_tmul (r : R) (a : A) : TensorProduct.rid R S A (a ⊗ₜ r) = r • a := rfl
variable {A} in
@[simp]
theorem rid_symm_apply (a : A) : (TensorProduct.rid R S A).symm a = a ⊗ₜ 1 := rfl
section CompatibleSMul
variable (R S A B : Type*) [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B]
variable [Algebra R A] [Algebra R B] [Algebra S A] [Algebra S B]
variable [SMulCommClass R S A] [CompatibleSMul R S A B]
/-- If A and B are both R- and S-algebras and their actions on them commute,
and if the S-action on `A ⊗[R] B` can switch between the two factors, then there is a
canonical S-algebra homomorphism from `A ⊗[S] B` to `A ⊗[R] B`. -/
def mapOfCompatibleSMul : A ⊗[S] B →ₐ[S] A ⊗[R] B :=
.ofLinearMap (_root_.TensorProduct.mapOfCompatibleSMul R S A B) rfl fun x ↦
x.induction_on (by simp) (fun _ _ y ↦ y.induction_on (by simp) (by simp)
fun _ _ h h' ↦ by simp only [mul_add, map_add, h, h'])
fun _ _ h h' _ ↦ by simp only [add_mul, map_add, h, h']
@[simp] theorem mapOfCompatibleSMul_tmul (m n) : mapOfCompatibleSMul R S A B (m ⊗ₜ n) = m ⊗ₜ n :=
rfl
theorem mapOfCompatibleSMul_surjective : Function.Surjective (mapOfCompatibleSMul R S A B) :=
_root_.TensorProduct.mapOfCompatibleSMul_surjective R S A B
attribute [local instance] SMulCommClass.symm
/-- `mapOfCompatibleSMul R S A B` is also A-linear. -/
def mapOfCompatibleSMul' : A ⊗[S] B →ₐ[R] A ⊗[R] B :=
.ofLinearMap (_root_.TensorProduct.mapOfCompatibleSMul' R S A B) rfl
(map_mul <| mapOfCompatibleSMul R S A B)
/-- If the R- and S-actions on A and B satisfy `CompatibleSMul` both ways,
then `A ⊗[S] B` is canonically isomorphic to `A ⊗[R] B`. -/
def equivOfCompatibleSMul [CompatibleSMul S R A B] : A ⊗[S] B ≃ₐ[S] A ⊗[R] B where
__ := mapOfCompatibleSMul R S A B
invFun := mapOfCompatibleSMul S R A B
__ := _root_.TensorProduct.equivOfCompatibleSMul R S A B
variable [Algebra R S] [CompatibleSMul R S S A] [CompatibleSMul S R S A]
omit [SMulCommClass R S A]
/-- If the R- and S- action on S and A satisfy `CompatibleSMul` both ways,
then `S ⊗[R] A` is canonically isomorphic to `A`. -/
def lidOfCompatibleSMul : S ⊗[R] A ≃ₐ[S] A :=
(equivOfCompatibleSMul R S S A).symm.trans (TensorProduct.lid _ _)
theorem lidOfCompatibleSMul_tmul (s a) : lidOfCompatibleSMul R S A (s ⊗ₜ[R] a) = s • a := rfl
instance {R M N : Type*} [CommSemiring R] [AddCommGroup M] [AddCommGroup N]
[Module R M] [Module R N] [Module ℚ M] [Module ℚ N] : CompatibleSMul R ℚ M N where
smul_tmul q m n := by
suffices q.den • ((q • m) ⊗ₜ[R] n) = q.den • (m ⊗ₜ[R] (q • n)) from
smul_right_injective (M ⊗[R] N) (c := q.den) q.den_nz <| by norm_cast
rw [smul_tmul', ← tmul_smul, ← smul_assoc, ← smul_assoc, nsmul_eq_mul, Rat.den_mul_eq_num]
norm_cast
rw [smul_tmul]
end CompatibleSMul
section
variable (B)
unseal mul in
/-- The tensor product of R-algebras is commutative, up to algebra isomorphism.
-/
protected def comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A :=
algEquivOfLinearEquivTensorProduct (_root_.TensorProduct.comm R A B) (fun _ _ _ _ => rfl) rfl
@[simp] theorem comm_toLinearEquiv :
(Algebra.TensorProduct.comm R A B).toLinearEquiv = _root_.TensorProduct.comm R A B := rfl
variable {A B} in
@[simp]
theorem comm_tmul (a : A) (b : B) :
TensorProduct.comm R A B (a ⊗ₜ b) = b ⊗ₜ a :=
rfl
variable {A B} in
@[simp]
theorem comm_symm_tmul (a : A) (b : B) :
(TensorProduct.comm R A B).symm (b ⊗ₜ a) = a ⊗ₜ b :=
rfl
theorem comm_symm :
(TensorProduct.comm R A B).symm = TensorProduct.comm R B A := by
ext; rfl
@[simp]
lemma comm_comp_includeLeft :
(TensorProduct.comm R A B : A ⊗[R] B →ₐ[R] B ⊗[R] A).comp includeLeft = includeRight := rfl
@[simp]
lemma comm_comp_includeRight :
(TensorProduct.comm R A B : A ⊗[R] B →ₐ[R] B ⊗[R] A).comp includeRight = includeLeft := rfl
theorem adjoin_tmul_eq_top : adjoin R { t : A ⊗[R] B | ∃ a b, a ⊗ₜ[R] b = t } = ⊤ :=
top_le_iff.mp <| (top_le_iff.mpr <| span_tmul_eq_top R A B).trans (span_le_adjoin R _)
end
section
variable {R A}
unseal mul in
theorem assoc_aux_1 (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C) :
(TensorProduct.assoc R A B C) ((a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) ⊗ₜ[R] (c₁ * c₂)) =
(TensorProduct.assoc R A B C) (a₁ ⊗ₜ[R] b₁ ⊗ₜ[R] c₁) *
(TensorProduct.assoc R A B C) (a₂ ⊗ₜ[R] b₂ ⊗ₜ[R] c₂) :=
rfl
theorem assoc_aux_2 : (TensorProduct.assoc R A B C) (1 ⊗ₜ[R] 1 ⊗ₜ[R] 1) = 1 :=
rfl
variable (R A C D)
-- Porting note: much nicer than Lean 3 proof
/-- The associator for tensor product of R-algebras, as an algebra isomorphism. -/
protected def assoc : A ⊗[S] C ⊗[R] D ≃ₐ[S] A ⊗[S] (C ⊗[R] D) :=
AlgEquiv.ofLinearEquiv
(AlgebraTensorModule.assoc R S S A C D)
(by simp [Algebra.TensorProduct.one_def])
((LinearMap.map_mul_iff _).mpr <| by ext; simp)
@[simp] theorem assoc_toLinearEquiv :
(TensorProduct.assoc R S A C D).toLinearEquiv = AlgebraTensorModule.assoc R S S A C D := rfl
variable {A C D}
@[simp]
theorem assoc_tmul (a : A) (b : C) (c : D) :
TensorProduct.assoc R S A C D ((a ⊗ₜ b) ⊗ₜ c) = a ⊗ₜ (b ⊗ₜ c) := rfl
@[simp]
theorem assoc_symm_tmul (a : A) (b : C) (c : D) :
(TensorProduct.assoc R S A C D).symm (a ⊗ₜ (b ⊗ₜ c)) = (a ⊗ₜ b) ⊗ₜ c := rfl
end
section
variable (T A B : Type*) [CommSemiring T] [CommSemiring A] [CommSemiring B]
[Algebra R T] [Algebra R A] [Algebra R B] [Algebra T A] [IsScalarTower R T A] [Algebra S A]
[IsScalarTower R S A] [Algebra S T] [IsScalarTower S T A]
/-- The natural isomorphism `A ⊗[S] (S ⊗[R] B) ≃ₐ[T] A ⊗[R] B`. -/
def cancelBaseChange : A ⊗[S] (S ⊗[R] B) ≃ₐ[T] A ⊗[R] B :=
AlgEquiv.symm <| AlgEquiv.ofLinearEquiv
(TensorProduct.AlgebraTensorModule.cancelBaseChange R S T A B).symm
(by simp [Algebra.TensorProduct.one_def]) <|
LinearMap.map_mul_of_map_mul_tmul (fun _ _ _ _ ↦ by simp)
@[simp]
lemma cancelBaseChange_tmul (a : A) (s : S) (b : B) :
Algebra.TensorProduct.cancelBaseChange R S T A B (a ⊗ₜ (s ⊗ₜ b)) = (s • a) ⊗ₜ b :=
TensorProduct.AlgebraTensorModule.cancelBaseChange_tmul R S T a b s
@[simp]
lemma cancelBaseChange_symm_tmul (a : A) (b : B) :
(Algebra.TensorProduct.cancelBaseChange R S T A B).symm (a ⊗ₜ b) = a ⊗ₜ (1 ⊗ₜ b) :=
TensorProduct.AlgebraTensorModule.cancelBaseChange_symm_tmul R S T a b
end
variable {R S A}
/-- The tensor product of a pair of algebra morphisms. -/
def map (f : A →ₐ[S] C) (g : B →ₐ[R] D) : A ⊗[R] B →ₐ[S] C ⊗[R] D :=
algHomOfLinearMapTensorProduct (AlgebraTensorModule.map f.toLinearMap g.toLinearMap) (by simp)
(by simp [one_def])
@[simp]
theorem map_tmul (f : A →ₐ[S] C) (g : B →ₐ[R] D) (a : A) (b : B) : map f g (a ⊗ₜ b) = f a ⊗ₜ g b :=
rfl
@[simp]
theorem map_id : map (.id S A) (.id R B) = .id S _ :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
theorem map_comp
(f₂ : C →ₐ[S] E) (f₁ : A →ₐ[S] C) (g₂ : D →ₐ[R] F) (g₁ : B →ₐ[R] D) :
map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
lemma map_id_comp (g₂ : D →ₐ[R] F) (g₁ : B →ₐ[R] D) :
map (AlgHom.id S A) (g₂.comp g₁) = (map (AlgHom.id S A) g₂).comp (map (AlgHom.id S A) g₁) :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
lemma map_comp_id
(f₂ : C →ₐ[S] E) (f₁ : A →ₐ[S] C) :
map (f₂.comp f₁) (AlgHom.id R E) = (map f₂ (AlgHom.id R E)).comp (map f₁ (AlgHom.id R E)) :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
@[simp]
theorem map_comp_includeLeft (f : A →ₐ[S] C) (g : B →ₐ[R] D) :
(map f g).comp includeLeft = includeLeft.comp f :=
AlgHom.ext <| by simp
@[simp]
theorem map_restrictScalars_comp_includeRight (f : A →ₐ[S] C) (g : B →ₐ[R] D) :
((map f g).restrictScalars R).comp includeRight = includeRight.comp g :=
AlgHom.ext <| by simp
@[simp]
theorem map_comp_includeRight (f : A →ₐ[R] C) (g : B →ₐ[R] D) :
(map f g).comp includeRight = includeRight.comp g :=
map_restrictScalars_comp_includeRight f g
theorem map_range (f : A →ₐ[R] C) (g : B →ₐ[R] D) :
(map f g).range = (includeLeft.comp f).range ⊔ (includeRight.comp g).range := by
apply le_antisymm
· rw [← map_top, ← adjoin_tmul_eq_top, ← adjoin_image, adjoin_le_iff]
rintro _ ⟨_, ⟨a, b, rfl⟩, rfl⟩
rw [map_tmul, ← mul_one (f a), ← one_mul (g b), ← tmul_mul_tmul]
exact mul_mem_sup (AlgHom.mem_range_self _ a) (AlgHom.mem_range_self _ b)
· rw [← map_comp_includeLeft f g, ← map_comp_includeRight f g]
exact sup_le (AlgHom.range_comp_le_range _ _) (AlgHom.range_comp_le_range _ _)
lemma comm_comp_map (f : A →ₐ[R] C) (g : B →ₐ[R] D) :
(TensorProduct.comm R C D : C ⊗[R] D →ₐ[R] D ⊗[R] C).comp (Algebra.TensorProduct.map f g) =
(Algebra.TensorProduct.map g f).comp (TensorProduct.comm R A B).toAlgHom := by
ext <;> rfl
lemma comm_comp_map_apply (f : A →ₐ[R] C) (g : B →ₐ[R] D) (x) :
TensorProduct.comm R C D (Algebra.TensorProduct.map f g x) =
(Algebra.TensorProduct.map g f) (TensorProduct.comm R A B x) :=
congr($(comm_comp_map f g) x)
/-- Construct an isomorphism between tensor products of an S-algebra with an R-algebra
from S- and R- isomorphisms between the tensor factors.
-/
def congr (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) : A ⊗[R] B ≃ₐ[S] C ⊗[R] D :=
AlgEquiv.ofAlgHom (map f g) (map f.symm g.symm)
(ext' fun b d => by simp) (ext' fun a c => by simp)
@[simp] theorem congr_toLinearEquiv (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) :
(Algebra.TensorProduct.congr f g).toLinearEquiv =
TensorProduct.AlgebraTensorModule.congr f.toLinearEquiv g.toLinearEquiv := rfl
@[simp]
theorem congr_apply (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) (x) :
congr f g x = (map (f : A →ₐ[S] C) (g : B →ₐ[R] D)) x :=
rfl
@[simp]
theorem congr_symm_apply (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) (x) :
(congr f g).symm x = (map (f.symm : C →ₐ[S] A) (g.symm : D →ₐ[R] B)) x :=
rfl
@[simp]
theorem congr_refl : congr (.refl : A ≃ₐ[S] A) (.refl : B ≃ₐ[R] B) = .refl :=
AlgEquiv.coe_algHom_injective <| map_id
theorem congr_trans
(f₁ : A ≃ₐ[S] C) (f₂ : C ≃ₐ[S] E) (g₁ : B ≃ₐ[R] D) (g₂ : D ≃ₐ[R] F) :
congr (f₁.trans f₂) (g₁.trans g₂) = (congr f₁ g₁).trans (congr f₂ g₂) :=
AlgEquiv.coe_algHom_injective <| map_comp f₂.toAlgHom f₁.toAlgHom g₂.toAlgHom g₁.toAlgHom
theorem congr_symm (f : A ≃ₐ[S] C) (g : B ≃ₐ[R] D) : congr f.symm g.symm = (congr f g).symm := rfl
variable (R A B C) in
/-- Tensor product of algebras analogue of `mul_left_comm`.
This is the algebra version of `TensorProduct.leftComm`. -/
def leftComm : A ⊗[R] (B ⊗[R] C) ≃ₐ[R] B ⊗[R] (A ⊗[R] C) :=
(Algebra.TensorProduct.assoc R R A B C).symm.trans <|
(congr (Algebra.TensorProduct.comm R A B) .refl).trans <| TensorProduct.assoc R R B A C
@[simp]
theorem leftComm_tmul (m : A) (n : B) (p : C) :
leftComm R A B C (m ⊗ₜ (n ⊗ₜ p)) = n ⊗ₜ (m ⊗ₜ p) :=
rfl
@[simp]
theorem leftComm_symm_tmul (m : A) (n : B) (p : C) :
(leftComm R A B C).symm (n ⊗ₜ (m ⊗ₜ p)) = m ⊗ₜ (n ⊗ₜ p) :=
rfl
@[simp]
theorem leftComm_toLinearEquiv : ↑(leftComm R A B C) = _root_.TensorProduct.leftComm R A B C :=
LinearEquiv.toLinearMap_injective (by ext; rfl)
variable [CommSemiring T] [Algebra R T] [Algebra T A] [IsScalarTower R T A] [SMulCommClass S T A]
[Algebra S T] [IsScalarTower S T A] [CommSemiring R'] [Algebra R R'] [Algebra R' T] [Algebra R' A]
[Algebra R' B] [IsScalarTower R R' A] [SMulCommClass S R' A] [SMulCommClass R' S A]
[IsScalarTower R' T A] [IsScalarTower R R' B]
variable (R R' S T A B C D) in
/-- Tensor product of algebras analogue of `mul_mul_mul_comm`.
This is the algebra version of `TensorProduct.AlgebraTensorModule.tensorTensorTensorComm`. -/
def tensorTensorTensorComm : A ⊗[R'] B ⊗[S] (C ⊗[R] D) ≃ₐ[T] A ⊗[S] C ⊗[R'] (B ⊗[R] D) :=
AlgEquiv.ofLinearEquiv (TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R' S T A B C D)
rfl (LinearMap.map_mul_iff _ |>.mpr <| by ext; simp)
@[simp]
theorem tensorTensorTensorComm_tmul (m : A) (n : B) (p : C) (q : D) :
tensorTensorTensorComm R R' S T A B C D (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) :=
rfl
@[simp]
theorem tensorTensorTensorComm_symm_tmul (m : A) (n : C) (p : B) (q : D) :
(tensorTensorTensorComm R R' S T A B C D).symm (m ⊗ₜ n ⊗ₜ (p ⊗ₜ q)) = m ⊗ₜ p ⊗ₜ (n ⊗ₜ q) :=
rfl
theorem tensorTensorTensorComm_symm :
(tensorTensorTensorComm R R' S T A B C D).symm = tensorTensorTensorComm R S R' T A C B D := by
ext; rfl
theorem tensorTensorTensorComm_toLinearEquiv :
(tensorTensorTensorComm R R' S T A B C D).toLinearEquiv =
TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R' S T A B C D := rfl
@[simp]
theorem toLinearEquiv_tensorTensorTensorComm :
(tensorTensorTensorComm R R R R A B C D).toLinearEquiv =
_root_.TensorProduct.tensorTensorTensorComm R A B C D := by
apply LinearEquiv.toLinearMap_injective
ext; simp
end
end Monoidal
section
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B]
variable [CommSemiring C] [Algebra R C] [Algebra S C] [IsScalarTower R S C]
/-- If `A`, `B`, `C` are `R`-algebras, `A` and `C` are also `S`-algebras (forming a tower as
`·/S/R`), then the product map of `f : A →ₐ[S] C` and `g : B →ₐ[R] C` is an `S`-algebra
homomorphism.
This is just a special case of `Algebra.TensorProduct.lift` for when `C` is commutative. -/
abbrev productLeftAlgHom (f : A →ₐ[S] C) (g : B →ₐ[R] C) : A ⊗[R] B →ₐ[S] C :=
lift f g (fun _ _ => Commute.all _ _)
lemma tmul_one_eq_one_tmul (r : R) : algebraMap R A r ⊗ₜ[R] 1 = 1 ⊗ₜ algebraMap R B r := by
rw [Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul]
end
variable (R A B) in
lemma closure_range_union_range_eq_top [CommRing R] [Ring A] [Ring B]
[Algebra R A] [Algebra R B] :
Subring.closure (Set.range (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] B) ∪
Set.range Algebra.TensorProduct.includeRight) = ⊤ := by
rw [← top_le_iff]
rintro x -
induction x with
| zero => exact zero_mem _
| tmul x y =>
convert_to (Algebra.TensorProduct.includeLeftRingHom (R := R) x) *
(Algebra.TensorProduct.includeRight y) ∈ _
· simp
· exact mul_mem (Subring.subset_closure (.inl ⟨x, rfl⟩))
(Subring.subset_closure (.inr ⟨_, rfl⟩))
| add x y _ _ => exact add_mem ‹_› ‹_›
section
variable [CommSemiring R] [Semiring A] [Semiring B] [CommSemiring S]
variable [Algebra R A] [Algebra R B] [Algebra R S]
variable (f : A →ₐ[R] S) (g : B →ₐ[R] S)
variable (R)
/-- `LinearMap.mul'` as an `AlgHom` over the algebra. -/
def lmul'' : S ⊗[R] S →ₐ[S] S :=
algHomOfLinearMapTensorProduct
{ __ := LinearMap.mul' R S
map_smul' := fun s x ↦ x.induction_on (by simp)
(fun _ _ ↦ by simp [TensorProduct.smul_tmul', mul_assoc])
fun x y hx hy ↦ by simp_all [mul_add] }
(fun a₁ a₂ b₁ b₂ => by simp [mul_mul_mul_comm]) <| by simp
theorem lmul''_eq_lid_comp_mapOfCompatibleSMul :
lmul'' R = (TensorProduct.lid S S).toAlgHom.comp (mapOfCompatibleSMul' _ _ _ _) := by
ext; rfl
/-- `LinearMap.mul'` as an `AlgHom` over the base ring. -/
def lmul' : S ⊗[R] S →ₐ[R] S := (lmul'' R).restrictScalars R
variable {R}
theorem lmul'_toLinearMap : (lmul' R : _ →ₐ[R] S).toLinearMap = LinearMap.mul' R S :=
rfl
@[simp]
theorem lmul'_apply_tmul (a b : S) : lmul' (S := S) R (a ⊗ₜ[R] b) = a * b :=
rfl
@[simp]
theorem lmul'_comp_includeLeft : (lmul' R : _ →ₐ[R] S).comp includeLeft = AlgHom.id R S :=
AlgHom.ext <| mul_one
@[simp]
theorem lmul'_comp_includeRight : (lmul' R : _ →ₐ[R] S).comp includeRight = AlgHom.id R S :=
AlgHom.ext <| one_mul
variable (R S) in
/-- If multiplication by elements of S can switch between the two factors of `S ⊗[R] S`,
then `lmul''` is an isomorphism. -/
def lmulEquiv [CompatibleSMul R S S S] : S ⊗[R] S ≃ₐ[S] S :=
.ofAlgHom (lmul'' R) includeLeft lmul'_comp_includeLeft <| AlgHom.ext fun x ↦ x.induction_on
(by simp) (fun x y ↦ show (x * y) ⊗ₜ[R] 1 = x ⊗ₜ[R] y by
rw [mul_comm, ← smul_eq_mul, smul_tmul, smul_eq_mul, mul_one])
fun _ _ hx hy ↦ by simp_all [add_tmul]
theorem lmulEquiv_eq_lidOfCompatibleSMul [CompatibleSMul R S S S] :
lmulEquiv R S = lidOfCompatibleSMul R S S :=
AlgEquiv.coe_algHom_injective <| by ext; rfl
/-- If `S` is commutative, for a pair of morphisms `f : A →ₐ[R] S`, `g : B →ₐ[R] S`,
We obtain a map `A ⊗[R] B →ₐ[R] S` that commutes with `f`, `g` via `a ⊗ b ↦ f(a) * g(b)`.
This is a special case of `Algebra.TensorProduct.productLeftAlgHom` for when the two base rings are
the same.
-/
def productMap : A ⊗[R] B →ₐ[R] S := productLeftAlgHom f g
theorem productMap_eq_comp_map : productMap f g = (lmul' R).comp (TensorProduct.map f g) := by
ext <;> rfl
@[simp]
theorem productMap_apply_tmul (a : A) (b : B) : productMap f g (a ⊗ₜ b) = f a * g b := rfl
theorem productMap_left_apply (a : A) : productMap f g (a ⊗ₜ 1) = f a := by
simp
@[simp]
theorem productMap_left : (productMap f g).comp includeLeft = f :=
lift_comp_includeLeft _ _ (fun _ _ => Commute.all _ _)
theorem productMap_right_apply (b : B) :
productMap f g (1 ⊗ₜ b) = g b := by simp
@[simp]
theorem productMap_right : (productMap f g).comp includeRight = g :=
lift_comp_includeRight _ _ (fun _ _ => Commute.all _ _)
theorem productMap_range : (productMap f g).range = f.range ⊔ g.range := by
rw [productMap_eq_comp_map, AlgHom.range_comp, map_range, map_sup, ← AlgHom.range_comp,
← AlgHom.range_comp,
← AlgHom.comp_assoc, ← AlgHom.comp_assoc, lmul'_comp_includeLeft, lmul'_comp_includeRight,
AlgHom.id_comp, AlgHom.id_comp]
end
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
/-- If `M` is a `B`-module that is also an `A`-module, the canonical map
`M →ₗ[A] B ⊗[A] M` is injective. -/
lemma mk_one_injective_of_isScalarTower (M : Type*) [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] :
Function.Injective (TensorProduct.mk R S M 1) := by
apply Function.RightInverse.injective (g := LinearMap.liftBaseChange S LinearMap.id)
intro m
simp
end TensorProduct
end Algebra
lemma Algebra.baseChange_lmul {R B : Type*} [CommSemiring R] [Semiring B] [Algebra R B]
{A : Type*} [CommSemiring A] [Algebra R A] (f : B) :
(Algebra.lmul R B f).baseChange A = Algebra.lmul A (A ⊗[R] B) (1 ⊗ₜ f) := by
ext i
simp
namespace LinearMap
variable (R A M N : Type*) [CommSemiring R] [CommSemiring A] [Algebra R A]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
open Module
open scoped TensorProduct
/-- The natural linear map $A ⊗ \text{Hom}_R(M, N) → \text{Hom}_A (M_A, N_A)$,
where $M_A$ and $N_A$ are the respective modules over $A$ obtained by extension of scalars.
See `LinearMap.tensorProductEnd` for this map specialized to endomorphisms,
and bundled as `A`-algebra homomorphism. -/
@[simps!]
def tensorProduct : A ⊗[R] (M →ₗ[R] N) →ₗ[A] (A ⊗[R] M) →ₗ[A] (A ⊗[R] N) :=
TensorProduct.AlgebraTensorModule.lift <|
{ toFun := fun a ↦ a • baseChangeHom R A M N
map_add' := by simp only [add_smul, forall_true_iff]
map_smul' := by simp only [smul_assoc, RingHom.id_apply, forall_true_iff] }
/-- The natural `A`-algebra homomorphism $A ⊗ (\text{End}_R M) → \text{End}_A (A ⊗ M)$,
where `M` is an `R`-module, and `A` an `R`-algebra. -/
@[simps!]
def tensorProductEnd : A ⊗[R] (End R M) →ₐ[A] End A (A ⊗[R] M) :=
Algebra.TensorProduct.algHomOfLinearMapTensorProduct
(LinearMap.tensorProduct R A M M)
(fun a b f g ↦ by
apply LinearMap.ext
intro x
simp only [tensorProduct, mul_comm a b, Module.End.mul_eq_comp,
TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul, coe_restrictScalars,
coe_mk, AddHom.coe_mk, mul_smul, smul_apply, baseChangeHom_apply, baseChange_comp,
comp_apply, Algebra.mul_smul_comm, Algebra.smul_mul_assoc])
(by
apply LinearMap.ext
intro x
simp only [tensorProduct, TensorProduct.AlgebraTensorModule.lift_apply,
TensorProduct.lift.tmul, coe_restrictScalars, coe_mk, AddHom.coe_mk, one_smul,
baseChangeHom_apply, baseChange_eq_ltensor, Module.End.one_eq_id,
lTensor_id, LinearMap.id_apply])
end LinearMap
namespace Module
variable {R S A M N : Type*} [CommSemiring R] [CommSemiring S] [Semiring A]
variable [AddCommMonoid M] [AddCommMonoid N]
variable [Algebra R S] [Algebra S A] [Algebra R A]
variable [Module R M] [Module S M] [Module A M] [Module R N]
variable [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S M]
/-- The algebra homomorphism from `End M ⊗ End N` to `End (M ⊗ N)` sending `f ⊗ₜ g` to
the `TensorProduct.map f g`, the tensor product of the two maps.
This is an `AlgHom` version of `TensorProduct.AlgebraTensorModule.homTensorHomMap`. Like that
definition, this is generalized across many different rings; namely a tower of algebras `A/S/R`. -/
def endTensorEndAlgHom : End A M ⊗[R] End R N →ₐ[S] End A (M ⊗[R] N) :=
Algebra.TensorProduct.algHomOfLinearMapTensorProduct
(AlgebraTensorModule.homTensorHomMap R A S M N M N)
(fun _f₁ _f₂ _g₁ _g₂ => AlgebraTensorModule.ext fun _m _n => rfl)
(AlgebraTensorModule.ext fun _m _n => rfl)
theorem endTensorEndAlgHom_apply (f : End A M) (g : End R N) :
endTensorEndAlgHom (R := R) (S := S) (A := A) (M := M) (N := N) (f ⊗ₜ[R] g)
= AlgebraTensorModule.map f g :=
rfl
end Module
namespace TensorProduct.Algebra
variable {R A B M : Type*}
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable [Semiring A] [Semiring B] [Module A M] [Module B M]
variable [Algebra R A] [Algebra R B]
variable [IsScalarTower R A M] [IsScalarTower R B M]
/-- An auxiliary definition, used for constructing the `Module (A ⊗[R] B) M` in
`TensorProduct.Algebra.module` below. -/
def moduleAux : A ⊗[R] B →ₗ[R] M →ₗ[R] M :=
TensorProduct.lift
{ toFun := fun a => a • (Algebra.lsmul R R M : B →ₐ[R] Module.End R M).toLinearMap
map_add' := fun r t => by
ext
simp only [add_smul, LinearMap.add_apply]
map_smul' := fun n r => by
ext
simp only [RingHom.id_apply, LinearMap.smul_apply, smul_assoc] }
theorem moduleAux_apply (a : A) (b : B) (m : M) : moduleAux (a ⊗ₜ[R] b) m = a • b • m :=
rfl
variable [SMulCommClass A B M]
/-- If `M` is a representation of two different `R`-algebras `A` and `B` whose actions commute,
then it is a representation the `R`-algebra `A ⊗[R] B`.
An important example arises from a semiring `S`; allowing `S` to act on itself via left and right
multiplication, the roles of `R`, `A`, `B`, `M` are played by `ℕ`, `S`, `Sᵐᵒᵖ`, `S`. This example
is important because a submodule of `S` as a `Module` over `S ⊗[ℕ] Sᵐᵒᵖ` is a two-sided ideal.
NB: This is not an instance because in the case `B = A` and `M = A ⊗[R] A` we would have a diamond
of `smul` actions. Furthermore, this would not be a mere definitional diamond but a true
mathematical diamond in which `A ⊗[R] A` had two distinct scalar actions on itself: one from its
multiplication, and one from this would-be instance. Arguably we could live with this but in any
case the real fix is to address the ambiguity in notation, probably along the lines outlined here:
https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.234773.20base.20change/near/240929258
-/
protected def module : Module (A ⊗[R] B) M where
smul x m := moduleAux x m
zero_smul m := by simp only [(· • ·), map_zero, LinearMap.zero_apply]
smul_zero x := by simp only [(· • ·), map_zero]
smul_add x m₁ m₂ := by simp only [(· • ·), map_add]
add_smul x y m := by simp only [(· • ·), map_add, LinearMap.add_apply]
one_smul m := by
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.one_def]
simp only [moduleAux_apply, one_smul]
mul_smul x y m := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> refine TensorProduct.induction_on y ?_ ?_ ?_
· simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro z w _ _
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a₁ b₁ a₂ b₂
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.tmul_mul_tmul]
simp only [moduleAux_apply, mul_smul, smul_comm a₁ b₂]
· intro z w hz hw a b
-- Porting note: was one `simp only`, but random stuff doesn't work
simp only [(· • ·)] at hz hw ⊢
simp only [moduleAux_apply, mul_add, LinearMap.map_add,
LinearMap.add_apply, moduleAux_apply, hz, hw]
· intro z w _ _
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [LinearMap.map_add, add_mul, LinearMap.add_apply, hz, hw]
· intro u v _ _ z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [add_mul, LinearMap.map_add, LinearMap.add_apply, hz, hw, add_add_add_comm]
attribute [local instance] TensorProduct.Algebra.module
theorem smul_def (a : A) (b : B) (m : M) : a ⊗ₜ[R] b • m = a • b • m :=
rfl
section Lemmas
theorem linearMap_comp_mul' :
Algebra.linearMap R (A ⊗[R] B) ∘ₗ LinearMap.mul' R R =
map (Algebra.linearMap R A) (Algebra.linearMap R B) := by
ext
simp only [AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars, map_tmul,
Algebra.linearMap_apply, map_one, LinearMap.coe_comp, Function.comp_apply,
LinearMap.mul'_apply, mul_one, Algebra.TensorProduct.one_def]
@[simp]
theorem mul'_comp_tensorTensorTensorComm :
LinearMap.mul' R (A ⊗[R] B) ∘ₗ tensorTensorTensorComm R A A B B =
map (LinearMap.mul' R A) (LinearMap.mul' R B) := by
ext
simp
end Lemmas
end TensorProduct.Algebra
open LinearMap in
lemma Submodule.map_range_rTensor_subtype_lid {R Q} [CommSemiring R] [AddCommMonoid Q]
[Module R Q] {I : Submodule R R} :
(range <| rTensor Q I.subtype).map (TensorProduct.lid R Q) = I • ⊤ := by
rw [← map_top, ← map_coe_toLinearMap, ← Submodule.map_comp, map_top]
refine le_antisymm ?_ fun q h ↦ Submodule.smul_induction_on h
(fun r hr q _ ↦ ⟨⟨r, hr⟩ ⊗ₜ q, by simp⟩) (by simp +contextual [add_mem])
rintro _ ⟨t, rfl⟩
exact t.induction_on (by simp) (by simp +contextual [Submodule.smul_mem_smul])
(by simp +contextual [add_mem])
section
variable {R M S T : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
[Semiring S] [Algebra R S] [Ring T] [Algebra R T]
variable (R S M) in
theorem TensorProduct.mk_surjective (h : Function.Surjective (algebraMap R S)) :
Function.Surjective (TensorProduct.mk R S M 1) := by
rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le]
rintro _ ⟨x, y, rfl⟩
obtain ⟨x, rfl⟩ := h x
rw [Algebra.algebraMap_eq_smul_one, smul_tmul]
exact ⟨x • y, rfl⟩
variable (S) in
lemma TensorProduct.flip_mk_surjective (h : Function.Surjective (algebraMap R T)) :
Function.Surjective ((TensorProduct.mk R S T).flip 1) := by
rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le]
rintro _ ⟨s, t, rfl⟩
obtain ⟨r, rfl⟩ := h t
rw [Algebra.algebraMap_eq_smul_one, ← smul_tmul]
exact ⟨r • s, rfl⟩
variable (T) in
lemma Algebra.TensorProduct.includeRight_surjective (h : Function.Surjective (algebraMap R S)) :
Function.Surjective (includeRight : T →ₐ[R] S ⊗[R] T) :=
TensorProduct.mk_surjective _ _ _ h
lemma Algebra.TensorProduct.includeLeft_surjective
(S A : Type*) [CommSemiring S] [Semiring A] [Algebra S A] [Algebra R A]
[SMulCommClass R S A] (h : Function.Surjective (algebraMap R T)) :
Function.Surjective (includeLeft : A →ₐ[S] A ⊗[R] T) :=
TensorProduct.flip_mk_surjective _ h
end
variable {R A B : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A]
[NonUnitalNonAssocSemiring B] [Module R A] [Module R B] [SMulCommClass R A A]
[SMulCommClass R B B] [IsScalarTower R A A] [IsScalarTower R B B]
lemma LinearMap.mulLeft_tmul (a : A) (b : B) :
mulLeft R (a ⊗ₜ[R] b) = map (mulLeft R a) (mulLeft R b) := by
ext; simp
lemma LinearMap.mulRight_tmul (a : A) (b : B) :
mulRight R (a ⊗ₜ[R] b) = map (mulRight R a) (mulRight R b) := by
ext; simp
|
ContinuousAffineEquiv.lean
|
/-
Copyright (c) 2024 Michael Rothgang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Rothgang
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
import Mathlib.Topology.Algebra.Module.Equiv
import Mathlib.Topology.Algebra.ContinuousAffineMap
/-!
# Continuous affine equivalences
In this file, we define continuous affine equivalences, affine equivalences
which are continuous with continuous inverse.
## Main definitions
* `ContinuousAffineEquiv.refl k P`: the identity map as a `ContinuousAffineEquiv`;
* `e.symm`: the inverse map of a `ContinuousAffineEquiv` as a `ContinuousAffineEquiv`;
* `e.trans e'`: composition of two `ContinuousAffineEquiv`s; note that the order
follows `mathlib`'s `CategoryTheory` convention (apply `e`, then `e'`),
not the convention used in function composition and compositions of bundled morphisms.
* `e.toHomeomorph`: the continuous affine equivalence `e` as a homeomorphism
* `e.toContinuousAffineMap`: the continuous affine equivalence `e` as a continuous affine map
* `ContinuousLinearEquiv.toContinuousAffineEquiv`: a continuous linear equivalence as a continuous
affine equivalence
* `ContinuousAffineEquiv.constVAdd`: `AffineEquiv.constVAdd` as a continuous affine equivalence
## TODO
- equip `ContinuousAffineEquiv k P P` with a `Group` structure,
with multiplication corresponding to composition in `AffineEquiv.group`.
-/
open Function
/-- A continuous affine equivalence, denoted `P₁ ≃ᴬ[k] P₂`, between two affine topological spaces
is an affine equivalence such that forward and inverse maps are continuous. -/
structure ContinuousAffineEquiv (k P₁ P₂ : Type*) {V₁ V₂ : Type*} [Ring k]
[AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁] [TopologicalSpace P₁]
[AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] [TopologicalSpace P₂]
extends P₁ ≃ᵃ[k] P₂ where
continuous_toFun : Continuous toFun := by continuity
continuous_invFun : Continuous invFun := by continuity
@[inherit_doc]
notation:25 P₁ " ≃ᴬ[" k:25 "] " P₂:0 => ContinuousAffineEquiv k P₁ P₂
variable {k P₁ P₂ P₃ P₄ V₁ V₂ V₃ V₄ : Type*} [Ring k]
[AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁] [TopologicalSpace P₁]
[AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂] [TopologicalSpace P₂]
[AddCommGroup V₃] [Module k V₃] [AddTorsor V₃ P₃] [TopologicalSpace P₃]
[AddCommGroup V₄] [Module k V₄] [AddTorsor V₄ P₄] [TopologicalSpace P₄]
namespace ContinuousAffineEquiv
-- Basic set-up: standard fields, coercions and ext lemmas
section Basic
/-- A continuous affine equivalence is a homeomorphism. -/
def toHomeomorph (e : P₁ ≃ᴬ[k] P₂) : P₁ ≃ₜ P₂ where
__ := e
theorem toAffineEquiv_injective : Injective (toAffineEquiv : (P₁ ≃ᴬ[k] P₂) → P₁ ≃ᵃ[k] P₂) := by
rintro ⟨e, econt, einv_cont⟩ ⟨e', e'cont, e'inv_cont⟩ H
congr
instance instEquivLike : EquivLike (P₁ ≃ᴬ[k] P₂) P₁ P₂ where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' _ _ h _ := toAffineEquiv_injective (DFunLike.coe_injective h)
attribute [coe] ContinuousAffineEquiv.toAffineEquiv
/-- Coerce continuous affine equivalences to affine equivalences. -/
instance coe : Coe (P₁ ≃ᴬ[k] P₂) (P₁ ≃ᵃ[k] P₂) := ⟨toAffineEquiv⟩
theorem coe_injective : Function.Injective ((↑) : (P₁ ≃ᴬ[k] P₂) → P₁ ≃ᵃ[k] P₂) := by
intro e e' H
cases e
congr
instance instFunLike : FunLike (P₁ ≃ᴬ[k] P₂) P₁ P₂ where
coe f := f.toAffineEquiv
coe_injective' _ _ h := coe_injective (DFunLike.coe_injective h)
@[simp, norm_cast]
theorem coe_coe (e : P₁ ≃ᴬ[k] P₂) : ⇑(e : P₁ ≃ᵃ[k] P₂) = e :=
rfl
@[simp]
theorem coe_toEquiv (e : P₁ ≃ᴬ[k] P₂) : ⇑e.toEquiv = e :=
rfl
/-- See Note [custom simps projection].
We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (e : P₁ ≃ᴬ[k] P₂) : P₁ → P₂ :=
e
/-- See Note [custom simps projection]. -/
def Simps.symm_apply (e : P₁ ≃ᴬ[k] P₂) : P₂ → P₁ :=
e.symm
initialize_simps_projections ContinuousAffineEquiv (toFun → apply, invFun → symm_apply)
@[ext]
theorem ext {e e' : P₁ ≃ᴬ[k] P₂} (h : ∀ x, e x = e' x) : e = e' :=
DFunLike.ext _ _ h
@[continuity]
protected theorem continuous (e : P₁ ≃ᴬ[k] P₂) : Continuous e :=
e.2
/-- A continuous affine equivalence is a continuous affine map. -/
def toContinuousAffineMap (e : P₁ ≃ᴬ[k] P₂) : P₁ →ᴬ[k] P₂ where
__ := e
cont := e.continuous_toFun
@[simp]
lemma coe_toContinuousAffineMap (e : P₁ ≃ᴬ[k] P₂) : ⇑e.toContinuousAffineMap = e :=
rfl
lemma toContinuousAffineMap_injective :
Function.Injective (toContinuousAffineMap : (P₁ ≃ᴬ[k] P₂) → (P₁ →ᴬ[k] P₂)) := by
intro e e' h
ext p
simp_rw [← coe_toContinuousAffineMap, h]
lemma toContinuousAffineMap_toAffineMap (e : P₁ ≃ᴬ[k] P₂) :
e.toContinuousAffineMap.toAffineMap = e.toAffineEquiv.toAffineMap :=
rfl
lemma toContinuousAffineMap_toContinuousMap (e : P₁ ≃ᴬ[k] P₂) :
e.toContinuousAffineMap.toContinuousMap = toContinuousMap e.toHomeomorph :=
rfl
end Basic
section ReflSymmTrans
variable (k P₁) in
/-- Identity map as a `ContinuousAffineEquiv`. -/
def refl : P₁ ≃ᴬ[k] P₁ where
toEquiv := Equiv.refl P₁
linear := LinearEquiv.refl k V₁
map_vadd' _ _ := rfl
@[simp]
theorem coe_refl : ⇑(refl k P₁) = id :=
rfl
@[simp]
theorem refl_apply (x : P₁) : refl k P₁ x = x :=
rfl
@[simp]
theorem toAffineEquiv_refl : (refl k P₁).toAffineEquiv = AffineEquiv.refl k P₁ :=
rfl
@[simp]
theorem toEquiv_refl : (refl k P₁).toEquiv = Equiv.refl P₁ :=
rfl
/-- Inverse of a continuous affine equivalence as a continuous affine equivalence. -/
@[symm]
def symm (e : P₁ ≃ᴬ[k] P₂) : P₂ ≃ᴬ[k] P₁ where
toAffineEquiv := e.toAffineEquiv.symm
continuous_toFun := e.continuous_invFun
continuous_invFun := e.continuous_toFun
@[simp]
theorem toAffineEquiv_symm (e : P₁ ≃ᴬ[k] P₂) : e.symm.toAffineEquiv = e.toAffineEquiv.symm :=
rfl
@[deprecated "use instead `toAffineEquiv_symm`, in the reverse direction" (since := "2025-06-08")]
theorem symm_toAffineEquiv (e : P₁ ≃ᴬ[k] P₂) : e.toAffineEquiv.symm = e.symm.toAffineEquiv :=
rfl
@[simp]
theorem coe_symm_toAffineEquiv (e : P₁ ≃ᴬ[k] P₂) : ⇑e.toAffineEquiv.symm = e.symm := rfl
@[simp]
theorem toEquiv_symm (e : P₁ ≃ᴬ[k] P₂) : e.symm.toEquiv = e.toEquiv.symm := rfl
@[deprecated "use instead `symm_toEquiv`, in the reverse direction" (since := "2025-06-08")]
theorem symm_toEquiv (e : P₁ ≃ᴬ[k] P₂) : e.toEquiv.symm = e.symm.toEquiv := rfl
@[simp]
theorem coe_symm_toEquiv (e : P₁ ≃ᴬ[k] P₂) : ⇑e.toEquiv.symm = e.symm := rfl
@[simp]
theorem apply_symm_apply (e : P₁ ≃ᴬ[k] P₂) (p : P₂) : e (e.symm p) = p :=
e.toEquiv.apply_symm_apply p
@[simp]
theorem symm_apply_apply (e : P₁ ≃ᴬ[k] P₂) (p : P₁) : e.symm (e p) = p :=
e.toEquiv.symm_apply_apply p
theorem apply_eq_iff_eq_symm_apply (e : P₁ ≃ᴬ[k] P₂) {p₁ p₂} : e p₁ = p₂ ↔ p₁ = e.symm p₂ :=
e.toEquiv.apply_eq_iff_eq_symm_apply
theorem apply_eq_iff_eq (e : P₁ ≃ᴬ[k] P₂) {p₁ p₂ : P₁} : e p₁ = e p₂ ↔ p₁ = p₂ :=
e.toEquiv.apply_eq_iff_eq
@[simp]
theorem symm_symm (e : P₁ ≃ᴬ[k] P₂) : e.symm.symm = e := rfl
theorem symm_bijective : Function.Bijective (symm : (P₁ ≃ᴬ[k] P₂) → _) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
theorem symm_symm_apply (e : P₁ ≃ᴬ[k] P₂) (x : P₁) : e.symm.symm x = e x :=
rfl
theorem symm_apply_eq (e : P₁ ≃ᴬ[k] P₂) {x y} : e.symm x = y ↔ x = e y :=
e.toAffineEquiv.symm_apply_eq
theorem eq_symm_apply (e : P₁ ≃ᴬ[k] P₂) {x y} : y = e.symm x ↔ e y = x :=
e.toAffineEquiv.eq_symm_apply
@[simp]
theorem image_symm (f : P₁ ≃ᴬ[k] P₂) (s : Set P₂) : f.symm '' s = f ⁻¹' s :=
f.symm.toEquiv.image_eq_preimage _
@[simp]
theorem preimage_symm (f : P₁ ≃ᴬ[k] P₂) (s : Set P₁) : f.symm ⁻¹' s = f '' s :=
(f.symm.image_symm _).symm
protected theorem bijective (e : P₁ ≃ᴬ[k] P₂) : Bijective e :=
e.toEquiv.bijective
protected theorem surjective (e : P₁ ≃ᴬ[k] P₂) : Surjective e :=
e.toEquiv.surjective
protected theorem injective (e : P₁ ≃ᴬ[k] P₂) : Injective e :=
e.toEquiv.injective
protected theorem image_eq_preimage (e : P₁ ≃ᴬ[k] P₂) (s : Set P₁) : e '' s = e.symm ⁻¹' s :=
e.toEquiv.image_eq_preimage s
protected theorem image_symm_eq_preimage (e : P₁ ≃ᴬ[k] P₂) (s : Set P₂) :
e.symm '' s = e ⁻¹' s := by
rw [e.symm.image_eq_preimage, e.symm_symm]
@[simp]
theorem image_preimage (e : P₁ ≃ᴬ[k] P₂) (s : Set P₂) : e '' (e ⁻¹' s) = s :=
e.surjective.image_preimage s
@[simp]
theorem preimage_image (e : P₁ ≃ᴬ[k] P₂) (s : Set P₁) : e ⁻¹' (e '' s) = s :=
e.injective.preimage_image s
theorem symm_image_image (e : P₁ ≃ᴬ[k] P₂) (s : Set P₁) : e.symm '' (e '' s) = s :=
e.toEquiv.symm_image_image s
theorem image_symm_image (e : P₁ ≃ᴬ[k] P₂) (s : Set P₂) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
@[simp]
theorem refl_symm : (refl k P₁).symm = refl k P₁ :=
rfl
@[simp]
theorem symm_refl : (refl k P₁).symm = refl k P₁ :=
rfl
/-- Composition of two `ContinuousAffineEquiv`alences, applied left to right. -/
@[trans]
def trans (e : P₁ ≃ᴬ[k] P₂) (e' : P₂ ≃ᴬ[k] P₃) : P₁ ≃ᴬ[k] P₃ where
toAffineEquiv := e.toAffineEquiv.trans e'.toAffineEquiv
continuous_toFun := e'.continuous_toFun.comp (e.continuous_toFun)
continuous_invFun := e.continuous_invFun.comp (e'.continuous_invFun)
@[simp]
theorem coe_trans (e : P₁ ≃ᴬ[k] P₂) (e' : P₂ ≃ᴬ[k] P₃) : ⇑(e.trans e') = e' ∘ e :=
rfl
@[simp]
theorem trans_apply (e : P₁ ≃ᴬ[k] P₂) (e' : P₂ ≃ᴬ[k] P₃) (p : P₁) : e.trans e' p = e' (e p) :=
rfl
theorem trans_assoc (e₁ : P₁ ≃ᴬ[k] P₂) (e₂ : P₂ ≃ᴬ[k] P₃) (e₃ : P₃ ≃ᴬ[k] P₄) :
(e₁.trans e₂).trans e₃ = e₁.trans (e₂.trans e₃) :=
ext fun _ ↦ rfl
@[simp]
theorem trans_refl (e : P₁ ≃ᴬ[k] P₂) : e.trans (refl k P₂) = e :=
ext fun _ ↦ rfl
@[simp]
theorem refl_trans (e : P₁ ≃ᴬ[k] P₂) : (refl k P₁).trans e = e :=
ext fun _ ↦ rfl
@[simp]
theorem self_trans_symm (e : P₁ ≃ᴬ[k] P₂) : e.trans e.symm = refl k P₁ :=
ext e.symm_apply_apply
@[simp]
theorem symm_trans_self (e : P₁ ≃ᴬ[k] P₂) : e.symm.trans e = refl k P₂ :=
ext e.apply_symm_apply
lemma trans_toContinuousAffineMap (e : P₁ ≃ᴬ[k] P₂) (e' : P₂ ≃ᴬ[k] P₃) :
(e.trans e').toContinuousAffineMap = e'.toContinuousAffineMap.comp e.toContinuousAffineMap :=
rfl
end ReflSymmTrans
section
variable {E F : Type*} [AddCommGroup E] [Module k E] [TopologicalSpace E]
[AddCommGroup F] [Module k F] [TopologicalSpace F]
/-- Reinterpret a continuous linear equivalence between modules
as a continuous affine equivalence. -/
def _root_.ContinuousLinearEquiv.toContinuousAffineEquiv (L : E ≃L[k] F) : E ≃ᴬ[k] F where
toAffineEquiv := L.toAffineEquiv
continuous_toFun := L.continuous_toFun
continuous_invFun := L.continuous_invFun
@[simp]
theorem _root_.ContinuousLinearEquiv.coe_toContinuousAffineEquiv (e : E ≃L[k] F) :
⇑e.toContinuousAffineEquiv = e :=
rfl
lemma _root_.ContinuousLinearEquiv.toContinuousAffineEquiv_toContinuousAffineMap (L : E ≃L[k] F) :
L.toContinuousAffineEquiv.toContinuousAffineMap =
L.toContinuousLinearMap.toContinuousAffineMap :=
rfl
variable (k P₁) in
/-- The map `p ↦ v +ᵥ p` as a continuous affine automorphism of an affine space
on which addition is continuous. -/
def constVAdd [ContinuousConstVAdd V₁ P₁] (v : V₁) : P₁ ≃ᴬ[k] P₁ where
toAffineEquiv := AffineEquiv.constVAdd k P₁ v
continuous_toFun := continuous_const_vadd v
continuous_invFun := continuous_const_vadd (-v)
lemma constVAdd_coe [ContinuousConstVAdd V₁ P₁] (v : V₁) :
(constVAdd k P₁ v).toAffineEquiv = .constVAdd k P₁ v := rfl
end
end ContinuousAffineEquiv
|
Ext.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Data.DFinsupp.Defs
/-!
# Extensionality principles for `DFinsupp`
## Main results
* `DFinsupp.addHom_ext`, `DFinsupp.addHom_ext'`: if two additive homomorphisms from `Π₀ i, β i`
are equal on each `single a b`, then they are equal.
-/
universe u u₁ u₂ v v₁ v₂ v₃ w x y l
variable {ι : Type u} {γ : Type w} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
namespace DFinsupp
section DecidableEq
variable [DecidableEq ι]
section AddMonoid
variable [∀ i, AddZeroClass (β i)]
@[simp]
theorem add_closure_iUnion_range_single :
AddSubmonoid.closure (⋃ i : ι, Set.range (single i : β i → Π₀ i, β i)) = ⊤ :=
top_unique fun x _ => by
apply DFinsupp.induction x
· exact AddSubmonoid.zero_mem _
exact fun a b f _ _ hf =>
AddSubmonoid.add_mem _
(AddSubmonoid.subset_closure <| Set.mem_iUnion.2 ⟨a, Set.mem_range_self _⟩) hf
/-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then
they are equal. -/
theorem addHom_ext {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄
(H : ∀ (i : ι) (y : β i), f (single i y) = g (single i y)) : f = g := by
refine AddMonoidHom.eq_of_eqOn_denseM add_closure_iUnion_range_single fun f hf => ?_
simp only [Set.mem_iUnion, Set.mem_range] at hf
rcases hf with ⟨x, y, rfl⟩
apply H
/-- If two additive homomorphisms from `Π₀ i, β i` are equal on each `single a b`, then
they are equal.
See note [partially-applied ext lemmas]. -/
@[ext]
theorem addHom_ext' {γ : Type w} [AddZeroClass γ] ⦃f g : (Π₀ i, β i) →+ γ⦄
(H : ∀ x, f.comp (singleAddHom β x) = g.comp (singleAddHom β x)) : f = g :=
addHom_ext fun x => DFunLike.congr_fun (H x)
end AddMonoid
end DecidableEq
end DFinsupp
|
output.v
|
From mathcomp Require Import
all_boot
all_order
all_algebra
all_field
all_character
all_fingroup
all_solvable.
Open Scope group_scope.
Check @cyclic_pgroup_Aut_structure.
|
Roots.lean
|
/-
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, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.algebraMap_self, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_ge <| hp.symm ▸ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots =
{a⁻¹ * b} := by
rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (a⁻¹ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots =
{-(a⁻¹ * b)} := by
rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ←
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by
rcases m with ⟨L⟩
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with ⟨m, hm⟩
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) :
Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by
rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· rw [Multiset.mem_map]
rintro ⟨a, -, h⟩
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : ℕ) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [pow_zero, nthRoots, ← C_1, ← C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [nthRoots, roots, h, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, ← C_1, ← RingHom.map_sub]
exact degree_C_le))
else by
rw [← Nat.cast_le (α := WithBot ℕ)]
rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_notMem, mem_nthRoots (by simp : 0 < 2),
← not_exists, eq_comm]
/-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) (a : R) {x : R} :
x ∈ nthRootsFinset n a ↔ x ^ (n : ℕ) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = ∅ := by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) :
f x ∈ nthRootsFinset n (f a) := by
by_cases hn : n = 0
· simp [hn] at hx
· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) :
f x ∈ nthRootsFinset n 1 := by
rw [← (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{η₁ η₂ : R} {a₁ a₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hη₂ : η₂ ∈ nthRootsFinset n a₂) :
η₁ * η₂ ∈ nthRootsFinset n (a₁ * a₂) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, notMem_empty] at hη₁
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢
rw [mul_pow, hη₁, hη₂]
theorem ne_zero_of_mem_nthRootsFinset {η : R} {a : R} (ha : a ≠ 0) (hη : η ∈ nthRootsFinset n a) :
η ≠ 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, notMem_empty] at hη
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη
exact ha hη.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
lemma nthRoots_two_one : Polynomial.nthRoots 2 (1 : R) = {-1,1} := by
have h₁ : (X ^ 2 - C 1 : R[X]) = (X + C 1) * (X - C 1) := by simp [← sq_sub_sq]
have h₂ : (X ^ 2 - C 1 : R[X]) ≠ 0 := fun h ↦ by simpa using congrArg (coeff · 0) h
rw [nthRoots, h₁, roots_mul (h₁ ▸ h₂), roots_X_add_C, roots_X_sub_C]; rfl
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩
theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by
rw [← sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [← C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(a • p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) :
(p ^ n).aroots S = n • p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) :
(X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(monomial n a).aroots S = n • ({0} : Multiset S) := by
rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
variable (R S) in
@[simp]
theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R]
[IsScalarTower T S R] :
(p.map (algebraMap T S)).aroots R = p.aroots R := by
rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R]
/-- The set of distinct roots of `p` in `S`.
If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S :=
haveI := Classical.decEq S
(p.aroots S).toFinset
theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] :
p.rootSet S = (p.aroots S).toFinset := by
rw [rootSet]
convert rfl
@[simp]
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = ∅ := by
classical
rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
@[simp]
theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = ∅ := by
rw [← C_0, rootSet_C]
@[simp]
theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = ∅ := by
rw [← C_1, rootSet_C]
@[simp]
theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
(-p).rootSet S = p.rootSet S := by
rw [rootSet, aroots_neg, rootSet]
instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
Fintype (p.rootSet S) :=
FinsetCoe.fintype _
theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
(p.rootSet S).Finite :=
Set.toFinite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S]
(m : R →+* S) (d : ℕ) {U : Set R} (h : U.Finite) :
(⋃ (f : R[X]) (_ : f.natDegree ≤ d ∧ ∀ i, f.coeff i ∈ U),
((f.map m).roots.toFinset.toSet : Set S)).Finite :=
Set.Finite.biUnion
(by
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `π` is finite
let π : R[X] → Fin (d + 1) → R := fun f i => f.coeff i
refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn π _)
· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i
· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_
exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩)
fun _ _ => Finset.finite_toSet _
theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} :
a ∈ p.rootSet S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
classical
rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots']
theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)]
theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] (hp : p ≠ 0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 :=
mem_rootSet.trans <| and_iff_right hp
theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 → p.map (algebraMap T S) = 0)
(f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by
rw [mem_rootSet'] at hx ⊢
rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero]
exact ⟨mt hp hx.1, rfl⟩
theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(h : a ∈ p.rootSet S) : p ≠ 0 := fun hf => by rwa [hf, rootSet_zero] at h
theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(hx : a ∈ p.rootSet S) : aeval a p = 0 :=
(mem_rootSet'.1 hx).2
theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S →ₐ[T] S') :
(p.rootSet S).MapsTo f (p.rootSet S') := by
refine rootSet_maps_to' (fun h₀ => ?_) f
obtain rfl : p = 0 :=
map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero])
exact Polynomial.map_zero _
theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R]
(h : Function.Injective (algebraMap S R)) {x : R} (hp : p ≠ 0) :
x ∈ p.rootSet R ↔ aeval x p = 0 := by
classical
exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp)
end Roots
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R]
(p : R[X]) {ι} [Fintype ι] {f : ι → R} (hf : Function.Injective f)
(heval : ∀ i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ι) : p = 0 := by
classical
by_contra hp
refine lt_irrefl #p.roots.toFinset ?_
calc
#p.roots.toFinset ≤ Multiset.card p.roots := Multiset.toFinset_card_le _
_ ≤ natDegree p := Polynomial.card_roots' p
_ < Fintype.card ι := hcard
_ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm
_ = #(Finset.univ.image f) := by rw [← Set.toFinset_card, Set.toFinset_range]
_ ≤ #p.roots.toFinset := Finset.card_mono ?_
intro _
simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq,
IsRoot.def, forall_exists_index, hp, not_false_eq_true]
rintro x rfl
exact heval _
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R]
(p : R[X]) (s : Finset R) (heval : ∀ i ∈ s, p.eval i = 0) (hcard : natDegree p < #s) :
p = 0 :=
eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective
(fun i : s ↦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm)
open Cardinal in
lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card
(f : R[X]) (hf : ∀ r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by
obtain hR|hR := finite_or_infinite R
· have := Fintype.ofFinite R
apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf
simpa only [mk_fintype, Nat.cast_lt] using hfR
· exact zero_of_eval_zero _ hf
open Cardinal in
lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f ≠ 0) (hfR : f.natDegree < #R) :
∃ r, f.eval r ≠ 0 := by
contrapose! hf
exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR
section
omit [IsDomain R]
theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod :=
monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a
theorem monic_prod_X_sub_C {α : Type*} (b : α → R) (s : Finset α) :
Monic (∏ a ∈ s, (X - C (b a))) :=
monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
theorem monic_finprod_X_sub_C {α : Type*} (b : α → R) : Monic (∏ᶠ k, (X - C (b k))) :=
monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
end
theorem prod_multiset_root_eq_finset_root [DecidableEq R] :
(p.roots.map fun a => X - C a).prod =
p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by
simp only [count_roots, Finset.prod_multiset_map_count]
/-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod ∣ p := by
classical
rw [← map_dvd_map _ (IsFractionRing.injective R <| FractionRing R)
(monic_multisetProd_X_sub_C p.roots)]
rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod]
refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_
· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X]
exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow
· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a)
/-- A Galois connection. -/
theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p ≠ 0) (s : Multiset R) :
(s.map fun a => X - C a).prod ∣ p ↔ s ≤ p.roots := by
classical exact
⟨fun h =>
Multiset.le_iff_count.2 fun r => by
rw [count_roots, le_rootMultiplicity_iff hp, ← Multiset.prod_replicate, ←
Multiset.map_replicate fun a => X - C a, ← Multiset.filter_eq]
exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h,
fun h =>
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩
theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) :
∃ q,
(p.roots.map fun a => X - C a).prod * q = p ∧
Multiset.card p.roots + q.natDegree = p.natDegree ∧ q.roots = 0 := by
obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd
use q, he.symm
obtain rfl | hq := eq_or_ne q 0
· rw [mul_zero] at he
subst he
simp
constructor
· conv_rhs => rw [he]
rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq,
natDegree_multiset_prod_X_sub_C_eq_card]
· replace he := congr_arg roots he.symm
rw [roots_mul, roots_multiset_prod_X_sub_C] at he
exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq]
/-- A polynomial `p` that has as many roots as its degree
can be written `p = p.leadingCoeff * ∏(X - a)`, for `a` in `p.roots`. -/
theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) :
C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p :=
(eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots)
p.prod_multiset_X_sub_C_dvd
((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm
/-- A monic polynomial `p` that has as many roots as its degree
can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/
theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic)
(hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by
convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots
rw [hp.leadingCoeff, C_1, one_mul]
theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a ∣ p) :
IsUnit a.leadingCoeff :=
isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap)
/-- To check a monic polynomial is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem Monic.irreducible_iff_degree_lt {p : R[X]} (p_monic : Monic p) (p_1 : p ≠ 1) :
Irreducible p ↔ ∀ q, degree q ≤ ↑(p.natDegree / 2) → q ∣ p → IsUnit q := by
simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp,
natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le]
constructor
· rintro h q deg_le dvd
by_contra q_unit
have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd
have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd
refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim
· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd]
· rintro h q _ deg_pos deg_le dvd
exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd)
end CommRing
section
variable {A B : Type*} [CommRing A] [CommRing B]
theorem le_rootMultiplicity_map {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0) (a : A) :
rootMultiplicity a p ≤ rootMultiplicity (f a) (p.map f) := by
rw [le_rootMultiplicity_iff hmap]
refine _root_.trans ?_ (_root_.map_dvd (mapRingHom f) (pow_rootMultiplicity_dvd p a))
rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C]
theorem eq_rootMultiplicity_map {p : A[X]} {f : A →+* B} (hf : Function.Injective f) (a : A) :
rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by
by_cases hp0 : p = 0; · simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero]
apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a)
rw [le_rootMultiplicity_iff hp0, ← map_dvd_map f hf ((monic_X_sub_C a).pow _),
Polynomial.map_pow, Polynomial.map_sub, map_X, map_C]
apply pow_rootMultiplicity_dvd
theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A →+* B} (hmap : map f p ≠ 0)
(b : B) :
(p.roots.map f).count b ≤ rootMultiplicity b (p.map f) := by
rw [le_rootMultiplicity_iff hmap, ← Multiset.prod_replicate, ←
Multiset.map_replicate fun a => X - C a]
rw [← Multiset.filter_eq]
refine
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_
convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd
simp only [Polynomial.map_multiset_prod, Multiset.map_map]
congr; ext1
simp only [Function.comp_apply, Polynomial.map_sub, map_X, map_C]
theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A →+* B}
(hf : Function.Injective f) (b : B) :
(p.roots.map f).count b ≤ rootMultiplicity b (p.map f) := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero,
rootMultiplicity_zero, le_refl]
· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b
theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
p.roots.map f ≤ (p.map f).roots := by
classical
exact Multiset.le_iff_count.2 fun b => by
rw [count_roots]
apply count_map_roots h
theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A →+* B}
(hf : Function.Injective f) : p.roots.map f ≤ (p.map f).roots := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl]
exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B} (h : p.map f ≠ 0) :
Multiset.card p.roots ≤ Multiset.card (p.map f).roots := by
rw [← p.roots.card_map f]
exact Multiset.card_le_card (map_roots_le h)
theorem card_roots_le_map_of_injective [IsDomain A] [IsDomain B] {p : A[X]} {f : A →+* B}
(hf : Function.Injective f) : Multiset.card p.roots ≤ Multiset.card (p.map f).roots := by
by_cases hp0 : p = 0
· simp only [hp0, roots_zero, Polynomial.map_zero, Multiset.card_zero, le_rfl]
exact card_roots_le_map ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem roots_map_of_injective_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
{f : A →+* B} (hf : Function.Injective f) (hroots : Multiset.card p.roots = p.natDegree) :
p.roots.map f = (p.map f).roots := by
apply Multiset.eq_of_le_of_card_le (map_roots_le_of_injective p hf)
simpa only [Multiset.card_map, hroots] using (card_roots' _).trans natDegree_map_le
theorem roots_map_of_map_ne_zero_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
(f : A →+* B) (h : p.map f ≠ 0) (hroots : p.roots.card = p.natDegree) :
p.roots.map f = (p.map f).roots :=
eq_of_le_of_card_le (map_roots_le h) <| by
simpa only [Multiset.card_map, hroots] using (p.map f).card_roots'.trans natDegree_map_le
theorem Monic.roots_map_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} (hm : p.Monic)
(f : A →+* B) (hroots : p.roots.card = p.natDegree) : p.roots.map f = (p.map f).roots :=
roots_map_of_map_ne_zero_of_card_eq_natDegree f (map_monic_ne_zero hm) hroots
end
end Polynomial
|
PrincipalIdealDomainOfPrime.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.Ideal.Colon
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Principal ideal domains and prime ideals
# Main results
- `IsPrincipalIdeal.of_prime`: a ring where all prime ideals are principal is a principal ideal ring
-/
open Ideal
variable {R : Type*} [CommRing R]
/-- If all prime ideals in a commutative ring are principal, so are all other ideals. -/
theorem IsPrincipalIdealRing.of_prime (H : ∀ P : Ideal R, P.IsPrime → P.IsPrincipal) :
IsPrincipalIdealRing R := by
-- Suppose the set of `nonPrincipals` is not empty.
rw [← nonPrincipals_eq_empty_iff, Set.eq_empty_iff_forall_notMem]
intro J hJ
-- We will show a maximal element `I ∈ nonPrincipals R` (which exists by Zorn) is prime.
obtain ⟨I, hJI, hI⟩ := zorn_le_nonempty₀ (nonPrincipals R) nonPrincipals_zorn _ hJ
have Imax' : ∀ {J}, I < J → J.IsPrincipal := by
intro K hK
simpa [nonPrincipals] using hI.not_prop_of_gt hK
by_cases hI1 : I = ⊤
· subst hI1
exact hI.prop top_isPrincipal
-- Let `x y : R` with `x * y ∈ I` and suppose WLOG `y ∉ I`.
refine hI.prop (H I ⟨hI1, fun {x y} hxy => or_iff_not_imp_right.mpr fun hy => ?_⟩)
obtain ⟨a, ha⟩ : (I ⊔ span {y}).IsPrincipal :=
Imax' (left_lt_sup.mpr (mt I.span_singleton_le_iff_mem.mp hy))
-- Then `x ∈ I.colon (span {y})`, which is equal to `I` if it's not principal.
suffices He : ¬(I.colon (span {y})).IsPrincipal by
rw [hI.eq_of_le ((nonPrincipals_def R).2 He) fun a ha ↦
Ideal.mem_colon_singleton.2 (mul_mem_right _ _ ha)]
exact Ideal.mem_colon_singleton.2 hxy
-- So suppose for the sake of contradiction that both `I ⊔ span {y}` and `I.colon (span {y})`
-- are principal.
rintro ⟨b, hb⟩
-- We will show `I` is generated by `a * b`.
refine (nonPrincipals_def _).1 hI.prop ⟨a * b, ?_⟩
refine
le_antisymm (α := Ideal R) (fun i hi => ?_) <|
(span_singleton_mul_span_singleton a b).ge.trans ?_
· have hisup : i ∈ I ⊔ span {y} := Ideal.mem_sup_left hi
have : y ∈ I ⊔ span {y} := Ideal.mem_sup_right (Ideal.mem_span_singleton_self y)
rw [ha, Ideal.submodule_span_eq, mem_span_singleton'] at hisup this
obtain ⟨v, rfl⟩ := this
obtain ⟨u, rfl⟩ := hisup
have hucolon : u ∈ I.colon (span {v * a}) := by
rw [Ideal.mem_colon_singleton, mul_comm v, ← mul_assoc]
exact mul_mem_right _ _ hi
rw [hb, Ideal.submodule_span_eq, mem_span_singleton'] at hucolon
obtain ⟨z, rfl⟩ := hucolon
exact mem_span_singleton'.2 ⟨z, by ring⟩
· rw [← Ideal.submodule_span_eq, ← ha, Ideal.sup_mul, sup_le_iff,
span_singleton_mul_span_singleton, mul_comm y, Ideal.span_singleton_le_iff_mem]
exact ⟨mul_le_right, Ideal.mem_colon_singleton.1 <| hb.symm ▸ Ideal.mem_span_singleton_self b⟩
|
SupClosed.lean
|
/-
Copyright (c) 2023 Yaël Dillies, Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Christopher Hoskin
-/
import Mathlib.Data.Finset.Lattice.Prod
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Order.Closure
import Mathlib.Order.ConditionallyCompleteLattice.Finset
/-!
# Sets closed under join/meet
This file defines predicates for sets closed under `⊔` and shows that each set in a join-semilattice
generates a join-closed set and that a semilattice where every directed set has a least upper bound
is automatically complete. All dually for `⊓`.
## Main declarations
* `SupClosed`: Predicate for a set to be closed under join (`a ∈ s` and `b ∈ s` imply `a ⊔ b ∈ s`).
* `InfClosed`: Predicate for a set to be closed under meet (`a ∈ s` and `b ∈ s` imply `a ⊓ b ∈ s`).
* `IsSublattice`: Predicate for a set to be closed under meet and join.
* `supClosure`: Sup-closure. Smallest sup-closed set containing a given set.
* `infClosure`: Inf-closure. Smallest inf-closed set containing a given set.
* `latticeClosure`: Smallest sublattice containing a given set.
* `SemilatticeSup.toCompleteSemilatticeSup`: A join-semilattice where every sup-closed set has a
least upper bound is automatically complete.
* `SemilatticeInf.toCompleteSemilatticeInf`: A meet-semilattice where every inf-closed set has a
greatest lower bound is automatically complete.
-/
variable {ι : Sort*} {F α β : Type*}
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β]
section Set
variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is *sup-closed* if `a ⊔ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/
def SupClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊔ b ∈ s
@[simp] lemma supClosed_empty : SupClosed (∅ : Set α) := by simp [SupClosed]
@[simp] lemma supClosed_singleton : SupClosed ({a} : Set α) := by simp [SupClosed]
@[simp] lemma supClosed_univ : SupClosed (univ : Set α) := by simp [SupClosed]
lemma SupClosed.inter (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ∩ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma supClosed_sInter (hS : ∀ s ∈ S, SupClosed s) : SupClosed (⋂₀ S) :=
fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs)
lemma supClosed_iInter (hf : ∀ i, SupClosed (f i)) : SupClosed (⋂ i, f i) :=
supClosed_sInter <| forall_mem_range.2 hf
lemma SupClosed.directedOn (hs : SupClosed s) : DirectedOn (· ≤ ·) s :=
fun _a ha _b hb ↦ ⟨_, hs ha hb, le_sup_left, le_sup_right⟩
lemma IsUpperSet.supClosed (hs : IsUpperSet s) : SupClosed s := fun _a _ _b ↦ hs le_sup_right
lemma SupClosed.preimage [FunLike F β α] [SupHomClass F β α] (hs : SupClosed s) (f : F) :
SupClosed (f ⁻¹' s) :=
fun a ha b hb ↦ by simpa [map_sup] using hs ha hb
lemma SupClosed.image [FunLike F α β] [SupHomClass F α β] (hs : SupClosed s) (f : F) :
SupClosed (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
rw [← map_sup]
exact Set.mem_image_of_mem _ <| hs ha hb
lemma supClosed_range [FunLike F α β] [SupHomClass F α β] (f : F) : SupClosed (Set.range f) := by
simpa using supClosed_univ.image f
lemma SupClosed.prod {t : Set β} (hs : SupClosed s) (ht : SupClosed t) : SupClosed (s ×ˢ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma supClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeSup (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, SupClosed (t i)) : SupClosed (s.pi t) :=
fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi)
lemma SupClosed.insert_upperBounds {s : Set α} {a : α} (hs : SupClosed s) (ha : a ∈ upperBounds s) :
SupClosed (insert a s) := by
rw [SupClosed]
aesop
lemma SupClosed.insert_lowerBounds {s : Set α} {a : α} (h : SupClosed s) (ha : a ∈ lowerBounds s) :
SupClosed (insert a s) := by
rw [SupClosed]
have ha' : ∀ b ∈ s, a ≤ b := fun _ a ↦ ha a
aesop
end Set
section Finset
variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α}
open Finset
lemma SupClosed.finsetSup'_mem (hs : SupClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.sup' ht f ∈ s :=
sup'_induction _ _ hs
lemma SupClosed.finsetSup_mem [OrderBot α] (hs : SupClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.sup f ∈ s :=
sup'_eq_sup ht f ▸ hs.finsetSup'_mem ht
end Finset
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β]
section Set
variable {ι : Sort*} {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is *inf-closed* if `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`. -/
def InfClosed (s : Set α) : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → a ⊓ b ∈ s
@[simp] lemma infClosed_empty : InfClosed (∅ : Set α) := by simp [InfClosed]
@[simp] lemma infClosed_singleton : InfClosed ({a} : Set α) := by simp [InfClosed]
@[simp] lemma infClosed_univ : InfClosed (univ : Set α) := by simp [InfClosed]
lemma InfClosed.inter (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ∩ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma infClosed_sInter (hS : ∀ s ∈ S, InfClosed s) : InfClosed (⋂₀ S) :=
fun _a ha _b hb _s hs ↦ hS _ hs (ha _ hs) (hb _ hs)
lemma infClosed_iInter (hf : ∀ i, InfClosed (f i)) : InfClosed (⋂ i, f i) :=
infClosed_sInter <| forall_mem_range.2 hf
lemma InfClosed.codirectedOn (hs : InfClosed s) : DirectedOn (· ≥ ·) s :=
fun _a ha _b hb ↦ ⟨_, hs ha hb, inf_le_left, inf_le_right⟩
lemma IsLowerSet.infClosed (hs : IsLowerSet s) : InfClosed s := fun _a _ _b ↦ hs inf_le_right
lemma InfClosed.preimage [FunLike F β α] [InfHomClass F β α] (hs : InfClosed s) (f : F) :
InfClosed (f ⁻¹' s) :=
fun a ha b hb ↦ by simpa [map_inf] using hs ha hb
lemma InfClosed.image [FunLike F α β] [InfHomClass F α β] (hs : InfClosed s) (f : F) :
InfClosed (f '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩
rw [← map_inf]
exact Set.mem_image_of_mem _ <| hs ha hb
lemma infClosed_range [FunLike F α β] [InfHomClass F α β] (f : F) : InfClosed (Set.range f) := by
simpa using infClosed_univ.image f
lemma InfClosed.prod {t : Set β} (hs : InfClosed s) (ht : InfClosed t) : InfClosed (s ×ˢ t) :=
fun _a ha _b hb ↦ ⟨hs ha.1 hb.1, ht ha.2 hb.2⟩
lemma infClosed_pi {ι : Type*} {α : ι → Type*} [∀ i, SemilatticeInf (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, InfClosed (t i)) : InfClosed (s.pi t) :=
fun _a ha _b hb _i hi ↦ ht _ hi (ha _ hi) (hb _ hi)
lemma InfClosed.insert_upperBounds {s : Set α} {a : α} (hs : InfClosed s) (ha : a ∈ upperBounds s) :
InfClosed (insert a s) := by
rw [InfClosed]
have ha' : ∀ b ∈ s, b ≤ a := fun _ a ↦ ha a
aesop
lemma InfClosed.insert_lowerBounds {s : Set α} {a : α} (h : InfClosed s) (ha : a ∈ lowerBounds s) :
InfClosed (insert a s) := by
rw [InfClosed]
aesop
end Set
section Finset
variable {ι : Type*} {f : ι → α} {s : Set α} {t : Finset ι} {a : α}
open Finset
lemma InfClosed.finsetInf'_mem (hs : InfClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.inf' ht f ∈ s :=
inf'_induction _ _ hs
lemma InfClosed.finsetInf_mem [OrderTop α] (hs : InfClosed s) (ht : t.Nonempty) :
(∀ i ∈ t, f i ∈ s) → t.inf f ∈ s :=
inf'_eq_inf ht f ▸ hs.finsetInf'_mem ht
end Finset
end SemilatticeInf
open Finset OrderDual
section Lattice
variable {ι : Sort*} [Lattice α] [Lattice β] {S : Set (Set α)} {f : ι → Set α} {s t : Set α} {a : α}
open Set
/-- A set `s` is a *sublattice* if `a ⊔ b ∈ s` and `a ⊓ b ∈ s` for all `a ∈ s`, `b ∈ s`.
Note: This is not the preferred way to declare a sublattice. One should instead use `Sublattice`.
TODO: Define `Sublattice`. -/
structure IsSublattice (s : Set α) : Prop where
supClosed : SupClosed s
infClosed : InfClosed s
@[simp] lemma isSublattice_empty : IsSublattice (∅ : Set α) := ⟨supClosed_empty, infClosed_empty⟩
@[simp] lemma isSublattice_singleton : IsSublattice ({a} : Set α) :=
⟨supClosed_singleton, infClosed_singleton⟩
@[simp] lemma isSublattice_univ : IsSublattice (Set.univ : Set α) :=
⟨supClosed_univ, infClosed_univ⟩
lemma IsSublattice.inter (hs : IsSublattice s) (ht : IsSublattice t) : IsSublattice (s ∩ t) :=
⟨hs.1.inter ht.1, hs.2.inter ht.2⟩
lemma isSublattice_sInter (hS : ∀ s ∈ S, IsSublattice s) : IsSublattice (⋂₀ S) :=
⟨supClosed_sInter fun _s hs ↦ (hS _ hs).1, infClosed_sInter fun _s hs ↦ (hS _ hs).2⟩
lemma isSublattice_iInter (hf : ∀ i, IsSublattice (f i)) : IsSublattice (⋂ i, f i) :=
⟨supClosed_iInter fun _i ↦ (hf _).1, infClosed_iInter fun _i ↦ (hf _).2⟩
lemma IsSublattice.preimage [FunLike F β α] [LatticeHomClass F β α]
(hs : IsSublattice s) (f : F) :
IsSublattice (f ⁻¹' s) := ⟨hs.1.preimage _, hs.2.preimage _⟩
lemma IsSublattice.image [FunLike F α β] [LatticeHomClass F α β] (hs : IsSublattice s) (f : F) :
IsSublattice (f '' s) := ⟨hs.1.image _, hs.2.image _⟩
lemma IsSublattice_range [FunLike F α β] [LatticeHomClass F α β] (f : F) :
IsSublattice (Set.range f) :=
⟨supClosed_range _, infClosed_range _⟩
lemma IsSublattice.prod {t : Set β} (hs : IsSublattice s) (ht : IsSublattice t) :
IsSublattice (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩
lemma isSublattice_pi {ι : Type*} {α : ι → Type*} [∀ i, Lattice (α i)] {s : Set ι}
{t : ∀ i, Set (α i)} (ht : ∀ i ∈ s, IsSublattice (t i)) : IsSublattice (s.pi t) :=
⟨supClosed_pi fun _i hi ↦ (ht _ hi).1, infClosed_pi fun _i hi ↦ (ht _ hi).2⟩
@[simp] lemma supClosed_preimage_toDual {s : Set αᵒᵈ} :
SupClosed (toDual ⁻¹' s) ↔ InfClosed s := Iff.rfl
@[simp] lemma infClosed_preimage_toDual {s : Set αᵒᵈ} :
InfClosed (toDual ⁻¹' s) ↔ SupClosed s := Iff.rfl
@[simp] lemma supClosed_preimage_ofDual {s : Set α} :
SupClosed (ofDual ⁻¹' s) ↔ InfClosed s := Iff.rfl
@[simp] lemma infClosed_preimage_ofDual {s : Set α} :
InfClosed (ofDual ⁻¹' s) ↔ SupClosed s := Iff.rfl
@[simp] lemma isSublattice_preimage_toDual {s : Set αᵒᵈ} :
IsSublattice (toDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩
@[simp] lemma isSublattice_preimage_ofDual :
IsSublattice (ofDual ⁻¹' s) ↔ IsSublattice s := ⟨fun h ↦ ⟨h.2, h.1⟩, fun h ↦ ⟨h.2, h.1⟩⟩
alias ⟨_, InfClosed.dual⟩ := supClosed_preimage_ofDual
alias ⟨_, SupClosed.dual⟩ := infClosed_preimage_ofDual
alias ⟨_, IsSublattice.dual⟩ := isSublattice_preimage_ofDual
alias ⟨_, IsSublattice.of_dual⟩ := isSublattice_preimage_toDual
end Lattice
section LinearOrder
variable [LinearOrder α]
@[simp] protected lemma LinearOrder.supClosed (s : Set α) : SupClosed s :=
fun a ha b hb ↦ by cases le_total a b <;> simp [*]
@[simp] protected lemma LinearOrder.infClosed (s : Set α) : InfClosed s :=
fun a ha b hb ↦ by cases le_total a b <;> simp [*]
@[simp] protected lemma LinearOrder.isSublattice (s : Set α) : IsSublattice s :=
⟨LinearOrder.supClosed _, LinearOrder.infClosed _⟩
end LinearOrder
/-! ## Closure -/
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β] {s t : Set α} {a b : α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def supClosure : ClosureOperator (Set α) := .ofPred
(fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.sup' ht id = a})
SupClosed
(fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩)
(by
classical
rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
refine ⟨_, ht.mono subset_union_left, ?_, sup'_union ht hu _⟩
rw [coe_union]
exact Set.union_subset hts hus)
(by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetSup'_mem ht fun i hi ↦ hs <| hts hi)
@[simp] lemma subset_supClosure {s : Set α} : s ⊆ supClosure s := supClosure.le_closure _
@[simp] lemma supClosed_supClosure : SupClosed (supClosure s) := supClosure.isClosed_closure _
lemma supClosure_mono : Monotone (supClosure : Set α → Set α) := supClosure.monotone
@[simp] lemma supClosure_eq_self : supClosure s = s ↔ SupClosed s := supClosure.isClosed_iff.symm
alias ⟨_, SupClosed.supClosure_eq⟩ := supClosure_eq_self
lemma supClosure_idem (s : Set α) : supClosure (supClosure s) = supClosure s :=
supClosure.idempotent _
@[simp] lemma supClosure_empty : supClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma supClosure_singleton : supClosure {a} = {a} := by simp
@[simp] lemma supClosure_univ : supClosure (Set.univ : Set α) = Set.univ := by simp
@[simp] lemma upperBounds_supClosure (s : Set α) : upperBounds (supClosure s) = upperBounds s :=
(upperBounds_mono_set subset_supClosure).antisymm <| by
rintro a ha _ ⟨t, ht, hts, rfl⟩
exact sup'_le _ _ fun b hb ↦ ha <| hts hb
@[simp] lemma isLUB_supClosure : IsLUB (supClosure s) a ↔ IsLUB s a := by simp [IsLUB]
lemma sup_mem_supClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊔ b ∈ supClosure s :=
supClosed_supClosure (subset_supClosure ha) (subset_supClosure hb)
lemma finsetSup'_mem_supClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α}
(hf : ∀ i ∈ t, f i ∈ s) : t.sup' ht f ∈ supClosure s :=
supClosed_supClosure.finsetSup'_mem _ fun _i hi ↦ subset_supClosure <| hf _ hi
lemma supClosure_min : s ⊆ t → SupClosed t → supClosure s ⊆ t := supClosure.closure_min
/-- The semilatice generated by a finite set is finite. -/
protected lemma Set.Finite.supClosure (hs : s.Finite) : (supClosure s).Finite := by
lift s to Finset α using hs
classical
refine ({t ∈ s.powerset | t.Nonempty}.attach.image
fun t ↦ t.1.sup' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_
rintro _ ⟨t, ht, hts, rfl⟩
simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists,
Finset.mem_powerset, mem_filter]
exact ⟨t, ⟨hts, ht⟩, rfl⟩
@[simp] lemma supClosure_prod (s : Set α) (t : Set β) :
supClosure (s ×ˢ t) = supClosure s ×ˢ supClosure t :=
le_antisymm (supClosure_min (Set.prod_mono subset_supClosure subset_supClosure) <|
supClosed_supClosure.prod supClosed_supClosure) <| by
rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩
refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩
· simpa only [coe_product] using Set.prod_mono hus hvt
· simp [prodMk_sup'_sup']
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β] {s t : Set α} {a b : α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def infClosure : ClosureOperator (Set α) := ClosureOperator.ofPred
(fun s ↦ {a | ∃ (t : Finset α) (ht : t.Nonempty), ↑t ⊆ s ∧ t.inf' ht id = a})
InfClosed
(fun s a ha ↦ ⟨{a}, singleton_nonempty _, by simpa⟩)
(by
classical
rintro s _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
refine ⟨_, ht.mono subset_union_left, ?_, inf'_union ht hu _⟩
rw [coe_union]
exact Set.union_subset hts hus)
(by rintro s₁ s₂ hs h₂ _ ⟨t, ht, hts, rfl⟩; exact h₂.finsetInf'_mem ht fun i hi ↦ hs <| hts hi)
@[simp] lemma subset_infClosure {s : Set α} : s ⊆ infClosure s := infClosure.le_closure _
@[simp] lemma infClosed_infClosure : InfClosed (infClosure s) := infClosure.isClosed_closure _
lemma infClosure_mono : Monotone (infClosure : Set α → Set α) := infClosure.monotone
@[simp] lemma infClosure_eq_self : infClosure s = s ↔ InfClosed s := infClosure.isClosed_iff.symm
alias ⟨_, InfClosed.infClosure_eq⟩ := infClosure_eq_self
lemma infClosure_idem (s : Set α) : infClosure (infClosure s) = infClosure s :=
infClosure.idempotent _
@[simp] lemma infClosure_empty : infClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma infClosure_singleton : infClosure {a} = {a} := by simp
@[simp] lemma infClosure_univ : infClosure (Set.univ : Set α) = Set.univ := by simp
@[simp] lemma lowerBounds_infClosure (s : Set α) : lowerBounds (infClosure s) = lowerBounds s :=
(lowerBounds_mono_set subset_infClosure).antisymm <| by
rintro a ha _ ⟨t, ht, hts, rfl⟩
exact le_inf' _ _ fun b hb ↦ ha <| hts hb
@[simp] lemma isGLB_infClosure : IsGLB (infClosure s) a ↔ IsGLB s a := by simp [IsGLB]
lemma inf_mem_infClosure (ha : a ∈ s) (hb : b ∈ s) : a ⊓ b ∈ infClosure s :=
infClosed_infClosure (subset_infClosure ha) (subset_infClosure hb)
lemma finsetInf'_mem_infClosure {ι : Type*} {t : Finset ι} (ht : t.Nonempty) {f : ι → α}
(hf : ∀ i ∈ t, f i ∈ s) : t.inf' ht f ∈ infClosure s :=
infClosed_infClosure.finsetInf'_mem _ fun _i hi ↦ subset_infClosure <| hf _ hi
lemma infClosure_min : s ⊆ t → InfClosed t → infClosure s ⊆ t := infClosure.closure_min
/-- The semilatice generated by a finite set is finite. -/
protected lemma Set.Finite.infClosure (hs : s.Finite) : (infClosure s).Finite := by
lift s to Finset α using hs
classical
refine ({t ∈ s.powerset | t.Nonempty}.attach.image
fun t ↦ t.1.inf' (mem_filter.1 t.2).2 id).finite_toSet.subset ?_
rintro _ ⟨t, ht, hts, rfl⟩
simp only [id_eq, coe_image, mem_image, mem_coe, mem_attach, true_and, Subtype.exists,
Finset.mem_powerset, mem_filter]
exact ⟨t, ⟨hts, ht⟩, rfl⟩
@[simp] lemma infClosure_prod (s : Set α) (t : Set β) :
infClosure (s ×ˢ t) = infClosure s ×ˢ infClosure t :=
le_antisymm (infClosure_min (Set.prod_mono subset_infClosure subset_infClosure) <|
infClosed_infClosure.prod infClosed_infClosure) <| by
rintro ⟨_, _⟩ ⟨⟨u, hu, hus, rfl⟩, v, hv, hvt, rfl⟩
refine ⟨u ×ˢ v, hu.product hv, ?_, ?_⟩
· simpa only [coe_product] using Set.prod_mono hus hvt
· simp [prodMk_inf'_inf']
end SemilatticeInf
section Lattice
variable [Lattice α] [Lattice β] {s t : Set α}
/-- Every set in a join-semilattice generates a set closed under join. -/
@[simps! isClosed]
def latticeClosure : ClosureOperator (Set α) :=
.ofCompletePred IsSublattice fun _ ↦ isSublattice_sInter
@[simp] lemma subset_latticeClosure : s ⊆ latticeClosure s := latticeClosure.le_closure _
@[simp] lemma isSublattice_latticeClosure : IsSublattice (latticeClosure s) :=
latticeClosure.isClosed_closure _
lemma latticeClosure_min : s ⊆ t → IsSublattice t → latticeClosure s ⊆ t :=
latticeClosure.closure_min
lemma latticeClosure_sup_inf_induction (p : (a : α) → a ∈ latticeClosure s → Prop)
(mem : ∀ (a : α) (has : a ∈ s), p a (subset_latticeClosure has))
(sup : ∀ (a : α) (has : a ∈ latticeClosure s) (b : α) (hbs : b ∈ latticeClosure s),
p a has → p b hbs → p (a ⊔ b) (isSublattice_latticeClosure.supClosed has hbs))
(inf : ∀ (a : α) (has : a ∈ latticeClosure s) (b : α) (hbs : b ∈ latticeClosure s),
p a has → p b hbs → p (a ⊓ b) (isSublattice_latticeClosure.infClosed has hbs))
{a : α} (has : a ∈ latticeClosure s) :
p a has := by
have h : IsSublattice { a : α | ∃ has : a ∈ latticeClosure s, p a has } := {
supClosed := fun a ⟨has, hpa⟩ b ⟨hbs, hpb⟩ =>
⟨isSublattice_latticeClosure.supClosed has hbs, sup a has b hbs hpa hpb⟩
infClosed := fun a ⟨has, hpa⟩ b ⟨hbs, hpb⟩ =>
⟨isSublattice_latticeClosure.infClosed has hbs, inf a has b hbs hpa hpb⟩ }
refine (latticeClosure_min (fun a ha ↦ ?_) h has).choose_spec
exact ⟨subset_latticeClosure ha, mem a ha⟩
lemma latticeClosure_mono : Monotone (latticeClosure : Set α → Set α) := latticeClosure.monotone
@[simp] lemma latticeClosure_eq_self : latticeClosure s = s ↔ IsSublattice s :=
latticeClosure.isClosed_iff.symm
alias ⟨_, IsSublattice.latticeClosure_eq⟩ := latticeClosure_eq_self
lemma latticeClosure_idem (s : Set α) : latticeClosure (latticeClosure s) = latticeClosure s :=
latticeClosure.idempotent _
@[simp] lemma latticeClosure_empty : latticeClosure (∅ : Set α) = ∅ := by simp
@[simp] lemma latticeClosure_singleton (a : α) : latticeClosure {a} = {a} := by simp
@[simp] lemma latticeClosure_univ : latticeClosure (Set.univ : Set α) = Set.univ := by simp
lemma image_latticeClosure (s : Set α) (f : α → β)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) :
f '' latticeClosure s = latticeClosure (f '' s) := by
simp only [subset_antisymm_iff, Set.image_subset_iff]
constructor <;> apply latticeClosure_sup_inf_induction
· exact fun a ha ↦ subset_latticeClosure <| Set.mem_image_of_mem _ ha
· rintro a - b - ha hb
simpa [map_sup] using isSublattice_latticeClosure.supClosed ha hb
· rintro a - b - ha hb
simpa [map_inf] using isSublattice_latticeClosure.infClosed ha hb
· exact Set.image_mono subset_latticeClosure
· rintro _ - _ - ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩
exact ⟨a ⊔ b, isSublattice_latticeClosure.supClosed ha hb, map_sup ..⟩
· rintro _ - _ - ⟨a, ha, rfl⟩ ⟨b, hb, rfl⟩
exact ⟨a ⊓ b, isSublattice_latticeClosure.infClosed ha hb, map_inf ..⟩
lemma ofDual_preimage_latticeClosure (s : Set α) :
ofDual ⁻¹' latticeClosure s = latticeClosure (ofDual ⁻¹' s) := by
change ClosureOperator.ofCompletePred _ _ _ = ClosureOperator.ofCompletePred _ _ _
congr 2
ext
exact ⟨fun h => ⟨h.2, h.1⟩, fun h => ⟨h.2, h.1⟩⟩
lemma image_latticeClosure' (s : Set α) (f : α → β)
(map_sup : ∀ a b, f (a ⊔ b) = f a ⊓ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊔ f b) :
f '' latticeClosure s = latticeClosure (f '' s) := by
simpa only [Set.image_comp, ← Set.preimage_equiv_eq_image_symm, ← ofDual_preimage_latticeClosure]
using image_latticeClosure s (ofDual.symm ∘ f) map_sup map_inf
end Lattice
section DistribLattice
variable [DistribLattice α] [DistribLattice β] {s : Set α}
protected lemma SupClosed.infClosure (hs : SupClosed s) : SupClosed (infClosure s) := by
rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
rw [inf'_sup_inf']
exact finsetInf'_mem_infClosure _
fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2)
protected lemma InfClosed.supClosure (hs : InfClosed s) : InfClosed (supClosure s) := by
rintro _ ⟨t, ht, hts, rfl⟩ _ ⟨u, hu, hus, rfl⟩
rw [sup'_inf_sup']
exact finsetSup'_mem_supClosure _
fun i hi ↦ hs (hts (mem_product.1 hi).1) (hus (mem_product.1 hi).2)
@[simp] lemma supClosure_infClosure (s : Set α) : supClosure (infClosure s) = latticeClosure s :=
le_antisymm (supClosure_min (infClosure_min subset_latticeClosure isSublattice_latticeClosure.2)
isSublattice_latticeClosure.1) <| latticeClosure_min (subset_infClosure.trans subset_supClosure)
⟨supClosed_supClosure, infClosed_infClosure.supClosure⟩
@[simp] lemma infClosure_supClosure (s : Set α) : infClosure (supClosure s) = latticeClosure s :=
le_antisymm (infClosure_min (supClosure_min subset_latticeClosure isSublattice_latticeClosure.1)
isSublattice_latticeClosure.2) <| latticeClosure_min (subset_supClosure.trans subset_infClosure)
⟨supClosed_supClosure.infClosure, infClosed_infClosure⟩
lemma Set.Finite.latticeClosure (hs : s.Finite) : (latticeClosure s).Finite := by
rw [← supClosure_infClosure]; exact hs.infClosure.supClosure
@[simp] lemma latticeClosure_prod (s : Set α) (t : Set β) :
latticeClosure (s ×ˢ t) = latticeClosure s ×ˢ latticeClosure t := by
simp_rw [← supClosure_infClosure]; simp
end DistribLattice
/-- A join-semilattice where every sup-closed set has a least upper bound is automatically complete.
-/
def SemilatticeSup.toCompleteSemilatticeSup [SemilatticeSup α] (sSup : Set α → α)
(h : ∀ s, SupClosed s → IsLUB s (sSup s)) : CompleteSemilatticeSup α where
sSup := fun s => sSup (supClosure s)
le_sSup _ _ ha := (h _ supClosed_supClosure).1 <| subset_supClosure ha
sSup_le s a ha := (isLUB_le_iff <| h _ supClosed_supClosure).2 <| by rwa [upperBounds_supClosure]
/-- A meet-semilattice where every inf-closed set has a greatest lower bound is automatically
complete. -/
def SemilatticeInf.toCompleteSemilatticeInf [SemilatticeInf α] (sInf : Set α → α)
(h : ∀ s, InfClosed s → IsGLB s (sInf s)) : CompleteSemilatticeInf α where
sInf := fun s => sInf (infClosure s)
sInf_le _ _ ha := (h _ infClosed_infClosure).1 <| subset_infClosure ha
le_sInf s a ha := (le_isGLB_iff <| h _ infClosed_infClosure).2 <| by rwa [lowerBounds_infClosure]
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] {f : ι → α} {s t : Set α}
lemma SupClosed.iSup_mem_of_nonempty [Finite ι] [Nonempty ι] (hs : SupClosed s)
(hf : ∀ i, f i ∈ s) : ⨆ i, f i ∈ s := by
cases nonempty_fintype (PLift ι)
rw [← iSup_plift_down, ← Finset.sup'_univ_eq_ciSup]
exact hs.finsetSup'_mem Finset.univ_nonempty fun _ _ ↦ hf _
lemma InfClosed.iInf_mem_of_nonempty [Finite ι] [Nonempty ι] (hs : InfClosed s)
(hf : ∀ i, f i ∈ s) : ⨅ i, f i ∈ s := hs.dual.iSup_mem_of_nonempty hf
lemma SupClosed.sSup_mem_of_nonempty (hs : SupClosed s) (ht : t.Finite) (ht' : t.Nonempty)
(hts : t ⊆ s) : sSup t ∈ s := by
have := ht.to_subtype
have := ht'.to_subtype
rw [sSup_eq_iSup']
exact hs.iSup_mem_of_nonempty (by simpa)
lemma InfClosed.sInf_mem_of_nonempty (hs : InfClosed s) (ht : t.Finite) (ht' : t.Nonempty)
(hts : t ⊆ s) : sInf t ∈ s := hs.dual.sSup_mem_of_nonempty ht ht' hts
end ConditionallyCompleteLattice
section BooleanAlgebra
variable [BooleanAlgebra α] {s : Set α}
lemma compl_image_latticeClosure (s : Set α) :
compl '' latticeClosure s = latticeClosure (compl '' s) :=
image_latticeClosure' s _ compl_sup_distrib (fun _ _ => compl_inf)
lemma compl_image_latticeClosure_eq_of_compl_image_eq_self (hs : compl '' s = s) :
compl '' latticeClosure s = latticeClosure s :=
compl_image_latticeClosure s ▸ hs.symm ▸ rfl
end BooleanAlgebra
variable [CompleteLattice α] {f : ι → α} {s t : Set α}
lemma SupClosed.biSup_mem_of_nonempty {ι : Type*} {t : Set ι} {f : ι → α} (hs : SupClosed s)
(ht : t.Finite) (ht' : t.Nonempty) (hf : ∀ i ∈ t, f i ∈ s) : ⨆ i ∈ t, f i ∈ s := by
rw [← sSup_image]
exact hs.sSup_mem_of_nonempty (ht.image _) (by simpa) (by simpa)
lemma InfClosed.biInf_mem_of_nonempty {ι : Type*} {t : Set ι} {f : ι → α} (hs : InfClosed s)
(ht : t.Finite) (ht' : t.Nonempty) (hf : ∀ i ∈ t, f i ∈ s) : ⨅ i ∈ t, f i ∈ s :=
hs.dual.biSup_mem_of_nonempty ht ht' hf
lemma SupClosed.iSup_mem [Finite ι] (hs : SupClosed s) (hbot : ⊥ ∈ s) (hf : ∀ i, f i ∈ s) :
⨆ i, f i ∈ s := by
cases isEmpty_or_nonempty ι
· simpa [iSup_of_empty]
· exact hs.iSup_mem_of_nonempty hf
lemma InfClosed.iInf_mem [Finite ι] (hs : InfClosed s) (htop : ⊤ ∈ s) (hf : ∀ i, f i ∈ s) :
⨅ i, f i ∈ s := hs.dual.iSup_mem htop hf
lemma SupClosed.sSup_mem (hs : SupClosed s) (ht : t.Finite) (hbot : ⊥ ∈ s) (hts : t ⊆ s) :
sSup t ∈ s := by
have := ht.to_subtype
rw [sSup_eq_iSup']
exact hs.iSup_mem hbot (by simpa)
lemma InfClosed.sInf_mem (hs : InfClosed s) (ht : t.Finite) (htop : ⊤ ∈ s) (hts : t ⊆ s) :
sInf t ∈ s := hs.dual.sSup_mem ht htop hts
lemma SupClosed.biSup_mem {ι : Type*} {t : Set ι} {f : ι → α} (hs : SupClosed s)
(ht : t.Finite) (hbot : ⊥ ∈ s) (hf : ∀ i ∈ t, f i ∈ s) : ⨆ i ∈ t, f i ∈ s := by
rw [← sSup_image]
exact hs.sSup_mem (ht.image _) hbot (by simpa)
lemma InfClosed.biInf_mem {ι : Type*} {t : Set ι} {f : ι → α} (hs : InfClosed s)
(ht : t.Finite) (htop : ⊤ ∈ s) (hf : ∀ i ∈ t, f i ∈ s) : ⨅ i ∈ t, f i ∈ s :=
hs.dual.biSup_mem ht htop hf
|
PGroup.lean
|
/-
Copyright (c) 2018 . All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Thomas Browning
-/
import Mathlib.GroupTheory.Perm.Cycle.Type
import Mathlib.GroupTheory.SpecificGroups.Cyclic
/-!
# p-groups
This file contains a proof that if `G` is a `p`-group acting on a finite set `α`,
then the number of fixed points of the action is congruent mod `p` to the cardinality of `α`.
It also contains proofs of some corollaries of this lemma about existence of fixed points.
-/
open Fintype MulAction
variable (p : ℕ) (G : Type*) [Group G]
/-- A p-group is a group in which every element has prime power order -/
def IsPGroup : Prop :=
∀ g : G, ∃ k : ℕ, g ^ p ^ k = 1
variable {p} {G}
namespace IsPGroup
theorem iff_orderOf [hp : Fact p.Prime] : IsPGroup p G ↔ ∀ g : G, ∃ k : ℕ, orderOf g = p ^ k :=
forall_congr' fun g =>
⟨fun ⟨_, hk⟩ =>
Exists.imp (fun _ h => h.right)
((Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hk)),
Exists.imp fun k hk => by rw [← hk, pow_orderOf_eq_one]⟩
theorem of_card {n : ℕ} (hG : Nat.card G = p ^ n) : IsPGroup p G := fun g =>
⟨n, by rw [← hG, pow_card_eq_one']⟩
theorem of_bot : IsPGroup p (⊥ : Subgroup G) :=
of_card (n := 0) (by rw [Subgroup.card_bot, pow_zero])
theorem iff_card [Fact p.Prime] [Finite G] : IsPGroup p G ↔ ∃ n : ℕ, Nat.card G = p ^ n := by
have hG : Nat.card G ≠ 0 := Nat.card_pos.ne'
refine ⟨fun h => ?_, fun ⟨n, hn⟩ => of_card hn⟩
suffices ∀ q ∈ (Nat.card G).primeFactorsList, q = p by
use (Nat.card G).primeFactorsList.length
rw [← List.prod_replicate, ← List.eq_replicate_of_mem this, Nat.prod_primeFactorsList hG]
intro q hq
obtain ⟨hq1, hq2⟩ := (Nat.mem_primeFactorsList hG).mp hq
haveI : Fact q.Prime := ⟨hq1⟩
obtain ⟨g, hg⟩ := exists_prime_orderOf_dvd_card' q hq2
obtain ⟨k, hk⟩ := (iff_orderOf.mp h) g
exact (hq1.pow_eq_iff.mp (hg.symm.trans hk).symm).1.symm
alias ⟨exists_card_eq, _⟩ := iff_card
section GIsPGroup
variable (hG : IsPGroup p G)
include hG
theorem of_injective {H : Type*} [Group H] (ϕ : H →* G) (hϕ : Function.Injective ϕ) :
IsPGroup p H := by
simp_rw [IsPGroup, ← hϕ.eq_iff, ϕ.map_pow, ϕ.map_one]
exact fun h => hG (ϕ h)
theorem to_subgroup (H : Subgroup G) : IsPGroup p H :=
hG.of_injective H.subtype Subtype.coe_injective
theorem of_surjective {H : Type*} [Group H] (ϕ : G →* H) (hϕ : Function.Surjective ϕ) :
IsPGroup p H := by
refine fun h => Exists.elim (hϕ h) fun g hg => Exists.imp (fun k hk => ?_) (hG g)
rw [← hg, ← ϕ.map_pow, hk, ϕ.map_one]
theorem to_quotient (H : Subgroup G) [H.Normal] : IsPGroup p (G ⧸ H) :=
hG.of_surjective (QuotientGroup.mk' H) Quotient.mk''_surjective
theorem of_equiv {H : Type*} [Group H] (ϕ : G ≃* H) : IsPGroup p H :=
hG.of_surjective ϕ.toMonoidHom ϕ.surjective
theorem orderOf_coprime {n : ℕ} (hn : p.Coprime n) (g : G) : (orderOf g).Coprime n :=
let ⟨k, hk⟩ := hG g
(hn.pow_left k).coprime_dvd_left (orderOf_dvd_of_pow_eq_one hk)
/-- If `gcd(p,n) = 1`, then the `n`th power map is a bijection. -/
noncomputable def powEquiv {n : ℕ} (hn : p.Coprime n) : G ≃ G :=
let h : ∀ g : G, (Nat.card (Subgroup.zpowers g)).Coprime n := fun g =>
(Nat.card_zpowers g).symm ▸ hG.orderOf_coprime hn g
{ toFun := (· ^ n)
invFun := fun g => (powCoprime (h g)).symm ⟨g, Subgroup.mem_zpowers g⟩
left_inv := fun g =>
Subtype.ext_iff.1 <|
(powCoprime (h (g ^ n))).left_inv
⟨g, _, Subtype.ext_iff.1 <| (powCoprime (h g)).left_inv ⟨g, Subgroup.mem_zpowers g⟩⟩
right_inv := fun g =>
Subtype.ext_iff.1 <| (powCoprime (h g)).right_inv ⟨g, Subgroup.mem_zpowers g⟩ }
@[simp]
theorem powEquiv_apply {n : ℕ} (hn : p.Coprime n) (g : G) : hG.powEquiv hn g = g ^ n :=
rfl
@[simp]
theorem powEquiv_symm_apply {n : ℕ} (hn : p.Coprime n) (g : G) :
(hG.powEquiv hn).symm g = g ^ (orderOf g).gcdB n := by rw [← Nat.card_zpowers]; rfl
variable [hp : Fact p.Prime]
/-- If `p ∤ n`, then the `n`th power map is a bijection. -/
noncomputable abbrev powEquiv' {n : ℕ} (hn : ¬p ∣ n) : G ≃ G :=
powEquiv hG (hp.out.coprime_iff_not_dvd.mpr hn)
theorem index (H : Subgroup G) [H.FiniteIndex] : ∃ n : ℕ, H.index = p ^ n := by
obtain ⟨n, hn⟩ := iff_card.mp (hG.to_quotient H.normalCore)
obtain ⟨k, _, hk2⟩ :=
(Nat.dvd_prime_pow hp.out).mp
((congr_arg _ (H.normalCore.index_eq_card.trans hn)).mp
(Subgroup.index_dvd_of_le H.normalCore_le))
exact ⟨k, hk2⟩
theorem card_eq_or_dvd : Nat.card G = 1 ∨ p ∣ Nat.card G := by
cases finite_or_infinite G
· obtain ⟨n, hn⟩ := iff_card.mp hG
rw [hn]
rcases n with - | n
· exact Or.inl rfl
· exact Or.inr ⟨p ^ n, by rw [pow_succ']⟩
· rw [Nat.card_eq_zero_of_infinite]
exact Or.inr ⟨0, rfl⟩
theorem nontrivial_iff_card [Finite G] : Nontrivial G ↔ ∃ n > 0, Nat.card G = p ^ n :=
⟨fun hGnt =>
let ⟨k, hk⟩ := iff_card.1 hG
⟨k,
Nat.pos_of_ne_zero fun hk0 => by
rw [hk0, pow_zero] at hk; exact Finite.one_lt_card.ne' hk,
hk⟩,
fun ⟨_, hk0, hk⟩ =>
Finite.one_lt_card_iff_nontrivial.1 <|
hk.symm ▸ one_lt_pow₀ (Fact.out (p := p.Prime)).one_lt (ne_of_gt hk0)⟩
variable {α : Type*} [MulAction G α]
theorem card_orbit (a : α) [Finite (orbit G a)] : ∃ n : ℕ, Nat.card (orbit G a) = p ^ n := by
let ϕ := orbitEquivQuotientStabilizer G a
haveI := Finite.of_equiv (orbit G a) ϕ
haveI := (stabilizer G a).finiteIndex_of_finite_quotient
rw [Nat.card_congr ϕ]
exact hG.index (stabilizer G a)
variable (α) [Finite α]
/-- If `G` is a `p`-group acting on a finite set `α`, then the number of fixed points
of the action is congruent mod `p` to the cardinality of `α` -/
theorem card_modEq_card_fixedPoints : Nat.card α ≡ Nat.card (fixedPoints G α) [MOD p] := by
have := Fintype.ofFinite α
have := Fintype.ofFinite (fixedPoints G α)
rw [Nat.card_eq_fintype_card, Nat.card_eq_fintype_card]
classical
calc
card α = card (Σ y : Quotient (orbitRel G α), { x // Quotient.mk'' x = y }) :=
card_congr (Equiv.sigmaFiberEquiv (@Quotient.mk'' _ (orbitRel G α))).symm
_ = ∑ a : Quotient (orbitRel G α), card { x // Quotient.mk'' x = a } := card_sigma
_ ≡ ∑ _a : fixedPoints G α, 1 [MOD p] := ?_
_ = _ := by simp
rw [← ZMod.natCast_eq_natCast_iff _ _ p, Nat.cast_sum, Nat.cast_sum]
have key :
∀ x,
card { y // (Quotient.mk'' y : Quotient (orbitRel G α)) = Quotient.mk'' x } =
card (orbit G x) :=
fun x => by simp only [Quotient.eq'']; congr
refine
Eq.symm
(Finset.sum_bij_ne_zero (fun a _ _ => Quotient.mk'' a.1) (fun _ _ _ => Finset.mem_univ _)
(fun a₁ _ _ a₂ _ _ h =>
Subtype.eq (mem_fixedPoints'.mp a₂.2 a₁.1 (Quotient.exact' h)))
(fun b => Quotient.inductionOn' b fun b _ hb => ?_) fun a ha _ => by
rw [key, mem_fixedPoints_iff_card_orbit_eq_one.mp a.2])
obtain ⟨k, hk⟩ := hG.card_orbit b
rw [Nat.card_eq_fintype_card] at hk
have : k = 0 := by
contrapose! hb
simp [-Quotient.eq, key, hk, hb]
exact
⟨⟨b, mem_fixedPoints_iff_card_orbit_eq_one.2 <| by rw [hk, this, pow_zero]⟩,
Finset.mem_univ _, ne_of_eq_of_ne Nat.cast_one one_ne_zero, rfl⟩
/-- If a p-group acts on `α` and the cardinality of `α` is not a multiple
of `p` then the action has a fixed point. -/
theorem nonempty_fixed_point_of_prime_not_dvd_card (α) [MulAction G α] (hpα : ¬p ∣ Nat.card α) :
(fixedPoints G α).Nonempty :=
have : Finite α := Nat.finite_of_card_ne_zero (fun h ↦ (h ▸ hpα) (dvd_zero p))
@Set.Nonempty.of_subtype _ _
(by
rw [← Finite.card_pos_iff, pos_iff_ne_zero]
contrapose! hpα
rw [← Nat.modEq_zero_iff_dvd, ← hpα]
exact hG.card_modEq_card_fixedPoints α)
/-- If a p-group acts on `α` and the cardinality of `α` is a multiple
of `p`, and the action has one fixed point, then it has another fixed point. -/
theorem exists_fixed_point_of_prime_dvd_card_of_fixed_point (hpα : p ∣ Nat.card α) {a : α}
(ha : a ∈ fixedPoints G α) : ∃ b, b ∈ fixedPoints G α ∧ a ≠ b := by
have hpf : p ∣ Nat.card (fixedPoints G α) :=
Nat.modEq_zero_iff_dvd.mp ((hG.card_modEq_card_fixedPoints α).symm.trans hpα.modEq_zero_nat)
have hα : 1 < Nat.card (fixedPoints G α) :=
(Fact.out (p := p.Prime)).one_lt.trans_le (Nat.le_of_dvd (Finite.card_pos_iff.2 ⟨⟨a, ha⟩⟩) hpf)
rw [Finite.one_lt_card_iff_nontrivial] at hα
exact
let ⟨⟨b, hb⟩, hba⟩ := exists_ne (⟨a, ha⟩ : fixedPoints G α)
⟨b, hb, fun hab => hba (by simp_rw [hab])⟩
theorem center_nontrivial [Nontrivial G] [Finite G] : Nontrivial (Subgroup.center G) := by
classical
have := (hG.of_equiv ConjAct.toConjAct).exists_fixed_point_of_prime_dvd_card_of_fixed_point G
rw [ConjAct.fixedPoints_eq_center] at this
have dvd : p ∣ Nat.card G := by
obtain ⟨n, hn0, hn⟩ := hG.nontrivial_iff_card.mp inferInstance
exact hn.symm ▸ dvd_pow_self _ (ne_of_gt hn0)
obtain ⟨g, hg⟩ := this dvd (Subgroup.center G).one_mem
exact ⟨⟨1, ⟨g, hg.1⟩, mt Subtype.ext_iff.mp hg.2⟩⟩
theorem bot_lt_center [Nontrivial G] [Finite G] : ⊥ < Subgroup.center G := by
haveI := center_nontrivial hG
classical exact
bot_lt_iff_ne_bot.mpr ((Subgroup.center G).one_lt_card_iff_ne_bot.mp Finite.one_lt_card)
end GIsPGroup
theorem to_le {H K : Subgroup G} (hK : IsPGroup p K) (hHK : H ≤ K) : IsPGroup p H :=
hK.of_injective (Subgroup.inclusion hHK) fun a b h =>
Subtype.ext (by
change ((Subgroup.inclusion hHK) a : G) = (Subgroup.inclusion hHK) b
apply Subtype.ext_iff.mp h)
theorem to_inf_left {H K : Subgroup G} (hH : IsPGroup p H) : IsPGroup p (H ⊓ K : Subgroup G) :=
hH.to_le inf_le_left
theorem to_inf_right {H K : Subgroup G} (hK : IsPGroup p K) : IsPGroup p (H ⊓ K : Subgroup G) :=
hK.to_le inf_le_right
theorem map {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : G →* K) :
IsPGroup p (H.map ϕ) := by
rw [← H.range_subtype, MonoidHom.map_range]
exact hH.of_surjective (ϕ.restrict H).rangeRestrict (ϕ.restrict H).rangeRestrict_surjective
theorem comap_of_ker_isPGroup {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K]
(ϕ : K →* G) (hϕ : IsPGroup p ϕ.ker) : IsPGroup p (H.comap ϕ) := by
intro g
obtain ⟨j, hj⟩ := hH ⟨ϕ g.1, g.2⟩
rw [Subtype.ext_iff, H.coe_pow, Subtype.coe_mk, ← ϕ.map_pow] at hj
obtain ⟨k, hk⟩ := hϕ ⟨g.1 ^ p ^ j, hj⟩
rw [Subtype.ext_iff, ϕ.ker.coe_pow, Subtype.coe_mk, ← pow_mul, ← pow_add] at hk
exact ⟨j + k, by rwa [Subtype.ext_iff, (H.comap ϕ).coe_pow]⟩
theorem ker_isPGroup_of_injective {K : Type*} [Group K] {ϕ : K →* G} (hϕ : Function.Injective ϕ) :
IsPGroup p ϕ.ker :=
(congr_arg (fun Q : Subgroup K => IsPGroup p Q) (ϕ.ker_eq_bot_iff.mpr hϕ)).mpr IsPGroup.of_bot
theorem comap_of_injective {H : Subgroup G} (hH : IsPGroup p H) {K : Type*} [Group K] (ϕ : K →* G)
(hϕ : Function.Injective ϕ) : IsPGroup p (H.comap ϕ) :=
hH.comap_of_ker_isPGroup ϕ (ker_isPGroup_of_injective hϕ)
theorem comap_subtype {H : Subgroup G} (hH : IsPGroup p H) {K : Subgroup G} :
IsPGroup p (H.comap K.subtype) :=
hH.comap_of_injective K.subtype Subtype.coe_injective
theorem to_sup_of_normal_right {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K)
[K.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := by
rw [← QuotientGroup.ker_mk' K, ← Subgroup.comap_map_eq]
apply (hH.map (QuotientGroup.mk' K)).comap_of_ker_isPGroup
rwa [QuotientGroup.ker_mk']
theorem to_sup_of_normal_left {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K)
[H.Normal] : IsPGroup p (H ⊔ K : Subgroup G) := sup_comm H K ▸ to_sup_of_normal_right hK hH
theorem to_sup_of_normal_right' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K)
(hHK : H ≤ K.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) :=
let hHK' :=
to_sup_of_normal_right (hH.of_equiv (Subgroup.subgroupOfEquivOfLe hHK).symm)
(hK.of_equiv (Subgroup.subgroupOfEquivOfLe Subgroup.le_normalizer).symm)
((congr_arg (fun H : Subgroup K.normalizer => IsPGroup p H)
(Subgroup.sup_subgroupOf_eq hHK Subgroup.le_normalizer)).mp
hHK').of_equiv
(Subgroup.subgroupOfEquivOfLe (sup_le hHK Subgroup.le_normalizer))
theorem to_sup_of_normal_left' {H K : Subgroup G} (hH : IsPGroup p H) (hK : IsPGroup p K)
(hHK : K ≤ H.normalizer) : IsPGroup p (H ⊔ K : Subgroup G) :=
sup_comm H K ▸ to_sup_of_normal_right' hK hH hHK
/-- finite p-groups with different p have coprime orders -/
theorem coprime_card_of_ne {G₂ : Type*} [Group G₂] (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime]
[hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂) (H₁ : Subgroup G) (H₂ : Subgroup G₂) [Finite H₁]
[Finite H₂] (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) :
Nat.Coprime (Nat.card H₁) (Nat.card H₂) := by
obtain ⟨n₁, heq₁⟩ := iff_card.mp hH₁; rw [heq₁]; clear heq₁
obtain ⟨n₂, heq₂⟩ := iff_card.mp hH₂; rw [heq₂]; clear heq₂
exact Nat.coprime_pow_primes _ _ hp₁.elim hp₂.elim hne
/-- p-groups with different p are disjoint -/
theorem disjoint_of_ne (p₁ p₂ : ℕ) [hp₁ : Fact p₁.Prime] [hp₂ : Fact p₂.Prime] (hne : p₁ ≠ p₂)
(H₁ H₂ : Subgroup G) (hH₁ : IsPGroup p₁ H₁) (hH₂ : IsPGroup p₂ H₂) : Disjoint H₁ H₂ := by
rw [Subgroup.disjoint_def]
intro x hx₁ hx₂
obtain ⟨n₁, hn₁⟩ := iff_orderOf.mp hH₁ ⟨x, hx₁⟩
obtain ⟨n₂, hn₂⟩ := iff_orderOf.mp hH₂ ⟨x, hx₂⟩
rw [Subgroup.orderOf_mk] at hn₁ hn₂
have : p₁ ^ n₁ = p₂ ^ n₂ := by rw [← hn₁, ← hn₂]
rcases n₁.eq_zero_or_pos with (rfl | hn₁)
· simpa using hn₁
· exact absurd (eq_of_prime_pow_eq hp₁.out.prime hp₂.out.prime hn₁ this) hne
theorem le_or_disjoint_of_coprime [hp : Fact p.Prime] {P : Subgroup G} (hP : IsPGroup p P)
{H : Subgroup G} [H.Normal] (h_cop : (Nat.card H).Coprime H.index) :
P ≤ H ∨ Disjoint H P := by
by_cases h1 : Nat.card H = 0
· rw [h1, Nat.coprime_zero_left, Subgroup.index_eq_one] at h_cop
rw [h_cop]
exact Or.inl le_top
by_cases h2 : H.index = 0
· rw [h2, Nat.coprime_zero_right, Subgroup.card_eq_one] at h_cop
rw [h_cop]
exact Or.inr disjoint_bot_left
have : Finite G := by
apply Nat.finite_of_card_ne_zero
rw [← H.card_mul_index]
exact mul_ne_zero h1 h2
have h3 : (Nat.card H).Coprime (Nat.card P) ∨ H.index.Coprime (Nat.card P) := by
obtain ⟨k, hk⟩ := hP.exists_card_eq
refine hk ▸ Or.imp hp.out.coprime_pow_of_not_dvd hp.out.coprime_pow_of_not_dvd ?_
contrapose! h_cop
exact Nat.Prime.not_coprime_iff_dvd.mpr ⟨p, hp.out, h_cop⟩
refine h3.symm.imp (fun h4 ↦ ?_) (fun h4 ↦ ?_)
· rw [← Subgroup.relindex_eq_one]
exact Nat.eq_one_of_dvd_coprimes h4 (H.relindex_dvd_index_of_normal P)
(Subgroup.relindex_dvd_card H P)
· exact disjoint_iff.mpr (Subgroup.inf_eq_bot_of_coprime h4)
section P2comm
variable [Fact p.Prime] {n : ℕ}
open Subgroup
/-- The cardinality of the `center` of a `p`-group is `p ^ k` where `k` is positive. -/
theorem card_center_eq_prime_pow (hGpn : Nat.card G = p ^ n) (hn : 0 < n) :
∃ k > 0, Nat.card (center G) = p ^ k := by
have : Finite G := Nat.finite_of_card_ne_zero (hGpn ▸ pow_ne_zero n (NeZero.ne p))
have hcG := to_subgroup (of_card hGpn) (center G)
rcases iff_card.1 hcG with _
haveI : Nontrivial G := (nontrivial_iff_card <| of_card hGpn).2 ⟨n, hn, hGpn⟩
exact (nontrivial_iff_card hcG).mp (center_nontrivial (of_card hGpn))
/-- The quotient by the center of a group of cardinality `p ^ 2` is cyclic. -/
theorem cyclic_center_quotient_of_card_eq_prime_sq (hG : Nat.card G = p ^ 2) :
IsCyclic (G ⧸ center G) := by
apply isCyclic_of_card_dvd_prime (p := p)
rw [← mul_dvd_mul_iff_left (NeZero.ne p), ← sq, ← hG, ← (center G).card_mul_index]
apply mul_dvd_mul_right
rcases card_center_eq_prime_pow hG zero_lt_two with ⟨k, hk0, hk⟩
rw [hk]
exact dvd_pow_self p hk0.ne'
/-- A group of order `p ^ 2` is commutative. See also `IsPGroup.commutative_of_card_eq_prime_sq`
for just the proof that `∀ a b, a * b = b * a` -/
def commGroupOfCardEqPrimeSq (hG : Nat.card G = p ^ 2) : CommGroup G :=
@commGroupOfCyclicCenterQuotient _ _ _ _ (cyclic_center_quotient_of_card_eq_prime_sq hG) _
(QuotientGroup.ker_mk' (center G)).le
/-- A group of order `p ^ 2` is commutative. See also `IsPGroup.commGroupOfCardEqPrimeSq`
for the `CommGroup` instance. -/
theorem commutative_of_card_eq_prime_sq (hG : Nat.card G = p ^ 2) : ∀ a b : G, a * b = b * a :=
(commGroupOfCardEqPrimeSq hG).mul_comm
end P2comm
end IsPGroup
namespace ZModModule
variable {n : ℕ} {G : Type*} [AddCommGroup G] [Module (ZMod n) G]
lemma isPGroup_multiplicative : IsPGroup n (Multiplicative G) := by
simpa [IsPGroup, Multiplicative.forall] using
fun _ ↦ ⟨1, by simp [← ofAdd_nsmul, ZModModule.char_nsmul_eq_zero]⟩
end ZModModule
|
Basic.lean
|
/-
Copyright (c) 2022 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.Topology.Algebra.Module.CharacterSpace
import Mathlib.Analysis.Normed.Module.WeakDual
import Mathlib.Analysis.Normed.Algebra.Spectrum
/-!
# Normed algebras
This file contains basic facts about normed algebras.
## Main results
* We show that the character space of a normed algebra is compact using the Banach-Alaoglu theorem.
## TODO
* Show compactness for topological vector spaces; this requires the TVS version of Banach-Alaoglu.
## Tags
normed algebra, character space, continuous functional calculus
-/
variable {𝕜 : Type*} {A : Type*}
namespace WeakDual
namespace CharacterSpace
variable [NontriviallyNormedField 𝕜] [NormedRing A] [NormedAlgebra 𝕜 A] [CompleteSpace A]
theorem norm_le_norm_one (φ : characterSpace 𝕜 A) : ‖toStrongDual (φ : WeakDual 𝕜 A)‖ ≤ ‖(1 : A)‖ :=
ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg (1 : A)) fun a =>
mul_comm ‖a‖ ‖(1 : A)‖ ▸ spectrum.norm_le_norm_mul_of_mem (apply_mem_spectrum φ a)
instance [ProperSpace 𝕜] : CompactSpace (characterSpace 𝕜 A) := by
rw [← isCompact_iff_compactSpace]
have h : characterSpace 𝕜 A ⊆ toStrongDual ⁻¹' Metric.closedBall 0 ‖(1 : A)‖ := by
intro φ hφ
rw [Set.mem_preimage, mem_closedBall_zero_iff]
exact (norm_le_norm_one ⟨φ, ⟨hφ.1, hφ.2⟩⟩ :)
exact (isCompact_closedBall 𝕜 0 _).of_isClosed_subset CharacterSpace.isClosed h
end CharacterSpace
end WeakDual
|
ssrfun.v
|
From mathcomp Require Import ssreflect.
From Corelib Require Export ssrfun.
From mathcomp Require Export ssrnotations.
#[export] Set Warnings "-overwriting-delimiting-key".
(* remove above line when requiring Rocq >= 9.0 *)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(******************)
(* v9.1 additions *)
(******************)
#[export] Set Warnings "-hiding-delimiting-key".
Delimit Scope function_scope with FUN.
Declare Scope fun_scope.
Close Scope fun_scope.
Definition injective2 (rT aT1 aT2 : Type) (f : aT1 -> aT2 -> rT) :=
forall (x1 x2 : aT1) (y1 y2 : aT2), f x1 y1 = f x2 y2 -> (x1 = x2) * (y1 = y2).
Arguments injective2 [rT aT1 aT2] f.
Lemma inj_omap {aT rT : Type} (f : aT -> rT) :
injective f -> injective (omap f).
Proof. by move=> injf [?|] [?|] //= [/injf->]. Qed.
Lemma omap_id {T : Type} (x : option T) : omap id x = x.
Proof. by case: x. Qed.
Lemma eq_omap {aT rT : Type} (f g : aT -> rT) : f =1 g -> omap f =1 omap g.
Proof. by move=> Ef [?|] //=; rewrite Ef. Qed.
Lemma omapK {aT rT : Type} (f : aT -> rT) (g : rT -> aT) :
cancel f g -> cancel (omap f) (omap g).
Proof. by move=> fK [?|] //=; rewrite fK. Qed.
Definition idempotent_op (S : Type) (op : S -> S -> S) := forall x, op x x = x.
#[deprecated(since="mathcomp 2.3.0", note="use `idempotent_op` instead")]
Notation idempotent:= idempotent_op (only parsing).
Definition idempotent_fun (U : Type) (f : U -> U) := f \o f =1 f.
Lemma inr_inj {A B} : injective (@inr A B). Proof. by move=> ? ? []. Qed.
Lemma inl_inj {A B} : injective (@inl A B). Proof. by move=> ? ? []. Qed.
(**********************)
(* not yet backported *)
(**********************)
Lemma taggedK {I : Type} (T_ : I -> Type) (s : {i : I & T_ i}) :
Tagged T_ (tagged s) = s.
Proof. by case: s. Qed.
Definition swap_pair {T1 T2 : Type} (x : T1 * T2) := (x.2, x.1).
(* Note that this lemma coudn't be an instance of the [involutive] predicate. *)
Lemma swap_pairK {T1 T2 : Type} : @cancel _ (T1 * T2) swap_pair swap_pair.
Proof. by case. Qed.
|
Tactic.lean
|
/-
Copyright (c) 2022 Arthur Paulino. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arthur Paulino, Jannis Limperg
-/
import Mathlib.Init
import Lean.MetavarContext
/-!
# Miscellaneous helper functions for tactics.
[TODO] Ideally we would find good homes for everything in this file, eventually removing it.
-/
namespace Mathlib.Tactic
open Lean Meta Tactic
variable {m : Type → Type}
/--
`modifyMetavarDecl mvarId f` updates the `MetavarDecl` for `mvarId` with `f`.
Conditions on `f`:
- The target of `f mdecl` is defeq to the target of `mdecl`.
- The local context of `f mdecl` must contain the same fvars as the local
context of `mdecl`. For each fvar in the local context of `f mdecl`, the type
(and value, if any) of the fvar must be defeq to the corresponding fvar in
the local context of `mdecl`.
If `mvarId` does not refer to a declared metavariable, nothing happens.
-/
def modifyMetavarDecl [MonadMCtx m] (mvarId : MVarId)
(f : MetavarDecl → MetavarDecl) : m Unit :=
modifyMCtx fun mctx ↦
match mctx.decls.find? mvarId with
| none => mctx
| some mdecl => { mctx with decls := mctx.decls.insert mvarId (f mdecl) }
/--
`modifyTarget mvarId f` updates the target of the metavariable `mvarId` with
`f`. For any `e`, `f e` must be defeq to `e`. If `mvarId` does not refer to
a declared metavariable, nothing happens.
-/
def modifyTarget [MonadMCtx m] (mvarId : MVarId) (f : Expr → Expr) : m Unit :=
modifyMetavarDecl mvarId fun mdecl ↦
{ mdecl with type := f mdecl.type }
/--
`modifyLocalContext mvarId f` updates the local context of the metavariable
`mvarId` with `f`. The new local context must contain the same fvars as the old
local context and the types (and values, if any) of the fvars in the new local
context must be defeq to their equivalents in the old local context.
If `mvarId` does not refer to a declared metavariable, nothing happens.
-/
def modifyLocalContext [MonadMCtx m] (mvarId : MVarId)
(f : LocalContext → LocalContext) : m Unit :=
modifyMetavarDecl mvarId fun mdecl ↦
{ mdecl with lctx := f mdecl.lctx }
/--
`modifyLocalDecl mvarId fvarId f` updates the local decl `fvarId` in the local
context of `mvarId` with `f`. `f` must leave the `fvarId` and `index` of the
`LocalDecl` unchanged. The type of the new `LocalDecl` must be defeq to the type
of the old `LocalDecl` (and the same applies to the value of the `LocalDecl`, if
any).
If `mvarId` does not refer to a declared metavariable or if `fvarId` does not
exist in the local context of `mvarId`, nothing happens.
-/
def modifyLocalDecl [MonadMCtx m] (mvarId : MVarId) (fvarId : FVarId)
(f : LocalDecl → LocalDecl) : m Unit :=
modifyLocalContext mvarId fun lctx ↦ lctx.modifyLocalDecl fvarId f
end Mathlib.Tactic
|
Basic.lean
|
/-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.EssentiallySmall
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.CategoryTheory.Subobject.Lattice
import Mathlib.Data.Set.Opposite
/-!
# Separating and detecting sets
There are several non-equivalent notions of a generator of a category. Here, we consider two of
them:
* We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`.
* We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism.
There are, of course, also the dual notions of coseparating and codetecting sets.
## Main results
We
* define predicates `IsSeparating`, `IsCoseparating`, `IsDetecting` and `IsCodetecting` on
sets of objects;
* show that equivalences of categories preserves these notions;
* show that separating and coseparating are dual notions;
* show that detecting and codetecting are dual notions;
* show that if `C` has equalizers, then detecting implies separating;
* show that if `C` has coequalizers, then codetecting implies coseparating;
* show that if `C` is balanced, then separating implies detecting and coseparating implies
codetecting;
* show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin;
* show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid;
* define predicates `IsSeparator`, `IsCoseparator`, `IsDetector` and `IsCodetector` as the
singleton counterparts to the definitions for sets above and restate the above results in this
situation;
* show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual);
* show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the
dual);
* show that `C` is `WellPowered` if it admits small pullbacks and a detector;
* define corresponding typeclasses `HasSeparator`, `HasCoseparator`, `HasDetector`
and `HasCodetector` on categories and prove analogous results for these.
## Future work
* We currently don't have any examples yet.
-/
universe w v₁ v₂ u₁ u₂
open CategoryTheory.Limits Opposite
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
/-- We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/
def IsSeparating (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ X), h ≫ f = h ≫ g) → f = g
/-- We say that `𝒢` is a coseparating set if the functors `C(-, G)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/
def IsCoseparating (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g
/-- We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. -/
def IsDetecting (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ Y), ∃! h' : G ⟶ X, h' ≫ f = h) → IsIso f
/-- We say that `𝒢` is a codetecting set if the functors `C(-, G)` collectively reflect
isomorphisms, i.e., if any `h` with codomain in `G` uniquely factors through `f`, then `f` is
an isomorphism. -/
def IsCodetecting (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : X ⟶ G), ∃! h' : Y ⟶ G, f ≫ h' = h) → IsIso f
section Equivalence
lemma IsSeparating.of_equivalence
{𝒢 : Set C} (h : IsSeparating 𝒢) {D : Type*} [Category D] (α : C ≌ D) :
IsSeparating (α.functor.obj '' 𝒢) := fun X Y f g H =>
α.inverse.map_injective (h _ _ (fun Z hZ h => by
obtain ⟨h', rfl⟩ := (α.toAdjunction.homEquiv _ _).surjective h
simp only [Adjunction.homEquiv_unit, Category.assoc, ← Functor.map_comp,
H (α.functor.obj Z) (Set.mem_image_of_mem _ hZ) h']))
lemma IsCoseparating.of_equivalence
{𝒢 : Set C} (h : IsCoseparating 𝒢) {D : Type*} [Category D] (α : C ≌ D) :
IsCoseparating (α.functor.obj '' 𝒢) := fun X Y f g H =>
α.inverse.map_injective (h _ _ (fun Z hZ h => by
obtain ⟨h', rfl⟩ := (α.symm.toAdjunction.homEquiv _ _).symm.surjective h
simp only [Adjunction.homEquiv_symm_apply, ← Category.assoc, ← Functor.map_comp,
Equivalence.symm_functor, H (α.functor.obj Z) (Set.mem_image_of_mem _ hZ) h']))
end Equivalence
section Dual
theorem isSeparating_op_iff (𝒢 : Set C) : IsSeparating 𝒢.op ↔ IsCoseparating 𝒢 := by
refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩
· refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_)
simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _
· refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_)
simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _
theorem isCoseparating_op_iff (𝒢 : Set C) : IsCoseparating 𝒢.op ↔ IsSeparating 𝒢 := by
refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩
· refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_)
simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _
· refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_)
simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _
theorem isCoseparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsCoseparating 𝒢.unop ↔ IsSeparating 𝒢 := by
rw [← isSeparating_op_iff, Set.unop_op]
theorem isSeparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsSeparating 𝒢.unop ↔ IsCoseparating 𝒢 := by
rw [← isCoseparating_op_iff, Set.unop_op]
theorem isDetecting_op_iff (𝒢 : Set C) : IsDetecting 𝒢.op ↔ IsCodetecting 𝒢 := by
refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩
· refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop
exact
⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩
· refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op
refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩
exact Quiver.Hom.unop_inj (by simpa only using hy)
theorem isCodetecting_op_iff (𝒢 : Set C) : IsCodetecting 𝒢.op ↔ IsDetecting 𝒢 := by
refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩
· refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop
exact
⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩
· refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op
refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩
exact Quiver.Hom.unop_inj (by simpa only using hy)
theorem isDetecting_unop_iff (𝒢 : Set Cᵒᵖ) : IsDetecting 𝒢.unop ↔ IsCodetecting 𝒢 := by
rw [← isCodetecting_op_iff, Set.unop_op]
theorem isCodetecting_unop_iff {𝒢 : Set Cᵒᵖ} : IsCodetecting 𝒢.unop ↔ IsDetecting 𝒢 := by
rw [← isDetecting_op_iff, Set.unop_op]
end Dual
theorem IsDetecting.isSeparating [HasEqualizers C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) :
IsSeparating 𝒢 := fun _ _ f g hfg =>
have : IsIso (equalizer.ι f g) := h𝒢 _ fun _ hG _ => equalizer.existsUnique _ (hfg _ hG _)
eq_of_epi_equalizer
theorem IsCodetecting.isCoseparating [HasCoequalizers C] {𝒢 : Set C} :
IsCodetecting 𝒢 → IsCoseparating 𝒢 := by
simpa only [← isSeparating_op_iff, ← isDetecting_op_iff] using IsDetecting.isSeparating
theorem IsSeparating.isDetecting [Balanced C] {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) :
IsDetecting 𝒢 := by
intro X Y f hf
refine
(isIso_iff_mono_and_epi _).2 ⟨⟨fun g h hgh => h𝒢 _ _ fun G hG i => ?_⟩, ⟨fun g h hgh => ?_⟩⟩
· obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f)
rw [ht (i ≫ g) (Category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ Category.assoc _ _ _)]
· refine h𝒢 _ _ fun G hG i => ?_
obtain ⟨t, rfl, -⟩ := hf G hG i
rw [Category.assoc, hgh, Category.assoc]
lemma IsDetecting.isIso_iff_of_mono {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢)
{X Y : C} (f : X ⟶ Y) [Mono f] :
IsIso f ↔ ∀ s ∈ 𝒢, Function.Surjective ((coyoneda.obj (op s)).map f) := by
constructor
· intro h
rw [isIso_iff_yoneda_map_bijective] at h
intro A _
exact (h A).2
· intro hf
refine h𝒢 _ (fun A hA g ↦ existsUnique_of_exists_of_unique ?_ ?_)
· exact hf A hA g
· intro l₁ l₂ h₁ h₂
rw [← cancel_mono f, h₁, h₂]
lemma IsCodetecting.isIso_iff_of_epi {𝒢 : Set C} (h𝒢 : IsCodetecting 𝒢)
{X Y : C} (f : X ⟶ Y) [Epi f] :
IsIso f ↔ ∀ s ∈ 𝒢, Function.Surjective ((yoneda.obj s).map f.op) := by
constructor
· intro h
rw [isIso_iff_coyoneda_map_bijective] at h
intro A _
exact (h A).2
· intro hf
refine h𝒢 _ (fun A hA g ↦ existsUnique_of_exists_of_unique ?_ ?_)
· exact hf A hA g
· intro l₁ l₂ h₁ h₂
rw [← cancel_epi f, h₁, h₂]
section
attribute [local instance] balanced_opposite
theorem IsCoseparating.isCodetecting [Balanced C] {𝒢 : Set C} :
IsCoseparating 𝒢 → IsCodetecting 𝒢 := by
simpa only [← isDetecting_op_iff, ← isSeparating_op_iff] using IsSeparating.isDetecting
end
theorem isDetecting_iff_isSeparating [HasEqualizers C] [Balanced C] (𝒢 : Set C) :
IsDetecting 𝒢 ↔ IsSeparating 𝒢 :=
⟨IsDetecting.isSeparating, IsSeparating.isDetecting⟩
theorem isCodetecting_iff_isCoseparating [HasCoequalizers C] [Balanced C] {𝒢 : Set C} :
IsCodetecting 𝒢 ↔ IsCoseparating 𝒢 :=
⟨IsCodetecting.isCoseparating, IsCoseparating.isCodetecting⟩
section Mono
theorem IsSeparating.mono {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsSeparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _
theorem IsCoseparating.mono {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsCoseparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _
theorem IsDetecting.mono {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsDetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _
theorem IsCodetecting.mono {𝒢 : Set C} (h𝒢 : IsCodetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsCodetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _
end Mono
section Empty
theorem thin_of_isSeparating_empty (h : IsSeparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ =>
⟨fun _ _ => h _ _ fun _ => False.elim⟩
theorem isSeparating_empty_of_thin [Quiver.IsThin C] : IsSeparating (∅ : Set C) :=
fun _ _ _ _ _ => Subsingleton.elim _ _
theorem thin_of_isCoseparating_empty (h : IsCoseparating (∅ : Set C)) : Quiver.IsThin C :=
fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩
theorem isCoseparating_empty_of_thin [Quiver.IsThin C] : IsCoseparating (∅ : Set C) :=
fun _ _ _ _ _ => Subsingleton.elim _ _
theorem groupoid_of_isDetecting_empty (h : IsDetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) :
IsIso f :=
h _ fun _ => False.elim
theorem isDetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] :
IsDetecting (∅ : Set C) := fun _ _ _ _ => inferInstance
theorem groupoid_of_isCodetecting_empty (h : IsCodetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) :
IsIso f :=
h _ fun _ => False.elim
theorem isCodetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] :
IsCodetecting (∅ : Set C) := fun _ _ _ _ => inferInstance
end Empty
theorem isSeparating_iff_epi (𝒢 : Set C)
[∀ A : C, HasCoproduct fun f : Σ G : 𝒢, (G : C) ⟶ A => (f.1 : C)] :
IsSeparating 𝒢 ↔ ∀ A : C, Epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ A)) := by
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using Sigma.ι (fun f : Σ G : 𝒢, (G : C) ⟶ A => (f.1 : C)) ⟨⟨G, hG⟩, f⟩ ≫= huv
· haveI := h X
refine
(cancel_epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ X))).1 (colimit.hom_ext fun j => ?_)
simpa using hh j.as.1.1 j.as.1.2 j.as.2
theorem isCoseparating_iff_mono (𝒢 : Set C)
[∀ A : C, HasProduct fun f : Σ G : 𝒢, A ⟶ (G : C) => (f.1 : C)] :
IsCoseparating 𝒢 ↔ ∀ A : C, Mono (Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C))) := by
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using huv =≫ Pi.π (fun f : Σ G : 𝒢, A ⟶ (G : C) => (f.1 : C)) ⟨⟨G, hG⟩, f⟩
· haveI := h Y
refine (cancel_mono (Pi.lift (@Sigma.snd 𝒢 fun G => Y ⟶ (G : C)))).1 (limit.hom_ext fun j => ?_)
simpa using hh j.as.1.1 j.as.1.2 j.as.2
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a complete well-powered
category with a small coseparating set has an initial object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already cocomplete,
see `hasColimits_of_hasLimits_of_isCoseparating`. -/
theorem hasInitial_of_isCoseparating [LocallySmall.{w} C] [WellPowered.{w} C]
[HasLimitsOfSize.{w, w} C] {𝒢 : Set C} [Small.{w} 𝒢]
(h𝒢 : IsCoseparating 𝒢) : HasInitial C := by
have := hasFiniteLimits_of_hasLimitsOfSize C
haveI : HasProductsOfShape 𝒢 C := hasProductsOfShape_of_small C 𝒢
haveI := fun A => hasProductsOfShape_of_small.{w} C (Σ G : 𝒢, A ⟶ (G : C))
letI := completeLatticeOfCompleteSemilatticeInf (Subobject (piObj (Subtype.val : 𝒢 → C)))
suffices ∀ A : C, Unique (((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C) ⟶ A) by
exact hasInitial_of_unique ((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C)
refine fun A => ⟨⟨?_⟩, fun f => ?_⟩
· let s := Pi.lift fun f : Σ G : 𝒢, A ⟶ (G : C) => id (Pi.π (Subtype.val : 𝒢 → C)) f.1
let t := Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C))
haveI : Mono t := (isCoseparating_iff_mono 𝒢).1 h𝒢 A
exact Subobject.ofLEMk _ (pullback.fst _ _ : pullback s t ⟶ _) bot_le ≫ pullback.snd _ _
· suffices ∀ (g : Subobject.underlying.obj ⊥ ⟶ A), f = g by
apply this
intro g
suffices IsSplitEpi (equalizer.ι f g) by exact eq_of_epi_equalizer
exact IsSplitEpi.mk' ⟨Subobject.ofLEMk _ (equalizer.ι f g ≫ Subobject.arrow _) bot_le, by
ext
simp⟩
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a cocomplete well-copowered
category with a small separating set has a terminal object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already complete, see
`hasLimits_of_hasColimits_of_isSeparating`. -/
theorem hasTerminal_of_isSeparating [LocallySmall.{w} Cᵒᵖ] [WellPowered.{w} Cᵒᵖ]
[HasColimitsOfSize.{w, w} C] {𝒢 : Set C} [Small.{w} 𝒢]
(h𝒢 : IsSeparating 𝒢) : HasTerminal C := by
haveI : Small.{w} 𝒢.op := small_of_injective (Set.opEquiv_self 𝒢).injective
haveI : HasInitial Cᵒᵖ := hasInitial_of_isCoseparating ((isCoseparating_op_iff _).2 h𝒢)
exact hasTerminal_of_hasInitial_op
section WellPowered
namespace Subobject
theorem eq_of_le_of_isDetecting {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C} (P Q : Subobject X)
(h₁ : P ≤ Q) (h₂ : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, Q.Factors f → P.Factors f) : P = Q := by
suffices IsIso (ofLE _ _ h₁) by exact le_antisymm h₁ (le_of_comm (inv (ofLE _ _ h₁)) (by simp))
refine h𝒢 _ fun G hG f => ?_
have : P.Factors (f ≫ Q.arrow) := h₂ _ hG ((factors_iff _ _).2 ⟨_, rfl⟩)
refine ⟨factorThru _ _ this, ?_, fun g (hg : g ≫ _ = f) => ?_⟩
· simp only [← cancel_mono Q.arrow, Category.assoc, ofLE_arrow, factorThru_arrow]
· simp only [← cancel_mono (Subobject.ofLE _ _ h₁), ← cancel_mono Q.arrow, hg, Category.assoc,
ofLE_arrow, factorThru_arrow]
theorem inf_eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C}
(P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f → Q.Factors f) : P ⊓ Q = P :=
eq_of_le_of_isDetecting h𝒢 _ _ _root_.inf_le_left
fun _ hG _ hf => (inf_factors _).2 ⟨hf, h _ hG hf⟩
theorem eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C}
(P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f ↔ Q.Factors f) : P = Q :=
calc
P = P ⊓ Q := Eq.symm <| inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).1 hf
_ = Q ⊓ P := inf_comm ..
_ = Q := inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).2 hf
end Subobject
/-- A category with pullbacks and a small detecting set is well-powered. -/
theorem wellPowered_of_isDetecting [HasPullbacks C] {𝒢 : Set C} [Small.{w} 𝒢]
[LocallySmall.{w} C] (h𝒢 : IsDetecting 𝒢) : WellPowered.{w} C :=
⟨fun X =>
@small_of_injective _ _ _ (fun P : Subobject X => { f : Σ G : 𝒢, G.1 ⟶ X | P.Factors f.2 })
fun P Q h => Subobject.eq_of_isDetecting h𝒢 _ _
(by simpa [Set.ext_iff, Sigma.forall] using h)⟩
end WellPowered
namespace StructuredArrow
variable (S : D) (T : C ⥤ D)
theorem isCoseparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) :
IsCoseparating ((proj S T).obj ⁻¹' 𝒢) := by
refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_)
exact congr_arg CommaMorphism.right (hfg (mk (Y.hom ≫ T.map h)) hG (homMk h rfl))
end StructuredArrow
namespace CostructuredArrow
variable (S : C ⥤ D) (T : D)
theorem isSeparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) :
IsSeparating ((proj S T).obj ⁻¹' 𝒢) := by
refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_)
exact congr_arg CommaMorphism.left (hfg (mk (S.map h ≫ X.hom)) hG (homMk h rfl))
end CostructuredArrow
/-- We say that `G` is a separator if the functor `C(G, -)` is faithful. -/
def IsSeparator (G : C) : Prop :=
IsSeparating ({G} : Set C)
/-- We say that `G` is a coseparator if the functor `C(-, G)` is faithful. -/
def IsCoseparator (G : C) : Prop :=
IsCoseparating ({G} : Set C)
/-- We say that `G` is a detector if the functor `C(G, -)` reflects isomorphisms. -/
def IsDetector (G : C) : Prop :=
IsDetecting ({G} : Set C)
/-- We say that `G` is a codetector if the functor `C(-, G)` reflects isomorphisms. -/
def IsCodetector (G : C) : Prop :=
IsCodetecting ({G} : Set C)
section Equivalence
theorem IsSeparator.of_equivalence {G : C} (h : IsSeparator G) (α : C ≌ D) :
IsSeparator (α.functor.obj G) := by simpa using IsSeparating.of_equivalence h α
theorem IsCoseparator.of_equivalence {G : C} (h : IsCoseparator G) (α : C ≌ D) :
IsCoseparator (α.functor.obj G) := by simpa using IsCoseparating.of_equivalence h α
end Equivalence
section Dual
theorem isSeparator_op_iff (G : C) : IsSeparator (op G) ↔ IsCoseparator G := by
rw [IsSeparator, IsCoseparator, ← isSeparating_op_iff, Set.singleton_op]
theorem isCoseparator_op_iff (G : C) : IsCoseparator (op G) ↔ IsSeparator G := by
rw [IsSeparator, IsCoseparator, ← isCoseparating_op_iff, Set.singleton_op]
theorem isCoseparator_unop_iff (G : Cᵒᵖ) : IsCoseparator (unop G) ↔ IsSeparator G := by
rw [IsSeparator, IsCoseparator, ← isCoseparating_unop_iff, Set.singleton_unop]
theorem isSeparator_unop_iff (G : Cᵒᵖ) : IsSeparator (unop G) ↔ IsCoseparator G := by
rw [IsSeparator, IsCoseparator, ← isSeparating_unop_iff, Set.singleton_unop]
theorem isDetector_op_iff (G : C) : IsDetector (op G) ↔ IsCodetector G := by
rw [IsDetector, IsCodetector, ← isDetecting_op_iff, Set.singleton_op]
theorem isCodetector_op_iff (G : C) : IsCodetector (op G) ↔ IsDetector G := by
rw [IsDetector, IsCodetector, ← isCodetecting_op_iff, Set.singleton_op]
theorem isCodetector_unop_iff (G : Cᵒᵖ) : IsCodetector (unop G) ↔ IsDetector G := by
rw [IsDetector, IsCodetector, ← isCodetecting_unop_iff, Set.singleton_unop]
theorem isDetector_unop_iff (G : Cᵒᵖ) : IsDetector (unop G) ↔ IsCodetector G := by
rw [IsDetector, IsCodetector, ← isDetecting_unop_iff, Set.singleton_unop]
end Dual
theorem IsDetector.isSeparator [HasEqualizers C] {G : C} : IsDetector G → IsSeparator G :=
IsDetecting.isSeparating
theorem IsCodetector.isCoseparator [HasCoequalizers C] {G : C} : IsCodetector G → IsCoseparator G :=
IsCodetecting.isCoseparating
theorem IsSeparator.isDetector [Balanced C] {G : C} : IsSeparator G → IsDetector G :=
IsSeparating.isDetecting
theorem IsCoseparator.isCodetector [Balanced C] {G : C} : IsCoseparator G → IsCodetector G :=
IsCoseparating.isCodetecting
theorem isSeparator_def (G : C) :
IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
⟨fun hG X Y f g hfg =>
hG _ _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hfg h,
fun hG _ _ _ _ hfg => hG _ _ fun _ => hfg _ (Set.mem_singleton _) _⟩
theorem IsSeparator.def {G : C} :
IsSeparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
(isSeparator_def _).1
theorem isCoseparator_def (G : C) :
IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
⟨fun hG X Y f g hfg =>
hG _ _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hfg h,
fun hG _ _ _ _ hfg => hG _ _ fun _ => hfg _ (Set.mem_singleton _) _⟩
theorem IsCoseparator.def {G : C} :
IsCoseparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
(isCoseparator_def _).1
theorem isDetector_def (G : C) :
IsDetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f :=
⟨fun hG X Y f hf =>
hG _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hf h,
fun hG _ _ _ hf => hG _ fun _ => hf _ (Set.mem_singleton _) _⟩
theorem IsDetector.def {G : C} :
IsDetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f :=
(isDetector_def _).1
theorem isCodetector_def (G : C) :
IsCodetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f :=
⟨fun hG X Y f hf =>
hG _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hf h,
fun hG _ _ _ hf => hG _ fun _ => hf _ (Set.mem_singleton _) _⟩
theorem IsCodetector.def {G : C} :
IsCodetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f :=
(isCodetector_def _).1
theorem isSeparator_iff_faithful_coyoneda_obj (G : C) :
IsSeparator G ↔ (coyoneda.obj (op G)).Faithful :=
⟨fun hG => ⟨fun hfg => hG.def _ _ (congr_fun hfg)⟩, fun _ =>
(isSeparator_def _).2 fun _ _ _ _ hfg => (coyoneda.obj (op G)).map_injective (funext hfg)⟩
theorem isCoseparator_iff_faithful_yoneda_obj (G : C) : IsCoseparator G ↔ (yoneda.obj G).Faithful :=
⟨fun hG => ⟨fun hfg => Quiver.Hom.unop_inj (hG.def _ _ (congr_fun hfg))⟩, fun _ =>
(isCoseparator_def _).2 fun _ _ _ _ hfg =>
Quiver.Hom.op_inj <| (yoneda.obj G).map_injective (funext hfg)⟩
theorem isSeparator_iff_epi (G : C) [∀ A : C, HasCoproduct fun _ : G ⟶ A => G] :
IsSeparator G ↔ ∀ A : C, Epi (Sigma.desc fun f : G ⟶ A => f) := by
rw [isSeparator_def]
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using Sigma.ι _ i ≫= huv
· haveI := h X
refine (cancel_epi (Sigma.desc fun f : G ⟶ X => f)).1 (colimit.hom_ext fun j => ?_)
simpa using hh j.as
theorem isCoseparator_iff_mono (G : C) [∀ A : C, HasProduct fun _ : A ⟶ G => G] :
IsCoseparator G ↔ ∀ A : C, Mono (Pi.lift fun f : A ⟶ G => f) := by
rw [isCoseparator_def]
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using huv =≫ Pi.π _ i
· haveI := h Y
refine (cancel_mono (Pi.lift fun f : Y ⟶ G => f)).1 (limit.hom_ext fun j => ?_)
simpa using hh j.as
section ZeroMorphisms
variable [HasZeroMorphisms C]
theorem isSeparator_coprod (G H : C) [HasBinaryCoproduct G H] :
IsSeparator (G ⨿ H) ↔ IsSeparating ({G, H} : Set C) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isSeparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => coprod.hom_ext ?_ ?_
· simpa using huv G (by simp) (coprod.inl ≫ g)
· simpa using huv H (by simp) (coprod.inr ≫ g)
· simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hZ
rcases hZ with (rfl | rfl)
· simpa using coprod.inl ≫= huv (coprod.desc g 0)
· simpa using coprod.inr ≫= huv (coprod.desc 0 g)
theorem isSeparator_coprod_of_isSeparator_left (G H : C) [HasBinaryCoproduct G H]
(hG : IsSeparator G) : IsSeparator (G ⨿ H) :=
(isSeparator_coprod _ _).2 <| IsSeparating.mono hG <| by simp
theorem isSeparator_coprod_of_isSeparator_right (G H : C) [HasBinaryCoproduct G H]
(hH : IsSeparator H) : IsSeparator (G ⨿ H) :=
(isSeparator_coprod _ _).2 <| IsSeparating.mono hH <| by simp
lemma isSeparator_of_isColimit_cofan {β : Type w} {f : β → C}
(hf : IsSeparating (Set.range f)) {c : Cofan f} (hc : IsColimit c) : IsSeparator c.pt := by
refine (isSeparator_def _).2 fun X Y u v huv => hf _ _ fun Z hZ g => ?_
obtain ⟨b, rfl⟩ := Set.mem_range.1 hZ
classical simpa using c.ι.app ⟨b⟩ ≫= huv (hc.desc (Cofan.mk _ (Pi.single b g)))
theorem isSeparator_sigma {β : Type w} (f : β → C) [HasCoproduct f] :
IsSeparator (∐ f) ↔ IsSeparating (Set.range f) := by
refine ⟨fun h X Y u v huv => ?_, fun h => isSeparator_of_isColimit_cofan h (colimit.isColimit _)⟩
refine h.def _ _ fun g => colimit.hom_ext fun b => ?_
simpa using huv (f b.as) (by simp) (colimit.ι (Discrete.functor f) _ ≫ g)
theorem IsSeparating.isSeparator_coproduct {β : Type w} {f : β → C} [HasCoproduct f]
(hS : IsSeparating (Set.range f)) : IsSeparator (∐ f) :=
(isSeparator_sigma _).2 hS
theorem isSeparator_sigma_of_isSeparator {β : Type w} (f : β → C) [HasCoproduct f] (b : β)
(hb : IsSeparator (f b)) : IsSeparator (∐ f) :=
(isSeparator_sigma _).2 <| IsSeparating.mono hb <| by simp
theorem isCoseparator_prod (G H : C) [HasBinaryProduct G H] :
IsCoseparator (G ⨯ H) ↔ IsCoseparating ({G, H} : Set C) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isCoseparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => Limits.prod.hom_ext ?_ ?_
· simpa using huv G (by simp) (g ≫ Limits.prod.fst)
· simpa using huv H (by simp) (g ≫ Limits.prod.snd)
· simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hZ
rcases hZ with (rfl | rfl)
· simpa using huv (prod.lift g 0) =≫ Limits.prod.fst
· simpa using huv (prod.lift 0 g) =≫ Limits.prod.snd
theorem isCoseparator_prod_of_isCoseparator_left (G H : C) [HasBinaryProduct G H]
(hG : IsCoseparator G) : IsCoseparator (G ⨯ H) :=
(isCoseparator_prod _ _).2 <| IsCoseparating.mono hG <| by simp
theorem isCoseparator_prod_of_isCoseparator_right (G H : C) [HasBinaryProduct G H]
(hH : IsCoseparator H) : IsCoseparator (G ⨯ H) :=
(isCoseparator_prod _ _).2 <| IsCoseparating.mono hH <| by simp
theorem isCoseparator_pi {β : Type w} (f : β → C) [HasProduct f] :
IsCoseparator (∏ᶜ f) ↔ IsCoseparating (Set.range f) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isCoseparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => limit.hom_ext fun b => ?_
simpa using huv (f b.as) (by simp) (g ≫ limit.π (Discrete.functor f) _)
· obtain ⟨b, rfl⟩ := Set.mem_range.1 hZ
classical simpa using huv (Pi.lift (Pi.single b g)) =≫ Pi.π f b
theorem isCoseparator_pi_of_isCoseparator {β : Type w} (f : β → C) [HasProduct f] (b : β)
(hb : IsCoseparator (f b)) : IsCoseparator (∏ᶜ f) :=
(isCoseparator_pi _).2 <| IsCoseparating.mono hb <| by simp
end ZeroMorphisms
theorem isDetector_iff_reflectsIsomorphisms_coyoneda_obj (G : C) :
IsDetector G ↔ (coyoneda.obj (op G)).ReflectsIsomorphisms := by
refine
⟨fun hG => ⟨fun f hf => hG.def _ fun h => ?_⟩, fun h =>
(isDetector_def _).2 fun X Y f hf => ?_⟩
· rw [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf
exact hf h
· suffices IsIso ((coyoneda.obj (op G)).map f) by
exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (coyoneda.obj (op G)) _ h
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique]
theorem isCodetector_iff_reflectsIsomorphisms_yoneda_obj (G : C) :
IsCodetector G ↔ (yoneda.obj G).ReflectsIsomorphisms := by
refine ⟨fun hG => ⟨fun f hf => ?_⟩, fun h => (isCodetector_def _).2 fun X Y f hf => ?_⟩
· refine (isIso_unop_iff _).1 (hG.def _ ?_)
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf
· rw [← isIso_op_iff]
suffices IsIso ((yoneda.obj G).map f.op) by
exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (yoneda.obj G) _ h
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique]
theorem wellPowered_of_isDetector [HasPullbacks C] (G : C) (hG : IsDetector G) :
WellPowered.{v₁} C :=
wellPowered_of_isDetecting hG
theorem wellPowered_of_isSeparator [HasPullbacks C] [Balanced C] (G : C) (hG : IsSeparator G) :
WellPowered.{v₁} C := wellPowered_of_isDetecting hG.isDetector
section HasGenerator
section Definitions
variable (C)
/--
For a category `C` and an object `G : C`, `G` is a separator of `C` if
the functor `C(G, -)` is faithful.
While `IsSeparator G : Prop` is the proposition that `G` is a separator of `C`,
an `HasSeparator C : Prop` is the proposition that such a separator exists.
Note that `HasSeparator C` is a proposition. It does not designate a favored separator
and merely asserts the existence of one.
-/
class HasSeparator : Prop where
hasSeparator : ∃ G : C, IsSeparator G
/--
For a category `C` and an object `G : C`, `G` is a coseparator of `C` if
the functor `C(-, G)` is faithful.
While `IsCoseparator G : Prop` is the proposition that `G` is a coseparator of `C`,
an `HasCoseparator C : Prop` is the proposition that such a coseparator exists.
Note that `HasCoseparator C` is a proposition. It does not designate a favored coseparator
and merely asserts the existence of one.
-/
class HasCoseparator : Prop where
hasCoseparator : ∃ G : C, IsCoseparator G
/--
For a category `C` and an object `G : C`, `G` is a detector of `C` if
the functor `C(G, -)` reflects isomorphisms.
While `IsDetector G : Prop` is the proposition that `G` is a detector of `C`,
an `HasDetector C : Prop` is the proposition that such a detector exists.
Note that `HasDetector C` is a proposition. It does not designate a favored detector
and merely asserts the existence of one.
-/
class HasDetector : Prop where
hasDetector : ∃ G : C, IsDetector G
/--
For a category `C` and an object `G : C`, `G` is a codetector of `C` if
the functor `C(-, G)` reflects isomorphisms.
While `IsCodetector G : Prop` is the proposition that `G` is a codetector of `C`,
an `HasCodetector C : Prop` is the proposition that such a codetector exists.
Note that `HasCodetector C` is a proposition. It does not designate a favored codetector
and merely asserts the existence of one.
-/
class HasCodetector : Prop where
hasCodetector : ∃ G : C, IsCodetector G
end Definitions
section Choice
variable (C)
/--
Given a category `C` that has a separator (`HasSeparator C`), `separator C` is an arbitrarily
chosen separator of `C`.
-/
noncomputable def separator [HasSeparator C] : C := HasSeparator.hasSeparator.choose
/--
Given a category `C` that has a coseparator (`HasCoseparator C`), `coseparator C` is an arbitrarily
chosen coseparator of `C`.
-/
noncomputable def coseparator [HasCoseparator C] : C := HasCoseparator.hasCoseparator.choose
/--
Given a category `C` that has a detector (`HasDetector C`), `detector C` is an arbitrarily
chosen detector of `C`.
-/
noncomputable def detector [HasDetector C] : C := HasDetector.hasDetector.choose
/--
Given a category `C` that has a codetector (`HasCodetector C`), `codetector C` is an arbitrarily
chosen codetector of `C`.
-/
noncomputable def codetector [HasCodetector C] : C := HasCodetector.hasCodetector.choose
theorem isSeparator_separator [HasSeparator C] : IsSeparator (separator C) :=
HasSeparator.hasSeparator.choose_spec
theorem isDetector_separator [Balanced C] [HasSeparator C] : IsDetector (separator C) :=
isSeparator_separator C |>.isDetector
theorem isCoseparator_coseparator [HasCoseparator C] : IsCoseparator (coseparator C) :=
HasCoseparator.hasCoseparator.choose_spec
theorem isCodetector_coseparator [Balanced C] [HasCoseparator C] : IsCodetector (coseparator C) :=
isCoseparator_coseparator C |>.isCodetector
theorem isDetector_detector [HasDetector C] : IsDetector (detector C) :=
HasDetector.hasDetector.choose_spec
theorem isSeparator_detector [HasEqualizers C] [HasDetector C] : IsSeparator (detector C) :=
isDetector_detector C |>.isSeparator
theorem isCodetector_codetector [HasCodetector C] : IsCodetector (codetector C) :=
HasCodetector.hasCodetector.choose_spec
theorem isCoseparator_codetector [HasCoequalizers C] [HasCodetector C] :
IsCoseparator (codetector C) := isCodetector_codetector C |>.isCoseparator
end Choice
section Instances
theorem HasSeparator.hasDetector [Balanced C] [HasSeparator C] : HasDetector C :=
⟨_, isDetector_separator C⟩
theorem HasDetector.hasSeparator [HasEqualizers C] [HasDetector C] : HasSeparator C :=
⟨_, isSeparator_detector C⟩
theorem HasCoseparator.hasCodetector [Balanced C] [HasCoseparator C] : HasCodetector C :=
⟨_, isCodetector_coseparator C⟩
theorem HasCodetector.hasCoseparator [HasCoequalizers C] [HasCodetector C] : HasCoseparator C :=
⟨_, isCoseparator_codetector C⟩
instance HasDetector.wellPowered [HasPullbacks C] [HasDetector C] : WellPowered.{v₁} C :=
isDetector_detector C |> wellPowered_of_isDetector _
instance HasSeparator.wellPowered [HasPullbacks C] [Balanced C] [HasSeparator C] :
WellPowered.{v₁} C := HasSeparator.hasDetector.wellPowered
end Instances
section Equivalence
theorem HasSeparator.of_equivalence [HasSeparator C] (α : C ≌ D) : HasSeparator D :=
⟨α.functor.obj (separator C), isSeparator_separator C |>.of_equivalence α⟩
theorem HasCoseparator.of_equivalence [HasCoseparator C] (α : C ≌ D) : HasCoseparator D :=
⟨α.functor.obj (coseparator C), isCoseparator_coseparator C |>.of_equivalence α⟩
end Equivalence
section Dual
@[simp]
theorem hasSeparator_op_iff : HasSeparator Cᵒᵖ ↔ HasCoseparator C :=
⟨fun ⟨G, hG⟩ => ⟨unop G, (isCoseparator_unop_iff G).mpr hG⟩,
fun ⟨G, hG⟩ => ⟨op G, (isSeparator_op_iff G).mpr hG⟩⟩
@[simp]
theorem hasCoseparator_op_iff : HasCoseparator Cᵒᵖ ↔ HasSeparator C :=
⟨fun ⟨G, hG⟩ => ⟨unop G, (isSeparator_unop_iff G).mpr hG⟩,
fun ⟨G, hG⟩ => ⟨op G, (isCoseparator_op_iff G).mpr hG⟩⟩
@[simp]
theorem hasDetector_op_iff : HasDetector Cᵒᵖ ↔ HasCodetector C :=
⟨fun ⟨G, hG⟩ => ⟨unop G, (isCodetector_unop_iff G).mpr hG⟩,
fun ⟨G, hG⟩ => ⟨op G, (isDetector_op_iff G).mpr hG⟩⟩
@[simp]
theorem hasCodetector_op_iff : HasCodetector Cᵒᵖ ↔ HasDetector C :=
⟨fun ⟨G, hG⟩ => ⟨unop G, (isDetector_unop_iff G).mpr hG⟩,
fun ⟨G, hG⟩ => ⟨op G, (isCodetector_op_iff G).mpr hG⟩⟩
instance HasSeparator.hasCoseparator_op [HasSeparator C] : HasCoseparator Cᵒᵖ := by simp [*]
theorem HasSeparator.hasCoseparator_of_hasSeparator_op [h : HasSeparator Cᵒᵖ] :
HasCoseparator C := by simp_all
instance HasCoseparator.hasSeparator_op [HasCoseparator C] : HasSeparator Cᵒᵖ := by simp [*]
theorem HasCoseparator.hasSeparator_of_hasCoseparator_op [HasCoseparator Cᵒᵖ] :
HasSeparator C := by simp_all
instance HasDetector.hasCodetector_op [HasDetector C] : HasCodetector Cᵒᵖ := by simp [*]
theorem HasDetector.hasCodetector_of_hasDetector_op [HasDetector Cᵒᵖ] :
HasCodetector C := by simp_all
instance HasCodetector.hasDetector_op [HasCodetector C] : HasDetector Cᵒᵖ := by simp [*]
theorem HasCodetector.hasDetector_of_hasCodetector_op [HasCodetector Cᵒᵖ] :
HasDetector C := by simp_all
end Dual
end HasGenerator
end CategoryTheory
|
TwoVariable.lean
|
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Calculus.SmoothSeries
import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod
import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation
import Mathlib.Data.Complex.FiniteDimensional
/-!
# The two-variable Jacobi theta function
This file defines the two-variable Jacobi theta function
$$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$
and proves the functional equation relating the values at `(z, τ)` and `(z / τ, -1 / τ)`,
using Poisson's summation formula. We also show holomorphy (jointly in both variables).
Additionally, we show some analogous results about the derivative (in the `z`-variable)
$$\theta'(z, τ) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$
(Note that the Mellin transform of `θ` will give us functional equations for `L`-functions
of even Dirichlet characters, and that of `θ'` will do the same for odd Dirichlet characters.)
-/
open Complex Real Asymptotics Filter Topology
open scoped ComplexConjugate
noncomputable section
section term_defs
/-!
## Definitions of the summands
-/
/-- Summand in the series for the Jacobi theta function. -/
def jacobiTheta₂_term (n : ℤ) (z τ : ℂ) : ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)
/-- Summand in the series for the Fréchet derivative of the Jacobi theta function. -/
def jacobiTheta₂_term_fderiv (n : ℤ) (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ :=
cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) •
((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) +
(π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ))
lemma hasFDerivAt_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) :
HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂_term n p.1 p.2)
(jacobiTheta₂_term_fderiv n z τ) (z, τ) := by
let f : ℂ × ℂ → ℂ := fun p ↦ 2 * π * I * n * p.1 + π * I * n ^ 2 * p.2
suffices HasFDerivAt f ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ)
+ (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) (z, τ) from this.cexp
exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _)
/-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/
def jacobiTheta₂'_term (n : ℤ) (z τ : ℂ) := 2 * π * I * n * jacobiTheta₂_term n z τ
end term_defs
section term_bounds
/-!
## Bounds for the summands
We show that the sums of the three functions `jacobiTheta₂_term`, `jacobiTheta₂'_term` and
`jacobiTheta₂_term_fderiv` are locally uniformly convergent in the domain `0 < im τ`, and diverge
everywhere else.
-/
lemma norm_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) :
‖jacobiTheta₂_term n z τ‖ = rexp (-π * n ^ 2 * τ.im - 2 * π * n * z.im) := by
rw [jacobiTheta₂_term, Complex.norm_exp, (by push_cast; ring :
(2 * π : ℂ) * I * n * z + π * I * n ^ 2 * τ = (π * (2 * n) :) * z * I + (π * n ^ 2 :) * τ * I),
add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul]
ring_nf
/-- A uniform upper bound for `jacobiTheta₂_term` on compact subsets. -/
lemma norm_jacobiTheta₂_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ}
(hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) :
‖jacobiTheta₂_term n z τ‖ ≤ rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by
simp_rw [norm_jacobiTheta₂_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, ← neg_add,
neg_le_neg_iff, mul_comm (2 : ℝ), mul_assoc π, ← mul_add, mul_le_mul_left pi_pos,
mul_comm T, mul_comm S]
refine add_le_add (mul_le_mul le_rfl hτ hT.le (sq_nonneg _)) ?_
rw [← mul_neg, mul_assoc, mul_assoc, mul_le_mul_left two_pos, mul_comm, neg_mul, ← mul_neg]
refine le_trans ?_ (neg_abs_le _)
rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs]
exact mul_le_mul_of_nonneg_left hz (abs_nonneg _)
/-- A uniform upper bound for `jacobiTheta₂'_term` on compact subsets. -/
lemma norm_jacobiTheta₂'_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ}
(hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) :
‖jacobiTheta₂'_term n z τ‖ ≤ 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by
rw [jacobiTheta₂'_term, norm_mul]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hT hz hτ n)
(norm_nonneg _) (by positivity)
simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
/-- The uniform bound we have given is summable, and remains so after multiplying by any fixed
power of `|n|` (we shall need this for `k = 0, 1, 2`). -/
lemma summable_pow_mul_jacobiTheta₂_term_bound (S : ℝ) {T : ℝ} (hT : 0 < T) (k : ℕ) :
Summable (fun n : ℤ ↦ (|n| ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))) := by
suffices Summable (fun n : ℕ ↦ (n ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * n))) by
apply Summable.of_nat_of_neg <;>
simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast]
apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one)
apply IsBigO.mul (isBigO_refl _ _)
refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_)
simp_rw [← tendsto_neg_atTop_iff, Pi.sub_apply]
conv =>
enter [1, n]
rw [show -(-π * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (π * T * n - (2 * π * S + 1)) by ring]
refine tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ (tendsto_atTop_add_const_right _ _ ?_)
exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT)
/-- The series defining the theta function is summable if and only if `0 < im τ`. -/
lemma summable_jacobiTheta₂_term_iff (z τ : ℂ) : Summable (jacobiTheta₂_term · z τ) ↔ 0 < im τ := by
-- NB. This is a statement of no great mathematical interest; it is included largely to avoid
-- having to impose `0 < im τ` as a hypothesis on many later lemmas.
refine Iff.symm ⟨fun hτ ↦ ?_, fun h ↦ ?_⟩ -- do quicker implication first!
· refine (summable_pow_mul_jacobiTheta₂_term_bound |im z| hτ 0).of_norm_bounded ?_
simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hτ le_rfl le_rfl
· by_contra! hτ
rcases lt_or_eq_of_le hτ with hτ | hτ
· -- easy case `im τ < 0`
suffices Tendsto (fun n : ℕ ↦ ‖jacobiTheta₂_term ↑n z τ‖) atTop atTop by
replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm
exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this)
simp only [norm_jacobiTheta₂_term, Int.cast_natCast]
conv =>
enter [1, n]
rw [show -π * n ^ 2 * τ.im - 2 * π * n * z.im =
n * (n * (-π * τ.im) - 2 * π * z.im) by ring]
refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ ?_)
exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const
(mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hτ))
· -- case im τ = 0: 3-way split according to `im z`
simp_rw [← summable_norm_iff (E := ℂ), norm_jacobiTheta₂_term, hτ, mul_zero, zero_sub] at h
rcases lt_trichotomy (im z) 0 with hz | hz | hz
· replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_natCast] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
refine tendsto_exp_atTop.comp ?_
simp only [tendsto_neg_atTop_iff, mul_assoc]
apply Filter.Tendsto.const_mul_atBot two_pos
exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos
· revert h
simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero
· have : ((-↑·) : ℕ → ℤ).Injective := fun _ _ ↦ by simp only [neg_inj, Nat.cast_inj, imp_self]
replace h := (h.comp_injective this).tendsto_atTop_zero
simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h
refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_)
exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop
(mul_pos two_pos pi_pos)).atTop_mul_const hz)
lemma norm_jacobiTheta₂_term_fderiv_le (n : ℤ) (z τ : ℂ) :
‖jacobiTheta₂_term_fderiv n z τ‖ ≤ 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ := by
-- this is slow to elaborate so do it once and reuse:
have hns (a : ℂ) (f : (ℂ × ℂ) →L[ℂ] ℂ) : ‖a • f‖ = ‖a‖ * ‖f‖ := norm_smul a f
rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, hns,
mul_comm _ ‖cexp _‖, (by norm_num : (3 : ℝ) = 2 + 1), add_mul, add_mul]
refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _)
· simp_rw [hns, norm_mul, ← ofReal_ofNat, ← ofReal_intCast,
norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one,
Real.norm_eq_abs, Int.cast_abs, mul_assoc]
refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le
refine le_trans ?_ (?_ : |(n : ℝ)| ≤ |(n : ℝ)| ^ 2)
· exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..)
· exact_mod_cast Int.le_self_sq |n|
· simp_rw [hns, norm_mul, one_mul, norm_I, mul_one,
norm_real, norm_of_nonneg pi_pos.le, ← ofReal_intCast, ← ofReal_pow, norm_real,
Real.norm_eq_abs, Int.cast_abs, abs_pow]
apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _))
exact ContinuousLinearMap.norm_snd_le ..
lemma norm_jacobiTheta₂_term_fderiv_ge (n : ℤ) (z τ : ℂ) :
π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by
have : ‖(jacobiTheta₂_term_fderiv n z τ) (0, 1)‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by
refine (ContinuousLinearMap.le_opNorm _ _).trans ?_
simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl]
refine le_trans ?_ this
simp_rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, ContinuousLinearMap.coe_smul',
Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul',
ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add,
smul_eq_mul, mul_one, mul_comm _ ‖cexp _‖, norm_mul]
refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _)
simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one,
Int.cast_abs, ← norm_intCast, norm_pow]
lemma summable_jacobiTheta₂_term_fderiv_iff (z τ : ℂ) :
Summable (jacobiTheta₂_term_fderiv · z τ) ↔ 0 < im τ := by
constructor
· rw [← summable_jacobiTheta₂_term_iff (z := z)]
intro h
have := h.norm
refine this.of_norm_bounded_eventually ?_
have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 :=
Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩)
filter_upwards [this] with n hn
refine le_trans ?_ (norm_jacobiTheta₂_term_fderiv_ge n z τ)
apply le_mul_of_one_le_left (norm_nonneg _)
refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le)
refine (by norm_num : 2⁻¹ ≤ (1 : ℝ)).trans ?_
rw [one_le_sq_iff_one_le_abs, ← Int.cast_abs, abs_abs, ← Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
· intro hτ
refine ((summable_pow_mul_jacobiTheta₂_term_bound
|z.im| hτ 2).mul_left (3 * π)).of_norm_bounded (fun n ↦ ?_)
refine (norm_jacobiTheta₂_term_fderiv_le n z τ).trans
(?_ : 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ _)
simp_rw [mul_assoc (3 * π)]
refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by simp : 0 < (3 : ℝ)) pi_pos).le
refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (abs_nonneg _)) _)
exact norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n
lemma summable_jacobiTheta₂'_term_iff (z τ : ℂ) :
Summable (jacobiTheta₂'_term · z τ) ↔ 0 < im τ := by
constructor
· rw [← summable_jacobiTheta₂_term_iff (z := z)]
refine fun h ↦ (h.norm.mul_left (2 * π)⁻¹).of_norm_bounded_eventually ?_
have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 :=
Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩)
filter_upwards [this] with n hn
rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc]
refine le_mul_of_one_le_left (norm_nonneg _) ?_
simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le,
← ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, ← ofReal_intCast, norm_real,
Real.norm_eq_abs, ← Int.cast_abs, ← mul_assoc _ (2 * π),
inv_mul_cancel₀ (mul_pos two_pos pi_pos).ne', one_mul]
rw [← Int.cast_one, Int.cast_le]
exact Int.one_le_abs hn
· refine fun hτ ↦ ((summable_pow_mul_jacobiTheta₂_term_bound
|z.im| hτ 1).mul_left (2 * π)).of_norm_bounded (fun n ↦ ?_)
rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc, pow_one]
refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n)
(norm_nonneg _) (by positivity)
simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le,
norm_intCast, mul_one, Int.cast_abs]
end term_bounds
/-!
## Definitions of the functions
-/
/-- The two-variable Jacobi theta function,
`θ z τ = ∑' (n : ℤ), cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`.
-/
def jacobiTheta₂ (z τ : ℂ) : ℂ := ∑' n : ℤ, jacobiTheta₂_term n z τ
/-- Fréchet derivative of the two-variable Jacobi theta function. -/
def jacobiTheta₂_fderiv (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := ∑' n : ℤ, jacobiTheta₂_term_fderiv n z τ
/-- The `z`-derivative of the Jacobi theta function,
`θ' z τ = ∑' (n : ℤ), 2 * π * I * n * cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`.
-/
def jacobiTheta₂' (z τ : ℂ) := ∑' n : ℤ, jacobiTheta₂'_term n z τ
lemma hasSum_jacobiTheta₂_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂_term n z τ) (jacobiTheta₂ z τ) :=
((summable_jacobiTheta₂_term_iff z τ).mpr hτ).hasSum
lemma hasSum_jacobiTheta₂_term_fderiv (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂_term_fderiv n z τ) (jacobiTheta₂_fderiv z τ) :=
((summable_jacobiTheta₂_term_fderiv_iff z τ).mpr hτ).hasSum
lemma hasSum_jacobiTheta₂'_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasSum (fun n ↦ jacobiTheta₂'_term n z τ) (jacobiTheta₂' z τ) :=
((summable_jacobiTheta₂'_term_iff z τ).mpr hτ).hasSum
lemma jacobiTheta₂_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂ z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂_term_iff]
exact not_lt.mpr hτ
lemma jacobiTheta₂_fderiv_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂_fderiv z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂_term_fderiv_iff]
exact not_lt.mpr hτ
lemma jacobiTheta₂'_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂' z τ = 0 := by
apply tsum_eq_zero_of_not_summable
rw [summable_jacobiTheta₂'_term_iff]
exact not_lt.mpr hτ
/-!
## Derivatives and continuity
-/
lemma hasFDerivAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (jacobiTheta₂_fderiv z τ) (z, τ) := by
obtain ⟨T, hT, hτ'⟩ := exists_between hτ
obtain ⟨S, hz⟩ := exists_gt |im z|
let V := {u | |im u| < S} ×ˢ {v | T < im v}
have hVo : IsOpen V := by
refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_
exact continuous_im.isOpen_preimage _ isOpen_Ioi
have hVmem : (z, τ) ∈ V := ⟨hz, hτ'⟩
have hVp : IsPreconnected V := by
refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected
simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _)
let f : ℤ → ℂ × ℂ → ℂ := fun n p ↦ jacobiTheta₂_term n p.1 p.2
let f' : ℤ → ℂ × ℂ → ℂ × ℂ →L[ℂ] ℂ := fun n p ↦ jacobiTheta₂_term_fderiv n p.1 p.2
have hf (n : ℤ) : ∀ p ∈ V, HasFDerivAt (f n) (f' n p) p :=
fun p _ ↦ hasFDerivAt_jacobiTheta₂_term n p.1 p.2
let u : ℤ → ℝ := fun n ↦ 3 * π * |n| ^ 2 * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))
have hu : ∀ (n : ℤ), ∀ x ∈ V, ‖f' n x‖ ≤ u n := by
refine fun n p hp ↦ (norm_jacobiTheta₂_term_fderiv_le n p.1 p.2).trans ?_
refine mul_le_mul_of_nonneg_left ?_ (by positivity)
exact norm_jacobiTheta₂_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n
have hu_sum : Summable u := by
simp_rw [u, mul_assoc (3 * π)]
exact (summable_pow_mul_jacobiTheta₂_term_bound S hT 2).mul_left _
have hf_sum : Summable fun n : ℤ ↦ f n (z, τ) := by
refine (summable_pow_mul_jacobiTheta₂_term_bound S hT 0).of_norm_bounded ?_
simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hT hz.le hτ'.le
simpa only [jacobiTheta₂, jacobiTheta₂_fderiv, f, f'] using
hasFDerivAt_tsum_of_isPreconnected hu_sum hVo hVp hf hu hVmem hf_sum hVmem
lemma continuousAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (z, τ) :=
(hasFDerivAt_jacobiTheta₂ z hτ).continuousAt
/-- Differentiability of `Θ z τ` in `z`, for fixed `τ`. -/
lemma differentiableAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
DifferentiableAt ℂ (jacobiTheta₂ · τ) z :=
((hasFDerivAt_jacobiTheta₂ z hτ).comp (𝕜 := ℂ) z (hasFDerivAt_prodMk_left z τ) :).differentiableAt
/-- Differentiability of `Θ z τ` in `τ`, for fixed `z`. -/
lemma differentiableAt_jacobiTheta₂_snd (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
DifferentiableAt ℂ (jacobiTheta₂ z) τ :=
((hasFDerivAt_jacobiTheta₂ z hτ).comp τ (hasFDerivAt_prodMk_right z τ)).differentiableAt
lemma hasDerivAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
HasDerivAt (jacobiTheta₂ · τ) (jacobiTheta₂' z τ) z := by
-- This proof is annoyingly fiddly, because of the need to commute "evaluation at a point"
-- through infinite sums of continuous linear maps.
let eval_fst_CLM : (ℂ × ℂ →L[ℂ] ℂ) →L[ℂ] ℂ :=
{ toFun := fun f ↦ f (1, 0)
cont := continuous_id'.clm_apply continuous_const
map_add' := by simp only [ContinuousLinearMap.add_apply, forall_const]
map_smul' := by simp only [ContinuousLinearMap.coe_smul', Pi.smul_apply, smul_eq_mul,
RingHom.id_apply, forall_const] }
have step1 : HasSum (fun n ↦ (jacobiTheta₂_term_fderiv n z τ) (1, 0))
((jacobiTheta₂_fderiv z τ) (1, 0)) := by
apply eval_fst_CLM.hasSum (hasSum_jacobiTheta₂_term_fderiv z hτ)
have step2 (n : ℤ) : (jacobiTheta₂_term_fderiv n z τ) (1, 0) = jacobiTheta₂'_term n z τ := by
simp only [jacobiTheta₂_term_fderiv, smul_add, ContinuousLinearMap.add_apply,
ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', Pi.smul_apply, smul_eq_mul,
mul_one, ContinuousLinearMap.coe_snd', mul_zero, add_zero, jacobiTheta₂'_term,
jacobiTheta₂_term, mul_comm _ (cexp _)]
rw [funext step2] at step1
have step3 : HasDerivAt (fun x ↦ jacobiTheta₂ x τ) ((jacobiTheta₂_fderiv z τ) (1, 0)) z :=
(((hasFDerivAt_jacobiTheta₂ z hτ).comp z (hasFDerivAt_prodMk_left z τ)).hasDerivAt :)
rwa [← step1.tsum_eq] at step3
lemma continuousAt_jacobiTheta₂' (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) :
ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂' p.1 p.2) (z, τ) := by
obtain ⟨T, hT, hτ'⟩ := exists_between hτ
obtain ⟨S, hz⟩ := exists_gt |im z|
let V := {u | |im u| < S} ×ˢ {v | T < im v}
have hVo : IsOpen V := ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _
isOpen_Iio).prod (continuous_im.isOpen_preimage _ isOpen_Ioi)
refine ContinuousOn.continuousAt ?_ (hVo.mem_nhds ⟨hz, hτ'⟩)
let u (n : ℤ) : ℝ := 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|))
have hu : Summable u := by simpa only [u, mul_assoc, pow_one]
using (summable_pow_mul_jacobiTheta₂_term_bound S hT 1).mul_left (2 * π)
refine continuousOn_tsum (fun n ↦ ?_) hu (fun n ⟨z', τ'⟩ ⟨hz', hτ'⟩ ↦ ?_)
· apply Continuous.continuousOn
unfold jacobiTheta₂'_term jacobiTheta₂_term
fun_prop
· exact norm_jacobiTheta₂'_term_le hT (le_of_lt hz') (le_of_lt hτ') n
/-!
## Periodicity and conjugation
-/
/-- The two-variable Jacobi theta function is periodic in `τ` with period 2. -/
lemma jacobiTheta₂_add_right (z τ : ℂ) : jacobiTheta₂ z (τ + 2) = jacobiTheta₂ z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, Complex.exp_add]
suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one]
rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul,
exp_two_pi_mul_I, one_zpow]
/-- The two-variable Jacobi theta function is periodic in `z` with period 1. -/
lemma jacobiTheta₂_add_left (z τ : ℂ) : jacobiTheta₂ (z + 1) τ = jacobiTheta₂ z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ),
exp_int_mul_two_pi_mul_I, mul_one]
/-- The two-variable Jacobi theta function is quasi-periodic in `z` with period `τ`. -/
lemma jacobiTheta₂_add_left' (z τ : ℂ) :
jacobiTheta₂ (z + τ) τ = cexp (-π * I * (τ + 2 * z)) * jacobiTheta₂ z τ := by
conv_rhs => rw [jacobiTheta₂, ← tsum_mul_left, ← (Equiv.addRight 1).tsum_eq]
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, ← Complex.exp_add, Equiv.coe_addRight, Int.cast_add]
ring_nf
/-- The two-variable Jacobi theta function is even in `z`. -/
@[simp]
lemma jacobiTheta₂_neg_left (z τ : ℂ) : jacobiTheta₂ (-z) τ = jacobiTheta₂ z τ := by
conv_lhs => rw [jacobiTheta₂, ← Equiv.tsum_eq (Equiv.neg ℤ)]
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂_term, Equiv.neg_apply, Int.cast_neg, neg_sq, mul_assoc, neg_mul_neg]
lemma jacobiTheta₂_conj (z τ : ℂ) :
conj (jacobiTheta₂ z τ) = jacobiTheta₂ (conj z) (-conj τ) := by
rw [← jacobiTheta₂_neg_left, jacobiTheta₂, conj_tsum]
congr 2 with n
simp only [jacobiTheta₂_term, mul_neg, ← exp_conj, map_add, map_neg, map_mul, map_ofNat,
conj_ofReal, conj_I, map_intCast, neg_mul, neg_neg, map_pow]
lemma jacobiTheta₂'_add_right (z τ : ℂ) : jacobiTheta₂' z (τ + 2) = jacobiTheta₂' z τ := by
refine tsum_congr (fun n ↦ ?_)
simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, Complex.exp_add]
suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one]
rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul,
exp_two_pi_mul_I, one_zpow]
lemma jacobiTheta₂'_add_left (z τ : ℂ) : jacobiTheta₂' (z + 1) τ = jacobiTheta₂' z τ := by
unfold jacobiTheta₂' jacobiTheta₂'_term jacobiTheta₂_term
refine tsum_congr (fun n ↦ ?_)
simp only [mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ), exp_int_mul_two_pi_mul_I,
mul_one]
lemma jacobiTheta₂'_add_left' (z τ : ℂ) :
jacobiTheta₂' (z + τ) τ =
cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂' z τ - 2 * π * I * jacobiTheta₂ z τ) := by
rcases le_or_gt τ.im 0 with hτ | hτ
· simp_rw [jacobiTheta₂_undef _ hτ, jacobiTheta₂'_undef _ hτ, mul_zero, sub_zero, mul_zero]
have (n : ℤ) : jacobiTheta₂'_term n (z + τ) τ =
cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂'_term (n + 1) z τ -
2 * π * I * jacobiTheta₂_term (n + 1) z τ) := by
simp only [jacobiTheta₂'_term, jacobiTheta₂_term]
conv_rhs => rw [← sub_mul, mul_comm, mul_assoc, ← Complex.exp_add, Int.cast_add, Int.cast_one,
mul_add, mul_one, add_sub_cancel_right]
congr 2
ring
rw [jacobiTheta₂', funext this, tsum_mul_left, ← (Equiv.subRight (1 : ℤ)).tsum_eq]
simp only [jacobiTheta₂, jacobiTheta₂', Equiv.subRight_apply, sub_add_cancel,
(hasSum_jacobiTheta₂'_term z hτ).summable.tsum_sub
((hasSum_jacobiTheta₂_term z hτ).summable.mul_left _), tsum_mul_left]
lemma jacobiTheta₂'_neg_left (z τ : ℂ) : jacobiTheta₂' (-z) τ = -jacobiTheta₂' z τ := by
rw [jacobiTheta₂', jacobiTheta₂', ← tsum_neg, ← (Equiv.neg ℤ).tsum_eq]
congr 1 with n
simp only [jacobiTheta₂'_term, jacobiTheta₂_term]
rw [Equiv.neg_apply, ← neg_mul]
push_cast
ring_nf
lemma jacobiTheta₂'_conj (z τ : ℂ) :
conj (jacobiTheta₂' z τ) = jacobiTheta₂' (conj z) (-conj τ) := by
rw [← neg_inj, ← jacobiTheta₂'_neg_left, jacobiTheta₂', jacobiTheta₂', conj_tsum, ← tsum_neg]
congr 1 with n
simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, map_mul, ← Complex.exp_conj, map_add, map_mul,
← ofReal_intCast, ← ofReal_ofNat, map_pow, conj_ofReal, conj_I]
ring_nf
/-!
## Functional equations
-/
/-- The functional equation for the Jacobi theta function: `jacobiTheta₂ z τ` is an explicit factor
times `jacobiTheta₂ (z / τ) (-1 / τ)`. This is the key lemma behind the proof of the functional
equation for L-series of even Dirichlet characters. -/
theorem jacobiTheta₂_functional_equation (z τ : ℂ) : jacobiTheta₂ z τ =
1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ) := by
rcases le_or_gt (im τ) 0 with hτ | hτ
· have : (-1 / τ).im ≤ 0 := by
rw [neg_div, neg_im, one_div, inv_im, neg_nonpos]
exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
rw [jacobiTheta₂_undef z hτ, jacobiTheta₂_undef _ this, mul_zero]
unfold jacobiTheta₂ jacobiTheta₂_term
have h0 : τ ≠ 0 := by contrapose! hτ; rw [hτ, zero_im]
have h2 : 0 < (-I * τ).re := by
simpa only [neg_mul, neg_re, mul_re, I_re, zero_mul, I_im, one_mul, zero_sub, neg_neg] using hτ
calc
_ = ∑' n : ℤ, cexp (-π * (-I * τ) * ↑n ^ 2 + 2 * π * (I * z) * ↑n) :=
tsum_congr (fun n ↦ by ring_nf)
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * ∑' (n : ℤ), cexp (-π / (-I * τ) * (n + I * (I * z)) ^ 2) := by
rw [tsum_exp_neg_quadratic h2]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (π * I * (-1 / τ) * z ^ 2) *
∑' (n : ℤ), cexp (2 * π * I * n * (z / τ) + π * I * n ^ 2 * (-1 / τ)) := by
simp_rw [mul_assoc _ (cexp _), ← tsum_mul_left (a := cexp _), ← Complex.exp_add]
congr 2 with n : 1; congr 1
field_simp [I_ne_zero]
ring_nf
simp_rw [I_sq, I_pow_four]
ring_nf
_ = _ := by
congr 3
ring
/-- The functional equation for the derivative of the Jacobi theta function, relating
`jacobiTheta₂' z τ` to `jacobiTheta₂' (z / τ) (-1 / τ)`. This is the key lemma behind the proof of
the functional equation for L-series of odd Dirichlet characters. -/
theorem jacobiTheta₂'_functional_equation (z τ : ℂ) :
jacobiTheta₂' z τ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) / τ *
(jacobiTheta₂' (z / τ) (-1 / τ) - 2 * π * I * z * jacobiTheta₂ (z / τ) (-1 / τ)) := by
rcases le_or_gt (im τ) 0 with hτ | hτ
· rw [jacobiTheta₂'_undef z hτ, jacobiTheta₂'_undef, jacobiTheta₂_undef, mul_zero,
sub_zero, mul_zero] <;>
rw [neg_div, neg_im, one_div, inv_im, neg_nonpos] <;>
exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ)
have hτ' : 0 < (-1 / τ).im := by
rw [div_eq_mul_inv, neg_one_mul, neg_im, inv_im, neg_div, neg_neg]
exact div_pos hτ (normSq_pos.mpr (fun h ↦ lt_irrefl 0 (zero_im ▸ h ▸ hτ)))
have hj : HasDerivAt (fun w ↦ jacobiTheta₂ (w / τ) (-1 / τ))
((1 / τ) * jacobiTheta₂' (z / τ) (-1 / τ)) z := by
have := hasDerivAt_jacobiTheta₂_fst (z / τ) hτ'
simpa only [mul_comm, one_div] using this.comp z (hasDerivAt_mul_const τ⁻¹)
calc
_ = deriv (jacobiTheta₂ · τ) z := (hasDerivAt_jacobiTheta₂_fst z hτ).deriv.symm
_ = deriv (fun z ↦ 1 / (-I * τ) ^ (1 / 2 : ℂ) *
cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by
rw [funext (jacobiTheta₂_functional_equation · τ)]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) *
deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by
simp_rw [mul_assoc, deriv_const_mul_field]
_ = 1 / (-I * τ) ^ (1 / 2 : ℂ) *
(deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ)) z * jacobiTheta₂ (z / τ) (-1 / τ)
+ cexp (-π * I * z ^ 2 / τ) * deriv (fun z ↦ jacobiTheta₂ (z / τ) (-1 / τ)) z) := by
rw [deriv_fun_mul _ hj.differentiableAt]
exact (((differentiableAt_pow 2).const_mul _).mul_const _).cexp
_ = _ := by
rw [hj.deriv]
simp only [div_eq_mul_inv _ τ]
rw [deriv_cexp (((differentiableAt_pow _).const_mul _).mul_const _), mul_comm,
deriv_mul_const_field, deriv_const_mul_field, deriv_pow_field]
ring_nf
|
Snoc.lean
|
/-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
/-!
This file establishes a `snoc : Vector α n → α → Vector α (n+1)` operation, that appends a single
element to the back of a vector.
It provides a collection of lemmas that show how different `Vector` operations reduce when their
argument is `snoc xs x`.
Also, an alternative, reverse, induction principle is added, that breaks down a vector into
`snoc xs x` for its inductive case. Effectively doing induction from right-to-left
-/
namespace List
namespace Vector
variable {α β σ φ : Type*} {n : ℕ} {x : α} {s : σ} (xs : Vector α n)
/-- Append a single element to the end of a vector -/
def snoc : Vector α n → α → Vector α (n + 1) :=
fun xs x => xs ++ x ::ᵥ Vector.nil
/-! ## Simplification lemmas -/
section Simp
variable {y : α}
@[simp]
theorem snoc_cons : (x ::ᵥ xs).snoc y = x ::ᵥ (xs.snoc y) :=
rfl
@[simp]
theorem snoc_nil : (nil.snoc x) = x ::ᵥ nil :=
rfl
@[simp]
theorem reverse_cons : reverse (x ::ᵥ xs) = (reverse xs).snoc x := by
cases xs
simp only [reverse, cons, toList_mk, List.reverse_cons, snoc]
congr
@[simp]
theorem reverse_snoc : reverse (xs.snoc x) = x ::ᵥ (reverse xs) := by
cases xs
simp only [reverse, snoc, cons, toList_mk]
congr
simp [toList, append_def]
theorem replicate_succ_to_snoc (val : α) :
replicate (n + 1) val = (replicate n val).snoc val := by
induction n with
| zero => rfl
| succ n ih =>
rw [replicate_succ]
conv => rhs; rw [replicate_succ]
rw [snoc_cons, ih]
end Simp
/-! ## Reverse induction principle -/
section Induction
/--
Define `C v` by *reverse* induction on `v : Vector α n`.
That is, break the vector down starting from the right-most element, using `snoc`
This function has two arguments: `nil` handles the base case on `C nil`,
and `snoc` defines the inductive step using `∀ x : α, C xs → C (xs.snoc x)`.
This can be used as `induction v using Vector.revInductionOn`. -/
@[elab_as_elim]
def revInductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C xs → C (xs.snoc x)) :
C v :=
cast (by simp) <| inductionOn
(C := fun v => C v.reverse)
v.reverse
nil
(@fun n x xs (r : C xs.reverse) => cast (by simp) <| snoc xs.reverse x r)
/-- Define `C v w` by *reverse* induction on a pair of vectors `v : Vector α n` and
`w : Vector β n`. -/
@[elab_as_elim]
def revInductionOn₂ {C : ∀ {n : ℕ}, Vector α n → Vector β n → Sort*} {n : ℕ}
(v : Vector α n) (w : Vector β n)
(nil : C nil nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (ys : Vector β n) (x : α) (y : β),
C xs ys → C (xs.snoc x) (ys.snoc y)) :
C v w :=
cast (by simp) <| inductionOn₂
(C := fun v w => C v.reverse w.reverse)
v.reverse
w.reverse
nil
(@fun n x y xs ys (r : C xs.reverse ys.reverse) =>
cast (by simp) <| snoc xs.reverse ys.reverse x y r)
/-- Define `C v` by *reverse* case analysis, i.e. by handling the cases `nil` and `xs.snoc x`
separately -/
@[elab_as_elim]
def revCasesOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C (xs.snoc x)) :
C v :=
revInductionOn v nil fun xs x _ => snoc xs x
end Induction
/-! ## More simplification lemmas -/
section Simp
@[simp]
theorem map_snoc {f : α → β} : map f (xs.snoc x) = (map f xs).snoc (f x) := by
induction xs <;> simp_all
@[simp]
theorem mapAccumr_nil {f : α → σ → σ × β} {s : σ} : mapAccumr f Vector.nil s = (s, Vector.nil) :=
rfl
@[simp]
theorem mapAccumr_snoc {f : α → σ → σ × β} {s : σ} :
mapAccumr f (xs.snoc x) s
= let q := f x s
let r := mapAccumr f xs q.1
(r.1, r.2.snoc q.2) := by
induction xs
· rfl
· simp [*]
variable (ys : Vector β n)
@[simp]
theorem map₂_snoc {f : α → β → σ} {y : β} :
map₂ f (xs.snoc x) (ys.snoc y) = (map₂ f xs ys).snoc (f x y) := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_nil {f : α → β → σ → σ × φ} :
mapAccumr₂ f Vector.nil Vector.nil s = (s, Vector.nil) :=
rfl
@[simp]
theorem mapAccumr₂_snoc (f : α → β → σ → σ × φ) (x : α) (y : β) :
mapAccumr₂ f (xs.snoc x) (ys.snoc y) s
= let q := f x y s
let r := mapAccumr₂ f xs ys q.1
(r.1, r.2.snoc q.2) := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
end Simp
end Vector
end List
|
Cast.lean
|
/-
Copyright (c) 2021 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.Nat.Choose.Basic
import Mathlib.Data.Nat.Factorial.Cast
/-!
# Cast of binomial coefficients
This file allows calculating the binomial coefficient `a.choose b` as an element of a division ring
of characteristic `0`.
-/
open Nat
variable (K : Type*)
namespace Nat
section DivisionSemiring
variable [DivisionSemiring K] [CharZero K]
theorem cast_choose {a b : ℕ} (h : a ≤ b) : (b.choose a : K) = b ! / (a ! * (b - a)!) := by
have : ∀ {n : ℕ}, (n ! : K) ≠ 0 := Nat.cast_ne_zero.2 (factorial_ne_zero _)
rw [eq_div_iff_mul_eq (mul_ne_zero this this)]
rw_mod_cast [← mul_assoc, choose_mul_factorial_mul_factorial h]
theorem cast_add_choose {a b : ℕ} : ((a + b).choose a : K) = (a + b)! / (a ! * b !) := by
rw [cast_choose K (_root_.le_add_right le_rfl), add_tsub_cancel_left]
theorem cast_choose_eq_ascPochhammer_div (a b : ℕ) :
(a.choose b : K) = (ascPochhammer K b).eval ↑(a - (b - 1)) / b ! := by
rw [eq_div_iff_mul_eq (cast_ne_zero.2 b.factorial_ne_zero : (b ! : K) ≠ 0), ← cast_mul,
mul_comm, ← descFactorial_eq_factorial_mul_choose, ← cast_descFactorial]
end DivisionSemiring
section DivisionRing
variable [DivisionRing K] [CharZero K]
theorem cast_choose_eq_descPochhammer_div (a b : ℕ) :
(a.choose b : K) = (descPochhammer K b).eval ↑a / b ! := by
rw [eq_div_iff_mul_eq (cast_ne_zero.2 b.factorial_ne_zero : (b ! : K) ≠ 0), ← cast_mul,
mul_comm, ← descFactorial_eq_factorial_mul_choose, descPochhammer_eval_eq_descFactorial]
theorem cast_choose_two (a : ℕ) : (a.choose 2 : K) = a * (a - 1) / 2 := by
rw [← cast_descFactorial_two, descFactorial_eq_factorial_mul_choose, factorial_two, mul_comm,
cast_mul, cast_two, eq_div_iff_mul_eq (two_ne_zero : (2 : K) ≠ 0)]
end DivisionRing
end Nat
|
spectral.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat.
From mathcomp Require Import seq div fintype bigop ssralg finset fingroup zmodp.
From mathcomp Require Import poly polydiv order ssrnum matrix mxalgebra vector.
From mathcomp Require Import mxpoly mxred sesquilinear.
(******************************************************************************)
(* Spectral theory *)
(* *)
(* This file provides a formalization of Gram-Schmidt orthonormalization, *)
(* Schur decomposition, etc. *)
(* *)
(* M ^t* := M ^t conjC *)
(* Notation in scope sesquilinear_scope. *)
(* M \is unitarymx == M is a unitary matrix *)
(* M : 'M[C]_(m, n) with C : numClosedFieldType *)
(* M \is normalmx == M is a normal matrix *)
(* M : 'M[C]_n with C : numClosedFieldType *)
(* *)
(* dotmx u v == dot product *)
(* u and v are row vectors over a numClosedFieldType *)
(* Local notations: '[u, v] := dotmx u v, *)
(* '[u] := '[u, u] *)
(* proj_ortho Y := proj_mx <<U>>%MS U^!%MS *)
(* where U^! is a 1-orthogonal completement of U *)
(* schmidt A == Gram-Schmidt basis *)
(* A : 'M[C]_(m, n) *)
(* schmidt_complete V := col_mx (schmidt (row_base V)) *)
(* (schmidt (row_base V^!%MS)) *)
(* spectralmx A, spectral_diag A == (M,X) s.t. A = M^-1 *m diag_mx X *m M *)
(* A : 'M[C]_n *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Order.Theory Num.Theory.
Local Open Scope ring_scope.
Local Open Scope sesquilinear_scope.
(* TODO: move? *)
Lemma eigenvalue_closed {C : numClosedFieldType} n (A : 'M[C]_n) : (n > 0)%N ->
exists a, eigenvalue A a.
Proof.
move=> n_gt0; have /closed_rootP [a rAa] : size (char_poly A) != 1%N.
by rewrite size_char_poly; case: (n) n_gt0.
by exists a; rewrite eigenvalue_root_char.
Qed.
(* TODO: move? *)
Lemma common_eigenvector {C : numClosedFieldType} n (As : seq 'M[C]_n) :
(n > 0)%N -> {in As &, forall A B, comm_mx A B} ->
exists2 v : 'rV_n, v != 0 & all (fun A => stablemx v A) As.
Proof.
move=> n_gt0 /all_comm_mxP; have [k sAsk] := ubnP (size As).
elim: k n n_gt0 As sAsk => [//|k IHk] n n_gt0 [|A As].
exists (const_mx 1) => //; apply/negP => /eqP/rowP/(_ (Ordinal n_gt0)).
by rewrite !mxE => /eqP; rewrite oner_eq0.
rewrite ltnS all_comm_mx_cons => sAsk /andP[].
move=> /allP/(_ _ _)/eqP/= A_comm /all_comm_mxP As_comm.
have [a a_eigen] := eigenvalue_closed A n_gt0.
have [] := IHk _ _ [seq restrictmx (eigenspace A a) B | B <- As].
- by rewrite lt0n mxrank_eq0.
- by rewrite size_map.
- apply/all_comm_mxP; move=> _ _ /= /mapP /= [B B_in ->] /mapP /= [B' B'_in ->].
rewrite -?conjmxM ?inE ?stablemx_row_base ?comm_mx_stable_eigenspace//;
by [rewrite As_comm | apply: As_comm | apply: A_comm].
move=> v vN0 /allP /= vP; exists (v *m (row_base (eigenspace A a))).
by rewrite mulmx_free_eq0 ?row_base_free.
apply/andP; split.
by apply/eigenvectorP; exists a; rewrite mulmx_sub // eq_row_base.
apply/allP => B B_in; rewrite -stablemx_restrict ?vP //.
by apply/mapP; exists B.
by rewrite comm_mx_stable_eigenspace //; exact: A_comm.
Qed.
(* TODO: move? *)
Lemma common_eigenvector2 {C : numClosedFieldType}n (A B : 'M[C]_n) :
(n > 0)%N -> A *m B = B *m A ->
exists2 v : 'rV_n, v != 0 & (stablemx v A) && (stablemx v B).
Proof.
move=> n_gt0 AB_comm; have [] := @common_eigenvector _ _ [:: A; B] n_gt0.
by move=> A' B'; rewrite !inE => /orP [] /eqP-> /orP [] /eqP->.
by move=> v v_neq0 /allP vP; exists v; rewrite ?vP ?(mem_head, in_cons, orbT).
Qed.
Notation "M ^t*" := (M ^t conjC) (at level 30) : sesquilinear_scope.
Notation realmx := (mxOver Num.real).
Lemma trmxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) : A ^t* ^t* = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
Section realmx.
Context {C : numClosedFieldType} {m n : nat}.
Implicit Types A B : 'M[C]_(m, n).
Lemma realmxC A : A \is a realmx -> A ^ conjC = A.
Proof.
by move=> ?; apply/matrixP => x y; rewrite mxE; exact/CrealP/mxOverP.
Qed.
Lemma realmxD A B : A \is a realmx -> B \is a realmx -> A + B \is a realmx.
Proof.
rewrite !qualifE/= => /'forall_forallP realA /'forall_forallP realB.
by apply/'forall_forallP => i j; rewrite mxE realD.
Qed.
Lemma Remx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Re _) = A}.
Proof.
move=> A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Re_rect // (mxOverP _ _).
Qed.
Lemma Immx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Im _) = B}.
Proof.
move=> /= A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Im_rect // (mxOverP _ _).
Qed.
Lemma eqmx_ReiIm A B A' B' :
A \is a realmx -> B \is a realmx -> A' \is a realmx -> B' \is a realmx ->
(A + 'i *: B) = (A' + 'i *: B') -> (A, B) = (A', B').
Proof.
move=> ARe BRe A'Im B'Im eqAB.
have /(congr1 (fun A => A ^ (@Im _))) := eqAB.
have /(congr1 (fun A => A ^ (@Re _))) := eqAB.
by rewrite !Remx_rect// !Immx_rect// => -> ->.
Qed.
End realmx.
Lemma realsym_hermsym {C : numClosedFieldType} {n} (A : 'M[C]_n) :
A \is symmetricmx -> A \is a realmx -> A \is hermsymmx.
Proof.
move=> Asym Areal; apply/is_hermitianmxP.
by rewrite (trmx_hermitian (HermitianMx Asym))/= !scale1r ?realmxC ?map_mx_id.
Qed.
Lemma real_similar {C : numClosedFieldType} {n} (A B : 'M[C]_n) :
similar_in unitmx A B ->
A \is a realmx -> B \is a realmx -> similar_in [predI realmx & unitmx] A B.
Proof.
case=> [P /=]; pose Pr := P ^ (@Re _); pose Pi := P ^ (@Im _).
have Pr_real : Pr \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Re.
have Pi_real : Pi \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Im.
pose Q x := P ^ (@Re _) + x *: P ^ (@Im _).
have -> : P = Q 'i by apply/matrixP=> i j; rewrite !mxE -Crect.
move=> Qi_unit eq_AP_PB Areal Breal.
pose p := \det (Pr ^ polyC + 'X *: Pi ^ polyC).
have horner_evaliC x : horner_eval (x : C) \o polyC =1 id := fun=> hornerC _ _.
have Qunit x : Q x \in unitmx = (p.[x] != 0).
rewrite /p -horner_evalE -det_map_mx map_mxD map_mxZ/= horner_evalE hornerX.
by rewrite -![(_ ^ polyC) ^ _]map_mx_comp !map_mx_id// unitmxE unitfE.
have p_neq0 : p != 0.
by move: Qi_unit; rewrite Qunit; apply: contra_neq => ->; rewrite hornerE.
have [a a_real rootNa] : exists2 a, a \is Num.real & ~~ root p a.
have rs_uniq : uniq [seq (i%:R : C) | i <- iota 0 (size p)].
by rewrite map_inj_uniq ?iota_uniq //; apply: mulrIn; rewrite oner_eq0.
have := contraNN (fun x => max_poly_roots p_neq0 x rs_uniq).
rewrite size_map size_iota ltnn => /(_ isT) /allPn[a a_in rootNpa].
by exists a => //; by move: a_in => /mapP [i _ ->]; rewrite realn.
exists (Q a).
rewrite inE Qunit rootNa andbT.
rewrite /Q/=.
by rewrite realmxD// mxOverZ.
apply/similarP; rewrite ?Qunit//; move: eq_AP_PB => /(similarP Qi_unit).
rewrite !mulmxDl !mulmxDr -!scalemxAr -!scalemxAl => /eqmx_ReiIm.
by rewrite !mxOverM// => /(_ isT isT isT isT) [-> ->].
Qed.
Section unitarymx.
Context {C : numClosedFieldType}.
Definition unitarymx {m n} := [qualify X : 'M[C]_(m, n) | X *m X ^t* == 1%:M].
Fact unitarymx_key m n : pred_key (@unitarymx m n). Proof. by []. Qed.
Canonical unitarymx_keyed m n := KeyedQualifier (unitarymx_key m n).
Lemma unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (M *m M^t* = 1%:M) (M \is unitarymx).
Proof. by apply: (iffP eqP). Qed.
Lemma mulmxtVK m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(n, m2)) :
B \is unitarymx -> A *m B *m B^t* = A.
Proof. by move=> B_unitary; rewrite -mulmxA (unitarymxP _) ?mulmx1. Qed.
Lemma unitarymx_unit n (M : 'M[C]_n) : M \is unitarymx -> M \in unitmx.
Proof. by move=> /unitarymxP /mulmx1_unit []. Qed.
Lemma invmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> invmx M = M^t*.
Proof.
move=> Munitary; apply: (@row_full_inj _ _ _ _ M).
by rewrite row_full_unit unitarymx_unit.
by rewrite mulmxV ?unitarymx_unit ?(unitarymxP _).
Qed.
Lemma mulmxKtV m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(m2, n)) :
B \is unitarymx -> m2 = n -> A *m B^t* *m B = A.
Proof.
move=> B_unitary m2E; case: _ / (esym m2E) in B B_unitary *.
by rewrite -invmx_unitary // mulmxKV //; exact: unitarymx_unit.
Qed.
Lemma mxrank_unitary m n (M : 'M[C]_(m, n)) : M \is unitarymx -> \rank M = m.
Proof.
rewrite qualifE => /eqP /(congr1 mxrank); rewrite mxrank1 => rkM.
apply/eqP; rewrite eqn_leq rank_leq_row /= -[X in (X <= _)%N]rkM.
by rewrite mxrankM_maxl.
Qed.
Lemma mul_unitarymx m n p (A : 'M[C]_(m, n)) (B : 'M[C]_(n, p)) :
A \is unitarymx -> B \is unitarymx -> A *m B \is unitarymx.
Proof.
move=> Aunitary Bunitary; apply/unitarymxP; rewrite trmx_mul map_mxM.
by rewrite mulmxA -[A *m _ *m _]mulmxA !(unitarymxP _, mulmx1).
Qed.
Lemma pinvmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> pinvmx M = M^t*.
Proof. by move=> Munitary; rewrite pinvmxE ?unitarymx_unit// invmx_unitary. Qed.
Lemma conjymx n (P M : 'M[C]_n) : P \is unitarymx -> conjmx P M = P *m M *m P^t*.
Proof. by move=> Munitary; rewrite conjumx ?invmx_unitary ?unitarymx_unit. Qed.
Lemma trmx_unitary n (M : 'M[C]_n) : (M ^T \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_trmx -trmx_mul.
by rewrite -trmx1 => /trmx_inj /mulmx1C->; rewrite trmx1.
by move=> /mulmx1C->; rewrite trmx1.
Qed.
Lemma conjC_unitary m n (M : 'M[C]_(m, n)) :
(M ^ conjC \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_mxM ?map_trmx; last first.
by move=> ->; rewrite map_mx1.
by rewrite -[1%:M](map_mx1 conjC) => /map_mx_inj ->; rewrite map_mx1.
Qed.
Lemma trmxC_unitary n (M : 'M[C]_n) : (M ^t* \is unitarymx) = (M \is unitarymx).
Proof. by rewrite conjC_unitary trmx_unitary. Qed.
End unitarymx.
Section normalmx.
Context {C : numClosedFieldType} {n : nat}.
Definition normalmx := [qualify M : 'M[C]_n | M *m M ^t* == M ^t* *m M].
Fact normalmx_key : pred_key normalmx. Proof. by []. Qed.
Canonical normalmx_keyed := KeyedQualifier normalmx_key.
Lemma normalmxP {M : 'M[C]_n} :
reflect (M *m M ^t* = M ^t* *m M) (M \is normalmx).
Proof. exact: eqP. Qed.
Lemma hermitian_normalmx (A : 'M[C]_n) : A \is hermsymmx -> A \is normalmx.
Proof.
move=> Ahermi; apply/normalmxP.
by rewrite (trmx_hermitian (HermitianMx Ahermi)) scale1r map_mxCK.
Qed.
Lemma symmetric_normalmx (A : 'M[C]_n) : A \is symmetricmx ->
A \is a realmx -> A \is normalmx.
Proof. by move=> Asym Areal; rewrite hermitian_normalmx// realsym_hermsym. Qed.
End normalmx.
Section Spectral.
Variable (C : numClosedFieldType).
Set Default Proof Using "C".
Local Notation dotmx_def := (form_of_matrix (@conjC _) 1%:M).
Definition dotmx n (u v : 'rV[C]_n) := dotmx_def u%R v%R.
(*
TODO: bug report
we were expecting
HB.instance Definition _ n := Bilinear.on (@dotmx n).
to be sufficient to equip dotmx with the bilinear structure
but needed to use .copy in the end as in:
*)
HB.instance Definition _ n := Bilinear.copy (@dotmx n) dotmx_def.
Local Notation "''[' u , v ]" := (dotmx u v) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
HB.instance Definition _ n := Hermitian.copy (@dotmx n) dotmx_def.
Lemma dotmxE n (u v : 'rV[C]_n) : '[u, v] = ( u *m v ^t* ) 0 0.
Proof. by rewrite /dotmx /form_of_matrix mulmx1 /= trace_mx11. Qed.
Lemma row_unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (forall i j, '[row i M, row j M] = (i == j)%:R) (M \is unitarymx).
Proof.
apply: (iffP eqP) => [Mo i j|Mo].
have /matrixP/(_ i j) := Mo; rewrite !mxE => <-.
by rewrite dotmxE !mxE; apply: eq_bigr => /= k _; rewrite !mxE.
apply/matrixP=> i j; rewrite !mxE; have := Mo i j; rewrite dotmxE !mxE => <-.
by apply: eq_bigr => /= k _; rewrite !mxE.
Qed.
Fact dotmx_is_dotmx n (u : 'rV[C]_n) : u != 0 -> 0 < '[u].
Proof.
move=> u_neq0; rewrite dotmxE mxE.
suff /existsP[i ui_neq0] : [exists i, u 0 i != 0].
rewrite (bigD1 i) //= ltr_wpDr// ?sumr_ge0// ?mxE ?mul_conjC_gt0//.
by move=> j _; rewrite !mxE mul_conjC_ge0.
apply: contraNT u_neq0; rewrite negb_exists => /forallP uNN0.
by apply/eqP/rowP=> j; rewrite mxE; apply/eqP; rewrite -[_ == _]negbK uNN0.
Qed.
HB.instance Definition _ n := isDotProduct.Build _ _ (@dotmx n)
(@dotmx_is_dotmx n).
Local Notation "B ^!" :=
(orthomx (@conjC C) (mx_of_hermitian (hermitian1mx _)) B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B^!)%MS : bool_scope.
Lemma orthomx1E m n p (A : 'M[C]_(m, n)) (B : 'M_(p, n)) :
(A '_|_ B)%MS = (A *m B^t* == 0).
Proof. by apply/sub_kermxP/eqP; rewrite !mul1mx. Qed.
Lemma orthomx1P m n p {A : 'M[C]_(m, n)} {B : 'M_(p, n)} :
reflect (A *m B^t* = 0) (A '_|_ B).
Proof. by rewrite orthomx1E; exact/eqP. Qed.
Lemma orthomx_disj n p q (A : 'M[C]_(p, n)) (B :'M_(q, n)) :
A '_|_ B -> (A :&: B = 0)%MS.
Proof.
move=> nAB; apply/eqP/rowV0Pn => [[v]]; rewrite sub_capmx => /andP [vA vB].
apply/negP; rewrite negbK.
by rewrite -(dnorm_eq0 (@dotmx n)) -orthomxE (orthomxP _ _ _ nAB).
Qed.
Lemma orthomx_ortho_disj n p (A : 'M[C]_(p, n)) : (A :&: A^! = 0)%MS.
Proof. exact/orthomx_disj/ortho_mx_ortho. Qed.
Lemma rank_ortho p n (A : 'M[C]_(p, n)) : \rank A^! = (n - \rank A)%N.
Proof. by rewrite mxrank_ker mul1mx mxrank_map mxrank_tr. Qed.
Lemma add_rank_ortho p n (A : 'M[C]_(p, n)) : (\rank A + \rank A^!)%N = n.
Proof. by rewrite rank_ortho subnKC ?rank_leq_col. Qed.
Lemma addsmx_ortho p n (A : 'M[C]_(p, n)) : (A + A^! :=: 1%:M)%MS.
Proof.
apply/eqmxP/andP; rewrite submx1; split=> //.
rewrite -mxrank_leqif_sup ?submx1 ?mxrank1 ?(mxdirectP _) /= ?add_rank_ortho //.
by rewrite mxdirect_addsE /= ?mxdirectE ?orthomx_ortho_disj !eqxx.
Qed.
Lemma ortho_id p n (A : 'M[C]_(p, n)) : (A^!^! :=: A)%MS.
Proof.
apply/eqmx_sym/eqmxP.
by rewrite -mxrank_leqif_eq 1?orthomx_sym // !rank_ortho subKn // ?rank_leq_col.
Qed.
Lemma submx_ortho p m n (U : 'M[C]_(p, n)) (V : 'M_(m, n)) :
(U^! <= V^!)%MS = (V <= U)%MS.
Proof. by rewrite orthomx_sym ortho_id. Qed.
Definition proj_ortho p n (U : 'M[C]_(p, n)) := proj_mx <<U>>%MS U^!%MS.
Lemma sub_adds_genmx_ortho (p m n : nat) (U : 'M[C]_(p, n)) (W : 'M_(m, n)) :
(W <= <<U>> + U^!)%MS.
Proof.
by rewrite !(adds_eqmx (genmxE _) (eqmx_refl _)) addsmx_ortho submx1.
Qed.
Local Hint Resolve sub_adds_genmx_ortho : core.
Lemma cap_genmx_ortho p n (U : 'M[C]_(p, n)) : (<<U>> :&: U^!)%MS = 0.
Proof.
apply/eqmx0P; rewrite !(cap_eqmx (genmxE _) (eqmx_refl _)).
by rewrite orthomx_ortho_disj; exact/eqmx0P.
Qed.
Local Hint Resolve cap_genmx_ortho : core.
Lemma proj_ortho_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W *m proj_ortho U <= U)%MS.
Proof. by rewrite (submx_trans (proj_mx_sub _ _ _)) // genmxE. Qed.
Lemma proj_ortho_compl_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W - W *m proj_ortho U <= U^!)%MS.
Proof. by rewrite proj_mx_compl_sub // addsmx_ortho submx1. Qed.
Lemma proj_ortho_id p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U)%MS -> W *m proj_ortho U = W.
Proof. by move=> WU; rewrite proj_mx_id ?genmxE. Qed.
Lemma proj_ortho_0 p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U^!)%MS -> W *m proj_ortho U = 0.
Proof. by move=> WUo; rewrite proj_mx_0. Qed.
Lemma add_proj_ortho p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
W *m proj_ortho U + W *m proj_ortho U^!%MS = W.
Proof.
rewrite -[W in LHS](@add_proj_mx _ _ _ <<U>>%MS U^!%MS W)//.
rewrite !mulmxDl proj_ortho_id ?proj_ortho_sub //.
rewrite proj_ortho_0 ?proj_mx_sub // addr0.
rewrite proj_ortho_0 ?ortho_id ?proj_ortho_sub // add0r.
by rewrite proj_ortho_id ?proj_mx_sub// add_proj_mx.
Qed.
Lemma proj_ortho_proj m n (U : 'M_(m, n)) : let P := proj_ortho U in P *m P = P.
Proof. by rewrite /= proj_mx_proj. Qed.
Lemma proj_orthoE p n (U : 'M_(p, n)) : (proj_ortho U :=: U)%MS.
Proof.
apply/eqmxP/andP; split; first by rewrite -proj_ortho_proj proj_ortho_sub.
by rewrite -[X in (X <= _)%MS](proj_ortho_id (submx_refl U)) mulmx_sub.
Qed.
Lemma orthomx_proj_mx_ortho p p' m m' n
(A : 'M_(p, n)) (A' : 'M_(p', n))
(W : 'M_(m, n)) (W' : 'M_(m', n)) :
A '_|_ A' -> W *m proj_ortho A '_|_ W' *m proj_ortho A'.
Proof.
rewrite orthomx_sym => An.
rewrite mulmx_sub // orthomx_sym (eqmx_ortho _ (proj_orthoE _)).
by rewrite (submx_trans _ An) // proj_ortho_sub.
Qed.
Lemma schmidt_subproof m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
exists2 B : 'M_(m, n), B \is unitarymx & [forall i : 'I_m,
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k B>>))%MS
&& ('[row i A, row i B] >= 0) ].
Proof.
elim: m A => [|m IHm].
exists (pid_mx n); first by rewrite qualifE !thinmx0.
by apply/forallP=> -[].
rewrite -addn1 => A leq_Sm_n.
have lemSm : (m <= m + 1)%N by rewrite addn1.
have ltmSm : (m < m + 1)%N by rewrite addn1.
have lemn : (m <= n)%N by rewrite ltnW // -addn1.
have [B Bortho] := IHm (usubmx A) lemn.
move=> /forallP /= subAB.
have [v /and4P [vBn v_neq0 dAv_ge0 dAsub]] :
exists v, [&& B '_|_ v, v != 0, '[dsubmx A, v] >= 0 & (dsubmx A <= B + v)%MS].
have := add_proj_ortho B (dsubmx A).
set BoSn := (_ *m proj_ortho _^!%MS) => pBE.
have [BoSn_eq0|BoSn_neq0] := eqVneq BoSn 0.
rewrite BoSn_eq0 addr0 in pBE.
have /rowV0Pn [v vBn v_neq0] : B^!%MS != 0.
rewrite -mxrank_eq0 rank_ortho -lt0n subn_gt0.
by rewrite mxrank_unitary // -addn1.
rewrite orthomx_sym in vBn.
exists v; rewrite vBn v_neq0 -pBE.
rewrite ['[_, _]](hermmx_eq0P _ _) ?lexx //=.
rewrite (submx_trans (proj_ortho_sub _ _)) //.
by rewrite -{1}[B]addr0 addmx_sub_adds ?sub0mx.
by rewrite (submx_trans _ vBn) // proj_ortho_sub.
pose c := (sqrtC '[BoSn])^-1; have c_gt0 : c > 0.
by rewrite invr_gt0 sqrtC_gt0 lt_def ?dnorm_eq0 ?dnorm_ge0 BoSn_neq0.
exists BoSn; apply/and4P; split => //.
- by rewrite orthomx_sym ?proj_ortho_sub // /gtr_eqF.
- rewrite -pBE linearDl //.
rewrite [X in X + '[_]](hermmx_eq0P _ _) ?add0r ?dnorm_ge0 //.
by rewrite orthomx_proj_mx_ortho // orthomx_sym.
- by rewrite -pBE addmx_sub_adds // proj_ortho_sub.
wlog nv_eq1 : v vBn v_neq0 dAv_ge0 dAsub / '[v] = 1.
pose c := (sqrtC '[v])^-1.
have c_gt0 : c > 0 by rewrite invr_gt0 sqrtC_gt0 ?dnorm_gt0.
have [c_ge0 c_eq0F] := (ltW c_gt0, gt_eqF c_gt0).
move=> /(_ (c *: v)); apply.
- by rewrite orthomxZ ?c_eq0F.
- by rewrite scaler_eq0 c_eq0F.
- by rewrite linearZr mulr_ge0 // conjC_ge0.
- by rewrite (submx_trans dAsub) // addsmxS // eqmx_scale // c_eq0F.
- rewrite dnormZ normfV ger0_norm ?sqrtC_ge0 ?dnorm_ge0 //.
by rewrite exprVn rootCK ?mulVf // dnorm_eq0.
exists (col_mx B v).
apply/row_unitarymxP => i j.
case: (split_ordP i) (split_ordP j) => [] i' -> [] j' ->;
rewrite eq_shift ?(rowKu, rowKd, row_id, ord1) -?val_eqE /=
?(row_unitarymxP _) //= ?addn0.
by rewrite ['[_, _]](hermmx_eq0P _ _)//= (submx_trans _ vBn)// row_sub.
rewrite ['[_, _]](hermmx_eq0P _ _)//= orthomx_sym (submx_trans _ vBn) //.
exact: row_sub.
apply/forallP => i; case: (split_ordP i) => j -> /=.
have /andP [sABj dot_gt0] := subAB j.
rewrite rowKu -row_usubmx (submx_trans sABj) //=.
rewrite (eq_rect _ (submx _) (submx_refl _)) //.
rewrite [in RHS](reindex (lshift 1)) /=.
by apply: eq_bigr=> k k_le; rewrite rowKu.
exists (fun k => insubd j k) => k; rewrite inE /= => le_kj;
by apply/val_inj; rewrite /= insubdK // -topredE /= (leq_ltn_trans le_kj).
rewrite rowKd -row_dsubmx !row_id ord1 ?dAv_ge0 ?andbT {j} addn0.
rewrite (bigD1 (rshift _ ord0)) /= ?addn0 ?rowKd ?row_id // addsmxC.
rewrite (submx_trans dAsub) // addsmxS ?genmxE //.
apply/row_subP => j; apply/(sumsmx_sup (lshift _ j)) => //=.
by rewrite ltnW ?ltn_ord //= -val_eqE /= addn0 ltn_eqF.
by rewrite rowKu genmxE.
Qed.
Definition schmidt m n (A : 'M[C]_(m, n)) :=
if (m <= n)%N =P true is ReflectT le_mn
then projT1 (sig2_eqW (schmidt_subproof A le_mn))
else A.
Lemma schmidt_unitarymx m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
schmidt A \is unitarymx.
Proof. by rewrite /schmidt; case: eqP => // ?; case: sig2_eqW. Qed.
Hint Resolve schmidt_unitarymx : core.
Lemma row_schmidt_sub m n (A : 'M[C]_(m, n)) i :
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k (schmidt A)>>))%MS.
Proof.
rewrite /schmidt; case: eqP => // ?.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
by apply/(sumsmx_sup i) => //; rewrite genmxE.
Qed.
Lemma form1_row_schmidt m n (A : 'M[C]_(m, n)) i :
'[row i A, row i (schmidt A)] >= 0.
Proof.
rewrite /schmidt; case: eqP => // ?; rewrite ?dnorm_ge0 //.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
Qed.
Lemma schmidt_sub m n (A : 'M[C]_(m, n)) : (A <= schmidt A)%MS.
Proof.
apply/row_subP => i; rewrite (submx_trans (row_schmidt_sub _ _)) //.
by apply/sumsmx_subP => /= j le_ji; rewrite genmxE row_sub.
Qed.
Hint Resolve schmidt_sub : core.
Lemma eqmx_schmidt_full m n (A : 'M[C]_(m, n)) :
row_full A -> (schmidt A :=: A)%MS.
Proof.
move=> Afull; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans n) ?rank_leq_col ?col_leq_rank.
Qed.
Lemma eqmx_schmidt_free m n (A : 'M[C]_(m, n)) :
row_free A -> (schmidt A :=: A)%MS.
Proof.
move=> Afree; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans m) ?rank_leq_row // ?row_leq_rank.
Qed.
Definition schmidt_complete m n (V : 'M[C]_(m, n)) :=
col_mx (schmidt (row_base V)) (schmidt (row_base V^!%MS)).
Lemma schmidt_complete_unitarymx m n (V : 'M[C]_(m, n)) :
schmidt_complete V \is unitarymx.
Proof.
apply/unitarymxP; rewrite tr_col_mx map_row_mx mul_col_row.
rewrite !(unitarymxP _) ?schmidt_unitarymx ?rank_leq_col //.
move=> [:nsV]; rewrite !(orthomx1P _) -?scalar_mx_block //;
[abstract: nsV|]; last by rewrite orthomx_sym.
by do 2!rewrite eqmx_schmidt_free ?eq_row_base ?row_base_free // orthomx_sym.
Qed.
Lemma cotrigonalization n (As : seq 'M[C]_n) :
{in As &, forall A B, comm_mx A B} ->
cotrigonalizable_in (@unitarymx C n n) As.
Proof.
elim: n {-2}n (leqnn n) As => [|N IHN] n.
rewrite leqn0 => /eqP n_eq0.
exists 1%:M; first by rewrite qualifE mul1mx trmx1 map_mx1.
apply/allP => ? ?; apply/is_trig_mxP => i j.
by suff: False by []; move: i; rewrite n_eq0 => -[].
rewrite leq_eqVlt => /predU1P [n_eqSN|/IHN//].
have /andP [n_gt0 n_small] : (n > 0)%N && (n - 1 <= N)%N.
by rewrite n_eqSN /= subn1.
move=> As As_comm;
have [v vN0 /allP /= vP] := common_eigenvector n_gt0 As_comm.
suff: exists2 P : 'M[C]_(\rank v + \rank v^!, n), P \is unitarymx &
all (fun A => is_trig_mx (P *m A *m ( P^t* ))) As.
rewrite add_rank_ortho // => -[P P_unitary] /=; rewrite -invmx_unitary//.
by under eq_all do rewrite -conjumx ?unitarymx_unit//; exists P.
pose S := schmidt_complete v.
pose r A := S *m A *m S^t*.
have vSvo X : stablemx v X ->
schmidt (row_base v) *m X *m schmidt (row_base v^!%MS) ^t* = 0.
move=> /eigenvectorP [a v_in].
rewrite (eigenspaceP (_ : (_ <= _ a))%MS); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
rewrite -scalemxAl (orthomx1P _) ?scaler0 //.
by do 2!rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base // orthomx_sym.
have drrE X : drsubmx (r X) =
schmidt (row_base v^!%MS) *m X *m schmidt (row_base v^!%MS) ^t*.
by rewrite /r mul_col_mx tr_col_mx map_row_mx mul_col_row block_mxKdr.
have vSv X a : (v <= eigenspace X a)%MS ->
schmidt (row_base v) *m X *m schmidt (row_base v) ^t* = a%:M.
move=> vXa; rewrite (eigenspaceP (_ : (_ <= _ a)%MS)); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
by rewrite -scalemxAl (unitarymxP _) ?scalemx1 ?schmidt_unitarymx ?rank_leq_col.
have [] := IHN _ _ [seq drsubmx (r A) | A <- As].
- by rewrite rank_ortho rank_rV vN0.
- move=> _ _ /mapP[/= A A_in ->] /mapP[/= B B_in ->].
have : (r A) *m (r B) = (r B) *m (r A).
rewrite /r !mulmxA !mulmxKtV // ?schmidt_complete_unitarymx //;
by rewrite ?add_rank_ortho // -![S *m _ *m _]mulmxA As_comm.
rewrite -[r A in X in X -> _]submxK -[r B in X in X -> _]submxK.
rewrite 2!mulmx_block => /eq_block_mx [_ _ _].
suff urr_eq0 X : X \in As -> ursubmx (r X) = 0.
by rewrite !urr_eq0 ?mulmx0 ?add0r.
rewrite /r /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !block_mxKur.
by move=> X_in; rewrite vSvo // vP.
move=> P' P'_unitary /allP /= P'P.
exists ((block_mx 1%:M 0 0 P') *m S).
rewrite mul_unitarymx ?schmidt_complete_unitarymx //.
apply/unitarymxP; rewrite tr_block_mx map_block_mx mulmx_block.
rewrite !trmx0 !(@map_mx0 _ _ conjC) !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
by rewrite (unitarymxP _) -?scalar_mx_block //.
apply/allP => /= A A_in.
rewrite trmx_mul map_mxM tr_block_mx map_block_mx.
rewrite !trmx0 !map_mx0 !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite mulmxA -[_ *m S *m _]mulmxA -[_ *m _ *m S^t*]mulmxA.
rewrite /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !mulmx_block.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
apply/is_trig_mxP => /= i j lt_ij; rewrite mxE.
case: splitP => //= i' i_eq; rewrite !mxE;
case: splitP => //= j' j_eq.
- have /vP /eigenvectorP [a v_in] := A_in.
by rewrite (vSv _ _ v_in) mxE -val_eqE ltn_eqF //= -i_eq -j_eq.
- by rewrite vSvo ?mul0mx ?mxE // vP //.
- move: lt_ij; rewrite i_eq j_eq ltnNge -ltnS (leq_trans (ltn_ord j'))//.
by rewrite -addnS leq_addr.
- set A' := _ *m A *m _; rewrite -invmx_unitary // -conjumx ?unitarymx_unit//.
have /(_ _) /is_trig_mxP -> // := P'P A'; last first.
by move: lt_ij; rewrite i_eq j_eq ltn_add2l.
by apply/mapP; exists A; rewrite //= drrE.
Qed.
Theorem Schur n (A : 'M[C]_n) : (n > 0)%N ->
trigonalizable_in (@unitarymx C n n) A.
Proof.
case: n => [//|n] in A * => _; have [] := @cotrigonalization _ [:: A].
by move=> ? ? /=; rewrite !in_cons !orbF => /eqP-> /eqP->.
by move=> P P_unitary /=; rewrite andbT=> A_trigo; exists P.
Qed.
Lemma cotrigonalization2 n (A B : 'M[C]_n) : A *m B = B *m A ->
exists2 P : 'M[C]_n, P \is unitarymx &
similar_trig P A && similar_trig P B.
Proof.
move=> AB_comm; have [] := @cotrigonalization _ [:: A; B].
by move=> ??; rewrite !inE => /orP[]/eqP->/orP[]/eqP->.
move=> P Punitary /allP /= PP; exists P => //.
by rewrite !PP ?(mem_head, in_cons, orbT).
Qed.
Theorem orthomx_spectral_subproof n {A : 'M[C]_n} : reflect
(exists2 sp : 'M_n * 'rV_n,
sp.1 \is unitarymx &
A = invmx sp.1 *m diag_mx sp.2 *m sp.1)
(A \is normalmx).
Proof.
apply: (iffP normalmxP); last first.
move=> [[/= P D] P_unitary ->].
rewrite !trmx_mul !map_mxM !mulmxA invmx_unitary //.
rewrite !trmxCK ![_ *m P *m _]mulmxtVK //.
by rewrite -[X in X *m P]mulmxA tr_diag_mx map_diag_mx diag_mxC mulmxA.
move=> /cotrigonalization2 [P Punitary /andP[]] PA PATC.
have Punit := unitarymx_unit Punitary.
suff: similar_diag P A.
move=> /similar_diagPex[D] PAD; exists (P, D) => //=.
by rewrite -conjVmx//; exact/similarLR.
apply/similar_diagPp => // i j; case: ltngtP => // [lt_ij|lt_ji] _.
by have /is_trig_mxP-> := PA.
have /is_trig_mxP -/(_ j i lt_ji)/eqP := PATC.
rewrite !conjumx// invmx_unitary// -[P as X in X *m _]trmxCK.
by rewrite -!map_mxM -!trmx_mul mulmxA 2!mxE conjC_eq0 => /eqP.
Qed.
Definition spectralmx n (A : 'M[C]_n) : 'M[C]_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).1 else 1%:M.
Definition spectral_diag n (A : 'M[C]_n) : 'rV_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).2 else 0.
Lemma spectral_unitarymx n (A : 'M[C]_n) : spectralmx A \is unitarymx.
Proof.
rewrite /spectralmx; case: orthomx_spectral_subproof; last first.
by move=> _; apply/unitarymxP; rewrite trmx1 map_mx1 mulmx1.
by move=> ?; case: sig2_eqW.
Qed.
Lemma spectral_unit n (A : 'M[C]_n) : spectralmx A \in unitmx.
Proof. exact/unitarymx_unit/spectral_unitarymx. Qed.
Theorem orthomx_spectralP {n} {A : 'M[C]_n}
(P := spectralmx A) (sp := spectral_diag A) :
reflect (A = invmx P *m diag_mx sp *m P) (A \is normalmx).
Proof.
rewrite /P /sp /spectralmx /spectral_diag.
case: orthomx_spectral_subproof.
by move=> Psp; case: sig2_eqW => //=; constructor.
move=> /orthomx_spectral_subproof Ann; constructor; apply/eqP.
apply: contra Ann; rewrite invmx1 mul1mx mulmx1 => /eqP->.
suff -> : diag_mx 0 = 0 by rewrite qualifE trmx0 (map_mx0 conjC).
by move=> ? ?; apply/matrixP=> i j; rewrite !mxE mul0rn.
Qed.
Lemma hermitian_spectral_diag_real n (A : 'M[C]_n) : A \is hermsymmx ->
spectral_diag A \is a realmx.
Proof.
move=> Ahermi; have /hermitian_normalmx /orthomx_spectralP A_eq := Ahermi.
have /(congr1 ( fun X => X^t* )) := A_eq.
rewrite invmx_unitary ?spectral_unitarymx //.
rewrite !trmx_mul !map_mxM map_trmx trmxK -map_mx_comp.
rewrite tr_diag_mx map_diag_mx (map_mx_id (@conjCK _)).
rewrite -[in RHS]invmx_unitary ?spectral_unitarymx //.
have := is_hermitianmxP _ _ _ Ahermi; rewrite expr0 scale1r => <-.
rewrite {1}A_eq mulmxA => /(congr1 (mulmx^~ (invmx (spectralmx A)))).
rewrite !mulmxK ?spectral_unit//.
move=> /(congr1 (mulmx (spectralmx A))); rewrite !mulKVmx ?spectral_unit//.
move=> eq_A_conjA; apply/mxOverP => i j; rewrite ord1 {i}.
have /matrixP /(_ j j) := eq_A_conjA; rewrite !mxE eqxx !mulr1n.
by move=> /esym/CrealP.
Qed.
End Spectral.
|
automorphism.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat fintype.
From mathcomp Require Import finset fingroup perm morphism.
(******************************************************************************)
(* Group automorphisms and characteristic subgroups. *)
(* Unlike morphisms on a group G, which are functions of type gT -> rT, with *)
(* a canonical structure of dependent type {morphim G >-> rT}, automorphisms *)
(* are permutations of type {perm gT} contained in Aut G : {set {perm gT}}. *)
(* This lets us use the finGroupType of {perm gT}. Note also that while *)
(* morphisms on G are undefined outside G, automorphisms have their support *)
(* in G, i.e., they are the identity outside G. *)
(* Definitions: *)
(* Aut G (or [Aut G]) == the automorphism group of G. *)
(* [Aut G]%G == the group structure for Aut G. *)
(* autm AutGa == the morphism on G induced by a, given *)
(* AutGa : a \in Aut G. *)
(* perm_in injf fA == the permutation with support B in induced by f, *)
(* given injf : {in A &, injective f} and *)
(* fA : f @: A \subset A. *)
(* aut injf fG == the automorphism of G induced by the morphism f, *)
(* given injf : 'injm f and fG : f @* G \subset G. *)
(* Aut_isom injf sDom == the injective homomorphism that maps Aut G to *)
(* Aut (f @* G), with f : {morphism D >-> rT} and *)
(* given injf: 'injm f and sDom : G \subset D. *)
(* conjgm G == the conjugation automorphism on G. *)
(* H \char G == H is a characteristic subgroup of G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
(***********************************************************************)
(* A group automorphism, defined as a permutation on a subset of a *)
(* finGroupType that respects the morphism law. *)
(* Here perm_on is used as a closure rule for the set A. *)
(***********************************************************************)
Section Automorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Types a b : {perm gT}.
Definition Aut A := [set a | perm_on A a & morphic A a].
Lemma Aut_morphic A a : a \in Aut A -> morphic A a.
Proof. by case/setIdP. Qed.
Lemma out_Aut A a x : a \in Aut A -> x \notin A -> a x = x.
Proof. by case/setIdP=> Aa _; apply: out_perm. Qed.
Lemma eq_Aut A : {in Aut A &, forall a b, {in A, a =1 b} -> a = b}.
Proof.
move=> a g Aa Ag /= eqag; apply/permP=> x.
by have [/eqag // | /out_Aut out] := boolP (x \in A); rewrite !out.
Qed.
(* The morphism that is represented by a given element of Aut A. *)
Definition autm A a (AutAa : a \in Aut A) := morphm (Aut_morphic AutAa).
Lemma autmE A a (AutAa : a \in Aut A) : autm AutAa = a.
Proof. by []. Qed.
Canonical autm_morphism A a aM := Eval hnf in [morphism of @autm A a aM].
Section AutGroup.
Variable G : {group gT}.
Lemma Aut_group_set : group_set (Aut G).
Proof.
apply/group_setP; split=> [|a b].
by rewrite inE perm_on1; apply/morphicP=> ? *; rewrite !permE.
rewrite !inE => /andP[Ga aM] /andP[Gb bM]; rewrite perm_onM //=.
apply/morphicP=> x y Gx Gy; rewrite !permM (morphicP aM) //.
by rewrite (morphicP bM) ?perm_closed.
Qed.
Canonical Aut_group := group Aut_group_set.
Variable (a : {perm gT}) (AutGa : a \in Aut G).
Notation f := (autm AutGa).
Notation fE := (autmE AutGa).
Lemma injm_autm : 'injm f.
Proof. by apply/injmP; apply: in2W; apply: perm_inj. Qed.
Lemma ker_autm : 'ker f = 1. Proof. by move/trivgP: injm_autm. Qed.
Lemma im_autm : f @* G = G.
Proof.
apply/setP=> x; rewrite morphimEdom (can_imset_pre _ (permK a)) inE.
by have /[1!inE] /andP[/perm_closed <-] := AutGa; rewrite permKV.
Qed.
Lemma Aut_closed x : x \in G -> a x \in G.
Proof. by move=> Gx; rewrite -im_autm; apply: mem_morphim. Qed.
End AutGroup.
Lemma Aut1 : Aut 1 = 1.
Proof.
apply/trivgP/subsetP=> a /= AutGa; apply/set1P.
apply: eq_Aut (AutGa) (group1 _) _ => _ /set1P->.
by rewrite -(autmE AutGa) morph1 perm1.
Qed.
End Automorphism.
Arguments Aut _ _%_g.
Notation "[ 'Aut' G ]" := (Aut_group G) (format "[ 'Aut' G ]") : Group_scope.
Notation "[ 'Aut' G ]" := (Aut G) (only parsing) : group_scope.
Prenex Implicits Aut autm.
(* The permutation function (total on the underlying groupType) that is the *)
(* representant of a given morphism f with domain A in (Aut A). *)
Section PermIn.
Variables (T : finType) (A : {set T}) (f : T -> T).
Hypotheses (injf : {in A &, injective f}) (sBf : f @: A \subset A).
Lemma perm_in_inj : injective (fun x => if x \in A then f x else x).
Proof.
move=> x y /=; wlog Ay: x y / y \in A.
by move=> IH eqfxy; case: ifP (eqfxy); [symmetry | case: ifP => //]; auto.
rewrite Ay; case: ifP => [Ax | nAx def_x]; first exact: injf.
by case/negP: nAx; rewrite def_x (subsetP sBf) ?imset_f.
Qed.
Definition perm_in := perm perm_in_inj.
Lemma perm_in_on : perm_on A perm_in.
Proof.
by apply/subsetP=> x; rewrite inE /= permE; case: ifP => // _; case/eqP.
Qed.
Lemma perm_inE : {in A, perm_in =1 f}.
Proof. by move=> x Ax; rewrite /= permE Ax. Qed.
End PermIn.
(* properties of injective endomorphisms *)
Section MakeAut.
Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> gT}).
Implicit Type A : {set gT}.
Hypothesis injf : 'injm f.
Lemma morphim_fixP A : A \subset G -> reflect (f @* A = A) (f @* A \subset A).
Proof.
rewrite /morphim => sAG; have:= eqEcard (f @: A) A.
rewrite (setIidPr sAG) card_in_imset ?leqnn ?andbT => [<-|]; first exact: eqP.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
Qed.
Hypothesis Gf : f @* G = G.
Lemma aut_closed : f @: G \subset G.
Proof. by rewrite -morphimEdom; apply/morphim_fixP. Qed.
Definition aut := perm_in (injmP injf) aut_closed.
Lemma autE : {in G, aut =1 f}.
Proof. exact: perm_inE. Qed.
Lemma morphic_aut : morphic G aut.
Proof. by apply/morphicP=> x y Gx Gy /=; rewrite !autE ?groupM // morphM. Qed.
Lemma Aut_aut : aut \in Aut G.
Proof. by rewrite inE morphic_aut perm_in_on. Qed.
Lemma imset_autE A : A \subset G -> aut @: A = f @* A.
Proof.
move=> sAG; rewrite /morphim (setIidPr sAG).
by apply: eq_in_imset; apply: sub_in1 autE; apply/subsetP.
Qed.
Lemma preim_autE A : A \subset G -> aut @^-1: A = f @*^-1 A.
Proof.
move=> sAG; apply/setP=> x; rewrite !inE permE /=.
by case Gx: (x \in G) => //; apply/negP=> Ax; rewrite (subsetP sAG) in Gx.
Qed.
End MakeAut.
Arguments morphim_fixP {gT G f}.
Prenex Implicits aut.
Section AutIsom.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma Aut_isom_subproof a :
{a' | a' \in Aut (f @* G) & a \in Aut G -> {in G, a' \o f =1 f \o a}}.
Proof.
set Aut_a := autm (subgP (subg [Aut G] a)).
have aDom: 'dom (f \o Aut_a \o invm injf) = f @* G.
rewrite /dom /= morphpre_invm -morphpreIim; congr (f @* _).
by rewrite [_ :&: D](setIidPl _) ?injmK ?injm_autm ?im_autm.
have [af [def_af ker_af _ im_af]] := domP _ aDom.
have inj_a': 'injm af by rewrite ker_af !injm_comp ?injm_autm ?injm_invm.
have im_a': af @* (f @* G) = f @* G.
by rewrite im_af !morphim_comp morphim_invm // im_autm.
pose a' := aut inj_a' im_a'; exists a' => [|AutGa x Gx]; first exact: Aut_aut.
have Dx := domG Gx; rewrite /= [a' _]autE ?mem_morphim //.
by rewrite def_af /= invmE // autmE subgK.
Qed.
Definition Aut_isom a := s2val (Aut_isom_subproof a).
Lemma Aut_Aut_isom a : Aut_isom a \in Aut (f @* G).
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomE a : a \in Aut G -> {in G, forall x, Aut_isom a (f x) = f (a x)}.
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomM : {in Aut G &, {morph Aut_isom: x y / x * y}}.
Proof.
move=> a b AutGa AutGb.
apply: (eq_Aut (Aut_Aut_isom _)); rewrite ?groupM ?Aut_Aut_isom // => fx.
case/morphimP=> x Dx Gx ->{fx}.
by rewrite permM !Aut_isomE ?groupM /= ?permM ?Aut_closed.
Qed.
Canonical Aut_isom_morphism := Morphism Aut_isomM.
Lemma injm_Aut_isom : 'injm Aut_isom.
Proof.
apply/injmP=> a b AutGa AutGb eq_ab'; apply: (eq_Aut AutGa AutGb) => x Gx.
by apply: (injmP injf); rewrite ?domG ?Aut_closed // -!Aut_isomE //= eq_ab'.
Qed.
End AutIsom.
Section InjmAut.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma im_Aut_isom : Aut_isom injf sGD @* Aut G = Aut (f @* G).
Proof.
apply/eqP; rewrite eqEcard; apply/andP; split.
by apply/subsetP=> _ /morphimP[a _ AutGa ->]; apply: Aut_Aut_isom.
have inj_isom' := injm_Aut_isom (injm_invm injf) (morphimS _ sGD).
rewrite card_injm ?injm_Aut_isom // -(card_injm inj_isom') ?subset_leq_card //.
apply/subsetP=> a /morphimP[a' _ AutfGa' def_a].
by rewrite -(morphim_invm injf sGD) def_a Aut_Aut_isom.
Qed.
Lemma Aut_isomP : isom (Aut G) (Aut (f @* G)) (Aut_isom injf sGD).
Proof. by apply/isomP; split; [apply: injm_Aut_isom | apply: im_Aut_isom]. Qed.
Lemma injm_Aut : Aut (f @* G) \isog Aut G.
Proof. by rewrite isog_sym (isom_isog _ _ Aut_isomP). Qed.
End InjmAut.
(* conjugation automorphism *)
Section ConjugationMorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Definition conjgm of {set gT} := fun x y : gT => y ^ x.
Lemma conjgmE A x y : conjgm A x y = y ^ x. Proof. by []. Qed.
Canonical conjgm_morphism A x :=
@Morphism _ _ A (conjgm A x) (in2W (fun y z => conjMg y z x)).
Lemma morphim_conj A x B : conjgm A x @* B = (A :&: B) :^ x.
Proof. by []. Qed.
Variable G : {group gT}.
Lemma injm_conj x : 'injm (conjgm G x).
Proof. by apply/injmP; apply: in2W; apply: conjg_inj. Qed.
Lemma conj_isom x : isom G (G :^ x) (conjgm G x).
Proof. by apply/isomP; rewrite morphim_conj setIid injm_conj. Qed.
Lemma conj_isog x : G \isog G :^ x.
Proof. exact: isom_isog (conj_isom x). Qed.
Lemma norm_conjg_im x : x \in 'N(G) -> conjgm G x @* G = G.
Proof. by rewrite morphimEdom; apply: normP. Qed.
Lemma norm_conj_isom x : x \in 'N(G) -> isom G G (conjgm G x).
Proof. by move/norm_conjg_im/restr_isom_to/(_ (conj_isom x))->. Qed.
Definition conj_aut x := aut (injm_conj _) (norm_conjg_im (subgP (subg _ x))).
Lemma norm_conj_autE : {in 'N(G) & G, forall x y, conj_aut x y = y ^ x}.
Proof. by move=> x y nGx Gy; rewrite /= autE //= subgK. Qed.
Lemma conj_autE : {in G &, forall x y, conj_aut x y = y ^ x}.
Proof. by apply: sub_in11 norm_conj_autE => //; apply: subsetP (normG G). Qed.
Lemma conj_aut_morphM : {in 'N(G) &, {morph conj_aut : x y / x * y}}.
Proof.
move=> x y nGx nGy; apply/permP=> z /=; rewrite permM.
case Gz: (z \in G); last by rewrite !permE /= !Gz.
by rewrite !norm_conj_autE // (conjgM, memJ_norm, groupM).
Qed.
Canonical conj_aut_morphism := Morphism conj_aut_morphM.
Lemma ker_conj_aut : 'ker conj_aut = 'C(G).
Proof.
apply/setP=> x /[1!inE]; case nGx: (x \in 'N(G)); last first.
by symmetry; apply/idP=> cGx; rewrite (subsetP (cent_sub G)) in nGx.
rewrite 2!inE /=; apply/eqP/centP=> [cx1 y Gy | cGx].
by rewrite /commute (conjgC y) -norm_conj_autE // cx1 perm1.
apply/permP=> y; case Gy: (y \in G); last by rewrite !permE Gy.
by rewrite perm1 norm_conj_autE // conjgE -cGx ?mulKg.
Qed.
Lemma Aut_conj_aut A : conj_aut @* A \subset Aut G.
Proof. by apply/subsetP=> _ /imsetP[x _ ->]; apply: Aut_aut. Qed.
End ConjugationMorphism.
Arguments conjgm _ _%_g.
Prenex Implicits conjgm conj_aut.
Reserved Notation "G \char H" (at level 70).
(* Characteristic subgroup *)
Section Characteristicity.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H K L : {group gT}.
Definition characteristic A B :=
(A \subset B) && [forall f in Aut B, f @: A \subset A].
Infix "\char" := characteristic.
Lemma charP H G :
let fixH (f : {morphism G >-> gT}) := 'injm f -> f @* G = G -> f @* H = H in
reflect [/\ H \subset G & forall f, fixH f] (H \char G).
Proof.
do [apply: (iffP andP) => -[sHG chHG]; split] => // [f injf Gf|].
by apply/morphim_fixP; rewrite // -imset_autE ?(forall_inP chHG) ?Aut_aut.
apply/forall_inP=> f Af; rewrite -(autmE Af) -morphimEsub //.
by rewrite chHG ?injm_autm ?im_autm.
Qed.
(* Characteristic subgroup properties : composition, relational properties *)
Lemma char1 G : 1 \char G.
Proof. by apply/charP; split=> [|f _ _]; rewrite (sub1G, morphim1). Qed.
Lemma char_refl G : G \char G.
Proof. exact/charP. Qed.
Lemma char_trans H G K : K \char H -> H \char G -> K \char G.
Proof.
case/charP=> sKH chKH; case/charP=> sHG chHG.
apply/charP; split=> [|f injf Gf]; first exact: subset_trans sHG.
rewrite -{1}(setIidPr sKH) -(morphim_restrm sHG) chKH //.
by rewrite ker_restrm; move/trivgP: injf => ->; apply: subsetIr.
by rewrite morphim_restrm setIid chHG.
Qed.
Lemma char_norms H G : H \char G -> 'N(G) \subset 'N(H).
Proof.
case/charP=> sHG chHG; apply/normsP=> x /normP-Nx.
have:= chHG [morphism of conjgm G x] => /=.
by rewrite !morphimEsub //=; apply; rewrite // injm_conj.
Qed.
Lemma char_sub A B : A \char B -> A \subset B.
Proof. by case/andP. Qed.
Lemma char_norm_trans H G A : H \char G -> A \subset 'N(G) -> A \subset 'N(H).
Proof. by move/char_norms=> nHnG nGA; apply: subset_trans nHnG. Qed.
Lemma char_normal_trans H G K : K \char H -> H <| G -> K <| G.
Proof.
move=> chKH /andP[sHG nHG].
by rewrite /normal (subset_trans (char_sub chKH)) // (char_norm_trans chKH).
Qed.
Lemma char_normal H G : H \char G -> H <| G.
Proof. by move/char_normal_trans; apply; apply/andP; rewrite normG. Qed.
Lemma char_norm H G : H \char G -> G \subset 'N(H).
Proof. by case/char_normal/andP. Qed.
Lemma charI G H K : H \char G -> K \char G -> H :&: K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> _ chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite subIset // sHG.
by rewrite morphimGI ?(chHG, chKG) //; apply: subset_trans (sub1G H).
Qed.
Lemma charY G H K : H \char G -> K \char G -> H <*> K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> sKG chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite gen_subG subUset sHG.
by rewrite morphim_gen ?(morphimU, subUset, sHG, chHG, chKG).
Qed.
Lemma charM G H K : H \char G -> K \char G -> H * K \char G.
Proof.
move=> chHG chKG; rewrite -norm_joinEl ?charY //.
exact: subset_trans (char_sub chHG) (char_norm chKG).
Qed.
Lemma lone_subgroup_char G H :
H \subset G -> (forall K, K \subset G -> K \isog H -> K \subset H) ->
H \char G.
Proof.
move=> sHG Huniq; apply/charP; split=> // f injf Gf; apply/eqP.
have{} injf: {in H &, injective f}.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
have fH: f @* H = f @: H by rewrite /morphim (setIidPr sHG).
rewrite eqEcard {2}fH card_in_imset ?{}Huniq //=.
by rewrite -{3}Gf morphimS.
rewrite isog_sym; apply/isogP.
exists [morphism of restrm sHG f] => //=; first exact/injmP.
by rewrite morphimEdom fH.
Qed.
End Characteristicity.
Arguments characteristic _ _%_g _%_g.
Notation "H \char G" := (characteristic H G) : group_scope.
#[global] Hint Resolve char_refl : core.
Section InjmChar.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_char (G H : {group aT}) :
G \subset D -> H \char G -> f @* H \char f @* G.
Proof.
move=> sGD /charP[sHG charH].
apply/charP; split=> [|g injg gfG]; first exact: morphimS.
have /domP[h [_ ker_h _ im_h]]: 'dom (invm injf \o g \o f) = G.
by rewrite /dom /= -(morphpreIim g) (setIidPl _) ?injmK // gfG morphimS.
have hH: h @* H = H.
apply: charH; first by rewrite ker_h !injm_comp ?injm_invm.
by rewrite im_h !morphim_comp gfG morphim_invm.
rewrite /= -{2}hH im_h !morphim_comp morphim_invmE morphpreK //.
by rewrite (subset_trans _ (morphimS f sGD)) //= -{3}gfG !morphimS.
Qed.
End InjmChar.
Section CharInjm.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma char_injm (G H : {group aT}) :
G \subset D -> H \subset D -> (f @* H \char f @* G) = (H \char G).
Proof.
move=> sGD sHD; apply/idP/idP; last exact: injm_char.
by move/(injm_char (injm_invm injf)); rewrite !morphim_invm ?morphimS // => ->.
Qed.
End CharInjm.
Unset Implicit Arguments.
|
StdBasis.lean
|
/-
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.Data.Matrix.Basis
import Mathlib.LinearAlgebra.StdBasis
/-!
# Standard basis on matrices
## Main results
* `Basis.matrix`: extend a basis on `M` to the standard basis on `Matrix n m M`
-/
open Module
namespace Module.Basis
variable {ι R M : Type*} (m n : Type*)
variable [Fintype m] [Fintype n] [Semiring R] [AddCommMonoid M] [Module R M]
/-- The standard basis of `Matrix m n M` given a basis on `M`. -/
protected noncomputable def matrix (b : Basis ι R M) :
Basis (m × n × ι) R (Matrix m n M) :=
Basis.reindex (Pi.basis fun _ : m => Pi.basis fun _ : n => b)
((Equiv.sigmaEquivProd _ _).trans <| .prodCongr (.refl _) (Equiv.sigmaEquivProd _ _))
|>.map (Matrix.ofLinearEquiv R)
variable {n m}
@[simp]
theorem matrix_apply (b : Basis ι R M) (i : m) (j : n) (k : ι) [DecidableEq m] [DecidableEq n] :
b.matrix m n (i, j, k) = Matrix.single i j (b k) := by
simp [Basis.matrix, Matrix.single_eq_of_single_single]
end Module.Basis
namespace Matrix
variable (R : Type*) (m n : Type*) [Fintype m] [Finite n] [Semiring R]
/-- The standard basis of `Matrix m n R`. -/
noncomputable def stdBasis : Basis (m × n) R (Matrix m n R) :=
Basis.reindex (Pi.basis fun _ : m => Pi.basisFun R n) (Equiv.sigmaEquivProd _ _)
|>.map (ofLinearEquiv R)
variable {n m}
theorem stdBasis_eq_single (i : m) (j : n) [DecidableEq m] [DecidableEq n] :
stdBasis R m n (i, j) = single i j (1 : R) := by
simp [stdBasis, single_eq_of_single_single]
@[deprecated (since := "2025-05-05")] alias stdBasis_eq_stdBasisMatrix := stdBasis_eq_single
end Matrix
namespace Module.Free
variable (R M : Type*) [Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M]
/-- The module of finite matrices is free. -/
instance matrix {m n : Type*} [Finite m] [Finite n] : Module.Free R (Matrix m n M) :=
Module.Free.pi R _
end Module.Free
|
Lattice.lean
|
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.Group.Subgroup.Defs
/-!
# Lattice structure of subgroups
We prove subgroups of a group form a complete lattice.
There are also theorems about the subgroups generated by an element or a subset of a group,
defined both inductively and as the infimum of the set of subgroups containing a given
element/subset.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G` is a `Group`
- `k` is a set of elements of type `G`
Definitions in the file:
* `CompleteLattice (Subgroup G)` : the subgroups of `G` form a complete lattice
* `Subgroup.closure k` : the minimal subgroup that includes the set `k`
* `Subgroup.gi` : `closure` forms a Galois insertion with the coercion to set
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists OrderedAddCommMonoid Multiset Ring
open Function
open scoped Int
variable {G : Type*} [Group G]
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
section mul_add
variable {A : Type*} [AddGroup A]
/-- Subgroups of a group `G` are isomorphic to additive subgroups of `Additive G`. -/
@[simps!]
def Subgroup.toAddSubgroup : Subgroup G ≃o AddSubgroup (Additive G) where
toFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' }
invFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' }
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Additive subgroup of an additive group `Additive G` are isomorphic to subgroup of `G`. -/
abbrev AddSubgroup.toSubgroup' : AddSubgroup (Additive G) ≃o Subgroup G :=
Subgroup.toAddSubgroup.symm
/-- Additive subgroups of an additive group `A` are isomorphic to subgroups of `Multiplicative A`.
-/
@[simps!]
def AddSubgroup.toSubgroup : AddSubgroup A ≃o Subgroup (Multiplicative A) where
toFun S := { AddSubmonoid.toSubmonoid S.toAddSubmonoid with inv_mem' := S.neg_mem' }
invFun S := { Submonoid.toAddSubmonoid S.toSubmonoid with neg_mem' := S.inv_mem' }
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Subgroups of an additive group `Multiplicative A` are isomorphic to additive subgroups of `A`.
-/
abbrev Subgroup.toAddSubgroup' : Subgroup (Multiplicative A) ≃o AddSubgroup A :=
AddSubgroup.toSubgroup.symm
end mul_add
namespace Subgroup
variable (H K : Subgroup G)
/-- The subgroup `G` of the group `G`. -/
@[to_additive /-- The `AddSubgroup G` of the `AddGroup G`. -/]
instance : Top (Subgroup G) :=
⟨{ (⊤ : Submonoid G) with inv_mem' := fun _ => Set.mem_univ _ }⟩
/-- The top subgroup is isomorphic to the group.
This is the group version of `Submonoid.topEquiv`. -/
@[to_additive (attr := simps!)
/-- The top additive subgroup is isomorphic to the additive group.
This is the additive group version of `AddSubmonoid.topEquiv`. -/]
def topEquiv : (⊤ : Subgroup G) ≃* G :=
Submonoid.topEquiv
/-- The trivial subgroup `{1}` of a group `G`. -/
@[to_additive /-- The trivial `AddSubgroup` `{0}` of an `AddGroup` `G`. -/]
instance : Bot (Subgroup G) :=
⟨{ (⊥ : Submonoid G) with inv_mem' := by simp}⟩
@[to_additive]
instance : Inhabited (Subgroup G) :=
⟨⊥⟩
@[to_additive (attr := simp)]
theorem mem_bot {x : G} : x ∈ (⊥ : Subgroup G) ↔ x = 1 :=
Iff.rfl
@[to_additive (attr := simp)]
theorem mem_top (x : G) : x ∈ (⊤ : Subgroup G) :=
Set.mem_univ x
@[to_additive (attr := simp)]
theorem coe_top : ((⊤ : Subgroup G) : Set G) = Set.univ :=
rfl
@[to_additive (attr := simp)]
theorem coe_bot : ((⊥ : Subgroup G) : Set G) = {1} :=
rfl
@[to_additive]
instance : Unique (⊥ : Subgroup G) :=
⟨⟨1⟩, fun g => Subtype.ext g.2⟩
@[to_additive (attr := simp)]
theorem top_toSubmonoid : (⊤ : Subgroup G).toSubmonoid = ⊤ :=
rfl
@[to_additive (attr := simp)]
theorem bot_toSubmonoid : (⊥ : Subgroup G).toSubmonoid = ⊥ :=
rfl
@[to_additive]
theorem eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) :=
toSubmonoid_injective.eq_iff.symm.trans <| Submonoid.eq_bot_iff_forall _
@[to_additive]
theorem eq_bot_of_subsingleton [Subsingleton H] : H = ⊥ := by
rw [Subgroup.eq_bot_iff_forall]
intro y hy
rw [← Subgroup.coe_mk H y hy, Subsingleton.elim (⟨y, hy⟩ : H) 1, Subgroup.coe_one]
@[to_additive (attr := simp, norm_cast)]
theorem coe_eq_univ {H : Subgroup G} : (H : Set G) = Set.univ ↔ H = ⊤ :=
(SetLike.ext'_iff.trans (by rfl)).symm
@[to_additive]
theorem coe_eq_singleton {H : Subgroup G} : (∃ g : G, (H : Set G) = {g}) ↔ H = ⊥ :=
⟨fun ⟨g, hg⟩ =>
haveI : Subsingleton (H : Set G) := by
rw [hg]
infer_instance
H.eq_bot_of_subsingleton,
fun h => ⟨1, SetLike.ext'_iff.mp h⟩⟩
@[to_additive]
theorem nontrivial_iff_exists_ne_one (H : Subgroup G) : Nontrivial H ↔ ∃ x ∈ H, x ≠ (1 : G) := by
rw [Subtype.nontrivial_iff_exists_ne (fun x => x ∈ H) (1 : H)]
simp
@[to_additive]
theorem exists_ne_one_of_nontrivial (H : Subgroup G) [Nontrivial H] :
∃ x ∈ H, x ≠ 1 := by
rwa [← Subgroup.nontrivial_iff_exists_ne_one]
@[to_additive]
theorem nontrivial_iff_ne_bot (H : Subgroup G) : Nontrivial H ↔ H ≠ ⊥ := by
rw [nontrivial_iff_exists_ne_one, ne_eq, eq_bot_iff_forall]
simp only [ne_eq, not_forall, exists_prop]
/-- A subgroup is either the trivial subgroup or nontrivial. -/
@[to_additive /-- A subgroup is either the trivial subgroup or nontrivial. -/]
theorem bot_or_nontrivial (H : Subgroup G) : H = ⊥ ∨ Nontrivial H := by
have := nontrivial_iff_ne_bot H
tauto
/-- A subgroup is either the trivial subgroup or contains a non-identity element. -/
@[to_additive /-- A subgroup is either the trivial subgroup or contains a nonzero element. -/]
theorem bot_or_exists_ne_one (H : Subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1 : G) := by
convert H.bot_or_nontrivial
rw [nontrivial_iff_exists_ne_one]
@[to_additive]
lemma ne_bot_iff_exists_ne_one {H : Subgroup G} : H ≠ ⊥ ↔ ∃ a : ↥H, a ≠ 1 := by
rw [← nontrivial_iff_ne_bot, nontrivial_iff_exists_ne_one]
simp only [ne_eq, Subtype.exists, mk_eq_one, exists_prop]
/-- The inf of two subgroups is their intersection. -/
@[to_additive /-- The inf of two `AddSubgroup`s is their intersection. -/]
instance : Min (Subgroup G) :=
⟨fun H₁ H₂ =>
{ H₁.toSubmonoid ⊓ H₂.toSubmonoid with
inv_mem' := fun ⟨hx, hx'⟩ => ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩ }⟩
@[to_additive (attr := simp)]
theorem coe_inf (p p' : Subgroup G) : ((p ⊓ p' : Subgroup G) : Set G) = (p : Set G) ∩ p' :=
rfl
@[to_additive (attr := simp)]
theorem mem_inf {p p' : Subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
@[to_additive]
instance : InfSet (Subgroup G) :=
⟨fun s =>
{ (⨅ S ∈ s, Subgroup.toSubmonoid S).copy (⋂ S ∈ s, ↑S) (by simp) with
inv_mem' := fun {x} hx =>
Set.mem_biInter fun i h => i.inv_mem (by apply Set.mem_iInter₂.1 hx i h) }⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_sInf (H : Set (Subgroup G)) : ((sInf H : Subgroup G) : Set G) = ⋂ s ∈ H, ↑s :=
rfl
@[to_additive (attr := simp)]
theorem mem_sInf {S : Set (Subgroup G)} {x : G} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[to_additive]
theorem mem_iInf {ι : Sort*} {S : ι → Subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by
simp only [iInf, mem_sInf, Set.forall_mem_range]
@[to_additive (attr := simp, norm_cast)]
theorem coe_iInf {ι : Sort*} {S : ι → Subgroup G} : (↑(⨅ i, S i) : Set G) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
/-- Subgroups of a group form a complete lattice. -/
@[to_additive /-- The `AddSubgroup`s of an `AddGroup` form a complete lattice. -/]
instance : CompleteLattice (Subgroup G) :=
{ completeLatticeOfInf (Subgroup G) fun _s =>
IsGLB.of_image SetLike.coe_subset_coe isGLB_biInf with
bot := ⊥
bot_le := fun S _x hx => (mem_bot.1 hx).symm ▸ S.one_mem
top := ⊤
le_top := fun _S x _hx => mem_top x
inf := (· ⊓ ·)
le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩
inf_le_left := fun _a _b _x => And.left
inf_le_right := fun _a _b _x => And.right }
@[to_additive]
theorem mem_sup_left {S T : Subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T :=
have : S ≤ S ⊔ T := le_sup_left; fun h ↦ this h
@[to_additive]
theorem mem_sup_right {S T : Subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T :=
have : T ≤ S ⊔ T := le_sup_right; fun h ↦ this h
@[to_additive]
theorem mul_mem_sup {S T : Subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)
@[to_additive]
theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Subgroup G} (i : ι) :
∀ {x : G}, x ∈ S i → x ∈ iSup S :=
have : S i ≤ iSup S := le_iSup _ _; fun h ↦ this h
@[to_additive]
theorem mem_sSup_of_mem {S : Set (Subgroup G)} {s : Subgroup G} (hs : s ∈ S) :
∀ {x : G}, x ∈ s → x ∈ sSup S :=
have : s ≤ sSup S := le_sSup hs; fun h ↦ this h
@[to_additive (attr := simp)]
theorem subsingleton_iff : Subsingleton (Subgroup G) ↔ Subsingleton G :=
⟨fun _ =>
⟨fun x y =>
have : ∀ i : G, i = 1 := fun i =>
mem_bot.mp <| Subsingleton.elim (⊤ : Subgroup G) ⊥ ▸ mem_top i
(this x).trans (this y).symm⟩,
fun _ => ⟨fun x y => Subgroup.ext fun i => Subsingleton.elim 1 i ▸ by simp⟩⟩
@[to_additive (attr := simp)]
theorem nontrivial_iff : Nontrivial (Subgroup G) ↔ Nontrivial G :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans
not_nontrivial_iff_subsingleton.symm)
@[to_additive]
instance [Subsingleton G] : Unique (Subgroup G) :=
⟨⟨⊥⟩, fun a => @Subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩
@[to_additive]
instance [Nontrivial G] : Nontrivial (Subgroup G) :=
nontrivial_iff.mpr ‹_›
@[to_additive]
instance [Nontrivial G] : Nontrivial (⊤ : Subgroup G) := by
rw [nontrivial_iff_ne_bot]
exact top_ne_bot
@[to_additive]
theorem eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
/-- The `Subgroup` generated by a set. -/
@[to_additive /-- The `AddSubgroup` generated by a set -/]
def closure (k : Set G) : Subgroup G :=
sInf { K | k ⊆ K }
variable {k : Set G}
@[to_additive]
theorem mem_closure {x : G} : x ∈ closure k ↔ ∀ K : Subgroup G, k ⊆ K → x ∈ K :=
mem_sInf
/-- The subgroup generated by a set includes the set. -/
@[to_additive (attr := simp, aesop safe 20 (rule_sets := [SetLike]))
/-- The `AddSubgroup` generated by a set includes the set. -/]
theorem subset_closure : k ⊆ closure k := fun _ hx => mem_closure.2 fun _ hK => hK hx
@[to_additive (attr := aesop 80% (rule_sets := [SetLike]))]
theorem mem_closure_of_mem {s : Set G} {x : G} (hx : x ∈ s) : x ∈ closure s := subset_closure hx
@[to_additive]
theorem notMem_of_notMem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := fun h =>
hP (subset_closure h)
@[deprecated (since := "2025-05-23")]
alias _root_.AddSubgroup.not_mem_of_not_mem_closure := AddSubgroup.notMem_of_notMem_closure
@[to_additive existing, deprecated (since := "2025-05-23")]
alias not_mem_of_not_mem_closure := notMem_of_notMem_closure
open Set
/-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/
@[to_additive (attr := simp)
/-- An additive subgroup `K` includes `closure k` if and only if it includes `k` -/]
theorem closure_le : closure k ≤ K ↔ k ⊆ K :=
⟨Subset.trans subset_closure, fun h => sInf_le h⟩
@[to_additive]
theorem closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K :=
le_antisymm ((closure_le <| K).2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and
is preserved under multiplication and inverse, then `p` holds for all elements of the closure
of `k`.
See also `Subgroup.closure_induction_left` and `Subgroup.closure_induction_right` for versions that
only require showing `p` is preserved by multiplication by elements in `k`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership. If `p`
holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p`
holds for all elements of the additive closure of `k`.
See also `AddSubgroup.closure_induction_left` and `AddSubgroup.closure_induction_left` for
versions that only require showing `p` is preserved by addition by elements in `k`. -/]
theorem closure_induction {p : (g : G) → g ∈ closure k → Prop}
(mem : ∀ x (hx : x ∈ k), p x (subset_closure hx)) (one : p 1 (one_mem _))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
(inv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx :=
let K : Subgroup G :=
{ carrier := { x | ∃ hx, p x hx }
mul_mem' := fun ⟨_, ha⟩ ⟨_, hb⟩ ↦ ⟨_, mul _ _ _ _ ha hb⟩
one_mem' := ⟨_, one⟩
inv_mem' := fun ⟨_, hb⟩ ↦ ⟨_, inv _ _ hb⟩ }
closure_le (K := 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. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for additive closure membership, for
predicates with two arguments. -/]
theorem closure_induction₂ {p : (x y : G) → x ∈ closure k → y ∈ closure k → Prop}
(mem : ∀ (x) (y) (hx : x ∈ k) (hy : y ∈ k), p x y (subset_closure hx) (subset_closure hy))
(one_left : ∀ x hx, p 1 x (one_mem _) hx) (one_right : ∀ x hx, p x 1 hx (one_mem _))
(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 : ∀ y z x hy hz hx, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz))
(inv_left : ∀ x y hx hy, p x y hx hy → p x⁻¹ y (inv_mem hx) hy)
(inv_right : ∀ x y hx hy, p x y hx hy → p x y⁻¹ hx (inv_mem hy))
{x y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) : 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 _ _ h hz
| one => exact one_left _ (subset_closure hz)
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| inv _ _ h => exact inv_left _ _ _ _ h
| one => exact one_right x hx
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ hx h₁ h₂
| inv _ _ h => exact inv_right _ _ _ _ h
@[to_additive (attr := simp)]
theorem closure_closure_coe_preimage {k : Set G} : closure (((↑) : closure k → G) ⁻¹' k) = ⊤ :=
eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦
closure_induction (fun _ h ↦ subset_closure h) (one_mem _) (fun _ _ _ _ ↦ mul_mem)
(fun _ _ ↦ inv_mem) hx'
variable (G) in
/-- `closure` forms a Galois insertion with the coercion to set. -/
@[to_additive /-- `closure` forms a Galois insertion with the coercion to set. -/]
protected def gi : GaloisInsertion (@closure G _) (↑) where
choice s _ := closure s
gc s t := @closure_le _ _ t s
le_l_u _s := subset_closure
choice_eq _s _h := rfl
/-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`,
then `closure h ≤ closure k`. -/
@[to_additive (attr := gcongr)
/-- Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`,
then `closure h ≤ closure k` -/]
theorem closure_mono ⦃h k : Set G⦄ (h' : h ⊆ k) : closure h ≤ closure k :=
(Subgroup.gi G).gc.monotone_l h'
/-- Closure of a subgroup `K` equals `K`. -/
@[to_additive (attr := simp) /-- Additive closure of an additive subgroup `K` equals `K` -/]
theorem closure_eq : closure (K : Set G) = K :=
(Subgroup.gi G).l_u_eq K
@[to_additive (attr := simp)]
theorem closure_empty : closure (∅ : Set G) = ⊥ :=
(Subgroup.gi G).gc.l_bot
@[to_additive (attr := simp)]
theorem closure_univ : closure (univ : Set G) = ⊤ :=
@coe_top G _ ▸ closure_eq ⊤
@[to_additive]
theorem closure_union (s t : Set G) : closure (s ∪ t) = closure s ⊔ closure t :=
(Subgroup.gi G).gc.l_sup
@[to_additive]
theorem sup_eq_closure (H H' : Subgroup G) : H ⊔ H' = closure ((H : Set G) ∪ (H' : Set G)) := by
simp_rw [closure_union, closure_eq]
@[to_additive]
theorem closure_iUnion {ι} (s : ι → Set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(Subgroup.gi G).gc.l_iSup
@[to_additive (attr := simp)]
theorem closure_eq_bot_iff : closure k = ⊥ ↔ k ⊆ {1} := le_bot_iff.symm.trans <| closure_le _
@[to_additive]
theorem iSup_eq_closure {ι : Sort*} (p : ι → Subgroup G) :
⨆ i, p i = closure (⋃ i, (p i : Set G)) := by simp_rw [closure_iUnion, closure_eq]
/-- The subgroup generated by an element of a group equals the set of integer number powers of
the element. -/
@[to_additive
/-- The `AddSubgroup` generated by an element of an `AddGroup` equals the set of
natural number multiples of the element. -/]
theorem mem_closure_singleton {x y : G} : y ∈ closure ({x} : Set G) ↔ ∃ n : ℤ, x ^ n = y := by
refine
⟨fun hy => closure_induction ?_ ?_ ?_ ?_ hy, fun ⟨n, hn⟩ =>
hn ▸ zpow_mem (subset_closure <| mem_singleton x) n⟩
· intro y hy
rw [eq_of_mem_singleton hy]
exact ⟨1, zpow_one x⟩
· exact ⟨0, zpow_zero x⟩
· rintro _ _ _ _ ⟨n, rfl⟩ ⟨m, rfl⟩
exact ⟨n + m, zpow_add x n m⟩
rintro _ _ ⟨n, rfl⟩
exact ⟨-n, zpow_neg x n⟩
@[to_additive]
theorem closure_singleton_one : closure ({1} : Set G) = ⊥ := by
simp [eq_bot_iff_forall, mem_closure_singleton]
@[to_additive (attr := simp)]
lemma mem_closure_singleton_self (x : G) : x ∈ closure ({x} : Set G) := by
simpa [-subset_closure] using subset_closure (k := {x})
@[to_additive]
theorem le_closure_toSubmonoid (S : Set G) : Submonoid.closure S ≤ (closure S).toSubmonoid :=
Submonoid.closure_le.2 subset_closure
@[to_additive]
theorem closure_eq_top_of_mclosure_eq_top {S : Set G} (h : Submonoid.closure S = ⊤) :
closure S = ⊤ :=
(eq_top_iff' _).2 fun _ => le_closure_toSubmonoid _ <| h.symm ▸ trivial
@[to_additive (attr := simp)]
theorem closure_insert_one (s : Set G) : closure (insert 1 s) = closure s := by
rw [insert_eq, closure_union]
simp [one_mem]
@[to_additive]
theorem closure_union_one (s : Set G) : closure (s ∪ {1}) = closure s := by
rw [union_singleton, closure_insert_one]
@[to_additive (attr := simp)]
theorem closure_diff_one (s : Set G) : closure (s \ {1}) = closure s := by
rw [← closure_union_one (s \ {1}), diff_union_self, closure_union_one]
theorem toAddSubgroup_closure (S : Set G) :
(Subgroup.closure S).toAddSubgroup = AddSubgroup.closure (Additive.toMul ⁻¹' S) :=
le_antisymm (toAddSubgroup.le_symm_apply.mp <|
(closure_le _).mpr (AddSubgroup.subset_closure (G := Additive G)))
((AddSubgroup.closure_le _).mpr (subset_closure (G := G)))
theorem _root_.AddSubgroup.toSubgroup_closure {A : Type*} [AddGroup A] (S : Set A) :
(AddSubgroup.closure S).toSubgroup = Subgroup.closure (Multiplicative.toAdd ⁻¹' S) :=
Subgroup.toAddSubgroup.injective (Subgroup.toAddSubgroup_closure _).symm
theorem toAddSubgroup'_closure {A : Type*} [AddGroup A] (S : Set (Multiplicative A)) :
(closure S).toAddSubgroup' = AddSubgroup.closure (Multiplicative.ofAdd ⁻¹' S) :=
le_antisymm (toAddSubgroup'.to_galoisConnection.l_le <|
(closure_le _).mpr <| AddSubgroup.subset_closure (G := A))
((AddSubgroup.closure_le _).mpr <| Subgroup.subset_closure (G := Multiplicative A))
theorem _root_.AddSubgroup.toSubgroup'_closure (S : Set (Additive G)) :
(AddSubgroup.closure S).toSubgroup' = Subgroup.closure (Additive.ofMul ⁻¹' S) :=
congr_arg AddSubgroup.toSubgroup' (toAddSubgroup'_closure _).symm
@[to_additive]
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {K : ι → Subgroup G} (hK : Directed (· ≤ ·) K)
{x : G} : x ∈ (iSup K : Subgroup G) ↔ ∃ i, x ∈ K i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup K i hi⟩
suffices x ∈ closure (⋃ i, (K i : Set G)) → ∃ i, x ∈ K i by
simpa only [closure_iUnion, closure_eq (K _)] using this
refine fun hx ↦ closure_induction (fun _ ↦ mem_iUnion.1) ?_ ?_ ?_ hx
· exact hι.elim fun i ↦ ⟨i, (K i).one_mem⟩
· rintro x y _ _ ⟨i, hi⟩ ⟨j, hj⟩
rcases hK i j with ⟨k, hki, hkj⟩
exact ⟨k, mul_mem (hki hi) (hkj hj)⟩
· rintro _ _ ⟨i, hi⟩
exact ⟨i, inv_mem hi⟩
@[to_additive]
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Subgroup G} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Subgroup G) : Set G) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
@[to_additive]
theorem mem_sSup_of_directedOn {K : Set (Subgroup G)} (Kne : K.Nonempty) (hK : DirectedOn (· ≤ ·) K)
{x : G} : x ∈ sSup K ↔ ∃ s ∈ K, x ∈ s := by
haveI : Nonempty K := Kne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hK.directed_val, SetCoe.exists, exists_prop]
variable {C : Type*} [CommGroup C] {s t : Subgroup C} {x : C}
@[to_additive]
theorem mem_sup : x ∈ s ⊔ t ↔ ∃ y ∈ s, ∃ z ∈ t, y * z = x :=
⟨fun h => by
rw [sup_eq_closure] at h
refine Subgroup.closure_induction ?_ ?_ ?_ ?_ h
· rintro y (h | h)
· exact ⟨y, h, 1, t.one_mem, by simp⟩
· exact ⟨1, s.one_mem, y, h, by simp⟩
· exact ⟨1, s.one_mem, 1, ⟨t.one_mem, mul_one 1⟩⟩
· rintro _ _ _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩
exact ⟨_, mul_mem hy₁ hy₂, _, mul_mem hz₁ hz₂, by simp [mul_assoc, mul_left_comm]⟩
· rintro _ _ ⟨y, hy, z, hz, rfl⟩
exact ⟨_, inv_mem hy, _, inv_mem hz, mul_comm z y ▸ (mul_inv_rev z y).symm⟩, by
rintro ⟨y, hy, z, hz, rfl⟩; exact mul_mem_sup hy hz⟩
@[to_additive]
theorem mem_sup' : x ∈ s ⊔ t ↔ ∃ (y : s) (z : t), (y : C) * z = x :=
mem_sup.trans <| by simp only [SetLike.exists, exists_prop]
@[to_additive]
theorem mem_closure_pair {x y z : C} :
z ∈ closure ({x, y} : Set C) ↔ ∃ m n : ℤ, x ^ m * y ^ n = z := by
rw [← Set.singleton_union, Subgroup.closure_union, mem_sup]
simp_rw [mem_closure_singleton, exists_exists_eq_and]
@[to_additive]
theorem disjoint_def {H₁ H₂ : Subgroup G} : Disjoint H₁ H₂ ↔ ∀ {x : G}, x ∈ H₁ → x ∈ H₂ → x = 1 :=
disjoint_iff_inf_le.trans <| by simp only [SetLike.le_def, mem_inf, mem_bot, and_imp]
@[to_additive]
theorem disjoint_def' {H₁ H₂ : Subgroup G} :
Disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x = y → x = 1 :=
disjoint_def.trans ⟨fun h _x _y hx hy hxy ↦ h hx <| hxy.symm ▸ hy, fun h _x hx hx' ↦ h hx hx' rfl⟩
@[to_additive]
theorem disjoint_iff_mul_eq_one {H₁ H₂ : Subgroup G} :
Disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x * y = 1 → x = 1 ∧ y = 1 :=
disjoint_def'.trans
⟨fun h x y hx hy hxy =>
let hx1 : x = 1 := h hx (H₂.inv_mem hy) (eq_inv_iff_mul_eq_one.mpr hxy)
⟨hx1, by simpa [hx1] using hxy⟩,
fun h _ _ hx hy hxy => (h hx (H₂.inv_mem hy) (mul_inv_eq_one.mpr hxy)).1⟩
@[to_additive]
theorem mul_injective_of_disjoint {H₁ H₂ : Subgroup G} (h : Disjoint H₁ H₂) :
Function.Injective (fun g => g.1 * g.2 : H₁ × H₂ → G) := by
intro x y hxy
rw [← inv_mul_eq_iff_eq_mul, ← mul_assoc, ← mul_inv_eq_one, mul_assoc] at hxy
replace hxy := disjoint_iff_mul_eq_one.mp h (y.1⁻¹ * x.1).prop (x.2 * y.2⁻¹).prop hxy
rwa [coe_mul, coe_mul, coe_inv, coe_inv, inv_mul_eq_one, mul_inv_eq_one, ← Subtype.ext_iff, ←
Subtype.ext_iff, eq_comm, ← Prod.ext_iff] at hxy
end Subgroup
|
Archimedean.lean
|
/-
Copyright (c) 2020 Heather Macbeth, Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Patrick Massot
-/
import Mathlib.Algebra.Group.Subgroup.Order
import Mathlib.Algebra.Order.Archimedean.Basic
/-!
# Archimedean groups
This file proves a few facts about ordered groups which satisfy the `Archimedean` property, that is:
`class Archimedean (α) [OrderedAddCommMonoid α] : Prop :=`
`(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y)`
They are placed here in a separate file (rather than incorporated as a continuation of
`Algebra.Order.Archimedean`) because they rely on some imports from `GroupTheory` -- bundled
subgroups in particular.
The main result is `AddSubgroup.cyclic_of_min`: a subgroup of a decidable archimedean abelian
group is cyclic, if its set of positive elements has a minimal element.
This result is used in this file to deduce `Int.subgroup_cyclic`, proving that every subgroup of `ℤ`
is cyclic. (There are several other methods one could use to prove this fact, including more purely
algebraic methods, but none seem to exist in mathlib as of writing. The closest is
`Subgroup.is_cyclic`, but that has not been transferred to `AddSubgroup`.)
The file also supports multiplicative groups via `MulArchimedean`.
The result is also used in `Topology.Instances.Real` as an ingredient in the classification of
subgroups of `ℝ`.
-/
assert_not_exists Finset
open Set
variable {G : Type*} [CommGroup G] [LinearOrder G] [IsOrderedMonoid G] [MulArchimedean G]
/-- Given a subgroup `H` of a decidable linearly ordered mul-archimedean abelian group `G`, if there
exists a minimal element `a` of `H ∩ G_{>1}` then `H` is generated by `a`. -/
@[to_additive AddSubgroup.cyclic_of_min /-- Given a subgroup `H` of a decidable linearly ordered
archimedean abelian group `G`, if there exists a minimal element `a` of `H ∩ G_{>0}` then `H` is
generated by `a`. -/]
theorem Subgroup.cyclic_of_min {H : Subgroup G} {a : G}
(ha : IsLeast { g : G | g ∈ H ∧ 1 < g } a) : H = closure {a} := by
obtain ⟨⟨a_in, a_pos⟩, a_min⟩ := ha
refine le_antisymm ?_ (H.closure_le.mpr <| by simp [a_in])
intro g g_in
obtain ⟨k, ⟨nonneg, lt⟩, _⟩ := existsUnique_zpow_near_of_one_lt a_pos g
have h_zero : g / (a ^ k) = 1 := by
by_contra h
have h : a ≤ g / (a ^ k) := by
refine a_min ⟨?_, ?_⟩
· exact Subgroup.div_mem H g_in (Subgroup.zpow_mem H a_in k)
· exact lt_of_le_of_ne (by simpa using nonneg) (Ne.symm h)
have h' : ¬a ≤ g / (a ^ k) := not_le.mpr (by simpa [zpow_add_one, div_lt_iff_lt_mul'] using lt)
contradiction
simp [div_eq_one.mp h_zero, mem_closure_singleton]
/-- If a nontrivial subgroup of a linear ordered commutative group is disjoint
with the interval `Set.Ioo 1 a` for some `1 < a`, then the set of elements greater than 1 of this
group admits the least element. -/
@[to_additive /-- If a nontrivial additive subgroup of a linear ordered additive commutative group
is disjoint with the interval `Set.Ioo 0 a` for some positive `a`, then the set of positive
elements of this group admits the least element. -/]
theorem Subgroup.exists_isLeast_one_lt {H : Subgroup G} (hbot : H ≠ ⊥) {a : G} (h₀ : 1 < a)
(hd : Disjoint (H : Set G) (Ioo 1 a)) : ∃ b, IsLeast { g : G | g ∈ H ∧ 1 < g } b := by
-- todo: move to a lemma?
have hex : ∀ g > 1, ∃ n : ℕ, g ∈ Ioc (a ^ n) (a ^ (n + 1)) := fun g hg => by
rcases existsUnique_mul_zpow_mem_Ico h₀ 1 (g / a) with ⟨m, ⟨hm, hm'⟩, -⟩
simp only [one_mul, div_le_iff_le_mul, div_mul_cancel, ← zpow_add_one] at hm hm'
lift m to ℕ
· rw [← Int.lt_add_one_iff, ← zpow_lt_zpow_iff_right h₀, zpow_zero]
exact hg.trans_le hm
· simp only [← Nat.cast_succ, zpow_natCast] at hm hm'
exact ⟨m, hm', hm⟩
have : ∃ n : ℕ, Set.Nonempty (H ∩ Ioc (a ^ n) (a ^ (n + 1))) := by
rcases (bot_or_exists_ne_one H).resolve_left hbot with ⟨g, hgH, hg₀⟩
rcases hex |g|ₘ (one_lt_mabs.2 hg₀) with ⟨n, hn⟩
exact ⟨n, _, (@mabs_mem_iff (Subgroup G) G _ _).2 hgH, hn⟩
classical rcases Nat.findX this with ⟨n, ⟨x, hxH, hnx, hxn⟩, hmin⟩
by_contra hxmin
simp only [IsLeast, not_and, mem_setOf_eq, mem_lowerBounds, not_exists, not_forall,
not_le] at hxmin
rcases hxmin x ⟨hxH, (one_le_pow_of_one_le' h₀.le _).trans_lt hnx⟩ with ⟨y, ⟨hyH, hy₀⟩, hxy⟩
rcases hex y hy₀ with ⟨m, hm⟩
rcases lt_or_ge m n with hmn | hnm
· exact hmin m hmn ⟨y, hyH, hm⟩
· refine disjoint_left.1 hd (div_mem hxH hyH) ⟨one_lt_div'.2 hxy, div_lt_iff_lt_mul'.2 ?_⟩
calc x ≤ a^ (n + 1) := hxn
_ ≤ a ^ (m + 1) := pow_le_pow_right' h₀.le (add_le_add_right hnm _)
_ = a ^ m * a := pow_succ _ _
_ < y * a := mul_lt_mul_right' hm.1 _
/-- If a subgroup of a linear ordered commutative group is disjoint with the
interval `Set.Ioo 1 a` for some `1 < a`, then this is a cyclic subgroup. -/
@[to_additive AddSubgroup.cyclic_of_isolated_zero /-- If an additive subgroup of a linear ordered
additive commutative group is disjoint with the interval `Set.Ioo 0 a` for some positive `a`, then
this is a cyclic subgroup. -/]
theorem Subgroup.cyclic_of_isolated_one {H : Subgroup G} {a : G} (h₀ : 1 < a)
(hd : Disjoint (H : Set G) (Ioo 1 a)) : ∃ b, H = closure {b} := by
rcases eq_or_ne H ⊥ with rfl | hbot
· exact ⟨1, closure_singleton_one.symm⟩
· exact (exists_isLeast_one_lt hbot h₀ hd).imp fun _ => cyclic_of_min
/-- Every subgroup of `ℤ` is cyclic. -/
theorem Int.subgroup_cyclic (H : AddSubgroup ℤ) : ∃ a, H = AddSubgroup.closure {a} :=
have : Ioo (0 : ℤ) 1 = ∅ := eq_empty_of_forall_notMem fun _ hm =>
hm.1.not_ge (lt_add_one_iff.1 hm.2)
AddSubgroup.cyclic_of_isolated_zero one_pos <| by simp [this]
|
Defs.lean
|
/-
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.Set.Defs
import Mathlib.Order.Defs.PartialOrder
/-!
# Intervals
In any preorder `α`, we define intervals
(which on each side can be either infinite, open, or closed)
using the following naming conventions:
- `i`: infinite
- `o`: open
- `c`: closed
Each interval has the name `I` + letter for left side + letter for right side.
For instance, `Ioc a b` denotes the interval `(a, b]`.
We also define a typeclass `Set.OrdConnected`
saying that a set includes `Set.Icc a b` whenever it contains both `a` and `b`.
-/
namespace Set
variable {α : Type*} [Preorder α] {a b x : α}
/-- `Ioo a b` is the left-open right-open interval $(a, b)$. -/
def Ioo (a b : α) := { x | a < x ∧ x < b }
@[simp, grind =] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl
theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl
/-- `Ico a b` is the left-closed right-open interval $[a, b)$. -/
def Ico (a b : α) := { x | a ≤ x ∧ x < b }
@[simp, grind =] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl
theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl
/-- `Iio b` is the left-infinite right-open interval $(-∞, b)$. -/
def Iio (b : α) := { x | x < b }
@[simp, grind =] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl
theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl
/-- `Icc a b` is the left-closed right-closed interval $[a, b]$. -/
def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b }
@[simp, grind =] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl
theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl
/-- `Iic b` is the left-infinite right-closed interval $(-∞, b]$. -/
def Iic (b : α) := { x | x ≤ b }
@[simp, grind =] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl
theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl
/-- `Ioc a b` is the left-open right-closed interval $(a, b]$. -/
def Ioc (a b : α) := { x | a < x ∧ x ≤ b }
@[simp, grind =] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl
theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl
/-- `Ici a` is the left-closed right-infinite interval $[a, ∞)$. -/
def Ici (a : α) := { x | a ≤ x }
@[simp, grind =] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl
theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl
/-- `Ioi a` is the left-open right-infinite interval $(a, ∞)$. -/
def Ioi (a : α) := { x | a < x }
@[simp, grind =] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl
theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl
/-- We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the
interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with
the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a
`LinearOrderedField`, then this condition is also equivalent to `Convex α s`. -/
class OrdConnected (s : Set α) : Prop where
/-- `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. -/
out' ⦃x : α⦄ (hx : x ∈ s) ⦃y : α⦄ (hy : y ∈ s) : Icc x y ⊆ s
end Set
|
ContinuousCompMeasurePreserving.lean
|
/-
Copyright (c) 2024 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Function.SimpleFuncDenseLp
import Mathlib.MeasureTheory.Measure.ContinuousPreimage
/-!
# Continuity of `MeasureTheory.Lp.compMeasurePreserving`
In this file we prove that the composition of an `L^p` function `g`
with a continuous measure-preserving map `f` is continuous in both arguments.
First, we prove it for indicator functions,
in terms of convergence of `μ ((f a ⁻¹' s) ∆ (g ⁻¹' s))` to zero.
Then we prove the continuity of the function of two arguments
defined on `MeasureTheory.Lp E p ν × {f : C(X, Y) // MeasurePreserving f μ ν}`.
Finally, we provide dot notation convenience lemmas.
-/
open Filter Set MeasureTheory
open scoped ENNReal Topology symmDiff
variable {X Y : Type*}
[TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [R1Space X]
[TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] [R1Space Y]
{μ : Measure X} {ν : Measure Y} [μ.InnerRegularCompactLTTop] [IsLocallyFiniteMeasure ν]
namespace MeasureTheory
namespace Lp
variable (μ ν)
variable (E : Type*) [NormedAddCommGroup E] {p : ℝ≥0∞} [Fact (1 ≤ p)]
/-- Let `X` and `Y` be R₁ topological spaces
with Borel σ-algebras and measures `μ` and `ν`, respectively.
Suppose that `μ` is inner regular for finite measure sets with respect to compact sets
and `ν` is a locally finite measure.
Let `1 ≤ p < ∞` be an extended nonnegative real number.
Then the composition of a function `g : Lp E p ν`
and a measure preserving continuous function `f : C(X, Y)`
is continuous in both variables. -/
theorem compMeasurePreserving_continuous (hp : p ≠ ∞) :
Continuous fun gf : Lp E p ν × {f : C(X, Y) // MeasurePreserving f μ ν} ↦
compMeasurePreserving gf.2.1 gf.2.2 gf.1 := by
have hp₀ : p ≠ 0 := (one_pos.trans_le Fact.out).ne'
refine continuous_prod_of_dense_continuous_lipschitzWith _ 1
(MeasureTheory.Lp.simpleFunc.dense hp) ?_ fun f ↦ (isometry_compMeasurePreserving f.2).lipschitz
intro f hf
lift f to Lp.simpleFunc E p ν using hf
induction f using Lp.simpleFunc.induction hp₀ hp with
| add hfp hgp _ ihf ihg => exact ihf.add ihg
| @indicatorConst c s hs hνs =>
dsimp only [Lp.simpleFunc.coe_indicatorConst, Lp.indicatorConstLp_compMeasurePreserving]
refine continuous_indicatorConstLp_set hp fun f ↦ ?_
apply tendsto_measure_symmDiff_preimage_nhds_zero continuousAt_subtype_val _ f.2
hs.nullMeasurableSet hνs.ne
exact .of_forall Subtype.property
end Lp
end MeasureTheory
variable {E : Type*} [NormedAddCommGroup E] {p : ℝ≥0∞} [Fact (1 ≤ p)]
theorem Filter.Tendsto.compMeasurePreservingLp {α : Type*} {l : Filter α}
{f : α → Lp E p ν} {f₀ : Lp E p ν} {g : α → C(X, Y)} {g₀ : C(X, Y)}
(hf : Tendsto f l (𝓝 f₀)) (hg : Tendsto g l (𝓝 g₀))
(hgm : ∀ a, MeasurePreserving (g a) μ ν) (hgm₀ : MeasurePreserving g₀ μ ν) (hp : p ≠ ∞) :
Tendsto (fun a ↦ Lp.compMeasurePreserving (g a) (hgm a) (f a)) l
(𝓝 (Lp.compMeasurePreserving g₀ hgm₀ f₀)) := by
have := (Lp.compMeasurePreserving_continuous μ ν E hp).tendsto ⟨f₀, g₀, hgm₀⟩
replace hg : Tendsto (fun a ↦ ⟨g a, hgm a⟩ : α → {g : C(X, Y) // MeasurePreserving g μ ν})
l (𝓝 ⟨g₀, hgm₀⟩) :=
tendsto_subtype_rng.2 hg
convert this.comp (hf.prodMk_nhds hg)
variable {Z : Type*} [TopologicalSpace Z] {f : Z → Lp E p ν} {g : Z → C(X, Y)} {s : Set Z} {z : Z}
theorem ContinuousWithinAt.compMeasurePreservingLp (hf : ContinuousWithinAt f s z)
(hg : ContinuousWithinAt g s z) (hgm : ∀ z, MeasurePreserving (g z) μ ν) (hp : p ≠ ∞) :
ContinuousWithinAt (fun z ↦ Lp.compMeasurePreserving (g z) (hgm z) (f z)) s z :=
Tendsto.compMeasurePreservingLp hf hg _ _ hp
theorem ContinuousAt.compMeasurePreservingLp (hf : ContinuousAt f z)
(hg : ContinuousAt g z) (hgm : ∀ z, MeasurePreserving (g z) μ ν) (hp : p ≠ ∞) :
ContinuousAt (fun z ↦ Lp.compMeasurePreserving (g z) (hgm z) (f z)) z :=
Tendsto.compMeasurePreservingLp hf hg _ _ hp
theorem ContinuousOn.compMeasurePreservingLp (hf : ContinuousOn f s)
(hg : ContinuousOn g s) (hgm : ∀ z, MeasurePreserving (g z) μ ν) (hp : p ≠ ∞) :
ContinuousOn (fun z ↦ Lp.compMeasurePreserving (g z) (hgm z) (f z)) s := fun z hz ↦
(hf z hz).compMeasurePreservingLp (hg z hz) hgm hp
theorem Continuous.compMeasurePreservingLp (hf : Continuous f) (hg : Continuous g)
(hgm : ∀ z, MeasurePreserving (g z) μ ν) (hp : p ≠ ∞) :
Continuous (fun z ↦ Lp.compMeasurePreserving (g z) (hgm z) (f z)) :=
continuous_iff_continuousAt.mpr fun _ ↦
hf.continuousAt.compMeasurePreservingLp hg.continuousAt hgm hp
|
Basic.lean
|
/-
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.Group.Submonoid.Operations
import Mathlib.Algebra.MonoidAlgebra.Module
import Mathlib.Algebra.MonoidAlgebra.NoZeroDivisors
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Data.Finset.Sort
import Mathlib.Tactic.FastInstance
/-!
# Theory of univariate polynomials
This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
## Main definitions
* `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map.
* `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism.
* `X` is the polynomial `X`, i.e., `monomial 1 1`.
* `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied
to coefficients of the polynomial `p`.
* `p.erase n` is the polynomial `p` in which one removes the `c X^n` term.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds `index` when acting on
the polynomials. For instance,
* `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`;
* `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`.
* Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`.
## Implementation
Polynomials are defined using `R[ℕ]`, where `R` is a semiring.
The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity
`X * p = p * X`. The relationship to `R[ℕ]` is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two
exceptions that we make semireducible:
* The zero polynomial, so that its coefficients are definitionally equal to `0`.
* The scalar action, to permit typeclass search to unfold it to resolve potential instance
diamonds.
The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is
done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial
gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The
equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should
in general not be used once the basic API for polynomials is constructed.
-/
noncomputable section
/-- `Polynomial R` is the type of univariate polynomials over `R`,
denoted as `R[X]` within the `Polynomial` namespace.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
structure Polynomial (R : Type*) [Semiring R] where ofFinsupp ::
/-- The coefficients `ℕ →₀ R` of a polynomial in `R[X]`. -/
toFinsupp : AddMonoidAlgebra R ℕ
@[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R
open AddMonoidAlgebra Finset
open Finsupp hiding single
open Function hiding Commute
namespace Polynomial
universe u
variable {R : Type u} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
theorem forall_iff_forall_finsupp (P : R[X] → Prop) :
(∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ :=
⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩
theorem exists_iff_exists_finsupp (P : R[X] → Prop) :
(∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ :=
⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩
@[simp]
theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by constructor
/-! ### Conversions to and from `AddMonoidAlgebra`
Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`.
-/
section AddMonoidAlgebra
private irreducible_def add : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a + b⟩
private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X]
| ⟨a⟩ => ⟨-a⟩
private irreducible_def mul : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a * b⟩
instance zero : Zero R[X] :=
⟨⟨0⟩⟩
instance one : One R[X] :=
⟨⟨1⟩⟩
instance add' : Add R[X] :=
⟨add⟩
instance neg' {R : Type u} [Ring R] : Neg R[X] :=
⟨neg⟩
instance sub {R : Type u} [Ring R] : Sub R[X] :=
⟨fun a b => a + -b⟩
instance mul' : Mul R[X] :=
⟨mul⟩
-- If the private definitions are accidentally exposed, simplify them away.
@[simp] theorem add_eq_add : add p q = p + q := rfl
@[simp] theorem mul_eq_mul : mul p q = p * q := rfl
instance instNSMul : SMul ℕ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where
smul r p := ⟨r • p.toFinsupp⟩
smul_zero a := congr_arg ofFinsupp (smul_zero a)
instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S R[X] where
eq_zero_or_eq_zero_of_smul_eq_zero eq :=
(eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp)
-- to avoid a bug in the `ring` tactic
instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p
@[simp]
theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 :=
rfl
@[simp]
theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 :=
rfl
@[simp]
theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ :=
show _ = add _ _ by rw [add_def]
@[simp]
theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ :=
show _ = neg _ by rw [neg_def]
@[simp]
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg]
rfl
@[simp]
theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ :=
show _ = mul _ _ by rw [mul_def]
@[simp]
theorem ofFinsupp_nsmul (a : ℕ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by
change _ = npowRec n _
induction n with
| zero => simp [npowRec]
| succ n n_ih => simp [npowRec, n_ih, pow_succ]
@[simp]
theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 :=
rfl
@[simp]
theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 :=
rfl
@[simp]
theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_add]
@[simp]
theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by
cases a
rw [← ofFinsupp_neg]
@[simp]
theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) :
(a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by
rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add]
rfl
@[simp]
theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_mul]
@[simp]
theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by
cases a
rw [← ofFinsupp_pow]
theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S}
(ha : IsSMulRegular R a) : IsSMulRegular R[X] a
| ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h)
theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) :=
fun ⟨_x⟩ ⟨_y⟩ => congr_arg _
@[simp]
theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b :=
toFinsupp_injective.eq_iff
@[simp]
theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by
rw [← toFinsupp_zero, toFinsupp_inj]
@[simp]
theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by
rw [← toFinsupp_one, toFinsupp_inj]
/-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/
theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b :=
iff_of_eq (ofFinsupp.injEq _ _)
@[simp]
theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by
rw [← ofFinsupp_zero, ofFinsupp_inj]
@[simp]
theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj]
instance inhabited : Inhabited R[X] :=
⟨0⟩
instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl
@[simp]
theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl
@[simp]
theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl
@[simp]
theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl
instance semiring : Semiring R[X] :=
fast_instance% Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero
toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_nsmul _ _) toFinsupp_pow
fun _ => rfl
instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] :=
fast_instance% Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] :=
fast_instance% Function.Injective.distribMulAction
⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul
instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where
eq_of_smul_eq_smul {_s₁ _s₂} h :=
eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩)
instance module {S} [Semiring S] [Module S R] : Module S R[X] :=
fast_instance% Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] :
SMulCommClass S₁ S₂ R[X] :=
⟨by
rintro m n ⟨f⟩
simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩
instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R]
[IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] :=
⟨by
rintro _ _ ⟨⟩
simp_rw [← ofFinsupp_smul, smul_assoc]⟩
instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] :
IsScalarTower α K[X] K[X] :=
⟨by
rintro _ ⟨⟩ ⟨⟩
simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩
instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] :
IsCentralScalar S R[X] :=
⟨by
rintro _ ⟨⟩
simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩
instance unique [Subsingleton R] : Unique R[X] :=
{ Polynomial.inhabited with
uniq := by
rintro ⟨x⟩
apply congr_arg ofFinsupp
simp [eq_iff_true_of_subsingleton] }
variable (R)
/-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps apply symm_apply]
def toFinsuppIso : R[X] ≃+* R[ℕ] where
toFun := toFinsupp
invFun := ofFinsupp
map_mul' := toFinsupp_mul
map_add' := toFinsupp_add
instance [DecidableEq R] : DecidableEq R[X] :=
@Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq)
/-- Linear isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps!]
def toFinsuppIsoLinear : R[X] ≃ₗ[R] R[ℕ] where
__ := toFinsuppIso R
map_smul' _ _ := rfl
end AddMonoidAlgebra
theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) :
(⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ :=
map_sum (toFinsuppIso R).symm f s
theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) :
(∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp :=
map_sum (toFinsuppIso R) f s
/-- The set of all `n` such that `X^n` has a non-zero coefficient. -/
def support : R[X] → Finset ℕ
| ⟨p⟩ => p.support
@[simp]
theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support]
theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support]
@[simp]
theorem support_zero : (0 : R[X]).support = ∅ :=
rfl
@[simp]
theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by
rcases p with ⟨⟩
simp [support]
@[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 :=
Finset.nonempty_iff_ne_empty.trans support_eq_empty.not
theorem card_support_eq_zero : #p.support = 0 ↔ p = 0 := by simp
/-- `monomial s a` is the monomial `a * X^s` -/
def monomial (n : ℕ) : R →ₗ[R] R[X] where
toFun t := ⟨Finsupp.single n t⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp`.
map_add' x y := by simp; rw [ofFinsupp_add]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [← ofFinsupp_smul]`.
map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single']
@[simp]
theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by
simp [monomial]
@[simp]
theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by
simp [monomial]
@[simp]
theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 :=
(monomial n).map_zero
-- This is not a `simp` lemma as `monomial_zero_left` is more general.
theorem monomial_zero_one : monomial 0 (1 : R) = 1 :=
rfl
-- TODO: can't we just delete this one?
theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s :=
(monomial n).map_add _ _
theorem monomial_mul_monomial (n m : ℕ) (r s : R) :
monomial n r * monomial m s = monomial (n + m) (r * s) :=
toFinsupp_injective <| by
simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single]
@[simp]
theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by
induction k with
| zero => simp [pow_zero, monomial_zero_one]
| succ k ih => simp [pow_succ, ih, monomial_mul_monomial, mul_add, add_comm]
theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) :
a • monomial n b = monomial n (a • b) :=
toFinsupp_injective <| AddMonoidAlgebra.smul_single _ _ _
theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) :=
(toFinsuppIso R).symm.injective.comp (single_injective n)
@[simp]
theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 :=
LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n)
theorem monomial_eq_monomial_iff {m n : ℕ} {a b : R} :
monomial m a = monomial n b ↔ m = n ∧ a = b ∨ a = 0 ∧ b = 0 := by
rw [← toFinsupp_inj, toFinsupp_monomial, toFinsupp_monomial, Finsupp.single_eq_single_iff]
theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by
simpa [support] using Finsupp.support_add
/-- `C a` is the constant polynomial `a`.
`C` is provided as a ring homomorphism.
-/
def C : R →+* R[X] :=
{ monomial 0 with
map_one' := by simp [monomial_zero_one]
map_mul' := by simp [monomial_mul_monomial]
map_zero' := by simp }
@[simp]
theorem monomial_zero_left (a : R) : monomial 0 a = C a :=
rfl
@[simp]
theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a :=
rfl
theorem C_0 : C (0 : R) = 0 := by simp
theorem C_1 : C (1 : R) = 1 :=
rfl
theorem C_mul : C (a * b) = C a * C b :=
C.map_mul a b
theorem C_add : C (a + b) = C a + C b :=
C.map_add a b
@[simp]
theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) :=
smul_monomial _ _ r
theorem C_pow : C (a ^ n) = C a ^ n :=
C.map_pow a n
theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) :=
map_natCast C n
@[simp]
theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, zero_add]
@[simp]
theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, add_zero]
/-- `X` is the polynomial variable (aka indeterminate). -/
def X : R[X] :=
monomial 1 1
theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X :=
rfl
theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by
induction n with
| zero => simp
| succ n ih => rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one]
@[simp]
theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) :=
rfl
theorem X_ne_C [Nontrivial R] (a : R) : X ≠ C a := by
intro he
simpa using monomial_eq_monomial_iff.1 he
/-- `X` commutes with everything, even when the coefficients are noncommutative. -/
theorem X_mul : X * p = p * X := by
rcases p with ⟨⟩
simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, ofFinsupp.injEq]
ext
simp [AddMonoidAlgebra.mul_apply, add_comm]
theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by
induction n with
| zero => simp
| succ n ih =>
conv_lhs => rw [pow_succ]
rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ]
/-- Prefer putting constants to the left of `X`.
This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/
@[simp]
theorem X_mul_C (r : R) : X * C r = C r * X :=
X_mul
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/
@[simp]
theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n :=
X_pow_mul
theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by
rw [mul_assoc, X_pow_mul, ← mul_assoc]
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/
@[simp]
theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n :=
X_pow_mul_assoc
theorem commute_X (p : R[X]) : Commute X p :=
X_mul
theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p :=
X_pow_mul
@[simp]
theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by
rw [X, monomial_mul_monomial, mul_one]
@[simp]
theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) :
monomial n r * X ^ k = monomial (n + k) r := by
induction k with
| zero => simp
| succ k ih => simp [ih, pow_succ, ← mul_assoc, add_assoc]
@[simp]
theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by
rw [X_mul, monomial_mul_X]
@[simp]
theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by
rw [X_pow_mul, monomial_mul_X_pow]
/-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/
def coeff : R[X] → ℕ → R
| ⟨p⟩ => p
@[simp]
theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff]
theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by
rintro ⟨p⟩ ⟨q⟩
simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq]
@[simp]
theorem coeff_inj : p.coeff = q.coeff ↔ p = q :=
coeff_injective.eq_iff
theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl
theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by
simp [coeff, Finsupp.single_apply]
@[simp]
theorem coeff_monomial_same (n : ℕ) (c : R) : (monomial n c).coeff n = c :=
Finsupp.single_eq_same
theorem coeff_monomial_of_ne {m n : ℕ} (c : R) (h : n ≠ m) : (monomial n c).coeff m = 0 :=
Finsupp.single_eq_of_ne h
@[simp]
theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 :=
rfl
theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by
simp_rw [eq_comm (a := n) (b := 0)]
exact coeff_monomial
@[simp]
theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by
simp [coeff_one]
@[simp]
theorem coeff_X_one : coeff (X : R[X]) 1 = 1 :=
coeff_monomial
@[simp]
theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 :=
coeff_monomial
@[simp]
theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial]
theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 :=
coeff_monomial
theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by
rw [coeff_X, if_neg hn.symm]
@[simp]
theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by
rcases p with ⟨⟩
simp
theorem notMem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp
@[deprecated (since := "2025-05-23")] alias not_mem_support_iff := notMem_support_iff
theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by
convert coeff_monomial (a := a) (m := n) (n := 0) using 2
simp [eq_comm]
@[simp]
theorem coeff_C_zero : coeff (C a) 0 = a :=
coeff_monomial
theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h]
@[simp]
lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C]
@[simp]
theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by
simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero]
@[simp]
theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) 0 = ofNat(a) :=
coeff_monomial
@[simp]
theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) (n + 1) = 0 := by
rw [← Nat.cast_ofNat]
simp [-Nat.cast_ofNat]
theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a
| 0 => mul_one _
| n + 1 => by
rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one]
@[simp high]
theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) :
Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by
rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial]
theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one]
@[simp high]
theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by
rw [C_mul_X_eq_monomial, toFinsupp_monomial]
theorem C_injective : Injective (C : R → R[X]) :=
monomial_injective 0
@[simp]
theorem C_inj : C a = C b ↔ a = b :=
C_injective.eq_iff
@[simp]
theorem C_eq_zero : C a = 0 ↔ a = 0 :=
C_injective.eq_iff' (map_zero C)
theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 :=
C_eq_zero.not
theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R :=
⟨@Injective.subsingleton _ _ _ C_injective, by
intro
infer_instance⟩
theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R :=
(subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _
theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by
simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton
theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by
rcases p with ⟨f : ℕ →₀ R⟩
rcases q with ⟨g : ℕ →₀ R⟩
simpa [coeff] using DFunLike.ext_iff (f := f) (g := g)
@[ext]
theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q :=
ext_iff.2
/-- Monomials generate the additive monoid of polynomials. -/
theorem addSubmonoid_closure_setOf_eq_monomial :
AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by
apply top_unique
rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ←
Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure]
refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_)
rintro _ ⟨n, a, rfl⟩
exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩
theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g :=
AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by
rintro p ⟨n, a, rfl⟩
exact h n a
@[ext high]
theorem addHom_ext' {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g :=
addHom_ext fun n => DFunLike.congr_fun (h n)
@[ext high]
theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M}
(h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g :=
LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n)
-- this has the same content as the subsingleton
theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by
rw [← one_smul R p, ← h, zero_smul]
section Fewnomials
theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by
rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H
theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by
rw [← ofFinsupp_single, support]
exact Finsupp.support_single_subset
theorem support_C {a : R} (h : a ≠ 0) : (C a).support = singleton 0 :=
support_monomial 0 h
theorem support_C_subset (a : R) : (C a).support ⊆ singleton 0 :=
support_monomial' 0 a
theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by
rw [C_mul_X_eq_monomial, support_monomial 1 h]
theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by
simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c
theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) :
Polynomial.support (C c * X ^ n) = singleton n := by
rw [C_mul_X_pow_eq_monomial, support_monomial n h]
theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by
simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c
open Finset
theorem support_binomial' (k m : ℕ) (x y : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m) ⊆ {k, m} :=
support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_singleton_self m)))))
theorem support_trinomial' (k m n : ℕ) (x y z : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m + C z * X ^ n) ⊆ {k, m, n} :=
support_add.trans
(union_subset
(support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m, n})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_self m {n}))))))
((support_C_mul_X_pow' n z).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_of_mem (mem_singleton_self n))))))
end Fewnomials
theorem X_pow_eq_monomial (n) : X ^ n = monomial n (1 : R) :=
(monomial_one_right_eq_X_pow n).symm
@[simp high]
theorem toFinsupp_X_pow (n : ℕ) : (X ^ n).toFinsupp = Finsupp.single n (1 : R) := by
rw [X_pow_eq_monomial, toFinsupp_monomial]
theorem smul_X_eq_monomial {n} : a • X ^ n = monomial n (a : R) := by
rw [X_pow_eq_monomial, smul_monomial, smul_eq_mul, mul_one]
theorem support_X_pow (H : ¬(1 : R) = 0) (n : ℕ) : (X ^ n : R[X]).support = singleton n := by
convert support_monomial n H
exact X_pow_eq_monomial n
theorem support_X_empty (H : (1 : R) = 0) : (X : R[X]).support = ∅ := by
rw [X, H, monomial_zero_right, support_zero]
theorem support_X (H : ¬(1 : R) = 0) : (X : R[X]).support = singleton 1 := by
rw [← pow_one X, support_X_pow H 1]
theorem monomial_left_inj {a : R} (ha : a ≠ 0) {i j : ℕ} :
monomial i a = monomial j a ↔ i = j := by
simp only [← ofFinsupp_single, ofFinsupp.injEq, Finsupp.single_left_inj ha]
theorem binomial_eq_binomial {k l m n : ℕ} {u v : R} (hu : u ≠ 0) (hv : v ≠ 0) :
C u * X ^ k + C v * X ^ l = C u * X ^ m + C v * X ^ n ↔
k = m ∧ l = n ∨ u = v ∧ k = n ∧ l = m ∨ u + v = 0 ∧ k = l ∧ m = n := by
simp_rw [C_mul_X_pow_eq_monomial, ← toFinsupp_inj, toFinsupp_add, toFinsupp_monomial]
exact Finsupp.single_add_single_eq_single_add_single hu hv
theorem natCast_mul (n : ℕ) (p : R[X]) : (n : R[X]) * p = n • p :=
(nsmul_eq_mul _ _).symm
/-- Summing the values of a function applied to the coefficients of a polynomial -/
def sum {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) : S :=
∑ n ∈ p.support, f n (p.coeff n)
theorem sum_def {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) :
p.sum f = ∑ n ∈ p.support, f n (p.coeff n) :=
rfl
theorem sum_eq_of_subset {S : Type*} [AddCommMonoid S] {p : R[X]} (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) {s : Finset ℕ} (hs : p.support ⊆ s) :
p.sum f = ∑ n ∈ s, f n (p.coeff n) :=
Finsupp.sum_of_support_subset _ hs f (fun i _ ↦ hf i)
/-- Expressing the product of two polynomials as a double sum. -/
theorem mul_eq_sum_sum :
p * q = ∑ i ∈ p.support, q.sum fun j a => (monomial (i + j)) (p.coeff i * a) := by
apply toFinsupp_injective
rcases p with ⟨⟩; rcases q with ⟨⟩
simp_rw [sum, coeff, toFinsupp_sum, support, toFinsupp_mul, toFinsupp_monomial,
AddMonoidAlgebra.mul_def, Finsupp.sum]
@[simp]
theorem sum_zero_index {S : Type*} [AddCommMonoid S] (f : ℕ → R → S) : (0 : R[X]).sum f = 0 := by
simp [sum]
@[simp]
theorem sum_monomial_index {S : Type*} [AddCommMonoid S] {n : ℕ} (a : R) (f : ℕ → R → S)
(hf : f n 0 = 0) : (monomial n a : R[X]).sum f = f n a :=
Finsupp.sum_single_index hf
@[simp]
theorem sum_C_index {a} {β} [AddCommMonoid β] {f : ℕ → R → β} (h : f 0 0 = 0) :
(C a).sum f = f 0 a :=
sum_monomial_index a f h
-- the assumption `hf` is only necessary when the ring is trivial
@[simp]
theorem sum_X_index {S : Type*} [AddCommMonoid S] {f : ℕ → R → S} (hf : f 1 0 = 0) :
(X : R[X]).sum f = f 1 1 :=
sum_monomial_index 1 f hf
theorem sum_add_index {S : Type*} [AddCommMonoid S] (p q : R[X]) (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) (h_add : ∀ a b₁ b₂, f a (b₁ + b₂) = f a b₁ + f a b₂) :
(p + q).sum f = p.sum f + q.sum f := by
rw [show p + q = ⟨p.toFinsupp + q.toFinsupp⟩ from add_def p q]
exact Finsupp.sum_add_index (fun i _ ↦ hf i) (fun a _ b₁ b₂ ↦ h_add a b₁ b₂)
theorem sum_add' {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) :
p.sum (f + g) = p.sum f + p.sum g := by simp [sum_def, Finset.sum_add_distrib]
theorem sum_add {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) :
(p.sum fun n x => f n x + g n x) = p.sum f + p.sum g :=
sum_add' _ _ _
theorem sum_smul_index {S : Type*} [AddCommMonoid S] (p : R[X]) (b : R) (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) : (b • p).sum f = p.sum fun n a => f n (b * a) :=
Finsupp.sum_smul_index hf
theorem sum_smul_index' {S T : Type*} [DistribSMul T R] [AddCommMonoid S] (p : R[X]) (b : T)
(f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) : (b • p).sum f = p.sum fun n a => f n (b • a) :=
Finsupp.sum_smul_index' hf
protected theorem smul_sum {S T : Type*} [AddCommMonoid S] [DistribSMul T S] (p : R[X]) (b : T)
(f : ℕ → R → S) : b • p.sum f = p.sum fun n a => b • f n a :=
Finsupp.smul_sum
@[simp]
theorem sum_monomial_eq : ∀ p : R[X], (p.sum fun n a => monomial n a) = p
| ⟨_p⟩ => (ofFinsupp_sum _ _).symm.trans (congr_arg _ <| Finsupp.sum_single _)
theorem sum_C_mul_X_pow_eq (p : R[X]) : (p.sum fun n a => C a * X ^ n) = p := by
simp_rw [C_mul_X_pow_eq_monomial, sum_monomial_eq]
@[elab_as_elim]
protected theorem induction_on {motive : R[X] → Prop} (p : R[X]) (C : ∀ a, motive (C a))
(add : ∀ p q, motive p → motive q → motive (p + q))
(monomial : ∀ (n : ℕ) (a : R),
motive (Polynomial.C a * X ^ n) → motive (Polynomial.C a * X ^ (n + 1))) : motive p := by
have A : ∀ {n : ℕ} {a}, motive (Polynomial.C a * X ^ n) := by
intro n a
induction n with
| zero => rw [pow_zero, mul_one]; exact C a
| succ n ih => exact monomial _ _ ih
have B : ∀ s : Finset ℕ, motive (s.sum fun n : ℕ => Polynomial.C (p.coeff n) * X ^ n) := by
apply Finset.induction
· convert C 0
exact C_0.symm
· intro n s ns ih
rw [sum_insert ns]
exact add _ _ A ih
rw [← sum_C_mul_X_pow_eq p, Polynomial.sum]
exact B (support p)
/-- To prove something about polynomials,
it suffices to show the condition is closed under taking sums,
and it holds for monomials.
-/
@[elab_as_elim]
protected theorem induction_on' {motive : R[X] → Prop} (p : R[X])
(add : ∀ p q, motive p → motive q → motive (p + q))
(monomial : ∀ (n : ℕ) (a : R), motive (monomial n a)) : motive p :=
Polynomial.induction_on p (monomial 0) add fun n a _h =>
by rw [C_mul_X_pow_eq_monomial]; exact monomial _ _
/-- `erase p n` is the polynomial `p` in which the `X^n` term has been erased. -/
irreducible_def erase (n : ℕ) : R[X] → R[X]
| ⟨p⟩ => ⟨p.erase n⟩
@[simp]
theorem toFinsupp_erase (p : R[X]) (n : ℕ) : toFinsupp (p.erase n) = p.toFinsupp.erase n := by
rcases p with ⟨⟩
simp only [erase_def]
@[simp]
theorem ofFinsupp_erase (p : R[ℕ]) (n : ℕ) :
(⟨p.erase n⟩ : R[X]) = (⟨p⟩ : R[X]).erase n := by
rcases p with ⟨⟩
simp only [erase_def]
@[simp]
theorem support_erase (p : R[X]) (n : ℕ) : support (p.erase n) = (support p).erase n := by
rcases p with ⟨⟩
simp only [support, erase_def, Finsupp.support_erase]
theorem monomial_add_erase (p : R[X]) (n : ℕ) : monomial n (coeff p n) + p.erase n = p :=
toFinsupp_injective <| by
rcases p with ⟨⟩
rw [toFinsupp_add, toFinsupp_monomial, toFinsupp_erase, coeff]
exact Finsupp.single_add_erase _ _
theorem coeff_erase (p : R[X]) (n i : ℕ) :
(p.erase n).coeff i = if i = n then 0 else p.coeff i := by
rcases p with ⟨⟩
simp only [erase_def, coeff]
exact ite_congr rfl (fun _ => rfl) (fun _ => rfl)
@[simp]
theorem erase_zero (n : ℕ) : (0 : R[X]).erase n = 0 :=
toFinsupp_injective <| by simp
@[simp]
theorem erase_monomial {n : ℕ} {a : R} : erase n (monomial n a) = 0 :=
toFinsupp_injective <| by simp
@[simp]
theorem erase_same (p : R[X]) (n : ℕ) : coeff (p.erase n) n = 0 := by simp [coeff_erase]
@[simp]
theorem erase_ne (p : R[X]) (n i : ℕ) (h : i ≠ n) : coeff (p.erase n) i = coeff p i := by
simp [coeff_erase, h]
section Update
/-- Replace the coefficient of a `p : R[X]` at a given degree `n : ℕ`
by a given value `a : R`. If `a = 0`, this is equal to `p.erase n`
If `p.natDegree < n` and `a ≠ 0`, this increases the degree to `n`. -/
def update (p : R[X]) (n : ℕ) (a : R) : R[X] :=
Polynomial.ofFinsupp (p.toFinsupp.update n a)
theorem coeff_update (p : R[X]) (n : ℕ) (a : R) :
(p.update n a).coeff = Function.update p.coeff n a := by
ext
cases p
simp only [coeff, update, Function.update_apply, coe_update]
theorem coeff_update_apply (p : R[X]) (n : ℕ) (a : R) (i : ℕ) :
(p.update n a).coeff i = if i = n then a else p.coeff i := by
rw [coeff_update, Function.update_apply]
@[simp]
theorem coeff_update_same (p : R[X]) (n : ℕ) (a : R) : (p.update n a).coeff n = a := by
rw [p.coeff_update_apply, if_pos rfl]
theorem coeff_update_ne (p : R[X]) {n : ℕ} (a : R) {i : ℕ} (h : i ≠ n) :
(p.update n a).coeff i = p.coeff i := by rw [p.coeff_update_apply, if_neg h]
@[simp]
theorem update_zero_eq_erase (p : R[X]) (n : ℕ) : p.update n 0 = p.erase n := by
ext
rw [coeff_update_apply, coeff_erase]
theorem support_update (p : R[X]) (n : ℕ) (a : R) [Decidable (a = 0)] :
support (p.update n a) = if a = 0 then p.support.erase n else insert n p.support := by
classical
cases p
simp only [support, update, Finsupp.support_update]
congr
theorem support_update_zero (p : R[X]) (n : ℕ) : support (p.update n 0) = p.support.erase n := by
rw [update_zero_eq_erase, support_erase]
theorem support_update_ne_zero (p : R[X]) (n : ℕ) {a : R} (ha : a ≠ 0) :
support (p.update n a) = insert n p.support := by classical rw [support_update, if_neg ha]
end Update
/-- The finset of nonzero coefficients of a polynomial. -/
def coeffs (p : R[X]) : Finset R :=
letI := Classical.decEq R
Finset.image (fun n => p.coeff n) p.support
@[simp]
theorem coeffs_zero : coeffs (0 : R[X]) = ∅ :=
rfl
theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)]
theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by
classical
simp_rw [coeffs, Finset.image_subset_iff]
simp_all [coeff_one]
theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by
classical
simp only [coeffs, mem_support_iff, Finset.mem_image, Ne]
exact ⟨n, h, rfl⟩
@[simp]
theorem coeffs_empty_iff (p : R[X]) : coeffs p = ∅ ↔ p = 0 := by
refine ⟨?_, fun h ↦ by simp [h]⟩
contrapose!
intro h
rw [← support_nonempty] at h
obtain ⟨n, hn⟩ := h
rw [mem_support_iff] at hn
rw [← nonempty_iff_ne_empty]
exact ⟨p.coeff n, coeff_mem_coeffs p n hn⟩
theorem coeffs_monomial (n : ℕ) {c : R} (hc : c ≠ 0) : (monomial n c).coeffs = {c} := by
rw [coeffs, support_monomial n hc]
simp
end Semiring
section CommSemiring
variable [CommSemiring R]
instance commSemiring : CommSemiring R[X] :=
fast_instance% { Function.Injective.commSemigroup toFinsupp toFinsupp_injective toFinsupp_mul with
toSemiring := Polynomial.semiring }
end CommSemiring
section Ring
variable [Ring R]
instance instZSMul : SMul ℤ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
@[simp]
theorem ofFinsupp_zsmul (a : ℤ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem toFinsupp_zsmul (a : ℤ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
instance instIntCast : IntCast R[X] where intCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_intCast (z : ℤ) : (⟨z⟩ : R[X]) = z := rfl
@[simp]
theorem toFinsupp_intCast (z : ℤ) : (z : R[X]).toFinsupp = z := rfl
instance ring : Ring R[X] :=
fast_instance% Function.Injective.ring toFinsupp toFinsupp_injective (toFinsupp_zero (R := R))
toFinsupp_one toFinsupp_add
toFinsupp_mul toFinsupp_neg toFinsupp_sub (fun _ _ => toFinsupp_nsmul _ _)
(fun _ _ => toFinsupp_zsmul _ _) toFinsupp_pow (fun _ => rfl) fun _ => rfl
@[simp]
theorem coeff_neg (p : R[X]) (n : ℕ) : coeff (-p) n = -coeff p n := by
rcases p with ⟨⟩
rw [← ofFinsupp_neg, coeff, coeff, Finsupp.neg_apply]
@[simp]
theorem coeff_sub (p q : R[X]) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := by
rcases p with ⟨⟩
rcases q with ⟨⟩
rw [← ofFinsupp_sub, coeff, coeff, coeff, Finsupp.sub_apply]
@[simp]
theorem monomial_neg (n : ℕ) (a : R) : monomial n (-a) = -monomial n a := by
rw [eq_neg_iff_add_eq_zero, ← monomial_add, neg_add_cancel, monomial_zero_right]
theorem monomial_sub (n : ℕ) : monomial n (a - b) = monomial n a - monomial n b := by
rw [sub_eq_add_neg, monomial_add, monomial_neg, sub_eq_add_neg]
@[simp]
theorem support_neg {p : R[X]} : (-p).support = p.support := by
rcases p with ⟨⟩
rw [← ofFinsupp_neg, support, support, Finsupp.support_neg]
theorem C_eq_intCast (n : ℤ) : C (n : R) = n := by simp
theorem C_neg : C (-a) = -C a :=
RingHom.map_neg C a
theorem C_sub : C (a - b) = C a - C b :=
RingHom.map_sub C a b
end Ring
instance commRing [CommRing R] : CommRing R[X] :=
--TODO: add reference to library note in PR https://github.com/leanprover-community/mathlib4/pull/7432
{ toRing := Polynomial.ring
mul_comm := mul_comm }
section Semiring
variable [Semiring R]
instance nontrivial [Nontrivial R] : Nontrivial R[X] := by
have h : Nontrivial R[ℕ] := by infer_instance
rcases h.exists_pair_ne with ⟨x, y, hxy⟩
refine ⟨⟨⟨x⟩, ⟨y⟩, ?_⟩⟩
simp [hxy]
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R[X]) ≠ 0 :=
mt (congr_arg fun p => coeff p 1) (by simp)
instance [NoZeroDivisors R] : NoZeroDivisors R[X] :=
(toFinsuppIso R).injective.noZeroDivisors _ (map_zero _) (map_mul _)
instance [IsCancelAdd R] [IsLeftCancelMulZero R] : IsLeftCancelMulZero R[X] :=
(toFinsuppIso R).injective.isLeftCancelMulZero _ (map_zero _) (map_mul _)
instance [IsCancelAdd R] [IsRightCancelMulZero R] : IsRightCancelMulZero R[X] :=
(toFinsuppIso R).injective.isRightCancelMulZero _ (map_zero _) (map_mul _)
instance [IsCancelAdd R] [IsCancelMulZero R] : IsCancelMulZero R[X] where
instance [IsCancelAdd R] [IsDomain R] : IsDomain R[X] where
end Semiring
section DivisionSemiring
variable [DivisionSemiring R]
lemma nnqsmul_eq_C_mul (q : ℚ≥0) (f : R[X]) : q • f = Polynomial.C (q : R) * f := by
rw [← NNRat.smul_one_eq_cast, ← Polynomial.smul_C, C_1, smul_one_mul]
end DivisionSemiring
section DivisionRing
variable [DivisionRing R]
theorem qsmul_eq_C_mul (a : ℚ) (f : R[X]) : a • f = Polynomial.C (a : R) * f := by
rw [← Rat.smul_one_eq_cast, ← Polynomial.smul_C, C_1, smul_one_mul]
end DivisionRing
@[simp]
theorem nontrivial_iff [Semiring R] : Nontrivial R[X] ↔ Nontrivial R :=
⟨fun h =>
let ⟨_r, _s, hrs⟩ := @exists_pair_ne _ h
Nontrivial.of_polynomial_ne hrs,
fun h => @Polynomial.nontrivial _ _ h⟩
section repr
variable [Semiring R]
protected instance repr [Repr R] [DecidableEq R] : Repr R[X] :=
⟨fun p prec =>
let termPrecAndReprs : List (WithTop ℕ × Lean.Format) :=
List.map (fun
| 0 => (max_prec, "C " ++ reprArg (coeff p 0))
| 1 => if coeff p 1 = 1
then (⊤, "X")
else (70, "C " ++ reprArg (coeff p 1) ++ " * X")
| n =>
if coeff p n = 1
then (80, "X ^ " ++ Nat.repr n)
else (70, "C " ++ reprArg (coeff p n) ++ " * X ^ " ++ Nat.repr n))
(p.support.sort (· ≤ ·))
match termPrecAndReprs with
| [] => "0"
| [(tprec, t)] => if prec ≥ tprec then Lean.Format.paren t else t
| ts =>
-- multiple terms, use `+` precedence
(if prec ≥ 65 then Lean.Format.paren else id)
(Lean.Format.fill
(Lean.Format.joinSep (ts.map Prod.snd) (" +" ++ Lean.Format.line)))⟩
end repr
end Polynomial
|
Constructor.lean
|
/-
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.DerivabilityStructure.Basic
/-!
# Constructor for derivability structures
In this file, we provide a constructor for right derivability structures.
Assume that `W₁` and `W₂` are classes of morphisms in categories `C₁` and `C₂`,
and that we have a localizer morphism `Φ : LocalizerMorphism W₁ W₂` that is
a localized equivalence, i.e. `Φ.functor` induces an equivalence of categories
between the localized categories. Assume moreover that `W₂` contains identities.
Then, `Φ` is a right derivability structure
(`LocalizerMorphism.IsRightDerivabilityStructure.mk'`) if it satisfies the
two following conditions:
* for any `X₂ : C₂`, the category `Φ.RightResolution X₂` of resolutions of `X₂` is connected
* any arrow in `C₂` admits a resolution (i.e. `Φ.arrow.HasRightResolutions` holds, where
`Φ.arrow` is the induced localizer morphism on categories of arrows in `C₁` and `C₂`)
This statement is essentially Lemme 6.5 in
[the paper by Kahn and Maltsiniotis][KahnMaltsiniotis2008].
## References
* [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008]
-/
namespace CategoryTheory
open Category Localization
variable {C₁ C₂ : Type*} [Category C₁] [Category C₂]
{W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂}
namespace LocalizerMorphism
namespace IsRightDerivabilityStructure
section
variable (Φ : LocalizerMorphism W₁ W₂)
[∀ X₂, IsConnected (Φ.RightResolution X₂)]
[Φ.arrow.HasRightResolutions] [W₂.ContainsIdentities]
namespace Constructor
variable {D : Type*} [Category D] (L : C₂ ⥤ D) [L.IsLocalization W₂]
{X₂ : C₂} {X₃ : D} (y : L.obj X₂ ⟶ X₃)
/-- Given `Φ : LocalizerMorphism W₁ W₂`, `L : C₂ ⥤ D` a localization functor for `W₂` and
a morphism `y : L.obj X₂ ⟶ X₃`, this is the functor which sends `R : Φ.RightResolution d` to
`(isoOfHom L W₂ R.w R.hw).inv ≫ y` in the category `w.CostructuredArrowDownwards y`
where `w` is `TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv`. -/
@[simps]
noncomputable def fromRightResolution :
Φ.RightResolution X₂ ⥤ (TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _)
(Functor.rightUnitor _).inv).CostructuredArrowDownwards y where
obj R := CostructuredArrow.mk (Y := StructuredArrow.mk R.w)
(StructuredArrow.homMk ((isoOfHom L W₂ R.w R.hw).inv ≫ y))
map {R R'} φ := CostructuredArrow.homMk (StructuredArrow.homMk φ.f) (by
ext
dsimp
rw [← assoc, ← cancel_epi (isoOfHom L W₂ R.w R.hw).hom,
isoOfHom_hom, isoOfHom_hom_inv_id_assoc, assoc, ← L.map_comp_assoc,
φ.comm, isoOfHom_hom_inv_id_assoc])
lemma isConnected :
IsConnected ((TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _)
(Functor.rightUnitor _).inv).CostructuredArrowDownwards y) := by
let w := (TwoSquare.mk Φ.functor (Φ.functor ⋙ L) L (𝟭 _) (Functor.rightUnitor _).inv)
have : Nonempty (w.CostructuredArrowDownwards y) :=
⟨(fromRightResolution Φ L y).obj (Classical.arbitrary _)⟩
suffices ∀ (X : w.CostructuredArrowDownwards y),
∃ Y, Zigzag X ((fromRightResolution Φ L y).obj Y) by
refine zigzag_isConnected (fun X X' => ?_)
obtain ⟨Y, hX⟩ := this X
obtain ⟨Y', hX'⟩ := this X'
exact hX.trans ((zigzag_obj_of_zigzag _ (isPreconnected_zigzag Y Y')).trans hX'.symm)
intro X
obtain ⟨c, g, x, fac, rfl⟩ := TwoSquare.CostructuredArrowDownwards.mk_surjective X
dsimp [w] at x fac
rw [id_comp] at fac
let ρ : Φ.arrow.RightResolution (Arrow.mk g) := Classical.arbitrary _
refine ⟨RightResolution.mk ρ.w.left ρ.hw.1, ?_⟩
have := zigzag_obj_of_zigzag
(fromRightResolution Φ L x ⋙ w.costructuredArrowDownwardsPrecomp x y g fac)
(isPreconnected_zigzag (RightResolution.mk (𝟙 _) (W₂.id_mem _))
(RightResolution.mk ρ.w.right ρ.hw.2))
refine Zigzag.trans ?_ (Zigzag.trans this ?_)
· exact Zigzag.of_hom (eqToHom (by simp))
· apply Zigzag.of_inv
refine CostructuredArrow.homMk (StructuredArrow.homMk ρ.X₁.hom (by simp)) ?_
ext
dsimp
rw [← cancel_epi (isoOfHom L W₂ ρ.w.left ρ.hw.1).hom, isoOfHom_hom,
isoOfHom_hom_inv_id_assoc, ← L.map_comp_assoc, Arrow.w_mk_right, Arrow.mk_hom,
L.map_comp, assoc, isoOfHom_hom_inv_id_assoc, fac]
end Constructor
/-- If a localizer morphism `Φ` is a localized equivalence, then it is a right
derivability structure if the categories of right resolutions are connected and the
categories of right resolutions of arrows are nonempty. -/
lemma mk' [Φ.IsLocalizedEquivalence] : Φ.IsRightDerivabilityStructure := by
rw [Φ.isRightDerivabilityStructure_iff (Φ.functor ⋙ W₂.Q) W₂.Q (𝟭 _)
(Functor.rightUnitor _).symm, TwoSquare.guitartExact_iff_isConnected_downwards]
intro X₂ X₃ g
apply Constructor.isConnected
end
end IsRightDerivabilityStructure
end LocalizerMorphism
end CategoryTheory
|
Lemmas.lean
|
/-
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.Data.EReal.Inv
import Mathlib.Topology.Semicontinuous
/-!
# Topological structure on `EReal`
We prove basic properties of the topology on `EReal`.
## Main results
* `Real.toEReal : ℝ → EReal` is an open embedding
* `ENNReal.toEReal : ℝ≥0∞ → EReal` is a closed embedding
* The addition on `EReal` is continuous except at `(⊥, ⊤)` and at `(⊤, ⊥)`.
* Negation is a homeomorphism on `EReal`.
## Implementation
Most proofs are adapted from the corresponding proofs on `ℝ≥0∞`.
-/
noncomputable section
open Set Filter Metric TopologicalSpace Topology
open scoped ENNReal
variable {α : Type*} [TopologicalSpace α]
namespace EReal
/-! ### Real coercion -/
theorem isEmbedding_coe : IsEmbedding ((↑) : ℝ → EReal) :=
coe_strictMono.isEmbedding_of_ordConnected <| by rw [range_coe_eq_Ioo]; exact ordConnected_Ioo
theorem isOpenEmbedding_coe : IsOpenEmbedding ((↑) : ℝ → EReal) :=
⟨isEmbedding_coe, by simp only [range_coe_eq_Ioo, isOpen_Ioo]⟩
@[norm_cast]
theorem tendsto_coe {α : Type*} {f : Filter α} {m : α → ℝ} {a : ℝ} :
Tendsto (fun a => (m a : EReal)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) :=
isEmbedding_coe.tendsto_nhds_iff.symm
theorem _root_.continuous_coe_real_ereal : Continuous ((↑) : ℝ → EReal) :=
isEmbedding_coe.continuous
theorem continuous_coe_iff {f : α → ℝ} : (Continuous fun a => (f a : EReal)) ↔ Continuous f :=
isEmbedding_coe.continuous_iff.symm
theorem nhds_coe {r : ℝ} : 𝓝 (r : EReal) = (𝓝 r).map (↑) :=
(isOpenEmbedding_coe.map_nhds_eq r).symm
theorem nhds_coe_coe {r p : ℝ} :
𝓝 ((r : EReal), (p : EReal)) = (𝓝 (r, p)).map fun p : ℝ × ℝ => (↑p.1, ↑p.2) :=
((isOpenEmbedding_coe.prodMap isOpenEmbedding_coe).map_nhds_eq (r, p)).symm
theorem tendsto_toReal {a : EReal} (ha : a ≠ ⊤) (h'a : a ≠ ⊥) :
Tendsto EReal.toReal (𝓝 a) (𝓝 a.toReal) := by
lift a to ℝ using ⟨ha, h'a⟩
rw [nhds_coe, tendsto_map'_iff]
exact tendsto_id
theorem continuousOn_toReal : ContinuousOn EReal.toReal ({⊥, ⊤}ᶜ : Set EReal) := fun _a ha =>
ContinuousAt.continuousWithinAt (tendsto_toReal (mt Or.inr ha) (mt Or.inl ha))
/-- The set of finite `EReal` numbers is homeomorphic to `ℝ`. -/
def neBotTopHomeomorphReal : ({⊥, ⊤}ᶜ : Set EReal) ≃ₜ ℝ where
toEquiv := neTopBotEquivReal
continuous_toFun := continuousOn_iff_continuous_restrict.1 continuousOn_toReal
continuous_invFun := continuous_coe_real_ereal.subtype_mk _
/-! ### ENNReal coercion -/
theorem isEmbedding_coe_ennreal : IsEmbedding ((↑) : ℝ≥0∞ → EReal) :=
coe_ennreal_strictMono.isEmbedding_of_ordConnected <| by
rw [range_coe_ennreal]; exact ordConnected_Ici
theorem isClosedEmbedding_coe_ennreal : IsClosedEmbedding ((↑) : ℝ≥0∞ → EReal) :=
⟨isEmbedding_coe_ennreal, by rw [range_coe_ennreal]; exact isClosed_Ici⟩
@[norm_cast]
theorem tendsto_coe_ennreal {α : Type*} {f : Filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} :
Tendsto (fun a => (m a : EReal)) f (𝓝 ↑a) ↔ Tendsto m f (𝓝 a) :=
isEmbedding_coe_ennreal.tendsto_nhds_iff.symm
theorem _root_.continuous_coe_ennreal_ereal : Continuous ((↑) : ℝ≥0∞ → EReal) :=
isEmbedding_coe_ennreal.continuous
theorem continuous_coe_ennreal_iff {f : α → ℝ≥0∞} :
(Continuous fun a => (f a : EReal)) ↔ Continuous f :=
isEmbedding_coe_ennreal.continuous_iff.symm
/-! ### Neighborhoods of infinity -/
theorem nhds_top : 𝓝 (⊤ : EReal) = ⨅ (a) (_ : a ≠ ⊤), 𝓟 (Ioi a) :=
nhds_top_order.trans <| by simp only [lt_top_iff_ne_top]
nonrec theorem nhds_top_basis : (𝓝 (⊤ : EReal)).HasBasis (fun _ : ℝ ↦ True) (Ioi ·) := by
refine (nhds_top_basis (α := EReal)).to_hasBasis (fun x hx => ?_)
fun _ _ ↦ ⟨_, coe_lt_top _, Subset.rfl⟩
rcases exists_rat_btwn_of_lt hx with ⟨y, hxy, -⟩
exact ⟨_, trivial, Ioi_subset_Ioi hxy.le⟩
theorem nhds_top' : 𝓝 (⊤ : EReal) = ⨅ a : ℝ, 𝓟 (Ioi ↑a) := nhds_top_basis.eq_iInf
theorem mem_nhds_top_iff {s : Set EReal} : s ∈ 𝓝 (⊤ : EReal) ↔ ∃ y : ℝ, Ioi (y : EReal) ⊆ s :=
nhds_top_basis.mem_iff.trans <| by simp only [true_and]
theorem tendsto_nhds_top_iff_real {α : Type*} {m : α → EReal} {f : Filter α} :
Tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ, ∀ᶠ a in f, ↑x < m a :=
nhds_top_basis.tendsto_right_iff.trans <| by simp only [true_implies, mem_Ioi]
theorem nhds_bot : 𝓝 (⊥ : EReal) = ⨅ (a) (_ : a ≠ ⊥), 𝓟 (Iio a) :=
nhds_bot_order.trans <| by simp only [bot_lt_iff_ne_bot]
theorem nhds_bot_basis : (𝓝 (⊥ : EReal)).HasBasis (fun _ : ℝ ↦ True) (Iio ·) := by
refine (_root_.nhds_bot_basis (α := EReal)).to_hasBasis (fun x hx => ?_)
fun _ _ ↦ ⟨_, bot_lt_coe _, Subset.rfl⟩
rcases exists_rat_btwn_of_lt hx with ⟨y, -, hxy⟩
exact ⟨_, trivial, Iio_subset_Iio hxy.le⟩
theorem nhds_bot' : 𝓝 (⊥ : EReal) = ⨅ a : ℝ, 𝓟 (Iio ↑a) :=
nhds_bot_basis.eq_iInf
theorem mem_nhds_bot_iff {s : Set EReal} : s ∈ 𝓝 (⊥ : EReal) ↔ ∃ y : ℝ, Iio (y : EReal) ⊆ s :=
nhds_bot_basis.mem_iff.trans <| by simp only [true_and]
theorem tendsto_nhds_bot_iff_real {α : Type*} {m : α → EReal} {f : Filter α} :
Tendsto m f (𝓝 ⊥) ↔ ∀ x : ℝ, ∀ᶠ a in f, m a < x :=
nhds_bot_basis.tendsto_right_iff.trans <| by simp only [true_implies, mem_Iio]
lemma nhdsWithin_top : 𝓝[≠] (⊤ : EReal) = (atTop).map Real.toEReal := by
apply (nhdsWithin_hasBasis nhds_top_basis_Ici _).ext (atTop_basis.map Real.toEReal)
· simp only [EReal.image_coe_Ici, true_and]
intro x hx
by_cases hx_bot : x = ⊥
· simp [hx_bot]
lift x to ℝ using ⟨hx.ne_top, hx_bot⟩
refine ⟨x, fun x ⟨h1, h2⟩ ↦ ?_⟩
simp [h1, h2.ne_top]
· simp only [EReal.image_coe_Ici, true_implies]
refine fun x ↦ ⟨x, ⟨EReal.coe_lt_top x, fun x ⟨(h1 : _ ≤ x), h2⟩ ↦ ?_⟩⟩
simp [h1, Ne.lt_top' fun a ↦ h2 a.symm]
lemma nhdsWithin_bot : 𝓝[≠] (⊥ : EReal) = (atBot).map Real.toEReal := by
apply (nhdsWithin_hasBasis nhds_bot_basis_Iic _).ext (atBot_basis.map Real.toEReal)
· simp only [EReal.image_coe_Iic,
true_and]
intro x hx
by_cases hx_top : x = ⊤
· simp [hx_top]
lift x to ℝ using ⟨hx_top, hx.ne_bot⟩
refine ⟨x, fun x ⟨h1, h2⟩ ↦ ?_⟩
simp [h2, h1.ne_bot]
· simp only [EReal.image_coe_Iic, true_implies]
refine fun x ↦ ⟨x, ⟨EReal.bot_lt_coe x, fun x ⟨(h1 : x ≤ _), h2⟩ ↦ ?_⟩⟩
simp [h1, Ne.bot_lt' fun a ↦ h2 a.symm]
omit [TopologicalSpace α] in
@[simp]
lemma tendsto_coe_nhds_top_iff {f : α → ℝ} {l : Filter α} :
Tendsto (fun x ↦ Real.toEReal (f x)) l (𝓝 ⊤) ↔ Tendsto f l atTop := by
rw [tendsto_nhds_top_iff_real, atTop_basis_Ioi.tendsto_right_iff]; simp
lemma tendsto_coe_atTop : Tendsto Real.toEReal atTop (𝓝 ⊤) :=
tendsto_coe_nhds_top_iff.2 tendsto_id
omit [TopologicalSpace α] in
@[simp]
lemma tendsto_coe_nhds_bot_iff {f : α → ℝ} {l : Filter α} :
Tendsto (fun x ↦ Real.toEReal (f x)) l (𝓝 ⊥) ↔ Tendsto f l atBot := by
rw [tendsto_nhds_bot_iff_real, atBot_basis_Iio.tendsto_right_iff]; simp
lemma tendsto_coe_atBot : Tendsto Real.toEReal atBot (𝓝 ⊥) :=
tendsto_coe_nhds_bot_iff.2 tendsto_id
lemma tendsto_toReal_atTop : Tendsto EReal.toReal (𝓝[≠] ⊤) atTop := by
rw [nhdsWithin_top, tendsto_map'_iff]
exact tendsto_id
lemma tendsto_toReal_atBot : Tendsto EReal.toReal (𝓝[≠] ⊥) atBot := by
rw [nhdsWithin_bot, tendsto_map'_iff]
exact tendsto_id
/-! ### toENNReal -/
lemma continuous_toENNReal : Continuous EReal.toENNReal := by
refine continuous_iff_continuousAt.mpr fun x ↦ ?_
by_cases h_top : x = ⊤
· simp only [ContinuousAt, h_top, toENNReal_top]
refine ENNReal.tendsto_nhds_top fun n ↦ ?_
filter_upwards [eventually_gt_nhds (coe_lt_top n)] with y hy
exact toENNReal_coe (x := n) ▸ toENNReal_lt_toENNReal (coe_ennreal_nonneg _) hy
refine ContinuousOn.continuousAt ?_ (compl_singleton_mem_nhds_iff.mpr h_top)
refine (continuousOn_of_forall_continuousAt fun x hx ↦ ?_).congr (fun _ h ↦ toENNReal_of_ne_top h)
by_cases h_bot : x = ⊥
· refine tendsto_nhds_of_eventually_eq ?_
rw [h_bot, nhds_bot_basis.eventually_iff]
simp [toReal_bot, ENNReal.ofReal_zero, ENNReal.ofReal_eq_zero, true_and]
exact ⟨0, fun _ hx ↦ toReal_nonpos hx.le⟩
refine ENNReal.continuous_ofReal.continuousAt.comp' <| continuousOn_toReal.continuousAt
<| (toFinite _).isClosed.compl_mem_nhds ?_
simp_all only [mem_compl_iff, mem_singleton_iff, mem_insert_iff, or_self, not_false_eq_true]
@[fun_prop]
lemma _root_.Continuous.ereal_toENNReal {α : Type*} [TopologicalSpace α] {f : α → EReal}
(hf : Continuous f) :
Continuous fun x => (f x).toENNReal :=
continuous_toENNReal.comp hf
@[deprecated (since := "2025-03-05")] alias _root_.Continous.ereal_toENNReal :=
_root_.Continuous.ereal_toENNReal
@[fun_prop]
lemma _root_.ContinuousOn.ereal_toENNReal {α : Type*} [TopologicalSpace α] {s : Set α}
{f : α → EReal} (hf : ContinuousOn f s) :
ContinuousOn (fun x => (f x).toENNReal) s :=
continuous_toENNReal.comp_continuousOn hf
@[fun_prop]
lemma _root_.ContinuousWithinAt.ereal_toENNReal {α : Type*} [TopologicalSpace α] {f : α → EReal}
{s : Set α} {x : α} (hf : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun x => (f x).toENNReal) s x :=
continuous_toENNReal.continuousAt.comp_continuousWithinAt hf
@[fun_prop]
lemma _root_.ContinuousAt.ereal_toENNReal {α : Type*} [TopologicalSpace α] {f : α → EReal}
{x : α} (hf : ContinuousAt f x) :
ContinuousAt (fun x => (f x).toENNReal) x :=
continuous_toENNReal.continuousAt.comp hf
/-! ### Infs and Sups -/
variable {α : Type*} {u v : α → EReal}
lemma add_iInf_le_iInf_add : (⨅ x, u x) + ⨅ x, v x ≤ ⨅ x, (u + v) x :=
le_iInf fun i ↦ add_le_add (iInf_le u i) (iInf_le v i)
lemma iSup_add_le_add_iSup : ⨆ x, (u + v) x ≤ (⨆ x, u x) + ⨆ x, v x :=
iSup_le fun i ↦ add_le_add (le_iSup u i) (le_iSup v i)
/-! ### Liminfs and Limsups -/
section LimInfSup
variable {α : Type*} {f : Filter α} {u v : α → EReal}
lemma liminf_neg : liminf (- v) f = - limsup v f :=
EReal.negOrderIso.limsup_apply.symm
lemma limsup_neg : limsup (- v) f = - liminf v f :=
EReal.negOrderIso.liminf_apply.symm
lemma le_liminf_add : (liminf u f) + (liminf v f) ≤ liminf (u + v) f := by
refine add_le_of_forall_lt fun a a_u b b_v ↦ (le_liminf_iff).2 fun c c_ab ↦ ?_
filter_upwards [eventually_lt_of_lt_liminf a_u, eventually_lt_of_lt_liminf b_v] with x a_x b_x
exact c_ab.trans (add_lt_add a_x b_x)
lemma limsup_add_le (h : limsup u f ≠ ⊥ ∨ limsup v f ≠ ⊤) (h' : limsup u f ≠ ⊤ ∨ limsup v f ≠ ⊥) :
limsup (u + v) f ≤ (limsup u f) + (limsup v f) := by
refine le_add_of_forall_gt h h' fun a a_u b b_v ↦ (limsup_le_iff).2 fun c c_ab ↦ ?_
filter_upwards [eventually_lt_of_limsup_lt a_u, eventually_lt_of_limsup_lt b_v] with x a_x b_x
exact (add_lt_add a_x b_x).trans c_ab
lemma le_limsup_add : (limsup u f) + (liminf v f) ≤ limsup (u + v) f :=
add_le_of_forall_lt fun _ a_u _ b_v ↦ (le_limsup_iff).2 fun _ c_ab ↦
(((frequently_lt_of_lt_limsup) a_u).and_eventually ((eventually_lt_of_lt_liminf) b_v)).mono
fun _ ab_x ↦ c_ab.trans (add_lt_add ab_x.1 ab_x.2)
lemma liminf_add_le (h : limsup u f ≠ ⊥ ∨ liminf v f ≠ ⊤) (h' : limsup u f ≠ ⊤ ∨ liminf v f ≠ ⊥) :
liminf (u + v) f ≤ (limsup u f) + (liminf v f) :=
le_add_of_forall_gt h h' fun _ a_u _ b_v ↦ (liminf_le_iff).2 fun _ c_ab ↦
(((frequently_lt_of_liminf_lt) b_v).and_eventually ((eventually_lt_of_limsup_lt) a_u)).mono
fun _ ab_x ↦ (add_lt_add ab_x.2 ab_x.1).trans c_ab
lemma limsup_add_bot_of_ne_top (h : limsup u f = ⊥) (h' : limsup v f ≠ ⊤) :
limsup (u + v) f = ⊥ := by
apply le_bot_iff.1 ((limsup_add_le (.inr h') _).trans _)
· rw [h]; exact .inl bot_ne_top
· rw [h, bot_add]
lemma limsup_add_le_of_le {a b : EReal} (ha : limsup u f < a) (hb : limsup v f ≤ b) :
limsup (u + v) f ≤ a + b := by
rcases eq_top_or_lt_top b with rfl | h
· rw [add_top_of_ne_bot ha.ne_bot]; exact le_top
· exact (limsup_add_le (.inr (hb.trans_lt h).ne) (.inl ha.ne_top)).trans (add_le_add ha.le hb)
lemma liminf_add_gt_of_gt {a b : EReal} (ha : a < liminf u f) (hb : b < liminf v f) :
a + b < liminf (u + v) f :=
(add_lt_add ha hb).trans_le le_liminf_add
lemma liminf_add_top_of_ne_bot (h : liminf u f = ⊤) (h' : liminf v f ≠ ⊥) :
liminf (u + v) f = ⊤ := by
apply top_le_iff.1 (le_trans _ le_liminf_add)
rw [h, top_add_of_ne_bot h']
lemma le_limsup_mul (hu : ∃ᶠ x in f, 0 ≤ u x) (hv : 0 ≤ᶠ[f] v) :
limsup u f * liminf v f ≤ limsup (u * v) f := by
rcases f.eq_or_neBot with rfl | _
· rw [limsup_bot, limsup_bot, liminf_bot, bot_mul_top]
have u0 : 0 ≤ limsup u f := le_limsup_of_frequently_le hu
have uv0 : 0 ≤ limsup (u * v) f :=
le_limsup_of_frequently_le <| (hu.and_eventually hv).mono fun _ ⟨hu, hv⟩ ↦ mul_nonneg hu hv
refine mul_le_of_forall_lt_of_nonneg u0 uv0 fun a ha b hb ↦ (le_limsup_iff).2 fun c c_ab ↦ ?_
refine (((frequently_lt_of_lt_limsup) (mem_Ioo.1 ha).2).and_eventually
<| (eventually_lt_of_lt_liminf (mem_Ioo.1 hb).2).and
<| hv).mono fun x ⟨xa, ⟨xb, vx⟩⟩ ↦ ?_
exact c_ab.trans_le (mul_le_mul xa.le xb.le (mem_Ioo.1 hb).1.le ((mem_Ioo.1 ha).1.le.trans xa.le))
lemma limsup_mul_le (hu : ∃ᶠ x in f, 0 ≤ u x) (hv : 0 ≤ᶠ[f] v)
(h₁ : limsup u f ≠ 0 ∨ limsup v f ≠ ⊤) (h₂ : limsup u f ≠ ⊤ ∨ limsup v f ≠ 0) :
limsup (u * v) f ≤ limsup u f * limsup v f := by
rcases f.eq_or_neBot with rfl | _
· rw [limsup_bot]; exact bot_le
have u_0 : 0 ≤ limsup u f := le_limsup_of_frequently_le hu
replace h₁ : 0 < limsup u f ∨ limsup v f ≠ ⊤ := h₁.imp_left fun h ↦ lt_of_le_of_ne u_0 h.symm
replace h₂ : limsup u f ≠ ⊤ ∨ 0 < limsup v f :=
h₂.imp_right fun h ↦ lt_of_le_of_ne (le_limsup_of_frequently_le hv.frequently) h.symm
refine le_mul_of_forall_lt h₁ h₂ fun a a_u b b_v ↦ (limsup_le_iff).2 fun c c_ab ↦ ?_
filter_upwards [eventually_lt_of_limsup_lt a_u, eventually_lt_of_limsup_lt b_v, hv]
with x x_a x_b v_0
apply lt_of_le_of_lt _ c_ab
rcases lt_or_ge (u x) 0 with hux | hux
· apply (mul_nonpos_iff.2 (.inr ⟨hux.le, v_0⟩)).trans
exact mul_nonneg (u_0.trans a_u.le) (v_0.trans x_b.le)
· exact mul_le_mul x_a.le x_b.le v_0 (hux.trans x_a.le)
lemma le_liminf_mul (hu : 0 ≤ᶠ[f] u) (hv : 0 ≤ᶠ[f] v) :
liminf u f * liminf v f ≤ liminf (u * v) f := by
apply mul_le_of_forall_lt_of_nonneg ((le_liminf_of_le) hu)
<| (le_liminf_of_le) ((hu.and hv).mono fun x ⟨u0, v0⟩ ↦ mul_nonneg u0 v0)
refine fun a ha b hb ↦ (le_liminf_iff).2 fun c c_ab ↦ ?_
filter_upwards [eventually_lt_of_lt_liminf (mem_Ioo.1 ha).2,
eventually_lt_of_lt_liminf (mem_Ioo.1 hb).2] with x xa xb
exact c_ab.trans_le (mul_le_mul xa.le xb.le (mem_Ioo.1 hb).1.le ((mem_Ioo.1 ha).1.le.trans xa.le))
lemma liminf_mul_le [NeBot f] (hu : 0 ≤ᶠ[f] u) (hv : 0 ≤ᶠ[f] v)
(h₁ : limsup u f ≠ 0 ∨ liminf v f ≠ ⊤) (h₂ : limsup u f ≠ ⊤ ∨ liminf v f ≠ 0) :
liminf (u * v) f ≤ limsup u f * liminf v f := by
replace h₁ : 0 < limsup u f ∨ liminf v f ≠ ⊤ := by
refine h₁.imp_left fun h ↦ lt_of_le_of_ne ?_ h.symm
exact le_of_eq_of_le (limsup_const 0).symm (limsup_le_limsup hu)
replace h₂ : limsup u f ≠ ⊤ ∨ 0 < liminf v f := by
refine h₂.imp_right fun h ↦ lt_of_le_of_ne ?_ h.symm
exact le_of_eq_of_le (liminf_const 0).symm (liminf_le_liminf hv)
refine le_mul_of_forall_lt h₁ h₂ fun a a_u b b_v ↦ (liminf_le_iff).2 fun c c_ab ↦ ?_
refine (((frequently_lt_of_liminf_lt) b_v).and_eventually <| (eventually_lt_of_limsup_lt a_u).and
<| hu.and hv).mono fun x ⟨x_v, x_u, u_0, v_0⟩ ↦ ?_
exact (mul_le_mul x_u.le x_v.le v_0 (u_0.trans x_u.le)).trans_lt c_ab
end LimInfSup
/-! ### Continuity of addition -/
theorem continuousAt_add_coe_coe (a b : ℝ) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, b) := by
simp only [ContinuousAt, nhds_coe_coe, ← coe_add, tendsto_map'_iff, Function.comp_def,
tendsto_coe, tendsto_add]
theorem continuousAt_add_top_coe (a : ℝ) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊤, a) := by
simp only [ContinuousAt, tendsto_nhds_top_iff_real, top_add_coe]
refine fun r ↦ ((lt_mem_nhds (coe_lt_top (r - (a - 1)))).prod_nhds
(lt_mem_nhds <| EReal.coe_lt_coe_iff.2 <| sub_one_lt _)).mono fun _ h ↦ ?_
simpa only [← coe_add, _root_.sub_add_cancel] using add_lt_add h.1 h.2
theorem continuousAt_add_coe_top (a : ℝ) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, ⊤) := by
simpa only [add_comm, Function.comp_def, ContinuousAt, Prod.swap]
using Tendsto.comp (continuousAt_add_top_coe a) (continuous_swap.tendsto ((a : EReal), ⊤))
theorem continuousAt_add_top_top : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊤, ⊤) := by
simp only [ContinuousAt, tendsto_nhds_top_iff_real, top_add_top]
refine fun r ↦ ((lt_mem_nhds (coe_lt_top 0)).prod_nhds
(lt_mem_nhds <| coe_lt_top r)).mono fun _ h ↦ ?_
simpa only [coe_zero, zero_add] using add_lt_add h.1 h.2
theorem continuousAt_add_bot_coe (a : ℝ) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊥, a) := by
simp only [ContinuousAt, tendsto_nhds_bot_iff_real, bot_add]
refine fun r ↦ ((gt_mem_nhds (bot_lt_coe (r - (a + 1)))).prod_nhds
(gt_mem_nhds <| EReal.coe_lt_coe_iff.2 <| lt_add_one _)).mono fun _ h ↦ ?_
simpa only [← coe_add, _root_.sub_add_cancel] using add_lt_add h.1 h.2
theorem continuousAt_add_coe_bot (a : ℝ) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (a, ⊥) := by
simpa only [add_comm, Function.comp_def, ContinuousAt, Prod.swap]
using Tendsto.comp (continuousAt_add_bot_coe a) (continuous_swap.tendsto ((a : EReal), ⊥))
theorem continuousAt_add_bot_bot : ContinuousAt (fun p : EReal × EReal => p.1 + p.2) (⊥, ⊥) := by
simp only [ContinuousAt, tendsto_nhds_bot_iff_real, bot_add]
refine fun r ↦ ((gt_mem_nhds (bot_lt_coe 0)).prod_nhds
(gt_mem_nhds <| bot_lt_coe r)).mono fun _ h ↦ ?_
simpa only [coe_zero, zero_add] using add_lt_add h.1 h.2
/-- The addition on `EReal` is continuous except where it doesn't make sense (i.e., at `(⊥, ⊤)`
and at `(⊤, ⊥)`). -/
theorem continuousAt_add {p : EReal × EReal} (h : p.1 ≠ ⊤ ∨ p.2 ≠ ⊥) (h' : p.1 ≠ ⊥ ∨ p.2 ≠ ⊤) :
ContinuousAt (fun p : EReal × EReal => p.1 + p.2) p := by
rcases p with ⟨x, y⟩
induction x <;> induction y
· exact continuousAt_add_bot_bot
· exact continuousAt_add_bot_coe _
· simp at h'
· exact continuousAt_add_coe_bot _
· exact continuousAt_add_coe_coe _ _
· exact continuousAt_add_coe_top _
· simp at h
· exact continuousAt_add_top_coe _
· exact continuousAt_add_top_top
lemma lowerSemicontinuous_add : LowerSemicontinuous fun p : EReal × EReal ↦ p.1 + p.2 := by
intro x y
by_cases hx₁ : x.1 = ⊥
· simp [hx₁]
by_cases hx₂ : x.2 = ⊥
· simp [hx₂]
· exact continuousAt_add (.inr hx₂) (.inl hx₁) |>.lowerSemicontinuousAt _
/-! ### Continuity of multiplication -/
/- Outside of indeterminacies `(0, ±∞)` and `(±∞, 0)`, the multiplication on `EReal` is continuous.
There are many different cases to consider, so we first prove some special cases and leverage as
much as possible the symmetries of the multiplication. -/
private lemma continuousAt_mul_swap {a b : EReal}
(h : ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, b)) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (b, a) := by
convert h.comp continuous_swap.continuousAt (x := (b, a))
simp [mul_comm]
private lemma continuousAt_mul_symm1 {a b : EReal}
(h : ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, b)) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (-a, b) := by
have : (fun p : EReal × EReal ↦ p.1 * p.2) = (fun x : EReal ↦ -x)
∘ (fun p : EReal × EReal ↦ p.1 * p.2) ∘ (fun p : EReal × EReal ↦ (-p.1, p.2)) := by
ext p
simp
rw [this]
apply ContinuousAt.comp (Continuous.continuousAt continuous_neg)
<| ContinuousAt.comp _ (ContinuousAt.prodMap (Continuous.continuousAt continuous_neg)
(Continuous.continuousAt continuous_id))
simp [h]
private lemma continuousAt_mul_symm2 {a b : EReal}
(h : ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, b)) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, -b) :=
continuousAt_mul_swap (continuousAt_mul_symm1 (continuousAt_mul_swap h))
private lemma continuousAt_mul_symm3 {a b : EReal}
(h : ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, b)) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (-a, -b) :=
continuousAt_mul_symm1 (continuousAt_mul_symm2 h)
private lemma continuousAt_mul_coe_coe (a b : ℝ) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (a, b) := by
simp [ContinuousAt, EReal.nhds_coe_coe, ← EReal.coe_mul, Filter.tendsto_map'_iff,
Function.comp_def, EReal.tendsto_coe, tendsto_mul]
private lemma continuousAt_mul_top_top :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (⊤, ⊤) := by
simp only [ContinuousAt, EReal.top_mul_top, EReal.tendsto_nhds_top_iff_real]
intro x
rw [_root_.eventually_nhds_iff]
use (Set.Ioi ((max x 0) : EReal)) ×ˢ (Set.Ioi 1)
split_ands
· intros p p_in_prod
simp only [Set.mem_prod, Set.mem_Ioi, max_lt_iff] at p_in_prod
rcases p_in_prod with ⟨⟨p1_gt_x, p1_pos⟩, p2_gt_1⟩
have := mul_le_mul_of_nonneg_left (le_of_lt p2_gt_1) (le_of_lt p1_pos)
rw [mul_one p.1] at this
exact lt_of_lt_of_le p1_gt_x this
· exact IsOpen.prod isOpen_Ioi isOpen_Ioi
· simp
· rw [Set.mem_Ioi, ← EReal.coe_one]; exact EReal.coe_lt_top 1
private lemma continuousAt_mul_top_pos {a : ℝ} (h : 0 < a) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (⊤, a) := by
simp only [ContinuousAt, EReal.top_mul_coe_of_pos h, EReal.tendsto_nhds_top_iff_real]
intro x
rw [_root_.eventually_nhds_iff]
use (Set.Ioi ((2*(max (x+1) 0)/a : ℝ) : EReal)) ×ˢ (Set.Ioi ((a/2 : ℝ) : EReal))
split_ands
· intros p p_in_prod
simp only [Set.mem_prod, Set.mem_Ioi] at p_in_prod
rcases p_in_prod with ⟨p1_gt, p2_gt⟩
have p1_pos : 0 < p.1 := by
apply lt_of_le_of_lt _ p1_gt
rw [EReal.coe_nonneg]
apply mul_nonneg _ (le_of_lt (inv_pos_of_pos h))
simp only [Nat.ofNat_pos, mul_nonneg_iff_of_pos_left, le_max_iff, le_refl, or_true]
have a2_pos : 0 < ((a/2 : ℝ) : EReal) := by rw [EReal.coe_pos]; linarith
have lock := mul_le_mul_of_nonneg_right (le_of_lt p1_gt) (le_of_lt a2_pos)
have key := mul_le_mul_of_nonneg_left (le_of_lt p2_gt) (le_of_lt p1_pos)
replace lock := le_trans lock key
apply lt_of_lt_of_le _ lock
rw [← EReal.coe_mul, EReal.coe_lt_coe_iff, _root_.div_mul_div_comm, mul_comm,
← _root_.div_mul_div_comm, mul_div_right_comm]
simp only [ne_eq, Ne.symm (ne_of_lt h), not_false_eq_true, _root_.div_self, OfNat.ofNat_ne_zero,
one_mul, lt_max_iff, lt_add_iff_pos_right, zero_lt_one, true_or]
· exact IsOpen.prod isOpen_Ioi isOpen_Ioi
· simp
· simp [h]
private lemma continuousAt_mul_top_ne_zero {a : ℝ} (h : a ≠ 0) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) (⊤, a) := by
rcases lt_or_gt_of_ne h with a_neg | a_pos
· exact neg_neg a ▸ continuousAt_mul_symm2 (continuousAt_mul_top_pos (neg_pos.2 a_neg))
· exact continuousAt_mul_top_pos a_pos
/-- The multiplication on `EReal` is continuous except at indeterminacies
(i.e. whenever one value is zero and the other infinite). -/
theorem continuousAt_mul {p : EReal × EReal} (h₁ : p.1 ≠ 0 ∨ p.2 ≠ ⊥)
(h₂ : p.1 ≠ 0 ∨ p.2 ≠ ⊤) (h₃ : p.1 ≠ ⊥ ∨ p.2 ≠ 0) (h₄ : p.1 ≠ ⊤ ∨ p.2 ≠ 0) :
ContinuousAt (fun p : EReal × EReal ↦ p.1 * p.2) p := by
rcases p with ⟨x, y⟩
induction x <;> induction y
· exact continuousAt_mul_symm3 continuousAt_mul_top_top
· simp only [ne_eq, not_true_eq_false, EReal.coe_eq_zero, false_or] at h₃
exact continuousAt_mul_symm1 (continuousAt_mul_top_ne_zero h₃)
· exact EReal.neg_top ▸ continuousAt_mul_symm1 continuousAt_mul_top_top
· simp only [ne_eq, EReal.coe_eq_zero, not_true_eq_false, or_false] at h₁
exact continuousAt_mul_symm2 (continuousAt_mul_swap (continuousAt_mul_top_ne_zero h₁))
· exact continuousAt_mul_coe_coe _ _
· simp only [ne_eq, EReal.coe_eq_zero, not_true_eq_false, or_false] at h₂
exact continuousAt_mul_swap (continuousAt_mul_top_ne_zero h₂)
· exact continuousAt_mul_symm2 continuousAt_mul_top_top
· simp only [ne_eq, not_true_eq_false, EReal.coe_eq_zero, false_or] at h₄
exact continuousAt_mul_top_ne_zero h₄
· exact continuousAt_mul_top_top
variable {a b : EReal}
protected theorem tendsto_mul (h₁ : a ≠ 0 ∨ b ≠ ⊥) (h₂ : a ≠ 0 ∨ b ≠ ⊤) (h₃ : a ≠ ⊥ ∨ b ≠ 0)
(h₄ : a ≠ ⊤ ∨ b ≠ 0) :
Tendsto (fun p : EReal × EReal ↦ p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) :=
(continuousAt_mul h₁ h₂ h₃ h₄).tendsto
protected theorem Tendsto.mul {f : Filter α} {ma : α → EReal} {mb : α → EReal} {a b : EReal}
(hma : Tendsto ma f (𝓝 a)) (hmb : Tendsto mb f (𝓝 b)) (h₁ : a ≠ 0 ∨ b ≠ ⊥)
(h₂ : a ≠ 0 ∨ b ≠ ⊤) (h₃ : a ≠ ⊥ ∨ b ≠ 0) (h₄ : a ≠ ⊤ ∨ b ≠ 0) :
Tendsto (fun x ↦ ma x * mb x) f (𝓝 (a * b)) :=
(EReal.tendsto_mul h₁ h₂ h₃ h₄).comp (hma.prodMk_nhds hmb)
protected theorem Tendsto.const_mul {f : Filter α} {m : α → EReal} {a b : EReal}
(hm : Tendsto m f (𝓝 b)) (h₁ : a ≠ ⊥ ∨ b ≠ 0) (h₂ : a ≠ ⊤ ∨ b ≠ 0) :
Tendsto (fun b ↦ a * m b) f (𝓝 (a * b)) :=
by_cases (fun (this : a = 0) => by simp [this, tendsto_const_nhds])
fun ha : a ≠ 0 => EReal.Tendsto.mul tendsto_const_nhds hm (Or.inl ha) (Or.inl ha) h₁ h₂
protected theorem Tendsto.mul_const {f : Filter α} {m : α → EReal} {a b : EReal}
(hm : Tendsto m f (𝓝 a)) (h₁ : a ≠ 0 ∨ b ≠ ⊥) (h₂ : a ≠ 0 ∨ b ≠ ⊤) :
Tendsto (fun x ↦ m x * b) f (𝓝 (a * b)) := by
simpa only [mul_comm] using EReal.Tendsto.const_mul hm h₁.symm h₂.symm
end EReal
|
all_fingroup.v
|
From mathcomp Require Export action.
From mathcomp Require Export automorphism.
From mathcomp Require Export fingroup.
From mathcomp Require Export gproduct.
From mathcomp Require Export morphism.
From mathcomp Require Export perm.
From mathcomp Require Export presentation.
From mathcomp Require Export quotient.
|
TransferInstance.lean
|
/-
Copyright (c) 2025 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Action.TransferInstance
import Mathlib.Algebra.GroupWithZero.Action.Defs
/-!
# Transfer algebraic structures across `Equiv`s
This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`.
-/
assert_not_exists Ring
variable {M M₀ A B : Type*}
namespace Equiv
variable (M) in
/-- Transfer `SMulZeroClass` across an `Equiv` -/
protected abbrev smulZeroClass (e : A ≃ B) [Zero B] [SMulZeroClass M B] :
letI := e.zero
SMulZeroClass M A := by
letI := e.zero
exact {
e.smul M with
smul_zero := by simp [smul_def, zero_def]
}
variable (M₀) in
/-- Transfer `SMulWithZero` across an `Equiv` -/
protected abbrev smulWithZero (e : A ≃ B) [Zero M₀] [Zero B] [SMulWithZero M₀ B] :
letI := e.zero
SMulWithZero M₀ A := by
letI := e.zero
exact {
e.smulZeroClass M₀ with
zero_smul := by simp [smul_def, zero_def]
}
variable (M₀) in
/-- Transfer `MulActionWithZero` across an `Equiv` -/
protected abbrev mulActionWithZero (e : A ≃ B) [MonoidWithZero M₀] [Zero B]
[MulActionWithZero M₀ B] :
letI := e.zero
MulActionWithZero M₀ A := by
letI := e.zero
exact { e.smulWithZero M₀, e.mulAction M₀ with }
variable (M) in
/-- Transfer `DistribSMul` across an `Equiv` -/
protected abbrev distribSMul (e : A ≃ B) [AddZeroClass B] [DistribSMul M B] :
letI := e.addZeroClass
DistribSMul M A := by
letI := e.addZeroClass
exact {
e.smulZeroClass M with
smul_add := by simp [add_def, smul_def, smul_add]
}
variable (M) in
/-- Transfer `DistribMulAction` across an `Equiv` -/
protected abbrev distribMulAction (e : A ≃ B) [Monoid M] [AddMonoid B] [DistribMulAction M B] :
letI := e.addMonoid
DistribMulAction M A := by
letI := e.addMonoid
exact { e.distribSMul M, e.mulAction M with }
end Equiv
|
PrimitiveRoots.lean
|
/-
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.Nat.Factorization.LCM
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 : ℕ} [NeZero 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_isPrimitiveRoot A B (Set.mem_singleton n) (NeZero.ne _) :
∃ 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 :=
(exists_isPrimitiveRoot A B (Set.mem_singleton n) (NeZero.ne _) :
∃ r : B, IsPrimitiveRoot r n).choose_spec
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 (NeZero.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 (NeZero.pos _)] }
-- 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) (NeZero.pos n))
rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat (NeZero.pos n))] 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 (NeZero.pos n))).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, NeZero.ne _, or_false] at 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 _ (NeZero.pos _), ?_⟩
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_right_iff] at hζ
rw [hζ, show 1 = algebraMap K L 1 by simp, Algebra.norm_algebraMap, one_pow]
· replace h1 : 2 ≤ n := (two_le_iff n).mpr ⟨NeZero.ne _, h1⟩
-- 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
omit [NeZero n] in
/-- 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 (NeZero.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
have : 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 := (lt_of_le_of_ne (succ_le_of_lt (IsPrimePow.one_lt hn)) h.symm)
let 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]
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
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 (pos_of_neZero (p ^ (k + 1))) hζ ?_
rw [← 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]
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; · exact hpri.1.isPrimePow.pow (Nat.succ_ne_zero _)
rw [add_sub_cancel_right] at H
rw [H]
congr
· rw [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₁,
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 => ?_
rw [← 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 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
replace hirr : Irreducible (cyclotomic (2 ^ (k + 1)) K) := by simp [hirr]
rw [this.eq_neg_one_of_two_right, H, Algebra.norm_algebraMap,
IsCyclotomicExtension.finrank L hirr, totient_prime_pow Nat.prime_two (zero_lt_succ k),
succ_sub_succ_eq_sub, tsub_zero]
simp
/-- If `Irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `ζ - 1` is `2`. -/
theorem norm_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ k)) (hk : 2 ≤ k)
[H : IsCyclotomicExtension {2 ^ k} K L] (hirr : Irreducible (cyclotomic (2 ^ k) K)) :
norm K (ζ - 1) = 2 := by
have : 2 < 2 ^ k := by
nth_rw 1 [← pow_one 2]
exact Nat.pow_lt_pow_right one_lt_two (lt_of_lt_of_le one_lt_two hk)
replace hirr : Irreducible (cyclotomic (2 ^ k) K) := by simp [hirr]
replace hζ : IsPrimitiveRoot ζ (2 ^ k) := by simp [hζ]
obtain ⟨k₁, hk₁⟩ := exists_eq_succ_of_ne_zero (lt_of_lt_of_le zero_lt_two hk).ne.symm
simpa [hk₁] using sub_one_norm_eq_eval_cyclotomic hζ this hirr
/-- 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 `k ≠ 0` and `s ≤ k`. -/
theorem norm_pow_sub_one_eq_prime_pow_of_ne_zero {k s : ℕ} (hζ : IsPrimitiveRoot ζ (p ^ (k + 1)))
[hpri : Fact p.Prime] [hcycl : IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (hs : s ≤ k) (hk : k ≠ 0) :
norm K (ζ ^ p ^ s - 1) = (p : K) ^ p ^ s := by
by_cases htwo : p ^ (k - s + 1) = 2
· have hp : p = 2 := by
rw [← pow_one 2] at htwo
exact eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (succ_pos _) htwo
replace hs : s = k := by
rw [hp] at htwo
nth_rw 2 [← pow_one 2] at htwo
replace htwo := Nat.pow_right_injective rfl.le htwo
rw [add_eq_right, Nat.sub_eq_zero_iff_le] at htwo
exact le_antisymm hs htwo
simp only [hp, hs] at hζ hirr hcycl ⊢
obtain ⟨k₁, hk₁⟩ := Nat.exists_eq_succ_of_ne_zero hk
rw [hζ.norm_pow_sub_one_two hirr, hk₁, _root_.pow_succ', pow_mul, neg_eq_neg_one_mul,
mul_pow, neg_one_sq, one_mul, ← pow_mul, ← _root_.pow_succ']
simp
· exact hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs htwo
end Field
end IsPrimitiveRoot
namespace IsCyclotomicExtension
open IsPrimitiveRoot
variable {K} (L) [Field K] [Field L] [Algebra K L]
/-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of `zeta n K L` is `1`
if `n` is odd. -/
theorem norm_zeta_eq_one [IsCyclotomicExtension {n} K L] (hn : n ≠ 2)
(hirr : Irreducible (cyclotomic n K)) : norm K (zeta n K L) = 1 :=
(zeta_spec n K L).norm_eq_one hn hirr
/-- If `IsPrimePow n`, `n ≠ 2` and `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`),
then the norm of `zeta n K L - 1` is `n.minFac`. -/
theorem norm_zeta_sub_one_of_isPrimePow (hn : IsPrimePow n) [IsCyclotomicExtension {n} K L]
(hirr : Irreducible (cyclotomic n K)) (h : n ≠ 2) :
norm K (zeta n K L - 1) = n.minFac :=
(zeta_spec n K L).sub_one_norm_isPrimePow hn hirr h
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime,
then the norm of `(zeta (p ^ (k + 1)) K L) ^ (p ^ s) - 1` is `p ^ (p ^ s)`
if `p ^ (k - s + 1) ≠ 2`. -/
theorem norm_zeta_pow_sub_one_of_prime_pow_ne_two {k : ℕ} [Fact p.Prime]
[IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) {s : ℕ} (hs : s ≤ k)
(htwo : p ^ (k - s + 1) ≠ 2) :
norm K (zeta (p ^ (k + 1)) K L ^ p ^ s - 1) = (p : K) ^ p ^ s :=
(zeta_spec _ K L).norm_pow_sub_one_of_prime_pow_ne_two hirr hs htwo
/-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd
prime, then the norm of `zeta (p ^ (k + 1)) K L - 1` is `p`. -/
theorem norm_zeta_pow_sub_one_of_prime_ne_two {k : ℕ} [Fact p.Prime]
[IsCyclotomicExtension {p ^ (k + 1)} K L]
(hirr : Irreducible (cyclotomic (p ^ (k + 1)) K)) (h : p ≠ 2) :
norm K (zeta (p ^ (k + 1)) K L - 1) = p :=
(zeta_spec _ K L).norm_sub_one_of_prime_ne_two hirr h
/-- If `Irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime,
then the norm of `zeta p K L - 1` is `p`. -/
theorem norm_zeta_sub_one_of_prime_ne_two [Fact p.Prime]
[IsCyclotomicExtension {p} K L] (hirr : Irreducible (cyclotomic p K)) (h : p ≠ 2) :
norm K (zeta p K L - 1) = p :=
(zeta_spec _ K L).norm_sub_one_of_prime_ne_two' hirr h
/-- If `Irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`,
then the norm of `zeta (2 ^ k) K L - 1` is `2`. -/
theorem norm_zeta_pow_sub_one_two {k : ℕ} (hk : 2 ≤ k)
[IsCyclotomicExtension {2 ^ k} K L] (hirr : Irreducible (cyclotomic (2 ^ k) K)) :
norm K (zeta (2 ^ k) K L - 1) = 2 :=
norm_sub_one_two (zeta_spec (2 ^ k) K L) hk hirr
end IsCyclotomicExtension
end Norm
|
Cone.lean
|
/-
Copyright (c) 2025 Moisés Herradón Cueto. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moisés Herradón Cueto
-/
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.WithTerminal.Basic
/-!
# Relations between `Cone`, `WithTerminal` and `Over`
Given categories `C` and `J`, an object `X : C` and a functor `K : J ⥤ Over X`,
it has an obvious lift `liftFromOver K : WithTerminal J ⥤ C`, namely, send the terminal
object to `X`. These two functors have equivalent categories of cones (`coneEquiv`).
As a corollary, the limit of `K` is the limit of `liftFromOver K`, and viceversa.
-/
open CategoryTheory Limits
universe w w' v₁ v₂ u₁ u₂
variable {C : Type u₁} [Category.{v₁} C]
variable {D : Type u₂} [Category.{v₂} D]
variable {J : Type w} [Category.{w'} J]
namespace CategoryTheory.WithTerminal
variable {X : C} {K : J ⥤ Over X} {F : C ⥤ D} {t : Cone K}
/-- The category of functors `J ⥤ Over X` can be seen as part of a comma category,
namely the comma category constructed from the identity of the category of functors
`J ⥤ C` and the functor that maps `X : C` to the constant functor `J ⥤ C`.
Given a functor `K : J ⥤ Over X`, it is mapped to a natural transformation from the
obvious functor `J ⥤ C` to the constant functor `X`. -/
@[simps]
def commaFromOver : (J ⥤ Over X) ⥤ Comma (𝟭 (J ⥤ C)) (Functor.const J) where
obj K := {
left := K ⋙ Over.forget X
right := X
hom.app a := (K.obj a).hom
}
map f := {
left := Functor.whiskerRight f (Over.forget X)
right := 𝟙 X
}
/-- For any functor `K : J ⥤ Over X`, there is a canonical extension
`WithTerminal J ⥤ C`, that sends `star` to `X`. -/
@[simps!]
def liftFromOver : (J ⥤ Over X) ⥤ WithTerminal J ⥤ C := commaFromOver ⋙ equivComma.inverse
/-- The extension of a functor to over categories behaves well with compositions. -/
@[simps]
def liftFromOverComp : liftFromOver.obj (K ⋙ Over.post F) ≅ liftFromOver.obj K ⋙ F where
hom.app | star | of a => 𝟙 _
inv.app | star | of a => 𝟙 _
/-- A cone of a functor `K : J ⥤ Over X` consists of an object of `Over X`, together
with morphisms. This same object is a cone of the extended functor
`liftFromOver.obj K : WithTerminal J ⥤ C`. -/
@[simps]
private def coneLift : Cone K ⥤ Cone (liftFromOver.obj K) where
obj t := {
pt := t.pt.left
π.app
| of a => (t.π.app a).left
| star => t.pt.hom
π.naturality
| star, star, _
| of a, star, _ => by aesop
| of a, of b, f => by simp [← Comma.comp_left]
}
map {t₁ t₂} f := {
hom := f.hom.left
w
| star => by cat_disch
| of a => by simp [← Comma.comp_left]
}
/-- This is the inverse of the previous construction: a cone of an extended functor
`liftFromOver.obj K : WithTerminal J ⥤ C` consists of an object of `C`, together
with morphisms. This same object is a cone of the original functor `K : J ⥤ Over X`. -/
@[simps]
private def coneBack : Cone (liftFromOver.obj K) ⥤ Cone K where
obj t := {
pt := .mk (t.π.app star)
π.app a := {
left := t.π.app (of a)
right := 𝟙 _
w := by simpa using t.w (homFrom a)
}
π.naturality a b f := by ext; simpa using t.π.naturality (incl.map f)
}
map {t₁ t₂ f} := {
hom := Over.homMk f.hom
}
/-- Given a functor `K : J ⥤ Over X` and its extension `liftFromOver K : WithTerminal J ⥤ C`,
there is an obvious equivalence between cones of these two functors.
A cone of `K` is an object of `Over X`, so it has the form `t ⟶ X`.
Equivalently, a cone of `WithTerminal K` is an object `t : C`,
and we can recover the structure morphism as `π.app X : t ⟶ X`. -/
@[simps! functor_obj_pt functor_map_hom inverse_obj_pt_left inverse_obj_pt_right_as
inverse_obj_pt_hom inverse_obj_π_app_left inverse_map_hom_left unitIso_hom_app_hom_left
unitIso_inv_app_hom_left counitIso_hom_app_hom counitIso_inv_app_hom]
def coneEquiv : Cone K ≌ Cone (liftFromOver.obj K) where
functor := coneLift
inverse := coneBack
unitIso := .refl _
counitIso := NatIso.ofComponents fun t ↦ Cones.ext <| .refl _
@[simp]
lemma coneEquiv_functor_obj_π_app_star : (coneEquiv.functor.obj t).π.app star = t.pt.hom := rfl
@[simp]
lemma coneEquiv_functor_obj_π_app_of (Y : J) :
(coneEquiv.functor.obj t).π.app (of Y) = (t.π.app Y).left := rfl
/-- A cone `t` of `K : J ⥤ Over X` is a limit if and only if the corresponding cone
`coneLift t` of `liftFromOver.obj K : WithTerminal K ⥤ C` is a limit. -/
@[simps!]
def isLimitEquiv : IsLimit (coneEquiv.functor.obj t) ≃ IsLimit t := IsLimit.ofConeEquiv coneEquiv
end WithTerminal
open WithTerminal in
lemma Over.hasLimit_of_hasLimit_liftFromOver {X : C} (F : J ⥤ Over X)
[HasLimit (liftFromOver.obj F)] : HasLimit F :=
⟨_, isLimitEquiv <| .ofIsoLimit
(limit.isLimit (liftFromOver.obj F)) (coneEquiv.counitIso.app _).symm⟩
instance (X : C) [HasLimitsOfShape (WithTerminal J) C] :
HasLimitsOfShape J (Over X) where
has_limit _ := Over.hasLimit_of_hasLimit_liftFromOver ..
instance (X : C) [HasLimitsOfSize.{w, w'} C] : HasLimitsOfSize.{w, w'} (Over X) where
namespace WithInitial
variable {X : C} {K : J ⥤ Under X} {F : C ⥤ D} {t : Cocone K}
/-- The category of functors `J ⥤ Under X` can be seen as part of a comma category,
namely the comma category constructed from the identity of the category of functors
`J ⥤ C` and the functor that maps `X : C` to the constant functor `J ⥤ C`.
Given a functor `K : J ⥤ Under X`, it is mapped to a natural transformation to the
obvious functor `J ⥤ C` from the constant functor `X`. -/
@[simps]
def commaFromUnder : (J ⥤ Under X) ⥤ Comma (Functor.const J) (𝟭 (J ⥤ C)) where
obj K := {
left := X
right := K ⋙ Under.forget X
hom.app a := (K.obj a).hom
}
map f := {
left := 𝟙 X
right := Functor.whiskerRight f (Under.forget X)
}
/-- For any functor `K : J ⥤ Under X`, there is a canonical extension
`WithInitial J ⥤ C`, that sends `star` to `X`. -/
@[simps!]
def liftFromUnder : (J ⥤ Under X) ⥤ WithInitial J ⥤ C := commaFromUnder ⋙ equivComma.inverse
/-- The extension of a functor to under categories behaves well with compositions. -/
@[simps]
def liftFromUnderComp : liftFromUnder.obj (K ⋙ Under.post F) ≅ liftFromUnder.obj K ⋙ F where
hom.app | star | of a => 𝟙 _
inv.app | star | of a => 𝟙 _
/-- A cocone of a functor `K : J ⥤ Under X` consists of an object of `Under X`, together
with morphisms. This same object is a cocone of the extended functor
`liftFromUnder.obj K : WithInitial J ⥤ C`. -/
@[simps]
private def coconeLift : Cocone K ⥤ Cocone (liftFromUnder.obj K) where
obj t := {
pt := t.pt.right
ι.app
| of a => (t.ι.app a).right
| star => t.pt.hom
ι.naturality
| star, star, _
| star, of b, _ => by aesop
| of a, of b, f => by simp [← Comma.comp_right]
}
map {t₁ t₂} f := {
hom := f.hom.right
w
| star => by cat_disch
| of a => by simp [← Comma.comp_right]
}
/-- This is the inverse of the previous construction: a cocone of an extended functor
`liftFromUnder.obj K : WithInitial J ⥤ C` consists of an object of `C`, together
with morphisms. This same object is a cocone of the original functor `K : J ⥤ Under X`. -/
@[simps]
private def coconeBack : Cocone (liftFromUnder.obj K) ⥤ Cocone K where
obj t := {
pt := .mk (t.ι.app star)
ι.app a := {
left := 𝟙 _
right := t.ι.app (of a)
w := by simpa using (t.w (homTo a)).symm
}
ι.naturality a b f := by ext; simpa using t.ι.naturality (incl.map f)
}
map {t₁ t₂ f} := {
hom := Under.homMk f.hom
}
/-- Given a functor `K : J ⥤ Under X` and its extension `liftFromUnder K : WithInitial J ⥤ C`,
there is an obvious equivalence between cocones of these two functors.
A cocone of `K` is an object of `Under X`, so it has the form `X ⟶ t`.
Equivalently, a cocone of `WithInitial K` is an object `t : C`,
and we can recover the structure morphism as `ι.app X : X ⟶ t`. -/
@[simps! functor_obj_pt functor_map_hom inverse_obj_pt_right inverse_obj_pt_left_as
inverse_obj_pt_hom inverse_obj_ι_app_right inverse_map_hom_right unitIso_hom_app_hom_right
unitIso_inv_app_hom_right counitIso_hom_app_hom counitIso_inv_app_hom]
def coconeEquiv : Cocone K ≌ Cocone (liftFromUnder.obj K) where
functor := coconeLift
inverse := coconeBack
unitIso := .refl _
counitIso := NatIso.ofComponents fun t ↦ Cocones.ext <| .refl _
@[simp]
lemma coconeEquiv_functor_obj_ι_app_star : (coconeEquiv.functor.obj t).ι.app star = t.pt.hom := rfl
@[simp]
lemma coconeEquiv_functor_obj_ι_app_of (Y : J) :
(coconeEquiv.functor.obj t).ι.app (of Y) = (t.ι.app Y).right := rfl
/-- A cocone `t` of `K : J ⥤ Under X` is a colimit if and only if the corresponding cocone
`coconeLift t` of `liftFromUnder.obj K : WithInitial K ⥤ C` is a colimit. -/
@[simps!]
def isColimitEquiv : IsColimit (coconeEquiv.functor.obj t) ≃ IsColimit t :=
IsColimit.ofCoconeEquiv coconeEquiv
end CategoryTheory.WithInitial
open WithInitial in
lemma Under.hasColimit_of_hasColimit_liftFromUnder {X : C} (F : J ⥤ Under X)
[HasColimit (liftFromUnder.obj F)] : HasColimit F :=
⟨_, isColimitEquiv <| .ofIsoColimit
(colimit.isColimit (liftFromUnder.obj F)) (coconeEquiv.counitIso.app _).symm⟩
instance (X : C) [HasColimitsOfShape (WithInitial J) C] :
HasColimitsOfShape J (Under X) where
has_colimit _ := Under.hasColimit_of_hasColimit_liftFromUnder ..
instance (X : C) [HasColimitsOfSize.{w, w'} C] : HasColimitsOfSize.{w, w'} (Under X) where
|
automorphism.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat fintype.
From mathcomp Require Import finset fingroup perm morphism.
(******************************************************************************)
(* Group automorphisms and characteristic subgroups. *)
(* Unlike morphisms on a group G, which are functions of type gT -> rT, with *)
(* a canonical structure of dependent type {morphim G >-> rT}, automorphisms *)
(* are permutations of type {perm gT} contained in Aut G : {set {perm gT}}. *)
(* This lets us use the finGroupType of {perm gT}. Note also that while *)
(* morphisms on G are undefined outside G, automorphisms have their support *)
(* in G, i.e., they are the identity outside G. *)
(* Definitions: *)
(* Aut G (or [Aut G]) == the automorphism group of G. *)
(* [Aut G]%G == the group structure for Aut G. *)
(* autm AutGa == the morphism on G induced by a, given *)
(* AutGa : a \in Aut G. *)
(* perm_in injf fA == the permutation with support B in induced by f, *)
(* given injf : {in A &, injective f} and *)
(* fA : f @: A \subset A. *)
(* aut injf fG == the automorphism of G induced by the morphism f, *)
(* given injf : 'injm f and fG : f @* G \subset G. *)
(* Aut_isom injf sDom == the injective homomorphism that maps Aut G to *)
(* Aut (f @* G), with f : {morphism D >-> rT} and *)
(* given injf: 'injm f and sDom : G \subset D. *)
(* conjgm G == the conjugation automorphism on G. *)
(* H \char G == H is a characteristic subgroup of G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
(***********************************************************************)
(* A group automorphism, defined as a permutation on a subset of a *)
(* finGroupType that respects the morphism law. *)
(* Here perm_on is used as a closure rule for the set A. *)
(***********************************************************************)
Section Automorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Types a b : {perm gT}.
Definition Aut A := [set a | perm_on A a & morphic A a].
Lemma Aut_morphic A a : a \in Aut A -> morphic A a.
Proof. by case/setIdP. Qed.
Lemma out_Aut A a x : a \in Aut A -> x \notin A -> a x = x.
Proof. by case/setIdP=> Aa _; apply: out_perm. Qed.
Lemma eq_Aut A : {in Aut A &, forall a b, {in A, a =1 b} -> a = b}.
Proof.
move=> a g Aa Ag /= eqag; apply/permP=> x.
by have [/eqag // | /out_Aut out] := boolP (x \in A); rewrite !out.
Qed.
(* The morphism that is represented by a given element of Aut A. *)
Definition autm A a (AutAa : a \in Aut A) := morphm (Aut_morphic AutAa).
Lemma autmE A a (AutAa : a \in Aut A) : autm AutAa = a.
Proof. by []. Qed.
Canonical autm_morphism A a aM := Eval hnf in [morphism of @autm A a aM].
Section AutGroup.
Variable G : {group gT}.
Lemma Aut_group_set : group_set (Aut G).
Proof.
apply/group_setP; split=> [|a b].
by rewrite inE perm_on1; apply/morphicP=> ? *; rewrite !permE.
rewrite !inE => /andP[Ga aM] /andP[Gb bM]; rewrite perm_onM //=.
apply/morphicP=> x y Gx Gy; rewrite !permM (morphicP aM) //.
by rewrite (morphicP bM) ?perm_closed.
Qed.
Canonical Aut_group := group Aut_group_set.
Variable (a : {perm gT}) (AutGa : a \in Aut G).
Notation f := (autm AutGa).
Notation fE := (autmE AutGa).
Lemma injm_autm : 'injm f.
Proof. by apply/injmP; apply: in2W; apply: perm_inj. Qed.
Lemma ker_autm : 'ker f = 1. Proof. by move/trivgP: injm_autm. Qed.
Lemma im_autm : f @* G = G.
Proof.
apply/setP=> x; rewrite morphimEdom (can_imset_pre _ (permK a)) inE.
by have /[1!inE] /andP[/perm_closed <-] := AutGa; rewrite permKV.
Qed.
Lemma Aut_closed x : x \in G -> a x \in G.
Proof. by move=> Gx; rewrite -im_autm; apply: mem_morphim. Qed.
End AutGroup.
Lemma Aut1 : Aut 1 = 1.
Proof.
apply/trivgP/subsetP=> a /= AutGa; apply/set1P.
apply: eq_Aut (AutGa) (group1 _) _ => _ /set1P->.
by rewrite -(autmE AutGa) morph1 perm1.
Qed.
End Automorphism.
Arguments Aut _ _%_g.
Notation "[ 'Aut' G ]" := (Aut_group G) (format "[ 'Aut' G ]") : Group_scope.
Notation "[ 'Aut' G ]" := (Aut G) (only parsing) : group_scope.
Prenex Implicits Aut autm.
(* The permutation function (total on the underlying groupType) that is the *)
(* representant of a given morphism f with domain A in (Aut A). *)
Section PermIn.
Variables (T : finType) (A : {set T}) (f : T -> T).
Hypotheses (injf : {in A &, injective f}) (sBf : f @: A \subset A).
Lemma perm_in_inj : injective (fun x => if x \in A then f x else x).
Proof.
move=> x y /=; wlog Ay: x y / y \in A.
by move=> IH eqfxy; case: ifP (eqfxy); [symmetry | case: ifP => //]; auto.
rewrite Ay; case: ifP => [Ax | nAx def_x]; first exact: injf.
by case/negP: nAx; rewrite def_x (subsetP sBf) ?imset_f.
Qed.
Definition perm_in := perm perm_in_inj.
Lemma perm_in_on : perm_on A perm_in.
Proof.
by apply/subsetP=> x; rewrite inE /= permE; case: ifP => // _; case/eqP.
Qed.
Lemma perm_inE : {in A, perm_in =1 f}.
Proof. by move=> x Ax; rewrite /= permE Ax. Qed.
End PermIn.
(* properties of injective endomorphisms *)
Section MakeAut.
Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> gT}).
Implicit Type A : {set gT}.
Hypothesis injf : 'injm f.
Lemma morphim_fixP A : A \subset G -> reflect (f @* A = A) (f @* A \subset A).
Proof.
rewrite /morphim => sAG; have:= eqEcard (f @: A) A.
rewrite (setIidPr sAG) card_in_imset ?leqnn ?andbT => [<-|]; first exact: eqP.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
Qed.
Hypothesis Gf : f @* G = G.
Lemma aut_closed : f @: G \subset G.
Proof. by rewrite -morphimEdom; apply/morphim_fixP. Qed.
Definition aut := perm_in (injmP injf) aut_closed.
Lemma autE : {in G, aut =1 f}.
Proof. exact: perm_inE. Qed.
Lemma morphic_aut : morphic G aut.
Proof. by apply/morphicP=> x y Gx Gy /=; rewrite !autE ?groupM // morphM. Qed.
Lemma Aut_aut : aut \in Aut G.
Proof. by rewrite inE morphic_aut perm_in_on. Qed.
Lemma imset_autE A : A \subset G -> aut @: A = f @* A.
Proof.
move=> sAG; rewrite /morphim (setIidPr sAG).
by apply: eq_in_imset; apply: sub_in1 autE; apply/subsetP.
Qed.
Lemma preim_autE A : A \subset G -> aut @^-1: A = f @*^-1 A.
Proof.
move=> sAG; apply/setP=> x; rewrite !inE permE /=.
by case Gx: (x \in G) => //; apply/negP=> Ax; rewrite (subsetP sAG) in Gx.
Qed.
End MakeAut.
Arguments morphim_fixP {gT G f}.
Prenex Implicits aut.
Section AutIsom.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma Aut_isom_subproof a :
{a' | a' \in Aut (f @* G) & a \in Aut G -> {in G, a' \o f =1 f \o a}}.
Proof.
set Aut_a := autm (subgP (subg [Aut G] a)).
have aDom: 'dom (f \o Aut_a \o invm injf) = f @* G.
rewrite /dom /= morphpre_invm -morphpreIim; congr (f @* _).
by rewrite [_ :&: D](setIidPl _) ?injmK ?injm_autm ?im_autm.
have [af [def_af ker_af _ im_af]] := domP _ aDom.
have inj_a': 'injm af by rewrite ker_af !injm_comp ?injm_autm ?injm_invm.
have im_a': af @* (f @* G) = f @* G.
by rewrite im_af !morphim_comp morphim_invm // im_autm.
pose a' := aut inj_a' im_a'; exists a' => [|AutGa x Gx]; first exact: Aut_aut.
have Dx := domG Gx; rewrite /= [a' _]autE ?mem_morphim //.
by rewrite def_af /= invmE // autmE subgK.
Qed.
Definition Aut_isom a := s2val (Aut_isom_subproof a).
Lemma Aut_Aut_isom a : Aut_isom a \in Aut (f @* G).
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomE a : a \in Aut G -> {in G, forall x, Aut_isom a (f x) = f (a x)}.
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomM : {in Aut G &, {morph Aut_isom: x y / x * y}}.
Proof.
move=> a b AutGa AutGb.
apply: (eq_Aut (Aut_Aut_isom _)); rewrite ?groupM ?Aut_Aut_isom // => fx.
case/morphimP=> x Dx Gx ->{fx}.
by rewrite permM !Aut_isomE ?groupM /= ?permM ?Aut_closed.
Qed.
Canonical Aut_isom_morphism := Morphism Aut_isomM.
Lemma injm_Aut_isom : 'injm Aut_isom.
Proof.
apply/injmP=> a b AutGa AutGb eq_ab'; apply: (eq_Aut AutGa AutGb) => x Gx.
by apply: (injmP injf); rewrite ?domG ?Aut_closed // -!Aut_isomE //= eq_ab'.
Qed.
End AutIsom.
Section InjmAut.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma im_Aut_isom : Aut_isom injf sGD @* Aut G = Aut (f @* G).
Proof.
apply/eqP; rewrite eqEcard; apply/andP; split.
by apply/subsetP=> _ /morphimP[a _ AutGa ->]; apply: Aut_Aut_isom.
have inj_isom' := injm_Aut_isom (injm_invm injf) (morphimS _ sGD).
rewrite card_injm ?injm_Aut_isom // -(card_injm inj_isom') ?subset_leq_card //.
apply/subsetP=> a /morphimP[a' _ AutfGa' def_a].
by rewrite -(morphim_invm injf sGD) def_a Aut_Aut_isom.
Qed.
Lemma Aut_isomP : isom (Aut G) (Aut (f @* G)) (Aut_isom injf sGD).
Proof. by apply/isomP; split; [apply: injm_Aut_isom | apply: im_Aut_isom]. Qed.
Lemma injm_Aut : Aut (f @* G) \isog Aut G.
Proof. by rewrite isog_sym (isom_isog _ _ Aut_isomP). Qed.
End InjmAut.
(* conjugation automorphism *)
Section ConjugationMorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Definition conjgm of {set gT} := fun x y : gT => y ^ x.
Lemma conjgmE A x y : conjgm A x y = y ^ x. Proof. by []. Qed.
Canonical conjgm_morphism A x :=
@Morphism _ _ A (conjgm A x) (in2W (fun y z => conjMg y z x)).
Lemma morphim_conj A x B : conjgm A x @* B = (A :&: B) :^ x.
Proof. by []. Qed.
Variable G : {group gT}.
Lemma injm_conj x : 'injm (conjgm G x).
Proof. by apply/injmP; apply: in2W; apply: conjg_inj. Qed.
Lemma conj_isom x : isom G (G :^ x) (conjgm G x).
Proof. by apply/isomP; rewrite morphim_conj setIid injm_conj. Qed.
Lemma conj_isog x : G \isog G :^ x.
Proof. exact: isom_isog (conj_isom x). Qed.
Lemma norm_conjg_im x : x \in 'N(G) -> conjgm G x @* G = G.
Proof. by rewrite morphimEdom; apply: normP. Qed.
Lemma norm_conj_isom x : x \in 'N(G) -> isom G G (conjgm G x).
Proof. by move/norm_conjg_im/restr_isom_to/(_ (conj_isom x))->. Qed.
Definition conj_aut x := aut (injm_conj _) (norm_conjg_im (subgP (subg _ x))).
Lemma norm_conj_autE : {in 'N(G) & G, forall x y, conj_aut x y = y ^ x}.
Proof. by move=> x y nGx Gy; rewrite /= autE //= subgK. Qed.
Lemma conj_autE : {in G &, forall x y, conj_aut x y = y ^ x}.
Proof. by apply: sub_in11 norm_conj_autE => //; apply: subsetP (normG G). Qed.
Lemma conj_aut_morphM : {in 'N(G) &, {morph conj_aut : x y / x * y}}.
Proof.
move=> x y nGx nGy; apply/permP=> z /=; rewrite permM.
case Gz: (z \in G); last by rewrite !permE /= !Gz.
by rewrite !norm_conj_autE // (conjgM, memJ_norm, groupM).
Qed.
Canonical conj_aut_morphism := Morphism conj_aut_morphM.
Lemma ker_conj_aut : 'ker conj_aut = 'C(G).
Proof.
apply/setP=> x /[1!inE]; case nGx: (x \in 'N(G)); last first.
by symmetry; apply/idP=> cGx; rewrite (subsetP (cent_sub G)) in nGx.
rewrite 2!inE /=; apply/eqP/centP=> [cx1 y Gy | cGx].
by rewrite /commute (conjgC y) -norm_conj_autE // cx1 perm1.
apply/permP=> y; case Gy: (y \in G); last by rewrite !permE Gy.
by rewrite perm1 norm_conj_autE // conjgE -cGx ?mulKg.
Qed.
Lemma Aut_conj_aut A : conj_aut @* A \subset Aut G.
Proof. by apply/subsetP=> _ /imsetP[x _ ->]; apply: Aut_aut. Qed.
End ConjugationMorphism.
Arguments conjgm _ _%_g.
Prenex Implicits conjgm conj_aut.
Reserved Notation "G \char H" (at level 70).
(* Characteristic subgroup *)
Section Characteristicity.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H K L : {group gT}.
Definition characteristic A B :=
(A \subset B) && [forall f in Aut B, f @: A \subset A].
Infix "\char" := characteristic.
Lemma charP H G :
let fixH (f : {morphism G >-> gT}) := 'injm f -> f @* G = G -> f @* H = H in
reflect [/\ H \subset G & forall f, fixH f] (H \char G).
Proof.
do [apply: (iffP andP) => -[sHG chHG]; split] => // [f injf Gf|].
by apply/morphim_fixP; rewrite // -imset_autE ?(forall_inP chHG) ?Aut_aut.
apply/forall_inP=> f Af; rewrite -(autmE Af) -morphimEsub //.
by rewrite chHG ?injm_autm ?im_autm.
Qed.
(* Characteristic subgroup properties : composition, relational properties *)
Lemma char1 G : 1 \char G.
Proof. by apply/charP; split=> [|f _ _]; rewrite (sub1G, morphim1). Qed.
Lemma char_refl G : G \char G.
Proof. exact/charP. Qed.
Lemma char_trans H G K : K \char H -> H \char G -> K \char G.
Proof.
case/charP=> sKH chKH; case/charP=> sHG chHG.
apply/charP; split=> [|f injf Gf]; first exact: subset_trans sHG.
rewrite -{1}(setIidPr sKH) -(morphim_restrm sHG) chKH //.
by rewrite ker_restrm; move/trivgP: injf => ->; apply: subsetIr.
by rewrite morphim_restrm setIid chHG.
Qed.
Lemma char_norms H G : H \char G -> 'N(G) \subset 'N(H).
Proof.
case/charP=> sHG chHG; apply/normsP=> x /normP-Nx.
have:= chHG [morphism of conjgm G x] => /=.
by rewrite !morphimEsub //=; apply; rewrite // injm_conj.
Qed.
Lemma char_sub A B : A \char B -> A \subset B.
Proof. by case/andP. Qed.
Lemma char_norm_trans H G A : H \char G -> A \subset 'N(G) -> A \subset 'N(H).
Proof. by move/char_norms=> nHnG nGA; apply: subset_trans nHnG. Qed.
Lemma char_normal_trans H G K : K \char H -> H <| G -> K <| G.
Proof.
move=> chKH /andP[sHG nHG].
by rewrite /normal (subset_trans (char_sub chKH)) // (char_norm_trans chKH).
Qed.
Lemma char_normal H G : H \char G -> H <| G.
Proof. by move/char_normal_trans; apply; apply/andP; rewrite normG. Qed.
Lemma char_norm H G : H \char G -> G \subset 'N(H).
Proof. by case/char_normal/andP. Qed.
Lemma charI G H K : H \char G -> K \char G -> H :&: K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> _ chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite subIset // sHG.
by rewrite morphimGI ?(chHG, chKG) //; apply: subset_trans (sub1G H).
Qed.
Lemma charY G H K : H \char G -> K \char G -> H <*> K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> sKG chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite gen_subG subUset sHG.
by rewrite morphim_gen ?(morphimU, subUset, sHG, chHG, chKG).
Qed.
Lemma charM G H K : H \char G -> K \char G -> H * K \char G.
Proof.
move=> chHG chKG; rewrite -norm_joinEl ?charY //.
exact: subset_trans (char_sub chHG) (char_norm chKG).
Qed.
Lemma lone_subgroup_char G H :
H \subset G -> (forall K, K \subset G -> K \isog H -> K \subset H) ->
H \char G.
Proof.
move=> sHG Huniq; apply/charP; split=> // f injf Gf; apply/eqP.
have{} injf: {in H &, injective f}.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
have fH: f @* H = f @: H by rewrite /morphim (setIidPr sHG).
rewrite eqEcard {2}fH card_in_imset ?{}Huniq //=.
by rewrite -{3}Gf morphimS.
rewrite isog_sym; apply/isogP.
exists [morphism of restrm sHG f] => //=; first exact/injmP.
by rewrite morphimEdom fH.
Qed.
End Characteristicity.
Arguments characteristic _ _%_g _%_g.
Notation "H \char G" := (characteristic H G) : group_scope.
#[global] Hint Resolve char_refl : core.
Section InjmChar.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_char (G H : {group aT}) :
G \subset D -> H \char G -> f @* H \char f @* G.
Proof.
move=> sGD /charP[sHG charH].
apply/charP; split=> [|g injg gfG]; first exact: morphimS.
have /domP[h [_ ker_h _ im_h]]: 'dom (invm injf \o g \o f) = G.
by rewrite /dom /= -(morphpreIim g) (setIidPl _) ?injmK // gfG morphimS.
have hH: h @* H = H.
apply: charH; first by rewrite ker_h !injm_comp ?injm_invm.
by rewrite im_h !morphim_comp gfG morphim_invm.
rewrite /= -{2}hH im_h !morphim_comp morphim_invmE morphpreK //.
by rewrite (subset_trans _ (morphimS f sGD)) //= -{3}gfG !morphimS.
Qed.
End InjmChar.
Section CharInjm.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma char_injm (G H : {group aT}) :
G \subset D -> H \subset D -> (f @* H \char f @* G) = (H \char G).
Proof.
move=> sGD sHD; apply/idP/idP; last exact: injm_char.
by move/(injm_char (injm_invm injf)); rewrite !morphim_invm ?morphimS // => ->.
Qed.
End CharInjm.
Unset Implicit Arguments.
|
falgebra.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path.
From mathcomp Require Import choice fintype div tuple finfun bigop ssralg.
From mathcomp Require Import finalg zmodp matrix vector poly.
(******************************************************************************)
(* Finite dimensional free algebras, usually known as F-algebras *)
(* *)
(* falgType K == the interface type for F-algebras over K; it simply *)
(* joins the unitAlgType K and vectType K interfaces *)
(* The HB class is called Falgebra. *)
(* Any aT with an falgType structure inherits all the Vector, NzRing and *)
(* Algebra operations, and supports the following additional operations: *)
(* \dim_A M == (\dim M %/ dim A)%N -- free module dimension *)
(* amull u == the linear function v |-> u * v, for u, v : aT *)
(* amulr u == the linear function v |-> v * u, for u, v : aT *)
(* 1, f * g, f ^+ n == the identity function, the composite g \o f, the nth *)
(* iterate of f, for 1, f, g in 'End(aT) *)
(* This is just the usual F-algebra structure on *)
(* 'End(aT). It is NOT canonical by default, but can be *)
(* activated by the line Import FalgLfun. Beware also *)
(* that (f^-1)%VF is the linear function inverse, not *)
(* the ring inverse of f (though they do coincide when *)
(* f is injective). *)
(* 1%VS == the line generated by 1 : aT *)
(* (U * V)%VS == the smallest subspace of aT that contains all *)
(* products u * v for u in U, v in V *)
(* (U ^+ n)%VS == (U * U * ... * U), n-times. U ^+ 0 = 1%VS *)
(* 'C[u]%VS == the centraliser subspace of the vector u *)
(* 'C_U[v]%VS := (U :&: 'C[v])%VS *)
(* 'C(V)%VS == the centraliser subspace of the subspace V *)
(* 'C_U(V)%VS := (U :&: 'C(V))%VS *)
(* 'Z(V)%VS == the center subspace of the subspace V *)
(* agenv U == the smallest subalgebra containing U ^+ n for all n *)
(* <<U; v>>%VS == agenv (U + <[v]>) (adjoin v to U) *)
(* <<U & vs>>%VS == agenv (U + <<vs>>) (adjoin vs to U) *)
(* {aspace aT} == a subType of {vspace aT} consisting of sub-algebras *)
(* of aT (see below); for A : {aspace aT}, subvs_of A *)
(* has a canonical falgType K structure *)
(* is_aspace U <=> the characteristic predicate of {aspace aT} stating *)
(* that U is closed under product and contains an *)
(* identity element, := has_algid U && (U * U <= U)%VS *)
(* algid A == the identity element of A : {aspace aT}, which need *)
(* not be equal to 1 (indeed, in a Wedderburn *)
(* decomposition it is not even a unit in aT) *)
(* is_algid U e <-> e : aT is an identity element for the subspace U: *)
(* e in U, e != 0 & e * u = u * e = u for all u in U *)
(* has_algid U <=> there is an e such that is_algid U e *)
(* [aspace of U] == a clone of an existing {aspace aT} structure on *)
(* U : {vspace aT} (more instances of {aspace aT} will *)
(* be defined in extFieldType) *)
(* [aspace of U for A] == a clone of A : {aspace aT} for U : {vspace aT} *)
(* 1%AS == the canonical sub-algebra 1%VS *)
(* {:aT}%AS == the canonical full algebra *)
(* <<U>>%AS == the canonical algebra for agenv U; note that this is *)
(* unrelated to <<vs>>%VS, the subspace spanned by vs *)
(* <<U; v>>%AS == the canonical algebra for <<U; v>>%VS *)
(* <<U & vs>>%AS == the canonical algebra for <<U & vs>>%VS *)
(* ahom_in U f <=> f : 'Hom(aT, rT) is a multiplicative homomorphism *)
(* inside U, and in addition f 1 = 1 (even if U doesn't *)
(* contain 1) *)
(* Note that f @: U need not be a subalgebra when U is, *)
(* as f could annilate U. *)
(* 'AHom(aT, rT) == the type of algebra homomorphisms from aT to rT, *)
(* where aT and rT ARE falgType structures. Elements of *)
(* 'AHom(aT, rT) coerce to 'End(aT, rT) and aT -> rT *)
(* 'AEnd(aT) == algebra endomorphisms of aT (:= 'AHom(aT, aT)) *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope aspace_scope.
Declare Scope lrfun_scope.
Local Open Scope ring_scope.
Reserved Notation "{ 'aspace' T }" (format "{ 'aspace' T }").
Reserved Notation "<< U & vs >>" (format "<< U & vs >>").
Reserved Notation "<< U ; x >>" (format "<< U ; x >>").
Reserved Notation "''AHom' ( T , rT )" (format "''AHom' ( T , rT )").
Reserved Notation "''AEnd' ( T )" (format "''AEnd' ( T )").
Notation "\dim_ E V" := (divn (\dim V) (\dim E))
(at level 10, E at level 2, V at level 8, format "\dim_ E V") : nat_scope.
Import GRing.Theory.
(* Finite dimensional algebra *)
#[short(type="falgType")]
HB.structure Definition Falgebra (R : nzRingType) :=
{ A of Vector R A & GRing.UnitAlgebra R A }.
#[deprecated(since="mathcomp 2.0.0", note="Use falgType instead.")]
Notation FalgType := falgType.
(* Supply a default unitRing mixin for the default unitAlgType base type. *)
HB.factory Record Algebra_isFalgebra (K : fieldType) A
of Vector K A & GRing.Algebra K A := {}.
HB.builders Context K A of Algebra_isFalgebra K A.
Let vA : Vector.type K := A.
Let am u := linfun (u \o* idfun : vA -> vA).
Let uam := [pred u | lker (am u) == 0%VS].
Let vam := [fun u => if u \in uam then (am u)^-1%VF 1 else u].
Lemma amE u v : am u v = v * u. Proof. by rewrite lfunE. Qed.
Lemma mulVr : {in uam, left_inverse 1 vam *%R}.
Proof. by move=> u Uu; rewrite /= Uu -amE lker0_lfunVK. Qed.
Lemma divrr : {in uam, right_inverse 1 vam *%R}.
Proof.
by move=> u Uu; apply/(lker0P Uu); rewrite !amE -mulrA mulVr // mul1r mulr1.
Qed.
Lemma unitrP : forall x y, y * x = 1 /\ x * y = 1 -> uam x.
Proof.
move=> u v [_ uv1].
by apply/lker0P=> w1 w2 /(congr1 (am v)); rewrite !amE -!mulrA uv1 !mulr1.
Qed.
Lemma invr_out : {in [predC uam], vam =1 id}.
Proof. by move=> u /negbTE/= ->. Qed.
HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build A
mulVr divrr unitrP invr_out.
HB.end.
Module FalgebraExports.
Bind Scope ring_scope with sort.
End FalgebraExports.
HB.export FalgebraExports.
Notation "1" := (vline 1) : vspace_scope.
HB.instance Definition _ (K : fieldType) n :=
Algebra_isFalgebra.Build K 'M[K]_n.+1.
HB.instance Definition _ (R : comUnitRingType) := GRing.UnitAlgebra.on R^o.
(* FIXME: remove once https://github.com/math-comp/hierarchy-builder/issues/197
is fixed *)
Lemma regular_fullv (K : fieldType) : (fullv = 1 :> {vspace K^o})%VS.
Proof. by apply/esym/eqP; rewrite eqEdim subvf dim_vline oner_eq0 dimvf. Qed.
Section Proper.
Variables (R : nzRingType) (aT : falgType R).
Import VectorInternalTheory.
Lemma FalgType_proper : dim aT > 0.
Proof.
rewrite lt0n; apply: contraNneq (oner_neq0 aT) => aT0.
by apply/eqP/v2r_inj; do 2!move: (v2r _); rewrite aT0 => u v; rewrite !thinmx0.
Qed.
End Proper.
Module FalgLfun.
Section FalgLfun.
Variable (R : comNzRingType) (aT : falgType R).
Implicit Types f g : 'End(aT).
HB.instance Definition _ := GRing.Algebra.copy 'End(aT)
(lfun_algType (FalgType_proper aT)).
Lemma lfun_mulE f g u : (f * g) u = g (f u). Proof. exact: lfunE. Qed.
Lemma lfun_compE f g : (g \o f)%VF = f * g. Proof. by []. Qed.
End FalgLfun.
Section InvLfun.
Variable (K : fieldType) (aT : falgType K).
Implicit Types f g : 'End(aT).
Definition lfun_invr f := if lker f == 0%VS then f^-1%VF else f.
Lemma lfun_mulVr f : lker f == 0%VS -> f^-1%VF * f = 1.
Proof. exact: lker0_compfV. Qed.
Lemma lfun_mulrV f : lker f == 0%VS -> f * f^-1%VF = 1.
Proof. exact: lker0_compVf. Qed.
Fact lfun_mulRVr f : lker f == 0%VS -> lfun_invr f * f = 1.
Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulVr. Qed.
Fact lfun_mulrRV f : lker f == 0%VS -> f * lfun_invr f = 1.
Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulrV. Qed.
Fact lfun_unitrP f g : g * f = 1 /\ f * g = 1 -> lker f == 0%VS.
Proof.
case=> _ fK; apply/lker0P; apply: can_inj (g) _ => u.
by rewrite -lfun_mulE fK lfunE.
Qed.
Lemma lfun_invr_out f : lker f != 0%VS -> lfun_invr f = f.
Proof. by rewrite /lfun_invr => /negPf->. Qed.
HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'End(aT)
lfun_mulRVr lfun_mulrRV lfun_unitrP lfun_invr_out.
Lemma lfun_invE f : lker f == 0%VS -> f^-1%VF = f^-1.
Proof. by rewrite /f^-1 /= /lfun_invr => ->. Qed.
End InvLfun.
End FalgLfun.
Section FalgebraTheory.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v : aT) (U V W : {vspace aT}).
Import FalgLfun.
Definition amull u : 'End(aT) := linfun (u \*o @idfun aT).
Definition amulr u : 'End(aT) := linfun (u \o* @idfun aT).
Lemma amull_inj : injective amull.
Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mulr1. Qed.
Lemma amulr_inj : injective amulr.
Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mul1r. Qed.
Fact amull_is_linear : linear amull.
Proof.
move=> a u v; apply/lfunP => w.
by rewrite !lfunE /= scale_lfunE !lfunE /= mulrDl scalerAl.
Qed.
#[hnf]
HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amull
(GRing.semilinear_linear amull_is_linear).
(* amull is a converse ring morphism *)
Lemma amull1 : amull 1 = \1%VF.
Proof. by apply/lfunP => z; rewrite id_lfunE lfunE /= mul1r. Qed.
Lemma amullM u v : (amull (u * v) = amull v * amull u)%VF.
Proof. by apply/lfunP => w; rewrite comp_lfunE !lfunE /= mulrA. Qed.
Lemma amulr_is_linear : linear amulr.
Proof.
move=> a u v; apply/lfunP => w.
by rewrite !lfunE /= !lfunE /= lfunE mulrDr /= scalerAr.
Qed.
Lemma amulr_is_monoid_morphism : monoid_morphism amulr.
Proof.
split=> [|x y]; first by apply/lfunP => w; rewrite id_lfunE !lfunE /= mulr1.
by apply/lfunP=> w; rewrite comp_lfunE !lfunE /= mulrA.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `amulr_is_monoid_morphism` instead")]
Definition amulr_is_multiplicative :=
(fun p => (p.2, p.1)) amulr_is_monoid_morphism.
#[hnf]
HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amulr
(GRing.semilinear_linear amulr_is_linear).
#[hnf]
HB.instance Definition _ := GRing.isMonoidMorphism.Build aT (hom aT aT) amulr
amulr_is_monoid_morphism.
Lemma lker0_amull u : u \is a GRing.unit -> lker (amull u) == 0%VS.
Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulrI. Qed.
Lemma lker0_amulr u : u \is a GRing.unit -> lker (amulr u) == 0%VS.
Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulIr. Qed.
Lemma lfun1_poly (p : {poly aT}) : map_poly \1%VF p = p.
Proof. by apply: map_poly_id => u _; apply: id_lfunE. Qed.
Fact prodv_key : unit. Proof. by []. Qed.
Definition prodv :=
locked_with prodv_key (fun U V => <<allpairs *%R (vbasis U) (vbasis V)>>%VS).
Canonical prodv_unlockable := [unlockable fun prodv].
Local Notation "A * B" := (prodv A B) : vspace_scope.
Lemma memv_mul U V : {in U & V, forall u v, u * v \in (U * V)%VS}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite mulr_suml; apply: memv_suml => i _.
rewrite mulr_sumr; apply: memv_suml => j _.
rewrite -scalerAl -scalerAr !memvZ // [prodv]unlock memv_span //.
by apply/allpairsP; exists ((vbasis U)`_i, (vbasis V)`_j); rewrite !memt_nth.
Qed.
Lemma prodvP {U V W} :
reflect {in U & V, forall u v, u * v \in W} (U * V <= W)%VS.
Proof.
apply: (iffP idP) => [sUVW u v Uu Vv | sUVW].
by rewrite (subvP sUVW) ?memv_mul.
rewrite [prodv]unlock; apply/span_subvP=> _ /allpairsP[[u v] /= [Uu Vv ->]].
by rewrite sUVW ?vbasis_mem.
Qed.
Lemma prodv_line u v : (<[u]> * <[v]> = <[u * v]>)%VS.
Proof.
apply: subv_anti; rewrite -memvE memv_mul ?memv_line // andbT.
apply/prodvP=> _ _ /vlineP[a ->] /vlineP[b ->].
by rewrite -scalerAr -scalerAl !memvZ ?memv_line.
Qed.
Lemma dimv1: \dim (1%VS : {vspace aT}) = 1.
Proof. by rewrite dim_vline oner_neq0. Qed.
Lemma dim_prodv U V : \dim (U * V) <= \dim U * \dim V.
Proof. by rewrite unlock (leq_trans (dim_span _)) ?size_tuple. Qed.
Lemma vspace1_neq0 : (1 != 0 :> {vspace aT})%VS.
Proof. by rewrite -dimv_eq0 dimv1. Qed.
Lemma vbasis1 : exists2 k, k != 0 & vbasis 1 = [:: k%:A] :> seq aT.
Proof.
move: (vbasis 1) (@vbasisP K aT 1); rewrite dim_vline oner_neq0.
case/tupleP=> x X0; rewrite {X0}tuple0 => defX; have Xx := mem_head x nil.
have /vlineP[k def_x] := basis_mem defX Xx; exists k; last by rewrite def_x.
by have:= basis_not0 defX Xx; rewrite def_x scaler_eq0 oner_eq0 orbF.
Qed.
Lemma prod0v : left_zero 0%VS prodv.
Proof.
move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv 0 U)) //.
by rewrite dimv0.
Qed.
Lemma prodv0 : right_zero 0%VS prodv.
Proof.
move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv U 0)) //.
by rewrite dimv0 muln0.
Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build {vspace aT} 0%VS prodv
prod0v prodv0.
Lemma prod1v : left_id 1%VS prodv.
Proof.
move=> U; apply/subv_anti/andP; split.
by apply/prodvP=> _ u /vlineP[a ->] Uu; rewrite mulr_algl memvZ.
by apply/subvP=> u Uu; rewrite -[u]mul1r memv_mul ?memv_line.
Qed.
Lemma prodv1 : right_id 1%VS prodv.
Proof.
move=> U; apply/subv_anti/andP; split.
by apply/prodvP=> u _ Uu /vlineP[a ->]; rewrite mulr_algr memvZ.
by apply/subvP=> u Uu; rewrite -[u]mulr1 memv_mul ?memv_line.
Qed.
Lemma prodvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 * V1 <= U2 * V2)%VS.
Proof.
move/subvP=> sU12 /subvP sV12; apply/prodvP=> u v Uu Vv.
by rewrite memv_mul ?sU12 ?sV12.
Qed.
Lemma prodvSl U1 U2 V : (U1 <= U2 -> U1 * V <= U2 * V)%VS.
Proof. by move/prodvS->. Qed.
Lemma prodvSr U V1 V2 : (V1 <= V2 -> U * V1 <= U * V2)%VS.
Proof. exact: prodvS. Qed.
Lemma prodvDl : left_distributive prodv addv.
Proof.
move=> U1 U2 V; apply/esym/subv_anti/andP; split.
by rewrite subv_add 2?prodvS ?addvSl ?addvSr.
apply/prodvP=> _ v /memv_addP[u1 Uu1 [u2 Uu2 ->]] Vv.
by rewrite mulrDl memv_add ?memv_mul.
Qed.
Lemma prodvDr : right_distributive prodv addv.
Proof.
move=> U V1 V2; apply/esym/subv_anti/andP; split.
by rewrite subv_add 2?prodvS ?addvSl ?addvSr.
apply/prodvP=> u _ Uu /memv_addP[v1 Vv1 [v2 Vv2 ->]].
by rewrite mulrDr memv_add ?memv_mul.
Qed.
HB.instance Definition _ := Monoid.isAddLaw.Build {vspace aT} prodv addv
prodvDl prodvDr.
Lemma prodvA : associative prodv.
Proof.
move=> U V W; rewrite -(span_basis (vbasisP U)) span_def !big_distrl /=.
apply: eq_bigr => u _; rewrite -(span_basis (vbasisP W)) span_def !big_distrr.
apply: eq_bigr => w _; rewrite -(span_basis (vbasisP V)) span_def /=.
rewrite !(big_distrl, big_distrr) /=; apply: eq_bigr => v _.
by rewrite !prodv_line mulrA.
Qed.
HB.instance Definition _ := Monoid.isLaw.Build {vspace aT} 1%VS prodv
prodvA prod1v prodv1.
Definition expv U n := iterop n.+1.-1 prodv U 1%VS.
Local Notation "A ^+ n" := (expv A n) : vspace_scope.
Lemma expv0 U : (U ^+ 0 = 1)%VS. Proof. by []. Qed.
Lemma expv1 U : (U ^+ 1 = U)%VS. Proof. by []. Qed.
Lemma expv2 U : (U ^+ 2 = U * U)%VS. Proof. by []. Qed.
Lemma expvSl U n : (U ^+ n.+1 = U * U ^+ n)%VS.
Proof. by case: n => //; rewrite prodv1. Qed.
Lemma expv0n n : (0 ^+ n = if n is _.+1 then 0 else 1)%VS.
Proof. by case: n => // n; rewrite expvSl prod0v. Qed.
Lemma expv1n n : (1 ^+ n = 1)%VS.
Proof. by elim: n => // n IHn; rewrite expvSl IHn prodv1. Qed.
Lemma expvD U m n : (U ^+ (m + n) = U ^+ m * U ^+ n)%VS.
Proof. by elim: m => [|m IHm]; rewrite ?prod1v // !expvSl IHm prodvA. Qed.
Lemma expvSr U n : (U ^+ n.+1 = U ^+ n * U)%VS.
Proof. by rewrite -addn1 expvD. Qed.
Lemma expvM U m n : (U ^+ (m * n) = U ^+ m ^+ n)%VS.
Proof. by elim: n => [|n IHn]; rewrite ?muln0 // mulnS expvD IHn expvSl. Qed.
Lemma expvS U V n : (U <= V -> U ^+ n <= V ^+ n)%VS.
Proof.
move=> sUV; elim: n => [|n IHn]; first by rewrite !expv0 subvv.
by rewrite !expvSl prodvS.
Qed.
Lemma expv_line u n : (<[u]> ^+ n = <[u ^+ n]>)%VS.
Proof.
elim: n => [|n IH]; first by rewrite expr0 expv0.
by rewrite exprS expvSl IH prodv_line.
Qed.
(* Centralisers and centers. *)
Definition centraliser1_vspace u := lker (amulr u - amull u).
Local Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope.
Definition centraliser_vspace V := (\bigcap_i 'C[tnth (vbasis V) i])%VS.
Local Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope.
Definition center_vspace V := (V :&: 'C(V))%VS.
Local Notation "'Z ( V )" := (center_vspace V) : vspace_scope.
Lemma cent1vP u v : reflect (u * v = v * u) (u \in 'C[v]%VS).
Proof. by rewrite (sameP eqlfunP eqP) !lfunE /=; apply: eqP. Qed.
Lemma cent1v1 u : 1 \in 'C[u]%VS. Proof. by apply/cent1vP; rewrite commr1. Qed.
Lemma cent1v_id u : u \in 'C[u]%VS. Proof. exact/cent1vP. Qed.
Lemma cent1vX u n : u ^+ n \in 'C[u]%VS. Proof. exact/cent1vP/esym/commrX. Qed.
Lemma cent1vC u v : (u \in 'C[v])%VS = (v \in 'C[u])%VS.
Proof. exact/cent1vP/cent1vP. Qed.
Lemma centvP u V : reflect {in V, forall v, u * v = v * u} (u \in 'C(V))%VS.
Proof.
apply: (iffP subv_bigcapP) => [cVu y /coord_vbasis-> | cVu i _].
apply/esym/cent1vP/rpred_sum=> i _; apply: rpredZ.
by rewrite -tnth_nth cent1vC memvE cVu.
exact/cent1vP/cVu/vbasis_mem/mem_tnth.
Qed.
Lemma centvsP U V : reflect {in U & V, commutative *%R} (U <= 'C(V))%VS.
Proof. by apply: (iffP subvP) => [cUV u v | cUV u] /cUV-/centvP; apply. Qed.
Lemma subv_cent1 U v : (U <= 'C[v])%VS = (v \in 'C(U)%VS).
Proof.
by apply/subvP/centvP=> cUv u Uu; apply/cent1vP; rewrite 1?cent1vC cUv.
Qed.
Lemma centv1 V : 1 \in 'C(V)%VS.
Proof. by apply/centvP=> v _; rewrite commr1. Qed.
Lemma centvX V u n : u \in 'C(V)%VS -> u ^+ n \in 'C(V)%VS.
Proof. by move/centvP=> cVu; apply/centvP=> v /cVu/esym/commrX->. Qed.
Lemma centvC U V : (U <= 'C(V))%VS = (V <= 'C(U))%VS.
Proof. by apply/centvsP/centvsP=> cUV u v UVu /cUV->. Qed.
Lemma centerv_sub V : ('Z(V) <= V)%VS. Proof. exact: capvSl. Qed.
Lemma cent_centerv V : (V <= 'C('Z(V)))%VS.
Proof. by rewrite centvC capvSr. Qed.
(* Building the predicate that checks is a vspace has a unit *)
Definition is_algid e U :=
[/\ e \in U, e != 0 & {in U, forall u, e * u = u /\ u * e = u}].
Fact algid_decidable U : decidable (exists e, is_algid e U).
Proof.
have [-> | nzU] := eqVneq U 0%VS.
by right=> [[e []]]; rewrite memv0 => ->.
pose X := vbasis U; pose feq f1 f2 := [tuple of map f1 X ++ map f2 X].
have feqL f i: tnth (feq _ f _) (lshift _ i) = f X`_i.
set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple.
by rewrite ltn_ord (nth_map 0) ?size_tuple.
have feqR f i: tnth (feq _ _ f) (rshift _ i) = f X`_i.
set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple.
by rewrite ltnNge leq_addr addKn /= (nth_map 0) ?size_tuple.
apply: decP (vsolve_eq (feq _ amulr amull) (feq _ id id) U) _.
apply: (iffP (vsolve_eqP _ _ _)) => [[e Ue id_e] | [e [Ue _ id_e]]].
suffices idUe: {in U, forall u, e * u = u /\ u * e = u}.
exists e; split=> //; apply: contraNneq nzU => e0; rewrite -subv0.
by apply/subvP=> u /idUe[<- _]; rewrite e0 mul0r mem0v.
move=> u /coord_vbasis->; rewrite mulr_sumr mulr_suml.
split; apply/eq_bigr=> i _; rewrite -(scalerAr, scalerAl); congr (_ *: _).
by have:= id_e (lshift _ i); rewrite !feqL lfunE.
by have:= id_e (rshift _ i); rewrite !feqR lfunE.
have{id_e} /all_and2[ideX idXe]:= id_e _ (vbasis_mem (mem_tnth _ X)).
exists e => // k; rewrite -[k]splitK.
by case: (split k) => i; rewrite !(feqL, feqR) lfunE /= -tnth_nth.
Qed.
Definition has_algid : pred {vspace aT} := algid_decidable.
Lemma has_algidP {U} : reflect (exists e, is_algid e U) (has_algid U).
Proof. exact: sumboolP. Qed.
Lemma has_algid1 U : 1 \in U -> has_algid U.
Proof.
move=> U1; apply/has_algidP; exists 1; split; rewrite ?oner_eq0 // => u _.
by rewrite mulr1 mul1r.
Qed.
Definition is_aspace U := has_algid U && (U * U <= U)%VS.
Structure aspace := ASpace {asval :> {vspace aT}; _ : is_aspace asval}.
HB.instance Definition _ := [isSub for asval].
HB.instance Definition _ := [Choice of aspace by <:].
Definition clone_aspace U (A : aspace) :=
fun algU & phant_id algU (valP A) => @ASpace U algU : aspace.
Fact aspace1_subproof : is_aspace 1.
Proof. by rewrite /is_aspace prod1v -memvE has_algid1 memv_line. Qed.
Canonical aspace1 : aspace := ASpace aspace1_subproof.
Lemma aspacef_subproof : is_aspace fullv.
Proof. by rewrite /is_aspace subvf has_algid1 ?memvf. Qed.
Canonical aspacef : aspace := ASpace aspacef_subproof.
Lemma polyOver1P p :
reflect (exists q, p = map_poly (in_alg aT) q) (p \is a polyOver 1%VS).
Proof.
apply: (iffP idP) => [/allP/=Qp | [q ->]]; last first.
by apply/polyOverP=> j; rewrite coef_map rpredZ ?memv_line.
exists (map_poly (coord [tuple 1] 0) p).
rewrite -map_poly_comp map_poly_id // => _ /Qp/vlineP[a ->] /=.
by rewrite linearZ /= (coord_free 0) ?mulr1 // seq1_free ?oner_eq0.
Qed.
End FalgebraTheory.
Delimit Scope aspace_scope with AS.
Bind Scope aspace_scope with aspace.
Arguments asval {K aT} a%_AS.
Arguments aspace [K]%_type aT%_type.
Arguments clone_aspace [K aT U%_VS A%_AS algU] _.
Notation "{ 'aspace' T }" := (aspace T) : type_scope.
Notation "A * B" := (prodv A B) : vspace_scope.
Notation "A ^+ n" := (expv A n) : vspace_scope.
Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope.
Notation "'C_ U [ v ]" := (capv U 'C[v]) : vspace_scope.
Notation "'C_ ( U ) [ v ]" := (capv U 'C[v]) (only parsing) : vspace_scope.
Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope.
Notation "'C_ U ( V )" := (capv U 'C(V)) : vspace_scope.
Notation "'C_ ( U ) ( V )" := (capv U 'C(V)) (only parsing) : vspace_scope.
Notation "'Z ( V )" := (center_vspace V) : vspace_scope.
Notation "1" := (aspace1 _) : aspace_scope.
Notation "{ : aT }" := (aspacef aT) : aspace_scope.
Notation "[ 'aspace' 'of' U ]" := (@clone_aspace _ _ U _ _ id)
(format "[ 'aspace' 'of' U ]") : form_scope.
Notation "[ 'aspace' 'of' U 'for' A ]" := (@clone_aspace _ _ U A _ idfun)
(format "[ 'aspace' 'of' U 'for' A ]") : form_scope.
Arguments prodvP {K aT U V W}.
Arguments cent1vP {K aT u v}.
Arguments centvP {K aT u V}.
Arguments centvsP {K aT U V}.
Arguments has_algidP {K aT U}.
Arguments polyOver1P {K aT p}.
Section AspaceTheory.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v e : aT) (U V : {vspace aT}) (A B : {aspace aT}).
Import FalgLfun.
Lemma algid_subproof U :
{e | e \in U
& has_algid U ==> (U <= lker (amull e - 1) :&: lker (amulr e - 1))%VS}.
Proof.
apply: sig2W; case: has_algidP => [[e]|]; last by exists 0; rewrite ?mem0v.
case=> Ae _ idAe; exists e => //; apply/subvP=> u /idAe[eu_u ue_u].
by rewrite memv_cap !memv_ker !lfun_simp /= eu_u ue_u subrr eqxx.
Qed.
Definition algid U := s2val (algid_subproof U).
Lemma memv_algid U : algid U \in U.
Proof. by rewrite /algid; case: algid_subproof. Qed.
Lemma algidl A : {in A, left_id (algid A) *%R}.
Proof.
rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A.
move/subvP=> idAe u /idAe/memv_capP[].
by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP.
Qed.
Lemma algidr A : {in A, right_id (algid A) *%R}.
Proof.
rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A.
move/subvP=> idAe u /idAe/memv_capP[_].
by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP.
Qed.
Lemma unitr_algid1 A u : u \in A -> u \is a GRing.unit -> algid A = 1.
Proof. by move=> Eu /mulrI; apply; rewrite mulr1 algidr. Qed.
Lemma algid_eq1 A : (algid A == 1) = (1 \in A).
Proof. by apply/eqP/idP=> [<- | /algidr <-]; rewrite ?memv_algid ?mul1r. Qed.
Lemma algid_neq0 A : algid A != 0.
Proof.
have /andP[/has_algidP[u [Au nz_u _]] _] := valP A.
by apply: contraNneq nz_u => e0; rewrite -(algidr Au) e0 mulr0.
Qed.
Lemma dim_algid A : \dim <[algid A]> = 1%N.
Proof. by rewrite dim_vline algid_neq0. Qed.
Lemma adim_gt0 A : (0 < \dim A)%N.
Proof. by rewrite -(dim_algid A) dimvS // -memvE ?memv_algid. Qed.
Lemma not_asubv0 A : ~~ (A <= 0)%VS.
Proof. by rewrite subv0 -dimv_eq0 -lt0n adim_gt0. Qed.
Lemma adim1P {A} : reflect (A = <[algid A]>%VS :> {vspace aT}) (\dim A == 1%N).
Proof.
rewrite eqn_leq adim_gt0 -(memv_algid A) andbC -(dim_algid A) -eqEdim eq_sym.
exact: eqP.
Qed.
Lemma asubv A : (A * A <= A)%VS.
Proof. by have /andP[] := valP A. Qed.
Lemma memvM A : {in A &, forall u v, u * v \in A}.
Proof. exact/prodvP/asubv. Qed.
Lemma prodv_id A : (A * A)%VS = A.
Proof.
apply/eqP; rewrite eqEsubv asubv; apply/subvP=> u Au.
by rewrite -(algidl Au) memv_mul // memv_algid.
Qed.
Lemma prodv_sub U V A : (U <= A -> V <= A -> U * V <= A)%VS.
Proof. by move=> sUA sVA; rewrite -prodv_id prodvS. Qed.
Lemma expv_id A n : (A ^+ n.+1)%VS = A.
Proof. by elim: n => // n IHn; rewrite !expvSl prodvA prodv_id -expvSl. Qed.
Lemma limg_amulr U v : (amulr v @: U = U * <[v]>)%VS.
Proof.
rewrite -(span_basis (vbasisP U)) limg_span !span_def big_distrl /= big_map.
by apply: eq_bigr => u; rewrite prodv_line lfunE.
Qed.
Lemma memv_cosetP {U v w} :
reflect (exists2 u, u\in U & w = u * v) (w \in U * <[v]>)%VS.
Proof.
rewrite -limg_amulr.
by apply: (iffP memv_imgP) => [] [u] Uu ->; exists u; rewrite ?lfunE.
Qed.
Lemma dim_cosetv_unit V u : u \is a GRing.unit -> \dim (V * <[u]>) = \dim V.
Proof.
by move/lker0_amulr/eqP=> Uu; rewrite -limg_amulr limg_dim_eq // Uu capv0.
Qed.
Lemma memvV A u : (u^-1 \in A) = (u \in A).
Proof.
suffices{u} invA: invr_closed A by apply/idP/idP=> /invA; rewrite ?invrK.
move=> u Au; have [Uu | /invr_out-> //] := boolP (u \is a GRing.unit).
rewrite memvE -(limg_ker0 _ _ (lker0_amulr Uu)) limg_line lfunE /= mulVr //.
suff ->: (amulr u @: A)%VS = A by rewrite -memvE -algid_eq1 (unitr_algid1 Au).
by apply/eqP; rewrite limg_amulr -dimv_leqif_eq ?prodv_sub ?dim_cosetv_unit.
Qed.
Fact aspace_cap_subproof A B : algid A \in B -> is_aspace (A :&: B).
Proof.
move=> BeA; apply/andP.
split; [apply/has_algidP | by rewrite subv_cap !prodv_sub ?capvSl ?capvSr].
exists (algid A); rewrite /is_algid algid_neq0 memv_cap memv_algid.
by split=> // u /memv_capP[Au _]; rewrite ?algidl ?algidr.
Qed.
Definition aspace_cap A B BeA := ASpace (@aspace_cap_subproof A B BeA).
Fact centraliser1_is_aspace u : is_aspace 'C[u].
Proof.
rewrite /is_aspace has_algid1 ?cent1v1 //=.
apply/prodvP=> v w /cent1vP-cuv /cent1vP-cuw.
by apply/cent1vP; rewrite -mulrA cuw !mulrA cuv.
Qed.
Canonical centraliser1_aspace u := ASpace (centraliser1_is_aspace u).
Fact centraliser_is_aspace V : is_aspace 'C(V).
Proof.
rewrite /is_aspace has_algid1 ?centv1 //=.
apply/prodvP=> u w /centvP-cVu /centvP-cVw.
by apply/centvP=> v Vv; rewrite /= -mulrA cVw // !mulrA cVu.
Qed.
Canonical centraliser_aspace V := ASpace (centraliser_is_aspace V).
Lemma centv_algid A : algid A \in 'C(A)%VS.
Proof. by apply/centvP=> u Au; rewrite algidl ?algidr. Qed.
Canonical center_aspace A := [aspace of 'Z(A) for aspace_cap (centv_algid A)].
Lemma algid_center A : algid 'Z(A) = algid A.
Proof.
rewrite -(algidl (subvP (centerv_sub A) _ (memv_algid _))) algidr //=.
by rewrite memv_cap memv_algid centv_algid.
Qed.
Lemma Falgebra_FieldMixin :
GRing.integral_domain_axiom aT -> GRing.field_axiom aT.
Proof.
move=> domT u nz_u; apply/unitrP.
have kerMu: lker (amulr u) == 0%VS.
rewrite eqEsubv sub0v andbT; apply/subvP=> v; rewrite memv_ker lfunE /=.
by move/eqP/domT; rewrite (negPf nz_u) orbF memv0.
have /memv_imgP[v _ vu1]: 1 \in limg (amulr u); last rewrite lfunE /= in vu1.
suffices /eqP->: limg (amulr u) == fullv by rewrite memvf.
by rewrite -dimv_leqif_eq ?subvf ?limg_dim_eq // (eqP kerMu) capv0.
exists v; split=> //; apply: (lker0P kerMu).
by rewrite !lfunE /= -mulrA -vu1 mulr1 mul1r.
Qed.
Section SkewField.
Hypothesis fieldT : GRing.field_axiom aT.
Lemma skew_field_algid1 A : algid A = 1.
Proof. by rewrite (unitr_algid1 (memv_algid A)) ?fieldT ?algid_neq0. Qed.
Lemma skew_field_module_semisimple A M :
let sumA X := (\sum_(x <- X) A * <[x]>)%VS in
(A * M <= M)%VS -> {X | [/\ sumA X = M, directv (sumA X) & 0 \notin X]}.
Proof.
move=> sumA sAM_M; pose X := Nil aT; pose k := (\dim (A * M) - \dim (sumA X))%N.
have: (\dim (A * M) - \dim (sumA X) < k.+1)%N by [].
have: [/\ (sumA X <= A * M)%VS, directv (sumA X) & 0 \notin X].
by rewrite /sumA directvE /= !big_nil sub0v dimv0.
elim: {X k}k.+1 (X) => // k IHk X [sAX_AM dxAX nzX]; rewrite ltnS => leAXk.
have [sM_AX | /subvPn/sig2W[y My notAXy]] := boolP (M <= sumA X)%VS.
by exists X; split=> //; apply/eqP; rewrite eqEsubv (subv_trans sAX_AM).
have nz_y: y != 0 by rewrite (memPnC notAXy) ?mem0v.
pose AY := sumA (y :: X).
have sAY_AM: (AY <= A * M)%VS by rewrite [AY]big_cons subv_add ?prodvSr.
have dxAY: directv AY.
rewrite directvE /= !big_cons [_ == _]directv_addE dxAX directvE eqxx /=.
rewrite -/(sumA X) eqEsubv sub0v andbT -limg_amulr.
apply/subvP=> _ /memv_capP[/memv_imgP[a Aa ->]]/[!lfunE]/= AXay.
rewrite memv0 (mulIr_eq0 a (mulIr _)) ?fieldT //.
apply: contraR notAXy => /fieldT-Ua; rewrite -[y](mulKr Ua) /sumA.
by rewrite -big_distrr -(prodv_id A) /= -prodvA big_distrr memv_mul ?memvV.
apply: (IHk (y :: X)); first by rewrite !inE eq_sym negb_or nz_y.
rewrite -subSn ?dimvS // (directvP dxAY) /= big_cons -(directvP dxAX) /=.
rewrite subnDA (leq_trans _ leAXk) ?leq_sub2r // leq_subLR -add1n leq_add2r.
by rewrite dim_cosetv_unit ?fieldT ?adim_gt0.
Qed.
Lemma skew_field_module_dimS A M : (A * M <= M)%VS -> \dim A %| \dim M.
Proof.
case/skew_field_module_semisimple=> X [<- /directvP-> nzX] /=.
rewrite big_seq prime.dvdn_sum // => x /(memPn nzX)nz_x.
by rewrite dim_cosetv_unit ?fieldT.
Qed.
Lemma skew_field_dimS A B : (A <= B)%VS -> \dim A %| \dim B.
Proof. by move=> sAB; rewrite skew_field_module_dimS ?prodv_sub. Qed.
End SkewField.
End AspaceTheory.
(* Note that local centraliser might not be proper sub-algebras. *)
Notation "'C [ u ]" := (centraliser1_aspace u) : aspace_scope.
Notation "'C ( V )" := (centraliser_aspace V) : aspace_scope.
Notation "'Z ( A )" := (center_aspace A) : aspace_scope.
Arguments adim1P {K aT A}.
Arguments memv_cosetP {K aT U v w}.
Section Closure.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v : aT) (U V W : {vspace aT}).
(* Subspaces of an F-algebra form a Kleene algebra *)
Definition agenv U := (\sum_(i < \dim {:aT}) U ^+ i)%VS.
Local Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope.
Local Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope.
Lemma agenvEl U : agenv U = (1 + U * agenv U)%VS.
Proof.
pose f V := (1 + U * V)%VS; rewrite -/(f _); pose n := \dim {:aT}.
have ->: agenv U = iter n f 0%VS.
rewrite /agenv -/n; elim: n => [|n IHn]; first by rewrite big_ord0.
rewrite big_ord_recl /= -{}IHn; congr (1 + _)%VS; rewrite big_distrr /=.
by apply: eq_bigr => i; rewrite expvSl.
have fS i j: i <= j -> (iter i f 0 <= iter j f 0)%VS.
by elim: i j => [|i IHi] [|j] leij; rewrite ?sub0v //= addvS ?prodvSr ?IHi.
suffices /(@trajectP _ f _ n.+1)[i le_i_n Dfi]: looping f 0%VS n.+1.
by apply/eqP; rewrite eqEsubv -iterS fS // Dfi fS.
apply: contraLR (dimvS (subvf (iter n.+1 f 0%VS))); rewrite -/n -ltnNge.
rewrite -looping_uniq; elim: n.+1 => // i IHi; rewrite trajectSr rcons_uniq.
rewrite {1}trajectSr mem_rcons inE negb_or eq_sym eqEdim fS ?leqW // -ltnNge.
by rewrite -andbA => /and3P[lt_fi _ /IHi/leq_ltn_trans->].
Qed.
Lemma agenvEr U : agenv U = (1 + agenv U * U)%VS.
Proof.
rewrite [lhs in lhs = _]agenvEl big_distrr big_distrl /=; congr (_ + _)%VS.
by apply: eq_bigr => i _ /=; rewrite -expvSr -expvSl.
Qed.
Lemma agenv_modl U V : (U * V <= V -> agenv U * V <= V)%VS.
Proof.
rewrite big_distrl /= => idlU_V; apply/subv_sumP=> [[i _] /= _].
elim: i => [|i]; first by rewrite expv0 prod1v.
by apply: subv_trans; rewrite expvSr -prodvA prodvSr.
Qed.
Lemma agenv_modr U V : (V * U <= V -> V * agenv U <= V)%VS.
Proof.
rewrite big_distrr /= => idrU_V; apply/subv_sumP=> [[i _] /= _].
elim: i => [|i]; first by rewrite expv0 prodv1.
by apply: subv_trans; rewrite expvSl prodvA prodvSl.
Qed.
Fact agenv_is_aspace U : is_aspace (agenv U).
Proof.
rewrite /is_aspace has_algid1; last by rewrite memvE agenvEl addvSl.
by rewrite agenv_modl // [V in (_ <= V)%VS]agenvEl addvSr.
Qed.
Canonical agenv_aspace U : {aspace aT} := ASpace (agenv_is_aspace U).
Lemma agenvE U : agenv U = agenv_aspace U. Proof. by []. Qed.
(* Kleene algebra properties *)
Lemma agenvM U : (agenv U * agenv U)%VS = agenv U. Proof. exact: prodv_id. Qed.
Lemma agenvX n U : (agenv U ^+ n.+1)%VS = agenv U. Proof. exact: expv_id. Qed.
Lemma sub1_agenv U : (1 <= agenv U)%VS. Proof. by rewrite agenvEl addvSl. Qed.
Lemma sub_agenv U : (U <= agenv U)%VS.
Proof. by rewrite 2!agenvEl addvC prodvDr prodv1 -addvA addvSl. Qed.
Lemma subX_agenv U n : (U ^+ n <= agenv U)%VS.
Proof.
by case: n => [|n]; rewrite ?sub1_agenv // -(agenvX n) expvS // sub_agenv.
Qed.
Lemma agenv_sub_modl U V : (1 <= V -> U * V <= V -> agenv U <= V)%VS.
Proof.
move=> s1V /agenv_modl; apply: subv_trans.
by rewrite -[Us in (Us <= _)%VS]prodv1 prodvSr.
Qed.
Lemma agenv_sub_modr U V : (1 <= V -> V * U <= V -> agenv U <= V)%VS.
Proof.
move=> s1V /agenv_modr; apply: subv_trans.
by rewrite -[Us in (Us <= _)%VS]prod1v prodvSl.
Qed.
Lemma agenv_id U : agenv (agenv U) = agenv U.
Proof.
apply/eqP; rewrite eqEsubv sub_agenv andbT.
by rewrite agenv_sub_modl ?sub1_agenv ?agenvM.
Qed.
Lemma agenvS U V : (U <= V -> agenv U <= agenv V)%VS.
Proof.
move=> sUV; rewrite agenv_sub_modl ?sub1_agenv //.
by rewrite -[Vs in (_ <= Vs)%VS]agenvM prodvSl ?(subv_trans sUV) ?sub_agenv.
Qed.
Lemma agenv_add_id U V : agenv (agenv U + V) = agenv (U + V).
Proof.
apply/eqP; rewrite eqEsubv andbC agenvS ?addvS ?sub_agenv //=.
rewrite agenv_sub_modl ?sub1_agenv //.
rewrite -[rhs in (_ <= rhs)%VS]agenvM prodvSl // subv_add agenvS ?addvSl //=.
exact: subv_trans (addvSr U V) (sub_agenv _).
Qed.
Lemma subv_adjoin U x : (U <= <<U; x>>)%VS.
Proof. by rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSl. Qed.
Lemma subv_adjoin_seq U xs : (U <= <<U & xs>>)%VS.
Proof. by rewrite (subv_trans (sub_agenv _)) // ?agenvS ?addvSl. Qed.
Lemma memv_adjoin U x : x \in <<U; x>>%VS.
Proof. by rewrite memvE (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed.
Lemma seqv_sub_adjoin U xs : {subset xs <= <<U & xs>>%VS}.
Proof.
by apply/span_subvP; rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSr.
Qed.
Lemma subvP_adjoin U x y : y \in U -> y \in <<U; x>>%VS.
Proof. exact/subvP/subv_adjoin. Qed.
Lemma adjoin_nil V : <<V & [::]>>%VS = agenv V.
Proof. by rewrite span_nil addv0. Qed.
Lemma adjoin_cons V x rs : <<V & x :: rs>>%VS = << <<V; x>> & rs>>%VS.
Proof. by rewrite span_cons addvA agenv_add_id. Qed.
Lemma adjoin_rcons V rs x : <<V & rcons rs x>>%VS = << <<V & rs>>%VS; x>>%VS.
Proof. by rewrite -cats1 span_cat addvA span_seq1 agenv_add_id. Qed.
Lemma adjoin_seq1 V x : <<V & [:: x]>>%VS = <<V; x>>%VS.
Proof. by rewrite adjoin_cons adjoin_nil agenv_id. Qed.
Lemma adjoinC V x y : << <<V; x>>; y>>%VS = << <<V; y>>; x>>%VS.
Proof. by rewrite !agenv_add_id -!addvA (addvC <[x]>%VS). Qed.
Lemma adjoinSl U V x : (U <= V -> <<U; x>> <= <<V; x>>)%VS.
Proof. by move=> sUV; rewrite agenvS ?addvS. Qed.
Lemma adjoin_seqSl U V rs : (U <= V -> <<U & rs>> <= <<V & rs>>)%VS.
Proof. by move=> sUV; rewrite agenvS ?addvS. Qed.
Lemma adjoin_seqSr U rs1 rs2 :
{subset rs1 <= rs2} -> (<<U & rs1>> <= <<U & rs2>>)%VS.
Proof. by move/sub_span=> s_rs12; rewrite agenvS ?addvS. Qed.
End Closure.
Notation "<< U >>" := (agenv_aspace U) : aspace_scope.
Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope.
Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope.
Notation "<< U & vs >>" := << U + <<vs>> >>%AS : aspace_scope.
Notation "<< U ; x >>" := << U + <[x]> >>%AS : aspace_scope.
Section SubFalgType.
(* The falgType structure of subvs_of A for A : {aspace aT}. *)
(* We can't use the rpred-based mixin, because A need not contain 1. *)
Variable (K : fieldType) (aT : falgType K) (A : {aspace aT}).
Definition subvs_one := Subvs (memv_algid A).
Definition subvs_mul (u v : subvs_of A) :=
Subvs (subv_trans (memv_mul (subvsP u) (subvsP v)) (asubv _)).
Fact subvs_mulA : associative subvs_mul.
Proof. by move=> x y z; apply/val_inj/mulrA. Qed.
Fact subvs_mu1l : left_id subvs_one subvs_mul.
Proof. by move=> x; apply/val_inj/algidl/(valP x). Qed.
Fact subvs_mul1 : right_id subvs_one subvs_mul.
Proof. by move=> x; apply/val_inj/algidr/(valP x). Qed.
Fact subvs_mulDl : left_distributive subvs_mul +%R.
Proof. move=> x y z; apply/val_inj/mulrDl. Qed.
Fact subvs_mulDr : right_distributive subvs_mul +%R.
Proof. move=> x y z; apply/val_inj/mulrDr. Qed.
HB.instance Definition _ := GRing.Zmodule_isNzRing.Build (subvs_of A)
subvs_mulA subvs_mu1l subvs_mul1 subvs_mulDl subvs_mulDr (algid_neq0 _).
Lemma subvs_scaleAl k (x y : subvs_of A) : k *: (x * y) = (k *: x) * y.
Proof. exact/val_inj/scalerAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build K (subvs_of A)
subvs_scaleAl.
Lemma subvs_scaleAr k (x y : subvs_of A) : k *: (x * y) = x * (k *: y).
Proof. exact/val_inj/scalerAr. Qed.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build K (subvs_of A)
subvs_scaleAr.
HB.instance Definition _ := Algebra_isFalgebra.Build K (subvs_of A).
Implicit Type w : subvs_of A.
Lemma vsval_unitr w : vsval w \is a GRing.unit -> w \is a GRing.unit.
Proof.
case: w => /= u Au Uu; have Au1: u^-1 \in A by rewrite memvV.
apply/unitrP; exists (Subvs Au1).
by split; apply: val_inj; rewrite /= ?mulrV ?mulVr ?(unitr_algid1 Au).
Qed.
Lemma vsval_invr w : vsval w \is a GRing.unit -> val w^-1 = (val w)^-1.
Proof.
move=> Uu; have def_w: w / w * w = w by rewrite divrK ?vsval_unitr.
by apply: (mulrI Uu); rewrite -[in u in u / _]def_w ?mulrK.
Qed.
End SubFalgType.
Section AHom.
Variable K : fieldType.
Section Class_Def.
Variables aT rT : falgType K.
Definition ahom_in (U : {vspace aT}) (f : 'Hom(aT, rT)) :=
all2rel (fun x y : aT => f (x * y) == f x * f y) (vbasis U) && (f 1 == 1).
Lemma ahom_inP {f : 'Hom(aT, rT)} {U : {vspace aT}} :
reflect ({in U &, {morph f : x y / x * y >-> x * y}} * (f 1 = 1))
(ahom_in U f).
Proof.
apply: (iffP andP) => [[/allrelP fM /eqP f1] | [fM f1]]; last first.
rewrite f1; split=> //; apply/allrelP => x y Ax Ay.
by rewrite fM // vbasis_mem.
split=> // x y /coord_vbasis -> /coord_vbasis ->.
rewrite !mulr_suml ![f _]linear_sum mulr_suml; apply: eq_bigr => i _ /=.
rewrite !mulr_sumr linear_sum; apply: eq_bigr => j _ /=.
rewrite !linearZ -!scalerAr -!scalerAl 2!linearZ /=; congr (_ *: (_ *: _)).
by apply/eqP/fM; apply: memt_nth.
Qed.
Lemma ahomP_tmp {f : 'Hom(aT, rT)} : reflect (monoid_morphism f) (ahom_in {:aT} f).
Proof.
apply: (iffP ahom_inP) => [[fM f1] | fRM_P]; last first.
by split=> [x y|]; [rewrite fRM_P.2|rewrite fRM_P.1].
by split=> // x y; rewrite fM ?memvf.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ahomP_tmp` instead")]
Lemma ahomP {f : 'Hom(aT, rT)} : reflect (multiplicative f) (ahom_in {:aT} f).
Proof. by apply: (iffP ahomP_tmp) => [][]. Qed.
Structure ahom := AHom {ahval :> 'Hom(aT, rT); _ : ahom_in {:aT} ahval}.
HB.instance Definition _ := [isSub for ahval].
HB.instance Definition _ := [Equality of ahom by <:].
HB.instance Definition _ := [Choice of ahom by <:].
Fact linfun_is_ahom (f : {lrmorphism aT -> rT}) : ahom_in {:aT} (linfun f).
Proof. by apply/ahom_inP; split=> [x y|]; rewrite !lfunE ?rmorphM ?rmorph1. Qed.
Canonical linfun_ahom f := AHom (linfun_is_ahom f).
End Class_Def.
Arguments ahom_in [aT rT].
Arguments ahom_inP {aT rT f U}.
#[warning="-deprecated-since-mathcomp-2.5.0"]
Arguments ahomP {aT rT f}.
Arguments ahomP_tmp {aT rT f}.
Section LRMorphism.
Variables aT rT sT : falgType K.
Fact ahom_is_monoid_morphism (f : ahom aT rT) : monoid_morphism f.
Proof. by apply/ahomP_tmp; case: f. Qed.
#[hnf]
HB.instance Definition _ (f : ahom aT rT) :=
GRing.isMonoidMorphism.Build aT rT f (ahom_is_monoid_morphism f).
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ahom_is_monoid_morphism` instead")]
Definition ahom_is_multiplicative (f : ahom aT rT) : multiplicative f :=
(fun p => (p.2, p.1)) (ahom_is_monoid_morphism f).
Lemma ahomWin (f : ahom aT rT) U : ahom_in U f.
Proof.
by apply/ahom_inP; split; [apply: in2W (rmorphM _) | apply: rmorph1].
Qed.
Lemma id_is_ahom (V : {vspace aT}) : ahom_in V \1.
Proof. by apply/ahom_inP; split=> [x y|] /=; rewrite !id_lfunE. Qed.
Canonical id_ahom := AHom (id_is_ahom (aspacef aT)).
Lemma comp_is_ahom (V : {vspace aT}) (f : 'Hom(rT, sT)) (g : 'Hom(aT, rT)) :
ahom_in {:rT} f -> ahom_in V g -> ahom_in V (f \o g).
Proof.
move=> /ahom_inP fM /ahom_inP gM; apply/ahom_inP.
by split=> [x y Vx Vy|] /=; rewrite !comp_lfunE gM // fM ?memvf.
Qed.
Canonical comp_ahom (f : ahom rT sT) (g : ahom aT rT) :=
AHom (comp_is_ahom (valP f) (valP g)).
Lemma aimgM (f : ahom aT rT) U V : (f @: (U * V) = f @: U * f @: V)%VS.
Proof.
apply/eqP; rewrite eqEsubv; apply/andP; split; last first.
apply/prodvP=> _ _ /memv_imgP[u Hu ->] /memv_imgP[v Hv ->].
by rewrite -rmorphM memv_img // memv_mul.
apply/subvP=> _ /memv_imgP[w UVw ->]; rewrite memv_preim (subvP _ w UVw) //.
by apply/prodvP=> u v Uu Vv; rewrite -memv_preim rmorphM memv_mul // memv_img.
Qed.
Lemma aimg1 (f : ahom aT rT) : (f @: 1 = 1)%VS.
Proof. by rewrite limg_line rmorph1. Qed.
Lemma aimgX (f : ahom aT rT) U n : (f @: (U ^+ n) = f @: U ^+ n)%VS.
Proof.
elim: n => [|n IH]; first by rewrite !expv0 aimg1.
by rewrite !expvSl aimgM IH.
Qed.
Lemma aimg_agen (f : ahom aT rT) U : (f @: agenv U)%VS = agenv (f @: U).
Proof.
apply/eqP; rewrite eqEsubv; apply/andP; split.
by rewrite limg_sum; apply/subv_sumP => i _; rewrite aimgX subX_agenv.
apply: agenv_sub_modl; first by rewrite -(aimg1 f) limgS // sub1_agenv.
by rewrite -aimgM limgS // [rhs in (_ <= rhs)%VS]agenvEl addvSr.
Qed.
Lemma aimg_adjoin (f : ahom aT rT) U x : (f @: <<U; x>> = <<f @: U; f x>>)%VS.
Proof. by rewrite aimg_agen limgD limg_line. Qed.
Lemma aimg_adjoin_seq (f : ahom aT rT) U xs :
(f @: <<U & xs>> = <<f @: U & map f xs>>)%VS.
Proof. by rewrite aimg_agen limgD limg_span. Qed.
Fact ker_sub_ahom_is_aspace (f g : ahom aT rT) :
is_aspace (lker (ahval f - ahval g)).
Proof.
rewrite /is_aspace has_algid1; last by apply/eqlfunP; rewrite !rmorph1.
apply/prodvP=> a b /eqlfunP Dfa /eqlfunP Dfb.
by apply/eqlfunP; rewrite !rmorphM /= Dfa Dfb.
Qed.
Canonical ker_sub_ahom_aspace f g := ASpace (ker_sub_ahom_is_aspace f g).
End LRMorphism.
Canonical fixedSpace_aspace aT (f : ahom aT aT) := [aspace of fixedSpace f].
End AHom.
Arguments ahom_in [K aT rT].
Notation "''AHom' ( aT , rT )" := (ahom aT rT) : type_scope.
Notation "''AEnd' ( aT )" := (ahom aT aT) : type_scope.
Delimit Scope lrfun_scope with AF.
Bind Scope lrfun_scope with ahom.
Notation "\1" := (@id_ahom _ _) : lrfun_scope.
Notation "f \o g" := (comp_ahom f g) : lrfun_scope.
|
ProjectiveLine.lean
|
/-
Copyright (c) 2024 Bjørn Kjos-Hanssen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bjørn Kjos-Hanssen, Oliver Nash
-/
import Mathlib.LinearAlgebra.Projectivization.Basic
import Mathlib.Topology.Compactification.OnePoint.Basic
/-!
# One-point compactification and projectivization
We construct a set-theoretic equivalence between
`OnePoint K` and the projectivization `ℙ K (K × K)` for an arbitrary division ring `K`.
TODO: Add the extension of this equivalence to a homeomorphism in the case `K = ℝ`,
where `OnePoint ℝ` gets the topology of one-point compactification.
## Main definitions and results
* `OnePoint.equivProjectivization` : the equivalence `OnePoint K ≃ ℙ K (K × K)`.
## Tags
one-point extension, projectivization
-/
open scoped LinearAlgebra.Projectivization OnePoint
open Projectivization
namespace OnePoint
variable (K : Type*) [DivisionRing K] [DecidableEq K]
/-- The one-point compactification of a division ring `K` is equivalent to
the projectivization `ℙ K (K × K)`. -/
def equivProjectivization :
OnePoint K ≃ ℙ K (K × K) where
toFun p := p.elim (mk K (1, 0) (by simp)) (fun t ↦ mk K (t, 1) (by simp))
invFun p := by
refine Projectivization.lift
(fun u : {v : K × K // v ≠ 0} ↦ if u.1.2 = 0 then ∞ else ((u.1.2)⁻¹ * u.1.1)) ?_ p
rintro ⟨-, hv⟩ ⟨⟨x, y⟩, hw⟩ t rfl
have ht : t ≠ 0 := by rintro rfl; simp at hv
by_cases h₀ : y = 0 <;> simp [h₀, ht, mul_assoc]
left_inv p := by cases p <;> simp
right_inv p := by
induction p using ind with | h p hp =>
obtain ⟨x, y⟩ := p
by_cases h₀ : y = 0 <;> simp only [mk_eq_mk_iff', h₀, Projectivization.lift_mk, if_true,
if_false, OnePoint.elim_infty, OnePoint.elim_some, Prod.smul_mk, Prod.mk.injEq, smul_eq_mul,
mul_zero, and_true]
· use x⁻¹
simp_all
· exact ⟨y⁻¹, rfl, inv_mul_cancel₀ h₀⟩
@[simp]
lemma equivProjectivization_apply_infinity :
equivProjectivization K ∞ = mk K ⟨1, 0⟩ (by simp) :=
rfl
@[simp]
lemma equivProjectivization_apply_coe (t : K) :
equivProjectivization K t = mk K ⟨t, 1⟩ (by simp) :=
rfl
@[simp]
lemma equivProjectivization_symm_apply_mk (x y : K) (h : (x, y) ≠ 0) :
(equivProjectivization K).symm (mk K ⟨x, y⟩ h) = if y = 0 then ∞ else y⁻¹ * x := by
simp [equivProjectivization]
end OnePoint
|
algnum.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly polydiv ssrnum ssrint archimedean rat.
From mathcomp Require Import finalg zmodp matrix mxalgebra mxpoly vector intdiv.
From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic.
(******************************************************************************)
(* This file provides a few basic results and constructions in algebraic *)
(* number theory, that are used in the character theory library. Most of *)
(* these could be generalized to a more abstract setting. Note that the type *)
(* of abstract number fields is simply extFieldType rat. We define here: *)
(* x \in Crat_span X <=> x is a Q-linear combination of elements of *)
(* X : seq algC. *)
(* x \in Cint_span X <=> x is a Z-linear combination of elements of *)
(* X : seq algC. *)
(* x \in Aint <=> x : algC is an algebraic integer, i.e., the (monic) *)
(* polynomial of x over Q has integer coefficients. *)
(* (e %| a)%A <=> e divides a with respect to algebraic integers, *)
(* (e %| a)%Ax i.e., a is in the algebraic integer ideal generated *)
(* by e. This is is notation for a \in dvdA e, where *)
(* dvdv is the (collective) predicate for the Aint *)
(* ideal generated by e. As in the (e %| a)%C notation *)
(* e and a can be coerced to algC from nat or int. *)
(* The (e %| a)%Ax display form is a workaround for *)
(* design limitations of the Coq Notation facilities. *)
(* (a == b %[mod e])%A, (a != b %[mod e])%A <=> *)
(* a is equal (resp. not equal) to b mod e, i.e., a and *)
(* b belong to the same e * Aint class. We do not *)
(* force a, b and e to be algebraic integers. *)
(* #[x]%C == the multiplicative order of x, i.e., the n such that *)
(* x is an nth primitive root of unity, or 0 if x is not *)
(* a root of unity. *)
(* In addition several lemmas prove the (constructive) existence of number *)
(* fields and of automorphisms of algC. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope algC_scope.
Declare Scope algC_expanded_scope.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition intr_inj_ZtoC := (intr_inj : injective ZtoC).
#[local] Hint Resolve intr_inj_ZtoC : core.
Section MoreAlgCaut.
Implicit Type rR : unitRingType.
Lemma alg_num_field (Qz : fieldExtType rat) a : a%:A = ratr a :> Qz.
Proof. by rewrite -in_algE fmorph_eq_rat. Qed.
Lemma rmorphZ_num (Qz : fieldExtType rat) rR (f : {rmorphism Qz -> rR}) a x :
f (a *: x) = ratr a * f x.
Proof. by rewrite -mulr_algl rmorphM alg_num_field fmorph_rat. Qed.
Lemma fmorph_numZ (Qz1 Qz2 : fieldExtType rat) (f : {rmorphism Qz1 -> Qz2}) :
scalable f.
Proof. by move=> a x; rewrite rmorphZ_num -alg_num_field mulr_algl. Qed.
End MoreAlgCaut.
(* Number fields and rational spans. *)
Lemma algC_PET (s : seq algC) :
{z | exists a : nat ^ size s, z = \sum_(i < size s) s`_i *+ a i
& exists ps, s = [seq (pQtoC p).[z] | p <- ps]}.
Proof.
elim: s => [|x s [z /sig_eqW[a Dz] /sig_eqW[ps Ds]]].
by exists 0; [exists [ffun _ => 2%N]; rewrite big_ord0 | exists nil].
have r_exists (y : algC): {r | r != 0 & root (pQtoC r) y}.
have [r [_ mon_r] dv_r] := minCpolyP y.
by exists r; rewrite ?monic_neq0 ?dv_r.
suffices /sig_eqW[[n [|px [|pz []]]]// [Dpx Dpz]]:
exists np, let zn := x *+ np.1 + z in
[:: x; z] = [seq (pQtoC p).[zn] | p <- np.2].
- exists (x *+ n + z).
exists [ffun i => oapp a n (unlift ord0 i)].
rewrite /= big_ord_recl ffunE unlift_none Dz; congr (_ + _).
by apply: eq_bigr => i _; rewrite ffunE liftK.
exists (px :: [seq p \Po pz | p <- ps]); rewrite /= -Dpx; congr (_ :: _).
rewrite -map_comp Ds; apply: eq_map => p /=.
by rewrite map_comp_poly horner_comp -Dpz.
have [rx nz_rx rx0] := r_exists x.
have [rz nz_rz rz0] := r_exists (- z).
have pchar0_Q: [pchar rat] =i pred0 by apply: pchar_num.
have [n [[pz Dpz] [px Dpx]]] := pchar0_PET nz_rz rz0 nz_rx rx0 pchar0_Q.
by exists (n, [:: px; - pz]); rewrite /= !raddfN hornerN -[z]opprK Dpz Dpx.
Qed.
Lemma num_field_exists (s : seq algC) :
{Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC}
& {s1 : seq Qs | map QsC s1 = s & <<1 & s1>>%VS = fullv}}}.
Proof.
have [z /sig_eqW[a Dz] /sig_eqW[ps Ds]] := algC_PET s.
suffices [Qs [QsC [z1 z1C z1gen]]]:
{Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC} &
{z1 : Qs | QsC z1 = z & forall xx, exists p, fieldExt_horner z1 p = xx}}}.
- set inQs := fieldExt_horner z1 in z1gen *; pose s1 := map inQs ps.
have inQsK p: QsC (inQs p) = (pQtoC p).[z].
rewrite /= -horner_map z1C -map_poly_comp; congr _.[z].
by apply: eq_map_poly => b /=; rewrite alg_num_field fmorph_rat.
exists Qs, QsC, s1; first by rewrite -map_comp Ds (eq_map inQsK).
have sz_ps: size ps = size s by rewrite Ds size_map.
apply/vspaceP=> x; rewrite memvf; have [p {x}<-] := z1gen x.
elim/poly_ind: p => [|p b ApQs]; first by rewrite /inQs rmorph0 mem0v.
rewrite /inQs rmorphD rmorphM /= fieldExt_hornerX fieldExt_hornerC -/inQs /=.
suffices ->: z1 = \sum_(i < size s) s1`_i *+ a i.
rewrite memvD ?memvZ ?mem1v ?memvM ?memv_suml // => i _.
by rewrite rpredMn ?seqv_sub_adjoin ?mem_nth // size_map sz_ps.
apply: (fmorph_inj QsC); rewrite z1C Dz rmorph_sum; apply: eq_bigr => i _.
by rewrite rmorphMn {1}Ds !(nth_map 0) ?sz_ps //= inQsK.
have [r [Dr /monic_neq0 nz_r] dv_r] := minCpolyP z.
have rz0: root (pQtoC r) z by rewrite dv_r.
have irr_r: irreducible_poly r.
by apply/(subfx_irreducibleP rz0 nz_r)=> q qz0 nzq; rewrite dvdp_leq // -dv_r.
exists (SubFieldExtType rz0 irr_r), (@subfx_inj _ _ QtoC z r).
exists (subfx_root _ z r) => [|x]; first exact: subfx_inj_root.
by have{x} [p ->] := subfxEroot rz0 nz_r x; exists p.
Qed.
Definition in_Crat_span s x :=
exists a : rat ^ size s, x = \sum_i QtoC (a i) * s`_i.
Fact Crat_span_subproof s x : decidable (in_Crat_span s x).
Proof.
have [Qxs [QxsC [[|x1 s1] // [<- <-] {x s} _]]] := num_field_exists (x :: s).
apply: decP (x1 \in <<in_tuple s1>>%VS) _; rewrite /in_Crat_span size_map.
apply: (iffP idP) => [/coord_span-> | [a Dx]].
move: (coord _) => a; exists [ffun i => a i x1]; rewrite rmorph_sum /=.
by apply: eq_bigr => i _; rewrite ffunE rmorphZ_num (nth_map 0).
have{Dx} ->: x1 = \sum_i a i *: s1`_i.
apply: (fmorph_inj QxsC); rewrite Dx rmorph_sum /=.
by apply: eq_bigr => i _; rewrite rmorphZ_num (nth_map 0).
by apply: memv_suml => i _; rewrite memvZ ?memv_span ?mem_nth.
Qed.
Definition Crat_span s : pred algC := Crat_span_subproof s.
Lemma Crat_spanP s x : reflect (in_Crat_span s x) (x \in Crat_span s).
Proof. exact: sumboolP. Qed.
Lemma mem_Crat_span s : {subset s <= Crat_span s}.
Proof.
move=> _ /(nthP 0)[ix ltxs <-]; pose i0 := Ordinal ltxs.
apply/Crat_spanP; exists [ffun i => (i == i0)%:R].
rewrite (bigD1_ord i0) //= ffunE eqxx // rmorph1 mul1r.
by rewrite big1 ?addr0 // => i; rewrite ffunE rmorph_nat mulr_natl lift_eqF.
Qed.
Fact Crat_span_zmod_closed s : zmod_closed (Crat_span s).
Proof.
split=> [|_ _ /Crat_spanP[x ->] /Crat_spanP[y ->]].
apply/Crat_spanP; exists 0.
by apply/esym/big1=> i _; rewrite ffunE rmorph0 mul0r.
apply/Crat_spanP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _.
by rewrite -mulrBl -rmorphB !ffunE.
Qed.
HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Crat_span s)
(Crat_span_zmod_closed s).
Section NumFieldProj.
Variables (Qn : fieldExtType rat) (QnC : {rmorphism Qn -> algC}).
Lemma Crat_spanZ b a : {in Crat_span b, forall x, ratr a * x \in Crat_span b}.
Proof.
move=> _ /Crat_spanP[a1 ->]; apply/Crat_spanP; exists [ffun i => a * a1 i].
by rewrite mulr_sumr; apply: eq_bigr => i _; rewrite ffunE mulrA -rmorphM.
Qed.
Lemma Crat_spanM b : {in Crat & Crat_span b, forall a x, a * x \in Crat_span b}.
Proof. by move=> _ x /CratP[a ->]; apply: Crat_spanZ. Qed.
(* In principle CtoQn could be taken to be additive and Q-linear, but this *)
(* would require a limit construction. *)
Lemma num_field_proj : {CtoQn | CtoQn 0 = 0 & cancel QnC CtoQn}.
Proof.
pose b := vbasis {:Qn}.
have Qn_bC (u : {x | x \in Crat_span (map QnC b)}): {y | QnC y = sval u}.
case: u => _ /= /Crat_spanP/sig_eqW[a ->].
exists (\sum_i a i *: b`_i); rewrite rmorph_sum /=; apply: eq_bigr => i _.
by rewrite rmorphZ_num (nth_map 0) // -(size_map QnC).
pose CtoQn x := oapp (fun u => sval (Qn_bC u)) 0 (insub x).
suffices QnCK: cancel QnC CtoQn by exists CtoQn; rewrite // -(rmorph0 QnC) /=.
move=> x; rewrite /CtoQn insubT => /= [|Qn_x]; last first.
by case: (Qn_bC _) => x1 /= /fmorph_inj.
rewrite (coord_vbasis (memvf x)) rmorph_sum rpred_sum //= => i _.
rewrite rmorphZ_num Crat_spanZ ?mem_Crat_span // -/b.
by rewrite -tnth_nth -tnth_map mem_tnth.
Qed.
Lemma restrict_aut_to_num_field (nu : {rmorphism algC -> algC}) :
(forall x, exists y, nu (QnC x) = QnC y) ->
{nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}.
Proof.
move=> Qn_nu; pose nu0 x := sval (sig_eqW (Qn_nu x)).
have QnC_nu0: {morph QnC : x / nu0 x >-> nu x}.
by rewrite /nu0 => x; case: (sig_eqW _).
have nu0a : zmod_morphism nu0.
by move=> x y; apply: (fmorph_inj QnC); rewrite !(QnC_nu0, rmorphB).
have nu0m : monoid_morphism nu0.
split=> [|x y]; apply: (fmorph_inj QnC); rewrite ?QnC_nu0 ?rmorph1 //.
by rewrite !rmorphM /= !QnC_nu0.
pose nu0aM := GRing.isZmodMorphism.Build Qn Qn nu0 nu0a.
pose nu0mM := GRing.isMonoidMorphism.Build Qn Qn nu0 nu0m.
pose nu0RM : {rmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM.
pose nu0lM := GRing.isScalable.Build rat Qn Qn *:%R nu0 (fmorph_numZ nu0RM).
pose nu0LRM : {lrmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM nu0lM.
by exists nu0LRM.
Qed.
Lemma map_Qnum_poly (nu : {rmorphism algC -> algC}) p :
p \in polyOver 1%VS -> map_poly (nu \o QnC) p = (map_poly QnC p).
Proof.
move=> Qp; apply/polyP=> i; rewrite /= !coef_map /=.
have /vlineP[a ->]: p`_i \in 1%VS by apply: polyOverP.
by rewrite alg_num_field !fmorph_rat.
Qed.
End NumFieldProj.
Lemma restrict_aut_to_normal_num_field (Qn : splittingFieldType rat)
(QnC : {rmorphism Qn -> algC})(nu : {rmorphism algC -> algC}) :
{nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}.
Proof.
apply: restrict_aut_to_num_field => x.
case: (splitting_field_normal 1%AS x) => rs /eqP Hrs.
have: root (map_poly (nu \o QnC) (minPoly 1%AS x)) (nu (QnC x)).
by rewrite fmorph_root root_minPoly.
rewrite map_Qnum_poly ?minPolyOver // Hrs.
rewrite [map_poly _ _](_:_ = \prod_(y <- map QnC rs) ('X - y%:P)).
by rewrite root_prod_XsubC; case/mapP => y _ ?; exists y.
by rewrite big_map rmorph_prod /=; apply: eq_bigr => i _; rewrite map_polyXsubC.
Qed.
(* Integral spans. *)
Lemma dec_Cint_span (V : vectType algC) m (s : m.-tuple V) v :
decidable (inIntSpan s v).
Proof.
have s_s (i : 'I_m): s`_i \in <<s>>%VS by rewrite memv_span ?memt_nth.
have s_Zs a: \sum_(i < m) s`_i *~ a i \in <<s>>%VS.
by rewrite memv_suml // => i _; rewrite -scaler_int memvZ.
case s_v: (v \in <<s>>%VS); last by right=> [[a Dv]]; rewrite Dv s_Zs in s_v.
pose IzT := {: 'I_m * 'I_(\dim <<s>>)}; pose Iz := 'I_#|IzT|.
pose b := vbasis <<s>>.
pose z_s := [seq coord b ij.2 (tnth s ij.1) | ij : IzT].
pose rank2 j i: Iz := enum_rank (i, j); pose val21 (p : Iz) := (enum_val p).1.
pose inQzs w := [forall j, Crat_span z_s (coord b j w)].
have enum_pairK j: {in predT, cancel (rank2 j) val21}.
by move=> i; rewrite /val21 enum_rankK.
have Qz_Zs a: inQzs (\sum_(i < m) s`_i *~ a i).
apply/forallP=> j; apply/Crat_spanP; rewrite /in_Crat_span size_map -cardE.
exists [ffun ij => (a (val21 ij))%:Q *+ ((enum_val ij).2 == j)].
rewrite linear_sum {1}(reindex_onto _ _ (enum_pairK j)) big_mkcond /=.
apply: eq_bigr => ij _ /=; rewrite nth_image (tnth_nth 0) ffunE /val21.
rewrite raddfMz rmorphMn rmorph_int mulrnAl mulrzl /=.
rewrite (can2_eq (@enum_rankK _) (@enum_valK _)).
by case: (enum_val ij) => i j1; rewrite xpair_eqE eqxx; have [->|] := eqVneq.
case Qz_v: (inQzs v); last by right=> [[a Dv]]; rewrite Dv Qz_Zs in Qz_v.
have [Qz [QzC [z1s Dz_s _]]] := num_field_exists z_s.
have sz_z1s: size z1s = #|IzT| by rewrite -(size_map QzC) Dz_s size_map cardE.
have xv j: {x | coord b j v = QzC x}.
apply: sig_eqW; have /Crat_spanP[x ->] := forallP Qz_v j.
exists (\sum_ij x ij *: z1s`_ij); rewrite rmorph_sum; apply: eq_bigr => ij _.
by rewrite rmorphZ_num -[in RHS](nth_map _ 0) ?Dz_s // -(size_map QzC) Dz_s.
pose sz := [tuple [ffun j => z1s`_(rank2 j i)] | i < m].
have [Zsv | Zs'v] := dec_Qint_span sz [ffun j => sval (xv j)].
left; have{Zsv} [a Dv] := Zsv; exists a.
transitivity (\sum_j \sum_(i < m) QzC ((sz`_i *~ a i) j) *: b`_j).
rewrite {1}(coord_vbasis s_v) -/b; apply: eq_bigr => j _.
rewrite -scaler_suml; congr (_ *: _).
have{Dv} /ffunP/(_ j) := Dv; rewrite sum_ffunE !ffunE -rmorph_sum => <-.
by case: (xv j).
rewrite exchange_big; apply: eq_bigr => i _.
rewrite (coord_vbasis (s_s i)) -/b mulrz_suml; apply: eq_bigr => j _.
rewrite scalerMzl ffunMzE rmorphMz; congr ((_ *~ _) *: _).
rewrite nth_mktuple ffunE -(nth_map _ 0) ?sz_z1s // Dz_s.
by rewrite nth_image enum_rankK /= (tnth_nth 0).
right=> [[a Dv]]; case: Zs'v; exists a.
apply/ffunP=> j; rewrite sum_ffunE !ffunE; apply: (fmorph_inj QzC).
case: (xv j) => /= _ <-; rewrite Dv linear_sum rmorph_sum /=.
apply: eq_bigr => i _; rewrite nth_mktuple raddfMz !ffunMzE rmorphMz ffunE.
by rewrite -(nth_map _ 0 QzC) ?sz_z1s // Dz_s nth_image enum_rankK -tnth_nth.
Qed.
Definition Cint_span (s : seq algC) : pred algC :=
fun x => dec_Cint_span (in_tuple [seq \row_(i < 1) y | y <- s]) (\row_i x).
Lemma Cint_spanP n (s : n.-tuple algC) x :
reflect (inIntSpan s x) (x \in Cint_span s).
Proof.
rewrite unfold_in; case: (dec_Cint_span _ _) => [Zs_x | Zs'x] /=.
left; have{Zs_x} [] := Zs_x; rewrite /= size_map size_tuple => a /rowP/(_ 0).
rewrite !mxE => ->; exists a; rewrite summxE; apply: eq_bigr => i _.
by rewrite -scaler_int (nth_map 0) ?size_tuple // !mxE mulrzl.
right=> [[a Dx]]; have{Zs'x} [] := Zs'x.
rewrite /inIntSpan /= size_map size_tuple; exists a.
apply/rowP=> i0; rewrite !mxE summxE Dx; apply: eq_bigr => i _.
by rewrite -scaler_int mxE mulrzl (nth_map 0) ?size_tuple // !mxE.
Qed.
Lemma mem_Cint_span s : {subset s <= Cint_span s}.
Proof.
move=> _ /(nthP 0)[ix ltxs <-]; apply/(Cint_spanP (in_tuple s)).
exists [ffun i => i == Ordinal ltxs : int].
rewrite (bigD1 (Ordinal ltxs)) //= ffunE eqxx.
by rewrite big1 ?addr0 // => i; rewrite ffunE => /negbTE->.
Qed.
Lemma Cint_span_zmod_closed s : zmod_closed (Cint_span s).
Proof.
have sP := Cint_spanP (in_tuple s); split=> [|_ _ /sP[x ->] /sP[y ->]].
by apply/sP; exists 0; rewrite big1 // => i; rewrite ffunE.
apply/sP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _.
by rewrite !ffunE raddfB.
Qed.
HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Cint_span s)
(Cint_span_zmod_closed s).
(* Automorphism extensions. *)
Lemma extend_algC_subfield_aut (Qs : fieldExtType rat)
(QsC : {rmorphism Qs -> algC}) (phi : {rmorphism Qs -> Qs}) :
{nu : {rmorphism algC -> algC} | {morph QsC : x / phi x >-> nu x}}.
Proof.
pose numF_inj (Qr : fieldExtType rat) := {rmorphism Qr -> algC}.
pose subAut := {Qr : _ & numF_inj Qr * {lrmorphism Qr -> Qr}}%type.
pose SubAut := existT _ _ (_, _) : subAut.
pose Sdom (mu : subAut) := projT1 mu.
pose Sinj (mu : subAut) : {rmorphism Sdom mu -> algC} := (projT2 mu).1.
pose Saut (mu : subAut) : {rmorphism Sdom mu -> Sdom mu} := (projT2 mu).2.
have Sinj_poly Qr (QrC : numF_inj Qr) p:
map_poly QrC (map_poly (in_alg Qr) p) = pQtoC p.
- rewrite -map_poly_comp; apply: eq_map_poly => a.
by rewrite /= rmorphZ_num rmorph1 mulr1.
have ext1 mu0 x : {mu1 | exists y, x = Sinj mu1 y
& exists2 in01 : {lrmorphism _ -> _}, Sinj mu0 =1 Sinj mu1 \o in01
& {morph in01: y / Saut mu0 y >-> Saut mu1 y}}.
- pose b0 := vbasis {:Sdom mu0}.
have [z _ /sig_eqW[[|px ps] // [Dx Ds]]] := algC_PET (x :: map (Sinj mu0) b0).
have [p [_ mon_p] /(_ p) pz0] := minCpolyP z; rewrite dvdpp in pz0.
have [r Dr] := closed_field_poly_normal (pQtoC p : {poly algC}).
rewrite lead_coef_map {mon_p}(monicP mon_p) rmorph1 scale1r in Dr.
have{pz0} rz: z \in r by rewrite -root_prod_XsubC -Dr.
have [Qr [QrC [rr Drr genQr]]] := num_field_exists r.
have{rz} [zz Dz]: {zz | QrC zz = z}.
by move: rz; rewrite -Drr => /mapP/sig2_eqW[zz]; exists zz.
have{ps Ds} [in01 Din01]:
{in01 : {lrmorphism _ -> _} | Sinj mu0 =1 QrC \o in01}.
have in01P y: {yy | Sinj mu0 y = QrC yy}.
exists (\sum_i coord b0 i y *: (map_poly (in_alg Qr) ps`_i).[zz]).
rewrite {1}(coord_vbasis (memvf y)) !rmorph_sum /=; apply: eq_bigr => i _.
rewrite 2!rmorphZ_num -(nth_map _ 0) ?size_tuple // Ds.
rewrite -horner_map Dz Sinj_poly (nth_map 0) //.
by have:= congr1 size Ds; rewrite !size_map size_tuple => <-.
pose in01 y := sval (in01P y).
have Din01 y: Sinj mu0 y = QrC (in01 y) by rewrite /in01; case: (in01P y).
pose rwM := (=^~ Din01, rmorphZ_num, rmorph1, rmorphB, rmorphM).
have in01a : zmod_morphism in01.
by move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM.
have in01m : monoid_morphism in01.
by split; try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM /= ?rwM.
have in01l : scalable in01.
by try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM.
pose in01aM := GRing.isZmodMorphism.Build _ _ in01 in01a.
pose in01mM := GRing.isMonoidMorphism.Build _ _ in01 in01m.
pose in01lM := GRing.isScalable.Build _ _ _ _ in01 in01l.
pose in01LRM : {lrmorphism _ -> _} := HB.pack in01
in01aM in01mM in01lM.
by exists in01LRM.
have {z zz Dz px} Dx: exists xx, x = QrC xx.
exists (map_poly (in_alg Qr) px).[zz].
by rewrite -horner_map Dz Sinj_poly Dx.
pose lin01 := linfun in01; pose K := (lin01 @: fullv)%VS.
have memK y: reflect (exists yy, y = in01 yy) (y \in K).
apply: (iffP memv_imgP) => [[yy _ ->] | [yy ->]];
by exists yy; rewrite ?lfunE ?memvf.
have algK: is_aspace K.
rewrite /is_aspace has_algid1; last first.
by apply/memK; exists 1; rewrite rmorph1.
apply/prodvP=> _ _ /memK[y1 ->] /memK[y2 ->].
by apply/memK; exists (y1 * y2); rewrite rmorphM.
have ker_in01: lker lin01 == 0%VS.
by apply/lker0P=> y1 y2; rewrite !lfunE; apply: fmorph_inj.
pose f := (lin01 \o linfun (Saut mu0) \o lin01^-1)%VF.
have Df y: f (in01 y) = in01 (Saut mu0 y).
transitivity (f (lin01 y)); first by rewrite !lfunE.
by do 4!rewrite lfunE /=; rewrite lker0_lfunK.
have hom_f: kHom 1 (ASpace algK) f.
apply/kHomP_tmp; split=> [_ /vlineP[a ->] | _ _ /memK[y1 ->] /memK[y2 ->]].
by rewrite -(rmorph_alg in01) Df /= !rmorph_alg.
by rewrite -rmorphM !Df !rmorphM.
pose pr := map_poly (in_alg Qr) p.
have Qpr: pr \is a polyOver 1%VS.
by apply/polyOverP=> i; rewrite coef_map memvZ ?memv_line.
have splitQr: splittingFieldFor K pr fullv.
apply: splittingFieldForS (sub1v (Sub K algK)) (subvf _) _; exists rr => //.
congr (_ %= _): (eqpxx pr); apply/(map_poly_inj QrC).
rewrite Sinj_poly Dr -Drr big_map rmorph_prod /=; apply: eq_bigr => zz _.
by rewrite map_polyXsubC.
have [f1 aut_f1 Df1]:= kHom_extends (sub1v (ASpace algK)) hom_f Qpr splitQr.
pose f1mM := GRing.isMonoidMorphism.Build _ _ f1 (kHom_monoid_morphism aut_f1).
pose nu : {lrmorphism _ -> _} := HB.pack (fun_of_lfun f1) f1mM.
exists (SubAut Qr QrC nu) => //; exists in01 => //= y.
by rewrite -Df -Df1 //; apply/memK; exists y.
have phiZ: scalable phi.
by move=> a y; rewrite rmorphZ_num -alg_num_field mulr_algl.
pose philM := GRing.isScalable.Build _ _ _ _ phi phiZ.
pose phiLRM : {lrmorphism _ -> _} := HB.pack (GRing.RMorphism.sort phi) philM.
pose fix ext n :=
if n is i.+1 then oapp (fun x => s2val (ext1 (ext i) x)) (ext i) (unpickle i)
else SubAut Qs QsC phiLRM.
have mem_ext x n: (pickle x < n)%N -> {xx | Sinj (ext n) xx = x}.
move=> ltxn; apply: sig_eqW; elim: n ltxn => // n IHn.
rewrite ltnS leq_eqVlt => /predU1P[<- | /IHn[xx <-]] /=.
by rewrite pickleK /=; case: (ext1 _ x) => mu [xx]; exists xx.
case: (unpickle n) => /= [y|]; last by exists xx.
case: (ext1 _ y) => mu /= _ [in_mu inj_in_mu _].
by exists (in_mu xx); rewrite inj_in_mu.
pose nu x := Sinj _ (Saut _ (sval (mem_ext x _ (ltnSn _)))).
have nu_inj n y: nu (Sinj (ext n) y) = Sinj (ext n) (Saut (ext n) y).
rewrite /nu; case: (mem_ext _ _ _); move: _.+1 => n1 y1 Dy /=.
without loss /subnK Dn1: n n1 y y1 Dy / (n <= n1)%N.
by move=> IH; case/orP: (leq_total n n1) => /IH => [/(_ y) | /(_ y1)]->.
move: (n1 - n)%N => k in Dn1; elim: k => [|k IHk] in n Dn1 y Dy *.
by move: y1 Dy; rewrite -Dn1 => y1 /fmorph_inj ->.
rewrite addSnnS in Dn1; move/IHk: Dn1 => /=.
case: (unpickle _) => [z|] /=; last exact.
case: (ext1 _ _) => mu /= _ [in_mu Dinj Daut].
by rewrite Dy => /(_ _ (Dinj _))->; rewrite -Daut Dinj.
pose le_nu (x : algC) n := (pickle x < n)%N.
have max3 x1 x2 x3: exists n, [/\ le_nu x1 n, le_nu x2 n & le_nu x3 n].
exists (maxn (pickle x1) (maxn (pickle x2) (pickle x3))).+1.
by apply/and3P; rewrite /le_nu !ltnS -!geq_max.
have nua : zmod_morphism nu.
move=> x1 x2; have [n] := max3 (x1 - x2) x1 x2.
case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2].
rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphB in Dx.
by rewrite (fmorph_inj _ Dx) !rmorphB -!nu_inj Dx1 Dx2.
have num : monoid_morphism nu.
split=> [|x1 x2]; first by rewrite -(rmorph1 QsC) (nu_inj 0) !rmorph1.
have [n] := max3 (x1 * x2) x1 x2.
case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2].
rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphM in Dx.
by rewrite (fmorph_inj _ Dx) !rmorphM /= -!nu_inj Dx1 Dx2.
pose nuaM := GRing.isZmodMorphism.Build _ _ nu nua.
pose numM := GRing.isMonoidMorphism.Build _ _ nu num.
pose nuRM : {rmorphism _ -> _} := HB.pack nu nuaM numM.
by exists nuRM => x; rewrite /= (nu_inj 0).
Qed.
(* Extended automorphisms of Q_n. *)
Lemma Qn_aut_exists k n :
coprime k n ->
{u : {rmorphism algC -> algC} | forall z, z ^+ n = 1 -> u z = z ^+ k}.
Proof.
have [-> /eqnP | n_gt0 co_k_n] := posnP n.
by rewrite gcdn0 => ->; exists idfun.
have [z prim_z] := C_prim_root_exists n_gt0.
have [Qn [QnC [[|zn []] // [Dz]]] genQn] := num_field_exists [:: z].
pose phi := kHomExtend 1 \1 zn (zn ^+ k).
have homQn1: kHom 1 1 (\1%VF : 'End(Qn)) by rewrite kHom1.
have pzn_zk0: root (map_poly \1%VF (minPoly 1 zn)) (zn ^+ k).
rewrite -(fmorph_root QnC) rmorphXn /= Dz -map_poly_comp.
rewrite (@eq_map_poly _ _ _ QnC) => [|a]; last by rewrite /= id_lfunE.
set p1 := map_poly _ _.
have [q1 Dp1]: exists q1, p1 = pQtoC q1.
have aP i: (minPoly 1 zn)`_i \in 1%VS.
by apply/polyOverP; apply: minPolyOver.
have{aP} a_ i := sig_eqW (vlineP _ _ (aP i)).
exists (\poly_(i < size (minPoly 1 zn)) sval (a_ i)).
apply/polyP=> i; rewrite coef_poly coef_map coef_poly /=.
case: ifP => _; rewrite ?rmorph0 //; case: (a_ i) => a /= ->.
by rewrite alg_num_field fmorph_rat.
have: root p1 z by rewrite -Dz fmorph_root root_minPoly.
rewrite Dp1; have [q2 [Dq2 _] ->] := minCpolyP z.
case/dvdpP=> r1 ->; rewrite rmorphM rootM /= -Dq2; apply/orP; right.
rewrite (minCpoly_cyclotomic prim_z) /cyclotomic.
rewrite (bigD1 (Ordinal (ltn_pmod k n_gt0))) ?coprime_modl //=.
by rewrite rootM root_XsubC prim_expr_mod ?eqxx.
have phim : monoid_morphism phi.
by apply/kHom_monoid_morphism; rewrite -genQn span_seq1 /= kHomExtendP.
pose phimM := GRing.isMonoidMorphism.Build _ _ phi phim.
pose phiRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun phi) phimM.
have [nu Dnu] := extend_algC_subfield_aut QnC phiRM.
exists nu => _ /(prim_rootP prim_z)[i ->].
rewrite rmorphXn /= exprAC -Dz -Dnu /= -{1}[zn]hornerX /phi.
rewrite (kHomExtend_poly homQn1) ?polyOverX //.
rewrite map_polyE map_id_in => [|?]; last by rewrite id_lfunE.
by rewrite polyseqK hornerX rmorphXn.
Qed.
(* Algebraic integers. *)
Definition Aint : {pred algC} := fun x => minCpoly x \is a polyOver Num.int.
Lemma root_monic_Aint p x :
root p x -> p \is monic -> p \is a polyOver Num.int -> x \in Aint.
Proof.
have pZtoQtoC pz: pQtoC (pZtoQ pz) = pZtoC pz.
by rewrite -map_poly_comp; apply: eq_map_poly => b; rewrite /= rmorph_int.
move=> px0 mon_p /floorpP[pz Dp]; rewrite unfold_in.
move: px0; rewrite Dp -pZtoQtoC; have [q [-> mon_q] ->] := minCpolyP x.
case/dvdpP_rat_int=> qz [a nz_a Dq] [r].
move/(congr1 (fun q1 => lead_coef (a *: pZtoQ q1))).
rewrite rmorphM scalerAl -Dq lead_coefZ lead_coefM /=.
have /monicP->: pZtoQ pz \is monic by rewrite -(map_monic QtoC) pZtoQtoC -Dp.
rewrite (monicP mon_q) mul1r mulr1 lead_coef_map_inj //; last exact: intr_inj.
rewrite Dq => ->; apply/polyOverP=> i; rewrite !(coefZ, coef_map).
by rewrite -rmorphM /= rmorph_int.
Qed.
Lemma Cint_rat_Aint z : z \in Crat -> z \in Aint -> z \in Num.int.
Proof.
case/CratP=> a ->{z} /polyOverP/(_ 0).
have [p [Dp mon_p] dv_p] := minCpolyP (ratr a); rewrite Dp coef_map.
suffices /eqP->: p == 'X - a%:P by rewrite polyseqXsubC /= rmorphN rpredN.
rewrite -eqp_monic ?monicXsubC // irredp_XsubC //.
by rewrite -(size_map_poly QtoC) -Dp neq_ltn size_minCpoly orbT.
by rewrite -dv_p fmorph_root root_XsubC.
Qed.
Lemma Aint_Cint : {subset Num.int <= Aint}.
Proof.
move=> x; rewrite -polyOverXsubC.
by apply: root_monic_Aint; rewrite ?monicXsubC ?root_XsubC.
Qed.
Lemma Aint_int x : x%:~R \in Aint. Proof. by rewrite Aint_Cint. Qed.
Lemma Aint0 : 0 \in Aint. Proof. exact: Aint_int 0. Qed.
Lemma Aint1 : 1 \in Aint. Proof. exact: Aint_int 1. Qed.
#[global] Hint Resolve Aint0 Aint1 : core.
Lemma Aint_unity_root n x : (n > 0)%N -> n.-unity_root x -> x \in Aint.
Proof.
move=> n_gt0 xn1; apply: root_monic_Aint xn1 (monicXnsubC _ n_gt0) _.
by apply/polyOverP=> i; rewrite coefB coefC -mulrb coefXn /= rpredB ?rpred_nat.
Qed.
Lemma Aint_prim_root n z : n.-primitive_root z -> z \in Aint.
Proof.
move=> pr_z; apply/(Aint_unity_root (prim_order_gt0 pr_z))/unity_rootP.
exact: prim_expr_order.
Qed.
Lemma Aint_Cnat : {subset Num.nat <= Aint}.
Proof. by move=> z /intr_nat/Aint_Cint. Qed.
(* This is Isaacs, Lemma (3.3) *)
Lemma Aint_subring_exists (X : seq algC) :
{subset X <= Aint} ->
{S : pred algC &
(*a*) subring_closed S
/\ (*b*) {subset X <= S}
& (*c*) {Y : {n : nat & n.-tuple algC} &
{subset tagged Y <= S}
& forall x, reflect (inIntSpan (tagged Y) x) (x \in S)}}.
Proof.
move=> AZ_X; pose m := (size X).+1.
pose n (i : 'I_m) := (size (minCpoly X`_i)).-2; pose N := (\max_i n i).+1.
pose IY := family (fun i => [pred e : 'I_N | e <= n i]%N).
have IY_0: 0 \in IY by apply/familyP=> // i; rewrite ffunE.
pose inIY := enum_rank_in IY_0.
pose Y := [seq \prod_(i < m) X`_i ^+ (f : 'I_N ^ m) i | f in IY].
have S_P := Cint_spanP [tuple of Y]; set S := Cint_span _ in S_P.
have sYS: {subset Y <= S} by apply: mem_Cint_span.
have S_1: 1 \in S.
by apply/sYS/imageP; exists 0 => //; rewrite big1 // => i; rewrite ffunE.
have SmulX (i : 'I_m): {in S, forall x, x * X`_i \in S}.
move=> _ /S_P[x ->]; rewrite mulr_suml rpred_sum // => j _.
rewrite mulrzAl rpredMz {x}// nth_image mulrC (bigD1 i) //= mulrA -exprS.
move: {j}(enum_val j) (familyP (enum_valP j)) => f fP.
have:= fP i; rewrite inE /= leq_eqVlt => /predU1P[-> | fi_ltn]; last first.
apply/sYS/imageP; have fiK: (inord (f i).+1 : 'I_N) = (f i).+1 :> nat.
by rewrite inordK // ltnS (bigmax_sup i).
exists (finfun [eta f with i |-> inord (f i).+1]).
apply/familyP=> i1; rewrite inE ffunE /= fun_if fiK.
by case: eqP => [-> // | _]; apply: fP.
rewrite (bigD1 i isT) ffunE /= eqxx fiK; congr (_ * _).
by apply: eq_bigr => i1 /[!ffunE]/= /negPf->.
have [/monicP ] := (minCpoly_monic X`_i, root_minCpoly X`_i).
rewrite /root horner_coef lead_coefE -(subnKC (size_minCpoly _)) subn2.
rewrite big_ord_recr /= addrC addr_eq0 => ->; rewrite mul1r => /eqP->.
have /floorpP[p Dp]: X`_i \in Aint.
by have [/(nth_default 0)-> | /(mem_nth 0)/AZ_X] := leqP (size X) i.
rewrite -/(n i) Dp mulNr rpredN // mulr_suml rpred_sum // => [[e le_e]] /= _.
rewrite coef_map -mulrA mulrzl rpredMz ?sYS //; apply/imageP.
have eK: (inord e : 'I_N) = e :> nat by rewrite inordK // ltnS (bigmax_sup i).
exists (finfun [eta f with i |-> inord e]).
apply/familyP=> i1; rewrite inE ffunE /= fun_if eK.
by case: eqP => [-> // | _]; apply: fP.
rewrite (bigD1 i isT) ffunE /= eqxx eK; congr (_ * _).
by apply: eq_bigr => i1 /[!ffunE] /= /negPf->.
exists S; last by exists (Tagged (fun n => n.-tuple _) [tuple of Y]).
split=> [|x Xx]; last first.
by rewrite -[x]mul1r -(nth_index 0 Xx) (SmulX (Ordinal _)) // ltnS index_size.
split=> // x y Sx Sy; first by rewrite rpredB.
case/S_P: Sy => {y}[y ->]; rewrite mulr_sumr rpred_sum //= => j.
rewrite mulrzAr rpredMz {y}// nth_image; move: {j}(enum_val j) => f.
elim/big_rec: _ => [|i y _ IHy] in x Sx *; first by rewrite mulr1.
rewrite mulrA {y}IHy //.
elim: {f}(f i : nat) => [|e IHe] in x Sx *; first by rewrite mulr1.
by rewrite exprS mulrA IHe // SmulX.
Qed.
Section AlgIntSubring.
(* This is Isaacs, Theorem (3.4). *)
Theorem fin_Csubring_Aint S n (Y : n.-tuple algC) :
mulr_closed S -> (forall x, reflect (inIntSpan Y x) (x \in S)) ->
{subset S <= Aint}.
Proof.
move=> mulS.
pose Sm := GRing.isMulClosed.Build _ _ mulS.
pose SC : mulrClosed _ := HB.pack S Sm.
have ZP_C c: (ZtoC c)%:P \is a polyOver Num.int_num_subdef.
by rewrite raddfMz rpred_int.
move=> S_P x Sx; pose v := \row_(i < n) Y`_i.
have [v0 | nz_v] := eqVneq v 0.
case/S_P: Sx => {}x ->; rewrite big1 ?isAlgInt0 // => i _.
by have /rowP/(_ i)/[!mxE] -> := v0; rewrite mul0rz.
have sYS (i : 'I_n): x * Y`_i \in SC.
by rewrite rpredM //; apply/S_P/Cint_spanP/mem_Cint_span/memt_nth.
pose A := \matrix_(i, j < n) sval (sig_eqW (S_P _ (sYS j))) i.
pose p := char_poly (map_mx ZtoC A).
have: p \is a polyOver Num.int_num_subdef.
rewrite rpred_sum // => s _; rewrite rpredMsign rpred_prod // => j _.
by rewrite !mxE /= rpredB ?rpredMn ?polyOverX.
apply: root_monic_Aint (char_poly_monic _).
rewrite -eigenvalue_root_char; apply/eigenvalueP; exists v => //.
apply/rowP=> j; case dAj: (sig_eqW (S_P _ (sYS j))) => [a DxY].
by rewrite !mxE DxY; apply: eq_bigr => i _; rewrite !mxE dAj /= mulrzr.
Qed.
(* This is Isaacs, Corollary (3.5). *)
Corollary Aint_subring : subring_closed Aint.
Proof.
suff rAZ: {in Aint &, forall x y, (x - y \in Aint) * (x * y \in Aint)}.
by split=> // x y AZx AZy; rewrite rAZ.
move=> x y AZx AZy.
have [|S [ringS] ] := @Aint_subring_exists [:: x; y]; first exact/allP/and3P.
move=> /allP/and3P[Sx Sy _] [Y _ genYS].
have AZ_S := fin_Csubring_Aint ringS genYS.
by have [_ S_B S_M] := ringS; rewrite !AZ_S ?S_B ?S_M.
Qed.
HB.instance Definition _ := GRing.isSubringClosed.Build _ Aint Aint_subring.
End AlgIntSubring.
Lemma Aint_aut (nu : {rmorphism algC -> algC}) x :
(nu x \in Aint) = (x \in Aint).
Proof. by rewrite !unfold_in minCpoly_aut. Qed.
Definition dvdA (e : Algebraics.divisor) : {pred algC} :=
fun z => if e == 0 then z == 0 else z / e \in Aint.
Delimit Scope algC_scope with A.
Delimit Scope algC_expanded_scope with Ax.
Notation "e %| x" := (x \in dvdA e) : algC_expanded_scope.
Notation "e %| x" := (@in_mem Algebraics.divisor x (mem (dvdA e))) : algC_scope.
Fact dvdA_zmod_closed e : zmod_closed (dvdA e).
Proof.
split=> [|x y]; first by rewrite unfold_in mul0r eqxx rpred0 ?if_same.
rewrite ![(e %| _)%A]unfold_in.
case: ifP => [_ x0 /eqP-> | _]; first by rewrite subr0.
by rewrite mulrBl; apply: rpredB.
Qed.
HB.instance Definition _ e := GRing.isZmodClosed.Build _ (dvdA e)
(dvdA_zmod_closed e).
Definition eqAmod (e x y : Algebraics.divisor) := (e %| x - y)%A.
Notation "x == y %[mod e ]" := (eqAmod e x y) : algC_scope.
Notation "x != y %[mod e ]" := (~~ (eqAmod e x y)) : algC_scope.
Lemma eqAmod_refl e x : (x == x %[mod e])%A.
Proof. by rewrite /eqAmod subrr rpred0. Qed.
#[global] Hint Resolve eqAmod_refl : core.
Lemma eqAmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%A.
Proof. by rewrite /eqAmod -opprB rpredN. Qed.
Lemma eqAmod_trans e y x z :
(x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%A.
Proof.
by move=> Exy Eyz; rewrite /eqAmod -[x](subrK y) -[_ - z]addrA rpredD.
Qed.
Lemma eqAmod_transl e x y z :
(x == y %[mod e])%A -> (x == z %[mod e])%A = (y == z %[mod e])%A.
Proof. by move/(sym_left_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed.
Lemma eqAmod_transr e x y z :
(x == y %[mod e])%A -> (z == x %[mod e])%A = (z == y %[mod e])%A.
Proof. by move/(sym_right_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed.
Lemma eqAmod0 e x : (x == 0 %[mod e])%A = (e %| x)%A.
Proof. by rewrite /eqAmod subr0. Qed.
Lemma eqAmodN e x y : (- x == y %[mod e])%A = (x == - y %[mod e])%A.
Proof. by rewrite eqAmod_sym /eqAmod !opprK addrC. Qed.
Lemma eqAmodDr e x y z : (y + x == z + x %[mod e])%A = (y == z %[mod e])%A.
Proof. by rewrite /eqAmod addrAC opprD !addrA subrK. Qed.
Lemma eqAmodDl e x y z : (x + y == x + z %[mod e])%A = (y == z %[mod e])%A.
Proof. by rewrite !(addrC x) eqAmodDr. Qed.
Lemma eqAmodD e x1 x2 y1 y2 :
(x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%A.
Proof.
by rewrite -(eqAmodDl e x2 y1) -(eqAmodDr e y1); apply: eqAmod_trans.
Qed.
Lemma eqAmodm0 e : (e == 0 %[mod e])%A.
Proof. by rewrite /eqAmod subr0 unfold_in; case: ifPn => // /divff->. Qed.
#[global] Hint Resolve eqAmodm0 : core.
Lemma eqAmodMr e :
{in Aint, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%A.
Proof.
move=> z Zz x y.
rewrite /eqAmod -mulrBl ![(e %| _)%A]unfold_in mulf_eq0 mulrAC.
by case: ifP => [_ -> // | _ Exy]; apply: rpredM.
Qed.
Lemma eqAmodMl e :
{in Aint, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%A.
Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqAmodMr. Qed.
Lemma eqAmodMl0 e : {in Aint, forall x, x * e == 0 %[mod e]}%A.
Proof. by move=> x Zx; rewrite -(mulr0 x) eqAmodMl. Qed.
Lemma eqAmodMr0 e : {in Aint, forall x, e * x == 0 %[mod e]}%A.
Proof. by move=> x Zx; rewrite /= mulrC eqAmodMl0. Qed.
Lemma eqAmod_addl_mul e : {in Aint, forall x y, x * e + y == y %[mod e]}%A.
Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqAmodDr eqAmodMl0. Qed.
Lemma eqAmodM e : {in Aint &, forall x1 y2 x2 y1,
x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%A.
Proof.
move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqAmodMl Zx1)/eqAmod_trans-> //.
exact: eqAmodMr.
Qed.
Lemma eqAmod_rat :
{in Crat & &, forall e m n, (m == n %[mod e])%A = (m == n %[mod e])%C}.
Proof.
move=> e m n Qe Qm Qn; rewrite /eqCmod unfold_in /eqAmod unfold_in.
case: ifPn => // nz_e; apply/idP/idP=> [/Cint_rat_Aint | /Aint_Cint] -> //.
by rewrite rpred_div ?rpredB.
Qed.
Lemma eqAmod0_rat : {in Crat &, forall e n, (n == 0 %[mod e])%A = (e %| n)%C}.
Proof. by move=> e n Qe Qn; rewrite /= eqAmod_rat /eqCmod ?subr0 ?Crat0. Qed.
Lemma eqAmod_nat (e m n : nat) : (m == n %[mod e])%A = (m == n %[mod e])%N.
Proof. by rewrite eqAmod_rat ?rpred_nat // eqCmod_nat. Qed.
Lemma eqAmod0_nat (e m : nat) : (m == 0 %[mod e])%A = (e %| m)%N.
Proof. by rewrite eqAmod0_rat ?rpred_nat // dvdC_nat. Qed.
(* Multiplicative order. *)
Definition orderC x :=
let p := minCpoly x in
oapp val 0 [pick n : 'I_(2 * size p ^ 2) | p == intrp 'Phi_n].
Notation "#[ x ]" := (orderC x) : C_scope.
Lemma exp_orderC x : x ^+ #[x]%C = 1.
Proof.
rewrite /orderC; case: pickP => //= [] [n _] /= /eqP Dp.
have n_gt0: (0 < n)%N.
rewrite lt0n; apply: contraTneq (size_minCpoly x) => n0.
by rewrite Dp n0 Cyclotomic0 rmorph1 size_poly1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite prim_expr_order // -(root_cyclotomic prim_z).
by rewrite -Cintr_Cyclotomic // -Dp root_minCpoly.
Qed.
Lemma dvdn_orderC x n : (#[x]%C %| n)%N = (x ^+ n == 1).
Proof.
apply/idP/eqP=> [|x_n_1]; first by apply: expr_dvd; apply: exp_orderC.
have [-> | n_gt0] := posnP n; first by rewrite dvdn0.
have [m prim_x m_dv_n] := prim_order_exists n_gt0 x_n_1.
have{n_gt0} m_gt0 := dvdn_gt0 n_gt0 m_dv_n; congr (_ %| n)%N: m_dv_n.
pose p := minCpoly x; have Dp: p = cyclotomic x m := minCpoly_cyclotomic prim_x.
rewrite /orderC; case: pickP => /= [k /eqP Dp_k | no_k]; last first.
suffices lt_m_2p: (m < 2 * size p ^ 2)%N.
have /eqP[] := no_k (Ordinal lt_m_2p).
by rewrite /= -/p Dp -Cintr_Cyclotomic.
rewrite Dp size_cyclotomic (sqrnD 1) addnAC mulnDr -add1n leq_add //.
suffices: (m <= \prod_(q <- primes m | q == 2) q * totient m ^ 2)%N.
have [m_even | m_odd] := boolP (2%N \in primes m).
by rewrite -big_filter filter_pred1_uniq ?primes_uniq // big_seq1.
by rewrite big_hasC ?has_pred1 // => /leq_trans-> //; apply: leq_addl.
rewrite big_mkcond totientE // -mulnn -!big_split /=.
rewrite {1}[m]prod_prime_decomp // prime_decompE big_map /= !big_seq.
elim/big_ind2: _ => // [n1 m1 n2 m2 | q]; first exact: leq_mul.
rewrite mem_primes => /and3P[q_pr _ q_dv_m].
rewrite lognE q_pr m_gt0 q_dv_m /=; move: (logn q _) => k.
rewrite !mulnA expnS leq_mul //.
case: (ltngtP q 2) (prime_gt1 q_pr) => // [q_gt2|->] _.
rewrite mul1n mulnAC mulnn -{1}[q]muln1 leq_mul ?expn_gt0 ?prime_gt0 //.
by rewrite -(subnKC q_gt2) (ltn_exp2l 1).
by rewrite !muln1 -expnS (ltn_exp2l 0).
have k_prim_x: k.-primitive_root x.
have k_gt0: (0 < k)%N.
rewrite lt0n; apply: contraTneq (size_minCpoly x) => k0.
by rewrite Dp_k k0 Cyclotomic0 rmorph1 size_poly1.
have [z prim_z] := C_prim_root_exists k_gt0.
rewrite -(root_cyclotomic prim_z) -Cintr_Cyclotomic //.
by rewrite -Dp_k root_minCpoly.
apply/eqP; rewrite eqn_dvd !(@prim_order_dvd _ _ x) //.
by rewrite !prim_expr_order ?eqxx.
Qed.
|
Pointed.lean
|
/-
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.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Adjunction.Basic
/-!
# The category of pointed types
This defines `Pointed`, the category of pointed types.
## TODO
* Monoidal structure
* Upgrade `typeToPointed` to an equivalence
-/
open CategoryTheory
universe u
/-- The category of pointed types. -/
structure Pointed : Type (u + 1) where
/-- the underlying type -/
protected X : Type u
/-- the distinguished element -/
point : X
namespace Pointed
instance : CoeSort Pointed Type* :=
⟨Pointed.X⟩
/-- Turns a point into a pointed type. -/
abbrev of {X : Type*} (point : X) : Pointed :=
⟨X, point⟩
theorem coe_of {X : Type*} (point : X) : ↥(of point) = X :=
rfl
alias _root_.Prod.Pointed := of
instance : Inhabited Pointed :=
⟨of ((), ())⟩
/-- Morphisms in `Pointed`. -/
@[ext]
protected structure Hom (X Y : Pointed.{u}) : Type u where
/-- the underlying map -/
toFun : X → Y
/-- compatibility with the distinguished points -/
map_point : toFun X.point = Y.point
namespace Hom
/-- The identity morphism of `X : Pointed`. -/
@[simps]
def id (X : Pointed) : Pointed.Hom X X :=
⟨_root_.id, rfl⟩
instance (X : Pointed) : Inhabited (Pointed.Hom X X) :=
⟨id X⟩
/-- Composition of morphisms of `Pointed`. -/
@[simps]
def comp {X Y Z : Pointed.{u}} (f : Pointed.Hom X Y) (g : Pointed.Hom Y Z) : Pointed.Hom X Z :=
⟨g.toFun ∘ f.toFun, by rw [Function.comp_apply, f.map_point, g.map_point]⟩
end Hom
instance largeCategory : LargeCategory Pointed where
Hom := Pointed.Hom
id := Hom.id
comp := @Hom.comp
@[simp] lemma Hom.id_toFun' (X : Pointed.{u}) : (𝟙 X : X ⟶ X).toFun = _root_.id := rfl
@[simp] lemma Hom.comp_toFun' {X Y Z : Pointed.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).toFun = g.toFun ∘ f.toFun := rfl
instance (X Y : Pointed) : FunLike { f : X → Y // f X.point = Y.point } X Y where
coe f := f
coe_injective' _ _ := Subtype.ext
instance hasForget : ConcreteCategory Pointed fun X Y => { f : X → Y // f X.point = Y.point } where
hom f := ⟨f.1, f.2⟩
ofHom f := ⟨f.1, f.2⟩
/-- Constructs an isomorphism between pointed types from an equivalence that preserves the point
between them. -/
@[simps]
def Iso.mk {α β : Pointed} (e : α ≃ β) (he : e α.point = β.point) : α ≅ β where
hom := ⟨e, he⟩
inv := ⟨e.symm, e.symm_apply_eq.2 he.symm⟩
hom_inv_id := Pointed.Hom.ext e.symm_comp_self
inv_hom_id := Pointed.Hom.ext e.self_comp_symm
end Pointed
/-- `Option` as a functor from types to pointed types. This is the free functor. -/
@[simps]
def typeToPointed : Type u ⥤ Pointed.{u} where
obj X := ⟨Option X, none⟩
map f := ⟨Option.map f, rfl⟩
map_id _ := Pointed.Hom.ext Option.map_id
map_comp _ _ := Pointed.Hom.ext (Option.map_comp_map _ _).symm
/-- `typeToPointed` is the free functor. -/
def typeToPointedForgetAdjunction : typeToPointed ⊣ forget Pointed :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y =>
{ toFun := fun f => f.toFun ∘ Option.some
invFun := fun f => ⟨fun o => o.elim Y.point f, rfl⟩
left_inv := fun f => by
apply Pointed.Hom.ext
funext x
cases x
· exact f.map_point.symm
· rfl }
homEquiv_naturality_left_symm := fun f g => by
apply Pointed.Hom.ext
funext x
cases x <;> rfl }
|
ContinuousMapZero.lean
|
/-
Copyright (c) 2024 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Topology.ContinuousMap.Algebra
import Mathlib.Topology.ContinuousMap.Compact
/-!
# Continuous maps sending zero to zero
This is the type of continuous maps from `X` to `R` such that `(0 : X) ↦ (0 : R)` for which we
provide the scoped notation `C(X, R)₀`. We provide this as a dedicated type solely for the
non-unital continuous functional calculus, as using various terms of type `Ideal C(X, R)` were
overly burdensome on type class synthesis.
Of course, one could generalize to maps between pointed topological spaces, but that goes beyond
the purpose of this type.
-/
assert_not_exists StarOrderedRing
open Function Set Topology
/-- The type of continuous maps which map zero to zero.
Note that one should never use the structure projection `ContinuousMapZero.toContinuousMap` and
instead favor the coercion `(↑) : C(X, R)₀ → C(X, R)` available from the instance of
`ContinuousMapClass`. All the instances on `C(X, R)₀` from `C(X, R)` passes through this coercion,
not the structure projection. Of course, the two are definitionally equal, but not reducibly so. -/
structure ContinuousMapZero (X R : Type*) [Zero X] [Zero R] [TopologicalSpace X]
[TopologicalSpace R] extends C(X, R) where
map_zero' : toContinuousMap 0 = 0
namespace ContinuousMapZero
@[inherit_doc]
scoped notation "C(" X ", " R ")₀" => ContinuousMapZero X R
section Basic
variable {X Y R : Type*} [Zero X] [Zero Y] [Zero R]
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace R]
instance instFunLike : FunLike C(X, R)₀ X R where
coe f := f.toFun
coe_injective' _ _ h := congr(⟨⟨$(h), _⟩, _⟩)
instance instContinuousMapClass : ContinuousMapClass C(X, R)₀ X R where
map_continuous f := f.continuous
instance instZeroHomClass : ZeroHomClass C(X, R)₀ X R where
map_zero f := f.map_zero'
/-- not marked as an instance because it would be a bad one in general, but it can
be useful when working with `ContinuousMapZero` and the non-unital continuous
functional calculus. -/
def _root_.Set.zeroOfFactMem {X : Type*} [Zero X] (s : Set X) [Fact (0 ∈ s)] :
Zero s where
zero := ⟨0, Fact.out⟩
scoped[ContinuousMapZero] attribute [instance] Set.zeroOfFactMem
@[ext]
lemma ext {f g : C(X, R)₀} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h
@[simp]
lemma coe_mk {f : C(X, R)} {h0 : f 0 = 0} : ⇑(mk f h0) = f := rfl
lemma toContinuousMap_injective : Injective ((↑) : C(X, R)₀ → C(X, R)) :=
fun _ _ h ↦ congr(.mk $(h) _)
lemma range_toContinuousMap : range ((↑) : C(X, R)₀ → C(X, R)) = {f : C(X, R) | f 0 = 0} :=
Set.ext fun f ↦ ⟨fun ⟨f', hf'⟩ ↦ hf' ▸ map_zero f', fun hf ↦ ⟨⟨f, hf⟩, rfl⟩⟩
/-- Composition of continuous maps which map zero to zero. -/
def comp (g : C(Y, R)₀) (f : C(X, Y)₀) : C(X, R)₀ where
toContinuousMap := (g : C(Y, R)).comp (f : C(X, Y))
map_zero' := show g (f 0) = 0 from map_zero f ▸ map_zero g
@[simp]
lemma comp_apply (g : C(Y, R)₀) (f : C(X, Y)₀) (x : X) : g.comp f x = g (f x) := rfl
instance instPartialOrder [PartialOrder R] : PartialOrder C(X, R)₀ :=
.lift _ DFunLike.coe_injective'
lemma le_def [PartialOrder R] (f g : C(X, R)₀) : f ≤ g ↔ ∀ x, f x ≤ g x := Iff.rfl
protected instance instTopologicalSpace : TopologicalSpace C(X, R)₀ :=
TopologicalSpace.induced ((↑) : C(X, R)₀ → C(X, R)) inferInstance
lemma isEmbedding_toContinuousMap : IsEmbedding ((↑) : C(X, R)₀ → C(X, R)) where
eq_induced := rfl
injective _ _ h := ext fun x ↦ congr($(h) x)
instance [T0Space R] : T0Space C(X, R)₀ := isEmbedding_toContinuousMap.t0Space
instance [R0Space R] : R0Space C(X, R)₀ := isEmbedding_toContinuousMap.r0Space
instance [T1Space R] : T1Space C(X, R)₀ := isEmbedding_toContinuousMap.t1Space
instance [R1Space R] : R1Space C(X, R)₀ := isEmbedding_toContinuousMap.r1Space
instance [T2Space R] : T2Space C(X, R)₀ := isEmbedding_toContinuousMap.t2Space
instance [RegularSpace R] : RegularSpace C(X, R)₀ := isEmbedding_toContinuousMap.regularSpace
instance [T3Space R] : T3Space C(X, R)₀ := isEmbedding_toContinuousMap.t3Space
instance instContinuousEvalConst : ContinuousEvalConst C(X, R)₀ X R :=
.of_continuous_forget isEmbedding_toContinuousMap.continuous
instance instContinuousEval [LocallyCompactPair X R] : ContinuousEval C(X, R)₀ X R :=
.of_continuous_forget isEmbedding_toContinuousMap.continuous
lemma isClosedEmbedding_toContinuousMap [T1Space R] :
IsClosedEmbedding ((↑) : C(X, R)₀ → C(X, R)) where
toIsEmbedding := isEmbedding_toContinuousMap
isClosed_range := by
rw [range_toContinuousMap]
exact isClosed_singleton.preimage <| continuous_eval_const 0
@[fun_prop]
lemma continuous_comp_left {X Y Z : Type*} [TopologicalSpace X]
[TopologicalSpace Y] [TopologicalSpace Z] [Zero X] [Zero Y] [Zero Z] (f : C(X, Y)₀) :
Continuous fun g : C(Y, Z)₀ ↦ g.comp f := by
rw [continuous_induced_rng]
change Continuous fun g : C(Y, Z)₀ ↦ (g : C(Y, Z)).comp (f : C(X, Y))
fun_prop
/-- The identity function as an element of `C(s, R)₀` when `0 ∈ (s : Set R)`. -/
@[simps!]
protected def id {s : Set R} [Zero s] (h0 : ((0 : s) : R) = 0) : C(s, R)₀ :=
⟨.restrict s (.id R), h0⟩
@[simp]
lemma toContinuousMap_id {s : Set R} [Zero s] (h0 : ((0 : s) : R) = 0) :
(ContinuousMapZero.id h0 : C(s, R)) = .restrict s (.id R) :=
rfl
end Basic
section mkD
variable {X R : Type*} [Zero R]
variable [TopologicalSpace X] [TopologicalSpace R]
open scoped Classical in
/--
Interpret `f : α → β` as an element of `C(α, β)₀`, falling back to the default value
`default : C(α, β)₀` if `f` is not continuous or does not map `0` to `0`.
This is mainly intended to be used for `C(α, β)₀`-valued integration. For example, if a family of
functions `f : ι → α → β` satisfies that `f i` is continuous and maps `0` to `0` for almost every
`i`, you can write the `C(α, β)₀`-valued integral "`∫ i, f i`" as
`∫ i, ContinuousMapZero.mkD (f i) 0`.
-/
noncomputable def mkD [Zero X] (f : X → R) (default : C(X, R)₀) : C(X, R)₀ :=
if h : Continuous f ∧ f 0 = 0 then ⟨⟨_, h.1⟩, h.2⟩ else default
lemma mkD_of_continuous [Zero X] {f : X → R} {g : C(X, R)₀} (hf : Continuous f) (hf₀ : f 0 = 0) :
mkD f g = ⟨⟨f, hf⟩, hf₀⟩ := by
simp only [mkD, And.intro hf hf₀, true_and, ↓reduceDIte]
lemma mkD_of_not_continuous [Zero X] {f : X → R} {g : C(X, R)₀} (hf : ¬ Continuous f) :
mkD f g = g := by
simp only [mkD, not_and_of_not_left _ hf, ↓reduceDIte]
lemma mkD_of_not_zero [Zero X] {f : X → R} {g : C(X, R)₀} (hf : f 0 ≠ 0) :
mkD f g = g := by
simp only [mkD, not_and_of_not_right _ hf, ↓reduceDIte]
lemma mkD_apply_of_continuous [Zero X] {f : X → R} {g : C(X, R)₀} {x : X}
(hf : Continuous f) (hf₀ : f 0 = 0) :
mkD f g x = f x := by
rw [mkD_of_continuous hf hf₀, coe_mk, ContinuousMap.coe_mk]
lemma mkD_of_continuousOn {s : Set X} [Zero s] {f : X → R} {g : C(s, R)₀}
(hf : ContinuousOn f s) (hf₀ : f (0 : s) = 0) :
mkD (s.restrict f) g = ⟨⟨s.restrict f, hf.restrict⟩, hf₀⟩ :=
mkD_of_continuous hf.restrict hf₀
lemma mkD_of_not_continuousOn {s : Set X} [Zero s] {f : X → R} {g : C(s, R)₀}
(hf : ¬ ContinuousOn f s) :
mkD (s.restrict f) g = g := by
rw [continuousOn_iff_continuous_restrict] at hf
exact mkD_of_not_continuous hf
lemma mkD_apply_of_continuousOn {s : Set X} [Zero s] {f : X → R} {g : C(s, R)₀} {x : s}
(hf : ContinuousOn f s) (hf₀ : f (0 : s) = 0) :
mkD (s.restrict f) g x = f x := by
rw [mkD_of_continuousOn hf hf₀, coe_mk, ContinuousMap.coe_mk, restrict_apply]
open ContinuousMap in
/-- Link between `ContinuousMapZero.mkD` and `ContinuousMap.mkD`. -/
lemma mkD_eq_mkD_of_map_zero [Zero X] (f : X → R) (g : C(X, R)₀) (f_zero : f 0 = 0) :
mkD f g = ContinuousMap.mkD f g := by
ext
by_cases f_cont : Continuous f <;>
simp [*, ContinuousMap.mkD_of_continuous, mkD_of_continuous, mkD_of_not_continuous,
ContinuousMap.mkD_of_not_continuous]
lemma mkD_eq_self [Zero X] {f g : C(X, R)₀} : mkD f g = f :=
mkD_of_continuous f.continuous (map_zero f)
end mkD
section Algebra
variable {X R : Type*} [Zero X] [TopologicalSpace X]
variable [TopologicalSpace R]
instance instZero [Zero R] : Zero C(X, R)₀ where
zero := ⟨0, rfl⟩
@[simp] lemma coe_zero [Zero R] : ⇑(0 : C(X, R)₀) = 0 := rfl
instance instAdd [AddZeroClass R] [ContinuousAdd R] : Add C(X, R)₀ where
add f g := ⟨f + g, by simp⟩
@[simp] lemma coe_add [AddZeroClass R] [ContinuousAdd R] (f g : C(X, R)₀) : ⇑(f + g) = f + g := rfl
instance instNeg [NegZeroClass R] [ContinuousNeg R] : Neg C(X, R)₀ where
neg f := ⟨- f, by simp⟩
@[simp] lemma coe_neg [NegZeroClass R] [ContinuousNeg R] (f : C(X, R)₀) : ⇑(-f) = -f := rfl
instance instSub [SubNegZeroMonoid R] [ContinuousSub R] : Sub C(X, R)₀ where
sub f g := ⟨f - g, by simp⟩
@[simp] lemma coe_sub [SubNegZeroMonoid R] [ContinuousSub R] (f g : C(X, R)₀) :
⇑(f - g) = f - g := rfl
instance instMul [MulZeroClass R] [ContinuousMul R] : Mul C(X, R)₀ where
mul f g := ⟨f * g, by simp⟩
@[simp] lemma coe_mul [MulZeroClass R] [ContinuousMul R] (f g : C(X, R)₀) : ⇑(f * g) = f * g := rfl
instance instSMul {M : Type*} [Zero R] [SMulZeroClass M R] [ContinuousConstSMul M R] :
SMul M C(X, R)₀ where
smul m f := ⟨m • f, by simp⟩
@[simp] lemma coe_smul {M : Type*} [Zero R] [SMulZeroClass M R] [ContinuousConstSMul M R]
(m : M) (f : C(X, R)₀) : ⇑(m • f) = m • f := rfl
section AddCommMonoid
variable [AddCommMonoid R] [ContinuousAdd R]
instance instAddCommMonoid : AddCommMonoid C(X, R)₀ :=
fast_instance% toContinuousMap_injective.addCommMonoid _ rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance instModule {M : Type*} [Semiring M] [Module M R] [ContinuousConstSMul M R] :
Module M C(X, R)₀ :=
fast_instance% toContinuousMap_injective.module M
{ toFun := _, map_add' := fun _ _ ↦ rfl, map_zero' := rfl } (fun _ _ ↦ rfl)
instance instSMulCommClass {M N : Type*} [SMulZeroClass M R] [ContinuousConstSMul M R]
[SMulZeroClass N R] [ContinuousConstSMul N R] [SMulCommClass M N R] :
SMulCommClass M N C(X, R)₀ where
smul_comm _ _ _ := ext fun _ ↦ smul_comm ..
instance instIsScalarTower {M N : Type*} [SMulZeroClass M R] [ContinuousConstSMul M R]
[SMulZeroClass N R] [ContinuousConstSMul N R] [SMul M N] [IsScalarTower M N R] :
IsScalarTower M N C(X, R)₀ where
smul_assoc _ _ _ := ext fun _ ↦ smul_assoc ..
end AddCommMonoid
section AddCommGroup
variable [AddCommGroup R] [IsTopologicalAddGroup R]
instance instAddCommGroup : AddCommGroup C(X, R)₀ :=
fast_instance% toContinuousMap_injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
end AddCommGroup
section Semiring
variable [CommSemiring R] [IsTopologicalSemiring R]
instance instNonUnitalCommSemiring : NonUnitalCommSemiring C(X, R)₀ :=
fast_instance% toContinuousMap_injective.nonUnitalCommSemiring
_ rfl (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance instSMulCommClass' {M : Type*} [SMulZeroClass M R] [SMulCommClass M R R]
[ContinuousConstSMul M R] : SMulCommClass M C(X, R)₀ C(X, R)₀ where
smul_comm m f g := ext fun x ↦ smul_comm m (f x) (g x)
instance instIsScalarTower' {M : Type*} [SMulZeroClass M R] [IsScalarTower M R R]
[ContinuousConstSMul M R] : IsScalarTower M C(X, R)₀ C(X, R)₀ where
smul_assoc m f g := ext fun x ↦ smul_assoc m (f x) (g x)
instance instStarRing [StarRing R] [ContinuousStar R] : StarRing C(X, R)₀ where
star f := ⟨star f, by simp⟩
star_involutive _ := ext fun _ ↦ star_star _
star_mul _ _ := ext fun _ ↦ star_mul ..
star_add _ _ := ext fun _ ↦ star_add ..
instance instStarModule [StarRing R] {M : Type*} [SMulZeroClass M R] [ContinuousConstSMul M R]
[Star M] [StarModule M R] [ContinuousStar R] : StarModule M C(X, R)₀ where
star_smul r f := ext fun x ↦ star_smul r (f x)
@[simp] lemma coe_star [StarRing R] [ContinuousStar R] (f : C(X, R)₀) : ⇑(star f) = star ⇑f := rfl
instance [StarRing R] [ContinuousStar R] [TrivialStar R] : TrivialStar C(X, R)₀ where
star_trivial _ := DFunLike.ext _ _ fun _ ↦ star_trivial _
instance instCanLift : CanLift C(X, R) C(X, R)₀ (↑) (fun f ↦ f 0 = 0) where
prf f hf := ⟨⟨f, hf⟩, rfl⟩
/-- The coercion `C(X, R)₀ → C(X, R)` bundled as a non-unital star algebra homomorphism. -/
@[simps]
def toContinuousMapHom [StarRing R] [ContinuousStar R] : C(X, R)₀ →⋆ₙₐ[R] C(X, R) where
toFun f := f
map_smul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl
map_mul' _ _ := rfl
map_star' _ := rfl
lemma coe_toContinuousMapHom [StarRing R] [ContinuousStar R] :
⇑(toContinuousMapHom (X := X) (R := R)) = (↑) :=
rfl
/-- The coercion `C(X, R)₀ → C(X, R)` bundled as a continuous linear map. -/
@[simps]
def toContinuousMapCLM (M : Type*) [Semiring M] [Module M R] [ContinuousConstSMul M R] :
C(X, R)₀ →L[M] C(X, R) where
toFun f := f
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- The evaluation at a point, as a continuous linear map from `C(X, R)₀` to `R`. -/
def evalCLM (𝕜 : Type*) [Semiring 𝕜] [Module 𝕜 R] [ContinuousConstSMul 𝕜 R] (x : X) :
C(X, R)₀ →L[𝕜] R :=
(ContinuousMap.evalCLM 𝕜 x).comp (toContinuousMapCLM 𝕜)
@[simp]
lemma evalCLM_apply {𝕜 : Type*} [Semiring 𝕜] [Module 𝕜 R] [ContinuousConstSMul 𝕜 R]
(x : X) (f : C(X, R)₀) : evalCLM 𝕜 x f = f x := rfl
/-- Coercion to a function as an `AddMonoidHom`. Similar to `ContinuousMap.coeFnAddMonoidHom`. -/
def coeFnAddMonoidHom : C(X, R)₀ →+ X → R where
toFun f := f
map_zero' := coe_zero
map_add' f g := by simp
@[simp]
lemma coeFnAddMonoidHom_apply (f : C(X, R)₀) : coeFnAddMonoidHom f = f := rfl
@[simp] lemma coe_sum {ι : Type*} (s : Finset ι)
(f : ι → C(X, R)₀) : ⇑(s.sum f) = s.sum (fun i => ⇑(f i)) :=
map_sum coeFnAddMonoidHom f s
end Semiring
section Ring
variable {X R : Type*} [Zero X] [TopologicalSpace X]
variable [CommRing R] [TopologicalSpace R] [IsTopologicalRing R]
instance instNonUnitalCommRing : NonUnitalCommRing C(X, R)₀ :=
fast_instance% toContinuousMap_injective.nonUnitalCommRing _ rfl
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
instance : ContinuousNeg C(X, R)₀ where
continuous_neg := by
rw [continuous_induced_rng]
exact continuous_neg.comp continuous_induced_dom
end Ring
end Algebra
section UniformSpace
variable {X R : Type*} [Zero X] [TopologicalSpace X]
variable [Zero R] [UniformSpace R]
protected instance instUniformSpace : UniformSpace C(X, R)₀ := .comap toContinuousMap inferInstance
lemma isUniformEmbedding_toContinuousMap :
IsUniformEmbedding ((↑) : C(X, R)₀ → C(X, R)) where
comap_uniformity := rfl
injective _ _ h := ext fun x ↦ congr($(h) x)
instance [T1Space R] [CompleteSpace C(X, R)] : CompleteSpace C(X, R)₀ :=
completeSpace_iff_isComplete_range isUniformEmbedding_toContinuousMap.isUniformInducing
|>.mpr isClosedEmbedding_toContinuousMap.isClosed_range.isComplete
lemma isUniformEmbedding_comp {Y : Type*} [UniformSpace Y] [Zero Y] (g : C(Y, R)₀)
(hg : IsUniformEmbedding g) : IsUniformEmbedding (g.comp · : C(X, Y)₀ → C(X, R)₀) :=
isUniformEmbedding_toContinuousMap.of_comp_iff.mp <|
ContinuousMap.isUniformEmbedding_comp g.toContinuousMap hg |>.comp
isUniformEmbedding_toContinuousMap
/-- The uniform equivalence `C(X, R)₀ ≃ᵤ C(Y, R)₀` induced by a homeomorphism of the domains
sending `0 : X` to `0 : Y`. -/
def _root_.UniformEquiv.arrowCongrLeft₀ {Y : Type*} [TopologicalSpace Y] [Zero Y] (f : X ≃ₜ Y)
(hf : f 0 = 0) : C(X, R)₀ ≃ᵤ C(Y, R)₀ where
toFun g := g.comp ⟨f.symm, (f.toEquiv.apply_eq_iff_eq_symm_apply.eq ▸ hf).symm⟩
invFun g := g.comp ⟨f, hf⟩
left_inv g := ext fun _ ↦ congrArg g <| f.left_inv _
right_inv g := ext fun _ ↦ congrArg g <| f.right_inv _
uniformContinuous_toFun := isUniformEmbedding_toContinuousMap.uniformContinuous_iff.mpr <|
ContinuousMap.uniformContinuous_comp_left (f.symm : C(Y, X)) |>.comp
isUniformEmbedding_toContinuousMap.uniformContinuous
uniformContinuous_invFun := isUniformEmbedding_toContinuousMap.uniformContinuous_iff.mpr <|
ContinuousMap.uniformContinuous_comp_left (f : C(X, Y)) |>.comp
isUniformEmbedding_toContinuousMap.uniformContinuous
end UniformSpace
section CompHoms
variable {X Y M R S : Type*} [Zero X] [Zero Y] [CommSemiring M]
[TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace R] [TopologicalSpace S]
[CommSemiring R] [StarRing R] [IsTopologicalSemiring R] [ContinuousStar R]
[CommSemiring S] [StarRing S] [IsTopologicalSemiring S] [ContinuousStar S]
[Module M R] [Module M S] [ContinuousConstSMul M R] [ContinuousConstSMul M S]
variable (R) in
/-- The functor `C(·, R)₀` from topological spaces with zero (and `ContinuousMapZero` maps) to
non-unital star algebras. -/
@[simps]
def nonUnitalStarAlgHom_precomp (f : C(X, Y)₀) : C(Y, R)₀ →⋆ₙₐ[R] C(X, R)₀ where
toFun g := g.comp f
map_zero' := rfl
map_add' _ _ := rfl
map_mul' _ _ := rfl
map_star' _ := rfl
map_smul' _ _ := rfl
variable (X) in
/-- The functor `C(X, ·)₀` from non-unital topological star algebras (with non-unital continuous
star homomorphisms) to non-unital star algebras. -/
@[simps apply]
def nonUnitalStarAlgHom_postcomp (φ : R →⋆ₙₐ[M] S) (hφ : Continuous φ) :
C(X, R)₀ →⋆ₙₐ[M] C(X, S)₀ where
toFun := .comp ⟨⟨φ, hφ⟩, by simp⟩
map_zero' := ext <| by simp
map_add' _ _ := ext <| by simp
map_mul' _ _ := ext <| by simp
map_star' _ := ext <| by simp [map_star]
map_smul' r f := ext <| by simp
end CompHoms
section Norm
variable {α : Type*} {𝕜 : Type*} {R : Type*} [TopologicalSpace α] [CompactSpace α] [Zero α]
noncomputable instance [MetricSpace R] [Zero R] : MetricSpace C(α, R)₀ :=
ContinuousMapZero.isUniformEmbedding_toContinuousMap.comapMetricSpace _
lemma isometry_toContinuousMap [MetricSpace R] [Zero R] :
Isometry (toContinuousMap : C(α, R)₀ → C(α, R)) :=
fun _ _ ↦ rfl
noncomputable instance [NormedAddCommGroup R] : Norm C(α, R)₀ where
norm f := ‖(f : C(α, R))‖
lemma norm_def [NormedAddCommGroup R] (f : C(α, R)₀) : ‖f‖ = ‖(f : C(α, R))‖ :=
rfl
noncomputable instance [NormedAddCommGroup R] : NormedAddCommGroup C(α, R)₀ where
dist_eq f g := NormedAddGroup.dist_eq (f : C(α, R)) g
noncomputable instance [NormedCommRing R] : NonUnitalNormedCommRing C(α, R)₀ where
dist_eq f g := NormedAddGroup.dist_eq (f : C(α, R)) g
norm_mul_le f g := norm_mul_le (f : C(α, R)) g
mul_comm f g := mul_comm f g
noncomputable instance [NormedField 𝕜] [NormedCommRing R] [NormedAlgebra 𝕜 R] :
NormedSpace 𝕜 C(α, R)₀ where
norm_smul_le r f := norm_smul_le r (f : C(α, R))
instance [NormedCommRing R] [StarRing R] [CStarRing R] : CStarRing C(α, R)₀ where
norm_mul_self_le f := CStarRing.norm_mul_self_le (f : C(α, R))
end Norm
end ContinuousMapZero
|
LinOrd.lean
|
/-
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.Order.Category.Lat
/-!
# Category of linear orders
This defines `LinOrd`, the category of linear orders with monotone maps.
-/
open CategoryTheory
universe u
/-- The category of linear orders. -/
structure LinOrd where
/-- The underlying linearly ordered type. -/
(carrier : Type*)
[str : LinearOrder carrier]
attribute [instance] LinOrd.str
initialize_simps_projections LinOrd (carrier → coe, -str)
namespace LinOrd
instance : CoeSort LinOrd (Type _) :=
⟨LinOrd.carrier⟩
attribute [coe] LinOrd.carrier
/-- Construct a bundled `LinOrd` from the underlying type and typeclass. -/
abbrev of (X : Type*) [LinearOrder X] : LinOrd := ⟨X⟩
/-- The type of morphisms in `LinOrd R`. -/
@[ext]
structure Hom (X Y : LinOrd.{u}) where
private mk ::
/-- The underlying `OrderHom`. -/
hom' : X →o Y
instance : Category LinOrd.{u} where
Hom X Y := Hom X Y
id _ := ⟨OrderHom.id⟩
comp f g := ⟨g.hom'.comp f.hom'⟩
instance : ConcreteCategory LinOrd (· →o ·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `LinOrd` back into a `OrderHom`. -/
abbrev Hom.hom {X Y : LinOrd.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := LinOrd) f
/-- Typecheck a `OrderHom` as a morphism in `LinOrd`. -/
abbrev ofHom {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) : of X ⟶ of Y :=
ConcreteCategory.ofHom (C := LinOrd) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : LinOrd.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' → hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma coe_id {X : LinOrd} : (𝟙 X : X → X) = id := rfl
@[simp]
lemma coe_comp {X Y Z : LinOrd} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl
@[simp]
lemma forget_map {X Y : LinOrd} (f : X ⟶ Y) :
(forget LinOrd).map f = f := rfl
@[ext]
lemma ext {X Y : LinOrd} {f g : X ⟶ Y} (w : ∀ x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (X : Type u) [LinearOrder X] : (LinOrd.of X : Type u) = X := rfl
@[simp]
lemma hom_id {X : LinOrd} : (𝟙 X : X ⟶ X).hom = OrderHom.id := rfl
/- Provided for rewriting. -/
lemma id_apply (X : LinOrd) (x : X) :
(𝟙 X : X ⟶ X) x = x := by simp
@[simp]
lemma hom_comp {X Y Z : LinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {X Y Z : LinOrd} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
(f ≫ g) x = g (f x) := by simp
@[ext]
lemma hom_ext {X Y : LinOrd} {f g : X ⟶ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) : (ofHom f).hom = f :=
rfl
@[simp]
lemma ofHom_hom {X Y : LinOrd} (f : X ⟶ Y) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {X : Type u} [LinearOrder X] : ofHom OrderHom.id = 𝟙 (of X) := rfl
@[simp]
lemma ofHom_comp {X Y Z : Type u} [LinearOrder X] [LinearOrder Y] [LinearOrder Z]
(f : X →o Y) (g : Y →o Z) :
ofHom (g.comp f) = ofHom f ≫ ofHom g :=
rfl
lemma ofHom_apply {X Y : Type u} [LinearOrder X] [LinearOrder Y] (f : X →o Y) (x : X) :
(ofHom f) x = f x := rfl
lemma inv_hom_apply {X Y : LinOrd} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by
simp
lemma hom_inv_apply {X Y : LinOrd} (e : X ≅ Y) (s : Y) : e.hom (e.inv s) = s := by
simp
instance : Inhabited LinOrd :=
⟨of PUnit⟩
instance hasForgetToLat : HasForget₂ LinOrd Lat where
forget₂.obj X := .of X
forget₂.map f := Lat.ofHom (OrderHomClass.toLatticeHom _ _ f.hom)
/-- Constructs an equivalence between linear orders from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : LinOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := ofHom e
inv := ofHom e.symm
/-- `OrderDual` as a functor. -/
@[simps map]
def dual : LinOrd ⥤ LinOrd where
obj X := of Xᵒᵈ
map f := ofHom f.hom.dual
/-- The equivalence between `LinOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : LinOrd ≌ LinOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end LinOrd
theorem linOrd_dual_comp_forget_to_Lat :
LinOrd.dual ⋙ forget₂ LinOrd Lat = forget₂ LinOrd Lat ⋙ Lat.dual :=
rfl
|
Finite.lean
|
/-
Copyright (c) 2025 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.Set.Finite.Basic
import Mathlib.Order.Minimal
/-!
# Finite preorders and finite sets in a preorder
This file shows that non-empty finite sets in a preorder have minimal/maximal elements, and
contrapositively that non-empty sets without minimal or maximal elements are infinite.
-/
variable {ι α β : Type*}
namespace Finset
variable [Preorder α] {s : Finset α} {a : α}
lemma exists_maximalFor (f : ι → α) (s : Finset ι) (hs : s.Nonempty) :
∃ i, MaximalFor (· ∈ s) f i := by
induction hs using Finset.Nonempty.cons_induction with
| singleton i => exact ⟨i, by simp⟩
| @cons i s hi hs ih =>
obtain ⟨j, hj⟩ := ih
by_cases hji : f j ≤ f i
· refine ⟨i, mem_cons_self .., ?_⟩
simp only [mem_cons, forall_eq_or_imp, le_refl, imp_self, true_and]
exact fun k hk hik ↦ (hj.2 hk <| hji.trans hik).trans hji
· exact ⟨j, mem_cons_of_mem hj.1, by simpa [hji] using hj.2⟩
lemma exists_minimalFor (f : ι → α) (s : Finset ι) (hs : s.Nonempty) :
∃ i, MinimalFor (· ∈ s) f i := exists_maximalFor (α := αᵒᵈ) f s hs
lemma exists_maximal (hs : s.Nonempty) : ∃ i, Maximal (· ∈ s) i := s.exists_maximalFor id hs
lemma exists_minimal (hs : s.Nonempty) : ∃ i, Minimal (· ∈ s) i := s.exists_minimalFor id hs
lemma exists_le_maximal (s : Finset α) (ha : a ∈ s) : ∃ b, a ≤ b ∧ Maximal (· ∈ s) b := by
classical
obtain ⟨b, hb, hab, hbmin⟩ : ∃ b ∈ s, a ≤ b ∧ _ := by
simpa [Maximal, and_assoc] using {x ∈ s | a ≤ x}.exists_maximal ⟨a, mem_filter.2 ⟨ha, le_rfl⟩⟩
exact ⟨b, hab, hb, fun c hc hbc ↦ hbmin hc (hab.trans hbc) hbc⟩
lemma exists_le_minimal (s : Finset α) (ha : a ∈ s) : ∃ b ≤ a, Minimal (· ∈ s) b :=
exists_le_maximal (α := αᵒᵈ) s ha
@[deprecated (since := "2025-05-04")] alias exists_minimal_le := exists_le_minimal
end Finset
namespace Set
section Preorder
variable [Preorder α] {s : Set α} {a : α}
lemma Finite.exists_maximalFor (f : ι → α) (s : Set ι) (h : s.Finite) (hs : s.Nonempty) :
∃ i, MaximalFor (· ∈ s) f i := by
lift s to Finset ι using h; exact s.exists_maximalFor f hs
lemma Finite.exists_minimalFor (f : ι → α) (s : Set ι) (h : s.Finite) (hs : s.Nonempty) :
∃ i, MinimalFor (· ∈ s) f i := Finite.exists_maximalFor (α := αᵒᵈ) f s h hs
lemma Finite.exists_maximal (h : s.Finite) (hs : s.Nonempty) : ∃ i, Maximal (· ∈ s) i :=
h.exists_maximalFor id _ hs
lemma Finite.exists_minimal (h : s.Finite) (hs : s.Nonempty) : ∃ i, Minimal (· ∈ s) i :=
h.exists_minimalFor id _ hs
/-- A version of `Finite.exists_maximalFor` with the (weaker) hypothesis that the image of `s`
is finite rather than `s` itself. -/
lemma Finite.exists_maximalFor' (f : ι → α) (s : Set ι) (h : (f '' s).Finite) (hs : s.Nonempty) :
∃ i, MaximalFor (· ∈ s) f i := by
obtain ⟨_, ⟨a, ha, rfl⟩, hmax⟩ := Finite.exists_maximalFor id (f '' s) h (hs.image f)
exact ⟨a, ha, fun a' ha' hf ↦ hmax (mem_image_of_mem f ha') hf⟩
/-- A version of `Finite.exists_minimalFor` with the (weaker) hypothesis that the image of `s`
is finite rather than `s` itself. -/
lemma Finite.exists_minimalFor' (f : ι → α) (s : Set ι) (h : (f '' s).Finite) (hs : s.Nonempty) :
∃ i, MinimalFor (· ∈ s) f i := h.exists_maximalFor' (α := αᵒᵈ) f s hs
@[deprecated (since := "2025-05-04")] alias Finite.exists_maximal_wrt := Finite.exists_maximalFor
@[deprecated (since := "2025-05-04")] alias Finite.exists_minimal_wrt := Finite.exists_minimalFor
@[deprecated (since := "2025-05-04")] alias Finite.exists_maximal_wrt' := Finite.exists_maximalFor'
@[deprecated (since := "2025-05-04")] alias Finite.exists_minimal_wrt' := Finite.exists_minimalFor'
lemma Finite.exists_le_maximal (hs : s.Finite) (ha : a ∈ s) : ∃ b, a ≤ b ∧ Maximal (· ∈ s) b := by
lift s to Finset α using hs; exact s.exists_le_maximal ha
lemma Finite.exists_le_minimal (hs : s.Finite) (ha : a ∈ s) : ∃ b, b ≤ a ∧ Minimal (· ∈ s) b := by
lift s to Finset α using hs; exact s.exists_le_minimal ha
variable [Nonempty α]
lemma infinite_of_forall_exists_gt (h : ∀ a, ∃ b ∈ s, a < b) : s.Infinite := by
inhabit α
let f (n : ℕ) : α := Nat.recOn n (h default).choose fun _ a ↦ (h a).choose
have hf : ∀ n, f n ∈ s := by rintro (_ | _) <;> exact (h _).choose_spec.1
exact infinite_of_injective_forall_mem
(strictMono_nat_of_lt_succ fun n => (h _).choose_spec.2).injective hf
lemma infinite_of_forall_exists_lt (h : ∀ a, ∃ b ∈ s, b < a) : s.Infinite :=
infinite_of_forall_exists_gt (α := αᵒᵈ) h
end Preorder
section PartialOrder
variable (α) [PartialOrder α]
lemma finite_isTop : {a : α | IsTop a}.Finite := (subsingleton_isTop α).finite
lemma finite_isBot : {a : α | IsBot a}.Finite := (subsingleton_isBot α).finite
end PartialOrder
section LinearOrder
variable [LinearOrder α] {s : Set α} {t : Set β} {f : α → β}
lemma Infinite.exists_lt_map_eq_of_mapsTo (hs : s.Infinite) (hf : MapsTo f s t) (ht : t.Finite) :
∃ x ∈ s, ∃ y ∈ s, x < y ∧ f x = f y :=
let ⟨x, hx, y, hy, hxy, hf⟩ := hs.exists_ne_map_eq_of_mapsTo hf ht
hxy.lt_or_gt.elim (fun hxy => ⟨x, hx, y, hy, hxy, hf⟩) fun hyx => ⟨y, hy, x, hx, hyx, hf.symm⟩
lemma Finite.exists_lt_map_eq_of_forall_mem [Infinite α] (hf : ∀ a, f a ∈ t) (ht : t.Finite) :
∃ a b, a < b ∧ f a = f b := by
rw [← mapsTo_univ_iff] at hf
obtain ⟨a, -, b, -, h⟩ := infinite_univ.exists_lt_map_eq_of_mapsTo hf ht
exact ⟨a, b, h⟩
end LinearOrder
end Set
section Preorder
variable [Preorder α] [Finite α] {p : α → Prop} {a : α}
lemma Finite.exists_le_maximal (h : p a) : ∃ b, a ≤ b ∧ Maximal p b :=
{x | p x}.toFinite.exists_le_maximal h
lemma Finite.exists_le_minimal (h : p a) : ∃ b ≤ a, Minimal p b :=
{x | p x}.toFinite.exists_le_minimal h
end Preorder
|
CommAlgCat.lean
|
import Mathlib.Algebra.Category.CommAlgCat.Basic
universe v u
open CategoryTheory CommAlgCat
set_option maxHeartbeats 10000
set_option synthInstance.maxHeartbeats 2000
variable (R : Type u) [CommRing R]
/- We test if all the coercions and `map_add` lemmas trigger correctly. -/
example (X : Type v) [CommRing X] [Algebra R X] : ⇑(𝟙 (of R X)) = id := by simp
example {X Y : Type v} [CommRing X] [Algebra R X] [CommRing Y] [Algebra R Y] (f : X →ₐ[R] Y) :
⇑(CommAlgCat.ofHom f) = ⇑f := by simp
example {X Y : Type v} [CommRing X] [Algebra R X] [CommRing Y] [Algebra R Y] (f : X →ₐ[R] Y)
(x : X) : (CommAlgCat.ofHom f) x = f x := by simp
example {X Y Z : CommAlgCat R} (f : X ⟶ Y) (g : Y ⟶ Z) : ⇑(f ≫ g) = ⇑g ∘ ⇑f := by simp
example {X Y Z : Type v} [CommRing X] [Algebra R X] [CommRing Y] [Algebra R Y] [CommRing Z]
[Algebra R Z] (f : X →ₐ[R] Y) (g : Y →ₐ[R] Z) :
⇑(CommAlgCat.ofHom f ≫ CommAlgCat.ofHom g) = g ∘ f := by simp
example {X Y : Type v} [CommRing X] [Algebra R X] [CommRing Y] [Algebra R Y] {Z : CommAlgCat R}
(f : X →ₐ[R] Y) (g : of R Y ⟶ Z) :
⇑(CommAlgCat.ofHom f ≫ g) = g ∘ f := by simp
example {X Y : CommAlgCat R} {Z : Type v} [CommRing Z] [Algebra R Z] (f : X ⟶ Y) (g : Y ⟶ of R Z) :
⇑(f ≫ g) = g ∘ f := by simp
example {Y Z : CommAlgCat R} {X : Type v} [CommRing X] [Algebra R X] (f : of R X ⟶ Y) (g : Y ⟶ Z) :
⇑(f ≫ g) = g ∘ f := by simp
example {X Y Z : CommAlgCat R} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) := by simp
example {X Y : CommAlgCat R} (e : X ≅ Y) (x : X) : e.inv (e.hom x) = x := by simp
example {X Y : CommAlgCat R} (e : X ≅ Y) (y : Y) : e.hom (e.inv y) = y := by simp
example (X : CommAlgCat R) : ⇑(𝟙 X) = id := by simp
example {M N : CommAlgCat.{v} R} (f : M ⟶ N) (x y : M) : f (x + y) = f x + f y := by
simp
example {M N : CommAlgCat.{v} R} (f : M ⟶ N) : f 0 = 0 := by
simp
example {M N : CommAlgCat.{v} R} (f : M ⟶ N) (r : R) (m : M) : f (r • m) = r • f m := by
simp
|
Skeleton.lean
|
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.CategoryTheory.Monoidal.Transport
import Mathlib.CategoryTheory.Skeletal
/-!
# The monoid on the skeleton of a monoidal category
The skeleton of a monoidal category is a monoid.
## Main results
* `Skeleton.instMonoid`, for monoidal categories.
* `Skeleton.instCommMonoid`, for braided monoidal categories.
-/
namespace CategoryTheory
open MonoidalCategory
universe v u
variable {C : Type u} [Category.{v} C] [MonoidalCategory C]
/-- If `C` is monoidal and skeletal, it is a monoid.
See note [reducible non-instances]. -/
abbrev monoidOfSkeletalMonoidal (hC : Skeletal C) : Monoid C where
mul X Y := (X ⊗ Y : C)
one := (𝟙_ C : C)
one_mul X := hC ⟨λ_ X⟩
mul_one X := hC ⟨ρ_ X⟩
mul_assoc X Y Z := hC ⟨α_ X Y Z⟩
/-- If `C` is braided and skeletal, it is a commutative monoid. -/
def commMonoidOfSkeletalBraided [BraidedCategory C] (hC : Skeletal C) : CommMonoid C :=
{ monoidOfSkeletalMonoidal hC with mul_comm := fun X Y => hC ⟨β_ X Y⟩ }
namespace Skeleton
/-- The skeleton of a monoidal category has a monoidal structure itself, induced by the equivalence.
-/
noncomputable instance instMonoidalCategory : MonoidalCategory (Skeleton C) :=
Monoidal.transport (skeletonEquivalence C).symm
/--
The skeleton of a monoidal category can be viewed as a monoid, where the multiplication is given by
the tensor product, and satisfies the monoid axioms since it is a skeleton.
-/
noncomputable instance instMonoid : Monoid (Skeleton C) :=
monoidOfSkeletalMonoidal (skeleton_isSkeleton _).skel
theorem mul_eq (X Y : Skeleton C) : X * Y = toSkeleton (X.out ⊗ Y.out) := rfl
theorem one_eq : (1 : Skeleton C) = toSkeleton (𝟙_ C) := rfl
theorem toSkeleton_tensorObj (X Y : C) : toSkeleton (X ⊗ Y) = toSkeleton X * toSkeleton Y :=
let φ := (skeletonEquivalence C).symm.unitIso.app; Quotient.sound ⟨φ X ⊗ᵢ φ Y⟩
/-- The skeleton of a braided monoidal category has a braided monoidal structure itself, induced by
the equivalence. -/
noncomputable instance instBraidedCategory [BraidedCategory C] : BraidedCategory (Skeleton C) :=
(BraidedCategory.ofFullyFaithful
(Monoidal.equivalenceTransported (skeletonEquivalence C).symm).inverse:)
/--
The skeleton of a braided monoidal category can be viewed as a commutative monoid, where the
multiplication is given by the tensor product, and satisfies the monoid axioms since it is a
skeleton.
-/
noncomputable instance instCommMonoid [BraidedCategory C] : CommMonoid (Skeleton C) :=
commMonoidOfSkeletalBraided (skeleton_isSkeleton _).skel
end Skeleton
end CategoryTheory
|
center.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import fintype bigop finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action gproduct gfunctor.
From mathcomp Require Import cyclic.
(******************************************************************************)
(* Definition of the center of a group and of external central products: *)
(* 'Z(G) == the center of the group G, i.e., 'C_G(G). *)
(* cprod_by isoZ == the finGroupType for the central product of H and K *)
(* with centers identified by the isomorphism gz on 'Z(H); *)
(* here isoZ : isom 'Z(H) 'Z(K) gz. Note that the actual *)
(* central product is [set: cprod_by isoZ]. *)
(* cpairg1 isoZ == the isomorphism from H to cprod_by isoZ, isoZ as above. *)
(* cpair1g isoZ == the isomorphism from K to cprod_by isoZ, isoZ as above. *)
(* xcprod H K == the finGroupType for the external central product of H *)
(* and K with identified centers, provided the dynamically *)
(* tested condition 'Z(H) \isog 'Z(K) holds. *)
(* ncprod H n == the finGroupType for the central product of n copies of *)
(* H with their centers identified; [set: ncprod H 0] is *)
(* isomorphic to 'Z(H). *)
(* xcprodm cf eqf == the morphism induced on cprod_by isoZ, where as above *)
(* isoZ : isom 'Z(H) 'Z(K) gz, by fH : {morphism H >-> rT} *)
(* and fK : {morphism K >-> rT}, given both *)
(* cf : fH @* H \subset 'C(fK @* K) and *)
(* eqf : {in 'Z(H), fH =1 fK \o gz}. *)
(* Following Aschbacher, we only provide external central products with *)
(* identified centers, as these are well defined provided the local center *)
(* isomorphism group of one of the subgroups is full. Nevertheless the *)
(* entire construction could be carried out under the weaker assumption that *)
(* gz is an isomorphism between subgroups of 'Z(H) and 'Z(K), and even the *)
(* uniqueness theorem holds under the weaker assumption that gz map 'Z(H) to *)
(* a characteristic subgroup of 'Z(K) not isomorphic to any other subgroup of *)
(* 'Z(K), a condition that holds for example when K is cyclic, as in the *)
(* structure theorem for p-groups of symplectic type. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Defs.
Variable gT : finGroupType.
Definition center (A : {set gT}) := 'C_A(A).
Canonical center_group (G : {group gT}) : {group gT} :=
Eval hnf in [group of center G].
End Defs.
Arguments center {gT} A%_g.
Notation "''Z' ( A )" := (center A) : group_scope.
Notation "''Z' ( H )" := (center_group H) : Group_scope.
Lemma morphim_center : GFunctor.pcontinuous (@center).
Proof. by move=> gT rT G D f; apply: morphim_subcent. Qed.
Canonical center_igFun := [igFun by fun _ _ => subsetIl _ _ & morphim_center].
Canonical center_gFun := [gFun by morphim_center].
Canonical center_pgFun := [pgFun by morphim_center].
Section Center.
Variables gT : finGroupType.
Implicit Type rT : finGroupType.
Implicit Types (x y : gT) (A B : {set gT}) (G H K D : {group gT}).
Lemma subcentP A B x : reflect (x \in A /\ centralises x B) (x \in 'C_A(B)).
Proof.
rewrite inE. case: (x \in A); last by right; case.
by apply: (iffP centP) => [|[]].
Qed.
Lemma subcent_sub A B : 'C_A(B) \subset 'N_A(B).
Proof. by rewrite setIS ?cent_sub. Qed.
Lemma subcent_norm G B : 'N_G(B) \subset 'N('C_G(B)).
Proof. by rewrite normsI ?subIset ?normG // orbC cent_norm. Qed.
Lemma subcent_normal G B : 'C_G(B) <| 'N_G(B).
Proof. by rewrite /normal subcent_sub subcent_norm. Qed.
Lemma subcent_char G H K : H \char G -> K \char G -> 'C_H(K) \char G.
Proof.
case/charP=> sHG chHG /charP[sKG chKG]; apply/charP.
split=> [|f injf Gf]; first by rewrite subIset ?sHG.
by rewrite injm_subcent ?chHG ?chKG.
Qed.
Lemma centerP A x : reflect (x \in A /\ centralises x A) (x \in 'Z(A)).
Proof. exact: subcentP. Qed.
Lemma center_sub A : 'Z(A) \subset A.
Proof. exact: subsetIl. Qed.
Lemma center1 : 'Z(1) = 1 :> {set gT}.
Proof. exact: gF1. Qed.
Lemma centerC A : {in A, centralised 'Z(A)}.
Proof. by apply/centsP; rewrite centsC subsetIr. Qed.
Lemma center_normal G : 'Z(G) <| G.
Proof. exact: gFnormal. Qed.
Lemma sub_center_normal H G : H \subset 'Z(G) -> H <| G.
Proof. by rewrite subsetI centsC /normal => /andP[-> /cents_norm]. Qed.
Lemma center_abelian G : abelian 'Z(G).
Proof. by rewrite /abelian subIset // centsC subIset // subxx orbT. Qed.
Lemma center_char G : 'Z(G) \char G.
Proof. exact: gFchar. Qed.
Lemma center_idP A : reflect ('Z(A) = A) (abelian A).
Proof. exact: setIidPl. Qed.
Lemma center_class_formula G :
#|G| = #|'Z(G)| + \sum_(xG in [set x ^: G | x in G :\: 'C(G)]) #|xG|.
Proof.
by rewrite acts_sum_card_orbit ?cardsID // astabsJ normsD ?norms_cent ?normG.
Qed.
Lemma subcent1P A x y : reflect (y \in A /\ commute x y) (y \in 'C_A[x]).
Proof.
rewrite inE; case: (y \in A); last by right; case.
by apply: (iffP cent1P) => [|[]].
Qed.
Lemma subcent1_id x G : x \in G -> x \in 'C_G[x].
Proof. by move=> Gx; rewrite inE Gx; apply/cent1P. Qed.
Lemma subcent1_sub x G : 'C_G[x] \subset G.
Proof. exact: subsetIl. Qed.
Lemma subcent1C x y G : x \in G -> y \in 'C_G[x] -> x \in 'C_G[y].
Proof. by move=> Gx /subcent1P[_ cxy]; apply/subcent1P. Qed.
Lemma subcent1_cycle_sub x G : x \in G -> <[x]> \subset 'C_G[x].
Proof. by move=> Gx; rewrite cycle_subG ?subcent1_id. Qed.
Lemma subcent1_cycle_norm x G : 'C_G[x] \subset 'N(<[x]>).
Proof. by rewrite cents_norm // cent_gen cent_set1 subsetIr. Qed.
Lemma subcent1_cycle_normal x G : x \in G -> <[x]> <| 'C_G[x].
Proof.
by move=> Gx; rewrite /normal subcent1_cycle_norm subcent1_cycle_sub.
Qed.
(* Gorenstein. 1.3.4 *)
Lemma cyclic_center_factor_abelian G : cyclic (G / 'Z(G)) -> abelian G.
Proof.
case/cyclicP=> a Ga; case: (cosetP a) => /= z Nz def_a.
have G_Zz: G :=: 'Z(G) * <[z]>.
rewrite -quotientK ?cycle_subG ?quotient_cycle //=.
by rewrite -def_a -Ga quotientGK // center_normal.
rewrite G_Zz abelianM cycle_abelian center_abelian centsC /= G_Zz.
by rewrite subIset ?centS ?orbT ?mulG_subr.
Qed.
Lemma cyclic_factor_abelian H G :
H \subset 'Z(G) -> cyclic (G / H) -> abelian G.
Proof.
move=> sHZ cycGH; apply: cyclic_center_factor_abelian.
have /andP[_ nHG]: H <| G := sub_center_normal sHZ.
have [f <-]:= homgP (homg_quotientS nHG (gFnorm _ G) sHZ).
exact: morphim_cyclic cycGH.
Qed.
Section Injm.
Variables (rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_center G : G \subset D -> f @* 'Z(G) = 'Z(f @* G).
Proof. exact: injm_subcent. Qed.
End Injm.
End Center.
Arguments center_idP {gT A}.
Lemma isog_center (aT rT : finGroupType) (G : {group aT}) (H : {group rT}) :
G \isog H -> 'Z(G) \isog 'Z(H).
Proof. exact: gFisog. Qed.
Section Product.
Variable gT : finGroupType.
Implicit Types (A B C : {set gT}) (G H K : {group gT}).
Lemma center_prod H K : K \subset 'C(H) -> 'Z(H) * 'Z(K) = 'Z(H * K).
Proof.
move=> cHK; apply/setP=> z; rewrite {3}/center centM !inE.
have cKH: H \subset 'C(K) by rewrite centsC.
apply/imset2P/and3P=> [[x y /setIP[Hx cHx] /setIP[Ky cKy] ->{z}]| []].
by rewrite imset2_f ?groupM // ?(subsetP cHK) ?(subsetP cKH).
case/imset2P=> x y Hx Ky ->{z}.
rewrite groupMr => [cHx|]; last exact: subsetP Ky.
rewrite groupMl => [cKy|]; last exact: subsetP Hx.
by exists x y; rewrite ?inE ?Hx ?Ky.
Qed.
Lemma center_cprod A B G : A \* B = G -> 'Z(A) \* 'Z(B) = 'Z(G).
Proof.
case/cprodP => [[H K -> ->] <- cHK].
rewrite cprodE ?center_prod //= subIset ?(subset_trans cHK) //.
by rewrite centS ?center_sub.
Qed.
Lemma center_bigcprod I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/cprodP: dG IHA IHB (dG) => [[H K -> ->] _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_cprod dG).
Qed.
Lemma cprod_center_id G : G \* 'Z(G) = G.
Proof. by rewrite cprodE ?subsetIr // mulGSid ?center_sub. Qed.
Lemma center_dprod A B G : A \x B = G -> 'Z(A) \x 'Z(B) = 'Z(G).
Proof.
case/dprodP=> [[H1 H2 -> ->] defG cH12 trH12].
move: defG; rewrite -cprodE // => /center_cprod/cprodP[_ /= <- cZ12].
by apply: dprodE; rewrite //= setIAC setIA -setIA trH12 (setIidPl _) ?sub1G.
Qed.
Lemma center_bigdprod I r P (F: I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/dprodP: dG IHA IHB (dG) => [[H K -> ->] _ _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_dprod dG).
Qed.
Lemma Aut_cprod_full G H K :
H \* K = G -> 'Z(H) = 'Z(K) ->
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G).
Proof.
move=> defG eqZHK; have [_ defHK cHK] := cprodP defG.
have defZ: 'Z(G) = 'Z(H) by rewrite -defHK -center_prod // eqZHK mulGid.
have ziHK: H :&: K = 'Z(K).
by apply/eqP; rewrite eqEsubset subsetI -{1 2}eqZHK !center_sub setIS.
have AutZP := Aut_sub_fullP (@center_sub gT _).
move/AutZP=> AutZHfull /AutZP AutZKfull; apply/AutZP=> g injg gZ.
have [gH [def_gH ker_gH _ im_gH]] := domP g defZ.
have [gK [def_gK ker_gK _ im_gK]] := domP g (etrans defZ eqZHK).
have [injgH injgK]: 'injm gH /\ 'injm gK by rewrite ker_gH ker_gK.
have [gHH gKK]: gH @* 'Z(H) = 'Z(H) /\ gK @* 'Z(K) = 'Z(K).
by rewrite im_gH im_gK -eqZHK -defZ.
have [|fH [injfH im_fH fHZ]] := AutZHfull gH injgH.
by rewrite im_gH /= -defZ.
have [|fK [injfK im_fK fKZ]] := AutZKfull gK injgK.
by rewrite im_gK /= -eqZHK -defZ.
have cfHK: fK @* K \subset 'C(fH @* H) by rewrite im_fH im_fK.
have eq_fHK: {in H :&: K, fH =1 fK}.
by move=> z; rewrite ziHK => Zz; rewrite fHZ ?fKZ /= ?eqZHK // def_gH def_gK.
exists (cprodm_morphism defG cfHK eq_fHK).
rewrite injm_cprodm injfH injfK im_cprodm im_fH im_fK defHK.
rewrite -morphimIdom ziHK -eqZHK injm_center // im_fH eqxx.
split=> //= z; rewrite {1}defZ => Zz; have [Hz _] := setIP Zz.
by rewrite cprodmEl // fHZ // def_gH.
Qed.
End Product.
Section CprodBy.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}) (gz : {morphism 'Z(H) >-> gTK}).
Definition ker_cprod_by of isom 'Z(H) 'Z(K) gz :=
[set xy | let: (x, y) := xy in (x \in 'Z(H)) && (y == (gz x)^-1)].
Hypothesis isoZ : isom 'Z(H) 'Z(K) gz.
Let kerHK := ker_cprod_by isoZ.
Let injgz : 'injm gz. Proof. by case/isomP: isoZ. Qed.
Let gzZ : gz @* 'Z(H) = 'Z(K). Proof. by case/isomP: isoZ. Qed.
Let gzZchar : gz @* 'Z(H) \char 'Z(K). Proof. by rewrite gzZ. Qed.
Let sgzZZ : gz @* 'Z(H) \subset 'Z(K) := char_sub gzZchar.
Let sZH := center_sub H.
Let sZK := center_sub K.
Let sgzZG : gz @* 'Z(H) \subset K := subset_trans sgzZZ sZK.
Lemma ker_cprod_by_is_group : group_set kerHK.
Proof.
apply/group_setP; rewrite inE /= group1 morph1 invg1 /=.
split=> // [[x1 y1] [x2 y2]].
rewrite inE /= => /andP[Zx1 /eqP->]; have [_ cGx1] := setIP Zx1.
rewrite inE /= => /andP[Zx2 /eqP->]; have [Gx2 _] := setIP Zx2.
by rewrite inE /= groupM //= -invMg (centP cGx1) // morphM.
Qed.
Canonical ker_cprod_by_group := Group ker_cprod_by_is_group.
Lemma ker_cprod_by_central : kerHK \subset 'Z(setX H K).
Proof.
rewrite -(center_dprod (setX_dprod H K)) -morphim_pairg1 -morphim_pair1g.
rewrite -!injm_center ?subsetT ?injm_pair1g ?injm_pairg1 //=.
rewrite morphim_pairg1 morphim_pair1g setX_dprod.
apply/subsetP=> [[x y]] /[1!inE] /andP[Zx /eqP->].
by rewrite inE /= Zx groupV (subsetP sgzZZ) ?mem_morphim.
Qed.
Fact cprod_by_key : unit. Proof. by []. Qed.
Definition cprod_by_def : finGroupType := subg_of (setX H K / kerHK).
Definition cprod_by := locked_with cprod_by_key cprod_by_def.
Local Notation C := [set: FinGroup.sort cprod_by].
(*FIXME : Check if we need arg_sort instead of sort*)
Definition in_cprod : gTH * gTK -> cprod_by :=
let: tt as k := cprod_by_key return _ -> locked_with k cprod_by_def in
subg _ \o coset kerHK.
Lemma in_cprodM : {in setX H K &, {morph in_cprod : u v / u * v}}.
Proof.
rewrite /in_cprod /cprod_by; case: cprod_by_key => /= u v Gu Gv.
have nkerHKG := normal_norm (sub_center_normal ker_cprod_by_central).
by rewrite -!morphM ?mem_quotient // (subsetP nkerHKG).
Qed.
Canonical in_cprod_morphism := Morphism in_cprodM.
Lemma ker_in_cprod : 'ker in_cprod = kerHK.
Proof.
transitivity ('ker (subg [group of setX H K / kerHK] \o coset kerHK)).
rewrite /ker /morphpre /= /in_cprod /cprod_by; case: cprod_by_key => /=.
by rewrite ['N(_) :&: _]quotientGK ?sub_center_normal ?ker_cprod_by_central.
by rewrite ker_comp ker_subg -kerE ker_coset.
Qed.
Lemma cpairg1_dom : H \subset 'dom (in_cprod \o @pairg1 gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pairg1 setXS ?sub1G. Qed.
Lemma cpair1g_dom : K \subset 'dom (in_cprod \o @pair1g gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pair1g setXS ?sub1G. Qed.
Definition cpairg1 := tag (restrmP _ cpairg1_dom).
Definition cpair1g := tag (restrmP _ cpair1g_dom).
Local Notation CH := (mfun cpairg1 @* gval H).
Local Notation CK := (mfun cpair1g @* gval K).
Lemma injm_cpairg1 : 'injm cpairg1.
Proof.
rewrite /cpairg1; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> x; rewrite !inE /=.
by case/and3P=> _ Zx; rewrite eq_sym (inv_eq invgK) invg1 morph_injm_eq1.
Qed.
Let injH := injm_cpairg1.
Lemma injm_cpair1g : 'injm cpair1g.
Proof.
rewrite /cpair1g; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> y; rewrite !inE /= morph1 invg1.
by case/and3P.
Qed.
Let injK := injm_cpair1g.
Lemma im_cpair_cent : CK \subset 'C(CH).
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp morphim_cents // morphim_pair1g morphim_pairg1.
by case/dprodP: (setX_dprod H K).
Qed.
Hint Resolve im_cpair_cent : core.
Lemma im_cpair : CH * CK = C.
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp -morphimMl morphim_pairg1 ?setXS ?sub1G //.
rewrite morphim_pair1g setX_prod morphimEdom /= /in_cprod /cprod_by.
by case: cprod_by_key; rewrite /= imset_comp imset_coset -morphimEdom im_subg.
Qed.
Lemma im_cpair_cprod : CH \* CK = C. Proof. by rewrite cprodE ?im_cpair. Qed.
Lemma eq_cpairZ : {in 'Z(H), cpairg1 =1 cpair1g \o gz}.
Proof.
rewrite /cpairg1 /cpair1g => z1 Zz1; set z2 := gz z1.
have Zz2: z2 \in 'Z(K) by rewrite (subsetP sgzZZ) ?mem_morphim.
have [[Gz1 _] [/= Gz2 _]]:= (setIP Zz1, setIP Zz2).
do 2![case: restrmP => f /= [df _ _ _]; rewrite {f}df].
apply/rcoset_kerP; rewrite ?inE ?group1 ?andbT //.
by rewrite ker_in_cprod mem_rcoset inE /= invg1 mulg1 mul1g Zz1 /=.
Qed.
Lemma setI_im_cpair : CH :&: CK = 'Z(CH).
Proof.
apply/eqP; rewrite eqEsubset setIS //=.
rewrite subsetI center_sub -injm_center //.
rewrite (eq_in_morphim _ eq_cpairZ); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
Lemma cpair1g_center : cpair1g @* 'Z(K) = 'Z(C).
Proof.
case/cprodP: (center_cprod im_cpair_cprod) => _ <- _.
by rewrite injm_center // -setI_im_cpair mulSGid //= setIC setIS 1?centsC.
Qed.
(* Uses gzZ. *)
Lemma cpair_center_id : 'Z(CH) = 'Z(CK).
Proof.
rewrite -!injm_center // -gzZ -morphim_comp; apply: eq_in_morphim eq_cpairZ.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
(* Uses gzZ. *)
Lemma cpairg1_center : cpairg1 @* 'Z(H) = 'Z(C).
Proof. by rewrite -cpair1g_center !injm_center // cpair_center_id. Qed.
Section ExtCprodm.
Variable rT : finGroupType.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Hypothesis eq_fHK : {in 'Z(H), fH =1 fK \o gz}.
Let gH := ifactm fH injm_cpairg1.
Let gK := ifactm fK injm_cpair1g.
Lemma xcprodm_cent : gK @* CK \subset 'C(gH @* CH).
Proof. by rewrite !im_ifactm. Qed.
Lemma xcprodmI : {in CH :&: CK, gH =1 gK}.
Proof.
rewrite setI_im_cpair -injm_center // => fHx; case/morphimP=> x Gx Zx ->{fHx}.
by rewrite {2}eq_cpairZ //= ?ifactmE ?eq_fHK //= (subsetP sgzZG) ?mem_morphim.
Qed.
Definition xcprodm := cprodm im_cpair_cprod xcprodm_cent xcprodmI.
Canonical xcprod_morphism := [morphism of xcprodm].
Lemma xcprodmEl : {in H, forall x, xcprodm (cpairg1 x) = fH x}.
Proof. by move=> x Hx; rewrite /xcprodm cprodmEl ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmEr : {in K, forall y, xcprodm (cpair1g y) = fK y}.
Proof. by move=> y Ky; rewrite /xcprodm cprodmEr ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmE :
{in H & K, forall x y, xcprodm (cpairg1 x * cpair1g y) = fH x * fK y}.
Proof.
by move=> x y Hx Ky; rewrite /xcprodm cprodmE ?mem_morphim ?ifactmE.
Qed.
Lemma im_xcprodm : xcprodm @* C = fH @* H * fK @* K.
Proof. by rewrite -im_cpair morphim_cprodm // !im_ifactm. Qed.
Lemma im_xcprodml A : xcprodm @* (cpairg1 @* A) = fH @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodml ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma im_xcprodmr A : xcprodm @* (cpair1g @* A) = fK @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodmr ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma injm_xcprodm : 'injm xcprodm = 'injm fH && 'injm fK.
Proof.
rewrite injm_cprodm !ker_ifactm !subG1 !morphim_injm_eq1 ?subsetIl // -!subG1.
apply: andb_id2l => /= injfH; apply: andb_idr => _.
rewrite !im_ifactm // -(morphimIdom gH) setI_im_cpair -injm_center //.
rewrite morphim_ifactm // eqEsubset subsetI morphimS //=.
rewrite {1}injm_center // setIS //=.
rewrite (eq_in_morphim _ eq_fHK); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
End ExtCprodm.
(* Uses gzZchar. *)
Lemma Aut_cprod_by_full :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut C) 'Z(C) \isog Aut 'Z(C).
Proof.
move=> AutZinH AutZinK.
have Cfull:= Aut_cprod_full im_cpair_cprod cpair_center_id.
by rewrite Cfull // -injm_center // injm_Aut_full ?center_sub.
Qed.
Section Isomorphism.
Let gzZ_lone (Y : {group gTK}) :
Y \subset 'Z(K) -> gz @* 'Z(H) \isog Y -> gz @* 'Z(H) = Y.
Proof.
move=> sYZ isoY; apply/eqP.
by rewrite eq_sym eqEcard (card_isog isoY) gzZ sYZ /=.
Qed.
Variables (rT : finGroupType) (GH GK G : {group rT}).
Hypotheses (defG : GH \* GK = G) (ziGHK : GH :&: GK = 'Z(GH)).
Hypothesis AutZHfull : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H).
Hypotheses (isoGH : GH \isog H) (isoGK : GK \isog K).
(* Uses gzZ_lone *)
Lemma cprod_by_uniq :
exists f : {morphism G >-> cprod_by},
[/\ isom G C f, f @* GH = CH & f @* GK = CK].
Proof.
have [_ defGHK cGKH] := cprodP defG.
have AutZinH := Aut_sub_fullP sZH AutZHfull.
have [fH injfH defGH]:= isogP (isog_symr isoGH).
have [fK injfK defGK]:= isogP (isog_symr isoGK).
have sfHZfK: fH @* 'Z(H) \subset fK @* K.
by rewrite injm_center //= defGH defGK -ziGHK subsetIr.
have gzZ_id: gz @* 'Z(H) = invm injfK @* (fH @* 'Z(H)).
apply: gzZ_lone => /=.
rewrite injm_center // defGH -ziGHK sub_morphim_pre /= ?defGK ?subsetIr //.
by rewrite setIC morphpre_invm injm_center // defGK setIS 1?centsC.
rewrite -morphim_comp.
apply: isog_trans (sub_isog _ _); first by rewrite isog_sym sub_isog.
by rewrite -sub_morphim_pre.
by rewrite !injm_comp ?injm_invm.
have: 'dom (invm injfH \o fK \o gz) = 'Z(H).
rewrite /dom /= -(morphpreIdom gz); apply/setIidPl.
by rewrite -2?sub_morphim_pre // gzZ_id morphim_invmE morphpreK ?morphimS.
case/domP=> gzH [def_gzH ker_gzH _ im_gzH].
have{ker_gzH} injgzH: 'injm gzH by rewrite ker_gzH !injm_comp ?injm_invm.
have{AutZinH} [|gH [injgH gH_H def_gH]] := AutZinH _ injgzH.
by rewrite im_gzH !morphim_comp /= gzZ_id !morphim_invmE morphpreK ?injmK.
have: 'dom (fH \o gH) = H by rewrite /dom /= -{3}gH_H injmK.
case/domP=> gfH [def_gfH ker_gfH _ im_gfH].
have{im_gfH} gfH_H: gfH @* H = GH by rewrite im_gfH morphim_comp gH_H.
have cgfHfK: fK @* K \subset 'C(gfH @* H) by rewrite gfH_H defGK.
have eq_gfHK: {in 'Z(H), gfH =1 fK \o gz}.
move=> z Zz; rewrite def_gfH /= def_gH //= def_gzH /= invmK //.
have {Zz}: gz z \in gz @* 'Z(H) by rewrite mem_morphim.
rewrite gzZ_id morphim_invmE; case/morphpreP=> _.
exact: (subsetP (morphimS _ _)).
pose f := xcprodm cgfHfK eq_gfHK.
have injf: 'injm f by rewrite injm_xcprodm ker_gfH injm_comp.
have fCH: f @* CH = GH by rewrite im_xcprodml gfH_H.
have fCK: f @* CK = GK by rewrite im_xcprodmr defGK.
have fC: f @* C = G by rewrite im_xcprodm gfH_H defGK defGHK.
have [f' [_ ker_f' _ im_f']] := domP (invm_morphism injf) fC.
exists f'; rewrite -fCH -fCK !{1}im_f' !{1}morphim_invm ?subsetT //.
by split=> //; apply/isomP; rewrite ker_f' injm_invm im_f' -fC im_invm.
Qed.
Lemma isog_cprod_by : G \isog C.
Proof. by have [f [isoG _ _]] := cprod_by_uniq; apply: isom_isog isoG. Qed.
End Isomorphism.
End CprodBy.
Section ExtCprod.
Import finfun.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}).
Let gt_ b := if b then gTK else gTH.
Local Notation isob := ('Z(H) \isog 'Z(K)) (only parsing).
Let G_ b := if b as b' return {group gt_ b'} then K else H.
Lemma xcprod_subproof :
{gz : {morphism 'Z(H) >-> gt_ isob} | isom 'Z(H) 'Z(G_ isob) gz}.
Proof.
case: (pickP [pred f : {ffun _} | misom 'Z(H) 'Z(K) f]) => [f isoZ | no_f].
rewrite (misom_isog isoZ); case/andP: isoZ => fM isoZ.
by exists [morphism of morphm fM].
move/pred0P: no_f => not_isoZ; rewrite [isob](congr1 negb not_isoZ).
by exists (idm_morphism _); apply/isomP; rewrite injm_idm im_idm.
Qed.
Definition xcprod := cprod_by (svalP xcprod_subproof).
Inductive xcprod_spec : finGroupType -> Prop :=
XcprodSpec gz isoZ : xcprod_spec (@cprod_by gTH gTK H K gz isoZ).
Lemma xcprodP : 'Z(H) \isog 'Z(K) -> xcprod_spec xcprod.
Proof. by rewrite /xcprod => isoZ; move: xcprod_subproof; rewrite isoZ. Qed.
Lemma isog_xcprod (rT : finGroupType) (GH GK G : {group rT}) :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
GH \isog H -> GK \isog K -> GH \* GK = G -> 'Z(GH) = 'Z(GK) ->
G \isog [set: xcprod].
Proof.
move=> AutZinH isoGH isoGK defG eqZGHK; have [_ _ cGHK] := cprodP defG.
have [|gz isoZ] := xcprodP.
have [[fH injfH <-] [fK injfK <-]] := (isogP isoGH, isogP isoGK).
rewrite -!injm_center -?(isog_transl _ (sub_isog _ _)) ?center_sub //=.
by rewrite eqZGHK sub_isog ?center_sub.
rewrite (isog_cprod_by _ defG) //.
by apply/eqP; rewrite eqEsubset setIS // subsetI {2}eqZGHK !center_sub.
Qed.
End ExtCprod.
Section IterCprod.
Variables (gT : finGroupType) (G : {group gT}).
Fixpoint ncprod_def n : finGroupType :=
if n is n'.+1 then xcprod G [set: ncprod_def n']
else subg_of 'Z(G).
Fact ncprod_key : unit. Proof. by []. Qed.
Definition ncprod := locked_with ncprod_key ncprod_def.
Local Notation G_ n := [set: gsort (ncprod n)].
Lemma ncprod0 : G_ 0 \isog 'Z(G).
Proof. by rewrite [ncprod]unlock isog_sym isog_subg. Qed.
Lemma center_ncprod0 : 'Z(G_ 0) = G_ 0.
Proof. by apply: center_idP; rewrite (isog_abelian ncprod0) center_abelian. Qed.
Lemma center_ncprod n : 'Z(G_ n) \isog 'Z(G).
Proof.
elim: n => [|n]; first by rewrite center_ncprod0 ncprod0.
rewrite [ncprod]unlock=> /isog_symr/xcprodP[gz isoZ] /=.
by rewrite -cpairg1_center isog_sym sub_isog ?center_sub ?injm_cpairg1.
Qed.
Lemma ncprodS n : xcprod_spec G [set: ncprod n] (ncprod n.+1).
Proof.
by have:= xcprodP (isog_symr (center_ncprod n)); rewrite [ncprod]unlock.
Qed.
Lemma ncprod1 : G_ 1 \isog G.
Proof.
case: ncprodS => gz isoZ; rewrite isog_sym /= -im_cpair.
rewrite mulGSid /=; first by rewrite sub_isog ?injm_cpairg1.
rewrite -{3}center_ncprod0 injm_center ?injm_cpair1g //.
by rewrite -cpair_center_id center_sub.
Qed.
Lemma Aut_ncprod_full n :
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G) ->
Aut_in (Aut (G_ n)) 'Z(G_ n) \isog Aut 'Z(G_ n).
Proof.
move=> AutZinG; elim: n => [|n IHn].
by rewrite center_ncprod0; apply/Aut_sub_fullP=> // g injg gG0; exists g.
by case: ncprodS => gz isoZ; apply: Aut_cprod_by_full.
Qed.
End IterCprod.
|
Creates.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
import Mathlib.CategoryTheory.Limits.Preserves.Basic
/-!
# Creating (co)limits
We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F`
(i.e. below) we can lift it to a cone "above", and further that `F` reflects
limits for `K`.
-/
open CategoryTheory CategoryTheory.Limits CategoryTheory.Functor
noncomputable section
namespace CategoryTheory
universe w' w'₁ w w₁ v₁ v₂ v₃ u₁ u₂ u₃
variable {C : Type u₁} [Category.{v₁} C]
section Creates
variable {D : Type u₂} [Category.{v₂} D]
variable {J : Type w} [Category.{w'} J] {K : J ⥤ C}
/-- Define the lift of a cone: For a cone `c` for `K ⋙ F`, give a cone for `K`
which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`.
We will then use this as part of the definition of creation of limits:
every limit cone has a lift.
Note this definition is really only useful when `c` is a limit already.
-/
structure LiftableCone (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) where
/-- a cone in the source category of the functor -/
liftedCone : Cone K
/-- the isomorphism expressing that `liftedCone` lifts the given cone -/
validLift : F.mapCone liftedCone ≅ c
/-- Define the lift of a cocone: For a cocone `c` for `K ⋙ F`, give a cocone for
`K` which is a lift of `c`, i.e. the image of it under `F` is (iso) to `c`.
We will then use this as part of the definition of creation of colimits:
every limit cocone has a lift.
Note this definition is really only useful when `c` is a colimit already.
-/
structure LiftableCocone (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) where
/-- a cocone in the source category of the functor -/
liftedCocone : Cocone K
/-- the isomorphism expressing that `liftedCocone` lifts the given cocone -/
validLift : F.mapCocone liftedCocone ≅ c
/-- Definition 3.3.1 of [Riehl].
We say that `F` creates limits of `K` if, given any limit cone `c` for `K ⋙ F`
(i.e. below) we can lift it to a cone "above", and further that `F` reflects
limits for `K`.
If `F` reflects isomorphisms, it suffices to show only that the lifted cone is
a limit - see `createsLimitOfReflectsIso`.
-/
class CreatesLimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsLimit K F where
/-- any limit cone can be lifted to a cone above -/
lifts : ∀ c, IsLimit c → LiftableCone K F c
/-- `F` creates limits of shape `J` if `F` creates the limit of any diagram
`K : J ⥤ C`.
-/
class CreatesLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where
CreatesLimit : ∀ {K : J ⥤ C}, CreatesLimit K F := by infer_instance
-- This should be used with explicit universe variables.
/-- `F` creates limits if it creates limits of shape `J` for any `J`. -/
@[nolint checkUnivs, pp_with_univ]
class CreatesLimitsOfSize (F : C ⥤ D) where
CreatesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesLimitsOfShape J F := by
infer_instance
/-- `F` creates small limits if it creates limits of shape `J` for any small `J`. -/
abbrev CreatesLimits (F : C ⥤ D) :=
CreatesLimitsOfSize.{v₂, v₂} F
/-- Dual of definition 3.3.1 of [Riehl].
We say that `F` creates colimits of `K` if, given any limit cocone `c` for
`K ⋙ F` (i.e. below) we can lift it to a cocone "above", and further that `F`
reflects limits for `K`.
If `F` reflects isomorphisms, it suffices to show only that the lifted cocone is
a limit - see `createsColimitOfReflectsIso`.
-/
class CreatesColimit (K : J ⥤ C) (F : C ⥤ D) extends ReflectsColimit K F where
/-- any limit cocone can be lifted to a cocone above -/
lifts : ∀ c, IsColimit c → LiftableCocone K F c
/-- `F` creates colimits of shape `J` if `F` creates the colimit of any diagram
`K : J ⥤ C`.
-/
class CreatesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where
CreatesColimit : ∀ {K : J ⥤ C}, CreatesColimit K F := by infer_instance
-- This should be used with explicit universe variables.
/-- `F` creates colimits if it creates colimits of shape `J` for any small `J`. -/
@[nolint checkUnivs, pp_with_univ]
class CreatesColimitsOfSize (F : C ⥤ D) where
CreatesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesColimitsOfShape J F := by
infer_instance
/-- `F` creates small colimits if it creates colimits of shape `J` for any small `J`. -/
abbrev CreatesColimits (F : C ⥤ D) :=
CreatesColimitsOfSize.{v₂, v₂} F
-- see Note [lower instance priority]
attribute [instance 100] CreatesLimitsOfShape.CreatesLimit CreatesLimitsOfSize.CreatesLimitsOfShape
CreatesColimitsOfShape.CreatesColimit CreatesColimitsOfSize.CreatesColimitsOfShape
-- see Note [lower instance priority]
-- Interface to the `CreatesLimit` class.
/-- `liftLimit t` is the cone for `K` given by lifting the limit `t` for `K ⋙ F`. -/
def liftLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) :
Cone K :=
(CreatesLimit.lifts c t).liftedCone
/-- The lifted cone has an image isomorphic to the original cone. -/
def liftedLimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)}
(t : IsLimit c) : F.mapCone (liftLimit t) ≅ c :=
(CreatesLimit.lifts c t).validLift
lemma liftedLimitMapsToOriginal_inv_map_π
{K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)} (t : IsLimit c) (j : J) :
(liftedLimitMapsToOriginal t).inv.hom ≫ F.map ((liftLimit t).π.app j) = c.π.app j := by
rw [show F.map ((liftLimit t).π.app j) = (liftedLimitMapsToOriginal t).hom.hom ≫ c.π.app j
from (by simp), ← Category.assoc, ← Cone.category_comp_hom]
simp
/-- The lifted cone is a limit. -/
def liftedLimitIsLimit {K : J ⥤ C} {F : C ⥤ D} [CreatesLimit K F] {c : Cone (K ⋙ F)}
(t : IsLimit c) : IsLimit (liftLimit t) :=
isLimitOfReflects _ (IsLimit.ofIsoLimit t (liftedLimitMapsToOriginal t).symm)
/-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/
theorem hasLimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasLimit (K ⋙ F)] [CreatesLimit K F] :
HasLimit K :=
HasLimit.mk
{ cone := liftLimit (limit.isLimit (K ⋙ F))
isLimit := liftedLimitIsLimit _ }
/-- If `F` creates limits of shape `J`, and `D` has limits of shape `J`, then
`C` has limits of shape `J`.
-/
theorem hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (F : C ⥤ D) [HasLimitsOfShape J D]
[CreatesLimitsOfShape J F] : HasLimitsOfShape J C :=
⟨fun G => hasLimit_of_created G F⟩
/-- If `F` creates limits, and `D` has all limits, then `C` has all limits. -/
theorem hasLimits_of_hasLimits_createsLimits (F : C ⥤ D) [HasLimitsOfSize.{w, w'} D]
[CreatesLimitsOfSize.{w, w'} F] : HasLimitsOfSize.{w, w'} C :=
⟨fun _ _ => hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape F⟩
-- Interface to the `CreatesColimit` class.
/-- `liftColimit t` is the cocone for `K` given by lifting the colimit `t` for `K ⋙ F`. -/
def liftColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)}
(t : IsColimit c) : Cocone K :=
(CreatesColimit.lifts c t).liftedCocone
/-- The lifted cocone has an image isomorphic to the original cocone. -/
def liftedColimitMapsToOriginal {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)}
(t : IsColimit c) : F.mapCocone (liftColimit t) ≅ c :=
(CreatesColimit.lifts c t).validLift
/-- The lifted cocone is a colimit. -/
def liftedColimitIsColimit {K : J ⥤ C} {F : C ⥤ D} [CreatesColimit K F] {c : Cocone (K ⋙ F)}
(t : IsColimit c) : IsColimit (liftColimit t) :=
isColimitOfReflects _ (IsColimit.ofIsoColimit t (liftedColimitMapsToOriginal t).symm)
/-- If `F` creates the limit of `K` and `K ⋙ F` has a limit, then `K` has a limit. -/
theorem hasColimit_of_created (K : J ⥤ C) (F : C ⥤ D) [HasColimit (K ⋙ F)] [CreatesColimit K F] :
HasColimit K :=
HasColimit.mk
{ cocone := liftColimit (colimit.isColimit (K ⋙ F))
isColimit := liftedColimitIsColimit _ }
/-- If `F` creates colimits of shape `J`, and `D` has colimits of shape `J`, then
`C` has colimits of shape `J`.
-/
theorem hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape (F : C ⥤ D)
[HasColimitsOfShape J D] [CreatesColimitsOfShape J F] : HasColimitsOfShape J C :=
⟨fun G => hasColimit_of_created G F⟩
/-- If `F` creates colimits, and `D` has all colimits, then `C` has all colimits. -/
theorem hasColimits_of_hasColimits_createsColimits (F : C ⥤ D) [HasColimitsOfSize.{w, w'} D]
[CreatesColimitsOfSize.{w, w'} F] : HasColimitsOfSize.{w, w'} C :=
⟨fun _ _ => hasColimitsOfShape_of_hasColimitsOfShape_createsColimitsOfShape F⟩
instance (priority := 10) reflectsLimitsOfShapeOfCreatesLimitsOfShape (F : C ⥤ D)
[CreatesLimitsOfShape J F] : ReflectsLimitsOfShape J F where
instance (priority := 10) reflectsLimitsOfCreatesLimits (F : C ⥤ D)
[CreatesLimitsOfSize.{w, w'} F] : ReflectsLimitsOfSize.{w, w'} F where
instance (priority := 10) reflectsColimitsOfShapeOfCreatesColimitsOfShape (F : C ⥤ D)
[CreatesColimitsOfShape J F] : ReflectsColimitsOfShape J F where
instance (priority := 10) reflectsColimitsOfCreatesColimits (F : C ⥤ D)
[CreatesColimitsOfSize.{w, w'} F] : ReflectsColimitsOfSize.{w, w'} F where
/-- A helper to show a functor creates limits. In particular, if we can show
that for any limit cone `c` for `K ⋙ F`, there is a lift of it which is
a limit and `F` reflects isomorphisms, then `F` creates limits.
Usually, `F` creating limits says that _any_ lift of `c` is a limit, but
here we only need to show that our particular lift of `c` is a limit.
-/
structure LiftsToLimit (K : J ⥤ C) (F : C ⥤ D) (c : Cone (K ⋙ F)) (t : IsLimit c) extends
LiftableCone K F c where
/-- the lifted cone is limit -/
makesLimit : IsLimit liftedCone
/-- A helper to show a functor creates colimits. In particular, if we can show
that for any limit cocone `c` for `K ⋙ F`, there is a lift of it which is
a limit and `F` reflects isomorphisms, then `F` creates colimits.
Usually, `F` creating colimits says that _any_ lift of `c` is a colimit, but
here we only need to show that our particular lift of `c` is a colimit.
-/
structure LiftsToColimit (K : J ⥤ C) (F : C ⥤ D) (c : Cocone (K ⋙ F)) (t : IsColimit c) extends
LiftableCocone K F c where
/-- the lifted cocone is colimit -/
makesColimit : IsColimit liftedCocone
/-- If `F` reflects isomorphisms and we can lift any limit cone to a limit cone,
then `F` creates limits.
In particular here we don't need to assume that F reflects limits.
-/
def createsLimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms]
(h : ∀ c t, LiftsToLimit K F c t) : CreatesLimit K F where
lifts c t := (h c t).toLiftableCone
toReflectsLimit :=
{ reflects := fun {d} hd => ⟨by
let d' : Cone K := (h (F.mapCone d) hd).toLiftableCone.liftedCone
let i : F.mapCone d' ≅ F.mapCone d :=
(h (F.mapCone d) hd).toLiftableCone.validLift
let hd' : IsLimit d' := (h (F.mapCone d) hd).makesLimit
let f : d ⟶ d' := hd'.liftConeMorphism d
have : (Cones.functoriality K F).map f = i.inv :=
(hd.ofIsoLimit i.symm).uniq_cone_morphism
haveI : IsIso ((Cones.functoriality K F).map f) := by
rw [this]
infer_instance
haveI : IsIso f := isIso_of_reflects_iso f (Cones.functoriality K F)
exact IsLimit.ofIsoLimit hd' (asIso f).symm⟩ }
/-- If `F` reflects isomorphisms and we can lift a single limit cone to a limit cone, then `F`
creates limits. Note that unlike `createsLimitOfReflectsIso`, to apply this result it is
necessary to know that `K ⋙ F` actually has a limit. -/
def createsLimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms]
{c : Cone (K ⋙ F)} (hc : IsLimit c) (h : LiftsToLimit K F c hc) : CreatesLimit K F :=
createsLimitOfReflectsIso fun _ t =>
{ liftedCone := h.liftedCone
validLift := h.validLift ≪≫ IsLimit.uniqueUpToIso hc t
makesLimit := h.makesLimit }
/-- If `F` reflects isomorphisms, and we already know that the limit exists in the source and `F`
preserves it, then `F` creates that limit. -/
def createsLimitOfReflectsIsomorphismsOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms]
[HasLimit K] [PreservesLimit K F] : CreatesLimit K F :=
createsLimitOfReflectsIso' (isLimitOfPreserves F (limit.isLimit _))
⟨⟨_, Iso.refl _⟩, limit.isLimit _⟩
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cone maps,
-- so the constructed limits may not be ideal, definitionally.
/--
When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to exhibit a lift
of a limit cone for `K ⋙ F`.
-/
def createsLimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
{l : Cone (K ⋙ F)} (hl : IsLimit l) (c : Cone K) (i : F.mapCone c ≅ l) :
CreatesLimit K F :=
createsLimitOfReflectsIso' hl ⟨⟨c, i⟩, isLimitOfReflects F (IsLimit.ofIsoLimit hl i.symm)⟩
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cone maps,
-- so the constructed limits may not be ideal, definitionally.
/-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K`
it suffices to exhibit a lift of the chosen limit cone for `K ⋙ F`.
-/
def createsLimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
[HasLimit (K ⋙ F)] (c : Cone K) (i : F.mapCone c ≅ limit.cone (K ⋙ F)) :
CreatesLimit K F :=
createsLimitOfFullyFaithfulOfLift' (limit.isLimit _) c i
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cone maps,
-- so the constructed limits may not be ideal, definitionally.
/--
When `F` is fully faithful, to show that `F` creates the limit for `K` it suffices to show that a
limit point is in the essential image of `F`.
-/
def createsLimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
{l : Cone (K ⋙ F)} (hl : IsLimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesLimit K F :=
createsLimitOfFullyFaithfulOfLift' hl
{ pt := X
π :=
{ app := fun j => F.preimage (i.hom ≫ l.π.app j)
naturality := fun Y Z f =>
F.map_injective <| by
simpa using (l.w f).symm } }
(Cones.ext i fun j => by simp only [Functor.map_preimage, Functor.mapCone_π_app])
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cone maps,
-- so the constructed limits may not be ideal, definitionally.
/-- When `F` is fully faithful, and `HasLimit (K ⋙ F)`, to show that `F` creates the limit for `K`
it suffices to show that the chosen limit point is in the essential image of `F`.
-/
def createsLimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
[HasLimit (K ⋙ F)] (X : C) (i : F.obj X ≅ limit (K ⋙ F)) : CreatesLimit K F :=
createsLimitOfFullyFaithfulOfIso' (limit.isLimit _) X i
/-- A fully faithful functor that preserves a limit that exists also creates the limit. -/
def createsLimitOfFullyFaithfulOfPreserves {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
[HasLimit K] [PreservesLimit K F] : CreatesLimit K F :=
createsLimitOfFullyFaithfulOfLift' (isLimitOfPreserves _ (limit.isLimit K)) _ (Iso.refl _)
-- see Note [lower instance priority]
/-- `F` preserves the limit of `K` if it creates the limit and `K ⋙ F` has the limit. -/
instance (priority := 100) preservesLimit_of_createsLimit_and_hasLimit (K : J ⥤ C) (F : C ⥤ D)
[CreatesLimit K F] [HasLimit (K ⋙ F)] : PreservesLimit K F where
preserves t := ⟨IsLimit.ofIsoLimit (limit.isLimit _)
((liftedLimitMapsToOriginal (limit.isLimit _)).symm ≪≫
(Cones.functoriality K F).mapIso ((liftedLimitIsLimit (limit.isLimit _)).uniqueUpToIso t))⟩
-- see Note [lower instance priority]
/-- `F` preserves the limit of shape `J` if it creates these limits and `D` has them. -/
instance (priority := 100) preservesLimitOfShape_of_createsLimitsOfShape_and_hasLimitsOfShape
(F : C ⥤ D) [CreatesLimitsOfShape J F] [HasLimitsOfShape J D] : PreservesLimitsOfShape J F where
-- see Note [lower instance priority]
/-- `F` preserves limits if it creates limits and `D` has limits. -/
instance (priority := 100) preservesLimits_of_createsLimits_and_hasLimits (F : C ⥤ D)
[CreatesLimitsOfSize.{w, w'} F] [HasLimitsOfSize.{w, w'} D] :
PreservesLimitsOfSize.{w, w'} F where
/-- If `F` reflects isomorphisms and we can lift any colimit cocone to a colimit cocone,
then `F` creates colimits.
In particular here we don't need to assume that F reflects colimits.
-/
def createsColimitOfReflectsIso {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms]
(h : ∀ c t, LiftsToColimit K F c t) : CreatesColimit K F where
lifts c t := (h c t).toLiftableCocone
toReflectsColimit :=
{ reflects := fun {d} hd => ⟨by
let d' : Cocone K := (h (F.mapCocone d) hd).toLiftableCocone.liftedCocone
let i : F.mapCocone d' ≅ F.mapCocone d :=
(h (F.mapCocone d) hd).toLiftableCocone.validLift
let hd' : IsColimit d' := (h (F.mapCocone d) hd).makesColimit
let f : d' ⟶ d := hd'.descCoconeMorphism d
have : (Cocones.functoriality K F).map f = i.hom :=
(hd.ofIsoColimit i.symm).uniq_cocone_morphism
haveI : IsIso ((Cocones.functoriality K F).map f) := by
rw [this]
infer_instance
haveI := isIso_of_reflects_iso f (Cocones.functoriality K F)
exact IsColimit.ofIsoColimit hd' (asIso f)⟩ }
/-- If `F` reflects isomorphisms and we can lift a single colimit cocone to a colimit cocone, then
`F` creates limits. Note that unlike `createsColimitOfReflectsIso`, to apply this result it is
necessary to know that `K ⋙ F` actually has a colimit. -/
def createsColimitOfReflectsIso' {K : J ⥤ C} {F : C ⥤ D} [F.ReflectsIsomorphisms]
{c : Cocone (K ⋙ F)} (hc : IsColimit c) (h : LiftsToColimit K F c hc) : CreatesColimit K F :=
createsColimitOfReflectsIso fun _ t =>
{ liftedCocone := h.liftedCocone
validLift := h.validLift ≪≫ IsColimit.uniqueUpToIso hc t
makesColimit := h.makesColimit }
/-- If `F` reflects isomorphisms, and we already know that the colimit exists in the source and `F`
preserves it, then `F` creates that colimit. -/
def createsColimitOfReflectsIsomorphismsOfPreserves {K : J ⥤ C} {F : C ⥤ D}
[F.ReflectsIsomorphisms] [HasColimit K] [PreservesColimit K F] : CreatesColimit K F :=
createsColimitOfReflectsIso' (isColimitOfPreserves F (colimit.isColimit _))
⟨⟨_, Iso.refl _⟩, colimit.isColimit _⟩
@[deprecated (since := "2025-02-01")]
noncomputable alias createsColimitOfFullyFaithfulOfPreserves :=
createsColimitOfReflectsIsomorphismsOfPreserves
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cocone maps,
-- so the constructed colimits may not be ideal, definitionally.
/--
When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to exhibit a
lift of a colimit cocone for `K ⋙ F`.
-/
def createsColimitOfFullyFaithfulOfLift' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
{l : Cocone (K ⋙ F)} (hl : IsColimit l) (c : Cocone K) (i : F.mapCocone c ≅ l) :
CreatesColimit K F :=
createsColimitOfReflectsIso' hl ⟨⟨c, i⟩, isColimitOfReflects F (IsColimit.ofIsoColimit hl i.symm)⟩
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cocone maps,
-- so the constructed colimits may not be ideal, definitionally.
/--
When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K`
it suffices to exhibit a lift of the chosen colimit cocone for `K ⋙ F`.
-/
def createsColimitOfFullyFaithfulOfLift {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
[HasColimit (K ⋙ F)] (c : Cocone K) (i : F.mapCocone c ≅ colimit.cocone (K ⋙ F)) :
CreatesColimit K F :=
createsColimitOfFullyFaithfulOfLift' (colimit.isColimit _) c i
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cocone maps,
-- so the constructed colimits may not be ideal, definitionally.
/--
When `F` is fully faithful, to show that `F` creates the colimit for `K` it suffices to show that
a colimit point is in the essential image of `F`.
-/
def createsColimitOfFullyFaithfulOfIso' {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
{l : Cocone (K ⋙ F)} (hl : IsColimit l) (X : C) (i : F.obj X ≅ l.pt) : CreatesColimit K F :=
createsColimitOfFullyFaithfulOfLift' hl
{ pt := X
ι :=
{ app := fun j => F.preimage (l.ι.app j ≫ i.inv)
naturality := fun Y Z f =>
F.map_injective <| by
simpa [← cancel_mono i.hom] using l.w f } }
(Cocones.ext i fun j => by simp)
-- Notice however that even if the isomorphism is `Iso.refl _`,
-- this construction will insert additional identity morphisms in the cocone maps,
-- so the constructed colimits may not be ideal, definitionally.
/--
When `F` is fully faithful, and `HasColimit (K ⋙ F)`, to show that `F` creates the colimit for `K`
it suffices to show that the chosen colimit point is in the essential image of `F`.
-/
def createsColimitOfFullyFaithfulOfIso {K : J ⥤ C} {F : C ⥤ D} [F.Full] [F.Faithful]
[HasColimit (K ⋙ F)] (X : C) (i : F.obj X ≅ colimit (K ⋙ F)) : CreatesColimit K F :=
createsColimitOfFullyFaithfulOfIso' (colimit.isColimit _) X i
-- see Note [lower instance priority]
/-- `F` preserves the colimit of `K` if it creates the colimit and `K ⋙ F` has the colimit. -/
instance (priority := 100) preservesColimit_of_createsColimit_and_hasColimit (K : J ⥤ C) (F : C ⥤ D)
[CreatesColimit K F] [HasColimit (K ⋙ F)] : PreservesColimit K F where
preserves t :=
⟨IsColimit.ofIsoColimit (colimit.isColimit _)
((liftedColimitMapsToOriginal (colimit.isColimit _)).symm ≪≫
(Cocones.functoriality K F).mapIso
((liftedColimitIsColimit (colimit.isColimit _)).uniqueUpToIso t))⟩
-- see Note [lower instance priority]
/-- `F` preserves the colimit of shape `J` if it creates these colimits and `D` has them. -/
instance (priority := 100) preservesColimitOfShape_of_createsColimitsOfShape_and_hasColimitsOfShape
(F : C ⥤ D) [CreatesColimitsOfShape J F] [HasColimitsOfShape J D] :
PreservesColimitsOfShape J F where
-- see Note [lower instance priority]
/-- `F` preserves limits if it creates limits and `D` has limits. -/
instance (priority := 100) preservesColimits_of_createsColimits_and_hasColimits (F : C ⥤ D)
[CreatesColimitsOfSize.{w, w'} F] [HasColimitsOfSize.{w, w'} D] :
PreservesColimitsOfSize.{w, w'} F where
/-- Transfer creation of limits along a natural isomorphism in the diagram. -/
def createsLimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesLimit K₁ F] :
CreatesLimit K₂ F :=
{ reflectsLimit_of_iso_diagram F h with
lifts := fun c t =>
let t' := (IsLimit.postcomposeInvEquiv (isoWhiskerRight h F :) c).symm t
{ liftedCone := (Cones.postcompose h.hom).obj (liftLimit t')
validLift :=
Functor.mapConePostcompose F ≪≫
(Cones.postcompose (isoWhiskerRight h F).hom).mapIso (liftedLimitMapsToOriginal t') ≪≫
Cones.ext (Iso.refl _) fun j => by
dsimp
rw [Category.assoc, ← F.map_comp]
simp } }
/-- If `F` creates the limit of `K` and `F ≅ G`, then `G` creates the limit of `K`. -/
def createsLimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimit K F] : CreatesLimit K G where
lifts c t :=
{ liftedCone := liftLimit ((IsLimit.postcomposeInvEquiv (isoWhiskerLeft K h :) c).symm t)
validLift := by
refine (IsLimit.mapConeEquiv h ?_).uniqueUpToIso t
apply IsLimit.ofIsoLimit _ (liftedLimitMapsToOriginal _).symm
apply (IsLimit.postcomposeInvEquiv _ _).symm t }
toReflectsLimit := reflectsLimit_of_natIso _ h
/-- If `F` creates limits of shape `J` and `F ≅ G`, then `G` creates limits of shape `J`. -/
def createsLimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfShape J F] :
CreatesLimitsOfShape J G where CreatesLimit := createsLimitOfNatIso h
/-- If `F` creates limits and `F ≅ G`, then `G` creates limits. -/
def createsLimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesLimitsOfSize.{w, w'} F] :
CreatesLimitsOfSize.{w, w'} G where
CreatesLimitsOfShape := createsLimitsOfShapeOfNatIso h
/-- If `F` creates limits of shape `J` and `J ≌ J'`, then `F` creates limits of shape `J'`. -/
def createsLimitsOfShapeOfEquiv {J' : Type w₁} [Category.{w'₁} J'] (e : J ≌ J') (F : C ⥤ D)
[CreatesLimitsOfShape J F] : CreatesLimitsOfShape J' F where
CreatesLimit {K} :=
{ lifts c hc := by
refine ⟨(Cones.whiskeringEquivalence e).inverse.obj
(liftLimit (hc.whiskerEquivalence e)), ?_⟩
letI inner := (Cones.whiskeringEquivalence (F := K ⋙ F) e).inverse.mapIso
(liftedLimitMapsToOriginal (K := e.functor ⋙ K) (hc.whiskerEquivalence e))
refine ?_ ≪≫ inner ≪≫ ((Cones.whiskeringEquivalence e).unitIso.app c).symm
exact Cones.ext (Iso.refl _)
toReflectsLimit := have := reflectsLimitsOfShape_of_equiv e F; inferInstance }
/-- Transfer creation of colimits along a natural isomorphism in the diagram. -/
def createsColimitOfIsoDiagram {K₁ K₂ : J ⥤ C} (F : C ⥤ D) (h : K₁ ≅ K₂) [CreatesColimit K₁ F] :
CreatesColimit K₂ F :=
{ reflectsColimit_of_iso_diagram F h with
lifts := fun c t =>
let t' := (IsColimit.precomposeHomEquiv (isoWhiskerRight h F :) c).symm t
{ liftedCocone := (Cocones.precompose h.inv).obj (liftColimit t')
validLift :=
Functor.mapCoconePrecompose F ≪≫
(Cocones.precompose (isoWhiskerRight h F).inv).mapIso
(liftedColimitMapsToOriginal t') ≪≫
Cocones.ext (Iso.refl _) fun j => by
dsimp
rw [← F.map_comp_assoc]
simp } }
/-- If `F` creates the colimit of `K` and `F ≅ G`, then `G` creates the colimit of `K`. -/
def createsColimitOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimit K F] : CreatesColimit K G where
lifts c t :=
{ liftedCocone := liftColimit ((IsColimit.precomposeHomEquiv (isoWhiskerLeft K h :) c).symm t)
validLift := by
refine (IsColimit.mapCoconeEquiv h ?_).uniqueUpToIso t
apply IsColimit.ofIsoColimit _ (liftedColimitMapsToOriginal _).symm
apply (IsColimit.precomposeHomEquiv _ _).symm t }
toReflectsColimit := reflectsColimit_of_natIso _ h
/-- If `F` creates colimits of shape `J` and `F ≅ G`, then `G` creates colimits of shape `J`. -/
def createsColimitsOfShapeOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfShape J F] :
CreatesColimitsOfShape J G where CreatesColimit := createsColimitOfNatIso h
/-- If `F` creates colimits and `F ≅ G`, then `G` creates colimits. -/
def createsColimitsOfNatIso {F G : C ⥤ D} (h : F ≅ G) [CreatesColimitsOfSize.{w, w'} F] :
CreatesColimitsOfSize.{w, w'} G where
CreatesColimitsOfShape := createsColimitsOfShapeOfNatIso h
/-- If `F` creates colimits of shape `J` and `J ≌ J'`, then `F` creates colimits of shape `J'`. -/
def createsColimitsOfShapeOfEquiv {J' : Type w₁} [Category.{w'₁} J'] (e : J ≌ J') (F : C ⥤ D)
[CreatesColimitsOfShape J F] : CreatesColimitsOfShape J' F where
CreatesColimit {K} :=
{ lifts c hc := by
refine ⟨(Cocones.whiskeringEquivalence e).inverse.obj
(liftColimit (hc.whiskerEquivalence e)), ?_⟩
letI inner := (Cocones.whiskeringEquivalence (F := K ⋙ F) e).inverse.mapIso
(liftedColimitMapsToOriginal (K := e.functor ⋙ K) (hc.whiskerEquivalence e))
refine ?_ ≪≫ inner ≪≫ ((Cocones.whiskeringEquivalence e).unitIso.app c).symm
exact Cocones.ext (Iso.refl _)
toReflectsColimit := have := reflectsColimitsOfShape_of_equiv e F; inferInstance }
-- For the inhabited linter later.
/-- If F creates the limit of K, any cone lifts to a limit. -/
def liftsToLimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F))
(t : IsLimit c) : LiftsToLimit K F c t where
liftedCone := liftLimit t
validLift := liftedLimitMapsToOriginal t
makesLimit := liftedLimitIsLimit t
-- For the inhabited linter later.
/-- If F creates the colimit of K, any cocone lifts to a colimit. -/
def liftsToColimitOfCreates (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F))
(t : IsColimit c) : LiftsToColimit K F c t where
liftedCocone := liftColimit t
validLift := liftedColimitMapsToOriginal t
makesColimit := liftedColimitIsColimit t
/-- Any cone lifts through the identity functor. -/
def idLiftsCone (c : Cone (K ⋙ 𝟭 C)) : LiftableCone K (𝟭 C) c where
liftedCone :=
{ pt := c.pt
π := c.π ≫ K.rightUnitor.hom }
validLift := Cones.ext (Iso.refl _)
/-- The identity functor creates all limits. -/
instance idCreatesLimits : CreatesLimitsOfSize.{w, w'} (𝟭 C) where
CreatesLimitsOfShape :=
{ CreatesLimit := { lifts := fun c _ => idLiftsCone c } }
/-- Any cocone lifts through the identity functor. -/
def idLiftsCocone (c : Cocone (K ⋙ 𝟭 C)) : LiftableCocone K (𝟭 C) c where
liftedCocone :=
{ pt := c.pt
ι := K.rightUnitor.inv ≫ c.ι }
validLift := Cocones.ext (Iso.refl _)
/-- The identity functor creates all colimits. -/
instance idCreatesColimits : CreatesColimitsOfSize.{w, w'} (𝟭 C) where
CreatesColimitsOfShape :=
{ CreatesColimit := { lifts := fun c _ => idLiftsCocone c } }
/-- Satisfy the inhabited linter -/
instance inhabitedLiftableCone (c : Cone (K ⋙ 𝟭 C)) : Inhabited (LiftableCone K (𝟭 C) c) :=
⟨idLiftsCone c⟩
instance inhabitedLiftableCocone (c : Cocone (K ⋙ 𝟭 C)) : Inhabited (LiftableCocone K (𝟭 C) c) :=
⟨idLiftsCocone c⟩
/-- Satisfy the inhabited linter -/
instance inhabitedLiftsToLimit (K : J ⥤ C) (F : C ⥤ D) [CreatesLimit K F] (c : Cone (K ⋙ F))
(t : IsLimit c) : Inhabited (LiftsToLimit _ _ _ t) :=
⟨liftsToLimitOfCreates K F c t⟩
instance inhabitedLiftsToColimit (K : J ⥤ C) (F : C ⥤ D) [CreatesColimit K F] (c : Cocone (K ⋙ F))
(t : IsColimit c) : Inhabited (LiftsToColimit _ _ _ t) :=
⟨liftsToColimitOfCreates K F c t⟩
section Comp
variable {E : Type u₃} [ℰ : Category.{v₃} E]
variable (F : C ⥤ D) (G : D ⥤ E)
instance compCreatesLimit [CreatesLimit K F] [CreatesLimit (K ⋙ F) G] :
CreatesLimit K (F ⋙ G) where
lifts c t := by
let c' : Cone ((K ⋙ F) ⋙ G) := c
let t' : IsLimit c' := t
exact
{ liftedCone := liftLimit (liftedLimitIsLimit t')
validLift := (Cones.functoriality (K ⋙ F) G).mapIso
(liftedLimitMapsToOriginal (liftedLimitIsLimit t')) ≪≫
liftedLimitMapsToOriginal t' }
instance compCreatesLimitsOfShape [CreatesLimitsOfShape J F] [CreatesLimitsOfShape J G] :
CreatesLimitsOfShape J (F ⋙ G) where CreatesLimit := inferInstance
instance compCreatesLimits [CreatesLimitsOfSize.{w, w'} F] [CreatesLimitsOfSize.{w, w'} G] :
CreatesLimitsOfSize.{w, w'} (F ⋙ G) where CreatesLimitsOfShape := inferInstance
instance compCreatesColimit [CreatesColimit K F] [CreatesColimit (K ⋙ F) G] :
CreatesColimit K (F ⋙ G) where
lifts c t :=
let c' : Cocone ((K ⋙ F) ⋙ G) := c
let t' : IsColimit c' := t
{ liftedCocone := liftColimit (liftedColimitIsColimit t')
validLift :=
(Cocones.functoriality (K ⋙ F) G).mapIso
(liftedColimitMapsToOriginal (liftedColimitIsColimit t')) ≪≫
liftedColimitMapsToOriginal t' }
instance compCreatesColimitsOfShape [CreatesColimitsOfShape J F] [CreatesColimitsOfShape J G] :
CreatesColimitsOfShape J (F ⋙ G) where CreatesColimit := inferInstance
instance compCreatesColimits [CreatesColimitsOfSize.{w, w'} F] [CreatesColimitsOfSize.{w, w'} G] :
CreatesColimitsOfSize.{w, w'} (F ⋙ G) where CreatesColimitsOfShape := inferInstance
end Comp
end Creates
end CategoryTheory
|
Localization.lean
|
/-
Copyright (c) 2025 Nailin Guan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nailin Guan
-/
import Mathlib.Algebra.Module.LocalizedModule.Basic
import Mathlib.RingTheory.Ideal.AssociatedPrime.Basic
import Mathlib.RingTheory.Localization.AtPrime.Basic
/-!
# Associated primes of localized module
This file mainly proves the relation between `Ass(S⁻¹M)` and `Ass(M)`
# Main Results
* `associatedPrimes.mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule` :
for an `R` module `M`, if `p` is a prime ideal of `S⁻¹R` and `p ∩ R ∈ Ass(M)` then
`p ∈ Ass (S⁻¹M)`.
TODO: prove the reverse when `p` is finitely generated and
get `Ass (S⁻¹M) = Ass(M) ∩ Spec(S⁻¹R)` when `R` noetherian.
TODO: deduce from the above that every minimal element in support is in `Ass(M)`.
-/
variable {R : Type*} [CommRing R] (S : Submonoid R) (R' : Type*) [CommRing R'] [Algebra R R']
[IsLocalization S R']
variable {M M' : Type*} [AddCommGroup M] [Module R M] [AddCommGroup M'] [Module R M']
(f : M →ₗ[R] M') [IsLocalizedModule S f] [Module R' M'] [IsScalarTower R R' M']
open IsLocalRing LinearMap
namespace Module.associatedPrimes
include S f in
lemma mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule
(p : Ideal R') [p.IsPrime]
(ass : p.comap (algebraMap R R') ∈ associatedPrimes R M) :
p ∈ associatedPrimes R' M' := by
rcases ass with ⟨hp, x, hx⟩
constructor
· /- use the following to remove `p.IsPrime`
exact (IsLocalization.isPrime_iff_isPrime_disjoint S _ _).mpr
⟨hp, (IsLocalization.disjoint_comap_iff S R' p).mpr (p ≠ ⊤)⟩ -/
assumption
· use f x
ext t
rcases IsLocalization.mk'_surjective S t with ⟨r, s, hrs⟩
rw [← IsLocalizedModule.mk'_one S, ← hrs, mem_ker, toSpanSingleton_apply,
IsLocalizedModule.mk'_smul_mk', mul_one, IsLocalizedModule.mk'_eq_zero']
refine ⟨fun h ↦ ?_, fun ⟨t, ht⟩ ↦ ?_⟩
· use 1
simp only [← toSpanSingleton_apply, one_smul, ← mem_ker, ← hx, Ideal.mem_comap]
have : (algebraMap R R') r =
IsLocalization.mk' R' r s * IsLocalization.mk' R' s.1 (1 : S) := by
rw [← IsLocalization.mk'_one (M := S) R', ← sub_eq_zero, ← IsLocalization.mk'_mul,
← IsLocalization.mk'_sub]
simp
rw [this]
exact Ideal.IsTwoSided.mul_mem_of_left _ h
· have : t • r • x = (t.1 * r) • x := smul_smul t.1 r x
rw [this, ← LinearMap.toSpanSingleton_apply, ← LinearMap.mem_ker, ← hx, Ideal.mem_comap,
← IsLocalization.mk'_one (M := S) R'] at ht
have : IsLocalization.mk' R' r s =
IsLocalization.mk' (M := S) R' (t.1 * r) 1 * IsLocalization.mk' R' 1 (t * s) := by
rw [← IsLocalization.mk'_mul, mul_one, one_mul, ← sub_eq_zero, ← IsLocalization.mk'_sub,
Submonoid.coe_mul]
simp [← mul_assoc, mul_comm r t.1, IsLocalization.mk'_zero]
simpa [this] using Ideal.IsTwoSided.mul_mem_of_left _ ht
lemma mem_associatePrimes_localizedModule_atPrime_of_mem_associated_primes
{p : Ideal R} [p.IsPrime] (ass : p ∈ associatedPrimes R M) :
maximalIdeal (Localization.AtPrime p) ∈
associatedPrimes (Localization.AtPrime p) (LocalizedModule p.primeCompl M) := by
apply mem_associatePrimes_of_comap_mem_associatePrimes_isLocalizedModule
p.primeCompl (Localization.AtPrime p) (LocalizedModule.mkLinearMap p.primeCompl M)
simpa [Localization.AtPrime.comap_maximalIdeal] using ass
end Module.associatedPrimes
|
DivergenceTheorem.lean
|
/-
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.BoxIntegral.DivergenceTheorem
import Mathlib.Analysis.BoxIntegral.Integrability
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Equiv
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
/-!
# Divergence theorem for Bochner integral
In this file we prove the Divergence theorem for Bochner integral on a box in
`ℝⁿ⁺¹ = Fin (n + 1) → ℝ`. More precisely, we prove the following theorem.
Let `E` be a complete normed space. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is
continuous on a rectangular box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, differentiable on its interior with
derivative `f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹`, and the divergence `fun x ↦ ∑ i, f' x eᵢ i`
is integrable on `[a, b]`, where `eᵢ = Pi.single i 1` is the `i`-th basis vector,
then its integral is equal to the sum of integrals of `f` over the faces of `[a, b]`,
taken with appropriate signs. Moreover, the same
is true if the function is not differentiable at countably many points of the interior of `[a, b]`.
Once we prove the general theorem, we deduce corollaries for functions `ℝ → E` and pairs of
functions `(ℝ × ℝ) → E`.
## Notations
We use the following local notation to make the statement more readable. Note that the documentation
website shows the actual terms, not those abbreviated using local notations.
Porting note (Yury Kudryashov): I disabled some of these notations because I failed to make them
work with Lean 4.
* `ℝⁿ`, `ℝⁿ⁺¹`, `Eⁿ⁺¹`: `Fin n → ℝ`, `Fin (n + 1) → ℝ`, `Fin (n + 1) → E`;
* `face i`: the `i`-th face of the box `[a, b]` as a closed segment in `ℝⁿ`, namely
`[a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]`;
* `e i` : `i`-th basis vector `Pi.single i 1`;
* `frontFace i`, `backFace i`: embeddings `ℝⁿ → ℝⁿ⁺¹` corresponding to the front face
`{x | x i = b i}` and back face `{x | x i = a i}` of the box `[a, b]`, respectively.
They are given by `Fin.insertNth i (b i)` and `Fin.insertNth i (a i)`.
## TODO
* Add a version that assumes existence and integrability of partial derivatives.
* Restore local notations for find another way to make the statements more readable.
## Tags
divergence theorem, Bochner integral
-/
open Set Finset TopologicalSpace Function BoxIntegral MeasureTheory Filter
open scoped Topology Interval
universe u
namespace MeasureTheory
variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E]
section
variable {n : ℕ}
local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t)
local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t)
local notation "e " i => Pi.single i 1
section
/-!
### Divergence theorem for functions on `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`.
In this section we use the divergence theorem for a Henstock-Kurzweil-like integral
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` to prove the divergence
theorem for Bochner integral. The divergence theorem for Bochner integral
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` assumes that the function
itself is continuous on a closed box, differentiable at all but countably many points of its
interior, and the divergence is integrable on the box.
This statement differs from `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt`
in several aspects.
* We use Bochner integral instead of a Henstock-Kurzweil integral. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁`. As a side effect
of this change, we need to assume that the divergence is integrable.
* We don't assume differentiability on the boundary of the box. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂`. To prove it, we
choose an increasing sequence of smaller boxes that cover the interior of the original box, then
apply the previous lemma to these smaller boxes and take the limit of both sides of the equation.
* We assume `a ≤ b` instead of `∀ i, a i < b i`. This is the last step of the proof, and it is done
in the main theorem `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`.
-/
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. This is exactly
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` reformulated for the
Bochner integral. -/
private theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (I : Box (Fin (n + 1)))
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹)
(hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x)
(Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
wlog hE : CompleteSpace E generalizing
· simp [integral, hE]
simp only [← setIntegral_congr_set (Box.coe_ae_eq_Icc _)]
have A := (Hi.mono_set Box.coe_subset_Icc).hasBoxIntegral ⊥ rfl
have B :=
hasIntegral_GP_divergence_of_forall_hasDerivWithinAt I f f' (s ∩ Box.Icc I)
(hs.mono inter_subset_left) (fun x hx => Hc _ hx.2) fun x hx =>
Hd _ ⟨hx.1, fun h => hx.2 ⟨h, hx.1⟩⟩
rw [continuousOn_pi] at Hc
refine (A.unique B).trans (sum_congr rfl fun i _ => ?_)
refine congr_arg₂ Sub.sub ?_ ?_
· have := Box.continuousOn_face_Icc (Hc i) (Set.right_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
· have := Box.continuousOn_face_Icc (Hc i) (Set.left_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. Compared to the previous
lemma, here we drop the assumption of differentiability on the boundary of the box. -/
private theorem integral_divergence_of_hasFDerivAt_off_countable_aux₂ (I : Box (Fin (n + 1)))
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹)
(s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ Box.Ioo I \ s, HasFDerivAt f (f' x) x)
(Hi : IntegrableOn (∑ i, f' · (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
/- Choose a monotone sequence `J k` of subboxes that cover the interior of `I` and prove that
these boxes satisfy the assumptions of the previous lemma. -/
rcases I.exists_seq_mono_tendsto with ⟨J, hJ_sub, hJl, hJu⟩
have hJ_sub' : ∀ k, Box.Icc (J k) ⊆ Box.Icc I := fun k => (hJ_sub k).trans I.Ioo_subset_Icc
have hJ_le : ∀ k, J k ≤ I := fun k => Box.le_iff_Icc.2 (hJ_sub' k)
have HcJ : ∀ k, ContinuousOn f (Box.Icc (J k)) := fun k => Hc.mono (hJ_sub' k)
have HdJ : ∀ (k), ∀ x ∈ (Box.Icc (J k)) \ s, HasFDerivWithinAt f (f' x) (Box.Icc (J k)) x :=
fun k x hx => (Hd x ⟨hJ_sub k hx.1, hx.2⟩).hasFDerivWithinAt
have HiJ : ∀ k, IntegrableOn (∑ i, f' · (e i) i) (Box.Icc (J k)) volume := fun k =>
Hi.mono_set (hJ_sub' k)
-- Apply the previous lemma to `J k`.
have HJ_eq := fun k =>
integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (J k) f f' s hs (HcJ k) (HdJ k)
(HiJ k)
-- Note that the LHS of `HJ_eq k` tends to the LHS of the goal as `k → ∞`.
have hI_tendsto :
Tendsto (fun k => ∫ x in Box.Icc (J k), ∑ i, f' x (e i) i) atTop
(𝓝 (∫ x in Box.Icc I, ∑ i, f' x (e i) i)) := by
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _)] at Hi ⊢
rw [← Box.iUnion_Ioo_of_tendsto J.monotone hJl hJu] at Hi ⊢
exact tendsto_setIntegral_of_monotone (fun k => (J k).measurableSet_Ioo)
(Box.Ioo.comp J).monotone Hi
-- Thus it suffices to prove the same about the RHS.
refine tendsto_nhds_unique_of_eventuallyEq hI_tendsto ?_ (Eventually.of_forall HJ_eq)
clear hI_tendsto
rw [tendsto_pi_nhds] at hJl hJu
/- We'll need to prove a similar statement about the integrals over the front sides and the
integrals over the back sides. In order to avoid repeating ourselves, we formulate a lemma. -/
suffices ∀ (i : Fin (n + 1)) (c : ℕ → ℝ) (d), (∀ k, c k ∈ Icc (I.lower i) (I.upper i)) →
Tendsto c atTop (𝓝 d) →
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth (c k) x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) by
rw [Box.Icc_eq_pi] at hJ_sub'
refine tendsto_finset_sum _ fun i _ => (this _ _ _ ?_ (hJu _)).sub (this _ _ _ ?_ (hJl _))
exacts [fun k => hJ_sub' k (J k).upper_mem_Icc _ trivial, fun k =>
hJ_sub' k (J k).lower_mem_Icc _ trivial]
intro i c d hc hcd
/- First we prove that the integrals of the restriction of `f` to `{x | x i = d}` over increasing
boxes `((J k).face i).Icc` tend to the desired limit. The proof mostly repeats the one above. -/
have hd : d ∈ Icc (I.lower i) (I.upper i) :=
isClosed_Icc.mem_of_tendsto hcd (Eventually.of_forall hc)
have Hic : ∀ k, IntegrableOn (fun x => f (i.insertNth (c k) x) i) (Box.Icc (I.face i)) := fun k =>
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) (hc k)).integrableOn_Icc
have Hid : IntegrableOn (fun x => f (i.insertNth d x) i) (Box.Icc (I.face i)) :=
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) hd).integrableOn_Icc
have H :
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) := by
have hIoo : (⋃ k, Box.Ioo ((J k).face i)) = Box.Ioo (I.face i) :=
Box.iUnion_Ioo_of_tendsto ((Box.monotone_face i).comp J.monotone)
(tendsto_pi_nhds.2 fun _ => hJl _) (tendsto_pi_nhds.2 fun _ => hJu _)
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _), ← hIoo] at Hid ⊢
exact tendsto_setIntegral_of_monotone (fun k => ((J k).face i).measurableSet_Ioo)
(Box.Ioo.monotone.comp ((Box.monotone_face i).comp J.monotone)) Hid
/- Thus it suffices to show that the distance between the integrals of the restrictions of `f` to
`{x | x i = c k}` and `{x | x i = d}` over `((J k).face i).Icc` tends to zero as `k → ∞`. Choose
`ε > 0`. -/
refine H.congr_dist (Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε εpos => ?_)
have hvol_pos : ∀ J : Box (Fin n), 0 < ∏ j, (J.upper j - J.lower j) := fun J =>
prod_pos fun j hj => sub_pos.2 <| J.lower_lt_upper _
/- Choose `δ > 0` such that for any `x y ∈ I.Icc` at distance at most `δ`, the distance between
`f x` and `f y` is at most `ε / volume (I.face i).Icc`, then the distance between the integrals
is at most `(ε / volume (I.face i).Icc) * volume ((J k).face i).Icc ≤ ε`. -/
rcases Metric.uniformContinuousOn_iff_le.1 (I.isCompact_Icc.uniformContinuousOn_of_continuous Hc)
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) (div_pos εpos (hvol_pos (I.face i)))
with ⟨δ, δpos, hδ⟩
refine (hcd.eventually (Metric.ball_mem_nhds _ δpos)).mono fun k hk => ?_
have Hsub : Box.Icc ((J k).face i) ⊆ Box.Icc (I.face i) :=
Box.le_iff_Icc.1 (Box.face_mono (hJ_le _) i)
rw [mem_closedBall_zero_iff, Real.norm_eq_abs, abs_of_nonneg dist_nonneg, dist_eq_norm,
← integral_sub (Hid.mono_set Hsub) ((Hic _).mono_set Hsub)]
calc
‖∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i - f (i.insertNth (c k) x) i‖ ≤
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) *
(volume (Box.Icc ((J k).face i))).toReal := by
refine norm_setIntegral_le_of_norm_le_const (((J k).face i).measure_Icc_lt_top _)
fun x hx => ?_
rw [← dist_eq_norm]
calc
dist (f (i.insertNth d x) i) (f (i.insertNth (c k) x) i) ≤
dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) :=
dist_le_pi_dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) i
_ ≤ ε / ∏ j, ((I.face i).upper j - (I.face i).lower j) :=
hδ _ (I.mapsTo_insertNth_face_Icc hd <| Hsub hx) _
(I.mapsTo_insertNth_face_Icc (hc _) <| Hsub hx) ?_
rw [Fin.dist_insertNth_insertNth, dist_self, dist_comm]
exact max_le hk.le δpos.lt.le
_ ≤ ε := by
rw [Box.Icc_def, Real.volume_Icc_pi_toReal ((J k).face i).lower_le_upper,
← le_div_iff₀ (hvol_pos _)]
gcongr
exacts [hvol_pos _, fun _ _ ↦ sub_nonneg.2 (Box.lower_le_upper _ _),
(hJ_sub' _ (J _).upper_mem_Icc).2 _, (hJ_sub' _ (J _).lower_mem_Icc).1 _]
variable (a b : Fin (n + 1) → ℝ)
local notation "face " i => Set.Icc (a ∘ Fin.succAbove i) (b ∘ Fin.succAbove i)
local notation:max "frontFace " i:arg => Fin.insertNth i (b i)
local notation:max "backFace " i:arg => Fin.insertNth i (a i)
/-- **Divergence theorem** for Bochner integral. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is continuous on a rectangular
box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, is differentiable on its interior with derivative
`f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹` and the divergence `fun x ↦ ∑ i, f' x eᵢ i` is integrable on `[a, b]`,
where `eᵢ = Pi.single i 1` is the `i`-th basis vector, then its integral is equal to the sum of
integrals of `f` over the faces of `[a, b]`, taken with appropriate signs.
Moreover, the same is true if the function is not differentiable at countably many
points of the interior of `[a, b]`.
We represent both faces `x i = a i` and `x i = b i` as the box
`face i = [a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]` in `ℝⁿ`, where
`Fin.succAbove : Fin n ↪o Fin (n + 1)` is the order embedding with range `{i}ᶜ`. The restrictions
of `f : ℝⁿ⁺¹ → Eⁿ⁺¹` to these faces are given by `f ∘ backFace i` and `f ∘ frontFace i`, where
`backFace i = Fin.insertNth i (a i)` and `frontFace i = Fin.insertNth i (b i)` are embeddings
`ℝⁿ → ℝⁿ⁺¹` that take `y : ℝⁿ` and insert `a i` (resp., `b i`) as `i`-th coordinate. -/
theorem integral_divergence_of_hasFDerivAt_off_countable (hle : a ≤ b)
(f : ℝⁿ⁺¹ → Eⁿ⁺¹) (f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹)
(s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Icc a b))
(Hd : ∀ x ∈ (Set.pi univ fun i => Ioo (a i) (b i)) \ s, HasFDerivAt f (f' x) x)
(Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Icc a b)) :
(∫ x in Icc a b, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in face i, f (frontFace i x) i) - ∫ x in face i, f (backFace i x) i) := by
rcases em (∃ i, a i = b i) with (⟨i, hi⟩ | hne)
· -- First we sort out the trivial case `∃ i, a i = b i`.
rw [volume_pi, ← setIntegral_congr_set Measure.univ_pi_Ioc_ae_eq_Icc]
have hi' : Ioc (a i) (b i) = ∅ := Ioc_eq_empty hi.not_lt
have : (pi Set.univ fun j => Ioc (a j) (b j)) = ∅ := univ_pi_eq_empty hi'
rw [this, setIntegral_empty, sum_eq_zero]
rintro j -
rcases eq_or_ne i j with (rfl | hne)
· simp [hi]
· rcases Fin.exists_succAbove_eq hne with ⟨i, rfl⟩
have : Icc (a ∘ j.succAbove) (b ∘ j.succAbove) =ᵐ[volume] (∅ : Set ℝⁿ) := by
rw [ae_eq_empty, Real.volume_Icc_pi, prod_eq_zero (Finset.mem_univ i)]
simp [hi]
rw [setIntegral_congr_set this, setIntegral_congr_set this, setIntegral_empty,
setIntegral_empty, sub_self]
· -- In the non-trivial case `∀ i, a i < b i`, we apply a lemma we proved above.
have hlt : ∀ i, a i < b i := fun i => (hle i).lt_of_ne fun hi => hne ⟨i, hi⟩
exact integral_divergence_of_hasFDerivAt_off_countable_aux₂ ⟨a, b, hlt⟩ f f' s hs Hc Hd Hi
@[deprecated (since := "2025-05-02")]
alias integral_divergence_of_hasFDerivWithinAt_off_countable :=
integral_divergence_of_hasFDerivAt_off_countable
/-- **Divergence theorem** for a family of functions `f : Fin (n + 1) → ℝⁿ⁺¹ → E`. See also
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable'` for a version formulated
in terms of a vector-valued function `f : ℝⁿ⁺¹ → Eⁿ⁺¹`. -/
theorem integral_divergence_of_hasFDerivAt_off_countable' (hle : a ≤ b)
(f : Fin (n + 1) → ℝⁿ⁺¹ → E)
(f' : Fin (n + 1) → ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] E) (s : Set ℝⁿ⁺¹)
(hs : s.Countable) (Hc : ∀ i, ContinuousOn (f i) (Icc a b))
(Hd : ∀ x ∈ (pi Set.univ fun i => Ioo (a i) (b i)) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x)
(Hi : IntegrableOn (fun x => ∑ i, f' i x (e i)) (Icc a b)) :
(∫ x in Icc a b, ∑ i, f' i x (e i)) =
∑ i : Fin (n + 1), ((∫ x in face i, f i (frontFace i x)) -
∫ x in face i, f i (backFace i x)) :=
integral_divergence_of_hasFDerivAt_off_countable a b hle (fun x i => f i x)
(fun x => ContinuousLinearMap.pi fun i => f' i x) s hs (continuousOn_pi.2 Hc)
(fun x hx => hasFDerivAt_pi.2 (Hd x hx)) Hi
@[deprecated (since := "2025-05-02")]
alias integral_divergence_of_hasFDerivWithinAt_off_countable' :=
integral_divergence_of_hasFDerivAt_off_countable'
end
/-- An auxiliary lemma that is used to specialize the general divergence theorem to spaces that do
not have the form `Fin n → ℝ`. -/
theorem integral_divergence_of_hasFDerivAt_off_countable_of_equiv {F : Type*}
[NormedAddCommGroup F] [NormedSpace ℝ F] [Preorder F] [MeasureSpace F] [BorelSpace F]
(eL : F ≃L[ℝ] ℝⁿ⁺¹) (he_ord : ∀ x y, eL x ≤ eL y ↔ x ≤ y)
(he_vol : MeasurePreserving eL volume volume) (f : Fin (n + 1) → F → E)
(f' : Fin (n + 1) → F → F →L[ℝ] E) (s : Set F) (hs : s.Countable) (a b : F) (hle : a ≤ b)
(Hc : ∀ i, ContinuousOn (f i) (Icc a b))
(Hd : ∀ x ∈ interior (Icc a b) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x) (DF : F → E)
(hDF : ∀ x, DF x = ∑ i, f' i x (eL.symm <| e i)) (Hi : IntegrableOn DF (Icc a b)) :
∫ x in Icc a b, DF x =
∑ i : Fin (n + 1),
((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL b i) x)) -
∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL a i) x)) :=
have he_emb : MeasurableEmbedding eL := eL.toHomeomorph.measurableEmbedding
have hIcc : eL ⁻¹' Icc (eL a) (eL b) = Icc a b := by
ext1 x; simp only [Set.mem_preimage, Set.mem_Icc, he_ord]
have hIcc' : Icc (eL a) (eL b) = eL.symm ⁻¹' Icc a b := by rw [← hIcc, eL.symm_preimage_preimage]
calc
∫ x in Icc a b, DF x = ∫ x in Icc a b, ∑ i, f' i x (eL.symm <| e i) := by simp only [hDF]
_ = ∫ x in Icc (eL a) (eL b), ∑ i, f' i (eL.symm x) (eL.symm <| e i) := by
rw [← he_vol.setIntegral_preimage_emb he_emb]
simp only [hIcc, eL.symm_apply_apply]
_ = ∑ i : Fin (n + 1),
((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL b i) x)) -
∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL a i) x)) := by
refine integral_divergence_of_hasFDerivAt_off_countable' (eL a) (eL b)
((he_ord _ _).2 hle) (fun i x => f i (eL.symm x))
(fun i x => f' i (eL.symm x) ∘L (eL.symm : ℝⁿ⁺¹ →L[ℝ] F)) (eL.symm ⁻¹' s)
(hs.preimage eL.symm.injective) ?_ ?_ ?_
· exact fun i => (Hc i).comp eL.symm.continuousOn hIcc'.subset
· refine fun x hx i => (Hd (eL.symm x) ⟨?_, hx.2⟩ i).comp x eL.symm.hasFDerivAt
rw [← hIcc]
refine preimage_interior_subset_interior_preimage eL.continuous ?_
simpa only [Set.mem_preimage, eL.apply_symm_apply, ← pi_univ_Icc,
interior_pi_set (@finite_univ (Fin _) _), interior_Icc] using hx.1
· rw [← he_vol.integrableOn_comp_preimage he_emb, hIcc]
simp [← hDF, Function.comp_def, Hi]
@[deprecated (since := "2025-05-02")]
alias integral_divergence_of_hasFDerivWithinAt_off_countable_of_equiv :=
integral_divergence_of_hasFDerivAt_off_countable_of_equiv
end
open scoped Interval
open ContinuousLinearMap (smulRight)
local macro:arg t:term:max noWs "¹" : term => `(Fin 1 → $t)
local macro:arg t:term:max noWs "²" : term => `(Fin 2 → $t)
/-- **Fundamental theorem of calculus, part 2**. This version assumes that `f` is continuous on the
interval and is differentiable off a countable set `s`.
See also
* `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` for a version that only assumes right
differentiability of `f`;
* `MeasureTheory.integral_eq_of_hasDerivWithinAt_off_countable` for a version that works both
for `a ≤ b` and `b ≤ a` at the expense of using unordered intervals instead of `Set.Icc`. -/
theorem integral_eq_of_hasDerivAt_off_countable_of_le [CompleteSpace E] (f f' : ℝ → E)
{a b : ℝ} (hle : a ≤ b) {s : Set ℝ} (hs : s.Countable) (Hc : ContinuousOn f (Icc a b))
(Hd : ∀ x ∈ Ioo a b \ s, HasDerivAt f (f' x) x) (Hi : IntervalIntegrable f' volume a b) :
∫ x in a..b, f' x = f b - f a := by
set e : ℝ ≃L[ℝ] ℝ¹ := (ContinuousLinearEquiv.funUnique (Fin 1) ℝ ℝ).symm
have e_symm : ∀ x, e.symm x = x 0 := fun x => rfl
set F' : ℝ → ℝ →L[ℝ] E := fun x => smulRight (1 : ℝ →L[ℝ] ℝ) (f' x)
have hF' : ∀ x y, F' x y = y • f' x := fun x y => rfl
calc
∫ x in a..b, f' x = ∫ x in Icc a b, f' x := by
rw [intervalIntegral.integral_of_le hle, setIntegral_congr_set Ioc_ae_eq_Icc]
_ = ∑ i : Fin 1,
((∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
f (e.symm <| i.insertNth (e b i) x)) -
∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
f (e.symm <| i.insertNth (e a i) x)) := by
simp only [← interior_Icc] at Hd
refine
integral_divergence_of_hasFDerivAt_off_countable_of_equiv e ?_ ?_ (fun _ => f)
(fun _ => F') s hs a b hle (fun _ => Hc) (fun x hx _ => Hd x hx) _ ?_ ?_
· exact fun x y => (OrderIso.funUnique (Fin 1) ℝ).symm.le_iff_le
· exact (volume_preserving_funUnique (Fin 1) ℝ).symm _
· intro x; rw [Fin.sum_univ_one, hF', e_symm, Pi.single_eq_same, one_smul]
· rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hle] at Hi
exact Hi.congr_set_ae Ioc_ae_eq_Icc.symm
_ = f b - f a := by
simp [e, Subsingleton.elim (const (Fin 0) _) isEmptyElim, volume_pi,
Measure.pi_of_empty fun _ : Fin 0 ↦ _]
@[deprecated (since := "2025-05-02")]
alias integral_eq_of_hasDerivWithinAt_off_countable_of_le :=
integral_eq_of_hasDerivAt_off_countable_of_le
/-- **Fundamental theorem of calculus, part 2**. This version assumes that `f` is continuous on the
interval and is differentiable off a countable set `s`.
See also `intervalIntegral.integral_eq_sub_of_hasDeriv_right` for a version that
only assumes right differentiability of `f`.
-/
theorem integral_eq_of_hasDerivAt_off_countable [CompleteSpace E] (f f' : ℝ → E) {a b : ℝ}
{s : Set ℝ} (hs : s.Countable) (Hc : ContinuousOn f [[a, b]])
(Hd : ∀ x ∈ Ioo (min a b) (max a b) \ s, HasDerivAt f (f' x) x)
(Hi : IntervalIntegrable f' volume a b) : ∫ x in a..b, f' x = f b - f a := by
rcases le_total a b with hab | hab
· simp only [uIcc_of_le hab, min_eq_left hab, max_eq_right hab] at *
exact integral_eq_of_hasDerivAt_off_countable_of_le f f' hab hs Hc Hd Hi
· simp only [uIcc_of_ge hab, min_eq_right hab, max_eq_left hab] at *
rw [intervalIntegral.integral_symm, neg_eq_iff_eq_neg, neg_sub]
exact integral_eq_of_hasDerivAt_off_countable_of_le f f' hab hs Hc Hd Hi.symm
@[deprecated (since := "2025-05-02")]
alias integral_eq_of_hasDerivWithinAt_off_countable := integral_eq_of_hasDerivAt_off_countable
/-- **Divergence theorem** for functions on the plane along rectangles. It is formulated in terms of
two functions `f g : ℝ × ℝ → E` and an integral over `Icc a b = [a.1, b.1] × [a.2, b.2]`, where
`a b : ℝ × ℝ`, `a ≤ b`. When thinking of `f` and `g` as the two coordinates of a single function
`F : ℝ × ℝ → E × E` and when `E = ℝ`, this is the usual statement that the integral of the
divergence of `F` inside the rectangle equals the integral of the normal derivative of `F` along the
boundary.
See also `MeasureTheory.integral2_divergence_prod_of_hasFDerivAt_off_countable` for a
version that does not assume `a ≤ b` and uses iterated interval integral instead of the integral
over `Icc a b`. -/
theorem integral_divergence_prod_Icc_of_hasFDerivAt_off_countable_of_le (f g : ℝ × ℝ → E)
(f' g' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E) (a b : ℝ × ℝ) (hle : a ≤ b) (s : Set (ℝ × ℝ)) (hs : s.Countable)
(Hcf : ContinuousOn f (Icc a b)) (Hcg : ContinuousOn g (Icc a b))
(Hdf : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2 \ s, HasFDerivAt f (f' x) x)
(Hdg : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2 \ s, HasFDerivAt g (g' x) x)
(Hi : IntegrableOn (fun x => f' x (1, 0) + g' x (0, 1)) (Icc a b)) :
(∫ x in Icc a b, f' x (1, 0) + g' x (0, 1)) =
(((∫ x in a.1..b.1, g (x, b.2)) - ∫ x in a.1..b.1, g (x, a.2)) +
∫ y in a.2..b.2, f (b.1, y)) -
∫ y in a.2..b.2, f (a.1, y) :=
let e : (ℝ × ℝ) ≃L[ℝ] ℝ² := (ContinuousLinearEquiv.finTwoArrow ℝ ℝ).symm
calc
(∫ x in Icc a b, f' x (1, 0) + g' x (0, 1)) =
∑ i : Fin 2,
((∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
![f, g] i (e.symm <| i.insertNth (e b i) x)) -
∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
![f, g] i (e.symm <| i.insertNth (e a i) x)) := by
refine integral_divergence_of_hasFDerivAt_off_countable_of_equiv e ?_ ?_ ![f, g]
![f', g'] s hs a b hle ?_ (fun x hx => ?_) _ ?_ Hi
· exact fun x y => (OrderIso.finTwoArrowIso ℝ).symm.le_iff_le
· exact (volume_preserving_finTwoArrow ℝ).symm _
· exact Fin.forall_fin_two.2 ⟨Hcf, Hcg⟩
· rw [Icc_prod_eq, interior_prod_eq, interior_Icc, interior_Icc] at hx
exact Fin.forall_fin_two.2 ⟨Hdf x hx, Hdg x hx⟩
· intro x; rw [Fin.sum_univ_two]; rfl
_ = ((∫ y in Icc a.2 b.2, f (b.1, y)) - ∫ y in Icc a.2 b.2, f (a.1, y)) +
((∫ x in Icc a.1 b.1, g (x, b.2)) - ∫ x in Icc a.1 b.1, g (x, a.2)) := by
have : ∀ (a b : ℝ¹) (f : ℝ¹ → E),
∫ x in Icc a b, f x = ∫ x in Icc (a 0) (b 0), f fun _ => x := fun a b f ↦ by
convert (((volume_preserving_funUnique (Fin 1) ℝ).symm _).setIntegral_preimage_emb
(MeasurableEquiv.measurableEmbedding _) f _).symm
exact ((OrderIso.funUnique (Fin 1) ℝ).symm.preimage_Icc a b).symm
simp only [Fin.sum_univ_two, this]
rfl
_ = (((∫ x in a.1..b.1, g (x, b.2)) - ∫ x in a.1..b.1, g (x, a.2)) +
∫ y in a.2..b.2, f (b.1, y)) - ∫ y in a.2..b.2, f (a.1, y) := by
simp only [intervalIntegral.integral_of_le hle.1, intervalIntegral.integral_of_le hle.2,
setIntegral_congr_set (Ioc_ae_eq_Icc (α := ℝ) (μ := volume))]
abel
@[deprecated (since := "2025-05-02")]
alias integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le :=
integral_divergence_prod_Icc_of_hasFDerivAt_off_countable_of_le
/-- **Divergence theorem** for functions on the plane. It is formulated in terms of two functions
`f g : ℝ × ℝ → E` and iterated integral `∫ x in a₁..b₁, ∫ y in a₂..b₂, _`, where
`a₁ a₂ b₁ b₂ : ℝ`. When thinking of `f` and `g` as the two coordinates of a single function
`F : ℝ × ℝ → E × E` and when `E = ℝ`, this is the usual statement that the integral of the
divergence of `F` inside the rectangle with vertices `(aᵢ, bⱼ)`, `i, j =1,2`, equals the integral of
the normal derivative of `F` along the boundary.
See also `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivAt_off_countable_of_le`
for a version that uses an integral over `Icc a b`, where `a b : ℝ × ℝ`, `a ≤ b`. -/
theorem integral2_divergence_prod_of_hasFDerivAt_off_countable (f g : ℝ × ℝ → E)
(f' g' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E) (a₁ a₂ b₁ b₂ : ℝ) (s : Set (ℝ × ℝ)) (hs : s.Countable)
(Hcf : ContinuousOn f ([[a₁, b₁]] ×ˢ [[a₂, b₂]]))
(Hcg : ContinuousOn g ([[a₁, b₁]] ×ˢ [[a₂, b₂]]))
(Hdf : ∀ x ∈ Ioo (min a₁ b₁) (max a₁ b₁) ×ˢ Ioo (min a₂ b₂) (max a₂ b₂) \ s,
HasFDerivAt f (f' x) x)
(Hdg : ∀ x ∈ Ioo (min a₁ b₁) (max a₁ b₁) ×ˢ Ioo (min a₂ b₂) (max a₂ b₂) \ s,
HasFDerivAt g (g' x) x)
(Hi : IntegrableOn (fun x => f' x (1, 0) + g' x (0, 1)) ([[a₁, b₁]] ×ˢ [[a₂, b₂]])) :
(∫ x in a₁..b₁, ∫ y in a₂..b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1)) =
(((∫ x in a₁..b₁, g (x, b₂)) - ∫ x in a₁..b₁, g (x, a₂)) + ∫ y in a₂..b₂, f (b₁, y)) -
∫ y in a₂..b₂, f (a₁, y) := by
wlog h₁ : a₁ ≤ b₁ generalizing a₁ b₁
· specialize this b₁ a₁
rw [uIcc_comm b₁ a₁, min_comm b₁ a₁, max_comm b₁ a₁] at this
simp only [intervalIntegral.integral_symm b₁ a₁]
refine (congr_arg Neg.neg (this Hcf Hcg Hdf Hdg Hi (le_of_not_ge h₁))).trans ?_; abel
wlog h₂ : a₂ ≤ b₂ generalizing a₂ b₂
· specialize this b₂ a₂
rw [uIcc_comm b₂ a₂, min_comm b₂ a₂, max_comm b₂ a₂] at this
simp only [intervalIntegral.integral_symm b₂ a₂, intervalIntegral.integral_neg]
refine (congr_arg Neg.neg (this Hcf Hcg Hdf Hdg Hi (le_of_not_ge h₂))).trans ?_; abel
simp only [uIcc_of_le h₁, uIcc_of_le h₂, min_eq_left, max_eq_right, h₁, h₂] at Hcf Hcg Hdf Hdg Hi
calc
(∫ x in a₁..b₁, ∫ y in a₂..b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1)) =
∫ x in Icc a₁ b₁, ∫ y in Icc a₂ b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1) := by
simp only [intervalIntegral.integral_of_le, h₁, h₂,
setIntegral_congr_set (Ioc_ae_eq_Icc (α := ℝ) (μ := volume))]
_ = ∫ x in Icc a₁ b₁ ×ˢ Icc a₂ b₂, f' x (1, 0) + g' x (0, 1) := (setIntegral_prod _ Hi).symm
_ = (((∫ x in a₁..b₁, g (x, b₂)) - ∫ x in a₁..b₁, g (x, a₂)) + ∫ y in a₂..b₂, f (b₁, y)) -
∫ y in a₂..b₂, f (a₁, y) := by
rw [Icc_prod_Icc] at *
apply integral_divergence_prod_Icc_of_hasFDerivAt_off_countable_of_le f g f' g'
(a₁, a₂) (b₁, b₂) ⟨h₁, h₂⟩ s <;> assumption
@[deprecated (since := "2025-05-02")]
alias integral2_divergence_prod_of_hasFDerivWithinAt_off_countable :=
integral2_divergence_prod_of_hasFDerivAt_off_countable
end MeasureTheory
|
ProximityFunction.lean
|
/-
Copyright (c) 2025 Stefan Kebekus. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stefan Kebekus
-/
import Mathlib.Algebra.Order.WithTop.Untop0
import Mathlib.Analysis.SpecialFunctions.Integrability.LogMeromorphic
import Mathlib.MeasureTheory.Integral.CircleAverage
/-!
# The Proximity Function of Value Distribution Theory
This file defines the "proximity function" attached to a meromorphic function defined on the complex
plane. Also known as the `Nevanlinna Proximity Function`, this is one of the three main functions
used in Value Distribution Theory.
The proximity function is a logarithmically weighted measure quantifying how well a meromorphic
function `f` approximates the constant function `a` on the circle of radius `R` in the complex
plane. The definition ensures that large values correspond to good approximation.
See Section~VI.2 of [Lang, *Introduction to Complex Hyperbolic Spaces*][MR886677] or Section~1.1 of
[Noguchi-Winkelmann, *Nevanlinna Theory in Several Complex Variables and Diophantine
Approximation*][MR3156076] for a detailed discussion.
-/
open Metric Real Set
namespace ValueDistribution
variable
{E : Type*} [NormedAddCommGroup E]
{f g : ℂ → E} {a : WithTop E} {a₀ : E}
open Real
variable (f a) in
/--
The Proximity Function of Value Distribution Theory
If `f : ℂ → E` is meromorphic and `a : WithTop E` is any value, the proximity function is a
logarithmically weighted measure quantifying how well a meromorphic function `f` approximates the
constant function `a` on the circle of radius `R` in the complex plane. In the special case where
`a = ⊤`, it quantifies how well `f` approximates infinity.
-/
noncomputable def proximity : ℝ → ℝ := by
by_cases h : a = ⊤
· exact circleAverage (log⁺ ‖f ·‖) 0
· exact circleAverage (log⁺ ‖f · - a.untop₀‖⁻¹) 0
/-- Expand the definition of `proximity f a₀` in case where `a₀` is finite. -/
lemma proximity_coe :
proximity f a₀ = circleAverage (log⁺ ‖f · - a₀‖⁻¹) 0 := by
simp [proximity]
/--
Expand the definition of `proximity f a₀` in case where `a₀` is zero.
-/
lemma proximity_zero : proximity f 0 = circleAverage (log⁺ ‖f ·‖⁻¹) 0 := by
simp [proximity]
/--
For complex-valued functions, expand the definition of `proximity f a₀` in case where `a₀` is zero.
This is a simple variant of `proximity_zero` defined above.
-/
lemma proximity_zero_of_complexValued {f : ℂ → ℂ} :
proximity f 0 = circleAverage (log⁺ ‖f⁻¹ ·‖) 0 := by
simp [proximity]
/--
Expand the definition of `proximity f a` in case where `a₀ = ⊤`.
-/
lemma proximity_top : proximity f ⊤ = circleAverage (log⁺ ‖f ·‖) 0 := by
simp [proximity]
/-!
## Elementary Properties of the Counting Function
-/
/--
For finite values `a₀`, the proximity function `proximity f a₀` equals the proximity function for
the value zero of the shifted function `f - a₀`.
-/
lemma proximity_coe_eq_proximity_sub_const_zero :
proximity f a₀ = proximity (f - fun _ ↦ a₀) 0 := by
simp [proximity]
/--
For complex-valued `f`, establish a simple relation between the proximity functions of `f` and of
`f⁻¹`.
-/
theorem proximity_inv {f : ℂ → ℂ} : proximity f⁻¹ ⊤ = proximity f 0 := by
simp [proximity_zero, proximity_top]
/--
For complex-valued `f`, the difference between `proximity f ⊤` and `proximity
f⁻¹ ⊤` is the circle average of `log ‖f ·‖`.
-/
theorem proximity_sub_proximity_inv_eq_circleAverage {f : ℂ → ℂ} (h₁f : MeromorphicOn f ⊤) :
proximity f ⊤ - proximity f⁻¹ ⊤ = circleAverage (log ‖f ·‖) 0 := by
ext R
simp only [proximity, ↓reduceDIte, Pi.inv_apply, norm_inv, Pi.sub_apply]
rw [← circleAverage_sub]
· simp_rw [← posLog_sub_posLog_inv, Pi.sub_def]
· apply circleIntegrable_posLog_norm_meromorphicOn (h₁f.mono_set (by tauto))
· simp_rw [← norm_inv]
apply circleIntegrable_posLog_norm_meromorphicOn (h₁f.inv.mono_set (by tauto))
end ValueDistribution
|
Inversion.lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Contraction
/-! # Results about inverses in Clifford algebras
This contains some basic results about the inversion of vectors, related to the fact that
$ι(m)^{-1} = \frac{ι(m)}{Q(m)}$.
-/
variable {R M : Type*}
variable [CommRing R] [AddCommGroup M] [Module R M] {Q : QuadraticForm R M}
namespace CliffordAlgebra
variable (Q)
/-- If the quadratic form of a vector is invertible, then so is that vector. -/
def invertibleιOfInvertible (m : M) [Invertible (Q m)] : Invertible (ι Q m) where
invOf := ι Q (⅟(Q m) • m)
invOf_mul_self := by
rw [map_smul, smul_mul_assoc, ι_sq_scalar, Algebra.smul_def, ← map_mul, invOf_mul_self, map_one]
mul_invOf_self := by
rw [map_smul, mul_smul_comm, ι_sq_scalar, Algebra.smul_def, ← map_mul, invOf_mul_self, map_one]
/-- For a vector with invertible quadratic form, $v^{-1} = \frac{v}{Q(v)}$ -/
theorem invOf_ι (m : M) [Invertible (Q m)] [Invertible (ι Q m)] :
⅟(ι Q m) = ι Q (⅟(Q m) • m) := by
letI := invertibleιOfInvertible Q m
convert (rfl : ⅟(ι Q m) = _)
theorem isUnit_ι_of_isUnit {m : M} (h : IsUnit (Q m)) : IsUnit (ι Q m) := by
cases h.nonempty_invertible
letI := invertibleιOfInvertible Q m
exact isUnit_of_invertible (ι Q m)
/-- $aba^{-1}$ is a vector. -/
theorem ι_mul_ι_mul_invOf_ι (a b : M) [Invertible (ι Q a)] [Invertible (Q a)] :
ι Q a * ι Q b * ⅟(ι Q a) = ι Q ((⅟(Q a) * QuadraticMap.polar Q a b) • a - b) := by
rw [invOf_ι, map_smul, mul_smul_comm, ι_mul_ι_mul_ι, ← map_smul, smul_sub, smul_smul, smul_smul,
invOf_mul_self, one_smul]
/-- $a^{-1}ba$ is a vector. -/
theorem invOf_ι_mul_ι_mul_ι (a b : M) [Invertible (ι Q a)] [Invertible (Q a)] :
⅟(ι Q a) * ι Q b * ι Q a = ι Q ((⅟(Q a) * QuadraticMap.polar Q a b) • a - b) := by
rw [invOf_ι, map_smul, smul_mul_assoc, smul_mul_assoc, ι_mul_ι_mul_ι, ← map_smul, smul_sub,
smul_smul, smul_smul, invOf_mul_self, one_smul]
section
variable [Invertible (2 : R)]
/-- Over a ring where `2` is invertible, `Q m` is invertible whenever `ι Q m`. -/
def invertibleOfInvertibleι (m : M) [Invertible (ι Q m)] : Invertible (Q m) :=
ExteriorAlgebra.invertibleAlgebraMapEquiv M (Q m) <|
.algebraMapOfInvertibleAlgebraMap (equivExterior Q).toLinearMap (by simp) <|
.copy (.mul ‹Invertible (ι Q m)› ‹Invertible (ι Q m)›) _ (ι_sq_scalar _ _).symm
theorem isUnit_of_isUnit_ι {m : M} (h : IsUnit (ι Q m)) : IsUnit (Q m) := by
cases h.nonempty_invertible
letI := invertibleOfInvertibleι Q m
exact isUnit_of_invertible (Q m)
@[simp] theorem isUnit_ι_iff {m : M} : IsUnit (ι Q m) ↔ IsUnit (Q m) :=
⟨isUnit_of_isUnit_ι Q, isUnit_ι_of_isUnit Q⟩
end
end CliffordAlgebra
|
RealVectorSpace.lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.Algebra.Module.Equiv
import Mathlib.Topology.Instances.Rat
import Mathlib.Algebra.Module.Rat
/-!
# Continuous additive maps are `ℝ`-linear
In this file we prove that a continuous map `f : E →+ F` between two topological vector spaces
over `ℝ` is `ℝ`-linear
-/
variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousSMul ℝ E]
{F : Type*} [AddCommGroup F] [Module ℝ F] [TopologicalSpace F] [ContinuousSMul ℝ F] [T2Space F]
/-- A continuous additive map between two vector spaces over `ℝ` is `ℝ`-linear. -/
theorem map_real_smul {G} [FunLike G E F] [AddMonoidHomClass G E F] (f : G) (hf : Continuous f)
(c : ℝ) (x : E) :
f (c • x) = c • f x :=
suffices (fun c : ℝ => f (c • x)) = fun c : ℝ => c • f x from congr_fun this c
Rat.isDenseEmbedding_coe_real.dense.equalizer (hf.comp <| continuous_id.smul continuous_const)
(continuous_id.smul continuous_const) (funext fun r => map_ratCast_smul f ℝ ℝ r x)
namespace AddMonoidHom
/-- Reinterpret a continuous additive homomorphism between two real vector spaces
as a continuous real-linear map. -/
def toRealLinearMap (f : E →+ F) (hf : Continuous f) : E →L[ℝ] F :=
⟨{ toFun := f
map_add' := f.map_add
map_smul' := map_real_smul f hf }, hf⟩
@[simp]
theorem coe_toRealLinearMap (f : E →+ F) (hf : Continuous f) : ⇑(f.toRealLinearMap hf) = f :=
rfl
end AddMonoidHom
/-- Reinterpret a continuous additive equivalence between two real vector spaces
as a continuous real-linear map. -/
def AddEquiv.toRealLinearEquiv (e : E ≃+ F) (h₁ : Continuous e) (h₂ : Continuous e.symm) :
E ≃L[ℝ] F :=
{ e, e.toAddMonoidHom.toRealLinearMap h₁ with }
/-- A topological group carries at most one structure of a topological `ℝ`-module, so for any
topological `ℝ`-algebra `A` (e.g. `A = ℂ`) and any topological group that is both a topological
`ℝ`-module and a topological `A`-module, these structures agree. -/
instance (priority := 900) Real.isScalarTower [T2Space E] {A : Type*} [TopologicalSpace A] [Ring A]
[Algebra ℝ A] [Module A E] [ContinuousSMul ℝ A] [ContinuousSMul A E] : IsScalarTower ℝ A E :=
⟨fun r x y => map_real_smul ((smulAddHom A E).flip y) (continuous_id.smul continuous_const) r x⟩
|
Matrix.lean
|
/-
Copyright (c) 2025 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.PerfectPairing.Basic
import Mathlib.LinearAlgebra.Matrix.Dual
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
/-!
# Perfect pairings and matrices
The file contains results connecting perfect pairings and matrices.
## Main definitions
* `Matrix.toPerfectPairing`: regard an invertible matrix as a perfect pairing.
-/
namespace Matrix
variable {R n : Type*} [CommRing R] [Fintype n] [DecidableEq n]
(A : Matrix n n R) (h : Invertible A)
/-- We may regard an invertible matrix as a perfect pairing. -/
def toPerfectPairing :
PerfectPairing R (n → R) (n → R) :=
((A.toLinearEquiv' h).trans (dotProductEquiv R n)).toPerfectPairing
@[simp] lemma toPerfectPairing_apply_apply (v w : n → R) :
A.toPerfectPairing h v w = A *ᵥ v ⬝ᵥ w :=
rfl
end Matrix
|
ConditionalProbability.lean
|
/-
Copyright (c) 2022 Rishikesh Vaishnav. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rishikesh Vaishnav
-/
import Mathlib.MeasureTheory.Measure.Typeclasses.Probability
/-!
# Conditional Probability
This file defines conditional probability and includes basic results relating to it.
Given some measure `μ` defined on a measure space on some type `Ω` and some `s : Set Ω`,
we define the measure of `μ` conditioned on `s` as the restricted measure scaled by
the inverse of the measure of `s`: `cond μ s = (μ s)⁻¹ • μ.restrict s`. The scaling
ensures that this is a probability measure (when `μ` is a finite measure).
From this definition, we derive the "axiomatic" definition of conditional probability
based on application: for any `s t : Set Ω`, we have `μ[t|s] = (μ s)⁻¹ * μ (s ∩ t)`.
## Main Statements
* `cond_cond_eq_cond_inter`: conditioning on one set and then another is equivalent
to conditioning on their intersection.
* `cond_eq_inv_mul_cond_mul`: Bayes' Theorem, `μ[t|s] = (μ s)⁻¹ * μ[s|t] * (μ t)`.
## Notations
This file uses the notation `μ[|s]` the measure of `μ` conditioned on `s`,
and `μ[t|s]` for the probability of `t` given `s` under `μ` (equivalent to the
application `μ[|s] t`).
These notations are contained in the locale `ProbabilityTheory`.
## Implementation notes
Because we have the alternative measure restriction application principles
`Measure.restrict_apply` and `Measure.restrict_apply'`, which require
measurability of the restricted and restricting sets, respectively,
many of the theorems here will have corresponding alternatives as well.
For the sake of brevity, we've chosen to only go with `Measure.restrict_apply'`
for now, but the alternative theorems can be added if needed.
Use of `@[simp]` generally follows the rule of removing conditions on a measure
when possible.
Hypotheses that are used to "define" a conditional distribution by requiring that
the conditioning set has non-zero measure should be named using the abbreviation
"c" (which stands for "conditionable") rather than "nz". For example `(hci : μ (s ∩ t) ≠ 0)`
(rather than `hnzi`) should be used for a hypothesis ensuring that `μ[|s ∩ t]` is defined.
## Tags
conditional, conditioned, bayes
-/
noncomputable section
open ENNReal MeasureTheory MeasureTheory.Measure MeasurableSpace Set
variable {Ω Ω' α : Type*} {m : MeasurableSpace Ω} {m' : MeasurableSpace Ω'} {μ : Measure Ω}
{s t : Set Ω}
namespace ProbabilityTheory
variable (μ) in
/-- The conditional probability measure of measure `μ` on set `s` is `μ` restricted to `s`
and scaled by the inverse of `μ s` (to make it a probability measure):
`(μ s)⁻¹ • μ.restrict s`. -/
def cond (s : Set Ω) : Measure Ω :=
(μ s)⁻¹ • μ.restrict s
@[inherit_doc ProbabilityTheory.cond]
scoped macro:max μ:term noWs "[|" s:term "]" : term =>
`(ProbabilityTheory.cond $μ $s)
@[inherit_doc cond]
scoped macro:max μ:term noWs "[" t:term " | " s:term "]" : term =>
`(ProbabilityTheory.cond $μ $s $t)
/-!
We can't use `notation` or `notation3` as it does not support `noWs`, and so we have to write
our own delaborators.
-/
section delaborators
open Lean PrettyPrinter.Delaborator SubExpr
/-- Unexpander for `μ[|s]` notation. -/
@[app_unexpander ProbabilityTheory.cond]
def condUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $μ $s) => `($μ[|$s])
| _ => throw ()
/-- info: μ[|s] : Measure Ω -/
#guard_msgs in
#check μ[|s]
/-- Delaborator for `μ[t|s]` notation. -/
@[app_delab DFunLike.coe]
def delabCondApplied : Delab :=
whenNotPPOption getPPExplicit <| whenPPOption getPPNotation <| withOverApp 6 do
let e ← getExpr
guard <| e.isAppOfArity' ``DFunLike.coe 6
guard <| (e.getArg!' 4).isAppOf' ``ProbabilityTheory.cond
let t ← withAppArg delab
withAppFn <| withAppArg do
let μ ← withNaryArg 2 delab
let s ← withNaryArg 3 delab
`($μ[$t|$s])
/-- info: μ[t | s] : ℝ≥0∞ -/
#guard_msgs in
#check μ[t | s]
/-- info: μ[t | s] : ℝ≥0∞ -/
#guard_msgs in
#check μ[|s] t
end delaborators
/-- The conditional probability measure of measure `μ` on `{ω | X ω ∈ s}`.
It is `μ` restricted to `{ω | X ω ∈ s}` and scaled by the inverse of `μ {ω | X ω ∈ s}`
(to make it a probability measure): `(μ {ω | X ω ∈ s})⁻¹ • μ.restrict {ω | X ω ∈ s}`. -/
scoped macro:max μ:term noWs "[|" X:term " in " s:term "]" : term => `($μ[|$X ⁻¹' $s])
/-- The conditional probability measure of measure `μ` on set `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[" s:term " | " X:term " in " t:term "]" : term =>
`($μ[$s | $X ⁻¹' $t])
/-- The conditional probability measure of measure `μ` on `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[|" X:term " ← " x:term "]" : term => `($μ[|$X in {$x:term}])
/-- The conditional probability measure of measure `μ` on set `{ω | X ω = x}`.
It is `μ` restricted to `{ω | X ω = x}` and scaled by the inverse of `μ {ω | X ω = x}`
(to make it a probability measure): `(μ {ω | X ω = x})⁻¹ • μ.restrict {ω | X ω = x}`. -/
scoped macro:max μ:term noWs "[" s:term " | " X:term " ← " x:term "]" : term =>
`($μ[$s | $X in {$x:term}])
/-- The conditional probability measure of any measure on any set of finite positive measure
is a probability measure. -/
theorem cond_isProbabilityMeasure_of_finite (hcs : μ s ≠ 0) (hs : μ s ≠ ∞) :
IsProbabilityMeasure μ[|s] :=
⟨by
unfold ProbabilityTheory.cond
simp only [Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply,
Set.univ_inter, smul_eq_mul]
exact ENNReal.inv_mul_cancel hcs hs⟩
/-- The conditional probability measure of any finite measure on any set of positive measure
is a probability measure. -/
theorem cond_isProbabilityMeasure [IsFiniteMeasure μ] (hcs : μ s ≠ 0) :
IsProbabilityMeasure μ[|s] := cond_isProbabilityMeasure_of_finite hcs (measure_ne_top μ s)
instance : IsZeroOrProbabilityMeasure μ[|s] := by
constructor
simp only [cond, Measure.coe_smul, Pi.smul_apply, MeasurableSet.univ, Measure.restrict_apply,
univ_inter, smul_eq_mul, ← ENNReal.div_eq_inv_mul]
rcases eq_or_ne (μ s) 0 with h | h
· simp [h]
rcases eq_or_ne (μ s) ∞ with h' | h'
· simp [h']
simp [ENNReal.div_self h h']
variable (μ) in
theorem cond_toMeasurable_eq :
μ[|(toMeasurable μ s)] = μ[|s] := by
unfold cond
by_cases hnt : μ s = ∞
· simp [hnt]
· simp [Measure.restrict_toMeasurable hnt]
lemma cond_absolutelyContinuous : μ[|s] ≪ μ :=
smul_absolutelyContinuous.trans restrict_le_self.absolutelyContinuous
lemma absolutelyContinuous_cond_univ [IsFiniteMeasure μ] : μ ≪ μ[|univ] := by
rw [cond, restrict_univ]
refine absolutelyContinuous_smul ?_
simp [measure_ne_top]
lemma ae_cond_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ[|s], x ∈ s :=
ae_smul_measure (ae_restrict_mem₀ hs) _
lemma ae_cond_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ[|s], x ∈ s :=
ae_smul_measure (ae_restrict_mem hs) _
section Bayes
variable (μ) in
@[simp] lemma cond_empty : μ[|∅] = 0 := by simp [cond]
variable (μ) in
@[simp] lemma cond_univ [IsProbabilityMeasure μ] : μ[|Set.univ] = μ := by
simp [cond, measure_univ, Measure.restrict_univ]
@[simp] lemma cond_eq_zero : μ[|s] = 0 ↔ μ s = ∞ ∨ μ s = 0 := by simp [cond]
lemma cond_eq_zero_of_meas_eq_zero (hμs : μ s = 0) : μ[|s] = 0 := by simp [hμs]
/-- The axiomatic definition of conditional probability derived from a measure-theoretic one. -/
theorem cond_apply (hms : MeasurableSet s) (μ : Measure Ω) (t : Set Ω) :
μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
rw [cond, Measure.smul_apply, Measure.restrict_apply' hms, Set.inter_comm, smul_eq_mul]
theorem cond_apply' (ht : MeasurableSet t) (μ : Measure Ω) : μ[t|s] = (μ s)⁻¹ * μ (s ∩ t) := by
rw [cond, Measure.smul_apply, Measure.restrict_apply ht, Set.inter_comm, smul_eq_mul]
@[simp] lemma cond_apply_self (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : μ[s|s] = 1 := by
simpa [cond] using ENNReal.inv_mul_cancel hs₀ hs
theorem cond_inter_self (hms : MeasurableSet s) (t : Set Ω) (μ : Measure Ω) :
μ[s ∩ t|s] = μ[t|s] := by
rw [cond_apply hms, ← Set.inter_assoc, Set.inter_self, ← cond_apply hms]
theorem inter_pos_of_cond_ne_zero (hms : MeasurableSet s) (hcst : μ[t | s] ≠ 0) :
0 < μ (s ∩ t) := by
refine pos_iff_ne_zero.mpr (right_ne_zero_of_mul (a := (μ s)⁻¹) ?_)
convert hcst
simp [hms, Set.inter_comm, cond]
lemma cond_pos_of_inter_ne_zero [IsFiniteMeasure μ] (hms : MeasurableSet s) (hci : μ (s ∩ t) ≠ 0) :
0 < μ[t | s] := by
rw [cond_apply hms]
refine ENNReal.mul_pos ?_ hci
exact ENNReal.inv_ne_zero.mpr (measure_ne_top _ _)
lemma cond_cond_eq_cond_inter' (hms : MeasurableSet s) (hmt : MeasurableSet t) (hcs : μ s ≠ ∞) :
μ[|s][|t] = μ[|s ∩ t] := by
ext u
obtain hst | hst := eq_or_ne (μ (s ∩ t)) 0
· have : μ (s ∩ t ∩ u) = 0 := measure_mono_null Set.inter_subset_left hst
simp [cond_apply, *, ← Set.inter_assoc]
· have hs : μ s ≠ 0 := (measure_pos_of_superset Set.inter_subset_left hst).ne'
simp [*, hms.inter hmt, cond_apply, ← Set.inter_assoc, ENNReal.mul_inv, ← mul_assoc,
mul_comm _ (μ s)⁻¹, ENNReal.inv_mul_cancel]
/-- Conditioning first on `s` and then on `t` results in the same measure as conditioning
on `s ∩ t`. -/
theorem cond_cond_eq_cond_inter (hms : MeasurableSet s) (hmt : MeasurableSet t) (μ : Measure Ω)
[IsFiniteMeasure μ] : μ[|s][|t] = μ[|s ∩ t] :=
cond_cond_eq_cond_inter' hms hmt (measure_ne_top μ s)
theorem cond_mul_eq_inter' (hms : MeasurableSet s) (hcs' : μ s ≠ ∞) (t : Set Ω) :
μ[t|s] * μ s = μ (s ∩ t) := by
obtain hcs | hcs := eq_or_ne (μ s) 0
· simp [hcs, measure_inter_null_of_null_left]
· rw [cond_apply hms, mul_comm, ← mul_assoc, ENNReal.mul_inv_cancel hcs hcs', one_mul]
theorem cond_mul_eq_inter (hms : MeasurableSet s) (t : Set Ω) (μ : Measure Ω) [IsFiniteMeasure μ] :
μ[t|s] * μ s = μ (s ∩ t) := cond_mul_eq_inter' hms (measure_ne_top _ s) t
/-- A version of the law of total probability. -/
theorem cond_add_cond_compl_eq (hms : MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] :
μ[t|s] * μ s + μ[t|sᶜ] * μ sᶜ = μ t := by
rw [cond_mul_eq_inter hms, cond_mul_eq_inter hms.compl, Set.inter_comm _ t,
Set.inter_comm _ t]
exact measure_inter_add_diff t hms
/-- **Bayes' Theorem** -/
theorem cond_eq_inv_mul_cond_mul (hms : MeasurableSet s) (hmt : MeasurableSet t) (μ : Measure Ω)
[IsFiniteMeasure μ] : μ[t|s] = (μ s)⁻¹ * μ[s|t] * μ t := by
rw [mul_assoc, cond_mul_eq_inter hmt s, Set.inter_comm, cond_apply hms]
end Bayes
lemma comap_cond {i : Ω' → Ω} (hi : MeasurableEmbedding i) (hi' : ∀ᵐ ω ∂μ, ω ∈ range i)
(hs : MeasurableSet s) : comap i μ[|s] = (comap i μ)[|i in s] := by
ext t ht
change μ (range i)ᶜ = 0 at hi'
rw [cond_apply, comap_apply, cond_apply, comap_apply, comap_apply, image_inter,
image_preimage_eq_inter_range, inter_right_comm, measure_inter_conull hi',
measure_inter_conull hi']
all_goals first
| exact hi.injective
| exact hi.measurableSet_image'
| exact hs
| exact ht
| exact hi.measurable hs
| exact (hi.measurable hs).inter ht
variable [Fintype α] [MeasurableSpace α] [DiscreteMeasurableSpace α]
/-- The **law of total probability** for a random variable taking finitely many values: a measure
`μ` can be expressed as a linear combination of its conditional measures `μ[|X ← x]` on fibers of a
random variable `X` valued in a fintype. -/
lemma sum_meas_smul_cond_fiber {X : Ω → α} (hX : Measurable X) (μ : Measure Ω) [IsFiniteMeasure μ] :
∑ x, μ (X ⁻¹' {x}) • μ[|X ← x] = μ := by
ext E hE
calc
_ = ∑ x, μ (X ⁻¹' {x} ∩ E) := by
simp only [Measure.coe_finset_sum, Measure.coe_smul, Finset.sum_apply,
Pi.smul_apply, smul_eq_mul]
simp_rw [mul_comm (μ _), cond_mul_eq_inter (hX (.singleton _))]
_ = _ := by
have : ⋃ x ∈ Finset.univ, X ⁻¹' {x} ∩ E = E := by ext; simp
rw [← measure_biUnion_finset _ fun _ _ ↦ (hX (.singleton _)).inter hE, this]
aesop (add simp [PairwiseDisjoint, Set.Pairwise, Function.onFun, disjoint_left])
end ProbabilityTheory
|
Extension.lean
|
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Junyan Xu
-/
import Mathlib.Data.Fintype.Order
import Mathlib.FieldTheory.IntermediateField.Adjoin.Basic
/-!
# Extension of field embeddings
`IntermediateField.exists_algHom_of_adjoin_splits'` is the main result: if E/L/F is a tower of
field extensions, K is another extension of F, and `f` is an embedding of L/F into K/F, such
that the minimal polynomials of a set of generators of E/L splits in K (via `f`), then `f`
extends to an embedding of E/F into K/F.
## Reference
[Isaacs1980] *Roots of Polynomials in Algebraic Extensions of Fields*,
The American Mathematical Monthly
-/
open Polynomial
namespace IntermediateField
variable (F E K : Type*) [Field F] [Field E] [Field K] [Algebra F E] [Algebra F K] {S : Set E}
/-- Lifts `L → K` of `F → K` -/
structure Lifts where
/-- The domain of a lift. -/
carrier : IntermediateField F E
/-- The lifted RingHom, expressed as an AlgHom. -/
emb : carrier →ₐ[F] K
variable {F E K}
namespace Lifts
instance : PartialOrder (Lifts F E K) where
le L₁ L₂ := ∃ h : L₁.carrier ≤ L₂.carrier, ∀ x, L₂.emb (inclusion h x) = L₁.emb x
le_refl L := ⟨le_rfl, by simp⟩
le_trans L₁ L₂ L₃ := by
rintro ⟨h₁₂, h₁₂'⟩ ⟨h₂₃, h₂₃'⟩
refine ⟨h₁₂.trans h₂₃, fun _ ↦ ?_⟩
rw [← inclusion_inclusion h₁₂ h₂₃, h₂₃', h₁₂']
le_antisymm := by
rintro ⟨L₁, e₁⟩ ⟨L₂, e₂⟩ ⟨h₁₂, h₁₂'⟩ ⟨h₂₁, h₂₁'⟩
obtain rfl : L₁ = L₂ := h₁₂.antisymm h₂₁
congr
exact AlgHom.ext h₂₁'
noncomputable instance : OrderBot (Lifts F E K) where
bot := ⟨⊥, (Algebra.ofId F K).comp (botEquiv F E)⟩
bot_le L := ⟨bot_le, fun x ↦ by
obtain ⟨x, rfl⟩ := (botEquiv F E).symm.surjective x
simp_rw [AlgHom.comp_apply, AlgHom.coe_coe, AlgEquiv.apply_symm_apply]
exact L.emb.commutes x⟩
noncomputable instance : Inhabited (Lifts F E K) :=
⟨⊥⟩
variable {L₁ L₂ : Lifts F E K}
theorem le_iff : L₁ ≤ L₂ ↔
∃ h : L₁.carrier ≤ L₂.carrier, L₂.emb.comp (inclusion h) = L₁.emb := by
simp_rw [AlgHom.ext_iff]; rfl
theorem eq_iff_le_carrier_eq : L₁ = L₂ ↔ L₁ ≤ L₂ ∧ L₁.carrier = L₂.carrier :=
⟨fun eq ↦ ⟨eq.le, congr_arg _ eq⟩, fun ⟨le, eq⟩ ↦ le.antisymm ⟨eq.ge, fun x ↦ (le.2 ⟨x, _⟩).symm⟩⟩
theorem eq_iff : L₁ = L₂ ↔
∃ h : L₁.carrier = L₂.carrier, L₂.emb.comp (inclusion h.le) = L₁.emb := by
rw [eq_iff_le_carrier_eq, le_iff]
exact ⟨fun h ↦ ⟨h.2, h.1.2⟩, fun h ↦ ⟨⟨h.1.le, h.2⟩, h.1⟩⟩
theorem lt_iff_le_carrier_ne : L₁ < L₂ ↔ L₁ ≤ L₂ ∧ L₁.carrier ≠ L₂.carrier := by
rw [lt_iff_le_and_ne, and_congr_right]; intro h; simp_rw [Ne, eq_iff_le_carrier_eq, h, true_and]
theorem lt_iff : L₁ < L₂ ↔
∃ h : L₁.carrier < L₂.carrier, L₂.emb.comp (inclusion h.le) = L₁.emb := by
rw [lt_iff_le_carrier_ne, le_iff]
exact ⟨fun h ↦ ⟨h.1.1.lt_of_ne h.2, h.1.2⟩, fun h ↦ ⟨⟨h.1.le, h.2⟩, h.1.ne⟩⟩
theorem le_of_carrier_le_iSup {ι} {ρ : ι → Lifts F E K} {σ τ : Lifts F E K}
(hσ : ∀ i, ρ i ≤ σ) (hτ : ∀ i, ρ i ≤ τ) (carrier_le : σ.carrier ≤ ⨆ i, (ρ i).carrier) :
σ ≤ τ :=
le_iff.mpr ⟨carrier_le.trans (iSup_le fun i ↦ (hτ i).1), algHom_ext_of_eq_adjoin _
(carrier_le.antisymm (iSup_le fun i ↦ (hσ i).1)|>.trans <| iSup_eq_adjoin _ _) fun x hx ↦
have ⟨i, hx⟩ := Set.mem_iUnion.mp hx
((hτ i).2 ⟨x, hx⟩).trans ((hσ i).2 ⟨x, hx⟩).symm⟩
/-- `σ : L →ₐ[F] K` is an extendible lift ("extendible pair" in [Isaacs1980]) if for every
intermediate field `M` that is finite-dimensional over `L`, `σ` extends to some `M →ₐ[F] K`.
In our definition we only require `M` to be finitely generated over `L`, which is equivalent
if the ambient field `E` is algebraic over `F` (which is the case in our main application).
We also allow the domain of the extension to be an intermediate field that properly contains `M`,
since one can always restrict the domain to `M`. -/
def IsExtendible (σ : Lifts F E K) : Prop :=
∀ S : Finset E, ∃ τ ≥ σ, (S : Set E) ⊆ τ.carrier
section Chain
variable (c : Set (Lifts F E K)) (hc : IsChain (· ≤ ·) c)
/-- The union of a chain of lifts. -/
noncomputable def union : Lifts F E K :=
let t (i : ↑(insert ⊥ c)) := i.val.carrier
have hc := hc.insert fun _ _ _ ↦ .inl bot_le
have dir : Directed (· ≤ ·) t := hc.directedOn.directed_val.mono_comp _ fun _ _ h ↦ h.1
⟨iSup t, (Subalgebra.iSupLift (toSubalgebra <| t ·) dir (·.val.emb) (fun i j h ↦
AlgHom.ext fun x ↦ (hc.total i.2 j.2).elim (fun hij ↦ (hij.snd x).symm) fun hji ↦ by
rw [AlgHom.comp_apply, ← inclusion]
dsimp only [coe_type_toSubalgebra]
rw [← hji.snd (inclusion h x), inclusion_inclusion, inclusion_self, AlgHom.id_apply x])
_ rfl).comp
(Subalgebra.equivOfEq _ _ <| toSubalgebra_iSup_of_directed dir)⟩
theorem le_union ⦃σ : Lifts F E K⦄ (hσ : σ ∈ c) : σ ≤ union c hc :=
have hσ := Set.mem_insert_of_mem ⊥ hσ
let t (i : ↑(insert ⊥ c)) := i.val.carrier
⟨le_iSup t ⟨σ, hσ⟩, fun x ↦ by
dsimp only [union, AlgHom.comp_apply]
exact Subalgebra.iSupLift_inclusion (K := (toSubalgebra <| t ·))
(i := ⟨σ, hσ⟩) x (le_iSup (toSubalgebra <| t ·) ⟨σ, hσ⟩)⟩
theorem carrier_union : (union c hc).carrier = ⨆ i : c, i.1.carrier :=
le_antisymm (iSup_le <| by rintro ⟨i, rfl | hi⟩; exacts [bot_le, le_iSup_of_le ⟨i, hi⟩ le_rfl]) <|
iSup_le fun i ↦ le_iSup_of_le ⟨i, .inr i.2⟩ le_rfl
/-- A chain of lifts has an upper bound. -/
theorem exists_upper_bound (c : Set (Lifts F E K)) (hc : IsChain (· ≤ ·) c) :
∃ ub, ∀ a ∈ c, a ≤ ub := ⟨_, le_union c hc⟩
theorem union_isExtendible [alg : Algebra.IsAlgebraic F E]
[Nonempty c] (hext : ∀ σ ∈ c, σ.IsExtendible) :
(union c hc).IsExtendible := fun S ↦ by
let Ω := adjoin F (S : Set E) →ₐ[F] K
have ⟨ω, hω⟩ : ∃ ω : Ω, ∀ π : c, ∃ θ ≥ π.1, ⟨_, ω⟩ ≤ θ ∧ θ.carrier = π.1.1 ⊔ adjoin F S := by
by_contra!; choose π hπ using this
have := finiteDimensional_adjoin (S := (S : Set E)) fun _ _ ↦ (alg.isIntegral).1 _
have ⟨π₀, hπ₀⟩ := hc.directed.finite_le π
have ⟨θ, hθπ, hθ⟩ := hext _ π₀.2 S
rw [← adjoin_le_iff] at hθ
let θ₀ := θ.emb.comp (inclusion hθ)
have := (hπ₀ θ₀).trans hθπ
exact hπ θ₀ ⟨_, θ.emb.comp <| inclusion <| sup_le this.1 hθ⟩
⟨le_sup_left, this.2⟩ ⟨le_sup_right, fun _ ↦ rfl⟩ rfl
choose θ ge hθ eq using hω
have : IsChain (· ≤ ·) (Set.range θ) := by
simp_rw [← restrictScalars_adjoin_eq_sup, restrictScalars_adjoin] at eq
rintro _ ⟨π₁, rfl⟩ _ ⟨π₂, rfl⟩ -
wlog h : π₁ ≤ π₂ generalizing π₁ π₂
· exact (this _ _ <| (hc.total π₁.2 π₂.2).resolve_left h).symm
refine .inl (le_iff.mpr ⟨?_, algHom_ext_of_eq_adjoin _ (eq _) ?_⟩)
· rw [eq, eq]; exact adjoin.mono _ _ _ (Set.union_subset_union_left _ h.1)
rintro x (hx|hx)
· change (θ π₂).emb (inclusion (ge π₂).1 <| inclusion h.1 ⟨x, hx⟩) =
(θ π₁).emb (inclusion (ge π₁).1 ⟨x, hx⟩)
rw [(ge π₁).2, (ge π₂).2, h.2]
· change (θ π₂).emb (inclusion (hθ π₂).1 ⟨x, subset_adjoin _ _ hx⟩) =
(θ π₁).emb (inclusion (hθ π₁).1 ⟨x, subset_adjoin _ _ hx⟩)
rw [(hθ π₁).2, (hθ π₂).2]
refine ⟨union _ this, le_of_carrier_le_iSup (fun π ↦ le_union c hc π.2)
(fun π ↦ (ge π).trans <| le_union _ _ ⟨_, rfl⟩) (carrier_union _ _).le, ?_⟩
simp_rw [carrier_union, iSup_range', eq]
exact (subset_adjoin _ _).trans (SetLike.coe_subset_coe.mpr <|
le_sup_right.trans <| le_iSup_of_le (Classical.arbitrary _) le_rfl)
end Chain
theorem nonempty_algHom_of_exist_lifts_finset [alg : Algebra.IsAlgebraic F E]
(h : ∀ S : Finset E, ∃ σ : Lifts F E K, (S : Set E) ⊆ σ.carrier) :
Nonempty (E →ₐ[F] K) := by
have : (⊥ : Lifts F E K).IsExtendible := fun S ↦ have ⟨σ, hσ⟩ := h S; ⟨σ, bot_le, hσ⟩
have ⟨ϕ, hϕ⟩ := zorn_le₀ {ϕ : Lifts F E K | ϕ.IsExtendible}
fun c hext hc ↦ (isEmpty_or_nonempty c).elim
(fun _ ↦ ⟨⊥, this, fun ϕ hϕ ↦ isEmptyElim (⟨ϕ, hϕ⟩ : c)⟩)
fun _ ↦ ⟨_, union_isExtendible c hc hext, le_union c hc⟩
suffices ϕ.carrier = ⊤ from ⟨ϕ.emb.comp <| ((equivOfEq this).trans topEquiv).symm⟩
by_contra!
obtain ⟨α, -, hα⟩ := SetLike.exists_of_lt this.lt_top
let _ : Algebra ϕ.carrier K := ϕ.emb.toAlgebra
let Λ := ϕ.carrier⟮α⟯ →ₐ[ϕ.carrier] K
have := finiteDimensional_adjoin (S := {α}) fun _ _ ↦ ((alg.tower_top ϕ.carrier).isIntegral).1 _
let L (σ : Λ) : Lifts F E K := ⟨ϕ.carrier⟮α⟯.restrictScalars F, σ.restrictScalars F⟩
have hL (σ : Λ) : ϕ < L σ := lt_iff.mpr
⟨by simpa only [L, restrictScalars_adjoin_eq_sup, left_lt_sup, adjoin_simple_le_iff],
AlgHom.coe_ringHom_injective σ.comp_algebraMap⟩
have ⟨(ϕ_ext : ϕ.IsExtendible), ϕ_max⟩ := maximal_iff_forall_gt.mp hϕ
simp_rw [Set.mem_setOf, IsExtendible] at ϕ_max; push_neg at ϕ_max
choose S hS using fun σ : Λ ↦ ϕ_max (hL σ)
classical
have ⟨θ, hθϕ, hθ⟩ := ϕ_ext ({α} ∪ Finset.univ.biUnion S)
simp_rw [Finset.coe_union, Set.union_subset_iff, Finset.coe_singleton, Set.singleton_subset_iff,
Finset.coe_biUnion, Finset.coe_univ, Set.mem_univ, Set.iUnion_true, Set.iUnion_subset_iff] at hθ
have : ϕ.carrier⟮α⟯.restrictScalars F ≤ θ.carrier := by
rw [restrictScalars_adjoin_eq_sup, sup_le_iff, adjoin_simple_le_iff]; exact ⟨hθϕ.1, hθ.1⟩
exact hS ⟨(θ.emb.comp <| inclusion this).toRingHom, hθϕ.2⟩ θ ⟨this, fun _ ↦ rfl⟩ (hθ.2 _)
/-- Given a lift `x` and an integral element `s : E` over `x.carrier` whose conjugates over
`x.carrier` are all in `K`, we can extend the lift to a lift whose carrier contains `s`. -/
theorem exists_lift_of_splits' (x : Lifts F E K) {s : E} (h1 : IsIntegral x.carrier s)
(h2 : (minpoly x.carrier s).Splits x.emb.toRingHom) : ∃ y, x ≤ y ∧ s ∈ y.carrier :=
have I2 := (minpoly.degree_pos h1).ne'
letI : Algebra x.carrier K := x.emb.toRingHom.toAlgebra
let carrier := x.carrier⟮s⟯.restrictScalars F
letI : Algebra x.carrier carrier := x.carrier⟮s⟯.toSubalgebra.algebra
let φ : carrier →ₐ[x.carrier] K := ((algHomAdjoinIntegralEquiv x.carrier h1).symm
⟨rootOfSplits x.emb.toRingHom h2 I2, by
rw [mem_aroots, and_iff_right (minpoly.ne_zero h1)]
exact map_rootOfSplits x.emb.toRingHom h2 I2⟩)
⟨⟨carrier, (@algHomEquivSigma F x.carrier carrier K _ _ _ _ _ _ _ _
(IsScalarTower.of_algebraMap_eq fun _ ↦ rfl)).symm ⟨x.emb, φ⟩⟩,
⟨fun z hz ↦ algebraMap_mem x.carrier⟮s⟯ ⟨z, hz⟩, φ.commutes⟩,
mem_adjoin_simple_self x.carrier s⟩
/-- Given an integral element `s : E` over `F` whose `F`-conjugates are all in `K`,
any lift can be extended to one whose carrier contains `s`. -/
theorem exists_lift_of_splits (x : Lifts F E K) {s : E} (h1 : IsIntegral F s)
(h2 : (minpoly F s).Splits (algebraMap F K)) : ∃ y, x ≤ y ∧ s ∈ y.carrier :=
exists_lift_of_splits' x h1.tower_top <| h1.minpoly_splits_tower_top' <| by
rwa [← x.emb.comp_algebraMap] at h2
end Lifts
section
private theorem exists_algHom_adjoin_of_splits'' {L : IntermediateField F E}
(f : L →ₐ[F] K) (hK : ∀ s ∈ S, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom) :
∃ φ : adjoin L S →ₐ[F] K, φ.restrictDomain L = f := by
obtain ⟨φ, hfφ, hφ⟩ := zorn_le_nonempty_Ici₀ _
(fun c _ hc _ _ ↦ Lifts.exists_upper_bound c hc) ⟨L, f⟩ le_rfl
refine ⟨φ.emb.comp (inclusion <| (le_extendScalars_iff hfφ.1 <| adjoin L S).mp <|
adjoin_le_iff.mpr fun s h ↦ ?_), AlgHom.ext hfφ.2⟩
letI := (inclusion hfφ.1).toAlgebra
letI : SMul L φ.carrier := Algebra.toSMul
have : IsScalarTower L φ.carrier E := ⟨fun x y ↦ smul_assoc x (y : E)⟩
have := φ.exists_lift_of_splits' (hK s h).1.tower_top ((hK s h).1.minpoly_splits_tower_top' ?_)
· obtain ⟨y, h1, h2⟩ := this
exact (hφ h1).1 h2
· convert (hK s h).2; ext; apply hfφ.2
variable {L : Type*} [Field L] [Algebra F L] [Algebra L E] [IsScalarTower F L E]
(f : L →ₐ[F] K) (hK : ∀ s ∈ S, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom)
include hK in
theorem exists_algHom_adjoin_of_splits' :
∃ φ : adjoin L S →ₐ[F] K, φ.restrictDomain L = f := by
let L' := (IsScalarTower.toAlgHom F L E).fieldRange
let f' : L' →ₐ[F] K := f.comp (AlgEquiv.ofInjectiveField _).symm.toAlgHom
have := exists_algHom_adjoin_of_splits'' f' (S := S) fun s hs ↦ ?_
· obtain ⟨φ, hφ⟩ := this; refine ⟨φ.comp <|
inclusion (?_ : (adjoin L S).restrictScalars F ≤ (adjoin L' S).restrictScalars F), ?_⟩
· simp_rw [← SetLike.coe_subset_coe, coe_restrictScalars, adjoin_subset_adjoin_iff]
exact ⟨subset_adjoin_of_subset_left S (F := L'.toSubfield) le_rfl, subset_adjoin _ _⟩
· ext x
let y := (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L E)) x
refine Eq.trans congr($hφ y) ?_
simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_comp, AlgHom.coe_coe, Function.comp_apply, f']
exact congr_arg f (AlgEquiv.symm_apply_apply _ _)
letI : Algebra L L' := (AlgEquiv.ofInjectiveField _).toRingHom.toAlgebra
have : IsScalarTower L L' E := IsScalarTower.of_algebraMap_eq' rfl
refine ⟨(hK s hs).1.tower_top, (hK s hs).1.minpoly_splits_tower_top' ?_⟩
convert (hK s hs).2
ext
simp only [AlgEquiv.toAlgHom_eq_coe, AlgHom.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe,
AlgHom.coe_comp, AlgHom.coe_coe, Function.comp_apply, f']
exact congr_arg f (AlgEquiv.symm_apply_apply _ _)
include hK in
theorem exists_algHom_of_adjoin_splits' (hS : adjoin L S = ⊤) :
∃ φ : E →ₐ[F] K, φ.restrictDomain L = f :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits' f hK
⟨φ.comp (((equivOfEq hS).trans topEquiv).symm.toAlgHom.restrictScalars F), hφ⟩
theorem exists_algHom_of_splits' (hK : ∀ s : E, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom) :
∃ φ : E →ₐ[F] K, φ.restrictDomain L = f :=
exists_algHom_of_adjoin_splits' f (fun x _ ↦ hK x) (adjoin_univ L E)
end
variable (hK : ∀ s ∈ S, IsIntegral F s ∧ (minpoly F s).Splits (algebraMap F K))
(hK' : ∀ s : E, IsIntegral F s ∧ (minpoly F s).Splits (algebraMap F K))
{L : IntermediateField F E} (f : L →ₐ[F] K) (hL : L ≤ adjoin F S) {x : E} {y : K}
section
include hK
theorem exists_algHom_adjoin_of_splits : ∃ φ : adjoin F S →ₐ[F] K, φ.comp (inclusion hL) = f := by
obtain ⟨φ, hfφ, hφ⟩ := zorn_le_nonempty_Ici₀ _
(fun c _ hc _ _ ↦ Lifts.exists_upper_bound c hc) ⟨L, f⟩ le_rfl
refine ⟨φ.emb.comp (inclusion <| adjoin_le_iff.mpr fun s hs ↦ ?_), ?_⟩
· rcases φ.exists_lift_of_splits (hK s hs).1 (hK s hs).2 with ⟨y, h1, h2⟩
exact (hφ h1).1 h2
· ext; apply hfφ.2
theorem nonempty_algHom_adjoin_of_splits : Nonempty (adjoin F S →ₐ[F] K) :=
have ⟨φ, _⟩ := exists_algHom_adjoin_of_splits hK (⊥ : Lifts F E K).emb bot_le; ⟨φ⟩
variable (hS : adjoin F S = ⊤)
include hS in
theorem exists_algHom_of_adjoin_splits : ∃ φ : E →ₐ[F] K, φ.comp L.val = f :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits hK f (hS.symm ▸ le_top)
⟨φ.comp ((equivOfEq hS).trans topEquiv).symm.toAlgHom, hφ⟩
include hS in
theorem nonempty_algHom_of_adjoin_splits : Nonempty (E →ₐ[F] K) :=
have ⟨φ, _⟩ := exists_algHom_of_adjoin_splits hK (⊥ : Lifts F E K).emb hS; ⟨φ⟩
variable (hx : x ∈ adjoin F S) (hy : aeval y (minpoly F x) = 0)
include hy
theorem exists_algHom_adjoin_of_splits_of_aeval : ∃ φ : adjoin F S →ₐ[F] K, φ ⟨x, hx⟩ = y := by
have := isAlgebraic_adjoin (fun s hs ↦ (hK s hs).1)
have ix : IsAlgebraic F _ := Algebra.IsAlgebraic.isAlgebraic (⟨x, hx⟩ : adjoin F S)
rw [isAlgebraic_iff_isIntegral, isIntegral_iff] at ix
obtain ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits hK ((algHomAdjoinIntegralEquiv F ix).symm
⟨y, mem_aroots.mpr ⟨minpoly.ne_zero ix, hy⟩⟩) (adjoin_simple_le_iff.mpr hx)
exact ⟨φ, (DFunLike.congr_fun hφ <| AdjoinSimple.gen F x).trans <|
algHomAdjoinIntegralEquiv_symm_apply_gen F ix _⟩
include hS in
theorem exists_algHom_of_adjoin_splits_of_aeval : ∃ φ : E →ₐ[F] K, φ x = y :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits_of_aeval hK (hS ▸ mem_top) hy
⟨φ.comp ((equivOfEq hS).trans topEquiv).symm.toAlgHom, hφ⟩
include hK'
end
section
include hK'
theorem exists_algHom_of_splits : ∃ φ : E →ₐ[F] K, φ.comp L.val = f :=
exists_algHom_of_adjoin_splits (fun x _ ↦ hK' x) f (adjoin_univ F E)
theorem nonempty_algHom_of_splits : Nonempty (E →ₐ[F] K) :=
nonempty_algHom_of_adjoin_splits (fun x _ ↦ hK' x) (adjoin_univ F E)
theorem exists_algHom_of_splits_of_aeval (hy : aeval y (minpoly F x) = 0) :
∃ φ : E →ₐ[F] K, φ x = y :=
exists_algHom_of_adjoin_splits_of_aeval (fun x _ ↦ hK' x) (adjoin_univ F E) hy
end
end IntermediateField
section Algebra.IsAlgebraic
/-- Let `K/F` be an algebraic extension of fields and `L` a field in which all the minimal
polynomial over `F` of elements of `K` splits. Then, for `x ∈ K`, the images of `x` by the
`F`-algebra morphisms from `K` to `L` are exactly the roots in `L` of the minimal polynomial
of `x` over `F`. -/
theorem Algebra.IsAlgebraic.range_eval_eq_rootSet_minpoly_of_splits {F K : Type*} (L : Type*)
[Field F] [Field K] [Field L] [Algebra F L] [Algebra F K]
(hA : ∀ x : K, (minpoly F x).Splits (algebraMap F L))
[Algebra.IsAlgebraic F K] (x : K) :
(Set.range fun (ψ : K →ₐ[F] L) => ψ x) = (minpoly F x).rootSet L := by
ext a
rw [mem_rootSet_of_ne (minpoly.ne_zero (Algebra.IsIntegral.isIntegral x))]
refine ⟨fun ⟨ψ, hψ⟩ ↦ ?_, fun ha ↦ IntermediateField.exists_algHom_of_splits_of_aeval
(fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, hA x⟩) ha⟩
rw [← hψ, Polynomial.aeval_algHom_apply ψ x, minpoly.aeval, map_zero]
end Algebra.IsAlgebraic
|
TensorProduct.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.BilinearForm.TensorProduct
import Mathlib.LinearAlgebra.QuadraticForm.Basic
/-!
# The quadratic form on a tensor product
## Main definitions
* `QuadraticForm.tensorDistrib (Q₁ ⊗ₜ Q₂)`: the quadratic form on `M₁ ⊗ M₂` constructed by applying
`Q₁` on `M₁` and `Q₂` on `M₂`. This construction is not available in characteristic two.
-/
universe uR uA uM₁ uM₂ uN₁ uN₂
variable {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂} {N₁ : Type uN₁} {N₂ : Type uN₂}
open LinearMap (BilinMap BilinForm)
open TensorProduct QuadraticMap
section CommRing
variable [CommRing R] [CommRing A]
variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup N₁] [AddCommGroup N₂]
variable [Algebra R A] [Module R M₁] [Module A M₁] [Module R N₁] [Module A N₁]
variable [SMulCommClass R A M₁] [IsScalarTower R A M₁] [IsScalarTower R A N₁]
variable [Module R M₂] [Module R N₂]
section InvertibleTwo
variable [Invertible (2 : R)]
namespace QuadraticMap
variable (R A) in
/-- The tensor product of two quadratic maps injects into quadratic maps on tensor products.
Note this is heterobasic; the quadratic map on the left can take values in a module over a larger
ring than the one on the right. -/
def tensorDistrib :
QuadraticMap A M₁ N₁ ⊗[R] QuadraticMap R M₂ N₂ →ₗ[A] QuadraticMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) :=
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
-- while `letI`s would produce a better term than `let`, they would make this already-slow
-- definition even slower.
let toQ := BilinMap.toQuadraticMapLinearMap A A (M₁ ⊗[R] M₂)
let tmulB := BilinMap.tensorDistrib R A (M₁ := M₁) (M₂ := M₂)
let toB := AlgebraTensorModule.map
(QuadraticMap.associated : QuadraticMap A M₁ N₁ →ₗ[A] BilinMap A M₁ N₁)
(QuadraticMap.associated : QuadraticMap R M₂ N₂ →ₗ[R] BilinMap R M₂ N₂)
toQ ∘ₗ tmulB ∘ₗ toB
@[simp]
theorem tensorDistrib_tmul (Q₁ : QuadraticMap A M₁ N₁) (Q₂ : QuadraticMap R M₂ N₂) (m₁ : M₁)
(m₂ : M₂) : tensorDistrib R A (Q₁ ⊗ₜ Q₂) (m₁ ⊗ₜ m₂) = Q₁ m₁ ⊗ₜ Q₂ m₂ :=
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
(BilinMap.tensorDistrib_tmul _ _ _ _ _ _).trans <| congr_arg₂ _
(associated_eq_self_apply _ _ _) (associated_eq_self_apply _ _ _)
/-- The tensor product of two quadratic maps, a shorthand for dot notation. -/
protected abbrev tmul (Q₁ : QuadraticMap A M₁ N₁)
(Q₂ : QuadraticMap R M₂ N₂) : QuadraticMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) :=
tensorDistrib R A (Q₁ ⊗ₜ[R] Q₂)
theorem associated_tmul [Invertible (2 : A)]
(Q₁ : QuadraticMap A M₁ N₁) (Q₂ : QuadraticMap R M₂ N₂) :
(Q₁.tmul Q₂).associated = Q₁.associated.tmul Q₂.associated := by
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
rw [QuadraticMap.tmul, BilinMap.tmul]
have : Subsingleton (Invertible (2 : A)) := inferInstance
convert associated_left_inverse A (LinearMap.BilinMap.tmul_isSymm
(QuadraticMap.associated_isSymm A Q₁) (QuadraticMap.associated_isSymm R Q₂))
end QuadraticMap
namespace QuadraticForm
variable (R A) in
/-- The tensor product of two quadratic forms injects into quadratic forms on tensor products.
Note this is heterobasic; the quadratic form on the left can take values in a larger ring than
the one on the right. -/
def tensorDistrib :
QuadraticForm A M₁ ⊗[R] QuadraticForm R M₂ →ₗ[A] QuadraticForm A (M₁ ⊗[R] M₂) :=
(AlgebraTensorModule.rid R A A).congrQuadraticMap.toLinearMap ∘ₗ QuadraticMap.tensorDistrib R A
-- TODO: make the RHS `MulOpposite.op (Q₂ m₂) • Q₁ m₁` so that this has a nicer defeq for
-- `R = A` of `Q₁ m₁ * Q₂ m₂`.
@[simp]
theorem tensorDistrib_tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) (m₁ : M₁) (m₂ : M₂) :
tensorDistrib R A (Q₁ ⊗ₜ Q₂) (m₁ ⊗ₜ m₂) = Q₂ m₂ • Q₁ m₁ :=
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
(LinearMap.BilinForm.tensorDistrib_tmul _ _ _ _ _ _ _ _).trans <| congr_arg₂ _
(associated_eq_self_apply _ _ _) (associated_eq_self_apply _ _ _)
/-- The tensor product of two quadratic forms, a shorthand for dot notation. -/
protected abbrev tmul (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) :
QuadraticForm A (M₁ ⊗[R] M₂) :=
tensorDistrib R A (Q₁ ⊗ₜ[R] Q₂)
theorem associated_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) :
(Q₁.tmul Q₂).associated = BilinForm.tmul Q₁.associated Q₂.associated := by
rw [BilinForm.tmul, BilinForm.tensorDistrib, LinearMap.comp_apply, ← BilinMap.tmul,
← QuadraticMap.associated_tmul Q₁ Q₂]
aesop
theorem polarBilin_tmul [Invertible (2 : A)] (Q₁ : QuadraticForm A M₁) (Q₂ : QuadraticForm R M₂) :
polarBilin (Q₁.tmul Q₂) = ⅟(2 : A) • BilinForm.tmul (polarBilin Q₁) (polarBilin Q₂) := by
simp_rw [← two_nsmul_associated A, ← two_nsmul_associated R, BilinForm.tmul, tmul_smul,
← smul_tmul', map_nsmul, associated_tmul]
rw [smul_comm (_ : A) (_ : ℕ), ← smul_assoc, two_smul _ (_ : A), invOf_two_add_invOf_two,
one_smul]
variable (A) in
/-- The base change of a quadratic form. -/
protected def baseChange (Q : QuadraticForm R M₂) : QuadraticForm A (A ⊗[R] M₂) :=
QuadraticForm.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (QuadraticMap.sq (R := A)) Q
@[simp]
theorem baseChange_tmul (Q : QuadraticForm R M₂) (a : A) (m₂ : M₂) :
Q.baseChange A (a ⊗ₜ m₂) = Q m₂ • (a * a) :=
tensorDistrib_tmul _ _ _ _
theorem associated_baseChange [Invertible (2 : A)] (Q : QuadraticForm R M₂) :
associated (R := A) (Q.baseChange A) = BilinForm.baseChange A (associated (R := R) Q) := by
dsimp only [QuadraticForm.baseChange, LinearMap.baseChange]
rw [associated_tmul (QuadraticMap.sq (R := A)) Q, associated_sq]
exact rfl
theorem polarBilin_baseChange [Invertible (2 : A)] (Q : QuadraticForm R M₂) :
polarBilin (Q.baseChange A) = BilinForm.baseChange A (polarBilin Q) := by
rw [QuadraticForm.baseChange, BilinForm.baseChange, polarBilin_tmul, BilinForm.tmul,
← LinearMap.map_smul, smul_tmul', ← two_nsmul_associated R, coe_associatedHom, associated_sq,
smul_comm, ← smul_assoc, two_smul, invOf_two_add_invOf_two, one_smul]
end QuadraticForm
end InvertibleTwo
/-- If two quadratic maps from `A ⊗[R] M₂` agree on elements of the form `1 ⊗ m`, they are equal.
In other words, if a base change exists for a quadratic map, it is unique.
Note that unlike `QuadraticForm.baseChange`, this does not need `Invertible (2 : R)`. -/
@[ext]
theorem baseChange_ext ⦃Q₁ Q₂ : QuadraticMap A (A ⊗[R] M₂) N₁⦄
(h : ∀ m, Q₁ (1 ⊗ₜ m) = Q₂ (1 ⊗ₜ m)) :
Q₁ = Q₂ := by
replace h (a m) : Q₁ (a ⊗ₜ m) = Q₂ (a ⊗ₜ m) := by
rw [← mul_one a, ← smul_eq_mul, ← smul_tmul', QuadraticMap.map_smul, QuadraticMap.map_smul, h]
ext x
induction x with
| tmul => simp [h]
| zero => simp
| add x y hx hy =>
have : Q₁.polarBilin = Q₂.polarBilin := by
ext
dsimp [polar]
rw [← TensorProduct.tmul_add, h, h, h]
replace := congr($this x y)
dsimp [polar] at this
linear_combination (norm := module) this + hx + hy
end CommRing
|
spectral.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat.
From mathcomp Require Import seq div fintype bigop ssralg finset fingroup zmodp.
From mathcomp Require Import poly polydiv order ssrnum matrix mxalgebra vector.
From mathcomp Require Import mxpoly mxred sesquilinear.
(******************************************************************************)
(* Spectral theory *)
(* *)
(* This file provides a formalization of Gram-Schmidt orthonormalization, *)
(* Schur decomposition, etc. *)
(* *)
(* M ^t* := M ^t conjC *)
(* Notation in scope sesquilinear_scope. *)
(* M \is unitarymx == M is a unitary matrix *)
(* M : 'M[C]_(m, n) with C : numClosedFieldType *)
(* M \is normalmx == M is a normal matrix *)
(* M : 'M[C]_n with C : numClosedFieldType *)
(* *)
(* dotmx u v == dot product *)
(* u and v are row vectors over a numClosedFieldType *)
(* Local notations: '[u, v] := dotmx u v, *)
(* '[u] := '[u, u] *)
(* proj_ortho Y := proj_mx <<U>>%MS U^!%MS *)
(* where U^! is a 1-orthogonal completement of U *)
(* schmidt A == Gram-Schmidt basis *)
(* A : 'M[C]_(m, n) *)
(* schmidt_complete V := col_mx (schmidt (row_base V)) *)
(* (schmidt (row_base V^!%MS)) *)
(* spectralmx A, spectral_diag A == (M,X) s.t. A = M^-1 *m diag_mx X *m M *)
(* A : 'M[C]_n *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Order.Theory Num.Theory.
Local Open Scope ring_scope.
Local Open Scope sesquilinear_scope.
(* TODO: move? *)
Lemma eigenvalue_closed {C : numClosedFieldType} n (A : 'M[C]_n) : (n > 0)%N ->
exists a, eigenvalue A a.
Proof.
move=> n_gt0; have /closed_rootP [a rAa] : size (char_poly A) != 1%N.
by rewrite size_char_poly; case: (n) n_gt0.
by exists a; rewrite eigenvalue_root_char.
Qed.
(* TODO: move? *)
Lemma common_eigenvector {C : numClosedFieldType} n (As : seq 'M[C]_n) :
(n > 0)%N -> {in As &, forall A B, comm_mx A B} ->
exists2 v : 'rV_n, v != 0 & all (fun A => stablemx v A) As.
Proof.
move=> n_gt0 /all_comm_mxP; have [k sAsk] := ubnP (size As).
elim: k n n_gt0 As sAsk => [//|k IHk] n n_gt0 [|A As].
exists (const_mx 1) => //; apply/negP => /eqP/rowP/(_ (Ordinal n_gt0)).
by rewrite !mxE => /eqP; rewrite oner_eq0.
rewrite ltnS all_comm_mx_cons => sAsk /andP[].
move=> /allP/(_ _ _)/eqP/= A_comm /all_comm_mxP As_comm.
have [a a_eigen] := eigenvalue_closed A n_gt0.
have [] := IHk _ _ [seq restrictmx (eigenspace A a) B | B <- As].
- by rewrite lt0n mxrank_eq0.
- by rewrite size_map.
- apply/all_comm_mxP; move=> _ _ /= /mapP /= [B B_in ->] /mapP /= [B' B'_in ->].
rewrite -?conjmxM ?inE ?stablemx_row_base ?comm_mx_stable_eigenspace//;
by [rewrite As_comm | apply: As_comm | apply: A_comm].
move=> v vN0 /allP /= vP; exists (v *m (row_base (eigenspace A a))).
by rewrite mulmx_free_eq0 ?row_base_free.
apply/andP; split.
by apply/eigenvectorP; exists a; rewrite mulmx_sub // eq_row_base.
apply/allP => B B_in; rewrite -stablemx_restrict ?vP //.
by apply/mapP; exists B.
by rewrite comm_mx_stable_eigenspace //; exact: A_comm.
Qed.
(* TODO: move? *)
Lemma common_eigenvector2 {C : numClosedFieldType}n (A B : 'M[C]_n) :
(n > 0)%N -> A *m B = B *m A ->
exists2 v : 'rV_n, v != 0 & (stablemx v A) && (stablemx v B).
Proof.
move=> n_gt0 AB_comm; have [] := @common_eigenvector _ _ [:: A; B] n_gt0.
by move=> A' B'; rewrite !inE => /orP [] /eqP-> /orP [] /eqP->.
by move=> v v_neq0 /allP vP; exists v; rewrite ?vP ?(mem_head, in_cons, orbT).
Qed.
Notation "M ^t*" := (M ^t conjC) (at level 30) : sesquilinear_scope.
Notation realmx := (mxOver Num.real).
Lemma trmxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) : A ^t* ^t* = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
Section realmx.
Context {C : numClosedFieldType} {m n : nat}.
Implicit Types A B : 'M[C]_(m, n).
Lemma realmxC A : A \is a realmx -> A ^ conjC = A.
Proof.
by move=> ?; apply/matrixP => x y; rewrite mxE; exact/CrealP/mxOverP.
Qed.
Lemma realmxD A B : A \is a realmx -> B \is a realmx -> A + B \is a realmx.
Proof.
rewrite !qualifE/= => /'forall_forallP realA /'forall_forallP realB.
by apply/'forall_forallP => i j; rewrite mxE realD.
Qed.
Lemma Remx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Re _) = A}.
Proof.
move=> A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Re_rect // (mxOverP _ _).
Qed.
Lemma Immx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Im _) = B}.
Proof.
move=> /= A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Im_rect // (mxOverP _ _).
Qed.
Lemma eqmx_ReiIm A B A' B' :
A \is a realmx -> B \is a realmx -> A' \is a realmx -> B' \is a realmx ->
(A + 'i *: B) = (A' + 'i *: B') -> (A, B) = (A', B').
Proof.
move=> ARe BRe A'Im B'Im eqAB.
have /(congr1 (fun A => A ^ (@Im _))) := eqAB.
have /(congr1 (fun A => A ^ (@Re _))) := eqAB.
by rewrite !Remx_rect// !Immx_rect// => -> ->.
Qed.
End realmx.
Lemma realsym_hermsym {C : numClosedFieldType} {n} (A : 'M[C]_n) :
A \is symmetricmx -> A \is a realmx -> A \is hermsymmx.
Proof.
move=> Asym Areal; apply/is_hermitianmxP.
by rewrite (trmx_hermitian (HermitianMx Asym))/= !scale1r ?realmxC ?map_mx_id.
Qed.
Lemma real_similar {C : numClosedFieldType} {n} (A B : 'M[C]_n) :
similar_in unitmx A B ->
A \is a realmx -> B \is a realmx -> similar_in [predI realmx & unitmx] A B.
Proof.
case=> [P /=]; pose Pr := P ^ (@Re _); pose Pi := P ^ (@Im _).
have Pr_real : Pr \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Re.
have Pi_real : Pi \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Im.
pose Q x := P ^ (@Re _) + x *: P ^ (@Im _).
have -> : P = Q 'i by apply/matrixP=> i j; rewrite !mxE -Crect.
move=> Qi_unit eq_AP_PB Areal Breal.
pose p := \det (Pr ^ polyC + 'X *: Pi ^ polyC).
have horner_evaliC x : horner_eval (x : C) \o polyC =1 id := fun=> hornerC _ _.
have Qunit x : Q x \in unitmx = (p.[x] != 0).
rewrite /p -horner_evalE -det_map_mx map_mxD map_mxZ/= horner_evalE hornerX.
by rewrite -![(_ ^ polyC) ^ _]map_mx_comp !map_mx_id// unitmxE unitfE.
have p_neq0 : p != 0.
by move: Qi_unit; rewrite Qunit; apply: contra_neq => ->; rewrite hornerE.
have [a a_real rootNa] : exists2 a, a \is Num.real & ~~ root p a.
have rs_uniq : uniq [seq (i%:R : C) | i <- iota 0 (size p)].
by rewrite map_inj_uniq ?iota_uniq //; apply: mulrIn; rewrite oner_eq0.
have := contraNN (fun x => max_poly_roots p_neq0 x rs_uniq).
rewrite size_map size_iota ltnn => /(_ isT) /allPn[a a_in rootNpa].
by exists a => //; by move: a_in => /mapP [i _ ->]; rewrite realn.
exists (Q a).
rewrite inE Qunit rootNa andbT.
rewrite /Q/=.
by rewrite realmxD// mxOverZ.
apply/similarP; rewrite ?Qunit//; move: eq_AP_PB => /(similarP Qi_unit).
rewrite !mulmxDl !mulmxDr -!scalemxAr -!scalemxAl => /eqmx_ReiIm.
by rewrite !mxOverM// => /(_ isT isT isT isT) [-> ->].
Qed.
Section unitarymx.
Context {C : numClosedFieldType}.
Definition unitarymx {m n} := [qualify X : 'M[C]_(m, n) | X *m X ^t* == 1%:M].
Fact unitarymx_key m n : pred_key (@unitarymx m n). Proof. by []. Qed.
Canonical unitarymx_keyed m n := KeyedQualifier (unitarymx_key m n).
Lemma unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (M *m M^t* = 1%:M) (M \is unitarymx).
Proof. by apply: (iffP eqP). Qed.
Lemma mulmxtVK m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(n, m2)) :
B \is unitarymx -> A *m B *m B^t* = A.
Proof. by move=> B_unitary; rewrite -mulmxA (unitarymxP _) ?mulmx1. Qed.
Lemma unitarymx_unit n (M : 'M[C]_n) : M \is unitarymx -> M \in unitmx.
Proof. by move=> /unitarymxP /mulmx1_unit []. Qed.
Lemma invmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> invmx M = M^t*.
Proof.
move=> Munitary; apply: (@row_full_inj _ _ _ _ M).
by rewrite row_full_unit unitarymx_unit.
by rewrite mulmxV ?unitarymx_unit ?(unitarymxP _).
Qed.
Lemma mulmxKtV m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(m2, n)) :
B \is unitarymx -> m2 = n -> A *m B^t* *m B = A.
Proof.
move=> B_unitary m2E; case: _ / (esym m2E) in B B_unitary *.
by rewrite -invmx_unitary // mulmxKV //; exact: unitarymx_unit.
Qed.
Lemma mxrank_unitary m n (M : 'M[C]_(m, n)) : M \is unitarymx -> \rank M = m.
Proof.
rewrite qualifE => /eqP /(congr1 mxrank); rewrite mxrank1 => rkM.
apply/eqP; rewrite eqn_leq rank_leq_row /= -[X in (X <= _)%N]rkM.
by rewrite mxrankM_maxl.
Qed.
Lemma mul_unitarymx m n p (A : 'M[C]_(m, n)) (B : 'M[C]_(n, p)) :
A \is unitarymx -> B \is unitarymx -> A *m B \is unitarymx.
Proof.
move=> Aunitary Bunitary; apply/unitarymxP; rewrite trmx_mul map_mxM.
by rewrite mulmxA -[A *m _ *m _]mulmxA !(unitarymxP _, mulmx1).
Qed.
Lemma pinvmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> pinvmx M = M^t*.
Proof. by move=> Munitary; rewrite pinvmxE ?unitarymx_unit// invmx_unitary. Qed.
Lemma conjymx n (P M : 'M[C]_n) : P \is unitarymx -> conjmx P M = P *m M *m P^t*.
Proof. by move=> Munitary; rewrite conjumx ?invmx_unitary ?unitarymx_unit. Qed.
Lemma trmx_unitary n (M : 'M[C]_n) : (M ^T \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_trmx -trmx_mul.
by rewrite -trmx1 => /trmx_inj /mulmx1C->; rewrite trmx1.
by move=> /mulmx1C->; rewrite trmx1.
Qed.
Lemma conjC_unitary m n (M : 'M[C]_(m, n)) :
(M ^ conjC \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_mxM ?map_trmx; last first.
by move=> ->; rewrite map_mx1.
by rewrite -[1%:M](map_mx1 conjC) => /map_mx_inj ->; rewrite map_mx1.
Qed.
Lemma trmxC_unitary n (M : 'M[C]_n) : (M ^t* \is unitarymx) = (M \is unitarymx).
Proof. by rewrite conjC_unitary trmx_unitary. Qed.
End unitarymx.
Section normalmx.
Context {C : numClosedFieldType} {n : nat}.
Definition normalmx := [qualify M : 'M[C]_n | M *m M ^t* == M ^t* *m M].
Fact normalmx_key : pred_key normalmx. Proof. by []. Qed.
Canonical normalmx_keyed := KeyedQualifier normalmx_key.
Lemma normalmxP {M : 'M[C]_n} :
reflect (M *m M ^t* = M ^t* *m M) (M \is normalmx).
Proof. exact: eqP. Qed.
Lemma hermitian_normalmx (A : 'M[C]_n) : A \is hermsymmx -> A \is normalmx.
Proof.
move=> Ahermi; apply/normalmxP.
by rewrite (trmx_hermitian (HermitianMx Ahermi)) scale1r map_mxCK.
Qed.
Lemma symmetric_normalmx (A : 'M[C]_n) : A \is symmetricmx ->
A \is a realmx -> A \is normalmx.
Proof. by move=> Asym Areal; rewrite hermitian_normalmx// realsym_hermsym. Qed.
End normalmx.
Section Spectral.
Variable (C : numClosedFieldType).
Set Default Proof Using "C".
Local Notation dotmx_def := (form_of_matrix (@conjC _) 1%:M).
Definition dotmx n (u v : 'rV[C]_n) := dotmx_def u%R v%R.
(*
TODO: bug report
we were expecting
HB.instance Definition _ n := Bilinear.on (@dotmx n).
to be sufficient to equip dotmx with the bilinear structure
but needed to use .copy in the end as in:
*)
HB.instance Definition _ n := Bilinear.copy (@dotmx n) dotmx_def.
Local Notation "''[' u , v ]" := (dotmx u v) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
HB.instance Definition _ n := Hermitian.copy (@dotmx n) dotmx_def.
Lemma dotmxE n (u v : 'rV[C]_n) : '[u, v] = ( u *m v ^t* ) 0 0.
Proof. by rewrite /dotmx /form_of_matrix mulmx1 /= trace_mx11. Qed.
Lemma row_unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (forall i j, '[row i M, row j M] = (i == j)%:R) (M \is unitarymx).
Proof.
apply: (iffP eqP) => [Mo i j|Mo].
have /matrixP/(_ i j) := Mo; rewrite !mxE => <-.
by rewrite dotmxE !mxE; apply: eq_bigr => /= k _; rewrite !mxE.
apply/matrixP=> i j; rewrite !mxE; have := Mo i j; rewrite dotmxE !mxE => <-.
by apply: eq_bigr => /= k _; rewrite !mxE.
Qed.
Fact dotmx_is_dotmx n (u : 'rV[C]_n) : u != 0 -> 0 < '[u].
Proof.
move=> u_neq0; rewrite dotmxE mxE.
suff /existsP[i ui_neq0] : [exists i, u 0 i != 0].
rewrite (bigD1 i) //= ltr_wpDr// ?sumr_ge0// ?mxE ?mul_conjC_gt0//.
by move=> j _; rewrite !mxE mul_conjC_ge0.
apply: contraNT u_neq0; rewrite negb_exists => /forallP uNN0.
by apply/eqP/rowP=> j; rewrite mxE; apply/eqP; rewrite -[_ == _]negbK uNN0.
Qed.
HB.instance Definition _ n := isDotProduct.Build _ _ (@dotmx n)
(@dotmx_is_dotmx n).
Local Notation "B ^!" :=
(orthomx (@conjC C) (mx_of_hermitian (hermitian1mx _)) B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B^!)%MS : bool_scope.
Lemma orthomx1E m n p (A : 'M[C]_(m, n)) (B : 'M_(p, n)) :
(A '_|_ B)%MS = (A *m B^t* == 0).
Proof. by apply/sub_kermxP/eqP; rewrite !mul1mx. Qed.
Lemma orthomx1P m n p {A : 'M[C]_(m, n)} {B : 'M_(p, n)} :
reflect (A *m B^t* = 0) (A '_|_ B).
Proof. by rewrite orthomx1E; exact/eqP. Qed.
Lemma orthomx_disj n p q (A : 'M[C]_(p, n)) (B :'M_(q, n)) :
A '_|_ B -> (A :&: B = 0)%MS.
Proof.
move=> nAB; apply/eqP/rowV0Pn => [[v]]; rewrite sub_capmx => /andP [vA vB].
apply/negP; rewrite negbK.
by rewrite -(dnorm_eq0 (@dotmx n)) -orthomxE (orthomxP _ _ _ nAB).
Qed.
Lemma orthomx_ortho_disj n p (A : 'M[C]_(p, n)) : (A :&: A^! = 0)%MS.
Proof. exact/orthomx_disj/ortho_mx_ortho. Qed.
Lemma rank_ortho p n (A : 'M[C]_(p, n)) : \rank A^! = (n - \rank A)%N.
Proof. by rewrite mxrank_ker mul1mx mxrank_map mxrank_tr. Qed.
Lemma add_rank_ortho p n (A : 'M[C]_(p, n)) : (\rank A + \rank A^!)%N = n.
Proof. by rewrite rank_ortho subnKC ?rank_leq_col. Qed.
Lemma addsmx_ortho p n (A : 'M[C]_(p, n)) : (A + A^! :=: 1%:M)%MS.
Proof.
apply/eqmxP/andP; rewrite submx1; split=> //.
rewrite -mxrank_leqif_sup ?submx1 ?mxrank1 ?(mxdirectP _) /= ?add_rank_ortho //.
by rewrite mxdirect_addsE /= ?mxdirectE ?orthomx_ortho_disj !eqxx.
Qed.
Lemma ortho_id p n (A : 'M[C]_(p, n)) : (A^!^! :=: A)%MS.
Proof.
apply/eqmx_sym/eqmxP.
by rewrite -mxrank_leqif_eq 1?orthomx_sym // !rank_ortho subKn // ?rank_leq_col.
Qed.
Lemma submx_ortho p m n (U : 'M[C]_(p, n)) (V : 'M_(m, n)) :
(U^! <= V^!)%MS = (V <= U)%MS.
Proof. by rewrite orthomx_sym ortho_id. Qed.
Definition proj_ortho p n (U : 'M[C]_(p, n)) := proj_mx <<U>>%MS U^!%MS.
Lemma sub_adds_genmx_ortho (p m n : nat) (U : 'M[C]_(p, n)) (W : 'M_(m, n)) :
(W <= <<U>> + U^!)%MS.
Proof.
by rewrite !(adds_eqmx (genmxE _) (eqmx_refl _)) addsmx_ortho submx1.
Qed.
Local Hint Resolve sub_adds_genmx_ortho : core.
Lemma cap_genmx_ortho p n (U : 'M[C]_(p, n)) : (<<U>> :&: U^!)%MS = 0.
Proof.
apply/eqmx0P; rewrite !(cap_eqmx (genmxE _) (eqmx_refl _)).
by rewrite orthomx_ortho_disj; exact/eqmx0P.
Qed.
Local Hint Resolve cap_genmx_ortho : core.
Lemma proj_ortho_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W *m proj_ortho U <= U)%MS.
Proof. by rewrite (submx_trans (proj_mx_sub _ _ _)) // genmxE. Qed.
Lemma proj_ortho_compl_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W - W *m proj_ortho U <= U^!)%MS.
Proof. by rewrite proj_mx_compl_sub // addsmx_ortho submx1. Qed.
Lemma proj_ortho_id p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U)%MS -> W *m proj_ortho U = W.
Proof. by move=> WU; rewrite proj_mx_id ?genmxE. Qed.
Lemma proj_ortho_0 p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U^!)%MS -> W *m proj_ortho U = 0.
Proof. by move=> WUo; rewrite proj_mx_0. Qed.
Lemma add_proj_ortho p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
W *m proj_ortho U + W *m proj_ortho U^!%MS = W.
Proof.
rewrite -[W in LHS](@add_proj_mx _ _ _ <<U>>%MS U^!%MS W)//.
rewrite !mulmxDl proj_ortho_id ?proj_ortho_sub //.
rewrite proj_ortho_0 ?proj_mx_sub // addr0.
rewrite proj_ortho_0 ?ortho_id ?proj_ortho_sub // add0r.
by rewrite proj_ortho_id ?proj_mx_sub// add_proj_mx.
Qed.
Lemma proj_ortho_proj m n (U : 'M_(m, n)) : let P := proj_ortho U in P *m P = P.
Proof. by rewrite /= proj_mx_proj. Qed.
Lemma proj_orthoE p n (U : 'M_(p, n)) : (proj_ortho U :=: U)%MS.
Proof.
apply/eqmxP/andP; split; first by rewrite -proj_ortho_proj proj_ortho_sub.
by rewrite -[X in (X <= _)%MS](proj_ortho_id (submx_refl U)) mulmx_sub.
Qed.
Lemma orthomx_proj_mx_ortho p p' m m' n
(A : 'M_(p, n)) (A' : 'M_(p', n))
(W : 'M_(m, n)) (W' : 'M_(m', n)) :
A '_|_ A' -> W *m proj_ortho A '_|_ W' *m proj_ortho A'.
Proof.
rewrite orthomx_sym => An.
rewrite mulmx_sub // orthomx_sym (eqmx_ortho _ (proj_orthoE _)).
by rewrite (submx_trans _ An) // proj_ortho_sub.
Qed.
Lemma schmidt_subproof m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
exists2 B : 'M_(m, n), B \is unitarymx & [forall i : 'I_m,
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k B>>))%MS
&& ('[row i A, row i B] >= 0) ].
Proof.
elim: m A => [|m IHm].
exists (pid_mx n); first by rewrite qualifE !thinmx0.
by apply/forallP=> -[].
rewrite -addn1 => A leq_Sm_n.
have lemSm : (m <= m + 1)%N by rewrite addn1.
have ltmSm : (m < m + 1)%N by rewrite addn1.
have lemn : (m <= n)%N by rewrite ltnW // -addn1.
have [B Bortho] := IHm (usubmx A) lemn.
move=> /forallP /= subAB.
have [v /and4P [vBn v_neq0 dAv_ge0 dAsub]] :
exists v, [&& B '_|_ v, v != 0, '[dsubmx A, v] >= 0 & (dsubmx A <= B + v)%MS].
have := add_proj_ortho B (dsubmx A).
set BoSn := (_ *m proj_ortho _^!%MS) => pBE.
have [BoSn_eq0|BoSn_neq0] := eqVneq BoSn 0.
rewrite BoSn_eq0 addr0 in pBE.
have /rowV0Pn [v vBn v_neq0] : B^!%MS != 0.
rewrite -mxrank_eq0 rank_ortho -lt0n subn_gt0.
by rewrite mxrank_unitary // -addn1.
rewrite orthomx_sym in vBn.
exists v; rewrite vBn v_neq0 -pBE.
rewrite ['[_, _]](hermmx_eq0P _ _) ?lexx //=.
rewrite (submx_trans (proj_ortho_sub _ _)) //.
by rewrite -{1}[B]addr0 addmx_sub_adds ?sub0mx.
by rewrite (submx_trans _ vBn) // proj_ortho_sub.
pose c := (sqrtC '[BoSn])^-1; have c_gt0 : c > 0.
by rewrite invr_gt0 sqrtC_gt0 lt_def ?dnorm_eq0 ?dnorm_ge0 BoSn_neq0.
exists BoSn; apply/and4P; split => //.
- by rewrite orthomx_sym ?proj_ortho_sub // /gtr_eqF.
- rewrite -pBE linearDl //.
rewrite [X in X + '[_]](hermmx_eq0P _ _) ?add0r ?dnorm_ge0 //.
by rewrite orthomx_proj_mx_ortho // orthomx_sym.
- by rewrite -pBE addmx_sub_adds // proj_ortho_sub.
wlog nv_eq1 : v vBn v_neq0 dAv_ge0 dAsub / '[v] = 1.
pose c := (sqrtC '[v])^-1.
have c_gt0 : c > 0 by rewrite invr_gt0 sqrtC_gt0 ?dnorm_gt0.
have [c_ge0 c_eq0F] := (ltW c_gt0, gt_eqF c_gt0).
move=> /(_ (c *: v)); apply.
- by rewrite orthomxZ ?c_eq0F.
- by rewrite scaler_eq0 c_eq0F.
- by rewrite linearZr mulr_ge0 // conjC_ge0.
- by rewrite (submx_trans dAsub) // addsmxS // eqmx_scale // c_eq0F.
- rewrite dnormZ normfV ger0_norm ?sqrtC_ge0 ?dnorm_ge0 //.
by rewrite exprVn rootCK ?mulVf // dnorm_eq0.
exists (col_mx B v).
apply/row_unitarymxP => i j.
case: (split_ordP i) (split_ordP j) => [] i' -> [] j' ->;
rewrite eq_shift ?(rowKu, rowKd, row_id, ord1) -?val_eqE /=
?(row_unitarymxP _) //= ?addn0.
by rewrite ['[_, _]](hermmx_eq0P _ _)//= (submx_trans _ vBn)// row_sub.
rewrite ['[_, _]](hermmx_eq0P _ _)//= orthomx_sym (submx_trans _ vBn) //.
exact: row_sub.
apply/forallP => i; case: (split_ordP i) => j -> /=.
have /andP [sABj dot_gt0] := subAB j.
rewrite rowKu -row_usubmx (submx_trans sABj) //=.
rewrite (eq_rect _ (submx _) (submx_refl _)) //.
rewrite [in RHS](reindex (lshift 1)) /=.
by apply: eq_bigr=> k k_le; rewrite rowKu.
exists (fun k => insubd j k) => k; rewrite inE /= => le_kj;
by apply/val_inj; rewrite /= insubdK // -topredE /= (leq_ltn_trans le_kj).
rewrite rowKd -row_dsubmx !row_id ord1 ?dAv_ge0 ?andbT {j} addn0.
rewrite (bigD1 (rshift _ ord0)) /= ?addn0 ?rowKd ?row_id // addsmxC.
rewrite (submx_trans dAsub) // addsmxS ?genmxE //.
apply/row_subP => j; apply/(sumsmx_sup (lshift _ j)) => //=.
by rewrite ltnW ?ltn_ord //= -val_eqE /= addn0 ltn_eqF.
by rewrite rowKu genmxE.
Qed.
Definition schmidt m n (A : 'M[C]_(m, n)) :=
if (m <= n)%N =P true is ReflectT le_mn
then projT1 (sig2_eqW (schmidt_subproof A le_mn))
else A.
Lemma schmidt_unitarymx m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
schmidt A \is unitarymx.
Proof. by rewrite /schmidt; case: eqP => // ?; case: sig2_eqW. Qed.
Hint Resolve schmidt_unitarymx : core.
Lemma row_schmidt_sub m n (A : 'M[C]_(m, n)) i :
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k (schmidt A)>>))%MS.
Proof.
rewrite /schmidt; case: eqP => // ?.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
by apply/(sumsmx_sup i) => //; rewrite genmxE.
Qed.
Lemma form1_row_schmidt m n (A : 'M[C]_(m, n)) i :
'[row i A, row i (schmidt A)] >= 0.
Proof.
rewrite /schmidt; case: eqP => // ?; rewrite ?dnorm_ge0 //.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
Qed.
Lemma schmidt_sub m n (A : 'M[C]_(m, n)) : (A <= schmidt A)%MS.
Proof.
apply/row_subP => i; rewrite (submx_trans (row_schmidt_sub _ _)) //.
by apply/sumsmx_subP => /= j le_ji; rewrite genmxE row_sub.
Qed.
Hint Resolve schmidt_sub : core.
Lemma eqmx_schmidt_full m n (A : 'M[C]_(m, n)) :
row_full A -> (schmidt A :=: A)%MS.
Proof.
move=> Afull; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans n) ?rank_leq_col ?col_leq_rank.
Qed.
Lemma eqmx_schmidt_free m n (A : 'M[C]_(m, n)) :
row_free A -> (schmidt A :=: A)%MS.
Proof.
move=> Afree; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans m) ?rank_leq_row // ?row_leq_rank.
Qed.
Definition schmidt_complete m n (V : 'M[C]_(m, n)) :=
col_mx (schmidt (row_base V)) (schmidt (row_base V^!%MS)).
Lemma schmidt_complete_unitarymx m n (V : 'M[C]_(m, n)) :
schmidt_complete V \is unitarymx.
Proof.
apply/unitarymxP; rewrite tr_col_mx map_row_mx mul_col_row.
rewrite !(unitarymxP _) ?schmidt_unitarymx ?rank_leq_col //.
move=> [:nsV]; rewrite !(orthomx1P _) -?scalar_mx_block //;
[abstract: nsV|]; last by rewrite orthomx_sym.
by do 2!rewrite eqmx_schmidt_free ?eq_row_base ?row_base_free // orthomx_sym.
Qed.
Lemma cotrigonalization n (As : seq 'M[C]_n) :
{in As &, forall A B, comm_mx A B} ->
cotrigonalizable_in (@unitarymx C n n) As.
Proof.
elim: n {-2}n (leqnn n) As => [|N IHN] n.
rewrite leqn0 => /eqP n_eq0.
exists 1%:M; first by rewrite qualifE mul1mx trmx1 map_mx1.
apply/allP => ? ?; apply/is_trig_mxP => i j.
by suff: False by []; move: i; rewrite n_eq0 => -[].
rewrite leq_eqVlt => /predU1P [n_eqSN|/IHN//].
have /andP [n_gt0 n_small] : (n > 0)%N && (n - 1 <= N)%N.
by rewrite n_eqSN /= subn1.
move=> As As_comm;
have [v vN0 /allP /= vP] := common_eigenvector n_gt0 As_comm.
suff: exists2 P : 'M[C]_(\rank v + \rank v^!, n), P \is unitarymx &
all (fun A => is_trig_mx (P *m A *m ( P^t* ))) As.
rewrite add_rank_ortho // => -[P P_unitary] /=; rewrite -invmx_unitary//.
by under eq_all do rewrite -conjumx ?unitarymx_unit//; exists P.
pose S := schmidt_complete v.
pose r A := S *m A *m S^t*.
have vSvo X : stablemx v X ->
schmidt (row_base v) *m X *m schmidt (row_base v^!%MS) ^t* = 0.
move=> /eigenvectorP [a v_in].
rewrite (eigenspaceP (_ : (_ <= _ a))%MS); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
rewrite -scalemxAl (orthomx1P _) ?scaler0 //.
by do 2!rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base // orthomx_sym.
have drrE X : drsubmx (r X) =
schmidt (row_base v^!%MS) *m X *m schmidt (row_base v^!%MS) ^t*.
by rewrite /r mul_col_mx tr_col_mx map_row_mx mul_col_row block_mxKdr.
have vSv X a : (v <= eigenspace X a)%MS ->
schmidt (row_base v) *m X *m schmidt (row_base v) ^t* = a%:M.
move=> vXa; rewrite (eigenspaceP (_ : (_ <= _ a)%MS)); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
by rewrite -scalemxAl (unitarymxP _) ?scalemx1 ?schmidt_unitarymx ?rank_leq_col.
have [] := IHN _ _ [seq drsubmx (r A) | A <- As].
- by rewrite rank_ortho rank_rV vN0.
- move=> _ _ /mapP[/= A A_in ->] /mapP[/= B B_in ->].
have : (r A) *m (r B) = (r B) *m (r A).
rewrite /r !mulmxA !mulmxKtV // ?schmidt_complete_unitarymx //;
by rewrite ?add_rank_ortho // -![S *m _ *m _]mulmxA As_comm.
rewrite -[r A in X in X -> _]submxK -[r B in X in X -> _]submxK.
rewrite 2!mulmx_block => /eq_block_mx [_ _ _].
suff urr_eq0 X : X \in As -> ursubmx (r X) = 0.
by rewrite !urr_eq0 ?mulmx0 ?add0r.
rewrite /r /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !block_mxKur.
by move=> X_in; rewrite vSvo // vP.
move=> P' P'_unitary /allP /= P'P.
exists ((block_mx 1%:M 0 0 P') *m S).
rewrite mul_unitarymx ?schmidt_complete_unitarymx //.
apply/unitarymxP; rewrite tr_block_mx map_block_mx mulmx_block.
rewrite !trmx0 !(@map_mx0 _ _ conjC) !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
by rewrite (unitarymxP _) -?scalar_mx_block //.
apply/allP => /= A A_in.
rewrite trmx_mul map_mxM tr_block_mx map_block_mx.
rewrite !trmx0 !map_mx0 !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite mulmxA -[_ *m S *m _]mulmxA -[_ *m _ *m S^t*]mulmxA.
rewrite /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !mulmx_block.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
apply/is_trig_mxP => /= i j lt_ij; rewrite mxE.
case: splitP => //= i' i_eq; rewrite !mxE;
case: splitP => //= j' j_eq.
- have /vP /eigenvectorP [a v_in] := A_in.
by rewrite (vSv _ _ v_in) mxE -val_eqE ltn_eqF //= -i_eq -j_eq.
- by rewrite vSvo ?mul0mx ?mxE // vP //.
- move: lt_ij; rewrite i_eq j_eq ltnNge -ltnS (leq_trans (ltn_ord j'))//.
by rewrite -addnS leq_addr.
- set A' := _ *m A *m _; rewrite -invmx_unitary // -conjumx ?unitarymx_unit//.
have /(_ _) /is_trig_mxP -> // := P'P A'; last first.
by move: lt_ij; rewrite i_eq j_eq ltn_add2l.
by apply/mapP; exists A; rewrite //= drrE.
Qed.
Theorem Schur n (A : 'M[C]_n) : (n > 0)%N ->
trigonalizable_in (@unitarymx C n n) A.
Proof.
case: n => [//|n] in A * => _; have [] := @cotrigonalization _ [:: A].
by move=> ? ? /=; rewrite !in_cons !orbF => /eqP-> /eqP->.
by move=> P P_unitary /=; rewrite andbT=> A_trigo; exists P.
Qed.
Lemma cotrigonalization2 n (A B : 'M[C]_n) : A *m B = B *m A ->
exists2 P : 'M[C]_n, P \is unitarymx &
similar_trig P A && similar_trig P B.
Proof.
move=> AB_comm; have [] := @cotrigonalization _ [:: A; B].
by move=> ??; rewrite !inE => /orP[]/eqP->/orP[]/eqP->.
move=> P Punitary /allP /= PP; exists P => //.
by rewrite !PP ?(mem_head, in_cons, orbT).
Qed.
Theorem orthomx_spectral_subproof n {A : 'M[C]_n} : reflect
(exists2 sp : 'M_n * 'rV_n,
sp.1 \is unitarymx &
A = invmx sp.1 *m diag_mx sp.2 *m sp.1)
(A \is normalmx).
Proof.
apply: (iffP normalmxP); last first.
move=> [[/= P D] P_unitary ->].
rewrite !trmx_mul !map_mxM !mulmxA invmx_unitary //.
rewrite !trmxCK ![_ *m P *m _]mulmxtVK //.
by rewrite -[X in X *m P]mulmxA tr_diag_mx map_diag_mx diag_mxC mulmxA.
move=> /cotrigonalization2 [P Punitary /andP[]] PA PATC.
have Punit := unitarymx_unit Punitary.
suff: similar_diag P A.
move=> /similar_diagPex[D] PAD; exists (P, D) => //=.
by rewrite -conjVmx//; exact/similarLR.
apply/similar_diagPp => // i j; case: ltngtP => // [lt_ij|lt_ji] _.
by have /is_trig_mxP-> := PA.
have /is_trig_mxP -/(_ j i lt_ji)/eqP := PATC.
rewrite !conjumx// invmx_unitary// -[P as X in X *m _]trmxCK.
by rewrite -!map_mxM -!trmx_mul mulmxA 2!mxE conjC_eq0 => /eqP.
Qed.
Definition spectralmx n (A : 'M[C]_n) : 'M[C]_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).1 else 1%:M.
Definition spectral_diag n (A : 'M[C]_n) : 'rV_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).2 else 0.
Lemma spectral_unitarymx n (A : 'M[C]_n) : spectralmx A \is unitarymx.
Proof.
rewrite /spectralmx; case: orthomx_spectral_subproof; last first.
by move=> _; apply/unitarymxP; rewrite trmx1 map_mx1 mulmx1.
by move=> ?; case: sig2_eqW.
Qed.
Lemma spectral_unit n (A : 'M[C]_n) : spectralmx A \in unitmx.
Proof. exact/unitarymx_unit/spectral_unitarymx. Qed.
Theorem orthomx_spectralP {n} {A : 'M[C]_n}
(P := spectralmx A) (sp := spectral_diag A) :
reflect (A = invmx P *m diag_mx sp *m P) (A \is normalmx).
Proof.
rewrite /P /sp /spectralmx /spectral_diag.
case: orthomx_spectral_subproof.
by move=> Psp; case: sig2_eqW => //=; constructor.
move=> /orthomx_spectral_subproof Ann; constructor; apply/eqP.
apply: contra Ann; rewrite invmx1 mul1mx mulmx1 => /eqP->.
suff -> : diag_mx 0 = 0 by rewrite qualifE trmx0 (map_mx0 conjC).
by move=> ? ?; apply/matrixP=> i j; rewrite !mxE mul0rn.
Qed.
Lemma hermitian_spectral_diag_real n (A : 'M[C]_n) : A \is hermsymmx ->
spectral_diag A \is a realmx.
Proof.
move=> Ahermi; have /hermitian_normalmx /orthomx_spectralP A_eq := Ahermi.
have /(congr1 ( fun X => X^t* )) := A_eq.
rewrite invmx_unitary ?spectral_unitarymx //.
rewrite !trmx_mul !map_mxM map_trmx trmxK -map_mx_comp.
rewrite tr_diag_mx map_diag_mx (map_mx_id (@conjCK _)).
rewrite -[in RHS]invmx_unitary ?spectral_unitarymx //.
have := is_hermitianmxP _ _ _ Ahermi; rewrite expr0 scale1r => <-.
rewrite {1}A_eq mulmxA => /(congr1 (mulmx^~ (invmx (spectralmx A)))).
rewrite !mulmxK ?spectral_unit//.
move=> /(congr1 (mulmx (spectralmx A))); rewrite !mulKVmx ?spectral_unit//.
move=> eq_A_conjA; apply/mxOverP => i j; rewrite ord1 {i}.
have /matrixP /(_ j j) := eq_A_conjA; rewrite !mxE eqxx !mulr1n.
by move=> /esym/CrealP.
Qed.
End Spectral.
|
Defs.lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Filippo A. E. Nuccio, Andrew Yang
-/
import Mathlib.RingTheory.Ideal.Prime
/-!
# Prime spectrum of a commutative (semi)ring as a type
The prime spectrum of a commutative (semi)ring is the type of all prime ideals.
For the Zariski topology, see `Mathlib/RingTheory/Spectrum/Prime/Topology.lean`.
(It is also naturally endowed with a sheaf of rings,
which is constructed in `AlgebraicGeometry.StructureSheaf`.)
## Main definitions
* `PrimeSpectrum R`: The prime spectrum of a commutative (semi)ring `R`,
i.e., the set of all prime ideals of `R`.
-/
/-- The prime spectrum of a commutative (semi)ring `R` is the type of all prime ideals of `R`.
It is naturally endowed with a topology (the Zariski topology),
and a sheaf of commutative rings (see `Mathlib/AlgebraicGeometry/StructureSheaf.lean`).
It is a fundamental building block in algebraic geometry. -/
@[ext]
structure PrimeSpectrum (R : Type*) [CommSemiring R] where
asIdeal : Ideal R
isPrime : asIdeal.IsPrime
attribute [instance] PrimeSpectrum.isPrime
namespace PrimeSpectrum
/-!
## The specialization order
We endow `PrimeSpectrum R` with a partial order induced from the ideal lattice.
This is exactly the specialization order.
See the corresponding section at `Mathlib/RingTheory/Spectrum/Prime/Topology.lean`.
-/
variable {R : Type*} [CommSemiring R]
instance : PartialOrder (PrimeSpectrum R) :=
PartialOrder.lift asIdeal (@PrimeSpectrum.ext _ _)
@[simp]
theorem asIdeal_le_asIdeal (x y : PrimeSpectrum R) : x.asIdeal ≤ y.asIdeal ↔ x ≤ y :=
Iff.rfl
@[simp]
theorem asIdeal_lt_asIdeal (x y : PrimeSpectrum R) : x.asIdeal < y.asIdeal ↔ x < y :=
Iff.rfl
variable (R) in
/-- The prime spectrum is in bijection with the set of prime ideals. -/
@[simps]
def equivSubtype : PrimeSpectrum R ≃o {I : Ideal R // I.IsPrime} where
toFun I := ⟨I.asIdeal, I.2⟩
invFun I := ⟨I, I.2⟩
map_rel_iff' := .rfl
end PrimeSpectrum
|
Topology.lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl
-/
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.Topology.Separation.Hausdorff
/-!
# Topological properties of fixed points
Currently this file contains two lemmas:
- `isFixedPt_of_tendsto_iterate`: if `f^n(x) → y` and `f` is continuous at `y`, then `f y = y`;
- `isClosed_fixedPoints`: the set of fixed points of a continuous map is a closed set.
## TODO
fixed points, iterates
-/
variable {α : Type*} [TopologicalSpace α] [T2Space α] {f : α → α}
open Function Filter
open Topology
/-- If the iterates `f^[n] x` converge to `y` and `f` is continuous at `y`,
then `y` is a fixed point for `f`. -/
theorem isFixedPt_of_tendsto_iterate {x y : α} (hy : Tendsto (fun n => f^[n] x) atTop (𝓝 y))
(hf : ContinuousAt f y) : IsFixedPt f y := by
refine tendsto_nhds_unique ((tendsto_add_atTop_iff_nat 1).1 ?_) hy
simp only [iterate_succ' f]
exact hf.tendsto.comp hy
/-- The set of fixed points of a continuous map is a closed set. -/
theorem isClosed_fixedPoints (hf : Continuous f) : IsClosed (fixedPoints f) :=
isClosed_eq hf continuous_id
|
Perm.lean
|
import Mathlib.GroupTheory.Perm.Cycle.Concrete
import Mathlib.Tactic.DeriveFintype
open Equiv
#guard with_decl_name% ex₁ unsafe (reprStr (1 : Perm (Fin 4))) == "1"
#guard with_decl_name% ex₂ unsafe (reprStr (c[0, 1] : Perm (Fin 4))) == "c[0, 1]"
#guard with_decl_name% ex₃
unsafe (reprStr (c[0, 1] * c[2, 3] : Perm (Fin 4))) == "c[0, 1] * c[2, 3]"
#guard with_decl_name% ex₄
unsafe (reprPrec (c[0, 1] * c[2, 3] : Perm (Fin 4)) 70).pretty == "(c[0, 1] * c[2, 3])"
#guard with_decl_name% ex₅
unsafe (reprPrec (c[0, 1] * c[1, 2] : Perm (Fin 4)) 70).pretty == "c[0, 1, 2]"
example : (c[0, 1] * c[1, 2] : Perm (Fin 4)).cycleType = {3} := by decide
|
UnitPartition.lean
|
/-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Algebra.Module.ZLattice.Basic
import Mathlib.Analysis.BoxIntegral.Integrability
import Mathlib.Analysis.BoxIntegral.Partition.Measure
import Mathlib.Analysis.BoxIntegral.Partition.Tagged
/-!
# Unit Partition
Fix `n` a positive integer. `BoxIntegral.unitPartition.box` are boxes in `ι → ℝ` obtained by
dividing the unit box uniformly into boxes of side length `1 / n` and translating the boxes by
vectors `ν : ι → ℤ`.
Let `B` be a `BoxIntegral`. A `unitPartition.box` is admissible for `B` (more precisely its index is
admissible) if it is contained in `B`. There are finitely many admissible `unitPartition.box` for
`B` and thus we can form the corresponding tagged prepartition, see
`BoxIntegral.unitPartition.prepartition` (note that each `unitPartition.box` comes with its
tag situated at its "upper most" vertex). If `B` satisfies `hasIntegralVertices`, that
is its vertices are in `ι → ℤ`, then the corresponding prepartition is actually a partition.
## Main definitions and results
* `BoxIntegral.hasIntegralVertices`: a `Prop` that states that the vertices of the box have
coordinates in `ℤ`
* `BoxIntegral.unitPartition.box`: a `BoxIntegral`, indexed by `ν : ι → ℤ`, with vertices
`ν i / n` and of side length `1 / n`.
* `BoxIntegral.unitPartition.admissibleIndex`: For `B : BoxIntegral.Box`, the set of indices of
`unitPartition.box` that are subsets of `B`. This is a finite set.
* `BoxIntegral.unitPartition.prepartition_isPartition`: For `B : BoxIntegral.Box`, if `B`
has integral vertices, then the prepartition of `unitPartition.box` admissible for `B` is a
partition of `B`.
* `tendsto_tsum_div_pow_atTop_integral`: let `s` be a bounded, measurable set of `ι → ℝ`
whose frontier has zero volume and let `F` be a continuous function. Then the limit as `n → ∞`
of `∑ F x / n ^ card ι`, where the sum is over the points in `s ∩ n⁻¹ • (ι → ℤ)`, tends to the
integral of `F` over `s`.
* `tendsto_card_div_pow_atTop_volume`: let `s` be a bounded, measurable set of `ι → ℝ` whose
frontier has zero volume. Then the limit as `n → ∞` of `card (s ∩ n⁻¹ • (ι → ℤ)) / n ^ card ι`
tends to the volume of `s`.
* `tendsto_card_div_pow_atTop_volume'`: a version of `tendsto_card_div_pow_atTop_volume` where we
assume in addition that `x • s ⊆ y • s` whenever `0 < x ≤ y`. Then we get the same limit
`card (s ∩ x⁻¹ • (ι → ℤ)) / x ^ card ι → volume s` but the limit is over a real variable `x`.
-/
noncomputable section
variable {ι : Type*}
open scoped Topology
section hasIntegralVertices
open Bornology
/-- A `BoxIntegral.Box` has integral vertices if its vertices have coordinates in `ℤ`. -/
def BoxIntegral.hasIntegralVertices (B : Box ι) : Prop :=
∃ l u : ι → ℤ, (∀ i, B.lower i = l i) ∧ (∀ i, B.upper i = u i)
/-- Any bounded set is contained in a `BoxIntegral.Box` with integral vertices. -/
theorem BoxIntegral.le_hasIntegralVertices_of_isBounded [Finite ι] {s : Set (ι → ℝ)}
(h : IsBounded s) :
∃ B : BoxIntegral.Box ι, hasIntegralVertices B ∧ s ≤ B := by
have := Fintype.ofFinite ι
obtain ⟨R, hR₁, hR₂⟩ := IsBounded.subset_ball_lt h 0 0
let C : ℕ := ⌈R⌉₊
have hC := Nat.ceil_pos.mpr hR₁
let I : Box ι := Box.mk (fun _ ↦ - C) (fun _ ↦ C )
(fun _ ↦ by simp [C, neg_lt_self_iff, Nat.cast_pos, hC])
refine ⟨I, ⟨fun _ ↦ - C, fun _ ↦ C, fun i ↦ (Int.cast_neg_natCast C).symm, fun _ ↦ rfl⟩,
le_trans hR₂ ?_⟩
suffices Metric.ball (0 : ι → ℝ) C ≤ I from
le_trans (Metric.ball_subset_ball (Nat.le_ceil R)) this
intro x hx
simp_rw [C, mem_ball_zero_iff, pi_norm_lt_iff (Nat.cast_pos.mpr hC),
Real.norm_eq_abs, abs_lt] at hx
exact fun i ↦ ⟨(hx i).1, le_of_lt (hx i).2⟩
end hasIntegralVertices
namespace BoxIntegral.unitPartition
open Bornology MeasureTheory Fintype BoxIntegral
variable (n : ℕ)
/-- A `BoxIntegral`, indexed by a positive integer `n` and `ν : ι → ℤ`, with corners `ν i / n`
and of side length `1 / n`. -/
def box [NeZero n] (ν : ι → ℤ) : Box ι where
lower := fun i ↦ ν i / n
upper := fun i ↦ (ν i + 1) / n
lower_lt_upper := fun _ ↦ by simp [add_div, n.pos_of_neZero]
@[simp]
theorem box_lower [NeZero n] (ν : ι → ℤ) :
(box n ν).lower = fun i ↦ (ν i / n : ℝ) := rfl
@[simp]
theorem box_upper [NeZero n] (ν : ι → ℤ) :
(box n ν).upper = fun i ↦ ((ν i + 1) / n : ℝ) := rfl
variable {n} in
@[simp]
theorem mem_box_iff [NeZero n] {ν : ι → ℤ} {x : ι → ℝ} :
x ∈ box n ν ↔ ∀ i, ν i / n < x i ∧ x i ≤ (ν i + 1) / n := by
simp_rw [Box.mem_def, box, Set.mem_Ioc]
variable {n} in
theorem mem_box_iff' [NeZero n] {ν : ι → ℤ} {x : ι → ℝ} :
x ∈ box n ν ↔ ∀ i, ν i < n * x i ∧ n * x i ≤ ν i + 1 := by
have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero
simp_rw [mem_box_iff, ← _root_.le_div_iff₀' h, ← div_lt_iff₀' h]
/-- The tag of (the index of) a `unitPartition.box`. -/
abbrev tag (ν : ι → ℤ) : ι → ℝ := fun i ↦ (ν i + 1) / n
@[simp]
theorem tag_apply (ν : ι → ℤ) (i : ι) : tag n ν i = (ν i + 1) / n := rfl
variable [NeZero n]
theorem tag_injective : Function.Injective (fun ν : ι → ℤ ↦ tag n ν) := by
refine fun _ _ h ↦ funext_iff.mpr fun i ↦ ?_
have := congr_arg (fun x ↦ x i) h
simp_rw [tag_apply, div_left_inj' (c := (n : ℝ)) (Nat.cast_ne_zero.mpr (NeZero.ne n)),
add_left_inj, Int.cast_inj] at this
exact this
theorem tag_mem (ν : ι → ℤ) :
tag n ν ∈ box n ν := by
refine mem_box_iff.mpr fun _ ↦ ?_
rw [tag, add_div]
have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero
exact ⟨lt_add_of_pos_right _ (by positivity), le_rfl⟩
/-- For `x : ι → ℝ`, its index is the index of the unique `unitPartition.box` to which
it belongs. -/
def index (x : ι → ℝ) (i : ι) : ℤ := ⌈n * x i⌉ - 1
@[simp]
theorem index_apply (m : ℕ) {x : ι → ℝ} (i : ι) :
index m x i = ⌈m * x i⌉ - 1 := rfl
variable {n} in
theorem mem_box_iff_index {x : ι → ℝ} {ν : ι → ℤ} :
x ∈ box n ν ↔ index n x = ν := by
simp_rw [mem_box_iff', funext_iff, index_apply, sub_eq_iff_eq_add, Int.ceil_eq_iff,
Int.cast_add, Int.cast_one, add_sub_cancel_right]
@[simp]
theorem index_tag (ν : ι → ℤ) :
index n (tag n ν) = ν := mem_box_iff_index.mp (tag_mem n ν)
variable {n} in
theorem disjoint {ν ν' : ι → ℤ} :
ν ≠ ν' ↔ Disjoint (box n ν).toSet (box n ν').toSet := by
rw [not_iff_comm, Set.not_disjoint_iff]
refine ⟨fun ⟨x, hx, hx'⟩ ↦ ?_, fun h ↦ ⟨tag n ν, tag_mem n ν, h ▸ tag_mem n ν⟩⟩
rw [← mem_box_iff_index.mp hx, ← mem_box_iff_index.mp hx']
theorem box_injective : Function.Injective (fun ν : ι → ℤ ↦ box n ν) := by
intro _ _ h
contrapose! h
exact Box.ne_of_disjoint_coe (disjoint.mp h)
lemma box.upper_sub_lower (ν : ι → ℤ) (i : ι) :
(box n ν ).upper i - (box n ν).lower i = 1 / n := by
simp_rw [box, add_div, add_sub_cancel_left]
variable [Fintype ι]
theorem diam_boxIcc (ν : ι → ℤ) :
Metric.diam (Box.Icc (box n ν)) ≤ 1 / n := by
rw [BoxIntegral.Box.Icc_eq_pi]
refine ENNReal.toReal_le_of_le_ofReal (by positivity) <| EMetric.diam_pi_le_of_le (fun i ↦ ?_)
simp_rw [Real.ediam_Icc, box.upper_sub_lower, le_rfl]
@[simp]
theorem volume_box (ν : ι → ℤ) :
volume (box n ν : Set (ι → ℝ)) = 1 / n ^ card ι := by
simp_rw [volume_pi, BoxIntegral.Box.coe_eq_pi, Measure.pi_pi, Real.volume_Ioc,
box.upper_sub_lower, Finset.prod_const, ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr
n.pos_of_neZero), ENNReal.ofReal_one, ENNReal.ofReal_natCast, one_div, ENNReal.inv_pow,
Finset.card_univ]
theorem setFinite_index {s : Set (ι → ℝ)} (hs₁ : NullMeasurableSet s) (hs₂ : volume s ≠ ⊤) :
Set.Finite {ν : ι → ℤ | ↑(box n ν) ⊆ s} := by
refine (Measure.finite_const_le_meas_of_disjoint_iUnion₀ volume (ε := 1 / n ^ card ι)
(by simp) (As := fun ν : ι → ℤ ↦ (box n ν) ∩ s) (fun ν ↦ ?_) (fun _ _ h ↦ ?_) ?_).subset
(fun _ hν ↦ ?_)
· refine NullMeasurableSet.inter ?_ hs₁
exact (box n ν).measurableSet_coe.nullMeasurableSet
· exact ((Disjoint.inter_right _ (disjoint.mp h)).inter_left _ ).aedisjoint
· exact lt_top_iff_ne_top.mp <| measure_lt_top_of_subset
(by simp only [Set.iUnion_subset_iff, Set.inter_subset_right, implies_true]) hs₂
· rw [Set.mem_setOf, Set.inter_eq_self_of_subset_left hν, volume_box]
/-- For `B : BoxIntegral.Box`, the set of indices of `unitPartition.box` that are subsets of `B`.
This is a finite set. These boxes cover `B` if it has integral vertices, see
`unitPartition.prepartition_isPartition`. -/
def admissibleIndex (B : Box ι) : Finset (ι → ℤ) := by
refine (setFinite_index n B.measurableSet_coe.nullMeasurableSet ?_).toFinset
exact lt_top_iff_ne_top.mp (IsBounded.measure_lt_top B.isBounded)
variable {n} in
theorem mem_admissibleIndex_iff {B : Box ι} {ν : ι → ℤ} :
ν ∈ admissibleIndex n B ↔ box n ν ≤ B := by
rw [admissibleIndex, Set.Finite.mem_toFinset, Set.mem_setOf_eq, Box.coe_subset_coe]
open Classical in
/-- For `B : BoxIntegral.Box`, the `TaggedPrepartition` formed by the set of all
`unitPartition.box` whose index is `B`-admissible. -/
def prepartition (B : Box ι) : TaggedPrepartition B where
boxes := Finset.image (fun ν ↦ box n ν) (admissibleIndex n B)
le_of_mem' _ hI := by
obtain ⟨_, hν, rfl⟩ := Finset.mem_image.mp hI
exact mem_admissibleIndex_iff.mp hν
pairwiseDisjoint _ hI₁ _ hI₂ h := by
obtain ⟨_, _, rfl⟩ := Finset.mem_image.mp hI₁
obtain ⟨_, _, rfl⟩ := Finset.mem_image.mp hI₂
exact disjoint.mp fun x ↦ h (congrArg (box n) x)
tag I :=
if hI : ∃ ν ∈ admissibleIndex n B, I = box n ν then tag n hI.choose else B.exists_mem.choose
tag_mem_Icc I := by
by_cases hI : ∃ ν ∈ admissibleIndex n B, I = box n ν
· simp_rw [dif_pos hI]
exact Box.coe_subset_Icc <| (mem_admissibleIndex_iff.mp hI.choose_spec.1) (tag_mem n _)
· simp_rw [dif_neg hI]
exact Box.coe_subset_Icc B.exists_mem.choose_spec
variable {n} in
@[simp]
theorem mem_prepartition_iff {B I : Box ι} :
I ∈ prepartition n B ↔ ∃ ν ∈ admissibleIndex n B, box n ν = I := by
classical
rw [prepartition, TaggedPrepartition.mem_mk, Prepartition.mem_mk, Finset.mem_image]
variable {n} in
theorem mem_prepartition_boxes_iff {B I : Box ι} :
I ∈ (prepartition n B).boxes ↔ ∃ ν ∈ admissibleIndex n B, box n ν = I :=
mem_prepartition_iff
theorem prepartition_tag {ν : ι → ℤ} {B : Box ι} (hν : ν ∈ admissibleIndex n B) :
(prepartition n B).tag (box n ν) = tag n ν := by
dsimp only [prepartition]
have h : ∃ ν' ∈ admissibleIndex n B, box n ν = box n ν' := ⟨ν, hν, rfl⟩
rw [dif_pos h, (tag_injective n).eq_iff, ← (box_injective n).eq_iff]
exact h.choose_spec.2.symm
theorem box_index_tag_eq_self {B I : Box ι} (hI : I ∈ (prepartition n B).boxes) :
box n (index n ((prepartition n B).tag I)) = I := by
obtain ⟨ν, hν, rfl⟩ := mem_prepartition_boxes_iff.mp hI
rw [prepartition_tag n hν, index_tag]
theorem prepartition_isHenstock (B : Box ι) :
(prepartition n B).IsHenstock := by
intro _ hI
obtain ⟨ν, hν, rfl⟩ := mem_prepartition_iff.mp hI
rw [prepartition_tag n hν]
exact Box.coe_subset_Icc (tag_mem _ _)
theorem prepartition_isSubordinate (B : Box ι) {r : ℝ} (hr : 0 < r) (hn : 1 / n ≤ r) :
(prepartition n B).IsSubordinate (fun _ ↦ ⟨r, hr⟩) := by
intro _ hI
obtain ⟨ν, hν, rfl⟩ := mem_prepartition_iff.mp hI
refine fun _ h ↦ le_trans (Metric.dist_le_diam_of_mem (Box.isBounded_Icc _) h ?_) ?_
· rw [prepartition_tag n hν]
exact Box.coe_subset_Icc (tag_mem _ _)
· exact le_trans (diam_boxIcc n ν) hn
private theorem mem_admissibleIndex_of_mem_box_aux₁ (x : ℝ) (a : ℤ) :
a < x ↔ a ≤ (⌈n * x⌉ - 1) / (n : ℝ) := by
have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero
rw [le_div_iff₀' h, le_sub_iff_add_le,
show (n : ℝ) * a + 1 = (n * a + 1 : ℤ) by norm_cast,
Int.cast_le, Int.add_one_le_ceil_iff, Int.cast_mul, Int.cast_natCast, mul_lt_mul_left h]
private theorem mem_admissibleIndex_of_mem_box_aux₂ (x : ℝ) (a : ℤ) :
x ≤ a ↔ (⌈n * x⌉ - 1 + 1) / (n : ℝ) ≤ a := by
have h : 0 < (n : ℝ) := Nat.cast_pos.mpr <| n.pos_of_neZero
rw [sub_add_cancel, div_le_iff₀' h,
show (n : ℝ) * a = (n * a : ℤ) by norm_cast,
Int.cast_le, Int.ceil_le, Int.cast_mul, Int.cast_natCast, mul_le_mul_left h]
/-- If `B : BoxIntegral.Box` has integral vertices and contains the point `x`, then the index of
`x` is admissible for `B`. -/
theorem mem_admissibleIndex_of_mem_box {B : Box ι} (hB : hasIntegralVertices B) {x : ι → ℝ}
(hx : x ∈ B) : index n x ∈ admissibleIndex n B := by
obtain ⟨l, u, hl, hu⟩ := hB
simp_rw [mem_admissibleIndex_iff, Box.le_iff_bounds, box_lower, box_upper, Pi.le_def,
index_apply, hl, hu, ← forall_and]
push_cast
refine fun i ↦ ⟨?_, ?_⟩
· exact (mem_admissibleIndex_of_mem_box_aux₁ n (x i) (l i)).mp ((hl i) ▸ (hx i).1)
· exact (mem_admissibleIndex_of_mem_box_aux₂ n (x i) (u i)).mp ((hu i) ▸ (hx i).2)
/-- If `B : BoxIntegral.Box` has integral vertices, then `prepartition n B` is a partition of
`B`. -/
theorem prepartition_isPartition {B : Box ι} (hB : hasIntegralVertices B) :
(prepartition n B).IsPartition := by
refine fun x hx ↦ ⟨box n (index n x), ?_, mem_box_iff_index.mpr rfl⟩
rw [TaggedPrepartition.mem_toPrepartition, mem_prepartition_iff]
exact ⟨index n x, mem_admissibleIndex_of_mem_box n hB hx, rfl⟩
open Submodule Pointwise BigOperators
open scoped Pointwise
variable (c : ℝ) (s : Set (ι → ℝ)) (F : (ι → ℝ) → ℝ)
-- The image of `ι → ℤ` inside `ι → ℝ`
local notation "L" => span ℤ (Set.range (Pi.basisFun ℝ ι))
variable {n} in
theorem mem_smul_span_iff {v : ι → ℝ} :
v ∈ (n : ℝ)⁻¹ • L ↔ ∀ i, n * v i ∈ Set.range (algebraMap ℤ ℝ) := by
rw [ZSpan.smul _ (inv_ne_zero (NeZero.ne _)), Module.Basis.mem_span_iff_repr_mem]
simp_rw [Module.Basis.repr_isUnitSMul, Pi.basisFun_repr, Units.smul_def, Units.val_inv_eq_inv_val,
IsUnit.unit_spec, inv_inv, smul_eq_mul]
theorem tag_mem_smul_span (ν : ι → ℤ) :
tag n ν ∈ (n : ℝ)⁻¹ • L := by
refine mem_smul_span_iff.mpr fun i ↦ ⟨ν i + 1, ?_⟩
rw [tag_apply, div_eq_inv_mul, ← mul_assoc, mul_inv_cancel_of_invertible, one_mul, map_add,
map_one, eq_intCast]
theorem tag_index_eq_self_of_mem_smul_span {x : ι → ℝ} (hx : x ∈ (n : ℝ)⁻¹ • L) :
tag n (index n x) = x := by
rw [mem_smul_span_iff] at hx
ext i
obtain ⟨a, ha⟩ : ∃ a : ℤ, a = n * x i := hx i
rwa [tag_apply, index_apply, Int.cast_sub, Int.cast_one, sub_add_cancel, ← ha, Int.ceil_intCast,
div_eq_iff (NeZero.ne _), mul_comm]
theorem eq_of_mem_smul_span_of_index_eq_index {x y : ι → ℝ} (hx : x ∈ (n : ℝ)⁻¹ • L)
(hy : y ∈ (n : ℝ)⁻¹ • L) (h : index n x = index n y) : x = y := by
rw [← tag_index_eq_self_of_mem_smul_span n hx, ← tag_index_eq_self_of_mem_smul_span n hy, h]
theorem integralSum_eq_tsum_div {B : Box ι} (hB : hasIntegralVertices B) (hs₀ : s ≤ B) :
integralSum (Set.indicator s F) (BoxAdditiveMap.toSMul (Measure.toBoxAdditive volume))
(prepartition n B) = (∑' x : ↑(s ∩ (n : ℝ)⁻¹ • L), F x) / n ^ card ι := by
classical
unfold integralSum
have : Fintype ↑(s ∩ (n : ℝ)⁻¹ • L) := by
apply Set.Finite.fintype
rw [← coe_pointwise_smul, ZSpan.smul _ (inv_ne_zero (NeZero.ne _))]
exact ZSpan.setFinite_inter _ (B.isBounded.subset hs₀)
rw [tsum_fintype, Finset.sum_set_coe, Finset.sum_div, eq_comm]
simp_rw [Set.indicator_apply, apply_ite, BoxAdditiveMap.toSMul_apply, Measure.toBoxAdditive_apply,
smul_eq_mul, mul_zero, Finset.sum_ite, Finset.sum_const_zero, add_zero]
refine Finset.sum_bij (fun x _ ↦ box n (index n x)) (fun _ hx ↦ Finset.mem_filter.mpr ?_)
(fun _ hx _ hy h ↦ ?_) (fun I hI ↦ ?_) (fun _ hx ↦ ?_)
· rw [Set.mem_toFinset] at hx
refine ⟨mem_prepartition_boxes_iff.mpr
⟨index n _, mem_admissibleIndex_of_mem_box n hB (hs₀ hx.1), rfl⟩, ?_⟩
simp_rw [prepartition_tag n (mem_admissibleIndex_of_mem_box n hB (hs₀ hx.1)),
tag_index_eq_self_of_mem_smul_span n hx.2, hx.1]
· rw [Set.mem_toFinset] at hx hy
exact eq_of_mem_smul_span_of_index_eq_index n hx.2 hy.2 (box_injective n h)
· rw [Finset.mem_filter] at hI
refine ⟨(prepartition n B).tag I, Set.mem_toFinset.mpr ⟨hI.2, ?_⟩, box_index_tag_eq_self n hI.1⟩
rw [← box_index_tag_eq_self n hI.1, prepartition_tag n
(mem_admissibleIndex_of_mem_box n hB (hs₀ hI.2))]
exact tag_mem_smul_span _ _
· rw [Set.mem_toFinset] at hx
rw [measureReal_def, volume_box,
prepartition_tag n (mem_admissibleIndex_of_mem_box n hB (hs₀ hx.1)),
tag_index_eq_self_of_mem_smul_span n hx.2, ENNReal.toReal_div,
ENNReal.toReal_one, ENNReal.toReal_pow, ENNReal.toReal_natCast, mul_comm_div, one_mul]
open Filter
/-- Let `s` be a bounded, measurable set of `ι → ℝ` whose frontier has zero volume and let `F`
be a continuous function. Then the limit as `n → ∞` of `∑ F x / n ^ card ι`, where the sum is
over the points in `s ∩ n⁻¹ • (ι → ℤ)`, tends to the integral of `F` over `s`. -/
theorem _root_.tendsto_tsum_div_pow_atTop_integral (hF : Continuous F) (hs₁ : IsBounded s)
(hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) :
Tendsto (fun n : ℕ ↦ (∑' x : ↑(s ∩ (n : ℝ)⁻¹ • L), F x) / n ^ card ι)
atTop (nhds (∫ x in s, F x)) := by
obtain ⟨B, hB, hs₀⟩ := le_hasIntegralVertices_of_isBounded hs₁
refine Metric.tendsto_atTop.mpr fun ε hε ↦ ?_
have h₁ : ∃ C, ∀ x ∈ Box.Icc B, ‖Set.indicator s F x‖ ≤ C := by
obtain ⟨C₀, h₀⟩ := (Box.isCompact_Icc B).exists_bound_of_continuousOn hF.continuousOn
refine ⟨max 0 C₀, fun x hx ↦ ?_⟩
rw [Set.indicator]
split_ifs with hs
· exact le_max_of_le_right (h₀ x hx)
· exact norm_zero.trans_le <|le_max_left 0 _
have h₂ : ∀ᵐ x, ContinuousAt (s.indicator F) x := by
filter_upwards [compl_mem_ae_iff.mpr hs₃] with _ h
using (hF.continuousOn).continuousAt_indicator h
obtain ⟨r, hr₁, hr₂⟩ := (hasIntegral_iff.mp <|
AEContinuous.hasBoxIntegral (volume : Measure (ι → ℝ)) h₁ h₂
IntegrationParams.Riemann) (ε / 2) (half_pos hε)
refine ⟨⌈(r 0 0 : ℝ)⁻¹⌉₊, fun n hn ↦ lt_of_le_of_lt ?_ (half_lt_self_iff.mpr hε)⟩
have : NeZero n :=
⟨Nat.ne_zero_iff_zero_lt.mpr <| (Nat.ceil_pos.mpr (inv_pos.mpr (r 0 0).prop)).trans_le hn⟩
rw [← integralSum_eq_tsum_div _ s F hB hs₀, ← Measure.restrict_restrict_of_subset hs₀,
← integral_indicator hs₂]
refine hr₂ 0 _ ⟨?_, fun _ ↦ ?_, fun h ↦ ?_, fun h ↦ ?_⟩ (prepartition_isPartition _ hB)
· rw [show r 0 = fun _ ↦ r 0 0 from funext_iff.mpr (hr₁ 0 rfl)]
apply prepartition_isSubordinate n B
rw [one_div, inv_le_comm₀ (mod_cast (Nat.pos_of_neZero n)) (r 0 0).prop]
exact le_trans (Nat.le_ceil _) (Nat.cast_le.mpr hn)
· exact prepartition_isHenstock n B
· simp only [IntegrationParams.Riemann, Bool.false_eq_true] at h
· simp only [IntegrationParams.Riemann, Bool.false_eq_true] at h
/-- Let `s` be a bounded, measurable set of `ι → ℝ` whose frontier has zero volume. Then the limit
as `n → ∞` of `card (s ∩ n⁻¹ • (ι → ℤ)) / n ^ card ι` tends to the volume of `s`. This is a
special case of `tendsto_card_div_pow` with `F = 1`. -/
theorem _root_.tendsto_card_div_pow_atTop_volume (hs₁ : IsBounded s)
(hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) :
Tendsto (fun n : ℕ ↦ (Nat.card ↑(s ∩ (n : ℝ)⁻¹ • L) : ℝ) / n ^ card ι)
atTop (𝓝 (volume.real s)) := by
convert tendsto_tsum_div_pow_atTop_integral s (fun _ ↦ 1) continuous_const hs₁ hs₂ hs₃
· rw [tsum_const, nsmul_eq_mul, mul_one, Nat.cast_inj]
· rw [setIntegral_const, smul_eq_mul, mul_one]
private def tendsto_card_div_pow₁ {c : ℝ} (hc : c ≠ 0) :
↑(s ∩ c⁻¹ • L) ≃ ↑(c • s ∩ L) :=
Equiv.subtypeEquiv (Equiv.smulRight hc) (fun x ↦ by
simp_rw [Set.mem_inter_iff, Equiv.smulRight_apply, Set.smul_mem_smul_set_iff₀ hc,
← Set.mem_inv_smul_set_iff₀ hc])
private theorem tendsto_card_div_pow₂ (hs₁ : IsBounded s)
(hs₄ : ∀ ⦃x y : ℝ⦄, 0 < x → x ≤ y → x • s ⊆ y • s) {x y : ℝ} (hx : 0 < x) (hy : x ≤ y) :
Nat.card ↑(s ∩ x⁻¹ • L) ≤ Nat.card ↑(s ∩ y⁻¹ • L) := by
rw [Nat.card_congr (tendsto_card_div_pow₁ s hx.ne'),
Nat.card_congr (tendsto_card_div_pow₁ s (hx.trans_le hy).ne')]
refine Nat.card_mono ?_ ?_
· exact ZSpan.setFinite_inter _ (IsBounded.smul₀ hs₁ y)
· exact Set.inter_subset_inter_left _ <| hs₄ hx hy
private theorem tendsto_card_div_pow₃ (hs₁ : IsBounded s)
(hs₄ : ∀ ⦃x y : ℝ⦄, 0 < x → x ≤ y → x • s ⊆ y • s) :
∀ᶠ x : ℝ in atTop, (Nat.card ↑(s ∩ (⌊x⌋₊ : ℝ)⁻¹ • L) : ℝ) / x ^ card ι ≤
(Nat.card ↑(s ∩ x⁻¹ • L) : ℝ) / x ^ card ι := by
filter_upwards [eventually_ge_atTop 1] with x hx
gcongr
exact tendsto_card_div_pow₂ s hs₁ hs₄ (Nat.cast_pos.mpr (Nat.floor_pos.mpr hx))
(Nat.floor_le (zero_le_one.trans hx))
private theorem tendsto_card_div_pow₄ (hs₁ : IsBounded s)
(hs₄ : ∀ ⦃x y : ℝ⦄, 0 < x → x ≤ y → x • s ⊆ y • s) :
∀ᶠ x : ℝ in atTop, (Nat.card ↑(s ∩ x⁻¹ • L) : ℝ) / x ^ card ι ≤
(Nat.card ↑(s ∩ (⌈x⌉₊ : ℝ)⁻¹ • L) : ℝ) / x ^ card ι := by
filter_upwards [eventually_gt_atTop 0] with x hx
gcongr
exact tendsto_card_div_pow₂ s hs₁ hs₄ hx (Nat.le_ceil _)
private theorem tendsto_card_div_pow₅ :
(fun x ↦ (Nat.card ↑(s ∩ (⌊x⌋₊ : ℝ)⁻¹ • L) : ℝ) / ⌊x⌋₊ ^ card ι * (⌊x⌋₊ / x) ^ card ι)
=ᶠ[atTop] (fun x ↦ (Nat.card ↑(s ∩ (⌊x⌋₊ : ℝ)⁻¹ • L) : ℝ) / x ^ card ι) := by
filter_upwards [eventually_ge_atTop 1] with x hx
have : 0 < ⌊x⌋₊ := Nat.floor_pos.mpr hx
rw [div_pow, mul_div, div_mul_cancel₀ _ (by positivity)]
private theorem tendsto_card_div_pow₆ :
(fun x ↦ (Nat.card ↑(s ∩ (⌈x⌉₊ : ℝ)⁻¹ • L) : ℝ) / ⌈x⌉₊ ^ card ι * (⌈x⌉₊ / x) ^ card ι)
=ᶠ[atTop] (fun x ↦ (Nat.card ↑(s ∩ (⌈x⌉₊ : ℝ)⁻¹ • L) : ℝ) / x ^ card ι) := by
filter_upwards [eventually_ge_atTop 1] with x hx
have : 0 < ⌊x⌋₊ := Nat.floor_pos.mpr hx
rw [div_pow, mul_div, div_mul_cancel₀ _ (by positivity)]
/-- A version of `tendsto_card_div_pow_atTop_volume` for a real variable. -/
theorem _root_.tendsto_card_div_pow_atTop_volume' (hs₁ : IsBounded s)
(hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0)
(hs₄ : ∀ ⦃x y : ℝ⦄, 0 < x → x ≤ y → x • s ⊆ y • s) :
Tendsto (fun x : ℝ ↦ (Nat.card ↑(s ∩ x⁻¹ • L) : ℝ) / x ^ card ι)
atTop (𝓝 (volume.real s)) := by
rw [show volume.real s = volume.real s * 1 ^ card ι by ring]
refine tendsto_of_tendsto_of_tendsto_of_le_of_le' ?_ ?_
(tendsto_card_div_pow₃ s hs₁ hs₄) (tendsto_card_div_pow₄ s hs₁ hs₄)
· refine Tendsto.congr' (tendsto_card_div_pow₅ s) (Tendsto.mul ?_ (Tendsto.pow ?_ _))
· exact Tendsto.comp (tendsto_card_div_pow_atTop_volume s hs₁ hs₂ hs₃) tendsto_nat_floor_atTop
· exact tendsto_nat_floor_div_atTop
· refine Tendsto.congr' (tendsto_card_div_pow₆ s) (Tendsto.mul ?_ (Tendsto.pow ?_ _))
· exact Tendsto.comp (tendsto_card_div_pow_atTop_volume s hs₁ hs₂ hs₃) tendsto_nat_ceil_atTop
· exact tendsto_nat_ceil_div_atTop
end BoxIntegral.unitPartition
|
Prod.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Algebra.Algebra.Prod
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
/-!
# Products of subalgebras
In this file we define the product of two subalgebras as a subalgebra of the product algebra.
## Main definitions
* `Subalgebra.prod`: the product of two subalgebras.
-/
namespace Subalgebra
open Algebra
variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable (S : Subalgebra R A) (S₁ : Subalgebra R B)
/-- The product of two subalgebras is a subalgebra. -/
def prod : Subalgebra R (A × B) :=
{ S.toSubsemiring.prod S₁.toSubsemiring with
carrier := S ×ˢ S₁
algebraMap_mem' := fun _ => ⟨algebraMap_mem _ _, algebraMap_mem _ _⟩ }
@[simp]
theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ (S₁ : Set B) :=
rfl
open Subalgebra in
theorem prod_toSubmodule : toSubmodule (S.prod S₁) = (toSubmodule S).prod (toSubmodule S₁) := rfl
@[simp]
theorem mem_prod {S : Subalgebra R A} {S₁ : Subalgebra R B} {x : A × B} :
x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ := Set.mem_prod
@[simp]
theorem prod_top : (prod ⊤ ⊤ : Subalgebra R (A × B)) = ⊤ := by ext; simp
theorem prod_mono {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :
S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=
Set.prod_mono
@[simp]
theorem prod_inf_prod {S T : Subalgebra R A} {S₁ T₁ : Subalgebra R B} :
S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=
SetLike.coe_injective Set.prod_inter_prod
end Subalgebra
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.