filename
stringlengths
5
42
content
stringlengths
15
319k
alt.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 choice. From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg. From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient. From mathcomp Require Import action cyclic pgroup gseries sylow. From mathcomp Require Import primitive_action nilpotent maximal. (******************************************************************************) (* Definitions of the symmetric and alternate groups, and some properties. *) (* 'Sym_T == The symmetric group over type T (which must have a finType *) (* structure). *) (* := [set: {perm T}] *) (* 'Alt_T == The alternating group over type T. *) (******************************************************************************) Unset Printing Implicit Defensive. Set Implicit Arguments. Unset Strict Implicit. Import GroupScope GRing. HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb. Section SymAltDef. Variable T : finType. Implicit Types (s : {perm T}) (x y z : T). (** Definitions of the alternate groups and some Properties **) Definition Sym : {set {perm T}} := setT. Canonical Sym_group := Eval hnf in [group of Sym]. Local Notation "'Sym_T" := Sym. Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)). Definition Alt := 'ker (@odd_perm T). Canonical Alt_group := Eval hnf in [group of Alt]. Local Notation "'Alt_T" := Alt. Lemma Alt_even p : (p \in 'Alt_T) = ~~ p. Proof. by rewrite !inE /=; case: odd_perm. Qed. Lemma Alt_subset : 'Alt_T \subset 'Sym_T. Proof. exact: subsetT. Qed. Lemma Alt_normal : 'Alt_T <| 'Sym_T. Proof. exact: ker_normal. Qed. Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T). Proof. by case/andP: Alt_normal. Qed. Let n := #|T|. Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2. Proof. move=> lt1n; rewrite -card_quotient ?Alt_norm //=. have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog. case/isogP=> g /injmP/card_in_imset <-. rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b. apply/imsetP; case: b => /=; last first. by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1]. case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0. rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=]. by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE. Qed. Lemma card_Sym : #|'Sym_T| = n`!. Proof. rewrite -[n]cardsE -card_perm; apply: eq_card => p. by apply/idP/subsetP=> [? ?|]; rewrite !inE. Qed. Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!. Proof. by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym. Qed. Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P]. Proof. apply/imsetP; pose t1 := [tuple of enum T]. have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP. exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE. case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj. exists (perm injf); first by rewrite inE. apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth. by rewrite (tnth_nth (enum_default i)) enum_valK. Qed. Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P]. Proof. case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0. have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2. case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t. rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA. case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u. apply/idP/imsetP=> [|[a _ ->{u}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE. case/(atransP2 tr_m dt)=> /= a _ ->{u}. case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a. exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a. apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _). by case: tpermP ntx nty => // <-; rewrite tz. Qed. Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P]. Proof. by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE. Qed. End SymAltDef. Arguments Sym T%_type. Arguments Sym_group T%_type. Arguments Alt T%_type. Arguments Alt_group T%_type. Notation "''Sym_' T" := (Sym T) (at level 8, T at level 2, format "''Sym_' T") : group_scope. Notation "''Sym_' T" := (Sym_group T) : Group_scope. Notation "''Alt_' T" := (Alt T) (at level 8, T at level 2, format "''Alt_' T") : group_scope. Notation "''Alt_' T" := (Alt_group T) : Group_scope. Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1. Proof. rewrite leq_eqVlt => /predU1P[] oT. by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT. suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT. by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case. Qed. Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T. Proof. move=> T3; have{T3} oA: #|'Alt_T| = 3. by apply: double_inj; rewrite -mul2n card_Alt T3. apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _]. have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA. case/pred2P=> eqK; [right | left]; apply/eqP. by rewrite eqEcard sKH eqK leqnn. by rewrite eq_sym eqEcard sub1G eqK cards1. Qed. Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T. Proof. move=> oT; set A := 'Alt_T. have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT. suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N]. case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP. rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int. by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int. have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12). by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod. rewrite /= oA mem_seq2 orbC. case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //. pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8. have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3. rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP]. apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP. rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px. by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox. have [/= P sylP] := Sylow_exists 2 [group of A]. rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP. by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE. rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const. rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first. by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA. apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=. case/andP=> sQA /eqP oQ; have:= oQ. rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x. rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1. apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id. have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=. by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->. Qed. Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T. Proof. move=> oT. have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT. have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|. - move=> Hh1 Hh3. have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT. have F2 := Alt_trans T; rewrite oT /= in F2. have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2. have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2. case: (prim_trans_norm F4 Hh1) => F5. by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _). have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5). have F7: 4 %| #|H|. have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT. case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7. pose K := 'C_H[x | 'P]%G. have F8 : K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]%G. have F9: [transitive^2 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. exact: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. exact: ntransitive_primitive F9. have F12: K \subset Gx by apply: setSI; apply: normal_sub. have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm. case: (prim_trans_norm F11 F13) => Ksub; last first. by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub. have F14: [faithful Gx, on [set~ x] | 'P]. apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'. apply: (subsetP (aperm_faithful 'Alt_T)). rewrite inE Altg /=; apply/astabP=> z _. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> nxz; rewrite (astabP cgx') ?inE //. have Hreg g (z : T): g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite (trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg. clear K F8 F12 F13 Ksub F14. case: (Cauchy _ F6) => // h Hh /eqP Horder. have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x. move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH. have: #[h ^+ n] = 5. rewrite orderXgcd // (eqP Horder). by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //). have Hhd2: h ^+ n \in H by rewrite groupX. by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1. pose S1 := [tuple x; h x; (h ^+ 3) x]. have DnS1: S1 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. pose S2 := [tuple x; h x; (h ^+ 2) x]. have DnS2: S2 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. case: (atransP2 F2 DnS1 DnS2) => g Hg [/=]. rewrite /aperm => Hgx Hghx Hgh3x. have h_g_com: h * g = g * h. suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1. rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg. by case/normalP: Hh1 => _ ->. have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x. rewrite !permM -Hgx. have ->: h (h x) = (h ^+ 2) x by rewrite /= permM. by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr. rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock. by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1. by rewrite (@Gauss_dvd 4 5) // F7. apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60. by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm. have {Hcard1 Hcard60} Hcard20: #|H| = 20. have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1. case H20: (#|H| == 20); first exact/eqP. case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _. by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //. have prime_5: prime 5 by []. have nSyl5: #|'Syl_5(H)| = 1%N. move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5). rewrite Hcard20; case: (card _) => // n Hdiv. move: (dvdn_leq (isT: (0 < 20)%N) Hdiv). by move: (n) Hdiv; do 20 (case=> //). case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS. have{} oS: #|S| = 5 by rewrite oS p_part Hcard20. suff: 20 %| #|S| by rewrite oS. apply: FF => [|S1]; last by rewrite S1 cards1 in oS. apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS. rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5. rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part. by rewrite (card_isog isoQS) oS. Qed. Section Restrict. Variables (T : finType) (x : T). Notation T' := {y | y != x}. Lemma rfd_funP (p : {perm T}) (u : T') : let p1 := if p x == x then p else 1 in p1 (val u) != x. Proof. case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u). by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u). Qed. Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T']. Lemma rfdP p : injective (rfd_fun p). Proof. apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=. rewrite -(can_eq (permK p)) permKV eq_sym. by case: eqP => _; rewrite !(perm1, permK). Qed. Definition rfd p := perm (@rfdP p). Hypothesis card_T : 2 < #|T|. Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}. Proof. move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x. apply/permP=> u; apply: val_inj. by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=. Qed. Canonical rfd_morphism := Morphism rfd_morph. Definition rgd_fun (p : {perm T'}) := [fun x1 => if insub x1 is Some u then sval (p u) else x]. Lemma rgdP p : injective (rgd_fun p). Proof. apply: can_inj (rgd_fun p^-1) _ => y /=. case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK. by rewrite negbK; move/eqP->; rewrite insubF //= eqxx. Qed. Definition rgd p := perm (@rgdP p). Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool. Proof. have rfd1: rfd 1 = 1. by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1. have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x. have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x]. suffices ->: p = 1 by rewrite rfd1 !odd_perm1. by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE. have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx. have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x. have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj). pose p1 := p * tperm x1 (p x1). have fix_p1 y: p y = y -> p1 y = y. by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy. have p1x_x: p1 x = x by apply: fix_p1. have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n. move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card. rewrite subsetD1 inE permM tpermR eqxx andbT. by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->. transitivity (p1 (+) true); last first. by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK. have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK. rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P. by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x. rewrite odd_permM IHn //=; congr (_ (+) _). pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x. suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2. by rewrite odd_tperm eq_sym; rewrite inE in Hx1. apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx. by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=. Qed. Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'. Proof. have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx. have rfd_rgd p: rfd (rgd p) = p. apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE. by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT. have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd. by apply/subsetP=> p /[!inE]/= /andP[]. apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first. rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|]. case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->. by rewrite Alt_even rfd_odd. have dz': rgd z x == x by rewrite rgd_x. move=> kz; exists (rgd z); last by rewrite /= rfd_rgd. by rewrite 2!inE (sameP astab1P eqP). rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP. by rewrite rfd_rgd mker // ?set11. apply/injmP=> x1 y1 /=. case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1. case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr. apply/permP => z. case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx]. move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr). by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx. Qed. End Restrict. Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T. Proof. suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1. elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base. have oT: 5 < #|T| by rewrite Hde addnC. apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm. rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //. by rewrite addSn factS mulnC -(prednK (fact_gt0 _)). case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT. case/pred0Pn: E1 => x _; have Hx := in_setT x. have F2: [transitive^4 'Alt_T, on setT | 'P]. by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT). have F3 := ntransitive1 (isT: 0 < 4) F2. have F4 := ntransitive_primitive (isT: 1 < 4) F2. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case: (prim_trans_norm F4 Hnorm) => F5. by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1. case E1: (pred0b (predD1 T x)). rewrite /pred0b in E1; move: oT. by rewrite (cardD1 x) (eqP E1); case: (T x). case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy. pose K := 'C_H[x | 'P]%G. have F8: K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]. have F9: [transitive^3 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. by apply: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. by apply: ntransitive_primitive F9. have F12: K \subset Gx by rewrite setSI // normal_sub. have F13: K <| Gx by apply/andP; rewrite normsIG. have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first. have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3). have: simple Gx. by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde. case/simpleP=> _ simGx; case/simGx: F13 => /= HH2. case Ez: (pred0b (predD1 (predD1 T x) y)). move: oT; rewrite /pred0b in Ez. by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y. case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz. have [diff_x_z Hz] := andP Hdz. have: z \in [set~ x] by rewrite !inE. rewrite -(atransP Ksub y) ?inE //; case/imsetP => g. rewrite /= HH2 inE; move/eqP=> -> HH4. by case/negP: diff_y_z; rewrite HH4 act1. by rewrite /= -F14 -[Gx]HH2 (mulSGid F8). have F14: [faithful Gx, on [set~ x] | 'P]. apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT. apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE. have Hreg g z: g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by rewrite memJ_norm ?(subsetP nH). clear K F8 F12 F13 Ksub F14. have Hcard: 5 < #|H|. apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0. by rewrite -cardsT (atrans_dvd F5). case Eh: (pred0b [predD1 H & 1]). by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh). case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh. case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)). move: Hcard; rewrite ltnNge; case/negP. rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg). by do 2!case: (_ \in _). case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g. case/andP => diff_1_g /= Hg. case diff_hx_x: (h x == x). by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)). case diff_gx_x: (g x == x). case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)). case diff_gx_hx: (g x == h x). case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp. apply: (Hreg _ x); first by rewrite groupM // groupV. by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1. case diff_hgx_x: ((h * g) x == x). case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp. by apply: (Hreg _ x); [apply: groupM | apply/eqP]. case diff_hgx_hx: ((h * g) x == h x). case/negP: diff_1_g; apply/eqP. by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM. case diff_hgx_gx: ((h * g) x == g x). by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM. case Ez: (pred0b (predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))). - move: oT; rewrite /pred0b in Ez. rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)). by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _). case/pred0Pn: Ez => z. case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz. pose S1 := [tuple x; h x; g x; z]. have DnS1: S1 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT. rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z. by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx. pose S2 := [tuple x; h x; g x; (h * g) x]. have DnS2: S2 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x). rewrite diff_hx_x diff_gx_x diff_hgx_x. by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx. case: (atransP2 F2 DnS1 DnS2) => k Hk [/=]. rewrite /aperm => Hkx Hkhx Hkgx Hkhgx. have h_k_com: h * k = k * h. suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have g_k_com: g * k = k * g. suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have HH: (k * (h * g) * k ^-1) x = z. by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1. case/negP: diff_hgx_z. rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA. by rewrite -g_k_com -!mulgA mulgV mulg1. Qed. Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| -> x != y -> #[c]%g = #|X| -> <<[set tperm x y; c]>>%g = ('Sym_X)%g. Proof. move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=. have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1. have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL. pose f (i : 'Z_#[c]%g) : X := Zpm i x. have [g fK gK] : bijective f. apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx. pose stabx := ('C_<[c]>[x | 'P])%g. have cjix : (c ^+ (j - i)%R)%g x = x. by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK. have : (c ^+ (j - i)%R)%g \in stabx. by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx. rewrite [stabx]perm_prime_astab// => /set1gP. move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1. by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->. pose gsf s := g \o s \o f. have gsf_inj (s : {perm X}) : injective (gsf s). apply: inj_comp; last exact: can_inj fK. by apply: inj_comp; [exact: can_inj gK|exact: perm_inj]. pose fsg s := f \o s \o g. have fsg_inj (s : {perm _}) : injective (fsg s). apply: inj_comp; last exact: can_inj gK. by apply: inj_comp; [exact: can_inj fK|exact: perm_inj]. have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)). apply/morphicP => u v _ _; apply/permP => /= i. by rewrite !permE/= !permE /gsf /= gK permM. pose phi := morphm gsf_morphic; rewrite /= in phi. have phi_inj : ('injm phi)%g. apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1. apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1. by rewrite !perm1 permE /gsf/= gK => /(can_inj gK). have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}]. apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _. apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//. by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK. have f0 : f 0%R = x by rewrite /f /Zpm permX. pose k := g y; have k_gt0 : (k > 0)%N. by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0. have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k. apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK). by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if. have phic : phi c = perm (addrI (1%R : 'Z_#[c])). apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK). by rewrite /f /Zpm -permM addrC expgD_Zp. rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi. rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic. suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by []. by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS. Qed. Section Perm_solvable. Local Open Scope nat_scope. Variable T : finType. Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false. Proof. move=> card_T; apply/negP => Alt_solvable. have/simple_Alt5 Alt_simple := card_T. have := simple_sol_prime Alt_solvable Alt_simple. have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply. have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T. move/even_prime => [/eqP|]; apply/negP. rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!). by apply/orP; right; apply/ltnW/ltn_fact/lt_T. by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T. Qed. Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false. Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed. End Perm_solvable.
Expand.lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Monad /-! ## Expand multivariate polynomials Given a multivariate polynomial `φ`, one may replace every occurrence of `X i` by `X i ^ n`, for some natural number `n`. This operation is called `MvPolynomial.expand` and it is an algebra homomorphism. ### Main declaration * `MvPolynomial.expand`: expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. -/ namespace MvPolynomial variable {σ τ R S : Type*} [CommSemiring R] [CommSemiring S] /-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`. See also `Polynomial.expand`. -/ noncomputable def expand (p : ℕ) : MvPolynomial σ R →ₐ[R] MvPolynomial σ R := { (eval₂Hom C fun i ↦ X i ^ p : MvPolynomial σ R →+* MvPolynomial σ R) with commutes' := fun _ ↦ eval₂Hom_C _ _ _ } theorem expand_C (p : ℕ) (r : R) : expand p (C r : MvPolynomial σ R) = C r := eval₂Hom_C _ _ _ @[simp] theorem expand_X (p : ℕ) (i : σ) : expand p (X i : MvPolynomial σ R) = X i ^ p := eval₂Hom_X' _ _ _ @[simp] theorem expand_monomial (p : ℕ) (d : σ →₀ ℕ) (r : R) : expand p (monomial d r) = C r * ∏ i ∈ d.support, (X i ^ p) ^ d i := bind₁_monomial _ _ _ theorem expand_one_apply (f : MvPolynomial σ R) : expand 1 f = f := by simp only [expand, pow_one, eval₂Hom_eq_bind₂, bind₂_C_left, AlgHom.coe_mk, RingHom.id_apply] @[simp] theorem expand_one : expand 1 = AlgHom.id R (MvPolynomial σ R) := by ext1 f rw [expand_one_apply, AlgHom.id_apply] theorem expand_comp_bind₁ (p : ℕ) (f : σ → MvPolynomial τ R) : (expand p).comp (bind₁ f) = bind₁ fun i ↦ expand p (f i) := by apply algHom_ext intro i simp only [AlgHom.comp_apply, bind₁_X_right] theorem expand_bind₁ (p : ℕ) (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) : expand p (bind₁ f φ) = bind₁ (fun i ↦ expand p (f i)) φ := by rw [← AlgHom.comp_apply, expand_comp_bind₁] @[simp] theorem map_expand (f : R →+* S) (p : ℕ) (φ : MvPolynomial σ R) : map f (expand p φ) = expand p (map f φ) := by simp [expand, map_bind₁] @[simp] theorem rename_expand (f : σ → τ) (p : ℕ) (φ : MvPolynomial σ R) : rename f (expand p φ) = expand p (rename f φ) := by simp [expand, bind₁_rename, rename_bind₁, Function.comp_def] @[simp] theorem rename_comp_expand (f : σ → τ) (p : ℕ) : (rename f).comp (expand p) = (expand p).comp (rename f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) := by ext1 φ simp only [rename_expand, AlgHom.comp_apply] end MvPolynomial
fieldext.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 div. From mathcomp Require Import choice fintype tuple finfun bigop ssralg countalg. From mathcomp Require Import finalg zmodp matrix vector falgebra poly polydiv. From mathcomp Require Import mxpoly generic_quotient. (******************************************************************************) (* Finite dimensional field extensions *) (* *) (* fieldExtType F == the interface type for finite field extensions of F *) (* it simply combines the fieldType and falgType F *) (* interfaces *) (* The HB class is called FieldExt. *) (* {subfield L} == the type of subfields of L that are also extensions *) (* of F; since we are in a finite dimensional setting *) (* these are exactly the F-subalgebras of L, and *) (* indeed {subfield L} is just display notation for *) (* {aspace L} when L is an extFieldType *) (* --> All aspace operations apply to {subfield L}, but there are several *) (* additional lemmas and canonical instances specific to {subfield L} *) (* spaces, e.g., subvs_of E is an extFieldType F when E : {subfield L}. *) (* --> Also note that not all constructive subfields have type {subfield E} *) (* in the same way that not all constructive subspaces have type *) (* {vspace E}. These types only include the so called "detachable" *) (* subspaces (and subalgebras). *) (* *) (* (E :&: F)%AS, (E * F)%AS == the intersection and product (meet and join) *) (* of E and F as subfields *) (* subFExtend iota z p == given a field morphism iota : F -> L, this is a *) (* type for the field F^iota(z) obtained by *) (* adjoining z to the image of F in L under iota *) (* The construction requires a non-zero polynomial *) (* p in F such that z is a root of p^iota; it *) (* returns the field F^iota if this is not so. *) (* However, p need not be irredicible. *) (* subfx_inj x == the injection of F^iota(z) into L *) (* inj_subfx iota z p x == the injection of F into F^iota(z) *) (* subfx_eval iota z p q == given q : {poly F} returns q.[z] as a value of *) (* type F^iota(z) *) (* subfx_root iota z p == the generator of F^iota(z) over F *) (* SubFieldExtType pz0 irr_p == a fieldExtType F structure for F^iota(z) *) (* (more precisely, subFExtend iota z p), given *) (* proofs pz0: root (map_poly iota p) z and *) (* irr_p : irreducible_poly p. *) (* The corresponding vectType substructure *) (* (SubfxVectType pz0 irr_p) has dimension *) (* (size p).-1 over F. *) (* minPoly K x == the monic minimal polynomial of x over the *) (* subfield K *) (* adjoin_degree K x == the degree of the minimal polynomial or the *) (* dimension of K(x)/K *) (* Fadjoin_poly K x y == a polynomial p over K such that y = p.[x] *) (* *) (* fieldOver F == L, but with an extFieldType (subvs_of F) *) (* structure, for F : {subfield L} *) (* vspaceOver F V == the smallest subspace of fieldOver F containing *) (* V; this coincides with V if V is an F-module *) (* baseFieldType L == L, but with an extFieldType F0 structure, when L *) (* has a canonical extFieldType F structure and F *) (* in turn has an extFieldType F0 structure *) (* baseVspace V == the subspace of baseFieldType L that coincides *) (* with V : {vspace L} *) (* --> Some caution must be exercised when using fieldOver and baseFieldType, *) (* because these are convertible to L while carrying different Lmodule *) (* structures. This means that the safeguards engineered in the ssralg *) (* library that normally curb the Coq kernel's inclination to diverge are *) (* no longer effectcive, so additional precautions should be taken when *) (* matching or rewriting terms of the form a *: u, because Coq may take *) (* forever to realize it's dealing with a *: in the wrong structure. The *) (* baseField_scaleE and fieldOver_scaleE lemmas should be used to expand *) (* or fold such "trans-structure" operations explicitly beforehand. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory. #[short(type="fieldExtType")] HB.structure Definition FieldExt (R : nzRingType) := {T of Falgebra R T & GRing.PzRing_hasCommutativeMul T & GRing.Field T}. Module FieldExtExports. Bind Scope ring_scope with FieldExt.sort. Notation "{ 'subfield' L }" := (aspace L) (* NB: was (@aspace_of _ (FalgType _) (Phant L)) *) (format "{ 'subfield' L }") : type_scope. End FieldExtExports. HB.export FieldExtExports. (* FIXME: strange way to build a FieldExt *) HB.instance Definition _ (F : fieldType) := GRing.Field.on F^o. Section FieldExtTheory. Variables (F0 : fieldType) (L : fieldExtType F0). Implicit Types (U V M : {vspace L}) (E F K : {subfield L}). Lemma dim_cosetv U x : x != 0 -> \dim (U * <[x]>) = \dim U. Proof. move=> nz_x; rewrite -limg_amulr limg_dim_eq //. apply/eqP; rewrite -subv0; apply/subvP=> y. by rewrite memv_cap memv0 memv_ker lfunE mulf_eq0 (negPf nz_x) orbF => /andP[]. Qed. Lemma prodvC : commutative (@prodv F0 L). Proof. move=> U V; without loss suffices subC: U V / (U * V <= V * U)%VS. by apply/eqP; rewrite eqEsubv !{1}subC. by apply/prodvP=> x y Ux Vy; rewrite mulrC memv_mul. Qed. HB.instance Definition _ := SemiGroup.isCommutativeLaw.Build {vspace L} (@prodv _ L) prodvC. Lemma prodvCA : left_commutative (@prodv F0 L). Proof. exact: Monoid.mulmCA. Qed. Lemma prodvAC : right_commutative (@prodv F0 L). Proof. exact: Monoid.mulmAC. Qed. Lemma algid1 K : algid K = 1. Proof. exact/skew_field_algid1/fieldP. Qed. Lemma mem1v K : 1 \in K. Proof. by rewrite -algid_eq1 algid1. Qed. Lemma sub1v K : (1 <= K)%VS. Proof. exact: mem1v. Qed. Lemma subfield_closed K : agenv K = K. Proof. by apply/eqP; rewrite eqEsubv sub_agenv agenv_sub_modr ?sub1v ?asubv. Qed. Lemma AHom_lker0 (rT : falgType F0) (f : 'AHom(L, rT)) : lker f == 0%VS. Proof. by apply/lker0P; apply: fmorph_inj. Qed. Lemma AEnd_lker0 (f : 'AEnd(L)) : lker f == 0%VS. Proof. exact: AHom_lker0. Qed. Fact aimg_is_aspace (rT : falgType F0) (f : 'AHom(L, rT)) (E : {subfield L}) : is_aspace (f @: E). Proof. rewrite /is_aspace -aimgM limgS ?prodv_id // has_algid1 //. by apply/memv_imgP; exists 1; rewrite ?mem1v ?rmorph1. Qed. Canonical aimg_aspace rT f E := ASpace (@aimg_is_aspace rT f E). Lemma Fadjoin_idP {K x} : reflect (<<K; x>>%VS = K) (x \in K). Proof. apply: (iffP idP) => [/addv_idPl-> | <-]; first exact: subfield_closed. exact: memv_adjoin. Qed. Lemma Fadjoin0 K : <<K; 0>>%VS = K. Proof. by rewrite addv0 subfield_closed. Qed. Lemma Fadjoin_nil K : <<K & [::]>>%VS = K. Proof. by rewrite adjoin_nil subfield_closed. Qed. Lemma FadjoinP {K x E} : reflect (K <= E /\ x \in E)%VS (<<K; x>>%AS <= E)%VS. Proof. apply: (iffP idP) => [sKxE | /andP]. by rewrite (subvP sKxE) ?memv_adjoin // (subv_trans _ sKxE) ?subv_adjoin. by rewrite -subv_add => /agenvS; rewrite subfield_closed. Qed. Lemma Fadjoin_seqP {K} {rs : seq L} {E} : reflect (K <= E /\ {subset rs <= E})%VS (<<K & rs>> <= E)%VS. Proof. apply: (iffP idP) => [sKrsE | [sKE /span_subvP/(conj sKE)/andP]]. split=> [|x rs_x]; first exact: subv_trans (subv_adjoin_seq _ _) sKrsE. by rewrite (subvP sKrsE) ?seqv_sub_adjoin. by rewrite -subv_add => /agenvS; rewrite subfield_closed. Qed. Lemma alg_polyOver E p : map_poly (in_alg L) p \is a polyOver E. Proof. by apply/(polyOverS (subvP (sub1v _)))/polyOver1P; exists p. Qed. Lemma sub_adjoin1v x E : (<<1; x>> <= E)%VS = (x \in E)%VS. Proof. by rewrite (sameP FadjoinP andP) sub1v. Qed. Fact vsval_monoid_morphism K : monoid_morphism (vsval : subvs_of K -> L). Proof. by split => //=; apply: algid1. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `subfx_eval_is_monoid_morphism` instead")] Definition vsval_is_multiplicative K := (fun g => (g.2,g.1)) (vsval_monoid_morphism K). HB.instance Definition _ (K : {subfield L}) := GRing.isMonoidMorphism.Build (subvs_of K) L vsval (vsval_monoid_morphism K). Lemma vsval_invf K (w : subvs_of K) : val w^-1 = (vsval w)^-1. Proof. have [-> | Uv] := eqVneq w 0; first by rewrite !invr0. by apply: vsval_invr; rewrite unitfE. Qed. Fact aspace_divr_closed K : divr_closed K. Proof. by split=> [|u v Ku Kv]; rewrite ?mem1v ?memvM ?memvV. Qed. HB.instance Definition _ K := GRing.isDivClosed.Build L (pred_of_vspace K) (aspace_divr_closed K). HB.instance Definition _ (K : {subfield L}) := GRing.isSubPzSemiRing.Build L (pred_of_vspace K) (subvs_of K) (rmorph1 _, rmorphM _). (* Note that the nzRingType structure was built in the SubFalgType section of falgebra.v but the SubRing structure did not stand there, it is thus built only here *) HB.instance Definition _ (K : {subfield L}) := [SubNzRing_isSubComNzRing of subvs_of K by <:]. HB.instance Definition _ (K : {subfield L}) := [SubComUnitRing_isSubIntegralDomain of subvs_of K by <:]. Lemma subvs_fieldMixin K : GRing.field_axiom (subvs_of K). Proof. by move=> w nz_w; rewrite unitrE -val_eqE /= vsval_invf algid1 divff. Qed. HB.instance Definition _ K := GRing.UnitRing_isField.Build (subvs_of K) (@subvs_fieldMixin K). Lemma polyOver_subvs {K} {p : {poly L}} : reflect (exists q : {poly subvs_of K}, p = map_poly vsval q) (p \is a polyOver K). Proof. apply: (iffP polyOverP) => [Hp | [q ->] i]; last by rewrite coef_map // subvsP. exists (\poly_(i < size p) (Subvs (Hp i))); rewrite -{1}[p]coefK. by apply/polyP=> i; rewrite coef_map !coef_poly; case: ifP. Qed. Lemma divp_polyOver K : {in polyOver K &, forall p q, p %/ q \is a polyOver K}. Proof. move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->]. by apply/polyOver_subvs; exists (p %/ q); rewrite map_divp. Qed. Lemma modp_polyOver K : {in polyOver K &, forall p q, p %% q \is a polyOver K}. Proof. move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->]. by apply/polyOver_subvs; exists (p %% q); rewrite map_modp. Qed. Lemma gcdp_polyOver K : {in polyOver K &, forall p q, gcdp p q \is a polyOver K}. Proof. move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->]. by apply/polyOver_subvs; exists (gcdp p q); rewrite gcdp_map. Qed. Fact prodv_is_aspace E F : is_aspace (E * F). Proof. rewrite /is_aspace prodvCA -!prodvA prodvA !prodv_id has_algid1 //=. by rewrite -[1]mulr1 memv_mul ?mem1v. Qed. Canonical prodv_aspace E F : {subfield L} := ASpace (prodv_is_aspace E F). Fact field_mem_algid E F : algid E \in F. Proof. by rewrite algid1 mem1v. Qed. Canonical capv_aspace E F : {subfield L} := aspace_cap (field_mem_algid E F). Lemma polyOverSv U V : (U <= V)%VS -> {subset polyOver U <= polyOver V}. Proof. by move/subvP=> sUV; apply: polyOverS. Qed. Lemma field_subvMl F U : (U <= F * U)%VS. Proof. by rewrite -{1}[U]prod1v prodvSl ?sub1v. Qed. Lemma field_subvMr U F : (U <= U * F)%VS. Proof. by rewrite prodvC field_subvMl. Qed. Lemma field_module_eq F M : (F * M <= M)%VS -> (F * M)%VS = M. Proof. by move=> modM; apply/eqP; rewrite eqEsubv modM field_subvMl. Qed. Lemma sup_field_module F E : (F * E <= E)%VS = (F <= E)%VS. Proof. apply/idP/idP; first exact: subv_trans (field_subvMr F E). by move/(prodvSl E)/subv_trans->; rewrite ?asubv. Qed. Lemma field_module_dimS F M : (F * M <= M)%VS -> (\dim F %| \dim M)%N. Proof. exact/skew_field_module_dimS/fieldP. Qed. Lemma field_dimS F E : (F <= E)%VS -> (\dim F %| \dim E)%N. Proof. exact/skew_field_dimS/fieldP. Qed. Lemma dim_field_module F M : (F * M <= M)%VS -> \dim M = (\dim_F M * \dim F)%N. Proof. by move/field_module_dimS/divnK. Qed. Lemma dim_sup_field F E : (F <= E)%VS -> \dim E = (\dim_F E * \dim F)%N. Proof. by move/field_dimS/divnK. Qed. Lemma field_module_semisimple F M (m := \dim_F M) : (F * M <= M)%VS -> {X : m.-tuple L | {subset X <= M} /\ 0 \notin X & let FX := (\sum_(i < m) F * <[X`_i]>)%VS in FX = M /\ directv FX}. Proof. move=> modM; have dimM: (m * \dim F)%N = \dim M by rewrite -dim_field_module. have [X [defM dxFX nzX]] := skew_field_module_semisimple (@fieldP L) modM. have szX: size X == m. rewrite -(eqn_pmul2r (adim_gt0 F)) dimM -defM (directvP dxFX) /=. rewrite -sum1_size big_distrl; apply/eqP/eq_big_seq => x Xx /=. by rewrite mul1n dim_cosetv ?(memPn nzX). rewrite directvE /= (big_nth 0) [eqbRHS](big_nth 0) in defM dxFX. rewrite (eqP szX) !big_mkord -directvE in defM dxFX. exists (Tuple szX) => //; split=> // _ /tnthP[i ->]; rewrite (tnth_nth 0) /=. by rewrite -defM memvE (sumv_sup i) ?field_subvMl. Qed. Section FadjoinPolyDefinitions. Variables (U : {vspace L}) (x : L). Definition adjoin_degree := (\dim_U <<U; x>>).-1.+1. Local Notation n := adjoin_degree. Definition Fadjoin_sum := (\sum_(i < n) U * <[x ^+ i]>)%VS. Definition Fadjoin_poly v : {poly L} := \poly_(i < n) (sumv_pi Fadjoin_sum (inord i) v / x ^+ i). Definition minPoly : {poly L} := 'X^n - Fadjoin_poly (x ^+ n). Lemma size_Fadjoin_poly v : size (Fadjoin_poly v) <= n. Proof. exact: size_poly. Qed. Lemma Fadjoin_polyOver v : Fadjoin_poly v \is a polyOver U. Proof. apply/(all_nthP 0) => i _; rewrite coef_poly /=. case: ifP => lti; last exact: mem0v. have /memv_cosetP[y Uy ->] := memv_sum_pi (erefl Fadjoin_sum) (inord i) v. rewrite inordK //; have [-> | /mulfK-> //] := eqVneq (x ^+ i) 0. by rewrite mulr0 mul0r mem0v. Qed. Fact Fadjoin_poly_is_linear : linear_for (in_alg L \; *:%R) Fadjoin_poly. Proof. move=> a u v; apply/polyP=> i; rewrite coefD coefZ !coef_poly. case: ifP => lti; last by rewrite mulr0 addr0. by rewrite linearP mulrA -mulrDl mulr_algl. Qed. HB.instance Definition _ := GRing.isSemilinear.Build F0 L {poly L} _ Fadjoin_poly (GRing.semilinear_linear Fadjoin_poly_is_linear). Lemma size_minPoly : size minPoly = n.+1. Proof. by rewrite size_polyDl ?size_polyXn // size_polyN ltnS size_poly. Qed. Lemma monic_minPoly : minPoly \is monic. Proof. rewrite monicE /lead_coef size_minPoly coefB coefXn eqxx. by rewrite nth_default ?subr0 ?size_poly. Qed. End FadjoinPolyDefinitions. Section FadjoinPoly. Variables (K : {subfield L}) (x : L). Local Notation n := (adjoin_degree (asval K) x). Local Notation sumKx := (Fadjoin_sum (asval K) x). Lemma adjoin_degreeE : n = \dim_K <<K; x>>. Proof. by rewrite [n]prednK // divn_gt0 ?adim_gt0 // dimvS ?subv_adjoin. Qed. Lemma dim_Fadjoin : \dim <<K; x>> = (n * \dim K)%N. Proof. by rewrite adjoin_degreeE -dim_sup_field ?subv_adjoin. Qed. Lemma adjoin0_deg : adjoin_degree K 0 = 1. Proof. by rewrite /adjoin_degree addv0 subfield_closed divnn adim_gt0. Qed. Lemma adjoin_deg_eq1 : (n == 1) = (x \in K). Proof. rewrite (sameP Fadjoin_idP eqP) adjoin_degreeE; have sK_Kx := subv_adjoin K x. apply/eqP/idP=> [dimKx1 | /eqP->]; last by rewrite divnn adim_gt0. by rewrite eq_sym eqEdim sK_Kx /= (dim_sup_field sK_Kx) dimKx1 mul1n. Qed. Lemma Fadjoin_sum_direct : directv sumKx. Proof. rewrite directvE /=; case: (ubnPgeq n) (isT : n > 0) => -[//|m] ltmn _. elim: m ltmn => [|m IHm] ltm1n; rewrite ?big_ord1 // !(big_ord_recr m.+1) /=. do [move/(_ (ltnW ltm1n))/eqP; set S := (\sum_i _)%VS] in IHm *. rewrite -IHm dimv_add_leqif; apply/subvP=> z; rewrite memv_cap => /andP[Sz]. case/memv_cosetP=> y Ky Dz; rewrite memv0 Dz mulf_eq0 expf_eq0 /=. apply: contraLR ltm1n => /norP[nz_y nz_x]. rewrite -leqNgt -(leq_pmul2r (adim_gt0 K)) -dim_Fadjoin. have{IHm} ->: (m.+1 * \dim K)%N = \dim S. rewrite -[m.+1]card_ord -sum_nat_const IHm. by apply: eq_bigr => i; rewrite dim_cosetv ?expf_neq0. apply/dimvS/agenv_sub_modl; first by rewrite (sumv_sup 0) //= prodv1 sub1v. rewrite prodvDl subv_add -[S]big_distrr prodvA prodv_id subvv !big_distrr /=. apply/subv_sumP=> i _; rewrite -expv_line prodvCA -expvSl expv_line. have [ltim | lemi] := ltnP i m; first by rewrite (sumv_sup (Sub i.+1 _)). have{lemi} /eqP->: i == m :> nat by rewrite eqn_leq leq_ord. rewrite -big_distrr -2!{2}(prodv_id K) /= -!prodvA big_distrr -/S prodvSr //=. by rewrite -(canLR (mulKf nz_y) Dz) -memvE memv_mul ?rpredV. Qed. Let nz_x_i (i : 'I_n) : x ^+ i != 0. Proof. by rewrite expf_eq0; case: eqP i => [->|_] [[]] //; rewrite adjoin0_deg. Qed. Lemma Fadjoin_eq_sum : <<K; x>>%VS = sumKx. Proof. apply/esym/eqP; rewrite eqEdim eq_leq ?andbT. apply/subv_sumP=> i _; rewrite -agenvM prodvS ?subv_adjoin //. by rewrite -expv_line (subv_trans (subX_agenv _ _)) ?agenvS ?addvSr. rewrite dim_Fadjoin -[n]card_ord -sum_nat_const (directvP Fadjoin_sum_direct). by apply: eq_bigr => i _; rewrite /= dim_cosetv. Qed. Lemma Fadjoin_poly_eq v : v \in <<K; x>>%VS -> (Fadjoin_poly K x v).[x] = v. Proof. move/(sumv_pi_sum Fadjoin_eq_sum)=> {2}<-; rewrite horner_poly. by apply: eq_bigr => i _; rewrite inord_val mulfVK. Qed. Lemma mempx_Fadjoin p : p \is a polyOver K -> p.[x] \in <<K; x>>%VS. Proof. move=> Kp; rewrite rpred_horner ?memv_adjoin ?(polyOverS _ Kp) //. exact: subvP_adjoin. Qed. Lemma Fadjoin_polyP {v} : reflect (exists2 p, p \in polyOver K & v = p.[x]) (v \in <<K; x>>%VS). Proof. apply: (iffP idP) => [Kx_v | [p Kp ->]]; last exact: mempx_Fadjoin. by exists (Fadjoin_poly K x v); rewrite ?Fadjoin_polyOver ?Fadjoin_poly_eq. Qed. Lemma Fadjoin_poly_unique p v : p \is a polyOver K -> size p <= n -> p.[x] = v -> Fadjoin_poly K x v = p. Proof. have polyKx q i: q \is a polyOver K -> q`_i * x ^+ i \in (K * <[x ^+ i]>)%VS. by move/polyOverP=> Kq; rewrite memv_mul ?Kq ?memv_line. move=> Kp szp Dv; have /Fadjoin_poly_eq/eqP := mempx_Fadjoin Kp. rewrite {1}Dv {Dv} !(@horner_coef_wide _ n) ?size_poly //. move/polyKx in Kp; have /polyKx K_pv := Fadjoin_polyOver K x v. rewrite (directv_sum_unique Fadjoin_sum_direct) // => /eqfunP eq_pq. apply/polyP=> i; have [leni|?] := leqP n i; last exact: mulIf (eq_pq (Sub i _)). by rewrite !nth_default ?(leq_trans _ leni) ?size_poly. Qed. Lemma Fadjoin_polyC v : v \in K -> Fadjoin_poly K x v = v%:P. Proof. move=> Kv; apply: Fadjoin_poly_unique; rewrite ?polyOverC ?hornerC //. by rewrite size_polyC (leq_trans (leq_b1 _)). Qed. Lemma Fadjoin_polyX : x \notin K -> Fadjoin_poly K x x = 'X. Proof. move=> K'x; apply: Fadjoin_poly_unique; rewrite ?polyOverX ?hornerX //. by rewrite size_polyX ltn_neqAle andbT eq_sym adjoin_deg_eq1. Qed. Lemma minPolyOver : minPoly K x \is a polyOver K. Proof. by rewrite /minPoly rpredB ?rpredX ?polyOverX ?Fadjoin_polyOver. Qed. Lemma minPolyxx : (minPoly K x).[x] = 0. Proof. by rewrite !hornerE Fadjoin_poly_eq ?subrr ?rpredX ?memv_adjoin. Qed. Lemma root_minPoly : root (minPoly K x) x. Proof. exact/rootP/minPolyxx. Qed. Lemma Fadjoin_poly_mod p : p \is a polyOver K -> Fadjoin_poly K x p.[x] = p %% minPoly K x. Proof. move=> Kp; rewrite {1}(divp_eq p (minPoly K x)) 2!hornerE minPolyxx mulr0 add0r. apply: Fadjoin_poly_unique => //; first by rewrite modp_polyOver // minPolyOver. by rewrite -ltnS -size_minPoly ltn_modp // monic_neq0 ?monic_minPoly. Qed. Lemma minPoly_XsubC : reflect (minPoly K x = 'X - x%:P) (x \in K). Proof. set p := minPoly K x; apply: (iffP idP) => [Kx | Dp]; last first. suffices ->: x = - p`_0 by rewrite rpredN (polyOverP minPolyOver). by rewrite Dp coefB coefX coefC add0r opprK. rewrite (@all_roots_prod_XsubC _ p [:: x]) /= ?root_minPoly //. by rewrite big_seq1 (monicP (monic_minPoly K x)) scale1r. by apply/eqP; rewrite size_minPoly eqSS adjoin_deg_eq1. Qed. Lemma root_small_adjoin_poly p : p \is a polyOver K -> size p <= n -> root p x = (p == 0). Proof. move=> Kp szp; apply/rootP/eqP=> [px0 | ->]; last by rewrite horner0. rewrite -(Fadjoin_poly_unique Kp szp px0). by apply: Fadjoin_poly_unique; rewrite ?polyOver0 ?size_poly0 ?horner0. Qed. Lemma minPoly_irr p : p \is a polyOver K -> p %| minPoly K x -> (p %= minPoly K x) || (p %= 1). Proof. rewrite dvdp_eq; set q := _ %/ _ => Kp def_pq. have Kq: q \is a polyOver K by rewrite divp_polyOver // minPolyOver. move: q Kq def_pq root_minPoly (size_minPoly K x) => q Kq /eqP->. rewrite rootM => pqx0 szpq. have [nzq nzp]: q != 0 /\ p != 0. by apply/norP; rewrite -mulf_eq0 -size_poly_eq0 szpq. without loss{pqx0} qx0: q p Kp Kq nzp nzq szpq / root q x. move=> IH; case/orP: pqx0 => /IH{}IH; first exact: IH. have{IH} /orP[]: (q %= p * q) || (q %= 1) by apply: IH => //; rewrite mulrC. by rewrite orbC -{1}[q]mul1r eqp_mul2r // eqp_sym => ->. by rewrite -{1}[p]mul1r eqp_sym eqp_mul2r // => ->. apply/orP; right; rewrite -size_poly_eq1 eqn_leq lt0n size_poly_eq0 nzp andbT. rewrite -(leq_add2r (size q)) -leq_subLR subn1 -size_mul // mulrC szpq. by rewrite ltnNge; apply: contra nzq => /(root_small_adjoin_poly Kq) <-. Qed. Lemma minPoly_dvdp p : p \is a polyOver K -> root p x -> (minPoly K x) %| p. Proof. move=> Kp rootp. have gcdK : gcdp (minPoly K x) p \is a polyOver K. by rewrite gcdp_polyOver ?minPolyOver. have /orP[gcd_eqK|gcd_eq1] := minPoly_irr gcdK (dvdp_gcdl (minPoly K x) p). by rewrite -(eqp_dvdl _ gcd_eqK) dvdp_gcdr. case/negP: (root1 x). by rewrite -(eqp_root gcd_eq1) root_gcd rootp root_minPoly. Qed. End FadjoinPoly. Lemma minPolyS K E a : (K <= E)%VS -> minPoly E a %| minPoly K a. Proof. move=> sKE; apply: minPoly_dvdp; last exact: root_minPoly. by apply: (polyOverSv sKE); rewrite minPolyOver. Qed. Arguments Fadjoin_polyP {K x v}. Lemma Fadjoin1_polyP x v : reflect (exists p, v = (map_poly (in_alg L) p).[x]) (v \in <<1; x>>%VS). Proof. apply: (iffP Fadjoin_polyP) => [[_ /polyOver1P]|] [p ->]; first by exists p. by exists (map_poly (in_alg L) p) => //; apply: alg_polyOver. Qed. Section Horner. Variables z : L. Definition fieldExt_horner := horner_morph (fun x => mulrC z (in_alg L x)). HB.instance Definition _ := GRing.RMorphism.on fieldExt_horner. Lemma fieldExt_hornerC b : fieldExt_horner b%:P = b%:A. Proof. exact: horner_morphC. Qed. Lemma fieldExt_hornerX : fieldExt_horner 'X = z. Proof. exact: horner_morphX. Qed. Fact fieldExt_hornerZ : scalable fieldExt_horner. Proof. move=> a p; rewrite -mul_polyC rmorphM /= fieldExt_hornerC. by rewrite -scalerAl mul1r. Qed. HB.instance Definition _ := GRing.isScalable.Build F0 {poly F0} L *:%R fieldExt_horner fieldExt_hornerZ. End Horner. End FieldExtTheory. Notation "E :&: F" := (capv_aspace E F) : aspace_scope. Notation "'C_ E [ x ]" := (capv_aspace E 'C[x]) : aspace_scope. Notation "'C_ ( E ) [ x ]" := (capv_aspace E 'C[x]) (only parsing) : aspace_scope. Notation "'C_ E ( V )" := (capv_aspace E 'C(V)) : aspace_scope. Notation "'C_ ( E ) ( V )" := (capv_aspace E 'C(V)) (only parsing) : aspace_scope. Notation "E * F" := (prodv_aspace E F) : aspace_scope. Notation "f @: E" := (aimg_aspace f E) : aspace_scope. Arguments Fadjoin_idP {F0 L K x}. Arguments FadjoinP {F0 L K x E}. Arguments Fadjoin_seqP {F0 L K rs E}. Arguments polyOver_subvs {F0 L K p}. Arguments Fadjoin_polyP {F0 L K x v}. Arguments Fadjoin1_polyP {F0 L x v}. Arguments minPoly_XsubC {F0 L K x}. Section MapMinPoly. Variables (F0 : fieldType) (L rL : fieldExtType F0) (f : 'AHom(L, rL)). Variables (K : {subfield L}) (x : L). Lemma adjoin_degree_aimg : adjoin_degree (f @: K) (f x) = adjoin_degree K x. Proof. rewrite !adjoin_degreeE -aimg_adjoin. by rewrite !limg_dim_eq ?(eqP (AHom_lker0 f)) ?capv0. Qed. Lemma map_minPoly : map_poly f (minPoly K x) = minPoly (f @: K) (f x). Proof. set fp := minPoly (f @: K) (f x). have [p Kp Dp]: exists2 p, p \is a polyOver K & map_poly f p = fp. have Kfp: fp \is a polyOver (f @: K)%VS by apply: minPolyOver. exists (map_poly f^-1%VF fp). apply/polyOver_poly=> j _; have /memv_imgP[y Ky ->] := polyOverP Kfp j. by rewrite lker0_lfunK ?AHom_lker0. rewrite -map_poly_comp map_poly_id // => _ /(allP Kfp)/memv_imgP[y _ ->]. by rewrite /= limg_lfunVK ?memv_img ?memvf. apply/eqP; rewrite -eqp_monic ?monic_map ?monic_minPoly // -Dp eqp_map. have: ~~ (p %= 1) by rewrite -size_poly_eq1 -(size_map_poly f) Dp size_minPoly. apply: implyP; rewrite implyNb orbC eqp_sym minPoly_irr //. rewrite -(dvdp_map f) Dp minPoly_dvdp ?fmorph_root ?root_minPoly //. by apply/polyOver_poly=> j _; apply/memv_img/polyOverP/minPolyOver. Qed. End MapMinPoly. (* Changing up the reference field of a fieldExtType. *) Section FieldOver. Variables (F0 : fieldType) (L : fieldExtType F0) (F : {subfield L}). Definition fieldOver of {vspace L} : Type := L. Local Notation K_F := (subvs_of F). Local Notation L_F := (fieldOver F). HB.instance Definition _ := GRing.Field.on L_F. Definition fieldOver_scale (a : K_F) (u : L_F) : L_F := vsval a * u. Local Infix "*F:" := fieldOver_scale (at level 40). Fact fieldOver_scaleA a b u : a *F: (b *F: u) = (a * b) *F: u. Proof. exact: mulrA. Qed. Fact fieldOver_scale1 u : 1 *F: u = u. Proof. by rewrite /(1 *F: u) /= algid1 mul1r. Qed. Fact fieldOver_scaleDr a u v : a *F: (u + v) = a *F: u + a *F: v. Proof. exact: mulrDr. Qed. Fact fieldOver_scaleDl v a b : (a + b) *F: v = a *F: v + b *F: v. Proof. exact: mulrDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ L_F fieldOver_scaleA fieldOver_scale1 fieldOver_scaleDr fieldOver_scaleDl. Lemma fieldOver_scaleE a (u : L) : a *: (u : L_F) = vsval a * u. Proof. by []. Qed. Fact fieldOver_scaleAl a u v : a *F: (u * v) = (a *F: u) * v. Proof. exact: mulrA. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ L_F fieldOver_scaleAl. Fact fieldOver_scaleAr a u v : a *F: (u * v) = u * (a *F: v). Proof. exact: mulrCA. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ L_F fieldOver_scaleAr. Fact fieldOver_vectMixin : Lmodule_hasFinDim K_F L_F. Proof. have [bL [_ nz_bL] [defL dxSbL]] := field_module_semisimple (subvf (F * _)). do [set n := \dim_F {:L} in bL nz_bL *; set SbL := (\sum_i _)%VS] in defL dxSbL. have in_bL i (a : K_F) : val a * (bL`_i : L_F) \in (F * <[bL`_i]>)%VS. by rewrite memv_mul ?(valP a) ?memv_line. have nz_bLi (i : 'I_n): bL`_i != 0 by rewrite (memPn nz_bL) ?memt_nth. pose r2v (v : 'rV[K_F]_n) : L_F := \sum_i v 0 i *: (bL`_i : L_F). have r2v_lin: linear r2v. move=> a u v; rewrite /r2v scaler_sumr -big_split /=; apply: eq_bigr => i _. by rewrite scalerA -scalerDl !mxE. pose r2vlM := GRing.isLinear.Build _ _ _ _ r2v r2v_lin. pose r2vL : {linear _ -> _} := HB.pack r2v r2vlM. have v2rP x: {r : 'rV[K_F]_n | x = r2v r}. apply: sig_eqW; have /memv_sumP[y Fy ->]: x \in SbL by rewrite defL memvf. have /fin_all_exists[r Dr] i: exists r, y i = r *: (bL`_i : L_F). by have /memv_cosetP[a Fa ->] := Fy i isT; exists (Subvs Fa). by exists (\row_i r i); apply: eq_bigr => i _; rewrite mxE. pose v2r x := sval (v2rP x). have v2rK: cancel v2r r2vL by rewrite /v2r => x; case: (v2rP x). suffices r2vK: cancel r2v v2r. by exists n, v2r; [apply: can2_linear v2rK | exists r2v]. move=> r; apply/rowP=> i; apply/val_inj/(mulIf (nz_bLi i))/eqP; move: i isT. by apply/forall_inP; move/directv_sum_unique: dxSbL => <- //; apply/eqP/v2rK. Qed. HB.instance Definition _ := fieldOver_vectMixin. Implicit Types (V : {vspace L}) (E : {subfield L}). Lemma trivial_fieldOver : (1%VS : {vspace L_F}) =i F. Proof. move=> x; apply/vlineP/idP=> [[{}x ->] | Fx]. by rewrite fieldOver_scaleE mulr1 (valP x). by exists (vsproj F x); rewrite fieldOver_scaleE mulr1 vsprojK. Qed. Definition vspaceOver V := <<vbasis V : seq L_F>>%VS. Lemma mem_vspaceOver V : vspaceOver V =i (F * V)%VS. Proof. move=> y; apply/idP/idP; last rewrite unlock; move/coord_span->. rewrite (@memv_suml F0 L) // => i _. by rewrite memv_mul ?subvsP // vbasis_mem ?memt_nth. rewrite memv_suml // => ij _; rewrite -tnth_nth; set x := tnth _ ij. have/allpairsP[[u z] /= [Fu Vz {x}->]]: x \in _ := mem_tnth ij _. by rewrite scalerAl (memvZ (Subvs _)) ?memvZ ?memv_span //= vbasis_mem. Qed. Lemma mem_aspaceOver E : (F <= E)%VS -> vspaceOver E =i E. Proof. by move=> sFE y; rewrite mem_vspaceOver field_module_eq ?sup_field_module. Qed. Fact aspaceOver_suproof E : is_aspace (vspaceOver E). Proof. rewrite /is_aspace has_algid1; last by rewrite mem_vspaceOver (@mem1v _ L). by apply/prodvP=> u v; rewrite !mem_vspaceOver; apply: memvM. Qed. Canonical aspaceOver E := ASpace (aspaceOver_suproof E). Lemma dim_vspaceOver M : (F * M <= M)%VS -> \dim (vspaceOver M) = \dim_F M. Proof. move=> modM; have [] := field_module_semisimple modM. set n := \dim_F M => b [Mb nz_b] [defM dx_b]. suff: basis_of (vspaceOver M) b by apply: size_basis. apply/andP; split. rewrite eqEsubv; apply/andP; split; apply/span_subvP=> u. by rewrite mem_vspaceOver field_module_eq // => /Mb. move/(@vbasis_mem _ _ _ M); rewrite -defM => /memv_sumP[{}u Fu ->]. apply: memv_suml => i _; have /memv_cosetP[a Fa ->] := Fu i isT. by apply: (memvZ (Subvs Fa)); rewrite memv_span ?memt_nth. apply/freeP=> a /(directv_sum_independent dx_b) a_0 i. have{a_0}: a i *: (b`_i : L_F) == 0. by rewrite a_0 {i}// => i _; rewrite memv_mul ?memv_line ?subvsP. by rewrite scaler_eq0=> /predU1P[] // /idPn[]; rewrite (memPn nz_b) ?memt_nth. Qed. Lemma dim_aspaceOver E : (F <= E)%VS -> \dim (vspaceOver E) = \dim_F E. Proof. by rewrite -sup_field_module; apply: dim_vspaceOver. Qed. Lemma vspaceOverP V_F : {V | [/\ V_F = vspaceOver V, (F * V <= V)%VS & V_F =i V]}. Proof. pose V := (F * <<vbasis V_F : seq L>>)%VS. have idV: (F * V)%VS = V by rewrite prodvA prodv_id. suffices defVF: V_F = vspaceOver V. by exists V; split=> [||u]; rewrite ?defVF ?mem_vspaceOver ?idV. apply/vspaceP=> v; rewrite mem_vspaceOver idV. do [apply/idP/idP; last rewrite /V unlock] => [/coord_vbasis|/coord_span] ->. by apply: memv_suml => i _; rewrite memv_mul ?subvsP ?memv_span ?memt_nth. apply: memv_suml => i _; rewrite -tnth_nth; set xu := tnth _ i. have /allpairsP[[x u] /=]: xu \in _ := mem_tnth i _. case=> /vbasis_mem Fx /vbasis_mem Vu ->. rewrite scalerAl (coord_span Vu) mulr_sumr memv_suml // => j_. by rewrite -scalerCA (memvZ (Subvs _)) ?memvZ // vbasis_mem ?memt_nth. Qed. Lemma aspaceOverP (E_F : {subfield L_F}) : {E | [/\ E_F = aspaceOver E, (F <= E)%VS & E_F =i E]}. Proof. have [V [defEF modV memV]] := vspaceOverP E_F. have algE: has_algid V && (V * V <= V)%VS. rewrite has_algid1; last by rewrite -memV mem1v. by apply/prodvP=> u v; rewrite -!memV; apply: memvM. by exists (ASpace algE); rewrite -sup_field_module; split; first apply: val_inj. Qed. End FieldOver. (* Changing the reference field to a smaller field. *) Section BaseField. Variables (F0 : fieldType) (F : fieldExtType F0) (L : fieldExtType F). Definition baseFieldType : Type := L. Notation L0 := baseFieldType. HB.instance Definition _ := GRing.Field.on L0. Definition baseField_scale (a : F0) (u : L0) : L0 := in_alg F a *: u. Local Infix "*F0:" := baseField_scale (at level 40). Fact baseField_scaleA a b u : a *F0: (b *F0: u) = (a * b) *F0: u. Proof. by rewrite [_ *F0: _]scalerA -rmorphM. Qed. Fact baseField_scale1 u : 1 *F0: u = u. Proof. by rewrite /(1 *F0: u) rmorph1 scale1r. Qed. Fact baseField_scaleDr a u v : a *F0: (u + v) = a *F0: u + a *F0: v. Proof. exact: scalerDr. Qed. Fact baseField_scaleDl v a b : (a + b) *F0: v = a *F0: v + b *F0: v. Proof. by rewrite -scalerDl -rmorphD. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ L0 baseField_scaleA baseField_scale1 baseField_scaleDr baseField_scaleDl. Lemma baseField_scaleE a (u : L) : a *: (u : L0) = a%:A *: u. Proof. by []. Qed. Fact baseField_scaleAl a (u v : L0) : a *F0: (u * v) = (a *F0: u) * v. Proof. exact: scalerAl. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ L0 baseField_scaleAl. Fact baseField_scaleAr a u v : a *F0: (u * v) = u * (a *F0: v). Proof. exact: scalerAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ L0 baseField_scaleAr. Let n := \dim {:F}. Let bF : n.-tuple F := vbasis {:F}. Let coordF (x : F) := (coord_vbasis (memvf x)). Fact baseField_vectMixin : Lmodule_hasFinDim F0 L0. Proof. pose bL := vbasis {:L}; set m := \dim {:L} in bL. pose v2r (x : L0) := mxvec (\matrix_(i, j) coord bF j (coord bL i x)). have v2r_lin: linear v2r. move=> a x y; rewrite -linearP; congr mxvec; apply/matrixP=> i j. by rewrite !mxE linearP /= mulr_algl linearP. pose r2v r := \sum_(i < m) (\sum_(j < n) vec_mx r i j *: bF`_j) *: bL`_i. have v2rK: cancel v2r r2v. move=> x; transitivity (\sum_(i < m) coord bL i x *: bL`_i); last first. by rewrite -coord_vbasis ?memvf. (* GG: rewrite {2}(coord_vbasis (memvf x)) -/m would take 8s; *) (* The -/m takes 8s, and without it then apply: eq_bigr takes 12s. *) (* The time drops to 2s with a -[GRing.Field.ringType F]/(F : fieldType) *) apply: eq_bigr => i _; rewrite mxvecK; congr (_ *: _ : L). by rewrite (coordF (coord bL i x)); apply: eq_bigr => j _; rewrite mxE. exists (m * n)%N, v2r => //; exists r2v => // r. apply: (canLR vec_mxK); apply/matrixP=> i j; rewrite mxE. by rewrite !coord_sum_free ?(basis_free (vbasisP _)). Qed. HB.instance Definition _ := baseField_vectMixin. Let F0ZEZ a x v : a *: ((x *: v : L) : L0) = (a *: x) *: v. Proof. by rewrite [a *: _]scalerA -scalerAl mul1r. Qed. Let baseVspace_basis V : seq L0 := [seq tnth bF ij.2 *: tnth (vbasis V) ij.1 | ij : 'I_(\dim V) * 'I_n]. Definition baseVspace V := <<baseVspace_basis V>>%VS. Lemma mem_baseVspace V : baseVspace V =i V. Proof. move=> y; apply/idP/idP=> [/coord_span->|/coord_vbasis->]; last first. apply: memv_suml => i _; rewrite (coordF (coord _ i (y : L))) scaler_suml -/n. apply: memv_suml => j _; rewrite -/bF -F0ZEZ memvZ ?memv_span // -!tnth_nth. by apply/imageP; exists (i, j). (* GG: the F0ZEZ lemma avoids serious performance issues here. *) apply: memv_suml => k _; rewrite nth_image; case: (enum_val k) => i j /=. by rewrite F0ZEZ memvZ ?vbasis_mem ?mem_tnth. Qed. Lemma dim_baseVspace V : \dim (baseVspace V) = (\dim V * n)%N. Proof. pose bV0 := baseVspace_basis V; set m := \dim V in bV0 *. suffices /size_basis->: basis_of (baseVspace V) bV0. by rewrite card_prod !card_ord. rewrite /basis_of eqxx. apply/freeP=> s sb0 k; rewrite -(enum_valK k); case/enum_val: k => i j. have free_baseP := freeP (basis_free (vbasisP _)). move: j; apply: (free_baseP _ _ fullv); move: i; apply: (free_baseP _ _ V). transitivity (\sum_i \sum_j s (enum_rank (i, j)) *: bV0`_(enum_rank (i, j))). apply: eq_bigr => i _; rewrite scaler_suml; apply: eq_bigr => j _. by rewrite -F0ZEZ nth_image enum_rankK -!tnth_nth. rewrite pair_bigA (reindex _ (onW_bij _ (enum_val_bij _))); apply: etrans sb0. by apply: eq_bigr => k _; rewrite -{5 6}[k](enum_valK k); case/enum_val: k. Qed. Fact baseAspace_suproof (E : {subfield L}) : is_aspace (baseVspace E). Proof. rewrite /is_aspace has_algid1; last by rewrite mem_baseVspace (mem1v E). by apply/prodvP=> u v; rewrite !mem_baseVspace; apply: memvM. Qed. Canonical baseAspace E := ASpace (baseAspace_suproof E). End BaseField. Arguments baseFieldType [F0 F]%_type L%_type. HB.lock Definition refBaseField (F0 : fieldType) (F : fieldExtType F0) (L : fieldExtType F) := baseAspace (1%AS : {aspace L}). Canonical refBaseField_unlockable := Unlockable refBaseField.unlock. Section RefBaseField. Variables (F0 : fieldType) (F : fieldExtType F0) (L : fieldExtType F). Notation F1 := (refBaseField L). Notation F1unlock := refBaseField.unlock. Notation L0 := (baseFieldType L). Let n := \dim {:F}. Let bF : n.-tuple F := vbasis {:F}. Let coordF (x : F) := (coord_vbasis (memvf x)). Lemma dim_refBaseField : \dim F1 = n. Proof. by rewrite F1unlock dim_baseVspace dimv1 mul1n. Qed. Lemma baseVspace_module V (V0 := baseVspace V) : (F1 * V0 <= V0)%VS. Proof. apply/prodvP=> u v; rewrite F1unlock !mem_baseVspace => /vlineP[x ->] Vv. by rewrite -(@scalerAl F L) mul1r; apply: memvZ. Qed. Lemma sub_baseField (E : {subfield L}) : (F1 <= baseVspace E)%VS. Proof. by rewrite -sup_field_module baseVspace_module. Qed. Lemma vspaceOver_refBase V : vspaceOver F1 (baseVspace V) =i V. Proof. move=> v; rewrite mem_vspaceOver field_module_eq ?baseVspace_module //. by rewrite mem_baseVspace. Qed. Lemma module_baseVspace M0 : (F1 * M0 <= M0)%VS -> {V | M0 = baseVspace V & M0 =i V}. Proof. move=> modM0; pose V := <<vbasis (vspaceOver F1 M0) : seq L>>%VS. suffices memM0: M0 =i V. by exists V => //; apply/vspaceP=> v; rewrite mem_baseVspace memM0. move=> v; rewrite -{1}(field_module_eq modM0) -(mem_vspaceOver M0) {}/V. move: (vspaceOver F1 M0) => M. apply/idP/idP=> [/coord_vbasis|/coord_span]->; apply/memv_suml=> i _. rewrite /(_ *: _) /= /fieldOver_scale; case: (coord _ i _) => /= x. rewrite {1}F1unlock mem_baseVspace => /vlineP[{}x ->]. by rewrite -(@scalerAl F L) mul1r memvZ ?memv_span ?memt_nth. move: (coord _ i _) => x; rewrite -[_`_i]mul1r scalerAl -tnth_nth. have F1x: x%:A \in F1. by rewrite F1unlock mem_baseVspace (@memvZ F L) // mem1v. by congr (_ \in M): (memvZ (Subvs F1x) (vbasis_mem (mem_tnth i _))). Qed. Lemma module_baseAspace (E0 : {subfield L0}) : (F1 <= E0)%VS -> {E | E0 = baseAspace E & E0 =i E}. Proof. rewrite -sup_field_module => /module_baseVspace[E defE0 memE0]. suffices algE: is_aspace E by exists (ASpace algE); first apply: val_inj. rewrite /is_aspace has_algid1 -?memE0 ?mem1v //. by apply/prodvP=> u v; rewrite -!memE0; apply: memvM. Qed. End RefBaseField. (* Base of fieldOver, finally. *) Section MoreFieldOver. Variables (F0 : fieldType) (L : fieldExtType F0) (F : {subfield L}). Lemma base_vspaceOver V : baseVspace (vspaceOver F V) =i (F * V)%VS. Proof. by move=> v; rewrite mem_baseVspace mem_vspaceOver. Qed. Lemma base_moduleOver V : (F * V <= V)%VS -> baseVspace (vspaceOver F V) =i V. Proof. by move=> /field_module_eq defV v; rewrite base_vspaceOver defV. Qed. Lemma base_aspaceOver (E : {subfield L}) : (F <= E)%VS -> baseVspace (vspaceOver F E) =i E. Proof. by rewrite -sup_field_module; apply: base_moduleOver. Qed. End MoreFieldOver. Section SubFieldExtension. Local Open Scope quotient_scope. Variables (F L : fieldType) (iota : {rmorphism F -> L}). Variables (z : L) (p : {poly F}). Local Notation "p ^iota" := (map_poly (GRing.RMorphism.sort iota) p) (format "p ^iota") : ring_scope. Let wf_p := (p != 0) && root p^iota z. Let p0 : {poly F} := if wf_p then (lead_coef p)^-1 *: p else 'X. Let z0 := if wf_p then z else 0. Let n := (size p0).-1. Let p0_mon : p0 \is monic. Proof. rewrite /p0; case: ifP => [/andP[nz_p _] | _]; last exact: monicX. by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0. Qed. Let nz_p0 : p0 != 0. Proof. by rewrite monic_neq0 // p0_mon. Qed. Let p0z0 : root p0^iota z0. Proof. rewrite /p0 /z0; case: ifP => [/andP[_ pz0]|]; last by rewrite map_polyX rootX. by rewrite map_polyZ rootE hornerZ (rootP pz0) mulr0. Qed. Let n_gt0: 0 < n. Proof. rewrite /n -subn1 subn_gt0 -(size_map_poly iota). by rewrite (root_size_gt1 _ p0z0) ?map_poly_eq0. Qed. Let z0Ciota : commr_rmorph iota z0. Proof. by move=> x; apply: mulrC. Qed. Local Notation iotaPz := (horner_morph z0Ciota). Let iotaFz (x : 'rV[F]_n) := iotaPz (rVpoly x). Definition equiv_subfext x y := (iotaFz x == iotaFz y). Fact equiv_subfext_is_equiv : equiv_class_of equiv_subfext. Proof. by rewrite /equiv_subfext; split=> x // y w /eqP->. Qed. Canonical equiv_subfext_equiv := EquivRelPack equiv_subfext_is_equiv. Canonical equiv_subfext_encModRel := defaultEncModRel equiv_subfext. Definition subFExtend := {eq_quot equiv_subfext}. HB.instance Definition _ := Choice.on subFExtend. HB.instance Definition _ := Quotient.on subFExtend. HB.instance Definition _ : EqQuotient 'M[F]_(1, n) equiv_subfext subFExtend := EqQuotient.on subFExtend. Definition subfx_inj := lift_fun1 subFExtend iotaFz. Fact pi_subfx_inj : {mono \pi : x / iotaFz x >-> subfx_inj x}. Proof. unlock subfx_inj => x; apply/eqP; rewrite -/(equiv_subfext _ x). by rewrite -eqmodE reprK. Qed. Canonical pi_subfx_inj_morph := PiMono1 pi_subfx_inj. Let iotaPz_repr x : iotaPz (rVpoly (repr (\pi_(subFExtend) x))) = iotaFz x. Proof. by rewrite -/(iotaFz _) -!pi_subfx_inj reprK. Qed. Definition subfext0 := lift_cst subFExtend 0. Canonical subfext0_morph := PiConst subfext0. Definition subfext_add := lift_op2 subFExtend +%R. Fact pi_subfext_add : {morph \pi : x y / x + y >-> subfext_add x y}. Proof. unlock subfext_add => x y /=; apply/eqmodP/eqP. by rewrite /iotaFz !linearD /= !iotaPz_repr. Qed. Canonical pi_subfx_add_morph := PiMorph2 pi_subfext_add. Definition subfext_opp := lift_op1 subFExtend -%R. Fact pi_subfext_opp : {morph \pi : x / - x >-> subfext_opp x}. Proof. unlock subfext_opp => y /=; apply/eqmodP/eqP. by rewrite /iotaFz !linearN /= !iotaPz_repr. Qed. Canonical pi_subfext_opp_morph := PiMorph1 pi_subfext_opp. Fact addfxA : associative subfext_add. Proof. by move=> x y t; rewrite -[x]reprK -[y]reprK -[t]reprK !piE addrA. Qed. Fact addfxC : commutative subfext_add. Proof. by move=> x y; rewrite -[x]reprK -[y]reprK !piE addrC. Qed. Fact add0fx : left_id subfext0 subfext_add. Proof. by move=> x; rewrite -[x]reprK !piE add0r. Qed. Fact addfxN : left_inverse subfext0 subfext_opp subfext_add. Proof. by move=> x; rewrite -[x]reprK !piE addNr. Qed. HB.instance Definition _ := GRing.isZmodule.Build subFExtend addfxA addfxC add0fx addfxN. Let poly_rV_modp_K q : rVpoly (poly_rV (q %% p0) : 'rV[F]_n) = q %% p0. Proof. by apply: poly_rV_K; rewrite -ltnS -polySpred // ltn_modp. Qed. Let iotaPz_modp q : iotaPz (q %% p0) = iotaPz q. Proof. rewrite {2}(divp_eq q p0) rmorphD rmorphM /=. by rewrite [iotaPz p0](rootP p0z0) mulr0 add0r. Qed. Definition subfx_mul_rep (x y : 'rV[F]_n) : 'rV[F]_n := poly_rV ((rVpoly x) * (rVpoly y) %% p0). Definition subfext_mul := lift_op2 subFExtend subfx_mul_rep. Fact pi_subfext_mul : {morph \pi : x y / subfx_mul_rep x y >-> subfext_mul x y}. Proof. unlock subfext_mul => x y /=; apply/eqmodP/eqP. by rewrite /iotaFz !poly_rV_modp_K !iotaPz_modp !rmorphM /= !iotaPz_repr. Qed. Canonical pi_subfext_mul_morph := PiMorph2 pi_subfext_mul. Definition subfext1 := lift_cst subFExtend (poly_rV 1). Canonical subfext1_morph := PiConst subfext1. Fact mulfxA : associative (subfext_mul). Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> w; rewrite !piE /subfx_mul_rep. by rewrite !poly_rV_modp_K [_ %% p0 * _]mulrC !modp_mul // mulrA mulrC. Qed. Fact mulfxC : commutative subfext_mul. Proof. by elim/quotW=> x; elim/quotW=> y; rewrite !piE /subfx_mul_rep /= mulrC. Qed. Fact mul1fx : left_id subfext1 subfext_mul. Proof. elim/quotW=> x; rewrite !piE /subfx_mul_rep poly_rV_K ?size_poly1 // mul1r. by rewrite modp_small ?rVpolyK // (polySpred nz_p0) ltnS size_poly. Qed. Fact mulfx_addl : left_distributive subfext_mul subfext_add. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> w. by rewrite !piE /subfx_mul_rep linearD /= mulrDl modpD linearD. Qed. Fact nonzero1fx : subfext1 != subfext0. Proof. rewrite !piE /equiv_subfext /iotaFz !linear0. by rewrite poly_rV_K ?rmorph1 ?oner_eq0 // size_poly1. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build subFExtend mulfxA mulfxC mul1fx mulfx_addl nonzero1fx. Definition subfx_poly_inv (q : {poly F}) : {poly F} := if iotaPz q == 0 then 0 else let r := gdcop q p0 in let: (u, v) := egcdp q r in ((u * q + v * r)`_0)^-1 *: u. Let subfx_poly_invE q : iotaPz (subfx_poly_inv q) = (iotaPz q)^-1. Proof. rewrite /subfx_poly_inv. have [-> | nzq] := eqVneq; first by rewrite rmorph0 invr0. rewrite [nth]lock -[_^-1]mul1r; apply: canRL (mulfK nzq) _; rewrite -rmorphM /=. have rz0: iotaPz (gdcop q p0) = 0. by apply/rootP; rewrite gdcop_map root_gdco ?map_poly_eq0 // p0z0 nzq. do [case: gdcopP => r _; rewrite (negPf nz_p0) orbF => co_r_q _] in rz0 *. case: (egcdp q r) (egcdpE q r) => u v /=/eqp_size/esym/eqP. rewrite coprimep_size_gcd 1?coprimep_sym // => /size_poly1P[a nz_a Da]. rewrite Da -scalerAl (canRL (addrK _) Da) -lock coefC linearZ linearB /=. by rewrite rmorphM /= rz0 mulr0 subr0 horner_morphC -rmorphM mulVf ?rmorph1. Qed. Definition subfx_inv_rep (x : 'rV[F]_n) : 'rV[F]_n := poly_rV (subfx_poly_inv (rVpoly x) %% p0). Definition subfext_inv := lift_op1 subFExtend subfx_inv_rep. Fact pi_subfext_inv : {morph \pi : x / subfx_inv_rep x >-> subfext_inv x}. Proof. unlock subfext_inv => x /=; apply/eqmodP/eqP; rewrite /iotaFz. by rewrite 2!{1}poly_rV_modp_K 2!{1}iotaPz_modp !subfx_poly_invE iotaPz_repr. Qed. Canonical pi_subfext_inv_morph := PiMorph1 pi_subfext_inv. Fact subfx_fieldAxiom : forall x, x != 0 -> subfext_inv x * x = 1. Proof. elim/quotW=> x; apply: contraNeq; rewrite !piE /equiv_subfext /iotaFz !linear0. apply: contraR => nz_x; rewrite poly_rV_K ?size_poly1 // !poly_rV_modp_K. by rewrite iotaPz_modp rmorph1 rmorphM /= iotaPz_modp subfx_poly_invE mulVf. Qed. Fact subfx_inv0 : subfext_inv (0 : subFExtend) = (0 : subFExtend). Proof. apply/eqP; rewrite !piE /equiv_subfext /iotaFz /subfx_inv_rep !linear0. by rewrite /subfx_poly_inv rmorph0 eqxx mod0p !linear0. Qed. HB.instance Definition _ := GRing.ComNzRing_isField.Build subFExtend subfx_fieldAxiom subfx_inv0. Fact subfx_inj_is_zmod_morphism : zmod_morphism subfx_inj. Proof. by elim/quotW => x; elim/quotW => y; rewrite !piE /iotaFz linearB rmorphB. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `subfx_inj_is_zmod_morphism` instead")] Definition subfx_inj_is_additive := subfx_inj_is_zmod_morphism. Fact subfx_inj_is_monoid_morphism : monoid_morphism subfx_inj. Proof. split; first by rewrite piE /iotaFz poly_rV_K ?rmorph1 ?size_poly1. elim/quotW=> x; elim/quotW=> y; rewrite !piE /subfx_mul_rep /iotaFz. by rewrite poly_rV_modp_K iotaPz_modp rmorphM. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `subfx_inj_is_monoid_morphism` instead")] Definition subfx_inj_is_multiplicative := (fun g => (g.2,g.1)) subfx_inj_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build subFExtend L subfx_inj subfx_inj_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build subFExtend L subfx_inj subfx_inj_is_monoid_morphism. Definition subfx_eval := lift_embed subFExtend (fun q => poly_rV (q %% p0)). Canonical subfx_eval_morph := PiEmbed subfx_eval. Definition subfx_root := subfx_eval 'X. Lemma subfx_eval_is_zmod_morphism : zmod_morphism subfx_eval. Proof. by move=> x y; apply/eqP; rewrite piE -linearB modpD modNp. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `subfx_eval_is_zmod_morphism` instead")] Definition subfx_eval_is_additive := subfx_eval_is_zmod_morphism. Lemma subfx_eval_is_monoid_morphism : monoid_morphism subfx_eval. Proof. split=> [|x y]; apply/eqP; rewrite piE. by rewrite modp_small // size_poly1 -subn_gt0 subn1. by rewrite /subfx_mul_rep !poly_rV_modp_K !(modp_mul, mulrC _ y). Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `subfx_eval_is_monoid_morphism` instead")] Definition subfx_eval_is_multiplicative := (fun g => (g.2,g.1)) subfx_eval_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build {poly F} subFExtend subfx_eval subfx_eval_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly F} subFExtend subfx_eval subfx_eval_is_monoid_morphism. Definition inj_subfx := (subfx_eval \o polyC). HB.instance Definition _ := GRing.RMorphism.on inj_subfx. Lemma subfxE x: exists p, x = subfx_eval p. Proof. elim/quotW: x => x; exists (rVpoly x); apply/eqP; rewrite piE /equiv_subfext. by rewrite /iotaFz poly_rV_modp_K iotaPz_modp. Qed. Definition subfx_scale a x := inj_subfx a * x. Fact subfx_scalerA a b x : subfx_scale a (subfx_scale b x) = subfx_scale (a * b) x. Proof. by rewrite /subfx_scale rmorphM mulrA. Qed. Fact subfx_scaler1r : left_id 1 subfx_scale. Proof. by move=> x; rewrite /subfx_scale rmorph1 mul1r. Qed. Fact subfx_scalerDr : right_distributive subfx_scale +%R. Proof. by move=> a; apply: mulrDr. Qed. Fact subfx_scalerDl x : {morph subfx_scale^~ x : a b / a + b}. Proof. by move=> a b; rewrite /subfx_scale rmorphD mulrDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ subFExtend subfx_scalerA subfx_scaler1r subfx_scalerDr subfx_scalerDl. Fact subfx_scaleAl a u v : subfx_scale a (u * v) = (subfx_scale a u) * v. Proof. exact: mulrA. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ subFExtend subfx_scaleAl. Fact subfx_scaleAr a u v : subfx_scale a (u * v) = u * (subfx_scale a v). Proof. exact: mulrCA. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ subFExtend subfx_scaleAr. Fact subfx_evalZ : scalable subfx_eval. Proof. by move=> a q; rewrite -mul_polyC rmorphM. Qed. HB.instance Definition _ := GRing.isScalable.Build F {poly F} subFExtend *:%R subfx_eval subfx_evalZ. Hypothesis (pz0 : root p^iota z). Section NonZero. Hypothesis nz_p : p != 0. Lemma subfx_inj_eval q : subfx_inj (subfx_eval q) = (q^iota).[z]. Proof. by rewrite piE /iotaFz poly_rV_modp_K iotaPz_modp /iotaPz /z0 /wf_p nz_p pz0. Qed. Lemma subfx_inj_root : subfx_inj subfx_root = z. Proof. by rewrite subfx_inj_eval // map_polyX hornerX. Qed. Lemma subfx_injZ b x : subfx_inj (b *: x) = iota b * subfx_inj x. Proof. by rewrite rmorphM /= subfx_inj_eval // map_polyC hornerC. Qed. Lemma subfx_inj_base b : subfx_inj b%:A = iota b. Proof. by rewrite subfx_injZ rmorph1 mulr1. Qed. Lemma subfxEroot x : {q | x = (map_poly (in_alg subFExtend) q).[subfx_root]}. Proof. have /sig_eqW[q ->] := subfxE x; exists q. apply: (fmorph_inj subfx_inj). rewrite -horner_map /= subfx_inj_root subfx_inj_eval //. by rewrite -map_poly_comp (eq_map_poly subfx_inj_base). Qed. Lemma subfx_irreducibleP : (forall q, root q^iota z -> q != 0 -> size p <= size q) <-> irreducible_poly p. Proof. split=> [min_p | irr_p q qz0 nz_q]. split=> [|q nonC_q q_dv_p]. by rewrite -(size_map_poly iota) (root_size_gt1 _ pz0) ?map_poly_eq0. have /dvdpP[r Dp] := q_dv_p; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=. have [nz_r nz_q]: r != 0 /\ q != 0 by apply/norP; rewrite -mulf_eq0 -Dp. have: root r^iota z || root q^iota z by rewrite -rootM -rmorphM -Dp. case/orP=> /min_p; [case/(_ _)/idPn=> // | exact]. rewrite polySpred // -leqNgt Dp size_mul //= polySpred // -subn2 ltn_subRL. by rewrite addSnnS addnC ltn_add2l ltn_neqAle eq_sym nonC_q size_poly_gt0. pose r := gcdp p q; have nz_r: r != 0 by rewrite gcdp_eq0 (negPf nz_p). suffices /eqp_size <-: r %= p by rewrite dvdp_leq ?dvdp_gcdr. rewrite (irr_p _) ?dvdp_gcdl // -(size_map_poly iota) gtn_eqF //. by rewrite (@root_size_gt1 _ z) ?map_poly_eq0 // gcdp_map root_gcd pz0. Qed. End NonZero. Section Irreducible. Hypothesis irr_p : irreducible_poly p. Let nz_p : p != 0. Proof. exact: irredp_neq0. Qed. (* The Vector axiom requires irreducibility. *) Lemma min_subfx_vect : Vector.axiom (size p).-1 subFExtend. Proof. move/subfx_irreducibleP: irr_p => /=/(_ nz_p) min_p; set d := (size p).-1. have Dd: d.+1 = size p by rewrite polySpred. pose Fz2v x : 'rV_d := poly_rV (sval (sig_eqW (subfxE x)) %% p). pose vFz : 'rV_d -> subFExtend := subfx_eval \o rVpoly. have FLinj: injective subfx_inj by apply: fmorph_inj. have Fz2vK: cancel Fz2v vFz. move=> x; rewrite /vFz /Fz2v; case: (sig_eqW _) => /= q ->. apply: FLinj; rewrite !subfx_inj_eval // {2}(divp_eq q p) rmorphD rmorphM /=. by rewrite !hornerE (eqP pz0) mulr0 add0r poly_rV_K // -ltnS Dd ltn_modpN0. suffices vFzK: cancel vFz Fz2v. by exists Fz2v; [apply: can2_linear Fz2vK | exists vFz]. apply: inj_can_sym Fz2vK _ => v1 v2 /(congr1 subfx_inj)/eqP. rewrite -subr_eq0 -!raddfB /= subfx_inj_eval // => /min_p/implyP. rewrite leqNgt implybNN -Dd ltnS size_poly linearB subr_eq0 /=. by move/eqP/(can_inj rVpolyK). Qed. Definition SubfxVect := Lmodule_hasFinDim.Build _ subFExtend min_subfx_vect. Definition SubFieldExtType : fieldExtType F := HB.pack subFExtend SubfxVect. End Irreducible. End SubFieldExtension. Prenex Implicits subfx_inj. Lemma irredp_FAdjoin (F : fieldType) (p : {poly F}) : irreducible_poly p -> {L : fieldExtType F & \dim {:L} = (size p).-1 & {z | root (map_poly (in_alg L) p) z & <<1; z>>%VS = fullv}}. Proof. case=> p_gt1 irr_p; set n := (size p).-1; pose vL : vectType F := 'rV_n. have Dn: n.+1 = size p := ltn_predK p_gt1. have nz_p: p != 0 by rewrite -size_poly_eq0 -Dn. suffices [L dimL [toPF [toL toPF_K toL_K]]]: {L : fieldExtType F & \dim {:L} = (size p).-1 & {toPF : {linear L -> {poly F}} & {toL : {lrmorphism {poly F} -> L} | cancel toPF toL & forall q, toPF (toL q) = q %% p}}}. - exists L => //; pose z := toL 'X; set iota := in_alg _. suffices q_z q: toPF (map_poly iota q).[z] = q %% p. exists z; first by rewrite /root -(can_eq toPF_K) q_z modpp linear0. apply/vspaceP=> x; rewrite memvf; apply/Fadjoin_polyP. exists (map_poly iota (toPF x)). by apply/polyOverP=> i; rewrite coef_map memvZ ?mem1v. by apply: (can_inj toPF_K); rewrite q_z -toL_K toPF_K. elim/poly_ind: q => [|a q IHq]. by rewrite map_poly0 horner0 linear0 mod0p. rewrite rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC linearD /=. rewrite linearZ /= -(rmorph1 toL) toL_K -modpZl alg_polyC modpD. congr (_ + _); rewrite -toL_K rmorphM -/z; congr (toPF (_ * z)). by apply: (can_inj toPF_K); rewrite toL_K. pose toL q : vL := poly_rV (q %% p); pose toPF (x : vL) := rVpoly x. have toL_K q : toPF (toL q) = q %% p. by rewrite /toPF poly_rV_K // -ltnS Dn ?ltn_modp -?Dn. have toPF_K: cancel toPF toL. by move=> x; rewrite /toL modp_small ?rVpolyK // -Dn ltnS size_poly. have toPinj := can_inj toPF_K. pose mul x y := toL (toPF x * toPF y); pose L1 := toL 1. have L1K: toPF L1 = 1 by rewrite toL_K modp_small ?size_poly1. have mulC: commutative mul by rewrite /mul => x y; rewrite mulrC. have mulA: associative mul. by move=> x y z; apply: toPinj; rewrite -!(mulC z) !toL_K !modp_mul mulrCA. have mul1: left_id L1 mul. by move=> x; apply: toPinj; rewrite mulC !toL_K modp_mul mulr1 -toL_K toPF_K. have mulD: left_distributive mul +%R. move=> x y z; apply: toPinj; rewrite /toPF raddfD /= -!/(toPF _). by rewrite !toL_K /toPF raddfD mulrDl modpD. have nzL1: L1 != 0 by rewrite -(inj_eq toPinj) L1K /toPF raddf0 oner_eq0. pose mulM := GRing.Zmodule_isComNzRing.Build _ mulA mulC mul1 mulD nzL1. pose rL : comNzRingType := HB.pack vL mulM. have mulZlM : GRing.Lmodule_isLalgebra F rL. constructor => a x y; apply: toPinj. by rewrite toL_K /toPF !linearZ /= -!/(toPF _) toL_K -scalerAl modpZl. pose laL : lalgType F := HB.pack rL mulZlM. have mulZrM : GRing.Lalgebra_isAlgebra F laL. by constructor => a x y; rewrite !(mulrC x) scalerAl. pose aL : algType F := HB.pack laL mulZrM. pose uLM := Algebra_isFalgebra.Build F aL. pose cuL : comUnitRingType := HB.pack aL uLM. have unitM : GRing.ComUnitRing_isField cuL. constructor => x nz_x; apply/unitrP; set q := toPF x. have nz_q: q != 0 by rewrite -(inj_eq toPinj) /toPF raddf0 in nz_x. have /Bezout_eq1_coprimepP[u upq1]: coprimep p q. apply: contraLR (leq_gcdpr p nz_q) => /irr_p/implyP. rewrite dvdp_gcdl -ltnNge /= => /eqp_size->. by rewrite (polySpred nz_p) ltnS size_poly. suffices: x * toL u.2 = 1 by exists (toL u.2); rewrite mulrC. apply: toPinj; rewrite !toL_K -upq1 modp_mul modpD mulrC. by rewrite modp_mull add0r. pose feL : fieldExtType F := HB.pack vL aL cuL unitM. exists feL; first by rewrite dimvf; apply: mul1n. exists toPF. have tol_lin: linear toL by move=> a q1 q2; rewrite -linearP -modpZl -modpD. have tol_mul : monoid_morphism (toL : {poly F} -> aL). by split=> [|q r]; apply: toPinj; rewrite !toL_K // modp_mul -!(mulrC r) modp_mul. pose toLlM := GRing.isLinear.Build _ _ _ _ toL tol_lin. pose toLmM := GRing.isMonoidMorphism.Build _ _ _ tol_mul. pose toLLRM : {lrmorphism _ -> feL} := HB.pack toL toLlM toLmM. by exists toLLRM. Qed. (*Coq 8.3 processes this shorter proof correctly, but then crashes on Qed. In Coq 8.4 Qed takes about 18s. In Coq 8.7, everything seems to be all right *) (* Lemma Xirredp_FAdjoin' (F : fieldType) (p : {poly F}) : *) (* irreducible_poly p -> *) (* {L : fieldExtType F & \dim {: L} = (size p).-1 & *) (* {z | root (map_poly (in_alg L) p) z & <<1; z>>%VS = fullv}}. *) (* Proof. *) (* case=> p_gt1 irr_p; set n := (size p).-1; pose vL := [vectType F of 'rV_n]. *) (* have Dn: n.+1 = size p := ltn_predK p_gt1. *) (* have nz_p: p != 0 by rewrite -size_poly_eq0 -Dn. *) (* pose toL q : vL := poly_rV (q %% p). *) (* have toL_K q : rVpoly (toL q) = q %% p. *) (* by rewrite poly_rV_K // -ltnS Dn ?ltn_modp -?Dn. *) (* pose mul (x y : vL) : vL := toL (rVpoly x * rVpoly y). *) (* pose L1 : vL := poly_rV 1. *) (* have L1K: rVpoly L1 = 1 by rewrite poly_rV_K // size_poly1 -ltnS Dn. *) (* have mulC: commutative mul by rewrite /mul => x y; rewrite mulrC. *) (* have mulA: associative mul. *) (* by move=> x y z; rewrite -!(mulC z) /mul !toL_K /toL !modp_mul mulrCA. *) (* have mul1: left_id L1 mul. *) (* move=> x; rewrite /mul L1K mul1r /toL modp_small ?rVpolyK // -Dn ltnS. *) (* by rewrite size_poly. *) (* have mulD: left_distributive mul +%R. *) (* move=> x y z; apply: canLR rVpolyK _. *) (* by rewrite !raddfD mulrDl /= !toL_K /toL modpD. *) (* have nzL1: L1 != 0 by rewrite -(can_eq rVpolyK) L1K raddf0 oner_eq0. *) (* pose mulM := GRing.Zmodule_isComNzRing.Build vL mulA mulC mul1 mulD nzL1. *) (* pose rL := ComNzRingType vL mulM. *) (* have mulZlM : GRing.Lmodule_isLalgebra F rL. *) (* constructor => a x y; apply: canRL rVpolyK _. *) (* by rewrite !linearZ /= toL_K -scalerAl modpZl. *) (* pose laL := LalgType F rL mulZlM. *) (* have mulZrM : GRing.Lalgebra_isAlgebra F laL. *) (* by constructor => a x y; rewrite !(mulrC x) scalerAl. *) (* pose aL := AlgType F laL mulZrM. *) (* pose uLM := Algebra_isFalgebra.Build F aL. *) (* pose cuL := ComUnitRingType uLM _. *) (* have unitM : GRing.ComUnitRing_isField cuL. *) (* constructor => x nz_x; apply/unitrP; set q := rVpoly x. *) (* have nz_q: q != 0 by rewrite -(can_eq rVpolyK) raddf0 in nz_x. *) (* have /Bezout_eq1_coprimepP[u upq1]: coprimep p q. *) (* have /contraR := irr_p _ _ (dvdp_gcdl p q); apply. *) (* have: size (gcdp p q) <= size q by apply: leq_gcdpr. *) (* rewrite leqNgt; apply: contra; move/eqp_size ->. *) (* by rewrite (polySpred nz_p) ltnS size_poly. *) (* suffices: x * toL u.2 = 1 by exists (toL u.2); rewrite mulrC. *) (* congr (poly_rV _); rewrite toL_K modp_mul mulrC (canRL (addKr _) upq1). *) (* by rewrite -mulNr modp_addl_mul_small ?size_poly1. *) (* pose feL := FieldExtType _ unitM _. *) (* exists feL; first by rewrite dimvf; apply: mul1n. *) (* pose z : vL := toL 'X; set iota := in_alg _. *) (* have q_z q: rVpoly (map_poly iota q).[z] = q %% p. *) (* elim/poly_ind: q => [|a q IHq]. *) (* by rewrite map_poly0 horner0 linear0 mod0p. *) (* rewrite rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC linearD /=. *) (* rewrite linearZ /= L1K alg_polyC modpD; congr (_ + _); last first. *) (* by rewrite modp_small // size_polyC; case: (~~ _) => //; apply: ltnW. *) (* by rewrite !toL_K IHq mulrC modp_mul mulrC modp_mul. *) (* exists z; first by rewrite /root -(can_eq rVpolyK) q_z modpp linear0. *) (* apply/vspaceP=> x; rewrite memvf; apply/Fadjoin_polyP. *) (* exists (map_poly iota (rVpoly x)). *) (* by apply/polyOverP=> i; rewrite coef_map memvZ ?mem1v. *) (* by apply/(can_inj rVpolyK); rewrite q_z modp_small // -Dn ltnS size_poly. *) (* Qed. *)
ModEq.lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Ring.Nat import Mathlib.Data.Int.GCD import Mathlib.Data.Nat.GCD.Basic /-! # Congruences modulo a natural number This file defines the equivalence relation `a ≡ b [MOD n]` on the natural numbers, and proves basic properties about it such as the Chinese Remainder Theorem `modEq_and_modEq_iff_modEq_mul`. ## Notations `a ≡ b [MOD n]` is notation for `Nat.ModEq n a b`, which is defined to mean `a % n = b % n`. ## Tags ModEq, congruence, mod, MOD, modulo -/ assert_not_exists OrderedAddCommMonoid Function.support namespace Nat /-- Modular equality. `n.ModEq a b`, or `a ≡ b [MOD n]`, means that `a % n = b % n`. -/ def ModEq (n a b : ℕ) := a % n = b % n @[inherit_doc] notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b variable {m n a b c d : ℕ} -- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n) namespace ModEq @[refl] protected theorem refl (a : ℕ) : a ≡ a [MOD n] := rfl protected theorem rfl : a ≡ a [MOD n] := ModEq.refl _ instance : IsRefl _ (ModEq n) := ⟨ModEq.refl⟩ @[symm] protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] := Eq.symm @[trans] protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] := Eq.trans instance : Trans (ModEq n) (ModEq n) (ModEq n) where trans := Nat.ModEq.trans protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] := ⟨ModEq.symm, ModEq.symm⟩ end ModEq theorem modEq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero] theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] := modEq_zero_iff_dvd.2 h theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≡ a [MOD n] := h.modEq_zero_nat.symm theorem modEq_iff_dvd : a ≡ b [MOD n] ↔ (n : ℤ) ∣ b - a := by rw [ModEq, eq_comm, ← Int.natCast_inj, Int.natCast_mod, Int.natCast_mod, Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero] alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd /-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/ theorem modEq_iff_dvd' (h : a ≤ b) : a ≡ b [MOD n] ↔ n ∣ b - a := by rw [modEq_iff_dvd, ← Int.natCast_dvd_natCast, Int.ofNat_sub h] theorem mod_modEq (a n) : a % n ≡ a [MOD n] := mod_mod _ _ namespace ModEq theorem self_mul_add : ModEq m (m * a + b) b := by simp [Nat.ModEq] lemma of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] := modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD c * n] := by unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h] protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] := (h.mul_left' _).of_dvd (dvd_mul_left _ _) protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n * c] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] := by rw [mul_comm a, mul_comm b]; exact h.mul_left c @[gcongr] protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] := (h₂.mul_left _).trans (h₁.mul_right _) @[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] := by induction m with | zero => rfl | succ d hd => rw [Nat.pow_succ, Nat.pow_succ] exact hd.mul h @[gcongr] protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] := by rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm] exact Int.dvd_add h₁.dvd h₂.dvd protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] := ModEq.rfl.add h protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] := h.add ModEq.rfl protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : c ≡ d [MOD n] := by simp only [modEq_iff_dvd, Int.natCast_add] at * rw [add_sub_add_comm] at h₂ convert Int.dvd_sub h₂ h₁ using 1 rw [add_sub_cancel_left] protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : a ≡ b [MOD n] := by rw [add_comm a, add_comm b] at h₂ exact h₁.add_left_cancel h₂ protected theorem add_right_cancel' (c : ℕ) (h : a + c ≡ b + c [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_right_cancel h protected lemma sub' (h : c ≤ a ↔ d ≤ b) (hab : a ≡ b [MOD n]) (hcd : c ≡ d [MOD n]) : a - c ≡ b - d [MOD n] := by obtain hac | hca := lt_or_ge a c · rw [Nat.sub_eq_zero_of_le hac.le, Nat.sub_eq_zero_of_le ((lt_iff_lt_of_le_iff_le h).1 hac).le] rw [modEq_iff_dvd, Int.natCast_sub hca, Int.natCast_sub <| h.1 hca, sub_sub_sub_comm] exact Int.dvd_sub hab.dvd hcd.dvd protected lemma sub_left' (h : b ≤ a ↔ c ≤ a) (hbc : b ≡ c [MOD n]) : a - b ≡ a - c [MOD n] := .sub' h .rfl hbc protected lemma sub_right' (h : a ≤ b ↔ a ≤ c) (hbc : b ≡ c [MOD n]) : b - a ≡ c - a [MOD n] := .sub' h hbc .rfl @[gcongr] protected lemma sub (hca : c ≤ a) (hdb : d ≤ b) (hab : a ≡ b [MOD n]) (hcd : c ≡ d [MOD n]) : a - c ≡ b - d [MOD n] := .sub' (iff_of_true hca hdb) hab hcd @[gcongr] protected lemma sub_left (hba : b ≤ a) (hca : c ≤ a) (hbc : b ≡ c [MOD n]) : a - b ≡ a - c [MOD n] := .sub hba hca .rfl hbc @[gcongr] protected lemma sub_right (hab : a ≤ b) (hac : a ≤ c) (hbc : b ≡ c [MOD n]) : b - a ≡ c - a [MOD n] := .sub hab hac hbc .rfl /-- Cancel left multiplication on both sides of the `≡` and in the modulus. For cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/ protected theorem mul_left_cancel' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.mul_sub] exact fun h => (Int.dvd_of_mul_dvd_mul_left (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_left_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m] := ⟨ModEq.mul_left_cancel' hc, ModEq.mul_left' _⟩ /-- Cancel right multiplication on both sides of the `≡` and in the modulus. For cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/ protected theorem mul_right_cancel' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.sub_mul] exact fun h => (Int.dvd_of_mul_dvd_mul_right (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_right_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m] := ⟨ModEq.mul_right_cancel' hc, ModEq.mul_right' _⟩ /-- Cancel left multiplication in the modulus. For cancelling left multiplication on both sides of the `≡`, see `nat.modeq.mul_left_cancel'`. -/ lemma of_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] := by rw [modEq_iff_dvd] at * exact (dvd_mul_left (n : ℤ) (m : ℤ)).trans h /-- Cancel right multiplication in the modulus. For cancelling right multiplication on both sides of the `≡`, see `nat.modeq.mul_right_cancel'`. -/ lemma of_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] := mul_comm m n ▸ of_mul_left _ theorem of_div (h : a / c ≡ b / c [MOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) : a ≡ b [MOD m] := by convert h.mul_left' c <;> rwa [Nat.mul_div_cancel'] end ModEq lemma modEq_sub (h : b ≤ a) : a ≡ b [MOD a - b] := (modEq_of_dvd <| by rw [Int.ofNat_sub h]).symm lemma modEq_one : a ≡ b [MOD 1] := modEq_of_dvd <| one_dvd _ @[simp] lemma modEq_zero_iff : a ≡ b [MOD 0] ↔ a = b := by rw [ModEq, mod_zero, mod_zero] @[simp] lemma add_modEq_left : n + a ≡ a [MOD n] := by rw [ModEq, add_mod_left] @[simp] lemma add_modEq_right : a + n ≡ a [MOD n] := by rw [ModEq, add_mod_right] namespace ModEq theorem le_of_lt_add (h1 : a ≡ b [MOD m]) (h2 : a < b + m) : a ≤ b := (le_total a b).elim id fun h3 => Nat.le_of_sub_eq_zero (eq_zero_of_dvd_of_lt ((modEq_iff_dvd' h3).mp h1.symm) (by omega)) theorem add_le_of_lt (h1 : a ≡ b [MOD m]) (h2 : a < b) : a + m ≤ b := le_of_lt_add (add_modEq_right.trans h1) (by omega) theorem dvd_iff (h : a ≡ b [MOD m]) (hdm : d ∣ m) : d ∣ a ↔ d ∣ b := by simp only [← modEq_zero_iff_dvd] replace h := h.of_dvd hdm exact ⟨h.symm.trans, h.trans⟩ theorem gcd_eq (h : a ≡ b [MOD m]) : gcd a m = gcd b m := by have h1 := gcd_dvd_right a m have h2 := gcd_dvd_right b m exact dvd_antisymm (dvd_gcd ((h.dvd_iff h1).mp (gcd_dvd_left a m)) h1) (dvd_gcd ((h.dvd_iff h2).mpr (gcd_dvd_left b m)) h2) lemma eq_of_abs_lt (h : a ≡ b [MOD m]) (h2 : |(b : ℤ) - a| < m) : a = b := by apply Int.ofNat.inj rw [eq_comm, ← sub_eq_zero] exact Int.eq_zero_of_abs_lt_dvd h.dvd h2 lemma eq_of_lt_of_lt (h : a ≡ b [MOD m]) (ha : a < m) (hb : b < m) : a = b := h.eq_of_abs_lt <| Int.abs_sub_lt_of_lt_lt ha hb /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m / gcd m c] := by let d := gcd m c have hmd := gcd_dvd_left m c have hcd := gcd_dvd_right m c rw [modEq_iff_dvd] refine @Int.dvd_of_dvd_mul_right_of_gcd_one (m / d) (c / d) (b - a) ?_ ?_ · show (m / d : ℤ) ∣ c / d * (b - a) rw [mul_comm, ← Int.mul_ediv_assoc (b - a) (Int.natCast_dvd_natCast.mpr hcd), mul_comm] apply Int.ediv_dvd_ediv (Int.natCast_dvd_natCast.mpr hmd) rw [Int.mul_sub] exact modEq_iff_dvd.mp h · show Int.gcd (m / d) (c / d) = 1 simp only [d, ← Int.natCast_div, Int.gcd_natCast_natCast (m / d) (c / d), gcd_div hmd hcd, Nat.div_self (gcd_pos_of_pos_left c hm)] /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m / gcd m c] := by apply cancel_left_div_gcd hm simpa [mul_comm] using h lemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : c * a ≡ d * b [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_right b).cancel_left_div_gcd hm lemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : a * c ≡ b * d [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_left b).cancel_right_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m] := by rcases m.eq_zero_or_pos with (rfl | hm) · simp only [gcd_zero_left] at hmc simp only [hmc, one_mul, modEq_zero_iff] at h subst h rfl simpa [hmc] using h.cancel_left_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m] := cancel_left_of_coprime hmc <| by simpa [mul_comm] using h end ModEq /-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder' (h : a ≡ b [MOD gcd n m]) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := if hn : n = 0 then ⟨a, by rw [hn, gcd_zero_left] at h; constructor · rfl · exact h⟩ else if hm : m = 0 then ⟨b, by rw [hm, gcd_zero_right] at h; constructor · exact h.symm · rfl⟩ else ⟨let (c, d) := xgcd n m; Int.toNat ((n * c * b + m * d * a) / gcd n m % lcm n m), by rw [xgcd_val] dsimp rw [modEq_iff_dvd, modEq_iff_dvd, Int.toNat_of_nonneg (Int.emod_nonneg _ (Int.natCast_ne_zero.2 (lcm_ne_zero hn hm)))] have hnonzero : (gcd n m : ℤ) ≠ 0 := by norm_cast rw [Nat.gcd_eq_zero_iff, not_and] exact fun _ => hm have hcoedvd : ∀ t, (gcd n m : ℤ) ∣ t * (b - a) := fun t => h.dvd.mul_left _ have := gcd_eq_gcd_ab n m constructor <;> rw [Int.emod_def, ← sub_add] <;> refine Int.dvd_add ?_ (dvd_mul_of_dvd_left ?_ _) <;> try norm_cast · rw [← sub_eq_iff_eq_add'] at this rw [← this, Int.sub_mul, ← add_sub_assoc, add_comm, add_sub_assoc, ← Int.mul_sub, Int.add_ediv_of_dvd_left, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_sub, sub_self, zero_sub, Int.dvd_neg, mul_assoc] · exact dvd_mul_right _ _ norm_cast exact dvd_mul_right _ _ · exact dvd_lcm_left n m · rw [← sub_eq_iff_eq_add] at this rw [← this, Int.sub_mul, sub_add, ← Int.mul_sub, Int.sub_ediv_of_dvd, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_add, sub_self, zero_add, mul_assoc] · exact dvd_mul_right _ _ · exact hcoedvd _ · exact dvd_lcm_right n m⟩ /-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder (co : n.Coprime m) (a b : ℕ) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := chineseRemainder' (by convert @modEq_one a b) theorem chineseRemainder'_lt_lcm (h : a ≡ b [MOD gcd n m]) (hn : n ≠ 0) (hm : m ≠ 0) : ↑(chineseRemainder' h) < lcm n m := by dsimp only [chineseRemainder'] rw [dif_neg hn, dif_neg hm, Subtype.coe_mk, xgcd_val, ← Int.toNat_natCast (lcm n m)] have lcm_pos := Int.natCast_pos.mpr (Nat.pos_of_ne_zero (lcm_ne_zero hn hm)) exact (Int.toNat_lt_toNat lcm_pos).mpr (Int.emod_lt_of_pos _ lcm_pos) theorem chineseRemainder_lt_mul (co : n.Coprime m) (a b : ℕ) (hn : n ≠ 0) (hm : m ≠ 0) : ↑(chineseRemainder co a b) < n * m := lt_of_lt_of_le (chineseRemainder'_lt_lcm _ hn hm) (le_of_eq co.lcm_eq_mul) theorem mod_lcm (hn : a ≡ b [MOD n]) (hm : a ≡ b [MOD m]) : a ≡ b [MOD lcm n m] := Nat.modEq_iff_dvd.mpr <| Int.coe_lcm_dvd (Nat.modEq_iff_dvd.mp hn) (Nat.modEq_iff_dvd.mp hm) theorem chineseRemainder_modEq_unique (co : n.Coprime m) {a b z} (hzan : z ≡ a [MOD n]) (hzbm : z ≡ b [MOD m]) : z ≡ chineseRemainder co a b [MOD n*m] := by simpa [Nat.Coprime.lcm_eq_mul co] using mod_lcm (hzan.trans ((chineseRemainder co a b).prop.1).symm) (hzbm.trans ((chineseRemainder co a b).prop.2).symm) theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℕ} (hmn : m.Coprime n) : a ≡ b [MOD m] ∧ a ≡ b [MOD n] ↔ a ≡ b [MOD m * n] := ⟨fun h => by rw [Nat.modEq_iff_dvd, Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast, ← Int.dvd_natAbs, Int.natCast_dvd_natCast] at h rw [Nat.modEq_iff_dvd, ← Int.dvd_natAbs, Int.natCast_dvd_natCast] exact hmn.mul_dvd_of_dvd_of_dvd h.1 h.2, fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩ theorem coprime_of_mul_modEq_one (b : ℕ) {a n : ℕ} (h : a * b ≡ 1 [MOD n]) : a.Coprime n := by obtain ⟨g, hh⟩ := Nat.gcd_dvd_right a n rw [Nat.coprime_iff_gcd_eq_one, ← Nat.dvd_one, ← Nat.modEq_zero_iff_dvd] calc 1 ≡ a * b [MOD a.gcd n] := (hh ▸ h).symm.of_mul_right g _ ≡ 0 * b [MOD a.gcd n] := (Nat.modEq_zero_iff_dvd.mpr (Nat.gcd_dvd_left _ _)).mul_right b _ = 0 := by rw [zero_mul] theorem add_mod_add_ite (a b c : ℕ) : ((a + b) % c + if c ≤ a % c + b % c then c else 0) = a % c + b % c := have : (a + b) % c = (a % c + b % c) % c := ((mod_modEq _ _).add <| mod_modEq _ _).symm if hc0 : c = 0 then by simp [hc0, Nat.mod_zero] else by rw [this] split_ifs with h · have h2 : (a % c + b % c) / c < 2 := Nat.div_lt_of_lt_mul (by rw [mul_two] exact add_lt_add (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0)) (Nat.mod_lt _ (Nat.pos_of_ne_zero hc0))) have h0 : 0 < (a % c + b % c) / c := Nat.div_pos h (Nat.pos_of_ne_zero hc0) rw [← @add_right_cancel_iff _ _ _ (c * ((a % c + b % c) / c)), add_comm _ c, add_assoc, mod_add_div, le_antisymm (le_of_lt_succ h2) h0, mul_one, add_comm] · rw [Nat.mod_eq_of_lt (lt_of_not_ge h), add_zero] theorem add_mod_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) : (a + b) % c = a % c + b % c := by rw [← add_mod_add_ite, if_neg (not_le_of_gt hc), add_zero] theorem add_mod_add_of_le_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) : (a + b) % c + c = a % c + b % c := by rw [← add_mod_add_ite, if_pos hc] theorem add_div_eq_of_add_mod_lt {a b c : ℕ} (hc : a % c + b % c < c) : (a + b) / c = a / c + b / c := if hc0 : c = 0 then by simp [hc0] else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0), if_neg (not_le_of_gt hc), add_zero] protected theorem add_div_of_dvd_right {a b c : ℕ} (hca : c ∣ a) : (a + b) / c = a / c + b / c := if h : c = 0 then by simp [h] else add_div_eq_of_add_mod_lt (by rw [Nat.mod_eq_zero_of_dvd hca, zero_add] exact Nat.mod_lt _ (zero_lt_of_ne_zero h)) protected theorem add_div_of_dvd_left {a b c : ℕ} (hca : c ∣ b) : (a + b) / c = a / c + b / c := by rwa [add_comm, Nat.add_div_of_dvd_right, add_comm] theorem add_div_eq_of_le_mod_add_mod {a b c : ℕ} (hc : c ≤ a % c + b % c) (hc0 : 0 < c) : (a + b) / c = a / c + b / c + 1 := by rw [Nat.add_div hc0, if_pos hc] theorem add_div_le_add_div (a b c : ℕ) : a / c + b / c ≤ (a + b) / c := if hc0 : c = 0 then by simp [hc0] else by rw [Nat.add_div (Nat.pos_of_ne_zero hc0)]; exact Nat.le_add_right _ _ theorem le_mod_add_mod_of_dvd_add_of_not_dvd {a b c : ℕ} (h : c ∣ a + b) (ha : ¬c ∣ a) : c ≤ a % c + b % c := by_contradiction fun hc => by have : (a + b) % c = a % c + b % c := add_mod_of_add_mod_lt (lt_of_not_ge hc) simp_all [dvd_iff_mod_eq_zero] lemma mod_sub_of_le {a b n : ℕ} (h : b ≤ a % n) : a % n - b = (a - b) % n := by rcases n.eq_zero_or_pos with rfl | hn; · simp only [mod_zero] nth_rw 2 [← div_add_mod a n]; rw [Nat.add_sub_assoc h, mul_add_mod] exact (mod_eq_of_lt <| (sub_le ..).trans_lt (mod_lt a hn)).symm theorem odd_mul_odd {n m : ℕ} : n % 2 = 1 → m % 2 = 1 → n * m % 2 = 1 := by simpa [Nat.ModEq] using @ModEq.mul 2 n 1 m 1 theorem odd_mul_odd_div_two {m n : ℕ} (hm1 : m % 2 = 1) (hn1 : n % 2 = 1) : m * n / 2 = m * (n / 2) + m / 2 := have hn0 : 0 < n := Nat.pos_of_ne_zero fun h => by simp_all mul_right_injective₀ two_ne_zero <| by dsimp rw [mul_add, two_mul_odd_div_two hm1, mul_left_comm, two_mul_odd_div_two hn1, two_mul_odd_div_two (Nat.odd_mul_odd hm1 hn1), Nat.mul_sub, mul_one, ← Nat.add_sub_assoc (by omega), Nat.sub_add_cancel (Nat.le_mul_of_pos_right m hn0)] theorem odd_of_mod_four_eq_one {n : ℕ} : n % 4 = 1 → n % 2 = 1 := by simpa [ModEq] using @ModEq.of_mul_left 2 n 1 2 theorem odd_of_mod_four_eq_three {n : ℕ} : n % 4 = 3 → n % 2 = 1 := by simpa [ModEq] using @ModEq.of_mul_left 2 n 3 2 /-- A natural number is odd iff it has residue `1` or `3` mod `4`. -/ theorem odd_mod_four_iff {n : ℕ} : n % 2 = 1 ↔ n % 4 = 1 ∨ n % 4 = 3 := have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → m = 1 ∨ m = 3 := by decide ⟨fun hn => help (n % 4) (mod_lt n (by omega)) <| (mod_mod_of_dvd n (by decide : 2 ∣ 4)).trans hn, fun h => Or.elim h odd_of_mod_four_eq_one odd_of_mod_four_eq_three⟩ lemma mod_eq_of_modEq {a b n} (h : a ≡ b [MOD n]) (hb : b < n) : a % n = b := Eq.trans h (mod_eq_of_lt hb) end Nat
Subcomplex.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.SimplicialSet.Basic import Mathlib.CategoryTheory.Subpresheaf.Basic /-! # Subcomplexes of a simplicial set Given a simplicial set `X`, this file defines the type `X.Subcomplex` of subcomplexes of `X` as an abbreviation for `Subpresheaf X`. It also introduces a coercion from `X.Subcomplex` to `SSet`. ## Implementation note `SSet.{u}` is defined as `Cᵒᵖ ⥤ Type u`, but it is not an abbreviation. This is the reason why `Subpresheaf.ι` is redefined here as `Subcomplex.ι` so that this morphism appears as a morphism in `SSet` instead of a morphism in the category of presheaves. -/ universe u open CategoryTheory namespace SSet variable (X : SSet.{u}) /-- The complete lattice of subcomplexes of a simplicial set. -/ abbrev Subcomplex := Subpresheaf X variable {X} /-- The underlying simplicial set of a subcomplex. -/ abbrev Subcomplex.toSSet (A : X.Subcomplex) : SSet.{u} := A.toPresheaf instance : CoeOut X.Subcomplex SSet.{u} where coe := fun S ↦ S.toSSet /-- If `A : Subcomplex X`, this is the inclusion `A ⟶ X` in the category `SSet`. -/ abbrev Subcomplex.ι (A : Subcomplex X) : Quiver.Hom (V := SSet) A X := Subpresheaf.ι A instance (A : X.Subcomplex) : Mono A.ι := inferInstanceAs (Mono (Subpresheaf.ι A)) end SSet
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.Order.Interval.Finset.Nat import Mathlib.Data.PNat.Defs /-! # Finite intervals of positive naturals This file proves that `ℕ+` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. -/ open Finset Function PNat namespace PNat variable (a b : ℕ+) instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ+ := Subtype.instLocallyFiniteOrder _ theorem Icc_eq_finset_subtype : Icc a b = (Icc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ico_eq_finset_subtype : Ico a b = (Ico (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ioc_eq_finset_subtype : Ioc a b = (Ioc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem Ioo_eq_finset_subtype : Ioo a b = (Ioo (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem uIcc_eq_finset_subtype : uIcc a b = (uIcc (a : ℕ) b).subtype fun n : ℕ => 0 < n := rfl theorem map_subtype_embedding_Icc : (Icc a b).map (Embedding.subtype _) = Icc ↑a ↑b := Finset.map_subtype_embedding_Icc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ico : (Ico a b).map (Embedding.subtype _) = Ico ↑a ↑b := Finset.map_subtype_embedding_Ico _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ioc : (Ioc a b).map (Embedding.subtype _) = Ioc ↑a ↑b := Finset.map_subtype_embedding_Ioc _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_Ioo : (Ioo a b).map (Embedding.subtype _) = Ioo ↑a ↑b := Finset.map_subtype_embedding_Ioo _ _ _ fun _c _ _x hx _ hc _ => hc.trans_le hx theorem map_subtype_embedding_uIcc : (uIcc a b).map (Embedding.subtype _) = uIcc ↑a ↑b := map_subtype_embedding_Icc _ _ @[simp] theorem card_Icc : #(Icc a b) = b + 1 - a := by rw [← Nat.card_Icc, ← map_subtype_embedding_Icc, card_map] @[simp] theorem card_Ico : #(Ico a b) = b - a := by rw [← Nat.card_Ico, ← map_subtype_embedding_Ico, card_map] @[simp] theorem card_Ioc : #(Ioc a b) = b - a := by rw [← Nat.card_Ioc, ← map_subtype_embedding_Ioc, card_map] @[simp] theorem card_Ioo : #(Ioo a b) = b - a - 1 := by rw [← Nat.card_Ioo, ← map_subtype_embedding_Ioo, card_map] @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := by rw [← Nat.card_uIcc, ← map_subtype_embedding_uIcc, card_map] theorem card_fintype_Icc : Fintype.card (Set.Icc a b) = b + 1 - a := by rw [← card_Icc, Fintype.card_ofFinset] theorem card_fintype_Ico : Fintype.card (Set.Ico a b) = b - a := by rw [← card_Ico, Fintype.card_ofFinset] theorem card_fintype_Ioc : Fintype.card (Set.Ioc a b) = b - a := by rw [← card_Ioc, Fintype.card_ofFinset] theorem card_fintype_Ioo : Fintype.card (Set.Ioo a b) = b - a - 1 := by rw [← card_Ioo, Fintype.card_ofFinset] theorem card_fintype_uIcc : Fintype.card (Set.uIcc a b) = (b - a : ℤ).natAbs + 1 := by rw [← card_uIcc, Fintype.card_ofFinset] end PNat
Star.lean
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Nicolò Cavalleri -/ import Mathlib.Topology.Algebra.Star import Mathlib.Algebra.Star.StarAlgHom import Mathlib.Topology.ContinuousMap.Algebra /-! # Star structures on continuous maps. -/ namespace ContinuousMap /-! ### Star structure If `β` has a continuous star operation, we put a star structure on `C(α, β)` by using the star operation pointwise. If `β` is a ⋆-ring, then `C(α, β)` inherits a ⋆-ring structure. If `β` is a ⋆-ring and a ⋆-module over `R`, then the space of continuous functions from `α` to `β` is a ⋆-module over `R`. -/ section StarStructure variable {R α β : Type*} variable [TopologicalSpace α] [TopologicalSpace β] section Star variable [Star β] [ContinuousStar β] instance : Star C(α, β) where star f := starContinuousMap.comp f @[simp] theorem coe_star (f : C(α, β)) : ⇑(star f) = star (⇑f) := rfl @[simp] theorem star_apply (f : C(α, β)) (x : α) : star f x = star (f x) := rfl instance instTrivialStar [TrivialStar β] : TrivialStar C(α, β) where star_trivial _ := ext fun _ => star_trivial _ end Star instance [InvolutiveStar β] [ContinuousStar β] : InvolutiveStar C(α, β) where star_involutive _ := ext fun _ => star_star _ instance starAddMonoid [AddMonoid β] [ContinuousAdd β] [StarAddMonoid β] [ContinuousStar β] : StarAddMonoid C(α, β) where star_add _ _ := ext fun _ => star_add _ _ instance starMul [Mul β] [ContinuousMul β] [StarMul β] [ContinuousStar β] : StarMul C(α, β) where star_mul _ _ := ext fun _ => star_mul _ _ instance [NonUnitalNonAssocSemiring β] [IsTopologicalSemiring β] [StarRing β] [ContinuousStar β] : StarRing C(α, β) := { ContinuousMap.starAddMonoid, ContinuousMap.starMul with } instance [Star R] [Star β] [SMul R β] [StarModule R β] [ContinuousStar β] [ContinuousConstSMul R β] : StarModule R C(α, β) where star_smul _ _ := ext fun _ => star_smul _ _ end StarStructure section Precomposition variable {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] variable (𝕜 : Type*) [CommSemiring 𝕜] variable (A : Type*) [TopologicalSpace A] [Semiring A] [IsTopologicalSemiring A] [Star A] variable [ContinuousStar A] [Algebra 𝕜 A] /-- The functorial map taking `f : C(X, Y)` to `C(Y, A) →⋆ₐ[𝕜] C(X, A)` given by pre-composition with the continuous function `f`. See `ContinuousMap.compMonoidHom'` and `ContinuousMap.compAddMonoidHom'`, `ContinuousMap.compRightAlgHom` for bundlings of pre-composition into a `MonoidHom`, an `AddMonoidHom` and an `AlgHom`, respectively, under suitable assumptions on `A`. -/ @[simps] def compStarAlgHom' (f : C(X, Y)) : C(Y, A) →⋆ₐ[𝕜] C(X, A) where toFun g := g.comp f map_one' := one_comp _ map_mul' _ _ := rfl map_zero' := zero_comp f map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl /-- `ContinuousMap.compStarAlgHom'` sends the identity continuous map to the identity `StarAlgHom` -/ theorem compStarAlgHom'_id : compStarAlgHom' 𝕜 A (ContinuousMap.id X) = StarAlgHom.id 𝕜 C(X, A) := StarAlgHom.ext fun _ => ContinuousMap.ext fun _ => rfl /-- `ContinuousMap.compStarAlgHom'` is functorial. -/ theorem compStarAlgHom'_comp (g : C(Y, Z)) (f : C(X, Y)) : compStarAlgHom' 𝕜 A (g.comp f) = (compStarAlgHom' 𝕜 A f).comp (compStarAlgHom' 𝕜 A g) := StarAlgHom.ext fun _ => ContinuousMap.ext fun _ => rfl end Precomposition section Postcomposition variable (X : Type*) {𝕜 A B C : Type*} [TopologicalSpace X] [CommSemiring 𝕜] variable [TopologicalSpace A] [Semiring A] [IsTopologicalSemiring A] [Star A] variable [ContinuousStar A] [Algebra 𝕜 A] variable [TopologicalSpace B] [Semiring B] [IsTopologicalSemiring B] [Star B] variable [ContinuousStar B] [Algebra 𝕜 B] variable [TopologicalSpace C] [Semiring C] [IsTopologicalSemiring C] [Star C] variable [ContinuousStar C] [Algebra 𝕜 C] /-- Post-composition with a continuous star algebra homomorphism is a star algebra homomorphism between spaces of continuous maps. -/ @[simps] def compStarAlgHom (φ : A →⋆ₐ[𝕜] B) (hφ : Continuous φ) : C(X, A) →⋆ₐ[𝕜] C(X, B) where toFun f := (⟨φ, hφ⟩ : C(A, B)).comp f map_one' := ext fun _ => map_one φ map_mul' f g := ext fun x => map_mul φ (f x) (g x) map_zero' := ext fun _ => map_zero φ map_add' f g := ext fun x => map_add φ (f x) (g x) commutes' r := ext fun _x => AlgHomClass.commutes φ r map_star' f := ext fun x => map_star φ (f x) /-- `ContinuousMap.compStarAlgHom` sends the identity `StarAlgHom` on `A` to the identity `StarAlgHom` on `C(X, A)`. -/ lemma compStarAlgHom_id : compStarAlgHom X (.id 𝕜 A) continuous_id = .id 𝕜 C(X, A) := rfl /-- `ContinuousMap.compStarAlgHom` is functorial. -/ lemma compStarAlgHom_comp (φ : A →⋆ₐ[𝕜] B) (ψ : B →⋆ₐ[𝕜] C) (hφ : Continuous φ) (hψ : Continuous ψ) : compStarAlgHom X (ψ.comp φ) (hψ.comp hφ) = (compStarAlgHom X ψ hψ).comp (compStarAlgHom X φ hφ) := rfl end Postcomposition end ContinuousMap namespace Homeomorph variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] variable (𝕜 : Type*) [CommSemiring 𝕜] variable (A : Type*) [TopologicalSpace A] [Semiring A] [IsTopologicalSemiring A] [StarRing A] variable [ContinuousStar A] [Algebra 𝕜 A] /-- `ContinuousMap.compStarAlgHom'` as a `StarAlgEquiv` when the continuous map `f` is actually a homeomorphism. -/ @[simps] def compStarAlgEquiv' (f : X ≃ₜ Y) : C(Y, A) ≃⋆ₐ[𝕜] C(X, A) := { (f : C(X, Y)).compStarAlgHom' 𝕜 A with toFun := (f : C(X, Y)).compStarAlgHom' 𝕜 A invFun := (f.symm : C(Y, X)).compStarAlgHom' 𝕜 A left_inv := fun g => by simp only [ContinuousMap.compStarAlgHom'_apply, ContinuousMap.comp_assoc, toContinuousMap_comp_symm, ContinuousMap.comp_id] right_inv := fun g => by simp only [ContinuousMap.compStarAlgHom'_apply, ContinuousMap.comp_assoc, symm_comp_toContinuousMap, ContinuousMap.comp_id] map_smul' := fun k a => map_smul ((f : C(X, Y)).compStarAlgHom' 𝕜 A) k a } end Homeomorph /-! ### Evaluation as a bundled map -/ variable {X : Type*} (S R : Type*) [TopologicalSpace X] [CommSemiring S] [CommSemiring R] variable [Algebra S R] [TopologicalSpace R] [IsTopologicalSemiring R] /-- Evaluation of continuous maps at a point, bundled as a star algebra homomorphism. -/ @[simps!] def ContinuousMap.evalStarAlgHom [StarRing R] [ContinuousStar R] (x : X) : C(X, R) →⋆ₐ[S] R := { ContinuousMap.evalAlgHom S R x with map_star' := fun _ => rfl }
fraction.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 div seq. From mathcomp Require Import ssrAC choice tuple bigop ssralg poly polydiv. From mathcomp Require Import generic_quotient. (******************************************************************************) (* Field of fraction of an integral domain *) (* *) (* This file builds the field of fraction of any integral domain. The main *) (* result of this file is the existence of the field and of the tofrac *) (* function which is a injective ring morphism from R to its fraction field *) (* {fraction R}. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Local Open Scope ring_scope. Local Open Scope quotient_scope. Reserved Notation "{ 'ratio' T }" (format "{ 'ratio' T }"). Reserved Notation "{ 'fraction' T }" (format "{ 'fraction' T }"). Reserved Notation "x %:F" (format "x %:F"). Section FracDomain. Variable R : nzRingType. (* ratios are pairs of R, such that the second member is nonzero *) Inductive ratio := mkRatio { frac :> R * R; _ : frac.2 != 0 }. HB.instance Definition _ := [isSub for frac]. HB.instance Definition _ := [Choice of ratio by <:]. Lemma denom_ratioP : forall f : ratio, f.2 != 0. Proof. by case. Qed. Definition ratio0 := (@mkRatio (0, 1) (oner_neq0 _)). Definition Ratio x y : ratio := insubd ratio0 (x, y). Lemma numer_Ratio x y : y != 0 -> (Ratio x y).1 = x. Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed. Lemma denom_Ratio x y : y != 0 -> (Ratio x y).2 = y. Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed. Definition numden_Ratio := (numer_Ratio, denom_Ratio). Variant Ratio_spec (n d : R) : ratio -> R -> R -> Type := | RatioNull of d = 0 : Ratio_spec n d ratio0 n 0 | RatioNonNull (d_neq0 : d != 0) : Ratio_spec n d (@mkRatio (n, d) d_neq0) n d. Lemma RatioP n d : Ratio_spec n d (Ratio n d) n d. Proof. rewrite /Ratio /insubd; case: insubP=> /= [x /= d_neq0 hx|]. have ->: x = @mkRatio (n, d) d_neq0 by apply: val_inj. by constructor. by rewrite negbK=> /eqP hx; rewrite {2}hx; constructor. Qed. Lemma Ratio0 x : Ratio x 0 = ratio0. Proof. by rewrite /Ratio /insubd; case: insubP; rewrite //= eqxx. Qed. End FracDomain. Arguments ratio R%_type. Notation "{ 'ratio' T }" := (ratio T) : type_scope. Notation "'\n_' x" := (frac x).1 (at level 8, x at level 2, format "'\n_' x"). Notation "'\d_' x" := (frac x).2 (at level 8, x at level 2, format "'\d_' x"). Module FracField. Section FracField. Variable R : idomainType. Local Notation frac := (R * R). Local Notation dom := (ratio R). Local Notation domP := denom_ratioP. Implicit Types x y z : dom. (* We define a relation in ratios *) Local Notation equivf_notation x y := (\n_x * \d_y == \d_x * \n_y). Definition equivf x y := equivf_notation x y. Lemma equivfE x y : equivf x y = equivf_notation x y. Proof. by []. Qed. Lemma equivf_refl : reflexive equivf. Proof. by move=> x; rewrite /equivf mulrC. Qed. Lemma equivf_sym : symmetric equivf. Proof. by move=> x y; rewrite /equivf eq_sym; congr (_==_); rewrite mulrC. Qed. Lemma equivf_trans : transitive equivf. Proof. move=> [x Px] [y Py] [z Pz]; rewrite /equivf /= mulrC => /eqP xy /eqP yz. by rewrite -(inj_eq (mulfI Px)) mulrA xy -mulrA yz mulrCA. Qed. (* we show that equivf is an equivalence *) Canonical equivf_equiv := EquivRel equivf equivf_refl equivf_sym equivf_trans. Definition type := {eq_quot equivf}. (* we recover some structure for the quotient *) HB.instance Definition _ : EqQuotient _ equivf type := EqQuotient.on type. HB.instance Definition _ := Choice.on type. (* we explain what was the equivalence on the quotient *) Lemma equivf_def (x y : ratio R) : x == y %[mod type] = (\n_x * \d_y == \d_x * \n_y). Proof. by rewrite eqmodE. Qed. Lemma equivf_r x : \n_x * \d_(repr (\pi_type x)) = \d_x * \n_(repr (\pi_type x)). Proof. by apply/eqP; rewrite -equivf_def reprK. Qed. Lemma equivf_l x : \n_(repr (\pi_type x)) * \d_x = \d_(repr (\pi_type x)) * \n_x. Proof. by apply/eqP; rewrite -equivf_def reprK. Qed. Lemma numer0 x : (\n_x == 0) = (x == (ratio0 R) %[mod_eq equivf]). Proof. by rewrite eqmodE /= !equivfE // mulr1 mulr0. Qed. Lemma Ratio_numden : forall x, Ratio \n_x \d_x = x. Proof. case=> [[n d] /= nd]; rewrite /Ratio /insubd; apply: val_inj=> /=. by case: insubP=> //=; rewrite nd. Qed. Definition tofrac := lift_embed type (fun x : R => Ratio x 1). Canonical tofrac_pi_morph := PiEmbed tofrac. Notation "x %:F" := (@tofrac x). Implicit Types a b c : type. Definition addf x y : dom := Ratio (\n_x * \d_y + \n_y * \d_x) (\d_x * \d_y). Definition add := lift_op2 type addf. Lemma pi_add : {morph \pi : x y / addf x y >-> add x y}. Proof. move=> x y; unlock add; apply/eqmodP; rewrite /= equivfE /addf /=. rewrite !numden_Ratio ?mulf_neq0 ?domP // mulrDr mulrDl; apply/eqP. symmetry; rewrite (AC (2*2) (3*1*2*4)) (AC (2*2) (3*2*1*4))/=. by rewrite !equivf_l (ACl ((2*3)*(1*4))) (ACl ((2*3)*(4*1)))/=. Qed. Canonical pi_add_morph := PiMorph2 pi_add. Definition oppf x : dom := Ratio (- \n_x) \d_x. Definition opp := lift_op1 type oppf. Lemma pi_opp : {morph \pi : x / oppf x >-> opp x}. Proof. move=> x; unlock opp; apply/eqmodP; rewrite /= /equivf /oppf /=. by rewrite !numden_Ratio ?(domP,mulf_neq0) // mulNr mulrN -equivf_r. Qed. Canonical pi_opp_morph := PiMorph1 pi_opp. Definition mulf x y : dom := Ratio (\n_x * \n_y) (\d_x * \d_y). Definition mul := lift_op2 type mulf. Lemma pi_mul : {morph \pi : x y / mulf x y >-> mul x y}. Proof. move=> x y; unlock mul; apply/eqmodP=> /=. rewrite equivfE /= /addf /= !numden_Ratio ?mulf_neq0 ?domP //. by rewrite mulrACA !equivf_r mulrACA. Qed. Canonical pi_mul_morph := PiMorph2 pi_mul. Definition invf x : dom := Ratio \d_x \n_x. Definition inv := lift_op1 type invf. Lemma pi_inv : {morph \pi : x / invf x >-> inv x}. Proof. move=> x; unlock inv; apply/eqmodP=> /=; rewrite equivfE /invf eq_sym. do 2?case: RatioP=> /= [/eqP|]; rewrite ?mul0r ?mul1r -?equivf_def ?numer0 ?reprK //. by move=> hx /eqP hx'; rewrite hx' eqxx in hx. by move=> /eqP ->; rewrite eqxx. Qed. Canonical pi_inv_morph := PiMorph1 pi_inv. Lemma addA : associative add. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE. rewrite /addf /= !numden_Ratio ?mulf_neq0 ?domP // !mulrDl. by rewrite !mulrA !addrA ![_ * _ * \d_x]mulrAC. Qed. Lemma addC : commutative add. Proof. by elim/quotW=> x; elim/quotW=> y; rewrite !piE /addf addrC [\d__ * _]mulrC. Qed. Lemma add0_l : left_id 0%:F add. Proof. elim/quotW=> x; rewrite !piE /addf !numden_Ratio ?oner_eq0 //. by rewrite mul0r mul1r mulr1 add0r Ratio_numden. Qed. Lemma addN_l : left_inverse 0%:F opp add. Proof. elim/quotW=> x; apply/eqP; rewrite piE /equivf. rewrite /addf /oppf !numden_Ratio ?(oner_eq0, mulf_neq0, domP) //. by rewrite mulr1 mulr0 mulNr addNr. Qed. (* fracions form an abelian group *) HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0_l addN_l. Lemma mulA : associative mul. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE. by rewrite /mulf !numden_Ratio ?mulf_neq0 ?domP // !mulrA. Qed. Lemma mulC : commutative mul. Proof. elim/quotW=> x; elim/quotW=> y; rewrite !piE /mulf. by rewrite [_ * (\d_x)]mulrC [_ * (\n_x)]mulrC. Qed. Lemma mul1_l : left_id 1%:F mul. Proof. elim/quotW=> x; rewrite !piE /mulf. by rewrite !numden_Ratio ?oner_eq0 // !mul1r Ratio_numden. Qed. Lemma mul_addl : left_distributive mul add. Proof. elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; apply/eqP. rewrite !piE /equivf /mulf /addf !numden_Ratio ?mulf_neq0 ?domP //; apply/eqP. rewrite !(mulrDr, mulrDl) (AC (3*(2*2)) (4*2*7*((1*3)*(6*5))))/=. by rewrite [X in _ + X](AC (3*(2*2)) (4*6*7*((1*3)*(2*5))))/=. Qed. Lemma nonzero1 : 1%:F != 0%:F :> type. Proof. by rewrite piE equivfE !numden_Ratio ?mul1r ?oner_eq0. Qed. (* fractions form a commutative ring *) HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build type mulA mulC mul1_l mul_addl nonzero1. Lemma mulV_l : forall a, a != 0%:F -> mul (inv a) a = 1%:F. Proof. elim/quotW=> x /=; rewrite !piE. rewrite /equivf !numden_Ratio ?oner_eq0 // mulr1 mulr0=> nx0. apply/eqmodP; rewrite /= equivfE. by rewrite !numden_Ratio ?(oner_eq0, mulf_neq0, domP) // !mulr1 mulrC. Qed. Lemma inv0 : inv 0%:F = 0%:F. Proof. rewrite !piE /invf !numden_Ratio ?oner_eq0 // /Ratio /insubd. do 2?case: insubP; rewrite //= ?eqxx ?oner_eq0 // => u _ hu _. by congr \pi; apply: val_inj; rewrite /= hu. Qed. (* fractions form a ring with explicit unit *) (* fractions form a field *) HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulV_l inv0. End FracField. End FracField. HB.export FracField. Arguments FracField.type R%_type. Notation "{ 'fraction' T }" := (FracField.type T). Notation equivf := (@FracField.equivf _). #[global] Hint Resolve denom_ratioP : core. Section FracFieldTheory. Import FracField. Variable R : idomainType. Lemma Ratio_numden (x : {ratio R}) : Ratio \n_x \d_x = x. Proof. exact: FracField.Ratio_numden. Qed. (* exporting the embedding from R to {fraction R} *) Local Notation tofrac := (@FracField.tofrac R). Local Notation "x %:F" := (tofrac x). Lemma tofrac_is_zmod_morphism: zmod_morphism tofrac. Proof. move=> p q /=; unlock tofrac. rewrite -[X in _ = _ + X]pi_opp -[RHS]pi_add. by rewrite /addf /oppf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1). Qed. #[deprecated(since="mathcomp 2.5.0", note="use `tofrac_is_zmod_morphism` instead")] Definition tofrac_is_additive := tofrac_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build R {fraction R} tofrac tofrac_is_zmod_morphism. Lemma tofrac_is_monoid_morphism: monoid_morphism tofrac. Proof. split=> [//|p q]; unlock tofrac; rewrite -[RHS]pi_mul. by rewrite /mulf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1). Qed. #[deprecated(since="mathcomp 2.5.0", note="use `tofrac_is_monoid_morphism` instead")] Definition tofrac_is_multiplicative := tofrac_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build R {fraction R} tofrac tofrac_is_monoid_morphism. (* tests *) Lemma tofrac0 : 0%:F = 0. Proof. exact: rmorph0. Qed. Lemma tofracN : {morph tofrac: x / - x}. Proof. exact: rmorphN. Qed. Lemma tofracD : {morph tofrac: x y / x + y}. Proof. exact: rmorphD. Qed. Lemma tofracB : {morph tofrac: x y / x - y}. Proof. exact: rmorphB. Qed. Lemma tofracMn n : {morph tofrac: x / x *+ n}. Proof. exact: rmorphMn. Qed. Lemma tofracMNn n : {morph tofrac: x / x *- n}. Proof. exact: rmorphMNn. Qed. Lemma tofrac1 : 1%:F = 1. Proof. exact: rmorph1. Qed. Lemma tofracM : {morph tofrac: x y / x * y}. Proof. exact: rmorphM. Qed. Lemma tofracXn n : {morph tofrac: x / x ^+ n}. Proof. exact: rmorphXn. Qed. Lemma tofrac_eq (p q : R): (p%:F == q%:F) = (p == q). Proof. apply/eqP/eqP=> [|->//]; unlock tofrac=> /eqmodP /eqP /=. by rewrite !numden_Ratio ?(oner_eq0, mul1r, mulr1). Qed. Lemma tofrac_eq0 (p : R): (p%:F == 0) = (p == 0). Proof. by rewrite tofrac_eq. Qed. End FracFieldTheory.
Equitable.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Defs /-! # Equitable functions This file defines equitable functions. A function `f` is equitable on a set `s` if `f a₁ ≤ f a₂ + 1` for all `a₁, a₂ ∈ s`. This is mostly useful when the codomain of `f` is `ℕ` or `ℤ` (or more generally a successor order). ## TODO `ℕ` can be replaced by any `SuccOrder` + `ConditionallyCompleteMonoid`, but we don't have the latter yet. -/ variable {α β : Type*} namespace Set /-- A set is equitable if no element value is more than one bigger than another. -/ def EquitableOn [LE β] [Add β] [One β] (s : Set α) (f : α → β) : Prop := ∀ ⦃a₁ a₂⦄, a₁ ∈ s → a₂ ∈ s → f a₁ ≤ f a₂ + 1 @[simp] theorem equitableOn_empty [LE β] [Add β] [One β] (f : α → β) : EquitableOn ∅ f := fun a _ ha => (Set.notMem_empty a ha).elim theorem equitableOn_iff_exists_le_le_add_one {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, ∀ a ∈ s, b ≤ f a ∧ f a ≤ b + 1 := by refine ⟨?_, fun ⟨b, hb⟩ x y hx hy => (hb x hx).2.trans (add_le_add_right (hb y hy).1 _)⟩ obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty · simp intro hs by_cases h : ∀ y ∈ s, f x ≤ f y · exact ⟨f x, fun y hy => ⟨h _ hy, hs hy hx⟩⟩ push_neg at h obtain ⟨w, hw, hwx⟩ := h refine ⟨f w, fun y hy => ⟨Nat.le_of_succ_le_succ ?_, hs hy hw⟩⟩ rw [(Nat.succ_le_of_lt hwx).antisymm (hs hx hw)] exact hs hx hy theorem equitableOn_iff_exists_image_subset_icc {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, f '' s ⊆ Icc b (b + 1) := by simpa only [image_subset_iff] using equitableOn_iff_exists_le_le_add_one theorem equitableOn_iff_exists_eq_eq_add_one {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, ∀ a ∈ s, f a = b ∨ f a = b + 1 := by simp_rw [equitableOn_iff_exists_le_le_add_one, Nat.le_and_le_add_one_iff] section LinearOrder variable [LinearOrder β] [Add β] [One β] {s : Set α} {f : α → β} @[simp] lemma not_equitableOn : ¬s.EquitableOn f ↔ ∃ a ∈ s, ∃ b ∈ s, f b + 1 < f a := by simp [EquitableOn] end LinearOrder section OrderedSemiring variable [Semiring β] [PartialOrder β] [IsOrderedRing β] theorem Subsingleton.equitableOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : s.EquitableOn f := fun i j hi hj => by rw [hs hi hj] exact le_add_of_nonneg_right zero_le_one theorem equitableOn_singleton (a : α) (f : α → β) : Set.EquitableOn {a} f := Set.subsingleton_singleton.equitableOn f end OrderedSemiring end Set open Set namespace Finset variable {s : Finset α} {f : α → ℕ} {a : α} theorem equitableOn_iff_le_le_add_one : EquitableOn (s : Set α) f ↔ ∀ a ∈ s, (∑ i ∈ s, f i) / s.card ≤ f a ∧ f a ≤ (∑ i ∈ s, f i) / s.card + 1 := by rw [Set.equitableOn_iff_exists_le_le_add_one] refine ⟨?_, fun h => ⟨_, h⟩⟩ rintro ⟨b, hb⟩ by_cases h : ∀ a ∈ s, f a = b + 1 · intro a ha rw [h _ ha, sum_const_nat h, Nat.mul_div_cancel_left _ (card_pos.2 ⟨a, ha⟩)] exact ⟨le_rfl, Nat.le_succ _⟩ push_neg at h obtain ⟨x, hx₁, hx₂⟩ := h suffices h : b = (∑ i ∈ s, f i) / s.card by simp_rw [← h] apply hb symm refine Nat.div_eq_of_lt_le (le_trans (by simp [mul_comm]) (sum_le_sum fun a ha => (hb a ha).1)) ((sum_lt_sum (fun a ha => (hb a ha).2) ⟨_, hx₁, (hb _ hx₁).2.lt_of_ne hx₂⟩).trans_le ?_) rw [mul_comm, sum_const_nat] exact fun _ _ => rfl theorem EquitableOn.le (h : EquitableOn (s : Set α) f) (ha : a ∈ s) : (∑ i ∈ s, f i) / s.card ≤ f a := (equitableOn_iff_le_le_add_one.1 h a ha).1 theorem EquitableOn.le_add_one (h : EquitableOn (s : Set α) f) (ha : a ∈ s) : f a ≤ (∑ i ∈ s, f i) / s.card + 1 := (equitableOn_iff_le_le_add_one.1 h a ha).2 theorem equitableOn_iff : EquitableOn (s : Set α) f ↔ ∀ a ∈ s, f a = (∑ i ∈ s, f i) / s.card ∨ f a = (∑ i ∈ s, f i) / s.card + 1 := by simp_rw [equitableOn_iff_le_le_add_one, Nat.le_and_le_add_one_iff] end Finset
Subfield.lean
/- Copyright (c) 2023 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Algebra.Field.Subfield.Basic import Mathlib.Data.W.Cardinal import Mathlib.Tactic.FinCases /-! # Cardinality of the division ring generated by a set `Subfield.cardinalMk_closure_le_max`: the cardinality of the (sub-)division ring generated by a set is bounded by the cardinality of the set unless it is finite. The method used to prove this (via `WType`) can be easily generalized to other algebraic structures, but those cardinalities can usually be obtained by other means, using some explicit universal objects. -/ universe u variable {α : Type u} (s : Set α) namespace Subfield private abbrev Operands : Fin 6 ⊕ s → Type | .inl 0 => Bool -- add | .inl 1 => Bool -- mul | .inl 2 => Unit -- neg | .inl 3 => Unit -- inv | .inl 4 => Empty -- zero | .inl 5 => Empty -- one | .inr _ => Empty -- s variable [DivisionRing α] private def operate : (Σ n, Operands s n → closure s) → closure s | ⟨.inl 0, f⟩ => f false + f true | ⟨.inl 1, f⟩ => f false * f true | ⟨.inl 2, f⟩ => - f () | ⟨.inl 3, f⟩ => (f ())⁻¹ | ⟨.inl 4, _⟩ => 0 | ⟨.inl 5, _⟩ => 1 | ⟨.inr a, _⟩ => ⟨a, subset_closure a.prop⟩ private def rangeOfWType : Subfield (closure s) where carrier := Set.range (WType.elim _ <| operate s) add_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 0) (Bool.rec x y), by rfl⟩ mul_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 1) (Bool.rec x y), by rfl⟩ neg_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 2) fun _ ↦ x, rfl⟩ inv_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 3) fun _ ↦ x, rfl⟩ zero_mem' := ⟨WType.mk (.inl 4) Empty.rec, rfl⟩ one_mem' := ⟨WType.mk (.inl 5) Empty.rec, rfl⟩ private lemma rangeOfWType_eq_top : rangeOfWType s = ⊤ := top_le_iff.mp fun a _ ↦ by rw [← SetLike.mem_coe, ← Subtype.val_injective.mem_set_image] change ↑a ∈ map (closure s).subtype _ refine closure_le.mpr (fun a ha ↦ ?_) a.prop exact ⟨⟨a, subset_closure ha⟩, ⟨WType.mk (.inr ⟨a, ha⟩) Empty.rec, rfl⟩, rfl⟩ private lemma surjective_ofWType : Function.Surjective (WType.elim _ <| operate s) := by rw [← Set.range_eq_univ] exact SetLike.coe_set_eq.mpr (rangeOfWType_eq_top s) open Cardinal lemma cardinalMk_closure_le_max : #(closure s) ≤ max #s ℵ₀ := (Cardinal.mk_le_of_surjective <| surjective_ofWType s).trans <| by convert WType.cardinalMk_le_max_aleph0_of_finite' using 1 · rw [lift_uzero, mk_sum, lift_uzero] have : lift.{u,0} #(Fin 6) < ℵ₀ := lift_lt_aleph0.mpr (lt_aleph0_of_finite _) obtain h|h := lt_or_ge #s ℵ₀ · rw [max_eq_right h.le, max_eq_right] exact (add_lt_aleph0 this h).le · rw [max_eq_left h, add_eq_right h (this.le.trans h), max_eq_left h] rintro (n|_) · fin_cases n <;> (dsimp only [id_eq]; infer_instance) infer_instance lemma cardinalMk_closure [Infinite s] : #(closure s) = #s := ((cardinalMk_closure_le_max s).trans_eq <| max_eq_left <| aleph0_le_mk s).antisymm (mk_le_mk_of_subset subset_closure) end Subfield
Orthogonal.lean
/- Copyright (c) 2018 Andreas Swerdlow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andreas Swerdlow, Kexing Ying -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.LinearAlgebra.BilinearForm.Properties /-! # Bilinear form This file defines orthogonal bilinear forms. ## Notations Given any term `B` of type `BilinForm`, due to a coercion, can use the notation `B x y` to refer to the function field, ie. `B x y = B.bilin x y`. In this file we use the following type variables: - `M`, `M'`, ... are modules over the commutative semiring `R`, - `M₁`, `M₁'`, ... are modules over the commutative ring `R₁`, - `V`, ... is a vector space over the field `K`. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ open LinearMap (BilinForm) open Module universe u v w variable {R : Type*} {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₁ : Type*} {M₁ : Type*} [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] variable {V : Type*} {K : Type*} [Field K] [AddCommGroup V] [Module K V] variable {B : BilinForm R M} {B₁ : BilinForm R₁ M₁} namespace LinearMap namespace BilinForm /-- The proposition that two elements of a bilinear form space are orthogonal. For orthogonality of an indexed set of elements, use `BilinForm.iIsOrtho`. -/ def IsOrtho (B : BilinForm R M) (x y : M) : Prop := B x y = 0 theorem isOrtho_def {B : BilinForm R M} {x y : M} : B.IsOrtho x y ↔ B x y = 0 := Iff.rfl theorem isOrtho_zero_left (x : M) : IsOrtho B (0 : M) x := LinearMap.isOrtho_zero_left B x theorem isOrtho_zero_right (x : M) : IsOrtho B x (0 : M) := zero_right x theorem ne_zero_of_not_isOrtho_self {B : BilinForm K V} (x : V) (hx₁ : ¬B.IsOrtho x x) : x ≠ 0 := fun hx₂ => hx₁ (hx₂.symm ▸ isOrtho_zero_left _) theorem IsRefl.ortho_comm (H : B.IsRefl) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x := ⟨eq_zero H, eq_zero H⟩ theorem IsAlt.ortho_comm (H : B₁.IsAlt) {x y : M₁} : IsOrtho B₁ x y ↔ IsOrtho B₁ y x := LinearMap.IsAlt.ortho_comm H theorem IsSymm.ortho_comm (H : B.IsSymm) {x y : M} : IsOrtho B x y ↔ IsOrtho B y x := LinearMap.IsSymm.ortho_comm (isSymm_iff.1 H) /-- A set of vectors `v` is orthogonal with respect to some bilinear form `B` if and only if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use `BilinForm.IsOrtho` -/ def iIsOrtho {n : Type w} (B : BilinForm R M) (v : n → M) : Prop := B.IsOrthoᵢ v theorem iIsOrtho_def {n : Type w} {B : BilinForm R M} {v : n → M} : B.iIsOrtho v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 := Iff.rfl section variable {R₄ M₄ : Type*} [CommRing R₄] [IsDomain R₄] variable [AddCommGroup M₄] [Module R₄ M₄] {G : BilinForm R₄ M₄} @[simp] theorem isOrtho_smul_left {x y : M₄} {a : R₄} (ha : a ≠ 0) : IsOrtho G (a • x) y ↔ IsOrtho G x y := by dsimp only [IsOrtho] rw [map_smul] simp only [LinearMap.smul_apply, smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp] exact fun a ↦ (ha a).elim @[simp] theorem isOrtho_smul_right {x y : M₄} {a : R₄} (ha : a ≠ 0) : IsOrtho G x (a • y) ↔ IsOrtho G x y := by dsimp only [IsOrtho] rw [map_smul] simp only [smul_eq_mul, mul_eq_zero, or_iff_right_iff_imp] exact fun a ↦ (ha a).elim /-- A set of orthogonal vectors `v` with respect to some bilinear form `B` is linearly independent if for all `i`, `B (v i) (v i) ≠ 0`. -/ theorem linearIndependent_of_iIsOrtho {n : Type w} {B : BilinForm K V} {v : n → V} (hv₁ : B.iIsOrtho v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K v := by classical rw [linearIndependent_iff'] intro s w hs i hi have : B (s.sum fun i : n => w i • v i) (v i) = 0 := by rw [hs, zero_left] have hsum : (s.sum fun j : n => w j * B (v j) (v i)) = w i * B (v i) (v i) := by apply Finset.sum_eq_single_of_mem i hi intro j _ hij rw [iIsOrtho_def.1 hv₁ _ _ hij, mul_zero] simp_rw [sum_left, smul_left, hsum] at this exact eq_zero_of_ne_zero_of_mul_right_eq_zero (hv₂ i) this end section Orthogonal /-- The orthogonal complement of a submodule `N` with respect to some bilinear form is the set of elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B y x = 0`. Note that for general (neither symmetric nor antisymmetric) bilinear forms this definition has a chirality; in addition to this "right" orthogonal complement one could define a "left" orthogonal complement for which, for all `y` in `N`, `B x y = 0`. This variant definition is not currently provided in mathlib. -/ def orthogonal (B : BilinForm R M) (N : Submodule R M) : Submodule R M where carrier := { m | ∀ n ∈ N, IsOrtho B n m } zero_mem' x _ := isOrtho_zero_right x add_mem' {x y} hx hy n hn := by rw [IsOrtho, add_right, show B n x = 0 from hx n hn, show B n y = 0 from hy n hn, zero_add] smul_mem' c x hx n hn := by rw [IsOrtho, smul_right, show B n x = 0 from hx n hn, mul_zero] variable {N L : Submodule R M} @[simp] theorem mem_orthogonal_iff {N : Submodule R M} {m : M} : m ∈ B.orthogonal N ↔ ∀ n ∈ N, IsOrtho B n m := Iff.rfl @[simp] lemma orthogonal_bot : B.orthogonal ⊥ = ⊤ := by ext; simp [IsOrtho] theorem orthogonal_le (h : N ≤ L) : B.orthogonal L ≤ B.orthogonal N := fun _ hn l hl => hn l (h hl) theorem le_orthogonal_orthogonal (b : B.IsRefl) : N ≤ B.orthogonal (B.orthogonal N) := fun n hn _ hm => b _ _ (hm n hn) lemma orthogonal_top_eq_ker (hB : B.IsRefl) : B.orthogonal ⊤ = LinearMap.ker B := by ext; simp [LinearMap.BilinForm.IsOrtho, LinearMap.ext_iff, hB.eq_iff] lemma orthogonal_top_eq_bot (hB : B.Nondegenerate) (hB₀ : B.IsRefl) : B.orthogonal ⊤ = ⊥ := (Submodule.eq_bot_iff _).mpr fun _ hx ↦ hB _ fun y ↦ hB₀ _ _ <| hx y Submodule.mem_top -- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0` theorem span_singleton_inf_orthogonal_eq_bot {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : (K ∙ x) ⊓ B.orthogonal (K ∙ x) = ⊥ := by rw [← Finset.coe_singleton] refine eq_bot_iff.2 fun y h => ?_ obtain ⟨μ, -, rfl⟩ := Submodule.mem_span_finset.1 h.1 have := h.2 x ?_ · rw [Finset.sum_singleton] at this ⊢ suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot] change B x (μ x • x) = 0 at this rw [smul_right] at this exact eq_zero_of_ne_zero_of_mul_right_eq_zero hx this · rw [Submodule.mem_span] exact fun _ hp => hp <| Finset.mem_singleton_self _ -- ↓ This lemma only applies in fields since we use the `mul_eq_zero` theorem orthogonal_span_singleton_eq_toLin_ker {B : BilinForm K V} (x : V) : B.orthogonal (K ∙ x) = LinearMap.ker (LinearMap.BilinForm.toLinHomAux₁ B x) := by ext y simp_rw [mem_orthogonal_iff, LinearMap.mem_ker, Submodule.mem_span_singleton] constructor · exact fun h => h x ⟨1, one_smul _ _⟩ · rintro h _ ⟨z, rfl⟩ rw [IsOrtho, smul_left, mul_eq_zero] exact Or.intro_right _ h theorem span_singleton_sup_orthogonal_eq_top {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : (K ∙ x) ⊔ B.orthogonal (K ∙ x) = ⊤ := by rw [orthogonal_span_singleton_eq_toLin_ker] exact LinearMap.span_singleton_sup_ker_eq_top _ hx /-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x` is complement to its orthogonal complement. -/ theorem isCompl_span_singleton_orthogonal {B : BilinForm K V} {x : V} (hx : ¬B.IsOrtho x x) : IsCompl (K ∙ x) (B.orthogonal <| K ∙ x) := { disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot hx codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx } end Orthogonal variable {M₂' : Type*} variable [AddCommMonoid M₂'] [Module R M₂'] /-- The restriction of a reflexive bilinear form `B` onto a submodule `W` is nondegenerate if `Disjoint W (B.orthogonal W)`. -/ theorem nondegenerate_restrict_of_disjoint_orthogonal (B : BilinForm R₁ M₁) (b : B.IsRefl) {W : Submodule R₁ M₁} (hW : Disjoint W (B.orthogonal W)) : (B.restrict W).Nondegenerate := by rintro ⟨x, hx⟩ b₁ rw [Submodule.mk_eq_zero, ← Submodule.mem_bot R₁] refine hW.le_bot ⟨hx, fun y hy => ?_⟩ specialize b₁ ⟨y, hy⟩ simp only [restrict_apply, domRestrict_apply] at b₁ exact isOrtho_def.mpr (b x y b₁) /-- An orthogonal basis with respect to a nondegenerate bilinear form has no self-orthogonal elements. -/ theorem iIsOrtho.not_isOrtho_basis_self_of_nondegenerate {n : Type w} [Nontrivial R] {B : BilinForm R M} {v : Basis n R M} (h : B.iIsOrtho v) (hB : B.Nondegenerate) (i : n) : ¬B.IsOrtho (v i) (v i) := by intro ho refine v.ne_zero i (hB (v i) fun m => ?_) obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m rw [Basis.repr_symm_apply, Finsupp.linearCombination_apply, Finsupp.sum, sum_right] apply Finset.sum_eq_zero rintro j - rw [smul_right] convert mul_zero (vi j) using 2 obtain rfl | hij := eq_or_ne i j · exact ho · exact h hij /-- Given an orthogonal basis with respect to a bilinear form, the bilinear form is nondegenerate iff the basis has no elements which are self-orthogonal. -/ theorem iIsOrtho.nondegenerate_iff_not_isOrtho_basis_self {n : Type w} [Nontrivial R] [NoZeroDivisors R] (B : BilinForm R M) (v : Basis n R M) (hO : B.iIsOrtho v) : B.Nondegenerate ↔ ∀ i, ¬B.IsOrtho (v i) (v i) := by refine ⟨hO.not_isOrtho_basis_self_of_nondegenerate, fun ho m hB => ?_⟩ obtain ⟨vi, rfl⟩ := v.repr.symm.surjective m rw [LinearEquiv.map_eq_zero_iff] ext i rw [Finsupp.zero_apply] specialize hB (v i) simp_rw [Basis.repr_symm_apply, Finsupp.linearCombination_apply, Finsupp.sum, sum_left, smul_left] at hB rw [Finset.sum_eq_single i] at hB · exact eq_zero_of_ne_zero_of_mul_right_eq_zero (ho i) hB · intro j _ hij convert mul_zero (vi j) using 2 exact hO hij · intro hi convert zero_mul (M₀ := R) _ using 2 exact Finsupp.notMem_support_iff.mp hi section theorem toLin_restrict_ker_eq_inf_orthogonal (B : BilinForm K V) (W : Subspace K V) (b : B.IsRefl) : (LinearMap.ker <| B.domRestrict W).map W.subtype = (W ⊓ B.orthogonal ⊤ : Subspace K V) := by ext x; constructor <;> intro hx · rcases hx with ⟨⟨x, hx⟩, hker, rfl⟩ erw [LinearMap.mem_ker] at hker constructor · simp [hx] · intro y _ rw [IsOrtho, b] change (B.domRestrict W) ⟨x, hx⟩ y = 0 rw [hker] rfl · simp_rw [Submodule.mem_map, LinearMap.mem_ker] refine ⟨⟨x, hx.1⟩, ?_, rfl⟩ ext y change B x y = 0 rw [b] exact hx.2 _ Submodule.mem_top theorem toLin_restrict_range_dualCoannihilator_eq_orthogonal (B : BilinForm K V) (W : Subspace K V) : (LinearMap.range (B.domRestrict W)).dualCoannihilator = B.orthogonal W := by ext x; constructor <;> rw [mem_orthogonal_iff] <;> intro hx · intro y hy rw [Submodule.mem_dualCoannihilator] at hx exact hx (B.domRestrict W ⟨y, hy⟩) ⟨⟨y, hy⟩, rfl⟩ · rw [Submodule.mem_dualCoannihilator] rintro _ ⟨⟨w, hw⟩, rfl⟩ exact hx w hw lemma ker_restrict_eq_of_codisjoint {p q : Submodule R M} (hpq : Codisjoint p q) {B : LinearMap.BilinForm R M} (hB : ∀ x ∈ p, ∀ y ∈ q, B x y = 0) : LinearMap.ker (B.restrict p) = (LinearMap.ker B).comap p.subtype := by ext ⟨z, hz⟩ simp only [LinearMap.mem_ker, Submodule.mem_comap, Submodule.coe_subtype] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · ext w obtain ⟨x, y, hx, hy, rfl⟩ := Submodule.codisjoint_iff_exists_add_eq.mp hpq w simpa [hB z hz y hy] using LinearMap.congr_fun h ⟨x, hx⟩ · ext ⟨x, hx⟩ simpa using LinearMap.congr_fun h x lemma inf_orthogonal_self_le_ker_restrict {W : Submodule R M} (b₁ : B.IsRefl) : W ⊓ B.orthogonal W ≤ (LinearMap.ker <| B.restrict W).map W.subtype := by rintro v ⟨hv : v ∈ W, hv' : v ∈ B.orthogonal W⟩ simp only [Submodule.mem_map, mem_ker, restrict_apply, Submodule.coe_subtype, Subtype.exists, exists_and_left, exists_prop, exists_eq_right_right] refine ⟨?_, hv⟩ ext ⟨w, hw⟩ exact b₁ w v <| hv' w hw variable [FiniteDimensional K V] open Module Submodule variable {B : BilinForm K V} theorem finrank_add_finrank_orthogonal (b₁ : B.IsRefl) (W : Submodule K V) : finrank K W + finrank K (B.orthogonal W) = finrank K V + finrank K (W ⊓ B.orthogonal ⊤ : Subspace K V) := by rw [← toLin_restrict_ker_eq_inf_orthogonal _ _ b₁, ← toLin_restrict_range_dualCoannihilator_eq_orthogonal _ _, finrank_map_subtype_eq] conv_rhs => rw [← @Subspace.finrank_add_finrank_dualCoannihilator_eq K V _ _ _ _ (LinearMap.range (B.domRestrict W)), add_comm, ← add_assoc, add_comm (finrank K (LinearMap.ker (B.domRestrict W))), LinearMap.finrank_range_add_finrank_ker] lemma finrank_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) : finrank K (B.orthogonal W) = finrank K V - finrank K W := by have := finrank_add_finrank_orthogonal hB₀ (W := W) rw [B.orthogonal_top_eq_bot hB hB₀, inf_bot_eq, finrank_bot, add_zero] at this omega lemma orthogonal_orthogonal (hB : B.Nondegenerate) (hB₀ : B.IsRefl) (W : Submodule K V) : B.orthogonal (B.orthogonal W) = W := by apply (eq_of_le_of_finrank_le (LinearMap.BilinForm.le_orthogonal_orthogonal hB₀) _).symm simp only [finrank_orthogonal hB hB₀] omega variable {W : Submodule K V} lemma isCompl_orthogonal_iff_disjoint (hB₀ : B.IsRefl) : IsCompl W (B.orthogonal W) ↔ Disjoint W (B.orthogonal W) := by refine ⟨IsCompl.disjoint, fun h ↦ ⟨h, ?_⟩⟩ rw [codisjoint_iff] apply (eq_top_of_finrank_eq <| (finrank_le _).antisymm _) calc finrank K V ≤ finrank K V + finrank K ↥(W ⊓ B.orthogonal ⊤) := le_self_add _ ≤ finrank K ↥(W ⊔ B.orthogonal W) + finrank K ↥(W ⊓ B.orthogonal W) := ?_ _ ≤ finrank K ↥(W ⊔ B.orthogonal W) := by simp [h.eq_bot] rw [finrank_sup_add_finrank_inf_eq, finrank_add_finrank_orthogonal hB₀ W] /-- A subspace is complement to its orthogonal complement with respect to some reflexive bilinear form if that bilinear form restricted on to the subspace is nondegenerate. -/ theorem isCompl_orthogonal_of_restrict_nondegenerate (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) : IsCompl W (B.orthogonal W) := by have : W ⊓ B.orthogonal W = ⊥ := by rw [eq_bot_iff] intro x hx obtain ⟨hx₁, hx₂⟩ := mem_inf.1 hx refine Subtype.mk_eq_mk.1 (b₂ ⟨x, hx₁⟩ ?_) rintro ⟨n, hn⟩ simp only [restrict_apply, domRestrict_apply] exact b₁ n x (b₁ x n (b₁ n x (hx₂ n hn))) refine IsCompl.of_eq this (eq_top_of_finrank_eq <| (finrank_le _).antisymm ?_) conv_rhs => rw [← add_zero (finrank K _)] rw [← finrank_bot K V, ← this, finrank_sup_add_finrank_inf_eq, finrank_add_finrank_orthogonal b₁] exact le_self_add /-- A subspace is complement to its orthogonal complement with respect to some reflexive bilinear form if and only if that bilinear form restricted on to the subspace is nondegenerate. -/ theorem restrict_nondegenerate_iff_isCompl_orthogonal (b₁ : B.IsRefl) : (B.restrict W).Nondegenerate ↔ IsCompl W (B.orthogonal W) := ⟨fun b₂ => isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂, fun h => B.nondegenerate_restrict_of_disjoint_orthogonal b₁ h.1⟩ lemma orthogonal_eq_top_iff (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) : B.orthogonal W = ⊤ ↔ W = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩ have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).inf_eq_bot rwa [h, inf_top_eq] at this lemma eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.orthogonal W = ⊥) : W = ⊤ := by have := (B.isCompl_orthogonal_of_restrict_nondegenerate b₁ b₂).sup_eq_top rwa [b₃, sup_bot_eq] at this lemma orthogonal_eq_bot_iff (b₁ : B.IsRefl) (b₂ : (B.restrict W).Nondegenerate) (b₃ : B.Nondegenerate) : B.orthogonal W = ⊥ ↔ W = ⊤ := by refine ⟨eq_top_of_restrict_nondegenerate_of_orthogonal_eq_bot b₁ b₂, fun h ↦ ?_⟩ rw [h, eq_bot_iff] exact fun x hx ↦ b₃ x fun y ↦ b₁ y x <| by simpa using hx y end /-! We note that we cannot use `BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` for the lemma below since the below lemma does not require `V` to be finite dimensional. However, `BilinForm.restrict_nondegenerate_iff_isCompl_orthogonal` does not require `B` to be nondegenerate on the whole space. -/ /-- The restriction of a reflexive, non-degenerate bilinear form on the orthogonal complement of the span of a singleton is also non-degenerate. -/ theorem restrict_nondegenerate_orthogonal_spanSingleton (B : BilinForm K V) (b₁ : B.Nondegenerate) (b₂ : B.IsRefl) {x : V} (hx : ¬B.IsOrtho x x) : Nondegenerate <| B.restrict <| B.orthogonal (K ∙ x) := by refine fun m hm => Submodule.coe_eq_zero.1 (b₁ m.1 fun n => ?_) have : n ∈ (K ∙ x) ⊔ B.orthogonal (K ∙ x) := (span_singleton_sup_orthogonal_eq_top hx).symm ▸ Submodule.mem_top rcases Submodule.mem_sup.1 this with ⟨y, hy, z, hz, rfl⟩ specialize hm ⟨z, hz⟩ rw [restrict] at hm erw [add_right, show B m.1 y = 0 by rw [b₂]; exact m.2 y hy, hm, add_zero] end BilinForm end LinearMap
Union.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.Algebra.Module.Submodule.Lattice import Mathlib.Data.Set.Card import Mathlib.LinearAlgebra.Dual.Defs import Mathlib.Tactic.Module /-! # Unions of `Submodule`s This file is a home for results about unions of submodules. ## Main results: * `Submodule.iUnion_ssubset_of_forall_ne_top_of_card_lt`: a finite union of proper submodules is a proper subset, provided the coefficients are a sufficiently large field. -/ open Function Set variable {ι K M : Type*} [Field K] [AddCommGroup M] [Module K M] lemma Submodule.iUnion_ssubset_of_forall_ne_top_of_card_lt (s : Finset ι) (p : ι → Submodule K M) (h₁ : ∀ i, p i ≠ ⊤) (h₂ : s.card < ENat.card K) : ⋃ i ∈ s, (p i : Set M) ⊂ univ := by -- Following https://mathoverflow.net/a/14241 classical induction s using Finset.induction_on with | empty => simp | insert j s hj hj' => simp only [ssubset_univ_iff] at hj' ⊢ rcases s.eq_empty_or_nonempty with rfl | hs · simpa [← SetLike.coe_ne_coe] using h₁ j replace h₂ : s.card + 1 < ENat.card K := by simpa [Finset.card_insert_of_notMem hj] using h₂ specialize hj' (lt_trans ENat.natCast_lt_succ h₂) contrapose! hj' replace hj' : (p j : Set M) ∪ (⋃ i ∈ s, p i) = univ := by simpa only [Finset.mem_insert, iUnion_iUnion_eq_or_left] using hj' suffices (p j : Set M) ⊆ ⋃ i ∈ s, p i by rwa [union_eq_right.mpr this] at hj' intro x (hx : x ∈ p j) rcases eq_or_ne x 0 with rfl | hx₀ · simpa using hs obtain ⟨y, hy⟩ : ∃ y, y ∉ p j := by specialize h₁ j; contrapose! h₁; ext; simp [h₁] have hy₀ : y ≠ 0 := by aesop let sxy := {x + t • y | (t : K) (ht : t ≠ 0)} have hsxy : sxy ⊆ ⋃ i ∈ s, p i := by suffices Disjoint sxy (p j) from this.subset_right_of_subset_union <| hj' ▸ sxy.subset_univ rw [Set.disjoint_iff] rintro - ⟨⟨t, ht₀, rfl⟩, ht : x + t • y ∈ p j⟩ rw [(p j).add_mem_iff_right hx, (p j).smul_mem_iff ht₀] at ht contradiction obtain ⟨k, hk, t₁, t₂, ht, ht₁, ht₂⟩ : ∃ᵉ (k ∈ s) (t₁ : K) (t₂ : K), t₁ ≠ t₂ ∧ x + t₁ • y ∈ p k ∧ x + t₂ • y ∈ p k := by suffices ∃ᵉ (k ∈ s) (z₁ ∈ sxy) (z₂ ∈ sxy), z₁ ≠ z₂ ∧ z₁ ∈ p k ∧ z₂ ∈ p k by obtain ⟨k, hk, -, ⟨t₁, -, rfl⟩, -, ⟨t₂, -, rfl⟩, htne, ht₁, ht₂⟩ := this exact ⟨k, hk, t₁, t₂, by aesop, ht₁, ht₂⟩ choose f hf using fun z : sxy ↦ mem_iUnion.mp (hsxy z.property) have hf' : MapsTo f univ s := fun z _ ↦ by specialize hf z; aesop suffices ∃ z₁ z₂, z₁ ≠ z₂ ∧ f z₁ = f z₂ by obtain ⟨z₁, z₂, hne, heq⟩ := this exact ⟨f z₁, hf' (mem_univ _), z₁, z₁.property, z₂, z₂.property, Subtype.coe_ne_coe.mpr hne, by specialize hf z₁; aesop, by specialize hf z₂; aesop⟩ have key : s.card < sxy.encard := by refine lt_of_add_lt_add_right <| lt_of_lt_of_le h₂ ?_ have : Injective (fun t : K ↦ x + t • y) := fun t₁ t₂ ht ↦ smul_left_injective K hy₀ <| by simpa using ht have aux : sxy = ((fun t : K ↦ x + t • y) '' {t | t ≠ 0}) := by ext; simp [sxy] rw [aux, this.encard_image, encard_ne_add_one] obtain ⟨z₁, -, z₂, -, h⟩ := exists_ne_map_eq_of_encard_lt_of_maps_to (by simpa) hf' exact ⟨z₁, z₂, h⟩ replace ht : y ∈ p k := by have : (t₁ - t₂) • y ∈ p k := by convert sub_mem ht₁ ht₂ using 1; module refine ((p k).smul_mem_iff ?_).mp this rwa [sub_ne_zero] replace ht : x ∈ p k := by convert sub_mem ht₁ ((p k).smul_mem t₁ ht); simp simpa using ⟨k, hk, ht⟩ variable [Finite ι] [Infinite K] lemma Submodule.exists_forall_notMem_of_forall_ne_top (p : ι → Submodule K M) (h : ∀ i, p i ≠ ⊤) : ∃ x, ∀ i, x ∉ p i := by let _i : Fintype ι := Fintype.ofFinite ι suffices ⋃ i, (p i : Set M) ⊂ univ by simpa [ssubset_univ_iff, iUnion_eq_univ_iff] using this simpa using iUnion_ssubset_of_forall_ne_top_of_card_lt Finset.univ p h (by simp) lemma Module.Dual.exists_forall_ne_zero_of_forall_exists (f : ι → Dual K M) (h : ∀ i, ∃ x, f i x ≠ 0) : ∃ x, ∀ i, f i x ≠ 0 := by let p i := LinearMap.ker (f i) replace h i : p i ≠ ⊤ := by specialize h i; aesop obtain ⟨x, hx⟩ := Submodule.exists_forall_notMem_of_forall_ne_top p h exact ⟨x, by simpa [p] using hx⟩ /-- A convenience variation of `Module.Dual.exists_forall_ne_zero_of_forall_exists` where we are concerned only about behaviour on a fixed submodule. -/ lemma Module.Dual.exists_forall_mem_ne_zero_of_forall_exists (p : Submodule K M) (f : ι → Dual K M) (h : ∀ i, ∃ x ∈ p, f i x ≠ 0) : ∃ x ∈ p, ∀ i, f i x ≠ 0 := by let f' (i : ι) : Dual K p := (f i).domRestrict p replace h (i : ι) : ∃ x : p, f' i x ≠ 0 := by obtain ⟨x, hxp, hx₀⟩ := h i; exact ⟨⟨x, hxp⟩, hx₀⟩ obtain ⟨⟨x, hxp⟩, hx₀⟩ := exists_forall_ne_zero_of_forall_exists f' h exact ⟨x, hxp, hx₀⟩
ssrnat.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From Corelib Require Import PosDef. From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype. #[export] Set Warnings "-overwriting-delimiting-key". (* remove above line when requiring Rocq >= 9.0 *) (******************************************************************************) (* A version of arithmetic on nat (natural numbers) that is better suited to *) (* small scale reflection than the Coq Arith library. It contains an *) (* extensive equational theory (including, e.g., the AGM inequality), as well *) (* as a congruence tactic. *) (* The following operations and notations are provided: *) (* *) (* successor and predecessor *) (* n.+1, n.+2, n.+3, n.+4 and n.-1, n.-2 *) (* this frees the names "S" and "pred" *) (* *) (* basic arithmetic *) (* m + n, m - n, m * n *) (* Important: m - n denotes TRUNCATED subtraction: m - n = 0 if m <= n. *) (* The definitions use simpl never to prevent undesirable computation *) (* during simplification, but remain compatible with the ones provided in *) (* the Coq.Init.Peano prelude. *) (* For computation, a module NatTrec rebinds all arithmetic notations *) (* to less convenient but also less inefficient tail-recursive functions; *) (* the auxiliary functions used by these versions are flagged with %Nrec. *) (* Also, there is support for input and output of large nat values. *) (* Num 3 082 241 inputs the number 3082241 *) (* [Num of n] outputs the value n *) (* There are coercions num >-> BinNat.N >-> nat; ssrnat rebinds the scope *) (* delimiter for BinNat.N to %num, as it uses the shorter %N for its own *) (* notations (Peano notations are flagged with %coq_nat). *) (* *) (* doubling, halving, and parity *) (* n.*2, n./2, odd n, uphalf n, with uphalf n = n.+1./2 *) (* bool coerces to nat so we can write, e.g., n = odd n + n./2.*2. *) (* *) (* iteration *) (* iter n f x0 == f ( .. (f x0)) *) (* iteri n g x0 == g n.-1 (g ... (g 0 x0)) *) (* iterop n op x x0 == op x (... op x x) (n x's) or x0 if n = 0 *) (* *) (* exponentiation, factorial *) (* m ^ n, n`! *) (* m ^ 1 is convertible to m, and m ^ 2 to m * m *) (* *) (* comparison *) (* m <= n, m < n, m >= n, m > n, m == n, m <= n <= p, etc., *) (* comparisons are BOOLEAN operators, and m == n is the generic eqType *) (* operation. *) (* Most compatibility lemmas are stated as boolean equalities; this keeps *) (* the size of the library down. All the inequalities refer to the same *) (* constant "leq"; in particular m < n is identical to m.+1 <= n. *) (* *) (* -> patterns for contextual rewriting: *) (* leqLHS := (X in (X <= _)%N)%pattern *) (* leqRHS := (X in (_ <= X)%N)%pattern *) (* ltnLHS := (X in (X < _)%N)%pattern *) (* ltnRHS := (X in (_ < X)%N)%pattern *) (* *) (* conditionally strict inequality `leqif' *) (* m <= n ?= iff condition == (m <= n) and ((m == n) = condition) *) (* This is actually a pair of boolean equalities, so rewriting with an *) (* `leqif' lemma can affect several kinds of comparison. The transitivity *) (* lemma for leqif aggregates the conditions, allowing for arguments of *) (* the form ``m <= n <= p <= m, so equality holds throughout''. *) (* *) (* maximum and minimum *) (* maxn m n, minn m n *) (* Note that maxn m n = m + (n - m), due to the truncating subtraction. *) (* Absolute difference (linear distance) between nats is defined in the int *) (* library (in the int.IntDist sublibrary), with the syntax `|m - n|. The *) (* '-' in this notation is the signed integer difference. *) (* *) (* countable choice *) (* ex_minn : forall P : pred nat, (exists n, P n) -> nat *) (* This returns the smallest n such that P n holds. *) (* ex_maxn : forall (P : pred nat) m, *) (* (exists n, P n) -> (forall n, P n -> n <= m) -> nat *) (* This returns the largest n such that P n holds (given an explicit upper *) (* bound). *) (* *) (* This file adds the following suffix conventions to those documented in *) (* ssrbool.v and eqtype.v: *) (* A (infix) -- conjunction, as in *) (* ltn_neqAle : (m < n) = (m != n) && (m <= n). *) (* B -- subtraction, as in subBn : (m - n) - p = m - (n + p). *) (* D -- addition, as in mulnDl : (m + n) * p = m * p + n * p. *) (* M -- multiplication, as in expnMn : (m * n) ^ p = m ^ p * n ^ p. *) (* p (prefix) -- positive, as in *) (* eqn_pmul2l : m > 0 -> (m * n1 == m * n2) = (n1 == n2). *) (* P -- greater than 1, as in *) (* ltn_Pmull : 1 < n -> 0 < m -> m < n * m. *) (* S -- successor, as in addSn : n.+1 + m = (n + m).+1. *) (* V (infix) -- disjunction, as in *) (* leq_eqVlt : (m <= n) = (m == n) || (m < n). *) (* X - exponentiation, as in lognX : logn p (m ^ n) = logn p m * n in *) (* file prime.v (the suffix is not used in this file). *) (* Suffixes that abbreviate operations (D, B, M and X) are used to abbreviate *) (* second-rank operations in equational lemma names that describe left-hand *) (* sides (e.g., mulnDl); they are not used to abbreviate the main operation *) (* of relational lemmas (e.g., leq_add2l). *) (* For the asymmetrical exponentiation operator expn (m ^ n) a right suffix *) (* indicates an operation on the exponent, e.g., expnM : m ^ (n1 * n2) = ...; *) (* a trailing "n" is used to indicate the left operand, e.g., *) (* expnMn : (m1 * m2) ^ n = ... The operands of other operators are selected *) (* using the l/r suffixes. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope coq_nat_scope. (* Disable Coq prelude hints to improve proof script robustness. *) #[global] Remove Hints plus_n_O plus_n_Sm mult_n_O mult_n_Sm : core. (* Declare legacy Arith operators in new scope. *) Delimit Scope coq_nat_scope with coq_nat. Notation "m + n" := (plus m n) : coq_nat_scope. Notation "m - n" := (minus m n) : coq_nat_scope. Notation "m * n" := (mult m n) : coq_nat_scope. Notation "m <= n" := (le m n) : coq_nat_scope. Notation "m < n" := (lt m n) : coq_nat_scope. Notation "m >= n" := (ge m n) : coq_nat_scope. Notation "m > n" := (gt m n) : coq_nat_scope. (* Rebind scope delimiters, reserving a scope for the "recursive", *) (* i.e., unprotected version of operators. *) Delimit Scope N_scope with num. #[warning="-hiding-delimiting-key"] Delimit Scope nat_scope with N. (* Postfix notation for the successor and predecessor functions. *) (* SSreflect uses "pred" for the generic predicate type, and S as *) (* a local bound variable. *) Notation succn := Datatypes.S. Notation predn := Peano.pred. Notation "n .+1" := (succn n) (left associativity, format "n .+1") : nat_scope. Notation "n .+2" := n.+1.+1 (left associativity, format "n .+2") : nat_scope. Notation "n .+3" := n.+2.+1 (left associativity, format "n .+3") : nat_scope. Notation "n .+4" := n.+2.+2 (left associativity, format "n .+4") : nat_scope. Notation "n .-1" := (predn n) (left associativity, format "n .-1") : nat_scope. Notation "n .-2" := n.-1.-1 (left associativity, format "n .-2") : nat_scope. Lemma succnK : cancel succn predn. Proof. by []. Qed. Lemma succn_inj : injective succn. Proof. by move=> n m []. Qed. (* Predeclare postfix doubling/halving operators. *) Reserved Notation "n .*2" (left associativity, format "n .*2"). Reserved Notation "n ./2" (left associativity, format "n ./2"). (* Canonical comparison and eqType for nat. *) Fixpoint eqn m n {struct m} := match m, n with | 0, 0 => true | m'.+1, n'.+1 => eqn m' n' | _, _ => false end. Lemma eqnP : Equality.axiom eqn. Proof. move=> n m; apply: (iffP idP) => [|<-]; last by elim n. by elim: n m => [|n IHn] [|m] //= /IHn->. Qed. HB.instance Definition _ := hasDecEq.Build nat eqnP. Arguments eqn !m !n. Arguments eqnP {x y}. Lemma eqnE : eqn = eq_op. Proof. by []. Qed. Lemma eqSS m n : (m.+1 == n.+1) = (m == n). Proof. by []. Qed. Lemma nat_irrelevance (x y : nat) (E E' : x = y) : E = E'. Proof. exact: eq_irrelevance. Qed. (* Protected addition, with a more systematic set of lemmas. *) Definition addn := plus. Arguments addn : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use addn instead.")] Definition addn_rec := addn. Notation "m + n" := (addn m n) : nat_scope. Lemma addnE : addn = plus. Proof. by []. Qed. Lemma plusE : plus = addn. Proof. by []. Qed. Lemma add0n : left_id 0 addn. Proof. by []. Qed. Lemma addSn m n : m.+1 + n = (m + n).+1. Proof. by []. Qed. Lemma add1n n : 1 + n = n.+1. Proof. by []. Qed. Lemma addn0 : right_id 0 addn. Proof. by move=> n; apply/eqP; elim: n. Qed. Lemma addnS m n : m + n.+1 = (m + n).+1. Proof. by apply/eqP; elim: m. Qed. Lemma addSnnS m n : m.+1 + n = m + n.+1. Proof. by rewrite addnS. Qed. Lemma addnCA : left_commutative addn. Proof. by move=> m n p; elim: m => //= m; rewrite addnS => <-. Qed. Lemma addnC : commutative addn. Proof. by move=> m n; rewrite -[n in LHS]addn0 addnCA addn0. Qed. Lemma addn1 n : n + 1 = n.+1. Proof. by rewrite addnC. Qed. Lemma addnA : associative addn. Proof. by move=> m n p; rewrite (addnC n) addnCA addnC. Qed. Lemma addnAC : right_commutative addn. Proof. by move=> m n p; rewrite -!addnA (addnC n). Qed. Lemma addnCAC m n p : m + n + p = p + n + m. Proof. by rewrite addnC addnA addnAC. Qed. Lemma addnACl m n p: m + n + p = n + (p + m). Proof. by rewrite (addnC m) addnC addnCA. Qed. Lemma addnACA : interchange addn addn. Proof. by move=> m n p q; rewrite -!addnA (addnCA n). Qed. Lemma addn_eq0 m n : (m + n == 0) = (m == 0) && (n == 0). Proof. by case: m; case: n. Qed. Lemma addn_eq1 m n : (m + n == 1) = ((m == 1) && (n == 0)) || ((m == 0) && (n == 1)). Proof. by case: m n => [|[|m]] [|[|n]]. Qed. Lemma eqn_add2l p m n : (p + m == p + n) = (m == n). Proof. by elim: p. Qed. Lemma eqn_add2r p m n : (m + p == n + p) = (m == n). Proof. by rewrite -!(addnC p) eqn_add2l. Qed. Lemma addnI : right_injective addn. Proof. by move=> p m n Heq; apply: eqP; rewrite -(eqn_add2l p) Heq eqxx. Qed. Lemma addIn : left_injective addn. Proof. move=> p m n; rewrite -!(addnC p); apply addnI. Qed. Lemma addn2 m : m + 2 = m.+2. Proof. by rewrite addnC. Qed. Lemma add2n m : 2 + m = m.+2. Proof. by []. Qed. Lemma addn3 m : m + 3 = m.+3. Proof. by rewrite addnC. Qed. Lemma add3n m : 3 + m = m.+3. Proof. by []. Qed. Lemma addn4 m : m + 4 = m.+4. Proof. by rewrite addnC. Qed. Lemma add4n m : 4 + m = m.+4. Proof. by []. Qed. (* Protected, structurally decreasing subtraction, and basic lemmas. *) (* Further properties depend on ordering conditions. *) Definition subn := minus. Arguments subn : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use subn instead.")] Definition subn_rec := subn. Notation "m - n" := (subn m n) : nat_scope. Lemma subnE : subn = minus. Proof. by []. Qed. Lemma minusE : minus = subn. Proof. by []. Qed. Lemma sub0n : left_zero 0 subn. Proof. by []. Qed. Lemma subn0 : right_id 0 subn. Proof. by case. Qed. Lemma subnn : self_inverse 0 subn. Proof. by elim. Qed. Lemma subSS n m : m.+1 - n.+1 = m - n. Proof. by []. Qed. Lemma subn1 n : n - 1 = n.-1. Proof. by case: n => [|[]]. Qed. Lemma subn2 n : (n - 2)%N = n.-2. Proof. by case: n => [|[|[]]]. Qed. Lemma subnDl p m n : (p + m) - (p + n) = m - n. Proof. by elim: p. Qed. Lemma subnDr p m n : (m + p) - (n + p) = m - n. Proof. by rewrite -!(addnC p) subnDl. Qed. Lemma addnK n : cancel (addn^~ n) (subn^~ n). Proof. by move=> m; rewrite (subnDr n m 0) subn0. Qed. Lemma addKn n : cancel (addn n) (subn^~ n). Proof. by move=> m; rewrite addnC addnK. Qed. Lemma subSnn n : n.+1 - n = 1. Proof. exact (addnK n 1). Qed. Lemma subnDA m n p : n - (m + p) = (n - m) - p. Proof. by elim: m n => [|m IHm] []. Qed. Lemma subnAC : right_commutative subn. Proof. by move=> m n p; rewrite -!subnDA addnC. Qed. Lemma subnS m n : m - n.+1 = (m - n).-1. Proof. by rewrite -addn1 subnDA subn1. Qed. Lemma subSKn m n : (m.+1 - n).-1 = m - n. Proof. by rewrite -subnS. Qed. (* Integer ordering, and its interaction with the other operations. *) Definition leq m n := m - n == 0. Notation "m <= n" := (leq m n) : nat_scope. Notation "m < n" := (m.+1 <= n) : nat_scope. Notation "m >= n" := (n <= m) (only parsing) : nat_scope. Notation "m > n" := (n < m) (only parsing) : nat_scope. (* For sorting, etc. *) Definition geq := [rel m n | m >= n]. Definition ltn := [rel m n | m < n]. Definition gtn := [rel m n | m > n]. Notation "m <= n <= p" := ((m <= n) && (n <= p)) : nat_scope. Notation "m < n <= p" := ((m < n) && (n <= p)) : nat_scope. Notation "m <= n < p" := ((m <= n) && (n < p)) : nat_scope. Notation "m < n < p" := ((m < n) && (n < p)) : nat_scope. Lemma ltnS m n : (m < n.+1) = (m <= n). Proof. by []. Qed. Lemma leq0n n : 0 <= n. Proof. by []. Qed. Lemma ltn0Sn n : 0 < n.+1. Proof. by []. Qed. Lemma ltn0 n : n < 0 = false. Proof. by []. Qed. Lemma leqnn n : n <= n. Proof. by elim: n. Qed. #[global] Hint Resolve leqnn : core. Lemma ltnSn n : n < n.+1. Proof. by []. Qed. Lemma eq_leq m n : m = n -> m <= n. Proof. by move->. Qed. Lemma leqnSn n : n <= n.+1. Proof. by elim: n. Qed. #[global] Hint Resolve leqnSn : core. Lemma leq_pred n : n.-1 <= n. Proof. by case: n => /=. Qed. Lemma leqSpred n : n <= n.-1.+1. Proof. by case: n => /=. Qed. Lemma ltn_predL n : (n.-1 < n) = (0 < n). Proof. by case: n => [//|n]; rewrite ltnSn. Qed. Lemma ltn_predRL m n : (m < n.-1) = (m.+1 < n). Proof. by case: n => [//|n]; rewrite succnK. Qed. Lemma ltn_predK m n : m < n -> n.-1.+1 = n. Proof. by case: n. Qed. Lemma prednK n : 0 < n -> n.-1.+1 = n. Proof. exact: ltn_predK. Qed. Lemma leqNgt m n : (m <= n) = ~~ (n < m). Proof. by elim: m n => [|m IHm] []. Qed. Lemma leqVgt m n : (m <= n) || (n < m). Proof. by rewrite leqNgt orNb. Qed. Lemma ltnNge m n : (m < n) = ~~ (n <= m). Proof. by rewrite leqNgt. Qed. Lemma ltnn n : n < n = false. Proof. by rewrite ltnNge leqnn. Qed. Lemma leqn0 n : (n <= 0) = (n == 0). Proof. by case: n. Qed. Lemma lt0n n : (0 < n) = (n != 0). Proof. by case: n. Qed. Lemma lt0n_neq0 n : 0 < n -> n != 0. Proof. by case: n. Qed. Lemma eqn0Ngt n : (n == 0) = ~~ (n > 0). Proof. by case: n. Qed. Lemma neq0_lt0n n : (n == 0) = false -> 0 < n. Proof. by case: n. Qed. #[global] Hint Resolve lt0n_neq0 neq0_lt0n : core. Lemma eqn_leq m n : (m == n) = (m <= n <= m). Proof. by elim: m n => [|m IHm] []. Qed. Lemma anti_leq : antisymmetric leq. Proof. by move=> m n; rewrite -eqn_leq => /eqP. Qed. Lemma neq_ltn m n : (m != n) = (m < n) || (n < m). Proof. by rewrite eqn_leq negb_and orbC -!ltnNge. Qed. Lemma gtn_eqF m n : m < n -> n == m = false. Proof. by rewrite eqn_leq (leqNgt n) => ->. Qed. Lemma ltn_eqF m n : m < n -> m == n = false. Proof. by move/gtn_eqF; rewrite eq_sym. Qed. Lemma ltn_geF m n : m < n -> m >= n = false. Proof. by rewrite (leqNgt n) => ->. Qed. Lemma leq_gtF m n : m <= n -> m > n = false. Proof. by rewrite (ltnNge n) => ->. Qed. Lemma leq_eqVlt m n : (m <= n) = (m == n) || (m < n). Proof. by elim: m n => [|m IHm] []. Qed. Lemma ltn_neqAle m n : (m < n) = (m != n) && (m <= n). Proof. by rewrite ltnNge leq_eqVlt negb_or -leqNgt eq_sym. Qed. Lemma leq_trans n m p : m <= n -> n <= p -> m <= p. Proof. by elim: n m p => [|i IHn] [|m] [|p] //; apply: IHn m p. Qed. Lemma leq_ltn_trans n m p : m <= n -> n < p -> m < p. Proof. by move=> Hmn; apply: leq_trans. Qed. Lemma ltnW m n : m < n -> m <= n. Proof. exact: leq_trans. Qed. #[global] Hint Resolve ltnW : core. Lemma leqW m n : m <= n -> m <= n.+1. Proof. by move=> le_mn; apply: ltnW. Qed. Lemma ltn_trans n m p : m < n -> n < p -> m < p. Proof. by move=> lt_mn /ltnW; apply: leq_trans. Qed. Lemma leq_total m n : (m <= n) || (m >= n). Proof. by rewrite -implyNb -ltnNge; apply/implyP; apply: ltnW. Qed. (* Helper lemmas to support generalized induction over a nat measure. *) (* The idiom for a proof by induction over a measure Mxy : nat involving *) (* variables x, y, ... (e.g., size x + size y) is *) (* have [n leMn] := ubnP Mxy; elim: n => // n IHn in x y ... leMn ... *. *) (* after which the current goal (possibly modified by generalizations in the *) (* in ... part) can be proven with the extra context assumptions *) (* n : nat *) (* IHn : forall x y ..., Mxy < n -> ... -> the_initial_goal *) (* leMn : Mxy < n.+1 *) (* This is preferable to the legacy idiom relying on numerical occurrence *) (* selection, which is fragile if there can be multiple occurrences of x, y, *) (* ... in the measure expression Mxy (e.g., in #|y| with x : finType and *) (* y : {set x}). *) (* The leMn statement is convertible to Mxy <= n; if it is necessary to *) (* have _exactly_ leMn : Mxy <= n, the ltnSE helper lemma may be used as *) (* follows *) (* have [n] := ubnP Mxy; elim: n => // n IHn in x y ... * => /ltnSE-leMn. *) (* We also provide alternative helper lemmas for proofs where the upper *) (* bound appears in the goal, and we assume nonstrict (in)equality. *) (* In either case the proof will have to dispatch an Mxy = 0 case. *) (* have [n defM] := ubnPleq Mxy; elim: n => [|n IHn] in x y ... defM ... *. *) (* yields two subgoals, in which Mxy has been replaced by 0 and n.+1, *) (* with the extra assumption defM : Mxy <= 0 / Mxy <= n.+1, respectively. *) (* The second goal also has the inductive assumption *) (* IHn : forall x y ..., Mxy <= n -> ... -> the_initial_goal[n / Mxy]. *) (* Using ubnPgeq or ubnPeq instead of ubnPleq yields assumptions with *) (* Mxy >= 0/n.+1 or Mxy == 0/n.+1 instead of Mxy <= 0/n.+1, respectively. *) (* These introduce a different kind of induction; for example ubnPgeq M lets *) (* us remember that n < M throughout the induction. *) (* Finally, the ltn_ind lemma provides a generalized induction view for a *) (* property of a single integer (i.e., the case Mxy := x). *) Lemma ubnP m : {n | m < n}. Proof. by exists m.+1. Qed. Lemma ltnSE m n : m < n.+1 -> m <= n. Proof. by []. Qed. Variant ubn_leq_spec m : nat -> Type := UbnLeq n of m <= n : ubn_leq_spec m n. Variant ubn_geq_spec m : nat -> Type := UbnGeq n of m >= n : ubn_geq_spec m n. Variant ubn_eq_spec m : nat -> Type := UbnEq n of m == n : ubn_eq_spec m n. Lemma ubnPleq m : ubn_leq_spec m m. Proof. by []. Qed. Lemma ubnPgeq m : ubn_geq_spec m m. Proof. by []. Qed. Lemma ubnPeq m : ubn_eq_spec m m. Proof. by []. Qed. Lemma ltn_ind P : (forall n, (forall m, m < n -> P m) -> P n) -> forall n, P n. Proof. move=> accP M; have [n leMn] := ubnP M; elim: n => // n IHn in M leMn *. by apply/accP=> p /leq_trans/(_ leMn)/IHn. Qed. (* Link to the legacy comparison predicates. *) Lemma leP m n : reflect (m <= n)%coq_nat (m <= n). Proof. apply: (iffP idP); last by elim: n / => // n _ /leq_trans->. elim: n => [|n IHn]; first by case: m. by rewrite leq_eqVlt ltnS => /predU1P[<- // | /IHn]; right. Qed. Arguments leP {m n}. Lemma le_irrelevance m n le_mn1 le_mn2 : le_mn1 = le_mn2 :> (m <= n)%coq_nat. Proof. elim/ltn_ind: n => n IHn in le_mn1 le_mn2 *; set n1 := n in le_mn1 *. pose def_n : n = n1 := erefl n; transitivity (eq_ind _ _ le_mn2 _ def_n) => //. case: n1 / le_mn1 le_mn2 => [|n1 le_mn1] {n}[|n le_mn2] in (def_n) IHn *. - by rewrite [def_n]eq_axiomK. - by case/leP/idPn: (le_mn2); rewrite -def_n ltnn. - by case/leP/idPn: (le_mn1); rewrite def_n ltnn. case: def_n (def_n) => <-{n1} def_n in le_mn1 *. by rewrite [def_n]eq_axiomK /=; congr le_S; apply: IHn. Qed. Lemma ltP m n : reflect (m < n)%coq_nat (m < n). Proof. exact leP. Qed. Arguments ltP {m n}. Lemma lt_irrelevance m n lt_mn1 lt_mn2 : lt_mn1 = lt_mn2 :> (m < n)%coq_nat. Proof. exact: (@le_irrelevance m.+1). Qed. (* Monotonicity lemmas *) Lemma leq_add2l p m n : (p + m <= p + n) = (m <= n). Proof. by elim: p. Qed. Lemma ltn_add2l p m n : (p + m < p + n) = (m < n). Proof. by rewrite -addnS; apply: leq_add2l. Qed. Lemma leq_add2r p m n : (m + p <= n + p) = (m <= n). Proof. by rewrite -!(addnC p); apply: leq_add2l. Qed. Lemma ltn_add2r p m n : (m + p < n + p) = (m < n). Proof. exact: leq_add2r p m.+1 n. Qed. Lemma leq_add m1 m2 n1 n2 : m1 <= n1 -> m2 <= n2 -> m1 + m2 <= n1 + n2. Proof. by move=> le_mn1 le_mn2; rewrite (@leq_trans (m1 + n2)) ?leq_add2l ?leq_add2r. Qed. Lemma leq_addl m n : n <= m + n. Proof. exact: (leq_add2r n 0). Qed. Lemma leq_addr m n : n <= n + m. Proof. by rewrite addnC leq_addl. Qed. Lemma ltn_addl m n p : m < n -> m < p + n. Proof. by move/leq_trans=> -> //; apply: leq_addl. Qed. Lemma ltn_addr m n p : m < n -> m < n + p. Proof. by move/leq_trans=> -> //; apply: leq_addr. Qed. Lemma addn_gt0 m n : (0 < m + n) = (0 < m) || (0 < n). Proof. by rewrite !lt0n -negb_and addn_eq0. Qed. Lemma subn_gt0 m n : (0 < n - m) = (m < n). Proof. by elim: m n => [|m IHm] [|n] //; apply: IHm n. Qed. Lemma subn_eq0 m n : (m - n == 0) = (m <= n). Proof. by []. Qed. Lemma leq_subLR m n p : (m - n <= p) = (m <= n + p). Proof. by rewrite -subn_eq0 -subnDA. Qed. Lemma leq_subr m n : n - m <= n. Proof. by rewrite leq_subLR leq_addl. Qed. Lemma ltn_subrR m n : (n < n - m) = false. Proof. by rewrite ltnNge leq_subr. Qed. Lemma leq_subrR m n : (n <= n - m) = (m == 0) || (n == 0). Proof. by case: m n => [|m] [|n]; rewrite ?subn0 ?leqnn ?ltn_subrR. Qed. Lemma ltn_subrL m n : (n - m < n) = (0 < m) && (0 < n). Proof. by rewrite ltnNge leq_subrR negb_or !lt0n. Qed. Lemma subnKC m n : m <= n -> m + (n - m) = n. Proof. by elim: m n => [|m IHm] [|n] // /(IHm n) {2}<-. Qed. Lemma addnBn m n : m + (n - m) = m - n + n. Proof. by elim: m n => [|m IHm] [|n] //; rewrite addSn addnS IHm. Qed. Lemma subnK m n : m <= n -> (n - m) + m = n. Proof. by rewrite addnC; apply: subnKC. Qed. Lemma addnBA m n p : p <= n -> m + (n - p) = m + n - p. Proof. by move=> le_pn; rewrite -[in RHS](subnK le_pn) addnA addnK. Qed. Lemma addnBAC m n p : n <= m -> m - n + p = m + p - n. Proof. by move=> le_nm; rewrite addnC addnBA // addnC. Qed. Lemma addnBCA m n p : p <= m -> p <= n -> m + (n - p) = n + (m - p). Proof. by move=> le_pm le_pn; rewrite !addnBA // addnC. Qed. Lemma addnABC m n p : p <= m -> p <= n -> m + (n - p) = m - p + n. Proof. by move=> le_pm le_pn; rewrite addnBA // addnBAC. Qed. Lemma subnBA m n p : p <= n -> m - (n - p) = m + p - n. Proof. by move=> le_pn; rewrite -[in RHS](subnK le_pn) subnDr. Qed. Lemma subnA m n p : p <= n -> n <= m -> m - (n - p) = m - n + p. Proof. by move=> le_pn lr_nm; rewrite addnBAC // subnBA. Qed. Lemma subKn m n : m <= n -> n - (n - m) = m. Proof. by move/subnBA->; rewrite addKn. Qed. Lemma subSn m n : m <= n -> n.+1 - m = (n - m).+1. Proof. by rewrite -add1n => /addnBA <-. Qed. Lemma subnSK m n : m < n -> (n - m.+1).+1 = n - m. Proof. by move/subSn. Qed. Lemma addnCBA m n p : p <= n -> m + (n - p) = n + m - p. Proof. by move=> pn; rewrite (addnC n m) addnBA. Qed. Lemma addnBr_leq n p m : n <= p -> m + (n - p) = m. Proof. by rewrite -subn_eq0 => /eqP->; rewrite addn0. Qed. Lemma addnBl_leq m n p : m <= n -> m - n + p = p. Proof. by rewrite -subn_eq0; move/eqP => ->; rewrite add0n. Qed. Lemma subnDAC m n p : m - (n + p) = m - p - n. Proof. by rewrite addnC subnDA. Qed. Lemma subnCBA m n p : p <= n -> m - (n - p) = p + m - n. Proof. by move=> pn; rewrite addnC subnBA. Qed. Lemma subnBr_leq n p m : n <= p -> m - (n - p) = m. Proof. by rewrite -subn_eq0 => /eqP->; rewrite subn0. Qed. Lemma subnBl_leq m n p : m <= n -> (m - n) - p = 0. Proof. by rewrite -subn_eq0 => /eqP->. Qed. Lemma subnBAC m n p : p <= n -> n <= m -> m - (n - p) = p + (m - n). Proof. by move=> pn nm; rewrite subnA // addnC. Qed. Lemma subDnAC m n p : p <= n -> m + n - p = n - p + m. Proof. by move=> pn; rewrite addnC -addnBAC. Qed. Lemma subDnCA m n p : p <= m -> m + n - p = n + (m - p). Proof. by move=> pm; rewrite addnC -addnBA. Qed. Lemma subDnCAC m n p : m <= p -> m + n - p = n - (p - m). Proof. by move=> mp; rewrite addnC -subnBA. Qed. Lemma addnBC m n : m - n + n = n - m + m. Proof. by rewrite -[in RHS]addnBn addnC. Qed. Lemma addnCB m n : m - n + n = m + (n - m). Proof. by rewrite addnBC addnC. Qed. Lemma addBnAC m n p : n <= m -> m - n + p = p + m - n. Proof. by move=> nm; rewrite [p + m]addnC addnBAC. Qed. Lemma addBnCAC m n p : n <= m -> n <= p -> m - n + p = p - n + m. Proof. by move=> nm np; rewrite addnC addnBA // subDnCA // addnC. Qed. Lemma addBnA m n p : n <= m -> p <= n -> m - n + p = m - (n - p). Proof. by move=> nm pn; rewrite subnBA // -subDnAC // addnC. Qed. Lemma subBnAC m n p : m - n - p = m - (p + n). Proof. by rewrite addnC -subnDA. Qed. Lemma predn_sub m n : (m - n).-1 = (m.-1 - n). Proof. by case: m => // m; rewrite subSKn. Qed. Lemma leq_sub2r p m n : m <= n -> m - p <= n - p. Proof. by move=> le_mn; rewrite leq_subLR (leq_trans le_mn) // -leq_subLR. Qed. Lemma leq_sub2l p m n : m <= n -> p - n <= p - m. Proof. rewrite -(leq_add2r (p - m)) leq_subLR. by apply: leq_trans; rewrite -leq_subLR. Qed. Lemma leq_sub m1 m2 n1 n2 : m1 <= m2 -> n2 <= n1 -> m1 - n1 <= m2 - n2. Proof. by move/(leq_sub2r n1)=> le_m12 /(leq_sub2l m2); apply: leq_trans. Qed. Lemma ltn_sub2r p m n : p < n -> m < n -> m - p < n - p. Proof. by move/subnSK <-; apply: (@leq_sub2r p.+1). Qed. Lemma ltn_sub2l p m n : m < p -> m < n -> p - n < p - m. Proof. by move/subnSK <-; apply: leq_sub2l. Qed. Lemma ltn_subRL m n p : (n < p - m) = (m + n < p). Proof. by rewrite !ltnNge leq_subLR. Qed. Lemma leq_psubRL m n p : 0 < n -> (n <= p - m) = (m + n <= p). Proof. by move=> /prednK<-; rewrite ltn_subRL addnS. Qed. Lemma ltn_psubLR m n p : 0 < p -> (m - n < p) = (m < n + p). Proof. by move=> /prednK<-; rewrite ltnS leq_subLR addnS. Qed. Lemma leq_subRL m n p : m <= p -> (n <= p - m) = (m + n <= p). Proof. by move=> /subnKC{2}<-; rewrite leq_add2l. Qed. Lemma ltn_subLR m n p : n <= m -> (m - n < p) = (m < n + p). Proof. by move=> /subnKC{2}<-; rewrite ltn_add2l. Qed. Lemma leq_subCl m n p : (m - n <= p) = (m - p <= n). Proof. by rewrite !leq_subLR // addnC. Qed. Lemma ltn_subCr m n p : (p < m - n) = (n < m - p). Proof. by rewrite !ltn_subRL // addnC. Qed. Lemma leq_psubCr m n p : 0 < p -> 0 < n -> (p <= m - n) = (n <= m - p). Proof. by move=> p_gt0 n_gt0; rewrite !leq_psubRL // addnC. Qed. Lemma ltn_psubCl m n p : 0 < p -> 0 < n -> (m - n < p) = (m - p < n). Proof. by move=> p_gt0 n_gt0; rewrite !ltn_psubLR // addnC. Qed. Lemma leq_subCr m n p : n <= m -> p <= m -> (p <= m - n) = (n <= m - p). Proof. by move=> np pm; rewrite !leq_subRL // addnC. Qed. Lemma ltn_subCl m n p : n <= m -> p <= m -> (m - n < p) = (m - p < n). Proof. by move=> nm pm; rewrite !ltn_subLR // addnC. Qed. Lemma leq_sub2rE p m n : p <= n -> (m - p <= n - p) = (m <= n). Proof. by move=> pn; rewrite leq_subLR subnKC. Qed. Lemma leq_sub2lE m n p : n <= m -> (m - p <= m - n) = (n <= p). Proof. by move=> nm; rewrite leq_subCl subKn. Qed. Lemma ltn_sub2rE p m n : p <= m -> (m - p < n - p) = (m < n). Proof. by move=> pn; rewrite ltn_subRL addnC subnK. Qed. Lemma ltn_sub2lE m n p : p <= m -> (m - p < m - n) = (n < p). Proof. by move=> pm; rewrite ltn_subCr subKn. Qed. Lemma eqn_sub2rE p m n : p <= m -> p <= n -> (m - p == n - p) = (m == n). Proof. by move=> pm pn; rewrite !eqn_leq !leq_sub2rE. Qed. Lemma eqn_sub2lE m n p : p <= m -> n <= m -> (m - p == m - n) = (p == n). Proof. by move=> pm nm; rewrite !eqn_leq !leq_sub2lE // -!eqn_leq eq_sym. Qed. (* Max and min. *) Definition maxn m n := if m < n then n else m. Definition minn m n := if m < n then m else n. Lemma max0n : left_id 0 maxn. Proof. by case. Qed. Lemma maxn0 : right_id 0 maxn. Proof. by []. Qed. Lemma maxnC : commutative maxn. Proof. by rewrite /maxn; elim=> [|m ih] [] // n; rewrite !ltnS -!fun_if ih. Qed. Lemma maxnE m n : maxn m n = m + (n - m). Proof. rewrite /maxn; elim: m n => [|m ih] [|n]; rewrite ?addn0 //. by rewrite ltnS subSS addSn -ih; case: leq. Qed. Lemma maxnAC : right_commutative maxn. Proof. by move=> m n p; rewrite !maxnE -!addnA !subnDA -!maxnE maxnC. Qed. Lemma maxnA : associative maxn. Proof. by move=> m n p; rewrite !(maxnC m) maxnAC. Qed. Lemma maxnCA : left_commutative maxn. Proof. by move=> m n p; rewrite !maxnA (maxnC m). Qed. Lemma maxnACA : interchange maxn maxn. Proof. by move=> m n p q; rewrite -!maxnA (maxnCA n). Qed. Lemma maxn_idPl {m n} : reflect (maxn m n = m) (m >= n). Proof. by rewrite -subn_eq0 -(eqn_add2l m) addn0 -maxnE; apply: eqP. Qed. Lemma maxn_idPr {m n} : reflect (maxn m n = n) (m <= n). Proof. by rewrite maxnC; apply: maxn_idPl. Qed. Lemma maxnn : idempotent_op maxn. Proof. by move=> n; apply/maxn_idPl. Qed. Lemma leq_max m n1 n2 : (m <= maxn n1 n2) = (m <= n1) || (m <= n2). Proof. without loss le_n21: n1 n2 / n2 <= n1. by case/orP: (leq_total n2 n1) => le_n12; last rewrite maxnC orbC; apply. by rewrite (maxn_idPl le_n21) orb_idr // => /leq_trans->. Qed. Lemma leq_maxl m n : m <= maxn m n. Proof. by rewrite leq_max leqnn. Qed. Lemma leq_maxr m n : n <= maxn m n. Proof. by rewrite maxnC leq_maxl. Qed. Lemma gtn_max m n1 n2 : (m > maxn n1 n2) = (m > n1) && (m > n2). Proof. by rewrite !ltnNge leq_max negb_or. Qed. Lemma geq_max m n1 n2 : (m >= maxn n1 n2) = (m >= n1) && (m >= n2). Proof. by rewrite -ltnS gtn_max. Qed. Lemma maxnSS m n : maxn m.+1 n.+1 = (maxn m n).+1. Proof. by rewrite !maxnE. Qed. Lemma addn_maxl : left_distributive addn maxn. Proof. by move=> m1 m2 n; rewrite !maxnE subnDr addnAC. Qed. Lemma addn_maxr : right_distributive addn maxn. Proof. by move=> m n1 n2; rewrite !(addnC m) addn_maxl. Qed. Lemma subn_maxl : left_distributive subn maxn. Proof. move=> m n p; apply/eqP. rewrite eqn_leq !geq_max !leq_sub2r leq_max ?leqnn ?andbT ?orbT // /maxn. by case: (_ < _); rewrite leqnn // orbT. Qed. Lemma min0n : left_zero 0 minn. Proof. by case. Qed. Lemma minn0 : right_zero 0 minn. Proof. by []. Qed. Lemma minnC : commutative minn. Proof. by rewrite /minn; elim=> [|m ih] [] // n; rewrite !ltnS -!fun_if ih. Qed. Lemma addn_min_max m n : minn m n + maxn m n = m + n. Proof. by rewrite /minn /maxn; case: (m < n) => //; exact: addnC. Qed. Lemma minnE m n : minn m n = m - (m - n). Proof. by rewrite -(subnDl n) -maxnE -addn_min_max addnK minnC. Qed. Lemma minnAC : right_commutative minn. Proof. by move=> m n p; rewrite !minnE -subnDA subnAC -maxnE maxnC maxnE subnAC subnDA. Qed. Lemma minnA : associative minn. Proof. by move=> m n p; rewrite minnC minnAC (minnC n). Qed. Lemma minnCA : left_commutative minn. Proof. by move=> m n p; rewrite !minnA (minnC n). Qed. Lemma minnACA : interchange minn minn. Proof. by move=> m n p q; rewrite -!minnA (minnCA n). Qed. Lemma minn_idPl {m n} : reflect (minn m n = m) (m <= n). Proof. rewrite (sameP maxn_idPr eqP) -(eqn_add2l m) eq_sym -addn_min_max eqn_add2r. exact: eqP. Qed. Lemma minn_idPr {m n} : reflect (minn m n = n) (m >= n). Proof. by rewrite minnC; apply: minn_idPl. Qed. Lemma minnn : idempotent_op minn. Proof. by move=> n; apply/minn_idPl. Qed. Lemma leq_min m n1 n2 : (m <= minn n1 n2) = (m <= n1) && (m <= n2). Proof. wlog le_n21: n1 n2 / n2 <= n1. by case/orP: (leq_total n2 n1) => ?; last rewrite minnC andbC; apply. rewrite /minn ltnNge le_n21 /=; case le_m_n1: (m <= n1) => //=. apply/contraFF: le_m_n1 => /leq_trans; exact. Qed. Lemma gtn_min m n1 n2 : (m > minn n1 n2) = (m > n1) || (m > n2). Proof. by rewrite !ltnNge leq_min negb_and. Qed. Lemma geq_min m n1 n2 : (m >= minn n1 n2) = (m >= n1) || (m >= n2). Proof. by rewrite -ltnS gtn_min. Qed. Lemma ltn_min m n1 n2 : (m < minn n1 n2) = (m < n1) && (m < n2). Proof. exact: leq_min. Qed. Lemma geq_minl m n : minn m n <= m. Proof. by rewrite geq_min leqnn. Qed. Lemma geq_minr m n : minn m n <= n. Proof. by rewrite minnC geq_minl. Qed. Lemma addn_minr : right_distributive addn minn. Proof. by move=> m1 m2 n; rewrite !minnE subnDl addnBA ?leq_subr. Qed. Lemma addn_minl : left_distributive addn minn. Proof. by move=> m1 m2 n; rewrite -!(addnC n) addn_minr. Qed. Lemma subn_minl : left_distributive subn minn. Proof. move=> m n p; apply/eqP. rewrite eqn_leq !leq_min !leq_sub2r geq_min ?leqnn ?orbT //= /minn. by case: (_ < _); rewrite leqnn // orbT. Qed. Lemma minnSS m n : minn m.+1 n.+1 = (minn m n).+1. Proof. by rewrite -(addn_minr 1). Qed. (* Quasi-cancellation (really, absorption) lemmas *) Lemma maxnK m n : minn (maxn m n) m = m. Proof. exact/minn_idPr/leq_maxl. Qed. Lemma maxKn m n : minn n (maxn m n) = n. Proof. exact/minn_idPl/leq_maxr. Qed. Lemma minnK m n : maxn (minn m n) m = m. Proof. exact/maxn_idPr/geq_minl. Qed. Lemma minKn m n : maxn n (minn m n) = n. Proof. exact/maxn_idPl/geq_minr. Qed. (* Distributivity. *) Lemma maxn_minl : left_distributive maxn minn. Proof. move=> m1 m2 n; wlog le_m21: m1 m2 / m2 <= m1. move=> IH; case/orP: (leq_total m2 m1) => /IH //. by rewrite minnC [in R in _ = R]minnC. rewrite (minn_idPr le_m21); apply/esym/minn_idPr. by rewrite geq_max leq_maxr leq_max le_m21. Qed. Lemma maxn_minr : right_distributive maxn minn. Proof. by move=> m n1 n2; rewrite !(maxnC m) maxn_minl. Qed. Lemma minn_maxl : left_distributive minn maxn. Proof. by move=> m1 m2 n; rewrite maxn_minr !maxn_minl -minnA maxnn (maxnC _ n) !maxnK. Qed. Lemma minn_maxr : right_distributive minn maxn. Proof. by move=> m n1 n2; rewrite !(minnC m) minn_maxl. Qed. (* Comparison predicates. *) Variant leq_xor_gtn m n : nat -> nat -> nat -> nat -> bool -> bool -> Set := | LeqNotGtn of m <= n : leq_xor_gtn m n m m n n true false | GtnNotLeq of n < m : leq_xor_gtn m n n n m m false true. Lemma leqP m n : leq_xor_gtn m n (minn n m) (minn m n) (maxn n m) (maxn m n) (m <= n) (n < m). Proof. rewrite (minnC m) /minn (maxnC m) /maxn ltnNge. by case le_mn: (m <= n); constructor; rewrite //= ltnNge le_mn. Qed. Variant ltn_xor_geq m n : nat -> nat -> nat -> nat -> bool -> bool -> Set := | LtnNotGeq of m < n : ltn_xor_geq m n m m n n false true | GeqNotLtn of n <= m : ltn_xor_geq m n n n m m true false. Lemma ltnP m n : ltn_xor_geq m n (minn n m) (minn m n) (maxn n m) (maxn m n) (n <= m) (m < n). Proof. by case: leqP; constructor. Qed. Variant eqn0_xor_gt0 n : bool -> bool -> Set := | Eq0NotPos of n = 0 : eqn0_xor_gt0 n true false | PosNotEq0 of n > 0 : eqn0_xor_gt0 n false true. Lemma posnP n : eqn0_xor_gt0 n (n == 0) (0 < n). Proof. by case: n; constructor. Qed. Variant compare_nat m n : nat -> nat -> nat -> nat -> bool -> bool -> bool -> bool -> bool -> bool -> Set := | CompareNatLt of m < n : compare_nat m n m m n n false false false true false true | CompareNatGt of m > n : compare_nat m n n n m m false false true false true false | CompareNatEq of m = n : compare_nat m n m m m m true true true true false false. Lemma ltngtP m n : compare_nat m n (minn n m) (minn m n) (maxn n m) (maxn m n) (n == m) (m == n) (n <= m) (m <= n) (n < m) (m < n). Proof. rewrite !ltn_neqAle [_ == n]eq_sym; have [mn|] := ltnP m n. by rewrite ltnW // gtn_eqF //; constructor. rewrite leq_eqVlt; case: ltnP; rewrite ?(orbT, orbF) => //= lt_nm eq_nm. by rewrite ltn_eqF //; constructor. by rewrite eq_nm (eqP eq_nm); constructor. Qed. (* Eliminating the idiom for structurally decreasing compare and subtract. *) Lemma subn_if_gt T m n F (E : T) : (if m.+1 - n is m'.+1 then F m' else E) = (if n <= m then F (m - n) else E). Proof. by have [le_nm|/eqnP-> //] := leqP; rewrite -{1}(subnK le_nm) -addSn addnK. Qed. Notation leqLHS := (X in (X <= _)%N)%pattern. Notation leqRHS := (X in (_ <= X)%N)%pattern. Notation ltnLHS := (X in (X < _)%N)%pattern. Notation ltnRHS := (X in (_ < X)%N)%pattern. (* Getting a concrete value from an abstract existence proof. *) Section ExMinn. Variable P : pred nat. Hypothesis exP : exists n, P n. Inductive acc_nat i : Prop := AccNat0 of P i | AccNatS of acc_nat i.+1. Lemma find_ex_minn : {m | P m & forall n, P n -> n >= m}. Proof. have: forall n, P n -> n >= 0 by []. have: acc_nat 0. case exP => n; rewrite -(addn0 n); elim: n 0 => [|n IHn] j; first by left. by rewrite addSnnS; right; apply: IHn. move: 0; fix find_ex_minn 2 => m IHm m_lb; case Pm: (P m); first by exists m. apply: find_ex_minn m.+1 _ _ => [|n Pn]; first by case: IHm; rewrite ?Pm. by rewrite ltn_neqAle m_lb //; case: eqP Pm => // -> /idP[]. Qed. Definition ex_minn := s2val find_ex_minn. Inductive ex_minn_spec : nat -> Type := ExMinnSpec m of P m & (forall n, P n -> n >= m) : ex_minn_spec m. Lemma ex_minnP : ex_minn_spec ex_minn. Proof. by rewrite /ex_minn; case: find_ex_minn. Qed. End ExMinn. Section ExMaxn. Variables (P : pred nat) (m : nat). Hypotheses (exP : exists i, P i) (ubP : forall i, P i -> i <= m). Lemma ex_maxn_subproof : exists i, P (m - i). Proof. by case: exP => i Pi; exists (m - i); rewrite subKn ?ubP. Qed. Definition ex_maxn := m - ex_minn ex_maxn_subproof. Variant ex_maxn_spec : nat -> Type := ExMaxnSpec i of P i & (forall j, P j -> j <= i) : ex_maxn_spec i. Lemma ex_maxnP : ex_maxn_spec ex_maxn. Proof. rewrite /ex_maxn; case: ex_minnP => i Pmi min_i; split=> // j Pj. have le_i_mj: i <= m - j by rewrite min_i // subKn // ubP. rewrite -subn_eq0 subnBA ?(leq_trans le_i_mj) ?leq_subr //. by rewrite addnC -subnBA ?ubP. Qed. End ExMaxn. Lemma eq_ex_minn P Q exP exQ : P =1 Q -> @ex_minn P exP = @ex_minn Q exQ. Proof. move=> eqPQ; case: ex_minnP => m1 Pm1 m1_lb; case: ex_minnP => m2 Pm2 m2_lb. by apply/eqP; rewrite eqn_leq m1_lb (m2_lb, eqPQ) // -eqPQ. Qed. Lemma eq_ex_maxn (P Q : pred nat) m n exP ubP exQ ubQ : P =1 Q -> @ex_maxn P m exP ubP = @ex_maxn Q n exQ ubQ. Proof. move=> eqPQ; case: ex_maxnP => i Pi max_i; case: ex_maxnP => j Pj max_j. by apply/eqP; rewrite eqn_leq max_i ?eqPQ // max_j -?eqPQ. Qed. Section Iteration. Variable T : Type. Implicit Types m n : nat. Implicit Types x y : T. Implicit Types S : {pred T}. Definition iter n f x := let fix loop m := if m is i.+1 then f (loop i) else x in loop n. Definition iteri n f x := let fix loop m := if m is i.+1 then f i (loop i) else x in loop n. Definition iterop n op x := let f i y := if i is 0 then x else op x y in iteri n f. Lemma iterSr n f x : iter n.+1 f x = iter n f (f x). Proof. by elim: n => //= n <-. Qed. Lemma iterS n f x : iter n.+1 f x = f (iter n f x). Proof. by []. Qed. Lemma iterD n m f x : iter (n + m) f x = iter n f (iter m f x). Proof. by elim: n => //= n ->. Qed. Lemma iteriS n f x : iteri n.+1 f x = f n (iteri n f x). Proof. by []. Qed. Lemma iteropS idx n op x : iterop n.+1 op x idx = iter n (op x) x. Proof. by elim: n => //= n ->. Qed. Lemma eq_iter f f' : f =1 f' -> forall n, iter n f =1 iter n f'. Proof. by move=> eq_f n x; elim: n => //= n ->; rewrite eq_f. Qed. Lemma iter_fix n f x : f x = x -> iter n f x = x. Proof. by move=> fixf; elim: n => //= n ->. Qed. Lemma eq_iteri f f' : f =2 f' -> forall n, iteri n f =1 iteri n f'. Proof. by move=> eq_f n x; elim: n => //= n ->; rewrite eq_f. Qed. Lemma eq_iterop n op op' : op =2 op' -> iterop n op =2 iterop n op'. Proof. by move=> eq_op x; apply: eq_iteri; case. Qed. Lemma iter_in f S i : {homo f : x / x \in S} -> {homo iter i f : x / x \in S}. Proof. by move=> f_in x xS; elim: i => [|i /f_in]. Qed. End Iteration. Lemma iter_succn m n : iter n succn m = m + n. Proof. by rewrite addnC; elim: n => //= n ->. Qed. Lemma iter_succn_0 n : iter n succn 0 = n. Proof. exact: iter_succn. Qed. Lemma iter_predn m n : iter n predn m = m - n. Proof. by elim: n m => /= [|n IHn] m; rewrite ?subn0 // IHn subnS. Qed. (* Multiplication. *) Definition muln := mult. Arguments muln : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use muln instead.")] Definition muln_rec := muln. Notation "m * n" := (muln m n) : nat_scope. Lemma multE : mult = muln. Proof. by []. Qed. Lemma mulnE : muln = mult. Proof. by []. Qed. Lemma mul0n : left_zero 0 muln. Proof. by []. Qed. Lemma muln0 : right_zero 0 muln. Proof. by elim. Qed. Lemma mul1n : left_id 1 muln. Proof. exact: addn0. Qed. Lemma mulSn m n : m.+1 * n = n + m * n. Proof. by []. Qed. Lemma mulSnr m n : m.+1 * n = m * n + n. Proof. exact: addnC. Qed. Lemma mulnS m n : m * n.+1 = m + m * n. Proof. by elim: m => // m; rewrite !mulSn !addSn addnCA => ->. Qed. Lemma mulnSr m n : m * n.+1 = m * n + m. Proof. by rewrite addnC mulnS. Qed. Lemma iter_addn m n p : iter n (addn m) p = m * n + p. Proof. by elim: n => /= [|n ->]; rewrite ?muln0 // mulnS addnA. Qed. Lemma iter_addn_0 m n : iter n (addn m) 0 = m * n. Proof. by rewrite iter_addn addn0. Qed. Lemma muln1 : right_id 1 muln. Proof. by move=> n; rewrite mulnSr muln0. Qed. Lemma mulnC : commutative muln. Proof. by move=> m n; elim: m => [|m]; rewrite (muln0, mulnS) // mulSn => ->. Qed. Lemma mulnDl : left_distributive muln addn. Proof. by move=> m1 m2 n; elim: m1 => //= m1 IHm; rewrite -addnA -IHm. Qed. Lemma mulnDr : right_distributive muln addn. Proof. by move=> m n1 n2; rewrite !(mulnC m) mulnDl. Qed. Lemma mulnBl : left_distributive muln subn. Proof. move=> m n [|p]; first by rewrite !muln0. by elim: m n => // [m IHm] [|n] //; rewrite mulSn subnDl -IHm. Qed. Lemma mulnBr : right_distributive muln subn. Proof. by move=> m n p; rewrite !(mulnC m) mulnBl. Qed. Lemma mulnA : associative muln. Proof. by move=> m n p; elim: m => //= m; rewrite mulSn mulnDl => ->. Qed. Lemma mulnCA : left_commutative muln. Proof. by move=> m n1 n2; rewrite !mulnA (mulnC m). Qed. Lemma mulnAC : right_commutative muln. Proof. by move=> m n p; rewrite -!mulnA (mulnC n). Qed. Lemma mulnACA : interchange muln muln. Proof. by move=> m n p q; rewrite -!mulnA (mulnCA n). Qed. Lemma muln_eq0 m n : (m * n == 0) = (m == 0) || (n == 0). Proof. by case: m n => // m [|n] //=; rewrite muln0. Qed. Lemma muln_eq1 m n : (m * n == 1) = (m == 1) && (n == 1). Proof. by case: m n => [|[|m]] [|[|n]] //; rewrite muln0. Qed. Lemma muln_gt0 m n : (0 < m * n) = (0 < m) && (0 < n). Proof. by case: m n => // m [|n] //=; rewrite muln0. Qed. Lemma leq_pmull m n : n > 0 -> m <= n * m. Proof. by move/prednK <-; apply: leq_addr. Qed. Lemma leq_pmulr m n : n > 0 -> m <= m * n. Proof. by move/leq_pmull; rewrite mulnC. Qed. Lemma leq_mul2l m n1 n2 : (m * n1 <= m * n2) = (m == 0) || (n1 <= n2). Proof. by rewrite [LHS]/leq -mulnBr muln_eq0. Qed. Lemma leq_mul2r m n1 n2 : (n1 * m <= n2 * m) = (m == 0) || (n1 <= n2). Proof. by rewrite -!(mulnC m) leq_mul2l. Qed. Lemma leq_mul m1 m2 n1 n2 : m1 <= n1 -> m2 <= n2 -> m1 * m2 <= n1 * n2. Proof. move=> le_mn1 le_mn2; apply (@leq_trans (m1 * n2)). by rewrite leq_mul2l le_mn2 orbT. by rewrite leq_mul2r le_mn1 orbT. Qed. Lemma eqn_mul2l m n1 n2 : (m * n1 == m * n2) = (m == 0) || (n1 == n2). Proof. by rewrite eqn_leq !leq_mul2l -orb_andr -eqn_leq. Qed. Lemma eqn_mul2r m n1 n2 : (n1 * m == n2 * m) = (m == 0) || (n1 == n2). Proof. by rewrite eqn_leq !leq_mul2r -orb_andr -eqn_leq. Qed. Lemma leq_pmul2l m n1 n2 : 0 < m -> (m * n1 <= m * n2) = (n1 <= n2). Proof. by move/prednK=> <-; rewrite leq_mul2l. Qed. Arguments leq_pmul2l [m n1 n2]. Lemma leq_pmul2r m n1 n2 : 0 < m -> (n1 * m <= n2 * m) = (n1 <= n2). Proof. by move/prednK <-; rewrite leq_mul2r. Qed. Arguments leq_pmul2r [m n1 n2]. Lemma eqn_pmul2l m n1 n2 : 0 < m -> (m * n1 == m * n2) = (n1 == n2). Proof. by move/prednK <-; rewrite eqn_mul2l. Qed. Arguments eqn_pmul2l [m n1 n2]. Lemma eqn_pmul2r m n1 n2 : 0 < m -> (n1 * m == n2 * m) = (n1 == n2). Proof. by move/prednK <-; rewrite eqn_mul2r. Qed. Arguments eqn_pmul2r [m n1 n2]. Lemma ltn_mul2l m n1 n2 : (m * n1 < m * n2) = (0 < m) && (n1 < n2). Proof. by rewrite lt0n !ltnNge leq_mul2l negb_or. Qed. Lemma ltn_mul2r m n1 n2 : (n1 * m < n2 * m) = (0 < m) && (n1 < n2). Proof. by rewrite lt0n !ltnNge leq_mul2r negb_or. Qed. Lemma ltn_pmul2l m n1 n2 : 0 < m -> (m * n1 < m * n2) = (n1 < n2). Proof. by move/prednK <-; rewrite ltn_mul2l. Qed. Arguments ltn_pmul2l [m n1 n2]. Lemma ltn_pmul2r m n1 n2 : 0 < m -> (n1 * m < n2 * m) = (n1 < n2). Proof. by move/prednK <-; rewrite ltn_mul2r. Qed. Arguments ltn_pmul2r [m n1 n2]. Lemma ltn_Pmull m n : 1 < n -> 0 < m -> m < n * m. Proof. by move=> lt1n m_gt0; rewrite -[ltnLHS]mul1n ltn_pmul2r. Qed. Lemma ltn_Pmulr m n : 1 < n -> 0 < m -> m < m * n. Proof. by move=> lt1n m_gt0; rewrite mulnC ltn_Pmull. Qed. Lemma ltn_mull m1 m2 n1 n2 : 0 < n2 -> m1 < n1 -> m2 <= n2 -> m1 * m2 < n1 * n2. Proof. move=> n20 lt_mn1 le_mn2. rewrite (@leq_ltn_trans (m1 * n2)) ?leq_mul2l ?le_mn2 ?orbT//. by rewrite ltn_mul2r lt_mn1 n20. Qed. Lemma ltn_mulr m1 m2 n1 n2 : 0 < n1 -> m1 <= n1 -> m2 < n2 -> m1 * m2 < n1 * n2. Proof. by move=> ? ? ?; rewrite mulnC [ltnRHS]mulnC ltn_mull. Qed. Lemma ltn_mul m1 m2 n1 n2 : m1 < n1 -> m2 < n2 -> m1 * m2 < n1 * n2. Proof. by move=> ? lt2; rewrite ltn_mull ?(leq_ltn_trans _ lt2)// ltnW. Qed. Lemma maxnMr : right_distributive muln maxn. Proof. by case=> // m n1 n2; rewrite /maxn (fun_if (muln _)) ltn_pmul2l. Qed. Lemma maxnMl : left_distributive muln maxn. Proof. by move=> m1 m2 n; rewrite -!(mulnC n) maxnMr. Qed. Lemma minnMr : right_distributive muln minn. Proof. by case=> // m n1 n2; rewrite /minn (fun_if (muln _)) ltn_pmul2l. Qed. Lemma minnMl : left_distributive muln minn. Proof. by move=> m1 m2 n; rewrite -!(mulnC n) minnMr. Qed. Lemma iterM (T : Type) (n m : nat) (f : T -> T) : iter (n * m) f =1 iter n (iter m f). Proof. by move=> x; elim: n => //= n <-; rewrite mulSn iterD. Qed. (* Exponentiation. *) Definition expn m n := iterop n muln m 1. Arguments expn : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use expn instead.")] Definition expn_rec := expn. Notation "m ^ n" := (expn m n) : nat_scope. Lemma expnE n m : expn m n = iterop n muln m 1. Proof. by []. Qed. Lemma expn0 m : m ^ 0 = 1. Proof. by []. Qed. Lemma expn1 m : m ^ 1 = m. Proof. by []. Qed. Lemma expnS m n : m ^ n.+1 = m * m ^ n. Proof. by case: n; rewrite ?muln1. Qed. Lemma expnSr m n : m ^ n.+1 = m ^ n * m. Proof. by rewrite mulnC expnS. Qed. Lemma iter_muln m n p : iter n (muln m) p = m ^ n * p. Proof. by elim: n => /= [|n ->]; rewrite ?mul1n // expnS mulnA. Qed. Lemma iter_muln_1 m n : iter n (muln m) 1 = m ^ n. Proof. by rewrite iter_muln muln1. Qed. Lemma exp0n n : 0 < n -> 0 ^ n = 0. Proof. by case: n => [|[]]. Qed. Lemma exp1n n : 1 ^ n = 1. Proof. by elim: n => // n; rewrite expnS mul1n. Qed. Lemma expnD m n1 n2 : m ^ (n1 + n2) = m ^ n1 * m ^ n2. Proof. by elim: n1 => [|n1 IHn]; rewrite !(mul1n, expnS) // IHn mulnA. Qed. Lemma expnMn m1 m2 n : (m1 * m2) ^ n = m1 ^ n * m2 ^ n. Proof. by elim: n => // n IHn; rewrite !expnS IHn -!mulnA (mulnCA m2). Qed. Lemma expnM m n1 n2 : m ^ (n1 * n2) = (m ^ n1) ^ n2. Proof. elim: n1 => [|n1 IHn]; first by rewrite exp1n. by rewrite expnD expnS expnMn IHn. Qed. Lemma expnAC m n1 n2 : (m ^ n1) ^ n2 = (m ^ n2) ^ n1. Proof. by rewrite -!expnM mulnC. Qed. Lemma expn_gt0 m n : (0 < m ^ n) = (0 < m) || (n == 0). Proof. by case: m => [|m]; elim: n => //= n IHn; rewrite expnS // addn_gt0 IHn. Qed. Lemma expn_eq0 m e : (m ^ e == 0) = (m == 0) && (e > 0). Proof. by rewrite !eqn0Ngt expn_gt0 negb_or -lt0n. Qed. Lemma ltn_expl m n : 1 < m -> n < m ^ n. Proof. move=> m_gt1; elim: n => //= n; rewrite -(leq_pmul2l (ltnW m_gt1)) expnS. by apply: leq_trans; apply: ltn_Pmull. Qed. Lemma leq_exp2l m n1 n2 : 1 < m -> (m ^ n1 <= m ^ n2) = (n1 <= n2). Proof. move=> m_gt1; elim: n1 n2 => [|n1 IHn] [|n2] //; last 1 first. - by rewrite !expnS leq_pmul2l ?IHn // ltnW. - by rewrite expn_gt0 ltnW. by rewrite leqNgt (leq_trans m_gt1) // expnS leq_pmulr // expn_gt0 ltnW. Qed. Lemma ltn_exp2l m n1 n2 : 1 < m -> (m ^ n1 < m ^ n2) = (n1 < n2). Proof. by move=> m_gt1; rewrite !ltnNge leq_exp2l. Qed. Lemma eqn_exp2l m n1 n2 : 1 < m -> (m ^ n1 == m ^ n2) = (n1 == n2). Proof. by move=> m_gt1; rewrite !eqn_leq !leq_exp2l. Qed. Lemma expnI m : 1 < m -> injective (expn m). Proof. by move=> m_gt1 e1 e2 /eqP; rewrite eqn_exp2l // => /eqP. Qed. Lemma leq_pexp2l m n1 n2 : 0 < m -> n1 <= n2 -> m ^ n1 <= m ^ n2. Proof. by case: m => [|[|m]] // _; [rewrite !exp1n | rewrite leq_exp2l]. Qed. Lemma ltn_pexp2l m n1 n2 : 0 < m -> m ^ n1 < m ^ n2 -> n1 < n2. Proof. by case: m => [|[|m]] // _; [rewrite !exp1n | rewrite ltn_exp2l]. Qed. Lemma ltn_exp2r m n e : e > 0 -> (m ^ e < n ^ e) = (m < n). Proof. move=> e_gt0; apply/idP/idP=> [|ltmn]. rewrite !ltnNge; apply: contra => lemn. by elim: e {e_gt0} => // e IHe; rewrite !expnS leq_mul. by elim: e e_gt0 => // [[|e] IHe] _; rewrite ?expn1 // ltn_mul // IHe. Qed. Lemma leq_exp2r m n e : e > 0 -> (m ^ e <= n ^ e) = (m <= n). Proof. by move=> e_gt0; rewrite leqNgt ltn_exp2r // -leqNgt. Qed. Lemma eqn_exp2r m n e : e > 0 -> (m ^ e == n ^ e) = (m == n). Proof. by move=> e_gt0; rewrite !eqn_leq !leq_exp2r. Qed. Lemma expIn e : e > 0 -> injective (expn^~ e). Proof. by move=> e_gt1 m n /eqP; rewrite eqn_exp2r // => /eqP. Qed. Lemma iterX (T : Type) (n m : nat) (f : T -> T) : iter (n ^ m) f =1 iter m (iter n) f. Proof. elim: m => //= m ihm x; rewrite expnS iterM; exact/eq_iter. Qed. (* Factorial. *) Fixpoint factorial n := if n is n'.+1 then n * factorial n' else 1. Arguments factorial : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use factorial instead.")] Definition fact_rec := factorial. Notation "n `!" := (factorial n) (at level 1, format "n `!") : nat_scope. Lemma factE n : factorial n = if n is n'.+1 then n * factorial n' else 1. Proof. by case: n. Qed. Lemma fact0 : 0`! = 1. Proof. by []. Qed. Lemma factS n : (n.+1)`! = n.+1 * n`!. Proof. by []. Qed. Lemma fact_gt0 n : n`! > 0. Proof. by elim: n => //= n IHn; rewrite muln_gt0. Qed. Lemma fact_geq n : n <= n`!. Proof. by case: n => // n; rewrite factS -(addn1 n) leq_pmulr ?fact_gt0. Qed. Lemma ltn_fact m n : 0 < m -> m < n -> m`! < n`!. Proof. case: m n => // m n _; elim: n m => // n ih [|m] ?; last by rewrite ltn_mul ?ih. by rewrite -[_.+1]muln1 leq_mul ?fact_gt0. Qed. (* Parity and bits. *) Coercion nat_of_bool (b : bool) := if b then 1 else 0. Lemma leq_b1 (b : bool) : b <= 1. Proof. by case: b. Qed. Lemma addn_negb (b : bool) : ~~ b + b = 1. Proof. by case: b. Qed. Lemma eqb0 (b : bool) : (b == 0 :> nat) = ~~ b. Proof. by case: b. Qed. Lemma eqb1 (b : bool) : (b == 1 :> nat) = b. Proof. by case: b. Qed. Lemma lt0b (b : bool) : (b > 0) = b. Proof. by case: b. Qed. Lemma sub1b (b : bool) : 1 - b = ~~ b. Proof. by case: b. Qed. Lemma mulnb (b1 b2 : bool) : b1 * b2 = b1 && b2. Proof. by case: b1; case: b2. Qed. Lemma mulnbl (b : bool) n : b * n = (if b then n else 0). Proof. by case: b; rewrite ?mul1n. Qed. Lemma mulnbr (b : bool) n : n * b = (if b then n else 0). Proof. by rewrite mulnC mulnbl. Qed. Fixpoint odd n := if n is n'.+1 then ~~ odd n' else false. Lemma oddS n : odd n.+1 = ~~ odd n. Proof. by []. Qed. Lemma oddb (b : bool) : odd b = b. Proof. by case: b. Qed. Lemma oddD m n : odd (m + n) = odd m (+) odd n. Proof. by elim: m => [|m IHn] //=; rewrite -addTb IHn addbA addTb. Qed. Lemma oddB m n : n <= m -> odd (m - n) = odd m (+) odd n. Proof. by move=> le_nm; apply: (@canRL bool) (addbK _) _; rewrite -oddD subnK. Qed. Lemma oddN i m : odd m = false -> i <= m -> odd (m - i) = odd i. Proof. by move=> oddm /oddB ->; rewrite oddm. Qed. Lemma oddM m n : odd (m * n) = odd m && odd n. Proof. by elim: m => //= m IHm; rewrite oddD -addTb andb_addl -IHm. Qed. Lemma oddX m n : odd (m ^ n) = (n == 0) || odd m. Proof. by elim: n => // n IHn; rewrite expnS oddM {}IHn orbC; case odd. Qed. (* Doubling. *) Fixpoint double n := if n is n'.+1 then (double n').+2 else 0. Arguments double : simpl never. #[deprecated(since="mathcomp 2.3.0", note="Use double instead.")] Definition double_rec := double. Notation "n .*2" := (double n) : nat_scope. Lemma doubleE n : double n = if n is n'.+1 then (double n').+2 else 0. Proof. by case: n. Qed. Lemma double0 : 0.*2 = 0. Proof. by []. Qed. Lemma doubleS n : n.+1.*2 = n.*2.+2. Proof. by []. Qed. Lemma double_pred n : n.-1.*2 = n.*2.-2. Proof. by case: n. Qed. Lemma addnn n : n + n = n.*2. Proof. by apply: eqP; elim: n => // n IHn; rewrite addnS. Qed. Lemma mul2n m : 2 * m = m.*2. Proof. by rewrite mulSn mul1n addnn. Qed. Lemma muln2 m : m * 2 = m.*2. Proof. by rewrite mulnC mul2n. Qed. Lemma doubleD m n : (m + n).*2 = m.*2 + n.*2. Proof. by rewrite -!mul2n mulnDr. Qed. Lemma doubleB m n : (m - n).*2 = m.*2 - n.*2. Proof. by elim: m n => [|m IHm] []. Qed. Lemma leq_double m n : (m.*2 <= n.*2) = (m <= n). Proof. by rewrite /leq -doubleB; case (m - n). Qed. Lemma ltn_double m n : (m.*2 < n.*2) = (m < n). Proof. by rewrite 2!ltnNge leq_double. Qed. Lemma ltn_Sdouble m n : (m.*2.+1 < n.*2) = (m < n). Proof. by rewrite -doubleS leq_double. Qed. Lemma leq_Sdouble m n : (m.*2 <= n.*2.+1) = (m <= n). Proof. by rewrite leqNgt ltn_Sdouble -leqNgt. Qed. Lemma odd_double n : odd n.*2 = false. Proof. by rewrite -addnn oddD addbb. Qed. Lemma double_gt0 n : (0 < n.*2) = (0 < n). Proof. by case: n. Qed. Lemma double_eq0 n : (n.*2 == 0) = (n == 0). Proof. by case: n. Qed. Lemma doubleMl m n : (m * n).*2 = m.*2 * n. Proof. by rewrite -!mul2n mulnA. Qed. Lemma doubleMr m n : (m * n).*2 = m * n.*2. Proof. by rewrite -!muln2 mulnA. Qed. (* Halving. *) Fixpoint half (n : nat) : nat := if n is n'.+1 then uphalf n' else n with uphalf (n : nat) : nat := if n is n'.+1 then n'./2.+1 else n where "n ./2" := (half n) : nat_scope. Lemma uphalfE n : uphalf n = n.+1./2. Proof. by []. Qed. Lemma doubleK : cancel double half. Proof. by elim=> //= n ->. Qed. Definition half_double := doubleK. Definition double_inj := can_inj doubleK. Lemma uphalf_double n : uphalf n.*2 = n. Proof. by elim: n => //= n ->. Qed. Lemma uphalf_half n : uphalf n = odd n + n./2. Proof. by elim: n => //= n ->; rewrite addnA addn_negb. Qed. Lemma odd_double_half n : odd n + n./2.*2 = n. Proof. by elim: n => //= n {3}<-; rewrite uphalf_half doubleD; case (odd n). Qed. Lemma halfK n : n./2.*2 = n - odd n. Proof. by rewrite -[n in n - _]odd_double_half addnC addnK. Qed. Lemma uphalfK n : (uphalf n).*2 = odd n + n. Proof. by rewrite uphalfE halfK/=; case: odd; rewrite ?subn1. Qed. Lemma odd_halfK n : odd n -> n./2.*2 = n.-1. Proof. by rewrite halfK => ->; rewrite subn1. Qed. Lemma even_halfK n : ~~ odd n -> n./2.*2 = n. Proof. by rewrite halfK => /negbTE->; rewrite subn0. Qed. Lemma odd_uphalfK n : odd n -> (uphalf n).*2 = n.+1. Proof. by rewrite uphalfK => ->. Qed. Lemma even_uphalfK n : ~~ odd n -> (uphalf n).*2 = n. Proof. by rewrite uphalfK => /negbTE->. Qed. Lemma half_bit_double n (b : bool) : (b + n.*2)./2 = n. Proof. by case: b; rewrite /= (half_double, uphalf_double). Qed. Lemma halfD m n : (m + n)./2 = (odd m && odd n) + (m./2 + n./2). Proof. rewrite -[n in LHS]odd_double_half addnCA. rewrite -[m in LHS]odd_double_half -addnA -doubleD. by do 2!case: odd; rewrite /= ?add0n ?half_double ?uphalf_double. Qed. Lemma half_leq m n : m <= n -> m./2 <= n./2. Proof. by move/subnK <-; rewrite halfD addnA leq_addl. Qed. Lemma geq_half_double m n : (m <= n./2) = (m.*2 <= n). Proof. rewrite -[X in _.*2 <= X]odd_double_half. case: odd; last by rewrite leq_double. by case: m => // m; rewrite doubleS ltnS ltn_double. Qed. Lemma ltn_half_double m n : (m./2 < n) = (m < n.*2). Proof. by rewrite ltnNge geq_half_double -ltnNge. Qed. Lemma leq_half_double m n : (m./2 <= n) = (m <= n.*2.+1). Proof. by case: m => [|[|m]] //; rewrite ltnS ltn_half_double. Qed. Lemma gtn_half_double m n : (n < m./2) = (n.*2.+1 < m). Proof. by rewrite ltnNge leq_half_double -ltnNge. Qed. Lemma half_gt0 n : (0 < n./2) = (1 < n). Proof. by case: n => [|[]]. Qed. Lemma uphalf_leq m n : m <= n -> uphalf m <= uphalf n. Proof. move/subnK <-; rewrite !uphalf_half oddD halfD !addnA. by do 2 case: odd; apply: leq_addl. Qed. Lemma leq_uphalf_double m n : (uphalf m <= n) = (m <= n.*2). Proof. by rewrite uphalfE leq_half_double. Qed. Lemma geq_uphalf_double m n : (m <= uphalf n) = (m.*2 <= n.+1). Proof. by rewrite uphalfE geq_half_double. Qed. Lemma gtn_uphalf_double m n : (n < uphalf m) = (n.*2 < m). Proof. by rewrite uphalfE gtn_half_double. Qed. Lemma ltn_uphalf_double m n : (uphalf m < n) = (m.+1 < n.*2). Proof. by rewrite uphalfE ltn_half_double. Qed. Lemma uphalf_gt0 n : (0 < uphalf n) = (0 < n). Proof. by case: n. Qed. Lemma odd_geq m n : odd n -> (m <= n) = (m./2.*2 <= n). Proof. move=> odd_n; rewrite -[m in LHS]odd_double_half -[n]odd_double_half odd_n. by case: (odd m); rewrite // leq_Sdouble ltnS leq_double. Qed. Lemma odd_ltn m n : odd n -> (n < m) = (n < m./2.*2). Proof. by move=> odd_n; rewrite !ltnNge odd_geq. Qed. Lemma odd_gt0 n : odd n -> n > 0. Proof. by case: n. Qed. Lemma odd_gt2 n : odd n -> n > 1 -> n > 2. Proof. by move=> odd_n n_gt1; rewrite odd_geq. Qed. (* Squares and square identities. *) Lemma mulnn m : m * m = m ^ 2. Proof. by rewrite !expnS muln1. Qed. Lemma sqrnD m n : (m + n) ^ 2 = m ^ 2 + n ^ 2 + 2 * (m * n). Proof. rewrite -!mulnn mul2n mulnDr !mulnDl (mulnC n) -!addnA. by congr (_ + _); rewrite addnA addnn addnC. Qed. Lemma sqrnB m n : n <= m -> (m - n) ^ 2 = m ^ 2 + n ^ 2 - 2 * (m * n). Proof. move/subnK <-; rewrite addnK sqrnD -addnA -addnACA -addnA. by rewrite addnn -mul2n -mulnDr -mulnDl addnK. Qed. Lemma sqrnD_sub m n : n <= m -> (m + n) ^ 2 - 4 * (m * n) = (m - n) ^ 2. Proof. move=> le_nm; rewrite -[4]/(2 * 2) -mulnA mul2n -addnn subnDA. by rewrite sqrnD addnK sqrnB. Qed. Lemma subn_sqr m n : m ^ 2 - n ^ 2 = (m - n) * (m + n). Proof. by rewrite mulnBl !mulnDr addnC (mulnC m) subnDl. Qed. Lemma ltn_sqr m n : (m ^ 2 < n ^ 2) = (m < n). Proof. by rewrite ltn_exp2r. Qed. Lemma leq_sqr m n : (m ^ 2 <= n ^ 2) = (m <= n). Proof. by rewrite leq_exp2r. Qed. Lemma sqrn_gt0 n : (0 < n ^ 2) = (0 < n). Proof. exact: (ltn_sqr 0). Qed. Lemma eqn_sqr m n : (m ^ 2 == n ^ 2) = (m == n). Proof. by rewrite eqn_exp2r. Qed. Lemma sqrn_inj : injective (expn ^~ 2). Proof. exact: expIn. Qed. (* Almost strict inequality: an inequality that is strict unless some *) (* specific condition holds, such as the Cauchy-Schwartz or the AGM *) (* inequality (we only prove the order-2 AGM here; the general one *) (* requires sequences). *) (* We formalize the concept as a rewrite multirule, that can be used *) (* both to rewrite the non-strict inequality to true, and the equality *) (* to the specific condition (for strict inequalities use the ltn_neqAle *) (* lemma); in addition, the conditional equality also coerces to a *) (* non-strict one. *) Definition leqif m n C := ((m <= n) * ((m == n) = C))%type. Notation "m <= n ?= 'iff' C" := (leqif m n C) : nat_scope. Coercion leq_of_leqif m n C (H : m <= n ?= iff C) := H.1 : m <= n. Lemma leqifP m n C : reflect (m <= n ?= iff C) (if C then m == n else m < n). Proof. rewrite ltn_neqAle; apply: (iffP idP) => [|lte]; last by rewrite !lte; case C. by case C => [/eqP-> | /andP[/negPf]]; split=> //; apply: eqxx. Qed. Lemma leqif_refl m C : reflect (m <= m ?= iff C) C. Proof. by apply: (iffP idP) => [-> | <-] //; split; rewrite ?eqxx. Qed. Lemma leqif_trans m1 m2 m3 C12 C23 : m1 <= m2 ?= iff C12 -> m2 <= m3 ?= iff C23 -> m1 <= m3 ?= iff C12 && C23. Proof. move=> ltm12 ltm23; apply/leqifP; rewrite -ltm12. have [->|eqm12] := eqVneq; first by rewrite ltn_neqAle !ltm23 andbT; case C23. by rewrite (@leq_trans m2) ?ltm23 // ltn_neqAle eqm12 ltm12. Qed. Lemma mono_leqif f : {mono f : m n / m <= n} -> forall m n C, (f m <= f n ?= iff C) = (m <= n ?= iff C). Proof. by move=> f_mono m n C; rewrite /leqif !eqn_leq !f_mono. Qed. Lemma leqif_geq m n : m <= n -> m <= n ?= iff (m >= n). Proof. by move=> lemn; split=> //; rewrite eqn_leq lemn. Qed. Lemma leqif_eq m n : m <= n -> m <= n ?= iff (m == n). Proof. by []. Qed. Lemma geq_leqif a b C : a <= b ?= iff C -> (b <= a) = C. Proof. by case=> le_ab; rewrite eqn_leq le_ab. Qed. Lemma ltn_leqif a b C : a <= b ?= iff C -> (a < b) = ~~ C. Proof. by move=> le_ab; rewrite ltnNge (geq_leqif le_ab). Qed. Lemma ltnNleqif x y C : x <= y ?= iff ~~ C -> (x < y) = C. Proof. by move=> /ltn_leqif; rewrite negbK. Qed. Lemma eq_leqif x y C : x <= y ?= iff C -> (x == y) = C. Proof. by move=> /leqifP; case: C ltngtP => [] []. Qed. Lemma eqTleqif x y C : x <= y ?= iff C -> C -> x = y. Proof. by move=> /eq_leqif<-/eqP. Qed. Lemma leqif_add m1 n1 C1 m2 n2 C2 : m1 <= n1 ?= iff C1 -> m2 <= n2 ?= iff C2 -> m1 + m2 <= n1 + n2 ?= iff C1 && C2. Proof. rewrite -(mono_leqif (leq_add2r m2)) -(mono_leqif (leq_add2l n1) m2). exact: leqif_trans. Qed. Lemma leqif_mul m1 n1 C1 m2 n2 C2 : m1 <= n1 ?= iff C1 -> m2 <= n2 ?= iff C2 -> m1 * m2 <= n1 * n2 ?= iff (n1 * n2 == 0) || (C1 && C2). Proof. case: n1 => [|n1] le1; first by case: m1 le1 => [|m1] [_ <-] //. case: n2 m2 => [|n2] [|m2] /=; try by case=> // _ <-; rewrite !muln0 ?andbF. have /leq_pmul2l-/mono_leqif<-: 0 < n1.+1 by []. by apply: leqif_trans; have /leq_pmul2r-/mono_leqif->: 0 < m2.+1. Qed. Lemma nat_Cauchy m n : 2 * (m * n) <= m ^ 2 + n ^ 2 ?= iff (m == n). Proof. without loss le_nm: m n / n <= m. by have [?|/ltnW ?] := leqP n m; last rewrite eq_sym addnC (mulnC m); apply. apply/leqifP; have [-> | ne_mn] := eqVneq; first by rewrite addnn mul2n. by rewrite -subn_gt0 -sqrnB // sqrn_gt0 subn_gt0 ltn_neqAle eq_sym ne_mn. Qed. Lemma nat_AGM2 m n : 4 * (m * n) <= (m + n) ^ 2 ?= iff (m == n). Proof. rewrite -[4]/(2 * 2) -mulnA mul2n -addnn sqrnD; apply/leqifP. by rewrite ltn_add2r eqn_add2r ltn_neqAle !nat_Cauchy; case: eqVneq. Qed. Section ContraLeq. Implicit Types (b : bool) (m n : nat) (P : Prop). Lemma contraTleq b m n : (n < m -> ~~ b) -> (b -> m <= n). Proof. by rewrite ltnNge; apply: contraTT. Qed. Lemma contraTltn b m n : (n <= m -> ~~ b) -> (b -> m < n). Proof. by rewrite ltnNge; apply: contraTN. Qed. Lemma contraPleq P m n : (n < m -> ~ P) -> (P -> m <= n). Proof. by rewrite ltnNge; apply: contraPT. Qed. Lemma contraPltn P m n : (n <= m -> ~ P) -> (P -> m < n). Proof. by rewrite ltnNge; apply: contraPN. Qed. Lemma contraNleq b m n : (n < m -> b) -> (~~ b -> m <= n). Proof. by rewrite ltnNge; apply: contraNT. Qed. Lemma contraNltn b m n : (n <= m -> b) -> (~~ b -> m < n). Proof. by rewrite ltnNge; apply: contraNN. Qed. Lemma contra_not_leq P m n : (n < m -> P) -> (~ P -> m <= n). Proof. by rewrite ltnNge; apply: contra_notT. Qed. Lemma contra_not_ltn P m n : (n <= m -> P) -> (~ P -> m < n). Proof. by rewrite ltnNge; apply: contra_notN. Qed. Lemma contraFleq b m n : (n < m -> b) -> (b = false -> m <= n). Proof. by rewrite ltnNge; apply: contraFT. Qed. Lemma contraFltn b m n : (n <= m -> b) -> (b = false -> m < n). Proof. by rewrite ltnNge; apply: contraFN. Qed. Lemma contra_leqT b m n : (~~ b -> m < n) -> (n <= m -> b). Proof. by rewrite ltnNge; apply: contraTT. Qed. Lemma contra_ltnT b m n : (~~ b -> m <= n) -> (n < m -> b). Proof. by rewrite ltnNge; apply: contraNT. Qed. Lemma contra_leqN b m n : (b -> m < n) -> (n <= m -> ~~ b). Proof. by rewrite ltnNge; apply: contraTN. Qed. Lemma contra_ltnN b m n : (b -> m <= n) -> (n < m -> ~~ b). Proof. by rewrite ltnNge; apply: contraNN. Qed. Lemma contra_leq_not P m n : (P -> m < n) -> (n <= m -> ~ P). Proof. by rewrite ltnNge; apply: contraTnot. Qed. Lemma contra_ltn_not P m n : (P -> m <= n) -> (n < m -> ~ P). Proof. by rewrite ltnNge; apply: contraNnot. Qed. Lemma contra_leqF b m n : (b -> m < n) -> (n <= m -> b = false). Proof. by rewrite ltnNge; apply: contraTF. Qed. Lemma contra_ltnF b m n : (b -> m <= n) -> (n < m -> b = false). Proof. by rewrite ltnNge; apply: contraNF. Qed. Lemma contra_leq m n p q : (q < p -> n < m) -> (m <= n -> p <= q). Proof. by rewrite !ltnNge; apply: contraTT. Qed. Lemma contra_leq_ltn m n p q : (q <= p -> n < m) -> (m <= n -> p < q). Proof. by rewrite !ltnNge; apply: contraTN. Qed. Lemma contra_ltn_leq m n p q : (q < p -> n <= m) -> (m < n -> p <= q). Proof. by rewrite !ltnNge; apply: contraNT. Qed. Lemma contra_ltn m n p q : (q <= p -> n <= m) -> (m < n -> p < q). Proof. by rewrite !ltnNge; apply: contraNN. Qed. End ContraLeq. Section Monotonicity. Variable T : Type. Lemma homo_ltn_in (D : {pred nat}) (f : nat -> T) (r : T -> T -> Prop) : (forall y x z, r x y -> r y z -> r x z) -> {in D &, forall i j k, i < k < j -> k \in D} -> {in D, forall i, i.+1 \in D -> r (f i) (f i.+1)} -> {in D &, {homo f : i j / i < j >-> r i j}}. Proof. move=> r_trans Dcx r_incr i j iD jD lt_ij; move: (lt_ij) (jD) => /subnKC<-. elim: (_ - _) => [|k ihk]; first by rewrite addn0 => Dsi; apply: r_incr. move=> DSiSk [: DSik]; apply: (r_trans _ _ _ (ihk _)); rewrite ?addnS. by abstract: DSik; apply: (Dcx _ _ iD DSiSk); rewrite ltn_addr ?addnS /=. by apply: r_incr; rewrite -?addnS. Qed. Lemma homo_ltn (f : nat -> T) (r : T -> T -> Prop) : (forall y x z, r x y -> r y z -> r x z) -> (forall i, r (f i) (f i.+1)) -> {homo f : i j / i < j >-> r i j}. Proof. by move=> /(@homo_ltn_in predT f) fr fS i j; apply: fr. Qed. Lemma homo_leq_in (D : {pred nat}) (f : nat -> T) (r : T -> T -> Prop) : (forall x, r x x) -> (forall y x z, r x y -> r y z -> r x z) -> {in D &, forall i j k, i < k < j -> k \in D} -> {in D, forall i, i.+1 \in D -> r (f i) (f i.+1)} -> {in D &, {homo f : i j / i <= j >-> r i j}}. Proof. move=> r_refl r_trans Dcx /(homo_ltn_in r_trans Dcx) lt_r i j iD jD. case: ltngtP => [? _||->] //; exact: lt_r. Qed. Lemma homo_leq (f : nat -> T) (r : T -> T -> Prop) : (forall x, r x x) -> (forall y x z, r x y -> r y z -> r x z) -> (forall i, r (f i) (f i.+1)) -> {homo f : i j / i <= j >-> r i j}. Proof. by move=> rrefl /(@homo_leq_in predT f r) fr fS i j; apply: fr. Qed. Section NatToNat. Variable (f : nat -> nat). (****************************************************************************) (* This listing of "Let"s factor out the required premises for the *) (* subsequent lemmas, putting them in the context so that "done" solves the *) (* goals quickly *) (****************************************************************************) Let ltn_neqAle := ltn_neqAle. Let gtn_neqAge x y : (y < x) = (x != y) && (y <= x). Proof. by rewrite ltn_neqAle eq_sym. Qed. Let anti_leq := anti_leq. Let anti_geq : antisymmetric geq. Proof. by move=> m n /=; rewrite andbC => /anti_leq. Qed. Let leq_total := leq_total. Lemma ltnW_homo : {homo f : m n / m < n} -> {homo f : m n / m <= n}. Proof. exact: homoW. Qed. Lemma inj_homo_ltn : injective f -> {homo f : m n / m <= n} -> {homo f : m n / m < n}. Proof. exact: inj_homo. Qed. Lemma ltnW_nhomo : {homo f : m n /~ m < n} -> {homo f : m n /~ m <= n}. Proof. exact: homoW. Qed. Lemma inj_nhomo_ltn : injective f -> {homo f : m n /~ m <= n} -> {homo f : m n /~ m < n}. Proof. exact: inj_homo. Qed. Lemma incn_inj : {mono f : m n / m <= n} -> injective f. Proof. exact: mono_inj. Qed. Lemma decn_inj : {mono f : m n /~ m <= n} -> injective f. Proof. exact: mono_inj. Qed. Lemma leqW_mono : {mono f : m n / m <= n} -> {mono f : m n / m < n}. Proof. exact: anti_mono. Qed. Lemma leqW_nmono : {mono f : m n /~ m <= n} -> {mono f : m n /~ m < n}. Proof. exact: anti_mono. Qed. Lemma leq_mono : {homo f : m n / m < n} -> {mono f : m n / m <= n}. Proof. exact: total_homo_mono. Qed. Lemma leq_nmono : {homo f : m n /~ m < n} -> {mono f : m n /~ m <= n}. Proof. exact: total_homo_mono. Qed. Variables (D D' : {pred nat}). Lemma ltnW_homo_in : {in D & D', {homo f : m n / m < n}} -> {in D & D', {homo f : m n / m <= n}}. Proof. exact: homoW_in. Qed. Lemma ltnW_nhomo_in : {in D & D', {homo f : m n /~ m < n}} -> {in D & D', {homo f : m n /~ m <= n}}. Proof. exact: homoW_in. Qed. Lemma inj_homo_ltn_in : {in D & D', injective f} -> {in D & D', {homo f : m n / m <= n}} -> {in D & D', {homo f : m n / m < n}}. Proof. exact: inj_homo_in. Qed. Lemma inj_nhomo_ltn_in : {in D & D', injective f} -> {in D & D', {homo f : m n /~ m <= n}} -> {in D & D', {homo f : m n /~ m < n}}. Proof. exact: inj_homo_in. Qed. Lemma incn_inj_in : {in D &, {mono f : m n / m <= n}} -> {in D &, injective f}. Proof. exact: mono_inj_in. Qed. Lemma decn_inj_in : {in D &, {mono f : m n /~ m <= n}} -> {in D &, injective f}. Proof. exact: mono_inj_in. Qed. Lemma leqW_mono_in : {in D &, {mono f : m n / m <= n}} -> {in D &, {mono f : m n / m < n}}. Proof. exact: anti_mono_in. Qed. Lemma leqW_nmono_in : {in D &, {mono f : m n /~ m <= n}} -> {in D &, {mono f : m n /~ m < n}}. Proof. exact: anti_mono_in. Qed. Lemma leq_mono_in : {in D &, {homo f : m n / m < n}} -> {in D &, {mono f : m n / m <= n}}. Proof. exact: total_homo_mono_in. Qed. Lemma leq_nmono_in : {in D &, {homo f : m n /~ m < n}} -> {in D &, {mono f : m n /~ m <= n}}. Proof. exact: total_homo_mono_in. Qed. End NatToNat. End Monotonicity. Lemma leq_pfact : {in [pred n | 0 < n] &, {mono factorial : m n / m <= n}}. Proof. by apply: leq_mono_in => n m n0 m0; apply: ltn_fact. Qed. Lemma leq_fact : {homo factorial : m n / m <= n}. Proof. by move=> [m|m n mn]; rewrite ?fact_gt0// leq_pfact// inE (leq_trans _ mn). Qed. Lemma ltn_pfact : {in [pred n | 0 < n] &, {mono factorial : m n / m < n}}. Proof. exact/leqW_mono_in/leq_pfact. Qed. (* Support for larger integers. The normal definitions of +, - and even *) (* IO are unsuitable for Peano integers larger than 2000 or so because *) (* they are not tail-recursive. We provide a workaround module, along *) (* with a rewrite multirule to change the tailrec operators to the *) (* normal ones. We handle IO via the NatBin module, but provide our *) (* own (more efficient) conversion functions. *) Module NatTrec. (* Usage: *) (* Import NatTrec. *) (* in section defining functions, rebinds all *) (* non-tail recursive operators. *) (* rewrite !trecE. *) (* in the correctness proof, restores operators *) Fixpoint add m n := if m is m'.+1 then m' + n.+1 else n where "n + m" := (add n m) : nat_scope. Fixpoint add_mul m n s := if m is m'.+1 then add_mul m' n (n + s) else s. Definition mul m n := if m is m'.+1 then add_mul m' n n else 0. Notation "n * m" := (mul n m) : nat_scope. Fixpoint mul_exp m n p := if n is n'.+1 then mul_exp m n' (m * p) else p. Definition exp m n := if n is n'.+1 then mul_exp m n' m else 1. Notation "n ^ m" := (exp n m) : nat_scope. Local Notation oddn := odd. Fixpoint odd n := if n is n'.+2 then odd n' else eqn n 1. Local Notation doublen := double. Definition double n := if n is n'.+1 then n' + n.+1 else 0. Notation "n .*2" := (double n) : nat_scope. Lemma addE : add =2 addn. Proof. by elim=> //= n IHn m; rewrite IHn addSnnS. Qed. Lemma doubleE : double =1 doublen. Proof. by case=> // n; rewrite -addnn -addE. Qed. Lemma add_mulE n m s : add_mul n m s = addn (muln n m) s. Proof. by elim: n => //= n IHn in m s *; rewrite IHn addE addnCA addnA. Qed. Lemma mulE : mul =2 muln. Proof. by case=> //= n m; rewrite add_mulE addnC. Qed. Lemma mul_expE m n p : mul_exp m n p = muln (expn m n) p. Proof. by elim: n => [|n IHn] in p *; rewrite ?mul1n //= expnS IHn mulE mulnCA mulnA. Qed. Lemma expE : exp =2 expn. Proof. by move=> m [|n] //=; rewrite mul_expE expnS mulnC. Qed. Lemma oddE : odd =1 oddn. Proof. move=> n; rewrite -[n in LHS]odd_double_half addnC. by elim: n./2 => //=; case (oddn n). Qed. Definition trecE := (addE, (doubleE, oddE), (mulE, add_mulE, (expE, mul_expE))). End NatTrec. Notation natTrecE := NatTrec.trecE. Definition N_eqb n m := match n, m with | N0, N0 => true | Npos p, Npos q => Pos.eqb p q | _, _ => false end. Lemma eq_binP : Equality.axiom N_eqb. Proof. move=> p q; apply: (iffP idP) => [|<-]; last by case: p => //; elim. by case: q; case: p => //; elim=> [p IHp|p IHp|] [q|q|] //= /IHp [->]. Qed. HB.instance Definition _ := hasDecEq.Build N eq_binP. Arguments N_eqb !n !m. Section NumberInterpretation. Section Trec. Import NatTrec. Fixpoint nat_of_pos p0 := match p0 with | xO p => (nat_of_pos p).*2 | xI p => (nat_of_pos p).*2.+1 | xH => 1 end. End Trec. Local Coercion nat_of_pos : positive >-> nat. Coercion nat_of_bin b := if b is Npos p then p : nat else 0. Fixpoint pos_of_nat n0 m0 := match n0, m0 with | n.+1, m.+2 => pos_of_nat n m | n.+1, 1 => xO (pos_of_nat n n) | n.+1, 0 => xI (pos_of_nat n n) | 0, _ => xH end. Definition bin_of_nat n0 := if n0 is n.+1 then Npos (pos_of_nat n n) else N0. Lemma bin_of_natK : cancel bin_of_nat nat_of_bin. Proof. have sub2nn n : n.*2 - n = n by rewrite -addnn addKn. case=> //= n; rewrite -[n in RHS]sub2nn. by elim: n {2 4}n => // m IHm [|[|n]] //=; rewrite IHm // natTrecE sub2nn. Qed. Lemma nat_of_binK : cancel nat_of_bin bin_of_nat. Proof. case=> //=; elim=> //= p; case: (nat_of_pos p) => //= n [<-]. by rewrite natTrecE !addnS {2}addnn; elim: {1 3}n. by rewrite natTrecE addnS /= addnS {2}addnn; elim: {1 3}n. Qed. Lemma nat_of_succ_pos p : Pos.succ p = p.+1 :> nat. Proof. by elim: p => //= p ->; rewrite !natTrecE. Qed. Lemma nat_of_add_pos p q : Pos.add p q = p + q :> nat. Proof. apply: @fst _ (Pos.add_carry p q = (p + q).+1 :> nat) _. elim: p q => [p IHp|p IHp|] [q|q|] //=; rewrite !natTrecE //; by rewrite ?IHp ?nat_of_succ_pos ?(doubleS, doubleD, addn1, addnS). Qed. Lemma nat_of_mul_pos p q : Pos.mul p q = p * q :> nat. Proof. elim: p => [p IHp|p IHp|] /=; rewrite ?mul1n //; by rewrite ?nat_of_add_pos /= !natTrecE IHp doubleMl. Qed. End NumberInterpretation. (* Big(ger) nat IO; usage: *) (* Num 1 072 399 *) (* to create large numbers for test cases *) (* Eval compute in [Num of some expression] *) (* to display the result of an expression that *) (* returns a larger integer. *) Record number : Type := Num {bin_of_number :> N}. Definition number_subType := Eval hnf in [isNew for bin_of_number]. HB.instance Definition _ := number_subType. HB.instance Definition _ := [Equality of number by <:]. Notation "[ 'Num' 'of' e ]" := (Num (bin_of_nat e)) (format "[ 'Num' 'of' e ]") : nat_scope. (* A congruence tactic, similar to the boolean one, along with an .+1/+ *) (* normalization tactic. *) Fixpoint pop_succn e := if e is e'.+1 then fun n => pop_succn e' n.+1 else id. Ltac pop_succn e := eval lazy beta iota delta [pop_succn] in (pop_succn e 1). Ltac succn_to_add := match goal with | |- context G [?e.+1] => let x := fresh "NatLit0" in match pop_succn e with | ?n.+1 => pose x := n.+1; let G' := context G [x] in change G' | _ ?e' ?n => pose x := n; let G' := context G [x + e'] in change G' end; succn_to_add; rewrite {}/x | _ => idtac end. Ltac nat_norm := succn_to_add; rewrite ?add0n ?addn0 -?addnA ?(addSn, addnS, add0n, addn0). Ltac nat_congr := first [ apply: (congr1 succn _) | apply: (congr1 predn _) | apply: (congr1 (addn _) _) | apply: (congr1 (subn _) _) | apply: (congr1 (addn^~ _) _) | match goal with |- (?X1 + ?X2 = ?X3) => symmetry; rewrite -1?(addnC X1) -?(addnCA X1); apply: (congr1 (addn X1) _); symmetry end ].
closed_field.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 seq. From mathcomp Require Import fintype generic_quotient bigop ssralg poly. From mathcomp Require Import polydiv matrix mxpoly countalg ring_quotient. (******************************************************************************) (* A quantifier elimination for algebraically closed fields *) (* *) (* This files contains two main contributions: *) (* 1. Factory "Field_isAlgClosed" *) (* Build an algebraically closed field that enjoy quantifier elimination, *) (* as described in *) (* ``A formal quantifier elimination for algebraically closed fields'', *) (* proceedings of Calculemus 2010, by Cyril Cohen and Assia Mahboubi *) (* *) (* We construct an instance of quantifier elimination mixin, *) (* (see the ssralg library) from the theory of polynomials with coefficients *) (* in an algebraically closed field (see the polydiv library). *) (* The algebraic operations on formulae are implemented in CPS style. *) (* We provide one CPS counterpart for each operation involved in the proof *) (* of quantifier elimination. See the paper above for more details. *) (* *) (* 2. Theorems "countable_field_extension" and "countable_algebraic_closure" *) (* constructions for both simple extension and algebraic closure of *) (* countable fields, by Georges Gonthier. *) (* Note that the construction of the algebraic closure relies on the *) (* above mentioned quantifier elimination. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Local Open Scope ring_scope. Import Pdiv.Ring. Import PreClosedField. Module ClosedFieldQE. Section ClosedFieldQE. Variables (F : fieldType) (F_closed : GRing.closed_field_axiom F). Notation fF := (@GRing.formula F). Notation tF := (@GRing.term F). Notation qf f := (GRing.qf_form f && GRing.rformula f). Definition polyF := seq tF. Lemma qf_simpl (f : fF) : (qf f -> GRing.qf_form f) * (qf f -> GRing.rformula f). Proof. by split=> /andP[]. Qed. Notation cps T := ((T -> fF) -> fF). Definition ret T1 : T1 -> cps T1 := fun x k => k x. Arguments ret {T1} x k /. Definition bind T1 T2 (x : cps T1) (f : T1 -> cps T2) : cps T2 := fun k => x (fun x => f x k). Arguments bind {T1 T2} x f k /. Notation "''let' x <- y ; z" := (bind y (fun x => z)) (at level 99, x at level 0, z at level 200, format "'[hv' ''let' x <- y ; '/' z ']'"). Definition cpsif T (c : fF) (t : T) (e : T) : cps T := fun k => GRing.If c (k t) (k e). Arguments cpsif {T} c t e k /. Notation "''if' c1 'then' c2 'else' c3" := (cpsif c1%T c2%T c3%T) (at level 200, right associativity, format "'[hv ' ''if' c1 '/' '[' 'then' c2 ']' '/' '[' 'else' c3 ']' ']'"). Notation eval := GRing.eval. Notation rterm := GRing.rterm. Notation qf_eval := GRing.qf_eval. Fixpoint eval_poly (e : seq F) pf := if pf is c :: q then eval_poly e q * 'X + (eval e c)%:P else 0. Definition rpoly (p : polyF) := all (@rterm F) p. Definition sizeT : polyF -> cps nat := (fix loop p := if p isn't c :: q then ret 0 else 'let n <- loop q; if n is m.+1 then ret m.+2 else 'if (c == 0) then 0%N else 1%N). Definition qf_red_cps T (x : cps T) (y : _ -> T) := forall e k, qf_eval e (x k) = qf_eval e (k (y e)). Notation "x ->_ e y" := (qf_red_cps x (fun e => y)) (e name, at level 90, format "x ->_ e y"). Definition qf_cps T D (x : cps T) := forall k, (forall y, D y -> qf (k y)) -> qf (x k). Lemma qf_cps_ret T D (x : T) : D x -> qf_cps D (ret x). Proof. move=> ??; exact. Qed. Hint Resolve qf_cps_ret : core. Lemma qf_cps_bind T1 D1 T2 D2 (x : cps T1) (f : T1 -> cps T2) : qf_cps D1 x -> (forall x, D1 x -> qf_cps D2 (f x)) -> qf_cps D2 (bind x f). Proof. by move=> xP fP k kP /=; apply: xP => y ?; apply: fP. Qed. Lemma qf_cps_if T D (c : fF) (t : T) (e : T) : qf c -> D t -> D e -> qf_cps D ('if c then t else e). Proof. move=> qfc Dt De k kP /=; have [qft qfe] := (kP _ Dt, kP _ De). by do !rewrite qf_simpl //. Qed. Lemma sizeTP (pf : polyF) : sizeT pf ->_e size (eval_poly e pf). Proof. elim: pf=> [|c qf qfP /=]; first by rewrite /= size_poly0. move=> e k; rewrite size_MXaddC qfP -(size_poly_eq0 (eval_poly _ _)). by case: (size (eval_poly e qf))=> //=; case: eqP; rewrite // orbF. Qed. Lemma sizeT_qf (p : polyF) : rpoly p -> qf_cps xpredT (sizeT p). Proof. elim: p => /= [_|c p ihp /andP[rc rq]]; first exact: qf_cps_ret. apply: qf_cps_bind; first exact: ihp. move=> [|n] //= _; last exact: qf_cps_ret. by apply: qf_cps_if; rewrite //= rc. Qed. Definition isnull (p : polyF) : cps bool := 'let n <- sizeT p; ret (n == 0). Lemma isnullP (p : polyF) : isnull p ->_e (eval_poly e p == 0). Proof. by move=> e k; rewrite sizeTP size_poly_eq0. Qed. Lemma isnull_qf (p : polyF) : rpoly p -> qf_cps xpredT (isnull p). Proof. move=> rp; apply: qf_cps_bind; first exact: sizeT_qf. by move=> ? _; apply: qf_cps_ret. Qed. Definition lt_sizeT (p q : polyF) : cps bool := 'let n <- sizeT p; 'let m <- sizeT q; ret (n < m). Definition lift (p : {poly F}) := map GRing.Const p. Lemma eval_lift (e : seq F) (p : {poly F}) : eval_poly e (lift p) = p. Proof. elim/poly_ind: p => [|p c]; first by rewrite /lift polyseq0. rewrite -cons_poly_def /lift polyseq_cons /nilp. case pn0: (_ == _) => /=; last by move->; rewrite -cons_poly_def. move=> _; rewrite polyseqC. case c0: (_==_)=> /=. move: pn0; rewrite (eqP c0) size_poly_eq0; move/eqP->. by apply: val_inj=> /=; rewrite polyseq_cons // polyseq0. by rewrite mul0r add0r; apply: val_inj=> /=; rewrite polyseq_cons // /nilp pn0. Qed. Fixpoint lead_coefT p : cps tF := if p is c :: q then 'let l <- lead_coefT q; 'if (l == 0) then c else l else ret 0%T. Lemma lead_coefTP (k : tF -> fF) : (forall x e, qf_eval e (k x) = qf_eval e (k (eval e x)%:T%T)) -> forall (p : polyF) (e : seq F), qf_eval e (lead_coefT p k) = qf_eval e (k (lead_coef (eval_poly e p))%:T%T). Proof. move=> kP p e; elim: p => [|a p IHp]/= in k kP e *. by rewrite lead_coef0 kP. rewrite IHp; last by move=> *; rewrite //= -kP. rewrite GRing.eval_If /= lead_coef_eq0. case p'0: (_ == _); first by rewrite (eqP p'0) mul0r add0r lead_coefC -kP. rewrite lead_coefDl ?lead_coefMX // polyseqC size_mul ?p'0 //; last first. by rewrite -size_poly_eq0 size_polyX. rewrite size_polyX addnC /=; case: (_ == _)=> //=. by rewrite ltnS lt0n size_poly_eq0 p'0. Qed. Lemma lead_coefT_qf (p : polyF) : rpoly p -> qf_cps (@rterm _) (lead_coefT p). Proof. elim: p => [_|c q ihp //= /andP[rc rq]]; first by apply: qf_cps_ret. apply: qf_cps_bind => [|y ty]; first exact: ihp. by apply: qf_cps_if; rewrite //= ty. Qed. Fixpoint amulXnT (a : tF) (n : nat) : polyF := if n is n'.+1 then 0%T :: (amulXnT a n') else [:: a]. Lemma eval_amulXnT (a : tF) (n : nat) (e : seq F) : eval_poly e (amulXnT a n) = (eval e a)%:P * 'X^n. Proof. elim: n=> [|n] /=; first by rewrite expr0 mulr1 mul0r add0r. by move->; rewrite addr0 -mulrA -exprSr. Qed. Lemma ramulXnT: forall a n, rterm a -> rpoly (amulXnT a n). Proof. by move=> a n; elim: n a=> [a /= -> //|n ihn a ra]; apply: ihn. Qed. Fixpoint sumpT (p q : polyF) := match p, q with a :: p, b :: q => (a + b)%T :: sumpT p q | [::], q => q | p, [::] => p end. Arguments sumpT : simpl nomatch. Lemma eval_sumpT (p q : polyF) (e : seq F) : eval_poly e (sumpT p q) = (eval_poly e p) + (eval_poly e q). Proof. elim: p q => [|a p Hp] q /=; first by rewrite add0r. case: q => [|b q] /=; first by rewrite addr0. rewrite Hp mulrDl -!addrA; congr (_ + _); rewrite polyCD addrC -addrA. by congr (_ + _); rewrite addrC. Qed. Lemma rsumpT (p q : polyF) : rpoly p -> rpoly q -> rpoly (sumpT p q). Proof. elim: p q=> [|a p ihp] q rp rq //; move: rp; case/andP=> ra rp. case: q rq => [|b q]; rewrite /= ?ra ?rp //=. by case/andP=> -> rq //=; apply: ihp. Qed. Fixpoint mulpT (p q : polyF) := if p isn't a :: p then [::] else sumpT [seq (a * x)%T | x <- q] (0%T :: mulpT p q). Lemma eval_mulpT (p q : polyF) (e : seq F) : eval_poly e (mulpT p q) = (eval_poly e p) * (eval_poly e q). Proof. elim: p q=> [|a p Hp] q /=; first by rewrite mul0r. rewrite eval_sumpT /= Hp addr0 mulrDl addrC mulrAC; congr (_ + _). by elim: q=> [|b q Hq] /=; rewrite ?mulr0 // Hq polyCM mulrDr mulrA. Qed. Lemma rpoly_map_mul (t : tF) (p : polyF) (rt : rterm t) : rpoly [seq (t * x)%T | x <- p] = rpoly p. Proof. by rewrite /rpoly all_map; apply/eq_all => x; rewrite /= rt. Qed. Lemma rmulpT (p q : polyF) : rpoly p -> rpoly q -> rpoly (mulpT p q). Proof. elim: p q=> [|a p ihp] q rp rq //=; move: rp; case/andP=> ra rp /=. apply: rsumpT; last exact: ihp. by rewrite rpoly_map_mul. Qed. Definition opppT : polyF -> polyF := map (GRing.Mul (- 1%T)%T). Lemma eval_opppT (p : polyF) (e : seq F) : eval_poly e (opppT p) = - eval_poly e p. Proof. by elim: p; rewrite /= ?oppr0 // => ? ? ->; rewrite !mulNr opprD polyCN mul1r. Qed. Definition natmulpT n : polyF -> polyF := map (GRing.Mul n%:R%T). Lemma eval_natmulpT (p : polyF) (n : nat) (e : seq F) : eval_poly e (natmulpT n p) = (eval_poly e p) *+ n. Proof. elim: p; rewrite //= ?mul0rn // => c p ->. rewrite mulrnDl mulr_natl polyCMn; congr (_ + _). by rewrite -mulr_natl mulrAC -mulrA mulr_natl mulrC. Qed. Fixpoint redivp_rec_loopT (q : polyF) sq cq (c : nat) (qq r : polyF) (n : nat) {struct n} : cps (nat * polyF * polyF) := 'let sr <- sizeT r; if sr < sq then ret (c, qq, r) else 'let lr <- lead_coefT r; let m := amulXnT lr (sr - sq) in let qq1 := sumpT (mulpT qq [::cq]) m in let r1 := sumpT (mulpT r ([::cq])) (opppT (mulpT m q)) in if n is n1.+1 then redivp_rec_loopT q sq cq c.+1 qq1 r1 n1 else ret (c.+1, qq1, r1). Fixpoint redivp_rec_loop (q : {poly F}) sq cq (k : nat) (qq r : {poly F}) (n : nat) {struct n} := if size r < sq then (k, qq, r) else let m := (lead_coef r) *: 'X^(size r - sq) in let qq1 := qq * cq%:P + m in let r1 := r * cq%:P - m * q in if n is n1.+1 then redivp_rec_loop q sq cq k.+1 qq1 r1 n1 else (k.+1, qq1, r1). Lemma redivp_rec_loopTP (k : nat * polyF * polyF -> fF) : (forall c qq r e, qf_eval e (k (c,qq,r)) = qf_eval e (k (c, lift (eval_poly e qq), lift (eval_poly e r)))) -> forall q sq cq c qq r n e (d := redivp_rec_loop (eval_poly e q) sq (eval e cq) c (eval_poly e qq) (eval_poly e r) n), qf_eval e (redivp_rec_loopT q sq cq c qq r n k) = qf_eval e (k (d.1.1, lift d.1.2, lift d.2)). Proof. move=> Pk q sq cq c qq r n e /=. elim: n c qq r k Pk e => [|n Pn] c qq r k Pk e; rewrite sizeTP. case ltrq : (_ < _); first by rewrite /= ltrq /= -Pk. rewrite lead_coefTP => [|a p]; rewrite [in LHS]Pk; [|symmetry]. rewrite ?(eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT) //=. by rewrite ltrq //= !mul_polyC ?(mul0r,add0r,scale0r). by rewrite [in LHS]Pk ?(eval_mulpT,eval_amulXnT,eval_sumpT, eval_opppT). case ltrq : (_<_); first by rewrite /= ltrq Pk. rewrite lead_coefTP. rewrite Pn ?(eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT) //=. by rewrite ltrq //= !mul_polyC ?(mul0r,add0r,scale0r). rewrite -/redivp_rec_loopT => x e'. rewrite Pn; last by move=> *; rewrite Pk. symmetry; rewrite Pn; last by move=> *; rewrite Pk. rewrite Pk ?(eval_lift,eval_mulpT,eval_amulXnT,eval_sumpT,eval_opppT). by rewrite mul_polyC ?(mul0r,add0r). Qed. Lemma redivp_rec_loopT_qf (q : polyF) (sq : nat) (cq : tF) (c : nat) (qq r : polyF) (n : nat) : rpoly q -> rterm cq -> rpoly qq -> rpoly r -> qf_cps (fun x => [&& rpoly x.1.2 & rpoly x.2]) (redivp_rec_loopT q sq cq c qq r n). Proof. do ![move=>x/(pair x){x}] => rw; elim: n => [|n IHn]//= in q sq cq c qq r rw *; apply: qf_cps_bind; do ?[by apply: sizeT_qf; rewrite !rw] => sr _; case: ifPn => // _; do ?[by apply: qf_cps_ret; rewrite //= ?rw]; apply: qf_cps_bind; do ?[by apply: lead_coefT_qf; rewrite !rw] => lr /= rlr; [apply: qf_cps_ret|apply: IHn]; by do !rewrite ?(rsumpT,rmulpT,ramulXnT,rpoly_map_mul,rlr,rw) //=. Qed. Definition redivpT (p : polyF) (q : polyF) : cps (nat * polyF * polyF) := 'let b <- isnull q; if b then ret (0, [::0%T], p) else 'let sq <- sizeT q; 'let sp <- sizeT p; 'let lq <- lead_coefT q; redivp_rec_loopT q sq lq 0 [::0%T] p sp. Lemma redivp_rec_loopP (q : {poly F}) (c : nat) (qq r : {poly F}) (n : nat) : redivp_rec q c qq r n = redivp_rec_loop q (size q) (lead_coef q) c qq r n. Proof. by elim: n c qq r => [| n Pn] c qq r //=; rewrite Pn. Qed. Lemma redivpTP (k : nat * polyF * polyF -> fF) : (forall c qq r e, qf_eval e (k (c,qq,r)) = qf_eval e (k (c, lift (eval_poly e qq), lift (eval_poly e r)))) -> forall p q e (d := redivp (eval_poly e p) (eval_poly e q)), qf_eval e (redivpT p q k) = qf_eval e (k (d.1.1, lift d.1.2, lift d.2)). Proof. move=> Pk p q e /=; rewrite isnullP unlock /=. case q0 : (eval_poly e q == 0) => /=; first by rewrite Pk /= mul0r add0r polyC0. rewrite !sizeTP lead_coefTP /=; last by move=> *; rewrite !redivp_rec_loopTP. rewrite redivp_rec_loopTP /=; last by move=> *; rewrite Pk. by rewrite mul0r add0r polyC0 redivp_rec_loopP. Qed. Lemma redivpT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps (fun x => [&& rpoly x.1.2 & rpoly x.2]) (redivpT p q). Proof. move=> rp rq; apply: qf_cps_bind => [|[] _]; first exact: isnull_qf. by apply: qf_cps_ret. apply: qf_cps_bind => [|sp _]; first exact: sizeT_qf. apply: qf_cps_bind => [|sq _]; first exact: sizeT_qf. apply: qf_cps_bind => [|lq rlq]; first exact: lead_coefT_qf. by apply: redivp_rec_loopT_qf => //=. Qed. Definition rmodpT (p : polyF) (q : polyF) : cps polyF := 'let d <- redivpT p q; ret d.2. Definition rdivpT (p : polyF) (q : polyF) : cps polyF := 'let d <- redivpT p q; ret d.1.2. Definition rscalpT (p : polyF) (q : polyF) : cps nat := 'let d <- redivpT p q; ret d.1.1. Definition rdvdpT (p : polyF) (q : polyF) : cps bool := 'let d <- rmodpT p q; isnull d. Fixpoint rgcdp_loop n (pp qq : {poly F}) {struct n} := let rr := rmodp pp qq in if rr == 0 then qq else if n is n1.+1 then rgcdp_loop n1 qq rr else rr. Fixpoint rgcdp_loopT n (pp : polyF) (qq : polyF) : cps polyF := 'let rr <- rmodpT pp qq; 'let nrr <- isnull rr; if nrr then ret qq else if n is n1.+1 then rgcdp_loopT n1 qq rr else ret rr. Lemma rgcdp_loopP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall n p q e, qf_eval e (rgcdp_loopT n p q k) = qf_eval e (k (lift (rgcdp_loop n (eval_poly e p) (eval_poly e q)))). Proof. move=> Pk n p q e; elim: n => /= [| m IHm] in p q e *; rewrite redivpTP /==> *; rewrite ?isnullP ?eval_lift -/(rmodp _ _); by case: (_ == _); do ?by rewrite -?Pk ?IHm ?eval_lift. Qed. Lemma rgcdp_loopT_qf (n : nat) (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgcdp_loopT n p q). Proof. elim: n => [|n IHn] in p q * => rp rq /=; (apply: qf_cps_bind=> [|rr rrr]; [ apply: qf_cps_bind => [|[[a u] v]]; do ?exact: redivpT_qf; by move=> /andP[/= ??]; apply: (@qf_cps_ret _ rpoly)| apply: qf_cps_bind => [|[] _]; by [apply: isnull_qf|apply: qf_cps_ret|apply: IHn]]). Qed. Definition rgcdpT (p : polyF) (q : polyF) : cps polyF := let aux p1 q1 : cps polyF := 'let b <- isnull p1; if b then ret q1 else 'let n <- sizeT p1; rgcdp_loopT n p1 q1 in 'let b <- lt_sizeT p q; if b then aux q p else aux p q. Lemma rgcdpTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q e, qf_eval e (rgcdpT p q k) = qf_eval e (k (lift (rgcdp (eval_poly e p) (eval_poly e q)))). Proof. move=> Pk p q e; rewrite /rgcdpT /rgcdp !sizeTP /=. case: (_ < _); rewrite !isnullP /=; case: (_ == _); rewrite -?Pk ?sizeTP; by rewrite ?rgcdp_loopP. Qed. Lemma rgcdpT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgcdpT p q). Proof. move=> rp rq k kP; rewrite /rgcdpT /=; do ![rewrite sizeT_qf => // ? _]. case: (_ < _); rewrite ?isnull_qf // => -[]; rewrite ?kP // => _; by rewrite sizeT_qf => // ? _; rewrite rgcdp_loopT_qf. Qed. Fixpoint rgcdpTs (ps : seq polyF) : cps polyF := if ps is p :: pr then 'let pr <- rgcdpTs pr; rgcdpT p pr else ret [::0%T]. Lemma rgcdpTsP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall ps e, qf_eval e (rgcdpTs ps k) = qf_eval e (k (lift (\big[@rgcdp _/0%:P]_(i <- ps)(eval_poly e i)))). Proof. move=> Pk ps e; elim: ps k Pk => [|p ps Pps] /= k Pk. by rewrite /= big_nil Pk /= mul0r add0r. by rewrite big_cons Pps => *; rewrite !rgcdpTP // !eval_lift -?Pk. Qed. Lemma rgcdpTs_qf (ps : seq polyF) : all rpoly ps -> qf_cps rpoly (rgcdpTs ps). Proof. elim: ps => [_|c p ihp /andP[rc rp]] //=; first exact: qf_cps_ret. by apply: qf_cps_bind => [|r rr]; [apply: ihp|apply: rgcdpT_qf]. Qed. Fixpoint rgdcop_recT n (q : polyF) (p : polyF) := if n is m.+1 then 'let g <- rgcdpT p q; 'let sg <- sizeT g; if sg == 1 then ret p else 'let r <- rdivpT p g; rgdcop_recT m q r else 'let b <- isnull q; ret [::b%:R%T]. Lemma rgdcop_recTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q n e, qf_eval e (rgdcop_recT n p q k) = qf_eval e (k (lift (rgdcop_rec (eval_poly e p) (eval_poly e q) n))). Proof. move=> Pk p q n e; elim: n => [|n Pn] /= in k Pk p q e *. rewrite isnullP /=. by case: (_ == _); rewrite Pk /= mul0r add0r ?(polyC0, polyC1). rewrite /rcoprimep rgcdpTP ?sizeTP ?eval_lift => * /=. case: (_ == _); by do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. case: (_ == _); by do ?[rewrite /= ?(=^~Pk, redivpTP, rgcdpTP, sizeTP, Pn, eval_lift) //==> *]. Qed. Lemma rgdcop_recT_qf (n : nat) (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgdcop_recT n p q). Proof. elim: n => [|n ihn] in p q * => k kP rp rq /=. by rewrite isnull_qf => //*; rewrite rq. rewrite rgcdpT_qf=> //*; rewrite sizeT_qf=> //*. case: (_ == _); rewrite ?kP ?rq //= redivpT_qf=> //= ? /andP[??]. by rewrite ihn. Qed. Definition rgdcopT q p := 'let sp <- sizeT p; rgdcop_recT sp q p. Lemma rgdcopTP (k : polyF -> fF) : (forall p e, qf_eval e (k p) = qf_eval e (k (lift (eval_poly e p)))) -> forall p q e, qf_eval e (rgdcopT p q k) = qf_eval e (k (lift (rgdcop (eval_poly e p) (eval_poly e q)))). Proof. by move=> *; rewrite sizeTP rgdcop_recTP 1?Pk. Qed. Lemma rgdcopT_qf (p : polyF) (q : polyF) : rpoly p -> rpoly q -> qf_cps rpoly (rgdcopT p q). Proof. by move=> rp rq k kP; rewrite sizeT_qf => //*; rewrite rgdcop_recT_qf. Qed. Definition ex_elim_seq (ps : seq polyF) (q : polyF) : fF := ('let g <- rgcdpTs ps; 'let d <- rgdcopT q g; 'let n <- sizeT d; ret (n != 1)) GRing.Bool. Lemma ex_elim_seqP (ps : seq polyF) (q : polyF) (e : seq F) : let gp := (\big[@rgcdp _/0%:P]_(p <- ps)(eval_poly e p)) in qf_eval e (ex_elim_seq ps q) = (size (rgdcop (eval_poly e q) gp) != 1). Proof. by do ![rewrite (rgcdpTsP,rgdcopTP,sizeTP,eval_lift) //= | move=> * //=]. Qed. Lemma ex_elim_seq_qf (ps : seq polyF) (q : polyF) : all rpoly ps -> rpoly q -> qf (ex_elim_seq ps q). Proof. move=> rps rq; apply: rgcdpTs_qf=> // g rg; apply: rgdcopT_qf=> // d rd. exact : sizeT_qf. Qed. Fixpoint abstrX (i : nat) (t : tF) := match t with | 'X_n => if n == i then [::0; 1] else [::t] | - x => opppT (abstrX i x) | x + y => sumpT (abstrX i x) (abstrX i y) | x * y => mulpT (abstrX i x) (abstrX i y) | x *+ n => natmulpT n (abstrX i x) | x ^+ n => let ax := (abstrX i x) in iter n (mulpT ax) [::1] | _ => [::t] end%T. Lemma abstrXP (i : nat) (t : tF) (e : seq F) (x : F) : rterm t -> (eval_poly e (abstrX i t)).[x] = eval (set_nth 0 e i x) t. Proof. elim: t => [n | r | n | t tP s sP | t tP | t tP n | t tP s sP | t tP | t tP n] h. - move=> /=; case ni: (_ == _); rewrite //= ?(mul0r,add0r,addr0,polyC1,mul1r,hornerX,hornerC); by rewrite // nth_set_nth /= ni. - by rewrite /= mul0r add0r hornerC. - by rewrite /= mul0r add0r hornerC. - by case/andP: h => *; rewrite /= eval_sumpT hornerD tP ?sP. - by rewrite /= eval_opppT hornerN tP. - by rewrite /= eval_natmulpT hornerMn tP. - by case/andP: h => *; rewrite /= eval_mulpT hornerM tP ?sP. - by []. - elim: n h => [|n ihn] rt; first by rewrite /= expr0 mul0r add0r hornerC. by rewrite /= eval_mulpT exprSr hornerM ihn // mulrC tP. Qed. Lemma rabstrX (i : nat) (t : tF) : rterm t -> rpoly (abstrX i t). Proof. elim: t; do ?[ by move=> * //=; do ?case: (_ == _)]. - move=> t irt s irs /=; case/andP=> rt rs. by apply: rsumpT; rewrite ?irt ?irs //. - by move=> t irt /= rt; rewrite rpoly_map_mul ?irt //. - by move=> t irt /= n rt; rewrite rpoly_map_mul ?irt //. - move=> t irt s irs /=; case/andP=> rt rs. by apply: rmulpT; rewrite ?irt ?irs //. - move=> t irt /= n rt; move: (irt rt) => {}rt; elim: n => [|n ihn] //=. exact: rmulpT. Qed. Implicit Types tx ty : tF. Lemma abstrX_mulM (i : nat) : {morph abstrX i : x y / x * y >-> mulpT x y}%T. Proof. by []. Qed. Lemma abstrX1 (i : nat) : abstrX i 1%T = [::1%T]. Proof. done. Qed. Lemma eval_poly_mulM e : {morph eval_poly e : x y / mulpT x y >-> x * y}. Proof. by move=> x y; rewrite eval_mulpT. Qed. Lemma eval_poly1 e : eval_poly e [::1%T] = 1. Proof. by rewrite /= mul0r add0r. Qed. Notation abstrX_bigmul := (big_morph _ (abstrX_mulM _) (abstrX1 _)). Notation eval_bigmul := (big_morph _ (eval_poly_mulM _) (eval_poly1 _)). Notation bigmap_id := (big_map _ (fun _ => true) id). Lemma rseq_poly_map (x : nat) (ts : seq tF) : all (@rterm _) ts -> all rpoly (map (abstrX x) ts). Proof. by elim: ts => //= t ts iht; case/andP=> rt rts; rewrite rabstrX // iht. Qed. Definition ex_elim (x : nat) (pqs : seq tF * seq tF) := ex_elim_seq (map (abstrX x) pqs.1) (abstrX x (\big[GRing.Mul/1%T]_(q <- pqs.2) q)). Lemma ex_elim_qf (x : nat) (pqs : seq tF * seq tF) : GRing.dnf_rterm pqs -> qf (ex_elim x pqs). case: pqs => ps qs; case/andP=> /= rps rqs. apply: ex_elim_seq_qf; first exact: rseq_poly_map. apply: rabstrX=> /=. elim: qs rqs=> [|t ts iht] //=; first by rewrite big_nil. by case/andP=> rt rts; rewrite big_cons /= rt /= iht. Qed. Lemma holds_conj : forall e i x ps, all (@rterm _) ps -> (GRing.holds (set_nth 0 e i x) (foldr (fun t : tF => GRing.And (t == 0)) GRing.True%T ps) <-> all ((@root _)^~ x) (map (eval_poly e \o abstrX i) ps)). Proof. move=> e i x; elim=> [|p ps ihps] //=. case/andP=> rp rps; rewrite rootE abstrXP //. constructor; first by case=> -> hps; rewrite eqxx /=; apply/ihps. by case/andP; move/eqP=> -> psr; split=> //; apply/ihps. Qed. Lemma holds_conjn (e : seq F) (i : nat) (x : F) (ps : seq tF) : all (@rterm _) ps -> (GRing.holds (set_nth 0 e i x) (foldr (fun t : tF => GRing.And (t != 0)) GRing.True ps) <-> all (fun p => ~~root p x) (map (eval_poly e \o abstrX i) ps)). Proof. elim: ps => [|p ps ihps] //=. case/andP=> rp rps; rewrite rootE abstrXP //. constructor; first by case=> /eqP-> hps /=; apply/ihps. by case/andP=> pr psr; split; first apply/eqP=> //; apply/ihps. Qed. Lemma holds_ex_elim: GRing.valid_QE_proj ex_elim. Proof. move=> i [ps qs] /= e; case/andP=> /= rps rqs. rewrite ex_elim_seqP big_map. have -> : \big[@rgcdp _/0%:P]_(j <- ps) eval_poly e (abstrX i j) = \big[@rgcdp _/0%:P]_(j <- (map (eval_poly e) (map (abstrX i) (ps)))) j. by rewrite !big_map. rewrite -!map_comp. have aux I (l : seq I) (P : I -> {poly F}) : \big[(@gcdp F)/0]_(j <- l) P j %= \big[(@rgcdp F)/0]_(j <- l) P j. elim: l => [| u l ihl] /=; first by rewrite !big_nil eqpxx. rewrite !big_cons; move: ihl; move/(eqp_gcdr (P u)) => h. by apply: eqp_trans h _; rewrite eqp_sym; apply: eqp_rgcd_gcd. case g0: (\big[(@rgcdp F)/0%:P]_(j <- map (eval_poly e \o abstrX i) ps) j == 0). rewrite (eqP g0) rgdcop0. case m0 : (_ == 0)=> //=; rewrite ?(size_poly1,size_poly0) //=. rewrite abstrX_bigmul eval_bigmul -bigmap_id in m0. constructor=> [[x] // []] //. case=> _; move/holds_conjn=> hc; move/hc:rqs. by rewrite -root_bigmul //= (eqP m0) root0. constructor; move/negP:m0; move/negP=>m0. case: (closed_nonrootP F_closed _ m0) => x {m0}. rewrite abstrX_bigmul eval_bigmul -bigmap_id root_bigmul=> m0. exists x; do 2?constructor=> //; last by apply/holds_conjn. apply/holds_conj; rewrite //= -root_biggcd. by rewrite (eqp_root (aux _ _ _ )) (eqP g0) root0. apply: (iffP (closed_rootP F_closed _)) => -[x Px]; exists x; move: Px => //=. rewrite (eqp_root (@eqp_rgdco_gdco F _ _)) root_gdco ?g0 //. rewrite -(eqp_root (aux _ _ _ )) root_biggcd abstrX_bigmul eval_bigmul. rewrite -bigmap_id root_bigmul; case/andP=> psr qsr. do 2?constructor; first by apply/holds_conj. by apply/holds_conjn. rewrite (eqp_root(@eqp_rgdco_gdco F _ _)) root_gdco?g0// -(eqp_root(aux _ _ _)). rewrite root_biggcd abstrX_bigmul eval_bigmul -bigmap_id. rewrite root_bigmul=> [[] // [hps hqs]]; apply/andP. constructor; first by apply/holds_conj. by apply/holds_conjn. Qed. Lemma wf_ex_elim : GRing.wf_QE_proj ex_elim. Proof. by move=> i bc /= rbc; apply: ex_elim_qf. Qed. End ClosedFieldQE. End ClosedFieldQE. HB.factory Record Field_isAlgClosed F of GRing.Field F := { solve_monicpoly : GRing.closed_field_axiom F; }. HB.builders Context F of Field_isAlgClosed F. HB.instance Definition _ := GRing.Field_QE_isDecField.Build F (@ClosedFieldQE.wf_ex_elim F) (ClosedFieldQE.holds_ex_elim solve_monicpoly). HB.instance Definition _ := GRing.DecField_isAlgClosed.Build F solve_monicpoly. HB.end. Import CodeSeq. Lemma countable_field_extension (F : countFieldType) (p : {poly F}) : size p > 1 -> {E : countFieldType & {FtoE : {rmorphism F -> E} & {w : E | root (map_poly FtoE p) w & forall u : E, exists q, u = (map_poly FtoE q).[w]}}}. Proof. pose fix d i := if i is i1.+1 then let d1 := oapp (gcdp (d i1)) 0 (unpickle i1) in if size d1 > 1 then d1 else d i1 else p. move=> p_gt1; have sz_d i: size (d i) > 1 by elim: i => //= i IHi; case: ifP. have dv_d i j: i <= j -> d j %| d i. move/subnK <-; elim: {j}(j - i)%N => //= j IHj; case: ifP => //=. case: (unpickle _) => /= [q _|]; last by rewrite size_poly0. exact: dvdp_trans (dvdp_gcdl _ _) IHj. pose I : pred {poly F} := [pred q | d (pickle q).+1 %| q]. have I'co q i: q \notin I -> i > pickle q -> coprimep q (d i). rewrite inE => I'q /dv_d/coprimep_dvdl-> //; apply: contraR I'q. rewrite coprimep_sym /coprimep /= pickleK /= neq_ltn. case: ifP => [_ _| ->]; first exact: dvdp_gcdr. rewrite orbF ltnS leqn0 size_poly_eq0 gcdp_eq0 -size_poly_eq0. by rewrite -leqn0 leqNgt ltnW //. have memI q: reflect (exists i, d i %| q) (q \in I). apply: (iffP idP) => [|[i dv_di_q]]; first by exists (pickle q).+1. have [le_i_q | /I'co i_co_q] := leqP i (pickle q). rewrite inE /= pickleK /=; case: ifP => _; first exact: dvdp_gcdr. exact: dvdp_trans (dv_d _ _ le_i_q) dv_di_q. apply: contraR i_co_q _. by rewrite /coprimep (eqp_size (dvdp_gcd_idr dv_di_q)) neq_ltn sz_d orbT. have I_ideal : idealr_closed I. split=> [||a q1 q2 Iq1 Iq2]; first exact: dvdp0. by apply/memI=> [[i /idPn[]]]; rewrite dvdp1 neq_ltn sz_d orbT. apply/memI; exists (maxn (pickle q1).+1 (pickle q2).+1); apply: dvdp_add. by apply: dvdp_mull; apply: dvdp_trans Iq1; apply/dv_d/leq_maxl. by apply: dvdp_trans Iq2; apply/dv_d/leq_maxr. pose IaM := GRing.isZmodClosed.Build _ I (idealr_closedB I_ideal). pose IpM := isProperIdeal.Build _ I (idealr_closed_nontrivial I_ideal). pose Iid : idealr _ := HB.pack I IaM IpM. pose E : comNzRingType := {ideal_quot Iid}. pose PtoE : {rmorphism {poly F} -> E} := \pi_E%qT. have PtoEd i: PtoE (d i) = 0. by apply/eqP; rewrite piE Quotient.equivE subr0; apply/memI; exists i. pose Einv (z : E) (q := repr z) (dq := d (pickle q).+1) := let q_unitP := Bezout_eq1_coprimepP q dq in if q_unitP is ReflectT ex_uv then PtoE (sval (sig_eqW ex_uv)).1 else 0. have Einv0 : Einv 0 = 0. rewrite /Einv; case: Bezout_eq1_coprimepP => // ex_uv. case/negP: (oner_neq0 E); rewrite [X in X == _]piE. rewrite /= -[_ 1]/(PtoE 1); have [uv <-] := ex_uv. by rewrite rmorphD !rmorphM [X in _ + _ * X]PtoEd /= reprK !mulr0 addr0. have EmulV : forall x, x != 0 -> Einv x * x = 1. rewrite /Einv=> z nz_z; case: Bezout_eq1_coprimepP => [ex_uv |]; last first. move/Bezout_eq1_coprimepP; rewrite I'co //. by rewrite piE -{1}[z]reprK -Quotient.idealrBE subr0 in nz_z. apply/eqP; case: sig_eqW => {ex_uv} [uv uv1]; set i := _.+1 in uv1 *. rewrite piE /= -[z]reprK -(rmorphM PtoE) -Quotient.idealrBE. rewrite -[X in _ - X]uv1 opprD addNKr -mulNr. by apply/memI; exists i; apply: dvdp_mull. pose EfieldMixin := GRing.ComNzRing_isField.Build _ EmulV Einv0. pose Efield : fieldType := HB.pack E EfieldMixin. pose EIsCountable := isCountable.Build E (pcan_pickleK (can_pcan (reprK))). pose Ecount : countFieldType := HB.pack E Efield EIsCountable. pose FtoE : {rmorphism _ -> _} := PtoE \o polyC; pose w : E := PtoE 'X. have defPtoE q: (map_poly FtoE q).[w] = PtoE q. by rewrite (map_poly_comp PtoE polyC) horner_map [_.['X]]comp_polyXr. exists Ecount, FtoE, w => [|u]. by rewrite /root defPtoE (PtoEd 0). by exists (repr u); rewrite defPtoE /= reprK. Qed. Lemma countable_algebraic_closure (F : countFieldType) : {K : countClosedFieldType & {FtoK : {rmorphism F -> K} | integralRange FtoK}}. Proof. pose minXp (R : nzRingType) (p : {poly R}) := if size p > 1 then p else 'X. have minXp_gt1 R p: size (minXp R p) > 1. by rewrite /minXp; case: ifP => // _; rewrite size_polyX. have minXpE (R : nzRingType) (p : {poly R}) : size p > 1 -> minXp R p = p. by rewrite /minXp => ->. have ext1 p := countable_field_extension (minXp_gt1 _ p). pose ext1fT E p := tag (ext1 E p). pose ext1to E p : {rmorphism _ -> ext1fT E p} := tag (tagged (ext1 E p)). pose ext1w E p : ext1fT E p := s2val (tagged (tagged (ext1 E p))). have ext1root E p: root (map_poly (ext1to E p) (minXp E p)) (ext1w E p). by rewrite /ext1w; case: (tagged (tagged (ext1 E p))). have ext1gen E p u: {q | u = (map_poly (ext1to E p) q).[ext1w E p]}. by apply: sig_eqW; rewrite /ext1w; case: (tagged (tagged (ext1 E p))) u. pose pExtEnum (E : countFieldType) := nat -> {poly E}. pose Ext := {E : countFieldType & pExtEnum E}; pose MkExt : Ext := Tagged _ _. pose EtoInc (E : Ext) i := ext1to (tag E) (tagged E i). pose incEp E i j := let v := map_poly (EtoInc E i) (tagged E j) in if decode j is [:: i1; k] then if i1 == i then odflt v (unpickle k) else v else v. pose fix E_ i := if i is i1.+1 then MkExt _ (incEp (E_ i1) i1) else MkExt F \0. pose E i := tag (E_ i); pose Krep := {i : nat & E i}. pose fix toEadd i k : {rmorphism E i -> E (k + i)%N} := if k isn't k1.+1 then idfun else EtoInc _ (k1 + i)%N \o toEadd _ _. pose toE i j (le_ij : i <= j) := ecast j {rmorphism E i -> E j} (subnK le_ij) (toEadd i (j - i)%N). have toEeq i le_ii: toE i i le_ii =1 id. by rewrite /toE; move: (subnK _); rewrite subnn => ?; rewrite eq_axiomK. have toEleS i j leij leiSj z: toE i j.+1 leiSj z = EtoInc _ _ (toE i j leij z). rewrite /toE; move: (j - i)%N {leij leiSj}(subnK _) (subnK _) => k. by case: j /; rewrite (addnK i k.+1) => eq_kk; rewrite [eq_kk]eq_axiomK. have toEirr := congr1 ((toE _ _)^~ _) (bool_irrelevance _ _). have toEtrans j i k leij lejk leik z: toE i k leik z = toE j k lejk (toE i j leij z). - elim: k leik lejk => [|k IHk] leiSk lejSk. by case: j => // in leij lejSk *; rewrite toEeq. have:= lejSk; rewrite {1}leq_eqVlt ltnS => /predU1P[Dk | lejk]. by rewrite -Dk in leiSk lejSk *; rewrite toEeq. by have leik := leq_trans leij lejk; rewrite !toEleS -IHk. have [leMl leMr] := (leq_maxl, leq_maxr); pose le_max := (leq_max, leqnn, orbT). pose pairK (x y : Krep) (m := maxn _ _) := (toE _ m (leMl _ _) (tagged x), toE _ m (leMr _ _) (tagged y)). pose eqKrep x y := uncurry (@eq_op _) (pairK x y). have eqKrefl : reflexive eqKrep by move=> z; apply/eqP; apply: toEirr. have eqKsym : symmetric eqKrep. move=> z1 z2; rewrite {1}/eqKrep /= eq_sym; move: (leMl _ _) (leMr _ _). by rewrite maxnC => lez1m lez2m; congr (_ == _); apply: toEirr. have eqKtrans : transitive eqKrep. rewrite /eqKrep /= => z2 z1 z3 /eqP eq_z12 /eqP eq_z23. rewrite -(inj_eq (fmorph_inj (toE _ _ (leMr (tag z2) _)))). rewrite -!toEtrans ?le_max // maxnCA maxnA => lez3m lez1m. rewrite {lez1m}(toEtrans (maxn (tag z1) (tag z2))) // {}eq_z12. do [rewrite -toEtrans ?le_max // -maxnA => lez2m] in lez3m *. by rewrite (toEtrans (maxn (tag z2) (tag z3))) // eq_z23 -toEtrans. pose K := {eq_quot EquivRel _ eqKrefl eqKsym eqKtrans}%qT. pose cntK := isCountable.Build K (pcan_pickleK (can_pcan (reprK))). pose EtoKrep i (x : E i) : K := \pi%qT (Tagged E x). have [EtoK piEtoK]: {EtoK | forall i, EtoKrep i =1 EtoK i} by exists EtoKrep. pose FtoK := EtoK 0; rewrite {}/EtoKrep in piEtoK. have eqEtoK i j x y: toE i _ (leMl i j) x = toE j _ (leMr i j) y -> EtoK i x = EtoK j y. - by move/eqP=> eq_xy; rewrite -!piEtoK; apply/eqmodP. have toEtoK j i leij x : EtoK j (toE i j leij x) = EtoK i x. by apply: eqEtoK; rewrite -toEtrans. have EtoK_0 i: EtoK i 0 = FtoK 0 by apply: eqEtoK; rewrite !rmorph0. have EtoK_1 i: EtoK i 1 = FtoK 1 by apply: eqEtoK; rewrite !rmorph1. have EtoKeq0 i x: (EtoK i x == FtoK 0) = (x == 0). by rewrite /FtoK -!piEtoK eqmodE /= /eqKrep /= rmorph0 fmorph_eq0. have toErepr m i leim x lerm: toE _ m lerm (tagged (repr (EtoK i x))) = toE i m leim x. - have: (Tagged E x == repr (EtoK i x) %[mod K])%qT by rewrite reprK piEtoK. rewrite eqmodE /= /eqKrep; case: (repr _) => j y /= in lerm * => /eqP /=. have leijm: maxn i j <= m by rewrite geq_max leim. by move/(congr1 (toE _ _ leijm)); rewrite -!toEtrans. pose Kadd (x y : K) := EtoK _ (uncurry +%R (pairK (repr x) (repr y))). pose Kopp (x : K) := EtoK _ (- tagged (repr x)). pose Kmul (x y : K) := EtoK _ (uncurry *%R (pairK (repr x) (repr y))). pose Kinv (x : K) := EtoK _ (tagged (repr x))^-1. have EtoK_D i: {morph EtoK i : x y / x + y >-> Kadd x y}. move=> x y; apply: eqEtoK; set j := maxn (tag _) _; rewrite !rmorphD. rewrite -![X in _ = X + _]toEtrans ?le_max// => lexm. rewrite -![X in _ = _ + X]toEtrans ?le_max// => leym. by rewrite !toErepr. have EtoK_N i: {morph EtoK i : x / - x >-> Kopp x}. by move=> x; apply: eqEtoK; set j := tag _; rewrite !rmorphN toErepr. have EtoK_M i: {morph EtoK i : x y / x * y >-> Kmul x y}. move=> x y; apply: eqEtoK; set j := maxn (tag _) _; rewrite !rmorphM. rewrite -![X in _ = X * _]toEtrans ?le_max// => lexm. rewrite -![X in _ = _ * X]toEtrans ?le_max// => leym. by rewrite !toErepr. have EtoK_V i: {morph EtoK i : x / x^-1 >-> Kinv x}. by move=> x; apply: eqEtoK; set j := tag _; rewrite !fmorphV toErepr. case: {toErepr}I in (Kadd) (Kopp) (Kmul) (Kinv) EtoK_D EtoK_N EtoK_M EtoK_V. pose inEi i z := {x : E i | z = EtoK i x}; have KtoE z: {i : nat & inEi i z}. by elim/quotW: z => [[i x] /=]; exists i, x; rewrite piEtoK. have inEle i j z: i <= j -> inEi i z -> inEi j z. by move=> leij [x ->]; exists (toE i j leij x); rewrite toEtoK. have KtoE2 z1 z2: {i : nat & inEi i z1 & inEi i z2}. have [[i1 Ez1] [i2 Ez2]] := (KtoE z1, KtoE z2). by exists (maxn i1 i2); [apply: inEle Ez1 | apply: inEle Ez2]. have KtoE3 z1 z2 z3: {i : nat & inEi i z1 & inEi i z2 * inEi i z3}%type. have [[i1 Ez1] [i2 Ez2 Ez3]] := (KtoE z1, KtoE2 z2 z3). by exists (maxn i1 i2); [apply: inEle Ez1 | split; apply: inEle (leMr _ _) _]. have KaddC: commutative Kadd. by move=> u v; have [i [x ->] [y ->]] := KtoE2 u v; rewrite -!EtoK_D addrC. have KaddA: associative Kadd. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!EtoK_D addrA. have Kadd0: left_id (FtoK 0) Kadd. by move=> u; have [i [x ->]] := KtoE u; rewrite -(EtoK_0 i) -EtoK_D add0r. have KaddN: left_inverse (FtoK 0) Kopp Kadd. by move=> u; have [i [x ->]] := KtoE u; rewrite -EtoK_N -EtoK_D addNr EtoK_0. pose KzmodMixin := GRing.isZmodule.Build K KaddA KaddC Kadd0 KaddN. pose Kzmod : countZmodType := HB.pack K KzmodMixin. have KmulC: commutative Kmul. by move=> u v; have [i [x ->] [y ->]] := KtoE2 u v; rewrite -!EtoK_M mulrC. have KmulA: @associative Kzmod Kmul. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!EtoK_M mulrA. have Kmul1: left_id (FtoK 1) Kmul. by move=> u; have [i [x ->]] := KtoE u; rewrite -(EtoK_1 i) -EtoK_M mul1r. have KmulD: left_distributive Kmul Kadd. move=> u v w; have [i [x ->] [[y ->] [z ->]]] := KtoE3 u v w. by rewrite -!(EtoK_M, EtoK_D) mulrDl. have Kone_nz: FtoK 1 != FtoK 0 by rewrite EtoKeq0 oner_neq0. pose KringMixin := GRing.Zmodule_isComNzRing.Build _ KmulA KmulC Kmul1 KmulD Kone_nz. pose Kring : comNzRingType := HB.pack K Kzmod KringMixin cntK. have KmulV: forall x : Kring, x != 0 -> (Kinv x : Kring) * x = 1. move=> u; have [i [x ->]] := KtoE u; rewrite EtoKeq0 => nz_x. by rewrite -EtoK_V -[_ * _]EtoK_M mulVf ?EtoK_1. have Kinv0: Kinv (FtoK 0) = FtoK 0 by rewrite -EtoK_V invr0. pose KfieldMixin := GRing.ComNzRing_isField.Build _ KmulV Kinv0. pose Kfield : fieldType := HB.pack K Kring KfieldMixin. have EtoKAdd i : zmod_morphism (EtoK i : E i -> Kfield). by move=> x y; rewrite EtoK_D EtoK_N. have EtoKMul i : monoid_morphism (EtoK i : E i -> Kfield). by split=> [|x y]; rewrite ?EtoK_M ?EtoK_1. pose EtoKMa i := GRing.isZmodMorphism.Build _ _ _ (EtoKAdd i). pose EtoKMm i := GRing.isMonoidMorphism.Build _ _ _ (EtoKMul i). pose EtoKM i : {rmorphism _ -> _} := HB.pack (EtoK i : E i -> Kfield) (EtoKMa i) (EtoKMm i). have EtoK_E: EtoK _ = EtoKM _ by []. have toEtoKp := @eq_map_poly _ Kring _ _(toEtoK _ _ _). have Kclosed: GRing.closed_field_axiom Kfield. move=> n pK n_gt0; pose m0 := \max_(i < n) tag (KtoE (pK i)); pose m := m0.+1. have /fin_all_exists[pE DpE] (i : 'I_n): exists y, EtoK m y = pK i. pose u := KtoE (pK i); have leum0: tag u <= m0 by rewrite (bigmax_sup i). by have [y ->] := tagged u; exists (toE _ _ (leqW leum0) y); rewrite toEtoK. pose p := 'X^n - rVpoly (\row_i pE i); pose j := code [:: m0; pickle p]. pose pj := tagged (E_ j) j; pose w : E j.+1 := ext1w (E j) pj. have lemj: m <= j by rewrite (allP (ltn_code _)) ?mem_head. exists (EtoKM j.+1 w); apply/eqP; rewrite -subr_eq0; apply/eqP. transitivity (EtoKM j.+1 (map_poly (toE m j.+1 (leqW lemj)) p).[w]). rewrite -horner_map -map_poly_comp toEtoKp EtoK_E. move: (EtoKM j.+1 w) => {}w. rewrite rmorphB [_ 'X^n]map_polyXn !hornerE; congr (_ - _ : Kring). rewrite (@horner_coef_wide _ n) ?size_map_poly ?size_poly //. by apply: eq_bigr => i _; rewrite coef_map coef_rVpoly valK mxE /= DpE. suffices Dpj: map_poly (toE m j lemj) p = pj. apply/eqP; rewrite EtoKeq0 (eq_map_poly (toEleS _ _ _ _)) map_poly_comp Dpj. rewrite -rootE -[pj]minXpE ?ext1root // -Dpj size_map_poly. by rewrite size_polyDl ?size_polyXn ltnS ?size_polyN ?size_poly. rewrite {w}/pj; set j0 := (j in tagged (E_ _) j). elim: {+}j lemj => // k IHk lemSk; rewrite {}/j0 in IHk *. have:= lemSk; rewrite leq_eqVlt ltnS => /predU1P[Dm | lemk]. rewrite -{}Dm in lemSk *; rewrite {k IHk lemSk}(eq_map_poly (toEeq m _)). by rewrite map_poly_id //= /incEp codeK eqxx pickleK. rewrite (eq_map_poly (toEleS _ _ _ _)) map_poly_comp {}IHk //= /incEp codeK. by rewrite -if_neg neq_ltn lemk. suffices{Kclosed} algF_K: {FtoK : {rmorphism F -> Kfield} | integralRange FtoK}. pose Kcc := Field_isAlgClosed.Build Kfield Kclosed. by exists (HB.pack_for countClosedFieldType K Kfield Kcc). exists (EtoKM 0) => /= z; have [i [{}z ->]] := KtoE z. suffices{z} /(_ z)[p mon_p]: integralRange (toE 0 i isT). by rewrite -(fmorph_root (EtoKM i)) -map_poly_comp toEtoKp; exists p. rewrite /toE /E; clear - minXp_gt1 ext1root ext1gen. move: (i - 0)%N (subnK _) => n; case: i /. elim: n => [|n IHn] /= z; first exact: integral_id. have{z} [q ->] := ext1gen _ _ z; set pn := tagged (E_ _) _. apply: integral_horner. by apply/integral_poly=> i; rewrite coef_map; apply: integral_rmorph. apply: integral_root (ext1root _ _) _. by rewrite map_poly_eq0 -size_poly_gt0 ltnW. by apply/integral_poly=> i; rewrite coef_map; apply: integral_rmorph. Qed.
all_solvable.v
From mathcomp Require Export abelian. From mathcomp Require Export alt. From mathcomp Require Export burnside_app. From mathcomp Require Export center. From mathcomp Require Export commutator. From mathcomp Require Export cyclic. From mathcomp Require Export extraspecial. From mathcomp Require Export extremal. From mathcomp Require Export finmodule. From mathcomp Require Export frobenius. From mathcomp Require Export gfunctor. From mathcomp Require Export gseries. From mathcomp Require Export hall. From mathcomp Require Export jordanholder. From mathcomp Require Export maximal. From mathcomp Require Export nilpotent. From mathcomp Require Export pgroup. From mathcomp Require Export primitive_action. From mathcomp Require Export sylow.
Group.lean
/- Copyright (c) 2018 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.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Algebra.Order.Group.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual /-! # Conditionally complete lattices and groups. -/ open Set section Mul variable {α : Type*} {ι : Sort*} [Nonempty ι] [ConditionallyCompleteLattice α] [Mul α] @[to_additive] lemma ciSup_mul_le_ciSup_mul_ciSup [MulLeftMono α] [MulRightMono α] {f g : ι → α} (hf : BddAbove (range f)) (hg : BddAbove (range g)) : ⨆ i, f i * g i ≤ (⨆ i, f i) * ⨆ i, g i := ciSup_le fun i ↦ mul_le_mul' (le_ciSup hf i) (le_ciSup hg i) @[to_additive] lemma ciInf_mul_ciInf_le_ciInf_mul [MulLeftMono α] [MulRightMono α] {f g : ι → α} (hf : BddBelow (range f)) (hg : BddBelow (range g)) : (⨅ i, f i) * ⨅ i, g i ≤ ⨅ i, f i * g i := le_ciInf fun i ↦ mul_le_mul' (ciInf_le hf i) (ciInf_le hg i) end Mul section Group variable {α : Type*} {ι : Sort*} {ι' : Sort*} [Nonempty ι] [Nonempty ι'] [ConditionallyCompleteLattice α] [Group α] @[to_additive] theorem le_mul_ciInf [MulLeftMono α] {a : α} {g : α} {h : ι → α} (H : ∀ j, a ≤ g * h j) : a ≤ g * iInf h := inv_mul_le_iff_le_mul.mp <| le_ciInf fun _ => inv_mul_le_iff_le_mul.mpr <| H _ @[to_additive] theorem mul_ciSup_le [MulLeftMono α] {a : α} {g : α} {h : ι → α} (H : ∀ j, g * h j ≤ a) : g * iSup h ≤ a := le_mul_ciInf (α := αᵒᵈ) H @[to_additive] theorem le_ciInf_mul [MulRightMono α] {a : α} {g : ι → α} {h : α} (H : ∀ i, a ≤ g i * h) : a ≤ iInf g * h := mul_inv_le_iff_le_mul.mp <| le_ciInf fun _ => mul_inv_le_iff_le_mul.mpr <| H _ @[to_additive] theorem ciSup_mul_le [MulRightMono α] {a : α} {g : ι → α} {h : α} (H : ∀ i, g i * h ≤ a) : iSup g * h ≤ a := le_ciInf_mul (α := αᵒᵈ) H @[to_additive] theorem le_ciInf_mul_ciInf [MulLeftMono α] [MulRightMono α] {a : α} {g : ι → α} {h : ι' → α} (H : ∀ i j, a ≤ g i * h j) : a ≤ iInf g * iInf h := le_ciInf_mul fun _ => le_mul_ciInf <| H _ @[to_additive] theorem ciSup_mul_ciSup_le [MulLeftMono α] [MulRightMono α] {a : α} {g : ι → α} {h : ι' → α} (H : ∀ i j, g i * h j ≤ a) : iSup g * iSup h ≤ a := ciSup_mul_le fun _ => mul_ciSup_le <| H _ end Group
hall.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 choice. From mathcomp Require Import fintype finset prime fingroup morphism. From mathcomp Require Import automorphism quotient action gproduct gfunctor. From mathcomp Require Import commutator center pgroup finmodule nilpotent. From mathcomp Require Import sylow abelian maximal. (*****************************************************************************) (* In this files we prove the Schur-Zassenhaus splitting and transitivity *) (* theorems (under solvability assumptions), then derive P. Hall's *) (* generalization of Sylow's theorem to solvable groups and its corollaries, *) (* in particular the theory of coprime action. We develop both the theory of *) (* coprime action of a solvable group on Sylow subgroups (as in Aschbacher *) (* 18.7), and that of coprime action on Hall subgroups of a solvable group *) (* as per B & G, Proposition 1.5; however we only support external group *) (* action (as opposed to internal action by conjugation) for the latter case *) (* because it is much harder to apply in practice. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Hall. Implicit Type gT : finGroupType. Theorem SchurZassenhaus_split gT (G H : {group gT}) : Hall G H -> H <| G -> [splits G, over H]. Proof. have [n] := ubnP #|G|; elim: n => // n IHn in gT G H * => /ltnSE-Gn hallH nsHG. have [sHG nHG] := andP nsHG. have [-> | [p pr_p pH]] := trivgVpdiv H. by apply/splitsP; exists G; rewrite inE -subG1 subsetIl mul1g eqxx. have [P sylP] := Sylow_exists p H. case nPG: (P <| G); last first. pose N := ('N_G(P))%G; have sNG: N \subset G by rewrite subsetIl. have eqHN_G: H * N = G by apply: Frattini_arg sylP. pose H' := (H :&: N)%G. have nsH'N: H' <| N. by rewrite /normal subsetIr normsI ?normG ?(subset_trans sNG). have eq_iH: #|G : H| = #|N| %/ #|H'|. rewrite -divgS // -(divnMl (cardG_gt0 H')) mulnC -eqHN_G. by rewrite -mul_cardG (mulnC #|H'|) divnMl // cardG_gt0. have hallH': Hall N H'. rewrite /Hall -divgS subsetIr //= -eq_iH. by case/andP: hallH => _; apply: coprimeSg; apply: subsetIl. have: [splits N, over H']. apply: IHn hallH' nsH'N; apply: {n}leq_trans Gn. rewrite proper_card // properEneq sNG andbT; apply/eqP=> eqNG. by rewrite -eqNG normal_subnorm (subset_trans (pHall_sub sylP)) in nPG. case/splitsP=> K /complP[tiKN eqH'K]. have sKN: K \subset N by rewrite -(mul1g K) -eqH'K mulSg ?sub1set. apply/splitsP; exists K; rewrite inE -subG1; apply/andP; split. by rewrite /= -(setIidPr sKN) setIA tiKN. by rewrite eqEsubset -eqHN_G mulgS // -eqH'K mulGS mulSg ?subsetIl. pose Z := 'Z(P); pose Gbar := G / Z; pose Hbar := H / Z. have sZP: Z \subset P by apply: center_sub. have sZH: Z \subset H by apply: subset_trans (pHall_sub sylP). have sZG: Z \subset G by apply: subset_trans sHG. have nZG: Z <| G by apply: gFnormal_trans nPG. have nZH: Z <| H by apply: normalS nZG. have nHGbar: Hbar <| Gbar by apply: morphim_normal. have hallHbar: Hall Gbar Hbar by apply: morphim_Hall (normal_norm _) _. have: [splits Gbar, over Hbar]. apply: IHn => //; apply: {n}leq_trans Gn; rewrite ltn_quotient //. apply/eqP=> /(trivg_center_pgroup (pHall_pgroup sylP))/eqP. rewrite trivg_card1 (card_Hall sylP) p_part -(expn0 p). by rewrite eqn_exp2l ?prime_gt1 // lognE pH pr_p cardG_gt0. case/splitsP=> Kbar /complP[tiHKbar eqHKbar]. have: Kbar \subset Gbar by rewrite -eqHKbar mulG_subr. case/inv_quotientS=> //= ZK quoZK sZZK sZKG. have nZZK: Z <| ZK by apply: normalS nZG. have cardZK: #|ZK| = (#|Z| * #|G : H|)%N. rewrite -(Lagrange sZZK); congr (_ * _)%N. rewrite -card_quotient -?quoZK; last by case/andP: nZZK. rewrite -(divgS sHG) -(Lagrange sZG) -(Lagrange sZH) divnMl //. rewrite -!card_quotient ?normal_norm //= -/Gbar -/Hbar. by rewrite -eqHKbar (TI_cardMg tiHKbar) mulKn. have: [splits ZK, over Z]. rewrite (Gaschutz_split nZZK _ sZZK) ?center_abelian //; last first. rewrite -divgS // cardZK mulKn ?cardG_gt0 //. by case/andP: hallH => _; apply: coprimeSg. by apply/splitsP; exists 1%G; rewrite inE -subG1 subsetIr mulg1 eqxx. case/splitsP=> K /complP[tiZK eqZK]. have sKZK: K \subset ZK by rewrite -(mul1g K) -eqZK mulSg ?sub1G. have tiHK: H :&: K = 1. apply/trivgP; rewrite /= -(setIidPr sKZK) setIA -tiZK setSI //. rewrite -quotient_sub1; last by rewrite subIset 1?normal_norm. by rewrite /= quotientGI //= -quoZK tiHKbar. apply/splitsP; exists K; rewrite inE tiHK ?eqEcard subxx leqnn /=. rewrite mul_subG ?(subset_trans sKZK) //= TI_cardMg //. rewrite -(@mulKn #|K| #|Z|) ?cardG_gt0 // -TI_cardMg // eqZK. by rewrite cardZK mulKn ?cardG_gt0 // Lagrange. Qed. Theorem SchurZassenhaus_trans_sol gT (H K K1 : {group gT}) : solvable H -> K \subset 'N(H) -> K1 \subset H * K -> coprime #|H| #|K| -> #|K1| = #|K| -> exists2 x, x \in H & K1 :=: K :^ x. Proof. have [n] := ubnP #|H|. elim: n => // n IHn in gT H K K1 * => /ltnSE-leHn solH nHK. have [-> | ] := eqsVneq H 1. rewrite mul1g => sK1K _ eqK1K; exists 1; first exact: set11. by apply/eqP; rewrite conjsg1 eqEcard sK1K eqK1K /=. pose G := (H <*> K)%G. have defG: G :=: H * K by rewrite -normC // -norm_joinEl // joingC. have sHG: H \subset G by apply: joing_subl. have sKG: K \subset G by apply: joing_subr. have nsHG: H <| G by rewrite /(H <| G) sHG join_subG normG. case/(solvable_norm_abelem solH nsHG)=> M [sMH nsMG ntM] /and3P[_ abelM _]. have [sMG nMG] := andP nsMG; rewrite -defG => sK1G coHK oK1K. have nMsG (L : {set gT}): L \subset G -> L \subset 'N(M). by move/subset_trans->. have [coKM coHMK]: coprime #|M| #|K| /\ coprime #|H / M| #|K|. by apply/andP; rewrite -coprimeMl card_quotient ?nMsG ?Lagrange. have oKM (K' : {group gT}): K' \subset G -> #|K'| = #|K| -> #|K' / M| = #|K|. move=> sK'G oK'. rewrite -quotientMidr -?norm_joinEl ?card_quotient ?nMsG //; last first. by rewrite gen_subG subUset sK'G. rewrite -divgS /=; last by rewrite -gen_subG genS ?subsetUr. by rewrite norm_joinEl ?nMsG // coprime_cardMg ?mulnK // oK' coprime_sym. have [xb]: exists2 xb, xb \in H / M & K1 / M = (K / M) :^ xb. apply: IHn; try by rewrite (quotient_sol, morphim_norms, oKM K) ?(oKM K1). by apply: leq_trans leHn; rewrite ltn_quotient. by rewrite -morphimMl ?nMsG // -defG morphimS. case/morphimP=> x nMx Hx ->{xb} eqK1Kx; pose K2 := (K :^ x)%G. have{eqK1Kx} eqK12: K1 / M = K2 / M by rewrite quotientJ. suff [y My ->]: exists2 y, y \in M & K1 :=: K2 :^ y. by exists (x * y); [rewrite groupMl // (subsetP sMH) | rewrite conjsgM]. have nMK1: K1 \subset 'N(M) by apply: nMsG. have defMK: M * K1 = M <*> K1 by rewrite -normC // -norm_joinEl // joingC. have sMKM: M \subset M <*> K1 by rewrite joing_subl. have nMKM: M <| M <*> K1 by rewrite normalYl. have trMK1: M :&: K1 = 1 by rewrite coprime_TIg ?oK1K. have trMK2: M :&: K2 = 1 by rewrite coprime_TIg ?cardJg ?oK1K. apply: (Gaschutz_transitive nMKM _ sMKM) => //=; last 2 first. - by rewrite inE trMK1 defMK !eqxx. - by rewrite -!(setIC M) trMK1. - by rewrite -divgS //= -defMK coprime_cardMg oK1K // mulKn. rewrite inE trMK2 eqxx eq_sym eqEcard /= -defMK andbC. by rewrite !coprime_cardMg ?cardJg ?oK1K ?leqnn //= mulGS -quotientSK -?eqK12. Qed. Lemma SchurZassenhaus_trans_actsol gT (G A B : {group gT}) : solvable A -> A \subset 'N(G) -> B \subset A <*> G -> coprime #|G| #|A| -> #|A| = #|B| -> exists2 x, x \in G & B :=: A :^ x. Proof. set AG := A <*> G; have [n] := ubnP #|AG|. elim: n => // n IHn in gT A B G AG * => /ltnSE-leAn solA nGA sB_AG coGA oAB. have [A1 | ntA] := eqsVneq A 1. by exists 1; rewrite // conjsg1 A1 (@card1_trivg _ B) // -oAB A1 cards1. have [M [sMA nsMA ntM]] := solvable_norm_abelem solA (normal_refl A) ntA. case/is_abelemP=> q q_pr /abelem_pgroup qM; have nMA := normal_norm nsMA. have defAG: AG = A * G := norm_joinEl nGA. have sA_AG: A \subset AG := joing_subl _ _. have sG_AG: G \subset AG := joing_subr _ _. have sM_AG := subset_trans sMA sA_AG. have oAG: #|AG| = (#|A| * #|G|)%N by rewrite defAG coprime_cardMg 1?coprime_sym. have q'G: #|G|`_q = 1%N. rewrite part_p'nat ?p'natE -?prime_coprime // coprime_sym. have [_ _ [k oM]] := pgroup_pdiv qM ntM. by rewrite -(@coprime_pexpr k.+1) // -oM (coprimegS sMA). have coBG: coprime #|B| #|G| by rewrite -oAB coprime_sym. have defBG: B * G = AG. by apply/eqP; rewrite eqEcard mul_subG ?sG_AG //= oAG oAB coprime_cardMg. case nMG: (G \subset 'N(M)). have nsM_AG: M <| AG by rewrite /normal sM_AG join_subG nMA. have nMB: B \subset 'N(M) := subset_trans sB_AG (normal_norm nsM_AG). have sMB: M \subset B. have [Q sylQ]:= Sylow_exists q B; have sQB := pHall_sub sylQ. apply: subset_trans (normal_sub_max_pgroup (Hall_max _) qM nsM_AG) (sQB). rewrite pHallE (subset_trans sQB) //= oAG partnM // q'G muln1 oAB. by rewrite (card_Hall sylQ). have defAGq: AG / M = (A / M) <*> (G / M). by rewrite quotient_gen ?quotientU ?subUset ?nMA. have: B / M \subset (A / M) <*> (G / M) by rewrite -defAGq quotientS. case/IHn; rewrite ?morphim_sol ?quotient_norms ?coprime_morph //. - by rewrite -defAGq (leq_trans _ leAn) ?ltn_quotient. - by rewrite !card_quotient // -!divgS // oAB. move=> Mx; case/morphimP=> x Nx Gx ->{Mx} //; rewrite -quotientJ //= => defBq. exists x => //; apply: quotient_inj defBq; first by rewrite /normal sMB. by rewrite -(normsP nMG x Gx) /normal normJ !conjSg. pose K := M <*> G; pose R := K :&: B; pose N := 'N_G(M). have defK: K = M * G by rewrite -norm_joinEl ?(subset_trans sMA). have oK: #|K| = (#|M| * #|G|)%N. by rewrite defK coprime_cardMg // coprime_sym (coprimegS sMA). have sylM: q.-Sylow(K) M. by rewrite pHallE joing_subl /= oK partnM // q'G muln1 part_pnat_id. have sylR: q.-Sylow(K) R. rewrite pHallE subsetIl /= -(card_Hall sylM) -(@eqn_pmul2r #|G|) // -oK. rewrite -coprime_cardMg ?(coprimeSg _ coBG) ?subsetIr //=. by rewrite group_modr ?joing_subr ?(setIidPl _) // defBG join_subG sM_AG. have [mx] := Sylow_trans sylM sylR. rewrite /= -/K defK; case/imset2P=> m x Mm Gx ->{mx}. rewrite conjsgM (conjGid Mm) {m Mm} => defR. have sNG: N \subset G := subsetIl _ _. have pNG: N \proper G by rewrite /proper sNG subsetI subxx nMG. have nNA: A \subset 'N(N) by rewrite normsI ?norms_norm. have: B :^ x^-1 \subset A <*> N. rewrite norm_joinEl ?group_modl // -defAG subsetI !sub_conjgV -normJ -defR. rewrite conjGid ?(subsetP sG_AG) // normsI ?normsG // (subset_trans sB_AG) //. by rewrite join_subG normsM // -defK normsG ?joing_subr. do [case/IHn; rewrite ?cardJg ?(coprimeSg _ coGA) //= -/N] => [|y Ny defB]. rewrite joingC norm_joinEr // coprime_cardMg ?(coprimeSg sNG) //. by rewrite (leq_trans _ leAn) // oAG mulnC ltn_pmul2l // proper_card. exists (y * x); first by rewrite groupM // (subsetP sNG). by rewrite conjsgM -defB conjsgKV. Qed. Lemma Hall_exists_subJ pi gT (G : {group gT}) : solvable G -> exists2 H : {group gT}, pi.-Hall(G) H & forall K : {group gT}, K \subset G -> pi.-group K -> exists2 x, x \in G & K \subset H :^ x. Proof. have [n] := ubnP #|G|; elim: n gT G => // n IHn gT G /ltnSE-leGn solG. have [-> | ntG] := eqsVneq G 1. exists 1%G => [|_ /trivGP-> _]; last by exists 1; rewrite ?set11 ?sub1G. by rewrite pHallE sub1G cards1 part_p'nat. case: (solvable_norm_abelem solG (normal_refl _)) => // M [sMG nsMG ntM]. case/is_abelemP=> p pr_p /and3P[pM cMM _]. pose Gb := (G / M)%G; case: (IHn _ Gb) => [||Hb]; try exact: quotient_sol. by rewrite (leq_trans (ltn_quotient _ _)). case/and3P=> [sHbGb piHb pi'Hb'] transHb. case: (inv_quotientS nsMG sHbGb) => H def_H sMH sHG. have nMG := normal_norm nsMG; have nMH := subset_trans sHG nMG. have{transHb} transH (K : {group gT}): K \subset G -> pi.-group K -> exists2 x, x \in G & K \subset H :^ x. - move=> sKG piK; have nMK := subset_trans sKG nMG. case: (transHb (K / M)%G) => [||xb Gxb sKHxb]; first exact: morphimS. exact: morphim_pgroup. case/morphimP: Gxb => x Nx Gx /= def_x; exists x => //. apply/subsetP=> y Ky. have: y \in coset M y by rewrite val_coset (subsetP nMK, rcoset_refl). have: coset M y \in (H :^ x) / M. rewrite /quotient morphimJ //=. by rewrite def_x def_H in sKHxb; apply/(subsetP sKHxb)/mem_quotient. case/morphimP=> z Nz Hxz ->. rewrite val_coset //; case/rcosetP=> t Mt ->; rewrite groupMl //. by rewrite mem_conjg (subsetP sMH) // -mem_conjg (normP Nx). have{pi'Hb'} pi'H': pi^'.-nat #|G : H|. move: pi'Hb'; rewrite -!divgS // def_H !card_quotient //. by rewrite -(divnMl (cardG_gt0 M)) !Lagrange. have [pi_p | pi'p] := boolP (p \in pi). exists H => //; apply/and3P; split=> //; rewrite /pgroup. by rewrite -(Lagrange sMH) -card_quotient // pnatM -def_H (pi_pnat pM). have [ltHG | leGH {n IHn leGn transH}] := ltnP #|H| #|G|. case: (IHn _ H (leq_trans ltHG leGn)) => [|H1]; first exact: solvableS solG. case/and3P=> sH1H piH1 pi'H1' transH1. have sH1G: H1 \subset G by apply: subset_trans sHG. exists H1 => [|K sKG piK]. apply/and3P; split => //. rewrite -divgS // -(Lagrange sHG) -(Lagrange sH1H) -mulnA. by rewrite mulKn // pnatM pi'H1'. case: (transH K sKG piK) => x Gx def_K. case: (transH1 (K :^ x^-1)%G) => [||y Hy def_K1]. - by rewrite sub_conjgV. - by rewrite /pgroup cardJg. exists (y * x); first by rewrite groupMr // (subsetP sHG). by rewrite -(conjsgKV x K) conjsgM conjSg. have{leGH Gb sHbGb sHG sMH pi'H'} eqHG: H = G. by apply/eqP; rewrite -val_eqE eqEcard sHG. have{H Hb def_H eqHG piHb nMH} hallM: pi^'.-Hall(G) M. rewrite /pHall /pgroup sMG pnatNK -card_quotient //=. by rewrite -eqHG -def_H (pi_pnat pM). case/splitsP: (SchurZassenhaus_split (pHall_Hall hallM) nsMG) => H. case/complP=> trMH defG. have sHG: H \subset G by rewrite -defG mulG_subr. exists H => [|K sKG piK]. apply: etrans hallM; rewrite /pHall sMG sHG /= -!divgS // -defG andbC. by rewrite (TI_cardMg trMH) mulKn ?mulnK // pnatNK. pose G1 := (K <*> M)%G; pose K1 := (H :&: G1)%G. have nMK: K \subset 'N(M) by apply: subset_trans sKG nMG. have defG1: M * K = G1 by rewrite -normC -?norm_joinEl. have sK1G1: K1 \subset M * K by rewrite defG1 subsetIr. have coMK: coprime #|M| #|K|. by rewrite coprime_sym (pnat_coprime piK) //; apply: (pHall_pgroup hallM). case: (SchurZassenhaus_trans_sol _ nMK sK1G1 coMK) => [||x Mx defK1]. - exact: solvableS solG. - apply/eqP; rewrite -(eqn_pmul2l (cardG_gt0 M)) -TI_cardMg //; last first. by apply/trivgP; rewrite -trMH /= setIA subsetIl. rewrite -coprime_cardMg // defG1; apply/eqP; congr #|(_ : {set _})|. rewrite group_modl; last by rewrite -defG1 mulG_subl. by apply/setIidPr; rewrite defG gen_subG subUset sKG. exists x^-1; first by rewrite groupV (subsetP sMG). by rewrite -(_ : K1 :^ x^-1 = K) ?(conjSg, subsetIl) // defK1 conjsgK. Qed. End Hall. Section HallCorollaries. Variable gT : finGroupType. Corollary Hall_exists pi (G : {group gT}) : solvable G -> exists H : {group gT}, pi.-Hall(G) H. Proof. by case/(Hall_exists_subJ pi) => H; exists H. Qed. Corollary Hall_trans pi (G H1 H2 : {group gT}) : solvable G -> pi.-Hall(G) H1 -> pi.-Hall(G) H2 -> exists2 x, x \in G & H1 :=: H2 :^ x. Proof. move=> solG; have [H hallH transH] := Hall_exists_subJ pi solG. have conjH (K : {group gT}): pi.-Hall(G) K -> exists2 x, x \in G & K = (H :^ x)%G. - move=> hallK; have [sKG piK _] := and3P hallK. case: (transH K sKG piK) => x Gx sKH; exists x => //. apply/eqP; rewrite -val_eqE eqEcard sKH cardJg. by rewrite (card_Hall hallH) (card_Hall hallK) /=. case/conjH=> x1 Gx1 ->{H1}; case/conjH=> x2 Gx2 ->{H2}. exists (x2^-1 * x1); first by rewrite groupMl ?groupV. by apply: val_inj; rewrite /= conjsgM conjsgK. Qed. Corollary Hall_superset pi (G K : {group gT}) : solvable G -> K \subset G -> pi.-group K -> exists2 H : {group gT}, pi.-Hall(G) H & K \subset H. Proof. move=> solG sKG; have [H hallH transH] := Hall_exists_subJ pi solG. by case/transH=> // x Gx sKHx; exists (H :^ x)%G; rewrite ?pHallJ. Qed. Corollary Hall_subJ pi (G H K : {group gT}) : solvable G -> pi.-Hall(G) H -> K \subset G -> pi.-group K -> exists2 x, x \in G & K \subset H :^ x. Proof. move=> solG HallH sKG piK; have [M HallM sKM]:= Hall_superset solG sKG piK. have [x Gx defM] := Hall_trans solG HallM HallH. by exists x; rewrite // -defM. Qed. Corollary Hall_Jsub pi (G H K : {group gT}) : solvable G -> pi.-Hall(G) H -> K \subset G -> pi.-group K -> exists2 x, x \in G & K :^ x \subset H. Proof. move=> solG HallH sKG piK; have [x Gx sKHx] := Hall_subJ solG HallH sKG piK. by exists x^-1; rewrite ?groupV // sub_conjgV. Qed. Lemma Hall_Frattini_arg pi (G K H : {group gT}) : solvable K -> K <| G -> pi.-Hall(K) H -> K * 'N_G(H) = G. Proof. move=> solK /andP[sKG nKG] hallH. have sHG: H \subset G by apply: subset_trans sKG; case/andP: hallH. rewrite setIC group_modl //; apply/setIidPr/subsetP=> x Gx. pose H1 := (H :^ x^-1)%G. have hallH1: pi.-Hall(K) H1 by rewrite pHallJnorm // groupV (subsetP nKG). case: (Hall_trans solK hallH hallH1) => y Ky defH. rewrite -(mulKVg y x) mem_mulg //; apply/normP. by rewrite conjsgM {1}defH conjsgK conjsgKV. Qed. End HallCorollaries. Section InternalAction. Variables (pi : nat_pred) (gT : finGroupType). Implicit Types G H K A X : {group gT}. (* Part of Aschbacher (18.7.4). *) Lemma coprime_norm_cent A G : A \subset 'N(G) -> coprime #|G| #|A| -> 'N_G(A) = 'C_G(A). Proof. move=> nGA coGA; apply/eqP; rewrite eqEsubset andbC setIS ?cent_sub //=. rewrite subsetI subsetIl /= (sameP commG1P trivgP) -(coprime_TIg coGA). rewrite subsetI commg_subr subsetIr andbT. move: nGA; rewrite -commg_subl; apply: subset_trans. by rewrite commSg ?subsetIl. Qed. (* This is B & G, Proposition 1.5(a) *) Proposition coprime_Hall_exists A G : A \subset 'N(G) -> coprime #|G| #|A| -> solvable G -> exists2 H : {group gT}, pi.-Hall(G) H & A \subset 'N(H). Proof. move=> nGA coGA solG; have [H hallH] := Hall_exists pi solG. have sG_AG: G \subset A <*> G by rewrite joing_subr. have nG_AG: A <*> G \subset 'N(G) by rewrite join_subG nGA normG. pose N := 'N_(A <*> G)(H)%G. have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG. have nGN_N: G :&: N <| N by rewrite /(_ <| N) subsetIr normsI ?normG. have NG_AG: G * N = A <*> G. by apply: Hall_Frattini_arg hallH => //; apply/andP. have iGN_A: #|N| %/ #|G :&: N| = #|A|. rewrite setIC divgI -card_quotient // -quotientMidl NG_AG. rewrite card_quotient -?divgS //= norm_joinEl //. by rewrite coprime_cardMg 1?coprime_sym // mulnK. have hallGN: Hall N (G :&: N). by rewrite /Hall -divgS subsetIr //= iGN_A (coprimeSg _ coGA) ?subsetIl. case/splitsP: {hallGN nGN_N}(SchurZassenhaus_split hallGN nGN_N) => B. case/complP=> trBGN defN. have{trBGN iGN_A} oBA: #|B| = #|A|. by rewrite -iGN_A -{1}defN (TI_cardMg trBGN) mulKn. have sBN: B \subset N by rewrite -defN mulG_subr. case: (SchurZassenhaus_trans_sol solG nGA _ coGA oBA) => [|x Gx defB]. by rewrite -(normC nGA) -norm_joinEl // -NG_AG -(mul1g B) mulgSS ?sub1G. exists (H :^ x^-1)%G; first by rewrite pHallJ ?groupV. apply/subsetP=> y Ay; have: y ^ x \in B by rewrite defB memJ_conjg. move/(subsetP sBN)=> /setIP[_ /normP nHyx]. by apply/normP; rewrite -conjsgM conjgCV invgK conjsgM nHyx. Qed. (* This is B & G, Proposition 1.5(c) *) Proposition coprime_Hall_trans A G H1 H2 : A \subset 'N(G) -> coprime #|G| #|A| -> solvable G -> pi.-Hall(G) H1 -> A \subset 'N(H1) -> pi.-Hall(G) H2 -> A \subset 'N(H2) -> exists2 x, x \in 'C_G(A) & H1 :=: H2 :^ x. Proof. move: H1 => H nGA coGA solG hallH nHA hallH2. have{H2 hallH2} [x Gx -> nH1xA] := Hall_trans solG hallH2 hallH. have sG_AG: G \subset A <*> G by rewrite -{1}genGid genS ?subsetUr. have nG_AG: A <*> G \subset 'N(G) by rewrite gen_subG subUset nGA normG. pose N := 'N_(A <*> G)(H)%G. have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG. have nGN_N: G :&: N <| N. apply/normalP; rewrite subsetIr; split=> // y Ny. by rewrite conjIg (normP _) // (subsetP nGN, conjGid). have NG_AG : G * N = A <*> G. by apply: Hall_Frattini_arg hallH => //; apply/andP. have iGN_A: #|N : G :&: N| = #|A|. rewrite -card_quotient //; last by case/andP: nGN_N. rewrite (card_isog (second_isog nGN)) /= -quotientMidr (normC nGN) NG_AG. rewrite card_quotient // -divgS //= joingC norm_joinEr //. by rewrite coprime_cardMg // mulnC mulnK. have solGN: solvable (G :&: N) by apply: solvableS solG; apply: subsetIl. have oAxA: #|A :^ x^-1| = #|A| by apply: cardJg. have sAN: A \subset N by rewrite subsetI -{1}genGid genS // subsetUl. have nGNA: A \subset 'N(G :&: N). by apply/normsP=> y ?; rewrite conjIg (normsP nGA) ?(conjGid, subsetP sAN). have coGNA: coprime #|G :&: N| #|A| := coprimeSg (subsetIl _ _) coGA. case: (SchurZassenhaus_trans_sol solGN nGNA _ coGNA oAxA) => [|y GNy defAx]. have ->: (G :&: N) * A = N. apply/eqP; rewrite eqEcard -{2}(mulGid N) mulgSS ?subsetIr //=. by rewrite coprime_cardMg // -iGN_A Lagrange ?subsetIr. rewrite sub_conjgV conjIg -normJ subsetI conjGid ?joing_subl //. by rewrite mem_gen // inE Gx orbT. case/setIP: GNy => Gy; case/setIP=> _; move/normP=> nHy. exists (y * x)^-1. rewrite -coprime_norm_cent // groupV inE groupM //=; apply/normP. by rewrite conjsgM -defAx conjsgKV. by apply: val_inj; rewrite /= -{2}nHy -(conjsgM _ y) conjsgK. Qed. (* A complement to the above: 'C(A) acts on 'Nby(A) *) Lemma norm_conj_cent A G x : x \in 'C(A) -> (A \subset 'N(G :^ x)) = (A \subset 'N(G)). Proof. by move=> cAx; rewrite norm_conj_norm ?(subsetP (cent_sub A)). Qed. (* Strongest version of the centraliser lemma -- not found in textbooks! *) (* Obviously, the solvability condition could be removed once we have the *) (* Odd Order Theorem. *) Lemma strongest_coprime_quotient_cent A G H : let R := H :&: [~: G, A] in A \subset 'N(H) -> R \subset G -> coprime #|R| #|A| -> solvable R || solvable A -> 'C_G(A) / H = 'C_(G / H)(A / H). Proof. move=> R nHA sRG coRA solRA. have nRA: A \subset 'N(R) by rewrite normsI ?commg_normr. apply/eqP; rewrite eqEsubset subsetI morphimS ?subsetIl //=. rewrite (subset_trans _ (morphim_cent _ _)) ?morphimS ?subsetIr //=. apply/subsetP=> _ /setIP[/morphimP[x Nx Gx ->] cAHx]. have{cAHx} cAxR y: y \in A -> [~ x, y] \in R. move=> Ay; have Ny: y \in 'N(H) by apply: subsetP Ay. rewrite inE mem_commg // andbT coset_idr ?groupR // morphR //=. by apply/eqP; apply/commgP; apply: (centP cAHx); rewrite mem_quotient. have AxRA: A :^ x \subset R * A. apply/subsetP=> _ /imsetP[y Ay ->]. rewrite -normC // -(mulKVg y (y ^ x)) -commgEl mem_mulg //. by rewrite -groupV invg_comm cAxR. have [y Ry def_Ax]: exists2 y, y \in R & A :^ x = A :^ y. have oAx: #|A :^ x| = #|A| by rewrite cardJg. have [solR | solA] := orP solRA; first exact: SchurZassenhaus_trans_sol. by apply: SchurZassenhaus_trans_actsol; rewrite // joingC norm_joinEr. rewrite -imset_coset; apply/imsetP; exists (x * y^-1); last first. by rewrite conjgCV mkerl // ker_coset memJ_norm groupV; case/setIP: Ry. rewrite /= inE groupMl // ?(groupV, subsetP sRG) //=. apply/centP=> z Az; apply/commgP/eqP/set1P. rewrite -[[set 1]](coprime_TIg coRA) inE {1}commgEl commgEr /= -/R. rewrite invMg -mulgA invgK (@groupMl _ R) // conjMg mulgA -commgEl. rewrite groupMl ?cAxR // memJ_norm ?(groupV, subsetP nRA) // Ry /=. by rewrite groupMr // conjVg groupV conjgM -mem_conjg -def_Ax memJ_conjg. Qed. (* A weaker but more practical version, still stronger than the usual form *) (* (viz. Aschbacher 18.7.4), similar to the one needed in Aschbacher's *) (* proof of Thompson factorization. Note that the coprime and solvability *) (* assumptions could be further weakened to H :&: G (and hence become *) (* trivial if H and G are TI). However, the assumption that A act on G is *) (* needed in this case. *) Lemma coprime_norm_quotient_cent A G H : A \subset 'N(G) -> A \subset 'N(H) -> coprime #|H| #|A| -> solvable H -> 'C_G(A) / H = 'C_(G / H)(A / H). Proof. move=> nGA nHA coHA solH; have sRH := subsetIl H [~: G, A]. rewrite strongest_coprime_quotient_cent ?(coprimeSg sRH) 1?(solvableS sRH) //. by rewrite subIset // commg_subl nGA orbT. Qed. (* A useful consequence (similar to Ex. 6.1 in Aschbacher) of the stronger *) (* theorem. *) Lemma coprime_cent_mulG A G H : A \subset 'N(G) -> A \subset 'N(H) -> G \subset 'N(H) -> coprime #|H| #|A| -> solvable H -> 'C_(H * G)(A) = 'C_H(A) * 'C_G(A). Proof. move=> nHA nGA nHG coHA solH; rewrite -norm_joinEr //. have nsHG: H <| H <*> G by rewrite /normal joing_subl join_subG normG. rewrite -{2}(setIidPr (normal_sub nsHG)) setIAC. rewrite group_modr ?setSI ?joing_subr //=; symmetry; apply/setIidPl. rewrite -quotientSK ?subIset 1?normal_norm //. by rewrite !coprime_norm_quotient_cent ?normsY //= norm_joinEr ?quotientMidl. Qed. (* Another special case of the strong coprime quotient lemma; not found in *) (* textbooks, but nevertheless used implicitly throughout B & G, sometimes *) (* justified by switching to external action. *) Lemma quotient_TI_subcent K G H : G \subset 'N(K) -> G \subset 'N(H) -> K :&: H = 1 -> 'C_K(G) / H = 'C_(K / H)(G / H). Proof. move=> nGK nGH tiKH. have tiHR: H :&: [~: K, G] = 1. by apply/trivgP; rewrite /= setIC -tiKH setSI ?commg_subl. apply: strongest_coprime_quotient_cent; rewrite ?tiHR ?sub1G ?solvable1 //. by rewrite cards1 coprime1n. Qed. (* This is B & G, Proposition 1.5(d): the more traditional form of the lemma *) (* above, with the assumption H <| G weakened to H \subset G. The stronger *) (* coprime and solvability assumptions are easier to satisfy in practice. *) Proposition coprime_quotient_cent A G H : H \subset G -> A \subset 'N(H) -> coprime #|G| #|A| -> solvable G -> 'C_G(A) / H = 'C_(G / H)(A / H). Proof. move=> sHG nHA coGA solG. have sRG: H :&: [~: G, A] \subset G by rewrite subIset ?sHG. by rewrite strongest_coprime_quotient_cent ?(coprimeSg sRG) 1?(solvableS sRG). Qed. (* This is B & G, Proposition 1.5(e). *) Proposition coprime_comm_pcore A G K : A \subset 'N(G) -> coprime #|G| #|A| -> solvable G -> pi^'.-Hall(G) K -> K \subset 'C_G(A) -> [~: G, A] \subset 'O_pi(G). Proof. move=> nGA coGA solG hallK cKA. case: (coprime_Hall_exists nGA) => // H hallH nHA. have sHG: H \subset G by case/andP: hallH. have sKG: K \subset G by case/andP: hallK. have coKH: coprime #|K| #|H|. case/and3P: hallH=> _ piH _; case/and3P: hallK => _ pi'K _. by rewrite coprime_sym (pnat_coprime piH pi'K). have defG: G :=: K * H. apply/eqP; rewrite eq_sym eqEcard coprime_cardMg //. rewrite -{1}(mulGid G) mulgSS //= (card_Hall hallH) (card_Hall hallK). by rewrite mulnC partnC. have sGA_H: [~: G, A] \subset H. rewrite gen_subG defG. apply/subsetP=> _ /imset2P[_ a /imset2P[x y Kx Hy ->] Aa ->]. rewrite commMgJ (([~ x, a] =P 1) _) ?(conj1g, mul1g). by rewrite groupMl ?groupV // memJ_norm ?(subsetP nHA). by rewrite subsetI sKG in cKA; apply/commgP/(centsP cKA). apply: pcore_max; last first. by rewrite /(_ <| G) /= commg_norml commGC commg_subr nGA. by case/and3P: hallH => _ piH _; apply: pgroupS piH. Qed. End InternalAction. (* This is B & G, Proposition 1.5(b). *) Proposition coprime_Hall_subset pi (gT : finGroupType) (A G X : {group gT}) : A \subset 'N(G) -> coprime #|G| #|A| -> solvable G -> X \subset G -> pi.-group X -> A \subset 'N(X) -> exists H : {group gT}, [/\ pi.-Hall(G) H, A \subset 'N(H) & X \subset H]. Proof. have [n] := ubnP #|G|. elim: n => // n IHn in gT A G X * => /ltnSE-leGn nGA coGA solG sXG piX nXA. have [G1 | ntG] := eqsVneq G 1. case: (coprime_Hall_exists pi nGA) => // H hallH nHA. by exists H; split; rewrite // (subset_trans sXG) // G1 sub1G. have sG_AG: G \subset A <*> G by rewrite joing_subr. have sA_AG: A \subset A <*> G by rewrite joing_subl. have nG_AG: A <*> G \subset 'N(G) by rewrite join_subG nGA normG. have nsG_AG: G <| A <*> G by apply/andP. case: (solvable_norm_abelem solG nsG_AG) => // M [sMG nsMAG ntM]. have{nsMAG} [nMA nMG]: A \subset 'N(M) /\ G \subset 'N(M). by apply/andP; rewrite -join_subG normal_norm. have nMX: X \subset 'N(M) by apply: subset_trans nMG. case/is_abelemP=> p pr_p; case/and3P=> pM cMM _. have: #|G / M| < n by rewrite (leq_trans (ltn_quotient _ _)). move/(IHn _ (A / M)%G _ (X / M)%G); rewrite !(quotient_norms, quotientS) //. rewrite !(coprime_morph, quotient_sol, morphim_pgroup) //. case=> //= Hq []; case/and3P=> sHGq piHq pi'Hq' nHAq sXHq. case/inv_quotientS: (sHGq) => [|HM defHM sMHM sHMG]; first exact/andP. have nMHM := subset_trans sHMG nMG. have{sXHq} sXHM: X \subset HM by rewrite -(quotientSGK nMX) -?defHM. have{pi'Hq' sHGq} pi'HM': pi^'.-nat #|G : HM|. move: pi'Hq'; rewrite -!divgS // defHM !card_quotient //. by rewrite -(divnMl (cardG_gt0 M)) !Lagrange. have{nHAq} nHMA: A \subset 'N(HM). by rewrite -(quotientSGK nMA) ?normsG ?quotient_normG -?defHM //; apply/andP. case/orP: (orbN (p \in pi)) => pi_p. exists HM; split=> //; apply/and3P; split; rewrite /pgroup //. by rewrite -(Lagrange sMHM) pnatM -card_quotient // -defHM (pi_pnat pM). case: (ltnP #|HM| #|G|) => [ltHG | leGHM {n IHn leGn}]. case: (IHn _ A HM X (leq_trans ltHG leGn)) => // [||H [hallH nHA sXH]]. - exact: coprimeSg coGA. - exact: solvableS solG. case/and3P: hallH => sHHM piH pi'H'. have sHG: H \subset G by apply: subset_trans sHMG. exists H; split=> //; apply/and3P; split=> //. rewrite -divgS // -(Lagrange sHMG) -(Lagrange sHHM) -mulnA mulKn //. by rewrite pnatM pi'H'. have{leGHM nHMA sHMG sMHM sXHM pi'HM'} eqHMG: HM = G. by apply/eqP; rewrite -val_eqE eqEcard sHMG. have pi'M: pi^'.-group M by rewrite /pgroup (pi_pnat pM). have{HM Hq nMHM defHM eqHMG piHq} hallM: pi^'.-Hall(G) M. apply/and3P; split; rewrite // /pgroup pnatNK. by rewrite -card_quotient // -eqHMG -defHM. case: (coprime_Hall_exists pi nGA) => // H hallH nHA. pose XM := (X <*> M)%G; pose Y := (H :&: XM)%G. case/and3P: (hallH) => sHG piH _. have sXXM: X \subset XM by rewrite joing_subl. have co_pi_M (B : {group gT}): pi.-group B -> coprime #|B| #|M|. by move=> piB; rewrite (pnat_coprime piB). have hallX: pi.-Hall(XM) X. rewrite /pHall piX sXXM -divgS //= norm_joinEl //. by rewrite coprime_cardMg ?co_pi_M // mulKn. have sXMG: XM \subset G by rewrite join_subG sXG. have hallY: pi.-Hall(XM) Y. have sYXM: Y \subset XM by rewrite subsetIr. have piY: pi.-group Y by apply: pgroupS piH; apply: subsetIl. rewrite /pHall sYXM piY -divgS // -(_ : Y * M = XM). by rewrite coprime_cardMg ?co_pi_M // mulKn //. rewrite /= setIC group_modr ?joing_subr //=; apply/setIidPl. rewrite ((H * M =P G) _) // eqEcard mul_subG //= coprime_cardMg ?co_pi_M //. by rewrite (card_Hall hallM) (card_Hall hallH) partnC. have nXMA: A \subset 'N(XM) by rewrite normsY. have:= coprime_Hall_trans nXMA _ _ hallX nXA hallY. rewrite !(coprimeSg sXMG, solvableS sXMG, normsI) //. case=> // x /setIP[XMx cAx] ->. exists (H :^ x)%G; split; first by rewrite pHallJ ?(subsetP sXMG). by rewrite norm_conj_cent. by rewrite conjSg subsetIl. Qed. Section ExternalAction. Variables (pi : nat_pred) (aT gT : finGroupType). Variables (A : {group aT}) (G : {group gT}) (to : groupAction A G). Section FullExtension. Local Notation inA := (sdpair2 to). Local Notation inG := (sdpair1 to). Local Notation A' := (inA @* gval A). Local Notation G' := (inG @* gval G). Let injG : 'injm inG := injm_sdpair1 _. Let injA : 'injm inA := injm_sdpair2 _. Hypotheses (coGA : coprime #|G| #|A|) (solG : solvable G). Lemma external_action_im_coprime : coprime #|G'| #|A'|. Proof. by rewrite !card_injm. Qed. Let coGA' := external_action_im_coprime. Let solG' : solvable G' := morphim_sol _ solG. Let nGA' := im_sdpair_norm to. Lemma ext_coprime_Hall_exists : exists2 H : {group gT}, pi.-Hall(G) H & [acts A, on H | to]. Proof. have [H' hallH' nHA'] := coprime_Hall_exists pi nGA' coGA' solG'. have sHG' := pHall_sub hallH'. exists (inG @*^-1 H')%G => /=. by rewrite -(morphim_invmE injG) -{1}(im_invm injG) morphim_pHall. by rewrite actsEsd ?morphpreK // subsetIl. Qed. Lemma ext_coprime_Hall_trans (H1 H2 : {group gT}) : pi.-Hall(G) H1 -> [acts A, on H1 | to] -> pi.-Hall(G) H2 -> [acts A, on H2 | to] -> exists2 x, x \in 'C_(G | to)(A) & H1 :=: H2 :^ x. Proof. move=> hallH1 nH1A hallH2 nH2A. have sH1G := pHall_sub hallH1; have sH2G := pHall_sub hallH2. rewrite !actsEsd // in nH1A nH2A. have hallH1': pi.-Hall(G') (inG @* H1) by rewrite morphim_pHall. have hallH2': pi.-Hall(G') (inG @* H2) by rewrite morphim_pHall. have [x'] := coprime_Hall_trans nGA' coGA' solG' hallH1' nH1A hallH2' nH2A. case/setIP=> /= Gx' cAx' /eqP defH1; pose x := invm injG x'. have Gx: x \in G by rewrite -(im_invm injG) mem_morphim. have def_x': x' = inG x by rewrite invmK. exists x; first by rewrite inE Gx gacentEsd mem_morphpre /= -?def_x'. apply/eqP; move: defH1; rewrite def_x' /= -morphimJ //=. by rewrite !eqEsubset !injmSK // conj_subG. Qed. Lemma ext_norm_conj_cent (H : {group gT}) x : H \subset G -> x \in 'C_(G | to)(A) -> [acts A, on H :^ x | to] = [acts A, on H | to]. Proof. move=> sHG /setIP[Gx]. rewrite gacentEsd !actsEsd ?conj_subG ?morphimJ // 2!inE Gx /=. exact: norm_conj_cent. Qed. Lemma ext_coprime_Hall_subset (X : {group gT}) : X \subset G -> pi.-group X -> [acts A, on X | to] -> exists H : {group gT}, [/\ pi.-Hall(G) H, [acts A, on H | to] & X \subset H]. Proof. move=> sXG piX; rewrite actsEsd // => nXA'. case: (coprime_Hall_subset nGA' coGA' solG' _ (morphim_pgroup _ piX) nXA'). exact: morphimS. move=> H' /= [piH' nHA' sXH']; have sHG' := pHall_sub piH'. exists (inG @*^-1 H')%G; rewrite actsEsd ?subsetIl ?morphpreK // nHA'. rewrite -sub_morphim_pre //= sXH'; split=> //. by rewrite -(morphim_invmE injG) -{1}(im_invm injG) morphim_pHall. Qed. End FullExtension. (* We only prove a weaker form of the coprime group action centraliser *) (* lemma, because it is more convenient in practice to make G the range *) (* of the action, whence G both contains H and is stable under A. *) (* However we do restrict the coprime/solvable assumptions to H, and *) (* we do not require that G normalize H. *) Lemma ext_coprime_quotient_cent (H : {group gT}) : H \subset G -> [acts A, on H | to] -> coprime #|H| #|A| -> solvable H -> 'C_(|to)(A) / H = 'C_(|to / H)(A). Proof. move=> sHG nHA coHA solH; pose N := 'N_G(H). have nsHN: H <| N by rewrite normal_subnorm. have [sHN nHn] := andP nsHN. have sNG: N \subset G by apply: subsetIl. have nNA: {acts A, on group N | to}. split; rewrite // actsEsd // injm_subnorm ?injm_sdpair1 //=. by rewrite normsI ?norms_norm ?im_sdpair_norm -?actsEsd. rewrite -!(gacentIdom _ A) -quotientInorm -gacentIim setIAC. rewrite -(gacent_actby nNA) gacentEsd -morphpreIim /= -/N. have:= (injm_sdpair1 <[nNA]>, injm_sdpair2 <[nNA]>). set inG := sdpair1 _; set inA := sdpair2 _ => [[injG injA]]. set G' := inG @* N; set A' := inA @* A; pose H' := inG @* H. have defN: 'N(H | to) = A by apply/eqP; rewrite eqEsubset subsetIl. have def_Dq: qact_dom to H = A by rewrite qact_domE. have sAq: A \subset qact_dom to H by rewrite def_Dq. rewrite {2}def_Dq -(gacent_ract _ sAq); set to_q := (_ \ _)%gact. have:= And3 (sdprod_sdpair to_q) (injm_sdpair1 to_q) (injm_sdpair2 to_q). rewrite gacentEsd; set inAq := sdpair2 _; set inGq := sdpair1 _ => /=. set Gq := inGq @* _; set Aq := inAq @* _ => [[q_d iGq iAq]]. have nH': 'N(H') = setT. apply/eqP; rewrite -subTset -im_sdpair mulG_subG morphim_norms //=. by rewrite -actsEsd // acts_actby subxx /= (setIidPr sHN). have: 'dom (coset H' \o inA \o invm iAq) = Aq. by rewrite ['dom _]morphpre_invm /= nH' morphpreT. case/domP=> /= qA [def_qA ker_qA _ im_qA]. have{coHA} coHA': coprime #|H'| #|A'| by rewrite !card_injm. have{ker_qA} injAq: 'injm qA. rewrite {}ker_qA !ker_comp ker_coset morphpre_invm -morphpreIim /= setIC. by rewrite coprime_TIg // -kerE (trivgP injA) morphim1. have{im_qA} im_Aq : qA @* Aq = A' / H'. by rewrite {}im_qA !morphim_comp im_invm. have: 'dom (quotm (sdpair1_morphism <[nNA]>) nsHN \o invm iGq) = Gq. by rewrite ['dom _]morphpre_invm /= quotientInorm. case/domP=> /= qG [def_qG ker_qG _ im_qG]. have{ker_qG} injGq: 'injm qG. rewrite {}ker_qG ker_comp ker_quotm morphpre_invm (trivgP injG). by rewrite quotient1 morphim1. have im_Gq: qG @* Gq = G' / H'. rewrite {}im_qG morphim_comp im_invm morphim_quotm //= -/inG -/H'. by rewrite -morphimIdom setIAC setIid. have{def_qA def_qG} q_J : {in Gq & Aq, morph_act 'J 'J qG qA}. move=> x' a'; case/morphimP=> Hx; case/morphimP=> x nHx Gx -> GHx ->{Hx x'}. case/morphimP=> a _ Aa ->{a'} /=; rewrite -/inAq -/inGq. rewrite !{}def_qG {}def_qA /= !invmE // -sdpair_act //= -/inG -/inA. have Nx: x \in N by rewrite inE Gx. have Nxa: to x a \in N by case: (nNA); move/acts_act->. have [Gxa nHxa] := setIP Nxa. rewrite invmE qactE ?quotmE ?mem_morphim ?def_Dq //=. by rewrite -morphJ /= ?nH' ?inE // -sdpair_act //= actbyE. pose q := sdprodm q_d q_J. have{injAq injGq} injq: 'injm q. rewrite injm_sdprodm injAq injGq /= {}im_Aq {}im_Gq -/Aq . by rewrite -quotientGI ?im_sdpair_TI ?morphimS //= quotient1. rewrite -[inGq @*^-1 _]morphpreIim -/Gq. have sC'G: inG @*^-1 'C_G'(A') \subset G by rewrite !subIset ?subxx. rewrite -[_ / _](injmK iGq) ?quotientS //= -/inGq; congr (_ @*^-1 _). apply: (injm_morphim_inj injq); rewrite 1?injm_subcent ?subsetT //= -/q. rewrite 2?morphim_sdprodml ?morphimS //= im_Gq. rewrite morphim_sdprodmr ?morphimS //= im_Aq. rewrite {}im_qG morphim_comp morphim_invm ?morphimS //. rewrite morphim_quotm morphpreK ?subsetIl //= -/H'. rewrite coprime_norm_quotient_cent ?im_sdpair_norm ?nH' ?subsetT //=. exact: morphim_sol. Qed. End ExternalAction. Section SylowSolvableAct. Variables (gT : finGroupType) (p : nat). Implicit Types A B G X : {group gT}. Lemma sol_coprime_Sylow_exists A G : solvable A -> A \subset 'N(G) -> coprime #|G| #|A| -> exists2 P : {group gT}, p.-Sylow(G) P & A \subset 'N(P). Proof. move=> solA nGA coGA; pose AG := A <*> G. have nsG_AG: G <| AG by rewrite /normal joing_subr join_subG nGA normG. have [sG_AG nG_AG]:= andP nsG_AG. have [P sylP] := Sylow_exists p G; pose N := 'N_AG(P); pose NG := G :&: N. have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG. have sNG_G: NG \subset G := subsetIl G N. have nsNG_N: NG <| N by rewrite /normal subsetIr normsI ?normG. have defAG: G * N = AG := Frattini_arg nsG_AG sylP. have oA : #|A| = #|N| %/ #|NG|. rewrite /NG setIC divgI -card_quotient // -quotientMidl defAG. rewrite card_quotient -?divgS //= norm_joinEl //. by rewrite coprime_cardMg 1?coprime_sym // mulnK. have: [splits N, over NG]. rewrite SchurZassenhaus_split // /Hall -divgS subsetIr //. by rewrite -oA (coprimeSg sNG_G). case/splitsP=> B; case/complP=> tNG_B defN. have [nPB]: B \subset 'N(P) /\ B \subset AG. by apply/andP; rewrite andbC -subsetI -/N -defN mulG_subr. case/SchurZassenhaus_trans_actsol => // [|x Gx defB]. by rewrite oA -defN TI_cardMg // mulKn. exists (P :^ x^-1)%G; first by rewrite pHallJ ?groupV. by rewrite normJ -sub_conjg -defB. Qed. Lemma sol_coprime_Sylow_trans A G : solvable A -> A \subset 'N(G) -> coprime #|G| #|A| -> [transitive 'C_G(A), on [set P in 'Syl_p(G) | A \subset 'N(P)] | 'JG]. Proof. move=> solA nGA coGA; pose AG := A <*> G; set FpA := finset _. have nG_AG: AG \subset 'N(G) by rewrite join_subG nGA normG. have [P sylP nPA] := sol_coprime_Sylow_exists solA nGA coGA. pose N := 'N_AG(P); have sAN: A \subset N by rewrite subsetI joing_subl. have trNPA: A :^: AG ::&: N = A :^: N. pose NG := 'N_G(P); have sNG_G : NG \subset G := subsetIl _ _. have nNGA: A \subset 'N(NG) by rewrite normsI ?norms_norm. apply/setP=> Ax; apply/setIdP/imsetP=> [[]|[x Nx ->{Ax}]]; last first. by rewrite conj_subG //; case/setIP: Nx => AGx; rewrite imset_f. have ->: N = A <*> NG by rewrite /N /AG !norm_joinEl // -group_modl. have coNG_A := coprimeSg sNG_G coGA; case/imsetP=> x AGx ->{Ax}. case/SchurZassenhaus_trans_actsol; rewrite ?cardJg // => y Ny /= ->. by exists y; rewrite // mem_gen 1?inE ?Ny ?orbT. have{trNPA}: [transitive 'N_AG(A), on FpA | 'JG]. have ->: FpA = 'Fix_('Syl_p(G) | 'JG)(A). by apply/setP=> Q; rewrite 4!inE afixJG. have SylP : P \in 'Syl_p(G) by rewrite inE. apply/(trans_subnorm_fixP _ SylP); rewrite ?astab1JG //. rewrite (atrans_supgroup _ (Syl_trans _ _)) ?joing_subr //= -/AG. by apply/actsP=> x /= AGx Q /=; rewrite !inE -{1}(normsP nG_AG x) ?pHallJ2. rewrite {1}/AG norm_joinEl // -group_modl ?normG ?coprime_norm_cent //=. rewrite -cent_joinEr ?subsetIr // => trC_FpA. have FpA_P: P \in FpA by rewrite !inE sylP. apply/(subgroup_transitiveP FpA_P _ trC_FpA); rewrite ?joing_subr //=. rewrite astab1JG cent_joinEr ?subsetIr // -group_modl // -mulgA. by congr (_ * _); rewrite mulSGid ?subsetIl. Qed. Lemma sol_coprime_Sylow_subset A G X : A \subset 'N(G) -> coprime #|G| #|A| -> solvable A -> X \subset G -> p.-group X -> A \subset 'N(X) -> exists P : {group gT}, [/\ p.-Sylow(G) P, A \subset 'N(P) & X \subset P]. Proof. move=> nGA coGA solA sXG pX nXA. pose nAp (Q : {group gT}) := [&& p.-group Q, Q \subset G & A \subset 'N(Q)]. have: nAp X by apply/and3P. case/maxgroup_exists=> R; case/maxgroupP; case/and3P=> pR sRG nRA maxR sXR. have [P sylP sRP]:= Sylow_superset sRG pR. suffices defP: P :=: R by exists P; rewrite sylP defP. case/and3P: sylP => sPG pP _; apply: (nilpotent_sub_norm (pgroup_nil pP)) => //. pose N := 'N_G(R); have{sPG} sPN_N: 'N_P(R) \subset N by apply: setSI. apply: norm_sub_max_pgroup (pgroupS (subsetIl _ _) pP) sPN_N (subsetIr _ _). have nNA: A \subset 'N(N) by rewrite normsI ?norms_norm. have coNA: coprime #|N| #|A| by apply: coprimeSg coGA; rewrite subsetIl. have{solA coNA} [Q sylQ nQA] := sol_coprime_Sylow_exists solA nNA coNA. suffices defQ: Q :=: R by rewrite max_pgroup_Sylow -{2}defQ. apply: maxR; first by apply/and3P; case/and3P: sylQ; rewrite subsetI; case/andP. by apply: normal_sub_max_pgroup (Hall_max sylQ) pR _; rewrite normal_subnorm. Qed. End SylowSolvableAct.
generic_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 ssrnat choice. From mathcomp Require Import seq fintype. (*****************************************************************************) (* Quotient Types *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* Provided a base type T, this files defines an interface for quotients Q *) (* of the type T with explicit functions for canonical surjection (\pi *) (* : T -> Q) and for choosing a representative (repr : Q -> T). It then *) (* provides a helper to quotient T by a decidable equivalence relation (e *) (* : rel T) if T is a choiceType (or encodable as a choiceType modulo e). *) (* *) (* Reference: Cyril Cohen, Pragmatic Quotient Types in Coq, ITP 2013 *) (* *) (* *** Generic Quotienting *** *) (* quotType T == the type of quotient types based on T *) (* The HB class is called Quotient. *) (* *) (* The quotType interface supports these operations (in quotient_scope): *) (* \pi_Q x == the class in Q of the element x of T *) (* \pi x == the class of x where Q is inferred from the context *) (* repr c == canonical representative in T of the class c *) (* x = y %[mod Q] := \pi_Q x = \pi_Q y *) (* <-> x and y are equal modulo Q *) (* x <> y %[mod Q] := \pi_Q x <> \pi_Q y *) (* x == y %[mod Q] := \pi_Q x == \pi_Q y *) (* x != y %[mod Q] := \pi_Q x != \pi_Q y *) (* *) (* The quotient_scope is delimited by %qT, *) (* The most useful lemmas are piE and reprK. *) (* *) (* List of factories: *) (* isQuotient.Build T Q (reprK : cancel repr pi) == builds the quotient *) (* whose canonical surjection function is (pi : T -> Q) and *) (* whose representative selection function is repr *) (* *** Morphisms *** *) (* One may declare existing functions and predicates as liftings of some *) (* morphisms for a quotient. *) (* PiMorph1 pi_f == where pi_f : {morph \pi : x / f x >-> fq x} *) (* declares fq : Q -> Q as the lifting of f : T -> T *) (* PiMorph2 pi_g == idem with pi_g : {morph \pi : x y / g x y >-> gq x y} *) (* PiMono1 pi_p == idem with pi_p : {mono \pi : x / p x >-> pq x} *) (* PiMono2 pi_r == idem with pi_r : {morph \pi : x y / r x y >-> rq x y} *) (* PiMorph11 pi_f == idem with pi_f : {morph \pi : x / f x >-> fq x} *) (* where fq : Q -> Q' and f : T -> T'. *) (* PiMorph eq == Most general declaration of compatibility, *) (* /!\ use with caution /!\ *) (* One can use the following helpers to build the liftings which may or *) (* may not satisfy the above properties (but if they do not, it is *) (* probably not a good idea to define them): *) (* lift_op1 Q f := lifts f : T -> T *) (* lift_op2 Q g := lifts g : T -> T -> T *) (* lift_fun1 Q p := lifts p : T -> R *) (* lift_fun2 Q r := lifts r : T -> T -> R *) (* lift_op11 Q Q' f := lifts f : T -> T' *) (* There is also the special case of constants and embedding functions *) (* that one may define and declare as compatible with Q using: *) (* lift_cst Q x := lifts x : T to Q *) (* PiConst c := declare the result c of the previous construction as *) (* compatible with Q *) (* lift_embed Q e := lifts e : R -> T to R -> Q *) (* PiEmbed f := declare the result f of the previous construction as *) (* compatible with Q *) (* *) (* *** Quotients that have an eqType structure *** *) (* Having a canonical (eqQuotType e) structure enables piE to replace terms *) (* of the form (x == y) by terms of the form (e x' y') if x and y are *) (* canonical surjections of some x' and y'. *) (* eqQuotType e == the type of quotients types on T which mirror *) (* the equivalence relation (e : rel T) *) (* the HB class is called EqQuotient. *) (* *) (* The most useful property is that an eqQuotType is an eqType. *) (* List of factories: *) (* isEqQuotient.Build T e Q m *) (* == builds an (eqQuotType e) structure on Q from the *) (* morphism property m *) (* where m : {mono \pi : x y / e x y >-> x == y} *) (* *) (* *** Equivalence and quotient by an equivalence *** *) (* EquivRel r er es et == builds an equiv_rel structure based on the *) (* reflexivity, symmetry and transitivity property *) (* of a boolean relation. *) (* {eq_quot e} == builds the quotType of T by equiv *) (* where e : rel T is an equiv_rel *) (* and T is a choiceType or a (choiceTypeMod e) *) (* it is canonically an eqType, a choiceType, *) (* a quotType and an eqQuotType *) (* x = y %[mod_eq e] := x = y %[mod {eq_quot e}] *) (* <-> x and y are equal modulo e *) (* ... *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope quotient_scope. Reserved Notation "\pi_ Q" (at level 0, format "\pi_ Q"). Reserved Notation "\pi" (format "\pi"). Reserved Notation "{pi_ Q a }" (Q at next level, format "{pi_ Q a }"). Reserved Notation "{pi a }" (format "{pi a }"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x == y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' == y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x = y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' = y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x != y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' != y '/' %[mod_eq e ] ']'"). #[warning="-postfix-notation-not-level-1"] Reserved Notation "x <> y %[mod_eq e ]" (no associativity, format "'[hv ' x '/' <> y '/' %[mod_eq e ] ']'"). Reserved Notation "{eq_quot e }" (format "{eq_quot e }"). Delimit Scope quotient_scope with qT. Local Open Scope quotient_scope. (*****************************************) (* Definition of the quotient interface. *) (*****************************************) HB.mixin Record isQuotient T (qT : Type) := { repr_of : qT -> T; quot_pi_subdef : T -> qT; repr_ofK_subproof : cancel repr_of quot_pi_subdef }. #[short(type="quotType")] HB.structure Definition Quotient T := { qT of isQuotient T qT }. Arguments repr_of [T qT] : rename. Section QuotientDef. Variable T : Type. Variable qT : quotType T. Definition pi_subdef := @quot_pi_subdef _ qT. Local Notation "\pi" := pi_subdef. Lemma repr_ofK : cancel (@repr_of _ _) \pi. Proof. exact: repr_ofK_subproof. Qed. End QuotientDef. Arguments repr_ofK {T qT}. (****************************) (* Protecting some symbols. *) (****************************) HB.lock Definition pi := pi_subdef. HB.lock Definition mpi := pi_subdef. HB.lock Definition repr := repr_of. (*******************) (* Fancy Notations *) (*******************) Arguments pi.body [T]%_type qT%_type. Notation "\pi_ Q" := (@pi _ Q) : quotient_scope. Notation "\pi" := (@pi _ _) (only parsing) : quotient_scope. Notation "x == y %[mod Q ]" := (\pi_Q x == \pi_Q y) : quotient_scope. Notation "x = y %[mod Q ]" := (\pi_Q x = \pi_Q y) : quotient_scope. Notation "x != y %[mod Q ]" := (\pi_Q x != \pi_Q y) : quotient_scope. Notation "x <> y %[mod Q ]" := (\pi_Q x <> \pi_Q y) : quotient_scope. Local Notation "\mpi" := (@mpi _ _). Canonical mpi_unlock := Unlockable mpi.unlock. Canonical pi_unlock := Unlockable pi.unlock. Canonical repr_unlock := Unlockable repr.unlock. Arguments repr {T qT} x. (************************) (* Exporting the theory *) (************************) Section QuotTypeTheory. Variable T : Type. Variable qT : quotType T. Lemma reprK : cancel repr \pi_qT. Proof. by move=> x; rewrite !unlock repr_ofK. Qed. Variant pi_spec (x : T) : T -> Type := PiSpec y of x = y %[mod qT] : pi_spec x y. Lemma piP (x : T) : pi_spec x (repr (\pi_qT x)). Proof. by constructor; rewrite reprK. Qed. Lemma mpiE : \mpi =1 \pi_qT. Proof. by move=> x; rewrite !unlock. Qed. Lemma quotW P : (forall y : T, P (\pi_qT y)) -> forall x : qT, P x. Proof. by move=> Py x; rewrite -[x]reprK; apply: Py. Qed. Lemma quotP P : (forall y : T, repr (\pi_qT y) = y -> P (\pi_qT y)) -> forall x : qT, P x. Proof. by move=> Py x; rewrite -[x]reprK; apply: Py; rewrite reprK. Qed. End QuotTypeTheory. Arguments reprK {T qT} x. (*******************) (* About morphisms *) (*******************) (* This was pi_morph T (x : T) := PiMorph { pi_op : T; _ : x = pi_op }. *) Structure equal_to T (x : T) := EqualTo { equal_val : T; _ : x = equal_val }. Lemma equal_toE (T : Type) (x : T) (m : equal_to x) : equal_val m = x. Proof. by case: m. Qed. Notation piE := (@equal_toE _ _). Canonical equal_to_pi T (qT : quotType T) (x : T) := @EqualTo _ (\pi_qT x) (\pi x) (erefl _). Arguments EqualTo {T x equal_val}. Section Morphism. Variables T U : Type. Variable (qT : quotType T). Variable (qU : quotType U). Variable (f : T -> T) (g : T -> T -> T) (p : T -> U) (r : T -> T -> U). Variable (fq : qT -> qT) (gq : qT -> qT -> qT) (pq : qT -> U) (rq : qT -> qT -> U). Variable (h : T -> U) (hq : qT -> qU). Hypothesis pi_f : {morph \pi : x / f x >-> fq x}. Hypothesis pi_g : {morph \pi : x y / g x y >-> gq x y}. Hypothesis pi_p : {mono \pi : x / p x >-> pq x}. Hypothesis pi_r : {mono \pi : x y / r x y >-> rq x y}. Hypothesis pi_h : forall (x : T), \pi_qU (h x) = hq (\pi_qT x). Variables (a b : T) (x : equal_to (\pi_qT a)) (y : equal_to (\pi_qT b)). (* Internal Lemmas : do not use directly *) Lemma pi_morph1 : \pi (f a) = fq (equal_val x). Proof. by rewrite !piE. Qed. Lemma pi_morph2 : \pi (g a b) = gq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed. Lemma pi_mono1 : p a = pq (equal_val x). Proof. by rewrite !piE. Qed. Lemma pi_mono2 : r a b = rq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed. Lemma pi_morph11 : \pi (h a) = hq (equal_val x). Proof. by rewrite !piE. Qed. End Morphism. Arguments pi_morph1 {T qT f fq}. Arguments pi_morph2 {T qT g gq}. Arguments pi_mono1 {T U qT p pq}. Arguments pi_mono2 {T U qT r rq}. Arguments pi_morph11 {T U qT qU h hq}. Notation "{pi_ Q a }" := (equal_to (\pi_Q a)) : quotient_scope. Notation "{pi a }" := (equal_to (\pi a)) : quotient_scope. (* Declaration of morphisms *) Notation PiMorph pi_x := (EqualTo pi_x). Notation PiMorph1 pi_f := (fun a (x : {pi a}) => EqualTo (pi_morph1 pi_f a x)). Notation PiMorph2 pi_g := (fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_morph2 pi_g a b x y)). Notation PiMono1 pi_p := (fun a (x : {pi a}) => EqualTo (pi_mono1 pi_p a x)). Notation PiMono2 pi_r := (fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_mono2 pi_r a b x y)). Notation PiMorph11 pi_f := (fun a (x : {pi a}) => EqualTo (pi_morph11 pi_f a x)). (* lifting helpers *) Notation lift_op1 Q f := (locked (fun x : Q => \pi_Q (f (repr x)) : Q)). Notation lift_op2 Q g := (locked (fun x y : Q => \pi_Q (g (repr x) (repr y)) : Q)). Notation lift_fun1 Q f := (locked (fun x : Q => f (repr x))). Notation lift_fun2 Q g := (locked (fun x y : Q => g (repr x) (repr y))). Notation lift_op11 Q Q' f := (locked (fun x : Q => \pi_Q' (f (repr x)) : Q')). (* constant declaration *) Notation lift_cst Q x := (locked (\pi_Q x : Q)). Notation PiConst a := (@EqualTo _ _ a (lock _)). (* embedding declaration, please don't redefine \pi *) Notation lift_embed qT e := (locked (fun x => \pi_qT (e x) : qT)). Lemma eq_lock T T' e : e =1 (@locked (T -> T') (fun x : T => e x)). Proof. by rewrite -lock. Qed. Prenex Implicits eq_lock. Notation PiEmbed e := (fun x => @EqualTo _ _ (e x) (eq_lock (fun _ => \pi _) _)). (********************) (* About eqQuotType *) (********************) HB.mixin Record isEqQuotient T (eq_quot_op : rel T) (Q : Type) of isQuotient T Q & hasDecEq Q := { pi_eq_quot : {mono \pi_Q : x y / eq_quot_op x y >-> x == y} }. #[short(type="eqQuotType")] HB.structure Definition EqQuotient T eq_quot_op := {Q of isEqQuotient T eq_quot_op Q & Quotient T Q & hasDecEq Q}. Canonical pi_eq_quot_mono T eq_quot_op eqT := PiMono2 (@pi_eq_quot T eq_quot_op eqT). (**************************************************************************) (* Even if a quotType is a natural subType, we do not make this subType *) (* canonical, to allow the user to define the subtyping he wants. However *) (* one can: *) (* - get the hasDecEq and the hasChoice by subtyping *) (* - get the subType structure and maybe declare it Canonical. *) (**************************************************************************) Definition quot_type_of T (qT : quotType T) : Type := qT. Arguments quot_type_of T%_type qT%_type : clear implicits. Notation quot_type Q := (quot_type_of _ Q). HB.instance Definition _ T (qT : quotType T) := Quotient.on (quot_type qT). Module QuotSubType. Section QuotSubType. Variable (T : eqType) (qT : quotType T). Definition Sub x (px : repr (\pi_qT x) == x) := \pi_qT x. Lemma qreprK x Px : repr (@Sub x Px) = x. Proof. by rewrite /Sub (eqP Px). Qed. Lemma sortPx (x : qT) : repr (\pi_qT (repr x)) == repr x. Proof. by rewrite !reprK eqxx. Qed. Lemma sort_Sub (x : qT) : x = Sub (sortPx x). Proof. by rewrite /Sub reprK. Qed. Lemma reprP K (PK : forall x Px, K (@Sub x Px)) u : K u. Proof. by rewrite (sort_Sub u); apply: PK. Qed. #[export] HB.instance Definition _ := isSub.Build _ _ (quot_type qT) reprP qreprK. #[export] HB.instance Definition _ := [Equality of quot_type qT by <:]. End QuotSubType. Module Exports. HB.reexport. End Exports. End QuotSubType. Export QuotSubType.Exports. HB.instance Definition _ (T : choiceType) (qT : quotType T) := [Choice of quot_type qT by <:]. HB.instance Definition _ (T : countType) (qT : quotType T) := [Countable of quot_type qT by <:]. HB.instance Definition _ (T : finType) (qT : quotType T) := [Finite of quot_type qT by <:]. Notation "[ 'Sub' Q 'of' T 'by' %/ ]" := (SubType.copy Q%type (quot_type_of T Q%type)) (format "[ 'Sub' Q 'of' T 'by' %/ ]") : form_scope. Notation "[ 'Sub' Q 'by' %/ ]" := (SubType.copy Q%type (quot_type Q)) (format "[ 'Sub' Q 'by' %/ ]") : form_scope. Notation "[ 'Equality' 'of' Q 'by' <:%/ ]" := (Equality.copy Q%type (quot_type Q)) (format "[ 'Equality' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Choice' 'of' Q 'by' <:%/ ]" := (Choice.copy Q%type (quot_type Q)) (format "[ 'Choice' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Countable' 'of' Q 'by' <:%/ ]" := (Countable.copy Q%type (quot_type Q)) (format "[ 'Countable' 'of' Q 'by' <:%/ ]") : form_scope. Notation "[ 'Finite' 'of' Q 'by' <:%/ ]" := (Finite.copy Q%type (quot_type Q)) (format "[ 'Finite' 'of' Q 'by' <:%/ ]") : form_scope. (****************************************************) (* Definition of a (decidable) equivalence relation *) (****************************************************) Section EquivRel. Variable T : Type. Lemma left_trans (e : rel T) : symmetric e -> transitive e -> left_transitive e. Proof. by move=> s t ? * ?; apply/idP/idP; apply: t; rewrite // s. Qed. Lemma right_trans (e : rel T) : symmetric e -> transitive e -> right_transitive e. Proof. by move=> s t ? * x; rewrite ![e x _]s; apply: left_trans. Qed. Variant equiv_class_of (equiv : rel T) := EquivClass of reflexive equiv & symmetric equiv & transitive equiv. Record equiv_rel := EquivRelPack { equiv :> rel T; _ : equiv_class_of equiv }. Variable e : equiv_rel. Definition equiv_class := let: EquivRelPack _ ce as e' := e return equiv_class_of e' in ce. Definition equiv_pack (r : rel T) ce of phant_id ce equiv_class := @EquivRelPack r ce. Lemma equiv_refl x : e x x. Proof. by case: e => [] ? []. Qed. Lemma equiv_sym : symmetric e. Proof. by case: e => [] ? []. Qed. Lemma equiv_trans : transitive e. Proof. by case: e => [] ? []. Qed. Lemma eq_op_trans (T' : eqType) : transitive (@eq_op T'). Proof. by move=> x y z /eqP -> /eqP ->. Qed. Lemma equiv_ltrans: left_transitive e. Proof. by apply: left_trans; [apply: equiv_sym|apply: equiv_trans]. Qed. Lemma equiv_rtrans: right_transitive e. Proof. by apply: right_trans; [apply: equiv_sym|apply: equiv_trans]. Qed. End EquivRel. #[global] Hint Resolve equiv_refl : core. Notation EquivRel r er es et := (@EquivRelPack _ r (EquivClass er es et)). Notation "[ 'equiv_rel' 'of' e ]" := (@equiv_pack _ _ e _ id) (format "[ 'equiv_rel' 'of' e ]") : form_scope. (**************************************************) (* Encoding to another type modulo an equivalence *) (**************************************************) Section EncodingModuloRel. Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : rel D). Variant encModRel_class_of (r : rel D) := EncModRelClassPack of (forall x, r x x -> r (ED (DE x)) x) & (r =2 e). Record encModRel := EncModRelPack { enc_mod_rel :> rel D; _ : encModRel_class_of enc_mod_rel }. Variable r : encModRel. Definition encModRelClass := let: EncModRelPack _ c as r' := r return encModRel_class_of r' in c. Definition encModRelP (x : D) : r x x -> r (ED (DE x)) x. Proof. by case: r => [] ? [] /= he _ /he. Qed. Definition encModRelE : r =2 e. Proof. by case: r => [] ? []. Qed. Definition encoded_equiv : rel E := [rel x y | r (ED x) (ED y)]. End EncodingModuloRel. Notation EncModRelClass m := (EncModRelClassPack (fun x _ => m x) (fun _ _ => erefl _)). Notation EncModRel r m := (@EncModRelPack _ _ _ _ _ r (EncModRelClass m)). Section EncodingModuloEquiv. Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : equiv_rel D). Variable (r : encModRel ED DE e). Lemma enc_mod_rel_is_equiv : equiv_class_of (enc_mod_rel r). Proof. split => [x|x y|y x z]; rewrite !encModRelE //; first by rewrite equiv_sym. by move=> exy /(equiv_trans exy). Qed. Definition enc_mod_rel_equiv_rel := EquivRelPack enc_mod_rel_is_equiv. Definition encModEquivP (x : D) : r (ED (DE x)) x. Proof. by rewrite encModRelP ?encModRelE. Qed. Local Notation e' := (encoded_equiv r). Lemma encoded_equivE : e' =2 [rel x y | e (ED x) (ED y)]. Proof. by move=> x y; rewrite /encoded_equiv /= encModRelE. Qed. Local Notation e'E := encoded_equivE. Lemma encoded_equiv_is_equiv : equiv_class_of e'. Proof. split => [x|x y|y x z]; rewrite !e'E //=; first by rewrite equiv_sym. by move=> exy /(equiv_trans exy). Qed. Canonical encoded_equiv_equiv_rel := EquivRelPack encoded_equiv_is_equiv. Lemma encoded_equivP x : e' (DE (ED x)) x. Proof. by rewrite /encoded_equiv /= encModEquivP. Qed. End EncodingModuloEquiv. (**************************************) (* Quotient by a equivalence relation *) (**************************************) Module EquivQuot. Section EquivQuot. Variables (D : Type) (C : choiceType) (CD : C -> D) (DC : D -> C). Variables (eD : equiv_rel D) (encD : encModRel CD DC eD). Notation eC := (encoded_equiv encD). Definition canon x := choose (eC x) (x). Record equivQuotient := EquivQuotient { erepr : C; _ : (frel canon) erepr erepr }. Definition type_of of (phantom (rel _) encD) := equivQuotient. Lemma canon_id : forall x, (invariant canon canon) x. Proof. move=> x /=; rewrite /canon (@eq_choose _ _ (eC x)). by rewrite (@choose_id _ (eC x) _ x) ?chooseP ?equiv_refl. by move=> y; apply: equiv_ltrans; rewrite equiv_sym /= chooseP. Qed. Definition pi := locked (fun x => EquivQuotient (canon_id x)). Lemma ereprK : cancel erepr pi. Proof. pose T : subType _ := HB.pack equivQuotient [isSub for erepr]. by unlock pi; case=> x hx; apply/(@val_inj _ _ T)/eqP. Qed. Local Notation encDE := (encModRelE encD). Local Notation encDP := (encModEquivP encD). Canonical encD_equiv_rel := EquivRelPack (enc_mod_rel_is_equiv encD). Lemma pi_CD (x y : C) : reflect (pi x = pi y) (eC x y). Proof. apply: (iffP idP) => hxy. apply: (can_inj ereprK); unlock pi canon => /=. rewrite -(@eq_choose _ (eC x) (eC y)); last first. by move=> z; rewrite /eC /=; apply: equiv_ltrans. by apply: choose_id; rewrite ?equiv_refl //. rewrite (equiv_trans (chooseP (equiv_refl _ _))) //=. move: hxy => /(f_equal erepr) /=; unlock pi canon => /= ->. by rewrite equiv_sym /= chooseP. Qed. Lemma pi_DC (x y : D) : reflect (pi (DC x) = pi (DC y)) (eD x y). Proof. apply: (iffP idP)=> hxy. apply/pi_CD; rewrite /eC /=. by rewrite (equiv_ltrans (encDP _)) (equiv_rtrans (encDP _)) /= encDE. rewrite -encDE -(equiv_ltrans (encDP _)) -(equiv_rtrans (encDP _)) /=. exact/pi_CD. Qed. Lemma equivQTP : cancel (CD \o erepr) (pi \o DC). Proof. by move=> x; rewrite /= (pi_CD _ (erepr x) _) ?ereprK /eC /= ?encDP. Qed. Local Notation qT := (type_of (Phantom (rel D) encD)). #[export] HB.instance Definition _ := isQuotient.Build D qT equivQTP. Lemma eqmodP x y : reflect (x = y %[mod qT]) (eD x y). Proof. by apply: (iffP (pi_DC _ _)); rewrite !unlock. Qed. #[export] HB.instance Definition _ := Choice.copy qT (can_type ereprK). Lemma eqmodE x y : x == y %[mod qT] = eD x y. Proof. exact: sameP eqP (@eqmodP _ _). Qed. #[export] HB.instance Definition _ := isEqQuotient.Build _ eD qT eqmodE. End EquivQuot. Module Exports. HB.reexport. End Exports. End EquivQuot. Export EquivQuot.Exports. Arguments EquivQuot.ereprK {D C CD DC eD encD}. Notation "{eq_quot e }" := (@EquivQuot.type_of _ _ _ _ _ _ (Phantom (rel _) e)) : quotient_scope. Notation "x == y %[mod_eq r ]" := (x == y %[mod {eq_quot r}]) : quotient_scope. Notation "x = y %[mod_eq r ]" := (x = y %[mod {eq_quot r}]) : quotient_scope. Notation "x != y %[mod_eq r ]" := (x != y %[mod {eq_quot r}]) : quotient_scope. Notation "x <> y %[mod_eq r ]" := (x <> y %[mod {eq_quot r}]) : quotient_scope. (***********************************************************) (* If the type is directly a choiceType, no need to encode *) (***********************************************************) Section DefaultEncodingModuloRel. Variables (D : choiceType) (r : rel D). Definition defaultEncModRelClass := @EncModRelClassPack D D id id r r (fun _ rxx => rxx) (fun _ _ => erefl _). Canonical defaultEncModRel := EncModRelPack defaultEncModRelClass. End DefaultEncodingModuloRel. (***************************************************) (* Recovering a potential countable type structure *) (***************************************************) Section CountEncodingModuloRel. Variables (D : Type) (C : countType) (CD : C -> D) (DC : D -> C). Variables (eD : equiv_rel D) (encD : encModRel CD DC eD). Notation eC := (encoded_equiv encD). HB.instance Definition _ := Countable.copy {eq_quot encD} (can_type EquivQuot.ereprK). End CountEncodingModuloRel. Section EquivQuotTheory. Variables (T : choiceType) (e : equiv_rel T) (Q : eqQuotType e). Lemma eqmodE x y : x == y %[mod_eq e] = e x y. Proof. by rewrite pi_eq_quot. Qed. Lemma eqmodP x y : reflect (x = y %[mod_eq e]) (e x y). Proof. by rewrite -eqmodE; apply/eqP. Qed. End EquivQuotTheory. Prenex Implicits eqmodE eqmodP. Section EqQuotTheory. Variables (T : Type) (e : rel T) (Q : eqQuotType e). Lemma eqquotE x y : x == y %[mod Q] = e x y. Proof. by rewrite pi_eq_quot. Qed. Lemma eqquotP x y : reflect (x = y %[mod Q]) (e x y). Proof. by rewrite -eqquotE; apply/eqP. Qed. End EqQuotTheory. Prenex Implicits eqquotE eqquotP.
CommSq.lean
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Joël Riou -/ import Mathlib.CategoryTheory.Comma.Arrow /-! # Commutative squares This file provide an API for commutative squares in categories. If `top`, `left`, `right` and `bottom` are four morphisms which are the edges of a square, `CommSq top left right bottom` is the predicate that this square is commutative. The structure `CommSq` is extended in `CategoryTheory/Shapes/Limits/CommSq.lean` as `IsPullback` and `IsPushout` in order to define pullback and pushout squares. ## Future work Refactor `LiftStruct` from `Arrow.lean` and lifting properties using `CommSq.lean`. -/ namespace CategoryTheory variable {C : Type*} [Category C] /-- The proposition that a square ``` W ---f---> X | | g h | | v v Y ---i---> Z ``` is a commuting square. -/ structure CommSq {W X Y Z : C} (f : W ⟶ X) (g : W ⟶ Y) (h : X ⟶ Z) (i : Y ⟶ Z) : Prop where /-- The square commutes. -/ w : f ≫ h = g ≫ i := by cat_disch attribute [reassoc] CommSq.w namespace CommSq variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem flip (p : CommSq f g h i) : CommSq g f i h := ⟨p.w.symm⟩ theorem of_arrow {f g : Arrow C} (h : f ⟶ g) : CommSq f.hom h.left h.right g.hom := ⟨h.w.symm⟩ /-- The commutative square in the opposite category associated to a commutative square. -/ theorem op (p : CommSq f g h i) : CommSq i.op h.op g.op f.op := ⟨by simp only [← op_comp, p.w]⟩ /-- The commutative square associated to a commutative square in the opposite category. -/ theorem unop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) : CommSq i.unop h.unop g.unop f.unop := ⟨by simp only [← unop_comp, p.w]⟩ theorem vert_inv {g : W ≅ Y} {h : X ≅ Z} (p : CommSq f g.hom h.hom i) : CommSq i g.inv h.inv f := ⟨by rw [Iso.comp_inv_eq, Category.assoc, Iso.eq_inv_comp, p.w]⟩ theorem horiz_inv {f : W ≅ X} {i : Y ≅ Z} (p : CommSq f.hom g h i.hom) : CommSq f.inv h g i.inv := flip (vert_inv (flip p)) /-- The horizontal composition of two commutative squares as below is a commutative square. ``` W ---f---> X ---f'--> X' | | | g h h' | | | v v v Y ---i---> Z ---i'--> Z' ``` -/ lemma horiz_comp {W X X' Y Z Z' : C} {f : W ⟶ X} {f' : X ⟶ X'} {g : W ⟶ Y} {h : X ⟶ Z} {h' : X' ⟶ Z'} {i : Y ⟶ Z} {i' : Z ⟶ Z'} (hsq₁ : CommSq f g h i) (hsq₂ : CommSq f' h h' i') : CommSq (f ≫ f') g h' (i ≫ i') := ⟨by rw [← Category.assoc, Category.assoc, ← hsq₁.w, hsq₂.w, Category.assoc]⟩ /-- The vertical composition of two commutative squares as below is a commutative square. ``` W ---f---> X | | g h | | v v Y ---i---> Z | | g' h' | | v v Y'---i'--> Z' ``` -/ lemma vert_comp {W X Y Y' Z Z' : C} {f : W ⟶ X} {g : W ⟶ Y} {g' : Y ⟶ Y'} {h : X ⟶ Z} {h' : Z ⟶ Z'} {i : Y ⟶ Z} {i' : Y' ⟶ Z'} (hsq₁ : CommSq f g h i) (hsq₂ : CommSq i g' h' i') : CommSq f (g ≫ g') (h ≫ h') i' := flip (horiz_comp (flip hsq₁) (flip hsq₂)) section variable {W X Y : C} theorem eq_of_mono {f : W ⟶ X} {g : W ⟶ X} {i : X ⟶ Y} [Mono i] (sq : CommSq f g i i) : f = g := (cancel_mono i).1 sq.w theorem eq_of_epi {f : W ⟶ X} {h : X ⟶ Y} {i : X ⟶ Y} [Epi f] (sq : CommSq f f h i) : h = i := (cancel_epi f).1 sq.w end end CommSq namespace Functor variable {D : Type*} [Category D] variable (F : C ⥤ D) {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} theorem map_commSq (s : CommSq f g h i) : CommSq (F.map f) (F.map g) (F.map h) (F.map i) := ⟨by simpa using congr_arg (fun k : W ⟶ Z => F.map k) s.w⟩ end Functor alias CommSq.map := Functor.map_commSq namespace CommSq variable {A B X Y : C} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} /-- Now we consider a square: ``` A ---f---> X | | i p | | v v B ---g---> Y ``` The datum of a lift in a commutative square, i.e. an up-right-diagonal morphism which makes both triangles commute. -/ @[ext] structure LiftStruct (sq : CommSq f i p g) where /-- The lift. -/ l : B ⟶ X /-- The upper left triangle commutes. -/ fac_left : i ≫ l = f := by cat_disch /-- The lower right triangle commutes. -/ fac_right : l ≫ p = g := by cat_disch namespace LiftStruct /-- A `LiftStruct` for a commutative square gives a `LiftStruct` for the corresponding square in the opposite category. -/ @[simps] def op {sq : CommSq f i p g} (l : LiftStruct sq) : LiftStruct sq.op where l := l.l.op fac_left := by rw [← op_comp, l.fac_right] fac_right := by rw [← op_comp, l.fac_left] /-- A `LiftStruct` for a commutative square in the opposite category gives a `LiftStruct` for the corresponding square in the original category. -/ @[simps] def unop {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} {sq : CommSq f i p g} (l : LiftStruct sq) : LiftStruct sq.unop where l := l.l.unop fac_left := by rw [← unop_comp, l.fac_right] fac_right := by rw [← unop_comp, l.fac_left] /-- Equivalences of `LiftStruct` for a square and the corresponding square in the opposite category. -/ @[simps] def opEquiv (sq : CommSq f i p g) : LiftStruct sq ≃ LiftStruct sq.op where toFun := op invFun := unop left_inv := by cat_disch right_inv := by cat_disch /-- Equivalences of `LiftStruct` for a square in the opposite category and the corresponding square in the original category. -/ def unopEquiv {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} (sq : CommSq f i p g) : LiftStruct sq ≃ LiftStruct sq.unop where toFun := unop invFun := op left_inv := by cat_disch right_inv := by cat_disch end LiftStruct instance subsingleton_liftStruct_of_epi (sq : CommSq f i p g) [Epi i] : Subsingleton (LiftStruct sq) := ⟨fun l₁ l₂ => by ext rw [← cancel_epi i] simp only [LiftStruct.fac_left]⟩ instance subsingleton_liftStruct_of_mono (sq : CommSq f i p g) [Mono p] : Subsingleton (LiftStruct sq) := ⟨fun l₁ l₂ => by ext rw [← cancel_mono p] simp only [LiftStruct.fac_right]⟩ variable (sq : CommSq f i p g) /-- The assertion that a square has a `LiftStruct`. -/ class HasLift : Prop where /-- Square has a `LiftStruct`. -/ exists_lift : Nonempty sq.LiftStruct namespace HasLift variable {sq} in theorem mk' (l : sq.LiftStruct) : HasLift sq := ⟨Nonempty.intro l⟩ theorem iff : HasLift sq ↔ Nonempty sq.LiftStruct := by constructor exacts [fun h => h.exists_lift, fun h => mk h] theorem iff_op : HasLift sq ↔ HasLift sq.op := by rw [iff, iff] exact Nonempty.congr (LiftStruct.opEquiv sq).toFun (LiftStruct.opEquiv sq).invFun theorem iff_unop {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} (sq : CommSq f i p g) : HasLift sq ↔ HasLift sq.unop := by rw [iff, iff] exact Nonempty.congr (LiftStruct.unopEquiv sq).toFun (LiftStruct.unopEquiv sq).invFun end HasLift /-- A choice of a diagonal morphism that is part of a `LiftStruct` when the square has a lift. -/ noncomputable def lift [hsq : HasLift sq] : B ⟶ X := hsq.exists_lift.some.l @[reassoc (attr := simp)] theorem fac_left [hsq : HasLift sq] : i ≫ sq.lift = f := hsq.exists_lift.some.fac_left @[reassoc (attr := simp)] theorem fac_right [hsq : HasLift sq] : sq.lift ≫ p = g := hsq.exists_lift.some.fac_right end CommSq end CategoryTheory
Over.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.UnderlyingMap import Mathlib.CategoryTheory.Limits.MorphismProperty /-! # Covers of schemes over a base In this file we define the typeclass `Cover.Over`. For a cover `𝒰` of an `S`-scheme `X`, the datum `𝒰.Over S` contains `S`-scheme structures on the components of `𝒰` and asserts that the component maps are morphisms of `S`-schemes. We provide instances of `𝒰.Over S` for standard constructions on covers. -/ universe v u noncomputable section open CategoryTheory Limits namespace AlgebraicGeometry.Scheme variable {P : MorphismProperty Scheme.{u}} (S : Scheme.{u}) /-- Bundle an `S`-scheme with `P` into an object of `P.Over ⊤ S`. -/ abbrev asOverProp (X : Scheme.{u}) (S : Scheme.{u}) [X.Over S] (h : P (X ↘ S)) : P.Over ⊤ S := ⟨X.asOver S, h⟩ /-- Bundle an `S`-morphism of `S`-scheme with `P` into a morphism in `P.Over ⊤ S`. -/ abbrev Hom.asOverProp {X Y : Scheme.{u}} (f : X.Hom Y) (S : Scheme.{u}) [X.Over S] [Y.Over S] [f.IsOver S] {hX : P (X ↘ S)} {hY : P (Y ↘ S)} : X.asOverProp S hX ⟶ Y.asOverProp S hY := ⟨f.asOver S, trivial, trivial⟩ /-- A `P`-cover of a scheme `X` over `S` is a cover, where the components are over `S` and the component maps commute with the structure morphisms. -/ protected class Cover.Over {P : MorphismProperty Scheme.{u}} {X : Scheme.{u}} [X.Over S] (𝒰 : X.Cover P) where over (j : 𝒰.J) : (𝒰.obj j).Over S := by infer_instance isOver_map (j : 𝒰.J) : (𝒰.map j).IsOver S := by infer_instance attribute [instance] Cover.Over.over Cover.Over.isOver_map instance [P.ContainsIdentities] [P.RespectsIso] {X Y : Scheme.{u}} (f : X ⟶ Y) [X.Over S] [Y.Over S] [f.IsOver S] [IsIso f] : (coverOfIsIso (P := P) f).Over S where over _ := inferInstanceAs <| X.Over S isOver_map _ := inferInstanceAs <| f.IsOver S section variable [P.IsStableUnderBaseChange] [IsJointlySurjectivePreserving P] variable {X W : Scheme.{u}} (𝒰 : X.Cover P) (f : W ⟶ X) [W.Over S] [X.Over S] [𝒰.Over S] [f.IsOver S] /-- The pullback of a cover of `S`-schemes along a morphism of `S`-schemes. This is not definitionally equal to `AlgebraicGeometry.Scheme.Cover.pullbackCover`, as here we take the pullback in `Over S`, whose underlying scheme is only isomorphic but not equal to the pullback in `Scheme`. -/ @[simps] def Cover.pullbackCoverOver : W.Cover P where J := 𝒰.J obj x := (pullback (f.asOver S) ((𝒰.map x).asOver S)).left map x := (pullback.fst (f.asOver S) ((𝒰.map x).asOver S)).left f x := 𝒰.f (f.base x) covers x := (mem_range_iff_of_surjective ((𝒰.pullbackCover f).map (𝒰.f (f.base x))) _ ((PreservesPullback.iso (Over.forget S) (f.asOver S) ((𝒰.map _).asOver S)).inv) (PreservesPullback.iso_inv_fst _ _ _) x).mp ((𝒰.pullbackCover f).covers x) map_prop j := by rw [← Over.forget_map, ← PreservesPullback.iso_hom_fst, P.cancel_left_of_respectsIso] exact P.pullback_fst _ _ (𝒰.map_prop j) instance (j : 𝒰.J) : ((𝒰.pullbackCoverOver S f).obj j).Over S where hom := (pullback (f.asOver S) ((𝒰.map j).asOver S)).hom instance : (𝒰.pullbackCoverOver S f).Over S where isOver_map j := { comp_over := by exact Over.w (pullback.fst (f.asOver S) ((𝒰.map j).asOver S)) } /-- A variant of `AlgebraicGeometry.Scheme.Cover.pullbackCoverOver` with the arguments in the fiber products flipped. -/ @[simps] def Cover.pullbackCoverOver' : W.Cover P where J := 𝒰.J obj x := (pullback ((𝒰.map x).asOver S) (f.asOver S)).left map x := (pullback.snd ((𝒰.map x).asOver S) (f.asOver S)).left f x := 𝒰.f (f.base x) covers x := (mem_range_iff_of_surjective ((𝒰.pullbackCover' f).map (𝒰.f (f.base x))) _ ((PreservesPullback.iso (Over.forget S) ((𝒰.map _).asOver S) (f.asOver S)).inv) (PreservesPullback.iso_inv_snd _ _ _) x).mp ((𝒰.pullbackCover' f).covers x) map_prop j := by rw [← Over.forget_map, ← PreservesPullback.iso_hom_snd, P.cancel_left_of_respectsIso] exact P.pullback_snd _ _ (𝒰.map_prop j) instance (j : 𝒰.J) : ((𝒰.pullbackCoverOver' S f).obj j).Over S where hom := (pullback ((𝒰.map j).asOver S) (f.asOver S)).hom instance : (𝒰.pullbackCoverOver' S f).Over S where isOver_map j := { comp_over := by exact Over.w (pullback.snd ((𝒰.map j).asOver S) (f.asOver S)) } variable {Q : MorphismProperty Scheme.{u}} [Q.HasOfPostcompProperty Q] [Q.IsStableUnderBaseChange] [Q.IsStableUnderComposition] variable (hX : Q (X ↘ S)) (hW : Q (W ↘ S)) (hQ : ∀ j, Q (𝒰.obj j ↘ S)) /-- The pullback of a cover of `S`-schemes with `Q` along a morphism of `S`-schemes. This is not definitionally equal to `AlgebraicGeometry.Scheme.Cover.pullbackCover`, as here we take the pullback in `Q.Over ⊤ S`, whose underlying scheme is only isomorphic but not equal to the pullback in `Scheme`. -/ @[simps -isSimp] def Cover.pullbackCoverOverProp : W.Cover P where J := 𝒰.J obj x := (pullback (f.asOverProp (hX := hW) (hY := hX) S) ((𝒰.map x).asOverProp (hX := hQ x) (hY := hX) S)).left map x := (pullback.fst (f.asOverProp S) ((𝒰.map x).asOverProp S)).left f x := 𝒰.f (f.base x) covers x := (mem_range_iff_of_surjective ((𝒰.pullbackCover f).map (𝒰.f (f.base x))) _ ((PreservesPullback.iso (MorphismProperty.Over.forget Q _ _ ⋙ Over.forget S) (f.asOverProp S) ((𝒰.map _).asOverProp S)).inv) (PreservesPullback.iso_inv_fst _ _ _) x).mp ((𝒰.pullbackCover f).covers x) map_prop j := by dsimp only rw [← Over.forget_map, MorphismProperty.Comma.toCommaMorphism_eq_hom, ← MorphismProperty.Comma.forget_map, ← Functor.comp_map] rw [← PreservesPullback.iso_hom_fst, P.cancel_left_of_respectsIso] exact P.pullback_fst _ _ (𝒰.map_prop j) instance (j : 𝒰.J) : ((𝒰.pullbackCoverOverProp S f hX hW hQ).obj j).Over S where hom := (pullback (f.asOverProp (hX := hW) (hY := hX) S) ((𝒰.map j).asOverProp (hX := hQ j) (hY := hX) S)).hom instance : (𝒰.pullbackCoverOverProp S f hX hW hQ).Over S where isOver_map j := { comp_over := by exact (pullback.fst (f.asOverProp S) ((𝒰.map j).asOverProp S)).w } /-- A variant of `AlgebraicGeometry.Scheme.Cover.pullbackCoverOverProp` with the arguments in the fiber products flipped. -/ @[simps -isSimp] def Cover.pullbackCoverOverProp' : W.Cover P where J := 𝒰.J obj x := (pullback ((𝒰.map x).asOverProp (hX := hQ x) (hY := hX) S) (f.asOverProp (hX := hW) (hY := hX) S)).left map x := (pullback.snd ((𝒰.map x).asOverProp S) (f.asOverProp S)).left f x := 𝒰.f (f.base x) covers x := (mem_range_iff_of_surjective ((𝒰.pullbackCover' f).map (𝒰.f (f.base x))) _ ((PreservesPullback.iso (MorphismProperty.Over.forget Q _ _ ⋙ Over.forget S) ((𝒰.map _).asOverProp S) (f.asOverProp S)).inv) (PreservesPullback.iso_inv_snd _ _ _) x).mp ((𝒰.pullbackCover' f).covers x) map_prop j := by dsimp only rw [← Over.forget_map, MorphismProperty.Comma.toCommaMorphism_eq_hom, ← MorphismProperty.Comma.forget_map, ← Functor.comp_map] rw [← PreservesPullback.iso_hom_snd, P.cancel_left_of_respectsIso] exact P.pullback_snd _ _ (𝒰.map_prop j) instance (j : 𝒰.J) : ((𝒰.pullbackCoverOverProp' S f hX hW hQ).obj j).Over S where hom := (pullback ((𝒰.map j).asOverProp (hX := hQ j) (hY := hX) S) (f.asOverProp (hX := hW) (hY := hX) S)).hom instance : (𝒰.pullbackCoverOverProp' S f hX hW hQ).Over S where isOver_map j := { comp_over := by exact (pullback.snd ((𝒰.map j).asOverProp S) (f.asOverProp S)).w } end variable [P.IsStableUnderComposition] variable {X : Scheme.{u}} (𝒰 : X.Cover P) (𝒱 : ∀ x, (𝒰.obj x).Cover P) [X.Over S] [𝒰.Over S] [∀ x, (𝒱 x).Over S] instance (j : (𝒰.bind 𝒱).J) : ((𝒰.bind 𝒱).obj j).Over S := inferInstanceAs <| ((𝒱 j.1).obj j.2).Over S instance {X : Scheme.{u}} (𝒰 : X.Cover P) (𝒱 : ∀ x, (𝒰.obj x).Cover P) [X.Over S] [𝒰.Over S] [∀ x, (𝒱 x).Over S] : (𝒰.bind 𝒱).Over S where over := fun ⟨i, j⟩ ↦ inferInstanceAs <| ((𝒱 i).obj j).Over S isOver_map := fun ⟨i, j⟩ ↦ { comp_over := by simp } end AlgebraicGeometry.Scheme
MellinInversion.lean
/- Copyright (c) 2024 Lawrence Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lawrence Wu -/ import Mathlib.Analysis.Fourier.Inversion import Mathlib.Analysis.MellinTransform /-! # Mellin inversion formula We derive the Mellin inversion formula as a consequence of the Fourier inversion formula. ## Main results - `mellin_inversion`: The inverse Mellin transform of the Mellin transform applied to `x > 0` is x. -/ open Real Complex Set MeasureTheory variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] open scoped FourierTransform private theorem rexp_neg_deriv_aux : ∀ x ∈ univ, HasDerivWithinAt (rexp ∘ Neg.neg) (-rexp (-x)) univ x := fun x _ ↦ mul_neg_one (rexp (-x)) ▸ ((Real.hasDerivAt_exp (-x)).comp x (hasDerivAt_neg x)).hasDerivWithinAt private theorem rexp_neg_image_aux : rexp ∘ Neg.neg '' univ = Ioi 0 := by rw [Set.image_comp, Set.image_univ_of_surjective neg_surjective, Set.image_univ, Real.range_exp] private theorem rexp_neg_injOn_aux : univ.InjOn (rexp ∘ Neg.neg) := Real.exp_injective.injOn.comp neg_injective.injOn (univ.mapsTo_univ _) private theorem rexp_cexp_aux (x : ℝ) (s : ℂ) (f : E) : rexp (-x) • cexp (-↑x) ^ (s - 1) • f = cexp (-s * ↑x) • f := by change (rexp (-x) : ℂ) • _ = _ • f rw [← smul_assoc, smul_eq_mul] push_cast conv in cexp _ * _ => lhs; rw [← cpow_one (cexp _)] rw [← cpow_add _ _ (Complex.exp_ne_zero _), cpow_def_of_ne_zero (Complex.exp_ne_zero _), Complex.log_exp (by simp [pi_pos]) (by simpa using pi_nonneg)] ring_nf theorem mellin_eq_fourierIntegral (f : ℝ → E) {s : ℂ} : mellin f s = 𝓕 (fun (u : ℝ) ↦ (Real.exp (-s.re * u) • f (Real.exp (-u)))) (s.im / (2 * π)) := calc mellin f s = ∫ (u : ℝ), Complex.exp (-s * u) • f (Real.exp (-u)) := by rw [mellin, ← rexp_neg_image_aux, integral_image_eq_integral_abs_deriv_smul MeasurableSet.univ rexp_neg_deriv_aux rexp_neg_injOn_aux] simp [rexp_cexp_aux] _ = ∫ (u : ℝ), Complex.exp (↑(-2 * π * (u * (s.im / (2 * π)))) * I) • (Real.exp (-s.re * u) • f (Real.exp (-u))) := by congr ext u trans Complex.exp (-s.im * u * I) • (Real.exp (-s.re * u) • f (Real.exp (-u))) · conv => lhs; rw [← re_add_im s] rw [neg_add, add_mul, Complex.exp_add, mul_comm, ← smul_eq_mul, smul_assoc] norm_cast push_cast ring_nf congr rw [mul_comm (-s.im : ℂ) (u : ℂ), mul_comm (-2 * π)] have : 2 * (π : ℂ) ≠ 0 := by simp field_simp _ = 𝓕 (fun (u : ℝ) ↦ (Real.exp (-s.re * u) • f (Real.exp (-u)))) (s.im / (2 * π)) := by simp [fourierIntegral_eq', mul_comm (_ / _)] theorem mellinInv_eq_fourierIntegralInv (σ : ℝ) (f : ℂ → E) {x : ℝ} (hx : 0 < x) : mellinInv σ f x = (x : ℂ) ^ (-σ : ℂ) • 𝓕⁻ (fun (y : ℝ) ↦ f (σ + 2 * π * y * I)) (-Real.log x) := calc mellinInv σ f x = (x : ℂ) ^ (-σ : ℂ) • (∫ (y : ℝ), Complex.exp (2 * π * (y * (-Real.log x)) * I) • f (σ + 2 * π * y * I)) := by rw [mellinInv, one_div, ← abs_of_pos (show 0 < (2 * π)⁻¹ by simp [pi_pos])] have hx0 : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr (ne_of_gt hx) simp_rw [neg_add, cpow_add _ _ hx0, mul_smul, integral_smul] rw [smul_comm, ← Measure.integral_comp_mul_left] congr! 3 rw [cpow_def_of_ne_zero hx0, ← Complex.ofReal_log hx.le] push_cast ring_nf _ = (x : ℂ) ^ (-σ : ℂ) • 𝓕⁻ (fun (y : ℝ) ↦ f (σ + 2 * π * y * I)) (-Real.log x) := by simp [fourierIntegralInv_eq', mul_comm (Real.log _)] variable [CompleteSpace E] /-- The inverse Mellin transform of the Mellin transform applied to `x > 0` is x. -/ theorem mellin_inversion (σ : ℝ) (f : ℝ → E) {x : ℝ} (hx : 0 < x) (hf : MellinConvergent f σ) (hFf : VerticalIntegrable (mellin f) σ) (hfx : ContinuousAt f x) : mellinInv σ (mellin f) x = f x := by let g := fun (u : ℝ) => Real.exp (-σ * u) • f (Real.exp (-u)) replace hf : Integrable g := by rw [MellinConvergent, ← rexp_neg_image_aux, integrableOn_image_iff_integrableOn_abs_deriv_smul MeasurableSet.univ rexp_neg_deriv_aux rexp_neg_injOn_aux] at hf replace hf : Integrable fun (x : ℝ) ↦ cexp (-↑σ * ↑x) • f (rexp (-x)) := by simpa [rexp_cexp_aux] using hf norm_cast at hf replace hFf : Integrable (𝓕 g) := by have h2π : 2 * π ≠ 0 := by simp have : Integrable (𝓕 (fun u ↦ rexp (-(σ * u)) • f (rexp (-u)))) := by simpa [mellin_eq_fourierIntegral, mul_div_cancel_right₀ _ h2π] using hFf.comp_mul_right' h2π simp_rw [neg_mul_eq_neg_mul] at this exact this replace hfx : ContinuousAt g (-Real.log x) := by refine ContinuousAt.smul (by fun_prop) (ContinuousAt.comp ?_ (by fun_prop)) simpa [Real.exp_log hx] using hfx calc mellinInv σ (mellin f) x = mellinInv σ (fun s ↦ 𝓕 g (s.im / (2 * π))) x := by simp [g, mellinInv, mellin_eq_fourierIntegral] _ = (x : ℂ) ^ (-σ : ℂ) • g (-Real.log x) := by rw [mellinInv_eq_fourierIntegralInv _ _ hx, ← hf.fourier_inversion hFf hfx] simp [mul_div_cancel_left₀ _ (show 2 * π ≠ 0 by simp)] _ = (x : ℂ) ^ (-σ : ℂ) • rexp (σ * Real.log x) • f (rexp (Real.log x)) := by simp [g] _ = f x := by norm_cast rw [mul_comm σ, ← rpow_def_of_pos hx, Real.exp_log hx, ← Complex.ofReal_cpow hx.le] norm_cast rw [← smul_assoc, smul_eq_mul, Real.rpow_neg hx.le, inv_mul_cancel₀ (ne_of_gt (rpow_pos_of_pos hx σ)), one_smul]
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.ObjectProperty.Shift import Mathlib.CategoryTheory.Triangulated.Pretriangulated /-! # t-structures on triangulated categories This files introduces the notion of t-structure on (pre)triangulated categories. The first example of t-structure shall be the canonical t-structure on the derived category of an abelian category (TODO). Given a t-structure `t : TStructure C`, we define type classes `t.IsLE X n` and `t.IsGE X n` in order to say that an object `X : C` is `≤ n` or `≥ n` for `t`. ## Implementation notes We introduce the type of t-structures rather than a type class saying that we have fixed a t-structure on a certain category. The reason is that certain triangulated categories have several t-structures which one may want to use depending on the context. ## TODO * define functors `t.truncLE n : C ⥤ C`,`t.truncGE n : C ⥤ C` and the associated distinguished triangles * promote these truncations to a (functorial) spectral object * define the heart of `t` and show it is an abelian category * define triangulated subcategories `t.plus`, `t.minus`, `t.bounded` and show that there are induced t-structures on these full subcategories ## References * [Beilinson, Bernstein, Deligne, Gabber, *Faisceaux pervers*][bbd-1982] -/ assert_not_exists TwoSidedIdeal namespace CategoryTheory open Limits namespace Triangulated variable (C : Type _) [Category C] [Preadditive C] [HasZeroObject C] [HasShift C ℤ] [∀ (n : ℤ), (shiftFunctor C n).Additive] [Pretriangulated C] open Pretriangulated /-- `TStructure C` is the type of t-structures on the (pre)triangulated category `C`. -/ structure TStructure where /-- the predicate of objects that are `≤ n` for `n : ℤ`. -/ le (n : ℤ) : ObjectProperty C /-- the predicate of objects that are `≥ n` for `n : ℤ`. -/ ge (n : ℤ) : ObjectProperty C le_isClosedUnderIsomorphisms (n : ℤ) : (le n).IsClosedUnderIsomorphisms := by infer_instance ge_isClosedUnderIsomorphisms (n : ℤ) : (ge n).IsClosedUnderIsomorphisms := by infer_instance le_shift (n a n' : ℤ) (h : a + n' = n) (X : C) (hX : le n X) : le n' (X⟦a⟧) ge_shift (n a n' : ℤ) (h : a + n' = n) (X : C) (hX : ge n X) : ge n' (X⟦a⟧) zero' ⦃X Y : C⦄ (f : X ⟶ Y) (hX : le 0 X) (hY : ge 1 Y) : f = 0 le_zero_le : le 0 ≤ le 1 ge_one_le : ge 1 ≤ ge 0 exists_triangle_zero_one (A : C) : ∃ (X Y : C) (_ : le 0 X) (_ : ge 1 Y) (f : X ⟶ A) (g : A ⟶ Y) (h : Y ⟶ X⟦(1 : ℤ)⟧), Triangle.mk f g h ∈ distTriang C namespace TStructure attribute [instance] le_isClosedUnderIsomorphisms ge_isClosedUnderIsomorphisms variable {C} variable (t : TStructure C) lemma exists_triangle (A : C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) : ∃ (X Y : C) (_ : t.le n₀ X) (_ : t.ge n₁ Y) (f : X ⟶ A) (g : A ⟶ Y) (h : Y ⟶ X⟦(1 : ℤ)⟧), Triangle.mk f g h ∈ distTriang C := by obtain ⟨X, Y, hX, hY, f, g, h, mem⟩ := t.exists_triangle_zero_one (A⟦n₀⟧) let T := (Triangle.shiftFunctor C (-n₀)).obj (Triangle.mk f g h) let e := (shiftEquiv C n₀).unitIso.symm.app A have hT' : Triangle.mk (T.mor₁ ≫ e.hom) (e.inv ≫ T.mor₂) T.mor₃ ∈ distTriang C := by refine isomorphic_distinguished _ (Triangle.shift_distinguished _ mem (-n₀)) _ ?_ refine Triangle.isoMk _ _ (Iso.refl _) e.symm (Iso.refl _) ?_ ?_ ?_ all_goals simp [T] exact ⟨_, _, t.le_shift _ _ _ (neg_add_cancel n₀) _ hX, t.ge_shift _ _ _ (by omega) _ hY, _, _, _, hT'⟩ lemma shift_le (a n n' : ℤ) (hn' : a + n = n') : (t.le n).shift a = t.le n' := by ext X constructor · intro hX exact ((t.le n').prop_iff_of_iso ((shiftEquiv C a).unitIso.symm.app X)).1 (t.le_shift n (-a) n' (by omega) _ hX) · intro hX exact t.le_shift _ _ _ hn' X hX lemma shift_ge (a n n' : ℤ) (hn' : a + n = n') : (t.ge n).shift a = t.ge n' := by ext X constructor · intro hX exact ((t.ge n').prop_iff_of_iso ((shiftEquiv C a).unitIso.symm.app X)).1 (t.ge_shift n (-a) n' (by omega) _ hX) · intro hX exact t.ge_shift _ _ _ hn' X hX lemma le_monotone : Monotone t.le := by let H := fun (a : ℕ) => ∀ (n : ℤ), t.le n ≤ t.le (n + a) suffices ∀ (a : ℕ), H a by intro n₀ n₁ h obtain ⟨a, ha⟩ := Int.nonneg_def.1 h obtain rfl : n₁ = n₀ + a := by omega apply this have H_zero : H 0 := fun n => by simp only [Nat.cast_zero, add_zero] rfl have H_one : H 1 := fun n X hX => by rw [← t.shift_le n 1 (n + (1 : ℕ)) rfl, ObjectProperty.prop_shift_iff] rw [← t.shift_le n 0 n (add_zero n), ObjectProperty.prop_shift_iff] at hX exact t.le_zero_le _ hX have H_add : ∀ (a b c : ℕ) (_ : a + b = c) (_ : H a) (_ : H b), H c := by intro a b c h ha hb n rw [← h, Nat.cast_add, ← add_assoc] exact (ha n).trans (hb (n+a)) intro a induction' a with a ha · exact H_zero · exact H_add a 1 _ rfl ha H_one lemma ge_antitone : Antitone t.ge := by let H := fun (a : ℕ) => ∀ (n : ℤ), t.ge (n + a) ≤ t.ge n suffices ∀ (a : ℕ), H a by intro n₀ n₁ h obtain ⟨a, ha⟩ := Int.nonneg_def.1 h obtain rfl : n₁ = n₀ + a := by omega apply this have H_zero : H 0 := fun n => by simp only [Nat.cast_zero, add_zero] rfl have H_one : H 1 := fun n X hX => by rw [← t.shift_ge n 1 (n + (1 : ℕ)) (by simp), ObjectProperty.prop_shift_iff] at hX rw [← t.shift_ge n 0 n (add_zero n)] exact t.ge_one_le _ hX have H_add : ∀ (a b c : ℕ) (_ : a + b = c) (_ : H a) (_ : H b), H c := by intro a b c h ha hb n rw [← h, Nat.cast_add, ← add_assoc ] exact (hb (n + a)).trans (ha n) intro a induction' a with a ha · exact H_zero · exact H_add a 1 _ rfl ha H_one /-- Given a t-structure `t` on a pretriangulated category `C`, the property `t.IsLE X n` holds if `X : C` is `≤ n` for the t-structure. -/ class IsLE (X : C) (n : ℤ) : Prop where le : t.le n X /-- Given a t-structure `t` on a pretriangulated category `C`, the property `t.IsGE X n` holds if `X : C` is `≥ n` for the t-structure. -/ class IsGE (X : C) (n : ℤ) : Prop where ge : t.ge n X lemma le_of_isLE (X : C) (n : ℤ) [t.IsLE X n] : t.le n X := IsLE.le lemma ge_of_isGE (X : C) (n : ℤ) [t.IsGE X n] : t.ge n X := IsGE.ge @[deprecated (since := "2025-02-25")] alias LE := le @[deprecated (since := "2025-02-25")] alias GE := ge @[deprecated (since := "2025-02-25")] alias LE_shift := le_shift @[deprecated (since := "2025-02-25")] alias GE_shift := ge_shift @[deprecated (since := "2025-02-25")] alias LE_zero_le := le_zero_le @[deprecated (since := "2025-02-25")] alias GE_one_le := ge_one_le @[deprecated (since := "2025-02-25")] alias predicateShift_LE := shift_le @[deprecated (since := "2025-02-25")] alias predicateShift_GE := shift_ge @[deprecated (since := "2025-02-25")] alias LE_monotone := le_monotone @[deprecated (since := "2025-02-25")] alias GE_antitone := ge_antitone @[deprecated (since := "2025-02-25")] alias mem_of_isLE := le_of_isLE @[deprecated (since := "2025-02-25")] alias mem_of_isGE := ge_of_isGE end TStructure end Triangulated end CategoryTheory
Unitization.lean
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Unitization import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul /-! # Unitization norms Given a not-necessarily-unital normed `𝕜`-algebra `A`, it is frequently of interest to equip its `Unitization` with a norm which simultaneously makes it into a normed algebra and also satisfies two properties: - `‖1‖ = 1` (i.e., `NormOneClass`) - The embedding of `A` in `Unitization 𝕜 A` is an isometry. (i.e., `Isometry Unitization.inr`) One way to do this is to pull back the norm from `WithLp 1 (𝕜 × A)`, that is, `‖(k, a)‖ = ‖k‖ + ‖a‖` using `Unitization.addEquiv` (i.e., the identity map). This is implemented for the type synonym `WithLp 1 (Unitization 𝕜 A)` in `WithLp.instUnitizationNormedAddCommGroup`, and it is shown there that this is a Banach algebra. However, when the norm on `A` is *regular* (i.e., `ContinuousLinearMap.mul` is an isometry), there is another natural choice: the pullback of the norm on `𝕜 × (A →L[𝕜] A)` under the map `(k, a) ↦ (k, k • 1 + ContinuousLinearMap.mul 𝕜 A a)`. It turns out that among all norms on the unitization satisfying the properties specified above, the norm inherited from `WithLp 1 (𝕜 × A)` is maximal, and the norm inherited from this pullback is minimal. Of course, this means that `WithLp.equiv : WithLp 1 (Unitization 𝕜 A) → Unitization 𝕜 A` can be upgraded to a continuous linear equivalence (when `𝕜` and `A` are complete). structure on `Unitization 𝕜 A` using the pullback described above. The reason for choosing this norm is that for a C⋆-algebra `A` its norm is always regular, and the pullback norm on `Unitization 𝕜 A` is then also a C⋆-norm. ## Main definitions - `Unitization.splitMul : Unitization 𝕜 A →ₐ[𝕜] (𝕜 × (A →L[𝕜] A))`: The first coordinate of this map is just `Unitization.fst` and the second is the `Unitization.lift` of the left regular representation of `A` (i.e., `NonUnitalAlgHom.Lmul`). We use this map to pull back the `NormedRing` and `NormedAlgebra` structures. ## Main statements - `Unitization.instNormedRing`, `Unitization.instNormedAlgebra`, `Unitization.instNormOneClass`, `Unitization.instCompleteSpace`: when `A` is a non-unital Banach `𝕜`-algebra with a regular norm, then `Unitization 𝕜 A` is a unital Banach `𝕜`-algebra with `‖1‖ = 1`. - `Unitization.norm_inr`, `Unitization.isometry_inr`: the natural inclusion `A → Unitization 𝕜 A` is an isometry, or in mathematical parlance, the norm on `A` extends to a norm on `Unitization 𝕜 A`. ## Implementation details We ensure that the uniform structure, and hence also the topological structure, is definitionally equal to the pullback of `instUniformSpaceProd` along `Unitization.addEquiv` (this is essentially viewing `Unitization 𝕜 A` as `𝕜 × A`) by means of forgetful inheritance. The same is true of the bornology. -/ suppress_compilation variable (𝕜 A : Type*) [NontriviallyNormedField 𝕜] [NonUnitalNormedRing A] variable [NormedSpace 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A] open ContinuousLinearMap namespace Unitization /-- Given `(k, a) : Unitization 𝕜 A`, the second coordinate of `Unitization.splitMul (k, a)` is the natural representation of `Unitization 𝕜 A` on `A` given by multiplication on the left in `A →L[𝕜] A`; note that this is not just `NonUnitalAlgHom.Lmul` for a few reasons: (a) that would either be `A` acting on `A`, or (b) `Unitization 𝕜 A` acting on `Unitization 𝕜 A`, and (c) that's a `NonUnitalAlgHom` but here we need an `AlgHom`. In addition, the first coordinate of `Unitization.splitMul (k, a)` should just be `k`. See `Unitization.splitMul_apply` also. -/ def splitMul : Unitization 𝕜 A →ₐ[𝕜] 𝕜 × (A →L[𝕜] A) := (lift 0).prod (lift <| NonUnitalAlgHom.Lmul 𝕜 A) variable {𝕜 A} @[simp] theorem splitMul_apply (x : Unitization 𝕜 A) : splitMul 𝕜 A x = (x.fst, algebraMap 𝕜 (A →L[𝕜] A) x.fst + mul 𝕜 A x.snd) := show (x.fst + 0, _) = (x.fst, _) by rw [add_zero]; rfl /-- this lemma establishes that if `ContinuousLinearMap.mul 𝕜 A` is injective, then so is `Unitization.splitMul 𝕜 A`. When `A` is a `RegularNormedAlgebra`, then `ContinuousLinearMap.mul 𝕜 A` is an isometry, and is therefore automatically injective. -/ theorem splitMul_injective_of_clm_mul_injective (h : Function.Injective (mul 𝕜 A)) : Function.Injective (splitMul 𝕜 A) := by rw [injective_iff_map_eq_zero] intro x hx induction x rw [map_add] at hx simp only [splitMul_apply, fst_inl, snd_inl, map_zero, add_zero, fst_inr, snd_inr, zero_add, Prod.mk_add_mk, Prod.mk_eq_zero] at hx obtain ⟨rfl, hx⟩ := hx simp only [map_zero, zero_add, inl_zero] at hx ⊢ rw [← map_zero (mul 𝕜 A)] at hx rw [h hx, inr_zero] variable [RegularNormedAlgebra 𝕜 A] variable (𝕜 A) /-- In a `RegularNormedAlgebra`, the map `Unitization.splitMul 𝕜 A` is injective. We will use this to pull back the norm from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A`. -/ theorem splitMul_injective : Function.Injective (splitMul 𝕜 A) := splitMul_injective_of_clm_mul_injective (isometry_mul 𝕜 A).injective variable {𝕜 A} section Aux /-- Pull back the normed ring structure from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A` using the algebra homomorphism `Unitization.splitMul 𝕜 A`. This does not give us the desired topology, uniformity or bornology on `Unitization 𝕜 A` (which we want to agree with `Prod`), so we only use it as a local instance to build the real one. -/ noncomputable abbrev normedRingAux : NormedRing (Unitization 𝕜 A) := NormedRing.induced (Unitization 𝕜 A) (𝕜 × (A →L[𝕜] A)) (splitMul 𝕜 A) (splitMul_injective 𝕜 A) attribute [local instance] Unitization.normedRingAux /-- Pull back the normed algebra structure from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A` using the algebra homomorphism `Unitization.splitMul 𝕜 A`. This uses the wrong `NormedRing` instance (i.e., `Unitization.normedRingAux`), so we only use it as a local instance to build the real one. -/ noncomputable abbrev normedAlgebraAux : NormedAlgebra 𝕜 (Unitization 𝕜 A) := NormedAlgebra.induced 𝕜 (Unitization 𝕜 A) (𝕜 × (A →L[𝕜] A)) (splitMul 𝕜 A) attribute [local instance] Unitization.normedAlgebraAux theorem norm_def (x : Unitization 𝕜 A) : ‖x‖ = ‖splitMul 𝕜 A x‖ := rfl theorem nnnorm_def (x : Unitization 𝕜 A) : ‖x‖₊ = ‖splitMul 𝕜 A x‖₊ := rfl /-- This is often the more useful lemma to rewrite the norm as opposed to `Unitization.norm_def`. -/ theorem norm_eq_sup (x : Unitization 𝕜 A) : ‖x‖ = ‖x.fst‖ ⊔ ‖algebraMap 𝕜 (A →L[𝕜] A) x.fst + mul 𝕜 A x.snd‖ := by rw [norm_def, splitMul_apply, Prod.norm_def] /-- This is often the more useful lemma to rewrite the norm as opposed to `Unitization.nnnorm_def`. -/ theorem nnnorm_eq_sup (x : Unitization 𝕜 A) : ‖x‖₊ = ‖x.fst‖₊ ⊔ ‖algebraMap 𝕜 (A →L[𝕜] A) x.fst + mul 𝕜 A x.snd‖₊ := NNReal.eq <| norm_eq_sup x theorem lipschitzWith_addEquiv : LipschitzWith 2 (Unitization.addEquiv 𝕜 A) := by rw [← Real.toNNReal_ofNat] refine AddMonoidHomClass.lipschitz_of_bound (Unitization.addEquiv 𝕜 A) 2 fun x => ?_ rw [norm_eq_sup, Prod.norm_def] refine max_le ?_ ?_ · rw [mul_max_of_nonneg _ _ (zero_le_two : (0 : ℝ) ≤ 2)] exact le_max_of_le_left ((le_add_of_nonneg_left (norm_nonneg _)).trans_eq (two_mul _).symm) · nontriviality A rw [two_mul] calc ‖x.snd‖ = ‖mul 𝕜 A x.snd‖ := .symm <| (isometry_mul 𝕜 A).norm_map_of_map_zero (map_zero _) _ _ ≤ ‖algebraMap 𝕜 _ x.fst + mul 𝕜 A x.snd‖ + ‖x.fst‖ := by simpa only [add_comm _ (mul 𝕜 A x.snd), norm_algebraMap'] using norm_le_add_norm_add (mul 𝕜 A x.snd) (algebraMap 𝕜 _ x.fst) _ ≤ _ := add_le_add le_sup_right le_sup_left theorem antilipschitzWith_addEquiv : AntilipschitzWith 2 (addEquiv 𝕜 A) := by refine AddMonoidHomClass.antilipschitz_of_bound (addEquiv 𝕜 A) fun x => ?_ rw [norm_eq_sup, Prod.norm_def, NNReal.coe_two] refine max_le ?_ ?_ · rw [mul_max_of_nonneg _ _ (zero_le_two : (0 : ℝ) ≤ 2)] exact le_max_of_le_left ((le_add_of_nonneg_left (norm_nonneg _)).trans_eq (two_mul _).symm) · nontriviality A calc ‖algebraMap 𝕜 _ x.fst + mul 𝕜 A x.snd‖ ≤ ‖algebraMap 𝕜 _ x.fst‖ + ‖mul 𝕜 A x.snd‖ := norm_add_le _ _ _ = ‖x.fst‖ + ‖x.snd‖ := by rw [norm_algebraMap', (AddMonoidHomClass.isometry_iff_norm (mul 𝕜 A)).mp (isometry_mul 𝕜 A)] _ ≤ _ := (add_le_add (le_max_left _ _) (le_max_right _ _)).trans_eq (two_mul _).symm open Bornology Filter open scoped Uniformity Topology theorem uniformity_eq_aux : 𝓤[instUniformSpaceProd.comap <| addEquiv 𝕜 A] = 𝓤 (Unitization 𝕜 A) := by have key : IsUniformInducing (addEquiv 𝕜 A) := antilipschitzWith_addEquiv.isUniformInducing lipschitzWith_addEquiv.uniformContinuous rw [← key.comap_uniformity] rfl theorem cobounded_eq_aux : @cobounded _ (Bornology.induced <| addEquiv 𝕜 A) = cobounded (Unitization 𝕜 A) := le_antisymm lipschitzWith_addEquiv.comap_cobounded_le antilipschitzWith_addEquiv.tendsto_cobounded.le_comap end Aux /-- The uniformity on `Unitization 𝕜 A` is inherited from `𝕜 × A`. -/ instance instUniformSpace : UniformSpace (Unitization 𝕜 A) := instUniformSpaceProd.comap (addEquiv 𝕜 A) /-- The natural equivalence between `Unitization 𝕜 A` and `𝕜 × A` as a uniform equivalence. -/ def uniformEquivProd : (Unitization 𝕜 A) ≃ᵤ (𝕜 × A) := Equiv.toUniformEquivOfIsUniformInducing (addEquiv 𝕜 A) ⟨rfl⟩ /-- The bornology on `Unitization 𝕜 A` is inherited from `𝕜 × A`. -/ instance instBornology : Bornology (Unitization 𝕜 A) := Bornology.induced <| addEquiv 𝕜 A theorem isUniformEmbedding_addEquiv {𝕜} [NontriviallyNormedField 𝕜] : IsUniformEmbedding (addEquiv 𝕜 A) where comap_uniformity := rfl injective := (addEquiv 𝕜 A).injective /-- `Unitization 𝕜 A` is complete whenever `𝕜` and `A` are also. -/ instance instCompleteSpace [CompleteSpace 𝕜] [CompleteSpace A] : CompleteSpace (Unitization 𝕜 A) := uniformEquivProd.completeSpace_iff.2 .prod /-- Pull back the metric structure from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A` using the algebra homomorphism `Unitization.splitMul 𝕜 A`, but replace the bornology and the uniformity so that they coincide with `𝕜 × A`. -/ noncomputable instance instMetricSpace : MetricSpace (Unitization 𝕜 A) := (normedRingAux.toMetricSpace.replaceUniformity uniformity_eq_aux).replaceBornology fun s => Filter.ext_iff.1 cobounded_eq_aux (sᶜ) /-- Pull back the normed ring structure from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A` using the algebra homomorphism `Unitization.splitMul 𝕜 A`. -/ noncomputable instance instNormedRing : NormedRing (Unitization 𝕜 A) where dist_eq := normedRingAux.dist_eq norm_mul_le := normedRingAux.norm_mul_le norm := normedRingAux.norm /-- Pull back the normed algebra structure from `𝕜 × (A →L[𝕜] A)` to `Unitization 𝕜 A` using the algebra homomorphism `Unitization.splitMul 𝕜 A`. -/ instance instNormedAlgebra : NormedAlgebra 𝕜 (Unitization 𝕜 A) where norm_smul_le k x := by rw [norm_def, map_smul] -- Note: this used to be `rw [norm_smul, ← norm_def]` before https://github.com/leanprover-community/mathlib4/pull/8386 exact (norm_smul k (splitMul 𝕜 A x)).le instance instNormOneClass : NormOneClass (Unitization 𝕜 A) where norm_one := by simpa only [norm_eq_sup, fst_one, norm_one, snd_one, map_one, map_zero, add_zero, sup_eq_left] using opNorm_le_bound _ zero_le_one fun x => by simp lemma norm_inr (a : A) : ‖(a : Unitization 𝕜 A)‖ = ‖a‖ := by simp [norm_eq_sup] lemma nnnorm_inr (a : A) : ‖(a : Unitization 𝕜 A)‖₊ = ‖a‖₊ := NNReal.eq <| norm_inr a lemma isometry_inr : Isometry ((↑) : A → Unitization 𝕜 A) := AddMonoidHomClass.isometry_of_norm (inrNonUnitalAlgHom 𝕜 A) norm_inr @[fun_prop] theorem continuous_inr : Continuous (inr : A → Unitization 𝕜 A) := isometry_inr.continuous lemma dist_inr (a b : A) : dist (a : Unitization 𝕜 A) (b : Unitization 𝕜 A) = dist a b := isometry_inr.dist_eq a b lemma nndist_inr (a b : A) : nndist (a : Unitization 𝕜 A) (b : Unitization 𝕜 A) = nndist a b := isometry_inr.nndist_eq a b /- These examples verify that the bornology and uniformity (hence also the topology) are the correct ones. -/ example : (instNormedRing (𝕜 := 𝕜) (A := A)).toMetricSpace = instMetricSpace := rfl example : (instMetricSpace (𝕜 := 𝕜) (A := A)).toBornology = instBornology := rfl example : (instMetricSpace (𝕜 := 𝕜) (A := A)).toUniformSpace = instUniformSpace := rfl end Unitization
GuardGoalNums.lean
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Init import Lean.Elab.Tactic.Basic /-! A tactic stub file for the `guard_goal_nums` tactic. -/ open Lean Meta Elab Tactic /-- `guard_goal_nums n` succeeds if there are exactly `n` goals and fails otherwise. -/ elab (name := guardGoalNums) "guard_goal_nums " n:num : tactic => do let numGoals := (← getGoals).length guard (numGoals = n.getNat) <|> throwError "expected {n.getNat} goals but found {numGoals}"
GrpWithZero.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.Algebra.Category.MonCat.Basic import Mathlib.Algebra.GroupWithZero.WithZero import Mathlib.CategoryTheory.Category.Bipointed /-! # The category of groups with zero This file defines `GrpWithZero`, the category of groups with zero. -/ assert_not_exists Ring universe u open CategoryTheory /-- The category of groups with zero. -/ structure GrpWithZero where /-- The underlying group with zero. -/ carrier : Type* [str : GroupWithZero carrier] attribute [instance] GrpWithZero.str namespace GrpWithZero instance : CoeSort GrpWithZero Type* := ⟨carrier⟩ /-- Construct a bundled `GrpWithZero` from a `GroupWithZero`. -/ abbrev of (α : Type*) [GroupWithZero α] : GrpWithZero where carrier := α instance : Inhabited GrpWithZero := ⟨of (WithZero PUnit)⟩ instance : LargeCategory.{u} GrpWithZero where Hom X Y := MonoidWithZeroHom X Y id X := MonoidWithZeroHom.id X comp f g := g.comp f instance groupWithZeroConcreteCategory : ConcreteCategory GrpWithZero (MonoidWithZeroHom · ·) where hom f := f ofHom f := f /-- Typecheck a `MonoidWithZeroHom` as a morphism in `GrpWithZero`. -/ abbrev ofHom {X Y : Type u} [GroupWithZero X] [GroupWithZero Y] (f : MonoidWithZeroHom X Y) : of X ⟶ of Y := ConcreteCategory.ofHom f @[simp] lemma hom_id {X : GrpWithZero} : ConcreteCategory.hom (𝟙 X : X ⟶ X) = MonoidWithZeroHom.id X := rfl @[simp] lemma hom_comp {X Y Z : GrpWithZero} {f : X ⟶ Y} {g : Y ⟶ Z} : ConcreteCategory.hom (f ≫ g) = g.comp f := rfl lemma coe_id {X : GrpWithZero} : (𝟙 X : X → X) = id := rfl lemma coe_comp {X Y Z : GrpWithZero} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g : X → Z) = g ∘ f := rfl @[simp] lemma forget_map {X Y : GrpWithZero} (f : X ⟶ Y) : (forget GrpWithZero).map f = f := rfl instance hasForgetToBipointed : HasForget₂ GrpWithZero Bipointed where forget₂ := { obj := fun X => ⟨X, 0, 1⟩ map := fun f => ⟨f, f.map_zero', f.map_one'⟩ } instance hasForgetToMon : HasForget₂ GrpWithZero MonCat where forget₂ := { obj := fun X => MonCat.of X map := fun f => MonCat.ofHom f.toMonoidHom } /-- Constructs an isomorphism of groups with zero from a group isomorphism between them. -/ @[simps] def Iso.mk {α β : GrpWithZero.{u}} (e : α ≃* β) : α ≅ β where hom := ofHom e inv := ofHom e.symm hom_inv_id := by ext exact e.symm_apply_apply _ inv_hom_id := by ext exact e.apply_symm_apply _ end GrpWithZero
Basic.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, Mario Carneiro, Patrick Massot -/ import Mathlib.Data.Rel import Mathlib.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology open scoped Uniformity universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} open scoped SetRel in lemma IsOpen.relComp [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {s : SetRel α β} {t : SetRel β γ} (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ○ t) := by conv => arg 1; equals ⋃ b, (fun p => (p.1, b)) ⁻¹' s ∩ (fun p => (b, p.2)) ⁻¹' t => ext ⟨_, _⟩; simp exact isOpen_iUnion fun a ↦ hs.preimage (by fun_prop) |>.inter <| ht.preimage (by fun_prop) section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono inf_le_left) map_comap_le theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) := le_trans (map_mono inf_le_right) map_comap_le theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.1 := tendsto_prod_uniformity_fst theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.2 := tendsto_prod_uniformity_snd variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁) (h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by rw [UniformContinuous, uniformity_prod] exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk := UniformContinuous.prodMk theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) : UniformContinuous fun a => f (a, b) := h.comp (uniformContinuous_id.prodMk uniformContinuous_const) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_left := UniformContinuous.prodMk_left theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) : UniformContinuous fun b => f (a, b) := h.comp (uniformContinuous_const.prodMk uniformContinuous_id) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_right := UniformContinuous.prodMk_right theorem UniformContinuous.prodMap [UniformSpace δ] {f : α → γ} {g : β → δ} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) := (hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd) theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] : @UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd = @instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace := rfl /-- A version of `UniformContinuous.inf_dom_left` for binary functions -/ theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_left₂` have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `UniformContinuous.inf_dom_right` for binary functions -/ theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_right₂` have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `uniformContinuous_sInf_dom` for binary functions -/ theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)} {ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ} (ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := sInf uas; haveI := sInf ubs exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_sInf_dom` let _ : UniformSpace (α × β) := instUniformSpaceProd have ha := uniformContinuous_sInf_dom ha uniformContinuous_id have hb := uniformContinuous_sInf_dom hb uniformContinuous_id have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id end Prod section open UniformSpace Function variable {δ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ] [UniformSpace δ'] local notation f " ∘₂ " g => Function.bicompr f g /-- Uniform continuity for functions of two variables. -/ def UniformContinuous₂ (f : α → β → γ) := UniformContinuous (uncurry f) theorem uniformContinuous₂_def (f : α → β → γ) : UniformContinuous₂ f ↔ UniformContinuous (uncurry f) := Iff.rfl theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) : UniformContinuous (uncurry f) := h theorem uniformContinuous₂_curry (f : α × β → γ) : UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by rw [UniformContinuous₂, uncurry_curry] theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : UniformContinuous g) (hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) := hg.comp hf theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β} (hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) : UniformContinuous₂ (bicompl f ga gb) := hf.uniformContinuous.comp (hga.prodMap hgb) end theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} : @UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype = @instTopologicalSpaceSubtype α p u.toTopologicalSpace := rfl section Sum variable [UniformSpace α] [UniformSpace β] open Sum -- Obsolete auxiliary definitions and lemmas /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓤 α) ⊔ map (fun p : β × β => (inr p.1, inr p.2)) (𝓤 β) symm := fun _ hs ↦ ⟨symm_le_uniformity hs.1, symm_le_uniformity hs.2⟩ comp := fun s hs ↦ by rcases comp_mem_uniformity_sets hs.1 with ⟨tα, htα, Htα⟩ rcases comp_mem_uniformity_sets hs.2 with ⟨tβ, htβ, Htβ⟩ filter_upwards [mem_lift' (union_mem_sup (image_mem_map htα) (image_mem_map htβ))] rintro ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩ exacts [@Htα (_, _) ⟨b, hab, hbc⟩, @Htβ (_, _) ⟨b, hab, hbc⟩] nhds_eq_comap_uniformity x := by ext cases x <;> simp [mem_comap', -mem_comap, nhds_inl, nhds_inr, nhds_eq_comap_uniformity, Prod.ext_iff] /-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage of the diagonal. -/ theorem union_mem_uniformity_sum {a : Set (α × α)} (ha : a ∈ 𝓤 α) {b : Set (β × β)} (hb : b ∈ 𝓤 β) : Prod.map inl inl '' a ∪ Prod.map inr inr '' b ∈ 𝓤 (α ⊕ β) := union_mem_sup (image_mem_map ha) (image_mem_map hb) theorem Sum.uniformity : 𝓤 (α ⊕ β) = map (Prod.map inl inl) (𝓤 α) ⊔ map (Prod.map inr inr) (𝓤 β) := rfl lemma uniformContinuous_inl : UniformContinuous (Sum.inl : α → α ⊕ β) := le_sup_left lemma uniformContinuous_inr : UniformContinuous (Sum.inr : β → α ⊕ β) := le_sup_right instance [IsCountablyGenerated (𝓤 α)] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α ⊕ β)) := by rw [Sum.uniformity] infer_instance end Sum end Constructions /-! ### Expressing continuity properties in uniform spaces We reformulate the various continuity properties of functions taking values in a uniform space in terms of the uniformity in the target. Since the same lemmas (essentially with the same names) also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or the edistance in the target), we put them in a namespace `Uniform` here. In the metric and emetric space setting, there are also similar lemmas where one assumes that both the source and the target are metric spaces, reformulating things in terms of the distance on both sides. These lemmas are generally written without primes, and the versions where only the target is a metric space is primed. We follow the same convention here, thus giving lemmas with primes. -/ namespace Uniform variable [UniformSpace α] theorem tendsto_nhds_right {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (a, u x)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity, tendsto_comap_iff]; rfl theorem tendsto_nhds_left {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (u x, a)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity', tendsto_comap_iff]; rfl theorem continuousAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_right] theorem continuousAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_left] theorem continuousAt_iff_prod [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x : β × β => (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) := ⟨fun H => le_trans (H.prodMap' H) (nhds_le_uniformity _), fun H => continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prodMk_nhds tendsto_const_nhds⟩ theorem continuousWithinAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_right] theorem continuousWithinAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_left] theorem continuousOn_iff'_right [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_right] theorem continuousOn_iff'_left [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_left] theorem continuous_iff'_right [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_right theorem continuous_iff'_left [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_left /-- Consider two functions `f` and `g` which coincide on a set `s` and are continuous there. Then there is an open neighborhood of `s` on which `f` and `g` are uniformly close. -/ lemma exists_is_open_mem_uniformity_of_forall_mem_eq [TopologicalSpace β] {r : Set (α × α)} {s : Set β} {f g : β → α} (hf : ∀ x ∈ s, ContinuousAt f x) (hg : ∀ x ∈ s, ContinuousAt g x) (hfg : s.EqOn f g) (hr : r ∈ 𝓤 α) : ∃ t, IsOpen t ∧ s ⊆ t ∧ ∀ x ∈ t, (f x, g x) ∈ r := by have A : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ∀ z ∈ t, (f z, g z) ∈ r := by intro x hx obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr have A : {z | (f x, f z) ∈ t} ∈ 𝓝 x := (hf x hx).preimage_mem_nhds (mem_nhds_left (f x) ht) have B : {z | (g x, g z) ∈ t} ∈ 𝓝 x := (hg x hx).preimage_mem_nhds (mem_nhds_left (g x) ht) rcases _root_.mem_nhds_iff.1 (inter_mem A B) with ⟨u, hu, u_open, xu⟩ refine ⟨u, u_open, xu, fun y hy ↦ ?_⟩ have I1 : (f y, f x) ∈ t := (htsymm.mk_mem_comm).2 (hu hy).1 have I2 : (g x, g y) ∈ t := (hu hy).2 rw [hfg hx] at I1 exact htr (prodMk_mem_compRel I1 I2) choose! t t_open xt ht using A refine ⟨⋃ x ∈ s, t x, isOpen_biUnion t_open, fun x hx ↦ mem_biUnion hx (xt x hx), ?_⟩ rintro x hx simp only [mem_iUnion, exists_prop] at hx rcases hx with ⟨y, ys, hy⟩ exact ht y ys x hy end Uniform theorem Filter.Tendsto.congr_uniformity {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β} (hf : Tendsto f l (𝓝 b)) (hg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto g l (𝓝 b) := Uniform.tendsto_nhds_right.2 <| (Uniform.tendsto_nhds_right.1 hf).uniformity_trans hg theorem Uniform.tendsto_congr {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β} (hfg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto f l (𝓝 b) ↔ Tendsto g l (𝓝 b) := ⟨fun h => h.congr_uniformity hfg, fun h => h.congr_uniformity hfg.uniformity_symm⟩
Contract.lean
/- Copyright (c) 2025 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Minor.Delete import Mathlib.Tactic.TautoSet /-! # Matroid Contraction Instead of deleting the the elements of `X : Set α` from `M : Matroid α`, we can contract them. The *contraction* of `X` from `M`, denoted `M / X`, is the matroid on ground set `M.E \ X` in which a set `I` is independent if and only if `I ∪ J` is independent in `M`, where `J` is an arbitrarily chosen basis for `X`. Contraction corresponds to contracting edges in graphic matroids (hence the name) and corresponds to projecting to a quotient space in the case of linearly representable matroids. It is an important notion in both these settings. We can also define contraction much more tersely in terms of deletion and duality with `M / X = (M✶ \ X)✶`: that is, contraction is the dual operation of deletion. While this is perhaps less intuitive, we use this very concise expression as the definition, and prove with the lemma `Matroid.IsBasis.contract_indep_iff` that this is equivalent to the more verbose definition above. # Main Declarations * `Matroid.contract M C`, written `M / C`, is the matroid on ground set `M.E \ C` in which a set `I ⊆ M.E \ C` is independent if and only if `I ∪ J` is independent in `M`, where `J` is an arbitrary basis for `C`. * `Matroid.contract_dual M C : (M / X)✶ = M✶ \ X`; the dual of contraction is deletion. * `Matroid.delete_dual M C : (M \ X)✶ = M✶ / X`; the dual of deletion is contraction. * `Matroid.IsBasis.contract_indep_iff`; if `I` is a basis for `C`, then the independent sets of `M / C` are exactly the `J ⊆ M.E \ C` for which `I ∪ J` is independent in `M`. * `Matroid.contract_delete_comm` : `M / C \ D = M \ D / C` for disjoint `C` and `D`. # Naming conventions Mirroring the convention for deletion, we use the abbreviation `contractElem` in lemma names to refer to the contraction `M / {e}` of a single element `e : α` from `M : Matroid α`. -/ open Set variable {α : Type*} {M M' N : Matroid α} {e f : α} {I J R D B X Y Z K : Set α} namespace Matroid section Contract variable {C C₁ C₂ : Set α} /-- The contraction `M / C` is the matroid on `M.E \ C` in which a set `I ⊆ M.E \ C` is independent if and only if `I ∪ J` is independent, where `J` is an arbitrarily chosen basis for `C`. It is also equal by definition to `(M✶ \ C)✶`; see `Matroid.IsBasis.contract_indep_iff` for a proof that its independent sets are the claimed ones. -/ def contract (M : Matroid α) (C : Set α) : Matroid α := (M✶ \ C)✶ /-- `M / C` refers to the contraction of a set `C` from the matroid `M`. -/ scoped infixl:75 " / " => Matroid.contract @[simp] lemma contract_ground (M : Matroid α) (C : Set α) : (M / C).E = M.E \ C := rfl lemma dual_delete_dual (M : Matroid α) (X : Set α) : (M✶ \ X)✶ = M / X := rfl @[simp] lemma dual_delete (M : Matroid α) (X : Set α) : (M \ X)✶ = M✶ / X := by rw [← dual_dual M, dual_delete_dual, dual_dual] @[simp] lemma dual_contract (M : Matroid α) (X : Set α) : (M / X)✶ = M✶ \ X := by rw [← dual_delete_dual, dual_dual] lemma dual_contract_dual (M : Matroid α) (X : Set α) : (M✶ / X)✶ = M \ X := by simp @[simp] lemma contract_contract (M : Matroid α) (C₁ C₂ : Set α) : M / C₁ / C₂ = M / (C₁ ∪ C₂) := by simp [← dual_inj] lemma contract_comm (M : Matroid α) (C₁ C₂ : Set α) : M / C₁ / C₂ = M / C₂ / C₁ := by simp [union_comm] lemma dual_contract_delete (M : Matroid α) (X Y : Set α) : (M / X \ Y)✶ = M✶ \ X / Y := by simp lemma dual_delete_contract (M : Matroid α) (X Y : Set α) : (M \ X / Y)✶ = M✶ / X \ Y := by simp lemma contract_eq_self_iff : M / C = M ↔ Disjoint C M.E := by rw [← dual_delete_dual, ← dual_inj, dual_dual, delete_eq_self_iff, dual_ground] lemma contractElem_eq_self (he : e ∉ M.E) : M / {e} = M := by rw [← dual_delete_dual, deleteElem_eq_self (by simpa), dual_dual] @[simp] lemma contract_empty (M : Matroid α) : M / ∅ = M := by rw [← dual_delete_dual, delete_empty, dual_dual] lemma contract_contract_eq_contract_diff (M : Matroid α) (C₁ C₂ : Set α) : M / C₁ / C₂ = M / C₁ / (C₂ \ C₁) := by simp lemma contract_eq_contract_iff : M / C₁ = M / C₂ ↔ C₁ ∩ M.E = C₂ ∩ M.E := by rw [← dual_delete_dual, ← dual_delete_dual, dual_inj, delete_eq_delete_iff, dual_ground] @[simp] lemma contract_inter_ground_eq (M : Matroid α) (C : Set α) : M / (C ∩ M.E) = M / C := by rw [← dual_delete_dual, ← dual_ground, delete_inter_ground_eq, dual_delete_dual] @[aesop unsafe 10% (rule_sets := [Matroid])] lemma contract_ground_subset_ground (M : Matroid α) (C : Set α) : (M / C).E ⊆ M.E := (M.contract_ground C).trans_subset diff_subset /-! ### Independence and Coindependence -/ lemma coindep_contract_iff : (M / C).Coindep X ↔ M.Coindep X ∧ Disjoint X C := by rw [coindep_def, dual_contract, delete_indep_iff, ← coindep_def] lemma Coindep.coindep_contract_of_disjoint (hX : M.Coindep X) (hXC : Disjoint X C) : (M / C).Coindep X := coindep_contract_iff.2 ⟨hX, hXC⟩ @[simp] lemma contract_isCocircuit_iff : (M / C).IsCocircuit K ↔ M.IsCocircuit K ∧ Disjoint K C := by rw [isCocircuit_def, dual_contract, delete_isCircuit_iff] lemma Indep.contract_isBase_iff (hI : M.Indep I) : (M / I).IsBase B ↔ M.IsBase (B ∪ I) ∧ Disjoint B I := by rw [← dual_delete_dual, dual_isBase_iff', delete_ground, dual_ground, delete_isBase_iff, subset_diff, ← and_assoc, and_congr_left_iff, ← dual_dual M, dual_isBase_iff', dual_dual, dual_dual, union_comm, dual_ground, union_subset_iff, and_iff_right hI.subset_ground, and_congr_left_iff, ← isBase_restrict_iff, diff_diff, Spanning.isBase_restrict_iff, and_iff_left (diff_subset_diff_right subset_union_left)] · simp rwa [← dual_ground, ← coindep_iff_compl_spanning, dual_coindep_iff] lemma Indep.contract_indep_iff (hI : M.Indep I) : (M / I).Indep J ↔ Disjoint J I ∧ M.Indep (J ∪ I) := by simp_rw [indep_iff, hI.contract_isBase_iff, union_subset_iff] exact ⟨fun ⟨B, ⟨hBI, hdj⟩, hJB⟩ ↦ ⟨disjoint_of_subset_left hJB hdj, _, hBI, hJB.trans subset_union_left, subset_union_right⟩, fun ⟨hdj, B, hB, hJB, hIB⟩ ↦ ⟨B \ I,⟨by simpa [union_eq_self_of_subset_right hIB], disjoint_sdiff_left⟩, subset_diff.2 ⟨hJB, hdj⟩ ⟩⟩ lemma IsNonloop.contractElem_indep_iff (he : M.IsNonloop e) : (M / {e}).Indep I ↔ e ∉ I ∧ M.Indep (insert e I) := by simp [he.indep.contract_indep_iff] lemma Indep.union_indep_iff_contract_indep (hI : M.Indep I) : M.Indep (I ∪ J) ↔ (M / I).Indep (J \ I) := by rw [hI.contract_indep_iff, and_iff_right disjoint_sdiff_left, diff_union_self, union_comm] lemma Indep.diff_indep_contract_of_subset (hJ : M.Indep J) (hIJ : I ⊆ J) : (M / I).Indep (J \ I) := by rwa [← (hJ.subset hIJ).union_indep_iff_contract_indep, union_eq_self_of_subset_left hIJ] lemma Indep.contract_dep_iff (hI : M.Indep I) : (M / I).Dep J ↔ Disjoint J I ∧ M.Dep (J ∪ I) := by rw [dep_iff, hI.contract_indep_iff, dep_iff, contract_ground, subset_diff, disjoint_comm, union_subset_iff, and_iff_left hI.subset_ground] tauto /-! ### Bases -/ /-- Contracting a set is the same as contracting a basis for the set, and deleting the rest. -/ lemma IsBasis.contract_eq_contract_delete (hI : M.IsBasis I X) : M / X = M / I \ (X \ I) := by nth_rw 1 [← diff_union_of_subset hI.subset, ← dual_inj, dual_contract_delete, dual_contract, union_comm, ← delete_delete, ext_iff_indep] refine ⟨rfl, fun J hJ ↦ ?_⟩ have hss : X \ I ⊆ (M✶ \ I).coloops := fun e he ↦ by rw [← dual_contract, dual_coloops, ← IsLoop, ← singleton_dep, hI.indep.contract_dep_iff, singleton_union, and_iff_right (by simpa using he.2), hI.indep.insert_dep_iff, hI.closure_eq_closure] exact diff_subset_diff_left (M.subset_closure X) he rw [((coloops_indep _).subset hss).contract_indep_iff, delete_indep_iff, union_indep_iff_indep_of_subset_coloops hss, and_comm] lemma Indep.union_isBasis_union_of_contract_isBasis (hI : M.Indep I) (hB : (M / I).IsBasis J X) : M.IsBasis (J ∪ I) (X ∪ I) := by simp_rw [IsBasis, hI.contract_indep_iff, contract_ground, subset_diff, maximal_subset_iff, and_imp] at hB refine hB.1.1.1.2.isBasis_of_maximal_subset (union_subset_union_left _ hB.1.1.2) fun K hK hKJ hKX ↦ ?_ rw [union_subset_iff] at hKJ rw [hB.1.2 (t := K \ I) disjoint_sdiff_left (by simpa [diff_union_of_subset hKJ.2]) (diff_subset_iff.2 (by rwa [union_comm])) (subset_diff.2 ⟨hKJ.1, hB.1.1.1.1⟩), diff_union_of_subset hKJ.2] lemma IsBasis'.contract_isBasis'_diff_diff_of_subset (hIX : M.IsBasis' I X) (hJI : J ⊆ I) : (M / J).IsBasis' (I \ J) (X \ J) := by suffices ∀ ⦃K⦄, Disjoint K J → M.Indep (K ∪ J) → K ⊆ X → I ⊆ K ∪ J → K ⊆ I by simpa +contextual [IsBasis', (hIX.indep.subset hJI).contract_indep_iff, subset_diff, maximal_subset_iff, disjoint_sdiff_left, union_eq_self_of_subset_right hJI, hIX.indep, diff_subset.trans hIX.subset, diff_subset_iff, subset_antisymm_iff, union_comm J] exact fun K hJK hKJi hKX hIJK ↦ by simp [hIX.eq_of_subset_indep hKJi hIJK (union_subset hKX (hJI.trans hIX.subset))] lemma IsBasis'.contract_isBasis'_diff_of_subset (hIX : M.IsBasis' I X) (hJI : J ⊆ I) : (M / J).IsBasis' (I \ J) X := by simpa [isBasis'_iff_isBasis_inter_ground, inter_diff_assoc, ← diff_inter_distrib_right] using (hIX.contract_isBasis'_diff_diff_of_subset hJI).isBasis_inter_ground lemma IsBasis.contract_isBasis_diff_diff_of_subset (hIX : M.IsBasis I X) (hJI : J ⊆ I) : (M / J).IsBasis (I \ J) (X \ J) := by have h := (hIX.isBasis'.contract_isBasis'_diff_of_subset hJI).isBasis_inter_ground rwa [contract_ground, ← inter_diff_assoc, inter_eq_self_of_subset_left hIX.subset_ground] at h lemma IsBasis.contract_diff_isBasis_diff (hIX : M.IsBasis I X) (hJY : M.IsBasis J Y) (hIJ : I ⊆ J) : (M / I).IsBasis (J \ I) (Y \ X) := by refine (hJY.contract_isBasis_diff_diff_of_subset hIJ).isBasis_subset ?_ ?_ · rw [subset_diff, and_iff_right (diff_subset.trans hJY.subset), hIX.eq_of_subset_indep (hJY.indep.inter_right X) (subset_inter hIJ hIX.subset) inter_subset_right, diff_self_inter] exact disjoint_sdiff_left refine diff_subset_diff_right hIX.subset lemma IsBasis'.contract_isBasis_union_union (h : M.IsBasis' (J ∪ I) (X ∪ I)) (hJI : Disjoint J I) (hXI : Disjoint X I) : (M / I).IsBasis' J X := by simpa [hJI.sdiff_eq_left, hXI.sdiff_eq_left] using h.contract_isBasis'_diff_diff_of_subset subset_union_right lemma IsBasis.contract_isBasis_union_union (h : M.IsBasis (J ∪ I) (X ∪ I)) (hJI : Disjoint J I) (hXI : Disjoint X I) : (M / I).IsBasis J X := by refine (isBasis'_iff_isBasis ?_).1 <| h.isBasis'.contract_isBasis_union_union hJI hXI rw [contract_ground, subset_diff, and_iff_left hXI] exact subset_union_left.trans h.subset_ground lemma IsBasis'.contract_eq_contract_delete (hI : M.IsBasis' I X) : M / X = M / I \ (X \ I) := by rw [← contract_inter_ground_eq, hI.isBasis_inter_ground.contract_eq_contract_delete, eq_comm, ← delete_inter_ground_eq, contract_ground, diff_eq, diff_eq, ← inter_inter_distrib_right, ← diff_eq] lemma IsBasis'.contract_indep_iff (hI : M.IsBasis' I X) : (M / X).Indep J ↔ M.Indep (J ∪ I) ∧ Disjoint X J := by rw [hI.contract_eq_contract_delete, delete_indep_iff, hI.indep.contract_indep_iff, and_comm, ← and_assoc, ← disjoint_union_right, diff_union_self, union_eq_self_of_subset_right hI.subset, and_comm, disjoint_comm] lemma IsBasis.contract_indep_iff (hI : M.IsBasis I X) : (M / X).Indep J ↔ M.Indep (J ∪ I) ∧ Disjoint X J := hI.isBasis'.contract_indep_iff lemma IsBasis'.contract_dep_iff (hI : M.IsBasis' I X) {D : Set α} : (M / X).Dep D ↔ M.Dep (D ∪ I) ∧ Disjoint X D := by rw [hI.contract_eq_contract_delete, delete_dep_iff, hI.indep.contract_dep_iff, and_comm, ← and_assoc, ← disjoint_union_right, diff_union_of_subset hI.subset, disjoint_comm, and_comm] lemma IsBasis.contract_dep_iff (hI : M.IsBasis I X) {D : Set α} : (M / X).Dep D ↔ M.Dep (D ∪ I) ∧ Disjoint X D := hI.isBasis'.contract_dep_iff lemma IsBasis.contract_indep_iff_of_disjoint (hI : M.IsBasis I X) (hdj : Disjoint X J) : (M / X).Indep J ↔ M.Indep (J ∪ I) := by rw [hI.contract_indep_iff, and_iff_left hdj] lemma IsBasis.contract_indep_diff_iff (hI : M.IsBasis I X) : (M / X).Indep (J \ X) ↔ M.Indep ((J \ X) ∪ I) := by rw [hI.contract_indep_iff, and_iff_left disjoint_sdiff_right] lemma IsBasis'.contract_indep_diff_iff (hI : M.IsBasis' I X) : (M / X).Indep (J \ X) ↔ M.Indep ((J \ X) ∪ I) := by rw [hI.contract_indep_iff, and_iff_left disjoint_sdiff_right] lemma IsBasis.contract_isBasis_of_isBasis' (h : M.IsBasis I X) (hJC : M.IsBasis' J C) (h_ind : M.Indep (I \ C ∪ J)) : (M / C).IsBasis (I \ C) (X \ C) := by have hIX := h.subset have hJCss := hJC.subset rw [hJC.contract_eq_contract_delete, delete_isBasis_iff] refine ⟨contract_isBasis_union_union (h_ind.isBasis_of_subset_of_subset_closure ?_ ?_) ?_ ?_, ?_⟩ rotate_left · rw [closure_union_congr_right hJC.closure_eq_closure, diff_union_self, closure_union_congr_left h.closure_eq_closure] exact subset_closure_of_subset' _ (by tauto_set) (union_subset (diff_subset.trans h.subset_ground) hJC.indep.subset_ground) all_goals tauto_set lemma IsBasis'.contract_isBasis' (h : M.IsBasis' I X) (hJC : M.IsBasis' J C) (h_ind : M.Indep (I \ C ∪ J)) : (M / C).IsBasis' (I \ C) (X \ C) := by rw [isBasis'_iff_isBasis_inter_ground, contract_ground, ← diff_inter_distrib_right] exact h.isBasis_inter_ground.contract_isBasis_of_isBasis' hJC h_ind lemma IsBasis.contract_isBasis (h : M.IsBasis I X) (hJC : M.IsBasis J C) (h_ind : M.Indep (I \ C ∪ J)) : (M / C).IsBasis (I \ C) (X \ C) := h.contract_isBasis_of_isBasis' hJC.isBasis' h_ind lemma IsBasis.contract_isBasis_of_disjoint (h : M.IsBasis I X) (hJC : M.IsBasis J C) (hdj : Disjoint C X) (h_ind : M.Indep (I ∪ J)) : (M / C).IsBasis I X := by have h' := h.contract_isBasis hJC rwa [(hdj.mono_right h.subset).sdiff_eq_right, hdj.sdiff_eq_right, imp_iff_right h_ind] at h' lemma IsBasis'.contract_isBasis_of_indep (h : M.IsBasis' I X) (h_ind : M.Indep (I ∪ J)) : (M / J).IsBasis' (I \ J) (X \ J) := h.contract_isBasis' (h_ind.subset subset_union_right).isBasis_self.isBasis' (by simpa) lemma IsBasis.contract_isBasis_of_indep (h : M.IsBasis I X) (h_ind : M.Indep (I ∪ J)) : (M / J).IsBasis (I \ J) (X \ J) := h.contract_isBasis (h_ind.subset subset_union_right).isBasis_self (by simpa) lemma IsBasis.contract_isBasis_of_disjoint_indep (h : M.IsBasis I X) (hdj : Disjoint J X) (h_ind : M.Indep (I ∪ J)) : (M / J).IsBasis I X := by rw [← hdj.sdiff_eq_right, ← (hdj.mono_right h.subset).sdiff_eq_right] exact h.contract_isBasis_of_indep h_ind lemma Indep.of_contract (hI : (M / C).Indep I) : M.Indep I := ((M.exists_isBasis' C).choose_spec.contract_indep_iff.1 hI).1.subset subset_union_left lemma Dep.of_contract (h : (M / C).Dep X) (hC : C ⊆ M.E := by aesop_mat) : M.Dep (C ∪ X) := by rw [Dep, and_iff_left (union_subset hC (h.subset_ground.trans diff_subset))] intro hi rw [Dep, (hi.subset subset_union_left).contract_indep_iff, union_comm, and_iff_left hi] at h exact h.1 (subset_diff.1 h.2).2 /-! ### Finiteness -/ instance contract_finite [M.Finite] : (M / C).Finite := by rw [← dual_delete_dual] infer_instance instance contract_rankFinite [RankFinite M] : RankFinite (M / C) := let ⟨B, hB⟩ := (M / C).exists_isBase ⟨B, hB, hB.indep.of_contract.finite⟩ instance contract_finitary [Finitary M] : Finitary (M / C) := by obtain ⟨J, hJ⟩ := M.exists_isBasis' C suffices (M / J).Finitary by rw [hJ.contract_eq_contract_delete] infer_instance exact ⟨fun I hI ↦ hJ.indep.contract_indep_iff.2 ⟨disjoint_left.2 fun e heI ↦ ((hI {e} (by simpa) (by simp)).subset_ground rfl).2, indep_of_forall_finite_subset_indep _ fun K hK hKfin ↦ (hJ.indep.contract_indep_iff.1 <| hI (K ∩ I) inter_subset_right (hKfin.inter_of_left _)).2.subset (by tauto_set)⟩⟩ /-! ### Loops and Coloops -/ lemma contract_eq_delete_of_subset_loops (hX : X ⊆ M.loops) : M / X = M \ X := by simp [(empty_isBasis_iff.2 hX).contract_eq_contract_delete] lemma contract_eq_delete_of_subset_coloops (hX : X ⊆ M.coloops) : M / X = M \ X := by rw [← dual_inj, dual_delete, contract_eq_delete_of_subset_loops hX, dual_contract] @[simp] lemma contract_isLoop_iff_mem_closure : (M / C).IsLoop e ↔ e ∈ M.closure C ∧ e ∉ C := by obtain ⟨I, hI⟩ := M.exists_isBasis' C rw [hI.contract_eq_contract_delete, delete_isLoop_iff, ← singleton_dep, hI.indep.contract_dep_iff, singleton_union, hI.indep.insert_dep_iff, hI.closure_eq_closure] by_cases heI : e ∈ I · simp [heI, hI.subset heI] simp [heI, and_comm] @[simp] lemma contract_loops_eq (M : Matroid α) (C : Set α) : (M / C).loops = M.closure C \ C := by simp [Set.ext_iff, ← isLoop_iff, contract_isLoop_iff_mem_closure] @[simp] lemma contract_coloops_eq (M : Matroid α) (C : Set α) : (M / C).coloops = M.coloops \ C := by rw [← dual_delete_dual, dual_coloops, delete_loops_eq, dual_loops] @[simp] lemma contract_isColoop_iff : (M / C).IsColoop e ↔ M.IsColoop e ∧ e ∉ C := by simp [isColoop_iff_mem_coloops] lemma IsNonloop.of_contract (h : (M / C).IsNonloop e) : M.IsNonloop e := by rw [← indep_singleton] at h ⊢ exact h.of_contract @[simp] lemma contract_isNonloop_iff : (M / C).IsNonloop e ↔ e ∈ M.E \ M.closure C := by rw [isNonloop_iff_mem_compl_loops, contract_ground, contract_loops_eq] refine ⟨fun ⟨he,heC⟩ ↦ ⟨he.1, fun h ↦ heC ⟨h, he.2⟩⟩, fun h ↦ ⟨⟨h.1, fun heC ↦ h.2 ?_⟩, fun h' ↦ h.2 h'.1⟩⟩ rw [← closure_inter_ground] exact (M.subset_closure (C ∩ M.E)) ⟨heC, h.1⟩ lemma IsBasis.diff_subset_loops_contract (hIX : M.IsBasis I X) : X \ I ⊆ (M / I).loops := by rw [diff_subset_iff, contract_loops_eq, union_diff_self, union_eq_self_of_subset_left (M.subset_closure I)] exact hIX.subset_closure /-! ### Closure -/ /-- Contracting the closure of a set is the same as contracting the set, and then deleting the rest of its elements. -/ lemma contract_closure_eq_contract_delete (M : Matroid α) (C : Set α) : M / M.closure C = M / C \ (M.closure C \ C) := by wlog hCE : C ⊆ M.E with aux · rw [← M.contract_inter_ground_eq C, ← closure_inter_ground, aux _ _ inter_subset_right, diff_inter, diff_eq_empty.2 (M.closure_subset_ground _), union_empty] obtain ⟨I, hI⟩ := M.exists_isBasis C rw [hI.isBasis_closure_right.contract_eq_contract_delete, hI.contract_eq_contract_delete, delete_delete, union_comm, diff_union_diff_cancel (M.subset_closure C) hI.subset] @[simp] lemma contract_closure_eq (M : Matroid α) (C X : Set α) : (M / C).closure X = M.closure (X ∪ C) \ C := by rw [← diff_union_inter (M.closure (X ∪ C) \ C) X, diff_diff, union_comm C, ← contract_loops_eq, union_comm X, ← contract_contract, contract_loops_eq, subset_antisymm_iff, union_subset_iff, and_iff_right diff_subset, ← diff_subset_iff] simp only [sdiff_sdiff_right_self, inf_eq_inter, subset_inter_iff, inter_subset_right, and_true] refine ⟨fun e ⟨he, he'⟩ ↦ ⟨mem_closure_of_mem' _ (.inr he') (mem_ground_of_mem_closure he).1, (closure_subset_ground _ _ he).2⟩, fun e ⟨⟨he, heC⟩, he'⟩ ↦ mem_closure_of_mem' _ he' ⟨M.closure_subset_ground _ he, heC⟩⟩ lemma contract_spanning_iff (hC : C ⊆ M.E := by aesop_mat) : (M / C).Spanning X ↔ M.Spanning (X ∪ C) ∧ Disjoint X C := by rw [spanning_iff, contract_closure_eq, contract_ground, spanning_iff, union_subset_iff, subset_diff, ← and_assoc, and_congr_left_iff, and_comm (a := X ⊆ _), ← and_assoc, and_congr_left_iff] refine fun hdj hX ↦ ⟨fun h ↦ ⟨?_, hC⟩, fun h ↦ by simp [h]⟩ rwa [← union_diff_cancel (M.subset_closure_of_subset' subset_union_right hC), h, union_diff_cancel] /-- A version of `Matroid.contract_spanning_iff` without the supportedness hypothesis. -/ lemma contract_spanning_iff' : (M / C).Spanning X ↔ M.Spanning (X ∪ (C ∩ M.E)) ∧ Disjoint X C := by rw [← contract_inter_ground_eq, contract_spanning_iff, and_congr_right_iff] refine fun h ↦ ⟨fun hdj ↦ ?_, Disjoint.mono_right inter_subset_left⟩ rw [← diff_union_inter C M.E, disjoint_union_right, and_iff_left hdj] exact disjoint_sdiff_right.mono_left (subset_union_left.trans h.subset_ground) lemma Spanning.contract (hX : M.Spanning X) (C : Set α) : (M / C).Spanning (X \ C) := by have hXE := hX.subset_ground rw [contract_spanning_iff', and_iff_left disjoint_sdiff_left] exact hX.superset (by tauto_set) (by tauto_set) lemma Spanning.contract_eq_loopyOn (hX : M.Spanning X) : M / X = loopyOn (M.E \ X) := by rw [eq_loopyOn_iff_loops_eq] simp [hX.closure_eq] /-! ### Circuits -/ lemma IsCircuit.contract_isCircuit (hK : M.IsCircuit K) (hC : C ⊂ K) : (M / C).IsCircuit (K \ C) := by suffices ∀ e ∈ K, e ∉ C → M.Indep (K \ {e} ∪ C) by simpa [isCircuit_iff_dep_forall_diff_singleton_indep, diff_diff_comm (s := K) (t := C), dep_iff, (hK.ssubset_indep hC).contract_indep_iff, diff_subset_diff_left hK.subset_ground, disjoint_sdiff_left, diff_union_of_subset hC.subset, hK.not_indep] exact fun e heK heC ↦ (hK.diff_singleton_indep heK).subset <| by simp [subset_diff_singleton hC.subset heC] lemma IsCircuit.contractElem_isCircuit (hC : M.IsCircuit C) (hnt : C.Nontrivial) (heC : e ∈ C) : (M / {e}).IsCircuit (C \ {e}) := hC.contract_isCircuit (ssubset_of_ne_of_subset hnt.ne_singleton.symm (by simpa)) lemma IsCircuit.contract_dep (hK : M.IsCircuit K) (hCK : Disjoint C K) : (M / C).Dep K := by obtain ⟨I, hI⟩ := M.exists_isBasis (C ∩ M.E) rw [← contract_inter_ground_eq, Dep, hI.contract_indep_iff, and_iff_left (hCK.mono_left inter_subset_left), contract_ground, subset_diff, and_iff_left (hCK.symm.mono_right inter_subset_left), and_iff_left hK.subset_ground] exact fun hi ↦ hK.dep.not_indep (hi.subset subset_union_left) lemma IsCircuit.contract_dep_of_not_subset (hK : M.IsCircuit K) {C : Set α} (hKC : ¬ K ⊆ C) : (M / C).Dep (K \ C) := by have h' := hK.contract_isCircuit (C := C ∩ K) (inter_subset_right.ssubset_of_ne (by simpa)) simp only [diff_inter_self_eq_diff] at h' have hwin := h'.contract_dep (C := C \ K) disjoint_sdiff_sdiff rwa [contract_contract, inter_union_diff] at hwin lemma IsCircuit.contract_diff_isCircuit (hC : M.IsCircuit C) (hK : K.Nonempty) (hKC : K ⊆ C) : (M / (C \ K)).IsCircuit K := by simpa [inter_eq_self_of_subset_right hKC] using hC.contract_isCircuit (C := C \ K) <| by rwa [diff_ssubset_left_iff, inter_eq_self_of_subset_right hKC] /-- If `C` is a circuit of `M / K`, then `M` has a circuit in the interval `[C, C ∪ K]`. -/ lemma IsCircuit.exists_subset_isCircuit_of_contract (hC : (M / K).IsCircuit C) : ∃ C', M.IsCircuit C' ∧ C ⊆ C' ∧ C' ⊆ C ∪ K := by wlog hKi : M.Indep K generalizing K with aux · obtain ⟨I, hI⟩ := M.exists_isBasis' K rw [hI.contract_eq_contract_delete, delete_isCircuit_iff] at hC obtain ⟨C', hC', hCC', hC'ss⟩ := aux hC.1 hI.indep exact ⟨C', hC', hCC', hC'ss.trans (union_subset_union_right _ hI.subset)⟩ obtain ⟨hCE : C ⊆ M.E, hCK : Disjoint C K⟩ := subset_diff.1 hC.subset_ground obtain ⟨C', hC'ss, hC'⟩ := (hKi.contract_dep_iff.1 hC.dep).2.exists_isCircuit_subset refine ⟨C', hC', ?_, hC'ss⟩ have hdep2 : (M / K).Dep (C' \ K) := by rw [hKi.contract_dep_iff, and_iff_right disjoint_sdiff_left] refine hC'.dep.superset (by simp) rw [← (hC.eq_of_dep_subset hdep2 (diff_subset_iff.2 (union_comm _ _ ▸ hC'ss)))] exact diff_subset lemma IsCocircuit.of_contract (hK : (M / C).IsCocircuit K) : M.IsCocircuit K := by rw [isCocircuit_def, dual_contract] at hK exact hK.of_delete lemma IsCocircuit.delete_isCocircuit {D : Set α} (hK : M.IsCocircuit K) (hD : D ⊂ K) : (M \ D).IsCocircuit (K \ D) := by rw [isCocircuit_def, dual_delete] exact hK.isCircuit.contract_isCircuit hD lemma IsCocircuit.delete_diff_isCocircuit {X : Set α} (hK : M.IsCocircuit K) (hXK : X ⊆ K) (hX : X.Nonempty) : (M \ (K \ X)).IsCocircuit X := by rw [isCocircuit_def, dual_delete] exact hK.isCircuit.contract_diff_isCircuit hX hXK /-! ### Commutativity -/ lemma contract_delete_diff (M : Matroid α) (C D : Set α) : M / C \ D = M / C \ (D \ C) := by rw [delete_eq_delete_iff, contract_ground, diff_eq, diff_eq, ← inter_inter_distrib_right, inter_assoc] lemma contract_restrict_eq_restrict_contract (M : Matroid α) (h : Disjoint C R) : (M / C) ↾ R = (M ↾ (R ∪ C)) / C := by refine ext_indep (by simp [h.sdiff_eq_right]) fun I (hI : I ⊆ R) ↦ ?_ obtain ⟨J, hJ⟩ := (M ↾ (R ∪ C)).exists_isBasis' C have hJ' : M.IsBasis' J C := by simpa [inter_eq_self_of_subset_left subset_union_right] using (isBasis'_restrict_iff.1 hJ).1 rw [restrict_indep_iff, hJ.contract_indep_iff, hJ'.contract_indep_iff, restrict_indep_iff] have hJC := hJ'.subset tauto_set lemma restrict_contract_eq_contract_restrict (M : Matroid α) (hCR : C ⊆ R) : (M ↾ R) / C = (M / C) ↾ (R \ C) := by rw [contract_restrict_eq_restrict_contract _ disjoint_sdiff_right] simp [union_eq_self_of_subset_right hCR] /-- Contraction and deletion commute for disjoint sets. -/ lemma contract_delete_comm (M : Matroid α) (hCD : Disjoint C D) : M / C \ D = M \ D / C := by wlog hCE : C ⊆ M.E generalizing C with aux · rw [← contract_inter_ground_eq, aux (hCD.mono_left inter_subset_left) inter_subset_right, contract_eq_contract_iff, inter_assoc, delete_ground, inter_eq_self_of_subset_right diff_subset] rw [delete_eq_restrict, delete_eq_restrict, contract_ground, diff_diff_comm, restrict_contract_eq_contract_restrict _ (by simpa [hCE, subset_diff])] /-- A version of `contract_delete_comm` without the disjointness hypothesis, and hence a less simple RHS. -/ lemma contract_delete_comm' (M : Matroid α) (C D : Set α) : M / C \ D = M \ (D \ C) / C := by rw [contract_delete_diff, contract_delete_comm _ disjoint_sdiff_right] lemma delete_contract_eq_diff (M : Matroid α) (D C : Set α) : M \ D / C = M \ D / (C \ D) := by rw [contract_eq_contract_iff, delete_ground, ← diff_inter_distrib_right, diff_eq, diff_eq, inter_assoc] /-- A version of `delete_contract_comm'` without the disjointness hypothesis, and hence a less simple RHS. -/ lemma delete_contract_comm' (M : Matroid α) (D C : Set α) : M \ D / C = M / (C \ D) \ D := by rw [delete_contract_eq_diff, ← contract_delete_comm _ disjoint_sdiff_left] /-- A version of `contract_delete_contract` without the disjointness hypothesis, and hence a less simple RHS. -/ lemma contract_delete_contract' (M : Matroid α) (C D C' : Set α) : M / C \ D / C' = M / (C ∪ C' \ D) \ D := by rw [delete_contract_eq_diff, ← contract_delete_comm _ disjoint_sdiff_left, contract_contract] lemma contract_delete_contract (M : Matroid α) (C D C' : Set α) (h : Disjoint C' D) : M / C \ D / C' = M / (C ∪ C') \ D := by rw [contract_delete_contract', sdiff_eq_left.mpr h] /-- A version of `contract_delete_contract_delete` without the disjointness hypothesis, and hence a less simple RHS. -/ lemma contract_delete_contract_delete' (M : Matroid α) (C D C' D' : Set α) : M / C \ D / C' \ D' = M / (C ∪ C' \ D) \ (D ∪ D') := by rw [contract_delete_contract', delete_delete] lemma contract_delete_contract_delete (M : Matroid α) (C D C' D' : Set α) (h : Disjoint C' D) : M / C \ D / C' \ D' = M / (C ∪ C') \ (D ∪ D') := by rw [contract_delete_contract_delete', sdiff_eq_left.mpr h] /-- A version of `delete_contract_delete` without the disjointness hypothesis, and hence a less simple RHS. -/ lemma delete_contract_delete' (M : Matroid α) (D C D' : Set α) : M \ D / C \ D' = M / (C \ D) \ (D ∪ D') := by rw [delete_contract_comm', delete_delete] lemma delete_contract_delete (M : Matroid α) (D C D' : Set α) (h : Disjoint C D) : M \ D / C \ D' = M / C \ (D ∪ D') := by rw [delete_contract_delete', sdiff_eq_left.mpr h] end Contract end Matroid
Set.lean
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Data.Fintype.EquivFin /-! # Lemmas about `Finite` and `Set`s In this file we prove two lemmas about `Finite` and `Set`s. ## Tags finiteness, finite sets -/ open Set universe u v w variable {α : Type u} {β : Type v} {ι : Sort w} theorem Finite.Set.finite_of_finite_image (s : Set α) {f : α → β} (h : s.InjOn f) [Finite (f '' s)] : Finite s := Finite.of_equiv _ (Equiv.ofBijective _ h.bijOn_image.bijective).symm theorem Finite.of_injective_finite_range {f : ι → α} (hf : Function.Injective f) [Finite (range f)] : Finite ι := Finite.of_injective (Set.rangeFactorization f) (hf.codRestrict _)
AEMeasurable.lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.LpSeminorm.Trim import Mathlib.MeasureTheory.Function.StronglyMeasurable.Lp /-! # Functions a.e. measurable with respect to a sub-σ-algebra A function `f` verifies `AEStronglyMeasurable[m] f μ` if it is `μ`-a.e. equal to an `m`-strongly measurable function. This is similar to `AEStronglyMeasurable`, but the `MeasurableSpace` structures used for the measurability statement and for the measure are different. We define `lpMeas F 𝕜 m p μ`, the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable[m] f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. ## Main statements We define an `IsometryEquiv` between `lpMeasSubgroup` and the `Lp` space corresponding to the measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of `lpMeas`. `Lp.induction_stronglyMeasurable` (see also `MemLp.induction_stronglyMeasurable`): To prove something for an `Lp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is closed. -/ open TopologicalSpace Filter open scoped ENNReal MeasureTheory namespace MeasureTheory theorem ae_eq_trim_iff_of_aestronglyMeasurable {α β} [TopologicalSpace β] [MetrizableSpace β] {m m0 : MeasurableSpace α} {μ : Measure α} {f g : α → β} (hm : m ≤ m0) (hfm : AEStronglyMeasurable[m] f μ) (hgm : AEStronglyMeasurable[m] g μ) : hfm.mk f =ᵐ[μ.trim hm] hgm.mk g ↔ f =ᵐ[μ] g := (hfm.stronglyMeasurable_mk.ae_eq_trim_iff hm hgm.stronglyMeasurable_mk).trans ⟨fun h => hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm), fun h => hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)⟩ @[deprecated (since := "2025-04-09")] alias ae_eq_trim_iff_of_aeStronglyMeasurable' := ae_eq_trim_iff_of_aestronglyMeasurable theorem AEStronglyMeasurable.comp_ae_measurable' {α β γ : Type*} [TopologicalSpace β] {mα : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → β} {μ : Measure γ} {g : γ → α} (hf : AEStronglyMeasurable f (μ.map g)) (hg : AEMeasurable g μ) : AEStronglyMeasurable[mα.comap g] (f ∘ g) μ := ⟨hf.mk f ∘ g, hf.stronglyMeasurable_mk.comp_measurable (measurable_iff_comap_le.mpr le_rfl), ae_eq_comp hg hf.ae_eq_mk⟩ variable {α F 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] section LpMeas /-! ## The subset `lpMeas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/ variable (F) /-- `lpMeasSubgroup F m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable[m] f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. -/ def lpMeasSubgroup (m : MeasurableSpace α) [MeasurableSpace α] (p : ℝ≥0∞) (μ : Measure α) : AddSubgroup (Lp F p μ) where carrier := {f : Lp F p μ | AEStronglyMeasurable[m] f μ} zero_mem' := ⟨(0 : α → F), @stronglyMeasurable_zero _ _ m _ _, Lp.coeFn_zero _ _ _⟩ add_mem' {f g} hf hg := (hf.add hg).congr (Lp.coeFn_add f g).symm neg_mem' {f} hf := AEStronglyMeasurable.congr hf.neg (Lp.coeFn_neg f).symm variable (𝕜) /-- `lpMeas F 𝕜 m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable[m] f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. -/ def lpMeas (m : MeasurableSpace α) [MeasurableSpace α] (p : ℝ≥0∞) (μ : Measure α) : Submodule 𝕜 (Lp F p μ) where carrier := {f : Lp F p μ | AEStronglyMeasurable[m] f μ} zero_mem' := ⟨(0 : α → F), @stronglyMeasurable_zero _ _ m _ _, Lp.coeFn_zero _ _ _⟩ add_mem' {f g} hf hg := (hf.add hg).congr (Lp.coeFn_add f g).symm smul_mem' c f hf := (hf.const_smul c).congr (Lp.coeFn_smul c f).symm variable {F 𝕜} theorem mem_lpMeasSubgroup_iff_aestronglyMeasurable {m m0 : MeasurableSpace α} {μ : Measure α} {f : Lp F p μ} : f ∈ lpMeasSubgroup F m p μ ↔ AEStronglyMeasurable[m] f μ := by rw [← AddSubgroup.mem_carrier, lpMeasSubgroup, Set.mem_setOf_eq] @[deprecated (since := "2025-04-09")] alias mem_lpMeasSubgroup_iff_aeStronglyMeasurable := mem_lpMeasSubgroup_iff_aestronglyMeasurable theorem mem_lpMeas_iff_aestronglyMeasurable {m m0 : MeasurableSpace α} {μ : Measure α} {f : Lp F p μ} : f ∈ lpMeas F 𝕜 m p μ ↔ AEStronglyMeasurable[m] f μ := by rw [← SetLike.mem_coe, ← Submodule.mem_carrier, lpMeas, Set.mem_setOf_eq] @[deprecated (since := "2025-04-09")] alias mem_lpMeas_iff_aeStronglyMeasurable := mem_lpMeas_iff_aestronglyMeasurable theorem lpMeas.aestronglyMeasurable {m _ : MeasurableSpace α} {μ : Measure α} (f : lpMeas F 𝕜 m p μ) : AEStronglyMeasurable[m] (f : α → F) μ := mem_lpMeas_iff_aestronglyMeasurable.mp f.mem @[deprecated (since := "2025-04-09")] alias lpMeas.aeStronglyMeasurable := lpMeas.aestronglyMeasurable theorem mem_lpMeas_self {m0 : MeasurableSpace α} (μ : Measure α) (f : Lp F p μ) : f ∈ lpMeas F 𝕜 m0 p μ := mem_lpMeas_iff_aestronglyMeasurable.mpr (Lp.aestronglyMeasurable f) theorem mem_lpMeas_indicatorConstLp {m m0 : MeasurableSpace α} (hm : m ≤ m0) {μ : Measure α} {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {c : F} : indicatorConstLp p (hm s hs) hμs c ∈ lpMeas F 𝕜 m p μ := ⟨s.indicator fun _ : α => c, (@stronglyMeasurable_const _ _ m _ _).indicator hs, indicatorConstLp_coeFn⟩ section CompleteSubspace /-! ## The subspace `lpMeas` is complete. We define an `IsometryEquiv` between `lpMeasSubgroup` and the `Lp` space corresponding to the measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of `lpMeasSubgroup` (and `lpMeas`). -/ variable {m m0 : MeasurableSpace α} {μ : Measure α} /-- If `f` belongs to `lpMeasSubgroup F m p μ`, then the measurable function it is almost everywhere equal to (given by `AEMeasurable.mk`) belongs to `ℒp` for the measure `μ.trim hm`. -/ theorem memLp_trim_of_mem_lpMeasSubgroup (hm : m ≤ m0) (f : Lp F p μ) (hf_meas : f ∈ lpMeasSubgroup F m p μ) : MemLp (mem_lpMeasSubgroup_iff_aestronglyMeasurable.mp hf_meas).choose p (μ.trim hm) := by have hf : AEStronglyMeasurable[m] f μ := mem_lpMeasSubgroup_iff_aestronglyMeasurable.mp hf_meas let g := hf.choose obtain ⟨hg, hfg⟩ := hf.choose_spec change MemLp g p (μ.trim hm) refine ⟨hg.aestronglyMeasurable, ?_⟩ have h_eLpNorm_fg : eLpNorm g p (μ.trim hm) = eLpNorm f p μ := by rw [eLpNorm_trim hm hg] exact eLpNorm_congr_ae hfg.symm rw [h_eLpNorm_fg] exact Lp.eLpNorm_lt_top f @[deprecated (since := "2025-02-21")] alias memℒp_trim_of_mem_lpMeasSubgroup := memLp_trim_of_mem_lpMeasSubgroup /-- If `f` belongs to `Lp` for the measure `μ.trim hm`, then it belongs to the subgroup `lpMeasSubgroup F m p μ`. -/ theorem mem_lpMeasSubgroup_toLp_of_trim (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : (memLp_of_memLp_trim hm (Lp.memLp f)).toLp f ∈ lpMeasSubgroup F m p μ := by let hf_mem_ℒp := memLp_of_memLp_trim hm (Lp.memLp f) rw [mem_lpMeasSubgroup_iff_aestronglyMeasurable] refine AEStronglyMeasurable.congr ?_ (MemLp.coeFn_toLp hf_mem_ℒp).symm exact (Lp.aestronglyMeasurable f).of_trim hm variable (F p μ) /-- Map from `lpMeasSubgroup` to `Lp F p (μ.trim hm)`. -/ noncomputable def lpMeasSubgroupToLpTrim (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : Lp F p (μ.trim hm) := MemLp.toLp (mem_lpMeasSubgroup_iff_aestronglyMeasurable.mp f.mem).choose (memLp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem) variable (𝕜) in /-- Map from `lpMeas` to `Lp F p (μ.trim hm)`. -/ noncomputable def lpMeasToLpTrim (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) : Lp F p (μ.trim hm) := MemLp.toLp (mem_lpMeas_iff_aestronglyMeasurable.mp f.mem).choose (memLp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem) /-- Map from `Lp F p (μ.trim hm)` to `lpMeasSubgroup`, inverse of `lpMeasSubgroupToLpTrim`. -/ noncomputable def lpTrimToLpMeasSubgroup (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpMeasSubgroup F m p μ := ⟨(memLp_of_memLp_trim hm (Lp.memLp f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f⟩ variable (𝕜) in /-- Map from `Lp F p (μ.trim hm)` to `lpMeas`, inverse of `Lp_meas_to_Lp_trim`. -/ noncomputable def lpTrimToLpMeas (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpMeas F 𝕜 m p μ := ⟨(memLp_of_memLp_trim hm (Lp.memLp f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f⟩ variable {F p μ} theorem lpMeasSubgroupToLpTrim_ae_eq (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm f =ᵐ[μ] f := (ae_eq_of_ae_eq_trim (MemLp.coeFn_toLp (memLp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem))).trans (mem_lpMeasSubgroup_iff_aestronglyMeasurable.mp f.mem).choose_spec.2.symm theorem lpTrimToLpMeasSubgroup_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpTrimToLpMeasSubgroup F p μ hm f =ᵐ[μ] f := MemLp.coeFn_toLp (memLp_of_memLp_trim hm (Lp.memLp f)) theorem lpMeasToLpTrim_ae_eq (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) : lpMeasToLpTrim F 𝕜 p μ hm f =ᵐ[μ] f := (ae_eq_of_ae_eq_trim (MemLp.coeFn_toLp (memLp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem))).trans (mem_lpMeasSubgroup_iff_aestronglyMeasurable.mp f.mem).choose_spec.2.symm theorem lpTrimToLpMeas_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpTrimToLpMeas F 𝕜 p μ hm f =ᵐ[μ] f := MemLp.coeFn_toLp (memLp_of_memLp_trim hm (Lp.memLp f)) /-- `lpTrimToLpMeasSubgroup` is a right inverse of `lpMeasSubgroupToLpTrim`. -/ theorem lpMeasSubgroupToLpTrim_right_inv (hm : m ≤ m0) : Function.RightInverse (lpTrimToLpMeasSubgroup F p μ hm) (lpMeasSubgroupToLpTrim F p μ hm) := by intro f ext1 refine (Lp.stronglyMeasurable _).ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _) ?_ exact (lpMeasSubgroupToLpTrim_ae_eq hm _).trans (lpTrimToLpMeasSubgroup_ae_eq hm _) /-- `lpTrimToLpMeasSubgroup` is a left inverse of `lpMeasSubgroupToLpTrim`. -/ theorem lpMeasSubgroupToLpTrim_left_inv (hm : m ≤ m0) : Function.LeftInverse (lpTrimToLpMeasSubgroup F p μ hm) (lpMeasSubgroupToLpTrim F p μ hm) := by intro f ext1 ext1 exact (lpTrimToLpMeasSubgroup_ae_eq hm _).trans (lpMeasSubgroupToLpTrim_ae_eq hm _) theorem lpMeasSubgroupToLpTrim_add (hm : m ≤ m0) (f g : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (f + g) = lpMeasSubgroupToLpTrim F p μ hm f + lpMeasSubgroupToLpTrim F p μ hm g := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine (Lp.stronglyMeasurable _).ae_eq_trim_of_stronglyMeasurable hm ?_ ?_ · exact (Lp.stronglyMeasurable _).add (Lp.stronglyMeasurable _) refine (lpMeasSubgroupToLpTrim_ae_eq hm _).trans ?_ refine EventuallyEq.trans ?_ (EventuallyEq.add (lpMeasSubgroupToLpTrim_ae_eq hm f).symm (lpMeasSubgroupToLpTrim_ae_eq hm g).symm) refine (Lp.coeFn_add _ _).trans ?_ filter_upwards with x using rfl theorem lpMeasSubgroupToLpTrim_neg (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (-f) = -lpMeasSubgroupToLpTrim F p μ hm f := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_neg _).symm refine (Lp.stronglyMeasurable _).ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _).neg <| (lpMeasSubgroupToLpTrim_ae_eq hm _).trans <| ((Lp.coeFn_neg _).trans ?_).trans (lpMeasSubgroupToLpTrim_ae_eq hm f).symm.neg exact Eventually.of_forall fun x => by rfl theorem lpMeasSubgroupToLpTrim_sub (hm : m ≤ m0) (f g : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (f - g) = lpMeasSubgroupToLpTrim F p μ hm f - lpMeasSubgroupToLpTrim F p μ hm g := by rw [sub_eq_add_neg, sub_eq_add_neg, lpMeasSubgroupToLpTrim_add, lpMeasSubgroupToLpTrim_neg] theorem lpMeasToLpTrim_smul (hm : m ≤ m0) (c : 𝕜) (f : lpMeas F 𝕜 m p μ) : lpMeasToLpTrim F 𝕜 p μ hm (c • f) = c • lpMeasToLpTrim F 𝕜 p μ hm f := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm refine (Lp.stronglyMeasurable _).ae_eq_trim_of_stronglyMeasurable hm ?_ ?_ · exact (Lp.stronglyMeasurable _).const_smul c refine (lpMeasToLpTrim_ae_eq hm _).trans ?_ refine (Lp.coeFn_smul _ _).trans ?_ refine (lpMeasToLpTrim_ae_eq hm f).mono fun x hx => ?_ simp only [Pi.smul_apply, hx] /-- `lpMeasSubgroupToLpTrim` preserves the norm. -/ theorem lpMeasSubgroupToLpTrim_norm_map [hp : Fact (1 ≤ p)] (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : ‖lpMeasSubgroupToLpTrim F p μ hm f‖ = ‖f‖ := by rw [Lp.norm_def, eLpNorm_trim hm (Lp.stronglyMeasurable _), eLpNorm_congr_ae (lpMeasSubgroupToLpTrim_ae_eq hm _), ← Lp.norm_def] congr theorem isometry_lpMeasSubgroupToLpTrim [hp : Fact (1 ≤ p)] (hm : m ≤ m0) : Isometry (lpMeasSubgroupToLpTrim F p μ hm) := Isometry.of_dist_eq fun f g => by rw [dist_eq_norm, ← lpMeasSubgroupToLpTrim_sub, lpMeasSubgroupToLpTrim_norm_map, dist_eq_norm] variable (F p μ) /-- `lpMeasSubgroup` and `Lp F p (μ.trim hm)` are isometric. -/ noncomputable def lpMeasSubgroupToLpTrimIso [Fact (1 ≤ p)] (hm : m ≤ m0) : lpMeasSubgroup F m p μ ≃ᵢ Lp F p (μ.trim hm) where toFun := lpMeasSubgroupToLpTrim F p μ hm invFun := lpTrimToLpMeasSubgroup F p μ hm left_inv := lpMeasSubgroupToLpTrim_left_inv hm right_inv := lpMeasSubgroupToLpTrim_right_inv hm isometry_toFun := isometry_lpMeasSubgroupToLpTrim hm variable (𝕜) /-- `lpMeasSubgroup` and `lpMeas` are isometric. -/ noncomputable def lpMeasSubgroupToLpMeasIso [Fact (1 ≤ p)] : lpMeasSubgroup F m p μ ≃ᵢ lpMeas F 𝕜 m p μ := IsometryEquiv.refl (lpMeasSubgroup F m p μ) /-- `lpMeas` and `Lp F p (μ.trim hm)` are isometric, with a linear equivalence. -/ noncomputable def lpMeasToLpTrimLie [Fact (1 ≤ p)] (hm : m ≤ m0) : lpMeas F 𝕜 m p μ ≃ₗᵢ[𝕜] Lp F p (μ.trim hm) where toFun := lpMeasToLpTrim F 𝕜 p μ hm invFun := lpTrimToLpMeas F 𝕜 p μ hm left_inv := lpMeasSubgroupToLpTrim_left_inv hm right_inv := lpMeasSubgroupToLpTrim_right_inv hm map_add' := lpMeasSubgroupToLpTrim_add hm map_smul' := lpMeasToLpTrim_smul hm norm_map' := lpMeasSubgroupToLpTrim_norm_map hm variable {F 𝕜 p μ} instance [hm : Fact (m ≤ m0)] [CompleteSpace F] [hp : Fact (1 ≤ p)] : CompleteSpace (lpMeasSubgroup F m p μ) := by rw [(lpMeasSubgroupToLpTrimIso F p μ hm.elim).completeSpace_iff]; infer_instance -- For now just no-lint this; lean4's tree-based logging will make this easier to debug. -- One possible change might be to generalize `𝕜` from `RCLike` to `NormedField`, as this -- result may well hold there. -- Porting note: removed @[nolint fails_quickly] instance [hm : Fact (m ≤ m0)] [CompleteSpace F] [hp : Fact (1 ≤ p)] : CompleteSpace (lpMeas F 𝕜 m p μ) := by rw [(lpMeasSubgroupToLpMeasIso F 𝕜 p μ).symm.completeSpace_iff]; infer_instance theorem isComplete_aestronglyMeasurable [hp : Fact (1 ≤ p)] [CompleteSpace F] (hm : m ≤ m0) : IsComplete {f : Lp F p μ | AEStronglyMeasurable[m] f μ} := by rw [← completeSpace_coe_iff_isComplete] haveI : Fact (m ≤ m0) := ⟨hm⟩ change CompleteSpace (lpMeasSubgroup F m p μ) infer_instance @[deprecated (since := "2025-04-09")] alias isComplete_aeStronglyMeasurable' := isComplete_aestronglyMeasurable theorem isClosed_aestronglyMeasurable [Fact (1 ≤ p)] [CompleteSpace F] (hm : m ≤ m0) : IsClosed {f : Lp F p μ | AEStronglyMeasurable[m] f μ} := IsComplete.isClosed (isComplete_aestronglyMeasurable hm) @[deprecated (since := "2025-04-09")] alias isClosed_aeStronglyMeasurable' := isClosed_aestronglyMeasurable end CompleteSubspace section StronglyMeasurable variable {m m0 : MeasurableSpace α} {μ : Measure α} /-- We do not get `ae_fin_strongly_measurable f (μ.trim hm)`, since we don't have `f =ᵐ[μ.trim hm] Lp_meas_to_Lp_trim F 𝕜 p μ hm f` but only the weaker `f =ᵐ[μ] Lp_meas_to_Lp_trim F 𝕜 p μ hm f`. -/ theorem lpMeas.ae_fin_strongly_measurable' (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : ∃ g, FinStronglyMeasurable g (μ.trim hm) ∧ f.1 =ᵐ[μ] g := ⟨lpMeasSubgroupToLpTrim F p μ hm f, Lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top, (lpMeasSubgroupToLpTrim_ae_eq hm f).symm⟩ /-- When applying the inverse of `lpMeasToLpTrimLie` (which takes a function in the Lp space of the sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the sub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/ theorem lpMeasToLpTrimLie_symm_indicator [one_le_p : Fact (1 ≤ p)] [NormedSpace ℝ F] {hm : m ≤ m0} {s : Set α} {μ : Measure α} (hs : MeasurableSet[m] s) (hμs : μ.trim hm s ≠ ∞) (c : F) : ((lpMeasToLpTrimLie F ℝ p μ hm).symm (indicatorConstLp p hs hμs c) : Lp F p μ) = indicatorConstLp p (hm s hs) ((le_trim hm).trans_lt hμs.lt_top).ne c := by ext1 change lpTrimToLpMeas F ℝ p μ hm (indicatorConstLp p hs hμs c) =ᵐ[μ] (indicatorConstLp p _ _ c : α → F) refine (lpTrimToLpMeas_ae_eq hm _).trans ?_ exact (ae_eq_of_ae_eq_trim indicatorConstLp_coeFn).trans indicatorConstLp_coeFn.symm theorem lpMeasToLpTrimLie_symm_toLp [one_le_p : Fact (1 ≤ p)] [NormedSpace ℝ F] (hm : m ≤ m0) (f : α → F) (hf : MemLp f p (μ.trim hm)) : ((lpMeasToLpTrimLie F ℝ p μ hm).symm (hf.toLp f) : Lp F p μ) = (memLp_of_memLp_trim hm hf).toLp f := by ext1 refine (lpTrimToLpMeas_ae_eq hm _).trans ?_ exact (ae_eq_of_ae_eq_trim (MemLp.coeFn_toLp hf)).trans (MemLp.coeFn_toLp _).symm end StronglyMeasurable end LpMeas section Induction variable {m m0 : MeasurableSpace α} {μ : Measure α} [Fact (1 ≤ p)] [NormedSpace ℝ F] /-- Auxiliary lemma for `Lp.induction_stronglyMeasurable`. -/ @[elab_as_elim] theorem Lp.induction_stronglyMeasurable_aux (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop) (h_ind : ∀ (c : F) {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s < ∞), P (Lp.simpleFunc.indicatorConst p (hm s hs) hμs.ne c)) (h_add : ∀ ⦃f g⦄, ∀ hf : MemLp f p μ, ∀ hg : MemLp g p μ, AEStronglyMeasurable[m] f μ → AEStronglyMeasurable[m] g μ → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) : ∀ f : Lp F p μ, AEStronglyMeasurable[m] f μ → P f := by intro f hf let f' := (⟨f, hf⟩ : lpMeas F ℝ m p μ) let g := lpMeasToLpTrimLie F ℝ p μ hm f' have hfg : f' = (lpMeasToLpTrimLie F ℝ p μ hm).symm g := by simp only [f', g, LinearIsometryEquiv.symm_apply_apply] change P ↑f' rw [hfg] refine @Lp.induction α F m _ p (μ.trim hm) _ hp_ne_top (fun g => P ((lpMeasToLpTrimLie F ℝ p μ hm).symm g)) ?_ ?_ ?_ g · intro b t ht hμt rw [@Lp.simpleFunc.coe_indicatorConst _ _ m, lpMeasToLpTrimLie_symm_indicator ht hμt.ne b] have hμt' : μ t < ∞ := (le_trim hm).trans_lt hμt specialize h_ind b ht hμt' rwa [Lp.simpleFunc.coe_indicatorConst] at h_ind · intro f g hf hg h_disj hfP hgP rw [LinearIsometryEquiv.map_add] push_cast have h_eq : ∀ (f : α → F) (hf : MemLp f p (μ.trim hm)), ((lpMeasToLpTrimLie F ℝ p μ hm).symm (MemLp.toLp f hf) : Lp F p μ) = (memLp_of_memLp_trim hm hf).toLp f := lpMeasToLpTrimLie_symm_toLp hm rw [h_eq f hf] at hfP ⊢ rw [h_eq g hg] at hgP ⊢ exact h_add (memLp_of_memLp_trim hm hf) (memLp_of_memLp_trim hm hg) (hf.aestronglyMeasurable.of_trim hm) (hg.aestronglyMeasurable.of_trim hm) h_disj hfP hgP · change IsClosed ((lpMeasToLpTrimLie F ℝ p μ hm).symm ⁻¹' {g : lpMeas F ℝ m p μ | P ↑g}) exact IsClosed.preimage (LinearIsometryEquiv.continuous _) h_closed /-- To prove something for an `Lp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is closed. -/ @[elab_as_elim] theorem Lp.induction_stronglyMeasurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop) (h_ind : ∀ (c : F) {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s < ∞), P (Lp.simpleFunc.indicatorConst p (hm s hs) hμs.ne c)) (h_add : ∀ ⦃f g⦄, ∀ hf : MemLp f p μ, ∀ hg : MemLp g p μ, StronglyMeasurable[m] f → StronglyMeasurable[m] g → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) : ∀ f : Lp F p μ, AEStronglyMeasurable[m] f μ → P f := by intro f hf suffices h_add_ae : ∀ ⦃f g⦄, ∀ hf : MemLp f p μ, ∀ hg : MemLp g p μ, AEStronglyMeasurable[m] f μ → AEStronglyMeasurable[m] g μ → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g) from Lp.induction_stronglyMeasurable_aux hm hp_ne_top _ h_ind h_add_ae h_closed f hf intro f g hf hg hfm hgm h_disj hPf hPg let s_f : Set α := Function.support (hfm.mk f) have hs_f : MeasurableSet[m] s_f := hfm.stronglyMeasurable_mk.measurableSet_support have hs_f_eq : s_f =ᵐ[μ] Function.support f := hfm.ae_eq_mk.symm.support let s_g : Set α := Function.support (hgm.mk g) have hs_g : MeasurableSet[m] s_g := hgm.stronglyMeasurable_mk.measurableSet_support have hs_g_eq : s_g =ᵐ[μ] Function.support g := hgm.ae_eq_mk.symm.support have h_inter_empty : (s_f ∩ s_g : Set α) =ᵐ[μ] (∅ : Set α) := by refine (hs_f_eq.inter hs_g_eq).trans ?_ suffices Function.support f ∩ Function.support g = ∅ by rw [this] exact Set.disjoint_iff_inter_eq_empty.mp h_disj let f' := (s_f \ s_g).indicator (hfm.mk f) have hff' : f =ᵐ[μ] f' := by have : s_f \ s_g =ᵐ[μ] s_f := by rw [← Set.diff_inter_self_eq_diff, Set.inter_comm] refine ((ae_eq_refl s_f).diff h_inter_empty).trans ?_ rw [Set.diff_empty] refine ((indicator_ae_eq_of_ae_eq_set this).trans ?_).symm rw [Set.indicator_support] exact hfm.ae_eq_mk.symm have hf'_meas : StronglyMeasurable[m] f' := hfm.stronglyMeasurable_mk.indicator (hs_f.diff hs_g) have hf'_Lp : MemLp f' p μ := hf.ae_eq hff' let g' := (s_g \ s_f).indicator (hgm.mk g) have hgg' : g =ᵐ[μ] g' := by have : s_g \ s_f =ᵐ[μ] s_g := by rw [← Set.diff_inter_self_eq_diff] refine ((ae_eq_refl s_g).diff h_inter_empty).trans ?_ rw [Set.diff_empty] refine ((indicator_ae_eq_of_ae_eq_set this).trans ?_).symm rw [Set.indicator_support] exact hgm.ae_eq_mk.symm have hg'_meas : StronglyMeasurable[m] g' := hgm.stronglyMeasurable_mk.indicator (hs_g.diff hs_f) have hg'_Lp : MemLp g' p μ := hg.ae_eq hgg' have h_disj : Disjoint (Function.support f') (Function.support g') := haveI : Disjoint (s_f \ s_g) (s_g \ s_f) := disjoint_sdiff_sdiff this.mono Set.support_indicator_subset Set.support_indicator_subset rw [← MemLp.toLp_congr hf'_Lp hf hff'.symm] at hPf ⊢ rw [← MemLp.toLp_congr hg'_Lp hg hgg'.symm] at hPg ⊢ exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg /-- To prove something for an arbitrary `MemLp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in the `Lᵖ` space strongly measurable w.r.t. `m` for which the property holds is closed. * the property is closed under the almost-everywhere equal relation. -/ @[elab_as_elim] theorem MemLp.induction_stronglyMeasurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : (α → F) → Prop) (h_ind : ∀ (c : F) ⦃s⦄, MeasurableSet[m] s → μ s < ∞ → P (s.indicator fun _ => c)) (h_add : ∀ ⦃f g : α → F⦄, Disjoint (Function.support f) (Function.support g) → MemLp f p μ → MemLp g p μ → StronglyMeasurable[m] f → StronglyMeasurable[m] g → P f → P g → P (f + g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) (h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → MemLp f p μ → P f → P g) : ∀ ⦃f : α → F⦄, MemLp f p μ → AEStronglyMeasurable[m] f μ → P f := by intro f hf hfm let f_Lp := hf.toLp f have hfm_Lp : AEStronglyMeasurable[m] f_Lp μ := hfm.congr hf.coeFn_toLp.symm refine h_ae hf.coeFn_toLp (Lp.memLp _) ?_ change P f_Lp refine Lp.induction_stronglyMeasurable hm hp_ne_top (fun f => P f) ?_ ?_ h_closed f_Lp hfm_Lp · intro c s hs hμs rw [Lp.simpleFunc.coe_indicatorConst] refine h_ae indicatorConstLp_coeFn.symm ?_ (h_ind c hs hμs) exact memLp_indicator_const p (hm s hs) c (Or.inr hμs.ne) · intro f g hf_mem hg_mem hfm hgm h_disj hfP hgP have hfP' : P f := h_ae hf_mem.coeFn_toLp (Lp.memLp _) hfP have hgP' : P g := h_ae hg_mem.coeFn_toLp (Lp.memLp _) hgP specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP' refine h_ae ?_ (hf_mem.add hg_mem) h_add exact (hf_mem.coeFn_toLp.symm.add hg_mem.coeFn_toLp.symm).trans (Lp.coeFn_add _ _).symm @[deprecated (since := "2025-02-21")] alias Memℒp.induction_stronglyMeasurable := MemLp.induction_stronglyMeasurable end Induction end MeasureTheory
Module.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.DirectSum.Basic import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.Basis.Defs /-! # Direct sum of modules The first part of the file provides constructors for direct sums of modules. It provides a construction of the direct sum using the universal property and proves its uniqueness (`DirectSum.toModule.unique`). The second part of the file covers the special case of direct sums of submodules of a fixed module `M`. There is a canonical linear map from this direct sum to `M` (`DirectSum.coeLinearMap`), and the construction is of particular importance when this linear map is an equivalence; that is, when the submodules provide an internal decomposition of `M`. The property is defined more generally elsewhere as `DirectSum.IsInternal`, but its basic consequences on `Submodule`s are established in this file. -/ universe u v w u₁ namespace DirectSum open DirectSum Finsupp Module section General variable {R : Type u} [Semiring R] variable {ι : Type v} variable {M : ι → Type w} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] instance : Module R (⨁ i, M i) := DFinsupp.module instance {S : Type*} [Semiring S] [∀ i, Module S (M i)] [∀ i, SMulCommClass R S (M i)] : SMulCommClass R S (⨁ i, M i) := DFinsupp.smulCommClass instance {S : Type*} [Semiring S] [SMul R S] [∀ i, Module S (M i)] [∀ i, IsScalarTower R S (M i)] : IsScalarTower R S (⨁ i, M i) := DFinsupp.isScalarTower instance [∀ i, Module Rᵐᵒᵖ (M i)] [∀ i, IsCentralScalar R (M i)] : IsCentralScalar R (⨁ i, M i) := DFinsupp.isCentralScalar theorem smul_apply (b : R) (v : ⨁ i, M i) (i : ι) : (b • v) i = b • v i := DFinsupp.smul_apply _ _ _ variable (R) in /-- Coercion from a `DirectSum` to a pi type is a `LinearMap`. -/ def coeFnLinearMap : (⨁ i, M i) →ₗ[R] ∀ i, M i := DFinsupp.coeFnLinearMap R @[simp] lemma coeFnLinearMap_apply (v : ⨁ i, M i) : coeFnLinearMap R v = v := rfl variable (R ι M) section DecidableEq variable [DecidableEq ι] /-- Create the direct sum given a family `M` of `R` modules indexed over `ι`. -/ def lmk : ∀ s : Finset ι, (∀ i : (↑s : Set ι), M i.val) →ₗ[R] ⨁ i, M i := DFinsupp.lmk /-- Inclusion of each component into the direct sum. -/ def lof : ∀ i : ι, M i →ₗ[R] ⨁ i, M i := DFinsupp.lsingle theorem lof_eq_of (i : ι) (b : M i) : lof R ι M i b = of M i b := rfl variable {ι M} theorem single_eq_lof (i : ι) (b : M i) : DFinsupp.single i b = lof R ι M i b := rfl /-- Scalar multiplication commutes with direct sums. -/ theorem mk_smul (s : Finset ι) (c : R) (x) : mk M s (c • x) = c • mk M s x := (lmk R ι M s).map_smul c x /-- Scalar multiplication commutes with the inclusion of each component into the direct sum. -/ theorem of_smul (i : ι) (c : R) (x) : of M i (c • x) = c • of M i x := (lof R ι M i).map_smul c x variable {R} theorem support_smul [∀ (i : ι) (x : M i), Decidable (x ≠ 0)] (c : R) (v : ⨁ i, M i) : (c • v).support ⊆ v.support := DFinsupp.support_smul _ _ variable {N : Type u₁} [AddCommMonoid N] [Module R N] variable (φ : ∀ i, M i →ₗ[R] N) variable (R ι N) /-- The linear map constructed using the universal property of the coproduct. -/ def toModule : (⨁ i, M i) →ₗ[R] N := DFunLike.coe (DFinsupp.lsum ℕ) φ /-- Coproducts in the categories of modules and additive monoids commute with the forgetful functor from modules to additive monoids. -/ theorem coe_toModule_eq_coe_toAddMonoid : (toModule R ι N φ : (⨁ i, M i) → N) = toAddMonoid fun i ↦ (φ i).toAddMonoidHom := rfl variable {ι N φ} /-- The map constructed using the universal property gives back the original maps when restricted to each component. -/ @[simp] theorem toModule_lof (i) (x : M i) : toModule R ι N φ (lof R ι M i x) = φ i x := toAddMonoid_of (fun i ↦ (φ i).toAddMonoidHom) i x variable (ψ : (⨁ i, M i) →ₗ[R] N) /-- Every linear map from a direct sum agrees with the one obtained by applying the universal property to each of its components. -/ theorem toModule.unique (f : ⨁ i, M i) : ψ f = toModule R ι N (fun i ↦ ψ.comp <| lof R ι M i) f := toAddMonoid.unique ψ.toAddMonoidHom f variable {ψ} {ψ' : (⨁ i, M i) →ₗ[R] N} /-- Two `LinearMap`s out of a direct sum are equal if they agree on the generators. See note [partially-applied ext lemmas]. -/ @[ext] theorem linearMap_ext ⦃ψ ψ' : (⨁ i, M i) →ₗ[R] N⦄ (H : ∀ i, ψ.comp (lof R ι M i) = ψ'.comp (lof R ι M i)) : ψ = ψ' := DFinsupp.lhom_ext' H /-- The inclusion of a subset of the direct summands into a larger subset of the direct summands, as a linear map. -/ def lsetToSet (S T : Set ι) (H : S ⊆ T) : (⨁ i : S, M i) →ₗ[R] ⨁ i : T, M i := toModule R _ _ fun i ↦ lof R T (fun i : Subtype T ↦ M i) ⟨i, H i.prop⟩ variable (ι M) /-- Given `Fintype α`, `linearEquivFunOnFintype R` is the natural `R`-linear equivalence between `⨁ i, M i` and `∀ i, M i`. -/ @[simps! apply] def linearEquivFunOnFintype [Fintype ι] : (⨁ i, M i) ≃ₗ[R] ∀ i, M i := DFinsupp.linearEquivFunOnFintype variable {ι M} @[simp] theorem linearEquivFunOnFintype_lof [Fintype ι] (i : ι) (m : M i) : (linearEquivFunOnFintype R ι M) (lof R ι M i m) = Pi.single i m := by ext a change (DFinsupp.equivFunOnFintype (lof R ι M i m)) a = _ convert _root_.congr_fun (DFinsupp.equivFunOnFintype_single i m) a @[simp] theorem linearEquivFunOnFintype_symm_single [Fintype ι] (i : ι) (m : M i) : (linearEquivFunOnFintype R ι M).symm (Pi.single i m) = lof R ι M i m := DFinsupp.equivFunOnFintype_symm_single i m end DecidableEq @[simp] theorem linearEquivFunOnFintype_symm_coe [Fintype ι] (f : ⨁ i, M i) : (linearEquivFunOnFintype R ι M).symm f = f := (linearEquivFunOnFintype R ι M).symm_apply_apply _ /-- The natural linear equivalence between `⨁ _ : ι, M` and `M` when `Unique ι`. -/ protected def lid (M : Type v) (ι : Type* := PUnit) [AddCommMonoid M] [Module R M] [Unique ι] : (⨁ _ : ι, M) ≃ₗ[R] M := { DirectSum.id M ι, toModule R ι M fun _ ↦ LinearMap.id with } /-- The projection map onto one component, as a linear map. -/ def component (i : ι) : (⨁ i, M i) →ₗ[R] M i := DFinsupp.lapply i variable {ι M} theorem apply_eq_component (f : ⨁ i, M i) (i : ι) : f i = component R ι M i f := rfl -- Note(kmill): `@[ext]` cannot prove `ext_iff` because `R` is not determined by `f` or `g`. -- This is not useful as an `@[ext]` lemma as the `ext` tactic can not infer `R`. theorem ext_component {f g : ⨁ i, M i} (h : ∀ i, component R ι M i f = component R ι M i g) : f = g := DFinsupp.ext h theorem ext_component_iff {f g : ⨁ i, M i} : f = g ↔ ∀ i, component R ι M i f = component R ι M i g := ⟨fun h _ ↦ by rw [h], ext_component R⟩ @[simp] theorem lof_apply [DecidableEq ι] (i : ι) (b : M i) : ((lof R ι M i) b) i = b := DFinsupp.single_eq_same @[simp] theorem component.lof_self [DecidableEq ι] (i : ι) (b : M i) : component R ι M i ((lof R ι M i) b) = b := lof_apply R i b theorem component.of [DecidableEq ι] (i j : ι) (b : M j) : component R ι M i ((lof R ι M j) b) = if h : j = i then Eq.recOn h b else 0 := DFinsupp.single_apply section map variable {R} {N : ι → Type*} section AddCommMonoid variable [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)] section variable (f : ∀ i, M i →+ N i) lemma mker_map : AddMonoidHom.mker (map f) = (AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mker (f i))).comap (coeFnAddMonoidHom M) := DFinsupp.mker_mapRangeAddMonoidHom f lemma mrange_map : AddMonoidHom.mrange (map f) = (AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mrange (f i))).comap (coeFnAddMonoidHom N) := DFinsupp.mrange_mapRangeAddMonoidHom f end variable (f : Π i, M i →ₗ[R] N i) /-- The linear map between direct sums induced by a family of linear maps. -/ def lmap : (⨁ i, M i) →ₗ[R] ⨁ i, N i := DFinsupp.mapRange.linearMap f @[simp] theorem lmap_apply (x i) : lmap f x i = f i (x i) := rfl @[simp] lemma lmap_of [DecidableEq ι] (i : ι) (x : M i) : lmap f (of M i x) = of N i (f i x) := DFinsupp.mapRange_single (hf := fun _ => map_zero _) @[simp] theorem lmap_lof [DecidableEq ι] (i) (x : M i) : lmap f (lof R _ _ _ x) = lof R _ _ _ (f i x) := DFinsupp.mapRange_single (hf := fun _ ↦ map_zero _) @[simp] lemma lmap_id : (lmap (fun i ↦ LinearMap.id (R := R) (M := M i))) = LinearMap.id := DFinsupp.mapRange.linearMap_id @[simp] lemma lmap_comp {K : ι → Type*} [∀ i, AddCommMonoid (K i)] [∀ i, Module R (K i)] (g : ∀ (i : ι), N i →ₗ[R] K i) : (lmap (fun i ↦ (g i) ∘ₗ (f i))) = (lmap g) ∘ₗ (lmap f) := DFinsupp.mapRange.linearMap_comp _ _ theorem lmap_injective : Function.Injective (lmap f) ↔ ∀ i, Function.Injective (f i) := by classical exact DFinsupp.mapRange_injective (hf := fun _ ↦ map_zero _) theorem lmap_surjective : Function.Surjective (lmap f) ↔ (∀ i, Function.Surjective (f i)) := by classical exact DFinsupp.mapRange_surjective (hf := fun _ ↦ map_zero _) lemma lmap_eq_iff (x y : ⨁ i, M i) : lmap f x = lmap f y ↔ ∀ i, f i (x i) = f i (y i) := map_eq_iff (fun i => (f i).toAddMonoidHom) _ _ lemma toAddMonoidHom_lmap : (lmap f).toAddMonoidHom = map (fun i => (f i).toAddMonoidHom) := rfl lemma lmap_eq_map (x : ⨁ i, M i) : lmap f x = map (fun i => (f i).toAddMonoidHom) x := rfl lemma ker_lmap : LinearMap.ker (lmap f) = (Submodule.pi Set.univ (fun i ↦ LinearMap.ker (f i))).comap (DirectSum.coeFnLinearMap R) := DFinsupp.ker_mapRangeLinearMap f lemma range_lmap : LinearMap.range (lmap f) = (Submodule.pi Set.univ (fun i ↦ LinearMap.range (f i))).comap (DirectSum.coeFnLinearMap R) := DFinsupp.range_mapRangeLinearMap f end AddCommMonoid section AddCommGroup variable {R : Type u} {ι : Type v} {M : ι → Type w} {N : ι → Type*} lemma ker_map [∀ i, AddCommGroup (M i)] [∀ i, AddCommMonoid (N i)] (f : ∀ i, M i →+ N i) : (map f).ker = (AddSubgroup.pi Set.univ (f · |>.ker)).comap (DirectSum.coeFnAddMonoidHom M) := DFinsupp.ker_mapRangeAddMonoidHom f lemma range_map [∀ i, AddCommGroup (M i)] [∀ i, AddCommGroup (N i)] (f : ∀ i, M i →+ N i) : (map f).range = (AddSubgroup.pi Set.univ (f · |>.range)).comap (DirectSum.coeFnAddMonoidHom N) := DFinsupp.range_mapRangeAddMonoidHom f end AddCommGroup end map section CongrLeft variable {κ : Type*} /-- Reindexing terms of a direct sum is linear. -/ def lequivCongrLeft (h : ι ≃ κ) : (⨁ i, M i) ≃ₗ[R] ⨁ k, M (h.symm k) := DFinsupp.domLCongr h @[simp] theorem lequivCongrLeft_apply (h : ι ≃ κ) (f : ⨁ i, M i) (k : κ) : lequivCongrLeft R h f k = f (h.symm k) := equivCongrLeft_apply _ _ _ end CongrLeft section Sigma variable {α : ι → Type*} {δ : ∀ i, α i → Type w} variable [DecidableEq ι] [∀ i j, AddCommMonoid (δ i j)] [∀ i j, Module R (δ i j)] /-- `curry` as a linear map. -/ def sigmaLcurry : (⨁ i : Σ _, _, δ i.1 i.2) →ₗ[R] ⨁ (i) (j), δ i j := { sigmaCurry with map_smul' := fun r ↦ by convert DFinsupp.sigmaCurry_smul (δ := δ) r } @[simp] theorem sigmaLcurry_apply (f : ⨁ i : Σ _, _, δ i.1 i.2) (i : ι) (j : α i) : sigmaLcurry R f i j = f ⟨i, j⟩ := sigmaCurry_apply f i j /-- `uncurry` as a linear map. -/ def sigmaLuncurry : (⨁ (i) (j), δ i j) →ₗ[R] ⨁ i : Σ _, _, δ i.1 i.2 := { sigmaUncurry with map_smul' := DFinsupp.sigmaUncurry_smul } @[simp] theorem sigmaLuncurry_apply (f : ⨁ (i) (j), δ i j) (i : ι) (j : α i) : sigmaLuncurry R f ⟨i, j⟩ = f i j := sigmaUncurry_apply f i j /-- `curryEquiv` as a linear equiv. -/ def sigmaLcurryEquiv : (⨁ i : Σ _, _, δ i.1 i.2) ≃ₗ[R] ⨁ (i) (j), δ i j := DFinsupp.sigmaCurryLEquiv end Sigma section Option variable {α : Option ι → Type w} [∀ i, AddCommMonoid (α i)] [∀ i, Module R (α i)] /-- Linear isomorphism obtained by separating the term of index `none` of a direct sum over `Option ι`. -/ @[simps] noncomputable def lequivProdDirectSum : (⨁ i, α i) ≃ₗ[R] α none × ⨁ i, α (some i) := { addEquivProdDirectSum with map_smul' := DFinsupp.equivProdDFinsupp_smul } end Option end General section Submodule section Semiring variable {R : Type u} [Semiring R] variable {ι : Type v} [dec_ι : DecidableEq ι] variable {M : Type*} [AddCommMonoid M] [Module R M] variable (A : ι → Submodule R M) /-- The canonical linear map from `⨁ i, A i` to `M` where `A` is a collection of `Submodule R M` indexed by `ι`. This is `DirectSum.coeAddMonoidHom` as a `LinearMap`. -/ def coeLinearMap : (⨁ i, A i) →ₗ[R] M := toModule R ι M fun i ↦ (A i).subtype theorem coeLinearMap_eq_dfinsuppSum [DecidableEq M] (x : DirectSum ι fun i => A i) : coeLinearMap A x = DFinsupp.sum x fun i => (fun x : A i => ↑x) := by simp only [coeLinearMap, toModule, DFinsupp.lsum, LinearEquiv.coe_mk, LinearMap.coe_mk, AddHom.coe_mk] rw [DFinsupp.sumAddHom_apply] simp only [LinearMap.toAddMonoidHom_coe, Submodule.coe_subtype] @[deprecated (since := "2025-04-06")] alias coeLinearMap_eq_dfinsupp_sum := coeLinearMap_eq_dfinsuppSum @[simp] theorem coeLinearMap_of (i : ι) (x : A i) : DirectSum.coeLinearMap A (of (fun i ↦ A i) i x) = x := -- Porting note: spelled out arguments. (I don't know how this works.) toAddMonoid_of (β := fun i => A i) (fun i ↦ ((A i).subtype : A i →+ M)) i x variable {A} theorem range_coeLinearMap : LinearMap.range (coeLinearMap A) = ⨆ i, A i := (Submodule.iSup_eq_range_dfinsupp_lsum _).symm @[simp] theorem IsInternal.ofBijective_coeLinearMap_same (h : IsInternal A) {i : ι} (x : A i) : (LinearEquiv.ofBijective (coeLinearMap A) h).symm x i = x := by rw [← coeLinearMap_of, LinearEquiv.ofBijective_symm_apply_apply, of_eq_same] @[simp] theorem IsInternal.ofBijective_coeLinearMap_of_ne (h : IsInternal A) {i j : ι} (hij : i ≠ j) (x : A i) : (LinearEquiv.ofBijective (coeLinearMap A) h).symm x j = 0 := by rw [← coeLinearMap_of, LinearEquiv.ofBijective_symm_apply_apply, of_eq_of_ne i j _ hij] theorem IsInternal.ofBijective_coeLinearMap_of_mem (h : IsInternal A) {i : ι} {x : M} (hx : x ∈ A i) : (LinearEquiv.ofBijective (coeLinearMap A) h).symm x i = ⟨x, hx⟩ := h.ofBijective_coeLinearMap_same ⟨x, hx⟩ theorem IsInternal.ofBijective_coeLinearMap_of_mem_ne (h : IsInternal A) {i j : ι} (hij : i ≠ j) {x : M} (hx : x ∈ A i) : (LinearEquiv.ofBijective (coeLinearMap A) h).symm x j = 0 := h.ofBijective_coeLinearMap_of_ne hij ⟨x, hx⟩ /-- If a direct sum of submodules is internal then the submodules span the module. -/ theorem IsInternal.submodule_iSup_eq_top (h : IsInternal A) : iSup A = ⊤ := by rw [Submodule.iSup_eq_range_dfinsupp_lsum, LinearMap.range_eq_top] exact Function.Bijective.surjective h /-- If a direct sum of submodules is internal then the submodules are independent. -/ theorem IsInternal.submodule_iSupIndep (h : IsInternal A) : iSupIndep A := iSupIndep_of_dfinsupp_lsum_injective _ h.injective /-- Given an internal direct sum decomposition of a module `M`, and a basis for each of the components of the direct sum, the disjoint union of these bases is a basis for `M`. -/ noncomputable def IsInternal.collectedBasis (h : IsInternal A) {α : ι → Type*} (v : ∀ i, Basis (α i) R (A i)) : Basis (Σ i, α i) R M where repr := ((LinearEquiv.ofBijective (DirectSum.coeLinearMap A) h).symm ≪≫ₗ DFinsupp.mapRange.linearEquiv fun i ↦ (v i).repr) ≪≫ₗ (sigmaFinsuppLequivDFinsupp R).symm @[simp] theorem IsInternal.collectedBasis_coe (h : IsInternal A) {α : ι → Type*} (v : ∀ i, Basis (α i) R (A i)) : ⇑(h.collectedBasis v) = fun a : Σ i, α i ↦ ↑(v a.1 a.2) := by funext a -- Porting note: was -- simp only [IsInternal.collectedBasis, toModule, coeLinearMap, Basis.coe_ofRepr, -- Basis.repr_symm_apply, DFinsupp.lsum_apply_apply, DFinsupp.mapRange.linearEquiv_apply, -- DFinsupp.mapRange.linearEquiv_symm, DFinsupp.mapRange_single, linearCombination_single, -- LinearEquiv.ofBijective_apply, LinearEquiv.symm_symm, LinearEquiv.symm_trans_apply, one_smul, -- sigmaFinsuppAddEquivDFinsupp_apply, sigmaFinsuppEquivDFinsupp_single, -- sigmaFinsuppLequivDFinsupp_apply] -- convert DFinsupp.sumAddHom_single (fun i ↦ (A i).subtype.toAddMonoidHom) a.1 (v a.1 a.2) simp only [IsInternal.collectedBasis, coeLinearMap, Basis.coe_ofRepr, LinearEquiv.trans_symm, LinearEquiv.symm_symm, LinearEquiv.trans_apply, sigmaFinsuppLequivDFinsupp_apply, AddEquiv.toEquiv_eq_coe, Equiv.toFun_as_coe, EquivLike.coe_coe, sigmaFinsuppAddEquivDFinsupp_apply, sigmaFinsuppEquivDFinsupp_single, LinearEquiv.ofBijective_apply] rw [DFinsupp.mapRange.linearEquiv_symm] -- `DFunLike.coe (β := fun x ↦ ⨁ (i : ι), ↥(A i))` -- appears in the goal, but the lemma is expecting -- `DFunLike.coe (β := fun x ↦ Π₀ (i : ι), ↥(A i))` erw [DFinsupp.mapRange.linearEquiv_apply] simp only [DFinsupp.mapRange_single, Basis.repr_symm_apply, linearCombination_single, one_smul, toModule] -- Similarly here. erw [DFinsupp.lsum_single] simp only [Submodule.coe_subtype] theorem IsInternal.collectedBasis_mem (h : IsInternal A) {α : ι → Type*} (v : ∀ i, Basis (α i) R (A i)) (a : Σ i, α i) : h.collectedBasis v a ∈ A a.1 := by simp theorem IsInternal.collectedBasis_repr_of_mem (h : IsInternal A) {α : ι → Type*} (v : ∀ i, Basis (α i) R (A i)) {x : M} {i : ι} {a : α i} (hx : x ∈ A i) : (h.collectedBasis v).repr x ⟨i, a⟩ = (v i).repr ⟨x, hx⟩ a := by change (sigmaFinsuppLequivDFinsupp R).symm (DFinsupp.mapRange _ (fun i ↦ map_zero _) _) _ = _ simp [h.ofBijective_coeLinearMap_of_mem hx] theorem IsInternal.collectedBasis_repr_of_mem_ne (h : IsInternal A) {α : ι → Type*} (v : ∀ i, Basis (α i) R (A i)) {x : M} {i j : ι} (hij : i ≠ j) {a : α j} (hx : x ∈ A i) : (h.collectedBasis v).repr x ⟨j, a⟩ = 0 := by change (sigmaFinsuppLequivDFinsupp R).symm (DFinsupp.mapRange _ (fun i ↦ map_zero _) _) _ = _ simp [h.ofBijective_coeLinearMap_of_mem_ne hij hx] /-- When indexed by only two distinct elements, `DirectSum.IsInternal` implies the two submodules are complementary. Over a `Ring R`, this is true as an iff, as `DirectSum.isInternal_submodule_iff_isCompl`. -/ theorem IsInternal.isCompl {A : ι → Submodule R M} {i j : ι} (hij : i ≠ j) (h : (Set.univ : Set ι) = {i, j}) (hi : IsInternal A) : IsCompl (A i) (A j) := ⟨hi.submodule_iSupIndep.pairwiseDisjoint hij, codisjoint_iff.mpr <| Eq.symm <| hi.submodule_iSup_eq_top.symm.trans <| by rw [← sSup_pair, iSup, ← Set.image_univ, h, Set.image_insert_eq, Set.image_singleton]⟩ end Semiring section Ring variable {R : Type u} [Ring R] variable {ι : Type v} [dec_ι : DecidableEq ι] variable {M : Type*} [AddCommGroup M] [Module R M] /-- Note that this is not generally true for `[Semiring R]`; see `iSupIndep.dfinsupp_lsum_injective` for details. -/ theorem isInternal_submodule_of_iSupIndep_of_iSup_eq_top {A : ι → Submodule R M} (hi : iSupIndep A) (hs : iSup A = ⊤) : IsInternal A := ⟨hi.dfinsupp_lsum_injective, -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify value of `f` (LinearMap.range_eq_top (f := DFinsupp.lsum _ _)).1 <| (Submodule.iSup_eq_range_dfinsupp_lsum _).symm.trans hs⟩ /-- `iff` version of `DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top`, `DirectSum.IsInternal.iSupIndep`, and `DirectSum.IsInternal.submodule_iSup_eq_top`. -/ theorem isInternal_submodule_iff_iSupIndep_and_iSup_eq_top (A : ι → Submodule R M) : IsInternal A ↔ iSupIndep A ∧ iSup A = ⊤ := ⟨fun i ↦ ⟨i.submodule_iSupIndep, i.submodule_iSup_eq_top⟩, And.rec isInternal_submodule_of_iSupIndep_of_iSup_eq_top⟩ /-- If a collection of submodules has just two indices, `i` and `j`, then `DirectSum.IsInternal` is equivalent to `isCompl`. -/ theorem isInternal_submodule_iff_isCompl (A : ι → Submodule R M) {i j : ι} (hij : i ≠ j) (h : (Set.univ : Set ι) = {i, j}) : IsInternal A ↔ IsCompl (A i) (A j) := by have : ∀ k, k = i ∨ k = j := fun k ↦ by simpa using Set.ext_iff.mp h k rw [isInternal_submodule_iff_iSupIndep_and_iSup_eq_top, iSup, ← Set.image_univ, h, Set.image_insert_eq, Set.image_singleton, sSup_pair, iSupIndep_pair hij this] exact ⟨fun ⟨hd, ht⟩ ↦ ⟨hd, codisjoint_iff.mpr ht⟩, fun ⟨hd, ht⟩ ↦ ⟨hd, ht.eq_top⟩⟩ @[simp] theorem isInternal_ne_bot_iff {A : ι → Submodule R M} : IsInternal (fun i : {i // A i ≠ ⊥} ↦ A i) ↔ IsInternal A := by simp [isInternal_submodule_iff_iSupIndep_and_iSup_eq_top] lemma isInternal_biSup_submodule_of_iSupIndep {A : ι → Submodule R M} (s : Set ι) (h : iSupIndep <| fun i : s ↦ A i) : IsInternal <| fun (i : s) ↦ (A i).comap (⨆ i ∈ s, A i).subtype := by refine (isInternal_submodule_iff_iSupIndep_and_iSup_eq_top _).mpr ⟨?_, by simp [iSup_subtype]⟩ let p := ⨆ i ∈ s, A i have hp : ∀ i ∈ s, A i ≤ p := fun i hi ↦ le_biSup A hi let e : Submodule R p ≃o Set.Iic p := p.mapIic suffices (e ∘ fun i : s ↦ (A i).comap p.subtype) = fun i ↦ ⟨A i, hp i i.property⟩ by rw [← iSupIndep_map_orderIso_iff e, this] exact .of_coe_Iic_comp h ext i m change m ∈ ((A i).comap p.subtype).map p.subtype ↔ _ rw [Submodule.map_comap_subtype, inf_of_le_right (hp i i.property)] /-! Now copy the lemmas for subgroup and submonoids. -/ theorem IsInternal.addSubmonoid_iSupIndep {M : Type*} [AddCommMonoid M] {A : ι → AddSubmonoid M} (h : IsInternal A) : iSupIndep A := iSupIndep_of_dfinsuppSumAddHom_injective _ h.injective theorem IsInternal.addSubgroup_iSupIndep {G : Type*} [AddCommGroup G] {A : ι → AddSubgroup G} (h : IsInternal A) : iSupIndep A := iSupIndep_of_dfinsuppSumAddHom_injective' _ h.injective end Ring end Submodule end DirectSum
VectorSpace.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 -/ import Mathlib.Algebra.FreeAbelianGroup.Finsupp import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.Algebra.Polynomial.Basic import Mathlib.LinearAlgebra.Basis.Defs import Mathlib.LinearAlgebra.DFinsupp import Mathlib.LinearAlgebra.FreeModule.Basic /-! # Linear structures on function with finite support `ι →₀ M` This file contains results on the `R`-module structure on functions of finite support from a type `ι` to an `R`-module `M`, in particular in the case that `R` is a field. -/ noncomputable section open Set LinearMap Module Submodule universe u v w namespace DFinsupp variable {ι : Type*} {R : Type*} {M : ι → Type*} variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] /-- The direct sum of free modules is free. Note that while this is stated for `DFinsupp` not `DirectSum`, the types are defeq. -/ noncomputable def basis {η : ι → Type*} (b : ∀ i, Basis (η i) R (M i)) : Basis (Σ i, η i) R (Π₀ i, M i) := .ofRepr ((mapRange.linearEquiv fun i => (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm) variable (R M) in instance _root_.Module.Free.dfinsupp [∀ i : ι, Module.Free R (M i)] : Module.Free R (Π₀ i, M i) := .of_basis <| DFinsupp.basis fun i => Module.Free.chooseBasis R (M i) variable [DecidableEq ι] {φ : ι → Type*} (f : ∀ i, φ i → M i) open Finsupp (linearCombination) theorem linearIndependent_single (hf : ∀ i, LinearIndependent R (f i)) : LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by classical have : linearCombination R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) = DFinsupp.mapRange.linearMap (fun i ↦ linearCombination R (f i)) ∘ₗ (sigmaFinsuppLequivDFinsupp R).toLinearMap := by ext; simp rw [LinearIndependent, this] exact ((DFinsupp.mapRange_injective _ fun _ ↦ map_zero _).mpr hf).comp (Equiv.injective _) lemma linearIndependent_single_iff : LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔ ∀ i, LinearIndependent R (f i) := ⟨fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩ end DFinsupp namespace Finsupp section Semiring variable {R : Type*} {M : Type*} {ι : Type*} variable [Semiring R] [AddCommMonoid M] [Module R M] theorem linearIndependent_single {φ : ι → Type*} (f : ∀ i, φ i → M) (hf : ∀ i, LinearIndependent R (f i)) : LinearIndependent R fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2) := by classical convert (DFinsupp.linearIndependent_single _ hf).map_injOn _ (finsuppLequivDFinsupp R).symm.injective.injOn simp lemma linearIndependent_single_iff {φ : ι → Type*} {f : ∀ i, φ i → M} : LinearIndependent R (fun ix : Σ i, φ i ↦ single ix.1 (f ix.1 ix.2)) ↔ ∀ i, LinearIndependent R (f i) := ⟨fun h i ↦ (h.comp _ sigma_mk_injective).of_comp (lsingle i), linearIndependent_single _⟩ open LinearMap Submodule open scoped Classical in /-- The basis on `ι →₀ M` with basis vectors `fun ⟨i, x⟩ ↦ single i (b i x)`. -/ protected def basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : Basis (Σ i, φ i) R (ι →₀ M) := .ofRepr <| (finsuppLequivDFinsupp R).trans <| (DFinsupp.mapRange.linearEquiv fun i ↦ (b i).repr).trans (sigmaFinsuppLequivDFinsupp R).symm @[simp] theorem basis_repr {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) (g : ι →₀ M) (ix) : (Finsupp.basis b).repr g ix = (b ix.1).repr (g ix.1) ix.2 := rfl @[simp] theorem coe_basis {φ : ι → Type*} (b : ∀ i, Basis (φ i) R M) : ⇑(Finsupp.basis b) = fun ix : Σ i, φ i => single ix.1 (b ix.1 ix.2) := funext fun ⟨i, x⟩ => Basis.apply_eq_iff.mpr <| by ext ⟨j, y⟩ by_cases h : i = j · cases h simp [Finsupp.single_apply_left sigma_mk_injective] · simp_all variable (ι R M) in instance _root_.Module.Free.finsupp [Module.Free R M] : Module.Free R (ι →₀ M) := .of_basis (Finsupp.basis fun _ => Module.Free.chooseBasis R M) /-- The basis on `ι →₀ R` with basis vectors `fun i ↦ single i 1`. -/ @[simps] protected def basisSingleOne : Basis ι R (ι →₀ R) := Basis.ofRepr (LinearEquiv.refl _ _) @[simp] theorem coe_basisSingleOne : (Finsupp.basisSingleOne : ι → ι →₀ R) = fun i => Finsupp.single i 1 := funext fun _ => Basis.apply_eq_iff.mpr rfl variable (ι R) in lemma linearIndependent_single_one : LinearIndependent R fun i : ι ↦ single i (1 : R) := Finsupp.basisSingleOne.linearIndependent end Semiring section Ring variable {R : Type*} {M : Type*} {ι : Type*} variable [Ring R] [AddCommGroup M] [Module R M] lemma linearIndependent_single_of_ne_zero [NoZeroSMulDivisors R M] {v : ι → M} (hv : ∀ i, v i ≠ 0) : LinearIndependent R fun i : ι ↦ single i (v i) := by rw [← linearIndependent_equiv (Equiv.sigmaPUnit ι)] exact linearIndependent_single (f := fun i (_ : Unit) ↦ v i) <| by simp +contextual [Fintype.linearIndependent_iff, hv] end Ring end Finsupp lemma Module.Free.trans {R S M : Type*} [CommSemiring R] [Semiring S] [Algebra R S] [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] [Module.Free S M] [Module.Free R S] : Module.Free R M := let e : (ChooseBasisIndex S M →₀ S) ≃ₗ[R] ChooseBasisIndex S M →₀ (ChooseBasisIndex R S →₀ R) := Finsupp.mapRange.linearEquiv (chooseBasis R S).repr let e : M ≃ₗ[R] ChooseBasisIndex S M →₀ (ChooseBasisIndex R S →₀ R) := (chooseBasis S M).repr.restrictScalars R ≪≫ₗ e .of_equiv e.symm /-! TODO: move this section to an earlier file. -/ namespace Basis variable {R M n : Type*} variable [DecidableEq n] variable [Semiring R] [AddCommMonoid M] [Module R M] theorem _root_.Finset.sum_single_ite [Fintype n] (a : R) (i : n) : (∑ x : n, Finsupp.single x (if i = x then a else 0)) = Finsupp.single i a := by simp only [apply_ite (Finsupp.single _), Finsupp.single_zero, Finset.sum_ite_eq, if_pos (Finset.mem_univ _)] @[simp] theorem equivFun_symm_single [Finite n] (b : Basis n R M) (i : n) : b.equivFun.symm (Pi.single i 1) = b i := by cases nonempty_fintype n simp [Pi.single_apply] end Basis section Algebra variable {R S : Type*} [CommRing R] [Ring S] [Algebra R S] {ι : Type*} (B : Basis ι R S) /-- For any `r : R`, `s : S`, we have `B.repr ((algebra_map R S r) * s) i = r * (B.repr s i) `. -/ theorem Module.Basis.repr_smul' (i : ι) (r : R) (s : S) : B.repr (algebraMap R S r * s) i = r * B.repr s i := by rw [← smul_eq_mul, ← smul_eq_mul, algebraMap_smul, map_smul, Finsupp.smul_apply] end Algebra namespace FreeAbelianGroup instance {σ : Type*} : Module.Free ℤ (FreeAbelianGroup σ) where exists_basis := ⟨σ, ⟨(FreeAbelianGroup.equivFinsupp _).toIntLinearEquiv⟩⟩ end FreeAbelianGroup namespace AddMonoidAlgebra variable {ι R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R S[ι] := .finsupp .. end AddMonoidAlgebra namespace MonoidAlgebra variable {ι R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R (MonoidAlgebra S ι) := .finsupp .. end MonoidAlgebra namespace Polynomial variable {R S : Type*} [Semiring R] [Semiring S] [Module R S] [Module.Free R S] instance : Module.Free R R[X] := .of_equiv (Polynomial.toFinsuppIsoLinear _).symm end Polynomial
Star.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.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.Module.LinearMap.Prod import Mathlib.Algebra.Order.Module.Synonym import Mathlib.Analysis.Convex.Segment import Mathlib.Tactic.GCongr import Mathlib.Tactic.Module /-! # Star-convex sets This files defines star-convex sets (aka star domains, star-shaped set, radially convex set). A set is star-convex at `x` if every segment from `x` to a point in the set is contained in the set. This is the prototypical example of a contractible set in homotopy theory (by scaling every point towards `x`), but has wider uses. Note that this has nothing to do with star rings, `Star` and co. ## Main declarations * `StarConvex 𝕜 x s`: `s` is star-convex at `x` with scalars `𝕜`. ## Implementation notes Instead of saying that a set is star-convex, we say a set is star-convex *at a point*. This has the advantage of allowing us to talk about convexity as being "everywhere star-convexity" and of making the union of star-convex sets be star-convex. Incidentally, this choice means we don't need to assume a set is nonempty for it to be star-convex. Concretely, the empty set is star-convex at every point. ## TODO Balanced sets are star-convex. The closure of a star-convex set is star-convex. Star-convex sets are contractible. A nonempty open star-convex set in `ℝ^n` is diffeomorphic to the entire space. -/ open Set open Convex Pointwise variable {𝕜 E F : Type*} section OrderedSemiring variable [Semiring 𝕜] [PartialOrder 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (x : E) (s : Set E) /-- Star-convexity of sets. `s` is star-convex at `x` if every segment from `x` to a point in `s` is contained in `s`. -/ def StarConvex (𝕜 : Type*) {E : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [SMul 𝕜 E] (x : E) (s : Set E) : Prop := ∀ ⦃y : E⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s variable {𝕜 x s} {t : Set E} theorem starConvex_iff_segment_subset : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := by constructor · rintro h y hy z ⟨a, b, ha, hb, hab, rfl⟩ exact h hy ha hb hab · rintro h y hy a b ha hb hab exact h hy ⟨a, b, ha, hb, hab, rfl⟩ theorem StarConvex.segment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := starConvex_iff_segment_subset.1 h hy theorem StarConvex.openSegment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hy) /-- Alternative definition of star-convexity, in terms of pointwise set operations. -/ theorem starConvex_iff_pointwise_add_subset : StarConvex 𝕜 x s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • {x} + b • s ⊆ s := by refine ⟨?_, fun h y hy a b ha hb hab => h ha hb hab (add_mem_add (smul_mem_smul_set <| mem_singleton _) ⟨_, hy, rfl⟩)⟩ rintro hA a b ha hb hab w ⟨au, ⟨u, rfl : u = x, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hv ha hb hab theorem starConvex_empty (x : E) : StarConvex 𝕜 x ∅ := fun _ hy => hy.elim theorem starConvex_univ (x : E) : StarConvex 𝕜 x univ := fun _ _ _ _ _ _ _ => trivial theorem StarConvex.inter (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∩ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.left ha hb hab, ht hy.right ha hb hab⟩ theorem starConvex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋂₀ S) := fun _ hy _ _ ha hb hab s hs => h s hs (hy s hs) ha hb hab theorem starConvex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋂ i, s i) := sInter_range s ▸ starConvex_sInter <| forall_mem_range.2 h theorem starConvex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : (i : ι) → κ i → Set E} (h : ∀ i j, StarConvex 𝕜 x (s i j)) : StarConvex 𝕜 x (⋂ (i) (j), s i j) := starConvex_iInter fun i => starConvex_iInter (h i) theorem StarConvex.union (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∪ t) := by rintro y (hy | hy) a b ha hb hab · exact Or.inl (hs hy ha hb hab) · exact Or.inr (ht hy ha hb hab) theorem starConvex_iUnion {ι : Sort*} {s : ι → Set E} (hs : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋃ i, s i) := by rintro y hy a b ha hb hab rw [mem_iUnion] at hy ⊢ obtain ⟨i, hy⟩ := hy exact ⟨i, hs i hy ha hb hab⟩ theorem starConvex_iUnion₂ {ι : Sort*} {κ : ι → Sort*} {s : (i : ι) → κ i → Set E} (h : ∀ i j, StarConvex 𝕜 x (s i j)) : StarConvex 𝕜 x (⋃ (i) (j), s i j) := starConvex_iUnion fun i => starConvex_iUnion (h i) theorem starConvex_sUnion {S : Set (Set E)} (hS : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋃₀ S) := by rw [sUnion_eq_iUnion] exact starConvex_iUnion fun s => hS _ s.2 theorem StarConvex.prod {y : F} {s : Set E} {t : Set F} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x, y) (s ×ˢ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.1 ha hb hab, ht hy.2 ha hb hab⟩ theorem starConvex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {x : ∀ i, E i} {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → StarConvex 𝕜 (x i) (t i)) : StarConvex 𝕜 x (s.pi t) := fun _ hy _ _ ha hb hab i hi => ht hi (hy i hi) ha hb hab end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {x y z : E} {s : Set E} theorem StarConvex.mem [ZeroLEOneClass 𝕜] (hs : StarConvex 𝕜 x s) (h : s.Nonempty) : x ∈ s := by obtain ⟨y, hy⟩ := h convert hs hy zero_le_one le_rfl (add_zero 1) rw [one_smul, zero_smul, add_zero] theorem starConvex_iff_forall_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, one_smul, zero_smul, zero_add] obtain rfl | hb := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, one_smul, zero_smul, add_zero] exact h hy ha hb hab theorem starConvex_iff_forall_ne_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy _ a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, zero_smul, one_smul, zero_add] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, zero_smul, one_smul, add_zero] obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] exact h hy hxy ha' hb' hab theorem starConvex_iff_openSegment_subset [ZeroLEOneClass 𝕜] (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := starConvex_iff_segment_subset.trans <| forall₂_congr fun _ hy => (openSegment_subset_iff_segment_subset hx hy).symm theorem starConvex_singleton (x : E) : StarConvex 𝕜 x {x} := by rintro y (rfl : y = x) a b _ _ hab exact Convex.combo_self hab _ theorem StarConvex.linear_image (hs : StarConvex 𝕜 x s) (f : E →ₗ[𝕜] F) : StarConvex 𝕜 (f x) (f '' s) := by rintro _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ theorem StarConvex.is_linear_image (hs : StarConvex 𝕜 x s) {f : E → F} (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 (f x) (f '' s) := hs.linear_image <| hf.mk' f theorem StarConvex.linear_preimage {s : Set F} (f : E →ₗ[𝕜] F) (hs : StarConvex 𝕜 (f x) s) : StarConvex 𝕜 x (f ⁻¹' s) := by intro y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hy ha hb hab theorem StarConvex.is_linear_preimage {s : Set F} {f : E → F} (hs : StarConvex 𝕜 (f x) s) (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 x (preimage f s) := hs.linear_preimage <| hf.mk' f theorem StarConvex.add {t : Set E} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x + y) (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add theorem StarConvex.add_left (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (z + x) ((fun x => z + x) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ match_scalars <;> simp [hab] theorem StarConvex.add_right (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (x + z) ((fun x => x + z) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ match_scalars <;> simp [hab] /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_right (hs : StarConvex 𝕜 (z + x) s) : StarConvex 𝕜 x ((fun x => z + x) ⁻¹' s) := by intro y hy a b ha hb hab have h := hs hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_left (hs : StarConvex 𝕜 (x + z) s) : StarConvex 𝕜 x ((fun x => x + z) ⁻¹' s) := by rw [add_comm] at hs simpa only [add_comm] using hs.preimage_add_right end Module end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] {x y : E} theorem StarConvex.sub' {s : Set (E × E)} (hs : StarConvex 𝕜 (x, y) s) : StarConvex 𝕜 (x - y) ((fun x : E × E => x.1 - x.2) '' s) := hs.is_linear_image IsLinearMap.isLinearMap_sub end AddCommGroup end OrderedSemiring section OrderedCommSemiring variable [CommSemiring 𝕜] [PartialOrder 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {x : E} {s : Set E} theorem StarConvex.smul (hs : StarConvex 𝕜 x s) (c : 𝕜) : StarConvex 𝕜 (c • x) (c • s) := hs.linear_image <| LinearMap.lsmul _ _ c theorem StarConvex.zero_smul (hs : StarConvex 𝕜 0 s) (c : 𝕜) : StarConvex 𝕜 0 (c • s) := by simpa using hs.smul c theorem StarConvex.preimage_smul {c : 𝕜} (hs : StarConvex 𝕜 (c • x) s) : StarConvex 𝕜 x ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) theorem StarConvex.affinity (hs : StarConvex 𝕜 x s) (z : E) (c : 𝕜) : StarConvex 𝕜 (z + c • x) ((fun x => z + c • x) '' s) := by have h := (hs.smul c).add_left z rwa [← image_smul, image_image] at h end AddCommMonoid end OrderedCommSemiring section OrderedRing variable [Ring 𝕜] [PartialOrder 𝕜] section AddCommMonoid variable [AddRightMono 𝕜] [AddCommMonoid E] [SMulWithZero 𝕜 E] {s : Set E} theorem starConvex_zero_iff : StarConvex 𝕜 0 s ↔ ∀ ⦃x : E⦄, x ∈ s → ∀ ⦃a : 𝕜⦄, 0 ≤ a → a ≤ 1 → a • x ∈ s := by refine forall_congr' fun x => forall_congr' fun _ => ⟨fun h a ha₀ ha₁ => ?_, fun h a b ha hb hab => ?_⟩ · simpa only [sub_add_cancel, eq_self_iff_true, forall_true_left, zero_add, smul_zero] using h (sub_nonneg_of_le ha₁) ha₀ · rw [smul_zero, zero_add] exact h hb (by rw [← hab]; exact le_add_of_nonneg_left ha) end AddCommMonoid section AddCommGroup section AddRightMono variable [AddRightMono 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {x y : E} {s t : Set E} theorem StarConvex.add_smul_mem (hs : StarConvex 𝕜 x s) (hy : x + y ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hy (sub_nonneg_of_le ht₁) ht₀ (sub_add_cancel _ _) theorem StarConvex.smul_mem (hs : StarConvex 𝕜 0 s) (hx : x ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : t • x ∈ s := by simpa using hs.add_smul_mem (by simpa using hx) ht₀ ht₁ theorem StarConvex.add_smul_sub_mem (hs : StarConvex 𝕜 x s) (hy : y ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : x + t • (y - x) ∈ s := by apply hs.segment_subset hy rw [segment_eq_image'] exact mem_image_of_mem _ ⟨ht₀, ht₁⟩ end AddRightMono variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {x y : E} {s t : Set E} /-- The preimage of a star-convex set under an affine map is star-convex. -/ theorem StarConvex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : StarConvex 𝕜 (f x) s) : StarConvex 𝕜 x (f ⁻¹' s) := by intro y hy a b ha hb hab rw [mem_preimage, Convex.combo_affine_apply hab] exact hs hy ha hb hab /-- The image of a star-convex set under an affine map is star-convex. -/ theorem StarConvex.affine_image (f : E →ᵃ[𝕜] F) {s : Set E} (hs : StarConvex 𝕜 x s) : StarConvex 𝕜 (f x) (f '' s) := by rintro y ⟨y', ⟨hy', hy'f⟩⟩ a b ha hb hab refine ⟨a • x + b • y', ⟨hs hy' ha hb hab, ?_⟩⟩ rw [Convex.combo_affine_apply hab, hy'f] theorem StarConvex.neg (hs : StarConvex 𝕜 x s) : StarConvex 𝕜 (-x) (-s) := by rw [← image_neg_eq_neg] exact hs.is_linear_image IsLinearMap.isLinearMap_neg theorem StarConvex.sub (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x - y) (s - t) := by simp_rw [sub_eq_add_neg] exact hs.add ht.neg end AddCommGroup section OrderedAddCommGroup variable [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} /-- If `x < y`, then `(Set.Iic x)ᶜ` is star convex at `y`. -/ lemma starConvex_compl_Iic (h : x < y) : StarConvex 𝕜 y (Iic x)ᶜ := by refine (starConvex_iff_forall_pos <| by simp [h.not_ge]).mpr fun z hz a b ha hb hab ↦ ?_ rw [mem_compl_iff, mem_Iic] at hz ⊢ contrapose! hz refine (lt_of_smul_lt_smul_of_nonneg_left ?_ hb.le).le calc b • z ≤ (a + b) • x - a • y := by rwa [le_sub_iff_add_le', hab, one_smul] _ < b • x := by rw [add_smul, sub_lt_iff_lt_add'] gcongr /-- If `x < y`, then `(Set.Ici y)ᶜ` is star convex at `x`. -/ lemma starConvex_compl_Ici (h : x < y) : StarConvex 𝕜 x (Ici y)ᶜ := starConvex_compl_Iic (E := Eᵒᵈ) h end OrderedAddCommGroup end OrderedRing section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] {x : E} {s : Set E} /-- Alternative definition of star-convexity, using division. -/ theorem starConvex_iff_div : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s := ⟨fun h y hy a b ha hb hab => by apply h hy · positivity · positivity · rw [← add_div] exact div_self hab.ne', fun h y hy a b ha hb hab => by have h' := h hy ha hb rw [hab, div_one, div_one] at h' exact h' zero_lt_one⟩ theorem StarConvex.mem_smul (hs : StarConvex 𝕜 0 s) (hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne'] exact hs.smul_mem hx (by positivity) (inv_le_one_of_one_le₀ ht) end AddCommGroup end LinearOrderedField /-! #### Star-convex sets in an ordered space Relates `starConvex` and `Set.ordConnected`. -/ section OrdConnected /-- If `s` is an order-connected set in an ordered module over an ordered semiring and all elements of `s` are comparable with `x ∈ s`, then `s` is `StarConvex` at `x`. -/ theorem Set.OrdConnected.starConvex [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x : E} {s : Set E} (hs : s.OrdConnected) (hx : x ∈ s) (h : ∀ y ∈ s, x ≤ y ∨ y ≤ x) : StarConvex 𝕜 x s := by intro y hy a b ha hb hab obtain hxy | hyx := h _ hy · refine hs.out hx hy (mem_Icc.2 ⟨?_, ?_⟩) · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr calc a • x + b • y ≤ a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ · refine hs.out hy hx (mem_Icc.2 ⟨?_, ?_⟩) · calc y = a • y + b • y := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr calc a • x + b • y ≤ a • x + b • x := by gcongr _ = x := Convex.combo_self hab _ theorem starConvex_iff_ordConnected [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) : StarConvex 𝕜 x s ↔ s.OrdConnected := by simp_rw [ordConnected_iff_uIcc_subset_left hx, starConvex_iff_segment_subset, segment_eq_uIcc] alias ⟨StarConvex.ordConnected, _⟩ := starConvex_iff_ordConnected end OrdConnected
MutuallySingular.lean
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.Restrict /-! # Mutually singular measures Two measures `μ`, `ν` are said to be mutually singular (`MeasureTheory.Measure.MutuallySingular`, localized notation `μ ⟂ₘ ν`) if there exists a measurable set `s` such that `μ s = 0` and `ν sᶜ = 0`. The measurability of `s` is an unnecessary assumption (see `MeasureTheory.Measure.MutuallySingular.mk`) but we keep it because this way `rcases (h : μ ⟂ₘ ν)` gives us a measurable set and usually it is easy to prove measurability. In this file we define the predicate `MeasureTheory.Measure.MutuallySingular` and prove basic facts about it. ## Tags measure, mutually singular -/ open Set open MeasureTheory NNReal ENNReal Filter namespace MeasureTheory namespace Measure variable {α : Type*} {m0 : MeasurableSpace α} {μ μ₁ μ₂ ν ν₁ ν₂ : Measure α} /-- Two measures `μ`, `ν` are said to be mutually singular if there exists a measurable set `s` such that `μ s = 0` and `ν sᶜ = 0`. -/ def MutuallySingular {_ : MeasurableSpace α} (μ ν : Measure α) : Prop := ∃ s : Set α, MeasurableSet s ∧ μ s = 0 ∧ ν sᶜ = 0 @[inherit_doc MeasureTheory.Measure.MutuallySingular] scoped[MeasureTheory] infixl:60 " ⟂ₘ " => MeasureTheory.Measure.MutuallySingular namespace MutuallySingular theorem mk {s t : Set α} (hs : μ s = 0) (ht : ν t = 0) (hst : univ ⊆ s ∪ t) : MutuallySingular μ ν := by use toMeasurable μ s, measurableSet_toMeasurable _ _, (measure_toMeasurable _).trans hs refine measure_mono_null (fun x hx => (hst trivial).resolve_left fun hxs => hx ?_) ht exact subset_toMeasurable _ _ hxs /-- A set such that `μ h.nullSet = 0` and `ν h.nullSetᶜ = 0`. -/ def nullSet (h : μ ⟂ₘ ν) : Set α := h.choose lemma measurableSet_nullSet (h : μ ⟂ₘ ν) : MeasurableSet h.nullSet := h.choose_spec.1 @[simp] lemma measure_nullSet (h : μ ⟂ₘ ν) : μ h.nullSet = 0 := h.choose_spec.2.1 @[simp] lemma measure_compl_nullSet (h : μ ⟂ₘ ν) : ν h.nullSetᶜ = 0 := h.choose_spec.2.2 -- TODO: this is proved by simp, but is not simplified in other contexts without the @[simp] -- attribute. Also, the linter does not complain about that attribute. @[simp] lemma restrict_nullSet (h : μ ⟂ₘ ν) : μ.restrict h.nullSet = 0 := by simp -- TODO: this is proved by simp, but is not simplified in other contexts without the @[simp] -- attribute. Also, the linter does not complain about that attribute. @[simp] lemma restrict_compl_nullSet (h : μ ⟂ₘ ν) : ν.restrict h.nullSetᶜ = 0 := by simp @[simp] theorem zero_right : μ ⟂ₘ 0 := ⟨∅, MeasurableSet.empty, measure_empty, rfl⟩ @[symm] theorem symm (h : ν ⟂ₘ μ) : μ ⟂ₘ ν := let ⟨i, hi, his, hit⟩ := h ⟨iᶜ, hi.compl, hit, (compl_compl i).symm ▸ his⟩ theorem comm : μ ⟂ₘ ν ↔ ν ⟂ₘ μ := ⟨fun h => h.symm, fun h => h.symm⟩ @[simp] theorem zero_left : 0 ⟂ₘ μ := zero_right.symm theorem mono_ac (h : μ₁ ⟂ₘ ν₁) (hμ : μ₂ ≪ μ₁) (hν : ν₂ ≪ ν₁) : μ₂ ⟂ₘ ν₂ := let ⟨s, hs, h₁, h₂⟩ := h ⟨s, hs, hμ h₁, hν h₂⟩ lemma congr_ac (hμμ₂ : μ ≪ μ₂) (hμ₂μ : μ₂ ≪ μ) (hνν₂ : ν ≪ ν₂) (hν₂ν : ν₂ ≪ ν) : μ ⟂ₘ ν ↔ μ₂ ⟂ₘ ν₂ := ⟨fun h ↦ h.mono_ac hμ₂μ hν₂ν, fun h ↦ h.mono_ac hμμ₂ hνν₂⟩ theorem mono (h : μ₁ ⟂ₘ ν₁) (hμ : μ₂ ≤ μ₁) (hν : ν₂ ≤ ν₁) : μ₂ ⟂ₘ ν₂ := h.mono_ac hμ.absolutelyContinuous hν.absolutelyContinuous @[simp] lemma self_iff (μ : Measure α) : μ ⟂ₘ μ ↔ μ = 0 := by refine ⟨?_, fun h ↦ by (rw [h]; exact zero_left)⟩ rintro ⟨s, hs, hμs, hμs_compl⟩ suffices μ Set.univ = 0 by rwa [measure_univ_eq_zero] at this rw [← Set.union_compl_self s, measure_union disjoint_compl_right hs.compl, hμs, hμs_compl, add_zero] @[simp] theorem sum_left {ι : Type*} [Countable ι] {μ : ι → Measure α} : sum μ ⟂ₘ ν ↔ ∀ i, μ i ⟂ₘ ν := by refine ⟨fun h i => h.mono (le_sum _ _) le_rfl, fun H => ?_⟩ choose s hsm hsμ hsν using H refine ⟨⋂ i, s i, MeasurableSet.iInter hsm, ?_, ?_⟩ · rw [sum_apply _ (MeasurableSet.iInter hsm), ENNReal.tsum_eq_zero] exact fun i => measure_mono_null (iInter_subset _ _) (hsμ i) · rwa [compl_iInter, measure_iUnion_null_iff] @[simp] theorem sum_right {ι : Type*} [Countable ι] {ν : ι → Measure α} : μ ⟂ₘ sum ν ↔ ∀ i, μ ⟂ₘ ν i := comm.trans <| sum_left.trans <| forall_congr' fun _ => comm @[simp] theorem add_left_iff : μ₁ + μ₂ ⟂ₘ ν ↔ μ₁ ⟂ₘ ν ∧ μ₂ ⟂ₘ ν := by rw [← sum_cond, sum_left, Bool.forall_bool, cond, cond, and_comm] @[simp] theorem add_right_iff : μ ⟂ₘ ν₁ + ν₂ ↔ μ ⟂ₘ ν₁ ∧ μ ⟂ₘ ν₂ := comm.trans <| add_left_iff.trans <| and_congr comm comm theorem add_left (h₁ : ν₁ ⟂ₘ μ) (h₂ : ν₂ ⟂ₘ μ) : ν₁ + ν₂ ⟂ₘ μ := add_left_iff.2 ⟨h₁, h₂⟩ theorem add_right (h₁ : μ ⟂ₘ ν₁) (h₂ : μ ⟂ₘ ν₂) : μ ⟂ₘ ν₁ + ν₂ := add_right_iff.2 ⟨h₁, h₂⟩ theorem smul (r : ℝ≥0∞) (h : ν ⟂ₘ μ) : r • ν ⟂ₘ μ := h.mono_ac (AbsolutelyContinuous.rfl.smul_left r) AbsolutelyContinuous.rfl theorem smul_nnreal (r : ℝ≥0) (h : ν ⟂ₘ μ) : r • ν ⟂ₘ μ := h.smul r lemma restrict (h : μ ⟂ₘ ν) (s : Set α) : μ.restrict s ⟂ₘ ν := by refine ⟨h.nullSet, h.measurableSet_nullSet, ?_, h.measure_compl_nullSet⟩ rw [Measure.restrict_apply h.measurableSet_nullSet] exact measure_mono_null Set.inter_subset_left h.measure_nullSet end MutuallySingular lemma eq_zero_of_absolutelyContinuous_of_mutuallySingular {μ ν : Measure α} (h_ac : μ ≪ ν) (h_ms : μ ⟂ₘ ν) : μ = 0 := by rw [← Measure.MutuallySingular.self_iff] exact h_ms.mono_ac Measure.AbsolutelyContinuous.rfl h_ac lemma absolutelyContinuous_of_add_of_mutuallySingular {ν₁ ν₂ : Measure α} (h : μ ≪ ν₁ + ν₂) (h_ms : μ ⟂ₘ ν₂) : μ ≪ ν₁ := by refine AbsolutelyContinuous.mk fun s hs hs_zero ↦ ?_ let t := h_ms.nullSet have ht : MeasurableSet t := h_ms.measurableSet_nullSet have htμ : μ t = 0 := h_ms.measure_nullSet have htν₂ : ν₂ tᶜ = 0 := h_ms.measure_compl_nullSet have : μ s = μ (s ∩ tᶜ) := by conv_lhs => rw [← inter_union_compl s t] rw [measure_union, measure_inter_null_of_null_right _ htμ, zero_add] · exact (disjoint_compl_right.inter_right' _ ).inter_left' _ · exact hs.inter ht.compl rw [this] refine h ?_ simp only [Measure.coe_add, Pi.add_apply, add_eq_zero] exact ⟨measure_inter_null_of_null_left _ hs_zero, measure_inter_null_of_null_right _ htν₂⟩ lemma _root_.MeasurableEmbedding.mutuallySingular_map {β : Type*} {_ : MeasurableSpace β} {f : α → β} (hf : MeasurableEmbedding f) (hμν : μ ⟂ₘ ν) : μ.map f ⟂ₘ ν.map f := by refine ⟨f '' hμν.nullSet, hf.measurableSet_image' hμν.measurableSet_nullSet, ?_, ?_⟩ · rw [hf.map_apply, hf.injective.preimage_image, hμν.measure_nullSet] · rw [hf.map_apply, Set.preimage_compl, hf.injective.preimage_image, hμν.measure_compl_nullSet] lemma exists_null_set_measure_lt_of_disjoint (h : Disjoint μ ν) {ε : ℝ≥0} (hε : 0 < ε) : ∃ s, μ s = 0 ∧ ν sᶜ ≤ 2 * ε := by have h₁ : (μ ⊓ ν) univ = 0 := le_bot_iff.1 (h (inf_le_left (b := ν)) inf_le_right) ▸ rfl simp_rw [Measure.inf_apply MeasurableSet.univ, inter_univ] at h₁ have h₂ : ∀ n : ℕ, ∃ t, μ t + ν tᶜ < ε * (1 / 2) ^ n := by intro n obtain ⟨m, ⟨t, ht₁, rfl⟩, hm₂⟩ : ∃ x ∈ {m | ∃ t, m = μ t + ν tᶜ}, x < ε * (1 / 2 : ℝ≥0∞) ^ n := by refine exists_lt_of_csInf_lt ⟨ν univ, ∅, by simp⟩ <| h₁ ▸ ENNReal.mul_pos ?_ (by simp) norm_cast exact hε.ne.symm exact ⟨t, hm₂⟩ choose t ht₂ using h₂ refine ⟨⋂ n, t n, ?_, ?_⟩ · refine eq_zero_of_le_mul_pow (by simp) fun n ↦ ((measure_mono <| iInter_subset_of_subset n fun _ ht ↦ ht).trans (le_add_right le_rfl)).trans (ht₂ n).le · rw [compl_iInter, (by simp [ENNReal.tsum_mul_left, mul_comm] : 2 * (ε : ℝ≥0∞) = ∑' (n : ℕ), ε * (1 / 2 : ℝ≥0∞) ^ n)] refine (measure_iUnion_le _).trans ?_ exact ENNReal.summable.tsum_le_tsum (fun n ↦ (le_add_left le_rfl).trans (ht₂ n).le) ENNReal.summable lemma mutuallySingular_of_disjoint (h : Disjoint μ ν) : μ ⟂ₘ ν := by have h' (n : ℕ) : ∃ s, μ s = 0 ∧ ν sᶜ ≤ (1 / 2) ^ n := by convert exists_null_set_measure_lt_of_disjoint h (ε := (1 / 2) ^ (n + 1)) <| pow_pos (by simp) (n + 1) push_cast rw [pow_succ, ← mul_assoc, mul_comm, ← mul_assoc] norm_cast rw [div_mul_cancel₀, one_mul] · push_cast simp · simp choose s hs₂ hs₃ using h' refine Measure.MutuallySingular.mk (t := (⋃ n, s n)ᶜ) (measure_iUnion_null hs₂) ?_ ?_ · rw [compl_iUnion] refine eq_zero_of_le_mul_pow (ε := 1) (by simp : (1 / 2 : ℝ≥0∞) < 1) <| fun n ↦ ?_ rw [ENNReal.coe_one, one_mul] exact (measure_mono <| iInter_subset_of_subset n fun _ ht ↦ ht).trans (hs₃ n) · rw [union_compl_self] lemma MutuallySingular.disjoint (h : μ ⟂ₘ ν) : Disjoint μ ν := by have h_bot_iff (ξ : Measure α) : ξ ≤ ⊥ ↔ ξ = 0 := by rw [le_bot_iff] rfl intro ξ hξμ hξν rw [h_bot_iff] ext s hs simp only [Measure.coe_zero, Pi.zero_apply] rw [← inter_union_compl s h.nullSet, measure_union, add_eq_zero] · exact ⟨measure_inter_null_of_null_right _ <| absolutelyContinuous_of_le hξμ h.measure_nullSet, measure_inter_null_of_null_right _ <| absolutelyContinuous_of_le hξν h.measure_compl_nullSet⟩ · exact Disjoint.mono inter_subset_right inter_subset_right disjoint_compl_right · exact hs.inter h.measurableSet_nullSet.compl lemma MutuallySingular.disjoint_ae (h : μ ⟂ₘ ν) : Disjoint (ae μ) (ae ν) := by rw [disjoint_iff_inf_le] intro s _ refine ⟨s ∪ h.nullSetᶜ, ?_, s ∪ h.nullSet, ?_, ?_⟩ · rw [mem_ae_iff, compl_union, compl_compl] exact measure_inter_null_of_null_right _ h.measure_nullSet · rw [mem_ae_iff, compl_union] exact measure_inter_null_of_null_right _ h.measure_compl_nullSet · rw [union_eq_compl_compl_inter_compl, union_eq_compl_compl_inter_compl, ← compl_union, compl_compl, inter_union_compl, compl_compl] lemma disjoint_of_disjoint_ae (h : Disjoint (ae μ) (ae ν)) : Disjoint μ ν := by rw [disjoint_iff_inf_le] at h ⊢ refine Measure.le_intro fun s hs _ ↦ ?_ rw [Measure.inf_apply hs] have : (⊥ : Measure α) = 0 := rfl simp only [this, Measure.coe_zero, Pi.zero_apply, nonpos_iff_eq_zero] specialize h (mem_bot (s := sᶜ)) rw [mem_inf_iff] at h obtain ⟨t₁, ht₁, t₂, ht₂, h_eq'⟩ := h have h_eq : s = t₁ᶜ ∪ t₂ᶜ := by rw [union_eq_compl_compl_inter_compl, compl_compl, compl_compl, ← h_eq', compl_compl] rw [mem_ae_iff] at ht₁ ht₂ refine le_antisymm ?_ zero_le' refine sInf_le_of_le (a := 0) (b := 0) ?_ le_rfl rw [h_eq] refine ⟨t₁ᶜ ∩ t₂, Eq.symm ?_⟩ rw [add_eq_zero] constructor · refine measure_inter_null_of_null_left _ ?_ exact measure_inter_null_of_null_left _ ht₁ · rw [compl_inter, compl_compl, union_eq_compl_compl_inter_compl, union_eq_compl_compl_inter_compl, ← compl_union, compl_compl, compl_compl, inter_comm, inter_comm t₁, union_comm, inter_union_compl] exact ht₂ lemma mutuallySingular_tfae : List.TFAE [ μ ⟂ₘ ν, Disjoint μ ν, Disjoint (ae μ) (ae ν) ] := by tfae_have 1 → 2 | h => h.disjoint tfae_have 2 → 1 | h => mutuallySingular_of_disjoint h tfae_have 1 → 3 | h => h.disjoint_ae tfae_have 3 → 2 | h => disjoint_of_disjoint_ae h tfae_finish lemma mutuallySingular_iff_disjoint : μ ⟂ₘ ν ↔ Disjoint μ ν := mutuallySingular_tfae.out 0 1 lemma mutuallySingular_iff_disjoint_ae : μ ⟂ₘ ν ↔ Disjoint (ae μ) (ae ν) := mutuallySingular_tfae.out 0 2 end Measure end MeasureTheory
RegularWreathProduct.lean
/- Copyright (c) 2025 Francisco Silva. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Francisco Silva -/ import Mathlib.GroupTheory.Sylow import Mathlib.Algebra.Group.PUnit import Mathlib.Data.Finite.Perm import Mathlib.Algebra.Group.End /-! # Regular wreath product This file defines the regular wreath product of groups, and the canonical maps in and out of the product. The regular wreath product of `D` and `Q` is the product `(Q → D) × Q` with the group operation `⟨a₁, a₂⟩ * ⟨b₁, b₂⟩ = ⟨a₁ * (fun x ↦ b₁ (a₂⁻¹ * x)), a₂ * b₂⟩`. ## Main definitions * `RegularWreathProduct D Q` : The regular wreath product of groups `D` and `Q`. * `rightHom` : The canonical projection `D ≀ᵣ Q →* Q`. * `inl` : The canonical map `Q →* D ≀ᵣ Q`. * `toPerm` : The homomorphism from `D ≀ᵣ Q` to `Equiv.Perm (Λ × Q)`, where `Λ` is a `D`-set. * `IteratedWreathProduct G n` : The iterated wreath product of a group `G` `n` times. * `Sylow.mulEquivIteratedWreathProduct` : The isomorphism between the Sylow `p`-subgroup of `Perm p^n` and the iterated wreath product of the cyclic group of order `p` `n` times. ## Notation This file introduces the global notation `D ≀ᵣ Q` for `RegularWreathProduct D Q`. ## Tags group, regular wreath product, sylow p-subgroup -/ variable (D Q : Type*) [Group D] [Group Q] /-- The regular wreath product of groups `Q` and `D`. It is the product `(Q → D) × Q` with the group operation `⟨a₁, a₂⟩ * ⟨b₁, b₂⟩ = ⟨a₁ * (fun x ↦ b₁ (a₂⁻¹ * x)), a₂ * b₂⟩`. -/ @[ext] structure RegularWreathProduct where /-- The function of Q → D -/ left : Q → D /-- The element of Q -/ right : Q @[inherit_doc] infix:65 " ≀ᵣ " => RegularWreathProduct namespace RegularWreathProduct variable {D Q} instance : Mul (D ≀ᵣ Q) where mul a b := ⟨a.1 * (fun x ↦ b.1 (a.2⁻¹ * x)), a.2 * b.2⟩ lemma mul_def (a b : D ≀ᵣ Q) : a * b = ⟨a.1 * fun x ↦ b.1 (a.2⁻¹ * x), a.2 * b.2⟩ := rfl @[simp] theorem mul_left (a b : D ≀ᵣ Q) : (a * b).1 = a.1 * fun x ↦ b.1 (a.2⁻¹ * x) := rfl @[simp] theorem mul_right (a b : D ≀ᵣ Q) : (a * b).right = a.right * b.right := rfl instance : One (RegularWreathProduct D Q) where one := ⟨1, 1⟩ @[simp] theorem one_left : (1 : D ≀ᵣ Q).left = 1 := rfl @[simp] theorem one_right : (1 : D ≀ᵣ Q).right = 1 := rfl instance : Inv (RegularWreathProduct D Q) where inv x := ⟨fun k ↦ x.1⁻¹ (x.2 * k), x.2⁻¹⟩ @[simp] theorem inv_left (a : D ≀ᵣ Q) : a⁻¹.left = fun x ↦ a.left⁻¹ (a.right * x) := rfl @[simp] theorem inv_right (a : D ≀ᵣ Q) : a⁻¹.right = a.right⁻¹ := rfl instance : Group (RegularWreathProduct D Q) where mul_assoc a b c := by ext <;> simp [mul_assoc] one_mul a := by ext <;> simp mul_one a := by ext <;> simp inv_mul_cancel a := by ext <;> simp instance : Inhabited (RegularWreathProduct D Q) := ⟨1⟩ /-- The canonical projection map `D ≀ᵣ Q →* Q`, as a group hom. -/ def rightHom : D ≀ᵣ Q →* Q where toFun := RegularWreathProduct.right map_one' := rfl map_mul' _ _ := rfl /-- The canonical map `Q →* D ≀ᵣ Q` sending `q` to `⟨1, q⟩` -/ def inl : Q →* D ≀ᵣ Q where toFun q := ⟨1, q⟩ map_one' := rfl map_mul' _ _ := by ext <;> simp @[simp] theorem left_inl (q : Q) : (inl q : D ≀ᵣ Q).left = 1 := rfl @[simp] theorem right_inl (q : Q) : (inl q : D ≀ᵣ Q).right = q := rfl @[simp] theorem rightHom_eq_right : (rightHom : D ≀ᵣ Q → Q) = right := rfl @[simp] theorem rightHom_comp_inl_eq_id : (rightHom : D ≀ᵣ Q →* Q).comp inl = MonoidHom.id _ := by ext; simp @[simp] theorem fun_id (q : Q) : rightHom (inl q : D ≀ᵣ Q) = q := by simp /-- The equivalence map for the representation as a product. -/ def equivProd D Q : D ≀ᵣ Q ≃ (Q → D) × Q where toFun := fun ⟨d, q⟩ => ⟨d, q⟩ invFun := fun ⟨d, q⟩ => ⟨d, q⟩ left_inv := fun _ => rfl right_inv := fun _ => rfl instance [Finite D] [Finite Q] : Finite (D ≀ᵣ Q) := Finite.of_equiv _ (equivProd D Q).symm omit [Group D] [Group Q] in theorem card [Finite Q] : Nat.card (D ≀ᵣ Q) = Nat.card D ^ Nat.card Q * Nat.card Q := by rw [Nat.card_congr (equivProd D Q), Nat.card_prod (Q → D) Q, Nat.card_fun] /-- Define an isomorphism from `D₁ ≀ᵣ Q₁` to `D₂ ≀ᵣ Q₂` given isomorphisms `D₁ ≀ᵣ Q₁` and `Q₁ ≃* Q₂`. -/ def congr {D₁ Q₁ D₂ Q₂ : Type*} [Group D₁] [Group Q₁] [Group D₂] [Group Q₂] (f : D₁ ≃* D₂) (g : Q₁ ≃* Q₂) : D₁ ≀ᵣ Q₁ ≃* D₂ ≀ᵣ Q₂ where toFun x := ⟨f ∘ (x.left ∘ g.symm), g x.right⟩ invFun x := ⟨(f.symm ∘ x.left) ∘ g, g.symm x.right⟩ left_inv x := by ext <;> simp right_inv x := by ext <;> simp map_mul' x y := by ext <;> simp section perm variable (D Q) (Λ : Type*) [MulAction D Λ] instance : SMul (D ≀ᵣ Q) (Λ × Q) where smul w p := ⟨(w.left (w.right * p.2)) • p.1, w.right * p.2⟩ @[simp] lemma smul_def {w : D ≀ᵣ Q} {p : Λ × Q} : w • p = ⟨(w.1 (w.2 * p.2)) • p.1, w.2 * p.2⟩ := rfl instance : MulAction (D ≀ᵣ Q) (Λ × Q) where one_smul := by simp mul_smul := by simp [smul_smul, mul_assoc] variable [FaithfulSMul D Λ] instance [Nonempty Q] [Nonempty Λ] : FaithfulSMul (D ≀ᵣ Q) (Λ × Q) where eq_of_smul_eq_smul := by simp only [smul_def, Prod.mk.injEq, mul_left_inj, Prod.forall] intro m₁ m₂ h let ⟨a⟩ := ‹Nonempty Λ› let ⟨b⟩ := ‹Nonempty Q› ext q · have hh := fun a => (h a (m₁.right⁻¹ * q)).1 rw [← (h a b).2] at hh group at hh exact FaithfulSMul.eq_of_smul_eq_smul hh · exact (h a b).2 /-- The map sending the wreath product `D ≀ᵣ Q` to its representation as a permutation of `Λ × Q` given `D`-set `Λ`. -/ def toPerm : D ≀ᵣ Q →* Equiv.Perm (Λ × Q) := MulAction.toPermHom (D ≀ᵣ Q) (Λ × Q) theorem toPermInj [Nonempty Λ] : Function.Injective (toPerm D Q Λ) := MulAction.toPerm_injective end perm end RegularWreathProduct section iterated universe u /-- The wreath product of group `G` iterated `n` times. -/ def IteratedWreathProduct (G : Type u) : (n : ℕ) → Type u | 0 => PUnit | n + 1 => (IteratedWreathProduct G n) ≀ᵣ G variable (G : Type u) (n : ℕ) @[simp] lemma IteratedWreathProduct_zero : IteratedWreathProduct G 0 = PUnit := rfl @[simp] lemma IteratedWreathProduct_succ : IteratedWreathProduct G (n + 1) = (IteratedWreathProduct G n) ≀ᵣ G := rfl instance [Finite G] : Finite (IteratedWreathProduct G n) := by induction n with | zero => rw [IteratedWreathProduct_zero]; infer_instance | succ n h => rw [IteratedWreathProduct_succ]; infer_instance theorem IteratedWreathProduct.card [Finite G] : Nat.card (IteratedWreathProduct G n) = Nat.card G ^ (∑ i ∈ Finset.range n, Nat.card G ^ i) := by induction n with | zero => simp | succ n h => rw [IteratedWreathProduct_succ, RegularWreathProduct.card, h, geom_sum_succ, pow_succ, pow_mul'] variable [Group G] instance : Group (IteratedWreathProduct G n) := by induction n with | zero => rw [IteratedWreathProduct_zero]; infer_instance | succ n ih => rw [IteratedWreathProduct_succ]; infer_instance /-- The homomorphism from `IteratedWreathProduct G n` to `Perm (Fin n → G)`. -/ def iteratedWreathToPermHom (G : Type*) [Group G] : (n : ℕ) → (IteratedWreathProduct G n →* Equiv.Perm (Fin n → G)) | 0 => 1 | n + 1 => by let _ := MulAction.compHom (Fin n → G) (iteratedWreathToPermHom G n) exact (Equiv.Perm.permCongrHom (Fin.succFunEquiv G n).symm).toMonoidHom.comp (RegularWreathProduct.toPerm (IteratedWreathProduct G n) G (Fin n → G)) lemma iteratedWreathToPermHomInj (G : Type*) [Group G] : (n : ℕ) → Function.Injective (iteratedWreathToPermHom G n) | 0 => by simp only [IteratedWreathProduct_zero] apply Function.injective_of_subsingleton | n + 1 => by let _ := MulAction.compHom (Fin n → G) (iteratedWreathToPermHom G n) have : FaithfulSMul (IteratedWreathProduct G n) (Fin n → G) := ⟨fun h ↦ iteratedWreathToPermHomInj G n (Equiv.ext h)⟩ exact ((Equiv.Perm.permCongrHom (Fin.succFunEquiv G n).symm).toEquiv.comp_injective _).mpr (RegularWreathProduct.toPermInj (IteratedWreathProduct G n) G (Fin n → G)) /-- The encoding of the Sylow `p`-subgroups of `Perm α` as an iterated wreath product. -/ noncomputable def Sylow.mulEquivIteratedWreathProduct (p : ℕ) [hp : Fact (Nat.Prime p)] (n : ℕ) (α : Type*) [Finite α] (hα : Nat.card α = p ^ n) (G : Type*) [Group G] [Finite G] (hG : Nat.card G = p) (P : Sylow p (Equiv.Perm α)) : P ≃* IteratedWreathProduct G n := by let e1 : α ≃ (Fin n → G) := (Finite.equivFinOfCardEq hα).trans (Finite.equivFinOfCardEq (by rw [Nat.card_fun, Nat.card_fin, hG])).symm let f := (Equiv.Perm.permCongrHom e1.symm).toMonoidHom.comp (iteratedWreathToPermHom G n) have hf : Function.Injective f := ((Equiv.Perm.permCongrHom e1.symm).comp_injective _).mpr (iteratedWreathToPermHomInj G n) let g := (MonoidHom.ofInjective hf).symm let P' : Sylow p (Equiv.Perm α) := Sylow.ofCard (MonoidHom.range f) (by rw [Nat.card_congr g.toEquiv, IteratedWreathProduct.card, hG, Nat.card_perm, hα, ← Nat.multiplicity_eq_factorization hp.out (p ^ n).factorial_ne_zero, Nat.Prime.multiplicity_factorial_pow hp.out]) exact (P.equiv P').trans g end iterated
AsLimit.lean
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne, Adam Topaz -/ import Mathlib.Topology.Category.Profinite.Basic import Mathlib.Topology.DiscreteQuotient /-! # Profinite sets as limits of finite sets. We show that any profinite set is isomorphic to the limit of its discrete (hence finite) quotients. ## Definitions There are a handful of definitions in this file, given `X : Profinite`: 1. `X.fintypeDiagram` is the functor `DiscreteQuotient X ⥤ FintypeCat` whose limit is isomorphic to `X` (the limit taking place in `Profinite` via `FintypeCat.toProfinite`, see 2). 2. `X.diagram` is an abbreviation for `X.fintypeDiagram ⋙ FintypeCat.toProfinite`. 3. `X.asLimitCone` is the cone over `X.diagram` whose cone point is `X`. 4. `X.isoAsLimitConeLift` is the isomorphism `X ≅ (Profinite.limitCone X.diagram).X` induced by lifting `X.asLimitCone`. 5. `X.asLimitConeIso` is the isomorphism `X.asLimitCone ≅ (Profinite.limitCone X.diagram)` induced by `X.isoAsLimitConeLift`. 6. `X.asLimit` is a term of type `IsLimit X.asLimitCone`. 7. `X.lim : CategoryTheory.Limits.LimitCone X.asLimitCone` is a bundled combination of 3 and 6. -/ noncomputable section open CategoryTheory namespace Profinite universe u variable (X : Profinite.{u}) /-- The functor `DiscreteQuotient X ⥤ Fintype` whose limit is isomorphic to `X`. -/ def fintypeDiagram : DiscreteQuotient X ⥤ FintypeCat where obj S := @FintypeCat.of S (Fintype.ofFinite S) map f := DiscreteQuotient.ofLE f.le -- Porting note: `map_comp` used to be proved by default by `cat_disch`. -- once `cat_disch` can prove this again, remove the entire `map_comp` here. map_comp _ _ := by funext; cat_disch /-- An abbreviation for `X.fintypeDiagram ⋙ FintypeCat.toProfinite`. -/ abbrev diagram : DiscreteQuotient X ⥤ Profinite := X.fintypeDiagram ⋙ FintypeCat.toProfinite /-- A cone over `X.diagram` whose cone point is `X`. -/ def asLimitCone : CategoryTheory.Limits.Cone X.diagram := { pt := X π := { app := fun S => CompHausLike.ofHom (Y := X.diagram.obj S) _ ⟨S.proj, IsLocallyConstant.continuous (S.proj_isLocallyConstant)⟩ } } instance isIso_asLimitCone_lift : IsIso ((limitConeIsLimit.{u, u} X.diagram).lift X.asLimitCone) := CompHausLike.isIso_of_bijective _ (by refine ⟨fun a b h => ?_, fun a => ?_⟩ · refine DiscreteQuotient.eq_of_forall_proj_eq fun S => ?_ apply_fun fun f : (limitCone.{u, u} X.diagram).pt => f.val S at h exact h · obtain ⟨b, hb⟩ := DiscreteQuotient.exists_of_compat (fun S => a.val S) fun _ _ h => a.prop (homOfLE h) use b -- ext S : 3 -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` does not work, replaced with following -- three lines. apply Subtype.ext apply funext rintro S -- Porting note: end replacement block apply hb ) /-- The isomorphism between `X` and the explicit limit of `X.diagram`, induced by lifting `X.asLimitCone`. -/ def isoAsLimitConeLift : X ≅ (limitCone.{u, u} X.diagram).pt := asIso <| (limitConeIsLimit.{u, u} _).lift X.asLimitCone /-- The isomorphism of cones `X.asLimitCone` and `Profinite.limitCone X.diagram`. The underlying isomorphism is defeq to `X.isoAsLimitConeLift`. -/ def asLimitConeIso : X.asLimitCone ≅ limitCone.{u, u} _ := Limits.Cones.ext (isoAsLimitConeLift _) fun _ => rfl /-- `X.asLimitCone` is indeed a limit cone. -/ def asLimit : CategoryTheory.Limits.IsLimit X.asLimitCone := Limits.IsLimit.ofIsoLimit (limitConeIsLimit _) X.asLimitConeIso.symm /-- A bundled version of `X.asLimitCone` and `X.asLimit`. -/ def lim : Limits.LimitCone X.diagram := ⟨X.asLimitCone, X.asLimit⟩ end Profinite
Defs.lean
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Order.ToIntervalMod import Mathlib.Algebra.Ring.AddAut import Mathlib.Data.Nat.Totient import Mathlib.GroupTheory.Divisible import Mathlib.Topology.Algebra.IsUniformGroup.Basic import Mathlib.Topology.Algebra.Order.Field import Mathlib.Topology.IsLocalHomeomorph import Mathlib.Topology.Order.T5 /-! # The additive circle We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`. See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see `AddCircle.NormedAddCommGroup` in a later file. ## Main definitions and results: * `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜` * `UnitAddCircle`: the special case `ℝ ⧸ ℤ` * `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q` * `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)` * `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order * `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational * `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and `Icc a (a + p)` with its endpoints identified. * `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on `Icc a (a + p)`. ## Implementation notes: Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally. ## TODO * Link with periodicity * Lie group structure * Exponential equivalence to `Circle` -/ noncomputable section open AddCommGroup Set Function AddSubgroup TopologicalSpace open Topology variable {𝕜 B : Type*} section Continuity variable [AddCommGroup 𝕜] [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {p : 𝕜} (hp : 0 < p) (a x : 𝕜) theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by intro s h rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter] haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩ simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢ obtain ⟨l, u, hxI, hIs⟩ := h let d := toIcoDiv hp a x • p have hd := toIcoMod_mem_Ico hp a x simp_rw [subset_def, mem_inter_iff] refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;> simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff] · exact ⟨hxI.1, hd.2, hxI.2⟩ · rintro ⟨h, h'⟩ apply hIs rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2] exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩] theorem continuous_left_toIocMod : ContinuousWithinAt (toIocMod hp a) (Iic x) x := by rw [(funext fun y => Eq.trans (by rw [neg_neg]) <| toIocMod_neg _ _ _ : toIocMod hp a = (fun x => p - x) ∘ toIcoMod hp (-a) ∘ Neg.neg)] exact (continuous_sub_left _).continuousAt.comp_continuousWithinAt <| (continuous_right_toIcoMod _ _ _).comp continuous_neg.continuousWithinAt fun y => neg_le_neg variable {x} theorem toIcoMod_eventuallyEq_toIocMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) : toIcoMod hp a =ᶠ[𝓝 x] toIocMod hp a := IsOpen.mem_nhds (by rw [Ico_eq_locus_Ioc_eq_iUnion_Ioo] exact isOpen_iUnion fun i => isOpen_Ioo) <| (not_modEq_iff_toIcoMod_eq_toIocMod hp).1 <| not_modEq_iff_ne_mod_zmultiples.2 hx.symm theorem continuousAt_toIcoMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) : ContinuousAt (toIcoMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨(continuous_left_toIocMod hp a x).congr_of_eventuallyEq (h.filter_mono nhdsWithin_le_nhds) h.eq_of_nhds, continuous_right_toIcoMod hp a x⟩ theorem continuousAt_toIocMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) : ContinuousAt (toIocMod hp a) x := let h := toIcoMod_eventuallyEq_toIocMod hp a hx continuousAt_iff_continuous_left_right.2 <| ⟨continuous_left_toIocMod hp a x, (continuous_right_toIcoMod hp a x).congr_of_eventuallyEq (h.symm.filter_mono nhdsWithin_le_nhds) h.symm.eq_of_nhds⟩ end Continuity /-- The "additive circle": `𝕜 ⧸ (ℤ ∙ p)`. See also `Circle` and `Real.angle`. -/ abbrev AddCircle [AddCommGroup 𝕜] (p : 𝕜) := 𝕜 ⧸ zmultiples p namespace AddCircle section LinearOrderedAddCommGroup variable [AddCommGroup 𝕜] (p : 𝕜) theorem coe_nsmul {n : ℕ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl theorem coe_zsmul {n : ℤ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) := rfl theorem coe_add (x y : 𝕜) : (↑(x + y) : AddCircle p) = (x : AddCircle p) + (y : AddCircle p) := rfl theorem coe_sub (x y : 𝕜) : (↑(x - y) : AddCircle p) = (x : AddCircle p) - (y : AddCircle p) := rfl theorem coe_neg {x : 𝕜} : (↑(-x) : AddCircle p) = -(x : AddCircle p) := rfl @[norm_cast] theorem coe_zero : ↑(0 : 𝕜) = (0 : AddCircle p) := rfl theorem coe_eq_zero_iff {x : 𝕜} : (x : AddCircle p) = 0 ↔ ∃ n : ℤ, n • p = x := by simp [AddSubgroup.mem_zmultiples_iff] theorem coe_period : (p : AddCircle p) = 0 := (QuotientAddGroup.eq_zero_iff p).2 <| mem_zmultiples p theorem coe_add_period (x : 𝕜) : ((x + p : 𝕜) : AddCircle p) = x := by rw [coe_add, ← eq_sub_iff_add_eq', sub_self, coe_period] @[continuity, nolint unusedArguments] protected theorem continuous_mk' [TopologicalSpace 𝕜] : Continuous (QuotientAddGroup.mk' (zmultiples p) : 𝕜 → AddCircle p) := continuous_coinduced_rng variable [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] theorem coe_eq_zero_of_pos_iff (hp : 0 < p) {x : 𝕜} (hx : 0 < x) : (x : AddCircle p) = 0 ↔ ∃ n : ℕ, n • p = x := by rw [coe_eq_zero_iff] constructor <;> rintro ⟨n, rfl⟩ · replace hx : 0 < n := by contrapose! hx simpa only [← neg_nonneg, ← zsmul_neg, zsmul_neg'] using zsmul_nonneg hp.le (neg_nonneg.2 hx) exact ⟨n.toNat, by rw [← natCast_zsmul, Int.toNat_of_nonneg hx.le]⟩ · exact ⟨(n : ℤ), by simp⟩ variable [hp : Fact (0 < p)] (a : 𝕜) [Archimedean 𝕜] /-- The equivalence between `AddCircle p` and the half-open interval `[a, a + p)`, whose inverse is the natural quotient map. -/ def equivIco : AddCircle p ≃ Ico a (a + p) := QuotientAddGroup.equivIcoMod hp.out a /-- The equivalence between `AddCircle p` and the half-open interval `(a, a + p]`, whose inverse is the natural quotient map. -/ def equivIoc : AddCircle p ≃ Ioc a (a + p) := QuotientAddGroup.equivIocMod hp.out a /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `[a, a + p)`. -/ def liftIco (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIco p a /-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on `(a, a + p]`. -/ def liftIoc (f : 𝕜 → B) : AddCircle p → B := restrict _ f ∘ AddCircle.equivIoc p a variable {p a} theorem coe_eq_coe_iff_of_mem_Ico {x y : 𝕜} (hx : x ∈ Ico a (a + p)) (hy : y ∈ Ico a (a + p)) : (x : AddCircle p) = y ↔ x = y := by refine ⟨fun h => ?_, by tauto⟩ suffices (⟨x, hx⟩ : Ico a (a + p)) = ⟨y, hy⟩ by exact Subtype.mk.inj this apply_fun equivIco p a at h rw [← (equivIco p a).right_inv ⟨x, hx⟩, ← (equivIco p a).right_inv ⟨y, hy⟩] exact h theorem liftIco_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ico a (a + p)) : liftIco p a f ↑x = f x := by have : (equivIco p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIco, comp_apply, this] rfl theorem liftIoc_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ioc a (a + p)) : liftIoc p a f ↑x = f x := by have : (equivIoc p a) x = ⟨x, hx⟩ := by rw [Equiv.apply_eq_iff_eq_symm_apply] rfl rw [liftIoc, comp_apply, this] rfl lemma eq_coe_Ico (a : AddCircle p) : ∃ b, b ∈ Ico 0 p ∧ ↑b = a := by let b := QuotientAddGroup.equivIcoMod hp.out 0 a exact ⟨b.1, by simpa only [zero_add] using b.2, (QuotientAddGroup.equivIcoMod hp.out 0).symm_apply_apply a⟩ lemma coe_eq_zero_iff_of_mem_Ico (ha : a ∈ Ico 0 p) : (a : AddCircle p) = 0 ↔ a = 0 := by have h0 : 0 ∈ Ico 0 (0 + p) := by simpa [zero_add, left_mem_Ico] using hp.out have ha' : a ∈ Ico 0 (0 + p) := by rwa [zero_add] rw [← AddCircle.coe_eq_coe_iff_of_mem_Ico ha' h0, QuotientAddGroup.mk_zero] variable (p a) section Continuity variable [TopologicalSpace 𝕜] @[continuity] theorem continuous_equivIco_symm : Continuous (equivIco p a).symm := continuous_quotient_mk'.comp continuous_subtype_val @[continuity] theorem continuous_equivIoc_symm : Continuous (equivIoc p a).symm := continuous_quotient_mk'.comp continuous_subtype_val variable [OrderTopology 𝕜] {x : AddCircle p} theorem continuousAt_equivIco (hx : x ≠ a) : ContinuousAt (equivIco p a) x := by induction x using QuotientAddGroup.induction_on rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map] exact (continuousAt_toIcoMod hp.out a hx).codRestrict _ theorem continuousAt_equivIoc (hx : x ≠ a) : ContinuousAt (equivIoc p a) x := by induction x using QuotientAddGroup.induction_on rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map] exact (continuousAt_toIocMod hp.out a hx).codRestrict _ /-- The quotient map `𝕜 → AddCircle p` as a partial homeomorphism. -/ @[simps] def partialHomeomorphCoe [DiscreteTopology (zmultiples p)] : PartialHomeomorph 𝕜 (AddCircle p) where toFun := (↑) invFun := fun x ↦ equivIco p a x source := Ioo a (a + p) target := {↑a}ᶜ map_source' := by intro x hx hx' exact hx.1.ne' ((coe_eq_coe_iff_of_mem_Ico (Ioo_subset_Ico_self hx) (left_mem_Ico.mpr (lt_add_of_pos_right a hp.out))).mp hx') map_target' := by intro x hx exact (eq_left_or_mem_Ioo_of_mem_Ico (equivIco p a x).2).resolve_left (hx ∘ ((equivIco p a).symm_apply_apply x).symm.trans ∘ congrArg _) left_inv' := fun x hx ↦ congrArg _ ((equivIco p a).apply_symm_apply ⟨x, Ioo_subset_Ico_self hx⟩) right_inv' := fun x _ ↦ (equivIco p a).symm_apply_apply x open_source := isOpen_Ioo open_target := isOpen_compl_singleton continuousOn_toFun := (AddCircle.continuous_mk' p).continuousOn continuousOn_invFun := by exact continuousOn_of_forall_continuousAt (fun _ ↦ continuousAt_subtype_val.comp ∘ continuousAt_equivIco p a) lemma isLocalHomeomorph_coe [DiscreteTopology (zmultiples p)] [DenselyOrdered 𝕜] : IsLocalHomeomorph ((↑) : 𝕜 → AddCircle p) := by intro a obtain ⟨b, hb1, hb2⟩ := exists_between (sub_lt_self a hp.out) exact ⟨partialHomeomorphCoe p b, ⟨hb2, lt_add_of_sub_right_lt hb1⟩, rfl⟩ end Continuity /-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Ico_eq : ((↑) : 𝕜 → AddCircle p) '' Ico a (a + p) = univ := by rw [image_eq_range] exact (equivIco p a).symm.range_eq_univ /-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Ioc_eq : ((↑) : 𝕜 → AddCircle p) '' Ioc a (a + p) = univ := by rw [image_eq_range] exact (equivIoc p a).symm.range_eq_univ /-- The image of the closed interval `[0, p]` under the quotient map `𝕜 → AddCircle p` is the entire space. -/ @[simp] theorem coe_image_Icc_eq : ((↑) : 𝕜 → AddCircle p) '' Icc a (a + p) = univ := eq_top_mono (image_mono Ico_subset_Icc_self) <| coe_image_Ico_eq _ _ end LinearOrderedAddCommGroup section LinearOrderedField variable [Field 𝕜] (p q : 𝕜) /-- The rescaling equivalence between additive circles with different periods. -/ def equivAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃+ AddCircle q := QuotientAddGroup.congr _ _ (AddAut.mulRight <| (Units.mk0 p hp)⁻¹ * Units.mk0 q hq) <| by rw [AddMonoidHom.map_zmultiples, AddMonoidHom.coe_coe, AddAut.mulRight_apply, Units.val_mul, Units.val_mk0, Units.val_inv_eq_inv_val, Units.val_mk0, mul_inv_cancel_left₀ hp] @[simp] theorem equivAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : equivAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) := rfl @[simp] theorem equivAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : (equivAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) := rfl section variable [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] /-- The rescaling homeomorphism between additive circles with different periods. -/ def homeomorphAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃ₜ AddCircle q := ⟨equivAddCircle p q hp hq, (continuous_quotient_mk'.comp (continuous_mul_right (p⁻¹ * q))).quotient_lift _, (continuous_quotient_mk'.comp (continuous_mul_right (q⁻¹ * p))).quotient_lift _⟩ @[simp] theorem homeomorphAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : homeomorphAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) := rfl @[simp] theorem homeomorphAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) : (homeomorphAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) := rfl end lemma natCast_div_mul_eq_nsmul (r : 𝕜) (m : ℕ) : (↑(↑m / q * r) : AddCircle p) = m • (r / q : AddCircle p) := by rw [mul_comm_div, ← nsmul_eq_mul, coe_nsmul] lemma intCast_div_mul_eq_zsmul (r : 𝕜) (m : ℤ) : (↑(↑m / q * r) : AddCircle p) = m • (r / q : AddCircle p) := by rw [mul_comm_div, ← zsmul_eq_mul, coe_zsmul] variable [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [hp : Fact (0 < p)] section FloorRing variable [FloorRing 𝕜] @[simp] theorem coe_equivIco_mk_apply (x : 𝕜) : (equivIco p 0 <| QuotientAddGroup.mk x : 𝕜) = Int.fract (x / p) * p := toIcoMod_eq_fract_mul _ x instance : DivisibleBy (AddCircle p) ℤ where div x n := (↑((n : 𝕜)⁻¹ * (equivIco p 0 x : 𝕜)) : AddCircle p) div_zero x := by simp div_cancel {n} x hn := by replace hn : (n : 𝕜) ≠ 0 := by norm_cast change n • QuotientAddGroup.mk' _ ((n : 𝕜)⁻¹ * ↑(equivIco p 0 x)) = x rw [← map_zsmul, ← smul_mul_assoc, zsmul_eq_mul, mul_inv_cancel₀ hn, one_mul] exact (equivIco p 0).symm_apply_apply x omit [IsStrictOrderedRing 𝕜] in @[simp] lemma coe_fract (x : 𝕜) : (↑(Int.fract x) : AddCircle (1 : 𝕜)) = x := by simp [← Int.self_sub_floor] end FloorRing section FiniteOrderPoints variable {p} theorem addOrderOf_period_div {n : ℕ} (h : 0 < n) : addOrderOf ((p / n : 𝕜) : AddCircle p) = n := by rw [addOrderOf_eq_iff h] replace h : 0 < (n : 𝕜) := Nat.cast_pos.2 h refine ⟨?_, fun m hn h0 => ?_⟩ <;> simp only [Ne, ← coe_nsmul, nsmul_eq_mul] · rw [mul_div_cancel₀ _ h.ne', coe_period] rw [coe_eq_zero_of_pos_iff p hp.out (mul_pos (Nat.cast_pos.2 h0) <| div_pos hp.out h)] rintro ⟨k, hk⟩ rw [mul_div, eq_div_iff h.ne', nsmul_eq_mul, mul_right_comm, ← Nat.cast_mul, (mul_left_injective₀ hp.out.ne').eq_iff, Nat.cast_inj, mul_comm] at hk exact (Nat.le_of_dvd h0 ⟨_, hk.symm⟩).not_gt hn variable (p) in theorem gcd_mul_addOrderOf_div_eq {n : ℕ} (m : ℕ) (hn : 0 < n) : m.gcd n * addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by rw [natCast_div_mul_eq_nsmul, IsOfFinAddOrder.addOrderOf_nsmul] · rw [addOrderOf_period_div hn, Nat.gcd_comm, Nat.mul_div_cancel'] exact n.gcd_dvd_left m · rwa [← addOrderOf_pos_iff, addOrderOf_period_div hn] theorem addOrderOf_div_of_gcd_eq_one {m n : ℕ} (hn : 0 < n) (h : m.gcd n = 1) : addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by convert gcd_mul_addOrderOf_div_eq p m hn rw [h, one_mul] theorem addOrderOf_div_of_gcd_eq_one' {m : ℤ} {n : ℕ} (hn : 0 < n) (h : m.natAbs.gcd n = 1) : addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by cases m · simp only [Int.ofNat_eq_coe, Int.cast_natCast, Int.natAbs_natCast] at h ⊢ exact addOrderOf_div_of_gcd_eq_one hn h · simp only [Int.cast_negSucc, neg_div, neg_mul, coe_neg, addOrderOf_neg] exact addOrderOf_div_of_gcd_eq_one hn h theorem addOrderOf_coe_rat {q : ℚ} : addOrderOf (↑(↑q * p) : AddCircle p) = q.den := by have : (↑(q.den : ℤ) : 𝕜) ≠ 0 := by norm_cast exact q.pos.ne.symm rw [← q.num_divInt_den, Rat.cast_divInt_of_ne_zero _ this, Int.cast_natCast, Rat.num_divInt_den, addOrderOf_div_of_gcd_eq_one' q.pos q.reduced] theorem nsmul_eq_zero_iff {u : AddCircle p} {n : ℕ} (h : 0 < n) : n • u = 0 ↔ ∃ m < n, ↑(↑m / ↑n * p) = u := by refine ⟨QuotientAddGroup.induction_on u fun k hk ↦ ?_, ?_⟩ · rw [← addOrderOf_dvd_iff_nsmul_eq_zero] rintro ⟨m, -, rfl⟩ constructor; rw [mul_comm, eq_comm] exact gcd_mul_addOrderOf_div_eq p m h rw [← coe_nsmul, coe_eq_zero_iff] at hk obtain ⟨a, ha⟩ := hk refine ⟨a.natMod n, Int.natMod_lt h.ne', ?_⟩ have h0 : (n : 𝕜) ≠ 0 := Nat.cast_ne_zero.2 h.ne' rw [nsmul_eq_mul, mul_comm, ← div_eq_iff h0, ← a.ediv_add_emod' n, add_smul, add_div, zsmul_eq_mul, Int.cast_mul, Int.cast_natCast, mul_assoc, ← mul_div, mul_comm _ p, mul_div_cancel_right₀ p h0] at ha rw [← ha, coe_add, ← Int.cast_natCast, Int.natMod, Int.toNat_of_nonneg, zsmul_eq_mul, mul_div_right_comm, eq_comm, add_eq_right, ←zsmul_eq_mul, coe_zsmul, coe_period, smul_zero] exact Int.emod_nonneg _ (by exact_mod_cast h.ne') theorem addOrderOf_eq_pos_iff {u : AddCircle p} {n : ℕ} (h : 0 < n) : addOrderOf u = n ↔ ∃ m < n, m.gcd n = 1 ∧ ↑(↑m / ↑n * p) = u := by refine ⟨QuotientAddGroup.induction_on u ?_, ?_⟩ · rintro ⟨m, -, h₁, rfl⟩ exact addOrderOf_div_of_gcd_eq_one h h₁ rintro k rfl obtain ⟨m, hm, hk⟩ := (nsmul_eq_zero_iff h).mp (addOrderOf_nsmul_eq_zero (k : AddCircle p)) refine ⟨m, hm, mul_right_cancel₀ h.ne' ?_, hk⟩ convert gcd_mul_addOrderOf_div_eq p m h using 1 · rw [hk] · apply one_mul theorem exists_gcd_eq_one_of_isOfFinAddOrder {u : AddCircle p} (h : IsOfFinAddOrder u) : ∃ m : ℕ, m.gcd (addOrderOf u) = 1 ∧ m < addOrderOf u ∧ ↑((m : 𝕜) / addOrderOf u * p) = u := let ⟨m, hl, hg, he⟩ := (addOrderOf_eq_pos_iff h.addOrderOf_pos).1 rfl ⟨m, hg, hl, he⟩ lemma not_isOfFinAddOrder_iff_forall_rat_ne_div {a : 𝕜} : ¬ IsOfFinAddOrder (a : AddCircle p) ↔ ∀ q : ℚ, (q : 𝕜) ≠ a / p := by simp +contextual [← QuotientAddGroup.mk_zsmul, mul_comm (Int.cast _), mem_zmultiples_iff, eq_div_iff (Fact.out : 0 < p).ne', isOfFinAddOrder_iff_zsmul_eq_zero, Rat.forall, div_eq_iff, div_mul_eq_mul_div] grind lemma isOfFinAddOrder_iff_exists_rat_eq_div {a : 𝕜} : IsOfFinAddOrder (a : AddCircle p) ↔ ∃ q : ℚ, (q : 𝕜) = a / p := by simpa using not_isOfFinAddOrder_iff_forall_rat_ne_div.not_right @[deprecated not_isOfFinAddOrder_iff_forall_rat_ne_div (since := "2025-08-13")] theorem addOrderOf_coe_eq_zero_iff_forall_rat_ne_div {a : 𝕜} : addOrderOf (a : AddCircle p) = 0 ↔ ∀ q : ℚ, (q : 𝕜) ≠ a / p := by simp [not_isOfFinAddOrder_iff_forall_rat_ne_div] variable (p) /-- The natural bijection between points of order `n` and natural numbers less than and coprime to `n`. The inverse of the map sends `m ↦ (m/n * p : AddCircle p)` where `m` is coprime to `n` and satisfies `0 ≤ m < n`. -/ def setAddOrderOfEquiv {n : ℕ} (hn : 0 < n) : { u : AddCircle p | addOrderOf u = n } ≃ { m | m < n ∧ m.gcd n = 1 } := Equiv.symm <| Equiv.ofBijective (fun m => ⟨↑((m : 𝕜) / n * p), addOrderOf_div_of_gcd_eq_one hn m.prop.2⟩) (by refine ⟨fun m₁ m₂ h => Subtype.ext ?_, fun u => ?_⟩ · simp_rw [Subtype.mk_eq_mk, natCast_div_mul_eq_nsmul] at h refine nsmul_injOn_Iio_addOrderOf ?_ ?_ h <;> rw [addOrderOf_period_div hn] exacts [m₁.2.1, m₂.2.1] · obtain ⟨m, hmn, hg, he⟩ := (addOrderOf_eq_pos_iff hn).mp u.2 exact ⟨⟨m, hmn, hg⟩, Subtype.ext he⟩) @[simp] theorem card_addOrderOf_eq_totient {n : ℕ} : Nat.card { u : AddCircle p // addOrderOf u = n } = n.totient := by rcases n.eq_zero_or_pos with (rfl | hn) · simp only [Nat.totient_zero, addOrderOf_eq_zero_iff] rcases em (∃ u : AddCircle p, ¬IsOfFinAddOrder u) with (⟨u, hu⟩ | h) · have : Infinite { u : AddCircle p // ¬IsOfFinAddOrder u } := by rw [← coe_setOf, infinite_coe_iff] exact infinite_not_isOfFinAddOrder hu exact Nat.card_eq_zero_of_infinite · have : IsEmpty { u : AddCircle p // ¬IsOfFinAddOrder u } := by simpa [isEmpty_subtype] using h exact Nat.card_of_isEmpty · rw [← coe_setOf, Nat.card_congr (setAddOrderOfEquiv p hn), n.totient_eq_card_lt_and_coprime] simp only [Nat.gcd_comm] theorem finite_setOf_addOrderOf_eq {n : ℕ} (hn : 0 < n) : {u : AddCircle p | addOrderOf u = n}.Finite := finite_coe_iff.mp <| Nat.finite_of_card_ne_zero <| by simp [hn.ne'] @[deprecated (since := "2025-03-26")] alias finite_setOf_add_order_eq := finite_setOf_addOrderOf_eq theorem finite_torsion {n : ℕ} (hn : 0 < n) : { u : AddCircle p | n • u = 0 }.Finite := by convert Set.finite_range (fun m : Fin n ↦ (↑(↑m / ↑n * p) : AddCircle p)) simp_rw [nsmul_eq_zero_iff hn, range, Fin.exists_iff, exists_prop] end FiniteOrderPoints end LinearOrderedField end AddCircle section IdentifyIccEnds /-! This section proves that for any `a`, the natural map from `[a, a + p] ⊂ 𝕜` to `AddCircle p` gives an identification of `AddCircle p`, as a topological space, with the quotient of `[a, a + p]` by the equivalence relation identifying the endpoints. -/ namespace AddCircle variable [AddCommGroup 𝕜] [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] (p a : 𝕜) [hp : Fact (0 < p)] local notation "𝕋" => AddCircle p /-- The relation identifying the endpoints of `Icc a (a + p)`. -/ inductive EndpointIdent : Icc a (a + p) → Icc a (a + p) → Prop | mk : EndpointIdent ⟨a, left_mem_Icc.mpr <| le_add_of_nonneg_right hp.out.le⟩ ⟨a + p, right_mem_Icc.mpr <| le_add_of_nonneg_right hp.out.le⟩ variable [Archimedean 𝕜] /-- The equivalence between `AddCircle p` and the quotient of `[a, a + p]` by the relation identifying the endpoints. -/ def equivIccQuot : 𝕋 ≃ Quot (EndpointIdent p a) where toFun x := Quot.mk _ <| inclusion Ico_subset_Icc_self (equivIco _ _ x) invFun x := Quot.liftOn x (↑) <| by rintro _ _ ⟨_⟩ exact (coe_add_period p a).symm left_inv := (equivIco p a).symm_apply_apply right_inv := Quot.ind <| by rintro ⟨x, hx⟩ rcases ne_or_eq x (a + p) with (h | rfl) · revert x dsimp only intro x hx h congr ext1 apply congr_arg Subtype.val ((equivIco p a).right_inv ⟨x, hx.1, hx.2.lt_of_ne h⟩) · rw [← Quot.sound EndpointIdent.mk] dsimp only congr ext1 apply congr_arg Subtype.val ((equivIco p a).right_inv ⟨a, le_refl a, lt_add_of_pos_right a hp.out⟩) theorem equivIccQuot_comp_mk_eq_toIcoMod : equivIccQuot p a ∘ Quotient.mk'' = fun x => Quot.mk _ ⟨toIcoMod hp.out a x, Ico_subset_Icc_self <| toIcoMod_mem_Ico _ _ x⟩ := rfl theorem equivIccQuot_comp_mk_eq_toIocMod : equivIccQuot p a ∘ Quotient.mk'' = fun x => Quot.mk _ ⟨toIocMod hp.out a x, Ioc_subset_Icc_self <| toIocMod_mem_Ioc _ _ x⟩ := by rw [equivIccQuot_comp_mk_eq_toIcoMod] funext x by_cases h : a ≡ x [PMOD p] · simp_rw [(modEq_iff_toIcoMod_eq_left hp.out).1 h, (modEq_iff_toIocMod_eq_right hp.out).1 h] exact Quot.sound EndpointIdent.mk · simp_rw [(not_modEq_iff_toIcoMod_eq_toIocMod hp.out).1 h] /-- The natural map from `[a, a + p] ⊂ 𝕜` with endpoints identified to `𝕜 / ℤ • p`, as a homeomorphism of topological spaces. -/ def homeoIccQuot [TopologicalSpace 𝕜] [OrderTopology 𝕜] : 𝕋 ≃ₜ Quot (EndpointIdent p a) where toEquiv := equivIccQuot p a continuous_toFun := by simp_rw [isQuotientMap_quotient_mk'.continuous_iff, continuous_iff_continuousAt, continuousAt_iff_continuous_left_right] intro x; constructor on_goal 1 => erw [equivIccQuot_comp_mk_eq_toIocMod] on_goal 2 => erw [equivIccQuot_comp_mk_eq_toIcoMod] all_goals apply continuous_quot_mk.continuousAt.comp_continuousWithinAt rw [IsInducing.subtypeVal.continuousWithinAt_iff] · apply continuous_left_toIocMod · apply continuous_right_toIcoMod continuous_invFun := continuous_quot_lift _ ((AddCircle.continuous_mk' p).comp continuous_subtype_val) /-! We now show that a continuous function on `[a, a + p]` satisfying `f a = f (a + p)` is the pullback of a continuous function on `AddCircle p`. -/ variable {p a} theorem liftIco_eq_lift_Icc {f : 𝕜 → B} (h : f a = f (a + p)) : liftIco p a f = Quot.lift (restrict (Icc a <| a + p) f) (by rintro _ _ ⟨_⟩ exact h) ∘ equivIccQuot p a := rfl theorem liftIco_zero_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ico 0 p) : liftIco p 0 f ↑x = f x := liftIco_coe_apply (by rwa [zero_add]) variable [TopologicalSpace 𝕜] [OrderTopology 𝕜] theorem liftIco_continuous [TopologicalSpace B] {f : 𝕜 → B} (hf : f a = f (a + p)) (hc : ContinuousOn f <| Icc a (a + p)) : Continuous (liftIco p a f) := by rw [liftIco_eq_lift_Icc hf] refine Continuous.comp ?_ (homeoIccQuot p a).continuous_toFun exact continuous_coinduced_dom.mpr (continuousOn_iff_continuous_restrict.mp hc) theorem liftIco_zero_continuous [TopologicalSpace B] {f : 𝕜 → B} (hf : f 0 = f p) (hc : ContinuousOn f <| Icc 0 p) : Continuous (liftIco p 0 f) := liftIco_continuous (by rwa [zero_add] : f 0 = f (0 + p)) (by rwa [zero_add]) end AddCircle end IdentifyIccEnds
LinearLocallyFinite.lean
/- Copyright (c) 2022 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.Countable.Basic import Mathlib.Data.Finset.Max import Mathlib.Data.Fintype.Pigeonhole import Mathlib.Logic.Encodable.Basic import Mathlib.Order.Interval.Finset.Defs import Mathlib.Order.SuccPred.Archimedean /-! # Linear locally finite orders We prove that a `LinearOrder` which is a `LocallyFiniteOrder` also verifies * `SuccOrder` * `PredOrder` * `IsSuccArchimedean` * `IsPredArchimedean` * `Countable` Furthermore, we show that there is an `OrderIso` between such an order and a subset of `ℤ`. ## Main definitions * `toZ i0 i`: in a linear order on which we can define predecessors and successors and which is succ-archimedean, we can assign a unique integer `toZ i0 i` to each element `i : ι` while respecting the order, starting from `toZ i0 i0 = 0`. ## Main results Results about linear locally finite orders: * `LinearLocallyFiniteOrder.SuccOrder`: a linear locally finite order has a successor function. * `LinearLocallyFiniteOrder.PredOrder`: a linear locally finite order has a predecessor function. * `LinearLocallyFiniteOrder.isSuccArchimedean`: a linear locally finite order is succ-archimedean. * `LinearOrder.pred_archimedean_of_succ_archimedean`: a succ-archimedean linear order is also pred-archimedean. * `countable_of_linear_succ_pred_arch` : a succ-archimedean linear order is countable. About `toZ`: * `orderIsoRangeToZOfLinearSuccPredArch`: `toZ` defines an `OrderIso` between `ι` and its range. * `orderIsoNatOfLinearSuccPredArch`: if the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. * `orderIsoIntOfLinearSuccPredArch`: if the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. * `orderIsoRangeOfLinearSuccPredArch`: if the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range ((toZ ⊥ ⊤).toNat + 1)`. -/ open Order variable {ι : Type*} [LinearOrder ι] namespace LinearOrder variable [SuccOrder ι] [PredOrder ι] instance (priority := 100) isPredArchimedean_of_isSuccArchimedean [IsSuccArchimedean ι] : IsPredArchimedean ι where exists_pred_iterate_of_le {i j} hij := by have h_exists := exists_succ_iterate_of_le hij obtain ⟨n, hn_eq, hn_lt_ne⟩ : ∃ n, succ^[n] i = j ∧ ∀ m < n, succ^[m] i ≠ j := ⟨Nat.find h_exists, Nat.find_spec h_exists, fun m hmn ↦ Nat.find_min h_exists hmn⟩ refine ⟨n, ?_⟩ rw [← hn_eq] cases n with | zero => simp only [Function.iterate_zero, id] | succ n => rw [pred_succ_iterate_of_not_isMax] rw [Nat.succ_sub_succ_eq_sub, tsub_zero] suffices succ^[n] i < succ^[n.succ] i from not_isMax_of_lt this refine lt_of_le_of_ne ?_ ?_ · rw [Function.iterate_succ_apply'] exact le_succ _ · rw [hn_eq] exact hn_lt_ne _ (Nat.lt_succ_self n) instance isSuccArchimedean_of_isPredArchimedean [IsPredArchimedean ι] : IsSuccArchimedean ι := inferInstanceAs (IsSuccArchimedean ιᵒᵈᵒᵈ) /-- In a linear `SuccOrder` that's also a `PredOrder`, `IsSuccArchimedean` and `IsPredArchimedean` are equivalent. -/ theorem isSuccArchimedean_iff_isPredArchimedean : IsSuccArchimedean ι ↔ IsPredArchimedean ι where mp _ := isPredArchimedean_of_isSuccArchimedean mpr _ := isSuccArchimedean_of_isPredArchimedean end LinearOrder namespace LinearLocallyFiniteOrder /-- Successor in a linear order. This defines a true successor only when `i` is isolated from above, i.e. when `i` is not the greatest lower bound of `(i, ∞)`. -/ noncomputable def succFn (i : ι) : ι := (exists_glb_Ioi i).choose theorem succFn_spec (i : ι) : IsGLB (Set.Ioi i) (succFn i) := (exists_glb_Ioi i).choose_spec theorem le_succFn (i : ι) : i ≤ succFn i := by rw [le_isGLB_iff (succFn_spec i), mem_lowerBounds] exact fun x hx ↦ le_of_lt hx theorem isGLB_Ioc_of_isGLB_Ioi {i j k : ι} (hij_lt : i < j) (h : IsGLB (Set.Ioi i) k) : IsGLB (Set.Ioc i j) k := by simp_rw [IsGLB, IsGreatest, mem_upperBounds, mem_lowerBounds] at h ⊢ refine ⟨fun x hx ↦ h.1 x hx.1, fun x hx ↦ h.2 x ?_⟩ intro y hy rcases le_or_gt y j with h_le | h_lt · exact hx y ⟨hy, h_le⟩ · exact le_trans (hx j ⟨hij_lt, le_rfl⟩) h_lt.le theorem isMax_of_succFn_le [LocallyFiniteOrder ι] (i : ι) (hi : succFn i ≤ i) : IsMax i := by refine fun j _ ↦ not_lt.mp fun hij_lt ↦ ?_ have h_succFn_eq : succFn i = i := le_antisymm hi (le_succFn i) have h_glb : IsGLB (Finset.Ioc i j : Set ι) i := by rw [Finset.coe_Ioc] have h := succFn_spec i rw [h_succFn_eq] at h exact isGLB_Ioc_of_isGLB_Ioi hij_lt h have hi_mem : i ∈ Finset.Ioc i j := by refine Finset.isGLB_mem _ h_glb ?_ exact ⟨_, Finset.mem_Ioc.mpr ⟨hij_lt, le_rfl⟩⟩ rw [Finset.mem_Ioc] at hi_mem exact lt_irrefl i hi_mem.1 theorem succFn_le_of_lt (i j : ι) (hij : i < j) : succFn i ≤ j := by have h := succFn_spec i rw [IsGLB, IsGreatest, mem_lowerBounds] at h exact h.1 j hij theorem le_of_lt_succFn (j i : ι) (hij : j < succFn i) : j ≤ i := by rw [lt_isGLB_iff (succFn_spec i)] at hij obtain ⟨k, hk_lb, hk⟩ := hij rw [mem_lowerBounds] at hk_lb exact not_lt.mp fun hi_lt_j ↦ not_le.mpr hk (hk_lb j hi_lt_j) variable (ι) in /-- A locally finite order is a `SuccOrder`. This is not an instance, because its `succ` field conflicts with computable `SuccOrder` structures on `ℕ` and `ℤ`. -/ noncomputable def succOrder [LocallyFiniteOrder ι] : SuccOrder ι where succ := succFn le_succ := le_succFn max_of_succ_le h := isMax_of_succFn_le _ h succ_le_of_lt h := succFn_le_of_lt _ _ h variable (ι) in /-- A locally finite order is a `PredOrder`. This is not an instance, because its `succ` field conflicts with computable `PredOrder` structures on `ℕ` and `ℤ`. -/ noncomputable def predOrder [LocallyFiniteOrder ι] : PredOrder ι := letI := succOrder (ι := ιᵒᵈ) inferInstanceAs (PredOrder ιᵒᵈᵒᵈ) instance (priority := 100) [LocallyFiniteOrder ι] [SuccOrder ι] : IsSuccArchimedean ι where exists_succ_iterate_of_le := by intro i j hij rw [le_iff_lt_or_eq] at hij rcases hij with hij | hij swap · refine ⟨0, ?_⟩ simpa only [Function.iterate_zero, id] using hij by_contra! h have h_lt : ∀ n, succ^[n] i < j := fun n ↦ by induction n with | zero => simpa only [Function.iterate_zero, id] using hij | succ n hn => refine lt_of_le_of_ne ?_ (h _) rw [Function.iterate_succ', Function.comp_apply] exact succ_le_of_lt hn have h_mem : ∀ n, succ^[n] i ∈ Finset.Icc i j := fun n ↦ Finset.mem_Icc.mpr ⟨le_succ_iterate n i, (h_lt n).le⟩ obtain ⟨n, m, hnm, h_eq⟩ : ∃ n m, n < m ∧ succ^[n] i = succ^[m] i := by let f : ℕ → Finset.Icc i j := fun n ↦ ⟨succ^[n] i, h_mem n⟩ obtain ⟨n, m, hnm_ne, hfnm⟩ : ∃ n m, n ≠ m ∧ f n = f m := Finite.exists_ne_map_eq_of_infinite f have hnm_eq : succ^[n] i = succ^[m] i := by simpa only [f, Subtype.mk_eq_mk] using hfnm rcases le_total n m with h_le | h_le · exact ⟨n, m, lt_of_le_of_ne h_le hnm_ne, hnm_eq⟩ · exact ⟨m, n, lt_of_le_of_ne h_le hnm_ne.symm, hnm_eq.symm⟩ have h_max : IsMax (succ^[n] i) := isMax_iterate_succ_of_eq_of_ne h_eq hnm.ne exact not_le.mpr (h_lt n) (h_max (h_lt n).le) instance (priority := 100) [LocallyFiniteOrder ι] [PredOrder ι] : IsPredArchimedean ι := inferInstanceAs (IsPredArchimedean ιᵒᵈᵒᵈ) end LinearLocallyFiniteOrder section toZ -- Requiring either of `IsSuccArchimedean` or `IsPredArchimedean` is equivalent. variable [SuccOrder ι] [IsSuccArchimedean ι] [PredOrder ι] {i0 i : ι} -- For "to_Z" /-- `toZ` numbers elements of `ι` according to their order, starting from `i0`. We prove in `orderIsoRangeToZOfLinearSuccPredArch` that this defines an `OrderIso` between `ι` and the range of `toZ`. -/ def toZ (i0 i : ι) : ℤ := dite (i0 ≤ i) (fun hi ↦ Nat.find (exists_succ_iterate_of_le hi)) fun hi ↦ -Nat.find (exists_pred_iterate_of_le (α := ι) (not_le.mp hi).le) theorem toZ_of_ge (hi : i0 ≤ i) : toZ i0 i = Nat.find (exists_succ_iterate_of_le hi) := dif_pos hi theorem toZ_of_lt (hi : i < i0) : toZ i0 i = -Nat.find (exists_pred_iterate_of_le (α := ι) hi.le) := dif_neg (not_le.mpr hi) @[simp] theorem toZ_of_eq : toZ i0 i0 = 0 := by rw [toZ_of_ge le_rfl] norm_cast refine le_antisymm (Nat.find_le ?_) (zero_le _) rw [Function.iterate_zero, id] theorem iterate_succ_toZ (i : ι) (hi : i0 ≤ i) : succ^[(toZ i0 i).toNat] i0 = i := by rw [toZ_of_ge hi, Int.toNat_natCast] exact Nat.find_spec (exists_succ_iterate_of_le hi) theorem iterate_pred_toZ (i : ι) (hi : i < i0) : pred^[(-toZ i0 i).toNat] i0 = i := by rw [toZ_of_lt hi, neg_neg, Int.toNat_natCast] exact Nat.find_spec (exists_pred_iterate_of_le hi.le) lemma toZ_nonneg (hi : i0 ≤ i) : 0 ≤ toZ i0 i := by rw [toZ_of_ge hi]; exact Int.natCast_nonneg _ theorem toZ_neg (hi : i < i0) : toZ i0 i < 0 := by refine lt_of_le_of_ne ?_ ?_ · rw [toZ_of_lt hi] omega · by_contra h have h_eq := iterate_pred_toZ i hi rw [← h_eq, h] at hi simp only [neg_zero, Int.toNat_zero, Function.iterate_zero, id, lt_self_iff_false] at hi theorem toZ_iterate_succ_le (n : ℕ) : toZ i0 (succ^[n] i0) ≤ n := by rw [toZ_of_ge (le_succ_iterate _ _)] norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_pred_ge (n : ℕ) : -(n : ℤ) ≤ toZ i0 (pred^[n] i0) := by rcases le_or_gt i0 (pred^[n] i0) with h | h · have h_eq : pred^[n] i0 = i0 := le_antisymm (pred_iterate_le _ _) h rw [h_eq, toZ_of_eq] omega · rw [toZ_of_lt h] refine Int.neg_le_neg ?_ norm_cast exact Nat.find_min' _ rfl theorem toZ_iterate_succ_of_not_isMax (n : ℕ) (hn : ¬IsMax (succ^[n] i0)) : toZ i0 (succ^[n] i0) = n := by let m := (toZ i0 (succ^[n] i0)).toNat have h_eq : succ^[m] i0 = succ^[n] i0 := iterate_succ_toZ _ (le_succ_iterate _ _) by_cases hmn : m = n · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_ge (le_succ_iterate _ _), max_eq_left] exact Int.natCast_nonneg _ suffices IsMax (succ^[n] i0) from absurd this hn exact isMax_iterate_succ_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem toZ_iterate_pred_of_not_isMin (n : ℕ) (hn : ¬IsMin (pred^[n] i0)) : toZ i0 (pred^[n] i0) = -n := by rcases n with - | n · simp have : pred^[n.succ] i0 < i0 := by refine lt_of_le_of_ne (pred_iterate_le _ _) fun h_pred_iterate_eq ↦ hn ?_ have h_pred_eq_pred : pred^[n.succ] i0 = pred^[0] i0 := by rwa [Function.iterate_zero, id] exact isMin_iterate_pred_of_eq_of_ne h_pred_eq_pred (Nat.succ_ne_zero n) let m := (-toZ i0 (pred^[n.succ] i0)).toNat have h_eq : pred^[m] i0 = pred^[n.succ] i0 := iterate_pred_toZ _ this by_cases hmn : m = n + 1 · nth_rw 2 [← hmn] rw [Int.toNat_eq_max, toZ_of_lt this, max_eq_left, neg_neg] rw [neg_neg] exact Int.natCast_nonneg _ · suffices IsMin (pred^[n.succ] i0) from absurd this hn exact isMin_iterate_pred_of_eq_of_ne h_eq.symm (Ne.symm hmn) theorem le_of_toZ_le {j : ι} (h_le : toZ i0 i ≤ toZ i0 j) : i ≤ j := by rcases le_or_gt i0 i with hi | hi <;> rcases le_or_gt i0 j with hj | hj · rw [← iterate_succ_toZ i hi, ← iterate_succ_toZ j hj] exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ _) (Int.toNat_le_toNat h_le) · exact absurd ((toZ_neg hj).trans_le (toZ_nonneg hi)) (not_lt.mpr h_le) · exact hi.le.trans hj · rw [← iterate_pred_toZ i hi, ← iterate_pred_toZ j hj] refine Monotone.antitone_iterate_of_map_le pred_mono (pred_le _) (Int.toNat_le_toNat ?_) exact Int.neg_le_neg h_le theorem toZ_mono {i j : ι} (h_le : i ≤ j) : toZ i0 i ≤ toZ i0 j := by by_cases hi_max : IsMax i · rw [le_antisymm h_le (hi_max h_le)] by_cases hj_min : IsMin j · rw [le_antisymm h_le (hj_min h_le)] rcases le_or_gt i0 i with hi | hi <;> rcases le_or_gt i0 j with hj | hj · let m := Nat.find (exists_succ_iterate_of_le h_le) have hm : succ^[m] i = j := Nat.find_spec (exists_succ_iterate_of_le h_le) have hj_eq : j = succ^[(toZ i0 i).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_succ_toZ i hi] rw [Function.iterate_add] rfl by_contra h by_cases hm0 : m = 0 · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hi_max (max_of_succ_le (le_trans ?_ (@le_of_toZ_le _ _ _ _ _ i0 j i ?_))) · have h_succ_le : succ^[(toZ i0 i).toNat + 1] i0 ≤ j := by rw [hj_eq] refine Monotone.monotone_iterate_of_le_map succ_mono (le_succ i0) (add_le_add_left ?_ _) exact Nat.one_le_iff_ne_zero.mpr hm0 rwa [Function.iterate_succ', Function.comp_apply, iterate_succ_toZ i hi] at h_succ_le · exact le_of_not_ge h · exact absurd h_le (not_le.mpr (hj.trans_le hi)) · exact (toZ_neg hi).le.trans (toZ_nonneg hj) · let m := Nat.find (exists_pred_iterate_of_le (α := ι) h_le) have hm : pred^[m] j = i := Nat.find_spec (exists_pred_iterate_of_le (α := ι) h_le) have hj_eq : i = pred^[(-toZ i0 j).toNat + m] i0 := by rw [← hm, add_comm] nth_rw 1 [← iterate_pred_toZ j hj] rw [Function.iterate_add] rfl by_contra h by_cases hm0 : m = 0 · rw [hm0, Function.iterate_zero, id] at hm rw [hm] at h exact h (le_of_eq rfl) refine hj_min (min_of_le_pred ?_) refine (@le_of_toZ_le _ _ _ _ _ i0 j i ?_).trans ?_ · exact le_of_not_ge h · have h_le_pred : i ≤ pred^[(-toZ i0 j).toNat + 1] i0 := by rw [hj_eq] refine Monotone.antitone_iterate_of_map_le pred_mono (pred_le i0) (add_le_add_left ?_ _) exact Nat.one_le_iff_ne_zero.mpr hm0 rwa [Function.iterate_succ', Function.comp_apply, iterate_pred_toZ j hj] at h_le_pred theorem toZ_le_iff (i j : ι) : toZ i0 i ≤ toZ i0 j ↔ i ≤ j := ⟨le_of_toZ_le, toZ_mono⟩ theorem toZ_iterate_succ [NoMaxOrder ι] (n : ℕ) : toZ i0 (succ^[n] i0) = n := toZ_iterate_succ_of_not_isMax n (not_isMax _) theorem toZ_iterate_pred [NoMinOrder ι] (n : ℕ) : toZ i0 (pred^[n] i0) = -n := toZ_iterate_pred_of_not_isMin n (not_isMin _) theorem injective_toZ : Function.Injective (toZ i0) := fun _ _ h ↦ le_antisymm (le_of_toZ_le h.le) (le_of_toZ_le h.symm.le) end toZ section OrderIso variable [SuccOrder ι] [PredOrder ι] [IsSuccArchimedean ι] /-- `toZ` defines an `OrderIso` between `ι` and its range. -/ noncomputable def orderIsoRangeToZOfLinearSuccPredArch [hι : Nonempty ι] : ι ≃o Set.range (toZ hι.some) where toEquiv := Equiv.ofInjective _ injective_toZ map_rel_iff' := by intro i j; exact toZ_le_iff i j instance (priority := 100) countable_of_linear_succ_pred_arch : Countable ι := by rcases isEmpty_or_nonempty ι with _ | hι · infer_instance · exact Countable.of_equiv _ orderIsoRangeToZOfLinearSuccPredArch.symm.toEquiv /-- If the order has neither bot nor top, `toZ` defines an `OrderIso` between `ι` and `ℤ`. -/ noncomputable def orderIsoIntOfLinearSuccPredArch [NoMaxOrder ι] [NoMinOrder ι] [hι : Nonempty ι] : ι ≃o ℤ where toFun := toZ hι.some invFun n := if 0 ≤ n then succ^[n.toNat] hι.some else pred^[(-n).toNat] hι.some left_inv i := by rcases le_or_gt hι.some i with hi | hi · have h_nonneg : 0 ≤ toZ hι.some i := toZ_nonneg hi simp_rw [if_pos h_nonneg] exact iterate_succ_toZ i hi · have h_neg : toZ hι.some i < 0 := toZ_neg hi simp_rw [if_neg (not_le.mpr h_neg)] exact iterate_pred_toZ i hi right_inv n := by rcases le_or_gt 0 n with hn | hn · simp_rw [if_pos hn] rw [toZ_iterate_succ] exact Int.toNat_of_nonneg hn · simp_rw [if_neg (not_le.mpr hn)] rw [toZ_iterate_pred] simp only [hn.le, Int.toNat_of_nonneg, Int.neg_nonneg_of_nonpos, Int.neg_neg] map_rel_iff' := by intro i j; exact toZ_le_iff i j /-- If the order has a bot but no top, `toZ` defines an `OrderIso` between `ι` and `ℕ`. -/ def orderIsoNatOfLinearSuccPredArch [NoMaxOrder ι] [OrderBot ι] : ι ≃o ℕ where toFun i := (toZ ⊥ i).toNat invFun n := succ^[n] ⊥ left_inv i := by dsimp only exact iterate_succ_toZ i bot_le right_inv n := by dsimp only rw [toZ_iterate_succ] exact Int.toNat_natCast n map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] /-- If the order has both a bot and a top, `toZ` gives an `OrderIso` between `ι` and `Finset.range n` for some `n`. -/ def orderIsoRangeOfLinearSuccPredArch [OrderBot ι] [OrderTop ι] : ι ≃o Finset.range ((toZ ⊥ (⊤ : ι)).toNat + 1) where toFun i := ⟨(toZ ⊥ i).toNat, Finset.mem_range_succ_iff.mpr (Int.toNat_le_toNat ((toZ_le_iff _ _).mpr le_top))⟩ invFun n := succ^[n] ⊥ left_inv i := iterate_succ_toZ i bot_le right_inv n := by ext1 simp only refine le_antisymm ?_ ?_ · rw [Int.toNat_le] exact toZ_iterate_succ_le _ by_cases hn_max : IsMax (succ^[↑n] (⊥ : ι)) · rw [← isTop_iff_isMax, isTop_iff_eq_top] at hn_max rw [hn_max] exact Nat.lt_succ_iff.mp (Finset.mem_range.mp n.prop) · rw [toZ_iterate_succ_of_not_isMax _ hn_max] simp only [Int.toNat_natCast, le_refl] map_rel_iff' := by intro i j simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Int.toNat_le] rw [← @toZ_le_iff ι _ _ _ _ ⊥, Int.toNat_of_nonneg (toZ_nonneg bot_le)] end OrderIso instance (priority := 100) Countable.of_linearOrder_locallyFiniteOrder [LocallyFiniteOrder ι] : Countable ι := have := LinearLocallyFiniteOrder.succOrder ι have := LinearLocallyFiniteOrder.predOrder ι countable_of_linear_succ_pred_arch
Coeff.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.Polynomial.Coeff import Mathlib.Algebra.Polynomial.Eval.Defs /-! # Evaluation of polynomials This file contains results on the interaction of `Polynomial.eval` and `Polynomial.coeff` -/ noncomputable section open Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v w y variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section variable [Semiring S] variable (f : R →+* S) (x : S) @[simp] theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by simp +contextual only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero, mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff, RingHom.map_zero, imp_true_iff] @[simp] theorem eval₂_C_X : eval₂ C X p = p := Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by rw [eval₂_monomial, ← smul_X_eq_monomial, C_mul'] end section Eval variable {x : R} theorem coeff_zero_eq_eval_zero (p : R[X]) : coeff p 0 = p.eval 0 := calc coeff p 0 = coeff p 0 * 0 ^ 0 := by simp _ = p.eval 0 := by symm rw [eval_eq_sum] exact Finset.sum_eq_single _ (fun b _ hb => by simp [zero_pow hb]) (by simp) theorem zero_isRoot_of_coeff_zero_eq_zero {p : R[X]} (hp : p.coeff 0 = 0) : IsRoot p 0 := by rwa [coeff_zero_eq_eval_zero] at hp end Eval section Map variable [Semiring S] variable (f : R →+* S) @[simp] theorem coeff_map (n : ℕ) : coeff (p.map f) n = f (coeff p n) := by rw [map, eval₂_def, coeff_sum, sum] simp_all lemma coeff_map_eq_comp (p : R[X]) (f : R →+* S) : (p.map f).coeff = f ∘ p.coeff := by ext n; exact coeff_map .. theorem map_map [Semiring T] (g : S →+* T) (p : R[X]) : (p.map f).map g = p.map (g.comp f) := ext (by simp [coeff_map]) @[simp] theorem map_id : p.map (RingHom.id _) = p := by simp [Polynomial.ext_iff, coeff_map] /-- The polynomial ring over a finite product of rings is isomorphic to the product of polynomial rings over individual rings. -/ def piEquiv {ι} [Finite ι] (R : ι → Type*) [∀ i, Semiring (R i)] : (∀ i, R i)[X] ≃+* ∀ i, (R i)[X] := .ofBijective (Pi.ringHom fun i ↦ mapRingHom (Pi.evalRingHom R i)) ⟨fun p q h ↦ by ext n i; simpa using congr_arg (fun p ↦ coeff (p i) n) h, fun p ↦ ⟨.ofFinsupp (.ofSupportFinite (fun n i ↦ coeff (p i) n) <| (Set.finite_iUnion fun i ↦ (p i).support.finite_toSet).subset fun n hn ↦ by simp only [Set.mem_iUnion, Finset.mem_coe, mem_support_iff, Function.mem_support] at hn ⊢ contrapose! hn; exact funext hn), by ext i n; exact coeff_map _ _⟩⟩ theorem map_injective (hf : Function.Injective f) : Function.Injective (map f) := fun p q h => ext fun m => hf <| by rw [← coeff_map f, ← coeff_map f, h] theorem map_injective_iff : Function.Injective (map f) ↔ Function.Injective f := ⟨fun h r r' eq ↦ by simpa using h (a₁ := C r) (a₂ := C r') (by simpa), map_injective f⟩ theorem map_surjective (hf : Function.Surjective f) : Function.Surjective (map f) := fun p => p.induction_on' (by rintro _ _ ⟨p, rfl⟩ ⟨q, rfl⟩; exact ⟨p + q, Polynomial.map_add f⟩) fun n s ↦ let ⟨r, hr⟩ := hf s ⟨monomial n r, by rw [map_monomial f, hr]⟩ theorem map_surjective_iff : Function.Surjective (map f) ↔ Function.Surjective f := ⟨fun h s ↦ let ⟨p, h⟩ := h (C s); ⟨p.coeff 0, by simpa using congr(coeff $h 0)⟩, map_surjective f⟩ variable {f} protected theorem map_eq_zero_iff (hf : Function.Injective f) : p.map f = 0 ↔ p = 0 := map_eq_zero_iff (mapRingHom f) (map_injective f hf) protected theorem map_ne_zero_iff (hf : Function.Injective f) : p.map f ≠ 0 ↔ p ≠ 0 := (Polynomial.map_eq_zero_iff hf).not variable (f) @[simp] theorem mapRingHom_id : mapRingHom (RingHom.id R) = RingHom.id R[X] := RingHom.ext fun _x => map_id @[simp] theorem mapRingHom_comp [Semiring T] (f : S →+* T) (g : R →+* S) : (mapRingHom f).comp (mapRingHom g) = mapRingHom (f.comp g) := RingHom.ext <| Polynomial.map_map g f theorem eval₂_map [Semiring T] (g : S →+* T) (x : T) : (p.map f).eval₂ g x = p.eval₂ (g.comp f) x := by rw [eval₂_eq_eval_map, eval₂_eq_eval_map, map_map] @[simp] theorem eval_zero_map (f : R →+* S) (p : R[X]) : (p.map f).eval 0 = f (p.eval 0) := by simp [← coeff_zero_eq_eval_zero] @[simp] theorem eval_one_map (f : R →+* S) (p : R[X]) : (p.map f).eval 1 = f (p.eval 1) := by induction p using Polynomial.induction_on' with | add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | monomial n r => simp only [one_pow, mul_one, eval_monomial, map_monomial] @[simp] theorem eval_natCast_map (f : R →+* S) (p : R[X]) (n : ℕ) : (p.map f).eval (n : S) = f (p.eval n) := by induction p using Polynomial.induction_on' with | add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | monomial n r => simp only [map_natCast f, eval_monomial, map_monomial, f.map_pow, f.map_mul] @[simp] theorem eval_intCast_map {R S : Type*} [Ring R] [Ring S] (f : R →+* S) (p : R[X]) (i : ℤ) : (p.map f).eval (i : S) = f (p.eval i) := by induction p using Polynomial.induction_on' with | add p q hp hq => simp only [hp, hq, Polynomial.map_add, RingHom.map_add, eval_add] | monomial n r => simp only [map_intCast, eval_monomial, map_monomial, map_pow, map_mul] end Map section HomEval₂ variable [Semiring S] [Semiring T] (f : R →+* S) (g : S →+* T) (p) theorem hom_eval₂ (x : S) : g (p.eval₂ f x) = p.eval₂ (g.comp f) (g x) := by rw [← eval₂_map, eval₂_at_apply, eval_map] end HomEval₂ end Semiring section CommSemiring section Eval section variable [Semiring R] {p q : R[X]} {x : R} [Semiring S] (f : R →+* S) theorem eval₂_hom (x : R) : p.eval₂ f (f x) = f (p.eval x) := RingHom.comp_id f ▸ (hom_eval₂ p (RingHom.id R) f x).symm end section variable [CommSemiring R] {p q : R[X]} {x : R} [CommSemiring S] (f : R →+* S) theorem evalRingHom_zero : evalRingHom 0 = constantCoeff := DFunLike.ext _ _ fun p => p.coeff_zero_eq_eval_zero.symm end end Eval section Map theorem support_map_subset [Semiring R] [Semiring S] (f : R →+* S) (p : R[X]) : (map f p).support ⊆ p.support := by intro x contrapose! simp +contextual theorem support_map_of_injective [Semiring R] [Semiring S] (p : R[X]) {f : R →+* S} (hf : Function.Injective f) : (map f p).support = p.support := by simp_rw [Finset.ext_iff, mem_support_iff, coeff_map, ← map_zero f, hf.ne_iff, forall_const] variable [CommSemiring R] [CommSemiring S] (f : R →+* S) theorem IsRoot.map {f : R →+* S} {x : R} {p : R[X]} (h : IsRoot p x) : IsRoot (p.map f) (f x) := by rw [IsRoot, eval_map, eval₂_hom, h.eq_zero, f.map_zero] theorem IsRoot.of_map {R} [Ring R] {f : R →+* S} {x : R} {p : R[X]} (h : IsRoot (p.map f) (f x)) (hf : Function.Injective f) : IsRoot p x := by rwa [IsRoot, ← (injective_iff_map_eq_zero' f).mp hf, ← eval₂_hom, ← eval_map] theorem isRoot_map_iff {R : Type*} [CommRing R] {f : R →+* S} {x : R} {p : R[X]} (hf : Function.Injective f) : IsRoot (p.map f) (f x) ↔ IsRoot p x := ⟨fun h => h.of_map hf, fun h => h.map⟩ end Map end CommSemiring end Polynomial
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 -/ import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.NaturalTransformation import Mathlib.CategoryTheory.Monoidal.Opposite import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.CommSq /-! # Braided and symmetric monoidal categories The basic definitions of braided monoidal categories, and symmetric monoidal categories, as well as braided functors. ## Implementation note We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this. The rationale is that we are not carrying any additional data, just requiring a property. ## Future work * Construct the Drinfeld center of a monoidal category as a braided monoidal category. * Say something about pseudo-natural transformations. ## References * [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15] -/ universe v v₁ v₂ v₃ u u₁ u₂ u₃ namespace CategoryTheory open Category MonoidalCategory Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal /-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism `β_ X Y : X ⊗ Y ≅ Y ⊗ X` which is natural in both arguments, and also satisfies the two hexagon identities. -/ class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where /-- The braiding natural isomorphism. -/ braiding : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X braiding_naturality_right : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f ▷ X := by cat_disch braiding_naturality_left : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ▷ Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by cat_disch /-- The first hexagon identity. -/ hexagon_forward : ∀ X Y Z : C, (α_ X Y Z).hom ≫ (braiding X (Y ⊗ Z)).hom ≫ (α_ Y Z X).hom = ((braiding X Y).hom ▷ Z) ≫ (α_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by cat_disch /-- The second hexagon identity. -/ hexagon_reverse : ∀ X Y Z : C, (α_ X Y Z).inv ≫ (braiding (X ⊗ Y) Z).hom ≫ (α_ Z X Y).inv = (X ◁ (braiding Y Z).hom) ≫ (α_ X Z Y).inv ≫ ((braiding X Z).hom ▷ Y) := by cat_disch attribute [reassoc (attr := simp)] BraidedCategory.braiding_naturality_left BraidedCategory.braiding_naturality_right attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse open BraidedCategory @[inherit_doc] notation "β_" => BraidedCategory.braiding namespace BraidedCategory variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C] @[simp, reassoc] theorem braiding_tensor_left_hom (X Y Z : C) : (β_ (X ⊗ Y) Z).hom = (α_ X Y Z).hom ≫ X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom := by apply (cancel_epi (α_ X Y Z).inv).1 apply (cancel_mono (α_ Z X Y).inv).1 simp [hexagon_reverse] @[deprecated (since := "2025-06-24")] alias braiding_tensor_left := braiding_tensor_left_hom @[simp, reassoc] theorem braiding_tensor_right_hom (X Y Z : C) : (β_ X (Y ⊗ Z)).hom = (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv := by apply (cancel_epi (α_ X Y Z).hom).1 apply (cancel_mono (α_ Y Z X).hom).1 simp [hexagon_forward] @[deprecated (since := "2025-06-24")] alias braiding_tensor_right := braiding_tensor_right_hom @[simp, reassoc] theorem braiding_tensor_left_inv (X Y Z : C) : (β_ (X ⊗ Y) Z).inv = (α_ Z X Y).inv ≫ (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫ X ◁ (β_ Y Z).inv ≫ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[deprecated (since := "2025-06-24")] alias braiding_inv_tensor_left := braiding_tensor_left_inv @[simp, reassoc] theorem braiding_tensor_right_inv (X Y Z : C) : (β_ X (Y ⊗ Z)).inv = (α_ Y Z X).hom ≫ Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z ≫ (α_ X Y Z).hom := eq_of_inv_eq_inv (by simp) @[deprecated (since := "2025-06-24")] alias braiding_inv_tensor_right := braiding_tensor_right_inv @[reassoc (attr := simp)] theorem braiding_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ₘ g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g ⊗ₘ f) := by rw [tensorHom_def' f g, tensorHom_def g f] simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc] @[reassoc (attr := simp)] theorem braiding_inv_naturality_right (X : C) {Y Z : C} (f : Y ⟶ Z) : X ◁ f ≫ (β_ Z X).inv = (β_ Y X).inv ≫ f ▷ X := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_left f X @[reassoc (attr := simp)] theorem braiding_inv_naturality_left {X Y : C} (f : X ⟶ Y) (Z : C) : f ▷ Z ≫ (β_ Z Y).inv = (β_ Z X).inv ≫ Z ◁ f := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_right Z f @[reassoc (attr := simp)] theorem braiding_inv_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (f ⊗ₘ g) ≫ (β_ Y' Y).inv = (β_ X' X).inv ≫ (g ⊗ₘ f) := CommSq.w <| .vert_inv <| .mk <| braiding_naturality g f /-- In a braided monoidal category, the functors `tensorLeft X` and `tensorRight X` are isomorphic. -/ @[simps] def tensorLeftIsoTensorRight (X : C) : tensorLeft X ≅ tensorRight X where hom := { app Y := (β_ X Y).hom } inv := { app Y := (β_ X Y).inv } @[reassoc] theorem yang_baxter (X Y Z : C) : (α_ X Y Z).inv ≫ (β_ X Y).hom ▷ Z ≫ (α_ Y X Z).hom ≫ Y ◁ (β_ X Z).hom ≫ (α_ Y Z X).inv ≫ (β_ Y Z).hom ▷ X ≫ (α_ Z Y X).hom = X ◁ (β_ Y Z).hom ≫ (α_ X Z Y).inv ≫ (β_ X Z).hom ▷ Y ≫ (α_ Z X Y).hom ≫ Z ◁ (β_ X Y).hom := by rw [← braiding_tensor_right_hom_assoc X Y Z, ← cancel_mono (α_ Z Y X).inv] repeat rw [assoc] rw [Iso.hom_inv_id, comp_id, ← braiding_naturality_right, braiding_tensor_right_hom] theorem yang_baxter' (X Y Z : C) : (β_ X Y).hom ▷ Z ⊗≫ Y ◁ (β_ X Z).hom ⊗≫ (β_ Y Z).hom ▷ X = 𝟙 _ ⊗≫ (X ◁ (β_ Y Z).hom ⊗≫ (β_ X Z).hom ▷ Y ⊗≫ Z ◁ (β_ X Y).hom) ⊗≫ 𝟙 _ := by rw [← cancel_epi (α_ X Y Z).inv, ← cancel_mono (α_ Z Y X).hom] convert yang_baxter X Y Z using 1 all_goals monoidal theorem yang_baxter_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) ≪≫ (α_ Y Z X).symm ≪≫ whiskerRightIso (β_ Y Z) X ≪≫ (α_ Z Y X) = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y ≪≫ α_ Z X Y ≪≫ whiskerLeftIso Z (β_ X Y) := Iso.ext (yang_baxter X Y Z) theorem hexagon_forward_iso (X Y Z : C) : α_ X Y Z ≪≫ β_ X (Y ⊗ Z) ≪≫ α_ Y Z X = whiskerRightIso (β_ X Y) Z ≪≫ α_ Y X Z ≪≫ whiskerLeftIso Y (β_ X Z) := Iso.ext (hexagon_forward X Y Z) theorem hexagon_reverse_iso (X Y Z : C) : (α_ X Y Z).symm ≪≫ β_ (X ⊗ Y) Z ≪≫ (α_ Z X Y).symm = whiskerLeftIso X (β_ Y Z) ≪≫ (α_ X Z Y).symm ≪≫ whiskerRightIso (β_ X Z) Y := Iso.ext (hexagon_reverse X Y Z) @[reassoc] theorem hexagon_forward_inv (X Y Z : C) : (α_ Y Z X).inv ≫ (β_ X (Y ⊗ Z)).inv ≫ (α_ X Y Z).inv = Y ◁ (β_ X Z).inv ≫ (α_ Y X Z).inv ≫ (β_ X Y).inv ▷ Z := by simp @[reassoc] theorem hexagon_reverse_inv (X Y Z : C) : (α_ Z X Y).hom ≫ (β_ (X ⊗ Y) Z).inv ≫ (α_ X Y Z).hom = (β_ X Z).inv ▷ Y ≫ (α_ X Z Y).hom ≫ X ◁ (β_ Y Z).inv := by simp end BraidedCategory -- FIXME: `reassoc_of%` should unfold `autoParam`. /-- Verifying the axioms for a braiding by checking that the candidate braiding is sent to a braiding by a faithful monoidal functor. -/ def BraidedCategory.ofFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C ⥤ D) [F.Monoidal] [F.Faithful] [BraidedCategory D] (β : ∀ X Y : C, X ⊗ Y ≅ Y ⊗ X) (w : ∀ X Y, μ F _ _ ≫ F.map (β X Y).hom = (β_ _ _).hom ≫ μ F _ _ := by cat_disch) : BraidedCategory C where braiding := β braiding_naturality_left := by unfold autoParam at w intros apply F.map_injective refine (cancel_epi (μ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← μ_natural_left_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_left_assoc, μ_natural_right] braiding_naturality_right := by unfold autoParam at w intros apply F.map_injective refine (cancel_epi (μ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← μ_natural_right_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_right_assoc, μ_natural_left] hexagon_forward := by unfold autoParam at w intros apply F.map_injective refine (cancel_epi (μ F _ _)).1 ?_ refine (cancel_epi (μ F _ _ ▷ _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← μ_natural_left_assoc, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, Functor.LaxMonoidal.associativity_assoc, Functor.LaxMonoidal.associativity_assoc, ← μ_natural_right, ← whiskerLeft_comp_assoc, w, whiskerLeft_comp_assoc, reassoc_of% w, braiding_naturality_right_assoc, Functor.LaxMonoidal.associativity, hexagon_forward_assoc] hexagon_reverse := by unfold autoParam at w intros apply F.map_injective refine (cancel_epi (μ F _ _)).1 ?_ refine (cancel_epi (_ ◁ μ F _ _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← μ_natural_right_assoc, ← whiskerLeft_comp_assoc, w, whiskerLeft_comp_assoc, Functor.LaxMonoidal.associativity_inv_assoc, Functor.LaxMonoidal.associativity_inv_assoc, ← μ_natural_left, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, reassoc_of% w, braiding_naturality_left_assoc, Functor.LaxMonoidal.associativity_inv, hexagon_reverse_assoc] @[deprecated (since := "2025-07-12")] alias braidedCategoryOfFaithful := BraidedCategory.ofFaithful /-- Pull back a braiding along a fully faithful monoidal functor. -/ noncomputable def BraidedCategory.ofFullyFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C ⥤ D) [F.Monoidal] [F.Full] [F.Faithful] [BraidedCategory D] : BraidedCategory C := .ofFaithful F fun X Y ↦ F.preimageIso ((μIso F _ _).symm ≪≫ β_ (F.obj X) (F.obj Y) ≪≫ μIso F _ _) @[deprecated (since := "2025-07-12")] alias braidedCategoryOfFullyFaithful := BraidedCategory.ofFullyFaithful section /-! We now establish how the braiding interacts with the unitors. I couldn't find a detailed proof in print, but this is discussed in: * Proposition 1 of André Joyal and Ross Street, "Braided monoidal categories", Macquarie Math Reports 860081 (1986). * Proposition 2.1 of André Joyal and Ross Street, "Braided tensor categories" , Adv. Math. 102 (1993), 20–78. * Exercise 8.1.6 of Etingof, Gelaki, Nikshych, Ostrik, "Tensor categories", vol 25, Mathematical Surveys and Monographs (2015), AMS. -/ variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [BraidedCategory C] theorem braiding_leftUnitor_aux₁ (X : C) : (α_ (𝟙_ C) (𝟙_ C) X).hom ≫ (𝟙_ C ◁ (β_ X (𝟙_ C)).inv) ≫ (α_ _ X _).inv ≫ ((λ_ X).hom ▷ _) = ((λ_ _).hom ▷ X) ≫ (β_ X (𝟙_ C)).inv := by monoidal theorem braiding_leftUnitor_aux₂ (X : C) : ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ ((λ_ X).hom ▷ 𝟙_ C) = (ρ_ X).hom ▷ 𝟙_ C := calc ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ ((λ_ X).hom ▷ 𝟙_ C) = ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ (α_ _ _ _).hom ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = ((β_ X (𝟙_ C)).hom ▷ 𝟙_ C) ≫ (α_ _ _ _).hom ≫ (_ ◁ (β_ X _).hom) ≫ (_ ◁ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫ (α_ _ _ _).hom ≫ (_ ◁ (β_ X _).inv) ≫ (α_ _ _ _).inv ≫ ((λ_ X).hom ▷ 𝟙_ C) := by simp _ = (α_ _ _ _).hom ≫ (β_ _ _).hom ≫ ((λ_ _).hom ▷ X) ≫ (β_ X _).inv := by rw [braiding_leftUnitor_aux₁] _ = (α_ _ _ _).hom ≫ (_ ◁ (λ_ _).hom) ≫ (β_ _ _).hom ≫ (β_ X _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_right]); simp only [assoc] _ = (α_ _ _ _).hom ≫ (_ ◁ (λ_ _).hom) := by rw [Iso.hom_inv_id, comp_id] _ = (ρ_ X).hom ▷ 𝟙_ C := by rw [triangle] @[reassoc] theorem braiding_leftUnitor (X : C) : (β_ X (𝟙_ C)).hom ≫ (λ_ X).hom = (ρ_ X).hom := by rw [← whiskerRight_iff, comp_whiskerRight, braiding_leftUnitor_aux₂] theorem braiding_rightUnitor_aux₁ (X : C) : (α_ X (𝟙_ C) (𝟙_ C)).inv ≫ ((β_ (𝟙_ C) X).inv ▷ 𝟙_ C) ≫ (α_ _ X _).hom ≫ (_ ◁ (ρ_ X).hom) = (X ◁ (ρ_ _).hom) ≫ (β_ (𝟙_ C) X).inv := by simp theorem braiding_rightUnitor_aux₂ (X : C) : (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (𝟙_ C ◁ (ρ_ X).hom) = 𝟙_ C ◁ (λ_ X).hom := calc (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (𝟙_ C ◁ (ρ_ X).hom) = (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by simp _ = (𝟙_ C ◁ (β_ (𝟙_ C) X).hom) ≫ (α_ _ _ _).inv ≫ ((β_ _ X).hom ▷ _) ≫ ((β_ _ X).inv ▷ _) ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by simp _ = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫ (α_ _ _ _).inv ≫ ((β_ _ X).inv ▷ _) ≫ (α_ _ _ _).hom ≫ (𝟙_ C ◁ (ρ_ X).hom) := by (slice_lhs 1 3 => rw [← hexagon_reverse]); simp only [assoc] _ = (α_ _ _ _).inv ≫ (β_ _ _).hom ≫ (X ◁ (ρ_ _).hom) ≫ (β_ _ X).inv := by simp _ = (α_ _ _ _).inv ≫ ((ρ_ _).hom ▷ _) ≫ (β_ _ X).hom ≫ (β_ _ _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_left]); simp only [assoc] _ = (α_ _ _ _).inv ≫ ((ρ_ _).hom ▷ _) := by rw [Iso.hom_inv_id, comp_id] _ = 𝟙_ C ◁ (λ_ X).hom := by rw [triangle_assoc_comp_right] @[reassoc] theorem braiding_rightUnitor (X : C) : (β_ (𝟙_ C) X).hom ≫ (ρ_ X).hom = (λ_ X).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, braiding_rightUnitor_aux₂] @[reassoc, simp] theorem braiding_tensorUnit_left (X : C) : (β_ (𝟙_ C) X).hom = (λ_ X).hom ≫ (ρ_ X).inv := by simp [← braiding_rightUnitor] @[reassoc, simp] theorem braiding_inv_tensorUnit_left (X : C) : (β_ (𝟙_ C) X).inv = (ρ_ X).hom ≫ (λ_ X).inv := by rw [Iso.inv_ext] rw [braiding_tensorUnit_left] monoidal @[reassoc] theorem leftUnitor_inv_braiding (X : C) : (λ_ X).inv ≫ (β_ (𝟙_ C) X).hom = (ρ_ X).inv := by simp @[reassoc] theorem rightUnitor_inv_braiding (X : C) : (ρ_ X).inv ≫ (β_ X (𝟙_ C)).hom = (λ_ X).inv := by apply (cancel_mono (λ_ X).hom).1 simp only [assoc, braiding_leftUnitor, Iso.inv_hom_id] @[reassoc, simp] theorem braiding_tensorUnit_right (X : C) : (β_ X (𝟙_ C)).hom = (ρ_ X).hom ≫ (λ_ X).inv := by simp [← rightUnitor_inv_braiding] @[reassoc, simp] theorem braiding_inv_tensorUnit_right (X : C) : (β_ X (𝟙_ C)).inv = (λ_ X).hom ≫ (ρ_ X).inv := by rw [Iso.inv_ext] rw [braiding_tensorUnit_right] monoidal end /-- A symmetric monoidal category is a braided monoidal category for which the braiding is symmetric. -/ @[stacks 0FFW] class SymmetricCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] extends BraidedCategory.{v} C where -- braiding symmetric: symmetry : ∀ X Y : C, (β_ X Y).hom ≫ (β_ Y X).hom = 𝟙 (X ⊗ Y) := by cat_disch attribute [reassoc (attr := simp)] SymmetricCategory.symmetry lemma SymmetricCategory.braiding_swap_eq_inv_braiding {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [SymmetricCategory C] (X Y : C) : (β_ Y X).hom = (β_ X Y).inv := Iso.inv_ext' (symmetry X Y) variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [BraidedCategory C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory D] [BraidedCategory D] variable {E : Type u₃} [Category.{v₃} E] [MonoidalCategory E] [BraidedCategory E] /-- A lax braided functor between braided monoidal categories is a lax monoidal functor which preserves the braiding. -/ class Functor.LaxBraided (F : C ⥤ D) extends F.LaxMonoidal where braided : ∀ X Y : C, μ X Y ≫ F.map (β_ X Y).hom = (β_ (F.obj X) (F.obj Y)).hom ≫ μ Y X := by cat_disch namespace Functor.LaxBraided attribute [reassoc] braided instance id : (𝟭 C).LaxBraided where instance (F : C ⥤ D) (G : D ⥤ E) [F.LaxBraided] [G.LaxBraided] : (F ⋙ G).LaxBraided where braided X Y := by dsimp slice_lhs 2 3 => rw [← CategoryTheory.Functor.map_comp, braided, CategoryTheory.Functor.map_comp] slice_lhs 1 2 => rw [braided] simp only [Category.assoc] end Functor.LaxBraided section variable (C D) /-- Bundled version of lax braided functors. -/ structure LaxBraidedFunctor extends C ⥤ D where laxBraided : toFunctor.LaxBraided := by infer_instance namespace LaxBraidedFunctor variable {C D} attribute [instance] laxBraided /-- Constructor for `LaxBraidedFunctor C D`. -/ @[simps toFunctor] def of (F : C ⥤ D) [F.LaxBraided] : LaxBraidedFunctor C D where toFunctor := F /-- The lax monoidal functor induced by a lax braided functor. -/ @[simps toFunctor] def toLaxMonoidalFunctor (F : LaxBraidedFunctor C D) : LaxMonoidalFunctor C D where toFunctor := F.toFunctor instance : Category (LaxBraidedFunctor C D) := InducedCategory.category (toLaxMonoidalFunctor) @[simp] lemma id_hom (F : LaxBraidedFunctor C D) : LaxMonoidalFunctor.Hom.hom (𝟙 F) = 𝟙 _ := rfl @[reassoc, simp] lemma comp_hom {F G H : LaxBraidedFunctor C D} (α : F ⟶ G) (β : G ⟶ H) : (α ≫ β).hom = α.hom ≫ β.hom := rfl @[ext] lemma hom_ext {F G : LaxBraidedFunctor C D} {α β : F ⟶ G} (h : α.hom = β.hom) : α = β := LaxMonoidalFunctor.hom_ext h /-- Constructor for morphisms in the category `LaxBraiededFunctor C D`. -/ @[simps] def homMk {F G : LaxBraidedFunctor C D} (f : F.toFunctor ⟶ G.toFunctor) [NatTrans.IsMonoidal f] : F ⟶ G := ⟨f, inferInstance⟩ /-- Constructor for isomorphisms in the category `LaxBraidedFunctor C D`. -/ @[simps] def isoMk {F G : LaxBraidedFunctor C D} (e : F.toFunctor ≅ G.toFunctor) [NatTrans.IsMonoidal e.hom] : F ≅ G where hom := homMk e.hom inv := homMk e.inv /-- The forgetful functor from lax braided functors to lax monoidal functors. -/ @[simps! obj map] def forget : LaxBraidedFunctor C D ⥤ LaxMonoidalFunctor C D := inducedFunctor _ /-- The forgetful functor from lax braided functors to lax monoidal functors is fully faithful. -/ def fullyFaithfulForget : (forget (C := C) (D := D)).FullyFaithful := fullyFaithfulInducedFunctor _ section variable {F G : LaxBraidedFunctor C D} (e : ∀ X, F.obj X ≅ G.obj X) (naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (e Y).hom = (e X).hom ≫ G.map f := by cat_disch) (unit : ε F.toFunctor ≫ (e (𝟙_ C)).hom = ε G.toFunctor := by cat_disch) (tensor : ∀ X Y, μ F.toFunctor X Y ≫ (e (X ⊗ Y)).hom = ((e X).hom ⊗ₘ (e Y).hom) ≫ μ G.toFunctor X Y := by cat_disch) /-- Constructor for isomorphisms between lax braided functors. -/ def isoOfComponents : F ≅ G := fullyFaithfulForget.preimageIso (LaxMonoidalFunctor.isoOfComponents e naturality unit tensor) @[simp] lemma isoOfComponents_hom_hom_app (X : C) : (isoOfComponents e naturality unit tensor).hom.hom.app X = (e X).hom := rfl @[simp] lemma isoOfComponents_inv_hom_app (X : C) : (isoOfComponents e naturality unit tensor).inv.hom.app X = (e X).inv := rfl end end LaxBraidedFunctor end /-- A braided functor between braided monoidal categories is a monoidal functor which preserves the braiding. -/ @[ext] class Functor.Braided (F : C ⥤ D) extends F.Monoidal, F.LaxBraided where @[simp, reassoc] lemma Functor.map_braiding (F : C ⥤ D) (X Y : C) [F.Braided] : F.map (β_ X Y).hom = δ F X Y ≫ (β_ (F.obj X) (F.obj Y)).hom ≫ μ F Y X := by rw [← Functor.Braided.braided, δ_μ_assoc] /-- A braided category with a faithful braided functor to a symmetric category is itself symmetric. -/ def symmetricCategoryOfFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] [BraidedCategory C] [SymmetricCategory D] (F : C ⥤ D) [F.Braided] [F.Faithful] : SymmetricCategory C where symmetry X Y := F.map_injective (by simp) namespace Functor.Braided instance : (𝟭 C).Braided where instance (F : C ⥤ D) (G : D ⥤ E) [F.Braided] [G.Braided] : (F ⋙ G).Braided where lemma toMonoidal_injective (F : C ⥤ D) : Function.Injective (@Braided.toMonoidal _ _ _ _ _ _ _ _ _ : F.Braided → F.Monoidal) := by rintro ⟨⟩ ⟨⟩ rfl; rfl end Functor.Braided section CommMonoid variable (M : Type u) [CommMonoid M] instance : BraidedCategory (Discrete M) where braiding X Y := Discrete.eqToIso (mul_comm X.as Y.as) variable {M} {N : Type u} [CommMonoid N] /-- A multiplicative morphism between commutative monoids gives a braided functor between the corresponding discrete braided monoidal categories. -/ instance Discrete.monoidalFunctorBraided (F : M →* N) : (Discrete.monoidalFunctor F).Braided where end CommMonoid namespace MonoidalCategory section Tensor /-- Swap the second and third objects in `(X₁ ⊗ X₂) ⊗ (Y₁ ⊗ Y₂)`. This is used to strength the tensor product functor from `C × C` to `C` as a monoidal functor. -/ def tensorμ (X₁ X₂ Y₁ Y₂ : C) : (X₁ ⊗ X₂) ⊗ Y₁ ⊗ Y₂ ⟶ (X₁ ⊗ Y₁) ⊗ X₂ ⊗ Y₂ := (α_ X₁ X₂ (Y₁ ⊗ Y₂)).hom ≫ (X₁ ◁ (α_ X₂ Y₁ Y₂).inv) ≫ (X₁ ◁ (β_ X₂ Y₁).hom ▷ Y₂) ≫ (X₁ ◁ (α_ Y₁ X₂ Y₂).hom) ≫ (α_ X₁ Y₁ (X₂ ⊗ Y₂)).inv /-- The inverse of `tensorμ`. -/ def tensorδ (X₁ X₂ Y₁ Y₂ : C) : (X₁ ⊗ Y₁) ⊗ X₂ ⊗ Y₂ ⟶ (X₁ ⊗ X₂) ⊗ Y₁ ⊗ Y₂ := (α_ X₁ Y₁ (X₂ ⊗ Y₂)).hom ≫ (X₁ ◁ (α_ Y₁ X₂ Y₂).inv) ≫ (X₁ ◁ (β_ X₂ Y₁).inv ▷ Y₂) ≫ (X₁ ◁ (α_ X₂ Y₁ Y₂).hom) ≫ (α_ X₁ X₂ (Y₁ ⊗ Y₂)).inv @[reassoc (attr := simp)] lemma tensorμ_tensorδ (X₁ X₂ Y₁ Y₂ : C) : tensorμ X₁ X₂ Y₁ Y₂ ≫ tensorδ X₁ X₂ Y₁ Y₂ = 𝟙 _ := by simp only [tensorμ, ← whiskerLeft_comp_assoc, tensorδ, assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, hom_inv_whiskerRight_assoc, Iso.inv_hom_id, whiskerLeft_id, id_comp, Iso.hom_inv_id] @[reassoc (attr := simp)] lemma tensorδ_tensorμ (X₁ X₂ Y₁ Y₂ : C) : tensorδ X₁ X₂ Y₁ Y₂ ≫ tensorμ X₁ X₂ Y₁ Y₂ = 𝟙 _ := by simp only [tensorδ, ← whiskerLeft_comp_assoc, tensorμ, assoc, Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, inv_hom_whiskerRight_assoc, Iso.inv_hom_id, whiskerLeft_id, id_comp, Iso.hom_inv_id] @[reassoc] theorem tensorμ_natural {X₁ X₂ Y₁ Y₂ U₁ U₂ V₁ V₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : U₁ ⟶ V₁) (g₂ : U₂ ⟶ V₂) : ((f₁ ⊗ₘ f₂) ⊗ₘ g₁ ⊗ₘ g₂) ≫ tensorμ Y₁ Y₂ V₁ V₂ = tensorμ X₁ X₂ U₁ U₂ ≫ ((f₁ ⊗ₘ g₁) ⊗ₘ f₂ ⊗ₘ g₂) := by dsimp only [tensorμ] simp_rw [← id_tensorHom, ← tensorHom_id] slice_lhs 1 2 => rw [associator_naturality] slice_lhs 2 3 => rw [← tensor_comp, comp_id f₁, ← id_comp f₁, associator_inv_naturality, tensor_comp] slice_lhs 3 4 => rw [← tensor_comp, ← tensor_comp, comp_id f₁, ← id_comp f₁, comp_id g₂, ← id_comp g₂, braiding_naturality, tensor_comp, tensor_comp] slice_lhs 4 5 => rw [← tensor_comp, comp_id f₁, ← id_comp f₁, associator_naturality, tensor_comp] slice_lhs 5 6 => rw [associator_inv_naturality] simp only [assoc] @[reassoc] theorem tensorμ_natural_left {X₁ X₂ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (Z₁ Z₂ : C) : (f₁ ⊗ₘ f₂) ▷ (Z₁ ⊗ Z₂) ≫ tensorμ Y₁ Y₂ Z₁ Z₂ = tensorμ X₁ X₂ Z₁ Z₂ ≫ (f₁ ▷ Z₁ ⊗ₘ f₂ ▷ Z₂) := by convert tensorμ_natural f₁ f₂ (𝟙 Z₁) (𝟙 Z₂) using 1 <;> simp @[reassoc] theorem tensorμ_natural_right (Z₁ Z₂ : C) {X₁ X₂ Y₁ Y₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) : (Z₁ ⊗ Z₂) ◁ (f₁ ⊗ₘ f₂) ≫ tensorμ Z₁ Z₂ Y₁ Y₂ = tensorμ Z₁ Z₂ X₁ X₂ ≫ (Z₁ ◁ f₁ ⊗ₘ Z₂ ◁ f₂) := by convert tensorμ_natural (𝟙 Z₁) (𝟙 Z₂) f₁ f₂ using 1 <;> simp @[reassoc] theorem tensor_left_unitality (X₁ X₂ : C) : (λ_ (X₁ ⊗ X₂)).hom = ((λ_ (𝟙_ C)).inv ▷ (X₁ ⊗ X₂)) ≫ tensorμ (𝟙_ C) (𝟙_ C) X₁ X₂ ≫ ((λ_ X₁).hom ⊗ₘ (λ_ X₂).hom) := by dsimp only [tensorμ] have : ((λ_ (𝟙_ C)).inv ▷ (X₁ ⊗ X₂)) ≫ (α_ (𝟙_ C) (𝟙_ C) (X₁ ⊗ X₂)).hom ≫ (𝟙_ C ◁ (α_ (𝟙_ C) X₁ X₂).inv) = 𝟙_ C ◁ (λ_ X₁).inv ▷ X₂ := by simp slice_rhs 1 3 => rw [this] clear this slice_rhs 1 2 => rw [← whiskerLeft_comp, ← comp_whiskerRight, leftUnitor_inv_braiding] simp [tensorHom_def] @[reassoc] theorem tensor_right_unitality (X₁ X₂ : C) : (ρ_ (X₁ ⊗ X₂)).hom = ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).inv) ≫ tensorμ X₁ X₂ (𝟙_ C) (𝟙_ C) ≫ ((ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom) := by dsimp only [tensorμ] have : ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).inv) ≫ (α_ X₁ X₂ (𝟙_ C ⊗ 𝟙_ C)).hom ≫ (X₁ ◁ (α_ X₂ (𝟙_ C) (𝟙_ C)).inv) = (α_ X₁ X₂ (𝟙_ C)).hom ≫ (X₁ ◁ (ρ_ X₂).inv ▷ 𝟙_ C) := by monoidal slice_rhs 1 3 => rw [this] clear this slice_rhs 2 3 => rw [← whiskerLeft_comp, ← comp_whiskerRight, rightUnitor_inv_braiding] simp [tensorHom_def] @[reassoc] theorem tensor_associativity (X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C) : (tensorμ X₁ X₂ Y₁ Y₂ ▷ (Z₁ ⊗ Z₂)) ≫ tensorμ (X₁ ⊗ Y₁) (X₂ ⊗ Y₂) Z₁ Z₂ ≫ ((α_ X₁ Y₁ Z₁).hom ⊗ₘ (α_ X₂ Y₂ Z₂).hom) = (α_ (X₁ ⊗ X₂) (Y₁ ⊗ Y₂) (Z₁ ⊗ Z₂)).hom ≫ ((X₁ ⊗ X₂) ◁ tensorμ Y₁ Y₂ Z₁ Z₂) ≫ tensorμ X₁ X₂ (Y₁ ⊗ Z₁) (Y₂ ⊗ Z₂) := by dsimp only [tensor_obj, prodMonoidal_tensorObj, tensorμ] simp only [braiding_tensor_left_hom, braiding_tensor_right_hom] calc _ = 𝟙 _ ⊗≫ X₁ ◁ ((β_ X₂ Y₁).hom ▷ (Y₂ ⊗ Z₁) ≫ (Y₁ ⊗ X₂) ◁ (β_ Y₂ Z₁).hom) ▷ Z₂ ⊗≫ X₁ ◁ Y₁ ◁ (β_ X₂ Z₁).hom ▷ Y₂ ▷ Z₂ ⊗≫ 𝟙 _ := by monoidal _ = _ := by rw [← whisker_exchange]; monoidal instance tensorMonoidal : (tensor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := (λ_ (𝟙_ C)).symm μIso := fun X Y ↦ { hom := tensorμ X.1 X.2 Y.1 Y.2 inv := tensorδ X.1 X.2 Y.1 Y.2 } μIso_hom_natural_left := fun f Z ↦ tensorμ_natural_left f.1 f.2 Z.1 Z.2 μIso_hom_natural_right := fun Z f ↦ tensorμ_natural_right Z.1 Z.2 f.1 f.2 associativity := fun X Y Z ↦ tensor_associativity X.1 X.2 Y.1 Y.2 Z.1 Z.2 left_unitality := fun ⟨X₁, X₂⟩ ↦ tensor_left_unitality X₁ X₂ right_unitality := fun ⟨X₁, X₂⟩ ↦ tensor_right_unitality X₁ X₂ } @[simp] lemma tensor_ε : ε (tensor C) = (λ_ (𝟙_ C)).inv := rfl @[simp] lemma tensor_η : η (tensor C) = (λ_ (𝟙_ C)).hom := rfl @[simp] lemma tensor_μ (X Y : C × C) : μ (tensor C) X Y = tensorμ X.1 X.2 Y.1 Y.2 := rfl @[simp] lemma tensor_δ (X Y : C × C) : δ (tensor C) X Y = tensorδ X.1 X.2 Y.1 Y.2 := rfl @[reassoc] theorem leftUnitor_monoidal (X₁ X₂ : C) : (λ_ X₁).hom ⊗ₘ (λ_ X₂).hom = tensorμ (𝟙_ C) X₁ (𝟙_ C) X₂ ≫ ((λ_ (𝟙_ C)).hom ▷ (X₁ ⊗ X₂)) ≫ (λ_ (X₁ ⊗ X₂)).hom := by dsimp only [tensorμ] have : (λ_ X₁).hom ⊗ₘ (λ_ X₂).hom = (α_ (𝟙_ C) X₁ (𝟙_ C ⊗ X₂)).hom ≫ (𝟙_ C ◁ (α_ X₁ (𝟙_ C) X₂).inv) ≫ (λ_ ((X₁ ⊗ 𝟙_ C) ⊗ X₂)).hom ≫ ((ρ_ X₁).hom ▷ X₂) := by monoidal rw [this]; clear this rw [← braiding_leftUnitor] monoidal @[reassoc] theorem rightUnitor_monoidal (X₁ X₂ : C) : (ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom = tensorμ X₁ (𝟙_ C) X₂ (𝟙_ C) ≫ ((X₁ ⊗ X₂) ◁ (λ_ (𝟙_ C)).hom) ≫ (ρ_ (X₁ ⊗ X₂)).hom := by dsimp only [tensorμ] have : (ρ_ X₁).hom ⊗ₘ (ρ_ X₂).hom = (α_ X₁ (𝟙_ C) (X₂ ⊗ 𝟙_ C)).hom ≫ (X₁ ◁ (α_ (𝟙_ C) X₂ (𝟙_ C)).inv) ≫ (X₁ ◁ (ρ_ (𝟙_ C ⊗ X₂)).hom) ≫ (X₁ ◁ (λ_ X₂).hom) := by monoidal rw [this]; clear this rw [← braiding_rightUnitor] monoidal @[reassoc] theorem associator_monoidal (X₁ X₂ X₃ Y₁ Y₂ Y₃ : C) : tensorμ (X₁ ⊗ X₂) X₃ (Y₁ ⊗ Y₂) Y₃ ≫ (tensorμ X₁ X₂ Y₁ Y₂ ▷ (X₃ ⊗ Y₃)) ≫ (α_ (X₁ ⊗ Y₁) (X₂ ⊗ Y₂) (X₃ ⊗ Y₃)).hom = ((α_ X₁ X₂ X₃).hom ⊗ₘ (α_ Y₁ Y₂ Y₃).hom) ≫ tensorμ X₁ (X₂ ⊗ X₃) Y₁ (Y₂ ⊗ Y₃) ≫ ((X₁ ⊗ Y₁) ◁ tensorμ X₂ X₃ Y₂ Y₃) := by dsimp only [tensorμ] calc _ = 𝟙 _ ⊗≫ X₁ ◁ X₂ ◁ (β_ X₃ Y₁).hom ▷ Y₂ ▷ Y₃ ⊗≫ X₁ ◁ ((X₂ ⊗ Y₁) ◁ (β_ X₃ Y₂).hom ≫ (β_ X₂ Y₁).hom ▷ (Y₂ ⊗ X₃)) ▷ Y₃ ⊗≫ 𝟙 _ := by rw [braiding_tensor_right_hom]; monoidal _ = _ := by rw [whisker_exchange, braiding_tensor_left_hom]; monoidal @[reassoc] lemma tensorμ_comp_μ_tensorHom_μ_comp_μ (F : C ⥤ D) [F.LaxBraided] (W X Y Z : C) : tensorμ (F.obj W) (F.obj X) (F.obj Y) (F.obj Z) ≫ (μ F W Y ⊗ₘ μ F X Z) ≫ μ F (W ⊗ Y) (X ⊗ Z) = (μ F W X ⊗ₘ μ F Y Z) ≫ μ F (W ⊗ X) (Y ⊗ Z) ≫ F.map (tensorμ W X Y Z) := by rw [tensorHom_def] simp only [tensorμ, Category.assoc] rw [whiskerLeft_μ_comp_μ, associator_inv_naturality_left_assoc, ← pentagon_inv_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, Category.assoc, μ_whiskerRight_comp_μ, whiskerLeft_hom_inv_assoc, Iso.inv_hom_id_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, μ_natural_left_assoc, associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, ← comp_whiskerRight_assoc, ← MonoidalCategory.whiskerLeft_comp, ← Functor.LaxBraided.braided, MonoidalCategory.whiskerLeft_comp_assoc, μ_natural_right, whiskerLeft_μ_comp_μ_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, comp_whiskerRight_assoc, pentagon_inv_assoc, μ_natural_left_assoc, μ_natural_left_assoc, Iso.hom_inv_id_assoc, ← associator_inv_naturality_left_assoc, μ_whiskerRight_comp_μ_assoc, Iso.inv_hom_id_assoc, ← tensorHom_def_assoc] simp only [← Functor.map_comp, whisker_assoc, Category.assoc, pentagon_inv_inv_hom_hom_inv, pentagon_inv_hom_hom_hom_inv_assoc] end Tensor end MonoidalCategory instance : BraidedCategory Cᵒᵖ where braiding X Y := (β_ Y.unop X.unop).op braiding_naturality_right X {_ _} f := Quiver.Hom.unop_inj <| by simp braiding_naturality_left {_ _} f Z := Quiver.Hom.unop_inj <| by simp section OppositeLemmas open Opposite @[simp] lemma op_braiding (X Y : C) : (β_ X Y).op = β_ (op Y) (op X) := rfl @[simp] lemma unop_braiding (X Y : Cᵒᵖ) : (β_ X Y).unop = β_ (unop Y) (unop X) := rfl @[simp] lemma op_hom_braiding (X Y : C) : (β_ X Y).hom.op = (β_ (op Y) (op X)).hom := rfl @[simp] lemma unop_hom_braiding (X Y : Cᵒᵖ) : (β_ X Y).hom.unop = (β_ (unop Y) (unop X)).hom := rfl @[simp] lemma op_inv_braiding (X Y : C) : (β_ X Y).inv.op = (β_ (op Y) (op X)).inv := rfl @[simp] lemma unop_inv_braiding (X Y : Cᵒᵖ) : (β_ X Y).inv.unop = (β_ (unop Y) (unop X)).inv := rfl end OppositeLemmas namespace MonoidalOpposite instance instBraiding : BraidedCategory Cᴹᵒᵖ where braiding X Y := (β_ Y.unmop X.unmop).mop braiding_naturality_right X {_ _} f := Quiver.Hom.unmop_inj <| by simp braiding_naturality_left {_ _} f Z := Quiver.Hom.unmop_inj <| by simp section MonoidalOppositeLemmas @[simp] lemma mop_braiding (X Y : C) : (β_ X Y).mop = β_ (mop Y) (mop X) := rfl @[simp] lemma unmop_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).unmop = β_ (unmop Y) (unmop X) := rfl @[simp] lemma mop_hom_braiding (X Y : C) : (β_ X Y).hom.mop = (β_ (mop Y) (mop X)).hom := rfl @[simp] lemma unmop_hom_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).hom.unmop = (β_ (unmop Y) (unmop X)).hom := rfl @[simp] lemma mop_inv_braiding (X Y : C) : (β_ X Y).inv.mop = (β_ (mop Y) (mop X)).inv := rfl @[simp] lemma unmop_inv_braiding (X Y : Cᴹᵒᵖ) : (β_ X Y).inv.unmop = (β_ (unmop Y) (unmop X)).inv := rfl end MonoidalOppositeLemmas instance : (mopFunctor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun X Y ↦ β_ (mop X) (mop Y) associativity := fun X Y Z ↦ by simp [← yang_baxter_assoc] } @[simp] lemma mopFunctor_ε : ε (mopFunctor C) = 𝟙 _ := rfl @[simp] lemma mopFunctor_η : η (mopFunctor C) = 𝟙 _ := rfl @[simp] lemma mopFunctor_μ (X Y : C) : μ (mopFunctor C) X Y = (β_ (mop X) (mop Y)).hom := rfl @[simp] lemma mopFunctor_δ (X Y : C) : δ (mopFunctor C) X Y = (β_ (mop X) (mop Y)).inv := rfl instance : (unmopFunctor C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := Iso.refl _ μIso := fun X Y ↦ β_ (unmop X) (unmop Y) associativity := fun X Y Z ↦ by simp [← yang_baxter_assoc] } @[simp] lemma unmopFunctor_ε : ε (unmopFunctor C) = 𝟙 _ := rfl @[simp] lemma unmopFunctor_η : η (unmopFunctor C) = 𝟙 _ := rfl @[simp] lemma unmopFunctor_μ (X Y : Cᴹᵒᵖ) : μ (unmopFunctor C) X Y = (β_ (unmop X) (unmop Y)).hom := rfl @[simp] lemma unmopFunctor_δ (X Y : Cᴹᵒᵖ) : δ (unmopFunctor C) X Y = (β_ (unmop X) (unmop Y)).inv := rfl /-- The identity functor on `C`, viewed as a functor from `C` to its monoidal opposite, upgraded to a braided functor. -/ instance : (mopFunctor C).Braided where /-- The identity functor on `C`, viewed as a functor from the monoidal opposite of `C` to `C`, upgraded to a braided functor. -/ instance : (unmopFunctor C).Braided where end MonoidalOpposite variable (C) /-- The braided monoidal category obtained from `C` by replacing its braiding `β_ X Y : X ⊗ Y ≅ Y ⊗ X` with the inverse `(β_ Y X)⁻¹ : X ⊗ Y ≅ Y ⊗ X`. This corresponds to the automorphism of the braid group swapping over-crossings and under-crossings. -/ abbrev reverseBraiding : BraidedCategory C where braiding X Y := (β_ Y X).symm braiding_naturality_right X {_ _} f := by simp braiding_naturality_left {_ _} f Z := by simp lemma SymmetricCategory.reverseBraiding_eq (C : Type u₁) [Category.{v₁} C] [MonoidalCategory C] [i : SymmetricCategory C] : reverseBraiding C = i.toBraidedCategory := by dsimp only [reverseBraiding] congr funext X Y exact Iso.ext (braiding_swap_eq_inv_braiding Y X).symm /-- The identity functor from `C` to `C`, where the codomain is given the reversed braiding, upgraded to a braided functor. -/ def SymmetricCategory.equivReverseBraiding (C : Type u₁) [Category.{v₁} C] [MonoidalCategory C] [SymmetricCategory C] := @Functor.Braided.mk C _ _ _ C _ _ (reverseBraiding C) (𝟭 C) _ <| by intros; simp [reverseBraiding, braiding_swap_eq_inv_braiding] end CategoryTheory
finfield.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 choice. From mathcomp Require Import fintype div tuple bigop prime finset fingroup. From mathcomp Require Import ssralg poly polydiv morphism action countalg. From mathcomp Require Import finalg zmodp cyclic center pgroup abelian matrix. From mathcomp Require Import mxpoly vector falgebra fieldext separable galois. From mathcomp Require ssrnum ssrint archimedean algC cyclotomic. (******************************************************************************) (* Additional constructions and results on finite fields *) (* *) (* FinFieldExtType L == a FinFieldType structure on the carrier of L, *) (* where L IS a fieldExtType F structure for an *) (* F that has a finFieldType structure. This *) (* does not take any existing finType structure *) (* on L; this should not be made canonical *) (* FinSplittingFieldType F L == a SplittingFieldType F structure on the *) (* carrier of L, where L IS a fieldExtType F for *) (* an F with a finFieldType structure; this *) (* should not be made canonical *) (* finvect_type vT == alias of vT : vecType R equipped with *) (* canonical instances for finType, finNzRing, *) (* etc structures (including FinFieldExtType *) (* above) for abstract vectType, falgType and *) (* fieldExtType over a finFieldType *) (* pPrimeCharType pcharRp == the carrier of a nzRingType R such that *) (* pcharRp : p \in [pchar R] holds. This type has*) (* canonical nzRingType, ..., fieldType *) (* structures compatible with those of R, as well*) (* as canonical lmodType 'F_p, ..., algType 'F_p *) (* structures, plus an falgType structure if R *) (* is a finUnitRingType and a splittingFieldType *) (* structure if R is a finFieldType *) (* FinSplittingFieldFor nz_p == sigma-pair whose sval is a splittingFieldType *) (* that is the splitting field for p : {poly F} *) (* over F : finFieldType, given nz_p : p != 0 *) (* PrimePowerField pr_p k_gt0 == sigma2-triple whose s2val is a finFieldType *) (* of characteristic p and order m = p ^ k, *) (* given pr_p : prime p and k_gt0 : k > 0 *) (* FinDomainFieldType domR == a finFieldType structure on a finUnitRingType *) (* R, given domR : GRing.IntegralDomain.axiom R. *) (* This is intended to be used inside proofs, *) (* where one cannot declare Canonical instances *) (* Otherwise one should construct explicitly the *) (* intermediate structures using the ssralg and *) (* finalg constructors, and finDomain_mulrC domR *) (* finDomain_fieldP domR to prove commutativity *) (* and field axioms (the former is Wedderburn's *) (* little theorem). *) (* FinDomainSplittingFieldType domR pcharRp == a splittingFieldType structure *) (* that repackages the two constructions above *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope GRing.Theory FinRing.Theory. Local Open Scope ring_scope. Section FinNzRing. Variable R : finNzRingType. Lemma finNzRing_nontrivial : [set: R] != 1%g. Proof. by apply/trivgPn; exists 1; rewrite ?inE ?oner_neq0. Qed. Lemma finNzRing_gt1 : 1 < #|R|. Proof. by rewrite -cardsT cardG_gt1 finNzRing_nontrivial. Qed. End FinNzRing. #[deprecated(since="mathcomp 2.4.0", note="Use finNzRing_nontrivial instead.")] Notation finRing_nontrivial := (finNzRing_nontrivial) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use finNzRing_gt1 instead.")] Notation finRing_gt1 := (finNzRing_gt1) (only parsing). Section FinField. Variable F : finFieldType. Lemma card_finField_unit : #|[set: {unit F}]| = #|F|.-1. Proof. by rewrite -(cardC1 0) cardsT card_sub; apply: eq_card => x; rewrite unitfE. Qed. Definition finField_unit x (nz_x : x != 0) := FinRing.unit F (etrans (unitfE x) nz_x). Lemma expf_card x : x ^+ #|F| = x :> F. Proof. rewrite -[RHS]mulr1 -(ltn_predK (finNzRing_gt1 F)) exprS. apply/eqP; rewrite -subr_eq0 -mulrBr mulf_eq0 subr_eq0 -implyNb -unitfE. apply/implyP=> Ux; rewrite -(val_unitX _ (Sub x _)) -val_unit1 val_eqE. by rewrite -order_dvdn -card_finField_unit order_dvdG ?inE. Qed. Lemma finField_genPoly : 'X^#|F| - 'X = \prod_x ('X - x%:P) :> {poly F}. Proof. set n := #|F|; set oppX := - 'X; set pF := LHS. have le_oppX_n: size oppX <= n by rewrite size_polyN size_polyX finNzRing_gt1. have: size pF = (size (enum F)).+1 by rewrite -cardE size_polyDl size_polyXn. move/all_roots_prod_XsubC->; last by rewrite uniq_rootsE enum_uniq. by rewrite big_enum lead_coefDl ?size_polyXn // lead_coefXn scale1r. by apply/allP=> x _; rewrite rootE !hornerE expf_card subrr. Qed. Lemma finPcharP : {p | prime p & p \in [pchar F]}. Proof. pose e := exponent [set: F]; have e_gt0: e > 0 by apply: exponent_gt0. have: e%:R == 0 :> F by rewrite -zmodXgE expg_exponent // inE. by case/natf0_pchar/sigW=> // p pcharFp; exists p; rewrite ?(pcharf_prime pcharFp). Qed. Lemma finField_is_abelem : is_abelem [set: F]. Proof. have [p pr_p pcharFp] := finPcharP. by apply/is_abelemP; exists p; last apply: fin_ring_pchar_abelem. Qed. Lemma card_finPcharP p n : #|F| = (p ^ n)%N -> prime p -> p \in [pchar F]. Proof. move=> oF pr_p; rewrite inE pr_p -order_dvdn. rewrite (abelem_order_p finField_is_abelem) ?inE ?oner_neq0 //=. have n_gt0: n > 0 by rewrite -(ltn_exp2l _ _ (prime_gt1 pr_p)) -oF finNzRing_gt1. by rewrite cardsT oF -(prednK n_gt0) pdiv_pfactor. Qed. End FinField. #[deprecated(since="mathcomp 2.4.0", note="Use finPcharP instead.")] Notation finCharP := (finPcharP) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_finPcharP instead.")] Notation card_finCharP := (card_finPcharP) (only parsing). Section CardVspace. Variables (F : finFieldType) (T : finType). Section Vector. Variable cvT : Vector F T. Let vT := Vector.Pack cvT. Lemma card_vspace (V : {vspace vT}) : #|V| = (#|F| ^ \dim V)%N. Proof. set n := \dim V; pose V2rV v := \row_i coord (vbasis V) i v. pose rV2V (rv : 'rV_n) := \sum_i rv 0 i *: (vbasis V)`_i. have rV2V_K: cancel rV2V V2rV. have freeV: free (vbasis V) := basis_free (vbasisP V). by move=> rv; apply/rowP=> i; rewrite mxE coord_sum_free. rewrite -[n]mul1n -card_mx -(card_imset _ (can_inj rV2V_K)). apply: eq_card => v; apply/idP/imsetP=> [/coord_vbasis-> | [rv _ ->]]. by exists (V2rV v) => //; apply: eq_bigr => i _; rewrite mxE. by apply: (@rpred_sum vT) => i _; rewrite rpredZ ?vbasis_mem ?memt_nth. Qed. Lemma card_vspacef : #|{: vT}%VS| = #|T|. Proof. by apply: eq_card => v; rewrite (@memvf _ vT). Qed. End Vector. Variable caT : Falgebra F T. Let aT := Falgebra.Pack caT. Lemma card_vspace1 : #|(1%VS : {vspace aT})| = #|F|. Proof. by rewrite card_vspace (dimv1 aT). Qed. End CardVspace. Definition finvect_type (vT : Type) : predArgType := vT. Section FinVector. Variables (R : finNzRingType) (vT : vectType R). Local Notation fvT := (finvect_type vT). HB.instance Definition _ := Vector.on fvT. HB.instance Definition _ := isCountable.Build fvT (pcan_pickleK (can_pcan VectorInternalTheory.v2rK)). HB.instance Definition _ := isFinite.Build fvT (pcan_enumP (can_pcan (VectorInternalTheory.v2rK : @cancel _ fvT _ _))). End FinVector. HB.instance Definition _ (F : finFieldType) (aT : falgType F) := Falgebra.on (finvect_type aT). Section FinFieldExt. Variables (F : finFieldType) (fT : fieldExtType F). Local Notation ffT := (finvect_type fT). HB.instance Definition _ := FieldExt.on ffT. Lemma ffT_splitting_subproof : SplittingField.axiom ffT. Proof. exists ('X^#|ffT| - 'X). by rewrite (@rpredB {poly fT}) 1?rpredX ?polyOverX. exists (enum ffT); first by rewrite big_enum finField_genPoly eqpxx. by apply/vspaceP=> x; rewrite memvf seqv_sub_adjoin ?mem_enum. Qed. HB.instance Definition _ := FieldExt_isSplittingField.Build F ffT ffT_splitting_subproof. End FinFieldExt. Definition FinSplittingFieldType (F : finFieldType) (fT : fieldExtType F) := HB.pack_for (splittingFieldType F) fT (SplittingField.on (finvect_type fT)). Definition FinFieldExtType (F : finFieldType) (fT : fieldExtType F) := HB.pack_for finFieldType (FinSplittingFieldType fT) (FinRing.Field.on (finvect_type fT)). Arguments FinSplittingFieldType : clear implicits. Section PrimeChar. Variable p : nat. Section PrimeCharRing. Variable R0 : nzRingType. Definition pPrimeCharType of p \in [pchar R0] : predArgType := R0. Hypothesis pcharRp : p \in [pchar R0]. Local Notation R := (pPrimeCharType pcharRp). Implicit Types (a b : 'F_p) (x y : R). HB.instance Definition _ := GRing.NzRing.on R. Definition pprimeChar_scale a x := a%:R * x. Local Infix "*p':" := pprimeChar_scale (at level 40). Let natrFp n : (inZp n : 'F_p)%:R = n%:R :> R. Proof. rewrite [in RHS](divn_eq n p) natrD mulrnA (mulrn_pchar pcharRp) add0r. by rewrite /= (Fp_cast (pcharf_prime pcharRp)). Qed. Lemma pprimeChar_scaleA a b x : a *p': (b *p': x) = (a * b) *p': x. Proof. by rewrite /pprimeChar_scale mulrA -natrM natrFp. Qed. Lemma pprimeChar_scale1 : left_id 1 pprimeChar_scale. Proof. by move=> x; rewrite /pprimeChar_scale mul1r. Qed. Lemma pprimeChar_scaleDr : right_distributive pprimeChar_scale +%R. Proof. by move=> a x y /=; rewrite /pprimeChar_scale mulrDr. Qed. Lemma pprimeChar_scaleDl x : {morph pprimeChar_scale^~ x: a b / a + b}. Proof. by move=> a b; rewrite /pprimeChar_scale natrFp natrD mulrDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build 'F_p R pprimeChar_scaleA pprimeChar_scale1 pprimeChar_scaleDr pprimeChar_scaleDl. Lemma pprimeChar_scaleAl (a : 'F_p) (u v : R) : a *: (u * v) = (a *: u) * v. Proof. by apply: mulrA. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build 'F_p R pprimeChar_scaleAl. Lemma pprimeChar_scaleAr (a : 'F_p) (x y : R) : a *: (x * y) = x * (a *: y). Proof. by rewrite ![a *: _]mulr_natl mulrnAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build 'F_p R pprimeChar_scaleAr. End PrimeCharRing. Local Notation type := @pPrimeCharType. (* TODO: automatize parameter inference to do all of these *) HB.instance Definition _ (R : unitRingType) pcharRp := GRing.UnitRing.on (type R pcharRp). HB.instance Definition _ (R : comNzRingType) pcharRp := GRing.ComNzRing.on (type R pcharRp). HB.instance Definition _ (R : comUnitRingType) pcharRp := GRing.ComUnitRing.on (type R pcharRp). HB.instance Definition _ (R : idomainType) pcharRp := GRing.IntegralDomain.on (type R pcharRp). HB.instance Definition _ (R : fieldType) pcharRp := GRing.Field.on (type R pcharRp). Section FinNzRing. Variables (R0 : finNzRingType) (pcharRp : p \in [pchar R0]). Local Notation R := (type _ pcharRp). HB.instance Definition _ := FinGroup.on R. Let pr_p : prime p. Proof. exact: pcharf_prime pcharRp. Qed. Lemma pprimeChar_abelem : p.-abelem [set: R]. Proof. exact: fin_Fp_lmod_abelem. Qed. Lemma pprimeChar_pgroup : p.-group [set: R]. Proof. by case/and3P: pprimeChar_abelem. Qed. Lemma order_pprimeChar x : x != 0 :> R -> #[x]%g = p. Proof. by apply: (abelem_order_p pprimeChar_abelem); rewrite inE. Qed. Let n := logn p #|R|. Lemma card_pprimeChar : #|R| = (p ^ n)%N. Proof. by rewrite /n -cardsT {1}(card_pgroup pprimeChar_pgroup). Qed. Lemma pprimeChar_vectAxiom : Vector.axiom n R. Proof. have /isog_isom/=[f /isomP[injf im_f]]: [set: R] \isog [set: 'rV['F_p]_n]. rewrite (@isog_abelem_card _ _ p) fin_Fp_lmod_abelem //=. by rewrite !cardsT card_pprimeChar card_mx mul1n card_Fp. exists f; last by exists (invm injf) => x; rewrite ?invmE ?invmK ?im_f ?inE. move=> a x y; rewrite [a *: _]mulr_natl morphM ?morphX ?inE // zmodXgE. by congr (_ + _); rewrite -scaler_nat natr_Zp. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build 'F_p R pprimeChar_vectAxiom. Lemma pprimeChar_dimf : \dim {: R : vectType 'F_p } = n. Proof. by rewrite dimvf. Qed. End FinNzRing. HB.instance Definition _ (R : finUnitRingType) pcharRp := FinRing.UnitRing.on (type R pcharRp). HB.instance Definition _ (R : finComNzRingType) pcharRp := FinRing.ComNzRing.on (type R pcharRp). HB.instance Definition _ (R : finComUnitRingType) pcharRp := FinRing.ComUnitRing.on (type R pcharRp). HB.instance Definition _ (R : finIdomainType) pcharRp := FinRing.IntegralDomain.on (type R pcharRp). Section FinField. Variables (F0 : finFieldType) (pcharFp : p \in [pchar F0]). Local Notation F := (type _ pcharFp). HB.instance Definition _ := Finite.on F. HB.instance Definition _ := SplittingField.copy F (finvect_type F). End FinField. End PrimeChar. #[deprecated(since="mathcomp 2.4.0", note="Use pPrimeCharType instead.")] Notation PrimeCharType := (pPrimeCharType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scale instead.")] Notation primeChar_scale := (pprimeChar_scale) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleA instead.")] Notation primeChar_scaleA := (pprimeChar_scaleA) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scale1 instead.")] Notation primeChar_scale1 := (pprimeChar_scale1) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleDr instead.")] Notation primeChar_scaleDr := (pprimeChar_scaleDr) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleDl instead.")] Notation primeChar_scaleDl := (pprimeChar_scaleDl) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleAl instead.")] Notation primeChar_scaleAl := (pprimeChar_scaleAl) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_scaleAr instead.")] Notation primeChar_scaleAr := (pprimeChar_scaleAr) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_abelem instead.")] Notation primeChar_abelem := (pprimeChar_abelem) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_pgroup instead.")] Notation primeChar_pgroup := (pprimeChar_pgroup) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use order_pprimeChar instead.")] Notation order_primeChar := (order_pprimeChar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use card_pprimeChar instead.")] Notation card_primeChar := (card_pprimeChar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_vectAxiom instead.")] Notation primeChar_vectAxiom := (pprimeChar_vectAxiom) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pprimeChar_dimf instead.")] Notation primeChar_dimf := (pprimeChar_dimf) (only parsing). Section FinSplittingField. Variable F : finFieldType. (* By card_vspace order K = #|K| for any finType structure on L; however we *) (* do not want to impose the FinVector instance here. *) Let order (L : vectType F) (K : {vspace L}) := (#|F| ^ \dim K)%N. Section FinGalois. Variable L : splittingFieldType F. Implicit Types (a b : F) (x y : L) (K E : {subfield L}). Let galL K : galois K {:L}. Proof. without loss {K} ->: K / K = 1%AS. by move=> IH_K; apply: galoisS (IH_K _ (erefl _)); rewrite sub1v subvf. apply/splitting_galoisField; pose finL := FinFieldExtType L. exists ('X^#|finL| - 'X); split; first by rewrite rpredB 1?rpredX ?polyOverX. rewrite (finField_genPoly finL) -big_enum /=. by rewrite separable_prod_XsubC ?(enum_uniq finL). exists (enum finL). by rewrite (@big_enum _ _ _ _ finL) (finField_genPoly finL) eqpxx. by apply/vspaceP=> x; rewrite memvf seqv_sub_adjoin ?(mem_enum finL). Qed. Fact galLgen K : {alpha | generator 'Gal({:L} / K) alpha & forall x, alpha x = x ^+ order K}. Proof. without loss{K} ->: K / K = 1%AS; last rewrite /order dimv1 expn1. case/(_ 1%AS)=> // alpha /eqP-defGalL; rewrite /order dimv1 expn1 => Dalpha. exists (alpha ^+ \dim K)%g => [|x]; last first. elim: (\dim K) => [|n IHn]; first by rewrite gal_id. by rewrite expgSr galM ?memvf // IHn Dalpha expnSr exprM. have sGalLK: 'Gal({:L} / K) \subset <[alpha]> by rewrite -defGalL galS ?sub1v. rewrite /generator {sGalLK}(eq_subG_cyclic _ sGalLK) ?cycle_cyclic ?cycleX //. rewrite -orderE orderXdiv orderE -defGalL -?{1}galois_dim ?dimv1 ?divn1 //. by rewrite field_dimS ?subvf. pose f x := x ^+ #|F|. have idfP x: reflect (f x = x) (x \in 1%VS). apply: (iffP (vlineP _ _)) => [[a ->] | xFx]. by rewrite -in_algE -[LHS]rmorphXn expf_card. pose q := map_poly (in_alg L) ('X^#|F| - 'X). have: root q x. rewrite /q rmorphB /= map_polyXn map_polyX. by rewrite rootE !(hornerE, hornerXn) [x ^+ _]xFx subrr. have{q} ->: q = \prod_(z <- [seq b%:A | b : F]) ('X - z%:P). rewrite /q finField_genPoly rmorph_prod big_image /=. by apply: eq_bigr => b _; rewrite rmorphB /= map_polyX map_polyC. by rewrite root_prod_XsubC => /mapP[a]; exists a. have fA : zmod_morphism f. rewrite /f => x y; rewrite ?exprMn ?expr1n //. have [p _ pcharFp] := finPcharP F; rewrite (card_pprimeChar pcharFp). elim: (logn _ _) => // n IHn; rewrite expnSr !exprM {}IHn. by rewrite -(pchar_lalg L) in pcharFp; rewrite -pFrobenius_autE rmorphB. have fM : monoid_morphism f. by rewrite /f; split=> [|x y]; rewrite ?exprMn ?expr1n //. have fZ: scalable f. move=> a x; rewrite -[in LHS]mulr_algl fM. by rewrite (idfP _ _) ?mulr_algl ?memvZ // memv_line. pose faM := GRing.isZmodMorphism.Build _ _ f fA. pose fmM := GRing.isMonoidMorphism.Build _ _ f fM. pose flM := GRing.isScalable.Build _ _ _ _ f fZ. pose fLRM : {lrmorphism _ -> _} := HB.pack f faM fmM flM. have /kAut_to_gal[alpha galLalpha Dalpha]: kAut 1 {:L} (linfun fLRM). rewrite kAutfE; apply/kHomP_tmp; split=> [x /idfP | x y _ _]; rewrite !lfunE //=. exact: (rmorphM fLRM). have{} Dalpha: alpha =1 f by move=> a; rewrite -Dalpha ?memvf ?lfunE. suffices <-: fixedField [set alpha] = 1%AS. by rewrite gal_generated /generator; exists alpha. apply/vspaceP=> x; apply/fixedFieldP/idfP; rewrite ?memvf // => id_x. by rewrite -Dalpha id_x ?set11. by move=> _ /set1P->; rewrite Dalpha. Qed. Lemma finField_galois K E : (K <= E)%VS -> galois K E. Proof. move=> sKE; have /galois_fixedField <- := galL E. rewrite normal_fixedField_galois // -sub_abelian_normal ?galS //. apply: abelianS (galS _ (sub1v _)) _. by have [alpha /('Gal(_ / _) =P _)-> _] := galLgen 1; apply: cycle_abelian. Qed. Lemma finField_galois_generator K E : (K <= E)%VS -> {alpha | generator 'Gal(E / K) alpha & {in E, forall x, alpha x = x ^+ order K}}. Proof. move=> sKE; have [alpha defGalLK Dalpha] := galLgen K. have inKL_E: (K <= E <= {:L})%VS by rewrite sKE subvf. have nKE: normalField K E by have/and3P[] := finField_galois sKE. have galLKalpha: alpha \in 'Gal({:L} / K). by rewrite (('Gal(_ / _) =P _) defGalLK) cycle_id. exists (normalField_cast _ alpha) => [|x Ex]; last first. by rewrite (normalField_cast_eq inKL_E). rewrite /generator -(morphim_cycle (normalField_cast_morphism inKL_E nKE)) //. by rewrite -((_ =P <[alpha]>) defGalLK) normalField_img. Qed. End FinGalois. Lemma Fermat's_little_theorem (L : fieldExtType F) (K : {subfield L}) a : (a \in K) = (a ^+ order K == a). Proof. move: K a; wlog [{}L -> K a]: L / exists galL : splittingFieldType F, L = galL. by pose galL := FinSplittingFieldType F L => /(_ galL); apply; exists galL. have /galois_fixedField fixLK := finField_galois (subvf K). have [alpha defGalLK Dalpha] := finField_galois_generator (subvf K). rewrite -Dalpha ?memvf // -{1}fixLK (('Gal(_ / _) =P _) defGalLK). rewrite /cycle -gal_generated (galois_fixedField _) ?fixedField_galois //. by apply/fixedFieldP/eqP=> [|-> | alpha_x _ /set1P->]; rewrite ?memvf ?set11. Qed. End FinSplittingField. Section FinFieldExists. (* While the existence of finite splitting fields and of finite fields of *) (* arbitrary prime power order is mathematically straightforward, it is *) (* technically challenging to formalize in Coq. The Coq typechecker performs *) (* poorly for some of the deeply nested dependent types used in the *) (* construction, such as polynomials over extensions of extensions of finite *) (* fields. Any conversion in a nested structure parameter incurs a huge *) (* overhead as it is shared across term comparison by call-by-need evalution. *) (* The proof of FinSplittingFieldFor is contrived to mitigate this effect: *) (* the abbreviation map_poly_extField alone divides by 3 the proof checking *) (* time, by reducing the number of occurrences of field(Ext)Type structures *) (* in the subgoals; the successive, apparently redundant 'suffices' localize *) (* some of the conversions to smaller subgoals, yielding a further 8-fold *) (* time gain. In particular, we construct the splitting field as a subtype *) (* of a recursive construction rather than prove that the latter yields *) (* precisely a splitting field. *) (* The apparently redundant type annotation reduces checking time by 30%. *) Let map_poly_extField (F : fieldType) (L : fieldExtType F) := map_poly (in_alg L) : {poly F} -> {poly L}. Local Notation "p ^%:A" := (map_poly_extField _ p) (format "p ^%:A") : ring_scope. Lemma FinSplittingFieldFor (F : finFieldType) (p : {poly F}) : p != 0 -> {L : splittingFieldType F | splittingFieldFor 1 p^%:A {:L}}. Proof. have mapXsubC (f : {rmorphism _ -> _}) x: map_poly f ('X - x%:P) = 'X - (f x)%:P. by rewrite rmorphB /= map_polyX map_polyC. move=> nz_p; pose splits q := {zs | q %= \prod_(z <- zs) ('X - z%:P)}. suffices [L splitLp]: {L : fieldExtType F | splittingFieldFor 1 p^%:A {:L}}. by exists (FinSplittingFieldType F L). suffices [L [ys Dp]]: {L : fieldExtType F & splits L p^%:A}. pose Lp := subvs_of <<1 & ys>>; pose toL := linfun (vsval : Lp -> L). have [zs Dys]: {zs | map toL zs = ys}. exists (map (vsproj _) ys); rewrite -map_comp map_id_in // => y ys_y. by rewrite /= lfunE /= vsprojK ?seqv_sub_adjoin. exists Lp, zs. set lhs := (lhs in lhs %= _); set rhs := (rhs in _ %= rhs). suffices: map_poly toL lhs %= map_poly toL rhs by rewrite eqp_map. rewrite -Dys big_map in Dp; apply: etrans Dp; apply: congr2. by rewrite -map_poly_comp; apply/eq_map_poly=> x; apply: rmorph_alg. by rewrite rmorph_prod; apply/eq_bigr=> z _; apply mapXsubC. set Lzs := LHS; pose Lys := (toL @: Lzs)%VS; apply/vspaceP=> u. have: val u \in Lys by rewrite /Lys aimg_adjoin_seq aimg1 Dys (valP u). by case/memv_imgP=> v Lzs_v; rewrite memvf lfunE => /val_inj->. move: {2}_.+1 (ltnSn (size p)) => n; elim: n => // n IHn in F p nz_p * => lbn. have [Cp|C'p] := leqP (size p) 1. exists F^o, [::]. by rewrite big_nil -size_poly_eq1 size_map_poly eqn_leq Cp size_poly_gt0. have [r r_dv_p irr_r]: {r | r %| p & irreducible_poly r}. pose rVp (v : 'rV_n) (r := rVpoly v) := (1 < size r) && (r %| p). have [v0 Dp]: {v0 | rVpoly v0 = p & rVp v0}. by exists (poly_rV p); rewrite /rVp poly_rV_K ?C'p /=. case/(arg_minnP (size \o rVpoly))=> /= v; set r := rVpoly v. case/andP=> C'r r_dv_p min_r; exists r => //; split=> // q C'q q_dv_r. have nz_r: r != 0 by rewrite -size_poly_gt0 ltnW. have le_q_r: size q <= size r by rewrite dvdp_leq. have [u Dq]: {u : 'rV_n | rVpoly u = q}. by exists (poly_rV q); rewrite poly_rV_K ?(leq_trans le_q_r) ?size_poly. rewrite -dvdp_size_eqp // eqn_leq le_q_r -Dq min_r // /rVp Dq. rewrite ltn_neqAle eq_sym C'q size_poly_gt0 (dvdpN0 q_dv_r) //=. exact: dvdp_trans q_dv_r r_dv_p. have{irr_r} [K _ [x rx0 defK]] := irredp_FAdjoin irr_r. have{r rx0 r_dv_p} /factor_theorem/sig_eqW[q Dp]: root p^%:A x. by rewrite -(divpK r_dv_p) [_^%:A]rmorphM rootM rx0 orbT. have Dszp: size p = size (q * ('X - x%:P)) by rewrite -Dp size_map_poly. have nz_q: q != 0. by move: nz_p; rewrite -size_poly_eq0 Dszp size_poly_eq0 mulf_eq0 => /norP[]. have [L [zs Dq]]: {L : fieldExtType K & splits L q^%:A}. apply: (IHn (FinFieldExtType K) q nz_q). by rewrite ltnS Dszp size_mul ?polyXsubC_eq0 ?size_XsubC ?addn2 in lbn. suffices: splits L p^%:A^%:A. rewrite -[_^%:A]map_poly_comp. (* TODO_HB : had to give the F explicitly *) rewrite -(eq_map_poly (fun a : F => baseField_scaleE a 1)). by exists (baseFieldType L). exists (x%:A :: zs); rewrite big_cons; set rhs := _ * _. by rewrite Dp mulrC [_^%:A]rmorphM /= mapXsubC /= eqp_mull. Qed. Lemma pPrimePowerField p k (m := (p ^ k)%N) : prime p -> 0 < k -> {Fm : finFieldType | p \in [pchar Fm] & #|Fm| = m}. Proof. move=> pr_p k_gt0; have m_gt1: m > 1 by rewrite (ltn_exp2l 0) ?prime_gt1. have m_gt0 := ltnW m_gt1; have m1_gt0: m.-1 > 0 by rewrite -ltnS prednK. pose q := 'X^m - 'X; have Dq R: q R = ('X^(m.-1) - 1) * ('X - 0). by rewrite subr0 mulrBl mul1r -exprSr prednK. have /FinSplittingFieldFor[/= L splitLq]: q 'F_p != 0. by rewrite Dq monic_neq0 ?rpredM ?monicXsubC ?monicXnsubC. rewrite [_^%:A]rmorphB rmorphXn /= map_polyX -/(q L) in splitLq. have pcharL: p \in [pchar L] by rewrite pchar_lalg pchar_Fp. pose Fm := FinFieldExtType L; exists Fm => //. have /finField_galois_generator[/= a _ Da]: (1 <= {:L})%VS by apply: sub1v. pose Em := fixedSpace (a ^+ k)%g; rewrite card_Fp //= dimv1 expn1 in Da. have{splitLq} [zs DqL defL] := splitLq. have Uzs: uniq zs. rewrite -separable_prod_XsubC -(eqp_separable DqL) Dq separable_root andbC. rewrite /root !hornerE subr_eq0 eq_sym expr0n gtn_eqF ?oner_eq0 //=. rewrite cyclotomic.separable_Xn_sub_1 // -subn1 natrB // subr_eq0. by rewrite natrX pcharf0 // expr0n gtn_eqF // eq_sym oner_eq0. suffices /eq_card->: Fm =i zs. apply: succn_inj; rewrite (card_uniqP _) //= -(size_prod_XsubC _ id). by rewrite -(eqp_size DqL) size_polyDl size_polyXn // size_polyN size_polyX. have in_zs: zs =i Em. move=> z; rewrite -root_prod_XsubC -(eqp_root DqL) (sameP fixedSpaceP eqP). rewrite /root !hornerE subr_eq0 /= /m; congr (_ == z). elim: (k) => [|i IHi]; first by rewrite gal_id. by rewrite expgSr expnSr exprM IHi galM ?Da ?memvf. suffices defEm: Em = {:L}%VS by move=> z; rewrite in_zs defEm memvf. apply/eqP; rewrite eqEsubv subvf -defL -[Em]subfield_closed agenvS //. by rewrite subv_add sub1v; apply/span_subvP=> z; rewrite in_zs. Qed. End FinFieldExists. #[deprecated(since="mathcomp 2.4.0", note="Use pPrimePowerField instead.")] Notation PrimePowerField := (pPrimePowerField) (only parsing). Section FinDomain. Import order ssrnum ssrint archimedean algC cyclotomic Order.TTheory Num.Theory. Local Infix "%|" := dvdn. (* Hide polynomial divisibility. *) Variable R : finUnitRingType. Hypothesis domR : GRing.integral_domain_axiom R. Implicit Types x y : R. Let lregR x : x != 0 -> GRing.lreg x. Proof. by move=> xnz; apply: mulrI0_lreg => y /domR/orP[/idPn | /eqP]. Qed. Lemma finDomain_field : GRing.field_axiom R. Proof. move=> x /lregR-regx; apply/unitrP; exists (invF regx 1). by split; first apply: (regx); rewrite ?mulrA f_invF // mulr1 mul1r. Qed. (* This is Witt's proof of Wedderburn's little theorem. *) Theorem finDomain_mulrC : @commutative R R *%R. Proof. have fieldR := finDomain_field. have [p p_pr pcharRp]: exists2 p, prime p & p \in [pchar R]. have [e /prod_prime_decomp->]: {e | (e > 0)%N & e%:R == 0 :> R}. by exists #|[set: R]%G|; rewrite // -order_dvdn order_dvdG ?inE. rewrite big_seq; elim/big_rec: _ => [|[p m] /= n]; first by rewrite oner_eq0. case/mem_prime_decomp=> p_pr _ _ IHn. elim: m => [|m IHm]; rewrite ?mul1n {IHn}// expnS -mulnA natrM. by case/eqP/domR/orP=> //; exists p; last apply/andP. pose Rp := pPrimeCharType pcharRp; pose L : {vspace Rp} := fullv. pose G := [set: {unit R}]; pose ofG : {unit R} -> Rp := val. pose projG (E : {vspace Rp}) := [preim ofG of E]. have inG t nzt: Sub t (finDomain_field nzt) \in G by rewrite inE. have card_projG E: #|projG E| = (p ^ \dim E - 1)%N. transitivity #|E|.-1; last by rewrite subn1 card_vspace card_Fp. rewrite (cardD1 0) mem0v (card_preim val_inj) /=. apply: eq_card => x; congr (_ && _); rewrite [LHS]codom_val. by apply/idP/idP=> [/(memPn _ _)-> | /fieldR]; rewrite ?unitr0. pose C u := 'C[ofG u]%AS; pose Q := 'C(L)%AS; pose q := (p ^ \dim Q)%N. have defC u: 'C[u] =i projG (C u). by move=> v; rewrite cent1E !inE (sameP cent1vP eqP). have defQ: 'Z(G) =i projG Q. move=> u /[!inE]. apply/centP/centvP=> cGu v _; last exact/val_inj/cGu/memvf. by have [-> | /inG/cGu[]] := eqVneq v 0; first by rewrite commr0. have q_gt1: (1 < q)%N by rewrite (ltn_exp2l 0) ?prime_gt1 ?adim_gt0. pose n := \dim_Q L; have oG: #|G| = (q ^ n - 1)%N. rewrite -expnM mulnC divnK ?skew_field_dimS ?subvf // -card_projG. by apply: eq_card => u; rewrite !inE memvf. have oZ: #|'Z(G)| = (q - 1)%N by rewrite -card_projG; apply: eq_card. suffices n_le1: (n <= 1)%N. move=> u v; apply/centvsP: (memvf (u : Rp)) (memvf (v : Rp)) => {u v}. rewrite -(geq_leqif (dimv_leqif_sup (subvf Q))) -/L. by rewrite leq_divLR ?mul1n ?skew_field_dimS ?subvf in n_le1. without loss n_gt1: / (1 < n)%N by rewrite ltnNge; apply: wlog_neg. have [q_gt0 n_gt0] := (ltnW q_gt1, ltnW n_gt1). have [z z_prim] := C_prim_root_exists n_gt0. have zn1: z ^+ n = 1 by apply: prim_expr_order. have /eqP-n1z: `|z| == 1 by rewrite -(pexpr_eq1 n_gt0) // -normrX zn1 normr1. suffices /eqP/normCBeq[t n1t [Dq Dz]]: `|q%:R - z : algC| == `|q%:R : algC| - `|z|. suffices z1: z == 1 by rewrite leq_eqVlt -dvdn1 (prim_order_dvd z_prim) z1. by rewrite Dz n1z mul1r -(eqr_pMn2r q_gt0) Dq normr_nat mulr_natl. pose aq d : algC := (cyclotomic (z ^+ (n %/ d)) d).[q%:R]. suffices: `|aq n| <= (q - 1)%:R. rewrite eq_le lerB_dist andbT n1z normr_nat natrB //; apply: le_trans. rewrite {}/aq horner_prod divnn n_gt0 expr1 normr_prod. rewrite (bigD1 (Ordinal n_gt1)) ?coprime1n //= !hornerE ler_peMr //. elim/big_ind: _ => // [|d _]; first exact: mulr_ege1. rewrite !hornerE; apply: le_trans (lerB_dist _ _). by rewrite normr_nat normrX n1z expr1n lerBDl (leC_nat 2). have Zaq d: d %| n -> aq d \in Num.int. move/(dvdn_prim_root z_prim)=> zd_prim. rewrite rpred_horner ?rpred_nat //= -Cintr_Cyclotomic //. by apply/polyOverP=> i; rewrite coef_map ?rpred_int. suffices: (aq n %| (q - 1)%:R)%C. rewrite {1}[aq n]intrEsign ?Zaq // -(rpredMsign _ (aq n < 0)%R). rewrite dvdC_mul2l ?signr_eq0 //. have /natrP[m ->]: `|aq n| \in Num.nat by rewrite natr_norm_int ?Zaq. by rewrite leC_nat dvdC_nat; apply: dvdn_leq; rewrite subn_gt0. have prod_aq m: m %| n -> \prod_(d < n.+1 | d %| m) aq d = (q ^ m - 1)%:R. move=> m_dv_n; transitivity ('X^m - 1).[q%:R : algC]; last first. by rewrite !hornerE -natrX natrB ?expn_gt0 ?prime_gt0. rewrite (prod_cyclotomic (dvdn_prim_root z_prim m_dv_n)). have def_divm: perm_eq (divisors m) [seq d <- index_iota 0 n.+1 | d %| m]. rewrite uniq_perm ?divisors_uniq ?filter_uniq ?iota_uniq // => d. rewrite -dvdn_divisors ?(dvdn_gt0 n_gt0) // mem_filter mem_iota ltnS /=. by apply/esym/andb_idr=> d_dv_m; rewrite dvdn_leq ?(dvdn_trans d_dv_m). rewrite (perm_big _ def_divm) big_filter big_mkord horner_prod. by apply: eq_bigr => d d_dv_m; rewrite -exprM muln_divA ?divnK. have /rpredBl<-: (aq n %| #|G|%:R)%C. rewrite oG -prod_aq // (bigD1 ord_max) //= dvdC_mulr //. by apply: rpred_prod => d /andP[/Zaq]. rewrite center_class_formula addrC oZ natrD addKr natr_sum /=. apply: rpred_sum => _ /imsetP[u /setDP[_ Z'u] ->]; rewrite -/G /=. have sQC: (Q <= C u)%VS by apply/subvP=> v /centvP-cLv; apply/cent1vP/cLv/memvf. have{sQC} /dvdnP[m Dm]: \dim Q %| \dim (C u) by apply: skew_field_dimS. have m_dv_n: m %| n by rewrite dvdn_divRL // -?Dm ?skew_field_dimS ?subvf. have m_gt0: (0 < m)%N := dvdn_gt0 n_gt0 m_dv_n. have{Dm} oCu: #|'C[u]| = (q ^ m - 1)%N. by rewrite -expnM mulnC -Dm (eq_card (defC u)) card_projG. have ->: #|u ^: G|%:R = \prod_(d < n.+1 | d %| n) (aq d / aq d ^+ (d %| m)). rewrite -index_cent1 natf_indexg ?subsetT //= setTI prodf_div prod_aq // -oG. congr (_ / _); rewrite big_mkcond oCu -prod_aq //= big_mkcond /=. by apply: eq_bigr => d _; case: ifP => [/dvdn_trans->| _]; rewrite ?if_same. rewrite (bigD1 ord_max) //= [n %| m](contraNF _ Z'u) => [|n_dv_m]; last first. rewrite -sub_cent1 subEproper eq_sym eqEcard subsetT oG oCu leq_sub2r //. by rewrite leq_exp2l // dvdn_leq. rewrite divr1 dvdC_mulr //; apply/rpred_prod => d /andP[/Zaq-Zaqd _]. have [-> | nz_aqd] := eqVneq (aq d) 0; first by rewrite mul0r /=. by rewrite -[aq d]expr1 -exprB ?leq_b1 ?unitfE ?rpredX. Qed. Definition FinDomainFieldType : finFieldType := let cC := GRing.PzRing_hasCommutativeMul.Build R finDomain_mulrC in let cR : comUnitRingType := HB.pack R cC in let iC := GRing.ComUnitRing_isIntegral.Build cR domR in let iR : finIdomainType := HB.pack cR iC in let fC := GRing.UnitRing_isField.Build iR finDomain_field in HB.pack iR fC. Definition FinDomainSplittingFieldType_pchar p (pcharRp : p \in [pchar R]) := SplittingField.clone 'F_p R (@pPrimeCharType p FinDomainFieldType pcharRp). End FinDomain. #[deprecated(since="mathcomp 2.4.0", note="Use FinDomainSplittingFieldType_pchar instead.")] Notation FinDomainSplittingFieldType := (FinDomainSplittingFieldType_pchar) (only parsing).
Instances.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, Mario Carneiro -/ import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.GroupTheory.GroupAction.IterateAct import Mathlib.Data.Rat.Init import Mathlib.Data.ZMod.Defs /-! # Measurable-space typeclass instances This file provides measurable-space instances for a selection of standard countable types, in each case defining the Σ-algebra to be `⊤` (the discrete measurable-space structure). -/ instance Empty.instMeasurableSpace : MeasurableSpace Empty := ⊤ instance PUnit.instMeasurableSpace : MeasurableSpace PUnit := ⊤ instance Bool.instMeasurableSpace : MeasurableSpace Bool := ⊤ instance Prop.instMeasurableSpace : MeasurableSpace Prop := ⊤ instance Nat.instMeasurableSpace : MeasurableSpace ℕ := ⊤ instance ENat.instMeasurableSpace : MeasurableSpace ℕ∞ := ⊤ instance Fin.instMeasurableSpace (n : ℕ) : MeasurableSpace (Fin n) := ⊤ instance ZMod.instMeasurableSpace (n : ℕ) : MeasurableSpace (ZMod n) := ⊤ instance Int.instMeasurableSpace : MeasurableSpace ℤ := ⊤ instance Rat.instMeasurableSpace : MeasurableSpace ℚ := ⊤ @[to_additive] instance IterateMulAct.instMeasurableSpace {α : Type*} {f : α → α} : MeasurableSpace (IterateMulAct f) := ⊤ @[to_additive] instance IterateMulAct.instDiscreteMeasurableSpace {α : Type*} {f : α → α} : DiscreteMeasurableSpace (IterateMulAct f) := inferInstance instance (priority := 100) Subsingleton.measurableSingletonClass {α} [MeasurableSpace α] [Subsingleton α] : MeasurableSingletonClass α := by refine ⟨fun i => ?_⟩ convert MeasurableSet.univ simp [Set.eq_univ_iff_forall, eq_iff_true_of_subsingleton] instance Bool.instMeasurableSingletonClass : MeasurableSingletonClass Bool := ⟨fun _ => trivial⟩ instance Prop.instMeasurableSingletonClass : MeasurableSingletonClass Prop := ⟨fun _ => trivial⟩ instance Nat.instMeasurableSingletonClass : MeasurableSingletonClass ℕ := ⟨fun _ => trivial⟩ instance ENat.instDiscreteMeasurableSpace : DiscreteMeasurableSpace ℕ∞ := ⟨fun _ ↦ trivial⟩ instance ENat.instMeasurableSingletonClass : MeasurableSingletonClass ℕ∞ := inferInstance instance Fin.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (Fin n) := ⟨fun _ => trivial⟩ instance ZMod.instMeasurableSingletonClass (n : ℕ) : MeasurableSingletonClass (ZMod n) := ⟨fun _ => trivial⟩ instance Int.instMeasurableSingletonClass : MeasurableSingletonClass ℤ := ⟨fun _ => trivial⟩ instance Rat.instMeasurableSingletonClass : MeasurableSingletonClass ℚ := ⟨fun _ => trivial⟩
GaussSum.lean
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic import Mathlib.NumberTheory.GaussSum /-! # Quadratic characters of finite fields Further facts relying on Gauss sums. -/ /-! ### Basic properties of the quadratic character We prove some properties of the quadratic character. We work with a finite field `F` here. The interesting case is when the characteristic of `F` is odd. -/ section SpecialValues open ZMod MulChar variable {F : Type*} [Field F] [Fintype F] /-- The value of the quadratic character at `2` -/ theorem quadraticChar_two [DecidableEq F] (hF : ringChar F ≠ 2) : quadraticChar F 2 = χ₈ (Fintype.card F) := IsQuadratic.eq_of_eq_coe (quadraticChar_isQuadratic F) isQuadratic_χ₈ hF ((quadraticChar_eq_pow_of_char_ne_two' hF 2).trans (FiniteField.two_pow_card hF)) /-- `2` is a square in `F` iff `#F` is not congruent to `3` or `5` mod `8`. -/ theorem FiniteField.isSquare_two_iff : IsSquare (2 : F) ↔ Fintype.card F % 8 ≠ 3 ∧ Fintype.card F % 8 ≠ 5 := by classical by_cases hF : ringChar F = 2 · have h := FiniteField.even_card_of_char_two hF simp only [FiniteField.isSquare_of_char_two hF, true_iff] omega · have h := FiniteField.odd_card_of_char_ne_two hF rw [← quadraticChar_one_iff_isSquare (Ring.two_ne_zero hF), quadraticChar_two hF, χ₈_nat_eq_if_mod_eight] omega /-- The value of the quadratic character at `-2` -/ theorem quadraticChar_neg_two [DecidableEq F] (hF : ringChar F ≠ 2) : quadraticChar F (-2) = χ₈' (Fintype.card F) := by rw [(by simp : (-2 : F) = -1 * 2), map_mul, χ₈'_eq_χ₄_mul_χ₈, quadraticChar_neg_one hF, quadraticChar_two hF, @cast_natCast _ (ZMod 4) _ _ _ (by decide : 4 ∣ 8)] /-- `-2` is a square in `F` iff `#F` is not congruent to `5` or `7` mod `8`. -/ theorem FiniteField.isSquare_neg_two_iff : IsSquare (-2 : F) ↔ Fintype.card F % 8 ≠ 5 ∧ Fintype.card F % 8 ≠ 7 := by classical by_cases hF : ringChar F = 2 · have h := FiniteField.even_card_of_char_two hF simp only [FiniteField.isSquare_of_char_two hF, true_iff] omega · have h := FiniteField.odd_card_of_char_ne_two hF rw [← quadraticChar_one_iff_isSquare (neg_ne_zero.mpr (Ring.two_ne_zero hF)), quadraticChar_neg_two hF, χ₈'_nat_eq_if_mod_eight] omega /-- The relation between the values of the quadratic character of one field `F` at the cardinality of another field `F'` and of the quadratic character of `F'` at the cardinality of `F`. -/ theorem quadraticChar_card_card [DecidableEq F] (hF : ringChar F ≠ 2) {F' : Type*} [Field F'] [Fintype F'] [DecidableEq F'] (hF' : ringChar F' ≠ 2) (h : ringChar F' ≠ ringChar F) : quadraticChar F (Fintype.card F') = quadraticChar F' (quadraticChar F (-1) * Fintype.card F) := by let χ := (quadraticChar F).ringHomComp (algebraMap ℤ F') have hχ₁ : χ ≠ 1 := by obtain ⟨a, ha⟩ := quadraticChar_exists_neg_one' hF refine ne_one_iff.mpr ⟨a, ?_⟩ simpa only [ringHomComp_apply, ha, eq_intCast, Int.cast_neg, Int.cast_one, χ] using Ring.neg_one_ne_one_of_char_ne_two hF' have h := Char.card_pow_card hχ₁ ((quadraticChar_isQuadratic F).comp _) h hF' rw [← quadraticChar_eq_pow_of_char_ne_two' hF'] at h exact (IsQuadratic.eq_of_eq_coe (quadraticChar_isQuadratic F') (quadraticChar_isQuadratic F) hF' h).symm /-- The value of the quadratic character at an odd prime `p` different from `ringChar F`. -/ theorem quadraticChar_odd_prime [DecidableEq F] (hF : ringChar F ≠ 2) {p : ℕ} [Fact p.Prime] (hp₁ : p ≠ 2) (hp₂ : ringChar F ≠ p) : quadraticChar F p = quadraticChar (ZMod p) (χ₄ (Fintype.card F) * Fintype.card F) := by rw [← quadraticChar_neg_one hF] have h := quadraticChar_card_card hF (ne_of_eq_of_ne (ringChar_zmod_n p) hp₁) (ne_of_eq_of_ne (ringChar_zmod_n p) hp₂.symm) rwa [card p] at h /-- An odd prime `p` is a square in `F` iff the quadratic character of `ZMod p` does not take the value `-1` on `χ₄#F * #F`. -/ theorem FiniteField.isSquare_odd_prime_iff (hF : ringChar F ≠ 2) {p : ℕ} [Fact p.Prime] (hp : p ≠ 2) : IsSquare (p : F) ↔ quadraticChar (ZMod p) (χ₄ (Fintype.card F) * Fintype.card F) ≠ -1 := by classical by_cases hFp : ringChar F = p · rw [show (p : F) = 0 by rw [← hFp]; exact ringChar.Nat.cast_ringChar] simp only [IsSquare.zero, Ne, true_iff, map_mul] obtain ⟨n, _, hc⟩ := FiniteField.card F (ringChar F) have hchar : ringChar F = ringChar (ZMod p) := by rw [hFp]; exact (ringChar_zmod_n p).symm conv => enter [1, 1, 2]; rw [hc, Nat.cast_pow, map_pow, hchar, map_ringChar] simp only [zero_pow n.ne_zero, mul_zero, zero_eq_neg, one_ne_zero, not_false_iff] · rw [← Iff.not_left (@quadraticChar_neg_one_iff_not_isSquare F _ _ _ _), quadraticChar_odd_prime hF hp] exact hFp end SpecialValues
maximal.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 choice. From mathcomp Require Import div fintype finfun bigop finset prime binomial. From mathcomp Require Import fingroup morphism perm automorphism quotient. From mathcomp Require Import action commutator gproduct gfunctor ssralg . From mathcomp Require Import countalg finalg zmodp cyclic pgroup center gseries. From mathcomp Require Import nilpotent sylow abelian finmodule. (******************************************************************************) (* This file establishes basic properties of several important classes of *) (* maximal subgroups: maximal, max and min normal, simple, characteristically *) (* simple subgroups, the Frattini and Fitting subgroups, the Thompson *) (* critical subgroup, special and extra-special groups, and self-centralising *) (* normal (SCN) subgroups. In detail, we define: *) (* charsimple G == G is characteristically simple (it has no nontrivial *) (* characteristic subgroups, and is nontrivial) *) (* 'Phi(G) == the Frattini subgroup of G, i.e., the intersection of *) (* all its maximal proper subgroups. *) (* 'F(G) == the Fitting subgroup of G, i.e., the largest normal *) (* nilpotent subgroup of G (defined as the (direct) *) (* product of all the p-cores of G). *) (* critical C G == C is a critical subgroup of G: C is characteristic *) (* (but not functorial) in G, the center of C contains *) (* both its Frattini subgroup and the commutator [G, C], *) (* and is equal to the centraliser of C in G. The *) (* Thompson_critical theorem provides critical subgroups *) (* for p-groups; we also show that in this case the *) (* centraliser of C in Aut G is a p-group as well. *) (* special G == G is a special group: its center, Frattini, and *) (* derived sugroups coincide (we follow Aschbacher in *) (* not considering nontrivial elementary abelian groups *) (* as special); we show that a p-group factors under *) (* coprime action into special groups (Aschbacher 24.7). *) (* extraspecial G == G is a special group whose center has prime order *) (* (hence G is non-abelian). *) (* 'SCN(G) == the set of self-centralising normal abelian subgroups *) (* of G (the A <| G such that 'C_G(A) = A). *) (* 'SCN_n(G) == the subset of 'SCN(G) containing all groups with rank *) (* at least n (i.e., A \in 'SCN(G) and 'm(A) >= n). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Defs. Variable gT : finGroupType. Implicit Types (A B D : {set gT}) (G : {group gT}). Definition charsimple A := [min A of G | G :!=: 1 & G \char A]. Definition Frattini A := \bigcap_(G : {group gT} | maximal_eq G A) G. Canonical Frattini_group A : {group gT} := Eval hnf in [group of Frattini A]. Definition Fitting A := \big[dprod/1]_(p <- primes #|A|) 'O_p(A). Lemma Fitting_group_set G : group_set (Fitting G). Proof. suffices [F ->]: exists F : {group gT}, Fitting G = F by apply: groupP. rewrite /Fitting; elim: primes (primes_uniq #|G|) => [_|p r IHr] /=. by exists [1 gT]%G; rewrite big_nil. case/andP=> rp /IHr[F defF]; rewrite big_cons defF. suffices{IHr} /and3P[p'F sFG nFG]: p^'.-group F && (F <| G). have nFGp: 'O_p(G) \subset 'N(F) := gFsub_trans _ nFG. have pGp: p.-group('O_p(G)) := pcore_pgroup p G. have{pGp} tiGpF: 'O_p(G) :&: F = 1 by rewrite coprime_TIg ?(pnat_coprime pGp). exists ('O_p(G) <*> F)%G; rewrite dprodEY // (sameP commG1P trivgP) -tiGpF. by rewrite subsetI commg_subl commg_subr (subset_trans sFG) // gFnorm. move/bigdprodWY: defF => <- {F}; elim: r rp => [_|q r IHr] /=. by rewrite big_nil gen0 pgroup1 normal1. rewrite inE eq_sym big_cons -joingE -joing_idr => /norP[qp /IHr {IHr}]. set F := <<_>> => /andP[p'F nsFG]. rewrite norm_joinEl /= -/F; last exact/gFsub_trans/normal_norm. by rewrite pgroupM p'F normalM ?pcore_normal //= (pi_pgroup (pcore_pgroup q G)). Qed. Canonical Fitting_group G := group (Fitting_group_set G). Definition critical A B := [/\ A \char B, Frattini A \subset 'Z(A), [~: B, A] \subset 'Z(A) & 'C_B(A) = 'Z(A)]. Definition special A := Frattini A = 'Z(A) /\ A^`(1) = 'Z(A). Definition extraspecial A := special A /\ prime #|'Z(A)|. Definition SCN B := [set A : {group gT} | A <| B & 'C_B(A) == A]. Definition SCN_at n B := [set A in SCN B | n <= 'r(A)]. End Defs. Arguments charsimple {gT} A%_g. Arguments Frattini {gT} A%_g. Arguments Fitting {gT} A%_g. Arguments critical {gT} A%_g B%_g. Arguments special {gT} A%_g. Arguments extraspecial {gT} A%_g. Arguments SCN {gT} B%_g. Arguments SCN_at {gT} n%_N B%_g. Notation "''Phi' ( A )" := (Frattini A) (format "''Phi' ( A )") : group_scope. Notation "''Phi' ( G )" := (Frattini_group G) : Group_scope. Notation "''F' ( G )" := (Fitting G) (format "''F' ( G )") : group_scope. Notation "''F' ( G )" := (Fitting_group G) : Group_scope. Notation "''SCN' ( B )" := (SCN B) (format "''SCN' ( B )") : group_scope. Notation "''SCN_' n ( B )" := (SCN_at n B) (n at level 2, format "''SCN_' n ( B )") : group_scope. Section PMax. Variables (gT : finGroupType) (p : nat) (P M : {group gT}). Hypothesis pP : p.-group P. Lemma p_maximal_normal : maximal M P -> M <| P. Proof. case/maxgroupP=> /andP[sMP sPM] maxM; rewrite /normal sMP. have:= subsetIl P 'N(M); rewrite subEproper. case/predU1P=> [/setIidPl-> // | /maxM/= SNM]; case/negP: sPM. rewrite (nilpotent_sub_norm (pgroup_nil pP) sMP) //. by rewrite SNM // subsetI sMP normG. Qed. Lemma p_maximal_index : maximal M P -> #|P : M| = p. Proof. move=> maxM; have nM := p_maximal_normal maxM. rewrite -card_quotient ?normal_norm //. rewrite -(quotient_maximal _ nM) ?normal_refl // trivg_quotient in maxM. case/maxgroupP: maxM; rewrite properEneq eq_sym sub1G andbT /=. case/(pgroup_pdiv (quotient_pgroup M pP)) => p_pr /Cauchy[] // xq. rewrite /order -cycle_subG subEproper => /predU1P[-> // | sxPq oxq_p _]. by move/(_ _ sxPq (sub1G _)) => xq1; rewrite -oxq_p xq1 cards1 in p_pr. Qed. Lemma p_index_maximal : M \subset P -> prime #|P : M| -> maximal M P. Proof. move=> sMP /primeP[lt1PM pr_PM]. apply/maxgroupP; rewrite properEcard sMP -(Lagrange sMP). rewrite -{1}(muln1 #|M|) ltn_pmul2l //; split=> // H sHP sMH. apply/eqP; rewrite eq_sym eqEcard sMH. case/orP: (pr_PM _ (indexSg sMH (proper_sub sHP))) => /eqP iM. by rewrite -(Lagrange sMH) iM muln1 /=. by have:= proper_card sHP; rewrite -(Lagrange sMH) iM Lagrange ?ltnn. Qed. End PMax. Section Frattini. Variables gT : finGroupType. Implicit Type G M : {group gT}. Lemma Phi_sub G : 'Phi(G) \subset G. Proof. by rewrite bigcap_inf // /maximal_eq eqxx. Qed. Lemma Phi_sub_max G M : maximal M G -> 'Phi(G) \subset M. Proof. by move=> maxM; rewrite bigcap_inf // /maximal_eq predU1r. Qed. Lemma Phi_proper G : G :!=: 1 -> 'Phi(G) \proper G. Proof. move/eqP; case/maximal_exists: (sub1G G) => [<- //| [M maxM _] _]. exact: sub_proper_trans (Phi_sub_max maxM) (maxgroupp maxM). Qed. Lemma Phi_nongen G X : 'Phi(G) <*> X = G -> <<X>> = G. Proof. move=> defG; have: <<X>> \subset G by rewrite -{1}defG genS ?subsetUr. case/maximal_exists=> //= [[M maxM]]; rewrite gen_subG => sXM. case/andP: (maxgroupp maxM) => _ /negP[]. by rewrite -defG gen_subG subUset Phi_sub_max. Qed. Lemma Frattini_continuous (rT : finGroupType) G (f : {morphism G >-> rT}) : f @* 'Phi(G) \subset 'Phi(f @* G). Proof. apply/bigcapsP=> M maxM; rewrite sub_morphim_pre ?Phi_sub // bigcap_inf //. have {2}<-: f @*^-1 (f @* G) = G by rewrite morphimGK ?subsetIl. by rewrite morphpre_maximal_eq ?maxM //; case/maximal_eqP: maxM. Qed. End Frattini. Canonical Frattini_igFun := [igFun by Phi_sub & Frattini_continuous]. Canonical Frattini_gFun := [gFun by Frattini_continuous]. Section Frattini0. Variable gT : finGroupType. Implicit Types (rT : finGroupType) (D G : {group gT}). Lemma Phi_char G : 'Phi(G) \char G. Proof. exact: gFchar. Qed. Lemma Phi_normal G : 'Phi(G) <| G. Proof. exact: gFnormal. Qed. Lemma injm_Phi rT D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* 'Phi(G) = 'Phi(f @* G). Proof. exact: injmF. Qed. Lemma isog_Phi rT G (H : {group rT}) : G \isog H -> 'Phi(G) \isog 'Phi(H). Proof. exact: gFisog. Qed. Lemma PhiJ G x : 'Phi(G :^ x) = 'Phi(G) :^ x. Proof. rewrite -{1}(setIid G) -(setIidPr (Phi_sub G)) -!morphim_conj. by rewrite injm_Phi ?injm_conj. Qed. End Frattini0. Section Frattini2. Variables gT : finGroupType. Implicit Type G : {group gT}. Lemma Phi_quotient_id G : 'Phi (G / 'Phi(G)) = 1. Proof. apply/trivgP; rewrite -cosetpreSK cosetpre1 /=; apply/bigcapsP=> M maxM. have nPhi := Phi_normal G; have nPhiM: 'Phi(G) <| M. by apply: normalS nPhi; [apply: bigcap_inf | case/maximal_eqP: maxM]. by rewrite sub_cosetpre_quo ?bigcap_inf // quotient_maximal_eq. Qed. Lemma Phi_quotient_cyclic G : cyclic (G / 'Phi(G)) -> cyclic G. Proof. case/cyclicP=> /= Px; case: (cosetP Px) => x nPx ->{Px} defG. apply/cyclicP; exists x; symmetry; apply: Phi_nongen. rewrite -joing_idr norm_joinEr -?quotientK ?cycle_subG //. by rewrite /quotient morphim_cycle //= -defG quotientGK ?Phi_normal. Qed. Variables (p : nat) (P : {group gT}). Lemma trivg_Phi : p.-group P -> ('Phi(P) == 1) = p.-abelem P. Proof. move=> pP; case: (eqsVneq P 1) => [P1 | ntP]. by rewrite P1 abelem1 -subG1 -P1 Phi_sub. have [p_pr _ _] := pgroup_pdiv pP ntP. apply/eqP/idP=> [trPhi | abP]. apply/abelemP=> //; split=> [|x Px]. apply/commG1P/trivgP; rewrite -trPhi. apply/bigcapsP=> M /predU1P[-> | maxM]; first exact: der1_subG. have /andP[_ nMP]: M <| P := p_maximal_normal pP maxM. rewrite der1_min // cyclic_abelian // prime_cyclic // card_quotient //. by rewrite (p_maximal_index pP). apply/set1gP; rewrite -trPhi; apply/bigcapP=> M. case/predU1P=> [-> | maxM]; first exact: groupX. have /andP[_ nMP] := p_maximal_normal pP maxM. have nMx : x \in 'N(M) by apply: subsetP Px. apply: coset_idr; rewrite ?groupX ?morphX //=; apply/eqP. rewrite -(p_maximal_index pP maxM) -card_quotient // -order_dvdn cardSg //=. by rewrite cycle_subG mem_quotient. apply/trivgP/subsetP=> x Phi_x; rewrite -cycle_subG. have Px: x \in P by apply: (subsetP (Phi_sub P)). have sxP: <[x]> \subset P by rewrite cycle_subG. case/splitsP: (abelem_splits abP sxP) => K /complP[tiKx defP]. have [-> | nt_x] := eqVneq x 1; first by rewrite cycle1. have oxp := abelem_order_p abP Px nt_x. rewrite /= -tiKx subsetI subxx cycle_subG. apply: (bigcapP Phi_x); apply/orP; right. apply: p_index_maximal; rewrite -?divgS -defP ?mulG_subr //. by rewrite (TI_cardMg tiKx) mulnK // [#|_|]oxp. Qed. End Frattini2. Section Frattini3. Variables (gT : finGroupType) (p : nat) (P : {group gT}). Hypothesis pP : p.-group P. Lemma Phi_quotient_abelem : p.-abelem (P / 'Phi(P)). Proof. by rewrite -trivg_Phi ?morphim_pgroup //= Phi_quotient_id. Qed. Lemma Phi_joing : 'Phi(P) = P^`(1) <*> 'Mho^1(P). Proof. have [sPhiP nPhiP] := andP (Phi_normal P). apply/eqP; rewrite eqEsubset join_subG. case: (eqsVneq P 1) => [-> | ntP] in sPhiP *. by rewrite /= (trivgP sPhiP) sub1G der_subS Mho_sub. have [p_pr _ _] := pgroup_pdiv pP ntP. have [abP x1P] := abelemP p_pr Phi_quotient_abelem. apply/andP; split. have nMP: P \subset 'N(P^`(1) <*> 'Mho^1(P)) by rewrite normsY // !gFnorm. rewrite -quotient_sub1 ?gFsub_trans //=. suffices <-: 'Phi(P / (P^`(1) <*> 'Mho^1(P))) = 1 by apply: morphimF. apply/eqP; rewrite (trivg_Phi (morphim_pgroup _ pP)) /= -quotientE. apply/abelemP=> //; rewrite [abelian _]quotient_cents2 ?joing_subl //. split=> // _ /morphimP[x Nx Px ->] /=. rewrite -morphX //= coset_id // (MhoE 1 pP) joing_idr expn1. by rewrite mem_gen //; apply/setUP; right; apply: imset_f. rewrite -quotient_cents2 // [_ \subset 'C(_)]abP (MhoE 1 pP) gen_subG /=. apply/subsetP=> _ /imsetP[x Px ->]; rewrite expn1. have nPhi_x: x \in 'N('Phi(P)) by apply: (subsetP nPhiP). by rewrite coset_idr ?groupX ?morphX ?x1P ?mem_morphim. Qed. Lemma Phi_Mho : abelian P -> 'Phi(P) = 'Mho^1(P). Proof. by move=> cPP; rewrite Phi_joing (derG1P cPP) joing1G. Qed. End Frattini3. Section Frattini4. Variables (p : nat) (gT : finGroupType). Implicit Types (rT : finGroupType) (P G H K D : {group gT}). Lemma PhiS G H : p.-group H -> G \subset H -> 'Phi(G) \subset 'Phi(H). Proof. move=> pH sGH; rewrite (Phi_joing pH) (Phi_joing (pgroupS sGH pH)). by rewrite genS // setUSS ?dergS ?MhoS. Qed. Lemma morphim_Phi rT P D (f : {morphism D >-> rT}) : p.-group P -> P \subset D -> f @* 'Phi(P) = 'Phi(f @* P). Proof. move=> pP sPD; rewrite !(@Phi_joing _ p) ?morphim_pgroup //. rewrite morphim_gen ?subUset ?gFsub_trans // morphimU -joingE. by rewrite morphimR ?morphim_Mho. Qed. Lemma quotient_Phi P H : p.-group P -> P \subset 'N(H) -> 'Phi(P) / H = 'Phi(P / H). Proof. exact: morphim_Phi. Qed. (* This is Aschbacher (23.2) *) Lemma Phi_min G H : p.-group G -> G \subset 'N(H) -> p.-abelem (G / H) -> 'Phi(G) \subset H. Proof. move=> pG nHG; rewrite -trivg_Phi ?quotient_pgroup // -subG1 /=. by rewrite -(quotient_Phi pG) ?quotient_sub1 // gFsub_trans. Qed. Lemma Phi_cprod G H K : p.-group G -> H \* K = G -> 'Phi(H) \* 'Phi(K) = 'Phi(G). Proof. move=> pG defG; have [_ /mulG_sub[sHG sKG] cHK] := cprodP defG. rewrite cprodEY /=; last by rewrite (centSS (Phi_sub _) (Phi_sub _)). rewrite !(Phi_joing (pgroupS _ pG)) //=. have /cprodP[_ <- /cent_joinEr <-] := der_cprod 1 defG. have /cprodP[_ <- /cent_joinEr <-] := Mho_cprod 1 defG. by rewrite !joingA /= -!(joingA H^`(1)) (joingC K^`(1)). Qed. Lemma Phi_mulg H K : p.-group H -> p.-group K -> K \subset 'C(H) -> 'Phi(H * K) = 'Phi(H) * 'Phi(K). Proof. move=> pH pK cHK; have defHK := cprodEY cHK. have [|_ ->] /= := cprodP (Phi_cprod _ defHK); rewrite cent_joinEr //. by rewrite pgroupM pH. Qed. Lemma charsimpleP G : reflect (G :!=: 1 /\ forall K, K :!=: 1 -> K \char G -> K :=: G) (charsimple G). Proof. apply: (iffP mingroupP); rewrite char_refl andbT => -[ntG simG]. by split=> // K ntK chK; apply: simG; rewrite ?ntK // char_sub. by split=> // K /andP[ntK chK] _; apply: simG. Qed. End Frattini4. Section Fitting. Variable gT : finGroupType. Implicit Types (p : nat) (G H : {group gT}). Lemma Fitting_normal G : 'F(G) <| G. Proof. rewrite -['F(G)](bigdprodWY (erefl 'F(G))). elim/big_rec: _ => [|p H _ nsHG]; first by rewrite gen0 normal1. by rewrite -[<<_>>]joing_idr normalY ?pcore_normal. Qed. Lemma Fitting_sub G : 'F(G) \subset G. Proof. by rewrite normal_sub ?Fitting_normal. Qed. Lemma Fitting_nil G : nilpotent 'F(G). Proof. apply: (bigdprod_nil (erefl 'F(G))) => p _. exact: pgroup_nil (pcore_pgroup p G). Qed. Lemma Fitting_max G H : H <| G -> nilpotent H -> H \subset 'F(G). Proof. move=> nsHG nilH; rewrite -(Sylow_gen H) gen_subG. apply/bigcupsP=> P /SylowP[p _ sylP]. case Gp: (p \in \pi(G)); last first. rewrite card1_trivg ?sub1G // (card_Hall sylP). rewrite part_p'nat // (pnat_dvd (cardSg (normal_sub nsHG))) //. by rewrite /pnat cardG_gt0 all_predC has_pred1 Gp. rewrite {P sylP}(nilpotent_Hall_pcore nilH sylP). rewrite -(bigdprodWY (erefl 'F(G))) sub_gen //. rewrite -(filter_pi_of (ltnSn _)) big_filter big_mkord. apply: (bigcup_max (Sub p _)) => //= [|_]. by have:= Gp; rewrite ltnS mem_primes => /and3P[_ ntG /dvdn_leq->]. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans. Qed. Lemma pcore_Fitting pi G : 'O_pi('F(G)) \subset 'O_pi(G). Proof. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans ?Fitting_normal. Qed. Lemma p_core_Fitting p G : 'O_p('F(G)) = 'O_p(G). Proof. apply/eqP; rewrite eqEsubset pcore_Fitting pcore_max ?pcore_pgroup //. apply: normalS (normal_sub (Fitting_normal _)) (pcore_normal _ _). exact: Fitting_max (pcore_normal _ _) (pgroup_nil (pcore_pgroup _ _)). Qed. Lemma nilpotent_Fitting G : nilpotent G -> 'F(G) = G. Proof. by move=> nilG; apply/eqP; rewrite eqEsubset Fitting_sub Fitting_max. Qed. Lemma Fitting_eq_pcore p G : 'O_p^'(G) = 1 -> 'F(G) = 'O_p(G). Proof. move=> p'G1; have /dprodP[_ /= <- _ _] := nilpotent_pcoreC p (Fitting_nil G). by rewrite p_core_Fitting ['O_p^'(_)](trivgP _) ?mulg1 // -p'G1 pcore_Fitting. Qed. Lemma FittingEgen G : 'F(G) = <<\bigcup_(p < #|G|.+1 | (p : nat) \in \pi(G)) 'O_p(G)>>. Proof. apply/eqP; rewrite eqEsubset gen_subG /=. rewrite -{1}(bigdprodWY (erefl 'F(G))) (big_nth 0) big_mkord genS. by apply/bigcupsP=> p _; rewrite -p_core_Fitting pcore_sub. apply/bigcupsP=> [[i /= lti]] _; set p := nth _ _ i. have pi_p: p \in \pi(G) by rewrite mem_nth. have p_dv_G: p %| #|G| by rewrite mem_primes in pi_p; case/and3P: pi_p. have lepG: p < #|G|.+1 by rewrite ltnS dvdn_leq. by rewrite (bigcup_max (Ordinal lepG)). Qed. End Fitting. Section FittingFun. Implicit Types gT rT : finGroupType. Lemma morphim_Fitting : GFunctor.pcontinuous (@Fitting). Proof. move=> gT rT G D f; apply: Fitting_max. by rewrite morphim_normal ?Fitting_normal. by rewrite morphim_nil ?Fitting_nil. Qed. Lemma FittingS gT (G H : {group gT}) : H \subset G -> H :&: 'F(G) \subset 'F(H). Proof. move=> sHG; rewrite -{2}(setIidPl sHG). do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_Fitting. Qed. Lemma FittingJ gT (G : {group gT}) x : 'F(G :^ x) = 'F(G) :^ x. Proof. rewrite !FittingEgen -genJ /= cardJg; symmetry; congr <<_>>. rewrite (big_morph (conjugate^~ x) (fun A B => conjUg A B x) (imset0 _)). by apply: eq_bigr => p _; rewrite pcoreJ. Qed. End FittingFun. Canonical Fitting_igFun := [igFun by Fitting_sub & morphim_Fitting]. Canonical Fitting_gFun := [gFun by morphim_Fitting]. Canonical Fitting_pgFun := [pgFun by morphim_Fitting]. Section IsoFitting. Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}). Lemma Fitting_char : 'F(G) \char G. Proof. exact: gFchar. Qed. Lemma injm_Fitting : 'injm f -> G \subset D -> f @* 'F(G) = 'F(f @* G). Proof. exact: injmF. Qed. Lemma isog_Fitting (H : {group rT}) : G \isog H -> 'F(G) \isog 'F(H). Proof. exact: gFisog. Qed. End IsoFitting. Section CharSimple. Variable gT : finGroupType. Implicit Types (rT : finGroupType) (G H K L : {group gT}) (p : nat). Lemma minnormal_charsimple G H : minnormal H G -> charsimple H. Proof. case/mingroupP=> /andP[ntH nHG] minH. apply/charsimpleP; split=> // K ntK chK. by apply: minH; rewrite ?ntK (char_sub chK, char_norm_trans chK). Qed. Lemma maxnormal_charsimple G H L : G <| L -> maxnormal H G L -> charsimple (G / H). Proof. case/andP=> sGL nGL /maxgroupP[/andP[/andP[sHG not_sGH] nHL] maxH]. have nHG: G \subset 'N(H) := subset_trans sGL nHL. apply/charsimpleP; rewrite -subG1 quotient_sub1 //; split=> // HK ntHK chHK. case/(inv_quotientN _): (char_normal chHK) => [|K defHK sHK]; first exact/andP. case/andP; rewrite subEproper defHK => /predU1P[-> // | ltKG] nKG. have nHK: H <| K by rewrite /normal sHK (subset_trans (proper_sub ltKG)). case/negP: ntHK; rewrite defHK -subG1 quotient_sub1 ?normal_norm //. rewrite (maxH K) // ltKG -(quotientGK nHK) -defHK norm_quotient_pre //. by rewrite (char_norm_trans chHK) ?quotient_norms. Qed. Lemma abelem_split_dprod rT p (A B : {group rT}) : p.-abelem A -> B \subset A -> exists C : {group rT}, B \x C = A. Proof. move=> abelA sBA; have [_ cAA _]:= and3P abelA. case/splitsP: (abelem_splits abelA sBA) => C /complP[tiBC defA]. by exists C; rewrite dprodE // (centSS _ sBA cAA) // -defA mulG_subr. Qed. Lemma p_abelem_split1 rT p (A : {group rT}) x : p.-abelem A -> x \in A -> exists B : {group rT}, [/\ B \subset A, #|B| = #|A| %/ #[x] & <[x]> \x B = A]. Proof. move=> abelA Ax; have sxA: <[x]> \subset A by rewrite cycle_subG. have [B defA] := abelem_split_dprod abelA sxA. have [_ defxB _ ti_xB] := dprodP defA. have sBA: B \subset A by rewrite -defxB mulG_subr. by exists B; split; rewrite // -defxB (TI_cardMg ti_xB) mulKn ?order_gt0. Qed. Lemma abelem_charsimple p G : p.-abelem G -> G :!=: 1 -> charsimple G. Proof. move=> abelG ntG; apply/charsimpleP; split=> // K ntK /charP[sKG chK]. case/eqVproper: sKG => // /properP[sKG [x Gx notKx]]. have ox := abelem_order_p abelG Gx (group1_contra notKx). have [A [sAG oA defA]] := p_abelem_split1 abelG Gx. case/trivgPn: ntK => y Ky nty; have Gy := subsetP sKG y Ky. have{nty} oy := abelem_order_p abelG Gy nty. have [B [sBG oB defB]] := p_abelem_split1 abelG Gy. have: isog A B; last case/isogP=> fAB injAB defAB. rewrite (isog_abelem_card _ (abelemS sAG abelG)) (abelemS sBG) //=. by rewrite oA oB ox oy. have: isog <[x]> <[y]>; last case/isogP=> fxy injxy /= defxy. by rewrite isog_cyclic_card ?cycle_cyclic // [#|_|]oy -ox eqxx. have cfxA: fAB @* A \subset 'C(fxy @* <[x]>). by rewrite defAB defxy; case/dprodP: defB. have injf: 'injm (dprodm defA cfxA). by rewrite injm_dprodm injAB injxy defAB defxy; apply/eqP; case/dprodP: defB. case/negP: notKx; rewrite -cycle_subG -(injmSK injf) ?cycle_subG //=. rewrite morphim_dprodml // defxy cycle_subG /= chK //. have [_ {4}<- _ _] := dprodP defB; have [_ {3}<- _ _] := dprodP defA. by rewrite morphim_dprodm // defAB defxy. Qed. Lemma charsimple_dprod G : charsimple G -> exists H : {group gT}, [/\ H \subset G, simple H & exists2 I : {set {perm gT}}, I \subset Aut G & \big[dprod/1]_(f in I) f @: H = G]. Proof. case/charsimpleP=> ntG simG. have [H minH sHG]: {H : {group gT} | minnormal H G & H \subset G}. by apply: mingroup_exists; rewrite ntG normG. case/mingroupP: minH => /andP[ntH nHG] minH. pose Iok (I : {set {perm gT}}) := (I \subset Aut G) && [exists (M : {group gT} | M <| G), \big[dprod/1]_(f in I) f @: H == M]. have defH: (1 : {perm gT}) @: H = H. apply/eqP; rewrite eqEcard card_imset ?leqnn; last exact: perm_inj. by rewrite andbT; apply/subsetP=> _ /imsetP[x Hx ->]; rewrite perm1. have [|I] := @maxset_exists _ Iok 1. rewrite /Iok sub1G; apply/existsP; exists H. by rewrite /normal sHG nHG (big_pred1 1) => [|f]; rewrite ?defH /= ?inE. case/maxsetP=> /andP[Aut_I /exists_eq_inP[M /andP[sMG nMG] defM]] maxI. rewrite sub1set=> ntI; case/eqVproper: sMG => [defG | /andP[sMG not_sGM]]. exists H; split=> //; last by exists I; rewrite ?defM. apply/mingroupP; rewrite ntH normG; split=> // N /andP[ntN nNH] sNH. apply: minH => //; rewrite ntN /= -defG. move: defM; rewrite (bigD1 1) //= defH; case/dprodP=> [[_ K _ ->] <- cHK _]. by rewrite mul_subG // cents_norm // (subset_trans cHK) ?centS. have defG: <<\bigcup_(f in Aut G) f @: H>> = G. have sXG: \bigcup_(f in Aut G) f @: H \subset G. by apply/bigcupsP=> f Af; rewrite -(im_autm Af) morphimEdom imsetS. apply: simG. apply: contra ntH; rewrite -!subG1; apply: subset_trans. by rewrite sub_gen // (bigcup_max 1) ?group1 ?defH. rewrite /characteristic gen_subG sXG; apply/forall_inP=> f Af. rewrite -(autmE Af) -morphimEsub ?gen_subG ?morphim_gen // genS //. rewrite morphimEsub //= autmE. apply/subsetP=> _ /imsetP[_ /bigcupP[g Ag /imsetP[x Hx ->]] ->]. apply/bigcupP; exists (g * f); first exact: groupM. by apply/imsetP; exists x; rewrite // permM. have [f Af sfHM]: exists2 f, f \in Aut G & ~~ (f @: H \subset M). move: not_sGM; rewrite -{1}defG gen_subG; case/subsetPn=> x. by case/bigcupP=> f Af fHx Mx; exists f => //; apply/subsetPn; exists x. case If: (f \in I). by case/negP: sfHM; rewrite -(bigdprodWY defM) sub_gen // (bigcup_max f). case/idP: (If); rewrite -(maxI ([set f] :|: I)) ?subsetUr ?inE ?eqxx //. rewrite {maxI}/Iok subUset sub1set Af {}Aut_I; apply/existsP. have sfHG: autm Af @* H \subset G by rewrite -{4}(im_autm Af) morphimS. have{minH nHG} /mingroupP[/andP[ntfH nfHG] minfH]: minnormal (autm Af @* H) G. apply/mingroupP; rewrite andbC -{1}(im_autm Af) morphim_norms //=. rewrite -subG1 sub_morphim_pre // -kerE ker_autm subG1. split=> // N /andP[ntN nNG] sNfH. have sNG: N \subset G := subset_trans sNfH sfHG. apply/eqP; rewrite eqEsubset sNfH sub_morphim_pre //=. rewrite -(morphim_invmE (injm_autm Af)) [_ @* N]minH //=. rewrite -subG1 sub_morphim_pre /= ?im_autm // morphpre_invm morphim1 subG1. by rewrite ntN -{1}(im_invm (injm_autm Af)) /= {2}im_autm morphim_norms. by rewrite sub_morphim_pre /= ?im_autm // morphpre_invm. have{minfH sfHM} tifHM: autm Af @* H :&: M = 1. apply/eqP/idPn=> ntMfH; case/setIidPl: sfHM. rewrite -(autmE Af) -morphimEsub //. by apply: minfH; rewrite ?subsetIl // ntMfH normsI. have cfHM: M \subset 'C(autm Af @* H). rewrite centsC (sameP commG1P trivgP) -tifHM subsetI commg_subl commg_subr. by rewrite (subset_trans sMG) // (subset_trans sfHG). exists (autm Af @* H <*> M)%G; rewrite /normal /= join_subG sMG sfHG normsY //=. rewrite (bigD1 f) ?inE ?eqxx // (eq_bigl [in I]) /= => [|g]; last first. by rewrite /= !inE andbC; case: eqP => // ->. by rewrite defM -(autmE Af) -morphimEsub // dprodE // cent_joinEr ?eqxx. Qed. Lemma simple_sol_prime G : solvable G -> simple G -> prime #|G|. Proof. move=> solG /simpleP[ntG simG]. have{solG} cGG: abelian G. apply/commG1P; case/simG: (der_normal 1 G) => // /eqP/idPn[]. by rewrite proper_neq // (sol_der1_proper solG). case: (trivgVpdiv G) ntG => [-> | [p p_pr]]; first by rewrite eqxx. case/Cauchy=> // x Gx oxp _; move: p_pr; rewrite -oxp orderE. have: <[x]> <| G by rewrite -sub_abelian_normal ?cycle_subG. by case/simG=> -> //; rewrite cards1. Qed. Lemma charsimple_solvable G : charsimple G -> solvable G -> is_abelem G. Proof. case/charsimple_dprod=> H [sHG simH [I Aut_I defG]] solG. have p_pr: prime #|H| by apply: simple_sol_prime (solvableS sHG solG) simH. set p := #|H| in p_pr; apply/is_abelemP; exists p => //. elim/big_rec: _ (G) defG => [_ <-|f B If IH_B M defM]; first exact: abelem1. have [Af [[_ K _ defB] _ _ _]] := (subsetP Aut_I f If, dprodP defM). rewrite (dprod_abelem p defM) defB IH_B // andbT -(autmE Af) -morphimEsub //=. rewrite morphim_abelem ?abelemE // exponent_dvdn. by rewrite cyclic_abelian ?prime_cyclic. Qed. Lemma minnormal_solvable L G H : minnormal H L -> H \subset G -> solvable G -> [/\ L \subset 'N(H), H :!=: 1 & is_abelem H]. Proof. move=> minH sHG solG; have /andP[ntH nHL] := mingroupp minH. split=> //; apply: (charsimple_solvable (minnormal_charsimple minH)). exact: solvableS solG. Qed. Lemma solvable_norm_abelem L G : solvable G -> G <| L -> G :!=: 1 -> exists H : {group gT}, [/\ H \subset G, H <| L, H :!=: 1 & is_abelem H]. Proof. move=> solG /andP[sGL nGL] ntG. have [H minH sHG]: {H : {group gT} | minnormal H L & H \subset G}. by apply: mingroup_exists; rewrite ntG. have [nHL ntH abH] := minnormal_solvable minH sHG solG. by exists H; split; rewrite // /normal (subset_trans sHG). Qed. Lemma trivg_Fitting G : solvable G -> ('F(G) == 1) = (G :==: 1). Proof. move=> solG; apply/idP/idP=> [F1 | /eqP->]; last by rewrite gF1. apply/idPn=> /(solvable_norm_abelem solG (normal_refl _))[M [_ nsMG ntM]]. case/is_abelemP=> p _ /and3P[pM _ _]; case/negP: ntM. by rewrite -subG1 -(eqP F1) Fitting_max ?(pgroup_nil pM). Qed. Lemma Fitting_pcore pi G : 'F('O_pi(G)) = 'O_pi('F(G)). Proof. apply/eqP; rewrite eqEsubset. rewrite (subset_trans _ (pcoreS _ (Fitting_sub _))); last first. by rewrite subsetI Fitting_sub Fitting_max ?Fitting_nil ?gFnormal_trans. rewrite (subset_trans _ (FittingS (pcore_sub _ _))) // subsetI pcore_sub. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans. Qed. End CharSimple. Section SolvablePrimeFactor. Variables (gT : finGroupType) (G : {group gT}). Lemma index_maxnormal_sol_prime (H : {group gT}) : solvable G -> maxnormal H G G -> prime #|G : H|. Proof. move=> solG maxH; have nsHG := maxnormal_normal maxH. rewrite -card_quotient ?normal_norm // simple_sol_prime ?quotient_sol //. by rewrite quotient_simple. Qed. Lemma sol_prime_factor_exists : solvable G -> G :!=: 1 -> {H : {group gT} | H <| G & prime #|G : H| }. Proof. move=> solG /ex_maxnormal_ntrivg[H maxH]. by exists H; [apply: maxnormal_normal | apply: index_maxnormal_sol_prime]. Qed. End SolvablePrimeFactor. Section Special. Variables (gT : finGroupType) (p : nat) (A G : {group gT}). (* This is Aschbacher (23.7) *) Lemma center_special_abelem : p.-group G -> special G -> p.-abelem 'Z(G). Proof. move=> pG [defPhi defG']. have [-> | ntG] := eqsVneq G 1; first by rewrite center1 abelem1. have [p_pr _ _] := pgroup_pdiv pG ntG. have fM: {in 'Z(G) &, {morph expgn^~ p : x y / x * y}}. by move=> x y /setIP[_ /centP cxG] /setIP[/cxG cxy _]; apply: expgMn. rewrite abelemE //= center_abelian; apply/exponentP=> /= z Zz. apply: (@kerP _ _ _ (Morphism fM)) => //; apply: subsetP z Zz. rewrite -{1}defG' gen_subG; apply/subsetP=> _ /imset2P[x y Gx Gy ->]. have Zxy: [~ x, y] \in 'Z(G) by rewrite -defG' mem_commg. have Zxp: x ^+ p \in 'Z(G). rewrite -defPhi (Phi_joing pG) (MhoE 1 pG) joing_idr mem_gen // !inE. by rewrite expn1 orbC (imset_f (expgn^~ p)). rewrite mem_morphpre /= ?defG' ?Zxy // inE -commXg; last first. by red; case/setIP: Zxy => _ /centP->. by apply/commgP; red; case/setIP: Zxp => _ /centP->. Qed. Lemma exponent_special : p.-group G -> special G -> exponent G %| p ^ 2. Proof. move=> pG spG; have [defPhi _] := spG. have /and3P[_ _ expZ] := center_special_abelem pG spG. apply/exponentP=> x Gx; rewrite expgM (exponentP expZ) // -defPhi. by rewrite (Phi_joing pG) mem_gen // inE orbC (Mho_p_elt 1) ?(mem_p_elt pG). Qed. (* Aschbacher 24.7 (replaces Gorenstein 5.3.7) *) Theorem abelian_charsimple_special : p.-group G -> coprime #|G| #|A| -> [~: G, A] = G -> \bigcup_(H : {group gT} | (H \char G) && abelian H) H \subset 'C(A) -> special G /\ 'C_G(A) = 'Z(G). Proof. move=> pG coGA defG /bigcupsP cChaA. have cZA: 'Z(G) \subset 'C_G(A). by rewrite subsetI center_sub cChaA // center_char center_abelian. have cChaG (H : {group gT}): H \char G -> abelian H -> H \subset 'Z(G). move=> chH abH; rewrite subsetI char_sub //= centsC -defG. rewrite comm_norm_cent_cent ?(char_norm chH) -?commg_subl ?defG //. by rewrite centsC cChaA ?chH. have cZ2GG: [~: 'Z_2(G), G, G] = 1. by apply/commG1P; rewrite (subset_trans (ucn_comm 1 G)) // ucn1 subsetIr. have{cZ2GG} cG'Z: 'Z_2(G) \subset 'C(G^`(1)). by rewrite centsC; apply/commG1P; rewrite three_subgroup // (commGC G). have{cG'Z} sZ2G'_Z: 'Z_2(G) :&: G^`(1) \subset 'Z(G). apply: cChaG; first by rewrite charI ?ucn_char ?der_char. by rewrite /abelian subIset // (subset_trans cG'Z) // centS ?subsetIr. have{sZ2G'_Z} sG'Z: G^`(1) \subset 'Z(G). rewrite der1_min ?gFnorm //; apply/derG1P. have /TI_center_nil: nilpotent (G / 'Z(G)) := quotient_nil _ (pgroup_nil pG). apply; first exact: gFnormal; rewrite /= setIC -ucn1 -ucn_central. rewrite -quotient_der ?gFnorm // -quotientGI ?ucn_subS ?quotientS1 //=. by rewrite ucn1. have sCG': 'C_G(A) \subset G^`(1). rewrite -quotient_sub1 //; last by rewrite subIset ?gFnorm. rewrite (subset_trans (quotient_subcent _ G A)) //= -[G in G / _]defG. have nGA: A \subset 'N(G) by rewrite -commg_subl defG. rewrite quotientR ?gFnorm_trans ?normG //. rewrite coprime_abel_cent_TI ?quotient_norms ?coprime_morph //. exact: sub_der1_abelian. have defZ: 'Z(G) = G^`(1) by apply/eqP; rewrite eqEsubset (subset_trans cZA). split; last by apply/eqP; rewrite eqEsubset cZA defZ sCG'. split=> //; apply/eqP; rewrite eqEsubset defZ (Phi_joing pG) joing_subl. have:= pG; rewrite -pnat_exponent => /p_natP[n expGpn]. rewrite join_subG subxx andbT /= -defZ -(subnn n.-1). elim: {2}n.-1 => [|m IHm]. rewrite (MhoE _ pG) gen_subG; apply/subsetP=> _ /imsetP[x Gx ->]. rewrite subn0 -subn1 -add1n -maxnE maxnC maxnE expnD. by rewrite expgM -expGpn expg_exponent ?groupX ?group1. rewrite cChaG ?Mho_char //= (MhoE _ pG) /abelian cent_gen gen_subG. apply/centsP=> _ /imsetP[x Gx ->] _ /imsetP[y Gy ->]. move: sG'Z; rewrite subsetI centsC => /andP[_ /centsP cGG']. apply/commgP; rewrite {1}expnSr expgM. rewrite commXg -?commgX; try by apply: cGG'; rewrite ?mem_commg ?groupX. apply/commgP; rewrite subsetI Mho_sub centsC in IHm. apply: (centsP IHm); first by rewrite groupX. rewrite -add1n -(addn1 m) subnDA -maxnE maxnC maxnE. rewrite -expgM -expnSr -addSn expnD expgM groupX //=. by rewrite Mho_p_elt ?(mem_p_elt pG). Qed. End Special. Section Extraspecial. Variables (p : nat) (gT rT : finGroupType). Implicit Types D E F G H K M R S T U : {group gT}. Section Basic. Variable S : {group gT}. Hypotheses (pS : p.-group S) (esS : extraspecial S). Let pZ : p.-group 'Z(S) := pgroupS (center_sub S) pS. Lemma extraspecial_prime : prime p. Proof. by case: esS => _ /prime_gt1; rewrite cardG_gt1; case/(pgroup_pdiv pZ). Qed. Lemma card_center_extraspecial : #|'Z(S)| = p. Proof. by apply/eqP; apply: (pgroupP pZ); case: esS. Qed. Lemma min_card_extraspecial : #|S| >= p ^ 3. Proof. have p_gt1 := prime_gt1 extraspecial_prime. rewrite leqNgt (card_pgroup pS) ltn_exp2l // ltnS. case: esS => [[_ defS']]; apply: contraL => /(p2group_abelian pS)/derG1P S'1. by rewrite -defS' S'1 cards1. Qed. End Basic. Lemma card_p3group_extraspecial E : prime p -> #|E| = (p ^ 3)%N -> #|'Z(E)| = p -> extraspecial E. Proof. move=> p_pr oEp3 oZp; have p_gt0 := prime_gt0 p_pr. have pE: p.-group E by rewrite /pgroup oEp3 pnatX pnat_id. have pEq: p.-group (E / 'Z(E))%g by rewrite quotient_pgroup. have /andP[sZE nZE] := center_normal E. have oEq: #|E / 'Z(E)|%g = (p ^ 2)%N. by rewrite card_quotient -?divgS // oEp3 oZp expnS mulKn. have cEEq: abelian (E / 'Z(E))%g by apply: card_p2group_abelian oEq. have not_cEE: ~~ abelian E. have: #|'Z(E)| < #|E| by rewrite oEp3 oZp (ltn_exp2l 1) ?prime_gt1. by apply: contraL => cEE; rewrite -leqNgt subset_leq_card // subsetI subxx. have defE': E^`(1) = 'Z(E). apply/eqP; rewrite eqEsubset der1_min //=; apply: contraR not_cEE => not_sE'Z. apply/commG1P/(TI_center_nil (pgroup_nil pE) (der_normal 1 _)). by rewrite setIC prime_TIg ?oZp. split; [split=> // | by rewrite oZp]; apply/eqP. rewrite eqEsubset andbC -{1}defE' {1}(Phi_joing pE) joing_subl. rewrite -quotient_sub1 ?gFsub_trans ?subG1 //=. rewrite (quotient_Phi pE) //= (trivg_Phi pEq). apply/abelemP=> //; split=> // Zx EqZx; apply/eqP; rewrite -order_dvdn /order. rewrite (card_pgroup (mem_p_elt pEq EqZx)) (@dvdn_exp2l _ _ 1) //. rewrite leqNgt -pfactor_dvdn // -oEq; apply: contra not_cEE => sEqZx. rewrite cyclic_center_factor_abelian //; apply/cyclicP. exists Zx; apply/eqP; rewrite eq_sym eqEcard cycle_subG EqZx -orderE. exact: dvdn_leq sEqZx. Qed. Lemma p3group_extraspecial G : p.-group G -> ~~ abelian G -> logn p #|G| <= 3 -> extraspecial G. Proof. move=> pG not_cGG; have /andP[sZG nZG] := center_normal G. have ntG: G :!=: 1 by apply: contraNneq not_cGG => ->; apply: abelian1. have ntZ: 'Z(G) != 1 by rewrite (center_nil_eq1 (pgroup_nil pG)). have [p_pr _ [n oG]] := pgroup_pdiv pG ntG; rewrite oG pfactorK //. have [_ _ [m oZ]] := pgroup_pdiv (pgroupS sZG pG) ntZ. have lt_m1_n: m.+1 < n. suffices: 1 < logn p #|(G / 'Z(G))|. rewrite card_quotient // -divgS // logn_div ?cardSg //. by rewrite oG oZ !pfactorK // ltn_subRL addn1. rewrite ltnNge; apply: contra not_cGG => cycGs. apply: cyclic_center_factor_abelian; rewrite (dvdn_prime_cyclic p_pr) //. by rewrite (card_pgroup (quotient_pgroup _ pG)) (dvdn_exp2l _ cycGs). rewrite -{lt_m1_n}(subnKC lt_m1_n) !addSn !ltnS leqn0 in oG *. case: m => // in oZ oG * => /eqP n2; rewrite {n}n2 in oG. exact: card_p3group_extraspecial oZ. Qed. Lemma extraspecial_nonabelian G : extraspecial G -> ~~ abelian G. Proof. case=> [[_ defG'] oZ]; rewrite /abelian (sameP commG1P eqP). by rewrite -derg1 defG' -cardG_gt1 prime_gt1. Qed. Lemma exponent_2extraspecial G : 2.-group G -> extraspecial G -> exponent G = 4. Proof. move=> p2G esG; have [spG _] := esG. case/dvdn_pfactor: (exponent_special p2G spG) => // k. rewrite leq_eqVlt ltnS => /predU1P[-> // | lek1] expG. case/negP: (extraspecial_nonabelian esG). by rewrite (@abelem_abelian _ 2) ?exponent2_abelem // expG pfactor_dvdn. Qed. Lemma injm_special D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> special G -> special (f @* G). Proof. move=> injf sGD [defPhiG defG']. by rewrite /special -morphim_der // -injm_Phi // defPhiG defG' injm_center. Qed. Lemma injm_extraspecial D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> extraspecial G -> extraspecial (f @* G). Proof. move=> injf sGD [spG ZG_pr]; split; first exact: injm_special spG. by rewrite -injm_center // card_injm // subIset ?sGD. Qed. Lemma isog_special G (R : {group rT}) : G \isog R -> special G -> special R. Proof. by case/isogP=> f injf <-; apply: injm_special. Qed. Lemma isog_extraspecial G (R : {group rT}) : G \isog R -> extraspecial G -> extraspecial R. Proof. by case/isogP=> f injf <-; apply: injm_extraspecial. Qed. Lemma cprod_extraspecial G H K : p.-group G -> H \* K = G -> H :&: K = 'Z(H) -> extraspecial H -> extraspecial K -> extraspecial G. Proof. move=> pG defG ziHK [[PhiH defH'] ZH_pr] [[PhiK defK'] ZK_pr]. have [_ defHK cHK]:= cprodP defG. have sZHK: 'Z(H) \subset 'Z(K). by rewrite subsetI -{1}ziHK subsetIr subIset // centsC cHK. have{sZHK} defZH: 'Z(H) = 'Z(K). by apply/eqP; rewrite eqEcard sZHK leq_eqVlt eq_sym -dvdn_prime2 ?cardSg. have defZ: 'Z(G) = 'Z(K). by case/cprodP: (center_cprod defG) => /= _ <- _; rewrite defZH mulGid. split; first split; rewrite defZ //. by have /cprodP[_ <- _] := Phi_cprod pG defG; rewrite PhiH PhiK defZH mulGid. by have /cprodP[_ <- _] := der_cprod 1 defG; rewrite defH' defK' defZH mulGid. Qed. (* Lemmas bundling Aschbacher (23.10) with (19.1), (19.2), (19.12) and (20.8) *) Section ExtraspecialFormspace. Variable G : {group gT}. Hypotheses (pG : p.-group G) (esG : extraspecial G). Let p_pr := extraspecial_prime pG esG. Let oZ := card_center_extraspecial pG esG. Let p_gt1 := prime_gt1 p_pr. Let p_gt0 := prime_gt0 p_pr. (* This encasulates Aschbacher (23.10)(1). *) Lemma cent1_extraspecial_maximal x : x \in G -> x \notin 'Z(G) -> maximal 'C_G[x] G. Proof. move=> Gx notZx; pose f y := [~ x, y]; have [[_ defG'] prZ] := esG. have{defG'} fZ y: y \in G -> f y \in 'Z(G). by move=> Gy; rewrite -defG' mem_commg. have fM: {in G &, {morph f : y z / y * z}}%g. move=> y z Gy Gz; rewrite {1}/f commgMJ conjgCV -conjgM (conjg_fixP _) //. rewrite (sameP commgP cent1P); apply: subsetP (fZ y Gy). by rewrite subIset // orbC -cent_set1 centS // sub1set !(groupM, groupV). pose fm := Morphism fM. have fmG: fm @* G = 'Z(G). have sfmG: fm @* G \subset 'Z(G). by apply/subsetP=> _ /morphimP[z _ Gz ->]; apply: fZ. apply/eqP; rewrite eqEsubset sfmG; apply: contraR notZx => /(prime_TIg prZ). rewrite (setIidPr _) // => fmG1; rewrite inE Gx; apply/centP=> y Gy. by apply/commgP; rewrite -in_set1 -[[set _]]fmG1; apply: mem_morphim. have ->: 'C_G[x] = 'ker fm. apply/setP=> z; rewrite inE (sameP cent1P commgP) !inE. by rewrite -invg_comm eq_invg_mul mulg1. rewrite p_index_maximal ?subsetIl // -card_quotient ?ker_norm //. by rewrite (card_isog (first_isog fm)) /= fmG. Qed. (* This is the tranposition of the hyperplane dimension theorem (Aschbacher *) (* (19.1)) to subgroups of an extraspecial group. *) Lemma subcent1_extraspecial_maximal U x : U \subset G -> x \in G :\: 'C(U) -> maximal 'C_U[x] U. Proof. move=> sUG /setDP[Gx not_cUx]; apply/maxgroupP; split=> [|H ltHU sCxH]. by rewrite /proper subsetIl subsetI subxx sub_cent1. case/andP: ltHU => sHU not_sHU; have sHG := subset_trans sHU sUG. apply/eqP; rewrite eqEsubset sCxH subsetI sHU /= andbT. apply: contraR not_sHU => not_sHCx. have maxCx: maximal 'C_G[x] G. rewrite cent1_extraspecial_maximal //; apply: contra not_cUx. by rewrite inE Gx; apply: subsetP (centS sUG) _. have nsCx := p_maximal_normal pG maxCx. rewrite -(setIidPl sUG) -(mulg_normal_maximal nsCx maxCx sHG) ?subsetI ?sHG //. by rewrite -group_modr //= setIA (setIidPl sUG) mul_subG. Qed. (* This is the tranposition of the orthogonal subspace dimension theorem *) (* (Aschbacher (19.2)) to subgroups of an extraspecial group. *) Lemma card_subcent_extraspecial U : U \subset G -> #|'C_G(U)| = (#|'Z(G) :&: U| * #|G : U|)%N. Proof. move=> sUG; rewrite setIAC (setIidPr sUG). have [m leUm] := ubnP #|U|; elim: m => // m IHm in U leUm sUG *. have [cUG | not_cUG]:= orP (orbN (G \subset 'C(U))). by rewrite !(setIidPl _) ?Lagrange // centsC. have{not_cUG} [x Gx not_cUx] := subsetPn not_cUG. pose W := 'C_U[x]; have sCW_G: 'C_G(W) \subset G := subsetIl G _. have maxW: maximal W U by rewrite subcent1_extraspecial_maximal // inE not_cUx. have nsWU: W <| U := p_maximal_normal (pgroupS sUG pG) maxW. have ltWU: W \proper U by apply: maxgroupp maxW. have [sWU [u Uu notWu]] := properP ltWU; have sWG := subset_trans sWU sUG. have defU: W * <[u]> = U by rewrite (mulg_normal_maximal nsWU) ?cycle_subG. have iCW_CU: #|'C_G(W) : 'C_G(U)| = p. rewrite -defU centM cent_cycle setIA /=; rewrite inE Uu cent1C in notWu. apply: p_maximal_index (pgroupS sCW_G pG) _. apply: subcent1_extraspecial_maximal sCW_G _. rewrite inE andbC (subsetP sUG) //= -sub_cent1. by apply/subsetPn; exists x; rewrite // inE Gx -sub_cent1 subsetIr. apply/eqP; rewrite -(eqn_pmul2r p_gt0) -{1}iCW_CU Lagrange ?setIS ?centS //. rewrite IHm ?(leq_trans (proper_card ltWU)) // -setIA -mulnA. rewrite -(Lagrange_index sUG sWU) (p_maximal_index (pgroupS sUG pG)) //=. by rewrite -cent_set1 (setIidPr (centS _)) ?sub1set. Qed. (* This is the tranposition of the proof that a singular vector is contained *) (* in a hyperbolic plane (Aschbacher (19.12)) to subgroups of an extraspecial *) (* group. *) Lemma split1_extraspecial x : x \in G :\: 'Z(G) -> {E : {group gT} & {R : {group gT} | [/\ #|E| = (p ^ 3)%N /\ #|R| = #|G| %/ p ^ 2, E \* R = G /\ E :&: R = 'Z(E), 'Z(E) = 'Z(G) /\ 'Z(R) = 'Z(G), extraspecial E /\ x \in E & if abelian R then R :=: 'Z(G) else extraspecial R]}}. Proof. case/setDP=> Gx notZx; rewrite inE Gx /= in notZx. have [[defPhiG defG'] prZ] := esG. have maxCx: maximal 'C_G[x] G. by rewrite subcent1_extraspecial_maximal // inE notZx. pose y := repr (G :\: 'C[x]). have [Gy not_cxy]: y \in G /\ y \notin 'C[x]. move/maxgroupp: maxCx => /properP[_ [t Gt not_cyt]]. by apply/setDP; apply: (mem_repr t); rewrite !inE Gt andbT in not_cyt *. pose E := <[x]> <*> <[y]>; pose R := 'C_G(E). exists [group of E]; exists [group of R] => /=. have sEG: E \subset G by rewrite join_subG !cycle_subG Gx. have [Ex Ey]: x \in E /\ y \in E by rewrite !mem_gen // inE cycle_id ?orbT. have sZE: 'Z(G) \subset E. rewrite (('Z(G) =P E^`(1)) _) ?der_sub // eqEsubset -{2}defG' dergS // andbT. apply: contraR not_cxy => /= not_sZE'. rewrite (sameP cent1P commgP) -in_set1 -[[set 1]](prime_TIg prZ not_sZE'). by rewrite /= -defG' inE !mem_commg. have ziER: E :&: R = 'Z(E) by rewrite setIA (setIidPl sEG). have cER: R \subset 'C(E) by rewrite subsetIr. have iCxG: #|G : 'C_G[x]| = p by apply: p_maximal_index. have maxR: maximal R 'C_G[x]. rewrite /R centY !cent_cycle setIA. rewrite subcent1_extraspecial_maximal ?subsetIl // inE Gy andbT -sub_cent1. by apply/subsetPn; exists x; rewrite 1?cent1C // inE Gx cent1id. have sRCx: R \subset 'C_G[x] by rewrite -cent_cycle setIS ?centS ?joing_subl. have sCxG: 'C_G[x] \subset G by rewrite subsetIl. have sRG: R \subset G by rewrite subsetIl. have iRCx: #|'C_G[x] : R| = p by rewrite (p_maximal_index (pgroupS sCxG pG)). have defG: E * R = G. rewrite -cent_joinEr //= -/R joingC joingA. have cGx_x: <[x]> \subset 'C_G[x] by rewrite cycle_subG inE Gx cent1id. have nsRcx := p_maximal_normal (pgroupS sCxG pG) maxR. rewrite (norm_joinEr (subset_trans cGx_x (normal_norm nsRcx))). rewrite (mulg_normal_maximal nsRcx) //=; last first. by rewrite centY !cent_cycle cycle_subG !in_setI Gx cent1id cent1C. have nsCxG := p_maximal_normal pG maxCx. have syG: <[y]> \subset G by rewrite cycle_subG. rewrite (norm_joinEr (subset_trans syG (normal_norm nsCxG))). by rewrite (mulg_normal_maximal nsCxG) //= cycle_subG inE Gy. have defZR: 'Z(R) = 'Z(G) by rewrite -['Z(R)]setIA -centM defG. have defZE: 'Z(E) = 'Z(G). by rewrite -defG -center_prod ?mulGSid //= -ziER subsetI center_sub defZR sZE. have [n oG] := p_natP pG. have n_gt1: n > 1. by rewrite ltnW // -(@leq_exp2l p) // -oG min_card_extraspecial. have oR: #|R| = (p ^ n.-2)%N. apply/eqP; rewrite -(divg_indexS sRCx) iRCx /= -(divg_indexS sCxG) iCxG /= oG. by rewrite -{1}(subnKC n_gt1) subn2 !expnS !mulKn. have oE: #|E| = (p ^ 3)%N. apply/eqP; rewrite -(@eqn_pmul2r #|R|) ?cardG_gt0 // mul_cardG defG ziER. by rewrite defZE oZ oG -{1}(subnKC n_gt1) oR -expnSr -expnD subn2. rewrite cprodE // oR oG -expnB ?subn2 //; split=> //. by split=> //; apply: card_p3group_extraspecial _ oE _; rewrite // defZE. case: ifP => [cRR | not_cRR]; first by rewrite -defZR (center_idP _). split; rewrite /special defZR //. have ntR': R^`(1) != 1 by rewrite (sameP eqP commG1P) -abelianE not_cRR. have pR: p.-group R := pgroupS sRG pG. have pR': p.-group R^`(1) := pgroupS (der_sub 1 _) pR. have defR': R^`(1) = 'Z(G). apply/eqP; rewrite eqEcard -{1}defG' dergS //= oZ. by have [_ _ [k ->]]:= pgroup_pdiv pR' ntR'; rewrite (leq_exp2l 1). split=> //; apply/eqP; rewrite eqEsubset -{1}defPhiG -defR' (PhiS pG) //=. by rewrite (Phi_joing pR) joing_subl. Qed. (* This is the tranposition of the proof that the dimension of any maximal *) (* totally singular subspace is equal to the Witt index (Aschbacher (20.8)), *) (* to subgroups of an extraspecial group (in a slightly more general form, *) (* since we allow for p != 2). *) (* Note that Aschbacher derives this from the Witt lemma, which we avoid. *) Lemma pmaxElem_extraspecial : 'E*_p(G) = 'E_p^('r_p(G))(G). Proof. have sZmax: {in 'E*_p(G), forall E, 'Z(G) \subset E}. move=> E maxE; have defE := pmaxElem_LdivP p_pr maxE. have abelZ: p.-abelem 'Z(G) by rewrite prime_abelem ?oZ. rewrite -(Ohm1_id abelZ) (OhmE 1 (abelem_pgroup abelZ)) gen_subG -defE. by rewrite setSI // setIS ?centS // -defE !subIset ?subxx. suffices card_max: {in 'E*_p(G) &, forall E F, #|E| <= #|F| }. have EprGmax: 'E_p^('r_p(G))(G) \subset 'E*_p(G) := p_rankElem_max p G. have [E EprE]:= p_rank_witness p G; have maxE := subsetP EprGmax E EprE. apply/eqP; rewrite eqEsubset EprGmax andbT; apply/subsetP=> F maxF. rewrite inE; have [-> _]:= pmaxElemP maxF; have [_ _ <-]:= pnElemP EprE. by apply/eqP; congr (logn p _); apply/eqP; rewrite eqn_leq !card_max. move=> E F maxE maxF; set U := E :&: F. have [sUE sUF]: U \subset E /\ U \subset F by apply/andP; rewrite -subsetI. have sZU: 'Z(G) \subset U by rewrite subsetI !sZmax. have [EpE _]:= pmaxElemP maxE; have{EpE} [sEG abelE] := pElemP EpE. have [EpF _]:= pmaxElemP maxF; have{EpF} [sFG abelF] := pElemP EpF. have [V] := abelem_split_dprod abelE sUE; case/dprodP=> _ defE cUV tiUV. have [W] := abelem_split_dprod abelF sUF; case/dprodP=> _ defF _ tiUW. have [sVE sWF]: V \subset E /\ W \subset F by rewrite -defE -defF !mulG_subr. have [sVG sWG] := (subset_trans sVE sEG, subset_trans sWF sFG). rewrite -defE -defF !TI_cardMg // leq_pmul2l ?cardG_gt0 //. rewrite -(leq_pmul2r (cardG_gt0 'C_G(W))) mul_cardG. rewrite card_subcent_extraspecial // mulnCA Lagrange // mulnC. rewrite leq_mul ?subset_leq_card //; last by rewrite mul_subG ?subsetIl. apply: subset_trans (sub1G _); rewrite -tiUV !subsetI subsetIl subIset ?sVE //=. rewrite -(pmaxElem_LdivP p_pr maxF) -defF centM -!setIA -(setICA 'C(W)). rewrite setIC (setIA G) setIS // subsetI cUV sub_LdivT. by case/and3P: (abelemS sVE abelE). Qed. End ExtraspecialFormspace. (* This is B & G, Theorem 4.15, as done in Aschbacher (23.8) *) Lemma critical_extraspecial R S : p.-group R -> S \subset R -> extraspecial S -> [~: S, R] \subset S^`(1) -> S \* 'C_R(S) = R. Proof. move=> pR sSR esS sSR_S'; have [[defPhi defS'] _] := esS. have [pS [sPS nPS]] := (pgroupS sSR pR, andP (Phi_normal S : 'Phi(S) <| S)). have{esS} oZS: #|'Z(S)| = p := card_center_extraspecial pS esS. have nSR: R \subset 'N(S) by rewrite -commg_subl (subset_trans sSR_S') ?der_sub. have nsCR: 'C_R(S) <| R by rewrite (normalGI nSR) ?cent_normal. have nCS: S \subset 'N('C_R(S)) by rewrite cents_norm // centsC subsetIr. rewrite cprodE ?subsetIr //= -{2}(quotientGK nsCR) normC -?quotientK //. congr (_ @*^-1 _); apply/eqP; rewrite eqEcard quotientS //=. rewrite -(card_isog (second_isog nCS)) setIAC (setIidPr sSR) /= -/'Z(S) -defPhi. rewrite -ker_conj_aut (card_isog (first_isog_loc _ nSR)) //=; set A := _ @* R. have{pS} abelSb := Phi_quotient_abelem pS; have [pSb cSSb _] := and3P abelSb. have [/= Xb defSb oXb] := grank_witness (S / 'Phi(S)). pose X := (repr \o val : coset_of _ -> gT) @: Xb. have sXS: X \subset S; last have nPX := subset_trans sXS nPS. apply/subsetP=> x; case/imsetP=> xb Xxb ->; have nPx := repr_coset_norm xb. rewrite -sub1set -(quotientSGK _ sPS) ?sub1set ?quotient_set1 //= sub1set. by rewrite coset_reprK -defSb mem_gen. have defS: <<X>> = S. apply: Phi_nongen; apply/eqP; rewrite eqEsubset join_subG sPS sXS -joing_idr. rewrite -genM_join sub_gen // -quotientSK ?quotient_gen // -defSb genS //. apply/subsetP=> xb Xxb; apply/imsetP; rewrite (setIidPr nPX). by exists (repr xb); rewrite /= ?coset_reprK //; apply: imset_f. pose f (a : {perm gT}) := [ffun x => if x \in X then x^-1 * a x else 1]. have injf: {in A &, injective f}. move=> _ _ /morphimP[y nSy Ry ->] /morphimP[z nSz Rz ->]. move/ffunP=> eq_fyz; apply: (@eq_Aut _ S); rewrite ?Aut_aut //= => x Sx. rewrite !norm_conj_autE //; apply: canRL (conjgKV z) _; rewrite -conjgM. rewrite /conjg -(centP _ x Sx) ?mulKg {x Sx}// -defS cent_gen -sub_cent1. apply/subsetP=> x Xx; have Sx := subsetP sXS x Xx. move/(_ x): eq_fyz; rewrite !ffunE Xx !norm_conj_autE // => /mulgI xy_xz. by rewrite cent1C inE conjg_set1 conjgM xy_xz conjgK. have sfA_XS': f @: A \subset pffun_on 1 X S^`(1). apply/subsetP=> _ /imsetP[_ /morphimP[y nSy Ry ->] ->]. apply/pffun_onP; split=> [|_ /imageP[x /= Xx ->]]. by apply/subsetP=> x; apply: contraNT => /[!ffunE]/negPf->. have Sx := subsetP sXS x Xx. by rewrite ffunE Xx norm_conj_autE // (subsetP sSR_S') ?mem_commg. rewrite -(card_in_imset injf) (leq_trans (subset_leq_card sfA_XS')) // defS'. rewrite card_pffun_on (card_pgroup pSb) -rank_abelem -?grank_abelian // -oXb. by rewrite -oZS ?leq_pexp2l ?cardG_gt0 ?leq_imset_card. Qed. (* This is part of Aschbacher (23.13) and (23.14). *) Theorem extraspecial_structure S : p.-group S -> extraspecial S -> {Es | all (fun E => (#|E| == p ^ 3)%N && ('Z(E) == 'Z(S))) Es & \big[cprod/1%g]_(E <- Es) E \* 'Z(S) = S}. Proof. have [m] := ubnP #|S|; elim: m S => // m IHm S leSm pS esS. have [x Z'x]: {x | x \in S :\: 'Z(S)}. apply/sigW/set0Pn; rewrite -subset0 subDset setU0. apply: contra (extraspecial_nonabelian esS) => sSZ. exact: abelianS sSZ (center_abelian S). have [E [R [[oE oR]]]]:= split1_extraspecial pS esS Z'x. case=> defS _ [defZE defZR] _; case: ifP => [_ defR | _ esR]. by exists [:: E]; rewrite /= ?oE ?defZE ?eqxx // big_seq1 -defR. have sRS: R \subset S by case/cprodP: defS => _ <- _; rewrite mulG_subr. have [|Es esEs defR] := IHm _ _ (pgroupS sRS pS) esR. rewrite oR (leq_trans (ltn_Pdiv _ _)) ?cardG_gt0 // (ltn_exp2l 0) //. exact: prime_gt1 (extraspecial_prime pS esS). exists (E :: Es); first by rewrite /= oE defZE !eqxx -defZR. by rewrite -defZR big_cons -cprodA defR. Qed. Section StructureCorollaries. Variable S : {group gT}. Hypotheses (pS : p.-group S) (esS : extraspecial S). Let p_pr := extraspecial_prime pS esS. Let oZ := card_center_extraspecial pS esS. (* This is Aschbacher (23.10)(2). *) Lemma card_extraspecial : {n | n > 0 & #|S| = (p ^ n.*2.+1)%N}. Proof. set T := S; exists (logn p #|T|)./2. rewrite half_gt0 ltnW // -(leq_exp2l _ _ (prime_gt1 p_pr)) -card_pgroup //. exact: min_card_extraspecial. have [Es] := extraspecial_structure pS esS; rewrite -[in RHS]/T. elim: Es T => [_ _ <-| E s IHs T] /=. by rewrite big_nil cprod1g oZ (pfactorK 1). rewrite -andbA big_cons -cprodA => /and3P[/eqP oEp3 /eqP defZE]. move=> /IHs{}IHs /cprodP[[_ U _ defU]]; rewrite defU => defT cEU. rewrite -(mulnK #|T| (cardG_gt0 (E :&: U))) -defT -mul_cardG /=. have ->: E :&: U = 'Z(S). apply/eqP; rewrite eqEsubset subsetI -{1 2}defZE subsetIl setIS //=. by case/cprodP: defU => [[V _ -> _]] <- _; apply: mulG_subr. rewrite (IHs U) // oEp3 oZ -expnD addSn expnS mulKn ?prime_gt0 //. by rewrite pfactorK //= uphalf_double. Qed. Lemma Aut_extraspecial_full : Aut_in (Aut S) 'Z(S) \isog Aut 'Z(S). Proof. have [p_gt1 p_gt0] := (prime_gt1 p_pr, prime_gt0 p_pr). have [Es] := extraspecial_structure pS esS. elim: Es S oZ => [T _ _ <-| E s IHs T oZT] /=. rewrite big_nil cprod1g (center_idP (center_abelian T)). by apply/Aut_sub_fullP=> // g injg gZ; exists g. rewrite -andbA big_cons -cprodA => /and3P[/eqP-oE /eqP-defZE es_s]. case/cprodP=> -[_ U _ defU]; rewrite defU => defT cEU. have sUT: U \subset T by rewrite -defT mulG_subr. have sZU: 'Z(T) \subset U. by case/cprodP: defU => [[V _ -> _] <- _]; apply: mulG_subr. have defZU: 'Z(E) = 'Z(U). apply/eqP; rewrite eqEsubset defZE subsetI sZU subIset ?centS ?orbT //=. by rewrite subsetI subIset ?sUT //= -defT centM setSI. apply: (Aut_cprod_full _ defZU); rewrite ?cprodE //; last first. by apply: IHs; rewrite -?defZU ?defZE. have oZE: #|'Z(E)| = p by rewrite defZE. have [p2 | odd_p] := even_prime p_pr. suffices <-: restr_perm 'Z(E) @* Aut E = Aut 'Z(E) by apply: Aut_in_isog. apply/eqP; rewrite eqEcard restr_perm_Aut ?center_sub //=. by rewrite card_Aut_cyclic ?prime_cyclic ?oZE // {1}p2 cardG_gt0. have pE: p.-group E by rewrite /pgroup oE pnatX pnat_id. have nZE: E \subset 'N('Z(E)) by rewrite normal_norm ?center_normal. have esE: extraspecial E := card_p3group_extraspecial p_pr oE oZE. have [[defPhiE defE'] prZ] := esE. have{defPhiE} sEpZ x: x \in E -> (x ^+ p)%g \in 'Z(E). move=> Ex; rewrite -defPhiE (Phi_joing pE) mem_gen // inE orbC. by rewrite (Mho_p_elt 1) // (mem_p_elt pE). have ltZE: 'Z(E) \proper E by rewrite properEcard subsetIl oZE oE (ltn_exp2l 1). have [x [Ex notZx oxp]]: exists x, [/\ x \in E, x \notin 'Z(E) & #[x] %| p]%N. have [_ [x Ex notZx]] := properP ltZE. case: (prime_subgroupVti <[x ^+ p]> prZ) => [sZxp | ]; last first. move/eqP; rewrite (setIidPl _) ?cycle_subG ?sEpZ //. by rewrite cycle_eq1 -order_dvdn; exists x. have [y Ey notxy]: exists2 y, y \in E & y \notin <[x]>. apply/subsetPn; apply: contra (extraspecial_nonabelian esE) => sEx. by rewrite (abelianS sEx) ?cycle_abelian. have: (y ^+ p)%g \in <[x ^+ p]> by rewrite (subsetP sZxp) ?sEpZ. case/cycleP=> i def_yp; set xi := (x ^- i)%g. have Exi: xi \in E by rewrite groupV groupX. exists (y * xi)%g; split; first by rewrite groupM. have sxpx: <[x ^+ p]> \subset <[x]> by rewrite cycle_subG mem_cycle. apply: contra notxy; move/(subsetP (subset_trans sZxp sxpx)). by rewrite groupMr // groupV mem_cycle. pose z := [~ xi, y]; have Zz: z \in 'Z(E) by rewrite -defE' mem_commg. case: (setIP Zz) => _; move/centP=> cEz. rewrite order_dvdn expMg_Rmul; try by apply: commute_sym; apply: cEz. rewrite def_yp expgVn -!expgM mulnC mulgV mul1g -order_dvdn. by rewrite (dvdn_trans (order_dvdG Zz)) //= oZE bin2odd // dvdn_mulr. have{oxp} ox: #[x] = p. apply/eqP; case/primeP: p_pr => _ dvd_p; case/orP: (dvd_p _ oxp) => //. by rewrite order_eq1; case: eqP notZx => // ->; rewrite group1. have [y Ey not_cxy]: exists2 y, y \in E & y \notin 'C[x]. by apply/subsetPn; rewrite sub_cent1; rewrite inE Ex in notZx. have notZy: y \notin 'Z(E). apply: contra not_cxy; rewrite inE Ey; apply: subsetP. by rewrite -cent_set1 centS ?sub1set. pose K := 'C_E[y]; have maxK: maximal K E by apply: cent1_extraspecial_maximal. have nsKE: K <| E := p_maximal_normal pE maxK; have [sKE nKE] := andP nsKE. have oK: #|K| = (p ^ 2)%N. by rewrite -(divg_indexS sKE) oE (p_maximal_index pE) ?mulKn. have cKK: abelian K := card_p2group_abelian p_pr oK. have sZK: 'Z(E) \subset K by rewrite setIS // -cent_set1 centS ?sub1set. have defE: K ><| <[x]> = E. have notKx: x \notin K by rewrite inE Ex cent1C. rewrite sdprodE ?(mulg_normal_maximal nsKE) ?cycle_subG ?(subsetP nKE) //. by rewrite setIC prime_TIg -?orderE ?ox ?cycle_subG. have /cyclicP[z defZ]: cyclic 'Z(E) by rewrite prime_cyclic ?oZE. apply/(Aut_sub_fullP (center_sub E)); rewrite /= defZ => g injg gZ. pose k := invm (injm_Zp_unitm z) (aut injg gZ). have fM: {in K &, {morph expgn^~ (val k): u v / u * v}}. by move=> u v Ku Kv; rewrite /= expgMn // /commute (centsP cKK). pose f := Morphism fM; have fK: f @* K = K. apply/setP=> u; rewrite morphimEdom. apply/imsetP/idP=> [[v Kv ->] | Ku]; first exact: groupX. exists (u ^+ expg_invn K (val k)); first exact: groupX. rewrite /f /= expgAC expgK // oK coprimeXl // -unitZpE //. by case: (k) => /=; rewrite orderE -defZ oZE => j; rewrite natr_Zp. have fMact: {in K & <[x]>, morph_act 'J 'J f (idm <[x]>)}. by move=> u v _ _; rewrite /= conjXg. exists (sdprodm_morphism defE fMact). rewrite im_sdprodm injm_sdprodm injm_idm -card_im_injm im_idm fK. have [_ -> _ ->] := sdprodP defE; rewrite !eqxx; split=> //= u Zu. rewrite sdprodmEl ?(subsetP sZK) ?defZ // -(autE injg gZ Zu). rewrite -[aut _ _](invmK (injm_Zp_unitm z)); first by rewrite permE Zu. by rewrite im_Zp_unitm Aut_aut. Qed. (* These are the parts of Aschbacher (23.12) and exercise 8.5 that are later *) (* used in Aschbacher (34.9), which itself replaces the informal discussion *) (* quoted from Gorenstein in the proof of B & G, Theorem 2.5. *) Lemma center_aut_extraspecial k : coprime k p -> exists2 f, f \in Aut S & forall z, z \in 'Z(S) -> f z = (z ^+ k)%g. Proof. have /cyclicP[z defZ]: cyclic 'Z(S) by rewrite prime_cyclic ?oZ. have oz: #[z] = p by rewrite orderE -defZ. rewrite coprime_sym -unitZpE ?prime_gt1 // -oz => u_k. pose g := Zp_unitm (FinRing.unit 'Z_#[z] u_k). have AutZg: g \in Aut 'Z(S) by rewrite defZ -im_Zp_unitm mem_morphim ?inE. have ZSfull := Aut_sub_fullP (center_sub S) Aut_extraspecial_full. have [f [injf fS fZ]] := ZSfull _ (injm_autm AutZg) (im_autm AutZg). exists (aut injf fS) => [|u Zu]; first exact: Aut_aut. have [Su _] := setIP Zu; have z_u: u \in <[z]> by rewrite -defZ. by rewrite autE // fZ //= autmE permE /= z_u /cyclem expg_znat. Qed. End StructureCorollaries. End Extraspecial. Section SCN. Variables (gT : finGroupType) (p : nat) (G : {group gT}). Implicit Types A Z H : {group gT}. Lemma SCN_P A : reflect (A <| G /\ 'C_G(A) = A) (A \in 'SCN(G)). Proof. by apply: (iffP setIdP) => [] [->]; move/eqP. Qed. Lemma SCN_abelian A : A \in 'SCN(G) -> abelian A. Proof. by case/SCN_P=> _ defA; rewrite /abelian -{1}defA subsetIr. Qed. Lemma exponent_Ohm1_class2 H : odd p -> p.-group H -> nil_class H <= 2 -> exponent 'Ohm_1(H) %| p. Proof. move=> odd_p pH; rewrite nil_class2 => sH'Z; apply/exponentP=> x /=. rewrite (OhmE 1 pH) expn1 gen_set_id => {x} [/LdivP[] //|]. apply/group_setP; split=> [|x y]; first by rewrite !inE group1 expg1n //=. case/LdivP=> Hx xp1 /LdivP[Hy yp1]; rewrite !inE groupM //=. have [_ czH]: [~ y, x] \in H /\ centralises [~ y, x] H. by apply/centerP; rewrite (subsetP sH'Z) ?mem_commg. rewrite expMg_Rmul ?xp1 ?yp1 /commute ?czH //= !mul1g. by rewrite bin2odd // -commXXg ?yp1 /commute ?czH // comm1g. Qed. (* SCN_max and max_SCN cover Aschbacher 23.15(1) *) Lemma SCN_max A : A \in 'SCN(G) -> [max A | A <| G & abelian A]. Proof. case/SCN_P => nAG scA; apply/maxgroupP; split=> [|H]. by rewrite nAG /abelian -{1}scA subsetIr. do 2![case/andP]=> sHG _ abelH sAH; apply/eqP. by rewrite eqEsubset sAH -scA subsetI sHG centsC (subset_trans sAH). Qed. Lemma max_SCN A : p.-group G -> [max A | A <| G & abelian A] -> A \in 'SCN(G). Proof. move/pgroup_nil=> nilG; rewrite /abelian. case/maxgroupP=> /andP[nsAG abelA] maxA; have [sAG nAG] := andP nsAG. rewrite inE nsAG eqEsubset /= andbC subsetI abelA normal_sub //=. rewrite -quotient_sub1; last by rewrite subIset 1?normal_norm. apply/trivgP; apply: (TI_center_nil (quotient_nil A nilG)). by rewrite quotient_normal // /normal subsetIl normsI ?normG ?norms_cent. apply/trivgP/subsetP=> _ /setIP[/morphimP[x Nx /setIP[_ Cx]] ->]. rewrite -cycle_subG in Cx => /setIP[GAx CAx]. have{CAx GAx}: <[coset A x]> <| G / A. by rewrite /normal cycle_subG GAx cents_norm // centsC cycle_subG. case/(inv_quotientN nsAG)=> B /= defB sAB nBG. rewrite -cycle_subG defB (maxA B) ?trivg_quotient // nBG. have{} defB : B :=: A * <[x]>. rewrite -quotientK ?cycle_subG ?quotient_cycle // defB quotientGK //. exact: normalS (normal_sub nBG) nsAG. apply/setIidPl; rewrite ?defB -[_ :&: _]center_prod //=. rewrite /center !(setIidPl _) //; apply: cycle_abelian. Qed. (* The two other assertions of Aschbacher 23.15 state properties of the *) (* normal series 1 <| Z = 'Ohm_1(A) <| A with A \in 'SCN(G). *) Section SCNseries. Variables A : {group gT}. Hypothesis SCN_A : A \in 'SCN(G). Let Z := 'Ohm_1(A). Let cAA := SCN_abelian SCN_A. Let sZA: Z \subset A := Ohm_sub 1 A. Let nZA : A \subset 'N(Z) := sub_abelian_norm cAA sZA. (* This is Aschbacher 23.15(2). *) Lemma der1_stab_Ohm1_SCN_series : ('C(Z) :&: 'C_G(A / Z | 'Q))^`(1) \subset A. Proof. case/SCN_P: SCN_A => /andP[sAG nAG] {4} <-. rewrite subsetI {1}setICA comm_subG ?subsetIl //= gen_subG. apply/subsetP=> w /imset2P[u v]. rewrite /= -groupV -(groupV _ v) /= astabQR //= -/Z !inE (groupV 'C(Z)). case/and4P=> cZu _ _ sRuZ /and4P[cZv' _ _ sRvZ] ->{w}. apply/centP=> a Aa; rewrite /commute -!mulgA (commgCV v) (mulgA u). rewrite (centP cZu); last by rewrite (subsetP sRvZ) ?mem_commg ?set11 ?groupV. rewrite 2!(mulgA v^-1) mulKVg 4!mulgA invgK (commgC u^-1) mulgA. rewrite -(mulgA _ _ v^-1) -(centP cZv') ?(subsetP sRuZ) ?mem_commg ?set11//. by rewrite -!mulgA invgK mulKVg !mulKg. Qed. (* This is Aschbacher 23.15(3); note that this proof does not depend on the *) (* maximality of A. *) Lemma Ohm1_stab_Ohm1_SCN_series : odd p -> p.-group G -> 'Ohm_1('C_G(Z)) \subset 'C_G(A / Z | 'Q). Proof. have [-> | ntG] := eqsVneq G 1; first by rewrite !(setIidPl (sub1G _)) Ohm1. move=> p_odd pG; have{ntG} [p_pr _ _] := pgroup_pdiv pG ntG. case/SCN_P: SCN_A => /andP[sAG nAG] _; have pA := pgroupS sAG pG. have pCGZ : p.-group 'C_G(Z) by rewrite (pgroupS _ pG) // subsetIl. rewrite {pCGZ}(OhmE 1 pCGZ) gen_subG; apply/subsetP=> x; rewrite /= 3!inE -andbA. rewrite -!cycle_subG => /and3P[sXG cZX xp1] /=; have cXX := cycle_abelian x. have nZX := cents_norm cZX; have{nAG} nAX := subset_trans sXG nAG. pose XA := <[x]> <*> A; pose C := 'C(<[x]> / Z | 'Q); pose CA := A :&: C. pose Y := <[x]> <*> CA; pose W := 'Ohm_1(Y). have sXC: <[x]> \subset C by rewrite sub_astabQ nZX (quotient_cents _ cXX). have defY : Y = <[x]> * CA by rewrite -norm_joinEl // normsI ?nAX ?normsG. have{nAX} defXA: XA = <[x]> * A := norm_joinEl nAX. suffices{sXC}: XA \subset Y. rewrite subsetI sXG /= sub_astabQ nZX centsC defY group_modl //= -/Z -/C. by rewrite subsetI sub_astabQ defXA quotientMl //= !mulG_subG; case/and4P. have sZCA: Z \subset CA by rewrite subsetI sZA [C]astabQ sub_cosetpre. have cZCA: CA \subset 'C(Z) by rewrite subIset 1?(sub_abelian_cent2 cAA). have sZY: Z \subset Y by rewrite (subset_trans sZCA) ?joing_subr. have{cZCA cZX} cZY: Y \subset 'C(Z) by rewrite join_subG cZX. have{cXX nZX} sY'Z : Y^`(1) \subset Z. rewrite der1_min ?cents_norm //= -/Y defY quotientMl // abelianM /= -/Z -/CA. rewrite !quotient_abelian // ?(abelianS _ cAA) ?subsetIl //=. by rewrite /= quotientGI ?Ohm_sub // quotient_astabQ subsetIr. have{sY'Z cZY} nil_classY: nil_class Y <= 2. by rewrite nil_class2 (subset_trans sY'Z ) // subsetI sZY centsC. have pY: p.-group Y by rewrite (pgroupS _ pG) // join_subG sXG subIset ?sAG. have sXW: <[x]> \subset W. by rewrite [W](OhmE 1 pY) ?genS // sub1set !inE -cycle_subG joing_subl. have{nil_classY pY sXW sZY sZCA} defW: W = <[x]> * Z. rewrite -[W](setIidPr (Ohm_sub _ _)) /= -/Y {1}defY -group_modl //= -/Y -/W. congr (_ * _); apply/eqP; rewrite eqEsubset {1}[Z](OhmE 1 pA). rewrite subsetI setIAC subIset //; first by rewrite sZCA -[Z]Ohm_id OhmS. rewrite sub_gen ?setIS //; apply/subsetP=> w Ww; rewrite inE. by apply/eqP; apply: exponentP w Ww; apply: exponent_Ohm1_class2. have{sXG sAG} sXAG: XA \subset G by rewrite join_subG sXG. have{sXAG} nilXA: nilpotent XA := nilpotentS sXAG (pgroup_nil pG). have sYXA: Y \subset XA by rewrite defY defXA mulgS ?subsetIl. rewrite -[Y](nilpotent_sub_norm nilXA) {nilXA sYXA}//= -/Y -/XA. suffices: 'N_XA('Ohm_1(Y)) \subset Y by apply/subset_trans/setIS/gFnorms. rewrite {XA}defXA -group_modl ?normsG /= -/W ?{W}defW ?mulG_subl //. rewrite {Y}defY mulgS // subsetI subsetIl {CA C}sub_astabQ subIset ?nZA //= -/Z. rewrite (subset_trans (quotient_subnorm _ _ _)) //= quotientMidr /= -/Z. rewrite -quotient_sub1 ?subIset ?cent_norm ?orbT //. rewrite (subset_trans (quotientI _ _ _)) ?coprime_TIg //. rewrite (@pnat_coprime p) // -/(p.-group _) ?quotient_pgroup {pA}//= -pgroupE. rewrite -(setIidPr (cent_sub _)) p'group_quotient_cent_prime //. by rewrite (dvdn_trans (dvdn_quotient _ _)) ?order_dvdn. Qed. End SCNseries. (* This is Aschbacher 23.16. *) Lemma Ohm1_cent_max_normal_abelem Z : odd p -> p.-group G -> [max Z | Z <| G & p.-abelem Z] -> 'Ohm_1('C_G(Z)) = Z. Proof. move=> p_odd pG; set X := 'Ohm_1('C_G(Z)). case/maxgroupP=> /andP[nsZG abelZ] maxZ. have [sZG nZG] := andP nsZG; have [_ cZZ expZp] := and3P abelZ. have{nZG} nsXG: X <| G by rewrite gFnormal_trans ?norm_normalI ?norms_cent. have cZX : X \subset 'C(Z) by apply/gFsub_trans/subsetIr. have{sZG expZp} sZX: Z \subset X. rewrite [X](OhmE 1 (pgroupS _ pG)) ?subsetIl ?sub_gen //. apply/subsetP=> x Zx; rewrite !inE ?(subsetP sZG) ?(subsetP cZZ) //=. by rewrite (exponentP expZp). suffices{sZX} expXp: (exponent X %| p). apply/eqP; rewrite eqEsubset sZX andbT -quotient_sub1 ?cents_norm //= -/X. have pGq: p.-group (G / Z) by rewrite quotient_pgroup. rewrite (TI_center_nil (pgroup_nil pGq)) ?quotient_normal //= -/X setIC. apply/eqP/trivgPn=> [[Zd]]; rewrite inE -!cycle_subG -cycle_eq1 -subG1 /= -/X. case/andP=> /sub_center_normal nsZdG. have{nsZdG} [D defD sZD nsDG] := inv_quotientN nsZG nsZdG; rewrite defD. have sDG := normal_sub nsDG; have nsZD := normalS sZD sDG nsZG. rewrite quotientSGK ?quotient_sub1 ?normal_norm //= -/X => sDX /negP[]. rewrite (maxZ D) // nsDG andbA (pgroupS sDG) ?(dvdn_trans (exponentS sDX)) //. have sZZD: Z \subset 'Z(D) by rewrite subsetI sZD centsC (subset_trans sDX). by rewrite (cyclic_factor_abelian sZZD) //= -defD cycle_cyclic. pose normal_abelian := [pred A : {group gT} | A <| G & abelian A]. have{nsZG cZZ} normal_abelian_Z : normal_abelian Z by apply/andP. have{normal_abelian_Z} [A maxA sZA] := maxgroup_exists normal_abelian_Z. have SCN_A : A \in 'SCN(G) by apply: max_SCN pG maxA. move/maxgroupp: maxA => /andP[nsAG cAA] {normal_abelian}. have pA := pgroupS (normal_sub nsAG) pG. have{abelZ maxZ nsAG cAA sZA} defA1: 'Ohm_1(A) = Z. have: Z \subset 'Ohm_1(A) by rewrite -(Ohm1_id abelZ) OhmS. by apply: maxZ; rewrite Ohm1_abelem ?gFnormal_trans. have{SCN_A} sX'A: X^`(1) \subset A. have sX_CWA1 : X \subset 'C('Ohm_1(A)) :&: 'C_G(A / 'Ohm_1(A) | 'Q). rewrite subsetI /X -defA1 (Ohm1_stab_Ohm1_SCN_series _ p_odd) //=. by rewrite gFsub_trans ?subsetIr. by apply: subset_trans (der1_stab_Ohm1_SCN_series SCN_A); rewrite commgSS. pose genXp := [pred U : {group gT} | 'Ohm_1(U) == U & ~~ (exponent U %| p)]. apply/idPn=> expXp'; have genXp_X: genXp [group of X] by rewrite /= Ohm_id eqxx. have{genXp_X expXp'} [U] := mingroup_exists genXp_X; case/mingroupP; case/andP. move/eqP=> defU1 expUp' minU sUX; case/negP: expUp'. have{nsXG} pU := pgroupS (subset_trans sUX (normal_sub nsXG)) pG. case gsetU1: (group_set 'Ldiv_p(U)). by rewrite -defU1 (OhmE 1 pU) gen_set_id // -sub_LdivT subsetIr. move: gsetU1; rewrite /group_set 2!inE group1 expg1n eqxx; case/subsetPn=> xy. case/imset2P=> x y /[!inE] /andP[Ux xp1] /andP[Uy yp1] ->{xy}. rewrite groupM //= => nt_xyp; pose XY := <[x]> <*> <[y]>. have{yp1 nt_xyp} defXY: XY = U. have sXY_U: XY \subset U by rewrite join_subG !cycle_subG Ux Uy. rewrite [XY]minU //= eqEsubset Ohm_sub (OhmE 1 (pgroupS _ pU)) //. rewrite /= joing_idl joing_idr genS; last first. by rewrite subsetI subset_gen subUset !sub1set !inE xp1 yp1. apply: contra nt_xyp => /exponentP-> //. by rewrite groupMl mem_gen // (set21, set22). have: <[x]> <|<| U by rewrite nilpotent_subnormal ?(pgroup_nil pU) ?cycle_subG. case/subnormalEsupport=> [defU | /=]. by apply: dvdn_trans (exponent_dvdn U) _; rewrite -defU order_dvdn. set V := <<class_support <[x]> U>>; case/andP=> sVU ltVU. have{genXp minU xp1 sVU ltVU} expVp: exponent V %| p. apply: contraR ltVU => expVp'; rewrite [V]minU //= expVp' eqEsubset Ohm_sub. rewrite (OhmE 1 (pgroupS sVU pU)) genS //= subsetI subset_gen class_supportEr. apply/bigcupsP=> z _; apply/subsetP=> v Vv. by rewrite inE -order_dvdn (dvdn_trans (order_dvdG Vv)) // cardJg order_dvdn. have{A pA defA1 sX'A V expVp} Zxy: [~ x, y] \in Z. rewrite -defA1 (OhmE 1 pA) mem_gen // !inE (exponentP expVp). by rewrite (subsetP sX'A) //= mem_commg ?(subsetP sUX). by rewrite groupMl -1?[x^-1]conjg1 mem_gen // imset2_f // ?groupV cycle_id. have{Zxy sUX cZX} cXYxy: [~ x, y] \in 'C(XY). by rewrite centsC in cZX; rewrite defXY (subsetP (centS sUX)) ?(subsetP cZX). rewrite -defU1 exponent_Ohm1_class2 // nil_class2 -defXY der1_joing_cycles //. by rewrite subsetI {1}defXY !cycle_subG groupR. Qed. Lemma critical_class2 H : critical H G -> nil_class H <= 2. Proof. case=> [chH _ sRZ _]. by rewrite nil_class2 (subset_trans _ sRZ) ?commSg // char_sub. Qed. (* This proof of the Thompson critical lemma is adapted from Aschbacher 23.6 *) Lemma Thompson_critical : p.-group G -> {K : {group gT} | critical K G}. Proof. move=> pG; pose qcr A := (A \char G) && ('Phi(A) :|: [~: G, A] \subset 'Z(A)). have [|K]:= @maxgroup_exists _ qcr 1 _. by rewrite /qcr char1 center1 commG1 subUset Phi_sub subxx. case/maxgroupP; rewrite {}/qcr subUset => /and3P[chK sPhiZ sRZ] maxK _. have sKG := char_sub chK; have nKG := char_normal chK. exists K; split=> //; apply/eqP; rewrite eqEsubset andbC setSI //=. have chZ: 'Z(K) \char G by [apply: subcent_char]; have nZG := char_norm chZ. have chC: 'C_G(K) \char G by apply: subcent_char chK. rewrite -quotient_sub1; last by rewrite subIset // char_norm. apply/trivgP; apply: (TI_center_nil (quotient_nil _ (pgroup_nil pG))). by rewrite quotient_normal ?norm_normalI ?norms_cent ?normal_norm. apply: TI_Ohm1; apply/trivgP; rewrite -trivg_quotient -sub_cosetpre_quo //. rewrite morphpreI quotientGK /=; last first. by apply: normalS (char_normal chZ); rewrite ?subsetIl ?setSI. set X := _ :&: _; pose gX := [group of X]. have sXG: X \subset G by rewrite subIset ?subsetIl. have cXK: K \subset 'C(gX) by rewrite centsC 2?subIset // subxx orbT. rewrite subsetI centsC cXK andbT -(mul1g K) -mulSG mul1g -(cent_joinEr cXK). rewrite [_ <*> K]maxK ?joing_subr //= andbC (cent_joinEr cXK). rewrite -center_prod // (subset_trans _ (mulG_subr _ _)). rewrite charM 1?charI ?(char_from_quotient (normal_cosetpre _)) //. by rewrite cosetpreK !gFchar_trans. rewrite (@Phi_mulg p) ?(pgroupS _ pG) // subUset commGC commMG; last first. by rewrite normsR ?(normsG sKG) // cents_norm // centsC. rewrite !mul_subG 1?commGC //. apply: subset_trans (commgS _ (subsetIr _ _)) _. rewrite -quotient_cents2 ?subsetIl // centsC // cosetpreK //. exact/gFsub_trans/subsetIr. have nZX := subset_trans sXG nZG; have pX : p.-group gX by apply: pgroupS pG. rewrite -quotient_sub1 ?gFsub_trans //=. have pXZ: p.-group (gX / 'Z(K)) by apply: morphim_pgroup. rewrite (quotient_Phi pX nZX) subG1 (trivg_Phi pXZ). apply: (abelemS (quotientS _ (subsetIr _ _))); rewrite /= cosetpreK /=. have pZ: p.-group 'Z(G / 'Z(K)). by rewrite (pgroupS (center_sub _)) ?morphim_pgroup. by rewrite Ohm1_abelem ?center_abelian. Qed. Lemma critical_p_stab_Aut H : critical H G -> p.-group G -> p.-group 'C(H | [Aut G]). Proof. move=> [chH sPhiZ sRZ eqCZ] pG; have sHG := char_sub chH. pose G' := (sdpair1 [Aut G] @* G)%G; pose H' := (sdpair1 [Aut G] @* H)%G. apply/pgroupP=> q pr_q; case/Cauchy=> //= f cHF; move: (cHF); rewrite astab_ract. case/setIP=> Af cHFP ofq; rewrite -cycle_subG in cHF; apply: (pgroupP pG) => //. pose F' := (sdpair2 [Aut G] @* <[f]>)%G. have trHF: [~: H', F'] = 1. apply/trivgP; rewrite gen_subG; apply/subsetP=> u; case/imset2P=> x' a'. case/morphimP=> x Gx Hx ->; case/morphimP=> a Aa Fa -> -> {u x' a'}. by rewrite inE commgEl -sdpair_act ?(astab_act (subsetP cHF _ Fa) Hx) ?mulVg. have sGH_H: [~: G', H'] \subset H'. by rewrite -morphimR ?(char_sub chH) // morphimS // commg_subr char_norm. have{trHF sGH_H} trFGH: [~: F', G', H'] = 1. apply: three_subgroup; last by rewrite trHF comm1G. by apply/trivgP; rewrite -trHF commSg. apply/negP=> qG; case: (qG); rewrite -ofq. suffices ->: f = 1 by rewrite order1 dvd1n. apply/permP=> x; rewrite perm1; case Gx: (x \in G); last first. by apply: out_perm (negbT Gx); case/setIdP: Af. have Gfx: f x \in G by rewrite -(im_autm Af) -{1}(autmE Af) mem_morphim. pose y := x^-1 * f x; have Gy: y \in G by rewrite groupMl ?groupV. have [inj1 inj2] := (injm_sdpair1 [Aut G], injm_sdpair2 [Aut G]). have Hy: y \in H. rewrite (subsetP (center_sub H)) // -eqCZ -cycle_subG. rewrite -(injmSK inj1) ?cycle_subG // injm_subcent // subsetI. rewrite morphimS ?morphim_cycle ?cycle_subG //=. suffices: sdpair1 [Aut G] y \in [~: G', F']. by rewrite commGC; apply: subsetP; apply/commG1P. rewrite morphM ?groupV ?morphV //= sdpair_act // -commgEl. by rewrite mem_commg ?mem_morphim ?cycle_id. have fy: f y = y := astabP cHFP _ Hy. have: (f ^+ q) x = x * y ^+ q. elim: (q) => [|i IHi]; first by rewrite perm1 mulg1. rewrite expgSr permM {}IHi -(autmE Af) morphM ?morphX ?groupX //= autmE. by rewrite fy expgS mulgA mulKVg. move/eqP; rewrite -{1}ofq expg_order perm1 eq_mulVg1 mulKg -order_dvdn. case/primeP: pr_q => _ pr_q /pr_q; rewrite order_eq1 -eq_mulVg1. by case: eqP => //= _ /eqP oyq; case: qG; rewrite -oyq order_dvdG. Qed. End SCN. Arguments SCN_P {gT G A}.
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.
Cones.lean
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Kim Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Functor.Const import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.Yoneda import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! # Cones and cocones We define `Cone F`, a cone over a functor `F`, and `F.cones : Cᵒᵖ ⥤ Type`, the functor associating to `X` the cones over `F` with cone point `X`. A cone `c` is defined by specifying its cone point `c.pt` and a natural transformation `c.π` from the constant `c.pt` valued functor to `F`. We provide `c.w f : c.π.app j ≫ F.map f = c.π.app j'` for any `f : j ⟶ j'` as a wrapper for `c.π.naturality f` avoiding unneeded identity morphisms. We define `c.extend f`, where `c : cone F` and `f : Y ⟶ c.pt` for some other `Y`, which replaces the cone point by `Y` and inserts `f` into each of the components of the cone. Similarly we have `c.whisker F` producing a `Cone (E ⋙ F)` We define morphisms of cones, and the category of cones. We define `Cone.postcompose α : cone F ⥤ cone G` for `α` a natural transformation `F ⟶ G`. And, of course, we dualise all this to cocones as well. For more results about the category of cones, see `cone_category.lean`. -/ -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅ open CategoryTheory variable {J : Type u₁} [Category.{v₁} J] variable {K : Type u₂} [Category.{v₂} K] variable {C : Type u₃} [Category.{v₃} C] variable {D : Type u₄} [Category.{v₄} D] variable {E : Type u₅} [Category.{v₅} E] open CategoryTheory open CategoryTheory.Category open CategoryTheory.Functor open Opposite namespace CategoryTheory namespace Functor variable (F : J ⥤ C) /-- If `F : J ⥤ C` then `F.cones` is the functor assigning to an object `X : C` the type of natural transformations from the constant functor with value `X` to `F`. An object representing this functor is a limit of `F`. -/ @[simps!] def cones : Cᵒᵖ ⥤ Type max u₁ v₃ := (const J).op ⋙ yoneda.obj F /-- If `F : J ⥤ C` then `F.cocones` is the functor assigning to an object `(X : C)` the type of natural transformations from `F` to the constant functor with value `X`. An object corepresenting this functor is a colimit of `F`. -/ @[simps!] def cocones : C ⥤ Type max u₁ v₃ := const J ⋙ coyoneda.obj (op F) end Functor section variable (J C) /-- Functorially associated to each functor `J ⥤ C`, we have the `C`-presheaf consisting of cones with a given cone point. -/ @[simps!] def cones : (J ⥤ C) ⥤ Cᵒᵖ ⥤ Type max u₁ v₃ where obj := Functor.cones map f := whiskerLeft (const J).op (yoneda.map f) /-- Contravariantly associated to each functor `J ⥤ C`, we have the `C`-copresheaf consisting of cocones with a given cocone point. -/ @[simps!] def cocones : (J ⥤ C)ᵒᵖ ⥤ C ⥤ Type max u₁ v₃ where obj F := Functor.cocones (unop F) map f := whiskerLeft (const J) (coyoneda.map f) end namespace Limits section /-- A `c : Cone F` is: * an object `c.pt` and * a natural transformation `c.π : c.pt ⟶ F` from the constant `c.pt` functor to `F`. Example: if `J` is a category coming from a poset then the data required to make a term of type `Cone F` is morphisms `πⱼ : c.pt ⟶ F j` for all `j : J` and, for all `i ≤ j` in `J`, morphisms `πᵢⱼ : F i ⟶ F j` such that `πᵢ ≫ πᵢⱼ = πᵢ`. `Cone F` is equivalent, via `cone.equiv` below, to `Σ X, F.cones.obj X`. -/ structure Cone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from the constant functor at `X` to `F` -/ π : (const J).obj pt ⟶ F instance inhabitedCone (F : Discrete PUnit ⥤ C) : Inhabited (Cone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ π := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => cat_disch } }⟩ @[reassoc (attr := simp)] theorem Cone.w {F : J ⥤ C} (c : Cone F) {j j' : J} (f : j ⟶ j') : c.π.app j ≫ F.map f = c.π.app j' := by rw [← c.π.naturality f] apply id_comp /-- A `c : Cocone F` is * an object `c.pt` and * a natural transformation `c.ι : F ⟶ c.pt` from `F` to the constant `c.pt` functor. For example, if the source `J` of `F` is a partially ordered set, then to give `c : Cocone F` is to give a collection of morphisms `ιⱼ : F j ⟶ c.pt` and, for all `j ≤ k` in `J`, morphisms `ιⱼₖ : F j ⟶ F k` such that `Fⱼₖ ≫ Fₖ = Fⱼ` for all `j ≤ k`. `Cocone F` is equivalent, via `Cone.equiv` below, to `Σ X, F.cocones.obj X`. -/ structure Cocone (F : J ⥤ C) where /-- An object of `C` -/ pt : C /-- A natural transformation from `F` to the constant functor at `pt` -/ ι : F ⟶ (const J).obj pt instance inhabitedCocone (F : Discrete PUnit ⥤ C) : Inhabited (Cocone F) := ⟨{ pt := F.obj ⟨⟨⟩⟩ ι := { app := fun ⟨⟨⟩⟩ => 𝟙 _ naturality := by intro X Y f match X, Y, f with | .mk A, .mk B, .up g => simp } }⟩ @[reassoc] theorem Cocone.w {F : J ⥤ C} (c : Cocone F) {j j' : J} (f : j ⟶ j') : F.map f ≫ c.ι.app j' = c.ι.app j := by rw [c.ι.naturality f] apply comp_id end variable {F : J ⥤ C} namespace Cone /-- The isomorphism between a cone on `F` and an element of the functor `F.cones`. -/ @[simps!] def equiv (F : J ⥤ C) : Cone F ≅ Σ X, F.cones.obj X where hom c := ⟨op c.pt, c.π⟩ inv c := { pt := c.1.unop π := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map to the vertex of a cone naturally induces a cone by composition. -/ @[simps] def extensions (c : Cone F) : yoneda.obj c.pt ⋙ uliftFunctor.{u₁} ⟶ F.cones where app _ f := (const J).map f.down ≫ c.π /-- A map to the vertex of a cone induces a cone by composition. -/ @[simps] def extend (c : Cone F) {X : C} (f : X ⟶ c.pt) : Cone F := { pt := X π := c.extensions.app (op X) ⟨f⟩ } /-- Whisker a cone by precomposition of a functor. -/ @[simps] def whisker (E : K ⥤ J) (c : Cone F) : Cone (E ⋙ F) where pt := c.pt π := whiskerLeft E c.π end Cone namespace Cocone /-- The isomorphism between a cocone on `F` and an element of the functor `F.cocones`. -/ def equiv (F : J ⥤ C) : Cocone F ≅ Σ X, F.cocones.obj X where hom c := ⟨c.pt, c.ι⟩ inv c := { pt := c.1 ι := c.2 } hom_inv_id := by funext X cases X rfl inv_hom_id := by funext X cases X rfl /-- A map from the vertex of a cocone naturally induces a cocone by composition. -/ @[simps] def extensions (c : Cocone F) : coyoneda.obj (op c.pt) ⋙ uliftFunctor.{u₁} ⟶ F.cocones where app _ f := c.ι ≫ (const J).map f.down /-- A map from the vertex of a cocone induces a cocone by composition. -/ @[simps] def extend (c : Cocone F) {Y : C} (f : c.pt ⟶ Y) : Cocone F where pt := Y ι := c.extensions.app Y ⟨f⟩ /-- Whisker a cocone by precomposition of a functor. See `whiskering` for a functorial version. -/ @[simps] def whisker (E : K ⥤ J) (c : Cocone F) : Cocone (E ⋙ F) where pt := c.pt ι := whiskerLeft E c.ι end Cocone /-- A cone morphism between two cones for the same diagram is a morphism of the cone points which commutes with the cone legs. -/ structure ConeMorphism (A B : Cone F) where /-- A morphism between the two vertex objects of the cones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ w : ∀ j : J, hom ≫ B.π.app j = A.π.app j := by cat_disch attribute [reassoc (attr := simp)] ConeMorphism.w instance inhabitedConeMorphism (A : Cone F) : Inhabited (ConeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ /-- The category of cones on a given diagram. -/ @[simps] instance Cone.category : Category (Cone F) where Hom A B := ConeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem ConeMorphism.ext {c c' : Cone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr @[reassoc (attr := simp)] lemma ConeMorphism.hom_inv_id {c d : Cone F} (f : c ≅ d) : f.hom.hom ≫ f.inv.hom = 𝟙 _ := by simp [← Cone.category_comp_hom] @[reassoc (attr := simp)] lemma ConeMorphism.inv_hom_id {c d : Cone F} (f : c ≅ d) : f.inv.hom ≫ f.hom.hom = 𝟙 _ := by simp [← Cone.category_comp_hom] instance {c d : Cone F} (f : c ≅ d) : IsIso f.hom.hom := ⟨f.inv.hom, by simp⟩ instance {c d : Cone F} (f : c ≅ d) : IsIso f.inv.hom := ⟨f.hom.hom, by simp⟩ namespace Cones /-- To give an isomorphism between cones, it suffices to give an isomorphism between their vertices which commutes with the cone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.π.app j = φ.hom ≫ c'.π.app j := by cat_disch) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.inv_comp_eq.mpr (w j) } /-- Eta rule for cones. -/ @[simps!] def eta (c : Cone F) : c ≅ ⟨c.pt, c.π⟩ := Cones.ext (Iso.refl _) /-- Given a cone morphism whose object part is an isomorphism, produce an isomorphism of cones. -/ theorem cone_iso_of_hom_iso {K : J ⥤ C} {c d : Cone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).inv_comp_eq.2 (f.w j).symm }, by cat_disch⟩⟩ /-- There is a morphism from an extended cone to the original cone. -/ @[simps] def extend (s : Cone F) {X : C} (f : X ⟶ s.pt) : s.extend f ⟶ s where hom := f /-- Extending a cone by the identity does nothing. -/ @[simps!] def extendId (s : Cone F) : s.extend (𝟙 s.pt) ≅ s := Cones.ext (Iso.refl _) /-- Extending a cone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cone F) {X Y : C} (f : X ⟶ Y) (g : Y ⟶ s.pt) : s.extend (f ≫ g) ≅ (s.extend g).extend f := Cones.ext (Iso.refl _) /-- A cone extended by an isomorphism is isomorphic to the original cone. -/ @[simps] def extendIso (s : Cone F) {X : C} (f : X ≅ s.pt) : s.extend f.hom ≅ s where hom := { hom := f.hom } inv := { hom := f.inv } instance {s : Cone F} {X : C} (f : X ⟶ s.pt) [IsIso f] : IsIso (Cones.extend s f) := ⟨(extendIso s (asIso f)).inv, by cat_disch⟩ /-- Functorially postcompose a cone for `F` by a natural transformation `F ⟶ G` to give a cone for `G`. -/ @[simps] def postcompose {G : J ⥤ C} (α : F ⟶ G) : Cone F ⥤ Cone G where obj c := { pt := c.pt π := c.π ≫ α } map f := { hom := f.hom } /-- Postcomposing a cone by the composite natural transformation `α ≫ β` is the same as postcomposing by `α` and then by `β`. -/ @[simps!] def postcomposeComp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : postcompose (α ≫ β) ≅ postcompose α ⋙ postcompose β := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Postcomposing by the identity does not change the cone up to isomorphism. -/ @[simps!] def postcomposeId : postcompose (𝟙 F) ≅ 𝟭 (Cone F) := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of cones. -/ @[simps] def postcomposeEquivalence {G : J ⥤ C} (α : F ≅ G) : Cone F ≌ Cone G where functor := postcompose α.hom inverse := postcompose α.inv unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) /-- Whiskering on the left by `E : K ⥤ J` gives a functor from `Cone F` to `Cone (E ⋙ F)`. -/ @[simps] def whiskering (E : K ⥤ J) : Cone F ⥤ Cone (E ⋙ F) where obj c := c.whisker E map f := { hom := f.hom } /-- Whiskering by an equivalence gives an equivalence between categories of cones. -/ @[simps] def whiskeringEquivalence (e : K ≌ J) : Cone F ≌ Cone (e.functor ⋙ F) where functor := whiskering e.functor inverse := whiskering e.inverse ⋙ postcompose (e.invFunIdAssoc F).hom unitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cones.ext (Iso.refl _) (by intro k simpa [e.counit_app_functor] using s.w (e.unitInv.app k)) /-- The categories of cones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic (possibly after changing the indexing category by an equivalence). -/ @[simps! functor inverse unitIso counitIso] def equivalenceOfReindexing {G : K ⥤ C} (e : K ≌ J) (α : e.functor ⋙ F ≅ G) : Cone F ≌ Cone G := (whiskeringEquivalence e).trans (postcomposeEquivalence α) section variable (F) /-- Forget the cone structure and obtain just the cone point. -/ @[simps] def forget : Cone F ⥤ C where obj t := t.pt map f := f.hom variable (G : C ⥤ D) /-- A functor `G : C ⥤ D` sends cones over `F` to cones over `F ⋙ G` functorially. -/ @[simps] def functoriality : Cone F ⥤ Cone (F ⋙ G) where obj A := { pt := G.obj A.pt π := { app := fun j => G.map (A.π.app j) naturality := by intros; erw [← G.map_comp]; simp } } map f := { hom := G.map f.hom w := fun j => by simp [-ConeMorphism.w, ← f.w j] } /-- Functoriality is functorial. -/ def functorialityCompFunctoriality (H : D ⥤ E) : functoriality F G ⋙ functoriality (F ⋙ G) H ≅ functoriality F (G ⋙ H) := NatIso.ofComponents (fun _ ↦ Iso.refl _) (by simp [functoriality]) instance functoriality_full [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom w := fun j => G.map_injective (by simpa using t.w j) }, by cat_disch⟩ instance functoriality_faithful [G.Faithful] : (Cones.functoriality F G).Faithful where map_injective {_X} {_Y} f g h := ConeMorphism.ext f g <| G.map_injective <| congr_arg ConeMorphism.hom h /-- If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an equivalence between cones over `F` and cones over `F ⋙ e.functor`. -/ @[simps] def functorialityEquivalence (e : C ≌ D) : Cone F ≌ Cone (F ⋙ e.functor) := let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e.unitIso.symm ≪≫ Functor.rightUnitor _ { functor := functoriality F e.functor inverse := functoriality (F ⋙ e.functor) e.inverse ⋙ (postcomposeEquivalence f).functor unitIso := NatIso.ofComponents fun c => Cones.ext (e.unitIso.app _) counitIso := NatIso.ofComponents fun c => Cones.ext (e.counitIso.app _) } /-- If `F` reflects isomorphisms, then `Cones.functoriality F` reflects isomorphisms as well. -/ instance reflects_cone_isomorphism (F : C ⥤ D) [F.ReflectsIsomorphisms] (K : J ⥤ C) : (Cones.functoriality K F).ReflectsIsomorphisms := by constructor intro A B f _ haveI : IsIso (F.map f.hom) := (Cones.forget (K ⋙ F)).map_isIso ((Cones.functoriality K F).map f) haveI := ReflectsIsomorphisms.reflects F f.hom apply cone_iso_of_hom_iso end end Cones /-- A cocone morphism between two cocones for the same diagram is a morphism of the cocone points which commutes with the cocone legs. -/ structure CoconeMorphism (A B : Cocone F) where /-- A morphism between the (co)vertex objects in `C` -/ hom : A.pt ⟶ B.pt /-- The triangle made from the two natural transformations and `hom` commutes -/ w : ∀ j : J, A.ι.app j ≫ hom = B.ι.app j := by cat_disch instance inhabitedCoconeMorphism (A : Cocone F) : Inhabited (CoconeMorphism A A) := ⟨{ hom := 𝟙 _ }⟩ attribute [reassoc (attr := simp)] CoconeMorphism.w @[simps] instance Cocone.category : Category (Cocone F) where Hom A B := CoconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the hom field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem CoconeMorphism.ext {c c' : Cocone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr @[reassoc (attr := simp)] lemma CoconeMorphism.hom_inv_id {c d : Cocone F} (f : c ≅ d) : f.hom.hom ≫ f.inv.hom = 𝟙 _ := by simp [← Cocone.category_comp_hom] @[reassoc (attr := simp)] lemma CoconeMorphism.inv_hom_id {c d : Cocone F} (f : c ≅ d) : f.inv.hom ≫ f.hom.hom = 𝟙 _ := by simp [← Cocone.category_comp_hom] instance {c d : Cocone F} (f : c ≅ d) : IsIso f.hom.hom := ⟨f.inv.hom, by simp⟩ instance {c d : Cocone F} (f : c ≅ d) : IsIso f.inv.hom := ⟨f.hom.hom, by simp⟩ namespace Cocones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Cocone F} (φ : c.pt ≅ c'.pt) (w : ∀ j, c.ι.app j ≫ φ.hom = c'.ι.app j := by cat_disch) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv w := fun j => φ.comp_inv_eq.mpr (w j).symm } /-- Eta rule for cocones. -/ @[simps!] def eta (c : Cocone F) : c ≅ ⟨c.pt, c.ι⟩ := Cocones.ext (Iso.refl _) /-- Given a cocone morphism whose object part is an isomorphism, produce an isomorphism of cocones. -/ theorem cocone_iso_of_hom_iso {K : J ⥤ C} {c d : Cocone K} (f : c ⟶ d) [i : IsIso f.hom] : IsIso f := ⟨⟨{ hom := inv f.hom w := fun j => (asIso f.hom).comp_inv_eq.2 (f.w j).symm }, by cat_disch⟩⟩ /-- There is a morphism from a cocone to its extension. -/ @[simps] def extend (s : Cocone F) {X : C} (f : s.pt ⟶ X) : s ⟶ s.extend f where hom := f /-- Extending a cocone by the identity does nothing. -/ @[simps!] def extendId (s : Cocone F) : s ≅ s.extend (𝟙 s.pt) := Cocones.ext (Iso.refl _) /-- Extending a cocone by a composition is the same as extending the cone twice. -/ @[simps!] def extendComp (s : Cocone F) {X Y : C} (f : s.pt ⟶ X) (g : X ⟶ Y) : s.extend (f ≫ g) ≅ (s.extend f).extend g := Cocones.ext (Iso.refl _) /-- A cocone extended by an isomorphism is isomorphic to the original cone. -/ @[simps] def extendIso (s : Cocone F) {X : C} (f : s.pt ≅ X) : s ≅ s.extend f.hom where hom := { hom := f.hom } inv := { hom := f.inv } instance {s : Cocone F} {X : C} (f : s.pt ⟶ X) [IsIso f] : IsIso (Cocones.extend s f) := ⟨(extendIso s (asIso f)).inv, by cat_disch⟩ /-- Functorially precompose a cocone for `F` by a natural transformation `G ⟶ F` to give a cocone for `G`. -/ @[simps] def precompose {G : J ⥤ C} (α : G ⟶ F) : Cocone F ⥤ Cocone G where obj c := { pt := c.pt ι := α ≫ c.ι } map f := { hom := f.hom } /-- Precomposing a cocone by the composite natural transformation `α ≫ β` is the same as precomposing by `β` and then by `α`. -/ def precomposeComp {G H : J ⥤ C} (α : F ⟶ G) (β : G ⟶ H) : precompose (α ≫ β) ≅ precompose β ⋙ precompose α := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- Precomposing by the identity does not change the cocone up to isomorphism. -/ def precomposeId : precompose (𝟙 F) ≅ 𝟭 (Cocone F) := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- If `F` and `G` are naturally isomorphic functors, then they have equivalent categories of cocones. -/ @[simps] def precomposeEquivalence {G : J ⥤ C} (α : G ≅ F) : Cocone F ≌ Cocone G where functor := precompose α.hom inverse := precompose α.inv unitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) /-- Whiskering on the left by `E : K ⥤ J` gives a functor from `Cocone F` to `Cocone (E ⋙ F)`. -/ @[simps] def whiskering (E : K ⥤ J) : Cocone F ⥤ Cocone (E ⋙ F) where obj c := c.whisker E map f := { hom := f.hom } /-- Whiskering by an equivalence gives an equivalence between categories of cones. -/ @[simps] def whiskeringEquivalence (e : K ≌ J) : Cocone F ≌ Cocone (e.functor ⋙ F) where functor := whiskering e.functor inverse := whiskering e.inverse ⋙ precompose ((Functor.leftUnitor F).inv ≫ whiskerRight e.counitIso.inv F ≫ (Functor.associator _ _ _).inv) unitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) counitIso := NatIso.ofComponents fun s => Cocones.ext (Iso.refl _) fun k => by simpa [e.counitInv_app_functor k] using s.w (e.unit.app k) /-- The categories of cocones over `F` and `G` are equivalent if `F` and `G` are naturally isomorphic (possibly after changing the indexing category by an equivalence). -/ @[simps! functor_obj] def equivalenceOfReindexing {G : K ⥤ C} (e : K ≌ J) (α : e.functor ⋙ F ≅ G) : Cocone F ≌ Cocone G := (whiskeringEquivalence e).trans (precomposeEquivalence α.symm) section variable (F) /-- Forget the cocone structure and obtain just the cocone point. -/ @[simps] def forget : Cocone F ⥤ C where obj t := t.pt map f := f.hom variable (G : C ⥤ D) /-- A functor `G : C ⥤ D` sends cocones over `F` to cocones over `F ⋙ G` functorially. -/ @[simps] def functoriality : Cocone F ⥤ Cocone (F ⋙ G) where obj A := { pt := G.obj A.pt ι := { app := fun j => G.map (A.ι.app j) naturality := by intros; erw [← G.map_comp]; simp } } map f := { hom := G.map f.hom w := by intros; rw [← Functor.map_comp, CoconeMorphism.w] } /-- Functoriality is functorial. -/ def functorialityCompFunctoriality (H : D ⥤ E) : functoriality F G ⋙ functoriality (F ⋙ G) H ≅ functoriality F (G ⋙ H) := NatIso.ofComponents (fun _ ↦ Iso.refl _) (by simp [functoriality]) instance functoriality_full [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom w := fun j => G.map_injective (by simpa using t.w j) }, by cat_disch⟩ instance functoriality_faithful [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := CoconeMorphism.ext f g <| G.map_injective <| congr_arg CoconeMorphism.hom h /-- If `e : C ≌ D` is an equivalence of categories, then `functoriality F e.functor` induces an equivalence between cocones over `F` and cocones over `F ⋙ e.functor`. -/ @[simps] def functorialityEquivalence (e : C ≌ D) : Cocone F ≌ Cocone (F ⋙ e.functor) := let f : (F ⋙ e.functor) ⋙ e.inverse ≅ F := Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e.unitIso.symm ≪≫ Functor.rightUnitor _ { functor := functoriality F e.functor inverse := functoriality (F ⋙ e.functor) e.inverse ⋙ (precomposeEquivalence f.symm).functor unitIso := NatIso.ofComponents fun c => Cocones.ext (e.unitIso.app _) counitIso := NatIso.ofComponents fun c => Cocones.ext (e.counitIso.app _) } /-- If `F` reflects isomorphisms, then `Cocones.functoriality F` reflects isomorphisms as well. -/ instance reflects_cocone_isomorphism (F : C ⥤ D) [F.ReflectsIsomorphisms] (K : J ⥤ C) : (Cocones.functoriality K F).ReflectsIsomorphisms := by constructor intro A B f _ haveI : IsIso (F.map f.hom) := (Cocones.forget (K ⋙ F)).map_isIso ((Cocones.functoriality K F).map f) haveI := ReflectsIsomorphisms.reflects F f.hom apply cocone_iso_of_hom_iso end end Cocones end Limits namespace Functor variable (H : C ⥤ D) {F : J ⥤ C} {G : J ⥤ C} open CategoryTheory.Limits /-- The image of a cone in C under a functor G : C ⥤ D is a cone in D. -/ @[simps!] def mapCone (c : Cone F) : Cone (F ⋙ H) := (Cones.functoriality F H).obj c /-- The construction `mapCone` respects functor composition. -/ @[simps!] noncomputable def mapConeMapCone {F : J ⥤ C} {H : C ⥤ D} {H' : D ⥤ E} (c : Cone F) : H'.mapCone (H.mapCone c) ≅ (H ⋙ H').mapCone c := Cones.ext (Iso.refl _) /-- The image of a cocone in C under a functor G : C ⥤ D is a cocone in D. -/ @[simps!] def mapCocone (c : Cocone F) : Cocone (F ⋙ H) := (Cocones.functoriality F H).obj c /-- The construction `mapCocone` respects functor composition. -/ @[simps!] noncomputable def mapCoconeMapCocone {F : J ⥤ C} {H : C ⥤ D} {H' : D ⥤ E} (c : Cocone F) : H'.mapCocone (H.mapCocone c) ≅ (H ⋙ H').mapCocone c := Cocones.ext (Iso.refl _) /-- Given a cone morphism `c ⟶ c'`, construct a cone morphism on the mapped cones functorially. -/ def mapConeMorphism {c c' : Cone F} (f : c ⟶ c') : H.mapCone c ⟶ H.mapCone c' := (Cones.functoriality F H).map f /-- Given a cocone morphism `c ⟶ c'`, construct a cocone morphism on the mapped cocones functorially. -/ def mapCoconeMorphism {c c' : Cocone F} (f : c ⟶ c') : H.mapCocone c ⟶ H.mapCocone c' := (Cocones.functoriality F H).map f /-- If `H` is an equivalence, we invert `H.mapCone` and get a cone for `F` from a cone for `F ⋙ H`. -/ noncomputable def mapConeInv [IsEquivalence H] (c : Cone (F ⋙ H)) : Cone F := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).inverse.obj c /-- `mapCone` is the left inverse to `mapConeInv`. -/ noncomputable def mapConeMapConeInv {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cone (F ⋙ H)) : mapCone H (mapConeInv H c) ≅ c := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).counitIso.app c /-- `MapCone` is the right inverse to `mapConeInv`. -/ noncomputable def mapConeInvMapCone {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cone F) : mapConeInv H (mapCone H c) ≅ c := (Limits.Cones.functorialityEquivalence F (asEquivalence H)).unitIso.symm.app c /-- If `H` is an equivalence, we invert `H.mapCone` and get a cone for `F` from a cone for `F ⋙ H`. -/ noncomputable def mapCoconeInv [IsEquivalence H] (c : Cocone (F ⋙ H)) : Cocone F := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).inverse.obj c /-- `mapCocone` is the left inverse to `mapCoconeInv`. -/ noncomputable def mapCoconeMapCoconeInv {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cocone (F ⋙ H)) : mapCocone H (mapCoconeInv H c) ≅ c := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).counitIso.app c /-- `mapCocone` is the right inverse to `mapCoconeInv`. -/ noncomputable def mapCoconeInvMapCocone {F : J ⥤ D} (H : D ⥤ C) [IsEquivalence H] (c : Cocone F) : mapCoconeInv H (mapCocone H c) ≅ c := (Limits.Cocones.functorialityEquivalence F (asEquivalence H)).unitIso.symm.app c /-- `functoriality F _ ⋙ postcompose (whisker_left F _)` simplifies to `functoriality F _`. -/ @[simps!] def functorialityCompPostcompose {H H' : C ⥤ D} (α : H ≅ H') : Cones.functoriality F H ⋙ Cones.postcompose (whiskerLeft F α.hom) ≅ Cones.functoriality F H' := NatIso.ofComponents fun c => Cones.ext (α.app _) /-- For `F : J ⥤ C`, given a cone `c : Cone F`, and a natural isomorphism `α : H ≅ H'` for functors `H H' : C ⥤ D`, the postcomposition of the cone `H.mapCone` using the isomorphism `α` is isomorphic to the cone `H'.mapCone`. -/ @[simps!] def postcomposeWhiskerLeftMapCone {H H' : C ⥤ D} (α : H ≅ H') (c : Cone F) : (Cones.postcompose (whiskerLeft F α.hom :)).obj (mapCone H c) ≅ mapCone H' c := (functorialityCompPostcompose α).app c /-- `mapCone` commutes with `postcompose`. In particular, for `F : J ⥤ C`, given a cone `c : Cone F`, a natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious ways of producing a cone over `G ⋙ H`, and they are both isomorphic. -/ @[simps!] def mapConePostcompose {α : F ⟶ G} {c} : mapCone H ((Cones.postcompose α).obj c) ≅ (Cones.postcompose (whiskerRight α H :)).obj (mapCone H c) := Cones.ext (Iso.refl _) /-- `mapCone` commutes with `postcomposeEquivalence` -/ @[simps!] def mapConePostcomposeEquivalenceFunctor {α : F ≅ G} {c} : mapCone H ((Cones.postcomposeEquivalence α).functor.obj c) ≅ (Cones.postcomposeEquivalence (isoWhiskerRight α H :)).functor.obj (mapCone H c) := Cones.ext (Iso.refl _) /-- `functoriality F _ ⋙ precompose (whiskerLeft F _)` simplifies to `functoriality F _`. -/ @[simps!] def functorialityCompPrecompose {H H' : C ⥤ D} (α : H ≅ H') : Cocones.functoriality F H ⋙ Cocones.precompose (whiskerLeft F α.inv) ≅ Cocones.functoriality F H' := NatIso.ofComponents fun c => Cocones.ext (α.app _) /-- For `F : J ⥤ C`, given a cocone `c : Cocone F`, and a natural isomorphism `α : H ≅ H'` for functors `H H' : C ⥤ D`, the precomposition of the cocone `H.mapCocone` using the isomorphism `α` is isomorphic to the cocone `H'.mapCocone`. -/ @[simps!] def precomposeWhiskerLeftMapCocone {H H' : C ⥤ D} (α : H ≅ H') (c : Cocone F) : (Cocones.precompose (whiskerLeft F α.inv :)).obj (mapCocone H c) ≅ mapCocone H' c := (functorialityCompPrecompose α).app c /-- `map_cocone` commutes with `precompose`. In particular, for `F : J ⥤ C`, given a cocone `c : Cocone F`, a natural transformation `α : F ⟶ G` and a functor `H : C ⥤ D`, we have two obvious ways of producing a cocone over `G ⋙ H`, and they are both isomorphic. -/ @[simps!] def mapCoconePrecompose {α : F ⟶ G} {c} : mapCocone H ((Cocones.precompose α).obj c) ≅ (Cocones.precompose (whiskerRight α H :)).obj (mapCocone H c) := Cocones.ext (Iso.refl _) /-- `mapCocone` commutes with `precomposeEquivalence` -/ @[simps!] def mapCoconePrecomposeEquivalenceFunctor {α : F ≅ G} {c} : mapCocone H ((Cocones.precomposeEquivalence α).functor.obj c) ≅ (Cocones.precomposeEquivalence (isoWhiskerRight α H :)).functor.obj (mapCocone H c) := Cocones.ext (Iso.refl _) /-- `mapCone` commutes with `whisker` -/ @[simps!] def mapConeWhisker {E : K ⥤ J} {c : Cone F} : mapCone H (c.whisker E) ≅ (mapCone H c).whisker E := Cones.ext (Iso.refl _) /-- `mapCocone` commutes with `whisker` -/ @[simps!] def mapCoconeWhisker {E : K ⥤ J} {c : Cocone F} : mapCocone H (c.whisker E) ≅ (mapCocone H c).whisker E := Cocones.ext (Iso.refl _) end Functor end CategoryTheory namespace CategoryTheory.Limits section variable {F : J ⥤ C} /-- Change a `Cocone F` into a `Cone F.op`. -/ @[simps] def Cocone.op (c : Cocone F) : Cone F.op where pt := Opposite.op c.pt π := NatTrans.op c.ι /-- Change a `Cone F` into a `Cocone F.op`. -/ @[simps] def Cone.op (c : Cone F) : Cocone F.op where pt := Opposite.op c.pt ι := NatTrans.op c.π /-- Change a `Cocone F.op` into a `Cone F`. -/ @[simps] def Cocone.unop (c : Cocone F.op) : Cone F where pt := Opposite.unop c.pt π := NatTrans.removeOp c.ι /-- Change a `Cone F.op` into a `Cocone F`. -/ @[simps] def Cone.unop (c : Cone F.op) : Cocone F where pt := Opposite.unop c.pt ι := NatTrans.removeOp c.π variable (F) /-- The category of cocones on `F` is equivalent to the opposite category of the category of cones on the opposite of `F`. -/ def coconeEquivalenceOpConeOp : Cocone F ≌ (Cone F.op)ᵒᵖ where functor := { obj := fun c => op (Cocone.op c) map := fun {X} {Y} f => Quiver.Hom.op { hom := f.hom.op w := fun j => by apply Quiver.Hom.unop_inj dsimp apply CoconeMorphism.w } } inverse := { obj := fun c => Cone.unop (unop c) map := fun {X} {Y} f => { hom := f.unop.hom.unop w := fun j => by apply Quiver.Hom.op_inj dsimp apply ConeMorphism.w } } unitIso := NatIso.ofComponents (fun c => Cocones.ext (Iso.refl _)) counitIso := NatIso.ofComponents (fun c => (Cones.ext (Iso.refl c.unop.pt)).op) fun {X} {Y} f => Quiver.Hom.unop_inj (ConeMorphism.ext _ _ (by simp)) functor_unitIso_comp c := by apply Quiver.Hom.unop_inj apply ConeMorphism.ext dsimp apply comp_id attribute [simps] coconeEquivalenceOpConeOp end section variable {F : J ⥤ Cᵒᵖ} /-- Change a cocone on `F.leftOp : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/ @[simps!] def coneOfCoconeLeftOp (c : Cocone F.leftOp) : Cone F where pt := op c.pt π := NatTrans.removeLeftOp c.ι /-- Change a cone on `F : J ⥤ Cᵒᵖ` to a cocone on `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def coconeLeftOpOfCone (c : Cone F) : Cocone F.leftOp where pt := unop c.pt ι := NatTrans.leftOp c.π /- When trying use `@[simps]` to generate the `ι_app` field of this definition, `@[simps]` tries to reduce the RHS using `expr.dsimp` and `expr.simp`, but for some reason the expression is not being simplified properly. -/ /-- Change a cone on `F.leftOp : Jᵒᵖ ⥤ C` to a cocone on `F : J ⥤ Cᵒᵖ`. -/ @[simps pt] def coconeOfConeLeftOp (c : Cone F.leftOp) : Cocone F where pt := op c.pt ι := NatTrans.removeLeftOp c.π @[simp] theorem coconeOfConeLeftOp_ι_app (c : Cone F.leftOp) (j) : (coconeOfConeLeftOp c).ι.app j = (c.π.app (op j)).op := by dsimp only [coconeOfConeLeftOp] simp /-- Change a cocone on `F : J ⥤ Cᵒᵖ` to a cone on `F.leftOp : Jᵒᵖ ⥤ C`. -/ @[simps!] def coneLeftOpOfCocone (c : Cocone F) : Cone F.leftOp where pt := unop c.pt π := NatTrans.leftOp c.ι end section variable {F : Jᵒᵖ ⥤ C} /-- Change a cocone on `F.rightOp : J ⥤ Cᵒᵖ` to a cone on `F : Jᵒᵖ ⥤ C`. -/ @[simps] def coneOfCoconeRightOp (c : Cocone F.rightOp) : Cone F where pt := unop c.pt π := NatTrans.removeRightOp c.ι /-- Change a cone on `F : Jᵒᵖ ⥤ C` to a cocone on `F.rightOp : Jᵒᵖ ⥤ C`. -/ @[simps] def coconeRightOpOfCone (c : Cone F) : Cocone F.rightOp where pt := op c.pt ι := NatTrans.rightOp c.π /-- Change a cone on `F.rightOp : J ⥤ Cᵒᵖ` to a cocone on `F : Jᵒᵖ ⥤ C`. -/ @[simps] def coconeOfConeRightOp (c : Cone F.rightOp) : Cocone F where pt := unop c.pt ι := NatTrans.removeRightOp c.π /-- Change a cocone on `F : Jᵒᵖ ⥤ C` to a cone on `F.rightOp : J ⥤ Cᵒᵖ`. -/ @[simps] def coneRightOpOfCocone (c : Cocone F) : Cone F.rightOp where pt := op c.pt π := NatTrans.rightOp c.ι end section variable {F : Jᵒᵖ ⥤ Cᵒᵖ} /-- Change a cocone on `F.unop : J ⥤ C` into a cone on `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def coneOfCoconeUnop (c : Cocone F.unop) : Cone F where pt := op c.pt π := NatTrans.removeUnop c.ι /-- Change a cone on `F : Jᵒᵖ ⥤ Cᵒᵖ` into a cocone on `F.unop : J ⥤ C`. -/ @[simps] def coconeUnopOfCone (c : Cone F) : Cocone F.unop where pt := unop c.pt ι := NatTrans.unop c.π /-- Change a cone on `F.unop : J ⥤ C` into a cocone on `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/ @[simps] def coconeOfConeUnop (c : Cone F.unop) : Cocone F where pt := op c.pt ι := NatTrans.removeUnop c.π /-- Change a cocone on `F : Jᵒᵖ ⥤ Cᵒᵖ` into a cone on `F.unop : J ⥤ C`. -/ @[simps] def coneUnopOfCocone (c : Cocone F) : Cone F.unop where pt := unop c.pt π := NatTrans.unop c.ι end end CategoryTheory.Limits namespace CategoryTheory.Functor open CategoryTheory.Limits variable {F : J ⥤ C} section variable (G : C ⥤ D) /-- The opposite cocone of the image of a cone is the image of the opposite cocone. -/ @[simps!] def mapConeOp (t : Cone F) : (mapCone G t).op ≅ mapCocone G.op t.op := Cocones.ext (Iso.refl _) /-- The opposite cone of the image of a cocone is the image of the opposite cone. -/ @[simps!] def mapCoconeOp {t : Cocone F} : (mapCocone G t).op ≅ mapCone G.op t.op := Cones.ext (Iso.refl _) end end CategoryTheory.Functor
Factors.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Data.List.Iterate import Mathlib.GroupTheory.Perm.Cycle.Basic import Mathlib.GroupTheory.NoncommPiCoprod import Mathlib.Tactic.Group /-! # Cycle factors of a permutation Let `β` be a `Fintype` and `f : Equiv.Perm β`. * `Equiv.Perm.cycleOf`: `f.cycleOf x` is the cycle of `f` that `x` belongs to. * `Equiv.Perm.cycleFactors`: `f.cycleFactors` is a list of disjoint cyclic permutations that multiply to `f`. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `cycleOf` -/ section CycleOf variable {f g : Perm α} {x y : α} /-- `f.cycleOf x` is the cycle of the permutation `f` to which `x` belongs. -/ def cycleOf (f : Perm α) [DecidableRel f.SameCycle] (x : α) : Perm α := ofSubtype (subtypePerm f fun _ => sameCycle_apply_right : Perm { y // SameCycle f x y }) theorem cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (x y : α) : cycleOf f x y = if SameCycle f x y then f y else y := by dsimp only [cycleOf] split_ifs with h · apply ofSubtype_apply_of_mem exact h · apply ofSubtype_apply_of_not_mem exact h theorem cycleOf_inv (f : Perm α) [DecidableRel f.SameCycle] (x : α) : (cycleOf f x)⁻¹ = cycleOf f⁻¹ x := Equiv.ext fun y => by rw [inv_eq_iff_eq, cycleOf_apply, cycleOf_apply] split_ifs <;> simp_all [sameCycle_inv, sameCycle_inv_apply_right] @[simp] theorem cycleOf_pow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℕ, (cycleOf f x ^ n) x = (f ^ n) x := by intro n induction n with | zero => rfl | succ n hn => rw [pow_succ', mul_apply, cycleOf_apply, hn, if_pos, pow_succ', mul_apply] exact ⟨n, rfl⟩ @[simp] theorem cycleOf_zpow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℤ, (cycleOf f x ^ n) x = (f ^ n) x := by intro z cases z with | ofNat z => exact cycleOf_pow_apply_self f x z | negSucc z => rw [zpow_negSucc, ← inv_pow, cycleOf_inv, zpow_negSucc, ← inv_pow, cycleOf_pow_apply_self] theorem SameCycle.cycleOf_apply [DecidableRel f.SameCycle] : SameCycle f x y → cycleOf f x y = f y := ofSubtype_apply_of_mem _ theorem cycleOf_apply_of_not_sameCycle [DecidableRel f.SameCycle] : ¬SameCycle f x y → cycleOf f x y = y := ofSubtype_apply_of_not_mem _ theorem SameCycle.cycleOf_eq [DecidableRel f.SameCycle] (h : SameCycle f x y) : cycleOf f x = cycleOf f y := by ext z rw [Equiv.Perm.cycleOf_apply] split_ifs with hz · exact (h.symm.trans hz).cycleOf_apply.symm · exact (cycleOf_apply_of_not_sameCycle (mt h.trans hz)).symm @[simp] theorem cycleOf_apply_apply_zpow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℤ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by rw [SameCycle.cycleOf_apply] · rw [add_comm, zpow_add, zpow_one, mul_apply] · exact ⟨k, rfl⟩ @[simp] theorem cycleOf_apply_apply_pow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℕ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by convert cycleOf_apply_apply_zpow_self f x k using 1 @[simp] theorem cycleOf_apply_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x (f x) = f (f x) := by convert cycleOf_apply_apply_pow_self f x 1 using 1 @[simp] theorem cycleOf_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x x = f x := SameCycle.rfl.cycleOf_apply theorem IsCycle.cycleOf_eq [DecidableRel f.SameCycle] (hf : IsCycle f) (hx : f x ≠ x) : cycleOf f x = f := Equiv.ext fun y => if h : SameCycle f x y then by rw [h.cycleOf_apply] else by rw [cycleOf_apply_of_not_sameCycle h, Classical.not_not.1 (mt ((isCycle_iff_sameCycle hx).1 hf).2 h)] @[simp] theorem cycleOf_eq_one_iff (f : Perm α) [DecidableRel f.SameCycle] : cycleOf f x = 1 ↔ f x = x := by simp_rw [Perm.ext_iff, cycleOf_apply, one_apply] refine ⟨fun h => (if_pos (SameCycle.refl f x)).symm.trans (h x), fun h y => ?_⟩ by_cases hy : f y = y · rw [hy, ite_self] · exact if_neg (mt SameCycle.apply_eq_self_iff (by tauto)) @[simp] theorem cycleOf_self_apply (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f (f x) = cycleOf f x := (sameCycle_apply_right.2 SameCycle.rfl).symm.cycleOf_eq @[simp] theorem cycleOf_self_apply_pow (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.pow_left.cycleOf_eq @[simp] theorem cycleOf_self_apply_zpow (f : Perm α) [DecidableRel f.SameCycle] (n : ℤ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.zpow_left.cycleOf_eq protected theorem IsCycle.cycleOf [DecidableRel f.SameCycle] [DecidableEq α] (hf : IsCycle f) : cycleOf f x = if f x = x then 1 else f := by by_cases hx : f x = x · rwa [if_pos hx, cycleOf_eq_one_iff] · rwa [if_neg hx, hf.cycleOf_eq] theorem cycleOf_one [DecidableRel (1 : Perm α).SameCycle] (x : α) : cycleOf 1 x = 1 := (cycleOf_eq_one_iff 1).mpr rfl theorem isCycle_cycleOf (f : Perm α) [DecidableRel f.SameCycle] (hx : f x ≠ x) : IsCycle (cycleOf f x) := have : cycleOf f x x ≠ x := by rwa [SameCycle.rfl.cycleOf_apply] (isCycle_iff_sameCycle this).2 @fun y => ⟨fun h => mt h.apply_eq_self_iff.2 this, fun h => if hxy : SameCycle f x y then let ⟨i, hi⟩ := hxy ⟨i, by rw [cycleOf_zpow_apply_self, hi]⟩ else by rw [cycleOf_apply_of_not_sameCycle hxy] at h exact (h rfl).elim⟩ theorem pow_mod_orderOf_cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : (f ^ (n % orderOf (cycleOf f x))) x = (f ^ n) x := by rw [← cycleOf_pow_apply_self f, ← cycleOf_pow_apply_self f, pow_mod_orderOf] theorem cycleOf_mul_of_apply_right_eq_self [DecidableRel f.SameCycle] [DecidableRel (f * g).SameCycle] (h : Commute f g) (x : α) (hx : g x = x) : (f * g).cycleOf x = f.cycleOf x := by ext y by_cases hxy : (f * g).SameCycle x y · obtain ⟨z, rfl⟩ := hxy rw [cycleOf_apply_apply_zpow_self] simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] · rw [cycleOf_apply_of_not_sameCycle hxy, cycleOf_apply_of_not_sameCycle] contrapose! hxy obtain ⟨z, rfl⟩ := hxy refine ⟨z, ?_⟩ simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] theorem Disjoint.cycleOf_mul_distrib [DecidableRel f.SameCycle] [DecidableRel g.SameCycle] [DecidableRel (f * g).SameCycle] [DecidableRel (g * f).SameCycle] (h : f.Disjoint g) (x : α) : (f * g).cycleOf x = f.cycleOf x * g.cycleOf x := by rcases (disjoint_iff_eq_or_eq.mp h) x with hfx | hgx · simp [h.commute.eq, cycleOf_mul_of_apply_right_eq_self h.symm.commute, hfx] · simp [cycleOf_mul_of_apply_right_eq_self h.commute, hgx] private theorem mem_support_cycleOf_iff_aux [DecidableRel f.SameCycle] [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f := by by_cases hx : f x = x · rw [(cycleOf_eq_one_iff _).mpr hx] simp [hx] · rw [mem_support, cycleOf_apply] split_ifs with hy · simp only [hx, hy, Ne, not_false_iff, and_self_iff, mem_support] rcases hy with ⟨k, rfl⟩ rw [← notMem_support] simpa using hx · simpa [hx] using hy private theorem mem_support_cycleOf_iff'_aux (hx : f x ≠ x) [DecidableRel f.SameCycle] [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y := by rw [mem_support_cycleOf_iff_aux, and_iff_left (mem_support.2 hx)] /-- `x` is in the support of `f` iff `Equiv.Perm.cycle_of f x` is a cycle. -/ theorem isCycle_cycleOf_iff (f : Perm α) [DecidableRel f.SameCycle] : IsCycle (cycleOf f x) ↔ f x ≠ x := by refine ⟨fun hx => ?_, f.isCycle_cycleOf⟩ rw [Ne, ← cycleOf_eq_one_iff f] exact hx.ne_one private theorem isCycleOn_support_cycleOf_aux [DecidableEq α] [Fintype α] (f : Perm α) [DecidableRel f.SameCycle] (x : α) : f.IsCycleOn (f.cycleOf x).support := ⟨f.bijOn <| by refine fun _ ↦ ⟨fun h ↦ mem_support_cycleOf_iff_aux.2 ?_, fun h ↦ mem_support_cycleOf_iff_aux.2 ?_⟩ · exact ⟨sameCycle_apply_right.1 (mem_support_cycleOf_iff_aux.1 h).1, (mem_support_cycleOf_iff_aux.1 h).2⟩ · exact ⟨sameCycle_apply_right.2 (mem_support_cycleOf_iff_aux.1 h).1, (mem_support_cycleOf_iff_aux.1 h).2⟩ , fun a ha b hb => by rw [mem_coe, mem_support_cycleOf_iff_aux] at ha hb exact ha.1.symm.trans hb.1⟩ private theorem SameCycle.exists_pow_eq_of_mem_support_aux {f} [DecidableEq α] [Fintype α] [DecidableRel f.SameCycle] (h : SameCycle f x y) (hx : x ∈ f.support) : ∃ i < #(f.cycleOf x).support, (f ^ i) x = y := by rw [mem_support] at hx exact Equiv.Perm.IsCycleOn.exists_pow_eq (b := y) (f.isCycleOn_support_cycleOf_aux x) (by rw [mem_support_cycleOf_iff'_aux hx]) (by rwa [mem_support_cycleOf_iff'_aux hx]) instance instDecidableRelSameCycle [DecidableEq α] [Fintype α] (f : Perm α) : DecidableRel (SameCycle f) := fun x y => decidable_of_iff (y ∈ List.iterate f x (Fintype.card α)) <| by simp only [List.mem_iterate, iterate_eq_pow, eq_comm (a := y)] constructor · rintro ⟨n, _, hn⟩ exact ⟨n, hn⟩ · intro hxy by_cases hx : x ∈ f.support case pos => -- we can't invoke the aux lemmas above without obtaining the decidable instance we are -- already building; but now we've left the data, so we can do this non-constructively -- without sacrificing computability. let _inst (f : Perm α) : DecidableRel (SameCycle f) := Classical.decRel _ rcases hxy.exists_pow_eq_of_mem_support_aux hx with ⟨i, hixy, hi⟩ refine ⟨i, lt_of_lt_of_le hixy (card_le_univ _), hi⟩ case neg => haveI : Nonempty α := ⟨x⟩ rw [notMem_support] at hx exact ⟨0, Fintype.card_pos, hxy.eq_of_left hx⟩ @[simp] theorem two_le_card_support_cycleOf_iff [DecidableEq α] [Fintype α] : 2 ≤ #(cycleOf f x).support ↔ f x ≠ x := by refine ⟨fun h => ?_, fun h => by simpa using (isCycle_cycleOf _ h).two_le_card_support⟩ contrapose! h rw [← cycleOf_eq_one_iff] at h simp [h] @[simp] lemma support_cycleOf_nonempty [DecidableEq α] [Fintype α] : (cycleOf f x).support.Nonempty ↔ f x ≠ x := by rw [← two_le_card_support_cycleOf_iff, ← card_pos, ← Nat.succ_le_iff] exact ⟨fun h => Or.resolve_left h.eq_or_lt (card_support_ne_one _).symm, zero_lt_two.trans_le⟩ theorem mem_support_cycleOf_iff [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f := mem_support_cycleOf_iff_aux theorem mem_support_cycleOf_iff' (hx : f x ≠ x) [DecidableEq α] [Fintype α] : y ∈ support (f.cycleOf x) ↔ SameCycle f x y := mem_support_cycleOf_iff'_aux hx theorem sameCycle_iff_cycleOf_eq_of_mem_support [DecidableEq α] [Fintype α] {g : Perm α} {x y : α} (hx : x ∈ g.support) (hy : y ∈ g.support) : g.SameCycle x y ↔ g.cycleOf x = g.cycleOf y := by refine ⟨SameCycle.cycleOf_eq, fun h ↦ ?_⟩ rw [← mem_support_cycleOf_iff' (mem_support.mp hx), h, mem_support_cycleOf_iff' (mem_support.mp hy)] theorem support_cycleOf_eq_nil_iff [DecidableEq α] [Fintype α] : (f.cycleOf x).support = ∅ ↔ x ∉ f.support := by simp theorem isCycleOn_support_cycleOf [DecidableEq α] [Fintype α] (f : Perm α) (x : α) : f.IsCycleOn (f.cycleOf x).support := isCycleOn_support_cycleOf_aux f x theorem SameCycle.exists_pow_eq_of_mem_support {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y) (hx : x ∈ f.support) : ∃ i < #(f.cycleOf x).support, (f ^ i) x = y := h.exists_pow_eq_of_mem_support_aux hx theorem support_cycleOf_le [DecidableEq α] [Fintype α] (f : Perm α) (x : α) : support (f.cycleOf x) ≤ support f := by intro y hy rw [mem_support, cycleOf_apply] at hy split_ifs at hy · exact mem_support.mpr hy · exact absurd rfl hy theorem SameCycle.mem_support_iff {f} [DecidableEq α] [Fintype α] (h : SameCycle f x y) : x ∈ support f ↔ y ∈ support f := ⟨fun hx => support_cycleOf_le f x (mem_support_cycleOf_iff.mpr ⟨h, hx⟩), fun hy => support_cycleOf_le f y (mem_support_cycleOf_iff.mpr ⟨h.symm, hy⟩)⟩ theorem pow_mod_card_support_cycleOf_self_apply [DecidableEq α] [Fintype α] (f : Perm α) (n : ℕ) (x : α) : (f ^ (n % #(f.cycleOf x).support)) x = (f ^ n) x := by by_cases hx : f x = x · rw [pow_apply_eq_self_of_apply_eq_self hx, pow_apply_eq_self_of_apply_eq_self hx] · rw [← cycleOf_pow_apply_self, ← cycleOf_pow_apply_self f, ← (isCycle_cycleOf f hx).orderOf, pow_mod_orderOf] theorem SameCycle.exists_pow_eq [DecidableEq α] [Fintype α] (f : Perm α) (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ #(f.cycleOf x).support + 1 ∧ (f ^ i) x = y := by by_cases hx : x ∈ f.support · obtain ⟨k, hk, hk'⟩ := h.exists_pow_eq_of_mem_support hx rcases k with - | k · refine ⟨#(f.cycleOf x).support, hk, self_le_add_right _ _, ?_⟩ simp only [pow_zero, coe_one, id_eq] at hk' subst hk' rw [← (isCycle_cycleOf _ <| mem_support.1 hx).orderOf, ← cycleOf_pow_apply_self, pow_orderOf_eq_one, one_apply] · exact ⟨k + 1, by simp, Nat.le_succ_of_le hk.le, hk'⟩ · refine ⟨1, zero_lt_one, by simp, ?_⟩ obtain ⟨k, rfl⟩ := h rw [notMem_support] at hx rw [pow_apply_eq_self_of_apply_eq_self hx, zpow_apply_eq_self_of_apply_eq_self hx] theorem zpow_eq_zpow_on_iff [DecidableEq α] [Fintype α] (g : Perm α) {m n : ℤ} {x : α} (hx : g x ≠ x) : (g ^ m) x = (g ^ n) x ↔ m % #(g.cycleOf x).support = n % #(g.cycleOf x).support := by rw [Int.emod_eq_emod_iff_emod_sub_eq_zero] conv_lhs => rw [← Int.sub_add_cancel m n, Int.add_comm, zpow_add] simp only [coe_mul, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] rw [← Int.dvd_iff_emod_eq_zero] rw [← cycleOf_zpow_apply_self g x, cycle_zpow_mem_support_iff] · rw [← Int.dvd_iff_emod_eq_zero] · exact isCycle_cycleOf g hx · simp only [cycleOf_apply_self]; exact hx end CycleOf /-! ### `cycleFactors` -/ section cycleFactors open scoped List in /-- Given a list `l : List α` and a permutation `f : Perm α` whose nonfixed points are all in `l`, recursively factors `f` into cycles. -/ def cycleFactorsAux [DecidableEq α] [Fintype α] (l : List α) (f : Perm α) (h : ∀ {x}, f x ≠ x → x ∈ l) : { pl : List (Perm α) // pl.prod = f ∧ (∀ g ∈ pl, IsCycle g) ∧ pl.Pairwise Disjoint } := go l f h (fun _ => rfl) where /-- The auxiliary of `cycleFactorsAux`. This functions separates cycles from `f` instead of `g` to prevent the process of a cycle gets complex. -/ go (l : List α) (g : Perm α) (hg : ∀ {x}, g x ≠ x → x ∈ l) (hfg : ∀ {x}, g x ≠ x → cycleOf f x = cycleOf g x) : { pl : List (Perm α) // pl.prod = g ∧ (∀ g' ∈ pl, IsCycle g') ∧ pl.Pairwise Disjoint } := match l with | [] => ⟨[], by { simp only [imp_false, List.Pairwise.nil, List.not_mem_nil, forall_const, and_true, forall_prop_of_false, Classical.not_not, not_false_iff, List.prod_nil] at * ext simp [*]}⟩ | x :: l => if hx : g x = x then go l g (by intro y hy; exact List.mem_of_ne_of_mem (fun h => hy (by rwa [h])) (hg hy)) hfg else let ⟨m, hm⟩ := go l ((cycleOf f x)⁻¹ * g) (by rw [hfg hx] intro y hy exact List.mem_of_ne_of_mem (fun h : y = x => by rw [h, mul_apply, Ne, inv_eq_iff_eq, cycleOf_apply_self] at hy exact hy rfl) (hg fun h : g y = y => by rw [mul_apply, h, Ne, inv_eq_iff_eq, cycleOf_apply] at hy split_ifs at hy <;> tauto)) (by rw [hfg hx] intro y hy simp [inv_eq_iff_eq, cycleOf_apply, eq_comm (a := g y)] at hy rw [hfg (Ne.symm hy.right), ← mul_inv_eq_one (a := g.cycleOf y), cycleOf_inv] simp_rw [mul_inv_rev] rw [inv_inv, cycleOf_mul_of_apply_right_eq_self, ← cycleOf_inv, mul_inv_eq_one] · rw [Commute.inv_left_iff, commute_iff_eq] ext z; by_cases hz : SameCycle g x z · simp [cycleOf_apply, hz] · simp [cycleOf_apply_of_not_sameCycle, hz] · exact cycleOf_apply_of_not_sameCycle hy.left) ⟨cycleOf f x :: m, by obtain ⟨hm₁, hm₂, hm₃⟩ := hm rw [hfg hx] at hm₁ ⊢ constructor · rw [List.prod_cons, hm₁] simp · exact ⟨fun g' hg' => ((List.mem_cons).1 hg').elim (fun hg' => hg'.symm ▸ isCycle_cycleOf _ hx) (hm₂ g'), List.pairwise_cons.2 ⟨fun g' hg' y => or_iff_not_imp_left.2 fun hgy => have hxy : SameCycle g x y := Classical.not_not.1 (mt cycleOf_apply_of_not_sameCycle hgy) have hg'm : (g' :: m.erase g') ~ m := List.cons_perm_iff_perm_erase.2 ⟨hg', List.Perm.refl _⟩ have : ∀ h ∈ m.erase g', Disjoint g' h := (List.pairwise_cons.1 ((hg'm.pairwise_iff Disjoint.symm).2 hm₃)).1 by_cases id fun hg'y : g' y ≠ y => (disjoint_prod_right _ this y).resolve_right <| by have hsc : SameCycle g⁻¹ x (g y) := by rwa [sameCycle_inv, sameCycle_apply_right] rw [disjoint_prod_perm hm₃ hg'm.symm, List.prod_cons, ← eq_inv_mul_iff_mul_eq] at hm₁ rwa [hm₁, mul_apply, mul_apply, cycleOf_inv, hsc.cycleOf_apply, inv_apply_self, inv_eq_iff_eq, eq_comm], hm₃⟩⟩⟩ theorem mem_list_cycles_iff {α : Type*} [Finite α] {l : List (Perm α)} (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) {σ : Perm α} : σ ∈ l ↔ σ.IsCycle ∧ ∀ a, σ a ≠ a → σ a = l.prod a := by suffices σ.IsCycle → (σ ∈ l ↔ ∀ a, σ a ≠ a → σ a = l.prod a) by exact ⟨fun hσ => ⟨h1 σ hσ, (this (h1 σ hσ)).mp hσ⟩, fun hσ => (this hσ.1).mpr hσ.2⟩ intro h3 classical cases nonempty_fintype α constructor · intro h a ha exact eq_on_support_mem_disjoint h h2 _ (mem_support.mpr ha) · intro h have hσl : σ.support ⊆ l.prod.support := by intro x hx rw [mem_support] at hx rwa [mem_support, ← h _ hx] obtain ⟨a, ha, -⟩ := id h3 rw [← mem_support] at ha obtain ⟨τ, hτ, hτa⟩ := exists_mem_support_of_mem_support_prod (hσl ha) have hτl : ∀ x ∈ τ.support, τ x = l.prod x := eq_on_support_mem_disjoint hτ h2 have key : ∀ x ∈ σ.support ∩ τ.support, σ x = τ x := by intro x hx rw [h x (mem_support.mp (mem_of_mem_inter_left hx)), hτl x (mem_of_mem_inter_right hx)] convert hτ refine h3.eq_on_support_inter_nonempty_congr (h1 _ hτ) key ?_ ha exact key a (mem_inter_of_mem ha hτa) open scoped List in theorem list_cycles_perm_list_cycles {α : Type*} [Finite α] {l₁ l₂ : List (Perm α)} (h₀ : l₁.prod = l₂.prod) (h₁l₁ : ∀ σ : Perm α, σ ∈ l₁ → σ.IsCycle) (h₁l₂ : ∀ σ : Perm α, σ ∈ l₂ → σ.IsCycle) (h₂l₁ : l₁.Pairwise Disjoint) (h₂l₂ : l₂.Pairwise Disjoint) : l₁ ~ l₂ := by classical refine (List.perm_ext_iff_of_nodup (nodup_of_pairwise_disjoint_cycles h₁l₁ h₂l₁) (nodup_of_pairwise_disjoint_cycles h₁l₂ h₂l₂)).mpr fun σ => ?_ by_cases hσ : σ.IsCycle · obtain _ := not_forall.mp (mt ext hσ.ne_one) rw [mem_list_cycles_iff h₁l₁ h₂l₁, mem_list_cycles_iff h₁l₂ h₂l₂, h₀] · exact iff_of_false (mt (h₁l₁ σ) hσ) (mt (h₁l₂ σ) hσ) /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactors [Fintype α] [LinearOrder α] (f : Perm α) : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := cycleFactorsAux (sort (α := α) (· ≤ ·) univ) f (fun {_ _} ↦ (mem_sort _).2 (mem_univ _)) /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`, without a linear order. -/ def truncCycleFactors [DecidableEq α] [Fintype α] (f : Perm α) : Trunc { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := Quotient.recOnSubsingleton (@univ α _).1 (fun l h => Trunc.mk (cycleFactorsAux l f (h _))) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1 from fun _ _ => mem_univ _) section CycleFactorsFinset variable [DecidableEq α] [Fintype α] (f : Perm α) /-- Factors a permutation `f` into a `Finset` of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactorsFinset : Finset (Perm α) := (truncCycleFactors f).lift (fun l : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } => ⟨↑l.val, nodup_of_pairwise_disjoint (fun h1 => not_isCycle_one <| l.2.2.1 _ h1) l.2.2.2⟩) fun ⟨_, hl⟩ ⟨_, hl'⟩ => Finset.eq_of_veq <| Multiset.coe_eq_coe.mpr <| list_cycles_perm_list_cycles (hl'.left.symm ▸ hl.left) hl.right.left hl'.right.left hl.right.right hl'.right.right open scoped List in theorem cycleFactorsFinset_eq_list_toFinset {σ : Perm α} {l : List (Perm α)} (hn : l.Nodup) : σ.cycleFactorsFinset = l.toFinset ↔ (∀ f : Perm α, f ∈ l → f.IsCycle) ∧ l.Pairwise Disjoint ∧ l.prod = σ := by obtain ⟨⟨l', hp', hc', hd'⟩, hl⟩ := Trunc.exists_rep σ.truncCycleFactors have ht : cycleFactorsFinset σ = l'.toFinset := by rw [cycleFactorsFinset, ← hl, Trunc.lift_mk, Multiset.toFinset_eq, List.toFinset_coe] rw [ht] constructor · intro h have hn' : l'.Nodup := nodup_of_pairwise_disjoint_cycles hc' hd' have hperm : l ~ l' := List.perm_of_nodup_nodup_toFinset_eq hn hn' h.symm refine ⟨?_, ?_, ?_⟩ · exact fun _ h => hc' _ (hperm.subset h) · have := List.Perm.pairwise_iff (@Disjoint.symmetric _) hperm rwa [this] · rw [← hp', hperm.symm.prod_eq'] refine hd'.imp ?_ exact Disjoint.commute · rintro ⟨hc, hd, hp⟩ refine List.toFinset_eq_of_perm _ _ ?_ refine list_cycles_perm_list_cycles ?_ hc' hc hd' hd rw [hp, hp'] theorem cycleFactorsFinset_eq_finset {σ : Perm α} {s : Finset (Perm α)} : σ.cycleFactorsFinset = s ↔ (∀ f : Perm α, f ∈ s → f.IsCycle) ∧ ∃ h : (s : Set (Perm α)).Pairwise Disjoint, s.noncommProd id (h.mono' fun _ _ => Disjoint.commute) = σ := by obtain ⟨l, hl, rfl⟩ := s.exists_list_nodup_eq simp [cycleFactorsFinset_eq_list_toFinset, hl] theorem cycleFactorsFinset_pairwise_disjoint : (cycleFactorsFinset f : Set (Perm α)).Pairwise Disjoint := (cycleFactorsFinset_eq_finset.mp rfl).2.choose /-- Two cycles of a permutation commute. -/ theorem cycleFactorsFinset_mem_commute : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := (cycleFactorsFinset_pairwise_disjoint _).mono' fun _ _ => Disjoint.commute /-- Two cycles of a permutation commute. -/ theorem cycleFactorsFinset_mem_commute' {g1 g2 : Perm α} (h1 : g1 ∈ f.cycleFactorsFinset) (h2 : g2 ∈ f.cycleFactorsFinset) : Commute g1 g2 := by rcases eq_or_ne g1 g2 with rfl | h · apply Commute.refl · exact Equiv.Perm.cycleFactorsFinset_mem_commute f h1 h2 h /-- The product of cycle factors is equal to the original `f : perm α`. -/ theorem cycleFactorsFinset_noncommProd (comm : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := cycleFactorsFinset_mem_commute f) : f.cycleFactorsFinset.noncommProd id comm = f := (cycleFactorsFinset_eq_finset.mp rfl).2.choose_spec theorem mem_cycleFactorsFinset_iff {f p : Perm α} : p ∈ cycleFactorsFinset f ↔ p.IsCycle ∧ ∀ a ∈ p.support, p a = f a := by obtain ⟨l, hl, hl'⟩ := f.cycleFactorsFinset.exists_list_nodup_eq rw [← hl'] rw [eq_comm, cycleFactorsFinset_eq_list_toFinset hl] at hl' simpa [List.mem_toFinset, Ne, ← hl'.right.right] using mem_list_cycles_iff hl'.left hl'.right.left theorem cycleOf_mem_cycleFactorsFinset_iff {f : Perm α} {x : α} : cycleOf f x ∈ cycleFactorsFinset f ↔ x ∈ f.support := by rw [mem_cycleFactorsFinset_iff] constructor · rintro ⟨hc, _⟩ contrapose! hc rw [notMem_support, ← cycleOf_eq_one_iff] at hc simp [hc] · intro hx refine ⟨isCycle_cycleOf _ (mem_support.mp hx), ?_⟩ intro y hy rw [mem_support] at hy rw [cycleOf_apply] split_ifs with H · rfl · rw [cycleOf_apply_of_not_sameCycle H] at hy contradiction lemma cycleOf_ne_one_iff_mem_cycleFactorsFinset {g : Equiv.Perm α} {x : α} : g.cycleOf x ≠ 1 ↔ g.cycleOf x ∈ g.cycleFactorsFinset := by rw [cycleOf_mem_cycleFactorsFinset_iff, mem_support, ne_eq, cycleOf_eq_one_iff] theorem mem_cycleFactorsFinset_support_le {p f : Perm α} (h : p ∈ cycleFactorsFinset f) : p.support ≤ f.support := by rw [mem_cycleFactorsFinset_iff] at h intro x hx rwa [mem_support, ← h.right x hx, ← mem_support] lemma support_zpowers_of_mem_cycleFactorsFinset_le {g : Perm α} {c : g.cycleFactorsFinset} (v : Subgroup.zpowers (c : Perm α)) : (v : Perm α).support ≤ g.support := by obtain ⟨m, hm⟩ := v.prop simp only [← hm] exact le_trans (support_zpow_le _ _) (mem_cycleFactorsFinset_support_le c.prop) theorem pairwise_disjoint_of_mem_zpowers : Pairwise fun (i j : f.cycleFactorsFinset) ↦ ∀ (x y : Perm α), x ∈ Subgroup.zpowers ↑i → y ∈ Subgroup.zpowers ↑j → Disjoint x y := fun c d hcd ↦ fun x y hx hy ↦ by obtain ⟨m, hm⟩ := hx; obtain ⟨n, hn⟩ := hy simp only [← hm, ← hn] apply Disjoint.zpow_disjoint_zpow exact f.cycleFactorsFinset_pairwise_disjoint c.prop d.prop (Subtype.coe_ne_coe.mpr hcd) lemma pairwise_commute_of_mem_zpowers : Pairwise fun (i j : f.cycleFactorsFinset) ↦ ∀ (x y : Perm α), x ∈ Subgroup.zpowers ↑i → y ∈ Subgroup.zpowers ↑j → Commute x y := f.pairwise_disjoint_of_mem_zpowers.mono (fun _ _ ↦ forall₂_imp (fun _ _ h hx hy ↦ (h hx hy).commute)) lemma disjoint_ofSubtype_noncommPiCoprod (u : Perm (Function.fixedPoints f)) (v : (c : { x // x ∈ f.cycleFactorsFinset }) → (Subgroup.zpowers (c : Perm α))) : Disjoint (ofSubtype u) ((Subgroup.noncommPiCoprod f.pairwise_commute_of_mem_zpowers) v) := by apply Finset.noncommProd_induction · intro a _ b _ h apply f.pairwise_commute_of_mem_zpowers h <;> simp only [Subgroup.coe_subtype, SetLike.coe_mem] · intro x y exact Disjoint.mul_right · exact disjoint_one_right _ · intro c _ simp only [Subgroup.coe_subtype] exact Disjoint.mono (disjoint_ofSubtype_of_memFixedPoints_self u) le_rfl (support_zpowers_of_mem_cycleFactorsFinset_le (v c)) lemma commute_ofSubtype_noncommPiCoprod (u : Perm (Function.fixedPoints f)) (v : (c : { x // x ∈ f.cycleFactorsFinset }) → (Subgroup.zpowers (c : Perm α))) : Commute (ofSubtype u) ((Subgroup.noncommPiCoprod f.pairwise_commute_of_mem_zpowers) v) := Disjoint.commute (f.disjoint_ofSubtype_noncommPiCoprod u v) theorem mem_support_iff_mem_support_of_mem_cycleFactorsFinset {g : Equiv.Perm α} {x : α} : x ∈ g.support ↔ ∃ c ∈ g.cycleFactorsFinset, x ∈ c.support := by constructor · intro h use g.cycleOf x, cycleOf_mem_cycleFactorsFinset_iff.mpr h rw [mem_support_cycleOf_iff] exact ⟨SameCycle.refl g x, h⟩ · rintro ⟨c, hc, hx⟩ exact mem_cycleFactorsFinset_support_le hc hx theorem cycleFactorsFinset_eq_empty_iff {f : Perm α} : cycleFactorsFinset f = ∅ ↔ f = 1 := by simpa [cycleFactorsFinset_eq_finset] using eq_comm @[simp] theorem cycleFactorsFinset_one : cycleFactorsFinset (1 : Perm α) = ∅ := by simp [cycleFactorsFinset_eq_empty_iff] @[simp] theorem cycleFactorsFinset_eq_singleton_self_iff {f : Perm α} : f.cycleFactorsFinset = {f} ↔ f.IsCycle := by simp [cycleFactorsFinset_eq_finset] theorem IsCycle.cycleFactorsFinset_eq_singleton {f : Perm α} (hf : IsCycle f) : f.cycleFactorsFinset = {f} := cycleFactorsFinset_eq_singleton_self_iff.mpr hf theorem cycleFactorsFinset_eq_singleton_iff {f g : Perm α} : f.cycleFactorsFinset = {g} ↔ f.IsCycle ∧ f = g := by suffices f = g → (g.IsCycle ↔ f.IsCycle) by rw [cycleFactorsFinset_eq_finset] simpa [eq_comm] rintro rfl exact Iff.rfl /-- Two permutations `f g : Perm α` have the same cycle factors iff they are the same. -/ theorem cycleFactorsFinset_injective : Function.Injective (@cycleFactorsFinset α _ _) := by intro f g h rw [← cycleFactorsFinset_noncommProd f] simpa [h] using cycleFactorsFinset_noncommProd g theorem Disjoint.disjoint_cycleFactorsFinset {f g : Perm α} (h : Disjoint f g) : _root_.Disjoint (cycleFactorsFinset f) (cycleFactorsFinset g) := by rw [disjoint_iff_disjoint_support] at h rw [Finset.disjoint_left] intro x hx hy simp only [mem_cycleFactorsFinset_iff, mem_support] at hx hy obtain ⟨⟨⟨a, ha, -⟩, hf⟩, -, hg⟩ := hx, hy have := h.le_bot (by simp [ha, ← hf a ha, ← hg a ha] : a ∈ f.support ∩ g.support) tauto theorem Disjoint.cycleFactorsFinset_mul_eq_union {f g : Perm α} (h : Disjoint f g) : cycleFactorsFinset (f * g) = cycleFactorsFinset f ∪ cycleFactorsFinset g := by rw [cycleFactorsFinset_eq_finset] refine ⟨?_, ?_, ?_⟩ · simp [or_imp, mem_cycleFactorsFinset_iff, forall_swap] · rw [coe_union, Set.pairwise_union_of_symmetric Disjoint.symmetric] exact ⟨cycleFactorsFinset_pairwise_disjoint _, cycleFactorsFinset_pairwise_disjoint _, fun x hx y hy _ => h.mono (mem_cycleFactorsFinset_support_le hx) (mem_cycleFactorsFinset_support_le hy)⟩ · rw [noncommProd_union_of_disjoint h.disjoint_cycleFactorsFinset] rw [cycleFactorsFinset_noncommProd, cycleFactorsFinset_noncommProd] theorem disjoint_mul_inv_of_mem_cycleFactorsFinset {f g : Perm α} (h : f ∈ cycleFactorsFinset g) : Disjoint (g * f⁻¹) f := by rw [mem_cycleFactorsFinset_iff] at h intro x by_cases hx : f x = x · exact Or.inr hx · refine Or.inl ?_ rw [mul_apply, ← h.right, apply_inv_self] rwa [← support_inv, apply_mem_support, support_inv, mem_support] /-- If c is a cycle, a ∈ c.support and c is a cycle of f, then `c = f.cycleOf a` -/ theorem cycle_is_cycleOf {f c : Equiv.Perm α} {a : α} (ha : a ∈ c.support) (hc : c ∈ f.cycleFactorsFinset) : c = f.cycleOf a := by suffices f.cycleOf a = c.cycleOf a by rw [this] apply symm exact Equiv.Perm.IsCycle.cycleOf_eq (Equiv.Perm.mem_cycleFactorsFinset_iff.mp hc).left (Equiv.Perm.mem_support.mp ha) let hfc := (Equiv.Perm.disjoint_mul_inv_of_mem_cycleFactorsFinset hc).symm let hfc2 := Perm.Disjoint.commute hfc rw [← Equiv.Perm.cycleOf_mul_of_apply_right_eq_self hfc2] · simp only [hfc2.eq, inv_mul_cancel_right] -- `a` is in the support of `c`, hence it is not in the support of `g c⁻¹` exact Equiv.Perm.notMem_support.mp (Finset.disjoint_left.mp (Equiv.Perm.Disjoint.disjoint_support hfc) ha) theorem isCycleOn_support_of_mem_cycleFactorsFinset {g c : Equiv.Perm α} (hc : c ∈ g.cycleFactorsFinset) : IsCycleOn g c.support := by obtain ⟨x, hx⟩ := IsCycle.nonempty_support (mem_cycleFactorsFinset_iff.mp hc).1 rw [cycle_is_cycleOf hx hc] exact isCycleOn_support_cycleOf g x theorem eq_cycleOf_of_mem_cycleFactorsFinset_iff (g c : Perm α) (hc : c ∈ g.cycleFactorsFinset) (x : α) : c = g.cycleOf x ↔ x ∈ c.support := by refine ⟨?_, (cycle_is_cycleOf · hc)⟩ rintro rfl rw [mem_support, cycleOf_apply_self, ne_eq, ← cycleOf_eq_one_iff] exact (mem_cycleFactorsFinset_iff.mp hc).left.ne_one theorem zpow_apply_mem_support_of_mem_cycleFactorsFinset_iff {g : Perm α} {x : α} {m : ℤ} {c : g.cycleFactorsFinset} : (g ^ m) x ∈ (c : Perm α).support ↔ x ∈ (c : Perm α).support := by rw [← g.eq_cycleOf_of_mem_cycleFactorsFinset_iff _ c.prop, cycleOf_self_apply_zpow, eq_cycleOf_of_mem_cycleFactorsFinset_iff _ _ c.prop] /-- A permutation `c` is a cycle of `g` iff `k * c * k⁻¹` is a cycle of `k * g * k⁻¹` -/ theorem mem_cycleFactorsFinset_conj (g k c : Perm α) : k * c * k⁻¹ ∈ (k * g * k⁻¹).cycleFactorsFinset ↔ c ∈ g.cycleFactorsFinset := by suffices imp_lemma : ∀ {g k c : Perm α}, c ∈ g.cycleFactorsFinset → k * c * k⁻¹ ∈ (k * g * k⁻¹).cycleFactorsFinset by refine ⟨fun h ↦ ?_, imp_lemma⟩ have aux : ∀ h : Perm α, h = k⁻¹ * (k * h * k⁻¹) * k := fun _ ↦ by group rw [aux g, aux c] exact imp_lemma h intro g k c simp only [mem_cycleFactorsFinset_iff] apply And.imp IsCycle.conj intro hc a ha simp only [coe_mul, Function.comp_apply, EmbeddingLike.apply_eq_iff_eq] apply hc rw [mem_support] at ha ⊢ contrapose! ha simp only [mul_smul, ← Perm.smul_def] at ha ⊢ rw [ha] simp only [Perm.smul_def, apply_inv_self] /-- If a permutation commutes with every cycle of `g`, then it commutes with `g` NB. The converse is false. Commuting with every cycle of `g` means that we belong to the kernel of the action of `Equiv.Perm α` on `g.cycleFactorsFinset` -/ theorem commute_of_mem_cycleFactorsFinset_commute (k g : Perm α) (hk : ∀ c ∈ g.cycleFactorsFinset, Commute k c) : Commute k g := by rw [← cycleFactorsFinset_noncommProd g (cycleFactorsFinset_mem_commute g)] apply Finset.noncommProd_commute simpa only [id_eq] using hk /-- The cycles of a permutation commute with it -/ theorem self_mem_cycle_factors_commute {g c : Perm α} (hc : c ∈ g.cycleFactorsFinset) : Commute c g := by apply commute_of_mem_cycleFactorsFinset_commute intro c' hc' by_cases hcc' : c = c' · rw [hcc'] · apply g.cycleFactorsFinset_mem_commute hc hc'; exact hcc' /-- If `c` and `d` are cycles of `g`, then `d` stabilizes the support of `c` -/ theorem mem_support_cycle_of_cycle {g d c : Perm α} (hc : c ∈ g.cycleFactorsFinset) (hd : d ∈ g.cycleFactorsFinset) : ∀ x : α, d x ∈ c.support ↔ x ∈ c.support := by intro x simp only [mem_support, not_iff_not] by_cases h : c = d · rw [← h, EmbeddingLike.apply_eq_iff_eq] · rw [← Perm.mul_apply, Commute.eq (cycleFactorsFinset_mem_commute g hc hd h), mul_apply, EmbeddingLike.apply_eq_iff_eq] /-- If a permutation is a cycle of `g`, then its support is invariant under `g`. -/ theorem mem_cycleFactorsFinset_support {g c : Perm α} (hc : c ∈ g.cycleFactorsFinset) (a : α) : g a ∈ c.support ↔ a ∈ c.support := mem_support_iff_of_commute (self_mem_cycle_factors_commute hc).symm a end CycleFactorsFinset @[elab_as_elim] theorem cycle_induction_on [Finite β] (P : Perm β → Prop) (σ : Perm β) (base_one : P 1) (base_cycles : ∀ σ : Perm β, σ.IsCycle → P σ) (induction_disjoint : ∀ σ τ : Perm β, Disjoint σ τ → IsCycle σ → P σ → P τ → P (σ * τ)) : P σ := by cases nonempty_fintype β suffices ∀ l : List (Perm β), (∀ τ : Perm β, τ ∈ l → τ.IsCycle) → l.Pairwise Disjoint → P l.prod by classical let x := σ.truncCycleFactors.out exact (congr_arg P x.2.1).mp (this x.1 x.2.2.1 x.2.2.2) intro l induction l with | nil => exact fun _ _ => base_one | cons σ l ih => intro h1 h2 rw [List.prod_cons] exact induction_disjoint σ l.prod (disjoint_prod_right _ (List.pairwise_cons.mp h2).1) (h1 _ List.mem_cons_self) (base_cycles σ (h1 σ List.mem_cons_self)) (ih (fun τ hτ => h1 τ (List.mem_cons_of_mem σ hτ)) h2.of_cons) theorem cycleFactorsFinset_mul_inv_mem_eq_sdiff [DecidableEq α] [Fintype α] {f g : Perm α} (h : f ∈ cycleFactorsFinset g) : cycleFactorsFinset (g * f⁻¹) = cycleFactorsFinset g \ {f} := by revert f refine cycle_induction_on (P := fun {g : Perm α} ↦ ∀ {f}, (f ∈ cycleFactorsFinset g) → cycleFactorsFinset (g * f⁻¹) = cycleFactorsFinset g \ {f}) _ ?_ ?_ ?_ · simp · intro σ hσ f hf simp only [cycleFactorsFinset_eq_singleton_self_iff.mpr hσ, mem_singleton] at hf ⊢ simp [hf] · intro σ τ hd _ hσ hτ f simp_rw [hd.cycleFactorsFinset_mul_eq_union, mem_union] -- if only `wlog` could work here... rintro (hf | hf) · rw [hd.commute.eq, union_comm, union_sdiff_distrib, sdiff_singleton_eq_erase, erase_eq_of_notMem, mul_assoc, Disjoint.cycleFactorsFinset_mul_eq_union, hσ hf] · rw [mem_cycleFactorsFinset_iff] at hf intro x rcases hd.symm x with hx | hx · exact Or.inl hx · refine Or.inr ?_ by_cases hfx : f x = x · rw [← hfx] simpa [hx] using hfx.symm · rw [mul_apply] rw [← hf.right _ (mem_support.mpr hfx)] at hx contradiction · exact fun H => notMem_empty _ (hd.disjoint_cycleFactorsFinset.le_bot (mem_inter_of_mem hf H)) · rw [union_sdiff_distrib, sdiff_singleton_eq_erase, erase_eq_of_notMem, mul_assoc, Disjoint.cycleFactorsFinset_mul_eq_union, hτ hf] · rw [mem_cycleFactorsFinset_iff] at hf intro x rcases hd x with hx | hx · exact Or.inl hx · refine Or.inr ?_ by_cases hfx : f x = x · rw [← hfx] simpa [hx] using hfx.symm · rw [mul_apply] rw [← hf.right _ (mem_support.mpr hfx)] at hx contradiction · exact fun H => notMem_empty _ (hd.disjoint_cycleFactorsFinset.le_bot (mem_inter_of_mem H hf)) theorem IsCycle.forall_commute_iff [DecidableEq α] [Fintype α] (g z : Perm α) : (∀ c ∈ g.cycleFactorsFinset, Commute z c) ↔ ∀ c ∈ g.cycleFactorsFinset, ∃ (hc : ∀ x : α, z x ∈ c.support ↔ x ∈ c.support), ofSubtype (subtypePerm z hc) ∈ Subgroup.zpowers c := by apply forall_congr' intro c apply imp_congr_right intro hc exact IsCycle.commute_iff (mem_cycleFactorsFinset_iff.mp hc).1 /-- A permutation restricted to the support of a cycle factor is that cycle factor -/ theorem subtypePerm_on_cycleFactorsFinset [DecidableEq α] [Fintype α] {g c : Perm α} (hc : c ∈ g.cycleFactorsFinset) : g.subtypePerm (mem_cycleFactorsFinset_support hc) = c.subtypePermOfSupport := by ext ⟨x, hx⟩ simp only [subtypePerm_apply, Subtype.coe_mk, subtypePermOfSupport] exact ((mem_cycleFactorsFinset_iff.mp hc).2 x hx).symm theorem commute_iff_of_mem_cycleFactorsFinset [DecidableEq α] [Fintype α] {g k c : Equiv.Perm α} (hc : c ∈ g.cycleFactorsFinset) : Commute k c ↔ ∃ hc' : ∀ x : α, k x ∈ c.support ↔ x ∈ c.support, k.subtypePerm hc' ∈ Subgroup.zpowers (g.subtypePerm (mem_cycleFactorsFinset_support hc)) := by rw [IsCycle.commute_iff' (mem_cycleFactorsFinset_iff.mp hc).1] apply exists_congr intro hc' simp only [Subgroup.mem_zpowers_iff] apply exists_congr intro n rw [Equiv.Perm.subtypePerm_on_cycleFactorsFinset hc] end cycleFactors end Perm end Equiv
Basic.lean
/- Copyright (c) 2024 Kyle Miller, Jack Cheverton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller, Jack Cheverton, Jeremy Tan -/ import Mathlib.Order.CompleteBooleanAlgebra import Mathlib.Data.Fintype.Pi /-! # Digraphs This module defines directed graphs on a vertex type `V`, which is the same notion as a relation `V → V → Prop`. While this might be too simple of a notion to deserve the grandeur of a new definition, the intention here is to develop relations using the language of graph theory. Note that in this treatment, a digraph may have self loops. The type `Digraph V` is structurally equivalent to `Quiver.{0} V`, but a difference between these is that `Quiver` is a class — its purpose is to attach a quiver structure to a particular type `V`. In contrast, for `Digraph V` we are interested in working with the entire lattice of digraphs on `V`. ## Main definitions * `Digraph` is a structure for relations. Unlike `SimpleGraph`, the relation does not need to be symmetric or irreflexive. * `CompleteAtomicBooleanAlgebra` instance: Under the subgraph relation, `Digraph` forms a `CompleteAtomicBooleanAlgebra`. In other words, this is the complete lattice of spanning subgraphs of the complete graph. -/ open Finset Function /-- A digraph is a relation `Adj` on a vertex type `V`. The relation describes which pairs of vertices are adjacent. In this treatment, a digraph may have self-loops. -/ @[ext] structure Digraph (V : Type*) where /-- The adjacency relation of a digraph. -/ Adj : V → V → Prop /-- Constructor for digraphs using a boolean function. This is useful for creating a digraph with a decidable `Adj` relation, and it's used in the construction of the `Fintype (Digraph V)` instance. -/ @[simps] def Digraph.mk' {V : Type*} : (V → V → Bool) ↪ Digraph V where toFun x := ⟨fun v w ↦ x v w⟩ inj' adj adj' := by simp_rw [mk.injEq] intro h funext v w simpa only [eq_iff_iff, Bool.coe_iff_coe] using congr($h v w) instance {V : Type*} (adj : V → V → Bool) : DecidableRel (Digraph.mk' adj).Adj := inferInstanceAs <| DecidableRel (fun v w ↦ adj v w) instance {V : Type*} [DecidableEq V] [Fintype V] : Fintype (Digraph V) := Fintype.ofBijective Digraph.mk' <| by classical refine ⟨Embedding.injective _, ?_⟩ intro G use fun v w ↦ G.Adj v w ext v w simp namespace Digraph /-- The complete digraph on a type `V` (denoted by `⊤`) is the digraph whose vertices are all adjacent. Note that every vertex is adjacent to itself in `⊤`. -/ protected def completeDigraph (V : Type*) : Digraph V where Adj := ⊤ /-- The empty digraph on a type `V` (denoted by `⊥`) is the digraph such that no pairs of vertices are adjacent. Note that `⊥` is called the empty digraph because it has no edges. -/ protected def emptyDigraph (V : Type*) : Digraph V where Adj _ _ := False /-- Two vertices are adjacent in the complete bipartite digraph on two vertex types if and only if they are not from the same side. Any bipartite digraph may be regarded as a subgraph of one of these. -/ @[simps] def completeBipartiteGraph (V W : Type*) : Digraph (Sum V W) where Adj v w := v.isLeft ∧ w.isRight ∨ v.isRight ∧ w.isLeft variable {ι : Sort*} {V : Type*} (G : Digraph V) {a b : V} theorem adj_injective : Injective (Adj : Digraph V → V → V → Prop) := fun _ _ ↦ Digraph.ext @[simp] theorem adj_inj {G H : Digraph V} : G.Adj = H.Adj ↔ G = H := Digraph.ext_iff.symm section Order /-- The relation that one `Digraph` is a spanning subgraph of another. Note that `Digraph.IsSubgraph G H` should be spelled `G ≤ H`. -/ protected def IsSubgraph (x y : Digraph V) : Prop := ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w instance : LE (Digraph V) := ⟨Digraph.IsSubgraph⟩ @[simp] theorem isSubgraph_eq_le : (Digraph.IsSubgraph : Digraph V → Digraph V → Prop) = (· ≤ ·) := rfl /-- The supremum of two digraphs `x ⊔ y` has edges where either `x` or `y` have edges. -/ instance : Max (Digraph V) where max x y := { Adj := x.Adj ⊔ y.Adj } @[simp] theorem sup_adj (x y : Digraph V) (v w : V) : (x ⊔ y).Adj v w ↔ x.Adj v w ∨ y.Adj v w := Iff.rfl /-- The infimum of two digraphs `x ⊓ y` has edges where both `x` and `y` have edges. -/ instance : Min (Digraph V) where min x y := { Adj := x.Adj ⊓ y.Adj } @[simp] theorem inf_adj (x y : Digraph V) (v w : V) : (x ⊓ y).Adj v w ↔ x.Adj v w ∧ y.Adj v w := Iff.rfl /-- We define `Gᶜ` to be the `Digraph V` such that no two adjacent vertices in `G` are adjacent in the complement, and every nonadjacent pair of vertices is adjacent. -/ instance hasCompl : HasCompl (Digraph V) where compl G := { Adj := fun v w ↦ ¬G.Adj v w } @[simp] theorem compl_adj (G : Digraph V) (v w : V) : Gᶜ.Adj v w ↔ ¬G.Adj v w := Iff.rfl /-- The difference of two digraphs `x \ y` has the edges of `x` with the edges of `y` removed. -/ instance sdiff : SDiff (Digraph V) where sdiff x y := { Adj := x.Adj \ y.Adj } @[simp] theorem sdiff_adj (x y : Digraph V) (v w : V) : (x \ y).Adj v w ↔ x.Adj v w ∧ ¬y.Adj v w := Iff.rfl instance supSet : SupSet (Digraph V) where sSup s := { Adj := fun a b ↦ ∃ G ∈ s, Adj G a b } instance infSet : InfSet (Digraph V) where sInf s := { Adj := fun a b ↦ (∀ ⦃G⦄, G ∈ s → Adj G a b) } @[simp] theorem sSup_adj {s : Set (Digraph V)} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem sInf_adj {s : Set (Digraph V)} : (sInf s).Adj a b ↔ ∀ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem iSup_adj {f : ι → Digraph V} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] @[simp] theorem iInf_adj {f : ι → Digraph V} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) := by simp [iInf] /-- For digraphs `G`, `H`, `G ≤ H` iff `∀ a b, G.Adj a b → H.Adj a b`. -/ instance distribLattice : DistribLattice (Digraph V) := { adj_injective.distribLattice Digraph.Adj (fun _ _ ↦ rfl) fun _ _ ↦ rfl with le := fun G H ↦ ∀ ⦃a b⦄, G.Adj a b → H.Adj a b } instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Digraph V) := { Digraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) compl := HasCompl.compl sdiff := (· \ ·) top := Digraph.completeDigraph V bot := Digraph.emptyDigraph V le_top := fun _ _ _ _ ↦ trivial bot_le := fun _ _ _ h ↦ h.elim sdiff_eq := fun _ _ ↦ rfl inf_compl_le_bot := fun _ _ _ h ↦ absurd h.1 h.2 top_le_sup_compl := fun G v w _ ↦ by tauto sSup := sSup le_sSup := fun _ G hG _ _ hab ↦ ⟨G, hG, hab⟩ sSup_le := fun s G hG a b ↦ by rintro ⟨H, hH, hab⟩ exact hG _ hH hab sInf := sInf sInf_le := fun _ _ hG _ _ hab ↦ hab hG le_sInf := fun _ _ hG _ _ hab ↦ fun _ hH ↦ hG _ hH hab iInf_iSup_eq := fun f ↦ by ext; simp [Classical.skolem] } @[simp] theorem top_adj (v w : V) : (⊤ : Digraph V).Adj v w := trivial @[simp] theorem bot_adj (v w : V) : (⊥ : Digraph V).Adj v w ↔ False := Iff.rfl @[simp] theorem completeDigraph_eq_top (V : Type*) : Digraph.completeDigraph V = ⊤ := rfl @[simp] theorem emptyDigraph_eq_bot (V : Type*) : Digraph.emptyDigraph V = ⊥ := rfl @[simps] instance (V : Type*) : Inhabited (Digraph V) := ⟨⊥⟩ instance [IsEmpty V] : Unique (Digraph V) where default := ⊥ uniq G := by ext1; congr! instance [Nonempty V] : Nontrivial (Digraph V) := by use ⊥, ⊤ have v := Classical.arbitrary V exact ne_of_apply_ne (·.Adj v v) (by simp) section Decidable variable (V) (H : Digraph V) [DecidableRel G.Adj] [DecidableRel H.Adj] instance Bot.adjDecidable : DecidableRel (⊥ : Digraph V).Adj := inferInstanceAs <| DecidableRel fun _ _ ↦ False instance Sup.adjDecidable : DecidableRel (G ⊔ H).Adj := inferInstanceAs <| DecidableRel fun v w ↦ G.Adj v w ∨ H.Adj v w instance Inf.adjDecidable : DecidableRel (G ⊓ H).Adj := inferInstanceAs <| DecidableRel fun v w ↦ G.Adj v w ∧ H.Adj v w instance SDiff.adjDecidable : DecidableRel (G \ H).Adj := inferInstanceAs <| DecidableRel fun v w ↦ G.Adj v w ∧ ¬H.Adj v w instance Top.adjDecidable : DecidableRel (⊤ : Digraph V).Adj := inferInstanceAs <| DecidableRel fun _ _ ↦ True instance Compl.adjDecidable : DecidableRel (Gᶜ.Adj) := inferInstanceAs <| DecidableRel fun v w ↦ ¬G.Adj v w end Decidable end Order end Digraph
SubDPIdeal.lean
/- Copyright (c) 2025 Antoine Chambert-Loir, María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.RingTheory.DividedPowers.DPMorphism import Mathlib.RingTheory.Ideal.Quotient.Operations /-! # Sub-divided power-ideals Let `A` be a commutative (semi)ring and let `I` be an ideal of `A` with a divided power structure `hI`. A subideal `J` of `I` is a *sub-dp-ideal* of `(I, hI)` if, for all `n ∈ ℕ > 0` and all `x ∈ J`, `hI.dpow n x ∈ J`. ## Main definitions * `DividedPowers.IsSubDPIdeal` : A sub-ideal `J` of a divided power ideal `(I, hI)` is a *sub-dp-ideal* if for all `n > 0` and all `x ∈ J`, `hI.dpow n j ∈ J`. * `DividedPowers.SubDPIdeal` : A bundled version of `IsSubDPIdeal`. * `DividedPowers.IsSubDPIdeal.dividedPowers`: the divided power structure on a sub-dp-ideal. * `DividedPowers.IsSubDPIdeal.prod` : if `J` is an `A`-ideal, then `I ⬝ J` is a sub-dp-ideal of `I`. * `DividedPowers.IsSubDPIdeal.span` : the sub-dp-ideal of `I` generated by a set of elements of `A`. * `DividedPowers.subDPIdeal_inf_of_quot` : if there is a dp-structure on `I⬝(A/J)` such that the quotient map is a dp-morphism, then `J ⊓ I` is a sub-dp-ideal of `I`. * `DividedPowers.Quotient.OfSurjective.dividedPowers`: when `f : A → B` is a surjective map and `f.ker ⊓ I` is a sub-dp-ideal of `I`, this is the induced divided power structure on the ideal `I.map f` of the target. * `DividedPowers.Quotient.dividedPowers` : when `I ⊓ J` is a sub-dp-ideal of `I`, this is the divided power structure on the ideal `I(A⧸J)` of the quotient. ## Main results * `DividedPowers.isSubDPIdeal_inf_iff` : the ideal `J ⊓ I` is a sub-dp-ideal of `I` if and only if (on `I`) the divided powers are compatible mod `J`. * `DividedPowers.span_isSubDPIdeal_iff` : the span of a set `S : Set A` is a sub-dp-ideal of `I` if and only if for all `n ∈ ℕ > 0` and all `s ∈ S`, hI.dpow n s ∈ span S. * `DividedPowers.isSubDPIdeal_ker` : the kernel of a divided power morphism from `I` to `J` is a sub-dp-ideal of `I`. * `DividedPowers.isSubDPIdeal_map` : the image of a divided power morphism from `I` to `J` is a sub-dp-ideal of `J`. * `DividedPowers.SubDPIdeal.instCompleteLattice` : sub-dp-ideals of `I` form a complete lattice under inclusion. * `DividedPowers.SubDPIdealspan_carrier_eq_dpow_span` : the underlying ideal of `SubDPIdeal.span hI S` is generated by the elements of the form `hI.dpow n x` with `n > 0` and `x ∈ S`. * `DividedPowers.Quotient.OfSurjective.dividedPowers_unique` : the only divided power structure on `I.map f` such that the surjective map `f : A → B` is a divided power morphism is given by `DividedPowers.Quotient.OfSurjective.dividedPowers`. * `DividedPowers.Quotient.dividedPowers_unique` : the only divided power structure on `I(A⧸J)` such that the quotient map `A → A/J` is a divided power morphism is given by `DividedPowers.Quotient.dividedPowers`. ## Implementation remarks We provide both a bundled and an unbundled definition of sub-dp-ideals. The unbundled version is often more convenient when a larger proof requires to show that a certain ideal is a sub-dp-ideal. On the other hand, a bundled version is required to prove that sub-dp-ideals form a complete lattice. ## References * [P. Berthelot, *Cohomologie cristalline des schémas de caractéristique $p$ > 0*][Berthelot-1974] * [P. Berthelot and A. Ogus, *Notes on crystalline cohomology*][BerthelotOgus-1978] * [N. Roby, *Lois polynomes et lois formelles en théorie des modules*][Roby-1963] * [N. Roby, *Les algèbres à puissances dividées*][Roby-1965] -/ open Subtype namespace DividedPowers /-- A sub-ideal `J` of a divided power ideal `(I, hI)` is a sub-dp-ideal if for all `n > 0` and all `x ∈ J`, `hI.dpow n j ∈ J`. -/ structure IsSubDPIdeal {A : Type*} [CommSemiring A] {I : Ideal A} (hI : DividedPowers I) (J : Ideal A) : Prop where isSubideal : J ≤ I dpow_mem : ∀ (n : ℕ) (_: n ≠ 0) {j : A} (_ : j ∈ J), hI.dpow n j ∈ J section IsSubDPIdeal namespace IsSubDPIdeal variable {A : Type*} [CommSemiring A] {I : Ideal A} (hI : DividedPowers I) open Ideal theorem self : IsSubDPIdeal hI I where isSubideal := le_rfl dpow_mem _ hn _ ha := hI.dpow_mem hn ha /-- The divided power structure on a sub-dp-ideal. -/ def dividedPowers {J : Ideal A} (hJ : IsSubDPIdeal hI J) [∀ x, Decidable (x ∈ J)] : DividedPowers J where dpow n x := if x ∈ J then hI.dpow n x else 0 dpow_null hx := by simp [if_neg hx] dpow_zero hx := by simp [if_pos hx, hI.dpow_zero (hJ.isSubideal hx)] dpow_one hx := by simp [if_pos hx, hI.dpow_one (hJ.isSubideal hx)] dpow_mem hn hx := by simp [if_pos hx, hJ.dpow_mem _ hn hx] dpow_add hx hy := by simp_rw [if_pos hx, if_pos hy, if_pos (Ideal.add_mem J hx hy), hI.dpow_add (hJ.isSubideal hx) (hJ.isSubideal hy)] dpow_mul hx := by simp [if_pos hx, if_pos (mul_mem_left J _ hx), hI.dpow_mul (hJ.isSubideal hx)] mul_dpow hx := by simp [if_pos hx, hI.mul_dpow (hJ.isSubideal hx)] dpow_comp hn hx := by simp [if_pos hx, if_pos (hJ.dpow_mem _ hn hx), hI.dpow_comp hn (hJ.isSubideal hx)] variable {J : Ideal A} (hJ : IsSubDPIdeal hI J) [∀ x, Decidable (x ∈ J)] lemma dpow_eq (n : ℕ) (a : A) : (IsSubDPIdeal.dividedPowers hI hJ).dpow n a = if a ∈ J then hI.dpow n a else 0 := rfl lemma dpow_eq_of_mem {n : ℕ} {a : A} (ha : a ∈ J) : (IsSubDPIdeal.dividedPowers hI hJ).dpow n a = hI.dpow n a := by rw [dpow_eq, if_pos ha] theorem isDPMorphism (hJ : IsSubDPIdeal hI J) : (IsSubDPIdeal.dividedPowers hI hJ).IsDPMorphism hI (RingHom.id A) := by simpa only [isDPMorphism_iff, Ideal.map_id, RingHom.id_apply] using ⟨hJ.1, fun _ _ _ ha ↦ by rw [dpow_eq_of_mem _ _ ha]⟩ end IsSubDPIdeal open Finset Ideal /-- The ideal `J ⊓ I` is a sub-dp-ideal of `I` if and only if the divided powers have some compatibility mod `J`. (The necessity was proved as a sanity check.) -/ theorem isSubDPIdeal_inf_iff {A : Type*} [CommRing A] {I : Ideal A} (hI : DividedPowers I) {J : Ideal A} : IsSubDPIdeal hI (J ⊓ I) ↔ ∀ {n : ℕ} {a b : A} (_ : a ∈ I) (_ : b ∈ I) (_ : a - b ∈ J), hI.dpow n a - hI.dpow n b ∈ J := by refine ⟨fun hIJ n a b ha hb hab ↦ ?_, fun hIJ ↦ ?_⟩ · have hab' : a - b ∈ I := I.sub_mem ha hb rw [← add_sub_cancel b a, hI.dpow_add' hb hab', range_succ, sum_insert notMem_range_self, tsub_self, hI.dpow_zero hab', mul_one, add_sub_cancel_left] exact J.sum_mem (fun i hi ↦ SemilatticeInf.inf_le_left J I ((J ⊓ I).smul_mem _ (hIJ.dpow_mem _ (ne_of_gt (Nat.sub_pos_of_lt (mem_range.mp hi))) ⟨hab, hab'⟩))) · refine ⟨SemilatticeInf.inf_le_right J I, fun {n} hn {a} ha ↦ ⟨?_, hI.dpow_mem hn ha.right⟩⟩ rw [← sub_zero (hI.dpow n a), ← hI.dpow_eval_zero hn] exact hIJ ha.right I.zero_mem (J.sub_mem ha.left J.zero_mem) variable {A B : Type*} [CommSemiring A] {I : Ideal A} {hI : DividedPowers I} [CommSemiring B] {J : Ideal B} {hJ : DividedPowers J} /-- [P. Berthelot and A. Ogus, *Notes on crystalline cohomology* (Lemma 3.6)][BerthelotOgus-1978] -/ theorem span_isSubDPIdeal_iff {S : Set A} (hS : S ⊆ I) : IsSubDPIdeal hI (span S) ↔ ∀ {n : ℕ} (_ : n ≠ 0), ∀ s ∈ S, hI.dpow n s ∈ span S := by refine ⟨fun hhI n hn s hs ↦ hhI.dpow_mem n hn (subset_span hs), fun hhI ↦ ?_⟩ · -- interesting direction have hSI := span_le.mpr hS apply IsSubDPIdeal.mk hSI intro m hm z hz induction hz using Submodule.span_induction generalizing m hm with | mem x h => exact hhI hm x h | zero => rw [hI.dpow_eval_zero hm] exact (span S).zero_mem | add x y hxI hyI hx hy => rw [hI.dpow_add' (hSI hxI) (hSI hyI)] apply Submodule.sum_mem (span S) intro m _ by_cases hm0 : m = 0 · exact hm0 ▸ mul_mem_left (span S) _ (hy _ hm) · exact mul_mem_right _ (span S) (hx _ hm0) | smul a x hxI hx => rw [Algebra.id.smul_eq_mul, hI.dpow_mul (hSI hxI)] exact mul_mem_left (span S) (a ^ m) (hx m hm) theorem isSubDPIdeal_sup {J K : Ideal A} (hJ : IsSubDPIdeal hI J) (hK : IsSubDPIdeal hI K) : IsSubDPIdeal hI (J ⊔ K) := by rw [← J.span_eq, ← K.span_eq, ← span_union, span_isSubDPIdeal_iff (Set.union_subset_iff.mpr ⟨hJ.1, hK.1⟩)] intro n hn a ha rcases ha with ha | ha · exact span_mono Set.subset_union_left (subset_span (hJ.2 n hn ha)) · exact span_mono Set.subset_union_right (subset_span (hK.2 n hn ha)) theorem isSubDPIdeal_iSup {ι : Type*} {J : ι → Ideal A} (hJ : ∀ i, IsSubDPIdeal hI (J i)) : IsSubDPIdeal hI (iSup J) := by rw [iSup_eq_span, span_isSubDPIdeal_iff (Set.iUnion_subset_iff.mpr <| fun i ↦ (hJ i).1)] simp_rw [Set.mem_iUnion] rintro n hn a ⟨i, ha⟩ exact span_mono (Set.subset_iUnion _ i) (subset_span ((hJ i).2 n hn ha)) theorem isSubDPIdeal_iInf {ι : Type*} {J : ι → Ideal A} (hJ : ∀ i, IsSubDPIdeal hI (J i)) : IsSubDPIdeal hI (I ⊓ iInf (fun i ↦ J i)) := by by_cases hι : Nonempty ι · refine ⟨fun _ hx ↦ hx.1, ?_⟩ intro n hn x hx simp only [Ideal.mem_inf, mem_iInf] at hx ⊢ exact ⟨hI.dpow_mem hn hx.1, fun i ↦ IsSubDPIdeal.dpow_mem (hJ i) n hn (hx.2 i)⟩ · simp only [not_nonempty_iff] at hι simp only [iInf_of_empty, le_top, inf_of_le_left] exact IsSubDPIdeal.self hI theorem isSubDPIdeal_map_of_isSubDPIdeal {f : A →+* B} (hf : IsDPMorphism hI hJ f) {K : Ideal A} (hK : IsSubDPIdeal hI K) : IsSubDPIdeal hJ (map f K) := by rw [Ideal.map, span_isSubDPIdeal_iff] · rintro n hn y ⟨x, hx, rfl⟩ exact hf.2 x (hK.1 hx) ▸ mem_map_of_mem _ (hK.2 _ hn hx) · rintro y ⟨x, hx, rfl⟩ exact hf.1 (mem_map_of_mem f (hK.1 hx)) /-- The image of a divided power morphism from `I` to `J` is a sub-dp-ideal of `J`. -/ theorem isSubDPIdeal_map {f : A →+* B} (hf : IsDPMorphism hI hJ f) : IsSubDPIdeal hJ (Ideal.map f I) := isSubDPIdeal_map_of_isSubDPIdeal hf (IsSubDPIdeal.self hI) end IsSubDPIdeal /-- A `SubDPIdeal` of `I` is a sub-ideal `J` of `I` such that for all `n > 0` `x ∈ J`, `hI.dpow n j ∈ J`. The unbundled version of this definition is called `IsSubDPIdeal`. -/ @[ext] structure SubDPIdeal {A : Type*} [CommSemiring A] {I : Ideal A} (hI : DividedPowers I) where /-- The underlying ideal. -/ carrier : Ideal A isSubideal : carrier ≤ I dpow_mem : ∀ (n : ℕ) (_ : n ≠ 0), ∀ j ∈ carrier, hI.dpow n j ∈ carrier namespace SubDPIdeal variable {A : Type*} [CommSemiring A] {I : Ideal A} {hI : DividedPowers I} /-- Constructs a `SubPDIdeal` given an ideal `J` satisfying `hI.IsSubDPIdeal J`. -/ def mk' {J : Ideal A} (hJ : hI.IsSubDPIdeal J) : hI.SubDPIdeal := ⟨J, hJ.1, hJ.2⟩ instance : SetLike (SubDPIdeal hI) A where coe s := s.carrier coe_injective' p q h := by rw [SetLike.coe_set_eq] at h cases p; cases q; congr /-- The coercion from `SubDPIdeal` to `Ideal`. -/ @[coe] def toIdeal (J : hI.SubDPIdeal) : Ideal A := J.carrier instance : CoeOut (hI.SubDPIdeal) (Ideal A) := ⟨fun J ↦ J.toIdeal⟩ theorem coe_def (J : SubDPIdeal hI) : J.toIdeal = J.carrier := rfl @[simp] theorem memCarrier {s : SubDPIdeal hI} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl lemma toIsSubDPIdeal (J : SubDPIdeal hI) : IsSubDPIdeal hI J.carrier where isSubideal := J.isSubideal dpow_mem := J.dpow_mem open Ideal /-- If `J` is an ideal of `A`, then `I⬝J` is a sub-dp-ideal of `I`. See [P. Berthelot, *Cohomologie cristalline des schémas de caractéristique $p$ > 0*, (Proposition 1.6.1 (i))][Berthelot-1974] -/ def prod (J : Ideal A) : SubDPIdeal hI where carrier := I • J isSubideal := mul_le_right dpow_mem m hm x hx := by induction hx using Submodule.smul_induction_on' generalizing m with | smul a ha b hb => rw [Algebra.id.smul_eq_mul, smul_eq_mul, mul_comm a b, hI.dpow_mul ha, mul_comm] exact Submodule.mul_mem_mul (J.pow_mem_of_mem hb m (zero_lt_iff.mpr hm)) (hI.dpow_mem hm ha) | add x hx y hy hx' hy' => rw [hI.dpow_add' (mul_le_right hx) (mul_le_right hy)] apply Submodule.sum_mem (I • J) intro k _ by_cases hk0 : k = 0 · exact hk0 ▸ mul_mem_left (I • J) _ (hy' _ hm) · exact mul_mem_right _ (I • J) (hx' k hk0) section CompleteLattice instance : CoeOut (SubDPIdeal hI) (Set.Iic I) := ⟨fun J ↦ ⟨J.carrier, J.isSubideal⟩⟩ instance : LE (SubDPIdeal hI) := ⟨fun J J' ↦ J.carrier ≤ J'.carrier⟩ theorem le_iff {J J' : SubDPIdeal hI} : J ≤ J' ↔ J.carrier ≤ J'.carrier := Iff.rfl instance : LT (SubDPIdeal hI) := ⟨fun J J' ↦ J.carrier < J'.carrier⟩ theorem lt_iff {J J' : SubDPIdeal hI} : J < J' ↔ J.carrier < J'.carrier := Iff.rfl /-- I is a sub-dp-ideal ot itself. -/ instance : Top (SubDPIdeal hI) := ⟨{carrier := I isSubideal := le_refl _ dpow_mem := fun _ hn _ hx ↦ hI.dpow_mem hn hx }⟩ instance inhabited : Inhabited hI.SubDPIdeal := ⟨⊤⟩ /-- `(0)` is a sub-dp-ideal ot the dp-ideal `I`. -/ instance : Bot (SubDPIdeal hI) := ⟨{carrier := ⊥ isSubideal := bot_le dpow_mem := fun _ hn x hx ↦ by rw [mem_bot.mp hx, hI.dpow_eval_zero hn, mem_bot]}⟩ /-- The intersection of two sub-dp-ideals is a sub-dp-ideal. -/ instance : Min (SubDPIdeal hI) := ⟨fun J J' ↦ { carrier := J.carrier ⊓ J'.carrier isSubideal := fun _ hx ↦ J.isSubideal hx.1 dpow_mem := fun _ hn x hx ↦ ⟨J.dpow_mem _ hn x hx.1, J'.dpow_mem _ hn x hx.2⟩ }⟩ theorem inf_carrier_def (J J' : SubDPIdeal hI) : (J ⊓ J').carrier = J.carrier ⊓ J'.carrier := rfl instance : InfSet (SubDPIdeal hI) := ⟨fun S ↦ { carrier := ⨅ s ∈ Insert.insert ⊤ S, (s : hI.SubDPIdeal).carrier isSubideal := fun x hx ↦ by simp only [mem_iInf] at hx exact hx ⊤ (Set.mem_insert ⊤ S) dpow_mem := fun _ hn x hx ↦ by simp only [mem_iInf] at hx ⊢ exact fun s hs ↦ s.dpow_mem _ hn x (hx s hs) }⟩ theorem sInf_carrier_def (S : Set (SubDPIdeal hI)) : (sInf S).carrier = ⨅ s ∈ Insert.insert ⊤ S, (s : hI.SubDPIdeal).carrier := rfl instance : Max (SubDPIdeal hI) := ⟨fun J J' ↦ SubDPIdeal.mk' (isSubDPIdeal_sup J.toIsSubDPIdeal J'.toIsSubDPIdeal)⟩ theorem sup_carrier_def (J J' : SubDPIdeal hI) : (J ⊔ J').carrier = J ⊔ J' := rfl instance : SupSet (SubDPIdeal hI) := ⟨fun S ↦ SubDPIdeal.mk' (J := sSup ((fun J ↦ J.carrier) '' S)) <| by have h : (⋃ (i : Ideal A) (_ : i ∈ (fun J ↦ J.carrier) '' S), ↑i) ⊆ (I : Set A) := by rintro a ⟨-, ⟨J, rfl⟩, haJ⟩ rw [Set.mem_iUnion, SetLike.mem_coe, exists_prop] at haJ obtain ⟨J', hJ'⟩ := (Set.mem_image _ _ _).mp haJ.1 exact J'.isSubideal (hJ'.2 ▸ haJ.2) rw [sSup_eq_iSup, Submodule.iSup_eq_span', submodule_span_eq, span_isSubDPIdeal_iff h] rintro n hn x ⟨T, ⟨J, rfl⟩, ⟨J', ⟨⟨hJ', rfl⟩, h'⟩⟩⟩ apply subset_span apply Set.mem_biUnion hJ' obtain ⟨K, hKS, rfl⟩ := hJ' exact K.dpow_mem _ hn x h'⟩ theorem sSup_carrier_def (S : Set (SubDPIdeal hI)) : (sSup S).carrier = sSup ((toIdeal) '' S) := rfl instance : CompleteLattice (SubDPIdeal hI) := by refine Function.Injective.completeLattice (fun J : SubDPIdeal hI ↦ (J : Set.Iic I)) (fun J J' h ↦ by simpa only [SubDPIdeal.ext_iff, Subtype.mk.injEq] using h) (fun J J' ↦ by rfl) (fun J J' ↦ by rfl) (fun S ↦ ?_) (fun S ↦ ?_) rfl rfl · conv_rhs => rw [iSup] rw [Subtype.ext_iff, Set.Iic.coe_sSup] dsimp only rw [sSup_carrier_def, sSup_image, sSup_image, iSup_range] have (J : hI.SubDPIdeal) : ((⨆ (_ : J ∈ S), (J : Set.Iic I) : Set.Iic I) : Ideal A) = ⨆ (_ : J ∈ S), (J : Ideal A) := by by_cases hJ : J ∈ S · simp [ciSup_pos hJ] · simp [hJ, not_false_eq_true, iSup_neg, Set.Iic.coe_bot] simp_rw [this] rfl · conv_rhs => rw [iInf] rw [Subtype.ext_iff, Set.Iic.coe_sInf] dsimp only rw [sInf_carrier_def, sInf_image, iInf_range, inf_iInf, iInf_insert, inf_iInf] apply iInf_congr (fun J ↦ ?_) by_cases hJ : J ∈ S · rw [ciInf_pos hJ, ciInf_pos hJ]; rfl · simp [hJ, iInf_neg, le_top, inf_of_le_left, Set.Iic.coe_top, le_refl]; rfl end CompleteLattice section Generated variable (hI) /-- The sub-dp-ideal of I generated by a family of elements of A. -/ protected def span (S : Set A) : SubDPIdeal hI := sInf {J : SubDPIdeal hI | S ⊆ J.carrier} theorem _root_.DividedPowers.dpow_span_isSubideal {S : Set A} (hS : S ⊆ I) : span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x} ≤ I := by rw [span_le] rintro y ⟨n, hn, x, hx, hxy⟩ exact hxy ▸ hI.dpow_mem hn (hS hx) theorem dpow_mem_span_of_mem_span {S : Set A} (hS : S ⊆ I) {k : ℕ} (hk : k ≠ 0) {z : A} (hz : z ∈ span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x}) : hI.dpow k z ∈ span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x} := by let J := span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x} have hSI := hI.dpow_span_isSubideal hS have haux : ∀ (n : ℕ) (_ : n ≠ 0), hI.dpow n z ∈ span {y | ∃ n, ∃ (_ : n ≠ 0), ∃ x, ∃ (_ : x ∈ S), y = hI.dpow n x} := by refine Submodule.span_induction ?_ ?_ ?_ ?_ hz · -- Elements of S rintro y ⟨m, hm, x, hxS, hxy⟩ n hn rw [hxy, hI.dpow_comp hm (hS hxS)] exact mul_mem_left _ _ (subset_span ⟨n * m, mul_ne_zero hn hm, x, hxS, rfl⟩) · -- Zero exact fun _ hn ↦ by simp only [hI.dpow_eval_zero hn, zero_mem] · intro x y hx hy hx_pow hy_pow n hn rw [hI.dpow_add' (hSI hx) (hSI hy)] apply Submodule.sum_mem (span _) intro m _ by_cases hm0 : m = 0 · rw [hm0]; exact (span _).mul_mem_left _ (hy_pow n hn) · exact (span _).mul_mem_right _ (hx_pow m hm0) · intro a x hx hx_pow n hn rw [smul_eq_mul, hI.dpow_mul (hSI hx)] exact mul_mem_left (span _) (a ^ n) (hx_pow n hn) exact haux _ hk /-- The underlying ideal of `SubDPIdeal.span hI S` is generated by the elements of the form `hI.dpow n x` with `n > 0` and `x ∈ S`. -/ theorem span_carrier_eq_dpow_span {S : Set A} (hS : S ⊆ I) : (SubDPIdeal.span hI S).carrier = span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x} := by set J : SubDPIdeal hI := { carrier := span {y : A | ∃ (n : ℕ) (_ : n ≠ 0) (x : A) (_ : x ∈ S), y = hI.dpow n x } isSubideal := hI.dpow_span_isSubideal hS dpow_mem _ hk _ hz := dpow_mem_span_of_mem_span hI hS hk hz } simp only [SubDPIdeal.span, sInf_carrier_def] apply le_antisymm · have h : J ∈ insert ⊤ {J : hI.SubDPIdeal | S ⊆ ↑J.carrier} := Set.mem_insert_of_mem _ (fun x hx ↦ subset_span ⟨1, one_ne_zero, x, hx, by rw [hI.dpow_one (hS hx)]⟩) refine sInf_le_of_le ⟨J, ?_⟩ (le_refl _) simp only [h, ciInf_pos] rfl · rw [le_iInf₂_iff] intro K hK have : S ≤ K := by simp only [Set.mem_insert_iff, Set.mem_setOf_eq] at hK rcases hK with hKI | hKS exacts [hKI ▸ hS, hKS] rw [span_le] rintro y ⟨n, hn, x, hx, hxy⟩ exact hxy ▸ K.dpow_mem n hn x (this hx) end Generated end SubDPIdeal section Ker variable {A : Type*} [CommRing A] {I : Ideal A} (hI : DividedPowers I) {B : Type*} [CommRing B] {J : Ideal B} (hJ : DividedPowers J) /-- The kernel of a divided power morphism from `I` to `J` is a sub-dp-ideal of `I`. -/ theorem isSubDPIdeal_ker {f : A →+* B} (hf : IsDPMorphism hI hJ f) : IsSubDPIdeal hI (RingHom.ker f ⊓ I) := by rw [isSubDPIdeal_inf_iff] simp only [isDPMorphism_def] at hf intro n a b ha hb simp only [RingHom.sub_mem_ker_iff, ← hf.2 a ha, ← hf.2 b hb] exact congr_arg _ open Ideal /-- The kernel of a divided power morphism, as a `SubDPIdeal`. -/ def DPMorphism.ker (f : DPMorphism hI hJ) : SubDPIdeal hI where carrier := RingHom.ker f.toRingHom ⊓ I isSubideal := inf_le_right dpow_mem _ hn a := by simp only [mem_inf, and_imp, RingHom.mem_ker] intro ha ha' rw [← f.isDPMorphism.2 a ha', ha] exact ⟨dpow_eval_zero hJ hn, hI.dpow_mem hn ha'⟩ end Ker section Equalizer variable {A : Type*} [CommSemiring A] {I : Ideal A} (hI hI' : DividedPowers I) /-- The ideal of `A` in which the two divided power structures `hI` and `hI'` coincide. -/ -- TODO : prove that this is the largest ideal which is a sub-dp-ideal in both `hI` and `hI'`. def dpEqualizer : Ideal A where carrier := { a ∈ I | ∀ n : ℕ, hI.dpow n a = hI'.dpow n a } add_mem' {a b} ha hb := by apply And.intro (I.add_mem ha.1 hb.1) (fun n ↦ ?_) rw [hI.dpow_add ha.1 hb.1, hI'.dpow_add ha.1 hb.1] exact Finset.sum_congr rfl (fun k _ ↦ by rw [ha.2, hb.2]) zero_mem' := by apply And.intro I.zero_mem (fun n ↦ ?_) by_cases hn : n = 0 · rw [hn, hI.dpow_zero (zero_mem I), hI'.dpow_zero (zero_mem I)] · rw [hI.dpow_eval_zero hn, hI'.dpow_eval_zero hn] smul_mem' a x hx := by rw [Algebra.id.smul_eq_mul] exact ⟨I.mul_mem_left a hx.1, (fun n ↦ by rw [hI.dpow_mul hx.1, hI'.dpow_mul hx.1, hx.2])⟩ theorem mem_dpEqualizer_iff {x : A} : x ∈ dpEqualizer hI hI' ↔ x ∈ I ∧ ∀ n : ℕ, hI.dpow n x = hI'.dpow n x := by simp [dpEqualizer, Submodule.mem_mk, AddSubmonoid.mem_mk, AddSubsemigroup.mem_mk, Set.mem_setOf_eq] theorem dpEqualizer_is_dp_ideal_left : DividedPowers.IsSubDPIdeal hI (dpEqualizer hI hI') := IsSubDPIdeal.mk (fun _ hx ↦ hx.1) (fun _ hn x hx ↦ ⟨hI.dpow_mem hn hx.1, fun m ↦ by rw [hI.dpow_comp hn hx.1, hx.2, hx.2, hI'.dpow_comp hn hx.1]⟩) theorem dpEqualizer_is_dp_ideal_right : DividedPowers.IsSubDPIdeal hI' (dpEqualizer hI hI') := IsSubDPIdeal.mk (fun _ hx ↦ hx.1) (fun _ hn x hx ↦ ⟨hI'.dpow_mem hn hx.1, fun m ↦ by rw [← hx.2, hI.dpow_comp hn hx.1, hx.2, hx.2, hI'.dpow_comp hn hx.1]⟩) open Ideal theorem le_equalizer_of_isDPMorphism {B : Type*} [CommSemiring B] (f : A →+* B) {K : Ideal B} (hI_le_K : Ideal.map f I ≤ K) (hK hK' : DividedPowers K) (hIK : IsDPMorphism hI hK f) (hIK' : IsDPMorphism hI hK' f) : Ideal.map f I ≤ dpEqualizer hK hK' := by rw [Ideal.map, span_le] rintro b ⟨a, ha, rfl⟩ exact ⟨hI_le_K (mem_map_of_mem f ha), fun n ↦ by rw [hIK.2 a ha, hIK'.2 a ha]⟩ /-- If there is a divided power structure on `I⬝(A/J)` such that the quotient map is a dp-morphism, then `J ⊓ I` is a sub-dp-ideal of `I`. -/ def subDPIdeal_inf_of_quot {A : Type*} [CommRing A] {I : Ideal A} {hI : DividedPowers I} {J : Ideal A} {hJ : DividedPowers (I.map (Ideal.Quotient.mk J))} {φ : DPMorphism hI hJ} (hφ : φ.toRingHom = Ideal.Quotient.mk J) : SubDPIdeal hI where carrier := J ⊓ I isSubideal := by simp only [inf_le_right] dpow_mem := fun _ hn a ⟨haJ, haI⟩ ↦ by refine ⟨?_, hI.dpow_mem hn haI⟩ rw [SetLike.mem_coe, ← Quotient.eq_zero_iff_mem, ← hφ, ← φ.dpow_comp a haI] suffices ha0 : φ.toRingHom a = 0 by rw [ha0, hJ.dpow_eval_zero hn] rw [hφ, Quotient.eq_zero_iff_mem] exact haJ end Equalizer section Quotient /- Divided power structure on a quotient ring in two settings: * The case of a surjective `RingHom`. * The specific case for `Ideal.Quotient.mk`. -/ namespace Quotient variable {A : Type*} [CommRing A] {I : Ideal A} (hI : DividedPowers I) namespace OfSurjective variable {B : Type*} [CommRing B] (f : A →+* B) (J : Ideal B) /-- The definition of divided powers on the codomain `B` of a surjective ring homomorphism from a ring `A` with divided powers `hI`. This definition is tagged as noncomputable because it makes use of `Function.extend`, but under the hypothesis `IsSubDPIdeal hI (RingHom.ker f ⊓ I)`, `dividedPowers_unique` proves that no choices are involved. -/ noncomputable def dpow : ℕ → B → B := fun n ↦ Function.extend (fun a ↦ f a : I → B) (fun a ↦ f (hI.dpow n a) : I → B) 0 variable {f} (hf : Function.Surjective f) {J} (hIJ : J = I.map f) (hIf : hI.IsSubDPIdeal (RingHom.ker f ⊓ I)) /-- Divided powers on the the codomain `B` of a surjective ring homomorphism `f` are compatible with `f`. -/ theorem dpow_apply' (hIf : IsSubDPIdeal hI (RingHom.ker f ⊓ I)) {n : ℕ} {a : A} (ha : a ∈ I) : dpow hI f n (f a) = f (hI.dpow n a) := by classical simp only [dpow, Function.extend_def] have h : ∃ (a_1 : I), f ↑a_1 = f a := by use ⟨a, ha⟩ rw [dif_pos h, ← sub_eq_zero, ← map_sub, ← RingHom.mem_ker] apply (hI.isSubDPIdeal_inf_iff.mp hIf) (Submodule.coe_mem _) ha rw [RingHom.mem_ker, map_sub, sub_eq_zero, h.choose_spec] open Ideal /-- When `f.ker ⊓ I` is a sub-dp-ideal of `I`, this is the induced divided power structure on the ideal `I.map f` of the target. -/ noncomputable def dividedPowers : DividedPowers J where dpow := dpow hI f dpow_null n {x} hx' := by classical rw [dpow, Function.extend_def, dif_neg, Pi.zero_apply] rintro ⟨⟨a, ha⟩, rfl⟩ exact (hIJ ▸ hx') (apply_coe_mem_map f I ⟨a, ha⟩) dpow_zero {x} hx := by obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) rw [dpow_apply' hI hIf ha, hI.dpow_zero ha, map_one] dpow_one {x} hx := by obtain ⟨a, ha, hax⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) rw [← hax, dpow_apply' hI hIf ha, hI.dpow_one ha] dpow_mem {n x} hn hx := by rw [hIJ] at hx ⊢ obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp hx rw [dpow_apply' hI hIf ha] exact mem_map_of_mem _ (hI.dpow_mem hn ha) dpow_add hx hy := by obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) obtain ⟨b, hb, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hy) rw [← map_add, dpow_apply' hI hIf (I.add_mem ha hb), hI.dpow_add ha hb, map_sum, Finset.sum_congr rfl] exact fun k _ ↦ by rw [dpow_apply' hI hIf ha, dpow_apply' hI hIf hb, ← _root_.map_mul] dpow_mul {n x y} hy := by obtain ⟨a, rfl⟩ := hf x obtain ⟨b, hb, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hy) rw [dpow_apply' hI hIf hb, ← _root_.map_mul, ← map_pow, dpow_apply' hI hIf (mul_mem_left I a hb), hI.dpow_mul hb, _root_.map_mul] mul_dpow hx := by obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) simp only [dpow_apply' hI hIf ha] rw [← _root_.map_mul, hI.mul_dpow ha, _root_.map_mul, map_natCast] dpow_comp hn hx := by obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) simp only [dpow_apply' hI hIf, ha, hI.dpow_mem hn ha] rw [hI.dpow_comp hn ha, _root_.map_mul, map_natCast] theorem dpow_def {n : ℕ} {x : B} : (dividedPowers hI hf hIJ hIf).dpow n x = dpow hI f n x := rfl theorem dpow_apply {n : ℕ} {a : A} (ha : a ∈ I) : (dividedPowers hI hf hIJ hIf).dpow n (f a) = f (hI.dpow n a) := by rw [dpow_def, dpow_apply' hI hIf ha] theorem isDPMorphism : IsDPMorphism hI (dividedPowers hI hf hIJ hIf) f := ⟨le_of_eq hIJ.symm, fun a ha ↦ by rw [dpow_apply hI hf hIJ hIf ha]⟩ theorem dividedPowers_unique (hquot : DividedPowers J) (hm : DividedPowers.IsDPMorphism hI hquot f) : hquot = dividedPowers hI hf hIJ hIf := ext _ _ fun n x hx ↦ by obtain ⟨a, ha, rfl⟩ := (mem_map_iff_of_surjective f hf).mp (hIJ ▸ hx) rw [hm.2 a ha, dpow_apply hI hf hIJ hIf ha] end OfSurjective variable {J : Ideal A} (hIJ : IsSubDPIdeal hI (J ⊓ I)) /-- The definition of divided powers on `A ⧸ J`. Tagged as noncomputable because it makes use of `Function.extend`, but under `IsSubDPIdeal hI (J ⊓ I)`, `dividedPowers_unique` proves that no choices are involved. -/ noncomputable def dpow (J : Ideal A) : ℕ → A ⧸ J → A ⧸ J := DividedPowers.Quotient.OfSurjective.dpow hI (Ideal.Quotient.mk J) private theorem isSubDPIdeal_aux (hIJ : IsSubDPIdeal hI (J ⊓ I)) : IsSubDPIdeal hI (RingHom.ker (Ideal.Quotient.mk J) ⊓ I) := by simpa [Ideal.mk_ker] using hIJ /-- When `I ⊓ J` is a sub-dp-ideal of `I`, this is the divided power structure on the ideal `I(A⧸J)` of the quotient. -/ noncomputable def dividedPowers : DividedPowers (I.map (Ideal.Quotient.mk J)) := DividedPowers.Quotient.OfSurjective.dividedPowers hI Ideal.Quotient.mk_surjective (refl _) (isSubDPIdeal_aux hI hIJ) /-- Divided powers on the quotient are compatible with quotient map -/ theorem dpow_apply {n : ℕ} {a : A} (ha : a ∈ I) : (dividedPowers hI hIJ).dpow n (Ideal.Quotient.mk J a) = (Ideal.Quotient.mk J) (hI.dpow n a) := DividedPowers.Quotient.OfSurjective.dpow_apply hI Ideal.Quotient.mk_surjective (refl _) (isSubDPIdeal_aux hI hIJ) ha theorem isDPMorphism : hI.IsDPMorphism (dividedPowers hI hIJ) (Ideal.Quotient.mk J) := DividedPowers.Quotient.OfSurjective.isDPMorphism hI Ideal.Quotient.mk_surjective (refl _) (isSubDPIdeal_aux hI hIJ) theorem dividedPowers_unique (hquot : DividedPowers (I.map (Ideal.Quotient.mk J))) (hm : DividedPowers.IsDPMorphism hI hquot (Ideal.Quotient.mk J)) : hquot = dividedPowers hI hIJ := DividedPowers.Quotient.OfSurjective.dividedPowers_unique hI Ideal.Quotient.mk_surjective (refl _) (isSubDPIdeal_aux hI hIJ) hquot hm end Quotient end Quotient end DividedPowers
Pi.lean
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.Calculus.FDeriv.Pi import Mathlib.Analysis.Calculus.Deriv.Basic /-! # One-dimensional derivatives on pi-types. -/ variable {𝕜 ι : Type*} [DecidableEq ι] [Fintype ι] [NontriviallyNormedField 𝕜] theorem hasDerivAt_update (x : ι → 𝕜) (i : ι) (y : 𝕜) : HasDerivAt (Function.update x i) (Pi.single i (1 : 𝕜)) y := by convert (hasFDerivAt_update x y).hasDerivAt ext z j rw [Pi.single, Function.update_apply] split_ifs with h · simp [h] · simp [Pi.single_eq_of_ne h] theorem hasDerivAt_single (i : ι) (y : 𝕜) : HasDerivAt (Pi.single (M := fun _ ↦ 𝕜) i) (Pi.single i (1 : 𝕜)) y := hasDerivAt_update 0 i y theorem deriv_update (x : ι → 𝕜) (i : ι) (y : 𝕜) : deriv (Function.update x i) y = Pi.single i (1 : 𝕜) := (hasDerivAt_update x i y).deriv theorem deriv_single (i : ι) (y : 𝕜) : deriv (Pi.single (M := fun _ ↦ 𝕜) i) y = Pi.single i (1 : 𝕜) := deriv_update 0 i y
CompleteMultipartite.lean
/- Copyright (c) 2024 John Talbot and Lian Bremner Tattersall. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: John Talbot, Lian Bremner Tattersall -/ import Mathlib.Combinatorics.SimpleGraph.Coloring import Mathlib.Combinatorics.SimpleGraph.Hasse /-! # Complete Multipartite Graphs A graph is complete multipartite iff non-adjacency is transitive. ## Main declarations * `SimpleGraph.IsCompleteMultipartite`: predicate for a graph to be complete-multi-partite. * `SimpleGraph.IsCompleteMultipartite.setoid`: the `Setoid` given by non-adjacency. * `SimpleGraph.IsCompleteMultipartite.iso`: the graph isomorphism from a graph that `IsCompleteMultipartite` to the corresponding `completeMultipartiteGraph`. * `SimpleGraph.IsPathGraph3Compl`: predicate for three vertices to be a witness to non-complete-multi-partite-ness of a graph G. (The name refers to the fact that the three vertices form the complement of `pathGraph 3`.) * See also: `Mathlib/Combinatorics/SimpleGraph/FiveWheelLike.lean` `colorable_iff_isCompleteMultipartite_of_maximal_cliqueFree` a maximally `r + 1`- cliquefree graph is `r`-colorable iff it is complete-multipartite. -/ universe u namespace SimpleGraph variable {α : Type u} /-- `G` is `IsCompleteMultipartite` iff non-adjacency is transitive -/ def IsCompleteMultipartite (G : SimpleGraph α) : Prop := Transitive (¬ G.Adj · ·) variable {G : SimpleGraph α} /-- The setoid given by non-adjacency -/ def IsCompleteMultipartite.setoid (h : G.IsCompleteMultipartite) : Setoid α := ⟨(¬ G.Adj · ·), ⟨G.loopless, fun h' ↦ by rwa [adj_comm] at h', fun h1 h2 ↦ h h1 h2⟩⟩ lemma completeMultipartiteGraph.isCompleteMultipartite {ι : Type*} (V : ι → Type*) : (completeMultipartiteGraph V).IsCompleteMultipartite := by intro aesop /-- The graph isomorphism from a graph `G` that `IsCompleteMultipartite` to the corresponding `completeMultipartiteGraph` (see also `isCompleteMultipartite_iff`) -/ def IsCompleteMultipartite.iso (h : G.IsCompleteMultipartite) : G ≃g completeMultipartiteGraph (fun (c : Quotient h.setoid) ↦ {x // h.setoid.r c.out x}) where toFun := fun x ↦ ⟨_, ⟨_, Quotient.mk_out x⟩⟩ invFun := fun ⟨_, x⟩ ↦ x.1 right_inv := fun ⟨_, x⟩ ↦ Sigma.subtype_ext (Quotient.mk_eq_iff_out.2 <| h.setoid.symm x.2) rfl map_rel_iff' := by simp_rw [Equiv.coe_fn_mk, comap_adj, top_adj, ne_eq, Quotient.eq] intros change ¬¬ G.Adj _ _ ↔ _ rw [not_not] lemma isCompleteMultipartite_iff : G.IsCompleteMultipartite ↔ ∃ (ι : Type u) (V : ι → Type u) (_ : ∀ i, Nonempty (V i)), Nonempty (G ≃g completeMultipartiteGraph V) := by constructor <;> intro h · exact ⟨_, _, fun _ ↦ ⟨_, h.setoid.refl _⟩, ⟨h.iso⟩⟩ · obtain ⟨_, _, _, ⟨e⟩⟩ := h intro _ _ _ h1 h2 rw [← e.map_rel_iff] at * exact completeMultipartiteGraph.isCompleteMultipartite _ h1 h2 lemma IsCompleteMultipartite.colorable_of_cliqueFree {n : ℕ} (h : G.IsCompleteMultipartite) (hc : G.CliqueFree n) : G.Colorable (n - 1) := (completeMultipartiteGraph.colorable_of_cliqueFree _ (fun _ ↦ ⟨_, h.setoid.refl _⟩) <| hc.comap h.iso.symm.toEmbedding).of_embedding h.iso.toEmbedding variable (G) in /-- The vertices `v, w₁, w₂` form an `IsPathGraph3Compl` in `G` iff `w₁w₂` is the only edge present between these three vertices. It is a witness to the non-complete-multipartite-ness of `G` (see `not_isCompleteMultipartite_iff_exists_isPathGraph3Compl`). This structure is an explicit way of saying that the induced graph on `{v, w₁, w₂}` is the complement of `P3`. -/ structure IsPathGraph3Compl (v w₁ w₂ : α) : Prop where adj : G.Adj w₁ w₂ not_adj_fst : ¬ G.Adj v w₁ not_adj_snd : ¬ G.Adj v w₂ namespace IsPathGraph3Compl variable {v w₁ w₂ : α} lemma ne_fst (h2 : G.IsPathGraph3Compl v w₁ w₂) : v ≠ w₁ := fun h ↦ h2.not_adj_snd (h.symm ▸ h2.adj) lemma ne_snd (h2 : G.IsPathGraph3Compl v w₁ w₂) : v ≠ w₂ := fun h ↦ h2.not_adj_fst (h ▸ h2.adj.symm) lemma fst_ne_snd (h2 : G.IsPathGraph3Compl v w₁ w₂) : w₁ ≠ w₂ := h2.adj.ne @[symm] lemma symm (h : G.IsPathGraph3Compl v w₁ w₂) : G.IsPathGraph3Compl v w₂ w₁ := by obtain ⟨h1, h2, h3⟩ := h exact ⟨h1.symm, h3, h2⟩ end IsPathGraph3Compl lemma exists_isPathGraph3Compl_of_not_isCompleteMultipartite (h : ¬ IsCompleteMultipartite G) : ∃ v w₁ w₂, G.IsPathGraph3Compl v w₁ w₂ := by rw [IsCompleteMultipartite, Transitive] at h push_neg at h obtain ⟨_, _, _, h1, h2, h3⟩ := h rw [adj_comm] at h1 exact ⟨_, _, _, h3, h1, h2⟩ lemma not_isCompleteMultipartite_iff_exists_isPathGraph3Compl : ¬ IsCompleteMultipartite G ↔ ∃ v w₁ w₂, G.IsPathGraph3Compl v w₁ w₂ := ⟨fun h ↦ G.exists_isPathGraph3Compl_of_not_isCompleteMultipartite h, fun ⟨_, _, _, h1, h2, h3⟩ ↦ fun h ↦ h (by rwa [adj_comm] at h2) h3 h1⟩ /-- Any `IsPathGraph3Compl` in `G` gives rise to a graph embedding of the complement of the path graph -/ def IsPathGraph3Compl.pathGraph3ComplEmbedding {v w₁ w₂ : α} (h : G.IsPathGraph3Compl v w₁ w₂) : (pathGraph 3)ᶜ ↪g G where toFun := fun x ↦ match x with | 0 => w₁ | 1 => v | 2 => w₂ inj' := by intro _ _ _ have := h.ne_fst have := h.ne_snd have := h.adj.ne aesop map_rel_iff' := by intro _ _ simp_rw [Function.Embedding.coeFn_mk, compl_adj, ne_eq, pathGraph_adj, not_or] have := h.adj have := h.adj.symm have h1 := h.not_adj_fst have h2 := h.not_adj_snd have ⟨_, _⟩ : ¬ G.Adj w₁ v ∧ ¬ G.Adj w₂ v := by rw [adj_comm] at h1 h2; exact ⟨h1, h2⟩ aesop /-- Embedding of `(pathGraph 3)ᶜ` into `G` that is not complete-multipartite. -/ noncomputable def pathGraph3ComplEmbeddingOf (h : ¬ G.IsCompleteMultipartite) : (pathGraph 3)ᶜ ↪g G := IsPathGraph3Compl.pathGraph3ComplEmbedding (exists_isPathGraph3Compl_of_not_isCompleteMultipartite h).choose_spec.choose_spec.choose_spec lemma not_isCompleteMultipartite_of_pathGraph3ComplEmbedding (e : (pathGraph 3)ᶜ ↪g G) : ¬ IsCompleteMultipartite G := by intro h have h0 : ¬ G.Adj (e 0) (e 1) := by simp [pathGraph_adj] have h1 : ¬ G.Adj (e 1) (e 2) := by simp [pathGraph_adj] have h2 : G.Adj (e 0) (e 2) := by simp [pathGraph_adj] exact h h0 h1 h2 theorem IsCompleteMultipartite.comap {β : Type*} {H : SimpleGraph β} (f : H ↪g G) : G.IsCompleteMultipartite → H.IsCompleteMultipartite := by intro h; contrapose h exact not_isCompleteMultipartite_of_pathGraph3ComplEmbedding <| f.comp (pathGraph3ComplEmbeddingOf h) end SimpleGraph
character.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 choice ssrnat seq. From mathcomp Require Import path div fintype tuple finfun bigop prime order. From mathcomp Require Import ssralg poly finset gproduct fingroup morphism. From mathcomp Require Import perm automorphism quotient finalg action zmodp. From mathcomp Require Import commutator cyclic center pgroup nilpotent sylow. From mathcomp Require Import abelian matrix mxalgebra mxpoly mxrepresentation. From mathcomp Require Import vector ssrnum algC classfun archimedean. (******************************************************************************) (* This file contains the basic notions of character theory, based on Isaacs. *) (* irr G == tuple of the elements of 'CF(G) that are irreducible *) (* characters of G. *) (* Nirr G == number of irreducible characters of G. *) (* Iirr G == index type for the irreducible characters of G. *) (* := 'I_(Nirr G). *) (* 'chi_i == the i-th element of irr G, for i : Iirr G. *) (* 'chi[G]_i Note that 'chi_0 = 1, the principal character of G. *) (* 'Chi_i == an irreducible representation that affords 'chi_i. *) (* socle_of_Iirr i == the Wedderburn component of the regular representation *) (* of G, corresponding to 'Chi_i. *) (* Iirr_of_socle == the inverse of socle_of_Iirr (which is one-to-one). *) (* phi.[A]%CF == the image of A \in group_ring G under phi : 'CF(G). *) (* cfRepr rG == the character afforded by the representation rG of G. *) (* cfReg G == the regular character, afforded by the regular *) (* representation of G. *) (* detRepr rG == the linear character afforded by the determinant of rG. *) (* cfDet phi == the linear character afforded by the determinant of a *) (* representation affording phi. *) (* 'o(phi) == the "determinential order" of phi (the multiplicative *) (* order of cfDet phi. *) (* phi \is a character <=> phi : 'CF(G) is a character of G or 0. *) (* i \in irr_constt phi <=> 'chi_i is an irreducible constituent of phi: phi *) (* has a non-zero coordinate on 'chi_i over the basis irr G. *) (* xi \is a linear_char xi <=> xi : 'CF(G) is a linear character of G. *) (* 'Z(chi)%CF == the center of chi when chi is a character of G, i.e., *) (* rcenter rG where rG is a representation that affords phi. *) (* If phi is not a character then 'Z(chi)%CF = cfker phi. *) (* aut_Iirr u i == the index of cfAut u 'chi_i in irr G. *) (* conjC_Iirr i == the index of 'chi_i^*%CF in irr G. *) (* morph_Iirr i == the index of cfMorph 'chi[f @* G]_i in irr G. *) (* isom_Iirr isoG i == the index of cfIsom isoG 'chi[G]_i in irr R. *) (* mod_Iirr i == the index of ('chi[G / H]_i %% H)%CF in irr G. *) (* quo_Iirr i == the index of ('chi[G]_i / H)%CF in irr (G / H). *) (* Ind_Iirr G i == the index of 'Ind[G, H] 'chi_i, provided it is an *) (* irreducible character (such as when if H is the inertia *) (* group of 'chi_i). *) (* Res_Iirr H i == the index of 'Res[H, G] 'chi_i, provided it is an *) (* irreducible character (such as when 'chi_i is linear). *) (* sdprod_Iirr defG i == the index of cfSdprod defG 'chi_i in irr G, given *) (* defG : K ><| H = G. *) (* And, for KxK : K \x H = G. *) (* dprodl_Iirr KxH i == the index of cfDprodl KxH 'chi[K]_i in irr G. *) (* dprodr_Iirr KxH j == the index of cfDprodr KxH 'chi[H]_j in irr G. *) (* dprod_Iirr KxH (i, j) == the index of cfDprod KxH 'chi[K]_i 'chi[H]_j. *) (* inv_dprod_Iirr KxH == the inverse of dprod_Iirr KxH. *) (* The following are used to define and exploit the character table: *) (* character_table G == the character table of G, whose i-th row lists the *) (* values taken by 'chi_i on the conjugacy classes *) (* of G; this is a square Nirr G x NirrG matrix. *) (* irr_class i == the conjugacy class of G with index i : Iirr G. *) (* class_Iirr xG == the index of xG \in classes G, in Iirr G. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Section AlgC. Variable (gT : finGroupType). Lemma groupC : group_closure_field algC gT. Proof. exact: group_closure_closed_field. Qed. End AlgC. Section Tensor. Variable (F : fieldType). Fixpoint trow (n1 : nat) : forall (A : 'rV[F]_n1) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m2,n1 * n2) := if n1 is n'1.+1 then fun (A : 'M[F]_(1,(1 + n'1))) m2 n2 (B : 'M[F]_(m2,n2)) => (row_mx (lsubmx A 0 0 *: B) (trow (rsubmx A) B)) else (fun _ _ _ _ => 0). Lemma trow0 n1 m2 n2 B : @trow n1 0 m2 n2 B = 0. Proof. elim: n1=> //= n1 IH. rewrite !mxE scale0r linear0. rewrite IH //; apply/matrixP=> i j; rewrite !mxE. by case: split=> *; rewrite mxE. Qed. Definition trowb n1 m2 n2 B A := @trow n1 A m2 n2 B. Lemma trowbE n1 m2 n2 A B : trowb B A = @trow n1 A m2 n2 B. Proof. by []. Qed. Lemma trowb_is_linear n1 m2 n2 (B : 'M_(m2,n2)) : linear (@trowb n1 m2 n2 B). Proof. elim: n1=> [|n1 IH] //= k A1 A2 /=; first by rewrite scaler0 add0r. rewrite !linearD /= !linearZ /= IH 2!mxE. by rewrite scalerDl -scalerA -add_row_mx -scale_row_mx. Qed. HB.instance Definition _ n1 m2 n2 B := GRing.isSemilinear.Build _ _ _ _ (trowb B) (GRing.semilinear_linear (@trowb_is_linear n1 m2 n2 B)). Lemma trow_is_linear n1 m2 n2 (A : 'rV_n1) : linear (@trow n1 A m2 n2). Proof. elim: n1 A => [|n1 IH] //= A k A1 A2 /=; first by rewrite scaler0 add0r. rewrite linearP /=; apply/matrixP=> i j; rewrite !mxE. by case: split=> a; rewrite ?IH !mxE. Qed. HB.instance Definition _ n1 m2 n2 A := GRing.isSemilinear.Build _ _ _ _ (@trow n1 A m2 n2) (GRing.semilinear_linear (@trow_is_linear n1 m2 n2 A)). Fixpoint tprod (m1 : nat) : forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m1 * m2,n1 * n2) := if m1 is m'1.+1 return forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m1 * m2,n1 * n2) then fun n1 (A : 'M[F]_(1 + m'1,n1)) m2 n2 B => (col_mx (trow (usubmx A) B) (tprod (dsubmx A) B)) else (fun _ _ _ _ _ => 0). Lemma dsumx_mul m1 m2 n p A B : dsubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = dsubmx (A : 'M_(m1 + m2, p)) *m B. Proof. apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _. by rewrite !mxE. Qed. Lemma usumx_mul m1 m2 n p A B : usubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = usubmx (A : 'M_(m1 + m2, p)) *m B. Proof. by apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _ /[!mxE]. Qed. Let trow_mul (m1 m2 n2 p2 : nat) (A : 'rV_m1) (B1: 'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) : trow A (B1 *m B2) = B1 *m trow A B2. Proof. elim: m1 A => [|m1 IH] A /=; first by rewrite mulmx0. by rewrite IH mul_mx_row -scalemxAr. Qed. Lemma tprodE m1 n1 p1 (A1 :'M[F]_(m1,n1)) (A2 :'M[F]_(n1,p1)) m2 n2 p2 (B1 :'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) : tprod (A1 *m A2) (B1 *m B2) = (tprod A1 B1) *m (tprod A2 B2). Proof. elim: m1 n1 p1 A1 A2 m2 n2 p2 B1 B2 => /= [|m1 IH]. by move=> *; rewrite mul0mx. move=> n1 p1 A1 A2 m2 n2 p2 B1 B2. rewrite mul_col_mx -IH. congr col_mx; last by rewrite dsumx_mul. rewrite usumx_mul. elim: n1 {A1}(usubmx (A1: 'M_(1 + m1, n1))) p1 A2=> //= [u p1 A2|]. by rewrite [A2](flatmx0) !mulmx0 -trowbE linear0. move=> n1 IH1 A p1 A2 //=. set Al := lsubmx _; set Ar := rsubmx _. set Su := usubmx _; set Sd := dsubmx _. rewrite mul_row_col -IH1. rewrite -{1}(@hsubmxK F 1 1 n1 A). rewrite -{1}(@vsubmxK F 1 n1 p1 A2). rewrite (@mul_row_col F 1 1 n1 p1). rewrite -trowbE linearD /= trowbE -/Al. congr (_ + _). rewrite {1}[Al]mx11_scalar mul_scalar_mx. by rewrite -trowbE linearZ /= trowbE -/Su trow_mul scalemxAl. Qed. Let tprod_tr m1 n1 (A :'M[F]_(m1, 1 + n1)) m2 n2 (B :'M[F]_(m2, n2)) : tprod A B = row_mx (trow (lsubmx A)^T B^T)^T (tprod (rsubmx A) B). Proof. elim: m1 n1 A m2 n2 B=> [|m1 IH] n1 A m2 n2 B //=. by rewrite trmx0 row_mx0. rewrite !IH. pose A1 := A : 'M_(1 + m1, 1 + n1). have F1: dsubmx (rsubmx A1) = rsubmx (dsubmx A1). by apply/matrixP=> i j; rewrite !mxE. have F2: rsubmx (usubmx A1) = usubmx (rsubmx A1). by apply/matrixP=> i j; rewrite !mxE. have F3: lsubmx (dsubmx A1) = dsubmx (lsubmx A1). by apply/matrixP=> i j; rewrite !mxE. rewrite tr_row_mx -block_mxEv -block_mxEh !(F1,F2,F3); congr block_mx. - by rewrite !mxE linearZ /= trmxK. by rewrite -trmx_dsub. Qed. Lemma tprod1 m n : tprod (1%:M : 'M[F]_(m,m)) (1%:M : 'M[F]_(n,n)) = 1%:M. Proof. elim: m n => [|m IH] n //=; first by rewrite [1%:M]flatmx0. rewrite tprod_tr. set u := rsubmx _; have->: u = 0. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j=> /= j Hj; case. set v := lsubmx (dsubmx _); have->: v = 0. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j; case. set w := rsubmx _; have->: w = 1%:M. apply/matrixP=> i j; rewrite !mxE. by case: i; case: j; case. rewrite IH -!trowbE !linear0. rewrite -block_mxEv. set z := (lsubmx _) 0 0; have->: z = 1. by rewrite /z !mxE eqxx. by rewrite scale1r scalar_mx_block. Qed. Lemma mxtrace_prod m n (A :'M[F]_(m)) (B :'M[F]_(n)) : \tr (tprod A B) = \tr A * \tr B. Proof. elim: m n A B => [|m IH] n A B //=. by rewrite [A]flatmx0 mxtrace0 mul0r. rewrite tprod_tr -block_mxEv mxtrace_block IH. rewrite linearZ/= -mulrDl -trace_mx11; congr (_ * _). pose A1 := A : 'M_(1 + m). rewrite -[A in RHS](@submxK _ 1 m 1 m A1). by rewrite (@mxtrace_block _ _ _ (ulsubmx A1)). Qed. End Tensor. (* Representation sigma type and standard representations. *) Section StandardRepresentation. Variables (R : fieldType) (gT : finGroupType) (G : {group gT}). Local Notation reprG := (mx_representation R G). Record representation := Representation {rdegree; mx_repr_of_repr :> reprG rdegree}. Lemma mx_repr0 : mx_repr G (fun _ : gT => 1%:M : 'M[R]_0). Proof. by split=> // g h Hg Hx; rewrite mulmx1. Qed. Definition grepr0 := Representation (MxRepresentation mx_repr0). Lemma add_mx_repr (rG1 rG2 : representation) : mx_repr G (fun g => block_mx (rG1 g) 0 0 (rG2 g)). Proof. split=> [|x y Hx Hy]; first by rewrite !repr_mx1 -scalar_mx_block. by rewrite mulmx_block !(mulmx0, mul0mx, addr0, add0r, repr_mxM). Qed. Definition dadd_grepr rG1 rG2 := Representation (MxRepresentation (add_mx_repr rG1 rG2)). Section DsumRepr. Variables (n : nat) (rG : reprG n). Lemma mx_rsim_dadd (U V W : 'M_n) (rU rV : representation) (modU : mxmodule rG U) (modV : mxmodule rG V) (modW : mxmodule rG W) : (U + V :=: W)%MS -> mxdirect (U + V) -> mx_rsim (submod_repr modU) rU -> mx_rsim (submod_repr modV) rV -> mx_rsim (submod_repr modW) (dadd_grepr rU rV). Proof. case: rU; case: rV=> nV rV nU rU defW dxUV /=. have tiUV := mxdirect_addsP dxUV. move=> [fU def_nU]; rewrite -{nU}def_nU in rU fU * => inv_fU hom_fU. move=> [fV def_nV]; rewrite -{nV}def_nV in rV fV * => inv_fV hom_fV. pose pU := in_submod U (proj_mx U V) *m fU. pose pV := in_submod V (proj_mx V U) *m fV. exists (val_submod 1%:M *m row_mx pU pV) => [||g Gg]. - by rewrite -defW (mxdirectP dxUV). - apply/row_freeP. pose pU' := invmx fU *m val_submod 1%:M. pose pV' := invmx fV *m val_submod 1%:M. exists (in_submod _ (col_mx pU' pV')). rewrite in_submodE mulmxA -in_submodE -mulmxA mul_row_col mulmxDr. rewrite -[pU *m _]mulmxA -[pV *m _]mulmxA !mulKVmx -?row_free_unit //. rewrite addrC (in_submodE V) 2![val_submod 1%:M *m _]mulmxA -in_submodE. rewrite addrC (in_submodE U) 2![val_submod 1%:M *m _ in X in X + _]mulmxA. rewrite -in_submodE -!val_submodE !in_submodK ?proj_mx_sub //. by rewrite add_proj_mx ?val_submodK // val_submod1 defW. rewrite mulmxA -val_submodE -[submod_repr _ g]mul1mx val_submodJ //. rewrite -(mulmxA _ (rG g)) mul_mx_row -[in RHS]mulmxA mul_row_block. rewrite !mulmx0 addr0 add0r !mul_mx_row. set W' := val_submod 1%:M; congr (row_mx _ _). rewrite 3!mulmxA in_submodE mulmxA. have hom_pU: (W' <= dom_hom_mx rG (proj_mx U V))%MS. by rewrite val_submod1 -defW proj_mx_hom. rewrite (hom_mxP hom_pU) // -in_submodE (in_submodJ modU) ?proj_mx_sub //. rewrite -(mulmxA _ _ fU) hom_fU // in_submodE -2!(mulmxA W') -in_submodE. by rewrite -mulmxA (mulmxA _ fU). rewrite 3!mulmxA in_submodE mulmxA. have hom_pV: (W' <= dom_hom_mx rG (proj_mx V U))%MS. by rewrite val_submod1 -defW addsmxC proj_mx_hom // capmxC. rewrite (hom_mxP hom_pV) // -in_submodE (in_submodJ modV) ?proj_mx_sub //. rewrite -(mulmxA _ _ fV) hom_fV // in_submodE -2!(mulmxA W') -in_submodE. by rewrite -mulmxA (mulmxA _ fV). Qed. Lemma mx_rsim_dsum (I : finType) (P : pred I) U rU (W : 'M_n) (modU : forall i, mxmodule rG (U i)) (modW : mxmodule rG W) : let S := (\sum_(i | P i) U i)%MS in (S :=: W)%MS -> mxdirect S -> (forall i, mx_rsim (submod_repr (modU i)) (rU i : representation)) -> mx_rsim (submod_repr modW) (\big[dadd_grepr/grepr0]_(i | P i) rU i). Proof. move=> /= defW dxW rsimU. rewrite mxdirectE /= -!(big_filter _ P) in dxW defW *. elim: {P}(filter P _) => [|i e IHe] in W modW dxW defW *. rewrite !big_nil /= in defW *. by exists 0 => [||? _]; rewrite ?mul0mx ?mulmx0 // /row_free -defW !mxrank0. rewrite !big_cons /= in dxW defW *. rewrite 2!(big_nth i) !big_mkord /= in IHe dxW defW. set Wi := (\sum_i _)%MS in defW dxW IHe. rewrite -mxdirectE mxdirect_addsE !mxdirectE eqxx /= -/Wi in dxW. have modWi: mxmodule rG Wi by apply: sumsmx_module. case/andP: dxW; move/(IHe Wi modWi) {IHe}; move/(_ (eqmx_refl _))=> rsimWi. by move/eqP; move/mxdirect_addsP=> dxUiWi; apply: mx_rsim_dadd (rsimU i) rsimWi. Qed. Definition muln_grepr rW k := \big[dadd_grepr/grepr0]_(i < k) rW. Lemma mx_rsim_socle (sG : socleType rG) (W : sG) (rW : representation) : let modW : mxmodule rG W := component_mx_module rG (socle_base W) in mx_rsim (socle_repr W) rW -> mx_rsim (submod_repr modW) (muln_grepr rW (socle_mult W)). Proof. set M := socle_base W => modW rsimM. have simM: mxsimple rG M := socle_simple W. have rankM_gt0: (\rank M > 0)%N by rewrite lt0n mxrank_eq0; case: simM. have [I /= U_I simU]: mxsemisimple rG W by apply: component_mx_semisimple. pose U (i : 'I_#|I|) := U_I (enum_val i). have reindexI := reindex _ (onW_bij I (enum_val_bij I)). rewrite mxdirectE /= !reindexI -mxdirectE /= => defW dxW. have isoU: forall i, mx_iso rG M (U i). move=> i; have sUiW: (U i <= W)%MS by rewrite -defW (sumsmx_sup i). exact: component_mx_iso (simU _) sUiW. have ->: socle_mult W = #|I|. rewrite -(mulnK #|I| rankM_gt0); congr (_ %/ _)%N. rewrite -defW (mxdirectP dxW) /= -sum_nat_const reindexI /=. by apply: eq_bigr => i _; rewrite -(mxrank_iso (isoU i)). have modU: mxmodule rG (U _) := mxsimple_module (simU _). suff: mx_rsim (submod_repr (modU _)) rW by apply: mx_rsim_dsum defW dxW. by move=> i; apply: mx_rsim_trans (mx_rsim_sym _) rsimM; apply/mx_rsim_iso. Qed. End DsumRepr. Section ProdRepr. Variables (n1 n2 : nat) (rG1 : reprG n1) (rG2 : reprG n2). Lemma prod_mx_repr : mx_repr G (fun g => tprod (rG1 g) (rG2 g)). Proof. split=>[|i j InG JnG]; first by rewrite !repr_mx1 tprod1. by rewrite !repr_mxM // tprodE. Qed. Definition prod_repr := MxRepresentation prod_mx_repr. End ProdRepr. Lemma prod_repr_lin n2 (rG1 : reprG 1) (rG2 : reprG n2) : {in G, forall x, let cast_n2 := esym (mul1n n2) in prod_repr rG1 rG2 x = castmx (cast_n2, cast_n2) (rG1 x 0 0 *: rG2 x)}. Proof. move=> x Gx /=; set cast_n2 := esym _; rewrite /prod_repr /= !mxE !lshift0. apply/matrixP=> i j; rewrite castmxE /=. do 2![rewrite mxE; case: splitP => [? ? | []//]]. by congr ((_ *: rG2 x) _ _); apply: val_inj. Qed. End StandardRepresentation. Arguments grepr0 {R gT G}. Prenex Implicits dadd_grepr. Section Char. Variables (gT : finGroupType) (G : {group gT}). Fact cfRepr_subproof n (rG : mx_representation algC G n) : is_class_fun <<G>> [ffun x => \tr (rG x) *+ (x \in G)]. Proof. rewrite genGid; apply: intro_class_fun => [x y Gx Gy | _ /negbTE-> //]. by rewrite groupJr // !repr_mxM ?groupM ?groupV // mxtrace_mulC repr_mxK. Qed. Definition cfRepr n rG := Cfun 0 (@cfRepr_subproof n rG). Lemma cfRepr1 n rG : @cfRepr n rG 1%g = n%:R. Proof. by rewrite cfunE group1 repr_mx1 mxtrace1. Qed. Lemma cfRepr_sim n1 n2 rG1 rG2 : mx_rsim rG1 rG2 -> @cfRepr n1 rG1 = @cfRepr n2 rG2. Proof. case/mx_rsim_def=> f12 [f21] fK def_rG1; apply/cfun_inP=> x Gx. by rewrite !cfunE def_rG1 // mxtrace_mulC mulmxA fK mul1mx. Qed. Lemma cfRepr0 : cfRepr grepr0 = 0. Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace1. Qed. Lemma cfRepr_dadd rG1 rG2 : cfRepr (dadd_grepr rG1 rG2) = cfRepr rG1 + cfRepr rG2. Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace_block. Qed. Lemma cfRepr_dsum I r (P : pred I) rG : cfRepr (\big[dadd_grepr/grepr0]_(i <- r | P i) rG i) = \sum_(i <- r | P i) cfRepr (rG i). Proof. exact: (big_morph _ cfRepr_dadd cfRepr0). Qed. Lemma cfRepr_muln rG k : cfRepr (muln_grepr rG k) = cfRepr rG *+ k. Proof. by rewrite cfRepr_dsum /= sumr_const card_ord. Qed. Section StandardRepr. Variables (n : nat) (rG : mx_representation algC G n). Let sG := DecSocleType rG. Let iG : irrType algC G := DecSocleType _. Definition standard_irr (W : sG) := irr_comp iG (socle_repr W). Definition standard_socle i := pick [pred W | standard_irr W == i]. Local Notation soc := standard_socle. Definition standard_irr_coef i := oapp (fun W => socle_mult W) 0 (soc i). Definition standard_grepr := \big[dadd_grepr/grepr0]_i muln_grepr (Representation (socle_repr i)) (standard_irr_coef i). Lemma mx_rsim_standard : mx_rsim rG standard_grepr. Proof. pose W i := oapp val 0 (soc i); pose S := (\sum_i W i)%MS. have C'G: [pchar algC]^'.-group G := algC'G_pchar G. have [defS dxS]: (S :=: 1%:M)%MS /\ mxdirect S. rewrite /S mxdirectE /= !(bigID soc xpredT) /=. rewrite addsmxC big1 => [|i]; last by rewrite /W; case (soc i). rewrite adds0mx_id addnC (@big1 nat) ?add0n => [|i]; last first. by rewrite /W; case: (soc i); rewrite ?mxrank0. have <-: Socle sG = 1%:M := reducible_Socle1 sG (mx_Maschke_pchar rG C'G). have [W0 _ | noW] := pickP sG; last first. suff no_i: (soc : pred iG) =1 xpred0 by rewrite /Socle !big_pred0 ?mxrank0. by move=> i; rewrite /soc; case: pickP => // W0; have:= noW W0. have irrK Wi: soc (standard_irr Wi) = Some Wi. rewrite /soc; case: pickP => [W' | /(_ Wi)] /= /eqP // eqWi. apply/eqP/socle_rsimP. apply: mx_rsim_trans (rsim_irr_comp_pchar iG C'G (socle_irr _)) (mx_rsim_sym _). by rewrite [irr_comp _ _]eqWi; apply: rsim_irr_comp_pchar (socle_irr _). have bij_irr: {on [pred i | soc i], bijective standard_irr}. exists (odflt W0 \o soc) => [Wi _ | i]; first by rewrite /= irrK. by rewrite inE /soc /=; case: pickP => //= Wi; move/eqP. rewrite !(reindex standard_irr) {bij_irr}//=. have all_soc Wi: soc (standard_irr Wi) by rewrite irrK. rewrite (eq_bigr val) => [|Wi _]; last by rewrite /W irrK. rewrite !(eq_bigl _ _ all_soc); split=> //. rewrite (eq_bigr (mxrank \o val)) => [|Wi _]; last by rewrite /W irrK. by rewrite -mxdirectE /= Socle_direct. pose modW i : mxmodule rG (W i) := if soc i is Some Wi as oWi return mxmodule rG (oapp val 0 oWi) then component_mx_module rG (socle_base Wi) else mxmodule0 rG n. apply: mx_rsim_trans (mx_rsim_sym (rsim_submod1 (mxmodule1 rG) _)) _ => //. apply: mx_rsim_dsum (modW) _ defS dxS _ => i. rewrite /W /standard_irr_coef /modW /soc; case: pickP => [Wi|_] /=; last first. rewrite /muln_grepr big_ord0. by exists 0 => [||x _]; rewrite /row_free ?mxrank0 ?mulmx0 ?mul0mx. move/eqP=> <-; apply: mx_rsim_socle. exact: rsim_irr_comp_pchar (socle_irr Wi). Qed. End StandardRepr. Definition cfReg (B : {set gT}) : 'CF(B) := #|B|%:R *: '1_[1]. Lemma cfRegE x : @cfReg G x = #|G|%:R *+ (x == 1%g). Proof. by rewrite cfunE cfuniE ?normal1 // inE mulr_natr. Qed. (* This is Isaacs, Lemma (2.10). *) Lemma cfReprReg : cfRepr (regular_repr algC G) = cfReg G. Proof. apply/cfun_inP=> x Gx; rewrite cfRegE. have [-> | ntx] := eqVneq x 1%g; first by rewrite cfRepr1. rewrite cfunE Gx [\tr _]big1 // => i _; rewrite 2!mxE /=. rewrite -(inj_eq enum_val_inj) gring_indexK ?groupM ?enum_valP //. by rewrite eq_mulVg1 mulKg (negbTE ntx). Qed. Definition xcfun (chi : 'CF(G)) A := (gring_row A *m (\col_(i < #|G|) chi (enum_val i))) 0 0. Lemma xcfun_is_zmod_morphism phi : zmod_morphism (xcfun phi). Proof. by move=> A B; rewrite /xcfun [gring_row _]linearB mulmxBl !mxE. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `xcfun_is_zmod_morphism` instead")] Definition xcfun_is_additive := xcfun_is_zmod_morphism. HB.instance Definition _ phi := GRing.isZmodMorphism.Build 'M_(gcard G) _ (xcfun phi) (xcfun_is_zmod_morphism phi). Lemma xcfunZr a phi A : xcfun phi (a *: A) = a * xcfun phi A. Proof. by rewrite /xcfun linearZ -scalemxAl mxE. Qed. (* In order to add a second canonical structure on xcfun *) Definition xcfun_r A phi := xcfun phi A. Arguments xcfun_r A phi /. Lemma xcfun_rE A chi : xcfun_r A chi = xcfun chi A. Proof. by []. Qed. Fact xcfun_r_is_zmod_morphism A : zmod_morphism (xcfun_r A). Proof. move=> phi psi; rewrite /= /xcfun !mxE -sumrB; apply: eq_bigr => i _. by rewrite !mxE !cfunE mulrBr. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `xcfun_r_is_zmod_morphism` instead")] Definition xcfun_r_is_additive := xcfun_r_is_zmod_morphism. HB.instance Definition _ A := GRing.isZmodMorphism.Build _ _ (xcfun_r A) (xcfun_r_is_zmod_morphism A). Lemma xcfunZl a phi A : xcfun (a *: phi) A = a * xcfun phi A. Proof. rewrite /xcfun !mxE big_distrr; apply: eq_bigr => i _ /=. by rewrite !mxE cfunE mulrCA. Qed. Lemma xcfun_repr n rG A : xcfun (@cfRepr n rG) A = \tr (gring_op rG A). Proof. rewrite gring_opE [gring_row A]row_sum_delta !linear_sum /xcfun !mxE. apply: eq_bigr => i _; rewrite !mxE /= !linearZ cfunE enum_valP /=. by congr (_ * \tr _); rewrite {A}/gring_mx /= -rowE rowK mxvecK. Qed. End Char. Arguments xcfun_r {_ _} A phi /. Notation "phi .[ A ]" := (xcfun phi A) : cfun_scope. Definition pred_Nirr gT B := #|@classes gT B|.-1. Arguments pred_Nirr {gT} B%_g. Notation Nirr G := (pred_Nirr G).+1. Notation Iirr G := 'I_(Nirr G). Section IrrClassDef. Variables (gT : finGroupType) (G : {group gT}). Let sG := DecSocleType (regular_repr algC G). Lemma NirrE : Nirr G = #|classes G|. Proof. by rewrite /pred_Nirr (cardD1 [1]) classes1. Qed. Fact Iirr_cast : Nirr G = #|sG|. Proof. by rewrite NirrE ?card_irr_pchar ?algC'G_pchar //; apply: groupC. Qed. Let offset := cast_ord (esym Iirr_cast) (enum_rank [1 sG]%irr). Definition socle_of_Iirr (i : Iirr G) : sG := enum_val (cast_ord Iirr_cast (i + offset)). Definition irr_of_socle (Wi : sG) : Iirr G := cast_ord (esym Iirr_cast) (enum_rank Wi) - offset. Local Notation W := socle_of_Iirr. Lemma socle_Iirr0 : W 0 = [1 sG]%irr. Proof. by rewrite /W add0r cast_ordKV enum_rankK. Qed. Lemma socle_of_IirrK : cancel W irr_of_socle. Proof. by move=> i; rewrite /irr_of_socle enum_valK cast_ordK addrK. Qed. Lemma irr_of_socleK : cancel irr_of_socle W. Proof. by move=> Wi; rewrite /W subrK cast_ordKV enum_rankK. Qed. Hint Resolve socle_of_IirrK irr_of_socleK : core. Lemma irr_of_socle_bij (A : {pred (Iirr G)}) : {on A, bijective irr_of_socle}. Proof. by apply: onW_bij; exists W. Qed. Lemma socle_of_Iirr_bij (A : {pred sG}) : {on A, bijective W}. Proof. by apply: onW_bij; exists irr_of_socle. Qed. End IrrClassDef. Prenex Implicits socle_of_IirrK irr_of_socleK. Arguments socle_of_Iirr {gT G%_G} i%_R. Notation "''Chi_' i" := (irr_repr (socle_of_Iirr i)) (at level 8, i at level 2, format "''Chi_' i"). HB.lock Definition irr gT B : (Nirr B).-tuple 'CF(B) := let irr_of i := 'Res[B, <<B>>] (@cfRepr gT _ _ 'Chi_(inord i)) in [tuple of mkseq irr_of (Nirr B)]. Arguments irr {gT} B%_g. Notation "''chi_' i" := (tnth (irr _) i%R) (at level 8, i at level 2, format "''chi_' i") : ring_scope. Notation "''chi[' G ]_ i" := (tnth (irr G) i%R) (at level 8, i at level 2, only parsing) : ring_scope. Section IrrClass. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (i : Iirr G) (B : {set gT}). Open Scope group_ring_scope. Lemma congr_irr i1 i2 : i1 = i2 -> 'chi_i1 = 'chi_i2. Proof. by move->. Qed. Lemma Iirr1_neq0 : G :!=: 1%g -> inord 1 != 0 :> Iirr G. Proof. by rewrite -classes_gt1 -NirrE -val_eqE /= => /inordK->. Qed. Lemma has_nonprincipal_irr : G :!=: 1%g -> {i : Iirr G | i != 0}. Proof. by move/Iirr1_neq0; exists (inord 1). Qed. Lemma irrRepr i : cfRepr 'Chi_i = 'chi_i. Proof. rewrite irr.unlock (tnth_nth 0) nth_mkseq // -[<<G>>]/(gval _) genGidG. by rewrite cfRes_id inord_val. Qed. Lemma irr0 : 'chi[G]_0 = 1. Proof. apply/cfun_inP=> x Gx; rewrite -irrRepr cfun1E cfunE Gx. by rewrite socle_Iirr0 irr1_repr // mxtrace1 degree_irr1. Qed. Lemma cfun1_irr : 1 \in irr G. Proof. by rewrite -irr0 mem_tnth. Qed. Lemma mem_irr i : 'chi_i \in irr G. Proof. exact: mem_tnth. Qed. Lemma irrP xi : reflect (exists i, xi = 'chi_i) (xi \in irr G). Proof. apply: (iffP idP) => [/(nthP 0)[i] | [i ->]]; last exact: mem_irr. rewrite size_tuple => lt_i_G <-. by exists (Ordinal lt_i_G); rewrite (tnth_nth 0). Qed. Let sG := DecSocleType (regular_repr algC G). Let C'G := algC'G_pchar G. Let closG := @groupC _ G. Local Notation W i := (@socle_of_Iirr _ G i). Local Notation "''n_' i" := 'n_(W i). Local Notation "''R_' i" := 'R_(W i). Local Notation "''e_' i" := 'e_(W i). Lemma irr1_degree i : 'chi_i 1%g = ('n_i)%:R. Proof. by rewrite -irrRepr cfRepr1. Qed. Lemma Cnat_irr1 i : 'chi_i 1%g \in Num.nat. Proof. by rewrite irr1_degree rpred_nat. Qed. Lemma irr1_gt0 i : 0 < 'chi_i 1%g. Proof. by rewrite irr1_degree ltr0n irr_degree_gt0. Qed. Lemma irr1_neq0 i : 'chi_i 1%g != 0. Proof. by rewrite eq_le lt_geF ?irr1_gt0. Qed. Lemma irr_neq0 i : 'chi_i != 0. Proof. by apply: contraNneq (irr1_neq0 i) => ->; rewrite cfunE. Qed. Local Remark cfIirr_key : unit. Proof. by []. Qed. Definition cfIirr : forall B, 'CF(B) -> Iirr B := locked_with cfIirr_key (fun B chi => inord (index chi (irr B))). Lemma cfIirrE chi : chi \in irr G -> 'chi_(cfIirr chi) = chi. Proof. move=> chi_irr; rewrite (tnth_nth 0) [cfIirr]unlock inordK ?nth_index //. by rewrite -index_mem size_tuple in chi_irr. Qed. Lemma cfIirrPE J (f : J -> 'CF(G)) (P : pred J) : (forall j, P j -> f j \in irr G) -> forall j, P j -> 'chi_(cfIirr (f j)) = f j. Proof. by move=> irr_f j /irr_f; apply: cfIirrE. Qed. (* This is Isaacs, Corollary (2.7). *) Corollary irr_sum_square : \sum_i ('chi[G]_i 1%g) ^+ 2 = #|G|%:R. Proof. rewrite -(sum_irr_degree_pchar sG) // natr_sum. rewrite (reindex _ (socle_of_Iirr_bij _)) /=. by apply: eq_bigr => i _; rewrite irr1_degree natrX. Qed. (* This is Isaacs, Lemma (2.11). *) Lemma cfReg_sum : cfReg G = \sum_i 'chi_i 1%g *: 'chi_i. Proof. apply/cfun_inP=> x Gx. rewrite -cfReprReg cfunE Gx (mxtrace_regular_pchar sG) //=. rewrite sum_cfunE (reindex _ (socle_of_Iirr_bij _)); apply: eq_bigr => i _. by rewrite -irrRepr cfRepr1 !cfunE Gx mulr_natl. Qed. Let aG := regular_repr algC G. Let R_G := group_ring algC G. Lemma xcfun_annihilate i j A : i != j -> (A \in 'R_j)%MS -> ('chi_i).[A]%CF = 0. Proof. move=> neq_ij RjA; rewrite -irrRepr xcfun_repr. rewrite (irr_repr'_op0_pchar _ _ RjA) ?raddf0 //. by rewrite eq_sym (can_eq socle_of_IirrK). Qed. Lemma xcfunG phi x : x \in G -> phi.[aG x]%CF = phi x. Proof. by move=> Gx; rewrite /xcfun /gring_row rowK -rowE !mxE !(gring_indexK, mul1g). Qed. Lemma xcfun_mul_id i A : (A \in R_G)%MS -> ('chi_i).['e_i *m A]%CF = ('chi_i).[A]%CF. Proof. move=> RG_A; rewrite -irrRepr !xcfun_repr gring_opM //. by rewrite op_Wedderburn_id_pchar ?mul1mx. Qed. Lemma xcfun_id i j : ('chi_i).['e_j]%CF = 'chi_i 1%g *+ (i == j). Proof. have [<-{j} | /xcfun_annihilate->//] := eqVneq; last exact: Wedderburn_id_mem. by rewrite -xcfunG // repr_mx1 -(xcfun_mul_id _ (envelop_mx1 _)) mulmx1. Qed. Lemma irr_free : free (irr G). Proof. apply/freeP=> s s0 i; apply: (mulIf (irr1_neq0 i)). rewrite mul0r -(raddf0 (xcfun_r 'e_i)) -{}s0 raddf_sum /=. rewrite (bigD1 i)//= -tnth_nth xcfunZl xcfun_id eqxx big1 ?addr0 // => j ne_ji. by rewrite -tnth_nth xcfunZl xcfun_id (negbTE ne_ji) mulr0. Qed. Lemma irr_inj : injective (tnth (irr G)). Proof. by apply/injectiveP/free_uniq; rewrite map_tnth_enum irr_free. Qed. Lemma irrK : cancel (tnth (irr G)) (@cfIirr G). Proof. by move=> i; apply: irr_inj; rewrite cfIirrE ?mem_irr. Qed. Lemma irr_eq1 i : ('chi_i == 1) = (i == 0). Proof. by rewrite -irr0 (inj_eq irr_inj). Qed. Lemma cforder_irr_eq1 i : (#['chi_i]%CF == 1) = (i == 0). Proof. by rewrite -dvdn1 dvdn_cforder irr_eq1. Qed. Lemma irr_basis : basis_of 'CF(G)%VS (irr G). Proof. rewrite /basis_of irr_free andbT -dimv_leqif_eq ?subvf //. by rewrite dim_cfun (eqnP irr_free) size_tuple NirrE. Qed. Lemma eq_sum_nth_irr a : \sum_i a i *: 'chi[G]_i = \sum_i a i *: (irr G)`_i. Proof. by apply: eq_bigr => i; rewrite -tnth_nth. Qed. (* This is Isaacs, Theorem (2.8). *) Theorem cfun_irr_sum phi : {a | phi = \sum_i a i *: 'chi[G]_i}. Proof. rewrite (coord_basis irr_basis (memvf phi)) -eq_sum_nth_irr. by exists ((coord (irr G))^~ phi). Qed. Lemma cfRepr_standard n (rG : mx_representation algC G n) : cfRepr (standard_grepr rG) = \sum_i (standard_irr_coef rG (W i))%:R *: 'chi_i. Proof. rewrite cfRepr_dsum (reindex _ (socle_of_Iirr_bij _)). by apply: eq_bigr => i _; rewrite scaler_nat cfRepr_muln irrRepr. Qed. Lemma cfRepr_inj n1 n2 rG1 rG2 : @cfRepr _ G n1 rG1 = @cfRepr _ G n2 rG2 -> mx_rsim rG1 rG2. Proof. move=> eq_repr12; pose c i : algC := (standard_irr_coef _ (W i))%:R. have [rsim1 rsim2] := (mx_rsim_standard rG1, mx_rsim_standard rG2). apply: mx_rsim_trans (rsim1) (mx_rsim_sym _). suffices ->: standard_grepr rG1 = standard_grepr rG2 by []. apply: eq_bigr => Wi _; congr (muln_grepr _ _); apply/eqP; rewrite -eqC_nat. rewrite -[Wi]irr_of_socleK -!/(c _ _ _) -!(coord_sum_free (c _ _) _ irr_free). rewrite -!eq_sum_nth_irr -!cfRepr_standard. by rewrite -(cfRepr_sim rsim1) -(cfRepr_sim rsim2) eq_repr12. Qed. Lemma cfRepr_rsimP n1 n2 rG1 rG2 : reflect (mx_rsim rG1 rG2) (@cfRepr _ G n1 rG1 == @cfRepr _ G n2 rG2). Proof. by apply: (iffP eqP) => [/cfRepr_inj | /cfRepr_sim]. Qed. Lemma irr_reprP xi : reflect (exists2 rG : representation _ G, mx_irreducible rG & xi = cfRepr rG) (xi \in irr G). Proof. apply: (iffP (irrP xi)) => [[i ->] | [[n rG] irr_rG ->]]. by exists (Representation 'Chi_i); [apply: socle_irr | rewrite irrRepr]. exists (irr_of_socle (irr_comp sG rG)); rewrite -irrRepr irr_of_socleK /=. exact/cfRepr_sim/rsim_irr_comp_pchar. Qed. (* This is Isaacs, Theorem (2.12). *) Lemma Wedderburn_id_expansion i : 'e_i = #|G|%:R^-1 *: (\sum_(x in G) 'chi_i 1%g * 'chi_i x^-1%g *: aG x). Proof. have Rei: ('e_i \in 'R_i)%MS by apply: Wedderburn_id_mem. have /envelop_mxP[a def_e]: ('e_i \in R_G)%MS; last rewrite -/aG in def_e. by move: Rei; rewrite genmxE mem_sub_gring => /andP[]. apply: canRL (scalerK (neq0CG _)) _; rewrite def_e linear_sum /=. apply: eq_bigr => x Gx; have Gx' := groupVr Gx; rewrite scalerA; congr (_ *: _). transitivity (cfReg G).['e_i *m aG x^-1%g]%CF. rewrite def_e mulmx_suml raddf_sum (bigD1 x) //= -scalemxAl xcfunZr. rewrite -repr_mxM // mulgV xcfunG // cfRegE eqxx mulrC big1 ?addr0 //. move=> y /andP[Gy /negbTE neq_xy]; rewrite -scalemxAl xcfunZr -repr_mxM //. by rewrite xcfunG ?groupM // cfRegE -eq_mulgV1 neq_xy mulr0. rewrite cfReg_sum -xcfun_rE raddf_sum /= (bigD1 i) //= xcfunZl. rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG ?groupV ?big1 ?addr0 // => j ne_ji. rewrite xcfunZl (xcfun_annihilate ne_ji) ?mulr0 //. have /andP[_ /(submx_trans _)-> //] := Wedderburn_ideal (W i). by rewrite mem_mulsmx // envelop_mx_id ?groupV. Qed. End IrrClass. Arguments cfReg {gT} B%_g. Prenex Implicits cfIirr irrK. Arguments irrP {gT G xi}. Arguments irr_reprP {gT G xi}. Arguments irr_inj {gT G} [x1 x2]. Section IsChar. Variable gT : finGroupType. Definition character_pred {G : {set gT}} := fun phi : 'CF(G) => [forall i, coord (irr G) i phi \in Num.nat]. Arguments character_pred _ _ /. Definition character {G : {set gT}} := [qualify a phi | @character_pred G phi]. Variable G : {group gT}. Implicit Types (phi chi xi : 'CF(G)) (i : Iirr G). Lemma irr_char i : 'chi_i \is a character. Proof. by apply/forallP=> j; rewrite (tnth_nth 0) coord_free ?irr_free. Qed. Lemma cfun1_char : (1 : 'CF(G)) \is a character. Proof. by rewrite -irr0 irr_char. Qed. Lemma cfun0_char : (0 : 'CF(G)) \is a character. Proof. by apply/forallP=> i; rewrite linear0 rpred0. Qed. Fact add_char : addr_closed (@character G). Proof. split=> [|chi xi /forallP-Nchi /forallP-Nxi]; first exact: cfun0_char. by apply/forallP=> i; rewrite linearD rpredD /=. Qed. HB.instance Definition _ := GRing.isAddClosed.Build (classfun G) character_pred add_char. Lemma char_sum_irrP {phi} : reflect (exists n, phi = \sum_i (n i)%:R *: 'chi_i) (phi \is a character). Proof. apply: (iffP idP)=> [/forallP-Nphi | [n ->]]; last first. by apply: rpred_sum => i _; rewrite scaler_nat rpredMn // irr_char. do [have [a ->] := cfun_irr_sum phi] in Nphi *; exists (Num.truncn \o a). apply: eq_bigr => i _; congr (_ *: _); have:= eqP (Nphi i). by rewrite eq_sum_nth_irr coord_sum_free ?irr_free. Qed. Lemma char_sum_irr chi : chi \is a character -> {r | chi = \sum_(i <- r) 'chi_i}. Proof. move=> Nchi; apply: sig_eqW; case/char_sum_irrP: Nchi => n {chi}->. elim/big_rec: _ => [|i _ _ [r ->]]; first by exists nil; rewrite big_nil. exists (ncons (n i) i r); rewrite scaler_nat. by elim: {n}(n i) => [|n IHn]; rewrite ?add0r //= big_cons mulrS -addrA IHn. Qed. Lemma Cnat_char1 chi : chi \is a character -> chi 1%g \in Num.nat. Proof. case/char_sum_irr=> r ->{chi}. by elim/big_rec: _ => [|i chi _ Nchi1]; rewrite cfunE ?rpredD // Cnat_irr1. Qed. Lemma char1_ge0 chi : chi \is a character -> 0 <= chi 1%g. Proof. by move/Cnat_char1/natr_ge0. Qed. Lemma char1_eq0 chi : chi \is a character -> (chi 1%g == 0) = (chi == 0). Proof. case/char_sum_irr=> r ->; apply/idP/idP=> [|/eqP->]; last by rewrite cfunE. case: r => [|i r]; rewrite ?big_nil // sum_cfunE big_cons. rewrite paddr_eq0 ?sumr_ge0 => // [||j _]; rewrite 1?ltW ?irr1_gt0 //. by rewrite (negbTE (irr1_neq0 i)). Qed. Lemma char1_gt0 chi : chi \is a character -> (0 < chi 1%g) = (chi != 0). Proof. by move=> Nchi; rewrite -char1_eq0 // natr_gt0 ?Cnat_char1. Qed. Lemma char_reprP phi : reflect (exists rG : representation algC G, phi = cfRepr rG) (phi \is a character). Proof. apply: (iffP char_sum_irrP) => [[n ->] | [[n rG] ->]]; last first. exists (fun i => standard_irr_coef rG (socle_of_Iirr i)). by rewrite -cfRepr_standard (cfRepr_sim (mx_rsim_standard rG)). exists (\big[dadd_grepr/grepr0]_i muln_grepr (Representation 'Chi_i) (n i)). rewrite cfRepr_dsum; apply: eq_bigr => i _. by rewrite cfRepr_muln irrRepr scaler_nat. Qed. Local Notation reprG := (mx_representation algC G). Lemma cfRepr_char n (rG : reprG n) : cfRepr rG \is a character. Proof. by apply/char_reprP; exists (Representation rG). Qed. Lemma cfReg_char : cfReg G \is a character. Proof. by rewrite -cfReprReg cfRepr_char. Qed. Lemma cfRepr_prod n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) : cfRepr rG1 * cfRepr rG2 = cfRepr (prod_repr rG1 rG2). Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE /= Gx mxtrace_prod. Qed. Lemma mul_char : mulr_closed (@character G). Proof. split=> [|_ _ /char_reprP[rG1 ->] /char_reprP[rG2 ->]]; first exact: cfun1_char. apply/char_reprP; exists (Representation (prod_repr rG1 rG2)). by rewrite cfRepr_prod. Qed. HB.instance Definition _ := GRing.isMulClosed.Build (classfun G) character_pred mul_char. End IsChar. Prenex Implicits character. Arguments character_pred _ _ _ /. Arguments char_reprP {gT G phi}. Section AutChar. Variables (gT : finGroupType) (G : {group gT}). Implicit Type u : {rmorphism algC -> algC}. Implicit Type chi : 'CF(G). Lemma cfRepr_map u n (rG : mx_representation algC G n) : cfRepr (map_repr u rG) = cfAut u (cfRepr rG). Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx map_reprE trace_map_mx. Qed. Lemma cfAut_char u chi : (cfAut u chi \is a character) = (chi \is a character). Proof. without loss /char_reprP[rG ->]: u chi / chi \is a character. by move=> IHu; apply/idP/idP=> ?; first rewrite -(cfAutK u chi); rewrite IHu. rewrite cfRepr_char; apply/char_reprP. by exists (Representation (map_repr u rG)); rewrite cfRepr_map. Qed. Lemma cfConjC_char chi : (chi^*%CF \is a character) = (chi \is a character). Proof. exact: cfAut_char. Qed. Lemma cfAut_char1 u (chi : 'CF(G)) : chi \is a character -> cfAut u chi 1%g = chi 1%g. Proof. by move/Cnat_char1=> Nchi1; rewrite cfunE /= aut_natr. Qed. Lemma cfAut_irr1 u i : (cfAut u 'chi[G]_i) 1%g = 'chi_i 1%g. Proof. exact: cfAut_char1 (irr_char i). Qed. Lemma cfConjC_char1 (chi : 'CF(G)) : chi \is a character -> chi^*%CF 1%g = chi 1%g. Proof. exact: cfAut_char1. Qed. Lemma cfConjC_irr1 u i : ('chi[G]_i)^*%CF 1%g = 'chi_i 1%g. Proof. exact: cfAut_irr1. Qed. End AutChar. Section Linear. Variables (gT : finGroupType) (G : {group gT}). Definition linear_char_pred {B : {set gT}} := fun phi : 'CF(B) => (phi \is a character) && (phi 1%g == 1). Arguments linear_char_pred _ _ /. Definition linear_char {B : {set gT}} := [qualify a phi | @linear_char_pred B phi]. Section OneChar. Variable xi : 'CF(G). Hypothesis CFxi : xi \is a linear_char. Lemma lin_char1: xi 1%g = 1. Proof. by case/andP: CFxi => _ /eqP. Qed. Lemma lin_charW : xi \is a character. Proof. by case/andP: CFxi. Qed. Lemma cfun1_lin_char : (1 : 'CF(G)) \is a linear_char. Proof. by rewrite qualifE/= cfun1_char /= cfun11. Qed. Lemma lin_charM : {in G &, {morph xi : x y / (x * y)%g >-> x * y}}. Proof. move=> x y Gx Gy; case/andP: CFxi => /char_reprP[[n rG] -> /=]. rewrite cfRepr1 pnatr_eq1 => /eqP n1; rewrite {n}n1 in rG *. rewrite !cfunE Gx Gy groupM //= !mulr1n repr_mxM //. by rewrite [rG x]mx11_scalar [rG y]mx11_scalar -scalar_mxM !mxtrace_scalar. Qed. Lemma lin_char_prod I r (P : pred I) (x : I -> gT) : (forall i, P i -> x i \in G) -> xi (\prod_(i <- r | P i) x i)%g = \prod_(i <- r | P i) xi (x i). Proof. move=> Gx; elim/(big_load (fun y => y \in G)): _. elim/big_rec2: _ => [|i a y Pi [Gy <-]]; first by rewrite lin_char1. by rewrite groupM ?lin_charM ?Gx. Qed. Let xiMV x : x \in G -> xi x * xi (x^-1)%g = 1. Proof. by move=> Gx; rewrite -lin_charM ?groupV // mulgV lin_char1. Qed. Lemma lin_char_neq0 x : x \in G -> xi x != 0. Proof. by move/xiMV/(congr1 (predC1 0)); rewrite /= oner_eq0 mulf_eq0 => /norP[]. Qed. Lemma lin_charV x : x \in G -> xi x^-1%g = (xi x)^-1. Proof. by move=> Gx; rewrite -[_^-1]mulr1 -(xiMV Gx) mulKf ?lin_char_neq0. Qed. Lemma lin_charX x n : x \in G -> xi (x ^+ n)%g = xi x ^+ n. Proof. move=> Gx; elim: n => [|n IHn]; first exact: lin_char1. by rewrite expgS exprS lin_charM ?groupX ?IHn. Qed. Lemma lin_char_unity_root x : x \in G -> xi x ^+ #[x] = 1. Proof. by move=> Gx; rewrite -lin_charX // expg_order lin_char1. Qed. Lemma normC_lin_char x : x \in G -> `|xi x| = 1. Proof. move=> Gx; apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) //. by rewrite -normrX // lin_char_unity_root ?normr1. Qed. Lemma lin_charV_conj x : x \in G -> xi x^-1%g = (xi x)^*. Proof. move=> Gx; rewrite lin_charV // invC_norm mulrC normC_lin_char //. by rewrite expr1n divr1. Qed. Lemma lin_char_irr : xi \in irr G. Proof. case/andP: CFxi => /char_reprP[rG ->]; rewrite cfRepr1 pnatr_eq1 => /eqP n1. by apply/irr_reprP; exists rG => //; apply/mx_abs_irrW/linear_mx_abs_irr. Qed. Lemma mul_conjC_lin_char : xi * xi^*%CF = 1. Proof. apply/cfun_inP=> x Gx. by rewrite !cfunE cfun1E Gx -normCK normC_lin_char ?expr1n. Qed. Lemma lin_char_unitr : xi \in GRing.unit. Proof. by apply/unitrPr; exists xi^*%CF; apply: mul_conjC_lin_char. Qed. Lemma invr_lin_char : xi^-1 = xi^*%CF. Proof. by rewrite -[_^-1]mulr1 -mul_conjC_lin_char mulKr ?lin_char_unitr. Qed. Lemma fful_lin_char_inj : cfaithful xi -> {in G &, injective xi}. Proof. move=> fful_phi x y Gx Gy xi_xy; apply/eqP; rewrite eq_mulgV1 -in_set1. rewrite (subsetP fful_phi) // inE groupM ?groupV //=; apply/forallP=> z. have [Gz | G'z] := boolP (z \in G); last by rewrite !cfun0 ?groupMl ?groupV. by rewrite -mulgA lin_charM ?xi_xy -?lin_charM ?groupM ?groupV // mulKVg. Qed. End OneChar. Lemma cfAut_lin_char u (xi : 'CF(G)) : (cfAut u xi \is a linear_char) = (xi \is a linear_char). Proof. by rewrite qualifE/= cfAut_char; apply/andb_id2l=> /cfAut_char1->. Qed. Lemma cfConjC_lin_char (xi : 'CF(G)) : (xi^*%CF \is a linear_char) = (xi \is a linear_char). Proof. exact: cfAut_lin_char. Qed. Lemma card_Iirr_abelian : abelian G -> #|Iirr G| = #|G|. Proof. by rewrite card_ord NirrE card_classes_abelian => /eqP. Qed. Lemma card_Iirr_cyclic : cyclic G -> #|Iirr G| = #|G|. Proof. by move/cyclic_abelian/card_Iirr_abelian. Qed. Lemma char_abelianP : reflect (forall i : Iirr G, 'chi_i \is a linear_char) (abelian G). Proof. apply: (iffP idP) => [cGG i | CF_G]. rewrite qualifE/= irr_char /= irr1_degree. by rewrite irr_degree_abelian //; last apply: groupC. rewrite card_classes_abelian -NirrE -eqC_nat -irr_sum_square //. rewrite -{1}[Nirr G]card_ord -sumr_const; apply/eqP/eq_bigr=> i _. by rewrite lin_char1 ?expr1n ?CF_G. Qed. Lemma irr_repr_lin_char (i : Iirr G) x : x \in G -> 'chi_i \is a linear_char -> irr_repr (socle_of_Iirr i) x = ('chi_i x)%:M. Proof. move=> Gx CFi; rewrite -irrRepr cfunE Gx. move: (_ x); rewrite -[irr_degree _](@natrK algC) -irr1_degree lin_char1 //. by rewrite (natrK 1) => A; rewrite trace_mx11 -mx11_scalar. Qed. Fact linear_char_divr : divr_closed (@linear_char G). Proof. split=> [|chi xi Lchi Lxi]; first exact: cfun1_lin_char. rewrite invr_lin_char // qualifE/= cfunE. by rewrite rpredM ?lin_char1 ?mulr1 ?lin_charW //= cfConjC_lin_char. Qed. HB.instance Definition _ := GRing.isDivClosed.Build (classfun G) linear_char_pred linear_char_divr. Lemma irr_cyclic_lin i : cyclic G -> 'chi[G]_i \is a linear_char. Proof. by move/cyclic_abelian/char_abelianP. Qed. Lemma irr_prime_lin i : prime #|G| -> 'chi[G]_i \is a linear_char. Proof. by move/prime_cyclic/irr_cyclic_lin. Qed. End Linear. Prenex Implicits linear_char. Arguments linear_char_pred _ _ _ /. Section OrthogonalityRelations. Variables aT gT : finGroupType. (* This is Isaacs, Lemma (2.15) *) Lemma repr_rsim_diag (G : {group gT}) f (rG : mx_representation algC G f) x : x \in G -> let chi := cfRepr rG in exists e, [/\ (*a*) exists2 B, B \in unitmx & rG x = invmx B *m diag_mx e *m B, (*b*) (forall i, e 0 i ^+ #[x] = 1) /\ (forall i, `|e 0 i| = 1), (*c*) chi x = \sum_i e 0 i /\ `|chi x| <= chi 1%g & (*d*) chi x^-1%g = (chi x)^*]. Proof. move=> Gx; without loss cGG: G rG Gx / abelian G. have sXG: <[x]> \subset G by rewrite cycle_subG. move/(_ _ (subg_repr rG sXG) (cycle_id x) (cycle_abelian x)). by rewrite /= !cfunE !groupV Gx (cycle_id x) !group1. have [I U W simU W1 dxW]: mxsemisimple rG 1%:M. rewrite -(reducible_Socle1 (DecSocleType rG) (mx_Maschke_pchar _ (algC'G_pchar G))). exact: Socle_semisimple. have linU i: \rank (U i) = 1. by apply: mxsimple_abelian_linear cGG (simU i); apply: groupC. have castI: f = #|I|. by rewrite -(mxrank1 algC f) -W1 (eqnP dxW) /= -sum1_card; apply/eq_bigr. pose B := \matrix_j nz_row (U (enum_val (cast_ord castI j))). have rowU i: (nz_row (U i) :=: U i)%MS. apply/eqmxP; rewrite -(geq_leqif (mxrank_leqif_eq (nz_row_sub _))) linU. by rewrite lt0n mxrank_eq0 (nz_row_mxsimple (simU i)). have unitB: B \in unitmx. rewrite -row_full_unit -sub1mx -W1; apply/sumsmx_subP=> i _. pose j := cast_ord (esym castI) (enum_rank i). by rewrite (submx_trans _ (row_sub j B)) // rowK cast_ordKV enum_rankK rowU. pose e := \row_j row j (B *m rG x *m invmx B) 0 j. have rGx: rG x = invmx B *m diag_mx e *m B. rewrite -mulmxA; apply: canRL (mulKmx unitB) _. apply/row_matrixP=> j; rewrite 2!row_mul; set u := row j B. have /sub_rVP[a def_ux]: (u *m rG x <= u)%MS. rewrite /u rowK rowU (eqmxMr _ (rowU _)). exact: (mxmoduleP (mxsimple_module (simU _))). rewrite def_ux [u]rowE scalemxAl; congr (_ *m _). apply/rowP=> k; rewrite 5!mxE !row_mul def_ux [u]rowE scalemxAl mulmxK //. by rewrite !mxE !eqxx !mulr_natr eq_sym. have exp_e j: e 0 j ^+ #[x] = 1. suffices: (diag_mx e j j) ^+ #[x] = (B *m rG (x ^+ #[x])%g *m invmx B) j j. by rewrite expg_order repr_mx1 mulmx1 mulmxV // [e]lock !mxE eqxx. elim: #[x] => [|n IHn]; first by rewrite repr_mx1 mulmx1 mulmxV // !mxE eqxx. rewrite expgS repr_mxM ?groupX // {1}rGx -!mulmxA mulKVmx //. by rewrite mul_diag_mx mulmxA [M in _ = M]mxE -IHn exprS {1}mxE eqxx. have norm1_e j: `|e 0 j| = 1. by apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) // -normrX exp_e normr1. exists e; split=> //; first by exists B. rewrite cfRepr1 !cfunE Gx rGx mxtrace_mulC mulKVmx // mxtrace_diag. split=> //=; apply: (le_trans (ler_norm_sum _ _ _)). by rewrite (eq_bigr _ (in1W norm1_e)) sumr_const card_ord lexx. rewrite !cfunE groupV !mulrb Gx rGx mxtrace_mulC mulKVmx //. rewrite -trace_map_mx map_diag_mx; set d' := diag_mx _. rewrite -[d'](mulKVmx unitB) mxtrace_mulC -[_ *m _](repr_mxK rG Gx) rGx. rewrite -!mulmxA mulKVmx // (mulmxA d'). suffices->: d' *m diag_mx e = 1%:M by rewrite mul1mx mulKmx. rewrite mulmx_diag -diag_const_mx; congr diag_mx; apply/rowP=> j. by rewrite [e]lock !mxE mulrC -normCK -lock norm1_e expr1n. Qed. Variables (A : {group aT}) (G : {group gT}). (* This is Isaacs, Lemma (2.15) (d). *) Lemma char_inv (chi : 'CF(G)) x : chi \is a character -> chi x^-1%g = (chi x)^*. Proof. case Gx: (x \in G); last by rewrite !cfun0 ?rmorph0 ?groupV ?Gx. by case/char_reprP=> rG ->; have [e [_ _ _]] := repr_rsim_diag rG Gx. Qed. Lemma irr_inv i x : 'chi[G]_i x^-1%g = ('chi_i x)^*. Proof. exact/char_inv/irr_char. Qed. (* This is Isaacs, Theorem (2.13). *) Theorem generalized_orthogonality_relation y (i j : Iirr G) : #|G|%:R^-1 * (\sum_(x in G) 'chi_i (x * y)%g * 'chi_j x^-1%g) = (i == j)%:R * ('chi_i y / 'chi_i 1%g). Proof. pose W := @socle_of_Iirr _ G; pose e k := Wedderburn_id (W k). pose aG := regular_repr algC G. have [Gy | notGy] := boolP (y \in G); last first. rewrite cfun0 // mul0r big1 ?mulr0 // => x Gx. by rewrite cfun0 ?groupMl ?mul0r. transitivity (('chi_i).[e j *m aG y]%CF / 'chi_j 1%g). rewrite [e j]Wedderburn_id_expansion -scalemxAl xcfunZr -mulrA; congr (_ * _). rewrite mulmx_suml raddf_sum big_distrl; apply: eq_bigr => x Gx /=. rewrite -scalemxAl xcfunZr -repr_mxM // xcfunG ?groupM // mulrAC mulrC. by congr (_ * _); rewrite mulrC mulKf ?irr1_neq0. rewrite mulr_natl mulrb; have [<-{j} | neq_ij] := eqVneq. by congr (_ / _); rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG. rewrite (xcfun_annihilate neq_ij) ?mul0r //. case/andP: (Wedderburn_ideal (W j)) => _; apply: submx_trans. by rewrite mem_mulsmx ?Wedderburn_id_mem ?envelop_mx_id. Qed. (* This is Isaacs, Corollary (2.14). *) Corollary first_orthogonality_relation (i j : Iirr G) : #|G|%:R^-1 * (\sum_(x in G) 'chi_i x * 'chi_j x^-1%g) = (i == j)%:R. Proof. have:= generalized_orthogonality_relation 1 i j. rewrite mulrA mulfK ?irr1_neq0 // => <-; congr (_ * _). by apply: eq_bigr => x; rewrite mulg1. Qed. (* The character table. *) Definition irr_class i := enum_val (cast_ord (NirrE G) i). Definition class_Iirr xG := cast_ord (esym (NirrE G)) (enum_rank_in (classes1 G) xG). Local Notation c := irr_class. Local Notation g i := (repr (c i)). Local Notation iC := class_Iirr. Definition character_table := \matrix_(i, j) 'chi[G]_i (g j). Local Notation X := character_table. Lemma irr_classP i : c i \in classes G. Proof. exact: enum_valP. Qed. Lemma repr_irr_classK i : g i ^: G = c i. Proof. by case/repr_classesP: (irr_classP i). Qed. Lemma irr_classK : cancel c iC. Proof. by move=> i; rewrite /iC enum_valK_in cast_ordK. Qed. Lemma class_IirrK : {in classes G, cancel iC c}. Proof. by move=> xG GxG; rewrite /c cast_ordKV enum_rankK_in. Qed. Lemma reindex_irr_class R idx (op : @Monoid.com_law R idx) F : \big[op/idx]_(xG in classes G) F xG = \big[op/idx]_i F (c i). Proof. rewrite (reindex c); first by apply: eq_bigl => i; apply: enum_valP. by exists iC; [apply: in1W; apply: irr_classK | apply: class_IirrK]. Qed. (* The explicit value of the inverse is needed for the proof of the second *) (* orthogonality relation. *) Let X' := \matrix_(i, j) (#|'C_G[g i]|%:R^-1 * ('chi[G]_j (g i))^*). Let XX'_1: X *m X' = 1%:M. Proof. apply/matrixP=> i j; rewrite !mxE -first_orthogonality_relation mulr_sumr. rewrite sum_by_classes => [|u v Gu Gv]; last by rewrite -conjVg !cfunJ. rewrite reindex_irr_class /=; apply/esym/eq_bigr=> k _. rewrite !mxE irr_inv // -/(g k) -divg_index -indexgI /=. rewrite (pchar0_natf_div Cpchar) ?dvdn_indexg // index_cent1 invfM invrK. by rewrite repr_irr_classK mulrCA mulrA mulrCA. Qed. Lemma character_table_unit : X \in unitmx. Proof. by case/mulmx1_unit: XX'_1. Qed. Let uX := character_table_unit. (* This is Isaacs, Theorem (2.18). *) Theorem second_orthogonality_relation x y : y \in G -> \sum_i 'chi[G]_i x * ('chi_i y)^* = #|'C_G[x]|%:R *+ (x \in y ^: G). Proof. move=> Gy; pose i_x := iC (x ^: G); pose i_y := iC (y ^: G). have [Gx | notGx] := boolP (x \in G); last first. rewrite (contraNF (subsetP _ x) notGx) ?class_subG ?big1 // => i _. by rewrite cfun0 ?mul0r. transitivity ((#|'C_G[repr (y ^: G)]|%:R *: (X' *m X)) i_y i_x). rewrite scalemxAl !mxE; apply: eq_bigr => k _; rewrite !mxE mulrC -!mulrA. by rewrite !class_IirrK ?mem_classes // !cfun_repr mulVKf ?neq0CG. rewrite mulmx1C // !mxE -!divg_index; do 2!rewrite -indexgI index_cent1. rewrite (class_eqP (mem_repr y _)) ?class_refl // mulr_natr. rewrite (can_in_eq class_IirrK) ?mem_classes //. have [-> | not_yGx] := eqVneq; first by rewrite class_refl. by rewrite [x \in _](contraNF _ not_yGx) // => /class_eqP->. Qed. Lemma eq_irr_mem_classP x y : y \in G -> reflect (forall i, 'chi[G]_i x = 'chi_i y) (x \in y ^: G). Proof. move=> Gy; apply: (iffP idP) => [/imsetP[z Gz ->] i | xGy]; first exact: cfunJ. have Gx: x \in G. congr is_true: Gy; apply/eqP; rewrite -(can_eq oddb) -eqC_nat -!cfun1E. by rewrite -irr0 xGy. congr is_true: (class_refl G x); apply/eqP; rewrite -(can_eq oddb). rewrite -(eqn_pmul2l (cardG_gt0 'C_G[x])) -eqC_nat !mulrnA; apply/eqP. by rewrite -!second_orthogonality_relation //; apply/eq_bigr=> i _; rewrite xGy. Qed. (* This is Isaacs, Theorem (6.32) (due to Brauer). *) Lemma card_afix_irr_classes (ito : action A (Iirr G)) (cto : action A _) a : a \in A -> [acts A, on classes G | cto] -> (forall i x y, x \in G -> y \in cto (x ^: G) a -> 'chi_i x = 'chi_(ito i a) y) -> #|'Fix_ito[a]| = #|'Fix_(classes G | cto)[a]|. Proof. move=> Aa actsAG stabAchi; apply/eqP; rewrite -eqC_nat; apply/eqP. have [[cP cK] iCK] := (irr_classP, irr_classK, class_IirrK). pose icto b i := iC (cto (c i) b). have Gca i: cto (c i) a \in classes G by rewrite (acts_act actsAG). have inj_qa: injective (icto a). by apply: can_inj (icto a^-1%g) _ => i; rewrite /icto iCK ?actKin ?cK. pose Pa : 'M[algC]_(Nirr G) := perm_mx (actperm ito a). pose qa := perm inj_qa; pose Qa : 'M[algC]_(Nirr G) := perm_mx qa^-1^-1%g. transitivity (\tr Pa). rewrite -sumr_const big_mkcond; apply: eq_bigr => i _. by rewrite !mxE permE inE sub1set inE; case: ifP. symmetry; transitivity (\tr Qa). rewrite cardsE -sumr_const -big_filter_cond big_mkcond big_filter /=. rewrite reindex_irr_class; apply: eq_bigr => i _; rewrite !mxE invgK permE. by rewrite inE sub1set inE -(can_eq cK) iCK //; case: ifP. rewrite -[Pa](mulmxK uX) -[Qa](mulKmx uX) mxtrace_mulC; congr (\tr(_ *m _)). rewrite -row_permE -col_permE; apply/matrixP=> i j; rewrite !mxE. rewrite -{2}[j](permKV qa); move: {j}(_ j) => j; rewrite !permE iCK //. apply: stabAchi; first by case/repr_classesP: (cP j). by rewrite repr_irr_classK (mem_repr_classes (Gca _)). Qed. End OrthogonalityRelations. Prenex Implicits irr_class class_Iirr irr_classK. Arguments class_IirrK {gT G%_G} [xG%_g] GxG : rename. Arguments character_table {gT} G%_g. Section InnerProduct. Variable (gT : finGroupType) (G : {group gT}). Lemma cfdot_irr i j : '['chi_i, 'chi_j]_G = (i == j)%:R. Proof. rewrite -first_orthogonality_relation; congr (_ * _). by apply: eq_bigr => x Gx; rewrite irr_inv. Qed. Lemma cfnorm_irr i : '['chi[G]_i] = 1. Proof. by rewrite cfdot_irr eqxx. Qed. Lemma irr_orthonormal : orthonormal (irr G). Proof. apply/orthonormalP; split; first exact: free_uniq (irr_free G). move=> _ _ /irrP[i ->] /irrP[j ->]. by rewrite cfdot_irr (inj_eq irr_inj). Qed. Lemma coord_cfdot phi i : coord (irr G) i phi = '[phi, 'chi_i]. Proof. rewrite {2}(coord_basis (irr_basis G) (memvf phi)). rewrite cfdot_suml (bigD1 i) // cfdotZl /= -tnth_nth cfdot_irr eqxx mulr1. rewrite big1 ?addr0 // => j neq_ji; rewrite cfdotZl /= -tnth_nth cfdot_irr. by rewrite (negbTE neq_ji) mulr0. Qed. Lemma cfun_sum_cfdot phi : phi = \sum_i '[phi, 'chi_i]_G *: 'chi_i. Proof. rewrite {1}(coord_basis (irr_basis G) (memvf phi)). by apply: eq_bigr => i _; rewrite coord_cfdot -tnth_nth. Qed. Lemma cfdot_sum_irr phi psi : '[phi, psi]_G = \sum_i '[phi, 'chi_i] * '[psi, 'chi_i]^*. Proof. rewrite {1}[phi]cfun_sum_cfdot cfdot_suml; apply: eq_bigr => i _. by rewrite cfdotZl -cfdotC. Qed. Lemma Cnat_cfdot_char_irr i phi : phi \is a character -> '[phi, 'chi_i]_G \in Num.nat. Proof. by move/forallP/(_ i); rewrite coord_cfdot. Qed. Lemma cfdot_char_r phi chi : chi \is a character -> '[phi, chi]_G = \sum_i '[phi, 'chi_i] * '[chi, 'chi_i]. Proof. move=> Nchi; rewrite cfdot_sum_irr; apply: eq_bigr => i _; congr (_ * _). by rewrite conj_natr ?Cnat_cfdot_char_irr. Qed. Lemma Cnat_cfdot_char chi xi : chi \is a character -> xi \is a character -> '[chi, xi]_G \in Num.nat. Proof. move=> Nchi Nxi; rewrite cfdot_char_r ?rpred_sum // => i _. by rewrite rpredM ?Cnat_cfdot_char_irr. Qed. Lemma cfdotC_char chi xi : chi \is a character-> xi \is a character -> '[chi, xi]_G = '[xi, chi]. Proof. by move=> Nchi Nxi; rewrite cfdotC conj_natr ?Cnat_cfdot_char. Qed. Lemma irrEchar chi : (chi \in irr G) = (chi \is a character) && ('[chi] == 1). Proof. apply/irrP/andP=> [[i ->] | [Nchi]]; first by rewrite irr_char cfnorm_irr. rewrite cfdot_sum_irr => /eqP/natr_sum_eq1[i _| i [_ ci1 cj0]]. by rewrite rpredM // ?conj_natr ?Cnat_cfdot_char_irr. exists i; rewrite [chi]cfun_sum_cfdot (bigD1 i) //=. rewrite -(normr_idP (natr_ge0 (Cnat_cfdot_char_irr i Nchi))). rewrite normC_def {}ci1 sqrtC1 scale1r big1 ?addr0 // => j neq_ji. by rewrite (('[_] =P 0) _) ?scale0r // -normr_eq0 normC_def cj0 ?sqrtC0. Qed. Lemma irrWchar chi : chi \in irr G -> chi \is a character. Proof. by rewrite irrEchar => /andP[]. Qed. Lemma irrWnorm chi : chi \in irr G -> '[chi] = 1. Proof. by rewrite irrEchar => /andP[_ /eqP]. Qed. Lemma mul_lin_irr xi chi : xi \is a linear_char -> chi \in irr G -> xi * chi \in irr G. Proof. move=> Lxi; rewrite !irrEchar => /andP[Nphi /eqP <-]. rewrite rpredM // ?lin_charW //=; apply/eqP; congr (_ * _). apply: eq_bigr=> x Gx; rewrite !cfunE rmorphM/= mulrACA -(lin_charV_conj Lxi)//. by rewrite -lin_charM ?groupV // mulgV lin_char1 ?mul1r. Qed. Lemma eq_scaled_irr a b i j : (a *: 'chi[G]_i == b *: 'chi_j) = (a == b) && ((a == 0) || (i == j)). Proof. apply/eqP/andP=> [|[/eqP-> /pred2P[]-> //]]; last by rewrite !scale0r. move/(congr1 (cfdotr 'chi__)) => /= eq_ai_bj. move: {eq_ai_bj}(eq_ai_bj i) (esym (eq_ai_bj j)); rewrite !cfdotZl !cfdot_irr. by rewrite !mulr_natr !mulrb !eqxx eq_sym orbC; case: ifP => _ -> //= ->. Qed. Lemma eq_signed_irr (s t : bool) i j : ((-1) ^+ s *: 'chi[G]_i == (-1) ^+ t *: 'chi_j) = (s == t) && (i == j). Proof. by rewrite eq_scaled_irr signr_eq0 (inj_eq signr_inj). Qed. Lemma eq_scale_irr a (i j : Iirr G) : (a *: 'chi_i == a *: 'chi_j) = (a == 0) || (i == j). Proof. by rewrite eq_scaled_irr eqxx. Qed. Lemma eq_addZ_irr a b (i j r t : Iirr G) : (a *: 'chi_i + b *: 'chi_j == a *: 'chi_r + b *: 'chi_t) = [|| [&& (a == 0) || (i == r) & (b == 0) || (j == t)], [&& i == t, j == r & a == b] | [&& i == j, r == t & a == - b]]. Proof. rewrite -!eq_scale_irr; apply/eqP/idP; last first. case/orP; first by case/andP=> /eqP-> /eqP->. case/orP=> /and3P[/eqP-> /eqP-> /eqP->]; first by rewrite addrC. by rewrite !scaleNr !addNr. have [-> /addrI/eqP-> // | /=] := eqVneq. rewrite eq_scale_irr => /norP[/negP nz_a /negPf neq_ir]. move/(congr1 (cfdotr 'chi__))/esym/eqP => /= eq_cfdot. move: {eq_cfdot}(eq_cfdot i) (eq_cfdot r); rewrite eq_sym !cfdotDl !cfdotZl. rewrite !cfdot_irr !mulr_natr !mulrb !eqxx -!(eq_sym i) neq_ir !add0r. have [<- _ | _] := i =P t; first by rewrite neq_ir addr0; case: ifP => // _ ->. rewrite 2!fun_if if_arg addr0 addr_eq0; case: eqP => //= <- ->. by rewrite neq_ir 2!fun_if if_arg eq_sym addr0; case: ifP. Qed. Lemma eq_subZnat_irr (a b : nat) (i j r t : Iirr G) : (a%:R *: 'chi_i - b%:R *: 'chi_j == a%:R *: 'chi_r - b%:R *: 'chi_t) = [|| a == 0 | i == r] && [|| b == 0 | j == t] || [&& i == j, r == t & a == b]. Proof. rewrite -!scaleNr eq_addZ_irr oppr_eq0 opprK -addr_eq0 -natrD eqr_nat. by rewrite !pnatr_eq0 addn_eq0; case: a b => [|a] [|b]; rewrite ?andbF. Qed. End InnerProduct. Section IrrConstt. Variable (gT : finGroupType) (G H : {group gT}). Lemma char1_ge_norm (chi : 'CF(G)) x : chi \is a character -> `|chi x| <= chi 1%g. Proof. case/char_reprP=> rG ->; case Gx: (x \in G); last first. by rewrite cfunE cfRepr1 Gx normr0 ler0n. by have [e [_ _ []]] := repr_rsim_diag rG Gx. Qed. Lemma max_cfRepr_norm_scalar n (rG : mx_representation algC G n) x : x \in G -> `|cfRepr rG x| = cfRepr rG 1%g -> exists2 c, `|c| = 1 & rG x = c%:M. Proof. move=> Gx; have [e [[B uB def_x] [_ e1] [-> _] _]] := repr_rsim_diag rG Gx. rewrite cfRepr1 -[n in n%:R]card_ord -sumr_const -(eq_bigr _ (in1W e1)). case/normC_sum_eq1=> [i _ | c /eqP norm_c_1 def_e]; first by rewrite e1. have{} def_e: e = const_mx c by apply/rowP=> i; rewrite mxE def_e ?andbT. by exists c => //; rewrite def_x def_e diag_const_mx scalar_mxC mulmxKV. Qed. Lemma max_cfRepr_mx1 n (rG : mx_representation algC G n) x : x \in G -> cfRepr rG x = cfRepr rG 1%g -> rG x = 1%:M. Proof. move=> Gx kerGx; have [|c _ def_x] := @max_cfRepr_norm_scalar n rG x Gx. by rewrite kerGx cfRepr1 normr_nat. move/eqP: kerGx; rewrite cfRepr1 cfunE Gx {rG}def_x mxtrace_scalar. case: n => [_|n]; first by rewrite ![_%:M]flatmx0. rewrite mulrb -subr_eq0 -mulrnBl -mulr_natl mulf_eq0 pnatr_eq0 /=. by rewrite subr_eq0 => /eqP->. Qed. Definition irr_constt (B : {set gT}) phi := [pred i | '[phi, 'chi_i]_B != 0]. Lemma irr_consttE i phi : (i \in irr_constt phi) = ('[phi, 'chi_i]_G != 0). Proof. by []. Qed. Lemma constt_charP (i : Iirr G) chi : chi \is a character -> reflect (exists2 chi', chi' \is a character & chi = 'chi_i + chi') (i \in irr_constt chi). Proof. move=> Nchi; apply: (iffP idP) => [i_in_chi| [chi' Nchi' ->]]; last first. rewrite inE /= cfdotDl cfdot_irr eqxx -(eqP (Cnat_cfdot_char_irr i Nchi')). by rewrite -natrD pnatr_eq0. exists (chi - 'chi_i); last by rewrite addrC subrK. apply/forallP=> j; rewrite coord_cfdot cfdotBl cfdot_irr. have [<- | _] := eqP; last by rewrite subr0 Cnat_cfdot_char_irr. move: i_in_chi; rewrite inE; case/natrP: (Cnat_cfdot_char_irr i Nchi) => n ->. by rewrite pnatr_eq0 -lt0n => /natrB <-; apply: rpred_nat. Qed. Lemma cfun_sum_constt (phi : 'CF(G)) : phi = \sum_(i in irr_constt phi) '[phi, 'chi_i] *: 'chi_i. Proof. rewrite {1}[phi]cfun_sum_cfdot (bigID [pred i | '[phi, 'chi_i] == 0]) /=. by rewrite big1 ?add0r // => i /eqP->; rewrite scale0r. Qed. Lemma neq0_has_constt (phi : 'CF(G)) : phi != 0 -> exists i, i \in irr_constt phi. Proof. move=> nz_phi; apply/existsP; apply: contra nz_phi => /pred0P phi0. by rewrite [phi]cfun_sum_constt big_pred0. Qed. Lemma constt_irr i : irr_constt 'chi[G]_i =i pred1 i. Proof. by move=> j; rewrite !inE cfdot_irr pnatr_eq0 (eq_sym j); case: (i == j). Qed. Lemma char1_ge_constt (i : Iirr G) chi : chi \is a character -> i \in irr_constt chi -> 'chi_i 1%g <= chi 1%g. Proof. move=> {chi} _ /constt_charP[// | chi Nchi ->]. by rewrite cfunE addrC -subr_ge0 addrK char1_ge0. Qed. Lemma constt_ortho_char (phi psi : 'CF(G)) i j : phi \is a character -> psi \is a character -> i \in irr_constt phi -> j \in irr_constt psi -> '[phi, psi] = 0 -> '['chi_i, 'chi_j] = 0. Proof. move=> _ _ /constt_charP[//|phi1 Nphi1 ->] /constt_charP[//|psi1 Npsi1 ->]. rewrite cfdot_irr; case: eqP => // -> /eqP/idPn[]. rewrite cfdotDl !cfdotDr cfnorm_irr -addrA gt_eqF ?ltr_wpDr ?ltr01 //. by rewrite natr_ge0 ?rpredD ?Cnat_cfdot_char ?irr_char. Qed. End IrrConstt. Arguments irr_constt {gT B%_g} phi%_CF. Section Kernel. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (phi chi xi : 'CF(G)) (H : {group gT}). Lemma cfker_repr n (rG : mx_representation algC G n) : cfker (cfRepr rG) = rker rG. Proof. apply/esym/setP=> x; rewrite inE mul1mx /=. case Gx: (x \in G); last by rewrite inE Gx. apply/eqP/idP=> Kx; last by rewrite max_cfRepr_mx1 // cfker1. rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !mulrb groupMl //. by case: ifP => // Gy; rewrite repr_mxM // Kx mul1mx. Qed. Lemma cfkerEchar chi : chi \is a character -> cfker chi = [set x in G | chi x == chi 1%g]. Proof. move=> Nchi; apply/setP=> x; apply/idP/setIdP=> [Kx | [Gx /eqP chi_x]]. by rewrite (subsetP (cfker_sub chi)) // cfker1. case/char_reprP: Nchi => rG -> in chi_x *; rewrite inE Gx; apply/forallP=> y. rewrite !cfunE groupMl // !mulrb; case: ifP => // Gy. by rewrite repr_mxM // max_cfRepr_mx1 ?mul1mx. Qed. Lemma cfker_nzcharE chi : chi \is a character -> chi != 0 -> cfker chi = [set x | chi x == chi 1%g]. Proof. move=> Nchi nzchi; apply/setP=> x; rewrite cfkerEchar // !inE andb_idl //. by apply: contraLR => /cfun0-> //; rewrite eq_sym char1_eq0. Qed. Lemma cfkerEirr i : cfker 'chi[G]_i = [set x | 'chi_i x == 'chi_i 1%g]. Proof. by rewrite cfker_nzcharE ?irr_char ?irr_neq0. Qed. Lemma cfker_irr0 : cfker 'chi[G]_0 = G. Proof. by rewrite irr0 cfker_cfun1. Qed. Lemma cfaithful_reg : cfaithful (cfReg G). Proof. apply/subsetP=> x; rewrite cfkerEchar ?cfReg_char // !inE !cfRegE eqxx. by case/andP=> _; apply: contraLR => /negbTE->; rewrite eq_sym neq0CG. Qed. Lemma cfkerE chi : chi \is a character -> cfker chi = G :&: \bigcap_(i in irr_constt chi) cfker 'chi_i. Proof. move=> Nchi; rewrite cfkerEchar //; apply/setP=> x; rewrite !inE. apply: andb_id2l => Gx; rewrite {1 2}[chi]cfun_sum_constt !sum_cfunE. apply/eqP/bigcapP=> [Kx i Ci | Kx]; last first. by apply: eq_bigr => i /Kx Kx_i; rewrite !cfunE cfker1. rewrite cfkerEirr inE /= -(inj_eq (mulfI Ci)). have:= (normC_sum_upper _ Kx) i; rewrite !cfunE => -> // {Ci}i _. have chi_i_ge0: 0 <= '[chi, 'chi_i]. by rewrite natr_ge0 ?Cnat_cfdot_char_irr. by rewrite !cfunE normrM (normr_idP _) ?ler_wpM2l ?char1_ge_norm ?irr_char. Qed. Lemma TI_cfker_irr : \bigcap_i cfker 'chi[G]_i = [1]. Proof. apply/trivgP; apply: subset_trans cfaithful_reg; rewrite cfkerE ?cfReg_char //. rewrite subsetI (bigcap_min 0) //=; last by rewrite cfker_irr0. by apply/bigcapsP=> i _; rewrite bigcap_inf. Qed. Lemma cfker_constt i chi : chi \is a character -> i \in irr_constt chi -> cfker chi \subset cfker 'chi[G]_i. Proof. by move=> Nchi Ci; rewrite cfkerE ?subIset ?(bigcap_min i) ?orbT. Qed. Section KerLin. Variable xi : 'CF(G). Hypothesis lin_xi : xi \is a linear_char. Let Nxi: xi \is a character. Proof. by have [] := andP lin_xi. Qed. Lemma lin_char_der1 : G^`(1)%g \subset cfker xi. Proof. rewrite gen_subG /=; apply/subsetP=> _ /imset2P[x y Gx Gy ->]. rewrite cfkerEchar // inE groupR //= !lin_charM ?lin_charV ?in_group //. by rewrite mulrCA mulKf ?mulVf ?lin_char_neq0 // lin_char1. Qed. Lemma cforder_lin_char : #[xi]%CF = exponent (G / cfker xi)%g. Proof. apply/eqP; rewrite eqn_dvd; apply/andP; split. apply/dvdn_cforderP=> x Gx; rewrite -lin_charX // -cfQuoEker ?groupX //. rewrite morphX ?(subsetP (cfker_norm xi)) //= expg_exponent ?mem_quotient //. by rewrite cfQuo1 ?cfker_normal ?lin_char1. have abGbar: abelian (G / cfker xi) := sub_der1_abelian lin_char_der1. have [_ /morphimP[x Nx Gx ->] ->] := exponent_witness (abelian_nil abGbar). rewrite order_dvdn -morphX //= coset_id cfkerEchar // !inE groupX //=. by rewrite lin_charX ?lin_char1 // (dvdn_cforderP _ _ _). Qed. Lemma cforder_lin_char_dvdG : #[xi]%CF %| #|G|. Proof. by rewrite cforder_lin_char (dvdn_trans (exponent_dvdn _)) ?dvdn_morphim. Qed. Lemma cforder_lin_char_gt0 : (0 < #[xi]%CF)%N. Proof. by rewrite cforder_lin_char exponent_gt0. Qed. End KerLin. End Kernel. Section Restrict. Variable (gT : finGroupType) (G H : {group gT}). Lemma cfRepr_sub n (rG : mx_representation algC G n) (sHG : H \subset G) : cfRepr (subg_repr rG sHG) = 'Res[H] (cfRepr rG). Proof. by apply/cfun_inP => x Hx; rewrite cfResE // !cfunE Hx (subsetP sHG). Qed. Lemma cfRes_char chi : chi \is a character -> 'Res[H, G] chi \is a character. Proof. have [sHG | not_sHG] := boolP (H \subset G). by case/char_reprP=> rG ->; rewrite -(cfRepr_sub rG sHG) cfRepr_char. by move/Cnat_char1=> Nchi1; rewrite cfResEout // rpredZ_nat ?rpred1. Qed. Lemma cfRes_eq0 phi : phi \is a character -> ('Res[H, G] phi == 0) = (phi == 0). Proof. by move=> Nchi; rewrite -!char1_eq0 ?cfRes_char // cfRes1. Qed. Lemma cfRes_lin_char chi : chi \is a linear_char -> 'Res[H, G] chi \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfRes_char ?cfRes1. Qed. Lemma Res_irr_neq0 i : 'Res[H, G] 'chi_i != 0. Proof. by rewrite cfRes_eq0 ?irr_neq0 ?irr_char. Qed. Lemma cfRes_lin_lin (chi : 'CF(G)) : chi \is a character -> 'Res[H] chi \is a linear_char -> chi \is a linear_char. Proof. by rewrite !qualifE/= !qualifE/= cfRes1 => -> /andP[]. Qed. Lemma cfRes_irr_irr chi : chi \is a character -> 'Res[H] chi \in irr H -> chi \in irr G. Proof. have [sHG /char_reprP[rG ->] | not_sHG Nchi] := boolP (H \subset G). rewrite -(cfRepr_sub _ sHG) => /irr_reprP[rH irrH def_rH]; apply/irr_reprP. suffices /subg_mx_irr: mx_irreducible (subg_repr rG sHG) by exists rG. by apply: mx_rsim_irr irrH; apply/cfRepr_rsimP/eqP. rewrite cfResEout // => /irrP[j Dchi_j]; apply/lin_char_irr/cfRes_lin_lin=> //. suffices j0: j = 0 by rewrite cfResEout // Dchi_j j0 irr0 rpred1. apply: contraNeq (irr1_neq0 j) => nz_j. have:= xcfun_id j 0; rewrite -Dchi_j cfunE xcfunZl -irr0 xcfun_id eqxx => ->. by rewrite (negPf nz_j). Qed. Definition Res_Iirr (A B : {set gT}) i := cfIirr ('Res[B, A] 'chi_i). Lemma Res_Iirr0 : Res_Iirr H (0 : Iirr G) = 0. Proof. by rewrite /Res_Iirr irr0 rmorph1 -irr0 irrK. Qed. Lemma lin_Res_IirrE i : 'chi[G]_i 1%g = 1 -> 'chi_(Res_Iirr H i) = 'Res 'chi_i. Proof. move=> chi1; rewrite cfIirrE ?lin_char_irr ?cfRes_lin_char //. by rewrite qualifE/= irr_char /= chi1. Qed. End Restrict. Arguments Res_Iirr {gT A%_g} B%_g i%_R. Section MoreConstt. Variables (gT : finGroupType) (G H : {group gT}). Lemma constt_Ind_Res i j : i \in irr_constt ('Ind[G] 'chi_j) = (j \in irr_constt ('Res[H] 'chi_i)). Proof. by rewrite !irr_consttE cfdotC conjC_eq0 -cfdot_Res_l. Qed. Lemma cfdot_Res_ge_constt i j psi : psi \is a character -> j \in irr_constt psi -> '['Res[H, G] 'chi_j, 'chi_i] <= '['Res[H] psi, 'chi_i]. Proof. move=> {psi} _ /constt_charP[// | psi Npsi ->]. rewrite linearD cfdotDl addrC -subr_ge0 addrK natr_ge0 //=. by rewrite Cnat_cfdot_char_irr // cfRes_char. Qed. Lemma constt_Res_trans j psi : psi \is a character -> j \in irr_constt psi -> {subset irr_constt ('Res[H, G] 'chi_j) <= irr_constt ('Res[H] psi)}. Proof. move=> Npsi Cj i; apply: contraNneq; rewrite eq_le => {1}<-. rewrite cfdot_Res_ge_constt ?natr_ge0 ?Cnat_cfdot_char_irr //. by rewrite cfRes_char ?irr_char. Qed. End MoreConstt. Section Morphim. Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}). Implicit Type chi : 'CF(f @* G). Lemma cfRepr_morphim n (rfG : mx_representation algC (f @* G) n) sGD : cfRepr (morphim_repr rfG sGD) = cfMorph (cfRepr rfG). Proof. apply/cfun_inP=> x Gx; have Dx: x \in D := subsetP sGD x Gx. by rewrite cfMorphE // !cfunE ?mem_morphim ?Gx. Qed. Lemma cfMorph_char chi : chi \is a character -> cfMorph chi \is a character. Proof. have [sGD /char_reprP[rfG ->] | outGD Nchi] := boolP (G \subset D); last first. by rewrite cfMorphEout // rpredZ_nat ?rpred1 ?Cnat_char1. apply/char_reprP; exists (Representation (morphim_repr rfG sGD)). by rewrite cfRepr_morphim. Qed. Lemma cfMorph_lin_char chi : chi \is a linear_char -> cfMorph chi \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfMorph1 cfMorph_char. Qed. Lemma cfMorph_charE chi : G \subset D -> (cfMorph chi \is a character) = (chi \is a character). Proof. move=> sGD; apply/idP/idP=> [/char_reprP[[n rG] /=Dfchi] | /cfMorph_char//]. pose H := 'ker_G f; have kerH: H \subset rker rG. by rewrite -cfker_repr -Dfchi cfker_morph // setIS // ker_sub_pre. have nHG: G \subset 'N(H) by rewrite normsI // (subset_trans sGD) ?ker_norm. have [h injh im_h] := first_isom_loc f sGD; rewrite -/H in h injh im_h. have DfG: invm injh @*^-1 (G / H) == (f @* G)%g by rewrite morphpre_invm im_h. pose rfG := eqg_repr (morphpre_repr _ (quo_repr kerH nHG)) DfG. apply/char_reprP; exists (Representation rfG). apply/cfun_inP=> _ /morphimP[x Dx Gx ->]; rewrite -cfMorphE // Dfchi !cfunE Gx. pose xH := coset H x; have GxH: xH \in (G / H)%g by apply: mem_quotient. suffices Dfx: f x = h xH by rewrite mem_morphim //= Dfx invmE ?quo_repr_coset. by apply/set1_inj; rewrite -?morphim_set1 ?im_h ?(subsetP nHG) ?sub1set. Qed. Lemma cfMorph_lin_charE chi : G \subset D -> (cfMorph chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfMorph1 => /cfMorph_charE->. Qed. Lemma cfMorph_irr chi : G \subset D -> (cfMorph chi \in irr G) = (chi \in irr (f @* G)). Proof. by move=> sGD; rewrite !irrEchar cfMorph_charE // cfMorph_iso. Qed. Definition morph_Iirr i := cfIirr (cfMorph 'chi[f @* G]_i). Lemma morph_Iirr0 : morph_Iirr 0 = 0. Proof. by rewrite /morph_Iirr irr0 rmorph1 -irr0 irrK. Qed. Hypothesis sGD : G \subset D. Lemma morph_IirrE i : 'chi_(morph_Iirr i) = cfMorph 'chi_i. Proof. by rewrite cfIirrE ?cfMorph_irr ?mem_irr. Qed. Lemma morph_Iirr_inj : injective morph_Iirr. Proof. by move=> i j eq_ij; apply/irr_inj/cfMorph_inj; rewrite // -!morph_IirrE eq_ij. Qed. Lemma morph_Iirr_eq0 i : (morph_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 morph_IirrE cfMorph_eq1. Qed. End Morphim. Section Isom. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variables (R : {group rT}) (isoGR : isom G R f). Implicit Type chi : 'CF(G). Lemma cfIsom_char chi : (cfIsom isoGR chi \is a character) = (chi \is a character). Proof. rewrite [cfIsom _]locked_withE cfMorph_charE //. by rewrite (isom_im (isom_sym _)) cfRes_id. Qed. Lemma cfIsom_lin_char chi : (cfIsom isoGR chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfIsom_char cfIsom1. Qed. Lemma cfIsom_irr chi : (cfIsom isoGR chi \in irr R) = (chi \in irr G). Proof. by rewrite !irrEchar cfIsom_char cfIsom_iso. Qed. Definition isom_Iirr i := cfIirr (cfIsom isoGR 'chi_i). Lemma isom_IirrE i : 'chi_(isom_Iirr i) = cfIsom isoGR 'chi_i. Proof. by rewrite cfIirrE ?cfIsom_irr ?mem_irr. Qed. Lemma isom_Iirr_inj : injective isom_Iirr. Proof. by move=> i j eqij; apply/irr_inj/(cfIsom_inj isoGR); rewrite -!isom_IirrE eqij. Qed. Lemma isom_Iirr_eq0 i : (isom_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 isom_IirrE cfIsom_eq1. Qed. Lemma isom_Iirr0 : isom_Iirr 0 = 0. Proof. by apply/eqP; rewrite isom_Iirr_eq0. Qed. End Isom. Arguments isom_Iirr_inj {aT rT G f R} isoGR [i1 i2] : rename. Section IsomInv. Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}). Variables (R : {group rT}) (isoGR : isom G R f). Lemma isom_IirrK : cancel (isom_Iirr isoGR) (isom_Iirr (isom_sym isoGR)). Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomK. Qed. Lemma isom_IirrKV : cancel (isom_Iirr (isom_sym isoGR)) (isom_Iirr isoGR). Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomKV. Qed. End IsomInv. Section Sdprod. Variables (gT : finGroupType) (K H G : {group gT}). Hypothesis defG : K ><| H = G. Let nKG: G \subset 'N(K). Proof. by have [/andP[]] := sdprod_context defG. Qed. Lemma cfSdprod_char chi : (cfSdprod defG chi \is a character) = (chi \is a character). Proof. by rewrite unlock cfMorph_charE // cfIsom_char. Qed. Lemma cfSdprod_lin_char chi : (cfSdprod defG chi \is a linear_char) = (chi \is a linear_char). Proof. by rewrite qualifE/= cfSdprod_char cfSdprod1. Qed. Lemma cfSdprod_irr chi : (cfSdprod defG chi \in irr G) = (chi \in irr H). Proof. by rewrite !irrEchar cfSdprod_char cfSdprod_iso. Qed. Definition sdprod_Iirr j := cfIirr (cfSdprod defG 'chi_j). Lemma sdprod_IirrE j : 'chi_(sdprod_Iirr j) = cfSdprod defG 'chi_j. Proof. by rewrite cfIirrE ?cfSdprod_irr ?mem_irr. Qed. Lemma sdprod_IirrK : cancel sdprod_Iirr (Res_Iirr H). Proof. by move=> j; rewrite /Res_Iirr sdprod_IirrE cfSdprodK irrK. Qed. Lemma sdprod_Iirr_inj : injective sdprod_Iirr. Proof. exact: can_inj sdprod_IirrK. Qed. Lemma sdprod_Iirr_eq0 i : (sdprod_Iirr i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 sdprod_IirrE cfSdprod_eq1. Qed. Lemma sdprod_Iirr0 : sdprod_Iirr 0 = 0. Proof. by apply/eqP; rewrite sdprod_Iirr_eq0. Qed. Lemma Res_sdprod_irr phi : K \subset cfker phi -> phi \in irr G -> 'Res phi \in irr H. Proof. move=> kerK /irrP[i Dphi]; rewrite irrEchar -(cfSdprod_iso defG). by rewrite cfRes_sdprodK // Dphi cfnorm_irr cfRes_char ?irr_char /=. Qed. Lemma sdprod_Res_IirrE i : K \subset cfker 'chi[G]_i -> 'chi_(Res_Iirr H i) = 'Res 'chi_i. Proof. by move=> kerK; rewrite cfIirrE ?Res_sdprod_irr ?mem_irr. Qed. Lemma sdprod_Res_IirrK i : K \subset cfker 'chi_i -> sdprod_Iirr (Res_Iirr H i) = i. Proof. by move=> kerK; rewrite /sdprod_Iirr sdprod_Res_IirrE ?cfRes_sdprodK ?irrK. Qed. End Sdprod. Arguments sdprod_Iirr_inj {gT K H G} defG [i1 i2] : rename. Section DProd. Variables (gT : finGroupType) (G K H : {group gT}). Hypothesis KxH : K \x H = G. Lemma cfDprodKl_abelian j : abelian H -> cancel ((cfDprod KxH)^~ 'chi_j) 'Res. Proof. by move=> cHH; apply: cfDprodKl; apply/lin_char1/char_abelianP. Qed. Lemma cfDprodKr_abelian i : abelian K -> cancel (cfDprod KxH 'chi_i) 'Res. Proof. by move=> cKK; apply: cfDprodKr; apply/lin_char1/char_abelianP. Qed. Lemma cfDprodl_char phi : (cfDprodl KxH phi \is a character) = (phi \is a character). Proof. exact: cfSdprod_char. Qed. Lemma cfDprodr_char psi : (cfDprodr KxH psi \is a character) = (psi \is a character). Proof. exact: cfSdprod_char. Qed. Lemma cfDprod_char phi psi : phi \is a character -> psi \is a character -> cfDprod KxH phi psi \is a character. Proof. by move=> Nphi Npsi; rewrite rpredM ?cfDprodl_char ?cfDprodr_char. Qed. Lemma cfDprod_eq1 phi psi : phi \is a character -> psi \is a character -> (cfDprod KxH phi psi == 1) = (phi == 1) && (psi == 1). Proof. move=> /Cnat_char1 Nphi /Cnat_char1 Npsi. apply/eqP/andP=> [phi_psi_1 | [/eqP-> /eqP->]]; last by rewrite cfDprod_cfun1. have /andP[/eqP phi1 /eqP psi1]: (phi 1%g == 1) && (psi 1%g == 1). by rewrite -natr_mul_eq1 // -(cfDprod1 KxH) phi_psi_1 cfun11. rewrite -[phi](cfDprodKl KxH psi1) -{2}[psi](cfDprodKr KxH phi1) phi_psi_1. by rewrite !rmorph1. Qed. Lemma cfDprodl_lin_char phi : (cfDprodl KxH phi \is a linear_char) = (phi \is a linear_char). Proof. exact: cfSdprod_lin_char. Qed. Lemma cfDprodr_lin_char psi : (cfDprodr KxH psi \is a linear_char) = (psi \is a linear_char). Proof. exact: cfSdprod_lin_char. Qed. Lemma cfDprod_lin_char phi psi : phi \is a linear_char -> psi \is a linear_char -> cfDprod KxH phi psi \is a linear_char. Proof. by move=> Nphi Npsi; rewrite rpredM ?cfSdprod_lin_char. Qed. Lemma cfDprodl_irr chi : (cfDprodl KxH chi \in irr G) = (chi \in irr K). Proof. exact: cfSdprod_irr. Qed. Lemma cfDprodr_irr chi : (cfDprodr KxH chi \in irr G) = (chi \in irr H). Proof. exact: cfSdprod_irr. Qed. Definition dprodl_Iirr i := cfIirr (cfDprodl KxH 'chi_i). Lemma dprodl_IirrE i : 'chi_(dprodl_Iirr i) = cfDprodl KxH 'chi_i. Proof. exact: sdprod_IirrE. Qed. Lemma dprodl_IirrK : cancel dprodl_Iirr (Res_Iirr K). Proof. exact: sdprod_IirrK. Qed. Lemma dprodl_Iirr_eq0 i : (dprodl_Iirr i == 0) = (i == 0). Proof. exact: sdprod_Iirr_eq0. Qed. Lemma dprodl_Iirr0 : dprodl_Iirr 0 = 0. Proof. exact: sdprod_Iirr0. Qed. Definition dprodr_Iirr j := cfIirr (cfDprodr KxH 'chi_j). Lemma dprodr_IirrE j : 'chi_(dprodr_Iirr j) = cfDprodr KxH 'chi_j. Proof. exact: sdprod_IirrE. Qed. Lemma dprodr_IirrK : cancel dprodr_Iirr (Res_Iirr H). Proof. exact: sdprod_IirrK. Qed. Lemma dprodr_Iirr_eq0 j : (dprodr_Iirr j == 0) = (j == 0). Proof. exact: sdprod_Iirr_eq0. Qed. Lemma dprodr_Iirr0 : dprodr_Iirr 0 = 0. Proof. exact: sdprod_Iirr0. Qed. Lemma cfDprod_irr i j : cfDprod KxH 'chi_i 'chi_j \in irr G. Proof. rewrite irrEchar cfDprod_char ?irr_char //=. by rewrite cfdot_dprod !cfdot_irr !eqxx mul1r. Qed. Definition dprod_Iirr ij := cfIirr (cfDprod KxH 'chi_ij.1 'chi_ij.2). Lemma dprod_IirrE i j : 'chi_(dprod_Iirr (i, j)) = cfDprod KxH 'chi_i 'chi_j. Proof. by rewrite cfIirrE ?cfDprod_irr. Qed. Lemma dprod_IirrEl i : 'chi_(dprod_Iirr (i, 0)) = cfDprodl KxH 'chi_i. Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mulr1. Qed. Lemma dprod_IirrEr j : 'chi_(dprod_Iirr (0, j)) = cfDprodr KxH 'chi_j. Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mul1r. Qed. Lemma dprod_Iirr_inj : injective dprod_Iirr. Proof. move=> [i1 j1] [i2 j2] /eqP; rewrite -[_ == _]oddb -(@natrK algC (_ == _)). rewrite -cfdot_irr !dprod_IirrE cfdot_dprod !cfdot_irr -natrM mulnb. by rewrite natrK oddb -xpair_eqE => /eqP. Qed. Lemma dprod_Iirr0 : dprod_Iirr (0, 0) = 0. Proof. by apply/irr_inj; rewrite dprod_IirrE !irr0 cfDprod_cfun1. Qed. Lemma dprod_Iirr0l j : dprod_Iirr (0, j) = dprodr_Iirr j. Proof. by apply/irr_inj; rewrite dprod_IirrE irr0 dprodr_IirrE cfDprod_cfun1l. Qed. Lemma dprod_Iirr0r i : dprod_Iirr (i, 0) = dprodl_Iirr i. Proof. by apply/irr_inj; rewrite dprod_IirrE irr0 dprodl_IirrE cfDprod_cfun1r. Qed. Lemma dprod_Iirr_eq0 i j : (dprod_Iirr (i, j) == 0) = (i == 0) && (j == 0). Proof. by rewrite -xpair_eqE -(inj_eq dprod_Iirr_inj) dprod_Iirr0. Qed. Lemma cfdot_dprod_irr i1 i2 j1 j2 : '['chi_(dprod_Iirr (i1, j1)), 'chi_(dprod_Iirr (i2, j2))] = ((i1 == i2) && (j1 == j2))%:R. Proof. by rewrite cfdot_irr (inj_eq dprod_Iirr_inj). Qed. Lemma dprod_Iirr_onto k : k \in codom dprod_Iirr. Proof. set D := codom _; have Df: dprod_Iirr _ \in D := codom_f dprod_Iirr _. have: 'chi_k 1%g ^+ 2 != 0 by rewrite mulf_neq0 ?irr1_neq0. apply: contraR => notDk; move/eqP: (irr_sum_square G). rewrite (bigID [in D]) (reindex _ (bij_on_codom dprod_Iirr_inj (0, 0))) /=. have ->: #|G|%:R = \sum_i \sum_j 'chi_(dprod_Iirr (i, j)) 1%g ^+ 2. rewrite -(dprod_card KxH) natrM. do 2![rewrite -irr_sum_square (mulr_suml, mulr_sumr); apply: eq_bigr => ? _]. by rewrite dprod_IirrE -exprMn -{3}(mulg1 1%g) cfDprodE. rewrite (eq_bigl _ _ Df) pair_bigA addrC -subr_eq0 addrK. by move/eqP/psumr_eq0P=> -> //= i _; rewrite irr1_degree -natrX ler0n. Qed. Definition inv_dprod_Iirr i := iinv (dprod_Iirr_onto i). Lemma dprod_IirrK : cancel dprod_Iirr inv_dprod_Iirr. Proof. by move=> p; apply: (iinv_f dprod_Iirr_inj). Qed. Lemma inv_dprod_IirrK : cancel inv_dprod_Iirr dprod_Iirr. Proof. by move=> i; apply: f_iinv. Qed. Lemma inv_dprod_Iirr0 : inv_dprod_Iirr 0 = (0, 0). Proof. by apply/(canLR dprod_IirrK); rewrite dprod_Iirr0. Qed. End DProd. Arguments dprod_Iirr_inj {gT G K H} KxH [i1 i2] : rename. Lemma dprod_IirrC (gT : finGroupType) (G K H : {group gT}) (KxH : K \x H = G) (HxK : H \x K = G) i j : dprod_Iirr KxH (i, j) = dprod_Iirr HxK (j, i). Proof. by apply: irr_inj; rewrite !dprod_IirrE; apply: cfDprodC. Qed. Section BigDprod. Variables (gT : finGroupType) (I : finType) (P : pred I). Variables (A : I -> {group gT}) (G : {group gT}). Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G. Let sAG i : P i -> A i \subset G. Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed. Lemma cfBigdprodi_char i (phi : 'CF(A i)) : phi \is a character -> cfBigdprodi defG phi \is a character. Proof. by move=> Nphi; rewrite cfDprodl_char cfRes_char. Qed. Lemma cfBigdprodi_charE i (phi : 'CF(A i)) : P i -> (cfBigdprodi defG phi \is a character) = (phi \is a character). Proof. by move=> Pi; rewrite cfDprodl_char Pi cfRes_id. Qed. Lemma cfBigdprod_char phi : (forall i, P i -> phi i \is a character) -> cfBigdprod defG phi \is a character. Proof. by move=> Nphi; apply: rpred_prod => i /Nphi; apply: cfBigdprodi_char. Qed. Lemma cfBigdprodi_lin_char i (phi : 'CF(A i)) : phi \is a linear_char -> cfBigdprodi defG phi \is a linear_char. Proof. by move=> Lphi; rewrite cfDprodl_lin_char ?cfRes_lin_char. Qed. Lemma cfBigdprodi_lin_charE i (phi : 'CF(A i)) : P i -> (cfBigdprodi defG phi \is a linear_char) = (phi \is a linear_char). Proof. by move=> Pi; rewrite qualifE/= cfBigdprodi_charE // cfBigdprodi1. Qed. Lemma cfBigdprod_lin_char phi : (forall i, P i -> phi i \is a linear_char) -> cfBigdprod defG phi \is a linear_char. Proof. by move=> Lphi; apply/rpred_prod=> i /Lphi; apply: cfBigdprodi_lin_char. Qed. Lemma cfBigdprodi_irr i chi : P i -> (cfBigdprodi defG chi \in irr G) = (chi \in irr (A i)). Proof. by move=> Pi; rewrite !irrEchar cfBigdprodi_charE ?cfBigdprodi_iso. Qed. Lemma cfBigdprod_irr chi : (forall i, P i -> chi i \in irr (A i)) -> cfBigdprod defG chi \in irr G. Proof. move=> Nchi; rewrite irrEchar cfBigdprod_char => [|i /Nchi/irrWchar] //=. by rewrite cfdot_bigdprod big1 // => i /Nchi/irrWnorm. Qed. Lemma cfBigdprod_eq1 phi : (forall i, P i -> phi i \is a character) -> (cfBigdprod defG phi == 1) = [forall (i | P i), phi i == 1]. Proof. move=> Nphi; set Phi := cfBigdprod defG phi. apply/eqP/eqfun_inP=> [Phi1 i Pi | phi1]; last first. by apply: big1 => i /phi1->; rewrite rmorph1. have Phi1_1: Phi 1%g = 1 by rewrite Phi1 cfun1E group1. have nz_Phi1: Phi 1%g != 0 by rewrite Phi1_1 oner_eq0. have [_ <-] := cfBigdprodK nz_Phi1 Pi. rewrite Phi1_1 divr1 -/Phi Phi1 rmorph1. rewrite prod_cfunE // in Phi1_1; have := natr_prod_eq1 _ Phi1_1 Pi. rewrite -(cfRes1 (A i)) cfBigdprodiK // => ->; first by rewrite scale1r. by move=> {i Pi} j /Nphi Nphi_j; rewrite Cnat_char1 ?cfBigdprodi_char. Qed. Lemma cfBigdprod_Res_lin chi : chi \is a linear_char -> cfBigdprod defG (fun i => 'Res[A i] chi) = chi. Proof. move=> Lchi; apply/cfun_inP=> _ /(mem_bigdprod defG)[x [Ax -> _]]. rewrite (lin_char_prod Lchi) ?cfBigdprodE // => [|i Pi]; last first. by rewrite (subsetP (sAG Pi)) ?Ax. by apply/eq_bigr=> i Pi; rewrite cfResE ?sAG ?Ax. Qed. Lemma cfBigdprodKlin phi : (forall i, P i -> phi i \is a linear_char) -> forall i, P i -> 'Res (cfBigdprod defG phi) = phi i. Proof. move=> Lphi i Pi; have Lpsi := cfBigdprod_lin_char Lphi. have [_ <-] := cfBigdprodK (lin_char_neq0 Lpsi (group1 G)) Pi. by rewrite !lin_char1 ?Lphi // divr1 scale1r. Qed. Lemma cfBigdprodKabelian Iphi (phi := fun i => 'chi_(Iphi i)) : abelian G -> forall i, P i -> 'Res (cfBigdprod defG phi) = 'chi_(Iphi i). Proof. move=> /(abelianS _) cGG. by apply: cfBigdprodKlin => i /sAG/cGG/char_abelianP->. Qed. End BigDprod. Section Aut. Variables (gT : finGroupType) (G : {group gT}). Implicit Type u : {rmorphism algC -> algC}. Lemma conjC_charAut u (chi : 'CF(G)) x : chi \is a character -> (u (chi x))^* = u (chi x)^*. Proof. have [Gx | /cfun0->] := boolP (x \in G); last by rewrite !rmorph0. case/char_reprP=> rG ->; have [e [_ [en1 _] [-> _] _]] := repr_rsim_diag rG Gx. by rewrite !rmorph_sum; apply: eq_bigr => i _; apply: aut_unity_rootC (en1 i). Qed. Lemma conjC_irrAut u i x : (u ('chi[G]_i x))^* = u ('chi_i x)^*. Proof. exact: conjC_charAut (irr_char i). Qed. Lemma cfdot_aut_char u (phi chi : 'CF(G)) : chi \is a character -> '[cfAut u phi, cfAut u chi] = u '[phi, chi]. Proof. by move/conjC_charAut=> Nchi; apply: cfdot_cfAut => _ /mapP[x _ ->]. Qed. Lemma cfdot_aut_irr u phi i : '[cfAut u phi, cfAut u 'chi[G]_i] = u '[phi, 'chi_i]. Proof. exact: cfdot_aut_char (irr_char i). Qed. Lemma cfAut_irr u chi : (cfAut u chi \in irr G) = (chi \in irr G). Proof. rewrite !irrEchar cfAut_char; apply/andb_id2l=> /cfdot_aut_char->. exact: fmorph_eq1. Qed. Lemma cfConjC_irr i : (('chi_i)^*)%CF \in irr G. Proof. by rewrite cfAut_irr mem_irr. Qed. Lemma irr_aut_closed u : cfAut_closed u (irr G). Proof. by move=> chi; rewrite /= cfAut_irr. Qed. Definition aut_Iirr u i := cfIirr (cfAut u 'chi[G]_i). Lemma aut_IirrE u i : 'chi_(aut_Iirr u i) = cfAut u 'chi_i. Proof. by rewrite cfIirrE ?cfAut_irr ?mem_irr. Qed. Definition conjC_Iirr := aut_Iirr conjC. Lemma conjC_IirrE i : 'chi[G]_(conjC_Iirr i) = ('chi_i)^*%CF. Proof. exact: aut_IirrE. Qed. Lemma conjC_IirrK : involutive conjC_Iirr. Proof. by move=> i; apply: irr_inj; rewrite !conjC_IirrE cfConjCK. Qed. Lemma aut_Iirr0 u : aut_Iirr u 0 = 0 :> Iirr G. Proof. by apply/irr_inj; rewrite aut_IirrE irr0 cfAut_cfun1. Qed. Lemma conjC_Iirr0 : conjC_Iirr 0 = 0 :> Iirr G. Proof. exact: aut_Iirr0. Qed. Lemma aut_Iirr_eq0 u i : (aut_Iirr u i == 0) = (i == 0). Proof. by rewrite -!irr_eq1 aut_IirrE cfAut_eq1. Qed. Lemma conjC_Iirr_eq0 i : (conjC_Iirr i == 0 :> Iirr G) = (i == 0). Proof. exact: aut_Iirr_eq0. Qed. Lemma aut_Iirr_inj u : injective (aut_Iirr u). Proof. by move=> i j eq_ij; apply/irr_inj/(cfAut_inj u); rewrite -!aut_IirrE eq_ij. Qed. End Aut. Arguments aut_Iirr_inj {gT G} u [i1 i2] : rename. Arguments conjC_IirrK {gT G} i : rename. Section Coset. Variable (gT : finGroupType). Implicit Types G H : {group gT}. Lemma cfQuo_char G H (chi : 'CF(G)) : chi \is a character -> (chi / H)%CF \is a character. Proof. move=> Nchi; without loss kerH: / H \subset cfker chi. move/contraNF=> IHchi; apply/wlog_neg=> N'chiH. suffices ->: (chi / H)%CF = (chi 1%g)%:A. by rewrite rpredZ_nat ?Cnat_char1 ?rpred1. by apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr cfunElock IHchi. without loss nsHG: G chi Nchi kerH / H <| G. move=> IHchi; have nsHN := normalSG (subset_trans kerH (cfker_sub chi)). rewrite cfQuoInorm//; apply/cfRes_char/IHchi => //; first exact: cfRes_char. by apply: sub_cfker_Res => //; apply: normal_sub. have [rG Dchi] := char_reprP Nchi; rewrite Dchi cfker_repr in kerH. apply/char_reprP; exists (Representation (quo_repr kerH (normal_norm nsHG))). apply/cfun_inP=> _ /morphimP[x nHx Gx ->]; rewrite Dchi cfQuoE ?cfker_repr //=. by rewrite !cfunE Gx quo_repr_coset ?mem_quotient. Qed. Lemma cfQuo_lin_char G H (chi : 'CF(G)) : chi \is a linear_char -> (chi / H)%CF \is a linear_char. Proof. by case/andP=> Nchi; rewrite qualifE/= cfQuo_char ?cfQuo1. Qed. Lemma cfMod_char G H (chi : 'CF(G / H)) : chi \is a character -> (chi %% H)%CF \is a character. Proof. exact: cfMorph_char. Qed. Lemma cfMod_lin_char G H (chi : 'CF(G / H)) : chi \is a linear_char -> (chi %% H)%CF \is a linear_char. Proof. exact: cfMorph_lin_char. Qed. Lemma cfMod_charE G H (chi : 'CF(G / H)) : H <| G -> (chi %% H \is a character)%CF = (chi \is a character). Proof. by case/andP=> _; apply: cfMorph_charE. Qed. Lemma cfMod_lin_charE G H (chi : 'CF(G / H)) : H <| G -> (chi %% H \is a linear_char)%CF = (chi \is a linear_char). Proof. by case/andP=> _; apply: cfMorph_lin_charE. Qed. Lemma cfQuo_charE G H (chi : 'CF(G)) : H <| G -> H \subset cfker chi -> (chi / H \is a character)%CF = (chi \is a character). Proof. by move=> nsHG kerH; rewrite -cfMod_charE ?cfQuoK. Qed. Lemma cfQuo_lin_charE G H (chi : 'CF(G)) : H <| G -> H \subset cfker chi -> (chi / H \is a linear_char)%CF = (chi \is a linear_char). Proof. by move=> nsHG kerH; rewrite -cfMod_lin_charE ?cfQuoK. Qed. Lemma cfMod_irr G H chi : H <| G -> (chi %% H \in irr G)%CF = (chi \in irr (G / H)). Proof. by case/andP=> _; apply: cfMorph_irr. Qed. Definition mod_Iirr G H i := cfIirr ('chi[G / H]_i %% H)%CF. Lemma mod_Iirr0 G H : mod_Iirr (0 : Iirr (G / H)) = 0. Proof. exact: morph_Iirr0. Qed. Lemma mod_IirrE G H i : H <| G -> 'chi_(mod_Iirr i) = ('chi[G / H]_i %% H)%CF. Proof. by move=> nsHG; rewrite cfIirrE ?cfMod_irr ?mem_irr. Qed. Lemma mod_Iirr_eq0 G H i : H <| G -> (mod_Iirr i == 0) = (i == 0 :> Iirr (G / H)). Proof. by case/andP=> _ /morph_Iirr_eq0->. Qed. Lemma cfQuo_irr G H chi : H <| G -> H \subset cfker chi -> ((chi / H)%CF \in irr (G / H)) = (chi \in irr G). Proof. by move=> nsHG kerH; rewrite -cfMod_irr ?cfQuoK. Qed. Definition quo_Iirr G H i := cfIirr ('chi[G]_i / H)%CF. Lemma quo_Iirr0 G H : quo_Iirr H (0 : Iirr G) = 0. Proof. by rewrite /quo_Iirr irr0 cfQuo_cfun1 -irr0 irrK. Qed. Lemma quo_IirrE G H i : H <| G -> H \subset cfker 'chi[G]_i -> 'chi_(quo_Iirr H i) = ('chi_i / H)%CF. Proof. by move=> nsHG kerH; rewrite cfIirrE ?cfQuo_irr ?mem_irr. Qed. Lemma quo_Iirr_eq0 G H i : H <| G -> H \subset cfker 'chi[G]_i -> (quo_Iirr H i == 0) = (i == 0). Proof. by move=> nsHG kerH; rewrite -!irr_eq1 quo_IirrE ?cfQuo_eq1. Qed. Lemma mod_IirrK G H : H <| G -> cancel (@mod_Iirr G H) (@quo_Iirr G H). Proof. move=> nsHG i; apply: irr_inj. by rewrite quo_IirrE ?mod_IirrE ?cfker_mod // cfModK. Qed. Lemma quo_IirrK G H i : H <| G -> H \subset cfker 'chi[G]_i -> mod_Iirr (quo_Iirr H i) = i. Proof. by move=> nsHG kerH; apply: irr_inj; rewrite mod_IirrE ?quo_IirrE ?cfQuoK. Qed. Lemma quo_IirrKeq G H : H <| G -> forall i, (mod_Iirr (quo_Iirr H i) == i) = (H \subset cfker 'chi[G]_i). Proof. move=> nsHG i; apply/eqP/idP=> [<- | ]; last exact: quo_IirrK. by rewrite mod_IirrE ?cfker_mod. Qed. Lemma mod_Iirr_bij H G : H <| G -> {on [pred i | H \subset cfker 'chi_i], bijective (@mod_Iirr G H)}. Proof. by exists (quo_Iirr H) => [i _ | i]; [apply: mod_IirrK | apply: quo_IirrK]. Qed. Lemma sum_norm_irr_quo H G x : x \in G -> H <| G -> \sum_i `|'chi[G / H]_i (coset H x)| ^+ 2 = \sum_(i | H \subset cfker 'chi_i) `|'chi[G]_i x| ^+ 2. Proof. move=> Gx nsHG; rewrite (reindex _ (mod_Iirr_bij nsHG)) /=. by apply/esym/eq_big=> [i | i _]; rewrite mod_IirrE ?cfker_mod ?cfModE. Qed. Lemma cap_cfker_normal G H : H <| G -> \bigcap_(i | H \subset cfker 'chi[G]_i) (cfker 'chi_i) = H. Proof. move=> nsHG; have [sHG nHG] := andP nsHG; set lhs := \bigcap_(i | _) _. have nHlhs: lhs \subset 'N(H) by rewrite (bigcap_min 0) ?cfker_irr0. apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) //= -quotient_sub1 //. rewrite -(TI_cfker_irr (G / H)); apply/bigcapsP=> i _. rewrite sub_quotient_pre // (bigcap_min (mod_Iirr i)) ?mod_IirrE ?cfker_mod //. by rewrite cfker_morph ?subsetIr. Qed. Lemma cfker_reg_quo G H : H <| G -> cfker (cfReg (G / H)%g %% H) = H. Proof. move=> nsHG; have [sHG nHG] := andP nsHG. apply/setP=> x; rewrite cfkerEchar ?cfMod_char ?cfReg_char //. rewrite -[in RHS in _ = RHS](setIidPr sHG) !inE; apply: andb_id2l => Gx. rewrite !cfModE // !cfRegE // morph1 eqxx. rewrite (sameP eqP (kerP _ (subsetP nHG x Gx))) ker_coset. by rewrite -!mulrnA eqr_nat eqn_pmul2l ?cardG_gt0 // (can_eq oddb) eqb_id. Qed. End Coset. Section DerivedGroup. Variable gT : finGroupType. Implicit Types G H : {group gT}. Lemma lin_irr_der1 G i : ('chi_i \is a linear_char) = (G^`(1)%g \subset cfker 'chi[G]_i). Proof. apply/idP/idP=> [|sG'K]; first exact: lin_char_der1. have nsG'G: G^`(1) <| G := der_normal 1 G. rewrite qualifE/= irr_char -[i](quo_IirrK nsG'G) // mod_IirrE //=. by rewrite cfModE // morph1 lin_char1 //; apply/char_abelianP/der_abelian. Qed. Lemma subGcfker G i : (G \subset cfker 'chi[G]_i) = (i == 0). Proof. rewrite -irr_eq1; apply/idP/eqP=> [chiG1 | ->]; last by rewrite cfker_cfun1. apply/cfun_inP=> x Gx; rewrite cfun1E Gx cfker1 ?(subsetP chiG1) ?lin_char1 //. by rewrite lin_irr_der1 (subset_trans (der_sub 1 G)). Qed. Lemma irr_prime_injP G i : prime #|G| -> reflect {in G &, injective 'chi[G]_i} (i != 0). Proof. move=> pr_G; apply: (iffP idP) => [nz_i | inj_chi]. apply: fful_lin_char_inj (irr_prime_lin i pr_G) _. by rewrite cfaithfulE -(setIidPr (cfker_sub _)) prime_TIg // subGcfker. have /trivgPn[x Gx ntx]: G :!=: 1%g by rewrite -cardG_gt1 prime_gt1. apply: contraNneq ntx => i0; apply/eqP/inj_chi=> //. by rewrite i0 irr0 !cfun1E Gx group1. Qed. (* This is Isaacs (2.23)(a). *) Lemma cap_cfker_lin_irr G : \bigcap_(i | 'chi[G]_i \is a linear_char) (cfker 'chi_i) = G^`(1)%g. Proof. rewrite -(cap_cfker_normal (der_normal 1 G)). by apply: eq_bigl => i; rewrite lin_irr_der1. Qed. (* This is Isaacs (2.23)(b) *) Lemma card_lin_irr G : #|[pred i | 'chi[G]_i \is a linear_char]| = #|G : G^`(1)%g|. Proof. have nsG'G := der_normal 1 G; rewrite (eq_card (@lin_irr_der1 G)). rewrite -(on_card_preimset (mod_Iirr_bij nsG'G)). rewrite -card_quotient ?normal_norm //. move: (der_abelian 0 G); rewrite card_classes_abelian; move/eqP<-. rewrite -NirrE -[RHS]card_ord. by apply: eq_card => i; rewrite !inE mod_IirrE ?cfker_mod. (* Alternative: use the equivalent result in modular representation theory transitivity #|@socle_of_Iirr _ G @^-1: linear_irr _|; last first. rewrite (on_card_preimset (socle_of_Iirr_bij _)). by rewrite card_linear_irr ?algC'G; last apply: groupC. by apply: eq_card => i; rewrite !inE /lin_char irr_char irr1_degree -eqC_nat. *) Qed. (* A non-trivial solvable group has a nonprincipal linear character. *) Lemma solvable_has_lin_char G : G :!=: 1%g -> solvable G -> exists2 i, 'chi[G]_i \is a linear_char & 'chi_i != 1. Proof. move=> ntG solG. suff /subsetPn[i]: ~~ ([pred i | 'chi[G]_i \is a linear_char] \subset pred1 0). by rewrite !inE -(inj_eq irr_inj) irr0; exists i. rewrite (contra (@subset_leq_card _ _ _)) // -ltnNge card1 card_lin_irr. by rewrite indexg_gt1 proper_subn // (sol_der1_proper solG). Qed. (* A combinatorial group isommorphic to the linear characters. *) Lemma lin_char_group G : {linG : finGroupType & {cF : linG -> 'CF(G) | [/\ injective cF, #|linG| = #|G : G^`(1)|, forall u, cF u \is a linear_char & forall phi, phi \is a linear_char -> exists u, phi = cF u] & [/\ cF 1%g = 1%R, {morph cF : u v / (u * v)%g >-> (u * v)%R}, forall k, {morph cF : u / (u^+ k)%g >-> u ^+ k}, {morph cF: u / u^-1%g >-> u^-1%CF} & {mono cF: u / #[u]%g >-> #[u]%CF} ]}}. Proof. pose linT := {i : Iirr G | 'chi_i \is a linear_char}. pose cF (u : linT) := 'chi_(sval u). have cFlin u: cF u \is a linear_char := svalP u. have cFinj: injective cF := inj_comp irr_inj val_inj. have inT xi : xi \is a linear_char -> {u | cF u = xi}. move=> lin_xi; have /irrP/sig_eqW[i Dxi] := lin_char_irr lin_xi. by apply: (exist _ (Sub i _)) => //; rewrite -Dxi. have [one cFone] := inT 1 (rpred1 _). pose inv u := sval (inT _ (rpredVr (cFlin u))). pose mul u v := sval (inT _ (rpredM (cFlin u) (cFlin v))). have cFmul u v: cF (mul u v) = cF u * cF v := svalP (inT _ _). have cFinv u: cF (inv u) = (cF u)^-1 := svalP (inT _ _). have mulA: associative mul by move=> u v w; apply: cFinj; rewrite !cFmul mulrA. have mul1: left_id one mul by move=> u; apply: cFinj; rewrite cFmul cFone mul1r. have mulV: left_inverse one inv mul. by move=> u; apply: cFinj; rewrite cFmul cFinv cFone mulVr ?lin_char_unitr. pose imA := isMulGroup.Build linT mulA mul1 mulV. pose linG : finGroupType := HB.pack linT imA. have cFexp k: {morph cF : u / ((u : linG) ^+ k)%g >-> u ^+ k}. by move=> u; elim: k => // k IHk; rewrite expgS exprS cFmul IHk. do [exists linG, cF; split=> //] => [|xi /inT[u <-]|u]; first 2 [by exists u]. have inj_cFI: injective (cfIirr \o cF). apply: can_inj (insubd one) _ => u; apply: val_inj. by rewrite insubdK /= ?irrK //; apply: cFlin. rewrite -(card_image inj_cFI) -card_lin_irr. apply/eq_card=> i /[1!inE]; apply/codomP/idP=> [[u ->] | /inT[u Du]]. by rewrite /= irrK; apply: cFlin. by exists u; apply: irr_inj; rewrite /= irrK. apply/eqP; rewrite eqn_dvd; apply/andP; split. by rewrite dvdn_cforder; rewrite -cFexp expg_order cFone. by rewrite order_dvdn -(inj_eq cFinj) cFone cFexp exp_cforder. Qed. Lemma cfExp_prime_transitive G (i j : Iirr G) : prime #|G| -> i != 0 -> j != 0 -> exists2 k, coprime k #['chi_i]%CF & 'chi_j = 'chi_i ^+ k. Proof. set p := #|G| => pr_p nz_i nz_j; have cycG := prime_cyclic pr_p. have [L [h [injh oL Lh h_ontoL]] [h1 hM hX _ o_h]] := lin_char_group G. rewrite (derG1P (cyclic_abelian cycG)) indexg1 -/p in oL. have /fin_all_exists[h' h'K] := h_ontoL _ (irr_cyclic_lin _ cycG). have o_h' k: k != 0 -> #[h' k] = p. rewrite -cforder_irr_eq1 h'K -o_h => nt_h'k. by apply/prime_nt_dvdP=> //; rewrite cforder_lin_char_dvdG. have{oL} genL k: k != 0 -> generator [set: L] (h' k). move=> /o_h' o_h'k; rewrite /generator eq_sym eqEcard subsetT /=. by rewrite cardsT oL -o_h'k. have [/(_ =P <[_]>)-> gen_j] := (genL i nz_i, genL j nz_j). have /cycleP[k Dj] := cycle_generator gen_j. by rewrite !h'K Dj o_h hX generator_coprime coprime_sym in gen_j *; exists k. Qed. (* This is Isaacs (2.24). *) Lemma card_subcent1_coset G H x : x \in G -> H <| G -> (#|'C_(G / H)[coset H x]| <= #|'C_G[x]|)%N. Proof. move=> Gx nsHG; rewrite -leC_nat. move: (second_orthogonality_relation x Gx); rewrite mulrb class_refl => <-. have GHx: coset H x \in (G / H)%g by apply: mem_quotient. move: (second_orthogonality_relation (coset H x) GHx). rewrite mulrb class_refl => <-. rewrite -2!(eq_bigr _ (fun _ _ => normCK _)) sum_norm_irr_quo // -subr_ge0. rewrite (bigID (fun i => H \subset cfker 'chi[G]_i)) //= [X in X + _]addrC addrK. by apply: sumr_ge0 => i _; rewrite normCK mul_conjC_ge0. Qed. End DerivedGroup. Arguments irr_prime_injP {gT G i}. (* Determinant characters and determinential order. *) Section DetRepr. Variables (gT : finGroupType) (G : {group gT}). Variables (n : nat) (rG : mx_representation algC G n). Definition det_repr_mx x : 'M_1 := (\det (rG x))%:M. Fact det_is_repr : mx_repr G det_repr_mx. Proof. split=> [|g h Gg Gh]; first by rewrite /det_repr_mx repr_mx1 det1. by rewrite /det_repr_mx repr_mxM // det_mulmx !mulmxE scalar_mxM. Qed. Canonical det_repr := MxRepresentation det_is_repr. Definition detRepr := cfRepr det_repr. Lemma detRepr_lin_char : detRepr \is a linear_char. Proof. by rewrite qualifE/= cfRepr_char cfunE group1 repr_mx1 mxtrace1 mulr1n /=. Qed. End DetRepr. HB.lock Definition cfDet (gT : finGroupType) (G : {group gT}) phi := \prod_i detRepr 'Chi_i ^+ Num.truncn '[phi, 'chi[G]_i]. Canonical cfDet_unlockable := Unlockable cfDet.unlock. Section DetOrder. Variables (gT : finGroupType) (G : {group gT}). Local Notation cfDet := (@cfDet gT G). Lemma cfDet_lin_char phi : cfDet phi \is a linear_char. Proof. rewrite unlock; apply: rpred_prod => i _; apply: rpredX. exact: detRepr_lin_char. Qed. Lemma cfDetD : {in character &, {morph cfDet : phi psi / phi + psi >-> phi * psi}}. Proof. move=> phi psi Nphi Npsi; rewrite unlock /= -big_split; apply: eq_bigr => i _ /=. by rewrite -exprD cfdotDl truncnD ?nnegrE ?natr_ge0 // Cnat_cfdot_char_irr. Qed. Lemma cfDet0 : cfDet 0 = 1. Proof. by rewrite unlock big1 // => i _; rewrite cfdot0l truncn0. Qed. Lemma cfDetMn k : {in character, {morph cfDet : phi / phi *+ k >-> phi ^+ k}}. Proof. move=> phi Nphi; elim: k => [|k IHk]; rewrite ?cfDet0 // mulrS exprS -{}IHk. by rewrite cfDetD ?rpredMn. Qed. Lemma cfDetRepr n rG : cfDet (cfRepr rG) = @detRepr _ _ n rG. Proof. transitivity (\prod_W detRepr (socle_repr W) ^+ standard_irr_coef rG W). rewrite (reindex _ (socle_of_Iirr_bij _)) unlock /=. apply: eq_bigr => i _; congr (_ ^+ _). rewrite (cfRepr_sim (mx_rsim_standard rG)) cfRepr_standard. rewrite cfdot_suml (bigD1 i) ?big1 //= => [|j i'j]; last first. by rewrite cfdotZl cfdot_irr (negPf i'j) mulr0. by rewrite cfdotZl cfnorm_irr mulr1 addr0 natrK. apply/cfun_inP=> x Gx; rewrite prod_cfunE //. transitivity (detRepr (standard_grepr rG) x); last first. rewrite !cfunE Gx !trace_mx11 !mxE eqxx !mulrb. case: (standard_grepr rG) (mx_rsim_standard rG) => /= n1 rG1 [B Dn1]. rewrite -{n1}Dn1 in rG1 B *; rewrite row_free_unit => uB rG_B. by rewrite -[rG x](mulmxK uB) rG_B // !det_mulmx mulrC -!det_mulmx mulKmx. rewrite /standard_grepr; elim/big_rec2: _ => [|W y _ _ ->]. by rewrite cfunE trace_mx11 mxE Gx det1. rewrite !cfunE Gx /= !{1}trace_mx11 !{1}mxE det_ublock; congr (_ * _). rewrite exp_cfunE //; elim: (standard_irr_coef rG W) => /= [|k IHk]. by rewrite /muln_grepr big_ord0 det1. rewrite exprS /muln_grepr big_ord_recl det_ublock -IHk; congr (_ * _). by rewrite cfunE trace_mx11 mxE Gx. Qed. Lemma cfDet_id xi : xi \is a linear_char -> cfDet xi = xi. Proof. move=> lin_xi; have /irrP[i Dxi] := lin_char_irr lin_xi. apply/cfun_inP=> x Gx; rewrite Dxi -irrRepr cfDetRepr !cfunE trace_mx11 mxE. move: lin_xi (_ x) => /andP[_]; rewrite Dxi irr1_degree pnatr_eq1 => /eqP-> X. by rewrite {1}[X]mx11_scalar det_scalar1 trace_mx11. Qed. Definition cfDet_order phi := #[cfDet phi]%CF. Definition cfDet_order_lin xi : xi \is a linear_char -> cfDet_order xi = #[xi]%CF. Proof. by rewrite /cfDet_order => /cfDet_id->. Qed. Definition cfDet_order_dvdG phi : cfDet_order phi %| #|G|. Proof. by rewrite cforder_lin_char_dvdG ?cfDet_lin_char. Qed. End DetOrder. Notation "''o' ( phi )" := (cfDet_order phi) (format "''o' ( phi )") : cfun_scope. Section CfDetOps. Implicit Types gT aT rT : finGroupType. Lemma cfDetRes gT (G H : {group gT}) phi : phi \is a character -> cfDet ('Res[H, G] phi) = 'Res (cfDet phi). Proof. move=> Nphi; have [sGH | not_sHG] := boolP (H \subset G); last first. have /natrP[n Dphi1] := Cnat_char1 Nphi. rewrite !cfResEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r. by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n. have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_sub, cfDetRepr) //. apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx. by rewrite mulmx1 mul1mx. Qed. Lemma cfDetMorph aT rT (D G : {group aT}) (f : {morphism D >-> rT}) (phi : 'CF(f @* G)) : phi \is a character -> cfDet (cfMorph phi) = cfMorph (cfDet phi). Proof. move=> Nphi; have [sGD | not_sGD] := boolP (G \subset D); last first. have /natrP[n Dphi1] := Cnat_char1 Nphi. rewrite !cfMorphEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r. by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n. have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_morphim, cfDetRepr) //. apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx. by rewrite mulmx1 mul1mx. Qed. Lemma cfDetIsom aT rT (G : {group aT}) (R : {group rT}) (f : {morphism G >-> rT}) (isoGR : isom G R f) phi : cfDet (cfIsom isoGR phi) = cfIsom isoGR (cfDet phi). Proof. rewrite unlock rmorph_prod (reindex (isom_Iirr isoGR)); last first. by exists (isom_Iirr (isom_sym isoGR)) => i; rewrite ?isom_IirrK ?isom_IirrKV. apply: eq_bigr=> i; rewrite -!cfDetRepr !irrRepr isom_IirrE rmorphXn cfIsom_iso. by rewrite /= ![in cfIsom _]unlock cfDetMorph ?cfRes_char ?cfDetRes ?irr_char. Qed. Lemma cfDet_mul_lin gT (G : {group gT}) (lambda phi : 'CF(G)) : lambda \is a linear_char -> phi \is a character -> cfDet (lambda * phi) = lambda ^+ Num.truncn (phi 1%g) * cfDet phi. Proof. case/andP=> /char_reprP[[n1 rG1] ->] /= n1_1 /char_reprP[[n2 rG2] ->] /=. do [rewrite !cfRepr1 pnatr_eq1 natrK; move/eqP] in n1_1 *. rewrite {n1}n1_1 in rG1 *; rewrite cfRepr_prod cfDetRepr. apply/cfun_inP=> x Gx; rewrite !cfunE cfDetRepr cfunE Gx !mulrb !trace_mx11. rewrite !mxE prod_repr_lin ?mulrb //=; case: _ / (esym _); rewrite detZ. congr (_ * _); case: {rG2}n2 => [|n2]; first by rewrite cfun1E Gx. by rewrite expS_cfunE //= cfunE Gx trace_mx11. Qed. End CfDetOps. Definition cfcenter (gT : finGroupType) (G : {set gT}) (phi : 'CF(G)) := if phi \is a character then [set g in G | `|phi g| == phi 1%g] else cfker phi. Notation "''Z' ( phi )" := (cfcenter phi) : cfun_scope. Section Center. Variable (gT : finGroupType) (G : {group gT}). Implicit Types (phi chi : 'CF(G)) (H : {group gT}). (* This is Isaacs (2.27)(a). *) Lemma cfcenter_repr n (rG : mx_representation algC G n) : 'Z(cfRepr rG)%CF = rcenter rG. Proof. rewrite /cfcenter /rcenter cfRepr_char /=. apply/setP=> x /[!inE]; apply/andb_id2l=> Gx. apply/eqP/is_scalar_mxP=> [|[c rG_c]]. by case/max_cfRepr_norm_scalar=> // c; exists c. rewrite -(sqrCK (char1_ge0 (cfRepr_char rG))) normC_def; congr (sqrtC _). rewrite expr2 -{2}(mulgV x) -char_inv ?cfRepr_char ?cfunE ?groupM ?groupV //. rewrite Gx group1 repr_mx1 repr_mxM ?repr_mxV ?groupV // !mulrb rG_c. by rewrite invmx_scalar -scalar_mxM !mxtrace_scalar mulrnAr mulrnAl mulr_natl. Qed. (* This is part of Isaacs (2.27)(b). *) Fact cfcenter_group_set phi : group_set ('Z(phi))%CF. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ G phi). by rewrite cfcenter_repr groupP. by rewrite /cfcenter notNphi groupP. Qed. Canonical cfcenter_group f := Group (cfcenter_group_set f). Lemma char_cfcenterE chi x : chi \is a character -> x \in G -> (x \in ('Z(chi))%CF) = (`|chi x| == chi 1%g). Proof. by move=> Nchi Gx; rewrite /cfcenter Nchi inE Gx. Qed. Lemma irr_cfcenterE i x : x \in G -> (x \in 'Z('chi[G]_i)%CF) = (`|'chi_i x| == 'chi_i 1%g). Proof. by move/char_cfcenterE->; rewrite ?irr_char. Qed. (* This is also Isaacs (2.27)(b). *) Lemma cfcenter_sub phi : ('Z(phi))%CF \subset G. Proof. by rewrite /cfcenter /cfker !setIdE -fun_if subsetIl. Qed. Lemma cfker_center_normal phi : cfker phi <| 'Z(phi)%CF. Proof. apply: normalS (cfcenter_sub phi) (cfker_normal phi). rewrite /= /cfcenter; case: ifP => // Hphi; rewrite cfkerEchar //. apply/subsetP=> x /[!inE] /andP[-> /eqP->] /=. by rewrite ger0_norm ?char1_ge0. Qed. Lemma cfcenter_normal phi : 'Z(phi)%CF <| G. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ phi). by rewrite cfcenter_repr rcenter_normal. by rewrite /cfcenter notNphi cfker_normal. Qed. (* This is Isaacs (2.27)(c). *) Lemma cfcenter_Res chi : exists2 chi1, chi1 \is a linear_char & 'Res['Z(chi)%CF] chi = chi 1%g *: chi1. Proof. have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ chi); last first. exists 1; first exact: cfun1_lin_char. rewrite /cfcenter notNphi; apply/cfun_inP=> x Kx. by rewrite cfunE cfun1E Kx mulr1 cfResE ?cfker_sub // cfker1. rewrite cfcenter_repr -(cfRepr_sub _ (normal_sub (rcenter_normal _))). case: rG => [[|n] rG] /=; rewrite cfRepr1. exists 1; first exact: cfun1_lin_char. by apply/cfun_inP=> x Zx; rewrite scale0r !cfunE flatmx0 raddf0 Zx. pose rZmx x := ((rG x 0 0)%:M : 'M_(1,1)). have rZmxP: mx_repr [group of rcenter rG] rZmx. split=> [|x y]; first by rewrite /rZmx repr_mx1 mxE eqxx. move=> /setIdP[Gx /is_scalar_mxP[a rGx]] /setIdP[Gy /is_scalar_mxP[b rGy]]. by rewrite /rZmx repr_mxM // rGx rGy -!scalar_mxM !mxE. exists (cfRepr (MxRepresentation rZmxP)). by rewrite qualifE/= cfRepr_char cfRepr1 eqxx. apply/cfun_inP=> x Zx; rewrite !cfunE Zx /= /rZmx mulr_natl. by case/setIdP: Zx => Gx /is_scalar_mxP[a ->]; rewrite mxE !mxtrace_scalar. Qed. (* This is Isaacs (2.27)(d). *) Lemma cfcenter_cyclic chi : cyclic ('Z(chi)%CF / cfker chi)%g. Proof. case Nchi: (chi \is a character); last first. by rewrite /cfcenter Nchi trivg_quotient cyclic1. have [-> | nz_chi] := eqVneq chi 0. rewrite quotientS1 ?cyclic1 //= /cfcenter cfkerEchar ?cfun0_char //. by apply/subsetP=> x /setIdP[Gx _]; rewrite inE Gx /= !cfunE. have [xi Lxi def_chi] := cfcenter_Res chi. set Z := ('Z(_))%CF in xi Lxi def_chi *. have sZG: Z \subset G by apply: cfcenter_sub. have ->: cfker chi = cfker xi. rewrite -(setIidPr (normal_sub (cfker_center_normal _))) -/Z. rewrite !cfkerEchar // ?lin_charW //= -/Z. apply/setP=> x /[!inE]; apply: andb_id2l => Zx. rewrite (subsetP sZG) //= -!(cfResE chi sZG) ?group1 // def_chi !cfunE. by rewrite (inj_eq (mulfI _)) ?char1_eq0. have: abelian (Z / cfker xi) by rewrite sub_der1_abelian ?lin_char_der1. have /irr_reprP[rG irrG ->] := lin_char_irr Lxi; rewrite cfker_repr. apply: mx_faithful_irr_abelian_cyclic (kquo_mx_faithful rG) _. exact/quo_mx_irr. Qed. (* This is Isaacs (2.27)(e). *) Lemma cfcenter_subset_center chi : ('Z(chi)%CF / cfker chi)%g \subset 'Z(G / cfker chi)%g. Proof. case Nchi: (chi \is a character); last first. by rewrite /cfcenter Nchi trivg_quotient sub1G. rewrite subsetI quotientS ?cfcenter_sub // quotient_cents2r //=. case/char_reprP: Nchi => rG ->{chi}; rewrite cfker_repr cfcenter_repr gen_subG. apply/subsetP=> _ /imset2P[x y /setIdP[Gx /is_scalar_mxP[c rGx]] Gy ->]. rewrite inE groupR //= !repr_mxM ?groupM ?groupV // rGx -(scalar_mxC c) -rGx. by rewrite !mulmxA !repr_mxKV. Qed. (* This is Isaacs (2.27)(f). *) Lemma cfcenter_eq_center (i : Iirr G) : ('Z('chi_i)%CF / cfker 'chi_i)%g = 'Z(G / cfker 'chi_i)%g. Proof. apply/eqP; rewrite eqEsubset; rewrite cfcenter_subset_center ?irr_char //. apply/subsetP=> _ /setIP[/morphimP[x /= _ Gx ->] cGx]; rewrite mem_quotient //=. rewrite -irrRepr cfker_repr cfcenter_repr inE Gx in cGx *. apply: mx_abs_irr_cent_scalar 'Chi_i _ _ _; first exact/groupC/socle_irr. have nKG: G \subset 'N(rker 'Chi_i) by apply: rker_norm. (* GG -- locking here is critical to prevent Coq kernel divergence. *) apply/centgmxP=> y Gy; rewrite [eq]lock -2?(quo_repr_coset (subxx _) nKG) //. move: (quo_repr _ _) => rG; rewrite -2?repr_mxM ?mem_quotient // -lock. by rewrite (centP cGx) // mem_quotient. Qed. (* This is Isaacs (2.28). *) Lemma cap_cfcenter_irr : \bigcap_i 'Z('chi[G]_i)%CF = 'Z(G). Proof. apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) /= => [|i _]; last first. rewrite -(quotientSGK _ (normal_sub (cfker_center_normal _))). by rewrite cfcenter_eq_center morphim_center. by rewrite subIset // normal_norm // cfker_normal. set Z := \bigcap_i _. have sZG: Z \subset G by rewrite (bigcap_min 0) ?cfcenter_sub. rewrite subsetI sZG (sameP commG1P trivgP) -(TI_cfker_irr G). apply/bigcapsP=> i _; have nKiG := normal_norm (cfker_normal 'chi_i). rewrite -quotient_cents2 ?(subset_trans sZG) //. rewrite (subset_trans (quotientS _ (bigcap_inf i _))) //. by rewrite cfcenter_eq_center subsetIr. Qed. (* This is Isaacs (2.29). *) Lemma cfnorm_Res_leif H phi : H \subset G -> '['Res[H] phi] <= #|G : H|%:R * '[phi] ?= iff (phi \in 'CF(G, H)). Proof. move=> sHG; rewrite cfun_onE mulrCA natf_indexg // -mulrA mulKf ?neq0CG //. rewrite (big_setID H) (setIidPr sHG) /= addrC. rewrite (mono_leif (ler_pM2l _)) ?invr_gt0 ?gt0CG // -leifBLR -sumrB. rewrite big1 => [|x Hx]; last by rewrite !cfResE ?subrr. have ->: (support phi \subset H) = (G :\: H \subset [set x | phi x == 0]). rewrite subDset setUC -subDset; apply: eq_subset => x. by rewrite !inE (andb_idr (contraR _)) // => /cfun0->. rewrite (sameP subsetP forall_inP); apply: leif_0_sum => x _. by rewrite !inE /<?=%R mul_conjC_ge0 eq_sym mul_conjC_eq0. Qed. (* This is Isaacs (2.30). *) Lemma irr1_bound (i : Iirr G) : ('chi_i 1%g) ^+ 2 <= #|G : 'Z('chi_i)%CF|%:R ?= iff ('chi_i \in 'CF(G, 'Z('chi_i)%CF)). Proof. congr (_ <= _ ?= iff _): (cfnorm_Res_leif 'chi_i (cfcenter_sub 'chi_i)). have [xi Lxi ->] := cfcenter_Res 'chi_i. have /irrP[j ->] := lin_char_irr Lxi; rewrite cfdotZl cfdotZr cfdot_irr eqxx. by rewrite mulr1 irr1_degree conjC_nat. by rewrite cfdot_irr eqxx mulr1. Qed. (* This is Isaacs (2.31). *) Lemma irr1_abelian_bound (i : Iirr G) : abelian (G / 'Z('chi_i)%CF) -> ('chi_i 1%g) ^+ 2 = #|G : 'Z('chi_i)%CF|%:R. Proof. move=> AbGc; apply/eqP; rewrite irr1_bound cfun_onE; apply/subsetP=> x nz_chi_x. have Gx: x \in G by apply: contraR nz_chi_x => /cfun0->. have nKx := subsetP (normal_norm (cfker_normal 'chi_i)) _ Gx. rewrite -(quotientGK (cfker_center_normal _)) inE nKx inE /=. rewrite cfcenter_eq_center inE mem_quotient //=. apply/centP=> _ /morphimP[y nKy Gy ->]; apply/commgP; rewrite -morphR //=. set z := [~ x, y]; rewrite coset_id //. have: z \in 'Z('chi_i)%CF. apply: subsetP (mem_commg Gx Gy). by rewrite der1_min // normal_norm ?cfcenter_normal. rewrite -irrRepr cfker_repr cfcenter_repr !inE in nz_chi_x *. case/andP=> Gz /is_scalar_mxP[c Chi_z]; rewrite Gz Chi_z mul1mx /=. apply/eqP; congr _%:M; apply: (mulIf nz_chi_x); rewrite mul1r. rewrite -{2}(cfunJ _ x Gy) conjg_mulR -/z !cfunE Gx groupM // !{1}mulrb. by rewrite repr_mxM // Chi_z mul_mx_scalar mxtraceZ. Qed. (* This is Isaacs (2.32)(a). *) Lemma irr_faithful_center i : cfaithful 'chi[G]_i -> cyclic 'Z(G). Proof. rewrite (isog_cyclic (isog_center (quotient1_isog G))) /=. by move/trivgP <-; rewrite -cfcenter_eq_center cfcenter_cyclic. Qed. Lemma cfcenter_fful_irr i : cfaithful 'chi[G]_i -> 'Z('chi_i)%CF = 'Z(G). Proof. move/trivgP=> Ki1; have:= cfcenter_eq_center i; rewrite {}Ki1. have inj1: 'injm (@coset gT 1%g) by rewrite ker_coset. by rewrite -injm_center; first apply: injm_morphim_inj; rewrite ?norms1. Qed. (* This is Isaacs (2.32)(b). *) Lemma pgroup_cyclic_faithful (p : nat) : p.-group G -> cyclic 'Z(G) -> exists i, cfaithful 'chi[G]_i. Proof. pose Z := 'Ohm_1('Z(G)) => pG cycZG; have nilG := pgroup_nil pG. have [-> | ntG] := eqsVneq G [1]; first by exists 0; apply: cfker_sub. have{pG} [[p_pr _ _] pZ] := (pgroup_pdiv pG ntG, pgroupS (center_sub G) pG). have ntZ: 'Z(G) != [1] by rewrite center_nil_eq1. have{pZ} oZ: #|Z| = p by apply: Ohm1_cyclic_pgroup_prime. apply/existsP; apply: contraR ntZ => /existsPn-not_ffulG. rewrite -Ohm1_eq1 -subG1 /= -/Z -(TI_cfker_irr G); apply/bigcapsP=> i _. rewrite prime_meetG ?oZ // setIC meet_Ohm1 // meet_center_nil ?cfker_normal //. by rewrite -subG1 not_ffulG. Qed. End Center. Section Induced. Variables (gT : finGroupType) (G H : {group gT}). Implicit Types (phi : 'CF(G)) (chi : 'CF(H)). Lemma cfInd_char chi : chi \is a character -> 'Ind[G] chi \is a character. Proof. move=> Nchi; apply/forallP=> i; rewrite coord_cfdot -Frobenius_reciprocity //. by rewrite Cnat_cfdot_char ?cfRes_char ?irr_char. Qed. Lemma cfInd_eq0 chi : H \subset G -> chi \is a character -> ('Ind[G] chi == 0) = (chi == 0). Proof. move=> sHG Nchi; rewrite -!(char1_eq0) ?cfInd_char // cfInd1 //. by rewrite (mulrI_eq0 _ (mulfI _)) ?neq0CiG. Qed. Lemma Ind_irr_neq0 i : H \subset G -> 'Ind[G, H] 'chi_i != 0. Proof. by move/cfInd_eq0->; rewrite ?irr_neq0 ?irr_char. Qed. Definition Ind_Iirr (A B : {set gT}) i := cfIirr ('Ind[B, A] 'chi_i). Lemma constt_cfRes_irr i : {j | j \in irr_constt ('Res[H, G] 'chi_i)}. Proof. apply/sigW/neq0_has_constt/Res_irr_neq0. Qed. Lemma constt_cfInd_irr i : H \subset G -> {j | j \in irr_constt ('Ind[G, H] 'chi_i)}. Proof. by move=> sHG; apply/sigW/neq0_has_constt/Ind_irr_neq0. Qed. Lemma cfker_Res phi : H \subset G -> phi \is a character -> cfker ('Res[H] phi) = H :&: cfker phi. Proof. move=> sHG Nphi; apply/setP=> x; rewrite !cfkerEchar ?cfRes_char // !inE. by apply/andb_id2l=> Hx; rewrite (subsetP sHG) ?cfResE. Qed. (* This is Isaacs Lemma (5.11). *) Lemma cfker_Ind chi : H \subset G -> chi \is a character -> chi != 0 -> cfker ('Ind[G, H] chi) = gcore (cfker chi) G. Proof. move=> sHG Nchi nzchi; rewrite !cfker_nzcharE ?cfInd_char ?cfInd_eq0 //. apply/setP=> x; rewrite inE cfIndE // (can2_eq (mulVKf _) (mulKf _)) ?neq0CG //. rewrite cfInd1 // mulrA -natrM Lagrange // mulr_natl -sumr_const. apply/eqP/bigcapP=> [/normC_sum_upper ker_chiG_x y Gy | ker_chiG_x]. by rewrite mem_conjg inE ker_chiG_x ?groupV // => z _; apply: char1_ge_norm. by apply: eq_bigr => y /groupVr/ker_chiG_x; rewrite mem_conjgV inE => /eqP. Qed. Lemma cfker_Ind_irr i : H \subset G -> cfker ('Ind[G, H] 'chi_i) = gcore (cfker 'chi_i) G. Proof. by move/cfker_Ind->; rewrite ?irr_neq0 ?irr_char. Qed. End Induced. Arguments Ind_Iirr {gT A%_g} B%_g i%_R.
Sub.lean
/- Copyright (c) 2022 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Zinkevich -/ import Mathlib.MeasureTheory.Measure.Typeclasses.Finite /-! # Subtraction of measures In this file we define `μ - ν` to be the least measure `τ` such that `μ ≤ τ + ν`. It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures. Compare with `ENNReal.instSub`. Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and `ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and `ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/ open Set namespace MeasureTheory namespace Measure /-- The measure `μ - ν` is defined to be the least measure `τ` such that `μ ≤ τ + ν`. It is the equivalent of `(μ - ν) ⊔ 0` if `μ` and `ν` were signed measures. Compare with `ENNReal.instSub`. Specifically, note that if you have `α = {1,2}`, and `μ {1} = 2`, `μ {2} = 0`, and `ν {2} = 2`, `ν {1} = 0`, then `(μ - ν) {1, 2} = 2`. However, if `μ ≤ ν`, and `ν univ ≠ ∞`, then `(μ - ν) + ν = μ`. -/ noncomputable instance instSub {α : Type*} [MeasurableSpace α] : Sub (Measure α) := ⟨fun μ ν => sInf { τ | μ ≤ τ + ν }⟩ variable {α : Type*} {m : MeasurableSpace α} {μ ν : Measure α} {s : Set α} theorem sub_def : μ - ν = sInf { d | μ ≤ d + ν } := rfl theorem sub_le_of_le_add {d} (h : μ ≤ d + ν) : μ - ν ≤ d := sInf_le h theorem sub_eq_zero_of_le (h : μ ≤ ν) : μ - ν = 0 := nonpos_iff_eq_zero'.1 <| sub_le_of_le_add <| by rwa [zero_add] theorem sub_le : μ - ν ≤ μ := sub_le_of_le_add <| Measure.le_add_right le_rfl @[simp] theorem sub_top : μ - ⊤ = 0 := sub_eq_zero_of_le le_top @[simp] theorem zero_sub : 0 - μ = 0 := sub_eq_zero_of_le μ.zero_le @[simp] theorem sub_self : μ - μ = 0 := sub_eq_zero_of_le le_rfl @[simp] protected theorem sub_zero : μ - 0 = μ := by rw [sub_def] apply le_antisymm · simp [sInf_le] · simp /-- This application lemma only works in special circumstances. Given knowledge of when `μ ≤ ν` and `ν ≤ μ`, a more general application lemma can be written. -/ theorem sub_apply [IsFiniteMeasure ν] (h₁ : MeasurableSet s) (h₂ : ν ≤ μ) : (μ - ν) s = μ s - ν s := by -- We begin by defining `measure_sub`, which will be equal to `(μ - ν)`. let measure_sub : Measure α := MeasureTheory.Measure.ofMeasurable (fun (t : Set α) (_ : MeasurableSet t) => μ t - ν t) (by simp) (fun g h_meas h_disj ↦ by simp only [measure_iUnion h_disj h_meas] rw [ENNReal.tsum_sub _ (h₂ <| g ·)] rw [← measure_iUnion h_disj h_meas] apply measure_ne_top) -- Now, we demonstrate `μ - ν = measure_sub`, and apply it. have h_measure_sub_add : ν + measure_sub = μ := by ext1 t h_t_measurable_set simp only [Pi.add_apply, coe_add] rw [MeasureTheory.Measure.ofMeasurable_apply _ h_t_measurable_set, add_comm, tsub_add_cancel_of_le (h₂ t)] have h_measure_sub_eq : μ - ν = measure_sub := by rw [MeasureTheory.Measure.sub_def] apply le_antisymm · apply sInf_le simp [le_refl, add_comm, h_measure_sub_add] apply le_sInf intro d h_d rw [← h_measure_sub_add, mem_setOf_eq, add_comm d] at h_d apply Measure.le_of_add_le_add_left h_d rw [h_measure_sub_eq] apply Measure.ofMeasurable_apply _ h₁ theorem sub_add_cancel_of_le [IsFiniteMeasure ν] (h₁ : ν ≤ μ) : μ - ν + ν = μ := by ext1 s h_s_meas rw [add_apply, sub_apply h_s_meas h₁, tsub_add_cancel_of_le (h₁ s)] @[simp] protected lemma add_sub_cancel [IsFiniteMeasure ν] : μ + ν - ν = μ := by ext1 s hs rw [sub_apply hs (Measure.le_add_left (le_refl _)), add_apply, ENNReal.add_sub_cancel_right (measure_ne_top ν s)] theorem restrict_sub_eq_restrict_sub_restrict (h_meas_s : MeasurableSet s) : (μ - ν).restrict s = μ.restrict s - ν.restrict s := by repeat rw [sub_def] have h_nonempty : { d | μ ≤ d + ν }.Nonempty := ⟨μ, Measure.le_add_right le_rfl⟩ rw [restrict_sInf_eq_sInf_restrict h_nonempty h_meas_s] apply le_antisymm · refine sInf_le_sInf_of_isCoinitialFor ?_ intro ν' h_ν'_in rw [mem_setOf_eq] at h_ν'_in refine ⟨ν'.restrict s, ?_, restrict_le_self⟩ refine ⟨ν' + (⊤ : Measure α).restrict sᶜ, ?_, ?_⟩ · rw [mem_setOf_eq, add_right_comm, Measure.le_iff] intro t h_meas_t repeat rw [← measure_inter_add_diff t h_meas_s] refine add_le_add ?_ ?_ · rw [add_apply, add_apply] apply le_add_right _ rw [← restrict_eq_self μ inter_subset_right, ← restrict_eq_self ν inter_subset_right] apply h_ν'_in · rw [add_apply, restrict_apply (h_meas_t.diff h_meas_s), diff_eq, inter_assoc, inter_self, ← add_apply] have h_mu_le_add_top : μ ≤ ν' + ν + ⊤ := by simp only [add_top, le_top] exact Measure.le_iff'.1 h_mu_le_add_top _ · ext1 t h_meas_t simp [restrict_apply h_meas_t, restrict_apply (h_meas_t.inter h_meas_s), inter_assoc] · refine sInf_le_sInf_of_isCoinitialFor ?_ refine forall_mem_image.2 fun t h_t_in => ⟨t.restrict s, ?_, le_rfl⟩ rw [Set.mem_setOf_eq, ← restrict_add] exact restrict_mono Subset.rfl h_t_in theorem sub_apply_eq_zero_of_restrict_le_restrict (h_le : μ.restrict s ≤ ν.restrict s) (h_meas_s : MeasurableSet s) : (μ - ν) s = 0 := by rw [← restrict_apply_self, restrict_sub_eq_restrict_sub_restrict, sub_eq_zero_of_le] <;> simp [*] instance isFiniteMeasure_sub [IsFiniteMeasure μ] : IsFiniteMeasure (μ - ν) := isFiniteMeasure_of_le μ sub_le end Measure end MeasureTheory
Basic.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.SmallObject.IsCardinalForSmallObjectArgument /-! # The small object argument Let `C` be a category. A class of morphisms `I : MorphismProperty C` permits the small object argument (typeclass `HasSmallObjectArgument.{w} I` where `w` is an auxiliary universe) if there exists a regular cardinal `κ : Cardinal.{w}` such that `IsCardinalForSmallObjectArgument I κ` holds. This technical condition is defined in the file `Mathlib/CategoryTheory/SmallObject/IsCardinalForSmallObjectArgument.lean`. It involves certain smallness conditions relative to `w`, the existence of certain colimits in `C`, and for each object `A` which is the source of a morphism in `I`, the `Hom(A, -)` functor (`coyoneda.obj (op A)`) should commute to transfinite compositions of pushouts of coproducts of morphisms in `I` (this condition is automatically satisfied for a suitable `κ` when `A` is a presentable object of `C`, see the file `Mathlib/CategoryTheory/Presentable/Basic.lean`). ## Main results Assuming `I` permits the small object argument, the two main results obtained in this file are: * the class `I.rlp.llp` of morphisms that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions (indexed by a suitable well ordered type `J`) of pushouts of coproducts of morphisms in `I`; * morphisms in `C` have a functorial factorization as a morphism in `I.rlp.llp` followed by a morphism in `I.rlp`. In the context of model categories, these results are known as Quillen's small object argument (originally for `J := ℕ`). Actually, the more general construction by transfinite induction already appeared in the proof of the existence of enough injectives in abelian categories with AB5 and a generator by Grothendieck, who then wrote that the "proof was essentially known". Indeed, the argument appeared in *Homological algebra* by Cartan and Eilenberg (p. 9-10) in the case of modules, and they mention that the result was initially obtained by Baer. ## Structure of the proof The main part in the proof is the construction of the functorial factorization. This involves a construction by transfinite induction. A general procedure for constructions by transfinite induction in categories (including the iteration of a functor) is done in the file `Mathlib/CategoryTheory/SmallObject/TransfiniteIteration.lean`. The factorization of the small object argument is obtained by doing a transfinite iteration of a specific functor `Arrow C ⥤ Arrow C` which is defined in the file `Mathlib/CategoryTheory/SmallObject/Construction.lean` (this definition involves coproducts and a pushout). These ingredients are combined in the file `Mathlib/CategoryTheory/SmallObject/IsCardinalForSmallObjectArgument.lean` where the main results are obtained under a `IsCardinalForSmallObjectArgument I κ` assumption. The fact that the left lifting property with respect to a class of morphisms is stable by transfinite compositions was obtained in the file `Mathlib/CategoryTheory/SmallObject/TransfiniteCompositionLifting.lean`. ## References - [Henri Cartan and Samuel Eilenberg, *Homological algebra*][cartan-eilenberg-1956] - [Alexander Grothendieck, *Sur quelques points d'algèbre homologique*][grothendieck-1957] - [Daniel G. Quillen, *Homotopical algebra*][Quillen1967] - https://ncatlab.org/nlab/show/small+object+argument -/ universe w v u namespace CategoryTheory open Category Limits SmallObject namespace MorphismProperty variable {C : Type u} [Category.{v} C] (I : MorphismProperty C) /-- A class of morphisms `I : MorphismProperty C` satisfies the property `HasSmallObjectArgument.{w} I` if it permits the small object argument, i.e. there exists a regular cardinal `κ : Cardinal.{w}` such that `IsCardinalForSmallObjectArgument I κ` holds. -/ class HasSmallObjectArgument : Prop where exists_cardinal : ∃ (κ : Cardinal.{w}) (_ : Fact κ.IsRegular) (_ : OrderBot κ.ord.toType), IsCardinalForSmallObjectArgument I κ variable [HasSmallObjectArgument.{w} I] /-- When `I : MorphismProperty C` permits the small object argument, this is a cardinal `κ` such that `IsCardinalForSmallObjectArgument I κ` holds. -/ noncomputable def smallObjectκ : Cardinal.{w} := (HasSmallObjectArgument.exists_cardinal (I := I)).choose local instance smallObjectκ_isRegular : Fact I.smallObjectκ.IsRegular := HasSmallObjectArgument.exists_cardinal.choose_spec.choose noncomputable instance : OrderBot I.smallObjectκ.ord.toType := HasSmallObjectArgument.exists_cardinal.choose_spec.choose_spec.choose instance isCardinalForSmallObjectArgument_smallObjectκ : IsCardinalForSmallObjectArgument.{w} I I.smallObjectκ := HasSmallObjectArgument.exists_cardinal.choose_spec.choose_spec.choose_spec instance : HasFunctorialFactorization I.rlp.llp I.rlp := hasFunctorialFactorization I I.smallObjectκ /-- If `I : MorphismProperty C` permits the small object argument, then the class of morphism that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions (indexed by `I.smallObjectκ.ord.toType`) of pushouts of coproducts of morphisms in `C`. -/ lemma llp_rlp_of_hasSmallObjectArgument' : I.rlp.llp = (transfiniteCompositionsOfShape (coproducts.{w} I).pushouts I.smallObjectκ.ord.toType).retracts := llp_rlp_of_isCardinalForSmallObjectArgument' I I.smallObjectκ /-- If `I : MorphismProperty C` permits the small object argument, then the class of morphism that have the left lifting property with respect to the maps that have the right lifting property with respect to `I` are exactly the retracts of transfinite compositions of pushouts of coproducts of morphisms in `C`. -/ lemma llp_rlp_of_hasSmallObjectArgument : I.rlp.llp = (transfiniteCompositions.{w} (coproducts.{w} I).pushouts).retracts := llp_rlp_of_isCardinalForSmallObjectArgument I I.smallObjectκ end MorphismProperty end CategoryTheory
PushoutI.lean
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.CoprodI import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## Pushouts of Monoids and Groups This file defines wide pushouts of monoids and groups and proves some properties of the amalgamated product of groups (i.e. the special case where all the maps in the diagram are injective). ## Main definitions - `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι` - `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout - `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout - `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout. - `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout - `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of groups then so is `of` - `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base monoid. ## References * The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf) from Queen Mary University ## Tags amalgamated product, pushout, group -/ namespace Monoid open CoprodI Subgroup Coprod Function List variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K] /-- The relation we quotient by to form the pushout -/ def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Con (Coprod (CoprodI G) H) := conGen (fun x y : Coprod (CoprodI G) H => ∃ i x', x = inl (of (φ i x')) ∧ y = inr x') /-- The indexed pushout of monoids, which is the pushout in the category of monoids, or the category of groups. -/ def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ := (PushoutI.con φ).Quotient namespace PushoutI section Monoid variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i} protected instance mul : Mul (PushoutI φ) := by delta PushoutI; infer_instance protected instance one : One (PushoutI φ) := by delta PushoutI; infer_instance instance monoid : Monoid (PushoutI φ) := { Con.monoid _ with toMul := PushoutI.mul toOne := PushoutI.one } /-- The map from each indexing group into the pushout -/ def of (i : ι) : G i →* PushoutI φ := (Con.mk' _).comp <| inl.comp CoprodI.of variable (φ) in /-- The map from the base monoid into the pushout -/ def base : H →* PushoutI φ := (Con.mk' _).comp inr theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by ext x apply (Con.eq _).2 refine ConGen.Rel.of _ _ ?_ simp only [MonoidHom.comp_apply] exact ⟨_, _, rfl, rfl⟩ variable (φ) in theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by rw [← MonoidHom.comp_apply, of_comp_eq_base] /-- Define a homomorphism out of the pushout of monoids be defining it on each object in the diagram -/ def lift (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) : PushoutI φ →* K := Con.lift _ (Coprod.lift (CoprodI.lift f) k) <| by apply Con.conGen_le fun x y => ?_ rintro ⟨i, x', rfl, rfl⟩ simp only [DFunLike.ext_iff, MonoidHom.coe_comp, comp_apply] at hf simp [hf] @[simp] theorem lift_of (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) {i : ι} (g : G i) : (lift f k hf) (of i g : PushoutI φ) = f i g := by delta PushoutI lift of simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inl, CoprodI.lift_of] @[simp] theorem lift_base (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) (g : H) : (lift f k hf) (base φ g : PushoutI φ) = k g := by delta PushoutI lift base simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inr] -- `ext` attribute should be lower priority then `hom_ext_nonempty` @[ext 1199] theorem hom_ext {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) (hbase : f.comp (base φ) = g.comp (base φ)) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext (CoprodI.ext_hom _ _ h) hbase @[ext high] theorem hom_ext_nonempty [hn : Nonempty ι] {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) : f = g := hom_ext h <| by cases hn with | intro i => ext rw [← of_comp_eq_base i, ← MonoidHom.comp_assoc, h, MonoidHom.comp_assoc] /-- The equivalence that is part of the universal property of the pushout. A hom out of the pushout is just a morphism out of all groups in the pushout that satisfies a commutativity condition. -/ @[simps] def homEquiv : (PushoutI φ →* K) ≃ { f : (Π i, G i →* K) × (H →* K) // ∀ i, (f.1 i).comp (φ i) = f.2 } := { toFun := fun f => ⟨(fun i => f.comp (of i), f.comp (base φ)), fun i => by rw [MonoidHom.comp_assoc, of_comp_eq_base]⟩ invFun := fun f => lift f.1.1 f.1.2 f.2, left_inv := fun _ => hom_ext (by simp [DFunLike.ext_iff]) (by simp [DFunLike.ext_iff]) right_inv := fun ⟨⟨_, _⟩, _⟩ => by simp [DFunLike.ext_iff, funext_iff] } /-- The map from the coproduct into the pushout -/ def ofCoprodI : CoprodI G →* PushoutI φ := CoprodI.lift of @[simp] theorem ofCoprodI_of (i : ι) (g : G i) : (ofCoprodI (CoprodI.of g) : PushoutI φ) = of i g := by simp [ofCoprodI] theorem induction_on {motive : PushoutI φ → Prop} (x : PushoutI φ) (of : ∀ (i : ι) (g : G i), motive (of i g)) (base : ∀ h, motive (base φ h)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by delta PushoutI PushoutI.of PushoutI.base at * induction x using Con.induction_on with | H x => induction x using Coprod.induction_on with | inl g => induction g using CoprodI.induction_on with | of i g => exact of i g | mul x y ihx ihy => rw [map_mul] exact mul _ _ ihx ihy | one => simpa using base 1 | inr h => exact base h | mul x y ihx ihy => exact mul _ _ ihx ihy end Monoid variable [∀ i, Group (G i)] [Group H] {φ : ∀ i, H →* G i} instance : Group (PushoutI φ) := { Con.group (PushoutI.con φ) with toMonoid := PushoutI.monoid } namespace NormalWord /- In this section we show that there is a normal form for words in the amalgamated product. To have a normal form, we need to pick canonical choice of element of each right coset of the base group. The choice of element in the base group itself is `1`. Given a choice of element of each right coset, given by the type `Transversal φ` we can find a normal form. The normal form for an element is an element of the base group, multiplied by a word in the coproduct, where each letter in the word is the canonical choice of element of its coset. We then show that all groups in the diagram act faithfully on the normal form. This implies that the maps into the coproduct are injective. We demonstrate the action is faithful using the equivalence `equivPair`. We show that `G i` acts faithfully on `Pair d i` and that `Pair d i` is isomorphic to `NormalWord d`. Here, `d` is a `Transversal`. A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. We then show that the equivalence between `NormalWord` and `PushoutI`, between the set of normal words and the elements of the amalgamated product. The key to this is the theorem `prod_smul_empty`, which says that going from `NormalWord` to `PushoutI` and back is the identity. This is proven by induction on the word using `consRecOn`. -/ variable (φ) /-- The data we need to pick a normal form for words in the pushout. We need to pick a canonical element of each coset. We also need all the maps in the diagram to be injective -/ structure Transversal : Type _ where /-- All maps in the diagram are injective -/ injective : ∀ i, Injective (φ i) /-- The underlying set, containing exactly one element of each coset of the base group -/ set : ∀ i, Set (G i) /-- The chosen element of the base group itself is the identity -/ one_mem : ∀ i, 1 ∈ set i /-- We have exactly one element of each coset of the base group -/ compl : ∀ i, IsComplement (φ i).range (set i) theorem transversal_nonempty (hφ : ∀ i, Injective (φ i)) : Nonempty (Transversal φ) := by choose t ht using fun i => (φ i).range.exists_isComplement_right 1 apply Nonempty.intro exact { injective := hφ set := t one_mem := fun i => (ht i).2 compl := fun i => (ht i).1 } variable {φ} /-- The normal form for words in the pushout. Every element of the pushout is the product of an element of the base group and a word made up of letters each of which is in the transversal. -/ structure _root_.Monoid.PushoutI.NormalWord (d : Transversal φ) extends CoprodI.Word G where /-- Every `NormalWord` is the product of an element of the base group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : H /-- All letter in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ toList → g ∈ d.set i /-- A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. Similar to `Monoid.CoprodI.Pair` except every letter must be in the transversal (not including the head letter). -/ structure Pair (d : Transversal φ) (i : ι) extends CoprodI.Word.Pair G i where /-- All letters in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ tail.toList → g ∈ d.set i variable {d : Transversal φ} /-- The empty normalized word, representing the identity element of the group. -/ @[simps!] def empty : NormalWord d := ⟨CoprodI.Word.empty, 1, fun i g => by simp [CoprodI.Word.empty]⟩ instance : Inhabited (NormalWord d) := ⟨NormalWord.empty⟩ instance (i : ι) : Inhabited (Pair d i) := ⟨{ (empty : NormalWord d) with head := 1, tail := _, fstIdx_ne := fun h => by cases h }⟩ @[ext] theorem ext {w₁ w₂ : NormalWord d} (hhead : w₁.head = w₂.head) (hlist : w₁.toList = w₂.toList) : w₁ = w₂ := by rcases w₁ with ⟨⟨_, _, _⟩, _, _⟩ rcases w₂ with ⟨⟨_, _, _⟩, _, _⟩ simp_all open Subgroup.IsComplement instance baseAction : MulAction H (NormalWord d) := { smul := fun h w => { w with head := h * w.head }, one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem base_smul_def' (h : H) (w : NormalWord d) : h • w = { w with head := h * w.head } := rfl /-- Take the product of a normal word as an element of the `PushoutI`. We show that this is bijective, in `NormalWord.equiv`. -/ def prod (w : NormalWord d) : PushoutI φ := base φ w.head * ofCoprodI (w.toWord).prod @[simp] theorem prod_base_smul (h : H) (w : NormalWord d) : (h • w).prod = base φ h * w.prod := by simp only [base_smul_def', prod, map_mul, mul_assoc] @[simp] theorem prod_empty : (empty : NormalWord d).prod = 1 := by simp [prod, empty] /-- A constructor that multiplies a `NormalWord` by an element, with condition to make sure the underlying list does get longer. -/ @[simps!] noncomputable def cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : NormalWord d := letI n := (d.compl i).equiv (g * (φ i w.head)) letI w' := Word.cons (n.2 : G i) w.toWord hmw (mt (coe_equiv_snd_eq_one_iff_mem _ (d.one_mem _)).1 (mt (mul_mem_cancel_right (by simp)).1 hgr)) { toWord := w' head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by simp only [w', Word.cons, mem_cons, Sigma.mk.inj_iff] at hg rcases hg with ⟨rfl, hg | hg⟩ · simp · exact w.normalized _ _ (by assumption) } @[simp] theorem prod_cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : (cons g w hmw hgr).prod = of i g * w.prod := by simp [prod, cons, ← of_apply_eq_base φ i, equiv_fst_eq_mul_inv, mul_assoc] variable [DecidableEq ι] [∀ i, DecidableEq (G i)] /-- Given a word in `CoprodI`, if every letter is in the transversal and when we multiply by an element of the base group it still has this property, then the element of the base group we multiplied by was one. -/ theorem eq_one_of_smul_normalized (w : CoprodI.Word G) {i : ι} (h : H) (hw : ∀ i g, ⟨i, g⟩ ∈ w.toList → g ∈ d.set i) (hφw : ∀ j g, ⟨j, g⟩ ∈ (CoprodI.of (φ i h) • w).toList → g ∈ d.set j) : h = 1 := by simp only [← (d.compl _).equiv_snd_eq_self_iff_mem (one_mem _)] at hw hφw have hhead : ((d.compl i).equiv (Word.equivPair i w).head).2 = (Word.equivPair i w).head := by rw [Word.equivPair_head] split_ifs with h · rcases h with ⟨_, rfl⟩ exact hw _ _ (List.head_mem _) · rw [equiv_one (d.compl i) (one_mem _) (d.one_mem _)] by_contra hh1 have := hφw i (φ i h * (Word.equivPair i w).head) ?_ · apply hh1 rw [equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩, hhead] at this simpa [((injective_iff_map_eq_one' _).1 (d.injective i))] using this · simp only [Word.mem_smul_iff, not_true, false_and, ne_eq, Option.mem_def, mul_right_inj, exists_eq_right', mul_eq_left, exists_prop, true_and, false_or] constructor · intro h apply_fun (d.compl i).equiv at h simp only [Prod.ext_iff, equiv_one (d.compl i) (one_mem _) (d.one_mem _), equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩ , hhead, Subtype.ext_iff, Prod.ext_iff] at h rcases h with ⟨h₁, h₂⟩ rw [h₂, equiv_one (d.compl i) (one_mem _) (d.one_mem _)] at h₁ erw [mul_one] at h₁ simp only [((injective_iff_map_eq_one' _).1 (d.injective i))] at h₁ contradiction · rw [Word.equivPair_head] dsimp split_ifs with hep · rcases hep with ⟨hnil, rfl⟩ rw [head?_eq_head hnil] simp_all · push_neg at hep by_cases hw : w.toList = [] · simp [hw, Word.fstIdx] · simp [head?_eq_head hw, Word.fstIdx, hep hw] theorem ext_smul {w₁ w₂ : NormalWord d} (i : ι) (h : CoprodI.of (φ i w₁.head) • w₁.toWord = CoprodI.of (φ i w₂.head) • w₂.toWord) : w₁ = w₂ := by rcases w₁ with ⟨w₁, h₁, hw₁⟩ rcases w₂ with ⟨w₂, h₂, hw₂⟩ dsimp at * rw [smul_eq_iff_eq_inv_smul, ← mul_smul] at h subst h simp only [← map_inv, ← map_mul] at hw₁ have : h₁⁻¹ * h₂ = 1 := eq_one_of_smul_normalized w₂ (h₁⁻¹ * h₂) hw₂ hw₁ rw [inv_mul_eq_one] at this; subst this simp /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, but putting head into normal form first, by making sure it is expressed as an element of the base group multiplied by an element of the transversal. -/ noncomputable def rcons (i : ι) (p : Pair d i) : NormalWord d := letI n := (d.compl i).equiv p.head let w := (Word.equivPair i).symm { p.toPair with head := n.2 } { toWord := w head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by dsimp [w] at hg rw [Word.equivPair_symm, Word.mem_rcons_iff] at hg rcases hg with hg | ⟨_, rfl, rfl⟩ · exact p.normalized _ _ hg · simp } theorem rcons_injective {i : ι} : Function.Injective (rcons (d := d) i) := by rintro ⟨⟨head₁, tail₁⟩, _⟩ ⟨⟨head₂, tail₂⟩, _⟩ simp only [rcons, NormalWord.mk.injEq, EmbeddingLike.apply_eq_iff_eq, Word.Pair.mk.injEq, Pair.mk.injEq, and_imp] intro h₁ h₂ h₃ subst h₂ rw [← equiv_fst_mul_equiv_snd (d.compl i) head₁, ← equiv_fst_mul_equiv_snd (d.compl i) head₂, h₁, h₃] simp /-- The equivalence between `NormalWord`s and pairs. We can turn a `NormalWord` into a pair by taking the head of the `List` if it is in `G i` and multiplying it by the element of the base group. -/ noncomputable def equivPair (i) : NormalWord d ≃ Pair d i := letI toFun : NormalWord d → Pair d i := fun w => letI p := Word.equivPair i (CoprodI.of (φ i w.head) • w.toWord) { toPair := p normalized := fun j g hg => by dsimp only [p] at hg rw [Word.of_smul_def, ← Word.equivPair_symm, Equiv.apply_symm_apply] at hg dsimp at hg exact w.normalized _ _ (Word.mem_of_mem_equivPair_tail _ hg) } haveI leftInv : Function.LeftInverse (rcons i) toFun := fun w => ext_smul i <| by simp only [toFun, rcons, Word.equivPair_symm, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul] { toFun := toFun invFun := rcons i left_inv := leftInv right_inv := fun _ => rcons_injective (leftInv _) } noncomputable instance summandAction (i : ι) : MulAction (G i) (NormalWord d) := { smul := fun g w => (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } one_smul := fun _ => by dsimp [instHSMul] rw [one_mul] exact (equivPair i).symm_apply_apply _ mul_smul := fun _ _ _ => by dsimp [instHSMul] simp [mul_assoc, Equiv.apply_symm_apply] } theorem summand_smul_def' {i : ι} (g : G i) (w : NormalWord d) : g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := rfl noncomputable instance mulAction : MulAction (PushoutI φ) (NormalWord d) := MulAction.ofEndHom <| lift (fun _ => MulAction.toEndHom) MulAction.toEndHom <| by intro i simp only [MulAction.toEndHom, DFunLike.ext_iff, MonoidHom.coe_comp, MonoidHom.coe_mk, OneHom.coe_mk, comp_apply] intro h funext w apply NormalWord.ext_smul i simp only [summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, equiv_fst_eq_mul_inv, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul, base_smul_def', MonoidHom.apply_ofInjective_symm] theorem base_smul_def (h : H) (w : NormalWord d) : base φ h • w = { w with head := h * w.head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_base] rfl theorem summand_smul_def {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_of] rfl theorem of_smul_eq_smul {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = g • w := by rw [summand_smul_def, summand_smul_def'] theorem base_smul_eq_smul (h : H) (w : NormalWord d) : base φ h • w = h • w := by rw [base_smul_def, base_smul_def'] /-- Induction principle for `NormalWord`, that corresponds closely to inducting on the underlying list. -/ @[elab_as_elim] noncomputable def consRecOn {motive : NormalWord d → Sort _} (w : NormalWord d) (empty : motive empty) (cons : ∀ (i : ι) (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (_hgn : g ∈ d.set i) (hgr : g ∉ (φ i).range) (_hw1 : w.head = 1), motive w → motive (cons g w hmw hgr)) (base : ∀ (h : H) (w : NormalWord d), w.head = 1 → motive w → motive (base φ h • w)) : motive w := by rcases w with ⟨w, head, h3⟩ convert base head ⟨w, 1, h3⟩ rfl ?_ · simp [base_smul_def] · induction w using Word.consRecOn with | empty => exact empty | cons i g w h1 hg1 ih => convert cons i g ⟨w, 1, fun _ _ h => h3 _ _ (List.mem_cons_of_mem _ h)⟩ h1 (h3 _ _ List.mem_cons_self) ?_ rfl (ih ?_) · ext simp only [Word.cons, NormalWord.cons, map_one, mul_one, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] · apply d.injective i simp only [NormalWord.cons, equiv_fst_eq_mul_inv, MonoidHom.apply_ofInjective_symm, map_one, mul_one, mul_inv_cancel, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] · rwa [← SetLike.mem_coe, ← coe_equiv_snd_eq_one_iff_mem (d.compl i) (d.one_mem _), (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] theorem cons_eq_smul {i : ι} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : cons g w hmw hgr = of (φ := φ) i g • w := by apply ext_smul i simp only [cons, Word.cons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, summand_smul_def, equivPair, rcons, Word.equivPair_symm, Word.rcons_eq_smul, Equiv.coe_fn_mk, Word.equivPair_tail_eq_inv_smul, Equiv.coe_fn_symm_mk, smul_inv_smul] @[simp] theorem prod_summand_smul {i : ι} (g : G i) (w : NormalWord d) : (g • w).prod = of i g * w.prod := by simp only [prod, summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, ← of_apply_eq_base φ i, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, Word.prod_smul, ofCoprodI_of, inv_mul_cancel_left, mul_inv_cancel_left] @[simp] theorem prod_smul (g : PushoutI φ) (w : NormalWord d) : (g • w).prod = g * w.prod := by induction g using PushoutI.induction_on generalizing w with | of i g => rw [of_smul_eq_smul, prod_summand_smul] | base h => rw [base_smul_eq_smul, prod_base_smul] | mul x y ihx ihy => rw [mul_smul, ihx, ihy, mul_assoc] theorem prod_smul_empty (w : NormalWord d) : w.prod • empty = w := by induction w using consRecOn with | empty => simp | cons i g w _ _ _ _ ih => rw [prod_cons, mul_smul, ih, cons_eq_smul] | base h w _ ih => rw [prod_smul, mul_smul, ih] /-- The equivalence between normal forms and elements of the pushout -/ noncomputable def equiv : PushoutI φ ≃ NormalWord d := { toFun := fun g => g • .empty invFun := fun w => w.prod left_inv := fun g => by simp only [prod_smul, prod_empty, mul_one] right_inv := fun w => prod_smul_empty w } theorem prod_injective {ι : Type*} {G : ι → Type*} [(i : ι) → Group (G i)] {φ : (i : ι) → H →* G i} {d : Transversal φ} : Function.Injective (prod : NormalWord d → PushoutI φ) := by letI := Classical.decEq ι letI := fun i => Classical.decEq (G i) classical exact equiv.symm.injective instance : FaithfulSMul (PushoutI φ) (NormalWord d) := ⟨fun h => by simpa using congr_arg prod (h empty)⟩ instance (i : ι) : FaithfulSMul (G i) (NormalWord d) := ⟨by simp [summand_smul_def']⟩ instance : FaithfulSMul H (NormalWord d) := ⟨by simp [base_smul_def']⟩ end NormalWord open NormalWord /-- All maps into the `PushoutI`, or amalgamated product of groups are injective, provided all maps in the diagram are injective. See also `base_injective` -/ theorem of_injective (hφ : ∀ i, Function.Injective (φ i)) (i : ι) : Function.Injective (of (φ := φ) i) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [funext_iff, of_smul_eq_smul]) theorem base_injective (hφ : ∀ i, Function.Injective (φ i)) : Function.Injective (base φ) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [funext_iff, base_smul_eq_smul]) section Reduced variable (φ) in /-- A word in `CoprodI` is reduced if none of its letters are in the base group. -/ def Reduced (w : Word G) : Prop := ∀ g, g ∈ w.toList → g.2 ∉ (φ g.1).range theorem Reduced.exists_normalWord_prod_eq (d : Transversal φ) {w : Word G} (hw : Reduced φ w) : ∃ w' : NormalWord d, w'.prod = ofCoprodI w.prod ∧ w'.toList.map Sigma.fst = w.toList.map Sigma.fst := by classical induction w using Word.consRecOn with | empty => exact ⟨empty, by simp, rfl⟩ | cons i g w hIdx hg1 ih => rcases ih (fun _ hg => hw _ (List.mem_cons_of_mem _ hg)) with ⟨w', hw'prod, hw'map⟩ refine ⟨cons g w' ?_ ?_, ?_⟩ · rwa [Word.fstIdx, ← List.head?_map, hw'map, List.head?_map] · exact hw _ List.mem_cons_self · simp [hw'prod, hw'map] /-- For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base group. -/ theorem Reduced.eq_empty_of_mem_range (hφ : ∀ i, Injective (φ i)) {w : Word G} (hw : Reduced φ w) (h : ofCoprodI w.prod ∈ (base φ).range) : w = .empty := by rcases transversal_nonempty φ hφ with ⟨d⟩ rcases hw.exists_normalWord_prod_eq d with ⟨w', hw'prod, hw'map⟩ rcases h with ⟨h, heq⟩ have : (NormalWord.prod (d := d) ⟨.empty, h, by simp⟩) = base φ h := by simp [NormalWord.prod] rw [← hw'prod, ← this] at heq suffices w'.toWord = .empty by simp [this, @eq_comm _ []] at hw'map ext simp [hw'map] rw [← prod_injective heq] end Reduced /-- The intersection of the images of the maps from any two distinct groups in the diagram into the amalgamated product is the image of the map from the base group in the diagram. -/ theorem inf_of_range_eq_base_range (hφ : ∀ i, Injective (φ i)) {i j : ι} (hij : i ≠ j) : (of i).range ⊓ (of j).range = (base φ).range := le_antisymm (by intro x ⟨⟨g₁, hg₁⟩, ⟨g₂, hg₂⟩⟩ by_contra hx have hx1 : x ≠ 1 := by rintro rfl; simp_all only [ne_eq, one_mem, not_true_eq_false] have hg₁1 : g₁ ≠ 1 := ne_of_apply_ne (of (φ := φ) i) (by simp_all) have hg₂1 : g₂ ≠ 1 := ne_of_apply_ne (of (φ := φ) j) (by simp_all) have hg₁r : g₁ ∉ (φ i).range := by rintro ⟨y, rfl⟩ subst hg₁ exact hx (of_apply_eq_base φ i y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) have hg₂r : g₂ ∉ (φ j).range := by rintro ⟨y, rfl⟩ subst hg₂ exact hx (of_apply_eq_base φ j y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) let w : Word G := ⟨[⟨_, g₁⟩, ⟨_, g₂⁻¹⟩], by simp_all, by simp_all⟩ have hw : Reduced φ w := by simp only [w, Reduced, List.mem_cons, forall_eq_or_imp, not_false_eq_true, hg₁r, hg₂r, List.mem_nil_iff, false_imp_iff, imp_true_iff, and_true, inv_mem_iff] have := hw.eq_empty_of_mem_range hφ (by simp only [w, Word.prod, List.map_cons, List.prod_cons, List.prod_nil, List.map_nil, map_mul, ofCoprodI_of, hg₁, hg₂, map_inv, mul_one, mul_inv_cancel, one_mem]) simp [w, Word.empty] at this) (le_inf (by rw [← of_comp_eq_base i] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ i h, rfl⟩) (by rw [← of_comp_eq_base j] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ j h, rfl⟩)) end PushoutI end Monoid
MulExpNegMulSqIntegral.lean
/- Copyright (c) 2025 Jakob Stiefel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob Stiefel -/ import Mathlib.Analysis.SpecialFunctions.MulExpNegMulSq import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Measure.RegularityCompacts import Mathlib.Topology.ContinuousMap.StoneWeierstrass /-! # Properties of the integral of `mulExpNegMulSq` The mapping `mulExpNegMulSq` can be used to transform a function `g : E → ℝ` into a bounded function `mulExpNegMulSq ε ∘ g : E → ℝ = fun x => g x * Real.exp (-ε * g x * g x)`. This file contains results on the integral of `mulExpNegMulSq g ε` with respect to a finite measure `P`. ## Lemmas - `tendsto_integral_mulExpNegMulSq_comp`: By the dominated convergence theorem and `mulExpNegMulSq_abs_le_norm`, the integral of `mulExpNegMulSq ε ∘ g` with respect to a finite measure `P` converges to the integral of `g`, as `ε → 0`; - `tendsto_integral_mul_one_add_inv_smul_sq_pow`: The integral of `mulExpNegMulSq ε ∘ g` with respect to a finite measure `P` can be approximated by the integral of the sequence approximating the exponential function, `fun x => (g * (1 + (n : ℝ)⁻¹ • -(ε • g * g)) ^ n) x`. This allows to transfer properties of a subalgebra of functions containing `g` to the function `mulExpNegMulSq ε ∘ g`, see e.g. `integral_mulExpNegMulSq_comp_eq`. ## Main Result `dist_integral_mulExpNegMulSq_comp_le`: For a subalgebra of functions `A`, if for any `g ∈ A` the integral with respect to two finite measures `P, P'` coincide, then the difference of the integrals of `mulExpNegMulSq ε ∘ g` with respect to `P, P'` is bounded by `6 * √ε`. This is a key ingredient in the proof of theorem `ext_of_forall_mem_subalgebra_integral_eq`, where it is shown that a subalgebra of functions that separates points separates finite measures. -/ open MeasureTheory Real NNReal ENNReal BoundedContinuousFunction Filter open scoped Topology variable {E : Type*} [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] {P : Measure E} [IsFiniteMeasure P] {ε : ℝ} theorem integrable_mulExpNegMulSq_comp (f : C(E, ℝ)) (hε : 0 < ε) : Integrable (fun x => mulExpNegMulSq ε (f x)) P := by apply integrable P ⟨⟨fun x => mulExpNegMulSq ε (f x), by fun_prop⟩, ⟨2 * (√ε)⁻¹, _⟩⟩ exact fun x y => dist_mulExpNegMulSq_le_two_mul_sqrt hε (f x) (f y) theorem integrable_mulExpNegMulSq_comp_restrict_of_isCompact {K : Set E} (hK : IsCompact K) (hKmeas : MeasurableSet K) (g : C(E, ℝ)) : Integrable (fun x => mulExpNegMulSq ε (g x)) (P.restrict K) := g.continuous.mulExpNegMulSq.continuousOn.integrableOn_compact' hK hKmeas /-- The integral of `mulExpNegMulSq ε ∘ g` with respect to a finite measure `P` converges to the integral of `g`, as `ε → 0` from above. -/ theorem tendsto_integral_mulExpNegMulSq_comp (g : E →ᵇ ℝ) : Tendsto (fun ε => ∫ x, mulExpNegMulSq ε (g x) ∂P) (𝓝[>] 0) (𝓝 (∫ x, g x ∂P)) := by apply tendsto_of_seq_tendsto intro u hu obtain ⟨N, hupos⟩ := eventually_atTop.mp (tendsto_nhdsWithin_iff.mp hu).2 apply tendsto_integral_filter_of_norm_le_const ?h_meas ?h_bound ?h_lim · exact Eventually.of_forall (fun n => g.continuous.mulExpNegMulSq.aestronglyMeasurable) · use norm g rw [eventually_atTop] use N intro n hn exact Eventually.of_forall (fun _ => abs_mulExpNegMulSq_comp_le_norm g (le_of_lt (Set.mem_Ioi.mp (hupos n hn)))) · exact Eventually.of_forall (fun _ => (tendsto_nhdsWithin_of_tendsto_nhds tendsto_mulExpNegMulSq).comp hu) /-- The integral of `mulExpNegMulSq ε ∘ g` with respect to a finite measure `P` can be approximated by the integral of the sequence approximating the exponential function. -/ theorem tendsto_integral_mul_one_add_inv_smul_sq_pow (g : E →ᵇ ℝ) (hε : 0 < ε) : Tendsto (fun (n : ℕ) => ∫ x, (g * (1 + (n : ℝ)⁻¹ • -(ε • g * g)) ^ n) x ∂ P) atTop (𝓝 (∫ x, mulExpNegMulSq ε (g x) ∂P)) := by apply tendsto_integral_filter_of_norm_le_const ?h_meas ?h_bound ?h_lim · apply Eventually.of_forall exact fun n => StronglyMeasurable.aestronglyMeasurable (Continuous.stronglyMeasurable (Continuous.mul g.continuous ((1 + ((n : ℝ)⁻¹ • -(ε • g * g))) ^ n).continuous)) · obtain ⟨N, hgN⟩ := exists_nat_gt (ε * (norm g * norm g)) use norm g rw [eventually_atTop] use N intro n hn have hnpos : 0 < (n : ℝ) := by apply lt_of_lt_of_le (lt_of_le_of_lt _ hgN) (Nat.cast_le.mpr hn) exact (mul_nonneg (le_of_lt hε) (mul_self_nonneg (norm g))) apply Eventually.of_forall intro x simp only [smul_neg, BoundedContinuousFunction.coe_mul, Pi.mul_apply, pow_apply, BoundedContinuousFunction.coe_add, BoundedContinuousFunction.coe_one, coe_neg, BoundedContinuousFunction.coe_smul, smul_eq_mul, Pi.add_apply, Pi.one_apply, Pi.neg_apply, norm_mul, norm_eq_abs, norm_pow] refine (mul_le_mul_of_nonneg_right (norm_coe_le_norm g x) (pow_nonneg (abs_nonneg _) n)).trans <| mul_le_of_le_one_right (norm_nonneg _) ?_ apply pow_le_one₀ (abs_nonneg _) rw [mul_assoc, inv_mul_eq_div, abs_le] refine ⟨?_, (add_le_iff_nonpos_right 1).mpr (Left.neg_nonpos_iff.mpr (div_nonneg (mul_nonneg (le_of_lt hε) (mul_self_nonneg (g x))) (le_of_lt hnpos)))⟩ apply le_trans (by linarith) (sub_nonneg_of_le ((div_le_one hnpos).mpr _)) apply le_trans (le_trans _ (le_of_lt hgN)) (Nat.cast_le.mpr hn) apply mul_le_mul (Preorder.le_refl ε) _ (mul_self_nonneg (g x)) (le_of_lt hε) rw [← abs_le_iff_mul_self_le, abs_norm] exact norm_coe_le_norm g x · apply Eventually.of_forall intro x apply Tendsto.const_mul (g x) simp [mul_assoc, inv_mul_eq_div, ← neg_div] exact tendsto_one_add_div_pow_exp (-(ε * (g x * g x))) @[deprecated (since := "2025-05-22")] alias tendsto_integral_mul_one_plus_inv_smul_sq_pow := tendsto_integral_mul_one_add_inv_smul_sq_pow theorem integral_mulExpNegMulSq_comp_eq {P' : Measure E} [IsFiniteMeasure P'] {A : Subalgebra ℝ (E →ᵇ ℝ)} (hε : 0 < ε) (heq : ∀ g ∈ A, ∫ x, (g : E → ℝ) x ∂P = ∫ x, (g : E → ℝ) x ∂P') {g : E →ᵇ ℝ} (hgA : g ∈ A) : ∫ x, mulExpNegMulSq ε (g x) ∂P = ∫ x, mulExpNegMulSq ε (g x) ∂P' := by have one_add_inv_mul_mem (n : ℕ) : g * (1 + (n : ℝ)⁻¹ • -(ε • g * g)) ^ n ∈ A := by apply Subalgebra.mul_mem A hgA (Subalgebra.pow_mem A _ n) apply Subalgebra.add_mem A (Subalgebra.one_mem A) (Subalgebra.smul_mem A _ n⁻¹) exact Subalgebra.neg_mem A (Subalgebra.mul_mem A (Subalgebra.smul_mem A hgA ε) hgA) have limP : Tendsto (fun n : ℕ => ∫ x, (g * (1 + (n : ℝ)⁻¹ • -(ε • g * g)) ^ n) x ∂P) atTop (𝓝 (∫ x, mulExpNegMulSq ε (g x) ∂P')) := by rw [funext fun n => heq _ (one_add_inv_mul_mem n)] exact tendsto_integral_mul_one_add_inv_smul_sq_pow g hε exact tendsto_nhds_unique (tendsto_integral_mul_one_add_inv_smul_sq_pow g hε) limP theorem abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt (f : C(E, ℝ)) {K : Set E} (hK : MeasurableSet K) (hε : 0 < ε) (hKP : P Kᶜ < ε.toNNReal) : |∫ x, mulExpNegMulSq ε (f x) ∂P - ∫ x in K, mulExpNegMulSq ε (f x) ∂P| < √ε := by apply lt_of_le_of_lt (norm_integral_sub_setIntegral_le (Eventually.of_forall (fun _ => abs_mulExpNegMulSq_le hε)) hK (integrable_mulExpNegMulSq_comp f hε)) rw [mul_inv_lt_iff₀ (sqrt_pos_of_pos hε), mul_self_sqrt (le_of_lt hε)] exact toReal_lt_of_lt_ofReal hKP theorem abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure {K : Set E} (hK : IsCompact K) (hKmeas : MeasurableSet K) (f g : C(E, ℝ)) {δ : ℝ} (hε : 0 < ε) (hfg : ∀ x ∈ K, |g x - f x| < δ) : |∫ x in K, mulExpNegMulSq ε (g x) ∂P - ∫ x in K, mulExpNegMulSq ε (f x) ∂P| ≤ δ * (P K).toReal := by rw [← (integral_sub (integrable_mulExpNegMulSq_comp_restrict_of_isCompact hK hKmeas g) (integrable_mulExpNegMulSq_comp_restrict_of_isCompact hK hKmeas f)), ← norm_eq_abs] exact norm_setIntegral_le_of_norm_le_const hK.measure_lt_top (fun x hxK => le_trans (dist_mulExpNegMulSq_le_dist hε) (hfg x hxK).le) variable {E : Type*} [MeasurableSpace E] [PseudoEMetricSpace E] [BorelSpace E] [CompleteSpace E] [SecondCountableTopology E] {P P' : Measure E} [IsFiniteMeasure P] [IsFiniteMeasure P'] /-- If for any `g ∈ A` the integrals with respect to two finite measures `P, P'` coincide, then the difference of the integrals of `mulExpNegMulSq ε ∘ g` with respect to `P, P'` is bounded by `6 * √ε`. -/ theorem dist_integral_mulExpNegMulSq_comp_le (f : E →ᵇ ℝ) {A : Subalgebra ℝ (E →ᵇ ℝ)} (hA : (A.map (toContinuousMapₐ ℝ)).SeparatesPoints) (heq : ∀ g ∈ A, ∫ x, (g : E → ℝ) x ∂P = ∫ x, (g : E → ℝ) x ∂P') (hε : 0 < ε) : |∫ x, mulExpNegMulSq ε (f x) ∂P - ∫ x, mulExpNegMulSq ε (f x) ∂P'| ≤ 6 * √ε := by -- if both measures are zero, the result is trivial by_cases hPP' : P = 0 ∧ P' = 0 · simp only [hPP', integral_zero_measure, sub_self, abs_zero, Nat.ofNat_pos, mul_nonneg_iff_of_pos_left, (le_of_lt (sqrt_pos_of_pos hε))] let const : ℝ := (max (P.real Set.univ) (P'.real Set.univ)) have pos_of_measure : 0 < const := by rw [not_and_or] at hPP' rcases hPP' with hP0 | hP'0 · exact lt_max_of_lt_left (toReal_pos ((Measure.measure_univ_ne_zero).mpr hP0) (measure_ne_top P Set.univ)) · exact lt_max_of_lt_right (toReal_pos ((Measure.measure_univ_ne_zero).mpr hP'0) (measure_ne_top P' Set.univ)) -- obtain K, a compact and closed set, which covers E up to a small area of measure at most ε -- wrt to both P and P' obtain ⟨KP, _, hKPco, hKPcl, hKP⟩ := MeasurableSet.exists_isCompact_isClosed_diff_lt (MeasurableSet.univ) (measure_ne_top P Set.univ) (ne_of_gt (ofReal_pos.mpr hε)) obtain ⟨KP', _, hKP'co, hKP'cl, hKP'⟩ := MeasurableSet.exists_isCompact_isClosed_diff_lt (MeasurableSet.univ) (measure_ne_top P' Set.univ) (ne_of_gt (ofReal_pos.mpr hε)) let K := KP ∪ KP' have hKco := IsCompact.union hKPco hKP'co have hKcl := IsClosed.union hKPcl hKP'cl simp [← Set.compl_eq_univ_diff] at hKP hKP' have hKPbound : P (KP ∪ KP')ᶜ < ε.toNNReal := lt_of_le_of_lt (measure_mono (Set.compl_subset_compl_of_subset (Set.subset_union_left))) hKP have hKP'bound : P' (KP ∪ KP')ᶜ < ε.toNNReal := lt_of_le_of_lt (measure_mono (Set.compl_subset_compl_of_subset (Set.subset_union_right))) hKP' -- stone-weierstrass approximation of f on K obtain ⟨g', hg'A, hg'approx⟩ := ContinuousMap.exists_mem_subalgebra_near_continuous_of_isCompact_of_separatesPoints hA f hKco (Left.mul_pos (sqrt_pos_of_pos hε) (inv_pos_of_pos pos_of_measure)) simp only [Subalgebra.mem_map] at hg'A let g := hg'A.choose have hgA : g ∈ A := hg'A.choose_spec.1 have hgapprox : ∀ x ∈ K, ‖g x - f x‖ < √ε * const⁻¹ := by rw [← coe_toContinuousMapₐ ℝ g, hg'A.choose_spec.2] exact hg'approx -- collect the results needed in the decomposition at the end of the proof have line1 : |∫ x, mulExpNegMulSq ε (f x) ∂P - ∫ x in K, mulExpNegMulSq ε (f x) ∂P| < √ε := abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt f (IsClosed.measurableSet hKcl) hε hKPbound have line3 : |∫ x in K, mulExpNegMulSq ε (g x) ∂P - ∫ x, mulExpNegMulSq ε (g x) ∂P| < √ε := by rw [abs_sub_comm] exact (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt g (IsClosed.measurableSet hKcl) hε hKPbound) have line5 : |∫ x, mulExpNegMulSq ε (g x) ∂P' - ∫ x in K, mulExpNegMulSq ε (g x) ∂P'| < √ε := (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt g (IsClosed.measurableSet hKcl) hε hKP'bound) have line7 : |∫ x in K, mulExpNegMulSq ε (f x) ∂P' - ∫ x, mulExpNegMulSq ε (f x) ∂P'| < √ε := by rw [abs_sub_comm] exact (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt f (IsClosed.measurableSet hKcl) hε hKP'bound) have line2 : |∫ x in K, mulExpNegMulSq ε (f x) ∂P - ∫ x in K, mulExpNegMulSq ε (g x) ∂P| ≤ √ε := by rw [abs_sub_comm] apply le_trans (abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure hKco (IsClosed.measurableSet hKcl) f g hε hgapprox) rw [mul_assoc] apply mul_le_of_le_one_right (le_of_lt (sqrt_pos_of_pos hε)) apply inv_mul_le_one_of_le₀ (le_max_of_le_left _) (le_of_lt pos_of_measure) exact (toReal_le_toReal (measure_ne_top P _) (measure_ne_top P _)).mpr (measure_mono (Set.subset_univ _)) have line6 : |∫ x in K, mulExpNegMulSq ε (g x) ∂P' - ∫ x in K, mulExpNegMulSq ε (f x) ∂P'| ≤ √ε := by apply le_trans (abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure hKco (IsClosed.measurableSet hKcl) f g hε hgapprox) rw [mul_assoc] apply mul_le_of_le_one_right (le_of_lt (sqrt_pos_of_pos hε)) apply inv_mul_le_one_of_le₀ (le_max_of_le_right _) (le_of_lt pos_of_measure) exact (toReal_le_toReal (measure_ne_top P' _) (measure_ne_top P' _)).mpr (measure_mono (Set.subset_univ _)) have line4 : |∫ x, mulExpNegMulSq ε (g x) ∂P - ∫ x, mulExpNegMulSq ε (g x) ∂P'| = 0 := by rw [abs_eq_zero, sub_eq_zero] exact integral_mulExpNegMulSq_comp_eq hε heq hgA calc |∫ x, mulExpNegMulSq ε (f x) ∂P - ∫ x, mulExpNegMulSq ε (f x) ∂P'| ≤ |∫ x, mulExpNegMulSq ε (f x) ∂P - ∫ x in K, mulExpNegMulSq ε (f x) ∂P| + |∫ x in K, mulExpNegMulSq ε (f x) ∂P - ∫ x in K, mulExpNegMulSq ε (g x) ∂P| + |∫ x in K, mulExpNegMulSq ε (g x) ∂P - ∫ x, mulExpNegMulSq ε (g x) ∂P| + |∫ x, mulExpNegMulSq ε (g x) ∂P - ∫ x, mulExpNegMulSq ε (g x) ∂P'| + |∫ x, mulExpNegMulSq ε (g x) ∂P' - ∫ x in K, mulExpNegMulSq ε (g x) ∂P'| + |∫ x in K, mulExpNegMulSq ε (g x) ∂P' - ∫ x in K, mulExpNegMulSq ε (f x) ∂P'| + |∫ x in K, mulExpNegMulSq ε (f x) ∂P' - ∫ x, mulExpNegMulSq ε (f x) ∂P'| := @dist_triangle8 ℝ _ _ _ _ _ _ _ _ _ _ ≤ 6 * √ε := by linarith
Basic.lean
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.W.Basic /-! # Polynomial Functors This file defines polynomial functors and the W-type construction as a polynomial functor. (For the M-type construction, see `Mathlib/Data/PFunctor/Univariate/M.lean`.) -/ universe u v uA uB uA₁ uB₁ uA₂ uB₂ v₁ v₂ v₃ /-- A polynomial functor `P` is given by a type `A` and a family `B` of types over `A`. `P` maps any type `α` to a new type `P α`, which is defined as the sigma type `Σ x, P.B x → α`. An element of `P α` is a pair `⟨a, f⟩`, where `a` is an element of a type `A` and `f : B a → α`. Think of `a` as the shape of the object and `f` as an index to the relevant elements of `α`. -/ -- Note: `nolint checkUnivs` should not apply here, we really do want two separate universe levels @[pp_with_univ, nolint checkUnivs] structure PFunctor where /-- The head type -/ A : Type uA /-- The child family of types -/ B : A → Type uB namespace PFunctor instance : Inhabited PFunctor := ⟨⟨default, default⟩⟩ variable (P : PFunctor.{uA, uB}) {α : Type v₁} {β : Type v₂} {γ : Type v₃} /-- Applying `P` to an object of `Type` -/ @[coe] def Obj (α : Type v) : Type (max v uA uB) := Σ x : P.A, P.B x → α instance : CoeFun PFunctor.{uA, uB} (fun _ => Type v → Type (max v uA uB)) where coe := Obj /-- Applying `P` to a morphism of `Type` -/ def map (f : α → β) : P α → P β := fun ⟨a, g⟩ => ⟨a, f ∘ g⟩ instance Obj.inhabited [Inhabited P.A] [Inhabited α] : Inhabited (P α) := ⟨⟨default, default⟩⟩ instance : Functor P.Obj where map := @map P /-- We prefer `PFunctor.map` to `Functor.map` because it is universe-polymorphic. -/ @[simp] theorem map_eq_map {α β : Type v} (f : α → β) (x : P α) : f <$> x = P.map f x := rfl @[simp] protected theorem map_eq (f : α → β) (a : P.A) (g : P.B a → α) : P.map f ⟨a, g⟩ = ⟨a, f ∘ g⟩ := rfl @[simp] protected theorem id_map : ∀ x : P α, P.map id x = x := fun ⟨_, _⟩ => rfl @[simp] protected theorem map_map (f : α → β) (g : β → γ) : ∀ x : P α, P.map g (P.map f x) = P.map (g ∘ f) x := fun ⟨_, _⟩ => rfl instance : LawfulFunctor (Obj.{v} P) where map_const := rfl id_map x := P.id_map x comp_map f g x := P.map_map f g x |>.symm /-- Re-export existing definition of W-types and adapt it to a packaged definition of polynomial functor. -/ def W : Type (max uA uB) := WType P.B /- Inhabitants of W types is awkward to encode as an instance assumption because there needs to be a value `a : P.A` such that `P.B a` is empty to yield a finite tree. -/ variable {P} /-- The root element of a W tree -/ def W.head : W P → P.A | ⟨a, _f⟩ => a /-- The children of the root of a W tree -/ def W.children : ∀ x : W P, P.B (W.head x) → W P | ⟨_a, f⟩ => f /-- The destructor for W-types -/ def W.dest : W P → P (W P) | ⟨a, f⟩ => ⟨a, f⟩ /-- The constructor for W-types -/ def W.mk : P (W P) → W P | ⟨a, f⟩ => ⟨a, f⟩ @[simp] theorem W.dest_mk (p : P (W P)) : W.dest (W.mk p) = p := by cases p; rfl @[simp] theorem W.mk_dest (p : W P) : W.mk (W.dest p) = p := by cases p; rfl variable (P) /-- `Idx` identifies a location inside the application of a polynomial functor. For `F : PFunctor`, `x : F α` and `i : F.Idx`, `i` can designate one part of `x` or is invalid, if `i.1 ≠ x.1`. -/ def Idx : Type (max uA uB) := Σ x : P.A, P.B x instance Idx.inhabited [Inhabited P.A] [Inhabited (P.B default)] : Inhabited P.Idx := ⟨⟨default, default⟩⟩ variable {P} /-- `x.iget i` takes the component of `x` designated by `i` if any is or returns a default value -/ def Obj.iget [DecidableEq P.A] {α} [Inhabited α] (x : P α) (i : P.Idx) : α := if h : i.1 = x.1 then x.2 (cast (congr_arg _ h) i.2) else default @[simp] theorem fst_map (x : P α) (f : α → β) : (P.map f x).1 = x.1 := by cases x; rfl @[simp] theorem iget_map [DecidableEq P.A] [Inhabited α] [Inhabited β] (x : P α) (f : α → β) (i : P.Idx) (h : i.1 = x.1) : (P.map f x).iget i = f (x.iget i) := by simp only [Obj.iget, fst_map, *, dif_pos] cases x rfl end PFunctor /- Composition of polynomial functors. -/ namespace PFunctor /-- Composition for polynomial functors -/ def comp (P₂ : PFunctor.{uA₂, uB₂}) (P₁ : PFunctor.{uA₁, uB₁}) : PFunctor.{max uA₁ uA₂ uB₂, max uB₁ uB₂} := ⟨Σ a₂ : P₂.1, P₂.2 a₂ → P₁.1, fun a₂a₁ => Σ u : P₂.2 a₂a₁.1, P₁.2 (a₂a₁.2 u)⟩ /-- Constructor for composition -/ def comp.mk (P₂ : PFunctor.{uA₂, uB₂}) (P₁ : PFunctor.{uA₁, uB₁}) {α : Type v} (x : P₂ (P₁ α)) : comp P₂ P₁ α := ⟨⟨x.1, Sigma.fst ∘ x.2⟩, fun a₂a₁ => (x.2 a₂a₁.1).2 a₂a₁.2⟩ /-- Destructor for composition -/ def comp.get (P₂ : PFunctor.{uA₂, uB₂}) (P₁ : PFunctor.{uA₁, uB₁}) {α : Type v} (x : comp P₂ P₁ α) : P₂ (P₁ α) := ⟨x.1.1, fun a₂ => ⟨x.1.2 a₂, fun a₁ => x.2 ⟨a₂, a₁⟩⟩⟩ end PFunctor /- Lifting predicates and relations. -/ namespace PFunctor variable {P : PFunctor.{uA, uB}} open Functor theorem liftp_iff {α : Type u} (p : α → Prop) (x : P α) : Liftp p x ↔ ∃ a f, x = ⟨a, f⟩ ∧ ∀ i, p (f i) := by constructor · rintro ⟨y, hy⟩ rcases h : y with ⟨a, f⟩ refine ⟨a, fun i => (f i).val, ?_, fun i => (f i).property⟩ rw [← hy, h, map_eq_map, PFunctor.map_eq] congr rintro ⟨a, f, xeq, pf⟩ use ⟨a, fun i => ⟨f i, pf i⟩⟩ rw [xeq]; rfl theorem liftp_iff' {α : Type u} (p : α → Prop) (a : P.A) (f : P.B a → α) : @Liftp.{u} P.Obj _ α p ⟨a, f⟩ ↔ ∀ i, p (f i) := by simp only [liftp_iff]; constructor <;> intro h · rcases h with ⟨a', f', heq, h'⟩ cases heq assumption repeat' first |constructor|assumption theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : P α) : Liftr r x y ↔ ∃ a f₀ f₁, x = ⟨a, f₀⟩ ∧ y = ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := by constructor · rintro ⟨u, xeq, yeq⟩ rcases h : u with ⟨a, f⟩ use a, fun i => (f i).val.fst, fun i => (f i).val.snd constructor · rw [← xeq, h] rfl constructor · rw [← yeq, h] rfl intro i exact (f i).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use ⟨a, fun i => ⟨(f₀ i, f₁ i), h i⟩⟩ constructor · rw [xeq] rfl rw [yeq]; rfl open Set theorem supp_eq {α : Type u} (a : P.A) (f : P.B a → α) : @supp.{u} P.Obj _ α (⟨a, f⟩ : P α) = f '' univ := by ext x; simp only [supp, image_univ, mem_range, mem_setOf_eq] constructor <;> intro h · apply @h fun x => ∃ y : P.B a, f y = x rw [liftp_iff'] intro exact ⟨_, rfl⟩ · simp only [liftp_iff'] cases h subst x tauto end PFunctor
L1.lean
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.SetToL1 /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here for L1 functions by extending the integral on simple functions. See the file `Mathlib/MeasureTheory/Integral/Bochner/Basic.lean` for the integral of functions and corresponding API. ## Main definitions The Bochner integral is defined through the extension process described in the file `Mathlib/MeasureTheory/Integral/SetToL1.lean`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = μ.real s * x`. `weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive` (defined in the file `Mathlib/MeasureTheory/Integral/SetToL1.lean`) with respect to the set `s`. 2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `SimpleFunc.integral` for details.) 3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation : `α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. ## Notations * `α →ₛ E` : simple functions (defined in `Mathlib/MeasureTheory/Function/SimpleFunc.lean`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `Mathlib/MeasureTheory/Function/LpSpace/Basic.lean`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `Mathlib/MeasureTheory/Function/SimpleFuncDense`) We also define notations for integral on a set, which are described in the file `Mathlib/MeasureTheory/Integral/SetIntegral.lean`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ assert_not_exists Differentiable noncomputable section open Filter ENNReal Set open scoped NNReal ENNReal MeasureTheory namespace MeasureTheory variable {α E F 𝕜 : Type*} section WeightedSMul open ContinuousLinearMap variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Given a set `s`, return the continuous linear map `fun x => μ.real s • x`. The extension of that set function through `setToL1` gives the Bochner integral of L1 functions. -/ def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F := μ.real s • ContinuousLinearMap.id ℝ F theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) : weightedSMul μ s x = μ.real s • x := by simp [weightedSMul] @[simp] theorem weightedSMul_zero_measure {m : MeasurableSpace α} : weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul] @[simp] theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) : weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by ext1 x push_cast simp_rw [Pi.add_apply, weightedSMul_apply] rw [measureReal_add_apply, add_smul] theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} : (weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by ext1 x simp [weightedSMul_apply, smul_smul] theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) : (weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by ext1 x; simp_rw [weightedSMul_apply, measureReal_def]; congr 2 theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by ext1 x; rw [weightedSMul_apply, measureReal_def, h_zero]; simp theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (hdisj : Disjoint s t) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by ext1 x simp_rw [add_apply, weightedSMul_apply, measureReal_union hdisj ht,add_smul] @[nolint unusedArguments] theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (hdisj : Disjoint s t) : (weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := weightedSMul_union' s t ht hs_finite ht_finite hdisj theorem weightedSMul_smul [SMul 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by simp_rw [weightedSMul_apply, smul_comm] theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ μ.real s := calc ‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖μ.real s‖ * ‖ContinuousLinearMap.id ℝ F‖ := norm_smul (μ.real s) (ContinuousLinearMap.id ℝ F) _ ≤ ‖μ.real s‖ := ((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le) _ = abs μ.real s := Real.norm_eq_abs _ _ = μ.real s := abs_eq_self.mpr ENNReal.toReal_nonneg theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) : DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 := ⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩ theorem weightedSMul_nonneg [PartialOrder F] [OrderedSMul ℝ F] (s : Set α) (x : F) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by simp only [weightedSMul, coe_smul', _root_.id, coe_id', Pi.smul_apply] exact smul_nonneg toReal_nonneg hx end WeightedSMul local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc section PosPart variable [LinearOrder E] [Zero E] [MeasurableSpace α] /-- Positive part of a simple function. -/ def posPart (f : α →ₛ E) : α →ₛ E := f.map fun b => max b 0 /-- Negative part of a simple function. -/ def negPart [Neg E] (f : α →ₛ E) : α →ₛ E := posPart (-f) theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _ theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by rw [negPart]; exact posPart_map_norm _ theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by simp only [posPart, negPart] ext a rw [coe_sub] exact max_zero_sub_eq_self (f a) end PosPart section Integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open Finset variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α} /-- Bochner integral of simple functions whose codomain is a real `NormedSpace`. This is equal to `∑ x ∈ f.range, μ.real (f ⁻¹' {x}) • x` (see `integral_eq`). -/ def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F := f.setToSimpleFunc (weightedSMul μ) theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : f.integral μ = ∑ x ∈ f.range, μ.real (f ⁻¹' {x}) • x := by simp [integral, setToSimpleFunc, weightedSMul_apply] theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) : f.integral μ = ∑ x ∈ {x ∈ f.range | x ≠ 0}, μ.real (f ⁻¹' {x}) • x := by simp_rw [integral_def, setToSimpleFunc_eq_sum_filter, weightedSMul_apply] /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F} (hs : {x ∈ f.range | x ≠ 0} ⊆ s) : f.integral μ = ∑ x ∈ s, μ.real (f ⁻¹' {x}) • x := by rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs] rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx rcases hx.symm with (rfl | hx) · simp rw [SimpleFunc.mem_range] at hx rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx] @[simp] theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) : (const α y).integral μ = μ.real univ • y := by classical calc (const α y).integral μ = ∑ z ∈ {y}, μ.real (const α y ⁻¹' {z}) • z := integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _) _ = μ.real univ • y := by simp [Set.preimage] @[simp] theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α} (hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by classical refine (integral_eq_sum_of_subset ?_).trans ((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm) · intro y hy simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at * rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩ exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩] · dsimp rw [Set.piecewise_eq_indicator, indicator_preimage_of_notMem, measureReal_restrict_apply (f.measurableSet_preimage _)] exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀) /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x ∈ f.range, (μ.real (f ⁻¹' {x})) • g x := map_setToSimpleFunc _ weightedSMul_union hf hg /-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf simp only [← map_apply g f, lintegral_eq_lintegral] rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum] · refine Finset.sum_congr rfl fun b _ => ?_ rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply, measureReal_def] · rintro a - by_cases a0 : a = 0 · rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top · apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne · simp [hg0] variable [NormedSpace ℝ E] theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h /-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/ theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) := h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm rw [← integral_eq_lintegral' hf] exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top] theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := setToSimpleFunc_add _ weightedSMul_union hf hg theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f := setToSimpleFunc_neg _ weightedSMul_union hf theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := setToSimpleFunc_sub _ weightedSMul_union hf hg theorem integral_smul [DistribSMul 𝕜 E] [SMulCommClass ℝ 𝕜 E] (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) : integral μ (c • f) = c • integral μ f := setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * μ.real s) {f : α →ₛ E} (hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ := calc ‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, μ.real (f ⁻¹' {x}) * ‖x‖ := norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf _ = C * (f.map norm).integral μ := by rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul] theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := by refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le exact (norm_weightedSMul_le s).trans (one_mul _).symm.le theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := by simp_rw [integral_def] refine setToSimpleFunc_add_left' (weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2] section Order variable [PartialOrder F] [IsOrderedAddMonoid F] [OrderedSMul ℝ F] lemma integral_nonneg {f : α →ₛ F} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ f.integral μ := by rw [integral_eq] apply Finset.sum_nonneg rw [forall_mem_range] intro y by_cases hy : 0 ≤ f y · positivity · suffices μ (f ⁻¹' {f y}) = 0 by simp [this, measureReal_def] rw [← nonpos_iff_eq_zero] refine le_of_le_of_eq (measure_mono fun x hx ↦ ?_) (ae_iff.mp hf) simp only [Set.mem_preimage, mem_singleton_iff, mem_setOf_eq] at hx ⊢ exact hx ▸ hy lemma integral_mono {f g : α →ₛ F} (h : f ≤ᵐ[μ] g) (hf : Integrable f μ) (hg : Integrable g μ) : f.integral μ ≤ g.integral μ := by rw [← sub_nonneg, ← integral_sub hg hf] rw [← sub_nonneg_ae] at h exact integral_nonneg h lemma integral_mono_measure {ν} {f : α →ₛ F} (hf : 0 ≤ᵐ[ν] f) (hμν : μ ≤ ν) (hfν : Integrable f ν) : f.integral μ ≤ f.integral ν := by simp only [integral_eq] apply Finset.sum_le_sum simp only [forall_mem_range] intro x by_cases hx : 0 ≤ f x · obtain (hx | hx) := hx.eq_or_lt · simp [← hx] simp only [measureReal_def] gcongr · exact integrable_iff.mp hfν (f x) hx.ne' |>.ne · exact hμν _ · suffices ν (f ⁻¹' {f x}) = 0 by have A : μ (f ⁻¹' {f x}) = 0 := by simpa using (hμν _ |>.trans_eq this) simp [measureReal_def, A, this] rw [← nonpos_iff_eq_zero, ← ae_iff.mp hf] refine measure_mono fun y hy ↦ ?_ simp_all end Order end Integral end SimpleFunc namespace L1 open AEEqFun Lp.simpleFunc Lp variable [NormedAddCommGroup E] {m : MeasurableSpace α} {μ : Measure α} namespace SimpleFunc theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero] simp_rw [smul_eq_mul] section PosPart /-- Positive part of a simple function in L1 space. -/ nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.posPart (f : α →₁[μ] ℝ), by rcases f with ⟨f, s, hsf⟩ use s.posPart simp only [SimpleFunc.posPart, SimpleFunc.coe_map, Function.comp_def, coe_posPart, ← hsf, posPart_mk] ⟩ /-- Negative part of a simple function in L1 space. -/ def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := posPart (-f) @[norm_cast] theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl @[norm_cast] theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl end PosPart section SimpleFuncIntegral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variable [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] attribute [local instance] simpleFunc.isBoundedSMul simpleFunc.module simpleFunc.normedSpace /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := (toSimpleFunc f).integral μ theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) : integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos] theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) : integral f = integral g := SimpleFunc.integral_congr (SimpleFunc.integrable f) h theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _ theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by rw [integral, norm_eq_integral] exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f) variable (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E := LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f => le_trans (norm_integral_le_norm _) <| by rw [one_mul] /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E := integralCLM' α E ℝ μ variable {α E μ 𝕜} local notation "Integral" => integralCLM α E μ open ContinuousLinearMap theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ zero_le_one fun f ↦ by simpa [one_mul] using norm_integral_le_norm f section PosPart theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ), toSimpleFunc_eq_toFun f] with _ _ h₂ h₃ convert h₂ using 1 rw [h₃] refine ae_eq.mono fun a h => ?_ rw [h, eq] theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) : toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart] filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f] intro a h₁ h₂ rw [h₁] change max _ _ = max _ _ rw [h₂] simp theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by filter_upwards [posPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply] -- Convert things in `L¹` to their `SimpleFunc` counterpart have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by filter_upwards [negPart_toSimpleFunc f] with _ h rw [SimpleFunc.map_apply, h] conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply] rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub] · change (toSimpleFunc f).integral μ = ((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f) filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂ rw [SimpleFunc.sub_apply, ← h₁, ← h₂] exact DFunLike.congr_fun (toSimpleFunc f).posPart_sub_negPart.symm _ · exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁ · exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂ end PosPart end SimpleFuncIntegral end SimpleFunc open SimpleFunc local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _ variable [NormedSpace ℝ E] [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E] [SMulCommClass ℝ 𝕜 E] [CompleteSpace E] section IntegrationInL1 attribute [local instance] simpleFunc.isBoundedSMul simpleFunc.module open ContinuousLinearMap variable (𝕜) in /-- The Bochner integral in L1 space as a continuous linear map. -/ nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E := (integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.isUniformInducing /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integralCLM : (α →₁[μ] E) →L[ℝ] E := integralCLM' ℝ /-- The Bochner integral in L1 space -/ irreducible_def integral : (α →₁[μ] E) → E := integralCLM theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM f := by simp only [integral] theorem integral_eq_setToL1 (f : α →₁[μ] E) : integral f = setToL1 (dominatedFinMeasAdditive_weightedSMul μ) f := by simp only [integral]; rfl @[norm_cast] theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by simp only [integral, L1.integral] exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f variable (α E) @[simp] theorem integral_zero : integral (0 : α →₁[μ] E) = 0 := by simp only [integral] exact map_zero integralCLM variable {α E} @[integral_simps] theorem integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := by simp only [integral] exact map_add integralCLM f g @[integral_simps] theorem integral_neg (f : α →₁[μ] E) : integral (-f) = -integral f := by simp only [integral] exact map_neg integralCLM f @[integral_simps] theorem integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := by simp only [integral] exact map_sub integralCLM f g @[integral_simps] theorem integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := by simp only [integral] change (integralCLM' 𝕜) (c • f) = c • (integralCLM' 𝕜) f exact map_smul (integralCLM' 𝕜) c f theorem norm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖ ≤ 1 := norm_setToL1_le (dominatedFinMeasAdditive_weightedSMul μ) zero_le_one theorem nnnorm_Integral_le_one : ‖integralCLM (α := α) (E := E) (μ := μ)‖₊ ≤ 1 := norm_Integral_le_one theorem norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ := calc ‖integral f‖ = ‖integralCLM f‖ := by simp only [integral] _ ≤ ‖integralCLM (α := α) (μ := μ)‖ * ‖f‖ := le_opNorm _ _ _ ≤ 1 * ‖f‖ := mul_le_mul_of_nonneg_right norm_Integral_le_one <| norm_nonneg _ _ = ‖f‖ := one_mul _ theorem nnnorm_integral_le (f : α →₁[μ] E) : ‖integral f‖₊ ≤ ‖f‖₊ := norm_integral_le f @[continuity] theorem continuous_integral : Continuous fun f : α →₁[μ] E => integral f := by simp only [integral] exact L1.integralCLM.continuous section PosPart theorem integral_eq_norm_posPart_sub (f : α →₁[μ] ℝ) : integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖ := by -- Use `isClosed_property` and `isClosed_eq` refine @isClosed_property _ _ _ ((↑) : (α →₁ₛ[μ] ℝ) → α →₁[μ] ℝ) (fun f : α →₁[μ] ℝ => integral f = ‖Lp.posPart f‖ - ‖Lp.negPart f‖) (simpleFunc.denseRange one_ne_top) (isClosed_eq ?_ ?_) ?_ f · simp only [integral] exact cont _ · refine Continuous.sub (continuous_norm.comp Lp.continuous_posPart) (continuous_norm.comp Lp.continuous_negPart) -- Show that the property holds for all simple functions in the `L¹` space. · intro s norm_cast exact SimpleFunc.integral_eq_norm_posPart_sub _ end PosPart end IntegrationInL1 end L1 end MeasureTheory
MkProof.lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Miyahara Kō -/ import Mathlib.Tactic.CC.Datatypes import Mathlib.Tactic.CC.Lemmas import Mathlib.Tactic.Relation.Rfl import Mathlib.Tactic.Relation.Symm /-! # Make proofs from a congruence closure -/ open Lean Meta Elab Tactic Std namespace Mathlib.Tactic.CC /-- The monad for the `cc` tactic stores the current state of the tactic. -/ abbrev CCM := StateRefT CCStructure MetaM namespace CCM /-- Run a computation in the `CCM` monad. -/ @[inline] def run {α : Type} (x : CCM α) (c : CCStructure) : MetaM (α × CCStructure) := StateRefT'.run x c /-- Update the `cache` field of the state. -/ @[inline] def modifyCache (f : CCCongrTheoremCache → CCCongrTheoremCache) : CCM Unit := modify fun cc => { cc with cache := f cc.cache } /-- Read the `cache` field of the state. -/ @[inline] def getCache : CCM CCCongrTheoremCache := do return (← get).cache /-- Look up an entry associated with the given expression. -/ def getEntry (e : Expr) : CCM (Option Entry) := do return (← get).entries[e]? /-- Use the normalizer to normalize `e`. If no normalizer was configured, returns `e` itself. -/ def normalize (e : Expr) : CCM Expr := do if let some normalizer := (← get).normalizer then normalizer.normalize e else return e /-- Return the root expression of the expression's congruence class. -/ def getRoot (e : Expr) : CCM Expr := do return (← get).root e /-- Is `e` the root of its congruence class? -/ def isCgRoot (e : Expr) : CCM Bool := do return (← get).isCgRoot e /-- Return true iff the given function application are congruent `e₁` should have the form `f a` and `e₂` the form `g b`. See paper: Congruence Closure for Intensional Type Theory. -/ partial def isCongruent (e₁ e₂ : Expr) : CCM Bool := do let .app f a := e₁ | failure let .app g b := e₂ | failure -- If they are non-dependent functions, then we can compare all arguments at once. if (← getEntry e₁).any Entry.fo then e₁.withApp fun f₁ args₁ => e₂.withApp fun f₂ args₂ => do if ha : args₁.size = args₂.size then for hi : i in [:args₁.size] do if (← getRoot args₁[i]) != (← getRoot (args₂[i]'(ha.symm ▸ hi.2.1))) then return false if f₁ == f₂ then return true else if (← getRoot f₁) != (← getRoot f₂) then -- `f₁` and `f₂` are not equivalent return false else if ← pureIsDefEq (← inferType f₁) (← inferType f₂) then return true else return false else return false else -- Given `e₁ := f a`, `e₂ := g b` if (← getRoot a) != (← getRoot b) then -- `a` and `b` are not equivalent return false else if (← getRoot f) != (← getRoot g) then -- `f` and `g` are not equivalent return false else if ← pureIsDefEq (← inferType f) (← inferType g) then /- Case 1: `f` and `g` have the same type, then we can create a congruence proof for `f a ≍ g b` -/ return true else if f.isApp && g.isApp then -- Case 2: `f` and `g` are congruent isCongruent f g else /- f and g are not congruent nor they have the same type. We can't generate a congruence proof in this case because the following lemma `hcongr : f₁ ≍ f₂ → a₁ ≍ a₂ → f₁ a₁ ≍ f₂ a₂` is not provable. Remark: it is also not provable in MLTT, Coq and Agda (even if we assume UIP). -/ return false /-- Try to find a congruence theorem for an application of `fn` with `nargs` arguments, with support for `HEq`. -/ def mkCCHCongrTheorem (fn : Expr) (nargs : Nat) : CCM (Option CCCongrTheorem) := do let cache ← getCache -- Check if `{ fn, nargs }` is in the cache let key₁ : CCCongrTheoremKey := { fn, nargs } if let some it := cache[key₁]? then return it -- Try automatically generated congruence lemma with support for heterogeneous equality. let lemm ← mkCCHCongrWithArity fn nargs if let some lemm := lemm then modifyCache fun ccc => ccc.insert key₁ (some lemm) return lemm -- cache failure modifyCache fun ccc => ccc.insert key₁ none return none /-- Try to find a congruence theorem for the expression `e` with support for `HEq`. -/ def mkCCCongrTheorem (e : Expr) : CCM (Option CCCongrTheorem) := do let fn := e.getAppFn let nargs := e.getAppNumArgs mkCCHCongrTheorem fn nargs /-- Treat the entry associated with `e` as a first-order function. -/ def setFO (e : Expr) : CCM Unit := modify fun ccs => { ccs with entries := ccs.entries.modify e fun d => { d with fo := true } } /-- Update the modification time of the congruence class of `e`. -/ partial def updateMT (e : Expr) : CCM Unit := do let r ← getRoot e let some ps := (← get).parents[r]? | return for p in ps do let some it ← getEntry p.expr | failure let gmt := (← get).gmt if it.mt < gmt then let newIt := { it with mt := gmt } modify fun ccs => { ccs with entries := ccs.entries.insert p.expr newIt } updateMT p.expr /-- Does the congruence class with root `root` have any `HEq` proofs? -/ def hasHEqProofs (root : Expr) : CCM Bool := do let some n ← getEntry root | failure guard (n.root == root) return n.heqProofs /-- Apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction. -/ def flipProofCore (H : Expr) (flipped heqProofs : Bool) : CCM Expr := do let mut newH := H if ← liftM <| pure heqProofs <&&> Expr.isEq <$> (inferType H >>= whnf) then newH ← mkAppM ``heq_of_eq #[H] if !flipped then return newH else if heqProofs then mkHEqSymm newH else mkEqSymm newH /-- In a delayed way, apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction. -/ def flipDelayedProofCore (H : DelayedExpr) (flipped heqProofs : Bool) : CCM DelayedExpr := do let mut newH := H if heqProofs then newH := .heqOfEq H if !flipped then return newH else if heqProofs then return .heqSymm newH else return .eqSymm newH /-- Apply symmetry to `H`, which is an `Eq` or a `HEq`. * If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`). * If `flipped` is true, apply `symm`, otherwise keep the same direction. -/ def flipProof (H : EntryExpr) (flipped heqProofs : Bool) : CCM EntryExpr := match H with | .ofExpr H => EntryExpr.ofExpr <$> flipProofCore H flipped heqProofs | .ofDExpr H => EntryExpr.ofDExpr <$> flipDelayedProofCore H flipped heqProofs | _ => return H /-- Are `e₁` and `e₂` known to be in the same equivalence class? -/ def isEqv (e₁ e₂ : Expr) : CCM Bool := do let some n₁ ← getEntry e₁ | return false let some n₂ ← getEntry e₂ | return false return n₁.root == n₂.root /-- Is `e₁ ≠ e₂` known to be true? Note that this is stronger than `not (isEqv e₁ e₂)`: only if we can prove they are distinct this returns `true`. -/ def isNotEqv (e₁ e₂ : Expr) : CCM Bool := do let tmp ← mkEq e₁ e₂ if ← isEqv tmp (.const ``False []) then return true let tmp ← mkHEq e₁ e₂ isEqv tmp (.const ``False []) /-- Is the proposition `e` known to be true? -/ @[inline] def isEqTrue (e : Expr) : CCM Bool := isEqv e (.const ``True []) /-- Is the proposition `e` known to be false? -/ @[inline] def isEqFalse (e : Expr) : CCM Bool := isEqv e (.const ``False []) /-- Apply transitivity to `H₁` and `H₂`, which are both `Eq` or `HEq` depending on `heqProofs`. -/ def mkTrans (H₁ H₂ : Expr) (heqProofs : Bool) : MetaM Expr := if heqProofs then mkHEqTrans H₁ H₂ else mkEqTrans H₁ H₂ /-- Apply transitivity to `H₁?` and `H₂`, which are both `Eq` or `HEq` depending on `heqProofs`. If `H₁?` is `none`, return `H₂` instead. -/ def mkTransOpt (H₁? : Option Expr) (H₂ : Expr) (heqProofs : Bool) : MetaM Expr := match H₁? with | some H₁ => mkTrans H₁ H₂ heqProofs | none => pure H₂ mutual /-- Use congruence on arguments to prove `lhs = rhs`. That is, tries to prove that `lhsFn lhsArgs[0] ... lhsArgs[n-1] = lhsFn rhsArgs[0] ... rhsArgs[n-1]` by showing that `lhsArgs[i] = rhsArgs[i]` for all `i`. Fails if the head function of `lhs` is not that of `rhs`. -/ partial def mkCongrProofCore (lhs rhs : Expr) (heqProofs : Bool) : CCM Expr := do let mut lhsArgsRev : Array Expr := #[] let mut rhsArgsRev : Array Expr := #[] let mut lhsIt := lhs let mut rhsIt := rhs -- Collect the arguments to `lhs` and `rhs`. -- As an optimization, we stop collecting arguments as soon as the functions are defeq, -- so `lhsFn` and `rhsFn` might end up still of the form `(f x y z)` and `(f x' y' z')`. if lhs != rhs then repeat let .app lhsItFn lhsItArg := lhsIt | failure let .app rhsItFn rhsItArg := rhsIt | failure lhsArgsRev := lhsArgsRev.push lhsItArg rhsArgsRev := rhsArgsRev.push rhsItArg lhsIt := lhsItFn rhsIt := rhsItFn if lhsIt == rhsIt then break if ← pureIsDefEq lhsIt rhsIt then break if ← isEqv lhsIt rhsIt <&&> inferType lhsIt >>= fun i₁ => inferType rhsIt >>= fun i₂ => pureIsDefEq i₁ i₂ then break -- If we collect no arguments, the expressions themselves are defeq; return `rfl`. if lhsArgsRev.isEmpty then if heqProofs then return (← mkHEqRefl lhs) else return (← mkEqRefl lhs) let lhsArgs := lhsArgsRev.reverse let rhsArgs := rhsArgsRev.reverse -- Ensure that `lhsFn = rhsFn`, they have the same type and the same list of arguments. let PLift.up ha ← if ha : lhsArgs.size = rhsArgs.size then pure (PLift.up ha) else failure let lhsFn := lhsIt let rhsFn := rhsIt guard (← isEqv lhsFn rhsFn <||> pureIsDefEq lhsFn rhsFn) guard (← pureIsDefEq (← inferType lhsFn) (← inferType rhsFn)) /- Create `r`, a proof for `lhsFn lhsArgs[0] ... lhsArgs[n-1] = lhsFn rhsArgs[0] ... rhsArgs[n-1]` where `n := lhsArgs.size` -/ let some specLemma ← mkCCHCongrTheorem lhsFn lhsArgs.size | failure let mut kindsIt := specLemma.argKinds let mut lemmaArgs : Array Expr := #[] for hi : i in [:lhsArgs.size] do guard !kindsIt.isEmpty lemmaArgs := lemmaArgs.push lhsArgs[i] |>.push (rhsArgs[i]'(ha.symm ▸ hi.2.1)) if kindsIt[0]! matches CongrArgKind.heq then let some p ← getHEqProof lhsArgs[i] (rhsArgs[i]'(ha.symm ▸ hi.2.1)) | failure lemmaArgs := lemmaArgs.push p else guard (kindsIt[0]! matches .eq) let some p ← getEqProof lhsArgs[i] (rhsArgs[i]'(ha.symm ▸ hi.2.1)) | failure lemmaArgs := lemmaArgs.push p kindsIt := kindsIt.eraseIdx! 0 let mut r := mkAppN specLemma.proof lemmaArgs if specLemma.heqResult && !heqProofs then r ← mkAppM ``eq_of_heq #[r] else if !specLemma.heqResult && heqProofs then r ← mkAppM ``heq_of_eq #[r] if ← pureIsDefEq lhsFn rhsFn then return r /- Convert `r` into a proof of `lhs = rhs` using `Eq.rec` and the proof that `lhsFn = rhsFn` -/ let some lhsFnEqRhsFn ← getEqProof lhsFn rhsFn | failure let motive ← withLocalDeclD `x (← inferType lhsFn) fun x => do let motiveRhs := mkAppN x rhsArgs let motive ← if heqProofs then mkHEq lhs motiveRhs else mkEq lhs motiveRhs let hType ← mkEq lhsFn x withLocalDeclD `h hType fun h => mkLambdaFVars #[x, h] motive mkEqRec motive r lhsFnEqRhsFn /-- If `e₁ : R lhs₁ rhs₁`, `e₂ : R lhs₂ rhs₂` and `lhs₁ = rhs₂`, where `R` is a symmetric relation, prove `R lhs₁ rhs₁` is equivalent to `R lhs₂ rhs₂`. * if `lhs₁` is known to equal `lhs₂`, return `none` * if `lhs₁` is not known to equal `rhs₂`, fail. -/ partial def mkSymmCongrProof (e₁ e₂ : Expr) (heqProofs : Bool) : CCM (Option Expr) := do let some (R₁, lhs₁, rhs₁) ← e₁.relSidesIfSymm? | return none let some (R₂, lhs₂, rhs₂) ← e₂.relSidesIfSymm? | return none if R₁ != R₂ then return none if (← isEqv lhs₁ lhs₂) then return none guard (← isEqv lhs₁ rhs₂) /- We must apply symmetry. The symm congruence table is implicitly using symmetry. That is, we have `e₁ := lhs₁ ~R₁~ rhs₁` and `e2 := lhs₂ ~R₁~ rhs₂` But, `lhs₁ ~R₁~ rhs₂` and `rhs₁ ~R₁~ lhs₂` -/ /- Given `e₁ := lhs₁ ~R₁~ rhs₁`, create proof for `lhs₁ ~R₁~ rhs₁` = `rhs₁ ~R₁~ lhs₁` -/ let newE₁ ← mkRel R₁ rhs₁ lhs₁ let e₁IffNewE₁ ← withLocalDeclD `h₁ e₁ fun h₁ => withLocalDeclD `h₂ newE₁ fun h₂ => do mkAppM ``Iff.intro #[← mkLambdaFVars #[h₁] (← h₁.applySymm), ← mkLambdaFVars #[h₂] (← h₂.applySymm)] let mut e₁EqNewE₁ := mkApp3 (.const ``propext []) e₁ newE₁ e₁IffNewE₁ let newE₁EqE₂ ← mkCongrProofCore newE₁ e₂ heqProofs if heqProofs then e₁EqNewE₁ ← mkAppM ``heq_of_eq #[e₁EqNewE₁] return some (← mkTrans e₁EqNewE₁ newE₁EqE₂ heqProofs) /-- Use congruence on arguments to prove `e₁ = e₂`. Special case: if `e₁` and `e₂` have the form `R lhs₁ rhs₁` and `R lhs₂ rhs₂` such that `R` is symmetric and `lhs₁ = rhs₂`, then use those facts instead. -/ partial def mkCongrProof (e₁ e₂ : Expr) (heqProofs : Bool) : CCM Expr := do if let some r ← mkSymmCongrProof e₁ e₂ heqProofs then return r else mkCongrProofCore e₁ e₂ heqProofs /-- Turn a delayed proof into an actual proof term. -/ partial def mkDelayedProof (H : DelayedExpr) : CCM Expr := do match H with | .ofExpr H => return H | .eqProof lhs rhs => liftOption (← getEqProof lhs rhs) | .congrArg f h => mkCongrArg f (← mkDelayedProof h) | .congrFun h a => mkCongrFun (← mkDelayedProof h) (← liftOption a.toExpr) | .eqSymm h => mkEqSymm (← mkDelayedProof h) | .eqSymmOpt a₁ a₂ h => mkAppOptM ``Eq.symm #[none, ← liftOption a₁.toExpr, ← liftOption a₂.toExpr, ← mkDelayedProof h] | .eqTrans h₁ h₂ => mkEqTrans (← mkDelayedProof h₁) (← mkDelayedProof h₂) | .eqTransOpt a₁ a₂ a₃ h₁ h₂ => mkAppOptM ``Eq.trans #[none, ← liftOption a₁.toExpr, ← liftOption a₂.toExpr, ← liftOption a₃.toExpr, ← mkDelayedProof h₁, ← mkDelayedProof h₂] | .heqOfEq h => mkAppM ``heq_of_eq #[← mkDelayedProof h] | .heqSymm h => mkHEqSymm (← mkDelayedProof h) /-- Use the format of `H` to try and construct a proof or `lhs = rhs`: * If `H = .congr`, then use congruence. * If `H = .eqTrue`, try to prove `lhs = True` or `rhs = True`, if they have the format `R a b`, by proving `a = b`. * Otherwise, return the (delayed) proof encoded by `H` itself. -/ partial def mkProof (lhs rhs : Expr) (H : EntryExpr) (heqProofs : Bool) : CCM Expr := do match H with | .congr => mkCongrProof lhs rhs heqProofs | .eqTrue => let (flip, some (R, a, b)) ← if lhs == .const ``True [] then ((true, ·)) <$> rhs.relSidesIfRefl? else ((false, ·)) <$> lhs.relSidesIfRefl? | failure let aRb ← if R == ``Eq then getEqProof a b >>= liftOption else if R == ``HEq then getHEqProof a b >>= liftOption else -- TODO(Leo): the following code assumes R is homogeneous. -- We should add support arbitrary heterogeneous reflexive relations. getEqProof a b >>= liftOption >>= fun aEqb => liftM (liftFromEq R aEqb) let aRbEqTrue ← mkEqTrue aRb if flip then mkEqSymm aRbEqTrue else return aRbEqTrue | .refl => let type ← if heqProofs then mkHEq lhs rhs else mkEq lhs rhs let proof ← if heqProofs then mkHEqRefl lhs else mkEqRefl lhs mkExpectedTypeHint proof type | .ofExpr H => return H | .ofDExpr H => mkDelayedProof H /-- If `asHEq` is `true`, then build a proof for `e₁ ≍ e₂`. Otherwise, build a proof for `e₁ = e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class. -/ partial def getEqProofCore (e₁ e₂ : Expr) (asHEq : Bool) : CCM (Option Expr) := do if e₁.hasExprMVar || e₂.hasExprMVar then return none if ← pureIsDefEq e₁ e₂ then if asHEq then return some (← mkHEqRefl e₁) else return some (← mkEqRefl e₁) let some n₁ ← getEntry e₁ | return none let some n₂ ← getEntry e₂ | return none if n₁.root != n₂.root then return none let heqProofs ← hasHEqProofs n₁.root -- 1. Retrieve "path" from `e₁` to `root` let mut path₁ : Array Expr := #[] let mut Hs₁ : Array EntryExpr := #[] let mut visited : ExprSet := ∅ let mut it₁ := e₁ repeat visited := visited.insert it₁ let some it₁N ← getEntry it₁ | failure let some t := it₁N.target | break path₁ := path₁.push t let some p := it₁N.proof | failure Hs₁ := Hs₁.push (← flipProof p it₁N.flipped heqProofs) it₁ := t guard (it₁ == n₁.root) -- 2. The path from `e₂` to root must have at least one element `c` in visited -- Retrieve "path" from `e₂` to `c` let mut path₂ : Array Expr := #[] let mut Hs₂ : Array EntryExpr := #[] let mut it₂ := e₂ repeat if visited.contains it₂ then break -- found common let some it₂N ← getEntry it₂ | failure let some t := it₂N.target | failure path₂ := path₂.push it₂ let some p := it₂N.proof | failure Hs₂ := Hs₂.push (← flipProof p (!it₂N.flipped) heqProofs) it₂ := t -- `it₂` is the common element... -- 3. Shrink `path₁`/`Hs₁` until we find `it₂` (the common element) repeat if path₁.isEmpty then guard (it₂ == e₁) break if path₁.back! == it₂ then -- found it! break path₁ := path₁.pop Hs₁ := Hs₁.pop -- 4. Build transitivity proof let mut pr? : Option Expr := none let mut lhs := e₁ for h : i in [:path₁.size] do pr? ← some <$> mkTransOpt pr? (← mkProof lhs path₁[i] Hs₁[i]! heqProofs) heqProofs lhs := path₁[i] let mut i := Hs₂.size while i > 0 do i := i - 1 pr? ← some <$> mkTransOpt pr? (← mkProof lhs path₂[i]! Hs₂[i]! heqProofs) heqProofs lhs := path₂[i]! let mut some pr := pr? | failure if heqProofs && !asHEq then pr ← mkAppM ``eq_of_heq #[pr] else if !heqProofs && asHEq then pr ← mkAppM ``heq_of_eq #[pr] return pr /-- Build a proof for `e₁ = e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class. -/ @[inline] partial def getEqProof (e₁ e₂ : Expr) : CCM (Option Expr) := getEqProofCore e₁ e₂ false /-- Build a proof for `e₁ ≍ e₂`. The result is `none` if `e₁` and `e₂` are not in the same equivalence class. -/ @[inline] partial def getHEqProof (e₁ e₂ : Expr) : CCM (Option Expr) := getEqProofCore e₁ e₂ true end /-- Build a proof for `e = True`. Fails if `e` is not known to be true. -/ def getEqTrueProof (e : Expr) : CCM Expr := do guard (← isEqTrue e) let some p ← getEqProof e (.const ``True []) | failure return p /-- Build a proof for `e = False`. Fails if `e` is not known to be false. -/ def getEqFalseProof (e : Expr) : CCM Expr := do guard (← isEqFalse e) let some p ← getEqProof e (.const ``False []) | failure return p /-- Build a proof for `a = b`. Fails if `a` and `b` are not known to be equal. -/ def getPropEqProof (a b : Expr) : CCM Expr := do guard (← isEqv a b) let some p ← getEqProof a b | failure return p /-- Build a proof of `False` if the context is inconsistent. Returns `none` if `False` is not known to be true. -/ def getInconsistencyProof : CCM (Option Expr) := do guard !(← get).frozePartitions if let some p ← getEqProof (.const ``True []) (.const ``False []) then return some (← mkAppM ``false_of_true_eq_false #[p]) else return none /-- Given `a`, `a₁` and `a₁NeB : a₁ ≠ b`, return a proof of `a ≠ b` if `a` and `a₁` are in the same equivalence class. -/ def mkNeOfEqOfNe (a a₁ a₁NeB : Expr) : CCM (Option Expr) := do guard (← isEqv a a₁) if a == a₁ then return some a₁NeB let aEqA₁ ← getEqProof a a₁ match aEqA₁ with | none => return none -- failed to build proof | some aEqA₁ => mkAppM ``ne_of_eq_of_ne #[aEqA₁, a₁NeB] /-- Given `aNeB₁ : a ≠ b₁`, `b₁` and `b`, return a proof of `a ≠ b` if `b` and `b₁` are in the same equivalence class. -/ def mkNeOfNeOfEq (aNeB₁ b₁ b : Expr) : CCM (Option Expr) := do guard (← isEqv b b₁) if b == b₁ then return some aNeB₁ let b₁EqB ← getEqProof b b₁ match b₁EqB with | none => return none -- failed to build proof | some b₁EqB => mkAppM ``ne_of_ne_of_eq #[aNeB₁, b₁EqB] /-- Return the proof of `e₁ = e₂` using `ac_rfl` tactic. -/ def mkACProof (e₁ e₂ : Expr) : MetaM Expr := do let eq ← mkEq e₁ e₂ let .mvar m ← mkFreshExprSyntheticOpaqueMVar eq | failure AC.rewriteUnnormalizedRefl m let pr ← instantiateMVars (.mvar m) mkExpectedTypeHint pr eq /-- Given `tr := t*r` `sr := s*r` `tEqs : t = s`, return a proof for `tr = sr` We use `a*b` to denote an AC application. That is, `(a*b)*(c*a)` is the term `a*a*b*c`. -/ def mkACSimpProof (tr t s r sr : ACApps) (tEqs : DelayedExpr) : MetaM DelayedExpr := do if tr == t then return tEqs else if tr == sr then let some tre := tr.toExpr | failure DelayedExpr.ofExpr <$> mkEqRefl tre else let .apps op _ := tr | failure let some re := r.toExpr | failure let some te := t.toExpr | failure let some se := s.toExpr | failure let some tre := tr.toExpr | failure let some sre := sr.toExpr | failure let opr := op.app re -- `(*) r` let rt := mkApp2 op re te -- `r * t` let rs := mkApp2 op re se -- `r * s` let rtEqrs := DelayedExpr.congrArg opr tEqs let trEqrt ← mkACProof tre rt let rsEqsr ← mkACProof rs sre return .eqTrans (.eqTrans trEqrt rtEqrs) rsEqsr /-- Given `e := lhs * r` and `H : lhs = rhs`, return `rhs * r` and the proof of `e = rhs * r`. -/ def simplifyACCore (e lhs rhs : ACApps) (H : DelayedExpr) : CCM (ACApps × DelayedExpr) := do guard (lhs.isSubset e) if e == lhs then return (rhs, H) else let .apps op _ := e | failure let newArgs := e.diff lhs let r : ACApps := if newArgs.isEmpty then default else .mkApps op newArgs let newArgs := ACApps.append op rhs newArgs let newE := ACApps.mkApps op newArgs let some true := (← get).opInfo[op]? | failure let newPr ← mkACSimpProof e lhs rhs r newE H return (newE, newPr) /-- The single step of `simplifyAC`. Simplifies an expression `e` by either simplifying one argument to the AC operator, or the whole expression. -/ def simplifyACStep (e : ACApps) : CCM (Option (ACApps × DelayedExpr)) := do if let .apps _ args := e then for h : i in [:args.size] do if i == 0 || args[i] != (args[i - 1]'(Nat.lt_of_le_of_lt (i.sub_le 1) h.2.1)) then let some ae := (← get).acEntries[args[i]]? | failure let occs := ae.RLHSOccs let mut Rlhs? : Option ACApps := none for Rlhs in occs do if Rlhs.isSubset e then Rlhs? := some Rlhs break if let some Rlhs := Rlhs? then let some (Rrhs, H) := (← get).acR[Rlhs]? | failure return (some <| ← simplifyACCore e Rlhs Rrhs H) else if let some p := (← get).acR[e]? then return some p return none /-- If `e` can be simplified by the AC module, return the simplified term and the proof term of the equality. -/ def simplifyAC (e : ACApps) : CCM (Option (ACApps × DelayedExpr)) := do let mut some (curr, pr) ← simplifyACStep e | return none repeat let some (newCurr, newPr) ← simplifyACStep curr | break pr := .eqTransOpt e curr newCurr pr newPr curr := newCurr return some (curr, pr) end Mathlib.Tactic.CC.CCM
Multinomial.lean
/- Copyright (c) 2022 Pim Otte. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller, Pim Otte -/ import Mathlib.Algebra.Order.Antidiag.Pi import Mathlib.Data.Finsupp.Multiset import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Factorial.BigOperators import Mathlib.Data.Nat.Factorial.DoubleFactorial /-! # Multinomial This file defines the multinomial coefficient and several small lemma's for manipulating it. ## Main declarations - `Nat.multinomial`: the multinomial coefficient ## Main results - `Finset.sum_pow`: The expansion of `(s.sum x) ^ n` using multinomial coefficients -/ open Finset open scoped Nat namespace Nat variable {α : Type*} (s : Finset α) (f : α → ℕ) {a b : α} (n : ℕ) /-- The multinomial coefficient. Gives the number of strings consisting of symbols from `s`, where `c ∈ s` appears with multiplicity `f c`. Defined as `(∑ i ∈ s, f i)! / ∏ i ∈ s, (f i)!`. -/ def multinomial : ℕ := (∑ i ∈ s, f i)! / ∏ i ∈ s, (f i)! theorem multinomial_pos : 0 < multinomial s f := Nat.div_pos (le_of_dvd (factorial_pos _) (prod_factorial_dvd_factorial_sum s f)) (prod_factorial_pos s f) theorem multinomial_spec : (∏ i ∈ s, (f i)!) * multinomial s f = (∑ i ∈ s, f i)! := Nat.mul_div_cancel' (prod_factorial_dvd_factorial_sum s f) @[simp] lemma multinomial_empty : multinomial ∅ f = 1 := by simp [multinomial] variable {s f} lemma multinomial_cons (ha : a ∉ s) (f : α → ℕ) : multinomial (s.cons a ha) f = (f a + ∑ i ∈ s, f i).choose (f a) * multinomial s f := by rw [multinomial, Nat.div_eq_iff_eq_mul_left _ (prod_factorial_dvd_factorial_sum _ _), prod_cons, multinomial, mul_assoc, mul_left_comm _ (f a)!, Nat.div_mul_cancel (prod_factorial_dvd_factorial_sum _ _), ← mul_assoc, Nat.choose_symm_add, Nat.add_choose_mul_factorial_mul_factorial, Finset.sum_cons] positivity lemma multinomial_insert [DecidableEq α] (ha : a ∉ s) (f : α → ℕ) : multinomial (insert a s) f = (f a + ∑ i ∈ s, f i).choose (f a) * multinomial s f := by rw [← cons_eq_insert _ _ ha, multinomial_cons] @[simp] lemma multinomial_singleton (a : α) (f : α → ℕ) : multinomial {a} f = 1 := by rw [← cons_empty, multinomial_cons]; simp @[simp] theorem multinomial_insert_one [DecidableEq α] (h : a ∉ s) (h₁ : f a = 1) : multinomial (insert a s) f = (s.sum f).succ * multinomial s f := by simp only [multinomial] rw [Finset.sum_insert h, Finset.prod_insert h, h₁, add_comm, ← succ_eq_add_one, factorial_succ] simp only [factorial, succ_eq_add_one, zero_add, mul_one, one_mul] rw [Nat.mul_div_assoc _ (prod_factorial_dvd_factorial_sum _ _)] theorem multinomial_congr {f g : α → ℕ} (h : ∀ a ∈ s, f a = g a) : multinomial s f = multinomial s g := by simp only [multinomial]; congr 1 · rw [Finset.sum_congr rfl h] · exact Finset.prod_congr rfl fun a ha => by rw [h a ha] /-! ### Connection to binomial coefficients When `Nat.multinomial` is applied to a `Finset` of two elements `{a, b}`, the result a binomial coefficient. We use `binomial` in the names of lemmas that involves `Nat.multinomial {a, b}`. -/ theorem binomial_eq [DecidableEq α] (h : a ≠ b) : multinomial {a, b} f = (f a + f b)! / ((f a)! * (f b)!) := by simp [multinomial, Finset.sum_pair h, Finset.prod_pair h] theorem binomial_eq_choose [DecidableEq α] (h : a ≠ b) : multinomial {a, b} f = (f a + f b).choose (f a) := by simp [binomial_eq h, choose_eq_factorial_div_factorial (Nat.le_add_right _ _)] theorem binomial_spec [DecidableEq α] (hab : a ≠ b) : (f a)! * (f b)! * multinomial {a, b} f = (f a + f b)! := by simpa [Finset.sum_pair hab, Finset.prod_pair hab] using multinomial_spec {a, b} f theorem binomial_one [DecidableEq α] (h : a ≠ b) (h₁ : f a = 1) : multinomial {a, b} f = (f b).succ := by simp [h, h₁] theorem binomial_succ_succ [DecidableEq α] (h : a ≠ b) : multinomial {a, b} (Function.update (Function.update f a (f a).succ) b (f b).succ) = multinomial {a, b} (Function.update f a (f a).succ) + multinomial {a, b} (Function.update f b (f b).succ) := by simp only [binomial_eq_choose, Function.update_apply, h, Ne, ite_true, ite_false, not_false_eq_true] rw [if_neg h.symm] rw [add_succ, choose_succ_succ, succ_add_eq_add_succ] ring theorem succ_mul_binomial [DecidableEq α] (h : a ≠ b) : (f a + f b).succ * multinomial {a, b} f = (f a).succ * multinomial {a, b} (Function.update f a (f a).succ) := by rw [binomial_eq_choose h, binomial_eq_choose h, mul_comm (f a).succ, Function.update_self, Function.update_of_ne h.symm] rw [succ_mul_choose_eq (f a + f b) (f a), succ_add (f a) (f b)] /-! ### Simple cases -/ theorem multinomial_univ_two (a b : ℕ) : multinomial Finset.univ ![a, b] = (a + b)! / (a ! * b !) := by rw [multinomial, Fin.sum_univ_two, Fin.prod_univ_two] dsimp only [Matrix.cons_val] theorem multinomial_univ_three (a b c : ℕ) : multinomial Finset.univ ![a, b, c] = (a + b + c)! / (a ! * b ! * c !) := by rw [multinomial, Fin.sum_univ_three, Fin.prod_univ_three] rfl end Nat /-! ### Alternative definitions -/ namespace Finsupp variable {α : Type*} /-- Alternative multinomial definition based on a finsupp, using the support for the big operations -/ def multinomial (f : α →₀ ℕ) : ℕ := (f.sum fun _ => id)! / f.prod fun _ n => n ! theorem multinomial_eq (f : α →₀ ℕ) : f.multinomial = Nat.multinomial f.support f := rfl theorem multinomial_update (a : α) (f : α →₀ ℕ) : f.multinomial = (f.sum fun _ => id).choose (f a) * (f.update a 0).multinomial := by simp only [multinomial_eq] classical by_cases h : a ∈ f.support · rw [← Finset.insert_erase h, Nat.multinomial_insert (Finset.notMem_erase a _), Finset.add_sum_erase _ f h, support_update_zero] congr 1 exact Nat.multinomial_congr fun _ h ↦ (Function.update_of_ne (mem_erase.1 h).1 0 f).symm rw [notMem_support_iff] at h rw [h, Nat.choose_zero_right, one_mul, ← h, update_self] end Finsupp namespace Multiset variable {α : Type*} /-- Alternative definition of multinomial based on `Multiset` delegating to the finsupp definition -/ def multinomial [DecidableEq α] (m : Multiset α) : ℕ := m.toFinsupp.multinomial theorem multinomial_filter_ne [DecidableEq α] (a : α) (m : Multiset α) : m.multinomial = m.card.choose (m.count a) * (m.filter (a ≠ ·)).multinomial := by dsimp only [multinomial] convert Finsupp.multinomial_update a _ · rw [← Finsupp.card_toMultiset, m.toFinsupp_toMultiset] · ext1 a rw [toFinsupp_apply, count_filter, Finsupp.coe_update] split_ifs with h · rw [Function.update_of_ne h.symm, toFinsupp_apply] · rw [not_ne_iff.1 h, Function.update_self] @[simp] theorem multinomial_zero [DecidableEq α] : multinomial (0 : Multiset α) = 1 := by simp [multinomial, Finsupp.multinomial] end Multiset namespace Finset open _root_.Nat /-! ### Multinomial theorem -/ variable {α R : Type*} [DecidableEq α] section Semiring variable [Semiring R] open scoped Function -- required for scoped `on` notation -- TODO: Can we prove one of the following two from the other one? /-- The **multinomial theorem**. -/ lemma sum_pow_eq_sum_piAntidiag_of_commute (s : Finset α) (f : α → R) (hc : (s : Set α).Pairwise (Commute on f)) (n : ℕ) : (∑ i ∈ s, f i) ^ n = ∑ k ∈ piAntidiag s n, multinomial s k * s.noncommProd (fun i ↦ f i ^ k i) (hc.mono' fun _ _ h ↦ h.pow_pow ..) := by classical induction' s using Finset.cons_induction with a s has ih generalizing n · cases n <;> simp rw [Finset.sum_cons, piAntidiag_cons, sum_disjiUnion] simp only [sum_map, Pi.add_apply, multinomial_cons, Pi.add_apply, if_true, Nat.cast_mul, noncommProd_cons, if_true, sum_add_distrib, sum_ite_eq', has, if_false, add_zero, addRightEmbedding_apply] suffices ∀ p : ℕ × ℕ, p ∈ antidiagonal n → ∑ g ∈ piAntidiag s p.2, ((g a + p.1 + s.sum g).choose (g a + p.1) : R) * multinomial s (g + fun i ↦ ite (i = a) p.1 0) * (f a ^ (g a + p.1) * s.noncommProd (fun i ↦ f i ^ (g i + ite (i = a) p.1 0)) ((hc.mono (by simp)).mono' fun i j h ↦ h.pow_pow ..)) = ∑ g ∈ piAntidiag s p.2, n.choose p.1 * multinomial s g * (f a ^ p.1 * s.noncommProd (fun i ↦ f i ^ g i) ((hc.mono (by simp)).mono' fun i j h ↦ h.pow_pow ..)) by rw [sum_congr rfl this] simp only [Nat.antidiagonal_eq_map, sum_map, Function.Embedding.coeFn_mk] rw [(Commute.sum_right _ _ _ fun i hi ↦ hc (by simp) (by simp [hi]) (by simpa [eq_comm] using ne_of_mem_of_not_mem hi has)).add_pow] simp only [ih (hc.mono (by simp)), sum_mul, mul_sum] refine sum_congr rfl fun i _ ↦ sum_congr rfl fun g _ ↦ ?_ rw [← Nat.cast_comm, (Nat.commute_cast (f a ^ i) _).left_comm, mul_assoc] refine fun p hp ↦ sum_congr rfl fun f hf ↦ ?_ rw [mem_piAntidiag] at hf rw [not_imp_comm.1 (hf.2 _) has, zero_add, hf.1] congr 2 · rw [mem_antidiagonal.1 hp] · rw [multinomial_congr] intro t ht rw [Pi.add_apply, if_neg, add_zero] exact ne_of_mem_of_not_mem ht has refine noncommProd_congr rfl (fun t ht ↦ ?_) _ rw [if_neg, add_zero] exact ne_of_mem_of_not_mem ht has /-- The **multinomial theorem**. -/ theorem sum_pow_of_commute (x : α → R) (s : Finset α) (hc : (s : Set α).Pairwise (Commute on x)) : ∀ n, s.sum x ^ n = ∑ k : s.sym n, k.1.1.multinomial * (k.1.1.map <| x).noncommProd (Multiset.map_set_pairwise <| hc.mono <| mem_sym_iff.1 k.2) := by induction' s using Finset.induction with a s ha ih · rw [sum_empty] rintro (_ | n) · rw [_root_.pow_zero, Fintype.sum_subsingleton] swap · exact ⟨0, by simp [eq_iff_true_of_subsingleton]⟩ convert (@one_mul R _ _).symm convert @Nat.cast_one R _ simp · rw [_root_.pow_succ, mul_zero] haveI : IsEmpty (Finset.sym (∅ : Finset α) n.succ) := Finset.instIsEmpty apply (Fintype.sum_empty _).symm intro n; specialize ih (hc.mono <| s.subset_insert a) rw [sum_insert ha, (Commute.sum_right s _ _ _).add_pow, sum_range]; swap · exact fun _ hb => hc (mem_insert_self a s) (mem_insert_of_mem hb) (ne_of_mem_of_not_mem hb ha).symm · simp_rw [ih, mul_sum, sum_mul, sum_sigma', univ_sigma_univ] refine (Fintype.sum_equiv (symInsertEquiv ha) _ _ fun m => ?_).symm rw [m.1.1.multinomial_filter_ne a] conv in m.1.1.map _ => rw [← m.1.1.filter_add_not (a = ·), Multiset.map_add] simp_rw [Multiset.noncommProd_add, m.1.1.filter_eq, Multiset.map_replicate, m.1.2] rw [Multiset.noncommProd_eq_pow_card _ _ _ fun _ => Multiset.eq_of_mem_replicate] rw [Multiset.card_replicate, Nat.cast_mul, mul_assoc, Nat.cast_comm] congr 1; simp_rw [← mul_assoc, Nat.cast_comm]; rfl end Semiring section CommSemiring variable [CommSemiring R] {f : α → R} {s : Finset α} lemma sum_pow_eq_sum_piAntidiag (s : Finset α) (f : α → R) (n : ℕ) : (∑ i ∈ s, f i) ^ n = ∑ k ∈ piAntidiag s n, multinomial s k * ∏ i ∈ s, f i ^ k i := by simp_rw [← noncommProd_eq_prod] rw [← sum_pow_eq_sum_piAntidiag_of_commute _ _ fun _ _ _ _ _ ↦ Commute.all ..] theorem sum_pow (x : α → R) (n : ℕ) : s.sum x ^ n = ∑ k ∈ s.sym n, k.val.multinomial * (k.val.map x).prod := by conv_rhs => rw [← sum_coe_sort] convert sum_pow_of_commute x s (fun _ _ _ _ _ ↦ Commute.all ..) n rw [Multiset.noncommProd_eq_prod] end CommSemiring end Finset namespace Nat variable {ι : Type*} {s : Finset ι} {f : ι → ℕ} lemma multinomial_two_mul_le_mul_multinomial : multinomial s (fun i ↦ 2 * f i) ≤ ((∑ i ∈ s, f i) ^ ∑ i ∈ s, f i) * multinomial s f := by rw [multinomial, multinomial, ← mul_sum, ← Nat.mul_div_assoc _ (prod_factorial_dvd_factorial_sum ..)] refine Nat.div_le_div_of_mul_le_mul (by positivity) ((prod_factorial_dvd_factorial_sum ..).trans (Nat.dvd_mul_left ..)) ?_ calc (2 * ∑ i ∈ s, f i)! * ∏ i ∈ s, (f i)! ≤ ((2 * ∑ i ∈ s, f i) ^ (∑ i ∈ s, f i) * (∑ i ∈ s, f i)!) * ∏ i ∈ s, (f i)! := by gcongr; exact Nat.factorial_two_mul_le _ _ = ((∑ i ∈ s, f i) ^ ∑ i ∈ s, f i) * (∑ i ∈ s, f i)! * ∏ i ∈ s, 2 ^ f i * (f i)! := by rw [mul_pow, ← prod_pow_eq_pow_sum, prod_mul_distrib]; ring _ ≤ ((∑ i ∈ s, f i) ^ ∑ i ∈ s, f i) * (∑ i ∈ s, f i)! * ∏ i ∈ s, (2 * f i)! := by gcongr rw [← doubleFactorial_two_mul] exact doubleFactorial_le_factorial _ end Nat namespace Sym variable {n : ℕ} {α : Type*} [DecidableEq α] theorem multinomial_coe_fill_of_notMem {m : Fin (n + 1)} {s : Sym α (n - m)} {x : α} (hx : x ∉ s) : (fill x m s : Multiset α).multinomial = n.choose m * (s : Multiset α).multinomial := by rw [Multiset.multinomial_filter_ne x] rw [← mem_coe] at hx refine congrArg₂ _ ?_ ?_ · rw [card_coe, count_coe_fill_self_of_notMem hx] · refine congrArg _ ?_ rw [coe_fill, coe_replicate, Multiset.filter_add] rw [Multiset.filter_eq_self.mpr] · rw [add_eq_left] rw [Multiset.filter_eq_nil] exact fun j hj ↦ by simp [Multiset.mem_replicate.mp hj] · exact fun j hj h ↦ hx <| by simpa [h] using hj @[deprecated (since := "2025-05-23")] alias multinomial_coe_fill_of_not_mem := multinomial_coe_fill_of_notMem end Sym
Operations.lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Patrick Massot -/ import Mathlib.Algebra.Algebra.Subalgebra.Operations import Mathlib.Algebra.Ring.Fin import Mathlib.LinearAlgebra.Quotient.Basic import Mathlib.RingTheory.Ideal.Quotient.Basic /-! # More operations on modules and ideals related to quotients ## Main results: - `RingHom.quotientKerEquivRange` : the **first isomorphism theorem** for commutative rings. - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `AlgHom.quotientKerEquivRange` : the **first isomorphism theorem** for a morphism of algebras (over a commutative semiring) - `RingHom.quotientKerEquivRangeS` : the **first isomorphism theorem** for a morphism from a commutative ring to a semiring. - `Ideal.quotientInfRingEquivPiQuotient`: the **Chinese Remainder Theorem**, version for coprime ideals (see also `ZMod.prodEquivPi` in `Data.ZMod.Quotient` for elementary versions about `ZMod`). -/ universe u v w namespace RingHom variable {R : Type u} {S : Type v} [Ring R] [Semiring S] (f : R →+* S) /-- The induced map from the quotient by the kernel to the codomain. This is an isomorphism if `f` has a right inverse (`quotientKerEquivOfRightInverse`) / is surjective (`quotientKerEquivOfSurjective`). -/ def kerLift : R ⧸ ker f →+* S := Ideal.Quotient.lift _ f fun _ => mem_ker.mp @[simp] theorem kerLift_mk (r : R) : kerLift f (Ideal.Quotient.mk (ker f) r) = f r := Ideal.Quotient.lift_mk _ _ _ theorem lift_injective_of_ker_le_ideal (I : Ideal R) [I.IsTwoSided] {f : R →+* S} (H : ∀ a : R, a ∈ I → f a = 0) (hI : ker f ≤ I) : Function.Injective (Ideal.Quotient.lift I f H) := by rw [RingHom.injective_iff_ker_eq_bot, RingHom.ker_eq_bot_iff_eq_zero] intro u hu obtain ⟨v, rfl⟩ := Ideal.Quotient.mk_surjective u rw [Ideal.Quotient.lift_mk] at hu rw [Ideal.Quotient.eq_zero_iff_mem] exact hI (RingHom.mem_ker.mpr hu) /-- The induced map from the quotient by the kernel is injective. -/ theorem kerLift_injective : Function.Injective (kerLift f) := lift_injective_of_ker_le_ideal (ker f) (fun a => by simp only [mem_ker, imp_self]) le_rfl variable {f} /-- The **first isomorphism theorem for commutative rings**, computable version. -/ def quotientKerEquivOfRightInverse {g : S → R} (hf : Function.RightInverse g f) : R ⧸ ker f ≃+* S := { kerLift f with toFun := kerLift f invFun := Ideal.Quotient.mk (ker f) ∘ g left_inv := by rintro ⟨x⟩ apply kerLift_injective simp only [Submodule.Quotient.quot_mk_eq_mk, Ideal.Quotient.mk_eq_mk, kerLift_mk, Function.comp_apply, hf (f x)] right_inv := hf } @[simp] theorem quotientKerEquivOfRightInverse.apply {g : S → R} (hf : Function.RightInverse g f) (x : R ⧸ ker f) : quotientKerEquivOfRightInverse hf x = kerLift f x := rfl @[simp] theorem quotientKerEquivOfRightInverse.Symm.apply {g : S → R} (hf : Function.RightInverse g f) (x : S) : (quotientKerEquivOfRightInverse hf).symm x = Ideal.Quotient.mk (ker f) (g x) := rfl /-- The **first isomorphism theorem** for commutative rings, surjective case. -/ noncomputable def quotientKerEquivOfSurjective (hf : Function.Surjective f) : R ⧸ (ker f) ≃+* S := quotientKerEquivOfRightInverse (Classical.choose_spec hf.hasRightInverse) /-- The **first isomorphism theorem** for commutative rings (`RingHom.rangeS` version). -/ noncomputable def quotientKerEquivRangeS (f : R →+* S) : R ⧸ ker f ≃+* f.rangeS := (Ideal.quotEquivOfEq f.ker_rangeSRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeSRestrict_surjective variable {S : Type v} [Ring S] (f : R →+* S) /-- The **first isomorphism theorem** for commutative rings (`RingHom.range` version). -/ noncomputable def quotientKerEquivRange (f : R →+* S) : R ⧸ ker f ≃+* f.range := (Ideal.quotEquivOfEq f.ker_rangeRestrict.symm).trans <| quotientKerEquivOfSurjective f.rangeRestrict_surjective end RingHom namespace Ideal open Function RingHom variable {R : Type u} {S : Type v} {F : Type w} [Ring R] [Semiring S] @[simp] theorem map_quotient_self (I : Ideal R) [I.IsTwoSided] : map (Quotient.mk I) I = ⊥ := eq_bot_iff.2 <| Ideal.map_le_iff_le_comap.2 fun _ hx => (Submodule.mem_bot (R ⧸ I)).2 <| Ideal.Quotient.eq_zero_iff_mem.2 hx @[simp] theorem mk_ker {I : Ideal R} [I.IsTwoSided] : ker (Quotient.mk I) = I := by ext rw [ker, mem_comap, Submodule.mem_bot, Quotient.eq_zero_iff_mem] theorem map_mk_eq_bot_of_le {I J : Ideal R} [J.IsTwoSided] (h : I ≤ J) : I.map (Quotient.mk J) = ⊥ := by rw [map_eq_bot_iff_le_ker, mk_ker] exact h theorem ker_quotient_lift {I : Ideal R} [I.IsTwoSided] (f : R →+* S) (H : I ≤ ker f) : ker (Ideal.Quotient.lift I f H) = (RingHom.ker f).map (Quotient.mk I) := by apply Ideal.ext intro x constructor · intro hx obtain ⟨y, hy⟩ := Quotient.mk_surjective x rw [mem_ker, ← hy, Ideal.Quotient.lift_mk, ← mem_ker] at hx rw [← hy, mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] exact ⟨y, hx, rfl⟩ · intro hx rw [mem_map_iff_of_surjective (Quotient.mk I) Quotient.mk_surjective] at hx obtain ⟨y, hy⟩ := hx rw [mem_ker, ← hy.right, Ideal.Quotient.lift_mk] exact hy.left lemma injective_lift_iff {I : Ideal R} [I.IsTwoSided] {f : R →+* S} (H : ∀ (a : R), a ∈ I → f a = 0) : Injective (Quotient.lift I f H) ↔ ker f = I := by rw [injective_iff_ker_eq_bot, ker_quotient_lift, map_eq_bot_iff_le_ker, mk_ker] constructor · exact fun h ↦ le_antisymm h H · rintro rfl; rfl lemma ker_Pi_Quotient_mk {ι : Type*} (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] : ker (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) = ⨅ i, I i := by simp [Pi.ker_ringHom, mk_ker] @[simp] theorem bot_quotient_isMaximal_iff (I : Ideal R) [I.IsTwoSided] : (⊥ : Ideal (R ⧸ I)).IsMaximal ↔ I.IsMaximal := ⟨fun hI => mk_ker (I := I) ▸ comap_isMaximal_of_surjective (Quotient.mk I) Quotient.mk_surjective (K := ⊥) (H := hI), fun hI => by letI := Quotient.divisionRing I exact bot_isMaximal⟩ /-- See also `Ideal.mem_quotient_iff_mem` in case `I ≤ J`. -/ @[simp] theorem mem_quotient_iff_mem_sup {I J : Ideal R} [I.IsTwoSided] {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J ⊔ I := by rw [← mem_comap, comap_map_of_surjective (Quotient.mk I) Quotient.mk_surjective, ← ker_eq_comap_bot, mk_ker] /-- See also `Ideal.mem_quotient_iff_mem_sup` if the assumption `I ≤ J` is not available. -/ theorem mem_quotient_iff_mem {I J : Ideal R} [I.IsTwoSided] (hIJ : I ≤ J) {x : R} : Quotient.mk I x ∈ J.map (Quotient.mk I) ↔ x ∈ J := by rw [mem_quotient_iff_mem_sup, sup_eq_left.mpr hIJ] section ChineseRemainder open Function Quotient Finset variable {ι : Type*} /-- The homomorphism from `R/(⋂ i, f i)` to `∏ i, (R / f i)` featured in the Chinese Remainder Theorem. It is bijective if the ideals `f i` are coprime. -/ def quotientInfToPiQuotient (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] : (R ⧸ ⨅ i, I i) →+* ∀ i, R ⧸ I i := Quotient.lift (⨅ i, I i) (Pi.ringHom fun i : ι ↦ Quotient.mk (I i)) (by simp [← RingHom.mem_ker, ker_Pi_Quotient_mk]) lemma quotientInfToPiQuotient_mk (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] (x : R) : quotientInfToPiQuotient I (Quotient.mk _ x) = fun i : ι ↦ Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_mk' (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] (x : R) (i : ι) : quotientInfToPiQuotient I (Quotient.mk _ x) i = Quotient.mk (I i) x := rfl lemma quotientInfToPiQuotient_inj (I : ι → Ideal R) [∀ i, (I i).IsTwoSided] : Injective (quotientInfToPiQuotient I) := by rw [quotientInfToPiQuotient, injective_lift_iff, ker_Pi_Quotient_mk] variable {R : Type*} [CommRing R] {ι : Type*} [Finite ι] lemma quotientInfToPiQuotient_surj {I : ι → Ideal R} (hI : Pairwise (IsCoprime on I)) : Surjective (quotientInfToPiQuotient I) := by classical cases nonempty_fintype ι intro g choose f hf using fun i ↦ mk_surjective (g i) have key : ∀ i, ∃ e : R, mk (I i) e = 1 ∧ ∀ j, j ≠ i → mk (I j) e = 0 := by intro i have hI' : ∀ j ∈ ({i} : Finset ι)ᶜ, IsCoprime (I i) (I j) := by intros j hj exact hI (by simpa [ne_comm, isCoprime_iff_add] using hj) rcases isCoprime_iff_exists.mp (isCoprime_biInf hI') with ⟨u, hu, e, he, hue⟩ replace he : ∀ j, j ≠ i → e ∈ I j := by simpa using he refine ⟨e, ?_, ?_⟩ · simp [eq_sub_of_add_eq' hue, map_sub, eq_zero_iff_mem.mpr hu] · exact fun j hj ↦ eq_zero_iff_mem.mpr (he j hj) choose e he using key use mk _ (∑ i, f i*e i) ext i rw [quotientInfToPiQuotient_mk', map_sum, Fintype.sum_eq_single i] · simp [(he i).1, hf] · intros j hj simp [(he j).2 i hj.symm] /-- **Chinese Remainder Theorem**. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/ noncomputable def quotientInfRingEquivPiQuotient (f : ι → Ideal R) (hf : Pairwise (IsCoprime on f)) : (R ⧸ ⨅ i, f i) ≃+* ∀ i, R ⧸ f i := { Equiv.ofBijective _ ⟨quotientInfToPiQuotient_inj f, quotientInfToPiQuotient_surj hf⟩, quotientInfToPiQuotient f with } /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then the canonical map `R → ∏ (R ⧸ Iᵢ)` is surjective. -/ lemma pi_quotient_surjective {I : ι → Ideal R} (hf : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : (i : ι) → R ⧸ I i) : ∃ r : R, ∀ i, r = x i := by obtain ⟨y, rfl⟩ := Ideal.quotientInfToPiQuotient_surj hf x obtain ⟨r, rfl⟩ := Ideal.Quotient.mk_surjective y exact ⟨r, fun i ↦ rfl⟩ -- variant of `IsDedekindDomain.exists_forall_sub_mem_ideal` which doesn't assume Dedekind domain! /-- Corollary of Chinese Remainder Theorem: if `Iᵢ` are pairwise coprime ideals in a commutative ring then given elements `xᵢ` you can find `r` with `r - xᵢ ∈ Iᵢ` for all `i`. -/ lemma exists_forall_sub_mem_ideal {I : ι → Ideal R} (hI : Pairwise fun i j ↦ IsCoprime (I i) (I j)) (x : ι → R) : ∃ r : R, ∀ i, r - x i ∈ I i := by obtain ⟨y, hy⟩ := Ideal.pi_quotient_surjective hI (fun i ↦ x i) exact ⟨y, fun i ↦ (Submodule.Quotient.eq (I i)).mp <| hy i⟩ /-- **Chinese remainder theorem**, specialized to two ideals. -/ noncomputable def quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : R ⧸ I ⊓ J ≃+* (R ⧸ I) × R ⧸ J := let f : Fin 2 → Ideal R := ![I, J] have hf : Pairwise (IsCoprime on f) := by intro i j h fin_cases i <;> fin_cases j <;> try contradiction · assumption · exact coprime.symm (Ideal.quotEquivOfEq (by simp [f, iInf, inf_comm])).trans <| (Ideal.quotientInfRingEquivPiQuotient f hf).trans <| RingEquiv.piFinTwo fun i => R ⧸ f i @[simp] theorem quotientInfEquivQuotientProd_fst (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).fst = Ideal.Quotient.factor inf_le_left x := Quot.inductionOn x fun _ => rfl @[simp] theorem quotientInfEquivQuotientProd_snd (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I ⊓ J) : (quotientInfEquivQuotientProd I J coprime x).snd = Ideal.Quotient.factor inf_le_right x := Quot.inductionOn x fun _ => rfl @[simp] theorem fst_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.fst _ _).comp (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor inf_le_left := by apply Quotient.ringHom_ext; ext; rfl @[simp] theorem snd_comp_quotientInfEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.snd _ _).comp (quotientInfEquivQuotientProd I J coprime : R ⧸ I ⊓ J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor inf_le_right := by apply Quotient.ringHom_ext; ext; rfl /-- **Chinese remainder theorem**, specialized to two ideals. -/ noncomputable def quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : R ⧸ I * J ≃+* (R ⧸ I) × R ⧸ J := Ideal.quotEquivOfEq (inf_eq_mul_of_isCoprime coprime).symm |>.trans <| Ideal.quotientInfEquivQuotientProd I J coprime @[simp] theorem quotientMulEquivQuotientProd_fst (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I * J) : (quotientMulEquivQuotientProd I J coprime x).fst = Ideal.Quotient.factor mul_le_right x := Quot.inductionOn x fun _ => rfl @[simp] theorem quotientMulEquivQuotientProd_snd (I J : Ideal R) (coprime : IsCoprime I J) (x : R ⧸ I * J) : (quotientMulEquivQuotientProd I J coprime x).snd = Ideal.Quotient.factor mul_le_left x := Quot.inductionOn x fun _ => rfl @[simp] theorem fst_comp_quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.fst _ _).comp (quotientMulEquivQuotientProd I J coprime : R ⧸ I * J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor mul_le_right := by apply Quotient.ringHom_ext; ext; rfl @[simp] theorem snd_comp_quotientMulEquivQuotientProd (I J : Ideal R) (coprime : IsCoprime I J) : (RingHom.snd _ _).comp (quotientMulEquivQuotientProd I J coprime : R ⧸ I * J →+* (R ⧸ I) × R ⧸ J) = Ideal.Quotient.factor mul_le_left := by apply Quotient.ringHom_ext; ext; rfl end ChineseRemainder section QuotientAlgebra variable (R₁ R₂ : Type*) {A B : Type*} variable [CommSemiring R₁] [CommSemiring R₂] [Ring A] variable [Algebra R₁ A] [Algebra R₂ A] /-- The `R₁`-algebra structure on `A/I` for an `R₁`-algebra `A` -/ instance Quotient.algebra {I : Ideal A} [I.IsTwoSided] : Algebra R₁ (A ⧸ I) where algebraMap := (Ideal.Quotient.mk I).comp (algebraMap R₁ A) smul_def' := fun _ x => Quotient.inductionOn' x fun _ => ((Quotient.mk I).congr_arg <| Algebra.smul_def _ _).trans (RingHom.map_mul _ _ _) commutes' := by rintro r ⟨x⟩; exact congr_arg (⟦·⟧) (Algebra.commutes r x) instance {A} [CommRing A] [Algebra R₁ A] (I : Ideal A) : Algebra R₁ (A ⧸ I) := inferInstance -- Lean can struggle to find this instance later if we don't provide this shortcut -- Porting note: this can probably now be deleted -- update: maybe not - removal causes timeouts instance Quotient.isScalarTower [SMul R₁ R₂] [IsScalarTower R₁ R₂ A] (I : Ideal A) : IsScalarTower R₁ R₂ (A ⧸ I) := inferInstance /-- The canonical morphism `A →ₐ[R₁] A ⧸ I` as morphism of `R₁`-algebras, for `I` an ideal of `A`, where `A` is an `R₁`-algebra. -/ def Quotient.mkₐ (I : Ideal A) [I.IsTwoSided] : A →ₐ[R₁] A ⧸ I := ⟨⟨⟨⟨fun a => Submodule.Quotient.mk a, rfl⟩, fun _ _ => rfl⟩, rfl, fun _ _ => rfl⟩, fun _ => rfl⟩ theorem Quotient.algHom_ext {I : Ideal A} [I.IsTwoSided] {S} [Semiring S] [Algebra R₁ S] ⦃f g : A ⧸ I →ₐ[R₁] S⦄ (h : f.comp (Quotient.mkₐ R₁ I) = g.comp (Quotient.mkₐ R₁ I)) : f = g := AlgHom.ext fun x => Quotient.inductionOn' x <| AlgHom.congr_fun h theorem Quotient.alg_map_eq {A} [CommRing A] [Algebra R₁ A] (I : Ideal A) : algebraMap R₁ (A ⧸ I) = (algebraMap A (A ⧸ I)).comp (algebraMap R₁ A) := rfl theorem Quotient.mkₐ_toRingHom (I : Ideal A) [I.IsTwoSided] : (Quotient.mkₐ R₁ I).toRingHom = Ideal.Quotient.mk I := rfl @[simp] theorem Quotient.mkₐ_eq_mk (I : Ideal A) [I.IsTwoSided] : ⇑(Quotient.mkₐ R₁ I) = Quotient.mk I := rfl @[simp] theorem Quotient.algebraMap_eq {R} [CommRing R] (I : Ideal R) : algebraMap R (R ⧸ I) = Quotient.mk I := rfl @[simp] theorem Quotient.mk_comp_algebraMap (I : Ideal A) [I.IsTwoSided] : (Quotient.mk I).comp (algebraMap R₁ A) = algebraMap R₁ (A ⧸ I) := rfl @[simp] theorem Quotient.mk_algebraMap (I : Ideal A) [I.IsTwoSided] (x : R₁) : Quotient.mk I (algebraMap R₁ A x) = algebraMap R₁ (A ⧸ I) x := rfl /-- The canonical morphism `A →ₐ[R₁] I.quotient` is surjective. -/ theorem Quotient.mkₐ_surjective (I : Ideal A) [I.IsTwoSided] : Function.Surjective (Quotient.mkₐ R₁ I) := Quot.mk_surjective /-- The kernel of `A →ₐ[R₁] I.quotient` is `I`. -/ @[simp] theorem Quotient.mkₐ_ker (I : Ideal A) [I.IsTwoSided] : RingHom.ker (Quotient.mkₐ R₁ I : A →+* A ⧸ I) = I := Ideal.mk_ker lemma Quotient.mk_bijective_iff_eq_bot (I : Ideal A) [I.IsTwoSided] : Function.Bijective (mk I) ↔ I = ⊥ := by constructor · intro h rw [← map_eq_bot_iff_of_injective h.1] exact (map_eq_bot_iff_le_ker _).mpr <| le_of_eq mk_ker.symm · exact fun h => ⟨(injective_iff_ker_eq_bot _).mpr <| by rw [mk_ker, h], mk_surjective⟩ section /-- `AlgHom` version of `Ideal.Quotient.factor`. -/ def Quotient.factorₐ {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (hIJ : I ≤ J) : A ⧸ I →ₐ[R₁] A ⧸ J where __ := Ideal.Quotient.factor hIJ commutes' _ := rfl variable {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (hIJ : I ≤ J) @[simp] lemma Quotient.coe_factorₐ : (Ideal.Quotient.factorₐ R₁ hIJ : A ⧸ I →+* A ⧸ J) = Ideal.Quotient.factor hIJ := rfl @[simp] lemma Quotient.factorₐ_apply_mk (x : A) : Ideal.Quotient.factorₐ R₁ hIJ x = x := rfl @[simp] lemma Quotient.factorₐ_comp_mk : (Ideal.Quotient.factorₐ R₁ hIJ).comp (Ideal.Quotient.mkₐ R₁ I) = Ideal.Quotient.mkₐ R₁ J := rfl @[simp] lemma Quotient.factorₐ_comp {K : Ideal A} [K.IsTwoSided] (hJK : J ≤ K) : (Ideal.Quotient.factorₐ R₁ hJK).comp (Ideal.Quotient.factorₐ R₁ hIJ) = Ideal.Quotient.factorₐ R₁ (hIJ.trans hJK) := Ideal.Quotient.algHom_ext _ (by ext; simp) end variable {R₁} section variable [Semiring B] [Algebra R₁ B] /-- `Ideal.quotient.lift` as an `AlgHom`. -/ def Quotient.liftₐ (I : Ideal A) [I.IsTwoSided] (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) : A ⧸ I →ₐ[R₁] B := {-- this is IsScalarTower.algebraMap_apply R₁ A (A ⧸ I) but the file `Algebra.Algebra.Tower` -- imports this file. Ideal.Quotient.lift I (f : A →+* B) hI with commutes' := fun r => by have : algebraMap R₁ (A ⧸ I) r = Ideal.Quotient.mk I (algebraMap R₁ A r) := rfl rw [this, RingHom.toFun_eq_coe, Ideal.Quotient.lift_mk, AlgHom.coe_toRingHom, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, map_smul, map_one] } @[simp] theorem Quotient.liftₐ_apply (I : Ideal A) [I.IsTwoSided] (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) (x) : Ideal.Quotient.liftₐ I f hI x = Ideal.Quotient.lift I (f : A →+* B) hI x := rfl theorem Quotient.liftₐ_comp (I : Ideal A) [I.IsTwoSided] (f : A →ₐ[R₁] B) (hI : ∀ a : A, a ∈ I → f a = 0) : (Ideal.Quotient.liftₐ I f hI).comp (Ideal.Quotient.mkₐ R₁ I) = f := AlgHom.ext fun _ => (Ideal.Quotient.lift_mk I (f : A →+* B) hI :) theorem Quotient.span_singleton_one (I : Ideal A) [I.IsTwoSided] : Submodule.span A {(1 : A ⧸ I)} = ⊤ := by rw [← map_one (mk _), ← Submodule.range_mkQ I, ← Submodule.map_top, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, Set.image_singleton, Submodule.mkQ_apply, Quotient.mk_eq_mk] open Pointwise in lemma Quotient.smul_top {R : Type*} [CommRing R] (a : R) (I : Ideal R) : (a • ⊤ : Submodule R (R ⧸ I)) = Submodule.span R {Submodule.Quotient.mk a} := by simp [← Ideal.Quotient.span_singleton_one, Algebra.smul_def, Submodule.smul_span] theorem KerLift.map_smul (f : A →ₐ[R₁] B) (r : R₁) (x : A ⧸ (RingHom.ker f)) : f.kerLift (r • x) = r • f.kerLift x := by obtain ⟨a, rfl⟩ := Quotient.mkₐ_surjective R₁ _ x exact _root_.map_smul f _ _ /-- The induced algebras morphism from the quotient by the kernel to the codomain. This is an isomorphism if `f` has a right inverse (`quotientKerAlgEquivOfRightInverse`) / is surjective (`quotientKerAlgEquivOfSurjective`). -/ def kerLiftAlg (f : A →ₐ[R₁] B) : A ⧸ (RingHom.ker f) →ₐ[R₁] B := AlgHom.mk' (RingHom.kerLift (f : A →+* B)) fun _ _ => KerLift.map_smul f _ _ @[simp] theorem kerLiftAlg_mk (f : A →ₐ[R₁] B) (a : A) : kerLiftAlg f (Quotient.mk (RingHom.ker f) a) = f a := by rfl @[simp] theorem kerLiftAlg_toRingHom (f : A →ₐ[R₁] B) : (kerLiftAlg f : A ⧸ ker f →+* B) = RingHom.kerLift (f : A →+* B) := rfl /-- The induced algebra morphism from the quotient by the kernel is injective. -/ theorem kerLiftAlg_injective (f : A →ₐ[R₁] B) : Function.Injective (kerLiftAlg f) := RingHom.kerLift_injective (R := A) (S := B) f /-- The **first isomorphism** theorem for algebras, computable version. -/ @[simps!] def quotientKerAlgEquivOfRightInverse {f : A →ₐ[R₁] B} {g : B → A} (hf : Function.RightInverse g f) : (A ⧸ RingHom.ker f) ≃ₐ[R₁] B := { RingHom.quotientKerEquivOfRightInverse hf, kerLiftAlg f with } /-- The **first isomorphism theorem** for algebras. -/ @[simps!] noncomputable def quotientKerAlgEquivOfSurjective {f : A →ₐ[R₁] B} (hf : Function.Surjective f) : (A ⧸ (RingHom.ker f)) ≃ₐ[R₁] B := quotientKerAlgEquivOfRightInverse (Classical.choose_spec hf.hasRightInverse) end section Ring_Ring variable {S : Type v} [Ring S] /-- The ring hom `R/I →+* S/J` induced by a ring hom `f : R →+* S` with `I ≤ f⁻¹(J)` -/ def quotientMap {I : Ideal R} (J : Ideal S) [I.IsTwoSided] [J.IsTwoSided] (f : R →+* S) (hIJ : I ≤ J.comap f) : R ⧸ I →+* S ⧸ J := Quotient.lift I ((Quotient.mk J).comp f) fun _ ha => by simpa [Function.comp_apply, RingHom.coe_comp, Quotient.eq_zero_iff_mem] using hIJ ha @[simp] theorem quotientMap_mk {J : Ideal R} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {f : R →+* S} {H : J ≤ I.comap f} {x : R} : quotientMap I f H (Quotient.mk J x) = Quotient.mk I (f x) := Quotient.lift_mk J _ _ @[simp] theorem quotientMap_algebraMap {J : Ideal A} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {f : A →+* S} {H : J ≤ I.comap f} {x : R₁} : quotientMap I f H (algebraMap R₁ (A ⧸ J) x) = Quotient.mk I (f (algebraMap _ _ x)) := Quotient.lift_mk J _ _ theorem quotientMap_comp_mk {J : Ideal R} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {f : R →+* S} (H : J ≤ I.comap f) : (quotientMap I f H).comp (Quotient.mk J) = (Quotient.mk I).comp f := RingHom.ext fun x => by simp only [Function.comp_apply, RingHom.coe_comp, Ideal.quotientMap_mk] lemma ker_quotientMap_mk {I J : Ideal R} [I.IsTwoSided] [J.IsTwoSided] : RingHom.ker (quotientMap (J.map _) (Quotient.mk I) le_comap_map) = I.map (Quotient.mk J) := by rw [Ideal.quotientMap, Ideal.ker_quotient_lift, ← RingHom.comap_ker, Ideal.mk_ker, Ideal.comap_map_of_surjective _ Ideal.Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, Ideal.mk_ker, Ideal.map_sup, Ideal.map_quotient_self, bot_sup_eq] section quotientEquiv variable (I : Ideal R) (J : Ideal S) [I.IsTwoSided] [J.IsTwoSided] (f : R ≃+* S) (hIJ : J = I.map (f : R →+* S)) /-- The ring equiv `R/I ≃+* S/J` induced by a ring equiv `f : R ≃+* S`, where `J = f(I)`. -/ @[simps] def quotientEquiv : R ⧸ I ≃+* S ⧸ J where __ := quotientMap J f (hIJ ▸ le_comap_map) invFun := quotientMap I f.symm (hIJ ▸ (map_comap_of_equiv f).le) left_inv := by rintro ⟨r⟩ simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, RingHom.toFun_eq_coe, quotientMap_mk, RingEquiv.coe_toRingHom, RingEquiv.symm_apply_apply] right_inv := by rintro ⟨s⟩ simp only [Submodule.Quotient.quot_mk_eq_mk, Quotient.mk_eq_mk, RingHom.toFun_eq_coe, quotientMap_mk, RingEquiv.coe_toRingHom, RingEquiv.apply_symm_apply] /- Porting note: removed simp. LHS simplified. Slightly different version of the simplified form closed this and was itself closed by simp -/ theorem quotientEquiv_mk (x : R) : quotientEquiv I J f hIJ (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J (f x) := rfl -- @[simp] /- adaption note for https://github.com/leanprover/lean4/pull/8419 : the simpNF linter complained -/ theorem quotientEquiv_symm_mk (x : S) : (quotientEquiv I J f hIJ).symm (Ideal.Quotient.mk J x) = Ideal.Quotient.mk I (f.symm x) := rfl end quotientEquiv /-- `H` and `h` are kept as separate hypothesis since H is used in constructing the quotient map. -/ theorem quotientMap_injective' {J : Ideal R} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {f : R →+* S} {H : J ≤ I.comap f} (h : I.comap f ≤ J) : Function.Injective (quotientMap I f H) := by refine (injective_iff_map_eq_zero (quotientMap I f H)).2 fun a ha => ?_ obtain ⟨r, rfl⟩ := Quotient.mk_surjective a rw [quotientMap_mk, Quotient.eq_zero_iff_mem] at ha exact Quotient.eq_zero_iff_mem.mpr (h ha) /-- If we take `J = I.comap f` then `quotientMap` is injective automatically. -/ theorem quotientMap_injective {I : Ideal S} {f : R →+* S} [I.IsTwoSided] : Function.Injective (quotientMap I f le_rfl) := quotientMap_injective' le_rfl theorem quotientMap_surjective {J : Ideal R} {I : Ideal S} [I.IsTwoSided] [J.IsTwoSided] {f : R →+* S} {H : J ≤ I.comap f} (hf : Function.Surjective f) : Function.Surjective (quotientMap I f H) := fun x => let ⟨x, hx⟩ := Quotient.mk_surjective x let ⟨y, hy⟩ := hf x ⟨(Quotient.mk J) y, by simp [hx, hy]⟩ /-- Commutativity of a square is preserved when taking quotients by an ideal. -/ theorem comp_quotientMap_eq_of_comp_eq {R' S' : Type*} [Ring R'] [Ring S'] {f : R →+* S} {f' : R' →+* S'} {g : R →+* R'} {g' : S →+* S'} (hfg : f'.comp g = g'.comp f) (I : Ideal S') [I.IsTwoSided] : -- Porting note: was losing track of I let leq := le_of_eq (_root_.trans (comap_comap (I := I) f g') (hfg ▸ comap_comap (I := I) g f')) (quotientMap I g' le_rfl).comp (quotientMap (I.comap g') f le_rfl) = (quotientMap I f' le_rfl).comp (quotientMap (I.comap f') g leq) := by refine RingHom.ext fun a => ?_ obtain ⟨r, rfl⟩ := Quotient.mk_surjective a simp only [RingHom.comp_apply, quotientMap_mk] exact (Ideal.Quotient.mk I).congr_arg (_root_.trans (g'.comp_apply f r).symm (hfg ▸ f'.comp_apply g r)) end Ring_Ring section variable [Ring B] [Algebra R₁ B] {I : Ideal A} (J : Ideal B) [I.IsTwoSided] [J.IsTwoSided] /-- The algebra hom `A/I →+* B/J` induced by an algebra hom `f : A →ₐ[R₁] B` with `I ≤ f⁻¹(J)`. -/ def quotientMapₐ (f : A →ₐ[R₁] B) (hIJ : I ≤ J.comap f) : A ⧸ I →ₐ[R₁] B ⧸ J := { quotientMap J (f : A →+* B) hIJ with commutes' := fun r => by simp only [RingHom.toFun_eq_coe, quotientMap_algebraMap, AlgHom.coe_toRingHom, AlgHom.commutes, Quotient.mk_algebraMap] } @[simp] theorem quotient_map_mkₐ (f : A →ₐ[R₁] B) (H : I ≤ J.comap f) {x : A} : quotientMapₐ J f H (Quotient.mk I x) = Quotient.mkₐ R₁ J (f x) := rfl theorem quotient_map_comp_mkₐ (f : A →ₐ[R₁] B) (H : I ≤ J.comap f) : (quotientMapₐ J f H).comp (Quotient.mkₐ R₁ I) = (Quotient.mkₐ R₁ J).comp f := AlgHom.ext fun x => by simp only [quotient_map_mkₐ, Quotient.mkₐ_eq_mk, AlgHom.comp_apply] variable (I) in /-- The algebra equiv `A/I ≃ₐ[R] B/J` induced by an algebra equiv `f : A ≃ₐ[R] B`, where`J = f(I)`. -/ def quotientEquivAlg (f : A ≃ₐ[R₁] B) (hIJ : J = I.map (f : A →+* B)) : (A ⧸ I) ≃ₐ[R₁] B ⧸ J := { quotientEquiv I J (f : A ≃+* B) hIJ with commutes' := fun r => by -- Porting note: Needed to add the below lemma because Equivs coerce weird have : ∀ (e : RingEquiv (A ⧸ I) (B ⧸ J)), Equiv.toFun e.toEquiv = DFunLike.coe e := fun _ ↦ rfl rw [this] simp only [quotientEquiv_apply, RingHom.toFun_eq_coe, quotientMap_algebraMap, RingEquiv.coe_toRingHom, AlgEquiv.coe_ringEquiv, AlgEquiv.commutes, Quotient.mk_algebraMap]} end /-- If `P` lies over `p`, then `R / p` has a canonical map to `A / P`. -/ abbrev Quotient.algebraQuotientOfLEComap {R} [CommRing R] [Algebra R A] {p : Ideal R} {P : Ideal A} [P.IsTwoSided] (h : p ≤ comap (algebraMap R A) P) : Algebra (R ⧸ p) (A ⧸ P) where algebraMap := quotientMap P (algebraMap R A) h smul := Quotient.lift₂ (⟦· • ·⟧) fun r₁ a₁ r₂ a₂ hr ha ↦ Quotient.sound <| by have := h (p.quotientRel_def.mp hr) rw [mem_comap, map_sub] at this simpa only [Algebra.smul_def] using P.quotientRel_def.mpr (P.mul_sub_mul_mem this <| P.quotientRel_def.mp ha) smul_def' := by rintro ⟨_⟩ ⟨_⟩; exact congr_arg (⟦·⟧) (Algebra.smul_def _ _) commutes' := by rintro ⟨_⟩ ⟨_⟩; exact congr_arg (⟦·⟧) (Algebra.commutes _ _) instance (priority := 100) quotientAlgebra {R} [CommRing R] {I : Ideal A} [I.IsTwoSided] [Algebra R A] : Algebra (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := Quotient.algebraQuotientOfLEComap le_rfl instance (R) {A} [CommRing R] [CommRing A] (I : Ideal A) [Algebra R A] : Algebra (R ⧸ I.comap (algebraMap R A)) (A ⧸ I) := inferInstance theorem algebraMap_quotient_injective {R} [CommRing R] {I : Ideal A} [I.IsTwoSided] [Algebra R A] : Function.Injective (algebraMap (R ⧸ I.comap (algebraMap R A)) (A ⧸ I)) := by rintro ⟨a⟩ ⟨b⟩ hab replace hab := Quotient.eq.mp hab rw [← RingHom.map_sub] at hab exact Quotient.eq.mpr hab variable (R₁) /-- Quotienting by equal ideals gives equivalent algebras. -/ def quotientEquivAlgOfEq {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (h : I = J) : (A ⧸ I) ≃ₐ[R₁] A ⧸ J := quotientEquivAlg I J AlgEquiv.refl <| h ▸ (map_id I).symm @[simp] theorem quotientEquivAlgOfEq_mk {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (h : I = J) (x : A) : quotientEquivAlgOfEq R₁ h (Ideal.Quotient.mk I x) = Ideal.Quotient.mk J x := rfl @[simp] theorem quotientEquivAlgOfEq_symm {I J : Ideal A} [I.IsTwoSided] [J.IsTwoSided] (h : I = J) : (quotientEquivAlgOfEq R₁ h).symm = quotientEquivAlgOfEq R₁ h.symm := by ext rfl lemma comap_map_mk {I J : Ideal R} [I.IsTwoSided] (h : I ≤ J) : Ideal.comap (Ideal.Quotient.mk I) (Ideal.map (Ideal.Quotient.mk I) J) = J := by ext; rw [← Ideal.mem_quotient_iff_mem h, Ideal.mem_comap] /-- The **first isomorphism theorem** for commutative algebras (`AlgHom.range` version). -/ noncomputable def quotientKerEquivRange {R A B : Type*} [CommSemiring R] [Ring A] [Algebra R A] [Semiring B] [Algebra R B] (f : A →ₐ[R] B) : (A ⧸ RingHom.ker f) ≃ₐ[R] f.range := (Ideal.quotientEquivAlgOfEq R (AlgHom.ker_rangeRestrict f).symm).trans <| Ideal.quotientKerAlgEquivOfSurjective f.rangeRestrict_surjective end QuotientAlgebra end Ideal section quotientBot variable {R S : Type*} variable (R) in /-- The quotient of a ring by he zero ideal is isomorphic to the ring itself. -/ def RingEquiv.quotientBot [Ring R] : R ⧸ (⊥ : Ideal R) ≃+* R := (Ideal.quotEquivOfEq (RingHom.ker_coe_equiv <| .refl _).symm).trans <| RingHom.quotientKerEquivOfRightInverse (f := .id R) (g := _root_.id) fun _ ↦ rfl @[simp] lemma RingEquiv.quotientBot_mk [Ring R] (r : R) : RingEquiv.quotientBot R (Ideal.Quotient.mk ⊥ r) = r := rfl @[simp] lemma RingEquiv.quotientBot_symm_mk [Ring R] (r : R) : (RingEquiv.quotientBot R).symm r = r := rfl variable (R S) in /-- `RingEquiv.quotientBot` as an algebra isomorphism. -/ def AlgEquiv.quotientBot [CommSemiring R] [Ring S] [Algebra R S] : (S ⧸ (⊥ : Ideal S)) ≃ₐ[R] S where __ := RingEquiv.quotientBot S commutes' x := by simp [← Ideal.Quotient.mk_algebraMap] @[simp] lemma AlgEquiv.quotientBot_mk [CommSemiring R] [CommRing S] [Algebra R S] (s : S) : AlgEquiv.quotientBot R S (Ideal.Quotient.mk ⊥ s) = s := rfl @[simp] lemma AlgEquiv.quotientBot_symm_mk [CommSemiring R] [CommRing S] [Algebra R S] (s : S) : (AlgEquiv.quotientBot R S).symm s = s := rfl end quotientBot namespace DoubleQuot open Ideal variable {R : Type u} section variable [CommRing R] (I J : Ideal R) /-- The obvious ring hom `R/I → R/(I ⊔ J)` -/ def quotLeftToQuotSup : R ⧸ I →+* R ⧸ I ⊔ J := Ideal.Quotient.factor le_sup_left /-- The kernel of `quotLeftToQuotSup` -/ theorem ker_quotLeftToQuotSup : RingHom.ker (quotLeftToQuotSup I J) = J.map (Ideal.Quotient.mk I) := by simp only [mk_ker, sup_idem, sup_comm, quotLeftToQuotSup, Quotient.factor, ker_quotient_lift, map_eq_iff_sup_ker_eq_of_surjective (Ideal.Quotient.mk I) Quotient.mk_surjective, ← sup_assoc] /-- The ring homomorphism `(R/I)/J' -> R/(I ⊔ J)` induced by `quotLeftToQuotSup` where `J'` is the image of `J` in `R/I` -/ def quotQuotToQuotSup : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) →+* R ⧸ I ⊔ J := Ideal.Quotient.lift (J.map (Ideal.Quotient.mk I)) (quotLeftToQuotSup I J) (ker_quotLeftToQuotSup I J).symm.le /-- The composite of the maps `R → (R/I)` and `(R/I) → (R/I)/J'` -/ def quotQuotMk : R →+* (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) := (Ideal.Quotient.mk (J.map (Ideal.Quotient.mk I))).comp (Ideal.Quotient.mk I) -- Porting note: mismatched instances /-- The kernel of `quotQuotMk` -/ theorem ker_quotQuotMk : RingHom.ker (quotQuotMk I J) = I ⊔ J := by rw [RingHom.ker_eq_comap_bot, quotQuotMk, ← comap_comap, ← RingHom.ker, mk_ker, comap_map_of_surjective (Ideal.Quotient.mk I) Ideal.Quotient.mk_surjective, ← RingHom.ker, mk_ker, sup_comm] /-- The ring homomorphism `R/(I ⊔ J) → (R/I)/J' `induced by `quotQuotMk` -/ def liftSupQuotQuotMk (I J : Ideal R) : R ⧸ I ⊔ J →+* (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) := Ideal.Quotient.lift (I ⊔ J) (quotQuotMk I J) (ker_quotQuotMk I J).symm.le /-- `quotQuotToQuotSup` and `liftSupQuotQuotMk` are inverse isomorphisms. In the case where `I ≤ J`, this is the Third Isomorphism Theorem (see `quotQuotEquivQuotOfLe`). -/ def quotQuotEquivQuotSup : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* R ⧸ I ⊔ J := RingEquiv.ofHomInv (quotQuotToQuotSup I J) (liftSupQuotQuotMk I J) (by repeat apply Ideal.Quotient.ringHom_ext rfl) (by repeat apply Ideal.Quotient.ringHom_ext rfl) @[simp] theorem quotQuotEquivQuotSup_quotQuotMk (x : R) : quotQuotEquivQuotSup I J (quotQuotMk I J x) = Ideal.Quotient.mk (I ⊔ J) x := rfl @[simp] theorem quotQuotEquivQuotSup_symm_quotQuotMk (x : R) : (quotQuotEquivQuotSup I J).symm (Ideal.Quotient.mk (I ⊔ J) x) = quotQuotMk I J x := rfl /-- The obvious isomorphism `(R/I)/J' → (R/J)/I'` -/ def quotQuotEquivComm : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* (R ⧸ J) ⧸ I.map (Ideal.Quotient.mk J) := ((quotQuotEquivQuotSup I J).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup J I).symm -- Porting note: mismatched instances @[simp] theorem quotQuotEquivComm_quotQuotMk (x : R) : quotQuotEquivComm I J (quotQuotMk I J x) = quotQuotMk J I x := rfl -- Porting note: mismatched instances @[simp] theorem quotQuotEquivComm_comp_quotQuotMk : RingHom.comp (↑(quotQuotEquivComm I J)) (quotQuotMk I J) = quotQuotMk J I := RingHom.ext <| quotQuotEquivComm_quotQuotMk I J @[simp] theorem quotQuotEquivComm_symm : (quotQuotEquivComm I J).symm = quotQuotEquivComm J I := by /- Porting note: this proof used to just be rfl but currently rfl opens up a bottomless pit of processor cycles. Synthesizing instances does not seem to be an issue. -/ change (((quotQuotEquivQuotSup I J).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup J I).symm).symm = ((quotQuotEquivQuotSup J I).trans (quotEquivOfEq (sup_comm ..))).trans (quotQuotEquivQuotSup I J).symm ext r dsimp rfl variable {I J} /-- **The Third Isomorphism theorem** for rings. See `quotQuotEquivQuotSup` for a version that does not assume an inclusion of ideals. -/ def quotQuotEquivQuotOfLE (h : I ≤ J) : (R ⧸ I) ⧸ J.map (Ideal.Quotient.mk I) ≃+* R ⧸ J := (quotQuotEquivQuotSup I J).trans (Ideal.quotEquivOfEq <| sup_eq_right.mpr h) @[simp] theorem quotQuotEquivQuotOfLE_quotQuotMk (x : R) (h : I ≤ J) : quotQuotEquivQuotOfLE h (quotQuotMk I J x) = (Ideal.Quotient.mk J) x := rfl @[simp] theorem quotQuotEquivQuotOfLE_symm_mk (x : R) (h : I ≤ J) : (quotQuotEquivQuotOfLE h).symm ((Ideal.Quotient.mk J) x) = quotQuotMk I J x := rfl theorem quotQuotEquivQuotOfLE_comp_quotQuotMk (h : I ≤ J) : RingHom.comp (↑(quotQuotEquivQuotOfLE h)) (quotQuotMk I J) = (Ideal.Quotient.mk J) := by ext rfl theorem quotQuotEquivQuotOfLE_symm_comp_mk (h : I ≤ J) : RingHom.comp (↑(quotQuotEquivQuotOfLE h).symm) (Ideal.Quotient.mk J) = quotQuotMk I J := by ext rfl end section Algebra @[simp] theorem quotQuotEquivComm_mk_mk [CommRing R] (I J : Ideal R) (x : R) : quotQuotEquivComm I J (Ideal.Quotient.mk _ (Ideal.Quotient.mk _ x)) = algebraMap R _ x := rfl variable [CommSemiring R] {A : Type v} [CommRing A] [Algebra R A] (I J : Ideal A) @[simp] theorem quotQuotEquivQuotSup_quot_quot_algebraMap (x : R) : DoubleQuot.quotQuotEquivQuotSup I J (algebraMap R _ x) = algebraMap _ _ x := rfl @[simp] theorem quotQuotEquivComm_algebraMap (x : R) : quotQuotEquivComm I J (algebraMap R _ x) = algebraMap _ _ x := rfl end Algebra section AlgebraQuotient variable (R) {A : Type*} [CommSemiring R] [CommRing A] [Algebra R A] (I J : Ideal A) /-- The natural algebra homomorphism `A / I → A / (I ⊔ J)`. -/ def quotLeftToQuotSupₐ : A ⧸ I →ₐ[R] A ⧸ I ⊔ J := AlgHom.mk (quotLeftToQuotSup I J) fun _ => rfl @[simp] theorem quotLeftToQuotSupₐ_toRingHom : (quotLeftToQuotSupₐ R I J : _ →+* _) = quotLeftToQuotSup I J := rfl @[simp] theorem coe_quotLeftToQuotSupₐ : ⇑(quotLeftToQuotSupₐ R I J) = quotLeftToQuotSup I J := rfl /-- The algebra homomorphism `(A / I) / J' -> A / (I ⊔ J)` induced by `quotQuotToQuotSup`, where `J'` is the projection of `J` in `A / I`. -/ def quotQuotToQuotSupₐ : (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) →ₐ[R] A ⧸ I ⊔ J := AlgHom.mk (quotQuotToQuotSup I J) fun _ => rfl @[simp] theorem quotQuotToQuotSupₐ_toRingHom : ((quotQuotToQuotSupₐ R I J) : _ ⧸ map (Ideal.Quotient.mkₐ R I) J →+* _) = quotQuotToQuotSup I J := rfl @[simp] theorem coe_quotQuotToQuotSupₐ : ⇑(quotQuotToQuotSupₐ R I J) = quotQuotToQuotSup I J := rfl /-- The composition of the algebra homomorphisms `A → (A / I)` and `(A / I) → (A / I) / J'`, where `J'` is the projection `J` in `A / I`. -/ def quotQuotMkₐ : A →ₐ[R] (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) := AlgHom.mk (quotQuotMk I J) fun _ => rfl @[simp] theorem quotQuotMkₐ_toRingHom : (quotQuotMkₐ R I J : _ →+* _ ⧸ J.map (Quotient.mkₐ R I)) = quotQuotMk I J := rfl @[simp] theorem coe_quotQuotMkₐ : ⇑(quotQuotMkₐ R I J) = quotQuotMk I J := rfl /-- The injective algebra homomorphism `A / (I ⊔ J) → (A / I) / J'`induced by `quot_quot_mk`, where `J'` is the projection `J` in `A / I`. -/ def liftSupQuotQuotMkₐ (I J : Ideal A) : A ⧸ I ⊔ J →ₐ[R] (A ⧸ I) ⧸ J.map (Quotient.mkₐ R I) := AlgHom.mk (liftSupQuotQuotMk I J) fun _ => rfl @[simp] theorem liftSupQuotQuotMkₐ_toRingHom : (liftSupQuotQuotMkₐ R I J : _ →+* _ ⧸ J.map (Quotient.mkₐ R I)) = liftSupQuotQuotMk I J := rfl @[simp] theorem coe_liftSupQuotQuotMkₐ : ⇑(liftSupQuotQuotMkₐ R I J) = liftSupQuotQuotMk I J := rfl /-- `quotQuotToQuotSup` and `liftSupQuotQuotMk` are inverse isomorphisms. In the case where `I ≤ J`, this is the Third Isomorphism Theorem (see `DoubleQuot.quotQuotEquivQuotOfLE`). -/ def quotQuotEquivQuotSupₐ : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] A ⧸ I ⊔ J := AlgEquiv.ofRingEquiv (f := quotQuotEquivQuotSup I J) fun _ => rfl @[simp] theorem quotQuotEquivQuotSupₐ_toRingEquiv : (quotQuotEquivQuotSupₐ R I J : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _) = quotQuotEquivQuotSup I J := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotSupₐ : ⇑(quotQuotEquivQuotSupₐ R I J) = ⇑(quotQuotEquivQuotSup I J) := rfl @[simp] theorem quotQuotEquivQuotSupₐ_symm_toRingEquiv : ((quotQuotEquivQuotSupₐ R I J).symm : _ ≃+* _ ⧸ J.map (Quotient.mkₐ R I)) = (quotQuotEquivQuotSup I J).symm := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotSupₐ_symm : ⇑(quotQuotEquivQuotSupₐ R I J).symm = ⇑(quotQuotEquivQuotSup I J).symm := rfl /-- The natural algebra isomorphism `(A / I) / J' → (A / J) / I'`, where `J'` (resp. `I'`) is the projection of `J` in `A / I` (resp. `I` in `A / J`). -/ def quotQuotEquivCommₐ : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] (A ⧸ J) ⧸ I.map (Quotient.mkₐ R J) := AlgEquiv.ofRingEquiv (f := quotQuotEquivComm I J) fun _ => rfl @[simp] theorem quotQuotEquivCommₐ_toRingEquiv : (quotQuotEquivCommₐ R I J : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _ ⧸ I.map (Quotient.mkₐ R J)) = quotQuotEquivComm I J := -- Porting note: should just be `rfl` but `AlgEquiv.toRingEquiv` and `AlgEquiv.ofRingEquiv` -- involve repacking everything in the structure, so Lean ends up unfolding `quotQuotEquivComm` -- and timing out. RingEquiv.ext fun _ => rfl @[simp] theorem coe_quotQuotEquivCommₐ : ⇑(quotQuotEquivCommₐ R I J) = ⇑(quotQuotEquivComm I J) := rfl @[simp] theorem quotQuotEquivComm_symmₐ : (quotQuotEquivCommₐ R I J).symm = quotQuotEquivCommₐ R J I := by -- Porting note: should just be `rfl` but `AlgEquiv.toRingEquiv` and `AlgEquiv.ofRingEquiv` -- involve repacking everything in the structure, so Lean ends up unfolding `quotQuotEquivComm` -- and timing out. ext unfold quotQuotEquivCommₐ congr @[simp] theorem quotQuotEquivComm_comp_quotQuotMkₐ : AlgHom.comp (↑(quotQuotEquivCommₐ R I J)) (quotQuotMkₐ R I J) = quotQuotMkₐ R J I := AlgHom.ext <| quotQuotEquivComm_quotQuotMk I J variable {I J} /-- The **third isomorphism theorem** for algebras. See `quotQuotEquivQuotSupₐ` for version that does not assume an inclusion of ideals. -/ def quotQuotEquivQuotOfLEₐ (h : I ≤ J) : ((A ⧸ I) ⧸ J.map (Quotient.mkₐ R I)) ≃ₐ[R] A ⧸ J := AlgEquiv.ofRingEquiv (f := quotQuotEquivQuotOfLE h) fun _ => rfl @[simp] theorem quotQuotEquivQuotOfLEₐ_toRingEquiv (h : I ≤ J) : (quotQuotEquivQuotOfLEₐ R h : _ ⧸ J.map (Quotient.mkₐ R I) ≃+* _) = quotQuotEquivQuotOfLE h := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotOfLEₐ (h : I ≤ J) : ⇑(quotQuotEquivQuotOfLEₐ R h) = ⇑(quotQuotEquivQuotOfLE h) := rfl @[simp] theorem quotQuotEquivQuotOfLEₐ_symm_toRingEquiv (h : I ≤ J) : ((quotQuotEquivQuotOfLEₐ R h).symm : _ ≃+* _ ⧸ J.map (Quotient.mkₐ R I)) = (quotQuotEquivQuotOfLE h).symm := rfl @[simp] -- Porting note: had to add an extra coercion arrow on the right hand side. theorem coe_quotQuotEquivQuotOfLEₐ_symm (h : I ≤ J) : ⇑(quotQuotEquivQuotOfLEₐ R h).symm = ⇑(quotQuotEquivQuotOfLE h).symm := rfl @[simp] theorem quotQuotEquivQuotOfLE_comp_quotQuotMkₐ (h : I ≤ J) : AlgHom.comp (↑(quotQuotEquivQuotOfLEₐ R h)) (quotQuotMkₐ R I J) = Quotient.mkₐ R J := rfl @[simp] theorem quotQuotEquivQuotOfLE_symm_comp_mkₐ (h : I ≤ J) : AlgHom.comp (↑(quotQuotEquivQuotOfLEₐ R h).symm) (Quotient.mkₐ R J) = quotQuotMkₐ R I J := rfl end AlgebraQuotient end DoubleQuot namespace Ideal section PowQuot variable {R : Type*} [CommRing R] (I : Ideal R) (n : ℕ) /-- `I ^ n ⧸ I ^ (n + 1)` can be viewed as a quotient module and as ideal of `R ⧸ I ^ (n + 1)`. This definition gives the `R`-linear equivalence between the two. -/ noncomputable def powQuotPowSuccLinearEquivMapMkPowSuccPow : ((I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R))) ≃ₗ[R] Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n) := by refine { LinearMap.codRestrict (Submodule.restrictScalars _ (Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n))) (Submodule.mapQ (I • ⊤) (I ^ (n + 1)) (Submodule.subtype (I ^ n)) ?_) ?_, Equiv.ofBijective _ ⟨?_, ?_⟩ with } · intro simp [Submodule.mem_smul_top_iff, pow_succ'] · intro x obtain ⟨⟨y, hy⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ x simp [Ideal.mem_sup_left hy] · intro a b obtain ⟨⟨x, hx⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ a obtain ⟨⟨y, hy⟩, rfl⟩ := Submodule.Quotient.mk_surjective _ b simp [Ideal.Quotient.eq, Submodule.Quotient.eq, Submodule.mem_smul_top_iff, pow_succ'] · intro ⟨x, hx⟩ rw [Ideal.mem_map_iff_of_surjective _ Ideal.Quotient.mk_surjective] at hx obtain ⟨y, hy, rfl⟩ := hx refine ⟨Submodule.Quotient.mk ⟨y, hy⟩, ?_⟩ simp /-- `I ^ n ⧸ I ^ (n + 1)` can be viewed as a quotient module and as ideal of `R ⧸ I ^ (n + 1)`. This definition gives the equivalence between the two, instead of the `R`-linear equivalence, to bypass typeclass synthesis issues on complex `Module` goals. -/ noncomputable def powQuotPowSuccEquivMapMkPowSuccPow : ((I ^ n : Ideal R) ⧸ (I • ⊤ : Submodule R (I ^ n : Ideal R))) ≃ Ideal.map (Ideal.Quotient.mk (I ^ (n + 1))) (I ^ n) := powQuotPowSuccLinearEquivMapMkPowSuccPow I n end PowQuot end Ideal
Riemannian.lean
/- Copyright (c) 2025 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.InnerProductSpace.LinearMap import Mathlib.Topology.VectorBundle.Constructions import Mathlib.Topology.VectorBundle.Hom /-! # Riemannian vector bundles Given a real vector bundle over a topological space whose fibers are all endowed with an inner product, we say that this bundle is Riemannian if the inner product depends continuously on the base point. We introduce a typeclass `[IsContinuousRiemannianBundle F E]` registering this property. Under this assumption, we show that the inner product of two continuous maps into the same fibers of the bundle is a continuous function. If one wants to endow an existing vector bundle with a Riemannian metric, there is a subtlety: the inner product space structure on the fibers should give rise to a topology on the fibers which is defeq to the original one, to avoid diamonds. To do this, we introduce a class `[RiemannianBundle E]` containing the data of an inner product on the fibers defining the same topology as the original one. Given this class, we can construct `NormedAddCommGroup` and `InnerProductSpace` instances on the fibers, compatible in a defeq way with the initial topology. If the data used to register the instance `RiemannianBundle E` depends continuously on the base point, we register automatically an instance of `[IsContinuousRiemannianBundle F E]` (and similarly if the data is smooth). The general theory should be built assuming `[IsContinuousRiemannianBundle F E]`, while the `[RiemannianBundle E]` mechanism is only to build data in specific situations. As instances related to Riemannian bundles are both costly and quite specific, they are scoped to the `Bundle` namespace. ## Keywords Vector bundle, Riemannian metric -/ open Bundle ContinuousLinearMap Filter open scoped Topology variable {B : Type*} [TopologicalSpace B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ x, NormedAddCommGroup (E x)] [∀ x, InnerProductSpace ℝ (E x)] [FiberBundle F E] [VectorBundle ℝ F E] local notation "⟪" x ", " y "⟫" => inner ℝ x y variable (F E) in /-- Consider a real vector bundle in which each fiber is endowed with an inner product. We say that the bundle is *Riemannian* if the inner product depends continuously on the base point. This assumption is spelled `IsContinuousRiemannianBundle F E` where `F` is the model fiber, and `E : B → Type*` is the bundle. -/ class IsContinuousRiemannianBundle : Prop where /-- There exists a bilinear form, depending continuously on the basepoint and defining the inner product in the fibers. This is expressed as an existence statement so that it is Prop-valued in terms of existing data, the inner product on the fibers and the fiber bundle structure. -/ exists_continuous : ∃ g : (Π x, E x →L[ℝ] E x →L[ℝ] ℝ), Continuous (fun (x : B) ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) x (g x)) ∧ ∀ (x : B) (v w : E x), ⟪v, w⟫ = g x v w section Trivial variable {F₁ : Type*} [NormedAddCommGroup F₁] [InnerProductSpace ℝ F₁] /-- A trivial vector bundle, in which the model fiber has a inner product, is a Riemannian bundle. -/ instance : IsContinuousRiemannianBundle F₁ (Bundle.Trivial B F₁) := by refine ⟨fun x ↦ innerSL ℝ, ?_, fun x v w ↦ rfl⟩ rw [continuous_iff_continuousAt] intro x rw [FiberBundle.continuousAt_totalSpace] refine ⟨continuousAt_id, ?_⟩ convert continuousAt_const (y := innerSL ℝ) ext v w simp [hom_trivializationAt_apply, inCoordinates, Trivialization.linearMapAt_apply] end Trivial section Continuous variable {M : Type*} [TopologicalSpace M] [h : IsContinuousRiemannianBundle F E] {b : M → B} {v w : ∀ x, E (b x)} {s : Set M} {x : M} /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousWithinAt`. -/ lemma ContinuousWithinAt.inner_bundle (hv : ContinuousWithinAt (fun m ↦ (v m : TotalSpace F E)) s x) (hw : ContinuousWithinAt (fun m ↦ (w m : TotalSpace F E)) s x) : ContinuousWithinAt (fun m ↦ ⟪v m, w m⟫) s x := by rcases h.exists_continuous with ⟨g, g_cont, hg⟩ have hf : ContinuousWithinAt b s x := by simp only [FiberBundle.continuousWithinAt_totalSpace] at hv exact hv.1 simp only [hg] have : ContinuousWithinAt (fun m ↦ TotalSpace.mk' ℝ (E := Bundle.Trivial B ℝ) (b m) (g (b m) (v m) (w m))) s x := (g_cont.continuousAt.comp_continuousWithinAt hf).clm_bundle_apply₂ (F₁ := F) (F₂ := F) hv hw simp only [FiberBundle.continuousWithinAt_totalSpace] at this exact this.2 /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousAt`. -/ lemma ContinuousAt.inner_bundle (hv : ContinuousAt (fun m ↦ (v m : TotalSpace F E)) x) (hw : ContinuousAt (fun m ↦ (w m : TotalSpace F E)) x) : ContinuousAt (fun b ↦ ⟪v b, w b⟫) x := by simp only [← continuousWithinAt_univ] at hv hw ⊢ exact ContinuousWithinAt.inner_bundle hv hw /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. Version with `ContinuousOn`. -/ lemma ContinuousOn.inner_bundle (hv : ContinuousOn (fun m ↦ (v m : TotalSpace F E)) s) (hw : ContinuousOn (fun m ↦ (w m : TotalSpace F E)) s) : ContinuousOn (fun b ↦ ⟪v b, w b⟫) s := fun x hx ↦ (hv x hx).inner_bundle (hw x hx) /-- Given two continuous maps into the same fibers of a continuous Riemannian bundle, their inner product is continuous. -/ lemma Continuous.inner_bundle (hv : Continuous (fun m ↦ (v m : TotalSpace F E))) (hw : Continuous (fun m ↦ (w m : TotalSpace F E))) : Continuous (fun b ↦ ⟪v b, w b⟫) := by simp only [continuous_iff_continuousAt] at hv hw ⊢ exact fun x ↦ (hv x).inner_bundle (hw x) variable (F E) /-- In a continuous Riemannian bundle, local changes of coordinates given by the trivialization at a point distort the norm by a factor arbitrarily close to 1. -/ lemma eventually_norm_symmL_trivializationAt_self_comp_lt (x : B) {r : ℝ} (hr : 1 < r) : ∀ᶠ y in 𝓝 x, ‖((trivializationAt F E x).symmL ℝ x) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ y)‖ < r := by /- We will expand the definition of continuity of the inner product structure, in the chart. Denote `g' x` the metric in the fiber of `x`, read in the chart. For `y` close to `x`, then `g' y` and `g' x` are close. The inequality we have to prove reduces to comparing `g' y w w` and `g' x w w`, where `w` is the image in the chart of a tangent vector `v` at `y`. Their difference is controlled by `δ ‖w‖ ^ 2` for any small `δ > 0`. To conclude, we argue that `‖w‖` is comparable to the norm inside the fiber over `x`, i.e., `g' x w w`, because there is a continuous linear equivalence between these two spaces by definition of vector bundles. -/ obtain ⟨r', hr', r'r⟩ : ∃ r', 1 < r' ∧ r' < r := exists_between hr have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x let G := (trivializationAt F E x).continuousLinearEquivAt ℝ x h'x let C := (‖(G : E x →L[ℝ] F)‖) ^ 2 -- choose `δ` small enough that the computation below works when the metrics at `x` and `y` -- are `δ` close. When writing this proof, I have followed my nose in the computation, and -- recorded only in the end how small `δ` needs to be. The reader should skip the precise -- condition for now, as it doesn't give any useful insight. obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ (r' ^ 2) ⁻¹ < 1 - δ * C := by have A : ∀ᶠ δ in 𝓝[>] (0 : ℝ), 0 < δ := self_mem_nhdsWithin have B : Tendsto (fun δ ↦ 1 - δ * C) (𝓝[>] 0) (𝓝 (1 - 0 * C)) := by apply tendsto_inf_left exact tendsto_const_nhds.sub (tendsto_id.mul tendsto_const_nhds) have B' : ∀ᶠ δ in 𝓝[>] 0, (r' ^ 2) ⁻¹ < 1 - δ * C := by apply (tendsto_order.1 B).1 simpa using inv_lt_one_of_one_lt₀ (by nlinarith) exact (A.and B').exists rcases h.exists_continuous with ⟨g, g_cont, hg⟩ let g' : B → F →L[ℝ] F →L[ℝ] ℝ := fun y ↦ inCoordinates F E (F →L[ℝ] ℝ) (fun x ↦ E x →L[ℝ] ℝ) x y x y (g y) have hg' : ContinuousAt g' x := by have W := g_cont.continuousAt (x := x) simp only [continuousAt_hom_bundle] at W exact W.2 have : ∀ᶠ y in 𝓝 x, dist (g' y) (g' x) < δ := by rw [Metric.continuousAt_iff'] at hg' apply hg' _ δpos filter_upwards [this, (trivializationAt F E x).open_baseSet.mem_nhds h'x] with y hy h'y have : ‖g' x - g' y‖ ≤ δ := by rw [← dist_eq_norm']; exact hy.le -- To show that the norm of the composition is bounded by `r'`, we start from a vector -- `‖v‖`. We will show that its image has a controlled norm. apply (opNorm_le_bound _ (by linarith) (fun v ↦ ?_)).trans_lt r'r -- rewrite the norm of `‖v‖` and of its image in terms of norms in the model space let w := (trivializationAt F E x).continuousLinearMapAt ℝ y v suffices ‖((trivializationAt F E x).symmL ℝ x) w‖ ^ 2 ≤ r' ^ 2 * ‖v‖ ^ 2 from le_of_sq_le_sq (by simpa [mul_pow]) (by positivity) simp only [Trivialization.symmL_apply, ← real_inner_self_eq_norm_sq, hg] have hgy : g y v v = g' y w w := by rw [inCoordinates_apply_eq₂ h'y h'y (Set.mem_univ _)] have A : ((trivializationAt F E x).symm y) ((trivializationAt F E x).linearMapAt ℝ y v) = v := by convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'y).symm_apply_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'y] rfl simp [A, w] have hgx : g x ((trivializationAt F E x).symm x w) ((trivializationAt F E x).symm x w) = g' x w w := by rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] simp rw [hgx, hgy] -- get a good control for the norms of `w` in the model space, using continuity have : g' x w w ≤ δ * C * g' x w w + g' y w w := calc g' x w w _ = (g' x - g' y) w w + g' y w w := by simp _ ≤ ‖g' x - g' y‖ * ‖w‖ * ‖w‖ + g' y w w := by gcongr; exact (Real.le_norm_self _).trans (le_opNorm₂ (g' x - g' y) w w) _ ≤ δ * ‖w‖ ^ 2 + g' y w w := by rw [pow_two, mul_assoc]; gcongr _ ≤ δ * (‖(G : E x →L[ℝ] F)‖ * ‖G.symm w‖) ^ 2 + g' y w w := by gcongr have : w = G (G.symm w) := by simp conv_lhs => rw [this] exact le_opNorm (G : E x →L[ℝ] F) (G.symm w) _ = δ * C * ‖G.symm w‖^2 + g' y w w := by ring _ = δ * C * g x (G.symm w) (G.symm w) + g' y w w := by simp [← real_inner_self_eq_norm_sq, hg] _ = δ * C * g' x w w + g' y w w := by rw [← hgx]; rfl have : (1 - δ * C) * g' x w w ≤ g' y w w := by linarith rw [← (le_div_iff₀' (lt_of_le_of_lt (by positivity) hδ )), div_eq_inv_mul] at this apply this.trans gcongr · rw [← hgy, ← hg,real_inner_self_eq_norm_sq] positivity · exact inv_le_of_inv_le₀ (by positivity) hδ.le /-- In a continuous Riemannian bundle, the trivialization at a point is locally bounded in norm. -/ lemma eventually_norm_trivializationAt_lt (x : B) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖(trivializationAt F E x).continuousLinearMapAt ℝ y‖ < C := by refine ⟨(1 + ‖(trivializationAt F E x).continuousLinearMapAt ℝ x‖) * 2, by positivity, ?_⟩ filter_upwards [eventually_norm_symmL_trivializationAt_self_comp_lt F E x one_lt_two] with y hy have A : ((trivializationAt F E x).continuousLinearMapAt ℝ x) ∘L ((trivializationAt F E x).symmL ℝ x) = ContinuousLinearMap.id _ _ := by ext v have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x simp only [coe_comp', Trivialization.continuousLinearMapAt_apply, Trivialization.symmL_apply, Function.comp_apply, coe_id', id_eq] convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).apply_symm_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl have : (trivializationAt F E x).continuousLinearMapAt ℝ y = (ContinuousLinearMap.id _ _) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ y) := by simp rw [← A, comp_assoc] at this rw [this] apply (opNorm_comp_le _ _).trans_lt gcongr linarith /-- In a continuous Riemannian bundle, local changes of coordinates given by the trivialization at a point distort the norm by a factor arbitrarily close to 1. -/ lemma eventually_norm_symmL_trivializationAt_comp_self_lt (x : B) {r : ℝ} (hr : 1 < r) : ∀ᶠ y in 𝓝 x, ‖((trivializationAt F E x).symmL ℝ y) ∘L ((trivializationAt F E x).continuousLinearMapAt ℝ x)‖ < r := by /- We will expand the definition of continuity of the inner product structure, in the chart. Denote `g' x` the metric in the fiber of `x`, read in the chart. For `y` close to `x`, then `g' y` and `g' x` are close. The inequality we have to prove reduces to comparing `g' y w w` and `g' x w w`, where `w` is the image in the chart of a tangent vector `v` at `x`. Their difference is controlled by `δ ‖w‖ ^ 2` for any small `δ > 0`. To conclude, we argue that `‖w‖` is comparable to the norm inside the fiber over `x`, i.e., `g' x w w`, because there is a continuous linear equivalence between these two spaces by definition of vector bundles. -/ obtain ⟨r', hr', r'r⟩ : ∃ r', 1 < r' ∧ r' < r := exists_between hr have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x let G := (trivializationAt F E x).continuousLinearEquivAt ℝ x h'x let C := (‖(G : E x →L[ℝ] F)‖) ^ 2 -- choose `δ` small enough that the computation below works when the metrics at `x` and `y` -- are `δ` close. When writing this proof, I have followed my nose in the computation, and -- recorded only in the end how small `δ` needs to be. The reader should skip the precise -- condition for now, as it doesn't give any useful insight. obtain ⟨δ, δpos, h'δ⟩ : ∃ δ, 0 < δ ∧ (1 + δ * C) < r' ^ 2 := by have A : ∀ᶠ δ in 𝓝[>] (0 : ℝ), 0 < δ := self_mem_nhdsWithin have B : Tendsto (fun δ ↦ 1 + δ * C) (𝓝[>] 0) (𝓝 (1 + 0 * C)) := by apply tendsto_inf_left exact tendsto_const_nhds.add (tendsto_id.mul tendsto_const_nhds) have B' : ∀ᶠ δ in 𝓝[>] 0, 1 + δ * C < r' ^ 2 := by apply (tendsto_order.1 B).2 simpa using hr'.trans_le (le_abs_self _) exact (A.and B').exists rcases h.exists_continuous with ⟨g, g_cont, hg⟩ let g' : B → F →L[ℝ] F →L[ℝ] ℝ := fun y ↦ inCoordinates F E (F →L[ℝ] ℝ) (fun x ↦ E x →L[ℝ] ℝ) x y x y (g y) have hg' : ContinuousAt g' x := by have W := g_cont.continuousAt (x := x) simp only [continuousAt_hom_bundle] at W exact W.2 have : ∀ᶠ y in 𝓝 x, dist (g' y) (g' x) < δ := by rw [Metric.continuousAt_iff'] at hg' apply hg' _ δpos filter_upwards [this, (trivializationAt F E x).open_baseSet.mem_nhds h'x] with y hy h'y have : ‖g' y - g' x‖ ≤ δ := by rw [← dist_eq_norm]; exact hy.le -- To show that the norm of the composition is bounded by `r'`, we start from a vector -- `‖v‖`. We will show that its image has a controlled norm. apply (opNorm_le_bound _ (by linarith) (fun v ↦ ?_)).trans_lt r'r -- rewrite the norm of `‖v‖` and of its image in terms of norms in the model space let w := (trivializationAt F E x).continuousLinearMapAt ℝ x v suffices ‖((trivializationAt F E x).symmL ℝ y) w‖ ^ 2 ≤ r' ^ 2 * ‖v‖ ^ 2 from le_of_sq_le_sq (by simpa [mul_pow]) (by positivity) simp only [Trivialization.symmL_apply, ← real_inner_self_eq_norm_sq, hg] have hgx : g x v v = g' x w w := by rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] have A : ((trivializationAt F E x).symm x) ((trivializationAt F E x).linearMapAt ℝ x v) = v := by convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).symm_apply_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl simp [A, w] have hgy : g y ((trivializationAt F E x).symm y w) ((trivializationAt F E x).symm y w) = g' y w w := by rw [inCoordinates_apply_eq₂ h'y h'y (Set.mem_univ _)] simp rw [hgx, hgy] -- get a good control for the norms of `w` in the model space, using continuity calc g' y w w _ = (g' y - g' x) w w + g' x w w := by simp _ ≤ ‖g' y - g' x‖ * ‖w‖ * ‖w‖ + g' x w w := by gcongr; exact (Real.le_norm_self _).trans (le_opNorm₂ (g' y - g' x) w w) _ ≤ δ * ‖w‖ ^ 2 + g' x w w := by rw [pow_two, mul_assoc]; gcongr _ ≤ δ * (‖(G : E x →L[ℝ] F)‖ * ‖G.symm w‖) ^ 2 + g' x w w := by gcongr have : w = G (G.symm w) := by simp conv_lhs => rw [this] exact le_opNorm (G : E x →L[ℝ] F) (G.symm w) _ = δ * C * ‖G.symm w‖^2 + g' x w w := by ring _ = δ * C * g x (G.symm w) (G.symm w) + g' x w w := by simp [← real_inner_self_eq_norm_sq, hg] _ = δ * C * g' x w w + g' x w w := by congr rw [inCoordinates_apply_eq₂ h'x h'x (Set.mem_univ _)] simp only [Trivial.fiberBundle_trivializationAt', Trivial.linearMapAt_trivialization, LinearMap.id_coe, id_eq, w] rfl _ = (1 + δ * C) * g' x w w := by ring _ ≤ r' ^ 2 * g' x w w := by gcongr rw [← hgx, ← hg,real_inner_self_eq_norm_sq] positivity /-- In a continuous Riemannian bundle, the inverse of the trivialization at a point is locally bounded in norm. -/ lemma eventually_norm_symmL_trivializationAt_lt (x : B) : ∃ C > 0, ∀ᶠ y in 𝓝 x, ‖(trivializationAt F E x).symmL ℝ y‖ < C := by refine ⟨2 * (1 + ‖(trivializationAt F E x).symmL ℝ x‖), by positivity, ?_⟩ filter_upwards [eventually_norm_symmL_trivializationAt_comp_self_lt F E x one_lt_two] with y hy have A : ((trivializationAt F E x).continuousLinearMapAt ℝ x) ∘L ((trivializationAt F E x).symmL ℝ x) = ContinuousLinearMap.id _ _ := by ext v have h'x : x ∈ (trivializationAt F E x).baseSet := FiberBundle.mem_baseSet_trivializationAt' x simp only [coe_comp', Trivialization.continuousLinearMapAt_apply, Trivialization.symmL_apply, Function.comp_apply, coe_id', id_eq] convert ((trivializationAt F E x).continuousLinearEquivAt ℝ _ h'x).apply_symm_apply v rw [Trivialization.coe_continuousLinearEquivAt_eq _ h'x] rfl have : (trivializationAt F E x).symmL ℝ y = ((trivializationAt F E x).symmL ℝ y) ∘L (ContinuousLinearMap.id _ _) := by simp rw [← A, ← comp_assoc] at this rw [this] apply (opNorm_comp_le _ _).trans_lt gcongr linarith end Continuous namespace Bundle section Construction variable {B : Type*} [TopologicalSpace B] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {E : B → Type*} [TopologicalSpace (TotalSpace F E)] [∀ b, TopologicalSpace (E b)] [∀ b, AddCommGroup (E b)] [∀ b, Module ℝ (E b)] [∀ b, IsTopologicalAddGroup (E b)] [∀ b, ContinuousConstSMul ℝ (E b)] [FiberBundle F E] [VectorBundle ℝ F E] open Bornology variable (E) in /-- A family of inner product space structures on the fibers of a fiber bundle, defining the same topology as the already existing one. This family is not assumed to be continuous or smooth: to guarantee continuity, resp. smoothness, of the inner product as a function of the base point, use `ContinuousRiemannianMetric` or `ContMDiffRiemannianMetric`. This structure is used through `RiemannianBundle` for typeclass inference, to register the inner product space structure on the fibers without creating diamonds. -/ structure RiemannianMetric where /-- The inner product along the fibers of the bundle. -/ inner (b : B) : E b →L[ℝ] E b →L[ℝ] ℝ symm (b : B) (v w : E b) : inner b v w = inner b w v pos (b : B) (v : E b) (hv : v ≠ 0) : 0 < inner b v v /-- The continuity at `0` is automatic when `E b` is isomorphic to a normed space, but since we are not making this assumption here we have to include it. -/ continuousAt (b : B) : ContinuousAt (fun (v : E b) ↦ inner b v v) 0 isVonNBounded (b : B) : IsVonNBounded ℝ {v : E b | inner b v v < 1} /-- `Core structure associated to a family of inner products on the fibers of a fiber bundle. This is an auxiliary construction to endow the fibers with an inner product space structure without creating diamonds. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ @[reducible] noncomputable def RiemannianMetric.toCore (g : RiemannianMetric E) (b : B) : InnerProductSpace.Core ℝ (E b) where inner v w := g.inner b v w conj_inner_symm v w := g.symm b w v re_inner_nonneg v := by rcases eq_or_ne v 0 with rfl | hv · simp · simpa using (g.pos b v hv).le add_left v w x := by simp smul_left c v := by simp definite v h := by contrapose! h; exact (g.pos b v h).ne' variable (E) in /-- Class used to create an inner product structure space on the fibers of a fiber bundle, without creating diamonds. Use as follows: * `instance : RiemannianBundle E := ⟨g⟩` where `g : RiemannianMetric E` registers the inner product space on the fibers; * `instance : RiemannianBundle E := ⟨g.toRiemannianMetric⟩` where `g : ContinuousRiemannianMetric F E` registers the inner product space on the fibers, and the fact that it varies continuously (i.e., a `[IsContinuousRiemannianBundle]` instance). * `instance : RiemannianBundle E := ⟨g.toRiemannianMetric⟩` where `g : ContMDiffRiemannianMetric IB n F E` registers the inner product space on the fibers, and the fact that it varies smoothly (and continuously), i.e., `[IsContMDiffRiemannianBundle]` and `[IsContinuousRiemannianBundle]` instances. -/ class RiemannianBundle where /-- The family of inner products on the fibers -/ g : RiemannianMetric E /-- A fiber in a bundle satisfying the `[RiemannianBundle E]` typeclass inherits a `NormedAddCommGroup` structure. The normal priority for an instance which always applies like this one should be 100. We use 80 as this is rather specialized, so we want other paths to be tried first typically. As this instance is quite specific and very costly because of higher order unification, we also scope it to the `Bundle` namespace. -/ noncomputable scoped instance (priority := 80) [h : RiemannianBundle E] (b : B) : NormedAddCommGroup (E b) := (h.g.toCore b).toNormedAddCommGroupOfTopology (h.g.continuousAt b) (h.g.isVonNBounded b) /-- A fiber in a bundle satisfying the `[RiemannianBundle E]` typeclass inherits an `InnerProductSpace ℝ` structure. The normal priority for an instance which always applies like this one should be 100. We use 80 as this is rather specialized, so we want other paths to be tried first typically. As this instance is quite specific and very costly because of higher order unification, we also scope it to the `Bundle` namespace. -/ noncomputable scoped instance (priority := 80) [h : RiemannianBundle E] (b : B) : InnerProductSpace ℝ (E b) := .ofCoreOfTopology (h.g.toCore b) (h.g.continuousAt b) (h.g.isVonNBounded b) variable (F E) in /-- A family of inner product space structures on the fibers of a fiber bundle, defining the same topology as the already existing one, and varying continuously with the base point. See also `ContMDiffRiemannianMetric` for a smooth version. This structure is used through `RiemannianBundle` for typeclass inference, to register the inner product space structure on the fibers without creating diamonds. -/ structure ContinuousRiemannianMetric where /-- The inner product along the fibers of the bundle. -/ inner (b : B) : E b →L[ℝ] E b →L[ℝ] ℝ symm (b : B) (v w : E b) : inner b v w = inner b w v pos (b : B) (v : E b) (hv : v ≠ 0) : 0 < inner b v v isVonNBounded (b : B) : IsVonNBounded ℝ {v : E b | inner b v v < 1} continuous : Continuous (fun (b : B) ↦ TotalSpace.mk' (F →L[ℝ] F →L[ℝ] ℝ) b (inner b)) /-- A continuous Riemannian metric is in particular a Riemannian metric. -/ def ContinuousRiemannianMetric.toRiemannianMetric (g : ContinuousRiemannianMetric F E) : RiemannianMetric E where inner := g.inner symm := g.symm pos := g.pos isVonNBounded := g.isVonNBounded continuousAt b := by -- Continuity of bilinear maps is only true on normed spaces. As `F` is a normed space by -- assumption, we transfer everything to `F` and argue there. let e : E b ≃L[ℝ] F := Trivialization.continuousLinearEquivAt ℝ (trivializationAt F E b) _ (FiberBundle.mem_baseSet_trivializationAt' b) let m : (E b →L[ℝ] E b →L[ℝ] ℝ) ≃L[ℝ] (F →L[ℝ] F →L[ℝ] ℝ) := e.arrowCongr (e.arrowCongr (ContinuousLinearEquiv.refl ℝ ℝ )) have A (v : E b) : g.inner b v v = ((fun w ↦ m (g.inner b) w w) ∘ e) v := by simp [m] simp only [A] fun_prop /-- If a Riemannian bundle structure is defined using `g.toRiemannianMetric` where `g` is a `ContinuousRiemannianMetric`, then we make sure typeclass inference can infer automatically that the the bundle is a continuous Riemannian bundle. -/ instance (g : ContinuousRiemannianMetric F E) : letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩; IsContinuousRiemannianBundle F E := by letI : RiemannianBundle E := ⟨g.toRiemannianMetric⟩ exact ⟨⟨g.inner, g.continuous, fun b v w ↦ rfl⟩⟩ end Construction end Bundle
External.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.Data.Int.Order.Units import Mathlib.Data.ZMod.IntUnitsPower import Mathlib.RingTheory.TensorProduct.Basic import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.Algebra.DirectSum.Algebra /-! # 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 `ZMod 2` (or more generally, any index that satisfies `Module ι (Additive ℤˣ)`). The results for internally-graded algebras (via `GradedAlgebra`) are elsewhere, as is the type `GradedTensorProduct`. ## Main results * `TensorProduct.gradedComm`: the symmetric braiding operator on the tensor product of externally-graded rings. * `TensorProduct.gradedMul`: the previously-described multiplication on externally-graded rings, as a bilinear map. ## Implementation notes Rather than implementing the multiplication directly as above, we first implement the canonical non-trivial braiding sending $a \otimes b$ to $(-1)^{\deg a' \deg b} (b \otimes a)$, as the multiplication follows trivially from this after some point-free nonsense. ## References * https://math.stackexchange.com/q/202718/1896 * [*Algebra I*, Bourbaki : Chapter III, §4.7, example (2)][bourbaki1989] -/ open scoped TensorProduct DirectSum variable {R ι : Type*} namespace TensorProduct variable [CommSemiring ι] [Module ι (Additive ℤˣ)] [DecidableEq ι] variable (𝒜 : ι → Type*) (ℬ : ι → Type*) variable [CommRing R] variable [∀ i, AddCommGroup (𝒜 i)] [∀ i, AddCommGroup (ℬ i)] variable [∀ i, Module R (𝒜 i)] [∀ i, Module R (ℬ i)] -- this helps with performance instance (i : ι × ι) : Module R (𝒜 (Prod.fst i) ⊗[R] ℬ (Prod.snd i)) := TensorProduct.leftModule open DirectSum (lof) variable (R) section gradedComm local notation "𝒜ℬ" => (fun i : ι × ι => 𝒜 (Prod.fst i) ⊗[R] ℬ (Prod.snd i)) local notation "ℬ𝒜" => (fun i : ι × ι => ℬ (Prod.fst i) ⊗[R] 𝒜 (Prod.snd i)) /-- Auxliary construction used to build `TensorProduct.gradedComm`. This operates on direct sums of tensors instead of tensors of direct sums. -/ def gradedCommAux : DirectSum _ 𝒜ℬ →ₗ[R] DirectSum _ ℬ𝒜 := by refine DirectSum.toModule R _ _ fun i => ?_ have o := DirectSum.lof R _ ℬ𝒜 i.swap have s : ℤˣ := ((-1 : ℤˣ)^(i.1* i.2 : ι) : ℤˣ) exact (s • o) ∘ₗ (TensorProduct.comm R _ _).toLinearMap @[simp] theorem gradedCommAux_lof_tmul (i j : ι) (a : 𝒜 i) (b : ℬ j) : gradedCommAux R 𝒜 ℬ (lof R _ 𝒜ℬ (i, j) (a ⊗ₜ b)) = (-1 : ℤˣ)^(j * i) • lof R _ ℬ𝒜 (j, i) (b ⊗ₜ a) := by rw [gradedCommAux] simp [mul_comm i j] @[simp] theorem gradedCommAux_comp_gradedCommAux : gradedCommAux R 𝒜 ℬ ∘ₗ gradedCommAux R ℬ 𝒜 = LinearMap.id := by ext i a b dsimp rw [gradedCommAux_lof_tmul, LinearMap.map_smul_of_tower, gradedCommAux_lof_tmul, smul_smul, mul_comm i.2 i.1, Int.units_mul_self, one_smul] /-- The braiding operation for tensor products of externally `ι`-graded algebras. This sends $a ⊗ b$ to $(-1)^{\deg a' \deg b} (b ⊗ a)$. -/ def gradedComm : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i) ≃ₗ[R] (⨁ i, ℬ i) ⊗[R] (⨁ i, 𝒜 i) := by refine TensorProduct.directSum R R 𝒜 ℬ ≪≫ₗ ?_ ≪≫ₗ (TensorProduct.directSum R R ℬ 𝒜).symm exact LinearEquiv.ofLinear (gradedCommAux _ _ _) (gradedCommAux _ _ _) (gradedCommAux_comp_gradedCommAux _ _ _) (gradedCommAux_comp_gradedCommAux _ _ _) /-- The braiding is symmetric. -/ @[simp] theorem gradedComm_symm : (gradedComm R 𝒜 ℬ).symm = gradedComm R ℬ 𝒜 := by rw [gradedComm, gradedComm, LinearEquiv.trans_symm, LinearEquiv.symm_symm] ext rfl theorem gradedComm_of_tmul_of (i j : ι) (a : 𝒜 i) (b : ℬ j) : gradedComm R 𝒜 ℬ (lof R _ 𝒜 i a ⊗ₜ lof R _ ℬ j b) = (-1 : ℤˣ)^(j * i) • (lof R _ ℬ _ b ⊗ₜ lof R _ 𝒜 _ a) := by rw [gradedComm] dsimp only [LinearEquiv.trans_apply, LinearEquiv.ofLinear_apply] rw [TensorProduct.directSum_lof_tmul_lof, gradedCommAux_lof_tmul, Units.smul_def, -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 specialized `map_smul` to `LinearEquiv.map_smul` to avoid timeouts. ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, TensorProduct.directSum_symm_lof_tmul, Int.cast_smul_eq_zsmul, ← Units.smul_def] theorem gradedComm_tmul_of_zero (a : ⨁ i, 𝒜 i) (b : ℬ 0) : gradedComm R 𝒜 ℬ (a ⊗ₜ lof R _ ℬ 0 b) = lof R _ ℬ _ b ⊗ₜ a := by suffices (gradedComm R 𝒜 ℬ).toLinearMap ∘ₗ (TensorProduct.mk R (⨁ i, 𝒜 i) (⨁ i, ℬ i)).flip (lof R _ ℬ 0 b) = TensorProduct.mk R _ _ (lof R _ ℬ 0 b) from DFunLike.congr_fun this a ext i a dsimp rw [gradedComm_of_tmul_of, zero_mul, uzpow_zero, one_smul] theorem gradedComm_of_zero_tmul (a : 𝒜 0) (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (lof R _ 𝒜 0 a ⊗ₜ b) = b ⊗ₜ lof R _ 𝒜 _ a := by suffices (gradedComm R 𝒜 ℬ).toLinearMap ∘ₗ (TensorProduct.mk R (⨁ i, 𝒜 i) (⨁ i, ℬ i)) (lof R _ 𝒜 0 a) = (TensorProduct.mk R _ _).flip (lof R _ 𝒜 0 a) from DFunLike.congr_fun this b ext i b dsimp rw [gradedComm_of_tmul_of, mul_zero, uzpow_zero, one_smul] theorem gradedComm_tmul_one [GradedMonoid.GOne ℬ] (a : ⨁ i, 𝒜 i) : gradedComm R 𝒜 ℬ (a ⊗ₜ 1) = 1 ⊗ₜ a := gradedComm_tmul_of_zero _ _ _ _ _ theorem gradedComm_one_tmul [GradedMonoid.GOne 𝒜] (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (1 ⊗ₜ b) = b ⊗ₜ 1 := gradedComm_of_zero_tmul _ _ _ _ _ @[simp] theorem gradedComm_one [DirectSum.GSemiring 𝒜] [DirectSum.GSemiring ℬ] : gradedComm R 𝒜 ℬ 1 = 1 := gradedComm_one_tmul _ _ _ _ theorem gradedComm_tmul_algebraMap [DirectSum.GSemiring ℬ] [DirectSum.GAlgebra R ℬ] (a : ⨁ i, 𝒜 i) (r : R) : gradedComm R 𝒜 ℬ (a ⊗ₜ algebraMap R _ r) = algebraMap R _ r ⊗ₜ a := gradedComm_tmul_of_zero _ _ _ _ _ theorem gradedComm_algebraMap_tmul [DirectSum.GSemiring 𝒜] [DirectSum.GAlgebra R 𝒜] (r : R) (b : ⨁ i, ℬ i) : gradedComm R 𝒜 ℬ (algebraMap R _ r ⊗ₜ b) = b ⊗ₜ algebraMap R _ r := gradedComm_of_zero_tmul _ _ _ _ _ theorem gradedComm_algebraMap [DirectSum.GSemiring 𝒜] [DirectSum.GSemiring ℬ] [DirectSum.GAlgebra R 𝒜] [DirectSum.GAlgebra R ℬ] (r : R) : gradedComm R 𝒜 ℬ (algebraMap R _ r) = algebraMap R _ r := (gradedComm_algebraMap_tmul R 𝒜 ℬ r 1).trans (Algebra.TensorProduct.algebraMap_apply' r).symm end gradedComm variable [DirectSum.GRing 𝒜] [DirectSum.GRing ℬ] variable [DirectSum.GAlgebra R 𝒜] [DirectSum.GAlgebra R ℬ] open TensorProduct (assoc map) in /-- The multiplication operation for tensor products of externally `ι`-graded algebras. -/ noncomputable irreducible_def gradedMul : letI AB := DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ letI : Module R AB := TensorProduct.leftModule AB →ₗ[R] AB →ₗ[R] AB := by refine TensorProduct.curry ?_ refine map (LinearMap.mul' R (⨁ i, 𝒜 i)) (LinearMap.mul' R (⨁ i, ℬ i)) ∘ₗ ?_ refine (assoc R _ _ _).symm.toLinearMap ∘ₗ .lTensor _ ?_ ∘ₗ (assoc R _ _ _).toLinearMap refine (assoc R _ _ _).toLinearMap ∘ₗ .rTensor _ ?_ ∘ₗ (assoc R _ _ _).symm.toLinearMap exact (gradedComm _ _ _).toLinearMap theorem tmul_of_gradedMul_of_tmul (j₁ i₂ : ι) (a₁ : ⨁ i, 𝒜 i) (b₁ : ℬ j₁) (a₂ : 𝒜 i₂) (b₂ : ⨁ i, ℬ i) : gradedMul R 𝒜 ℬ (a₁ ⊗ₜ lof R _ ℬ j₁ b₁) (lof R _ 𝒜 i₂ a₂ ⊗ₜ b₂) = (-1 : ℤˣ)^(j₁ * i₂) • ((a₁ * lof R _ 𝒜 _ a₂) ⊗ₜ (lof R _ ℬ _ b₁ * b₂)) := by rw [gradedMul] dsimp only [curry_apply, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, assoc_tmul, map_tmul, LinearMap.id_coe, id_eq, assoc_symm_tmul, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul] rw [mul_comm j₁ i₂, gradedComm_of_tmul_of] -- the tower smul lemmas elaborate too slowly rw [Units.smul_def, Units.smul_def, ← Int.cast_smul_eq_zsmul R, ← Int.cast_smul_eq_zsmul R] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to avoid timeouts. rw [← smul_tmul', LinearEquiv.map_smul, tmul_smul, LinearEquiv.map_smul, LinearMap.map_smul] dsimp variable {R} theorem algebraMap_gradedMul (r : R) (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ (algebraMap R _ r ⊗ₜ 1) x = r • x := by suffices gradedMul R 𝒜 ℬ (algebraMap R _ r ⊗ₜ 1) = DistribMulAction.toLinearMap R _ r by exact DFunLike.congr_fun this x ext ia a ib b dsimp erw [tmul_of_gradedMul_of_tmul] rw [zero_mul, uzpow_zero, one_smul, smul_tmul'] erw [one_mul, _root_.Algebra.smul_def] theorem one_gradedMul (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ 1 x = x := by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_one` to avoid timeouts. simpa only [RingHom.map_one, one_smul] using algebraMap_gradedMul 𝒜 ℬ 1 x theorem gradedMul_algebraMap (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) (r : R) : gradedMul R 𝒜 ℬ x (algebraMap R _ r ⊗ₜ 1) = r • x := by suffices (gradedMul R 𝒜 ℬ).flip (algebraMap R _ r ⊗ₜ 1) = DistribMulAction.toLinearMap R _ r by exact DFunLike.congr_fun this x ext dsimp erw [tmul_of_gradedMul_of_tmul] rw [mul_zero, uzpow_zero, one_smul, smul_tmul', mul_one, _root_.Algebra.smul_def, Algebra.commutes] rfl theorem gradedMul_one (x : (⨁ i, 𝒜 i) ⊗[R] (⨁ i, ℬ i)) : gradedMul R 𝒜 ℬ x 1 = x := by -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_one` to avoid timeouts. simpa only [RingHom.map_one, one_smul] using gradedMul_algebraMap 𝒜 ℬ x 1 theorem gradedMul_assoc (x y z : DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ) : gradedMul R 𝒜 ℬ (gradedMul R 𝒜 ℬ x y) z = gradedMul R 𝒜 ℬ x (gradedMul R 𝒜 ℬ y z) := by let mA := gradedMul R 𝒜 ℬ -- restate as an equality of morphisms so that we can use `ext` suffices LinearMap.llcomp R _ _ _ mA ∘ₗ mA = (LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <| LinearMap.llcomp R _ _ _ mA.flip ∘ₗ mA).flip by exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z ext ixa xa ixb xb iya ya iyb yb iza za izb zb dsimp [mA] simp_rw [tmul_of_gradedMul_of_tmul, Units.smul_def, ← Int.cast_smul_eq_zsmul R, LinearMap.map_smul₂, LinearMap.map_smul, DirectSum.lof_eq_of, DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, tmul_of_gradedMul_of_tmul, DirectSum.lof_eq_of, ← DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, mul_assoc] simp_rw [Int.cast_smul_eq_zsmul R, ← Units.smul_def, smul_smul, ← uzpow_add, add_mul, mul_add] congr 2 abel theorem gradedComm_gradedMul (x y : DirectSum _ 𝒜 ⊗[R] DirectSum _ ℬ) : gradedComm R 𝒜 ℬ (gradedMul R 𝒜 ℬ x y) = gradedMul R ℬ 𝒜 (gradedComm R 𝒜 ℬ x) (gradedComm R 𝒜 ℬ y) := by suffices (gradedMul R 𝒜 ℬ).compr₂ (gradedComm R 𝒜 ℬ).toLinearMap = (gradedMul R ℬ 𝒜 ∘ₗ (gradedComm R 𝒜 ℬ).toLinearMap).compl₂ (gradedComm R 𝒜 ℬ).toLinearMap from LinearMap.congr_fun₂ this x y ext i₁ a₁ j₁ b₁ i₂ a₂ j₂ b₂ dsimp rw [gradedComm_of_tmul_of, gradedComm_of_tmul_of, tmul_of_gradedMul_of_tmul] -- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specialize `map_smul` to avoid timeouts. simp_rw [Units.smul_def, ← Int.cast_smul_eq_zsmul R, LinearEquiv.map_smul, LinearMap.map_smul, LinearMap.smul_apply] simp_rw [Int.cast_smul_eq_zsmul R, ← Units.smul_def, DirectSum.lof_eq_of, DirectSum.of_mul_of, ← DirectSum.lof_eq_of R, gradedComm_of_tmul_of, tmul_of_gradedMul_of_tmul, smul_smul, DirectSum.lof_eq_of, ← DirectSum.of_mul_of, ← DirectSum.lof_eq_of R] simp_rw [← uzpow_add, mul_add, add_mul, mul_comm i₁ j₂] congr 1 abel_nf rw [two_nsmul, uzpow_add, uzpow_add, Int.units_mul_self, one_mul] end TensorProduct
UpperLower.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.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Pointwise.Set.Lattice import Mathlib.Algebra.Order.Group.Defs import Mathlib.Algebra.Order.Group.OrderIso import Mathlib.Algebra.Order.Monoid.OrderDual import Mathlib.Order.UpperLower.Closure /-! # Algebraic operations on upper/lower sets Upper/lower sets are preserved under pointwise algebraic operations in ordered groups. -/ open Function Set open Pointwise section OrderedCommMonoid variable {α : Type*} [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] {s : Set α} {x : α} @[to_additive] theorem IsUpperSet.smul_subset (hs : IsUpperSet s) (hx : 1 ≤ x) : x • s ⊆ s := smul_set_subset_iff.2 fun _ ↦ hs <| le_mul_of_one_le_left' hx @[to_additive] theorem IsLowerSet.smul_subset (hs : IsLowerSet s) (hx : x ≤ 1) : x • s ⊆ s := smul_set_subset_iff.2 fun _ ↦ hs <| mul_le_of_le_one_left' hx end OrderedCommMonoid section OrderedCommGroup variable {α : Type*} [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : Set α} {a : α} @[to_additive] theorem IsUpperSet.smul (hs : IsUpperSet s) : IsUpperSet (a • s) := hs.image <| OrderIso.mulLeft _ @[to_additive] theorem IsLowerSet.smul (hs : IsLowerSet s) : IsLowerSet (a • s) := hs.image <| OrderIso.mulLeft _ @[to_additive] theorem Set.OrdConnected.smul (hs : s.OrdConnected) : (a • s).OrdConnected := by rw [← hs.upperClosure_inter_lowerClosure, smul_set_inter] exact (upperClosure _).upper.smul.ordConnected.inter (lowerClosure _).lower.smul.ordConnected @[to_additive] theorem IsUpperSet.mul_left (ht : IsUpperSet t) : IsUpperSet (s * t) := by rw [← smul_eq_mul, ← Set.iUnion_smul_set] exact isUpperSet_iUnion₂ fun x _ ↦ ht.smul @[to_additive] theorem IsUpperSet.mul_right (hs : IsUpperSet s) : IsUpperSet (s * t) := by rw [mul_comm] exact hs.mul_left @[to_additive] theorem IsLowerSet.mul_left (ht : IsLowerSet t) : IsLowerSet (s * t) := ht.toDual.mul_left @[to_additive] theorem IsLowerSet.mul_right (hs : IsLowerSet s) : IsLowerSet (s * t) := hs.toDual.mul_right @[to_additive] theorem IsUpperSet.inv (hs : IsUpperSet s) : IsLowerSet s⁻¹ := fun _ _ h ↦ hs <| inv_le_inv' h @[to_additive] theorem IsLowerSet.inv (hs : IsLowerSet s) : IsUpperSet s⁻¹ := fun _ _ h ↦ hs <| inv_le_inv' h @[to_additive] theorem IsUpperSet.div_left (ht : IsUpperSet t) : IsLowerSet (s / t) := by rw [div_eq_mul_inv] exact ht.inv.mul_left @[to_additive] theorem IsUpperSet.div_right (hs : IsUpperSet s) : IsUpperSet (s / t) := by rw [div_eq_mul_inv] exact hs.mul_right @[to_additive] theorem IsLowerSet.div_left (ht : IsLowerSet t) : IsUpperSet (s / t) := ht.toDual.div_left @[to_additive] theorem IsLowerSet.div_right (hs : IsLowerSet s) : IsLowerSet (s / t) := hs.toDual.div_right namespace UpperSet @[to_additive] instance : One (UpperSet α) := ⟨Ici 1⟩ @[to_additive] instance : Mul (UpperSet α) := ⟨fun s t ↦ ⟨image2 (· * ·) s t, s.2.mul_right⟩⟩ @[to_additive] instance : Div (UpperSet α) := ⟨fun s t ↦ ⟨image2 (· / ·) s t, s.2.div_right⟩⟩ @[to_additive] instance : SMul α (UpperSet α) := ⟨fun a s ↦ ⟨(a • ·) '' s, s.2.smul⟩⟩ omit [IsOrderedMonoid α] in @[to_additive (attr := simp, norm_cast)] theorem coe_one : ((1 : UpperSet α) : Set α) = Set.Ici 1 := rfl @[to_additive (attr := simp, norm_cast)] theorem coe_mul (s t : UpperSet α) : (↑(s * t) : Set α) = s * t := rfl @[to_additive (attr := simp, norm_cast)] theorem coe_div (s t : UpperSet α) : (↑(s / t) : Set α) = s / t := rfl omit [IsOrderedMonoid α] in @[to_additive (attr := simp)] theorem Ici_one : Ici (1 : α) = 1 := rfl @[to_additive] instance : MulAction α (UpperSet α) := SetLike.coe_injective.mulAction _ (fun _ _ => rfl) @[to_additive] instance commSemigroup : CommSemigroup (UpperSet α) := { (SetLike.coe_injective.commSemigroup _ coe_mul : CommSemigroup (UpperSet α)) with } @[to_additive] private theorem one_mul (s : UpperSet α) : 1 * s = s := SetLike.coe_injective <| (subset_mul_right _ left_mem_Ici).antisymm' <| by rw [← smul_eq_mul, ← Set.iUnion_smul_set] exact Set.iUnion₂_subset fun _ ↦ s.upper.smul_subset @[to_additive] instance : CommMonoid (UpperSet α) := { UpperSet.commSemigroup with one := 1 one_mul := one_mul mul_one := fun s ↦ by rw [mul_comm] exact one_mul _ } end UpperSet namespace LowerSet @[to_additive] instance : One (LowerSet α) := ⟨Iic 1⟩ @[to_additive] instance : Mul (LowerSet α) := ⟨fun s t ↦ ⟨image2 (· * ·) s t, s.2.mul_right⟩⟩ @[to_additive] instance : Div (LowerSet α) := ⟨fun s t ↦ ⟨image2 (· / ·) s t, s.2.div_right⟩⟩ @[to_additive] instance : SMul α (LowerSet α) := ⟨fun a s ↦ ⟨(a • ·) '' s, s.2.smul⟩⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_mul (s t : LowerSet α) : (↑(s * t) : Set α) = s * t := rfl @[to_additive (attr := simp, norm_cast)] theorem coe_div (s t : LowerSet α) : (↑(s / t) : Set α) = s / t := rfl omit [IsOrderedMonoid α] in @[to_additive (attr := simp)] theorem Iic_one : Iic (1 : α) = 1 := rfl @[to_additive] instance : MulAction α (LowerSet α) := SetLike.coe_injective.mulAction _ (fun _ _ => rfl) @[to_additive] instance commSemigroup : CommSemigroup (LowerSet α) := { (SetLike.coe_injective.commSemigroup _ coe_mul : CommSemigroup (LowerSet α)) with } @[to_additive] private theorem one_mul (s : LowerSet α) : 1 * s = s := SetLike.coe_injective <| (subset_mul_right _ right_mem_Iic).antisymm' <| by rw [← smul_eq_mul, ← Set.iUnion_smul_set] exact Set.iUnion₂_subset fun _ ↦ s.lower.smul_subset @[to_additive] instance : CommMonoid (LowerSet α) := { LowerSet.commSemigroup with one := 1 one_mul := one_mul mul_one := fun s ↦ by rw [mul_comm] exact one_mul _ } end LowerSet variable (a s t) omit [IsOrderedMonoid α] in @[to_additive (attr := simp)] theorem upperClosure_one : upperClosure (1 : Set α) = 1 := upperClosure_singleton _ omit [IsOrderedMonoid α] in @[to_additive (attr := simp)] theorem lowerClosure_one : lowerClosure (1 : Set α) = 1 := lowerClosure_singleton _ @[to_additive (attr := simp)] theorem upperClosure_smul : upperClosure (a • s) = a • upperClosure s := upperClosure_image <| OrderIso.mulLeft a @[to_additive (attr := simp)] theorem lowerClosure_smul : lowerClosure (a • s) = a • lowerClosure s := lowerClosure_image <| OrderIso.mulLeft a @[to_additive] theorem mul_upperClosure : s * upperClosure t = upperClosure (s * t) := by simp_rw [← smul_eq_mul, ← Set.iUnion_smul_set, upperClosure_iUnion, upperClosure_smul, UpperSet.coe_iInf₂] rfl @[to_additive] theorem mul_lowerClosure : s * lowerClosure t = lowerClosure (s * t) := by simp_rw [← smul_eq_mul, ← Set.iUnion_smul_set, lowerClosure_iUnion, lowerClosure_smul, LowerSet.coe_iSup₂] rfl @[to_additive] theorem upperClosure_mul : ↑(upperClosure s) * t = upperClosure (s * t) := by simp_rw [mul_comm _ t] exact mul_upperClosure _ _ @[to_additive] theorem lowerClosure_mul : ↑(lowerClosure s) * t = lowerClosure (s * t) := by simp_rw [mul_comm _ t] exact mul_lowerClosure _ _ @[to_additive (attr := simp)] theorem upperClosure_mul_distrib : upperClosure (s * t) = upperClosure s * upperClosure t := SetLike.coe_injective <| by rw [UpperSet.coe_mul, mul_upperClosure, upperClosure_mul, UpperSet.upperClosure] @[to_additive (attr := simp)] theorem lowerClosure_mul_distrib : lowerClosure (s * t) = lowerClosure s * lowerClosure t := SetLike.coe_injective <| by rw [LowerSet.coe_mul, mul_lowerClosure, lowerClosure_mul, LowerSet.lowerClosure] end OrderedCommGroup
FiniteDimensional.lean
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.Multilinear.Curry import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix /-! # Multilinear maps over finite dimensional spaces The main results are that multilinear maps over finitely-generated, free modules are finitely-generated and free. * `Module.Finite.multilinearMap` * `Module.Free.multilinearMap` We do not put this in `LinearAlgebra.Multilinear.Basic` to avoid making the imports too large there. -/ namespace MultilinearMap variable {ι R M₂ : Type*} {M₁ : ι → Type*} variable [Finite ι] variable [CommRing R] [AddCommGroup M₂] [Module R M₂] variable [Module.Finite R M₂] [Module.Free R M₂] private theorem free_and_finite_fin (n : ℕ) (N : Fin n → Type*) [∀ i, AddCommGroup (N i)] [∀ i, Module R (N i)] [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)] : Module.Free R (MultilinearMap R N M₂) ∧ Module.Finite R (MultilinearMap R N M₂) := by induction n with | zero => haveI : IsEmpty (Fin Nat.zero) := inferInstanceAs (IsEmpty (Fin 0)) exact ⟨Module.Free.of_equiv (constLinearEquivOfIsEmpty R R N M₂), Module.Finite.equiv (constLinearEquivOfIsEmpty R R N M₂)⟩ | succ n ih => suffices Module.Free R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) ∧ Module.Finite R (N 0 →ₗ[R] MultilinearMap R (fun i : Fin n => N i.succ) M₂) by cases this exact ⟨Module.Free.of_equiv (multilinearCurryLeftEquiv R N M₂).symm, Module.Finite.equiv (multilinearCurryLeftEquiv R N M₂).symm⟩ cases ih fun i => N i.succ exact ⟨Module.Free.linearMap _ _ _ _, Module.Finite.linearMap _ _ _ _⟩ variable [∀ i, AddCommGroup (M₁ i)] [∀ i, Module R (M₁ i)] variable [∀ i, Module.Finite R (M₁ i)] [∀ i, Module.Free R (M₁ i)] -- the induction requires us to show both at once private theorem free_and_finite : Module.Free R (MultilinearMap R M₁ M₂) ∧ Module.Finite R (MultilinearMap R M₁ M₂) := by cases nonempty_fintype ι have := @free_and_finite_fin R M₂ _ _ _ _ _ (Fintype.card ι) (fun x => M₁ ((Fintype.equivFin ι).symm x)) obtain ⟨l, r⟩ := this have e := domDomCongrLinearEquiv' R R M₁ M₂ (Fintype.equivFin ι) exact ⟨Module.Free.of_equiv e.symm, Module.Finite.equiv e.symm⟩ instance _root_.Module.Finite.multilinearMap : Module.Finite R (MultilinearMap R M₁ M₂) := free_and_finite.2 instance _root_.Module.Free.multilinearMap : Module.Free R (MultilinearMap R M₁ M₂) := free_and_finite.1 end MultilinearMap
MinimalAxioms.lean
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.MinimalAxioms /-! # Minimal Axioms for a Field This file defines constructors to define a `Field` structure on a Type, while proving a minimum number of equalities. ## Main Definitions * `Field.ofMinimalAxioms`: Define a `Field` structure on a Type by proving a minimized set of axioms -/ universe u /-- Define a `Field` structure on a Type by proving a minimized set of axioms. Note that this uses the default definitions for `npow`, `nsmul`, `zsmul`, `div` and `sub`. See note [reducible non-instances]. -/ abbrev Field.ofMinimalAxioms (K : Type u) [Add K] [Mul K] [Neg K] [Inv K] [Zero K] [One K] (add_assoc : ∀ a b c : K, a + b + c = a + (b + c)) (zero_add : ∀ a : K, 0 + a = a) (neg_add_cancel : ∀ a : K, -a + a = 0) (mul_assoc : ∀ a b c : K, a * b * c = a * (b * c)) (mul_comm : ∀ a b : K, a * b = b * a) (one_mul : ∀ a : K, 1 * a = a) (mul_inv_cancel : ∀ a : K, a ≠ 0 → a * a⁻¹ = 1) (inv_zero : (0 : K)⁻¹ = 0) (left_distrib : ∀ a b c : K, a * (b + c) = a * b + a * c) (exists_pair_ne : ∃ x y : K, x ≠ y) : Field K := letI := CommRing.ofMinimalAxioms add_assoc zero_add neg_add_cancel mul_assoc mul_comm one_mul left_distrib { exists_pair_ne := exists_pair_ne mul_inv_cancel := mul_inv_cancel inv_zero := inv_zero nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl }
UpperLowerSetTopology.lean
/- Copyright (c) 2023 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Topology.AlexandrovDiscrete import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Topology.Order.LowerUpperTopology /-! # Upper and lower sets topologies This file introduces the upper set topology on a preorder as the topology where the open sets are the upper sets and the lower set topology on a preorder as the topology where the open sets are the lower sets. In general the upper set topology does not coincide with the upper topology and the lower set topology does not coincide with the lower topology. ## Main statements - `Topology.IsUpperSet.toAlexandrovDiscrete`: The upper set topology is Alexandrov-discrete. - `Topology.IsUpperSet.isClosed_iff_isLower` - a set is closed if and only if it is a Lower set - `Topology.IsUpperSet.closure_eq_lowerClosure` - topological closure coincides with lower closure - `Topology.IsUpperSet.monotone_iff_continuous` - the continuous functions are the monotone functions - `IsUpperSet.monotone_to_upperTopology_continuous`: A monotone map from a preorder with the upper set topology to a preorder with the upper topology is continuous. We provide the upper set topology in three ways (and similarly for the lower set topology): * `Topology.upperSet`: The upper set topology as a `TopologicalSpace α` * `Topology.IsUpperSet`: Prop-valued mixin typeclass stating that an existing topology is the upper set topology. * `Topology.WithUpperSet`: Type synonym equipping a preorder with its upper set topology. ## Motivation An Alexandrov topology is a topology where the intersection of any collection of open sets is open. The upper set topology is an Alexandrov topology and, given any Alexandrov topological space, we can equip it with a preorder (namely the specialization preorder) whose upper set topology coincides with the original topology. See `Topology.Specialization`. ## Tags upper set topology, lower set topology, preorder, Alexandrov -/ open Set TopologicalSpace variable {α β γ : Type*} namespace Topology /-- Topology whose open sets are upper sets. Note: In general the upper set topology does not coincide with the upper topology. -/ def upperSet (α : Type*) [Preorder α] : TopologicalSpace α where IsOpen := IsUpperSet isOpen_univ := isUpperSet_univ isOpen_inter _ _ := IsUpperSet.inter isOpen_sUnion _ := isUpperSet_sUnion /-- Topology whose open sets are lower sets. Note: In general the lower set topology does not coincide with the lower topology. -/ def lowerSet (α : Type*) [Preorder α] : TopologicalSpace α where IsOpen := IsLowerSet isOpen_univ := isLowerSet_univ isOpen_inter _ _ := IsLowerSet.inter isOpen_sUnion _ := isLowerSet_sUnion /-- Type synonym for a preorder equipped with the upper set topology. -/ def WithUpperSet (α : Type*) := α namespace WithUpperSet /-- `toUpperSet` is the identity function to the `WithUpperSet` of a type. -/ @[match_pattern] def toUpperSet : α ≃ WithUpperSet α := Equiv.refl _ /-- `ofUpperSet` is the identity function from the `WithUpperSet` of a type. -/ @[match_pattern] def ofUpperSet : WithUpperSet α ≃ α := Equiv.refl _ @[simp] lemma toUpperSet_symm : (@toUpperSet α).symm = ofUpperSet := rfl @[simp] lemma ofUpperSet_symm : (@ofUpperSet α).symm = toUpperSet := rfl @[simp] lemma toUpperSet_ofUpperSet (a : WithUpperSet α) : toUpperSet (ofUpperSet a) = a := rfl @[simp] lemma ofUpperSet_toUpperSet (a : α) : ofUpperSet (toUpperSet a) = a := rfl lemma toUpperSet_inj {a b : α} : toUpperSet a = toUpperSet b ↔ a = b := Iff.rfl lemma ofUpperSet_inj {a b : WithUpperSet α} : ofUpperSet a = ofUpperSet b ↔ a = b := Iff.rfl /-- A recursor for `WithUpperSet`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {β : WithUpperSet α → Sort*} (h : ∀ a, β (toUpperSet a)) : ∀ a, β a := fun a => h (ofUpperSet a) instance [Nonempty α] : Nonempty (WithUpperSet α) := ‹Nonempty α› instance [Inhabited α] : Inhabited (WithUpperSet α) := ‹Inhabited α› variable [Preorder α] [Preorder β] instance : Preorder (WithUpperSet α) := ‹Preorder α› instance : TopologicalSpace (WithUpperSet α) := upperSet α lemma ofUpperSet_le_iff {a b : WithUpperSet α} : ofUpperSet a ≤ ofUpperSet b ↔ a ≤ b := Iff.rfl lemma toUpperSet_le_iff {a b : α} : toUpperSet a ≤ toUpperSet b ↔ a ≤ b := Iff.rfl /-- `ofUpperSet` as an `OrderIso` -/ def ofUpperSetOrderIso : WithUpperSet α ≃o α where toEquiv := ofUpperSet map_rel_iff' := ofUpperSet_le_iff /-- `toUpperSet` as an `OrderIso` -/ def toUpperSetOrderIso : α ≃o WithUpperSet α where toEquiv := toUpperSet map_rel_iff' := toUpperSet_le_iff end WithUpperSet /-- Type synonym for a preorder equipped with the lower set topology. -/ def WithLowerSet (α : Type*) := α namespace WithLowerSet /-- `toLowerSet` is the identity function to the `WithLowerSet` of a type. -/ @[match_pattern] def toLowerSet : α ≃ WithLowerSet α := Equiv.refl _ /-- `ofLowerSet` is the identity function from the `WithLowerSet` of a type. -/ @[match_pattern] def ofLowerSet : WithLowerSet α ≃ α := Equiv.refl _ @[simp] lemma toLowerSet_symm : (@toLowerSet α).symm = ofLowerSet := rfl @[simp] lemma ofLowerSet_symm : (@ofLowerSet α).symm = toLowerSet := rfl @[simp] lemma toLowerSet_ofLowerSet (a : WithLowerSet α) : toLowerSet (ofLowerSet a) = a := rfl @[simp] lemma ofLowerSet_toLowerSet (a : α) : ofLowerSet (toLowerSet a) = a := rfl lemma toLowerSet_inj {a b : α} : toLowerSet a = toLowerSet b ↔ a = b := Iff.rfl lemma ofLowerSet_inj {a b : WithLowerSet α} : ofLowerSet a = ofLowerSet b ↔ a = b := Iff.rfl /-- A recursor for `WithLowerSet`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {β : WithLowerSet α → Sort*} (h : ∀ a, β (toLowerSet a)) : ∀ a, β a := fun a => h (ofLowerSet a) instance [Nonempty α] : Nonempty (WithLowerSet α) := ‹Nonempty α› instance [Inhabited α] : Inhabited (WithLowerSet α) := ‹Inhabited α› variable [Preorder α] instance : Preorder (WithLowerSet α) := ‹Preorder α› instance : TopologicalSpace (WithLowerSet α) := lowerSet α lemma ofLowerSet_le_iff {a b : WithLowerSet α} : ofLowerSet a ≤ ofLowerSet b ↔ a ≤ b := Iff.rfl lemma toLowerSet_le_iff {a b : α} : toLowerSet a ≤ toLowerSet b ↔ a ≤ b := Iff.rfl /-- `ofLowerSet` as an `OrderIso` -/ def ofLowerSetOrderIso : WithLowerSet α ≃o α where toEquiv := ofLowerSet map_rel_iff' := ofLowerSet_le_iff /-- `toLowerSet` as an `OrderIso` -/ def toLowerSetOrderIso : α ≃o WithLowerSet α where toEquiv := toLowerSet map_rel_iff' := toLowerSet_le_iff end WithLowerSet /-- The Upper Set topology is homeomorphic to the Lower Set topology on the dual order -/ def WithUpperSet.toDualHomeomorph [Preorder α] : WithUpperSet α ≃ₜ WithLowerSet αᵒᵈ where toFun := OrderDual.toDual invFun := OrderDual.ofDual left_inv := OrderDual.toDual_ofDual right_inv := OrderDual.ofDual_toDual continuous_toFun := continuous_coinduced_rng continuous_invFun := continuous_coinduced_rng /-- Prop-valued mixin for an ordered topological space to be The upper set topology is the topology where the open sets are the upper sets. In general the upper set topology does not coincide with the upper topology. -/ protected class IsUpperSet (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where topology_eq_upperSetTopology : t = upperSet α attribute [nolint docBlame] IsUpperSet.topology_eq_upperSetTopology instance [Preorder α] : Topology.IsUpperSet (WithUpperSet α) := ⟨rfl⟩ instance [Preorder α] : @Topology.IsUpperSet α (upperSet α) _ := by letI := upperSet α exact ⟨rfl⟩ /-- The lower set topology is the topology where the open sets are the lower sets. In general the lower set topology does not coincide with the lower topology. -/ protected class IsLowerSet (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where topology_eq_lowerSetTopology : t = lowerSet α attribute [nolint docBlame] IsLowerSet.topology_eq_lowerSetTopology instance [Preorder α] : Topology.IsLowerSet (WithLowerSet α) := ⟨rfl⟩ instance [Preorder α] : @Topology.IsLowerSet α (lowerSet α) _ := by letI := lowerSet α exact ⟨rfl⟩ namespace IsUpperSet section Preorder variable (α) variable [Preorder α] [TopologicalSpace α] [Topology.IsUpperSet α] {s : Set α} lemma topology_eq : ‹_› = upperSet α := topology_eq_upperSetTopology variable {α} instance _root_.OrderDual.instIsLowerSet [Preorder α] [TopologicalSpace α] [Topology.IsUpperSet α] : Topology.IsLowerSet αᵒᵈ where topology_eq_lowerSetTopology := by ext; rw [IsUpperSet.topology_eq α] /-- If `α` is equipped with the upper set topology, then it is homeomorphic to `WithUpperSet α`. -/ def WithUpperSetHomeomorph : WithUpperSet α ≃ₜ α := WithUpperSet.ofUpperSet.toHomeomorphOfIsInducing ⟨topology_eq α ▸ induced_id.symm⟩ lemma isOpen_iff_isUpperSet : IsOpen s ↔ IsUpperSet s := by rw [topology_eq α] rfl instance toAlexandrovDiscrete : AlexandrovDiscrete α where isOpen_sInter S := by simpa only [isOpen_iff_isUpperSet] using isUpperSet_sInter (α := α) -- c.f. isClosed_iff_lower_and_subset_implies_LUB_mem lemma isClosed_iff_isLower : IsClosed s ↔ IsLowerSet s := by rw [← isOpen_compl_iff, isOpen_iff_isUpperSet, isLowerSet_compl.symm, compl_compl] lemma closure_eq_lowerClosure {s : Set α} : closure s = lowerClosure s := by rw [subset_antisymm_iff] refine ⟨?_, lowerClosure_min subset_closure (isClosed_iff_isLower.1 isClosed_closure)⟩ · apply closure_minimal subset_lowerClosure _ rw [isClosed_iff_isLower] exact LowerSet.lower (lowerClosure s) /-- The closure of a singleton `{a}` in the upper set topology is the right-closed left-infinite interval (-∞,a]. -/ @[simp] lemma closure_singleton {a : α} : closure {a} = Iic a := by rw [closure_eq_lowerClosure, lowerClosure_singleton] rfl lemma specializes_iff_le {a b : α} : a ⤳ b ↔ b ≤ a := by simp only [specializes_iff_closure_subset, closure_singleton, Iic_subset_Iic] end Preorder section maps variable [Preorder α] [Preorder β] open Topology protected lemma monotone_iff_continuous [TopologicalSpace α] [TopologicalSpace β] [Topology.IsUpperSet α] [Topology.IsUpperSet β] {f : α → β} : Monotone f ↔ Continuous f := by constructor · intro hf simp_rw [continuous_def, isOpen_iff_isUpperSet] exact fun _ hs ↦ IsUpperSet.preimage hs hf · intro hf a b hab rw [← mem_Iic, ← closure_singleton] at hab ⊢ apply Continuous.closure_preimage_subset hf {f b} apply mem_of_mem_of_subset hab apply closure_mono rw [singleton_subset_iff, mem_preimage, mem_singleton_iff] lemma monotone_to_upperTopology_continuous [TopologicalSpace α] [TopologicalSpace β] [Topology.IsUpperSet α] [IsUpper β] {f : α → β} (hf : Monotone f) : Continuous f := by simp_rw [continuous_def, isOpen_iff_isUpperSet] intro s hs exact (IsUpper.isUpperSet_of_isOpen hs).preimage hf lemma upperSet_le_upper {t₁ t₂ : TopologicalSpace α} [@Topology.IsUpperSet α t₁ _] [@Topology.IsUpper α t₂ _] : t₁ ≤ t₂ := fun s hs => by rw [@isOpen_iff_isUpperSet α _ t₁] exact IsUpper.isUpperSet_of_isOpen hs end maps end IsUpperSet namespace IsLowerSet section Preorder variable (α) variable [Preorder α] [TopologicalSpace α] [Topology.IsLowerSet α] {s : Set α} lemma topology_eq : ‹_› = lowerSet α := topology_eq_lowerSetTopology variable {α} instance _root_.OrderDual.instIsUpperSet [Preorder α] [TopologicalSpace α] [Topology.IsLowerSet α] : Topology.IsUpperSet αᵒᵈ where topology_eq_upperSetTopology := by ext; rw [IsLowerSet.topology_eq α] /-- If `α` is equipped with the lower set topology, then it is homeomorphic to `WithLowerSet α`. -/ def WithLowerSetHomeomorph : WithLowerSet α ≃ₜ α := WithLowerSet.ofLowerSet.toHomeomorphOfIsInducing ⟨topology_eq α ▸ induced_id.symm⟩ lemma isOpen_iff_isLowerSet : IsOpen s ↔ IsLowerSet s := by rw [topology_eq α]; rfl instance toAlexandrovDiscrete : AlexandrovDiscrete α := IsUpperSet.toAlexandrovDiscrete (α := αᵒᵈ) lemma isClosed_iff_isUpper : IsClosed s ↔ IsUpperSet s := by rw [← isOpen_compl_iff, isOpen_iff_isLowerSet, isUpperSet_compl.symm, compl_compl] lemma closure_eq_upperClosure {s : Set α} : closure s = upperClosure s := IsUpperSet.closure_eq_lowerClosure (α := αᵒᵈ) /-- The closure of a singleton `{a}` in the lower set topology is the right-closed left-infinite interval (-∞,a]. -/ @[simp] lemma closure_singleton {a : α} : closure {a} = Ici a := by rw [closure_eq_upperClosure, upperClosure_singleton] rfl end Preorder section maps variable [Preorder α] [Preorder β] open Topology open OrderDual protected lemma monotone_iff_continuous [TopologicalSpace α] [TopologicalSpace β] [Topology.IsLowerSet α] [Topology.IsLowerSet β] {f : α → β} : Monotone f ↔ Continuous f := by rw [← monotone_dual_iff] exact IsUpperSet.monotone_iff_continuous (α := αᵒᵈ) (β := βᵒᵈ) (f := (toDual ∘ f ∘ ofDual : αᵒᵈ → βᵒᵈ)) lemma monotone_to_lowerTopology_continuous [TopologicalSpace α] [TopologicalSpace β] [Topology.IsLowerSet α] [IsLower β] {f : α → β} (hf : Monotone f) : Continuous f := IsUpperSet.monotone_to_upperTopology_continuous (α := αᵒᵈ) (β := βᵒᵈ) hf.dual lemma lowerSet_le_lower {t₁ t₂ : TopologicalSpace α} [@Topology.IsLowerSet α t₁ _] [@IsLower α t₂ _] : t₁ ≤ t₂ := fun s hs => by rw [@isOpen_iff_isLowerSet α _ t₁] exact IsLower.isLowerSet_of_isOpen hs end maps end IsLowerSet lemma isUpperSet_orderDual [Preorder α] [TopologicalSpace α] : Topology.IsUpperSet αᵒᵈ ↔ Topology.IsLowerSet α := by constructor · apply OrderDual.instIsLowerSet · apply OrderDual.instIsUpperSet lemma isLowerSet_orderDual [Preorder α] [TopologicalSpace α] : Topology.IsLowerSet αᵒᵈ ↔ Topology.IsUpperSet α := isUpperSet_orderDual.symm namespace WithUpperSet variable [Preorder α] [Preorder β] [Preorder γ] /-- A monotone map between preorders spaces induces a continuous map between themselves considered with the upper set topology. -/ def map (f : α →o β) : C(WithUpperSet α, WithUpperSet β) where toFun := toUpperSet ∘ f ∘ ofUpperSet continuous_toFun := continuous_def.2 fun _s hs ↦ IsUpperSet.preimage hs f.monotone @[simp] lemma map_id : map (OrderHom.id : α →o α) = ContinuousMap.id _ := rfl @[simp] lemma map_comp (g : β →o γ) (f : α →o β) : map (g.comp f) = (map g).comp (map f) := rfl @[simp] lemma toUpperSet_specializes_toUpperSet {a b : α} : toUpperSet a ⤳ toUpperSet b ↔ b ≤ a := by simp_rw [specializes_iff_closure_subset, IsUpperSet.closure_singleton, Iic_subset_Iic, toUpperSet_le_iff] @[simp] lemma ofUpperSet_le_ofUpperSet {a b : WithUpperSet α} : ofUpperSet a ≤ ofUpperSet b ↔ b ⤳ a := toUpperSet_specializes_toUpperSet.symm @[simp] lemma isUpperSet_toUpperSet_preimage {s : Set (WithUpperSet α)} : IsUpperSet (toUpperSet ⁻¹' s) ↔ IsOpen s := Iff.rfl @[simp] lemma isOpen_ofUpperSet_preimage {s : Set α} : IsOpen (ofUpperSet ⁻¹' s) ↔ IsUpperSet s := isUpperSet_toUpperSet_preimage.symm end WithUpperSet namespace WithLowerSet variable [Preorder α] [Preorder β] [Preorder γ] /-- A monotone map between preorders spaces induces a continuous map between themselves considered with the lower set topology. -/ def map (f : α →o β) : C(WithLowerSet α, WithLowerSet β) where toFun := toLowerSet ∘ f ∘ ofLowerSet continuous_toFun := continuous_def.2 fun _s hs ↦ IsLowerSet.preimage hs f.monotone @[simp] lemma map_id : map (OrderHom.id : α →o α) = ContinuousMap.id _ := rfl @[simp] lemma map_comp (g : β →o γ) (f : α →o β) : map (g.comp f) = (map g).comp (map f) := rfl @[simp] lemma toLowerSet_specializes_toLowerSet {a b : α} : toLowerSet a ⤳ toLowerSet b ↔ a ≤ b := by simp_rw [specializes_iff_closure_subset, IsLowerSet.closure_singleton, Ici_subset_Ici, toLowerSet_le_iff] @[simp] lemma ofLowerSet_le_ofLowerSet {a b : WithLowerSet α} : ofLowerSet a ≤ ofLowerSet b ↔ a ⤳ b := toLowerSet_specializes_toLowerSet.symm @[simp] lemma isLowerSet_toLowerSet_preimage {s : Set (WithLowerSet α)} : IsLowerSet (toLowerSet ⁻¹' s) ↔ IsOpen s := Iff.rfl @[simp] lemma isOpen_ofLowerSet_preimage {s : Set α} : IsOpen (ofLowerSet ⁻¹' s) ↔ IsLowerSet s := isLowerSet_toLowerSet_preimage.symm end WithLowerSet end Topology
Isometric.lean
/- Copyright (c) 2025 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.PosPart.Basic import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Isometric /-! # Facts about `CFC.posPart` and `CFC.negPart` involving norms This file collects various facts about the positive and negative parts of elements of a C⋆-algebra that involve the norm. ## Main results * `CFC.norm_eq_max_norm_posPart_negPart`: states that `‖a‖ = max ‖a⁺‖ ‖a⁻‖` * `CFC.norm_posPart_le` and `CFC.norm_negPart_le`: state that `‖a⁺‖ ≤ ‖a‖` and `‖a⁻‖ ≤ ‖a‖` respectively. -/ variable {A : Type*} [NonUnitalNormedRing A] [NormedSpace ℝ A] [SMulCommClass ℝ A A] [IsScalarTower ℝ A A] [StarRing A] [NonUnitalIsometricContinuousFunctionalCalculus ℝ A IsSelfAdjoint] @[simp] lemma CStarAlgebra.norm_posPart_le (a : A) : ‖a⁺‖ ≤ ‖a‖ := by by_cases ha : IsSelfAdjoint a case neg => simp [CFC.posPart_def, cfcₙ_apply_of_not_predicate a ha] refine norm_cfcₙ_le fun x hx ↦ ?_ obtain (h | h) := le_or_gt x 0 · simp [posPart_def, max_eq_right h] · simp only [posPart_def, max_eq_left h.le] exact NonUnitalIsometricContinuousFunctionalCalculus.norm_quasispectrum_le a hx ha @[simp] lemma CStarAlgebra.norm_negPart_le (a : A) : ‖a⁻‖ ≤ ‖a‖ := by simpa [CFC.negPart_neg] using norm_posPart_le (-a) open CStarAlgebra in lemma IsSelfAdjoint.norm_eq_max_norm_posPart_negPart (a : A) (ha : IsSelfAdjoint a := by cfc_tac) : ‖a‖ = max ‖a⁺‖ ‖a⁻‖ := by refine le_antisymm ?_ <| max_le (norm_posPart_le a) (norm_negPart_le a) conv_lhs => rw [← cfcₙ_id' ℝ a] rw [norm_cfcₙ_le_iff ..] intro x hx obtain (hx' | hx') := le_total 0 x · apply le_max_of_le_left refine le_of_eq_of_le ?_ <| norm_apply_le_norm_cfcₙ _ a hx rw [posPart_eq_self.mpr hx'] · apply le_max_of_le_right refine le_of_eq_of_le ?_ <| norm_apply_le_norm_cfcₙ _ a hx rw [negPart_eq_neg.mpr hx', norm_neg]
Defs.lean
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.RingTheory.IntegralClosure.IsIntegral.Defs /-! # Integral algebras ## Main definitions Let `R` be a `CommRing` and let `A` be an R-algebra. * `Algebra.IsIntegral R A` : An algebra is integral if every element of the extension is integral over the base ring. -/ open Polynomial Submodule section Ring variable {R S A : Type*} variable [CommRing R] [Ring A] [Ring S] (f : R →+* S) variable [Algebra R A] (R) variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring. -/ @[mk_iff] protected class Algebra.IsIntegral : Prop where isIntegral : ∀ x : A, IsIntegral R x variable {R A} lemma Algebra.isIntegral_def : Algebra.IsIntegral R A ↔ ∀ x : A, IsIntegral R x := ⟨fun ⟨h⟩ ↦ h, fun h ↦ ⟨h⟩⟩ lemma algebraMap_isIntegral_iff : (algebraMap R A).IsIntegral ↔ Algebra.IsIntegral R A := (Algebra.isIntegral_iff ..).symm end Ring
FiniteType.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.Algebra.FreeAlgebra import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Adjoin.Tower import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Noetherian.Orzech /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe uR uS uA uB uM uN variable (R : Type uR) (S : Type uS) (A : Type uA) (B : Type uB) (M : Type uM) (N : Type uN) /-- An algebra over a commutative semiring is of `FiniteType` if it is finitely generated over the base ring as algebra. -/ class Algebra.FiniteType [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : (⊤ : Subalgebra R A).FG namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] namespace Finite open Submodule Set variable {R S M N} section Algebra -- see Note [lower instance priority] instance (priority := 100) finiteType {R : Type*} (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [hRA : Module.Finite R A] : Algebra.FiniteType R A := ⟨Subalgebra.fg_of_submodule_fg hRA.1⟩ end Algebra end Finite end Module namespace Algebra variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] namespace FiniteType @[deprecated inferInstance (since := "2025-07-12")] theorem self : FiniteType R R := inferInstance theorem of_restrictScalars_finiteType [Algebra S A] [IsScalarTower R S A] [hA : FiniteType R A] : FiniteType S A := by obtain ⟨s, hS⟩ := hA.out refine ⟨⟨s, eq_top_iff.2 fun b => ?_⟩⟩ have le : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S s) := by apply (Algebra.adjoin_le _ : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S ↑s)) simp only [Subalgebra.coe_restrictScalars] exact Algebra.subset_adjoin exact le (eq_top_iff.1 hS b) variable {R S A B} theorem of_surjective [FiniteType R A] (f : A →ₐ[R] B) (hf : Surjective f) : FiniteType R B := ⟨by convert ‹FiniteType R A›.1.map f simpa only [map_top f, @eq_comm _ ⊤, eq_top_iff, AlgHom.mem_range] using hf⟩ theorem equiv (hRA : FiniteType R A) (e : A ≃ₐ[R] B) : FiniteType R B := hRA.of_surjective e e.surjective theorem trans [Algebra S A] [IsScalarTower R S A] (hRS : FiniteType R S) (hSA : FiniteType S A) : FiniteType R A := ⟨fg_trans' hRS.1 hSA.1⟩ instance quotient (R : Type*) {S : Type*} [CommSemiring R] [CommRing S] [Algebra R S] (I : Ideal S) [h : Algebra.FiniteType R S] : Algebra.FiniteType R (S ⧸ I) := Algebra.FiniteType.trans h inferInstance instance [FiniteType R S] : FiniteType R S[X] := by refine .trans ‹_› ⟨{Polynomial.X}, ?_⟩ rw [Finset.coe_singleton] exact Polynomial.adjoin_X @[deprecated inferInstance (since := "2025-07-12")] protected theorem polynomial : FiniteType R R[X] := inferInstance instance {ι : Type*} [Finite ι] [FiniteType R S] : FiniteType R (MvPolynomial ι S) := by classical cases nonempty_fintype ι refine .trans ‹_› ⟨Finset.univ.image MvPolynomial.X, ?_⟩ rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact MvPolynomial.adjoin_range_X @[deprecated inferInstance (since := "2025-07-12")] protected theorem mvPolynomial (ι : Type*) [Finite ι] : FiniteType R (MvPolynomial ι R) := inferInstance instance {ι : Type*} [Finite ι] [FiniteType R S] : FiniteType R (FreeAlgebra S ι) := by classical cases nonempty_fintype ι refine .trans ‹_› ⟨Finset.univ.image (FreeAlgebra.ι _), ?_⟩ rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact FreeAlgebra.adjoin_range_ι .. @[deprecated inferInstance (since := "2025-07-12")] protected theorem freeAlgebra (ι : Type*) [Finite ι] : FiniteType R (FreeAlgebra R ι) := inferInstance /-- An algebra is finitely generated if and only if it is a quotient of a free algebra whose variables are indexed by a finset. -/ theorem iff_quotient_freeAlgebra : FiniteType R A ↔ ∃ (s : Finset A) (f : FreeAlgebra R s →ₐ[R] A), Surjective f := by constructor · rintro ⟨s, hs⟩ refine ⟨s, FreeAlgebra.lift _ (↑), ?_⟩ rw [← Set.range_eq_univ, ← AlgHom.coe_range, ← adjoin_range_eq_range_freeAlgebra_lift, Subtype.range_coe_subtype, Finset.setOf_mem, hs, coe_top] · rintro ⟨s, f, hsur⟩ exact .of_surjective f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a finset. -/ theorem iff_quotient_mvPolynomial : FiniteType R S ↔ ∃ (s : Finset S) (f : MvPolynomial { x // x ∈ s } R →ₐ[R] S), Surjective f := by constructor · rintro ⟨s, hs⟩ use s, MvPolynomial.aeval (↑) intro x have hrw : (↑s : Set S) = fun x : S => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range, ← adjoin_eq_range] simp_rw [← hrw, hs] exact Set.mem_univ x · rintro ⟨s, f, hsur⟩ exact .of_surjective f hsur /-- An algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_freeAlgebra' : FiniteType R A ↔ ∃ (ι : Type uA) (_ : Fintype ι) (f : FreeAlgebra R ι →ₐ[R] A), Surjective f := by constructor · rw [iff_quotient_freeAlgebra] rintro ⟨s, f, hsur⟩ use { x : A // x ∈ s }, inferInstance, f · rintro ⟨ι, hfintype, f, hsur⟩ letI : Fintype ι := hfintype exact .of_surjective f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_mvPolynomial' : FiniteType R S ↔ ∃ (ι : Type uS) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial] rintro ⟨s, f, hsur⟩ use { x : S // x ∈ s }, inferInstance, f · rintro ⟨ι, hfintype, f, hsur⟩ letI : Fintype ι := hfintype exact .of_surjective f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring in `n` variables. -/ theorem iff_quotient_mvPolynomial'' : FiniteType R S ↔ ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial'] rintro ⟨ι, hfintype, f, hsur⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) exact ⟨Fintype.card ι, AlgHom.comp f equiv.symm.toAlgHom, by simpa using hsur⟩ · rintro ⟨n, f, hsur⟩ exact .of_surjective f hsur instance prod [hA : FiniteType R A] [hB : FiniteType R B] : FiniteType R (A × B) := ⟨by rw [← Subalgebra.prod_top]; exact hA.1.prod hB.1⟩ theorem isNoetherianRing (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] [h : Algebra.FiniteType R S] [IsNoetherianRing R] : IsNoetherianRing S := by obtain ⟨s, hs⟩ := h.1 apply isNoetherianRing_of_surjective (MvPolynomial s R) S (MvPolynomial.aeval (↑) : MvPolynomial s R →ₐ[R] S).toRingHom rw [← Set.range_eq_univ, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, ← AlgHom.coe_range, ← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe_subtype, Finset.setOf_mem, hs] rfl theorem _root_.Subalgebra.fg_iff_finiteType (S : Subalgebra R A) : S.FG ↔ Algebra.FiniteType R S := S.fg_top.symm.trans ⟨fun h => ⟨h⟩, fun h => h.out⟩ end FiniteType end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `FiniteType` if `B` is finitely generated as `A`-algebra. -/ @[algebraize] def FiniteType (f : A →+* B) : Prop := @Algebra.FiniteType A B _ _ f.toAlgebra lemma finiteType_algebraMap [Algebra A B] : (algebraMap A B).FiniteType ↔ Algebra.FiniteType A B := by rw [FiniteType, toAlgebra_algebraMap] namespace Finite theorem finiteType {f : A →+* B} (hf : f.Finite) : FiniteType f := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf end Finite namespace FiniteType variable (A) in theorem id : FiniteType (RingHom.id A) := by simp [FiniteType]; infer_instance theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := by algebraize_only [f, g.comp f] exact ‹Algebra.FiniteType _ _›.of_surjective { g with toFun := g commutes' := fun a => rfl } hg theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.FiniteType := by rw [← f.comp_id] exact (id A).comp_surjective hf theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := by algebraize_only [f, g, g.comp f] exact Algebra.FiniteType.trans hf hg theorem of_finite {f : A →+* B} (hf : f.Finite) : f.FiniteType := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf alias _root_.RingHom.Finite.to_finiteType := of_finite theorem of_comp_finiteType {f : A →+* B} {g : B →+* C} (h : (g.comp f).FiniteType) : g.FiniteType := by algebraize [f, g, g.comp f] exact Algebra.FiniteType.of_restrictScalars_finiteType A B C end FiniteType end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is of `FiniteType` if it is of finite type as ring morphism. In other words, if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →ₐ[R] B) : Prop := f.toRingHom.FiniteType namespace Finite theorem finiteType {f : A →ₐ[R] B} (hf : f.Finite) : FiniteType f := RingHom.Finite.finiteType hf end Finite namespace FiniteType variable (R A) theorem id : FiniteType (AlgHom.id R A) := RingHom.FiniteType.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := RingHom.FiniteType.comp hg hf theorem comp_surjective {f : A →ₐ[R] B} {g : B →ₐ[R] C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := RingHom.FiniteType.comp_surjective hf hg theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.FiniteType := RingHom.FiniteType.of_surjective f.toRingHom hf theorem of_comp_finiteType {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).FiniteType) : g.FiniteType := RingHom.FiniteType.of_comp_finiteType h end FiniteType end AlgHom @[deprecated (since := "2025-08-12")] alias algebraMap_finiteType_iff_algebra_finiteType := RingHom.finiteType_algebraMap section MonoidAlgebra variable {R : Type*} {M : Type*} namespace AddMonoidAlgebra open Algebra AddSubmonoid Submodule section Span section Semiring variable [CommSemiring R] [AddMonoid M] /-- An element of `R[M]` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : R[M]) : f ∈ adjoin R (of' R M '' f.support) := by suffices span R (of' R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of' R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin /-- If a set `S` generates, as algebra, `R[M]`, then the set of supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of' R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf have hincl : of' R M '' f.support ⊆ ⋃ (g : R[M]) (_ : g ∈ S), of' R M '' g.support := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) /-- If a set `S` generates, as algebra, `R[M]`, then the image of the union of the supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen' {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of' R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] end Semiring section Ring variable [CommRing R] [AddMonoid M] /-- If `R[M]` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `R[M]`. -/ theorem exists_finset_adjoin_eq_top [h : FiniteType R R[M]] : ∃ G : Finset M, Algebra.adjoin R (of' R M '' G) = ⊤ := by obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this] exact support_gen_of_gen' hS /-- The image of an element `m : M` in `R[M]` belongs the submodule generated by `S : Set M` if and only if `m ∈ S`. -/ theorem of'_mem_span [Nontrivial R] {m : M} {S : Set M} : of' R M m ∈ span R (of' R M '' S) ↔ m ∈ S := by refine ⟨fun h => ?_, fun h => Submodule.subset_span <| Set.mem_image_of_mem (of R M) h⟩ unfold of' at h rw [← Finsupp.supported_eq_span_single, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ (one_ne_zero' R)] at h simpa using h /-- If the image of an element `m : M` in `R[M]` belongs the submodule generated by the closure of some `S : Set M` then `m ∈ closure S`. -/ theorem mem_closure_of_mem_span_closure [Nontrivial R] {m : M} {S : Set M} (h : of' R M m ∈ span R (Submonoid.closure (of' R M '' S) : Set R[M])) : m ∈ closure S := by suffices Multiplicative.ofAdd m ∈ Submonoid.closure (Multiplicative.toAdd ⁻¹' S) by simpa [← toSubmonoid_closure] let S' := @Submonoid.closure (Multiplicative M) Multiplicative.mulOneClass S have h' : Submonoid.map (of R M) S' = Submonoid.closure ((fun x : M => (of R M) x) '' S) := MonoidHom.map_mclosure _ _ rw [Set.image_congr' (show ∀ x, of' R M x = of R M x from fun x => of'_eq_of x), ← h'] at h simpa using of'_mem_span.1 h end Ring end Span /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem mvPolynomial_aeval_of_surjective_of_closure [AddCommMonoid M] [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (MvPolynomial.aeval fun s : S => of' R M ↑s : MvPolynomial S R → R[M]) := by intro f induction f using induction_on with | hM m => have : m ∈ closure S := hS.symm ▸ mem_top _ refine AddSubmonoid.closure_induction (fun m hm => ?_) ?_ ?_ this · exact ⟨MvPolynomial.X ⟨m, hm⟩, MvPolynomial.aeval_X _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ _ _ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]; rfl⟩ | hadd f g ihf ihg => rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ | hsmul r f ih => rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable [AddMonoid M] /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem freeAlgebra_lift_of_surjective_of_closure [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (FreeAlgebra.lift R fun s : S => of' R M ↑s : FreeAlgebra R S → R[M]) := by intro f induction f using induction_on with | hM m => have : m ∈ closure S := hS.symm ▸ mem_top _ refine AddSubmonoid.closure_induction (fun m hm => ?_) ?_ ?_ this · exact ⟨FreeAlgebra.ι R ⟨m, hm⟩, FreeAlgebra.lift_ι_apply _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ _ _ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]; rfl⟩ | hadd f g ihf ihg => rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ | hsmul r f ih => rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable (R M) /-- If an additive monoid `M` is finitely generated then `R[M]` is of finite type. -/ instance finiteType_of_fg [CommRing R] [h : AddMonoid.FG M] : FiniteType R R[M] := by obtain ⟨S, hS⟩ := h.fg_top exact .of_surjective (FreeAlgebra.lift R fun s : (S : Set M) => of' R M ↑s) (freeAlgebra_lift_of_surjective_of_closure hS) variable {R M} /-- An additive monoid `M` is finitely generated if and only if `R[M]` is of finite type. -/ theorem finiteType_iff_fg [CommRing R] [Nontrivial R] : FiniteType R R[M] ↔ AddMonoid.FG M := by refine ⟨fun h => ?_, fun h => @AddMonoidAlgebra.finiteType_of_fg _ _ _ _ h⟩ obtain ⟨S, hS⟩ := @exists_finset_adjoin_eq_top R M _ _ h refine AddMonoid.fg_def.2 ⟨S, (eq_top_iff' _).2 fun m => ?_⟩ have hm : of' R M m ∈ Subalgebra.toSubmodule (adjoin R (of' R M '' ↑S)) := by simp only [hS, top_toSubmodule, Submodule.mem_top] rw [adjoin_eq_span] at hm exact mem_closure_of_mem_span_closure hm /-- If `R[M]` is of finite type then `M` is finitely generated. -/ theorem fg_of_finiteType [CommRing R] [Nontrivial R] [h : FiniteType R R[M]] : AddMonoid.FG M := finiteType_iff_fg.1 h /-- An additive group `G` is finitely generated if and only if `R[G]` is of finite type. -/ theorem finiteType_iff_group_fg {G : Type*} [AddGroup G] [CommRing R] [Nontrivial R] : FiniteType R R[G] ↔ AddGroup.FG G := by simpa [AddGroup.fg_iff_addMonoid_fg] using finiteType_iff_fg end AddMonoidAlgebra namespace MonoidAlgebra open Algebra Submonoid Submodule section Span section Semiring variable [CommSemiring R] [Monoid M] /-- An element of `MonoidAlgebra R M` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : MonoidAlgebra R M) : f ∈ adjoin R (of R M '' f.support) := by suffices span R (of R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin /-- If a set `S` generates, as algebra, `MonoidAlgebra R M`, then the set of supports of elements of `S` generates `MonoidAlgebra R M`. -/ theorem support_gen_of_gen {S : Set (MonoidAlgebra R M)} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf -- Porting note: ⋃ notation did not work here. Was -- ⋃ (g : MonoidAlgebra R M) (H : g ∈ S), (of R M '' g.support) have hincl : (of R M '' f.support) ⊆ Set.iUnion fun (g : MonoidAlgebra R M) => Set.iUnion fun (_ : g ∈ S) => (of R M '' g.support) := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) /-- If a set `S` generates, as algebra, `MonoidAlgebra R M`, then the image of the union of the supports of elements of `S` generates `MonoidAlgebra R M`. -/ theorem support_gen_of_gen' {S : Set (MonoidAlgebra R M)} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] end Semiring section Ring variable [CommRing R] [Monoid M] /-- If `MonoidAlgebra R M` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `MonoidAlgebra R M`. -/ theorem exists_finset_adjoin_eq_top [h : FiniteType R (MonoidAlgebra R M)] : ∃ G : Finset M, Algebra.adjoin R (of R M '' G) = ⊤ := by obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this] exact support_gen_of_gen' hS /-- The image of an element `m : M` in `MonoidAlgebra R M` belongs the submodule generated by `S : Set M` if and only if `m ∈ S`. -/ theorem of_mem_span_of_iff [Nontrivial R] {m : M} {S : Set M} : of R M m ∈ span R (of R M '' S) ↔ m ∈ S := by refine ⟨fun h => ?_, fun h => Submodule.subset_span <| Set.mem_image_of_mem (of R M) h⟩ dsimp [of] at h rw [← Finsupp.supported_eq_span_single, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ (one_ne_zero' R)] at h simpa using h /-- If the image of an element `m : M` in `MonoidAlgebra R M` belongs the submodule generated by the closure of some `S : Set M` then `m ∈ closure S`. -/ theorem mem_closure_of_mem_span_closure [Nontrivial R] {m : M} {S : Set M} (h : of R M m ∈ span R (Submonoid.closure (of R M '' S) : Set (MonoidAlgebra R M))) : m ∈ closure S := by rw [← MonoidHom.map_mclosure] at h simpa using of_mem_span_of_iff.1 h end Ring end Span /-- If a set `S` generates a monoid `M`, then the image of `M` generates, as algebra, `MonoidAlgebra R M`. -/ theorem mvPolynomial_aeval_of_surjective_of_closure [CommMonoid M] [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (MvPolynomial.aeval fun s : S => of R M ↑s : MvPolynomial S R → MonoidAlgebra R M) := by intro f induction f using induction_on with | hM m => have : m ∈ closure S := hS.symm ▸ mem_top _ refine Submonoid.closure_induction (fun m hm => ?_) ?_ ?_ this · exact ⟨MvPolynomial.X ⟨m, hm⟩, MvPolynomial.aeval_X _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ _ _ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]⟩ | hadd f g ihf ihg => rcases ihf with ⟨P, rfl⟩; rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ | hsmul r f ih => rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ variable [Monoid M] /-- If a set `S` generates an additive monoid `M`, then the image of `M` generates, as algebra, `R[M]`. -/ theorem freeAlgebra_lift_of_surjective_of_closure [CommSemiring R] {S : Set M} (hS : closure S = ⊤) : Function.Surjective (FreeAlgebra.lift R fun s : S => of R M ↑s : FreeAlgebra R S → MonoidAlgebra R M) := by intro f induction f using induction_on with | hM m => have : m ∈ closure S := hS.symm ▸ mem_top _ refine Submonoid.closure_induction (fun m hm => ?_) ?_ ?_ this · exact ⟨FreeAlgebra.ι R ⟨m, hm⟩, FreeAlgebra.lift_ι_apply _ _⟩ · exact ⟨1, map_one _⟩ · rintro m₁ m₂ _ _ ⟨P₁, hP₁⟩ ⟨P₂, hP₂⟩ exact ⟨P₁ * P₂, by rw [map_mul, hP₁, hP₂, of_apply, of_apply, of_apply, single_mul_single, one_mul]⟩ | hadd f g ihf ihg => rcases ihf with ⟨P, rfl⟩ rcases ihg with ⟨Q, rfl⟩ exact ⟨P + Q, map_add _ _ _⟩ | hsmul r f ih => rcases ih with ⟨P, rfl⟩ exact ⟨r • P, map_smul _ _ _⟩ /-- If a monoid `M` is finitely generated then `MonoidAlgebra R M` is of finite type. -/ instance finiteType_of_fg [CommRing R] [Monoid.FG M] : FiniteType R (MonoidAlgebra R M) := (AddMonoidAlgebra.finiteType_of_fg R (Additive M)).equiv (toAdditiveAlgEquiv R M).symm /-- A monoid `M` is finitely generated if and only if `MonoidAlgebra R M` is of finite type. -/ theorem finiteType_iff_fg [CommRing R] [Nontrivial R] : FiniteType R (MonoidAlgebra R M) ↔ Monoid.FG M := ⟨fun h => Monoid.fg_iff_add_fg.2 <| AddMonoidAlgebra.finiteType_iff_fg.1 <| h.equiv <| toAdditiveAlgEquiv R M, fun h => @MonoidAlgebra.finiteType_of_fg _ _ _ _ h⟩ /-- If `MonoidAlgebra R M` is of finite type then `M` is finitely generated. -/ theorem fg_of_finiteType [CommRing R] [Nontrivial R] [h : FiniteType R (MonoidAlgebra R M)] : Monoid.FG M := finiteType_iff_fg.1 h /-- A group `G` is finitely generated if and only if `R[G]` is of finite type. -/ theorem finiteType_iff_group_fg {G : Type*} [Group G] [CommRing R] [Nontrivial R] : FiniteType R (MonoidAlgebra R G) ↔ Group.FG G := by simpa [Group.fg_iff_monoid_fg] using finiteType_iff_fg end MonoidAlgebra end MonoidAlgebra section Orzech open Submodule Module Module.Finite in /-- Any commutative ring `R` satisfies the `OrzechProperty`, that is, for any finitely generated `R`-module `M`, any surjective homomorphism `f : N →ₗ[R] M` from a submodule `N` of `M` to `M` is injective. This is a consequence of Noetherian case (`IsNoetherian.injective_of_surjective_of_injective`), which requires that `M` is a Noetherian module, but allows `R` to be non-commutative. The reduction of this result to Noetherian case is adapted from <https://math.stackexchange.com/a/1066110>: suppose `{ m_j }` is a finite set of generator of `M`, for any `n : N` one can write `i n = ∑ j, b_j * m_j` for `{ b_j }` in `R`, here `i : N →ₗ[R] M` is the standard inclusion. We can choose `{ n_j }` which are preimages of `{ m_j }` under `f`, and can choose `{ c_jl }` in `R` such that `i n_j = ∑ l, c_jl * m_l` for each `j`. Now let `A` be the subring of `R` generated by `{ b_j }` and `{ c_jl }`, then it is Noetherian. Let `N'` be the `A`-submodule of `N` generated by `n` and `{ n_j }`, `M'` be the `A`-submodule of `M` generated by `{ m_j }`, then it's easy to see that `i` and `f` restrict to `N' →ₗ[A] M'`, and the restricted version of `f` is surjective, hence by Noetherian case, it is also injective, in particular, if `f n = 0`, then `n = 0`. See also Orzech's original paper: *Onto endomorphisms are isomorphisms* [orzech1971]. -/ instance (priority := 100) CommRing.orzechProperty (R : Type*) [CommRing R] : OrzechProperty R := by refine ⟨fun {M} _ _ _ {N} f hf ↦ ?_⟩ letI := addCommMonoidToAddCommGroup R (M := M) letI := addCommMonoidToAddCommGroup R (M := N) let i := N.subtype let hi : Function.Injective i := N.injective_subtype refine LinearMap.ker_eq_bot.1 <| LinearMap.ker_eq_bot'.2 fun n hn ↦ ?_ obtain ⟨k, mj, hmj⟩ := exists_fin (R := R) (M := M) rw [← surjective_piEquiv_apply_iff] at hmj obtain ⟨b, hb⟩ := hmj (i n) choose nj hnj using fun j ↦ hf (mj j) choose c hc using fun j ↦ hmj (i (nj j)) let A := Subring.closure (Set.range b ∪ Set.range c.uncurry) let N' := span A ({n} ∪ Set.range nj) let M' := span A (Set.range mj) haveI : IsNoetherianRing A := is_noetherian_subring_closure _ (.union (Set.finite_range _) (Set.finite_range _)) haveI : Module.Finite A M' := span_of_finite A (Set.finite_range _) refine congr($((LinearMap.ker_eq_bot'.1 <| LinearMap.ker_eq_bot.2 <| IsNoetherian.injective_of_surjective_of_injective ((i.restrictScalars A).restrict fun x hx ↦ ?_ : N' →ₗ[A] M') ((f.restrictScalars A).restrict fun x hx ↦ ?_ : N' →ₗ[A] M') (fun _ _ h ↦ injective_subtype _ (hi congr(($h).1))) fun ⟨x, hx⟩ ↦ ?_) ⟨n, (subset_span (by simp))⟩ (Subtype.val_injective hn)).1) · induction hx using span_induction with | mem x hx => change i x ∈ M' simp only [Set.singleton_union, Set.mem_insert_iff, Set.mem_range] at hx rcases hx with hx | ⟨j, rfl⟩ · rw [hx, ← hb, piEquiv_apply_apply] refine Submodule.sum_mem _ fun j _ ↦ ?_ let b' : A := ⟨b j, Subring.subset_closure (by simp)⟩ rw [show b j • mj j = b' • mj j from rfl] exact smul_mem _ _ (subset_span (by simp)) · rw [← hc, piEquiv_apply_apply] refine Submodule.sum_mem _ fun j' _ ↦ ?_ let c' : A := ⟨c j j', Subring.subset_closure (by simp [show ∃ a b, c a b = c j j' from ⟨j, j', rfl⟩])⟩ rw [show c j j' • mj j' = c' • mj j' from rfl] exact smul_mem _ _ (subset_span (by simp)) | zero => simp | add x _ y _ hx hy => rw [map_add]; exact add_mem hx hy | smul a x _ hx => rw [map_smul]; exact smul_mem _ _ hx · induction hx using span_induction with | mem x hx => change f x ∈ M' simp only [Set.singleton_union, Set.mem_insert_iff, Set.mem_range] at hx rcases hx with hx | ⟨j, rfl⟩ · rw [hx, hn]; exact zero_mem _ · exact subset_span (by simp [hnj]) | zero => simp | add x _ y _ hx hy => rw [map_add]; exact add_mem hx hy | smul a x _ hx => rw [map_smul]; exact smul_mem _ _ hx suffices x ∈ LinearMap.range ((f.restrictScalars A).domRestrict N') by obtain ⟨a, ha⟩ := this exact ⟨a, Subtype.val_injective ha⟩ induction hx using span_induction with | mem x hx => obtain ⟨j, rfl⟩ := hx exact ⟨⟨nj j, subset_span (by simp)⟩, hnj j⟩ | zero => exact zero_mem _ | add x y _ _ hx hy => exact add_mem hx hy | smul a x _ hx => exact smul_mem _ a hx end Orzech
commutator.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 fintype. From mathcomp Require Import bigop finset binomial fingroup morphism. From mathcomp Require Import automorphism quotient gfunctor. (******************************************************************************) (* This files contains the proofs of several key properties of commutators, *) (* including the Hall-Witt identity and the Three Subgroup Lemma. *) (* The definition and notation for both pointwise and set wise commutators *) (* ([~x, y, ...] and [~: A, B ,...], respectively) are given in fingroup.v *) (* This file defines the derived group series: *) (* G^`(0) == G *) (* G^`(n.+1) == [~: G^`(n), G^`(n)] *) (* as several classical results involve the (first) derived group G^`(1), *) (* such as the equivalence H <| G /\ G / H abelian <-> G^`(1) \subset H. *) (* The connection between the derived series and solvable groups will only be *) (* established in nilpotent.v, however. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Definition derived_at n (gT : finGroupType) (A : {set gT}) := iter n (fun B => [~: B, B]) A. Arguments derived_at n%_N {gT} A%_g : simpl never. Notation "G ^` ( n )" := (derived_at n G) : group_scope. Section DerivedBasics. Variables gT : finGroupType. Implicit Type A : {set gT}. Implicit Types G : {group gT}. Lemma derg0 A : A^`(0) = A. Proof. by []. Qed. Lemma derg1 A : A^`(1) = [~: A, A]. Proof. by []. Qed. Lemma dergSn n A : A^`(n.+1) = [~: A^`(n), A^`(n)]. Proof. by []. Qed. Lemma der_group_set G n : group_set G^`(n). Proof. by case: n => [|n]; apply: groupP. Qed. Canonical derived_at_group G n := Group (der_group_set G n). End DerivedBasics. Notation "G ^` ( n )" := (derived_at_group G n) : Group_scope. Section Basic_commutator_properties. Variable gT : finGroupType. Implicit Types x y z : gT. Lemma conjg_mulR x y : x ^ y = x * [~ x, y]. Proof. by rewrite mulKVg. Qed. Lemma conjg_Rmul x y : x ^ y = [~ y, x^-1] * x. Proof. by rewrite commgEr invgK mulgKV. Qed. Lemma commMgJ x y z : [~ x * y, z] = [~ x, z] ^ y * [~ y, z]. Proof. by rewrite !commgEr conjgM mulgA -conjMg mulgK. Qed. Lemma commgMJ x y z : [~ x, y * z] = [~ x, z] * [~ x, y] ^ z. Proof. by rewrite !commgEl conjgM -mulgA -conjMg mulKVg. Qed. Lemma commMgR x y z : [~ x * y, z] = [~ x, z] * [~ x, z, y] * [~ y, z]. Proof. by rewrite commMgJ conjg_mulR. Qed. Lemma commgMR x y z : [~ x, y * z] = [~ x, z] * [~ x, y] * [~ x, y, z]. Proof. by rewrite commgMJ conjg_mulR mulgA. Qed. Lemma Hall_Witt_identity x y z : [~ x, y^-1, z] ^ y * [~ y, z^-1, x] ^ z * [~ z, x^-1, y] ^ x = 1. Proof. (* gsimpl *) pose a x y z : gT := x * z * y ^ x. suffices{x y z} hw_aux x y z: [~ x, y^-1, z] ^ y = (a x y z)^-1 * (a y z x). by rewrite !hw_aux 2!mulgA !mulgK mulVg. by rewrite commgEr conjMg -conjgM -conjg_Rmul 2!invMg conjgE !mulgA. Qed. (* the following properties are useful for studying p-groups of class 2 *) Section LeftComm. Variables (i : nat) (x y : gT). Hypothesis cxz : commute x [~ x, y]. Lemma commVg : [~ x^-1, y] = [~ x, y]^-1. Proof. apply/eqP; rewrite commgEl eq_sym eq_invg_mul invgK mulgA -cxz. by rewrite -conjg_mulR -conjMg mulgV conj1g. Qed. Lemma commXg : [~ x ^+ i, y] = [~ x, y] ^+ i. Proof. elim: i => [|i' IHi]; first exact: comm1g. by rewrite !expgS commMgJ /conjg commuteX // mulKg IHi. Qed. End LeftComm. Section RightComm. Variables (i : nat) (x y : gT). Hypothesis cyz : commute y [~ x, y]. Let cyz' := commuteV cyz. Lemma commgV : [~ x, y^-1] = [~ x, y]^-1. Proof. by rewrite -invg_comm commVg -(invg_comm x y) ?invgK. Qed. Lemma commgX : [~ x, y ^+ i] = [~ x, y] ^+ i. Proof. by rewrite -invg_comm commXg -(invg_comm x y) ?expgVn ?invgK. Qed. End RightComm. Section LeftRightComm. Variables (i j : nat) (x y : gT). Hypotheses (cxz : commute x [~ x, y]) (cyz : commute y [~ x, y]). Lemma commXXg : [~ x ^+ i, y ^+ j] = [~ x, y] ^+ (i * j). Proof. by rewrite expgM commgX commXg //; apply: commuteX. Qed. Lemma expMg_Rmul : (y * x) ^+ i = y ^+ i * x ^+ i * [~ x, y] ^+ 'C(i, 2). Proof. rewrite -bin2_sum; symmetry. elim: i => [|k IHk] /=; first by rewrite big_geq ?mulg1. rewrite big_nat_recr //= addnC expgD !expgS -{}IHk !mulgA; congr (_ * _). by rewrite -!mulgA commuteX2 // -commgX // [mulg y]lock 3!mulgA -commgC. Qed. End LeftRightComm. End Basic_commutator_properties. (***** Set theoretic commutators *****) Section Commutator_properties. Variable gT : finGroupType. Implicit Type (rT : finGroupType) (A B C : {set gT}) (D G H K : {group gT}). Lemma commG1 A : [~: A, 1] = 1. Proof. by apply/commG1P; rewrite centsC sub1G. Qed. Lemma comm1G A : [~: 1, A] = 1. Proof. by rewrite commGC commG1. Qed. Lemma commg_sub A B : [~: A, B] \subset A <*> B. Proof. by rewrite comm_subG // (joing_subl, joing_subr). Qed. Lemma commg_norml G A : G \subset 'N([~: G, A]). Proof. apply/subsetP=> x Gx; rewrite inE -genJ gen_subG. apply/subsetP=> _ /imsetP[_ /imset2P[y z Gy Az ->] ->]. by rewrite -(mulgK [~ x, z] (_ ^ x)) -commMgJ !(mem_commg, groupMl, groupV). Qed. Lemma commg_normr G A : G \subset 'N([~: A, G]). Proof. by rewrite commGC commg_norml. Qed. Lemma commg_norm G H : G <*> H \subset 'N([~: G, H]). Proof. by rewrite join_subG ?commg_norml ?commg_normr. Qed. Lemma commg_normal G H : [~: G, H] <| G <*> H. Proof. by rewrite /(_ <| _) commg_sub commg_norm. Qed. Lemma normsRl A G B : A \subset G -> A \subset 'N([~: G, B]). Proof. by move=> sAG; apply: subset_trans (commg_norml G B). Qed. Lemma normsRr A G B : A \subset G -> A \subset 'N([~: B, G]). Proof. by move=> sAG; apply: subset_trans (commg_normr G B). Qed. Lemma commg_subr G H : ([~: G, H] \subset H) = (G \subset 'N(H)). Proof. rewrite gen_subG; apply/subsetP/subsetP=> [sRH x Gx | nGH xy]. rewrite inE; apply/subsetP=> _ /imsetP[y Ky ->]. by rewrite conjg_Rmul groupMr // sRH // imset2_f ?groupV. case/imset2P=> x y Gx Hy ->{xy}. by rewrite commgEr groupMr // memJ_norm (groupV, nGH). Qed. Lemma commg_subl G H : ([~: G, H] \subset G) = (H \subset 'N(G)). Proof. by rewrite commGC commg_subr. Qed. Lemma commg_subI A B G H : A \subset 'N_G(H) -> B \subset 'N_H(G) -> [~: A, B] \subset G :&: H. Proof. rewrite !subsetI -(gen_subG _ 'N(G)) -(gen_subG _ 'N(H)). rewrite -commg_subr -commg_subl; case/andP=> sAG sRH; case/andP=> sBH sRG. by rewrite (subset_trans _ sRG) ?(subset_trans _ sRH) ?commgSS ?subset_gen. Qed. Lemma quotient_cents2 A B K : A \subset 'N(K) -> B \subset 'N(K) -> (A / K \subset 'C(B / K)) = ([~: A, B] \subset K). Proof. move=> nKA nKB. by rewrite (sameP commG1P trivgP) /= -quotientR // quotient_sub1 // comm_subG. Qed. Lemma quotient_cents2r A B K : [~: A, B] \subset K -> (A / K) \subset 'C(B / K). Proof. move=> sABK; rewrite -2![_ / _]morphimIdom -!quotientE. by rewrite quotient_cents2 ?subsetIl ?(subset_trans _ sABK) ?commgSS ?subsetIr. Qed. Lemma sub_der1_norm G H : G^`(1) \subset H -> H \subset G -> G \subset 'N(H). Proof. by move=> sG'H sHG; rewrite -commg_subr (subset_trans _ sG'H) ?commgS. Qed. Lemma sub_der1_normal G H : G^`(1) \subset H -> H \subset G -> H <| G. Proof. by move=> sG'H sHG; rewrite /(H <| G) sHG sub_der1_norm. Qed. Lemma sub_der1_abelian G H : G^`(1) \subset H -> abelian (G / H). Proof. by move=> sG'H; apply: quotient_cents2r. Qed. Lemma der1_min G H : G \subset 'N(H) -> abelian (G / H) -> G^`(1) \subset H. Proof. by move=> nHG abGH; rewrite -quotient_cents2. Qed. Lemma der_abelian n G : abelian (G^`(n) / G^`(n.+1)). Proof. by rewrite sub_der1_abelian // der_subS. Qed. Lemma commg_normSl G H K : G \subset 'N(H) -> [~: G, H] \subset 'N([~: K, H]). Proof. by move=> nHG; rewrite normsRr // commg_subr. Qed. Lemma commg_normSr G H K : G \subset 'N(H) -> [~: H, G] \subset 'N([~: H, K]). Proof. by move=> nHG; rewrite !(commGC H) commg_normSl. Qed. Lemma commMGr G H K : [~: G, K] * [~: H, K] \subset [~: G * H , K]. Proof. by rewrite mul_subG ?commSg ?(mulG_subl, mulG_subr). Qed. Lemma commMG G H K : H \subset 'N([~: G, K]) -> [~: G * H , K] = [~: G, K] * [~: H, K]. Proof. move=> nRH; apply/eqP; rewrite eqEsubset commMGr andbT. have nRHK: [~: H, K] \subset 'N([~: G, K]) by rewrite comm_subG ?commg_normr. have defM := norm_joinEr nRHK; rewrite -defM gen_subG /=. apply/subsetP=> _ /imset2P[_ z /imset2P[x y Gx Hy ->] Kz ->]. by rewrite commMgJ {}defM mem_mulg ?memJ_norm ?mem_commg // (subsetP nRH). Qed. Lemma comm3G1P A B C : reflect {in A & B & C, forall h k l, [~ h, k, l] = 1} ([~: A, B, C] :==: 1). Proof. have R_C := sameP trivgP commG1P. rewrite -subG1 R_C gen_subG -{}R_C gen_subG. apply: (iffP subsetP) => [cABC x y z Ax By Cz | cABC xyz]. by apply/set1P; rewrite cABC // !imset2_f. by case/imset2P=> _ z /imset2P[x y Ax By ->] Cz ->; rewrite cABC. Qed. Lemma three_subgroup G H K : [~: G, H, K] :=: 1 -> [~: H, K, G] :=: 1-> [~: K, G, H] :=: 1. Proof. move/eqP/comm3G1P=> cGHK /eqP/comm3G1P cHKG. apply/eqP/comm3G1P=> x y z Kx Gy Hz; symmetry. rewrite -(conj1g y) -(Hall_Witt_identity y^-1 z x) invgK. by rewrite cGHK ?groupV // cHKG ?groupV // !conj1g !mul1g conjgKV. Qed. Lemma der1_joing_cycles (x y : gT) : let XY := <[x]> <*> <[y]> in let xy := [~ x, y] in xy \in 'C(XY) -> XY^`(1) = <[xy]>. Proof. rewrite joing_idl joing_idr /= -sub_cent1 => /norms_gen nRxy. apply/eqP; rewrite eqEsubset cycle_subG mem_commg ?mem_gen ?set21 ?set22 //. rewrite der1_min // quotient_gen -1?gen_subG // quotientU abelian_gen. rewrite /abelian subUset centU !subsetI andbC centsC -andbA -!abelianE. rewrite !quotient_abelian ?(abelianS (subset_gen _) (cycle_abelian _)) //=. by rewrite andbb quotient_cents2r ?genS // /commg_set imset2_set1l imset_set1. Qed. Lemma commgAC G x y z : x \in G -> y \in G -> z \in G -> commute y z -> abelian [~: [set x], G] -> [~ x, y, z] = [~ x, z, y]. Proof. move=> Gx Gy Gz cyz /centsP cRxG; pose cx' u := [~ x^-1, u]. have xR3 u v: [~ x, u, v] = x^-1 * (cx' u * cx' v) * x ^ (u * v). rewrite mulgA -conjg_mulR conjVg [cx' v]commgEl mulgA -invMg. by rewrite -mulgA conjgM -conjMg -!commgEl. suffices RxGcx' u: u \in G -> cx' u \in [~: [set x], G]. by rewrite !xR3 {}cyz; congr (_ * _ * _); rewrite cRxG ?RxGcx'. move=> Gu; suffices/groupMl <-: [~ x, u] ^ x^-1 \in [~: [set x], G]. by rewrite -commMgJ mulgV comm1g group1. by rewrite memJ_norm ?mem_commg ?set11 // groupV (subsetP (commg_normr _ _)). Qed. (* Aschbacher, exercise 3.6 (used in proofs of Aschbacher 24.7 and B & G 1.10 *) Lemma comm_norm_cent_cent H G K : H \subset 'N(G) -> H \subset 'C(K) -> G \subset 'N(K) -> [~: G, H] \subset 'C(K). Proof. move=> nGH /centsP cKH nKG; rewrite commGC gen_subG centsC. apply/centsP=> x Kx _ /imset2P[y z Hy Gz ->]; red. rewrite mulgA -[x * _]cKH ?groupV // -!mulgA; congr (_ * _). rewrite (mulgA x) (conjgC x) (conjgCV z) 3!mulgA; congr (_ * _). by rewrite -2!mulgA (cKH y) // -mem_conjg (normsP nKG). Qed. Lemma charR H K G : H \char G -> K \char G -> [~: H, K] \char G. Proof. case/charP=> sHG chH /charP[sKG chK]; apply/charP. by split=> [|f infj Gf]; [rewrite comm_subG | rewrite morphimR // chH // chK]. Qed. Lemma der_char n G : G^`(n) \char G. Proof. by elim: n => [|n IHn]; rewrite ?char_refl // dergSn charR. Qed. Lemma der_sub n G : G^`(n) \subset G. Proof. by rewrite char_sub ?der_char. Qed. Lemma der_norm n G : G \subset 'N(G^`(n)). Proof. by rewrite char_norm ?der_char. Qed. Lemma der_normal n G : G^`(n) <| G. Proof. by rewrite char_normal ?der_char. Qed. Lemma der_subS n G : G^`(n.+1) \subset G^`(n). Proof. by rewrite comm_subG. Qed. Lemma der_normalS n G : G^`(n.+1) <| G^`(n). Proof. by rewrite sub_der1_normal // der_subS. Qed. Lemma morphim_der rT D (f : {morphism D >-> rT}) n G : G \subset D -> f @* G^`(n) = (f @* G)^`(n). Proof. move=> sGD; elim: n => // n IHn. by rewrite !dergSn -IHn morphimR ?(subset_trans (der_sub n G)). Qed. Lemma dergS n G H : G \subset H -> G^`(n) \subset H^`(n). Proof. by move=> sGH; elim: n => // n IHn; apply: commgSS. Qed. Lemma quotient_der n G H : G \subset 'N(H) -> G^`(n) / H = (G / H)^`(n). Proof. exact: morphim_der. Qed. Lemma derJ G n x : (G :^ x)^`(n) = G^`(n) :^ x. Proof. by elim: n => //= n IHn; rewrite !dergSn IHn -conjsRg. Qed. Lemma derG1P G : reflect (G^`(1) = 1) (abelian G). Proof. exact: commG1P. Qed. End Commutator_properties. Arguments derG1P {gT G}. Lemma der_cont n : GFunctor.continuous (@derived_at n). Proof. by move=> aT rT G f; rewrite morphim_der. Qed. Canonical der_igFun n := [igFun by der_sub^~ n & der_cont n]. Canonical der_gFun n := [gFun by der_cont n]. Canonical der_mgFun n := [mgFun by dergS^~ n]. Lemma isog_der (aT rT : finGroupType) n (G : {group aT}) (H : {group rT}) : G \isog H -> G^`(n) \isog H^`(n). Proof. exact: gFisog. Qed.
Extensions.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.Algebra.Homology.ShortComplex.ShortExact import Mathlib.CategoryTheory.ObjectProperty.Basic /-! # Properties of objects that are closed under extensions Given a category `C` and `P : ObjectProperty C`, we define a type class `P.IsClosedUnderExtensions` expressing that the property is closed under extensions. -/ universe v v' u u' namespace CategoryTheory open Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] namespace ObjectProperty variable (P : ObjectProperty C) section variable [HasZeroMorphisms C] /-- Given `P : ObjectProperty C`, we say that `P` is closed under extensions if whenever `0 ⟶ X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` is a short exact short complex, then `P X₁` and `P X₃` implies `P X₂`. -/ class IsClosedUnderExtensions : Prop where prop_X₂_of_shortExact {S : ShortComplex C} (hS : S.ShortExact) (h₁ : P S.X₁) (h₃ : P S.X₃) : P S.X₂ lemma prop_X₂_of_shortExact [P.IsClosedUnderExtensions] {S : ShortComplex C} (hS : S.ShortExact) (h₁ : P S.X₁) (h₃ : P S.X₃) : P S.X₂ := IsClosedUnderExtensions.prop_X₂_of_shortExact hS h₁ h₃ instance : (⊤ : ObjectProperty C).IsClosedUnderExtensions where prop_X₂_of_shortExact := by simp instance : IsClosedUnderExtensions (IsZero (C := C)) where prop_X₂_of_shortExact hS h₁ h₃ := hS.exact.isZero_of_both_zeros (h₁.eq_of_src _ _) (h₃.eq_of_tgt _ _) instance [P.IsClosedUnderExtensions] (F : D ⥤ C) [HasZeroMorphisms D] [F.PreservesZeroMorphisms] [PreservesFiniteLimits F] [PreservesFiniteColimits F] : (P.inverseImage F).IsClosedUnderExtensions where prop_X₂_of_shortExact hS h₁ h₃ := by have := hS.mono_f have := hS.epi_g exact P.prop_X₂_of_shortExact (hS.map F) h₁ h₃ end lemma prop_biprod {X₁ X₂ : C} (h₁ : P X₁) (h₂ : P X₂) [Preadditive C] [HasZeroObject C] [P.IsClosedUnderExtensions] [HasBinaryBiproduct X₁ X₂] : P (X₁ ⊞ X₂) := P.prop_X₂_of_shortExact (ShortComplex.Splitting.ofHasBinaryBiproduct X₁ X₂).shortExact h₁ h₂ end ObjectProperty end CategoryTheory
SnakeLemma.lean
/- Copyright (c) 2023 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.ExactSequence import Mathlib.Algebra.Homology.ShortComplex.Limits import Mathlib.CategoryTheory.Abelian.Refinements /-! # The snake lemma The snake lemma is a standard tool in homological algebra. The basic situation is when we have a diagram as follows in an abelian category `C`, with exact rows: L₁.X₁ ⟶ L₁.X₂ ⟶ L₁.X₃ ⟶ 0 | | | |v₁₂.τ₁ |v₁₂.τ₂ |v₁₂.τ₃ v v v 0 ⟶ L₂.X₁ ⟶ L₂.X₂ ⟶ L₂.X₃ We shall think of this diagram as the datum of a morphism `v₁₂ : L₁ ⟶ L₂` in the category `ShortComplex C` such that both `L₁` and `L₂` are exact, and `L₁.g` is epi and `L₂.f` is a mono (which is equivalent to saying that `L₁.X₃` is the cokernel of `L₁.f` and `L₂.X₁` is the kernel of `L₂.g`). Then, we may introduce the kernels and cokernels of the vertical maps. In other words, we may introduce short complexes `L₀` and `L₃` that are respectively the kernel and the cokernel of `v₁₂`. All these data constitute a `SnakeInput C`. Given such a `S : SnakeInput C`, we define a connecting homomorphism `S.δ : L₀.X₃ ⟶ L₃.X₁` and show that it is part of an exact sequence `L₀.X₁ ⟶ L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂ ⟶ L₃.X₃`. Each of the four exactness statement is first stated separately as lemmas `L₀_exact`, `L₁'_exact`, `L₂'_exact` and `L₃_exact` and the full 6-term exact sequence is stated as `snake_lemma`. This sequence can even be extended with an extra `0` on the left (see `mono_L₀_f`) if `L₁.X₁ ⟶ L₁.X₂` is a mono (i.e. `L₁` is short exact), and similarly an extra `0` can be added on the right (`epi_L₃_g`) if `L₂.X₂ ⟶ L₂.X₃` is an epi (i.e. `L₂` is short exact). These results were also obtained in the Liquid Tensor Experiment. The code and the proof here are slightly easier because of the use of the category `ShortComplex C`, the use of duality (which allows to construct only half of the sequence, and deducing the other half by arguing in the opposite category), and the use of "refinements" (see `CategoryTheory.Abelian.Refinements`) instead of a weak form of pseudo-elements. -/ namespace CategoryTheory open Category Limits Preadditive variable (C : Type*) [Category C] [Abelian C] namespace ShortComplex /-- A snake input in an abelian category `C` consists of morphisms of short complexes `L₀ ⟶ L₁ ⟶ L₂ ⟶ L₃` (which should be visualized vertically) such that `L₀` and `L₃` are respectively the kernel and the cokernel of `L₁ ⟶ L₂`, `L₁` and `L₂` are exact, `L₁.g` is epi and `L₂.f` is mono. -/ structure SnakeInput where /-- the zeroth row -/ L₀ : ShortComplex C /-- the first row -/ L₁ : ShortComplex C /-- the second row -/ L₂ : ShortComplex C /-- the third row -/ L₃ : ShortComplex C /-- the morphism from the zeroth row to the first row -/ v₀₁ : L₀ ⟶ L₁ /-- the morphism from the first row to the second row -/ v₁₂ : L₁ ⟶ L₂ /-- the morphism from the second row to the third row -/ v₂₃ : L₂ ⟶ L₃ w₀₂ : v₀₁ ≫ v₁₂ = 0 := by cat_disch w₁₃ : v₁₂ ≫ v₂₃ = 0 := by cat_disch /-- `L₀` is the kernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₀ : IsLimit (KernelFork.ofι _ w₀₂) /-- `L₃` is the cokernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₃ : IsColimit (CokernelCofork.ofπ _ w₁₃) L₁_exact : L₁.Exact epi_L₁_g : Epi L₁.g L₂_exact : L₂.Exact mono_L₂_f : Mono L₂.f initialize_simps_projections SnakeInput (-h₀, -h₃) namespace SnakeInput attribute [reassoc (attr := simp)] w₀₂ w₁₃ attribute [instance] epi_L₁_g attribute [instance] mono_L₂_f variable {C} variable (S : SnakeInput C) /-- The snake input in the opposite category that is deduced from a snake input. -/ @[simps] noncomputable def op : SnakeInput Cᵒᵖ where L₀ := S.L₃.op L₁ := S.L₂.op L₂ := S.L₁.op L₃ := S.L₀.op epi_L₁_g := by dsimp; infer_instance mono_L₂_f := by dsimp; infer_instance v₀₁ := opMap S.v₂₃ v₁₂ := opMap S.v₁₂ v₂₃ := opMap S.v₀₁ w₀₂ := congr_arg opMap S.w₁₃ w₁₃ := congr_arg opMap S.w₀₂ h₀ := isLimitForkMapOfIsLimit' (ShortComplex.opEquiv C).functor _ (CokernelCofork.IsColimit.ofπOp _ _ S.h₃) h₃ := isColimitCoforkMapOfIsColimit' (ShortComplex.opEquiv C).functor _ (KernelFork.IsLimit.ofιOp _ _ S.h₀) L₁_exact := S.L₂_exact.op L₂_exact := S.L₁_exact.op @[reassoc (attr := simp)] lemma w₀₂_τ₁ : S.v₀₁.τ₁ ≫ S.v₁₂.τ₁ = 0 := by rw [← comp_τ₁, S.w₀₂, zero_τ₁] @[reassoc (attr := simp)] lemma w₀₂_τ₂ : S.v₀₁.τ₂ ≫ S.v₁₂.τ₂ = 0 := by rw [← comp_τ₂, S.w₀₂, zero_τ₂] @[reassoc (attr := simp)] lemma w₀₂_τ₃ : S.v₀₁.τ₃ ≫ S.v₁₂.τ₃ = 0 := by rw [← comp_τ₃, S.w₀₂, zero_τ₃] @[reassoc (attr := simp)] lemma w₁₃_τ₁ : S.v₁₂.τ₁ ≫ S.v₂₃.τ₁ = 0 := by rw [← comp_τ₁, S.w₁₃, zero_τ₁] @[reassoc (attr := simp)] lemma w₁₃_τ₂ : S.v₁₂.τ₂ ≫ S.v₂₃.τ₂ = 0 := by rw [← comp_τ₂, S.w₁₃, zero_τ₂] @[reassoc (attr := simp)] lemma w₁₃_τ₃ : S.v₁₂.τ₃ ≫ S.v₂₃.τ₃ = 0 := by rw [← comp_τ₃, S.w₁₃, zero_τ₃] /-- `L₀.X₁` is the kernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₀τ₁ : IsLimit (KernelFork.ofι S.v₀₁.τ₁ S.w₀₂_τ₁) := isLimitForkMapOfIsLimit' π₁ S.w₀₂ S.h₀ /-- `L₀.X₂` is the kernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₀τ₂ : IsLimit (KernelFork.ofι S.v₀₁.τ₂ S.w₀₂_τ₂) := isLimitForkMapOfIsLimit' π₂ S.w₀₂ S.h₀ /-- `L₀.X₃` is the kernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₀τ₃ : IsLimit (KernelFork.ofι S.v₀₁.τ₃ S.w₀₂_τ₃) := isLimitForkMapOfIsLimit' π₃ S.w₀₂ S.h₀ instance mono_v₀₁_τ₁ : Mono S.v₀₁.τ₁ := mono_of_isLimit_fork S.h₀τ₁ instance mono_v₀₁_τ₂ : Mono S.v₀₁.τ₂ := mono_of_isLimit_fork S.h₀τ₂ instance mono_v₀₁_τ₃ : Mono S.v₀₁.τ₃ := mono_of_isLimit_fork S.h₀τ₃ /-- The upper part of the first column of the snake diagram is exact. -/ lemma exact_C₁_up : (ShortComplex.mk S.v₀₁.τ₁ S.v₁₂.τ₁ (by rw [← comp_τ₁, S.w₀₂, zero_τ₁])).Exact := exact_of_f_is_kernel _ S.h₀τ₁ /-- The upper part of the second column of the snake diagram is exact. -/ lemma exact_C₂_up : (ShortComplex.mk S.v₀₁.τ₂ S.v₁₂.τ₂ (by rw [← comp_τ₂, S.w₀₂, zero_τ₂])).Exact := exact_of_f_is_kernel _ S.h₀τ₂ /-- The upper part of the third column of the snake diagram is exact. -/ lemma exact_C₃_up : (ShortComplex.mk S.v₀₁.τ₃ S.v₁₂.τ₃ (by rw [← comp_τ₃, S.w₀₂, zero_τ₃])).Exact := exact_of_f_is_kernel _ S.h₀τ₃ instance mono_L₀_f [Mono S.L₁.f] : Mono S.L₀.f := by have : Mono (S.L₀.f ≫ S.v₀₁.τ₂) := by rw [← S.v₀₁.comm₁₂] apply mono_comp exact mono_of_mono _ S.v₀₁.τ₂ /-- `L₃.X₁` is the cokernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₃τ₁ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₁ S.w₁₃_τ₁) := isColimitCoforkMapOfIsColimit' π₁ S.w₁₃ S.h₃ /-- `L₃.X₂` is the cokernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₃τ₂ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₂ S.w₁₃_τ₂) := isColimitCoforkMapOfIsColimit' π₂ S.w₁₃ S.h₃ /-- `L₃.X₃` is the cokernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₃τ₃ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₃ S.w₁₃_τ₃) := isColimitCoforkMapOfIsColimit' π₃ S.w₁₃ S.h₃ instance epi_v₂₃_τ₁ : Epi S.v₂₃.τ₁ := epi_of_isColimit_cofork S.h₃τ₁ instance epi_v₂₃_τ₂ : Epi S.v₂₃.τ₂ := epi_of_isColimit_cofork S.h₃τ₂ instance epi_v₂₃_τ₃ : Epi S.v₂₃.τ₃ := epi_of_isColimit_cofork S.h₃τ₃ /-- The lower part of the first column of the snake diagram is exact. -/ lemma exact_C₁_down : (ShortComplex.mk S.v₁₂.τ₁ S.v₂₃.τ₁ (by rw [← comp_τ₁, S.w₁₃, zero_τ₁])).Exact := exact_of_g_is_cokernel _ S.h₃τ₁ /-- The lower part of the second column of the snake diagram is exact. -/ lemma exact_C₂_down : (ShortComplex.mk S.v₁₂.τ₂ S.v₂₃.τ₂ (by rw [← comp_τ₂, S.w₁₃, zero_τ₂])).Exact := exact_of_g_is_cokernel _ S.h₃τ₂ /-- The lower part of the third column of the snake diagram is exact. -/ lemma exact_C₃_down : (ShortComplex.mk S.v₁₂.τ₃ S.v₂₃.τ₃ (by rw [← comp_τ₃, S.w₁₃, zero_τ₃])).Exact := exact_of_g_is_cokernel _ S.h₃τ₃ instance epi_L₃_g [Epi S.L₂.g] : Epi S.L₃.g := by have : Epi (S.v₂₃.τ₂ ≫ S.L₃.g) := by rw [S.v₂₃.comm₂₃] apply epi_comp exact epi_of_epi S.v₂₃.τ₂ _ lemma L₀_exact : S.L₀.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ obtain ⟨A₁, π₁, hπ₁, y₁, hy₁⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ S.v₀₁.τ₂) (by rw [assoc, S.v₀₁.comm₂₃, reassoc_of% hx₂, zero_comp]) have hy₁' : y₁ ≫ S.v₁₂.τ₁ = 0 := by simp only [← cancel_mono S.L₂.f, assoc, zero_comp, S.v₁₂.comm₁₂, ← reassoc_of% hy₁, w₀₂_τ₂, comp_zero] obtain ⟨x₁, hx₁⟩ : ∃ x₁, x₁ ≫ S.v₀₁.τ₁ = y₁ := ⟨_, S.exact_C₁_up.lift_f y₁ hy₁'⟩ refine ⟨A₁, π₁, hπ₁, x₁, ?_⟩ simp only [← cancel_mono S.v₀₁.τ₂, assoc, ← S.v₀₁.comm₁₂, reassoc_of% hx₁, hy₁] lemma L₃_exact : S.L₃.Exact := S.op.L₀_exact.unop /-- The fiber product of `L₁.X₂` and `L₀.X₃` over `L₁.X₃`. This is an auxiliary object in the construction of the morphism `δ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def P := pullback S.L₁.g S.v₀₁.τ₃ /-- The canonical map `P ⟶ L₂.X₂`. -/ noncomputable def φ₂ : S.P ⟶ S.L₂.X₂ := pullback.fst _ _ ≫ S.v₁₂.τ₂ @[reassoc (attr := simp)] lemma lift_φ₂ {A : C} (a : A ⟶ S.L₁.X₂) (b : A ⟶ S.L₀.X₃) (h : a ≫ S.L₁.g = b ≫ S.v₀₁.τ₃) : pullback.lift a b h ≫ S.φ₂ = a ≫ S.v₁₂.τ₂ := by simp [φ₂] /-- The canonical map `P ⟶ L₂.X₁`. -/ noncomputable def φ₁ : S.P ⟶ S.L₂.X₁ := S.L₂_exact.lift S.φ₂ (by simp only [φ₂, assoc, S.v₁₂.comm₂₃, pullback.condition_assoc, w₀₂_τ₃, comp_zero]) @[reassoc (attr := simp)] lemma φ₁_L₂_f : S.φ₁ ≫ S.L₂.f = S.φ₂ := S.L₂_exact.lift_f _ _ /-- The short complex that is part of an exact sequence `L₁.X₁ ⟶ P ⟶ L₀.X₃ ⟶ 0`. -/ noncomputable def L₀' : ShortComplex C where X₁ := S.L₁.X₁ X₂ := S.P X₃ := S.L₀.X₃ f := pullback.lift S.L₁.f 0 (by simp) g := pullback.snd _ _ zero := by simp @[reassoc (attr := simp)] lemma L₁_f_φ₁ : S.L₀'.f ≫ S.φ₁ = S.v₁₂.τ₁ := by dsimp only [L₀'] simp only [← cancel_mono S.L₂.f, assoc, φ₁_L₂_f, φ₂, pullback.lift_fst_assoc, S.v₁₂.comm₁₂] instance : Epi S.L₀'.g := by dsimp only [L₀']; infer_instance instance [Mono S.L₁.f] : Mono S.L₀'.f := mono_of_mono_fac (show S.L₀'.f ≫ pullback.fst _ _ = S.L₁.f by simp [L₀']) lemma L₀'_exact : S.L₀'.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ dsimp [L₀'] at x₂ hx₂ obtain ⟨A', π, hπ, x₁, fac⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ pullback.fst _ _) (by rw [assoc, pullback.condition, reassoc_of% hx₂, zero_comp]) exact ⟨A', π, hπ, x₁, pullback.hom_ext (by simpa [L₀'] using fac) (by simp [L₀', hx₂])⟩ /-- The connecting homomorphism `δ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def δ : S.L₀.X₃ ⟶ S.L₃.X₁ := S.L₀'_exact.desc (S.φ₁ ≫ S.v₂₃.τ₁) (by simp only [L₁_f_φ₁_assoc, w₁₃_τ₁]) @[reassoc (attr := simp)] lemma snd_δ : (pullback.snd _ _ : S.P ⟶ _) ≫ S.δ = S.φ₁ ≫ S.v₂₃.τ₁ := S.L₀'_exact.g_desc _ _ /-- The pushout of `L₂.X₂` and `L₃.X₁` along `L₂.X₁`. -/ noncomputable def P' := pushout S.L₂.f S.v₂₃.τ₁ lemma snd_δ_inr : (pullback.snd _ _ : S.P ⟶ _) ≫ S.δ ≫ (pushout.inr _ _ : _ ⟶ S.P') = pullback.fst _ _ ≫ S.v₁₂.τ₂ ≫ pushout.inl _ _ := by simp only [snd_δ_assoc, ← pushout.condition, φ₂, φ₁_L₂_f_assoc, assoc] /-- The canonical morphism `L₀.X₂ ⟶ P`. -/ @[simp] noncomputable def L₀X₂ToP : S.L₀.X₂ ⟶ S.P := pullback.lift S.v₀₁.τ₂ S.L₀.g S.v₀₁.comm₂₃ @[reassoc] lemma L₀X₂ToP_comp_pullback_snd : S.L₀X₂ToP ≫ pullback.snd _ _ = S.L₀.g := by simp @[reassoc] lemma L₀X₂ToP_comp_φ₁ : S.L₀X₂ToP ≫ S.φ₁ = 0 := by simp only [← cancel_mono S.L₂.f, L₀X₂ToP, assoc, φ₂, φ₁_L₂_f, pullback.lift_fst_assoc, w₀₂_τ₂, zero_comp] lemma L₀_g_δ : S.L₀.g ≫ S.δ = 0 := by rw [← L₀X₂ToP_comp_pullback_snd, assoc] erw [S.L₀'_exact.g_desc] rw [L₀X₂ToP_comp_φ₁_assoc, zero_comp] lemma δ_L₃_f : S.δ ≫ S.L₃.f = 0 := by rw [← cancel_epi S.L₀'.g] erw [S.L₀'_exact.g_desc_assoc] simp [S.v₂₃.comm₁₂, φ₂] /-- The short complex `L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁`. -/ @[simps] noncomputable def L₁' : ShortComplex C := ShortComplex.mk _ _ S.L₀_g_δ /-- The short complex `L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂`. -/ @[simps] noncomputable def L₂' : ShortComplex C := ShortComplex.mk _ _ S.δ_L₃_f /-- Exactness of `L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁`. -/ lemma L₁'_exact : S.L₁'.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A₀ x₃ hx₃ dsimp at x₃ hx₃ obtain ⟨A₁, π₁, hπ₁, p, hp⟩ := surjective_up_to_refinements_of_epi S.L₀'.g x₃ dsimp [L₀'] at p hp have hp' : (p ≫ S.φ₁) ≫ S.v₂₃.τ₁ = 0 := by rw [assoc, ← S.snd_δ, ← reassoc_of% hp, hx₃, comp_zero] obtain ⟨A₂, π₂, hπ₂, x₁, hx₁⟩ := S.exact_C₁_down.exact_up_to_refinements (p ≫ S.φ₁) hp' dsimp at x₁ hx₁ let x₂' := x₁ ≫ S.L₁.f let x₂ := π₂ ≫ p ≫ pullback.fst _ _ have hx₂' : (x₂ - x₂') ≫ S.v₁₂.τ₂ = 0 := by simp only [x₂, x₂', sub_comp, assoc, ← S.v₁₂.comm₁₂, ← reassoc_of% hx₁, φ₂, φ₁_L₂_f, sub_self] let k₂ : A₂ ⟶ S.L₀.X₂ := S.exact_C₂_up.lift _ hx₂' have hk₂ : k₂ ≫ S.v₀₁.τ₂ = x₂ - x₂' := S.exact_C₂_up.lift_f _ _ have hk₂' : k₂ ≫ S.L₀.g = π₂ ≫ p ≫ pullback.snd _ _ := by simp only [x₂, x₂', ← cancel_mono S.v₀₁.τ₃, assoc, ← S.v₀₁.comm₂₃, reassoc_of% hk₂, sub_comp, S.L₁.zero, comp_zero, sub_zero, pullback.condition] exact ⟨A₂, π₂ ≫ π₁, epi_comp _ _, k₂, by simp only [assoc, L₁'_f, ← hk₂', hp]⟩ /-- The duality isomorphism `S.P ≅ Opposite.unop S.op.P'`. -/ noncomputable def PIsoUnopOpP' : S.P ≅ Opposite.unop S.op.P' := pullbackIsoUnopPushout _ _ /-- The duality isomorphism `S.P' ≅ Opposite.unop S.op.P`. -/ noncomputable def P'IsoUnopOpP : S.P' ≅ Opposite.unop S.op.P := pushoutIsoUnopPullback _ _ lemma op_δ : S.op.δ = S.δ.op := Quiver.Hom.unop_inj (by rw [Quiver.Hom.unop_op, ← cancel_mono (pushout.inr _ _ : _ ⟶ S.P'), ← cancel_epi (pullback.snd _ _ : S.P ⟶ _), S.snd_δ_inr, ← cancel_mono S.P'IsoUnopOpP.hom, ← cancel_epi S.PIsoUnopOpP'.inv, P'IsoUnopOpP, PIsoUnopOpP', assoc, assoc, assoc, assoc, pushoutIsoUnopPullback_inr_hom, pullbackIsoUnopPushout_inv_snd_assoc, pushoutIsoUnopPullback_inl_hom, pullbackIsoUnopPushout_inv_fst_assoc] apply Quiver.Hom.op_inj simpa only [op_comp, Quiver.Hom.op_unop, assoc] using S.op.snd_δ_inr) /-- The duality isomorphism `S.L₂'.op ≅ S.op.L₁'`. -/ noncomputable def L₂'OpIso : S.L₂'.op ≅ S.op.L₁' := ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) (by simp) (by dsimp; simp only [id_comp, comp_id, S.op_δ]) /-- Exactness of `L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂`. -/ lemma L₂'_exact : S.L₂'.Exact := by rw [← exact_op_iff, exact_iff_of_iso S.L₂'OpIso] exact S.op.L₁'_exact /-- The diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃` for any `S : SnakeInput C`. -/ noncomputable abbrev composableArrows : ComposableArrows C 5 := ComposableArrows.mk₅ S.L₀.f S.L₀.g S.δ S.L₃.f S.L₃.g open ComposableArrows in /-- The diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃` is exact for any `S : SnakeInput C`. -/ lemma snake_lemma : S.composableArrows.Exact := exact_of_δ₀ S.L₀_exact.exact_toComposableArrows (exact_of_δ₀ S.L₁'_exact.exact_toComposableArrows (exact_of_δ₀ S.L₂'_exact.exact_toComposableArrows S.L₃_exact.exact_toComposableArrows)) lemma δ_eq {A : C} (x₃ : A ⟶ S.L₀.X₃) (x₂ : A ⟶ S.L₁.X₂) (x₁ : A ⟶ S.L₂.X₁) (h₂ : x₂ ≫ S.L₁.g = x₃ ≫ S.v₀₁.τ₃) (h₁ : x₁ ≫ S.L₂.f = x₂ ≫ S.v₁₂.τ₂) : x₃ ≫ S.δ = x₁ ≫ S.v₂₃.τ₁ := by have H := (pullback.lift x₂ x₃ h₂) ≫= S.snd_δ rw [pullback.lift_snd_assoc] at H rw [H, ← assoc] congr 1 simp only [← cancel_mono S.L₂.f, assoc, φ₁_L₂_f, lift_φ₂, h₁] theorem mono_δ (h₀ : IsZero S.L₀.X₂) : Mono S.δ := (S.L₁'.exact_iff_mono (IsZero.eq_zero_of_src h₀ S.L₁'.f)).1 S.L₁'_exact theorem epi_δ (h₃ : IsZero S.L₃.X₂) : Epi S.δ := (S.L₂'.exact_iff_epi (IsZero.eq_zero_of_tgt h₃ S.L₂'.g)).1 S.L₂'_exact theorem isIso_δ (h₀ : IsZero S.L₀.X₂) (h₃ : IsZero S.L₃.X₂) : IsIso S.δ := @Balanced.isIso_of_mono_of_epi _ _ _ _ _ S.δ (S.mono_δ h₀) (S.epi_δ h₃) /-- When `L₀₂` and `L₃₂` are trivial, `δ` defines an isomorphism `L₀₃ ≅ L₃₁`. -/ noncomputable def δIso (h₀ : IsZero S.L₀.X₂) (h₃ : IsZero S.L₃.X₂) : S.L₀.X₃ ≅ S.L₃.X₁ := @asIso _ _ _ _ S.δ (SnakeInput.isIso_δ S h₀ h₃) variable (S₁ S₂ S₃ : SnakeInput C) /-- A morphism of snake inputs involve four morphisms of short complexes which make the obvious diagram commute. -/ @[ext] structure Hom where /-- a morphism between the zeroth lines -/ f₀ : S₁.L₀ ⟶ S₂.L₀ /-- a morphism between the first lines -/ f₁ : S₁.L₁ ⟶ S₂.L₁ /-- a morphism between the second lines -/ f₂ : S₁.L₂ ⟶ S₂.L₂ /-- a morphism between the third lines -/ f₃ : S₁.L₃ ⟶ S₂.L₃ comm₀₁ : f₀ ≫ S₂.v₀₁ = S₁.v₀₁ ≫ f₁ := by cat_disch comm₁₂ : f₁ ≫ S₂.v₁₂ = S₁.v₁₂ ≫ f₂ := by cat_disch comm₂₃ : f₂ ≫ S₂.v₂₃ = S₁.v₂₃ ≫ f₃ := by cat_disch namespace Hom attribute [reassoc] comm₀₁ comm₁₂ comm₂₃ /-- The identity morphism of a snake input. -/ @[simps] def id : Hom S S where f₀ := 𝟙 _ f₁ := 𝟙 _ f₂ := 𝟙 _ f₃ := 𝟙 _ variable {S₁ S₂ S₃} /-- The composition of morphisms of snake inputs. -/ @[simps] def comp (f : Hom S₁ S₂) (g : Hom S₂ S₃) : Hom S₁ S₃ where f₀ := f.f₀ ≫ g.f₀ f₁ := f.f₁ ≫ g.f₁ f₂ := f.f₂ ≫ g.f₂ f₃ := f.f₃ ≫ g.f₃ comm₀₁ := by simp only [assoc, comm₀₁, comm₀₁_assoc] comm₁₂ := by simp only [assoc, comm₁₂, comm₁₂_assoc] comm₂₃ := by simp only [assoc, comm₂₃, comm₂₃_assoc] end Hom instance : Category (SnakeInput C) where Hom := Hom id := Hom.id comp := Hom.comp variable {S₁ S₂ S₃} @[simp] lemma id_f₀ : Hom.f₀ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₁ : Hom.f₁ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₂ : Hom.f₂ (𝟙 S) = 𝟙 _ := rfl @[simp] lemma id_f₃ : Hom.f₃ (𝟙 S) = 𝟙 _ := rfl section variable (f : S₁ ⟶ S₂) (g : S₂ ⟶ S₃) @[simp, reassoc] lemma comp_f₀ : (f ≫ g).f₀ = f.f₀ ≫ g.f₀ := rfl @[simp, reassoc] lemma comp_f₁ : (f ≫ g).f₁ = f.f₁ ≫ g.f₁ := rfl @[simp, reassoc] lemma comp_f₂ : (f ≫ g).f₂ = f.f₂ ≫ g.f₂ := rfl @[simp, reassoc] lemma comp_f₃ : (f ≫ g).f₃ = f.f₃ ≫ g.f₃ := rfl end /-- The functor which sends `S : SnakeInput C` to its zeroth line `S.L₀`. -/ @[simps] def functorL₀ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₀ map f := f.f₀ /-- The functor which sends `S : SnakeInput C` to its zeroth line `S.L₁`. -/ @[simps] def functorL₁ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₁ map f := f.f₁ /-- The functor which sends `S : SnakeInput C` to its second line `S.L₂`. -/ @[simps] def functorL₂ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₂ map f := f.f₂ /-- The functor which sends `S : SnakeInput C` to its third line `S.L₃`. -/ @[simps] def functorL₃ : SnakeInput C ⥤ ShortComplex C where obj S := S.L₃ map f := f.f₃ /-- The functor which sends `S : SnakeInput C` to the auxiliary object `S.P`, which is `pullback S.L₁.g S.v₀₁.τ₃`. -/ @[simps] noncomputable def functorP : SnakeInput C ⥤ C where obj S := S.P map f := pullback.map _ _ _ _ f.f₁.τ₂ f.f₀.τ₃ f.f₁.τ₃ f.f₁.comm₂₃.symm (congr_arg ShortComplex.Hom.τ₃ f.comm₀₁.symm) map_id _ := by dsimp [P]; simp map_comp _ _ := by dsimp [P]; cat_disch @[reassoc] lemma naturality_φ₂ (f : S₁ ⟶ S₂) : S₁.φ₂ ≫ f.f₂.τ₂ = functorP.map f ≫ S₂.φ₂ := by dsimp [φ₂] simp only [assoc, pullback.lift_fst_assoc, ← comp_τ₂, f.comm₁₂] @[reassoc] lemma naturality_φ₁ (f : S₁ ⟶ S₂) : S₁.φ₁ ≫ f.f₂.τ₁ = functorP.map f ≫ S₂.φ₁ := by simp only [← cancel_mono S₂.L₂.f, assoc, φ₁_L₂_f, ← naturality_φ₂, f.f₂.comm₁₂, φ₁_L₂_f_assoc] @[reassoc] lemma naturality_δ (f : S₁ ⟶ S₂) : S₁.δ ≫ f.f₃.τ₁ = f.f₀.τ₃ ≫ S₂.δ := by rw [← cancel_epi (pullback.snd _ _ : S₁.P ⟶ _), S₁.snd_δ_assoc, ← comp_τ₁, ← f.comm₂₃, comp_τ₁, naturality_φ₁_assoc, ← S₂.snd_δ, functorP_map, pullback.lift_snd_assoc, assoc] /-- The functor which sends `S : SnakeInput C` to `S.L₁'` which is `S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁`. -/ @[simps] noncomputable def functorL₁' : SnakeInput C ⥤ ShortComplex C where obj S := S.L₁' map f := { τ₁ := f.f₀.τ₂ τ₂ := f.f₀.τ₃ τ₃ := f.f₃.τ₁ comm₁₂ := f.f₀.comm₂₃ comm₂₃ := (naturality_δ f).symm } /-- The functor which sends `S : SnakeInput C` to `S.L₂'` which is `S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂`. -/ @[simps] noncomputable def functorL₂' : SnakeInput C ⥤ ShortComplex C where obj S := S.L₂' map f := { τ₁ := f.f₀.τ₃ τ₂ := f.f₃.τ₁ τ₃ := f.f₃.τ₂ comm₁₂ := (naturality_δ f).symm comm₂₃ := f.f₃.comm₁₂ } /-- The functor which maps `S : SnakeInput C` to the diagram `S.L₀.X₁ ⟶ S.L₀.X₂ ⟶ S.L₀.X₃ ⟶ S.L₃.X₁ ⟶ S.L₃.X₂ ⟶ S.L₃.X₃`. -/ @[simps] noncomputable def composableArrowsFunctor : SnakeInput C ⥤ ComposableArrows C 5 where obj S := S.composableArrows map f := ComposableArrows.homMk₅ f.f₀.τ₁ f.f₀.τ₂ f.f₀.τ₃ f.f₃.τ₁ f.f₃.τ₂ f.f₃.τ₃ f.f₀.comm₁₂.symm f.f₀.comm₂₃.symm (naturality_δ f) f.f₃.comm₁₂.symm f.f₃.comm₂₃.symm end SnakeInput end ShortComplex end CategoryTheory
ContinuousMonoidHom.lean
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Nailin Guan -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Topology.Algebra.Group.Defs /-! # Continuous Monoid Homs This file defines the space of continuous homomorphisms between two topological groups. ## Main definitions * `ContinuousMonoidHom A B`: The continuous homomorphisms `A →* B`. * `ContinuousAddMonoidHom A B`: The continuous additive homomorphisms `A →+ B`. -/ assert_not_exists ContinuousLinearMap assert_not_exists ContinuousLinearEquiv section open Function Topology variable (F A B C D E : Type*) variable [Monoid A] [Monoid B] [Monoid C] [Monoid D] variable [TopologicalSpace A] [TopologicalSpace B] [TopologicalSpace C] [TopologicalSpace D] /-- The type of continuous additive monoid homomorphisms from `A` to `B`. When possible, instead of parametrizing results over `(f : ContinuousAddMonoidHom A B)`, you should parametrize over `(F : Type*) [FunLike F A B] [ContinuousMapClass F A B] [AddMonoidHomClass F A B] (f : F)`. When you extend this structure, make sure to extend `ContinuousMapClass` and/or `AddMonoidHomClass`, if needed. -/ structure ContinuousAddMonoidHom (A B : Type*) [AddMonoid A] [AddMonoid B] [TopologicalSpace A] [TopologicalSpace B] extends A →+ B, C(A, B) /-- The type of continuous monoid homomorphisms from `A` to `B`. When possible, instead of parametrizing results over `(f : ContinuousMonoidHom A B)`, you should parametrize over `(F : Type*) [FunLike F A B] [ContinuousMapClass F A B] [MonoidHomClass F A B] (f : F)`. When you extend this structure, make sure to extend `ContinuousMapClass` and/or `MonoidHomClass`, if needed. -/ @[to_additive /-- The type of continuous additive monoid homomorphisms from `A` to `B`. -/] structure ContinuousMonoidHom extends A →* B, C(A, B) /-- Reinterpret a `ContinuousMonoidHom` as a `MonoidHom`. -/ add_decl_doc ContinuousMonoidHom.toMonoidHom /-- Reinterpret a `ContinuousAddMonoidHom` as an `AddMonoidHom`. -/ add_decl_doc ContinuousAddMonoidHom.toAddMonoidHom /-- Reinterpret a `ContinuousMonoidHom` as a `ContinuousMap`. -/ add_decl_doc ContinuousMonoidHom.toContinuousMap /-- Reinterpret a `ContinuousAddMonoidHom` as a `ContinuousMap`. -/ add_decl_doc ContinuousAddMonoidHom.toContinuousMap namespace ContinuousMonoidHom /-- The type of continuous monoid homomorphisms from `A` to `B`.-/ infixr:25 " →ₜ+ " => ContinuousAddMonoidHom /-- The type of continuous monoid homomorphisms from `A` to `B`.-/ infixr:25 " →ₜ* " => ContinuousMonoidHom variable {A B C D E} @[to_additive] instance instFunLike : FunLike (A →ₜ* B) A B where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨⟨ _ , _ ⟩, _⟩, _⟩ := f obtain ⟨⟨⟨ _ , _ ⟩, _⟩, _⟩ := g congr @[to_additive] instance instMonoidHomClass : MonoidHomClass (A →ₜ* B) A B where map_mul f := f.map_mul' map_one f := f.map_one' @[to_additive] instance instContinuousMapClass : ContinuousMapClass (A →ₜ* B) A B where map_continuous f := f.continuous_toFun @[to_additive (attr := simp)] lemma coe_toMonoidHom (f : A →ₜ* B) : f.toMonoidHom = f := rfl @[to_additive (attr := simp)] lemma coe_toContinuousMap (f : A →ₜ* B) : f.toContinuousMap = f := rfl section variable {F : Type*} [FunLike F A B] /-- Turn an element of a type `F` satisfying `MonoidHomClass F A B` and `ContinuousMapClass F A B` into a`ContinuousMonoidHom`. This is declared as the default coercion from `F` to `(A →ₜ* B)`. -/ @[to_additive (attr := coe) /-- Turn an element of a type `F` satisfying `AddMonoidHomClass F A B` and `ContinuousMapClass F A B` into a`ContinuousAddMonoidHom`. This is declared as the default coercion from `F` to `ContinuousAddMonoidHom A B`. -/] def toContinuousMonoidHom [MonoidHomClass F A B] [ContinuousMapClass F A B] (f : F) : A →ₜ* B := { MonoidHomClass.toMonoidHom f with } /-- Any type satisfying `MonoidHomClass` and `ContinuousMapClass` can be cast into `ContinuousMonoidHom` via `ContinuousMonoidHom.toContinuousMonoidHom`. -/ @[to_additive /-- Any type satisfying `AddMonoidHomClass` and `ContinuousMapClass` can be cast into `ContinuousAddMonoidHom` via `ContinuousAddMonoidHom.toContinuousAddMonoidHom`. -/] instance [MonoidHomClass F A B] [ContinuousMapClass F A B] : CoeOut F (A →ₜ* B) := ⟨ContinuousMonoidHom.toContinuousMonoidHom⟩ @[to_additive (attr := simp)] lemma coe_coe [MonoidHomClass F A B] [ContinuousMapClass F A B] (f : F) : ⇑(f : A →ₜ* B) = f := rfl @[to_additive (attr := simp, norm_cast)] lemma toMonoidHom_toContinuousMonoidHom [MonoidHomClass F A B] [ContinuousMapClass F A B] (f : F) : ((f : A →ₜ* B) : A →* B) = f := rfl @[to_additive (attr := simp, norm_cast)] lemma toContinuousMap_toContinuousMonoidHom [MonoidHomClass F A B] [ContinuousMapClass F A B] (f : F) : ((f : A →ₜ* B) : C(A, B)) = f := rfl end @[to_additive (attr := ext)] theorem ext {f g : A →ₜ* B} (h : ∀ x, f x = g x) : f = g := DFunLike.ext _ _ h @[to_additive] theorem toContinuousMap_injective : Injective (toContinuousMap : _ → C(A, B)) := fun f g h => ext <| by convert DFunLike.ext_iff.1 h /-- Composition of two continuous homomorphisms. -/ @[to_additive (attr := simps!) /-- Composition of two continuous homomorphisms. -/] def comp (g : B →ₜ* C) (f : A →ₜ* B) : A →ₜ* C := ⟨g.toMonoidHom.comp f.toMonoidHom, (map_continuous g).comp (map_continuous f)⟩ @[to_additive (attr := simp)] lemma coe_comp (g : ContinuousMonoidHom B C) (f : ContinuousMonoidHom A B) : ⇑(g.comp f) = ⇑g ∘ ⇑f := rfl /-- Product of two continuous homomorphisms on the same space. -/ @[to_additive (attr := simps!) prod /-- Product of two continuous homomorphisms on the same space. -/] def prod (f : A →ₜ* B) (g : A →ₜ* C) : A →ₜ* (B × C) := ⟨f.toMonoidHom.prod g.toMonoidHom, f.continuous_toFun.prodMk g.continuous_toFun⟩ /-- Product of two continuous homomorphisms on different spaces. -/ @[to_additive (attr := simps!) prodMap /-- Product of two continuous homomorphisms on different spaces. -/] def prodMap (f : A →ₜ* C) (g : B →ₜ* D) : (A × B) →ₜ* (C × D) := ⟨f.toMonoidHom.prodMap g.toMonoidHom, f.continuous_toFun.prodMap g.continuous_toFun⟩ variable (A B C D E) /-- The trivial continuous homomorphism. -/ @[to_additive (attr := simps!) /-- The trivial continuous homomorphism. -/] instance : One (A →ₜ* B) where one := ⟨1, continuous_const⟩ @[to_additive (attr := simp)] lemma coe_one : ⇑(1 : A →ₜ* B) = 1 := rfl @[to_additive] instance : Inhabited (A →ₜ* B) := ⟨1⟩ /-- The identity continuous homomorphism. -/ @[to_additive (attr := simps!) /-- The identity continuous homomorphism. -/] def id : A →ₜ* A := ⟨.id A, continuous_id⟩ @[to_additive (attr := simp)] lemma coe_id : ⇑(ContinuousMonoidHom.id A) = _root_.id := rfl /-- The continuous homomorphism given by projection onto the first factor. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by projection onto the first factor. -/] def fst : (A × B) →ₜ* A := ⟨MonoidHom.fst A B, continuous_fst⟩ /-- The continuous homomorphism given by projection onto the second factor. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by projection onto the second factor. -/] def snd : (A × B) →ₜ* B := ⟨MonoidHom.snd A B, continuous_snd⟩ /-- The continuous homomorphism given by inclusion of the first factor. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by inclusion of the first factor. -/] def inl : A →ₜ* (A × B) := prod (id A) 1 /-- The continuous homomorphism given by inclusion of the second factor. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by inclusion of the second factor. -/] def inr : B →ₜ* (A × B) := prod 1 (id B) /-- The continuous homomorphism given by the diagonal embedding. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by the diagonal embedding. -/] def diag : A →ₜ* (A × A) := prod (id A) (id A) /-- The continuous homomorphism given by swapping components. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by swapping components. -/] def swap : (A × B) →ₜ* (B × A) := prod (snd A B) (fst A B) section CommMonoid variable [CommMonoid E] [TopologicalSpace E] [ContinuousMul E] /-- The continuous homomorphism given by multiplication. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by addition. -/] def mul : (E × E) →ₜ* E := ⟨mulMonoidHom, continuous_mul⟩ variable {A B C D E} @[to_additive] instance : CommMonoid (A →ₜ* E) where mul f g := (mul E).comp (f.prod g) mul_comm f g := ext fun x => mul_comm (f x) (g x) mul_assoc f g h := ext fun x => mul_assoc (f x) (g x) (h x) one_mul f := ext fun x => one_mul (f x) mul_one f := ext fun x => mul_one (f x) /-- Coproduct of two continuous homomorphisms to the same space. -/ @[to_additive (attr := simps!) /-- Coproduct of two continuous homomorphisms to the same space. -/] def coprod (f : ContinuousMonoidHom A E) (g : ContinuousMonoidHom B E) : ContinuousMonoidHom (A × B) E := (mul E).comp (f.prodMap g) end CommMonoid section CommGroup variable [CommGroup E] [TopologicalSpace E] [IsTopologicalGroup E] /-- The continuous homomorphism given by inversion. -/ @[to_additive (attr := simps!) /-- The continuous homomorphism given by negation. -/] def inv : ContinuousMonoidHom E E := ⟨invMonoidHom, continuous_inv⟩ @[to_additive] instance : CommGroup (ContinuousMonoidHom A E) where __ : CommMonoid (ContinuousMonoidHom A E) := inferInstance inv f := (inv E).comp f inv_mul_cancel f := ext fun x => inv_mul_cancel (f x) div f g := .comp ⟨divMonoidHom, continuous_div'⟩ (f.prod g) div_eq_mul_inv f g := ext fun x => div_eq_mul_inv (f x) (g x) end CommGroup /-- For `f : F` where `F` is a class of continuous monoid hom, this yields an element `ContinuousMonoidHom A B`. -/ @[to_additive /-- For `f : F` where `F` is a class of continuous additive monoid hom, this yields an element `ContinuousAddMonoidHom A B`. -/] def ofClass (F : Type*) [FunLike F A B] [ContinuousMapClass F A B] [MonoidHomClass F A B] (f : F) : (ContinuousMonoidHom A B) := toContinuousMonoidHom f end ContinuousMonoidHom end section /-! # Continuous MulEquiv This section defines the space of continuous isomorphisms between two topological groups. ## Main definitions -/ universe u v variable (G : Type u) [TopologicalSpace G] (H : Type v) [TopologicalSpace H] /-- The structure of two-sided continuous isomorphisms between additive groups. Note that both the map and its inverse have to be continuous. -/ structure ContinuousAddEquiv [Add G] [Add H] extends G ≃+ H , G ≃ₜ H /-- The structure of two-sided continuous isomorphisms between groups. Note that both the map and its inverse have to be continuous. -/ @[to_additive /-- The structure of two-sided continuous isomorphisms between additive groups. Note that both the map and its inverse have to be continuous. -/] structure ContinuousMulEquiv [Mul G] [Mul H] extends G ≃* H , G ≃ₜ H /-- The homeomorphism induced from a two-sided continuous isomorphism of groups. -/ add_decl_doc ContinuousMulEquiv.toHomeomorph /-- The homeomorphism induced from a two-sided continuous isomorphism additive groups. -/ add_decl_doc ContinuousAddEquiv.toHomeomorph @[inherit_doc] infixl:25 " ≃ₜ* " => ContinuousMulEquiv @[inherit_doc] infixl:25 " ≃ₜ+ " => ContinuousAddEquiv section namespace ContinuousMulEquiv variable {M N : Type*} [TopologicalSpace M] [TopologicalSpace N] [Mul M] [Mul N] section coe @[to_additive] instance : EquivLike (M ≃ₜ* N) M N where coe f := f.toFun inv f := f.invFun left_inv f := f.left_inv right_inv f := f.right_inv coe_injective' f g h₁ h₂ := by cases f cases g congr exact MulEquiv.ext_iff.mpr (congrFun h₁) @[to_additive] instance : MulEquivClass (M ≃ₜ* N) M N where map_mul f := f.map_mul' @[to_additive] instance : HomeomorphClass (M ≃ₜ* N) M N where map_continuous f := f.continuous_toFun inv_continuous f := f.continuous_invFun /-- Two continuous multiplicative isomorphisms agree if they are defined by the same underlying function. -/ @[to_additive (attr := ext) /-- Two continuous additive isomorphisms agree if they are defined by the same underlying function. -/] theorem ext {f g : M ≃ₜ* N} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[to_additive (attr := simp)] theorem coe_mk (f : M ≃* N) (hf1 hf2) : ⇑(mk f hf1 hf2) = f := rfl @[to_additive] theorem toEquiv_eq_coe (f : M ≃ₜ* N) : f.toEquiv = f := rfl @[to_additive (attr := simp)] theorem toMulEquiv_eq_coe (f : M ≃ₜ* N) : f.toMulEquiv = f := rfl @[to_additive] theorem toHomeomorph_eq_coe (f : M ≃ₜ* N) : f.toHomeomorph = f := rfl /-- Makes a continuous multiplicative isomorphism from a homeomorphism which preserves multiplication. -/ @[to_additive /-- Makes an continuous additive isomorphism from a homeomorphism which preserves addition. -/] def mk' (f : M ≃ₜ N) (h : ∀ x y, f (x * y) = f x * f y) : M ≃ₜ* N := ⟨⟨f.toEquiv,h⟩, f.continuous_toFun, f.continuous_invFun⟩ set_option linter.docPrime false in -- This is about `ContinuousMulEquiv.mk'` @[simp] lemma coe_mk' (f : M ≃ₜ N) (h : ∀ x y, f (x * y) = f x * f y) : ⇑(mk' f h) = f := rfl end coe section bijective @[to_additive] protected theorem bijective (e : M ≃ₜ* N) : Function.Bijective e := EquivLike.bijective e @[to_additive] protected theorem injective (e : M ≃ₜ* N) : Function.Injective e := EquivLike.injective e @[to_additive] protected theorem surjective (e : M ≃ₜ* N) : Function.Surjective e := EquivLike.surjective e @[to_additive] theorem apply_eq_iff_eq (e : M ≃ₜ* N) {x y : M} : e x = e y ↔ x = y := e.injective.eq_iff end bijective section refl variable (M) /-- The identity map is a continuous multiplicative isomorphism. -/ @[to_additive (attr := refl) /-- The identity map is a continuous additive isomorphism. -/] def refl : M ≃ₜ* M := { MulEquiv.refl _ with } @[to_additive] instance : Inhabited (M ≃ₜ* M) := ⟨ContinuousMulEquiv.refl M⟩ @[to_additive (attr := simp, norm_cast)] theorem coe_refl : ↑(refl M) = id := rfl @[to_additive (attr := simp)] theorem refl_apply (m : M) : refl M m = m := rfl end refl section symm /-- The inverse of a ContinuousMulEquiv. -/ @[to_additive (attr := symm) /-- The inverse of a ContinuousAddEquiv. -/] def symm (cme : M ≃ₜ* N) : N ≃ₜ* M := { cme.toMulEquiv.symm with continuous_toFun := cme.continuous_invFun continuous_invFun := cme.continuous_toFun } initialize_simps_projections ContinuousMulEquiv (toFun → apply, invFun → symm_apply) initialize_simps_projections ContinuousAddEquiv (toFun → apply, invFun → symm_apply) @[to_additive] theorem invFun_eq_symm {f : M ≃ₜ* N} : f.invFun = f.symm := rfl @[to_additive (attr := simp)] theorem coe_toHomeomorph_symm (f : M ≃ₜ* N) : (f : M ≃ₜ N).symm = (f.symm : N ≃ₜ M) := rfl @[to_additive (attr := simp)] theorem equivLike_inv_eq_symm (f : M ≃ₜ* N) : EquivLike.inv f = f.symm := rfl @[to_additive (attr := simp)] theorem symm_symm (f : M ≃ₜ* N) : f.symm.symm = f := rfl @[to_additive] theorem symm_bijective : Function.Bijective (symm : M ≃ₜ* N → _) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/ @[to_additive (attr := simp) /-- `e.symm` is a right inverse of `e`, written as `e (e.symm y) = y`. -/] theorem apply_symm_apply (e : M ≃ₜ* N) (y : N) : e (e.symm y) = y := e.toEquiv.apply_symm_apply y /-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/ @[to_additive (attr := simp) /-- `e.symm` is a left inverse of `e`, written as `e.symm (e y) = y`. -/] theorem symm_apply_apply (e : M ≃ₜ* N) (x : M) : e.symm (e x) = x := e.toEquiv.symm_apply_apply x @[to_additive (attr := simp)] theorem symm_comp_self (e : M ≃ₜ* N) : e.symm ∘ e = id := funext e.symm_apply_apply @[to_additive (attr := simp)] theorem self_comp_symm (e : M ≃ₜ* N) : e ∘ e.symm = id := funext e.apply_symm_apply @[to_additive] theorem apply_eq_iff_symm_apply (e : M ≃ₜ* N) {x : M} {y : N} : e x = y ↔ x = e.symm y := e.toEquiv.apply_eq_iff_eq_symm_apply @[to_additive] theorem symm_apply_eq (e : M ≃ₜ* N) {x y} : e.symm x = y ↔ x = e y := e.toEquiv.symm_apply_eq @[to_additive] theorem eq_symm_apply (e : M ≃ₜ* N) {x y} : y = e.symm x ↔ e y = x := e.toEquiv.eq_symm_apply @[to_additive] theorem eq_comp_symm {α : Type*} (e : M ≃ₜ* N) (f : N → α) (g : M → α) : f = g ∘ e.symm ↔ f ∘ e = g := e.toEquiv.eq_comp_symm f g @[to_additive] theorem comp_symm_eq {α : Type*} (e : M ≃ₜ* N) (f : N → α) (g : M → α) : g ∘ e.symm = f ↔ g = f ∘ e := e.toEquiv.comp_symm_eq f g @[to_additive] theorem eq_symm_comp {α : Type*} (e : M ≃ₜ* N) (f : α → M) (g : α → N) : f = e.symm ∘ g ↔ e ∘ f = g := e.toEquiv.eq_symm_comp f g @[to_additive] theorem symm_comp_eq {α : Type*} (e : M ≃ₜ* N) (f : α → M) (g : α → N) : e.symm ∘ g = f ↔ g = e ∘ f := e.toEquiv.symm_comp_eq f g end symm section trans variable {L : Type*} [Mul L] [TopologicalSpace L] /-- The composition of two ContinuousMulEquiv. -/ @[to_additive /-- The composition of two ContinuousAddEquiv. -/] def trans (cme1 : M ≃ₜ* N) (cme2 : N ≃ₜ* L) : M ≃ₜ* L where __ := cme1.toMulEquiv.trans cme2.toMulEquiv continuous_toFun := by convert Continuous.comp cme2.continuous_toFun cme1.continuous_toFun continuous_invFun := by convert Continuous.comp cme1.continuous_invFun cme2.continuous_invFun @[to_additive (attr := simp)] theorem coe_trans (e₁ : M ≃ₜ* N) (e₂ : N ≃ₜ* L) : ↑(e₁.trans e₂) = e₂ ∘ e₁ := rfl @[to_additive (attr := simp)] theorem trans_apply (e₁ : M ≃ₜ* N) (e₂ : N ≃ₜ* L) (m : M) : e₁.trans e₂ m = e₂ (e₁ m) := rfl @[to_additive (attr := simp)] theorem symm_trans_apply (e₁ : M ≃ₜ* N) (e₂ : N ≃ₜ* L) (l : L) : (e₁.trans e₂).symm l = e₁.symm (e₂.symm l) := rfl @[to_additive (attr := simp)] theorem symm_trans_self (e : M ≃ₜ* N) : e.symm.trans e = refl N := DFunLike.ext _ _ e.apply_symm_apply @[to_additive (attr := simp)] theorem self_trans_symm (e : M ≃ₜ* N) : e.trans e.symm = refl M := DFunLike.ext _ _ e.symm_apply_apply end trans section unique /-- The `MulEquiv` between two monoids with a unique element. -/ @[to_additive /-- The `AddEquiv` between two `AddMonoid`s with a unique element. -/] def ofUnique {M N} [Unique M] [Unique N] [Mul M] [Mul N] [TopologicalSpace M] [TopologicalSpace N] : M ≃ₜ* N where __ := MulEquiv.ofUnique continuous_toFun := by continuity continuous_invFun := by continuity /-- There is a unique monoid homomorphism between two monoids with a unique element. -/ @[to_additive /-- There is a unique additive monoid homomorphism between two additive monoids with a unique element. -/] instance {M N} [Unique M] [Unique N] [Mul M] [Mul N] [TopologicalSpace M] [TopologicalSpace N] : Unique (M ≃ₜ* N) where default := ofUnique uniq _ := ext fun _ ↦ Subsingleton.elim _ _ end unique end ContinuousMulEquiv end end
EpiMono.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.Category.ModuleCat.Presheaf.Colimits import Mathlib.Algebra.Category.ModuleCat.Presheaf.Limits /-! # Epimorphisms and monomorphisms in the category of presheaves of modules In this file, we give characterizations of epimorphisms and monomorphisms in the category of presheaves of modules. -/ universe v v₁ u₁ u open CategoryTheory namespace PresheafOfModules variable {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}} {M₁ M₂ : PresheafOfModules.{v} R} {f : M₁ ⟶ M₂} lemma epi_of_surjective (hf : ∀ ⦃X : Cᵒᵖ⦄, Function.Surjective (f.app X)) : Epi f where left_cancellation g₁ g₂ hg := by ext X m₂ obtain ⟨m₁, rfl⟩ := hf m₂ exact congr_fun ((evaluation R X ⋙ forget _).congr_map hg) m₁ lemma mono_of_injective (hf : ∀ ⦃X : Cᵒᵖ⦄, Function.Injective (f.app X)) : Mono f where right_cancellation {M} g₁ g₂ hg := by ext X m exact hf (congr_fun ((evaluation R X ⋙ forget _).congr_map hg) m) variable (f) instance [Epi f] (X : Cᵒᵖ) : Epi (f.app X) := inferInstanceAs (Epi ((evaluation R X).map f)) instance [Mono f] (X : Cᵒᵖ) : Mono (f.app X) := inferInstanceAs (Mono ((evaluation R X).map f)) lemma surjective_of_epi [Epi f] (X : Cᵒᵖ) : Function.Surjective (f.app X) := by rw [← ModuleCat.epi_iff_surjective] infer_instance lemma injective_of_mono [Mono f] (X : Cᵒᵖ) : Function.Injective (f.app X) := by rw [← ModuleCat.mono_iff_injective] infer_instance lemma epi_iff_surjective : Epi f ↔ ∀ ⦃X : Cᵒᵖ⦄, Function.Surjective (f.app X) := ⟨fun _ ↦ surjective_of_epi f, epi_of_surjective⟩ lemma mono_iff_surjective : Mono f ↔ ∀ ⦃X : Cᵒᵖ⦄, Function.Injective (f.app X) := ⟨fun _ ↦ injective_of_mono f, mono_of_injective⟩ end PresheafOfModules
Function.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `grind`/`aesop` as a forward rule. -/ @[aesop safe forward, grind →] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := by grind /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by grind theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := by grind theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction n generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop @[simp low] lemma injOn_of_eq_iff_eq (s : Set α) (h : ∀ x y, f x = f y ↔ x = y) : Set.InjOn f s := fun x _ y _ => (h x y).mp theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_mono⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_mono diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff @[simp] lemma surjOn_univ_of_subsingleton_nonempty [Subsingleton β] [Nonempty β] : SurjOn f s univ ↔ s.Nonempty := by cases nonempty_unique β; simp [univ_unique, Subsingleton.elim (f _) default, Set.Nonempty] theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_mono hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_mono hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_mono hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj : InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb grind lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ /-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`, then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/ theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t') (ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f rw [image_diff_preimage, image_inter_preimage] at hbij refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩ · exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left · rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff] exact ⟨htt', diff_subset.trans inter_subset_right⟩ · rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn] · refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_ rw [← h.image_eq] exact ⟨x, hxs, hxy⟩ exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo rw [image_union, h.image_eq, hbij.image_eq, union_diff_self] exact .inr ⟨ht' hyt', hyt'⟩ /-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`, then `f` maps some superset of `s` bijectively to `t'`. -/ theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) : ∃ s', s ⊆ s' ∧ BijOn f s' t' := by simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn]) theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) : ∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs (image_mono hrs) Subset.rfl exact ⟨u, hru, hus, h.image_eq, h.injOn⟩ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] theorem preimage_invFun_of_notMem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] @[deprecated (since := "2025-05-23")] alias preimage_invFun_of_not_mem := preimage_invFun_of_notMem lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ end Set namespace Function open Set variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α} theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) := hg.injOn.comp hf (mapsTo_univ _ _) theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s := (surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _) theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s := fun x _ => h x theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) : RightInvOn f g s := fun x _ => h x theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) : RightInvOn f g (range g) := forall_mem_range.2 fun i => congr_arg g (h i) namespace Semiconj theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) := fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩ theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) : MapsTo f (fa '' s) (fb '' t) := mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩ theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ => hy ▸ ⟨fa x, h x⟩ theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by rintro y ⟨x, hxt, rfl⟩ rcases ha hxt with ⟨x, hxs, rfl⟩ rw [h x] exact mem_image_of_mem _ (mem_image_of_mem _ hxs) theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) : SurjOn fb (range f) (range f) := by rw [← image_univ] exact h.surjOn_image (ha.surjOn univ) theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) : InjOn fb (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H simp only [← h.eq] at H exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) : InjOn fb (range f) := by rw [← image_univ] at * exact h.injOn_image ha.injOn hf theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) : BijOn fb (f '' s) (f '' t) := ⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf), h.surjOn_image ha.surjOn⟩ theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) : BijOn fb (range f) (range f) := by rw [← image_univ] exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) : MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx] theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s) (hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by intro x hx y hy H have := congr_arg f H rw [h.eq, h.eq] at this exact hf hx hy (hb hx hy this) end Semiconj theorem update_comp_eq_of_notMem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β] (g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) : (fun j => update g i a (f j)) = fun j => g (f j) := (update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩ @[deprecated (since := "2025-05-23")] alias update_comp_eq_of_not_mem_range' := update_comp_eq_of_notMem_range' /-- Non-dependent version of `Function.update_comp_eq_of_notMem_range'` -/ theorem update_comp_eq_of_notMem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f := update_comp_eq_of_notMem_range' g a h @[deprecated (since := "2025-05-23")] alias update_comp_eq_of_not_mem_range := update_comp_eq_of_notMem_range theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ => (insert_inj ha).1 lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) : f a = b := by simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a end Function /-! ### Equivalences, permutations -/ namespace Set variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α} protected lemma MapsTo.extendDomain (h : MapsTo g s t) : MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma SurjOn.extendDomain (h : SurjOn g s t) : SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩ obtain ⟨b, hb, rfl⟩ := h ha exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma BijOn.extendDomain (h : BijOn g s t) : BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩ protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) : LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) : RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) : InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.1.extendDomain, h.2.extendDomain⟩ end Set namespace Set variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂} {f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂} lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) : (s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) := fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2) lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) : SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by rintro x hx obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1 obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2 exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩ lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) : MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩ lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) : BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩ lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) : LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) : RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) : InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩ end Set namespace Equiv open Set variable (e : α ≃ β) {s : Set α} {t : Set β} lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t := ⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩ protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t := e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply] lemma invOn : InvOn e e.symm t s := ⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩ lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn variable {e} @[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm variable [DecidableEq α] {a b : α} lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s := (swap a b).bijOn fun x ↦ by obtain rfl | hxa := eq_or_ne x a <;> obtain rfl | hxb := eq_or_ne x b <;> simp [*, swap_apply_of_ne_of_ne] end Equiv
Cauchy.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, Mario Carneiro -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Algebra.Order.Group.Nat import Mathlib.Topology.UniformSpace.DiscreteUniformity /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, forall_mem_comm] lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {α} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x := tendsto_const_nhds.cauchySeq theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α} (hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α} (hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to ℕ ≃ ℕ using hf simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto theorem cauchySeq_iff {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] theorem CauchySeq.prodMap {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv @[deprecated (since := "2025-03-10")] alias CauchySeq.prod_map := CauchySeq.prodMap theorem CauchySeq.prodMk {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map) @[deprecated (since := "2025-03-10")] alias CauchySeq.prod := CauchySeq.prodMk theorem CauchySeq.eventually_eventually [Preorder β] {u : β → α} (hu : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β} (hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ := extraction_forall_of_eventually' this exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| Nat.lt_add_one n).le⟩ theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} {a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩ rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with ⟨φ, φ_mono, hφV⟩ exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩ /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u) {ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α} (ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) := le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf) /-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/ theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by constructor <;> intro h · rw [cauchySeq_iff] at h ⊢ intro V mV obtain ⟨N, h⟩ := h V mV use N + k intro a ha b hb convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega · exact h.comp_tendsto (tendsto_add_atTop_nat k) theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (h : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq] refine (atTop_basis.prod_self.tendsto_iff h).trans ?_ simp only [true_and, Prod.forall, mem_prod_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β] theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (H : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩ · exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl · rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩ rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩ refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩ exacts [hN m hm, hN n hn] theorem cauchySeq_of_controlled [SemilatticeSup β] [Nonempty β] (U : β → Set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) {f : β → α} (hf : ∀ ⦃N m n : β⦄, N ≤ m → N ≤ n → (f m, f n) ∈ U N) : CauchySeq f := cauchySeq_iff_tendsto.2 (by intro s hs rw [mem_map, mem_atTop_sets] obtain ⟨N, hN⟩ := hU s hs refine ⟨(N, N), fun mn hmn => ?_⟩ obtain ⟨m, n⟩ := mn exact hN (hf hmn.1 hmn.2)) theorem isComplete_iff_clusterPt {s : Set α} : IsComplete s ↔ ∀ l, Cauchy l → l ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x l := forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ => le_nhds_iff_adhp_of_cauchy hl theorem isComplete_iff_ultrafilter {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ↑l ≤ 𝓟 s → ∃ x ∈ s, ↑l ≤ 𝓝 x := by refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩ haveI := hl.1 rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with ⟨x, hxs, hxl⟩ exact ⟨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)⟩ theorem isComplete_iff_ultrafilter' {s : Set α} : IsComplete s ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → s ∈ l → ∃ x ∈ s, ↑l ≤ 𝓝 x := isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe] protected theorem IsComplete.union {s t : Set α} (hs : IsComplete s) (ht : IsComplete t) : IsComplete (s ∪ t) := by simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at * exact fun l hl => ⟨fun hsl => (hs l hl hsl).imp fun x hx => ⟨Or.inl hx.1, hx.2⟩, fun htl => (ht l hl htl).imp fun x hx => ⟨Or.inr hx.1, hx.2⟩⟩ theorem isComplete_iUnion_separated {ι : Sort*} {s : ι → Set α} (hs : ∀ i, IsComplete (s i)) {U : Set (α × α)} (hU : U ∈ 𝓤 α) (hd : ∀ (i j : ι), ∀ x ∈ s i, ∀ y ∈ s j, (x, y) ∈ U → i = j) : IsComplete (⋃ i, s i) := by set S := ⋃ i, s i intro l hl hls rw [le_principal_iff] at hls obtain ⟨hl_ne, hl'⟩ := cauchy_iff.1 hl obtain ⟨t, htS, htl, htU⟩ : ∃ t, t ⊆ S ∧ t ∈ l ∧ t ×ˢ t ⊆ U := by rcases hl' U hU with ⟨t, htl, htU⟩ refine ⟨t ∩ S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htU⟩ gcongr <;> apply inter_subset_left obtain ⟨i, hi⟩ : ∃ i, t ⊆ s i := by rcases Filter.nonempty_of_mem htl with ⟨x, hx⟩ rcases mem_iUnion.1 (htS hx) with ⟨i, hi⟩ refine ⟨i, fun y hy => ?_⟩ rcases mem_iUnion.1 (htS hy) with ⟨j, hj⟩ rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)] rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with ⟨x, hxs, hlx⟩ exact ⟨x, mem_iUnion.2 ⟨i, hxs⟩, hlx⟩ /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class CompleteSpace (α : Type u) [UniformSpace α] : Prop where /-- In a complete uniform space, every Cauchy filter converges. -/ complete : ∀ {f : Filter α}, Cauchy f → ∃ x, f ≤ 𝓝 x theorem complete_univ {α : Type u} [UniformSpace α] [CompleteSpace α] : IsComplete (univ : Set α) := fun f hf _ => by rcases CompleteSpace.complete hf with ⟨x, hx⟩ exact ⟨x, mem_univ x, hx⟩ instance CompleteSpace.prod [UniformSpace β] [CompleteSpace α] [CompleteSpace β] : CompleteSpace (α × β) where complete hf := let ⟨x1, hx1⟩ := CompleteSpace.complete <| hf.map uniformContinuous_fst let ⟨x2, hx2⟩ := CompleteSpace.complete <| hf.map uniformContinuous_snd ⟨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumption⟩ lemma CompleteSpace.fst_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty β] : CompleteSpace α where complete hf := let ⟨y⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y) ⟨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) hab⟩ lemma CompleteSpace.snd_of_prod [UniformSpace β] [CompleteSpace (α × β)] [h : Nonempty α] : CompleteSpace β where complete hf := let ⟨x⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf ⟨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) hab⟩ lemma completeSpace_prod_of_nonempty [UniformSpace β] [Nonempty α] [Nonempty β] : CompleteSpace (α × β) ↔ CompleteSpace α ∧ CompleteSpace β := ⟨fun _ ↦ ⟨.fst_of_prod (β := β), .snd_of_prod (α := α)⟩, fun ⟨_, _⟩ ↦ .prod⟩ @[to_additive] instance CompleteSpace.mulOpposite [CompleteSpace α] : CompleteSpace αᵐᵒᵖ where complete hf := MulOpposite.op_surjective.exists.mpr <| let ⟨x, hx⟩ := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop) ⟨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _⟩ /-- If `univ` is complete, the space is a complete space -/ theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set α)) : CompleteSpace α := ⟨fun hf => let ⟨x, _, hx⟩ := h _ hf ((@principal_univ α).symm ▸ le_top); ⟨x, hx⟩⟩ theorem completeSpace_iff_isComplete_univ : CompleteSpace α ↔ IsComplete (univ : Set α) := ⟨@complete_univ α _, completeSpace_of_isComplete_univ⟩ theorem completeSpace_iff_ultrafilter : CompleteSpace α ↔ ∀ l : Ultrafilter α, Cauchy (l : Filter α) → ∃ x : α, ↑l ≤ 𝓝 x := by simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter] theorem cauchy_iff_exists_le_nhds [CompleteSpace α] {l : Filter α} [NeBot l] : Cauchy l ↔ ∃ x, l ≤ 𝓝 x := ⟨CompleteSpace.complete, fun ⟨_, hx⟩ => cauchy_nhds.mono hx⟩ theorem cauchy_map_iff_exists_tendsto [CompleteSpace α] {l : Filter β} {f : β → α} [NeBot l] : Cauchy (l.map f) ↔ ∃ x, Tendsto f l (𝓝 x) := cauchy_iff_exists_le_nhds /-- A Cauchy sequence in a complete space converges -/ theorem cauchySeq_tendsto_of_complete [Preorder β] [CompleteSpace α] {u : β → α} (H : CauchySeq u) : ∃ x, Tendsto u atTop (𝓝 x) := CompleteSpace.complete H /-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/ theorem cauchySeq_tendsto_of_isComplete [Preorder β] {K : Set α} (h₁ : IsComplete K) {u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : CauchySeq u) : ∃ v ∈ K, Tendsto u atTop (𝓝 v) := h₁ _ h₃ <| le_principal_iff.2 <| mem_map_iff_exists_image.2 ⟨univ, univ_mem, by rwa [image_univ, range_subset_iff]⟩ theorem Cauchy.le_nhds_lim [CompleteSpace α] {f : Filter α} (hf : Cauchy f) : haveI := hf.1.nonempty; f ≤ 𝓝 (lim f) := _root_.le_nhds_lim (CompleteSpace.complete hf) theorem CauchySeq.tendsto_limUnder [Preorder β] [CompleteSpace α] {u : β → α} (h : CauchySeq u) : haveI := h.1.nonempty; Tendsto u atTop (𝓝 <| limUnder atTop u) := h.le_nhds_lim theorem IsClosed.isComplete [CompleteSpace α] {s : Set α} (h : IsClosed s) : IsComplete s := fun _ cf fs => let ⟨x, hx⟩ := CompleteSpace.complete cf ⟨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩ namespace DiscreteUniformity variable [DiscreteUniformity α] /-- A Cauchy filter in a discrete uniform space is contained in the principal filter of a point. -/ theorem eq_pure_of_cauchy {f : Filter α} (hf : Cauchy f) : ∃ x : α, f = pure x := by rcases hf with ⟨f_ne_bot, f_le⟩ simp only [DiscreteUniformity.eq_principal_idRel, le_principal_iff, mem_prod_iff] at f_le obtain ⟨S, ⟨hS, ⟨T, ⟨hT, H⟩⟩⟩⟩ := f_le obtain ⟨x, rfl⟩ := eq_singleton_left_of_prod_subset_idRel (f_ne_bot.nonempty_of_mem hS) (Filter.nonempty_of_mem hT) H exact ⟨x, f_ne_bot.le_pure_iff.mp <| le_pure_iff.mpr hS⟩ @[deprecated (since := "2025-03-23")] alias _root_.UniformSpace.DiscreteUnif.cauchy_le_pure := eq_pure_of_cauchy /-- The discrete uniformity makes a space complete. -/ instance : CompleteSpace α where complete {f} hf := by obtain ⟨x, rfl⟩ := eq_pure_of_cauchy hf exact ⟨x, pure_le_nhds x⟩ variable {X} /-- A constant to which a Cauchy filter in a discrete uniform space converges. -/ noncomputable def cauchyConst {f : Filter α} (hf : Cauchy f) : α := (eq_pure_of_cauchy hf).choose @[deprecated (since := "2025-03-23")] alias _root_.UniformSpace.DiscreteUnif.cauchyConst := cauchyConst theorem eq_pure_cauchyConst {f : Filter α} (hf : Cauchy f) : f = pure (cauchyConst hf) := (eq_pure_of_cauchy hf).choose_spec @[deprecated (since := "2025-03-23")] alias _root_.UniformSpace.DiscreteUnif.eq_const_of_cauchy := eq_pure_cauchyConst end DiscreteUniformity /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def TotallyBounded (s : Set α) : Prop := ∀ d ∈ 𝓤 α, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } theorem TotallyBounded.exists_subset {s : Set α} (hs : TotallyBounded s) {U : Set (α × α)} (hU : U ∈ 𝓤 α) : ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U } := by rcases comp_symm_of_uniformity hU with ⟨r, hr, rs, rU⟩ rcases hs r hr with ⟨k, fk, ks⟩ let u := k ∩ { y | ∃ x ∈ s, (x, y) ∈ r } choose f hfs hfr using fun x : u => x.coe_prop.2 refine ⟨range f, ?_, ?_, ?_⟩ · exact range_subset_iff.2 hfs · haveI : Fintype u := (fk.inter_of_left _).fintype exact finite_range f · intro x xs obtain ⟨y, hy, xy⟩ := mem_iUnion₂.1 (ks xs) rw [biUnion_range, mem_iUnion] set z : ↥u := ⟨y, hy, ⟨x, xs, xy⟩⟩ exact ⟨z, rU <| mem_compRel.2 ⟨y, xy, rs (hfr z)⟩⟩ theorem totallyBounded_iff_subset {s : Set α} : TotallyBounded s ↔ ∀ d ∈ 𝓤 α, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ d } := ⟨fun H _ hd ↦ H.exists_subset hd, fun H d hd ↦ let ⟨t, _, ht⟩ := H d hd; ⟨t, ht⟩⟩ theorem Filter.HasBasis.totallyBounded_iff {ι} {p : ι → Prop} {U : ι → Set (α × α)} (H : (𝓤 α).HasBasis p U) {s : Set α} : TotallyBounded s ↔ ∀ i, p i → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, { x | (x, y) ∈ U i } := H.forall_iff fun _ _ hUV h => h.imp fun _ ht => ⟨ht.1, ht.2.trans <| iUnion₂_mono fun _ _ _ hy => hUV hy⟩ theorem totallyBounded_of_forall_symm {s : Set α} (h : ∀ V ∈ 𝓤 α, IsSymmetricRel V → ∃ t : Set α, Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y V) : TotallyBounded s := UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V hV => by simpa only [ball_eq_of_symmetry hV.2] using h V hV.1 hV.2 theorem TotallyBounded.subset {s₁ s₂ : Set α} (hs : s₁ ⊆ s₂) (h : TotallyBounded s₂) : TotallyBounded s₁ := fun d hd => let ⟨t, ht₁, ht₂⟩ := h d hd ⟨t, ht₁, Subset.trans hs ht₂⟩ /-- The closure of a totally bounded set is totally bounded. -/ theorem TotallyBounded.closure {s : Set α} (h : TotallyBounded s) : TotallyBounded (closure s) := uniformity_hasBasis_closed.totallyBounded_iff.2 fun V hV => let ⟨t, htf, hst⟩ := h V hV.1 ⟨t, htf, closure_minimal hst <| htf.isClosed_biUnion fun _ _ => hV.2.preimage (.prodMk_left _)⟩ @[simp] lemma totallyBounded_closure {s : Set α} : TotallyBounded (closure s) ↔ TotallyBounded s := ⟨fun h ↦ h.subset subset_closure, TotallyBounded.closure⟩ /-- A finite indexed union is totally bounded if and only if each set of the family is totally bounded. -/ @[simp] lemma totallyBounded_iUnion {ι : Sort*} [Finite ι] {s : ι → Set α} : TotallyBounded (⋃ i, s i) ↔ ∀ i, TotallyBounded (s i) := by refine ⟨fun h i ↦ h.subset (subset_iUnion _ _), fun h U hU ↦ ?_⟩ choose t htf ht using (h · U hU) refine ⟨⋃ i, t i, finite_iUnion htf, ?_⟩ rw [biUnion_iUnion] gcongr; apply ht /-- A union indexed by a finite set is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_biUnion {ι : Type*} {I : Set ι} (hI : I.Finite) {s : ι → Set α} : TotallyBounded (⋃ i ∈ I, s i) ↔ ∀ i ∈ I, TotallyBounded (s i) := by have := hI.to_subtype rw [biUnion_eq_iUnion, totallyBounded_iUnion, Subtype.forall] /-- A union of a finite family of sets is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_sUnion {S : Set (Set α)} (hS : S.Finite) : TotallyBounded (⋃₀ S) ↔ ∀ s ∈ S, TotallyBounded s := by rw [sUnion_eq_biUnion, totallyBounded_biUnion hS] /-- A finite set is totally bounded. -/ lemma Set.Finite.totallyBounded {s : Set α} (hs : s.Finite) : TotallyBounded s := fun _U hU ↦ ⟨s, hs, fun _x hx ↦ mem_biUnion hx <| refl_mem_uniformity hU⟩ /-- A subsingleton is totally bounded. -/ lemma Set.Subsingleton.totallyBounded {s : Set α} (hs : s.Subsingleton) : TotallyBounded s := hs.finite.totallyBounded @[simp] lemma totallyBounded_singleton (a : α) : TotallyBounded {a} := (finite_singleton a).totallyBounded @[simp] theorem totallyBounded_empty : TotallyBounded (∅ : Set α) := finite_empty.totallyBounded /-- The union of two sets is totally bounded if and only if each of the two sets is totally bounded. -/ @[simp] lemma totallyBounded_union {s t : Set α} : TotallyBounded (s ∪ t) ↔ TotallyBounded s ∧ TotallyBounded t := by rw [union_eq_iUnion, totallyBounded_iUnion] simp [and_comm] /-- The union of two totally bounded sets is totally bounded. -/ protected lemma TotallyBounded.union {s t : Set α} (hs : TotallyBounded s) (ht : TotallyBounded t) : TotallyBounded (s ∪ t) := totallyBounded_union.2 ⟨hs, ht⟩ @[simp] lemma totallyBounded_insert (a : α) {s : Set α} : TotallyBounded (insert a s) ↔ TotallyBounded s := by simp_rw [← singleton_union, totallyBounded_union, totallyBounded_singleton, true_and] protected alias ⟨_, TotallyBounded.insert⟩ := totallyBounded_insert /-- The image of a totally bounded set under a uniformly continuous map is totally bounded. -/ theorem TotallyBounded.image [UniformSpace β] {f : α → β} {s : Set α} (hs : TotallyBounded s) (hf : UniformContinuous f) : TotallyBounded (f '' s) := fun t ht => have : { p : α × α | (f p.1, f p.2) ∈ t } ∈ 𝓤 α := hf ht let ⟨c, hfc, hct⟩ := hs _ this ⟨f '' c, hfc.image f, by simp only [mem_image, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, image_subset_iff, preimage_iUnion, preimage_setOf_eq] simp? [subset_def] at hct says simp only [mem_setOf_eq, subset_def, mem_iUnion, exists_prop] at hct intro x hx simpa using hct x hx⟩ theorem Ultrafilter.cauchy_of_totallyBounded {s : Set α} (f : Ultrafilter α) (hs : TotallyBounded s) (h : ↑f ≤ 𝓟 s) : Cauchy (f : Filter α) := ⟨f.neBot', fun _ ht => let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht let ⟨i, hi, hs_union⟩ := hs t' ht'₁ have : (⋃ y ∈ i, { x | (x, y) ∈ t' }) ∈ f := mem_of_superset (le_principal_iff.mp h) hs_union have : ∃ y ∈ i, { x | (x, y) ∈ t' } ∈ f := (Ultrafilter.finite_biUnion_mem_iff hi).1 this let ⟨y, _, hif⟩ := this have : { x | (x, y) ∈ t' } ×ˢ { x | (x, y) ∈ t' } ⊆ compRel t' t' := fun ⟨_, _⟩ ⟨(h₁ : (_, y) ∈ t'), (h₂ : (_, y) ∈ t')⟩ => ⟨y, h₁, ht'_symm h₂⟩ mem_of_superset (prod_mem_prod hif hif) (Subset.trans this ht'_t)⟩ theorem totallyBounded_iff_filter {s : Set α} : TotallyBounded s ↔ ∀ f, NeBot f → f ≤ 𝓟 s → ∃ c ≤ f, Cauchy c := by constructor · exact fun H f hf hfs => ⟨Ultrafilter.of f, Ultrafilter.of_le f, (Ultrafilter.of f).cauchy_of_totallyBounded H ((Ultrafilter.of_le f).trans hfs)⟩ · intro H d hd contrapose! H with hd_cover set f := ⨅ t : Finset α, 𝓟 (s \ ⋃ y ∈ t, { x | (x, y) ∈ d }) have hb : HasAntitoneBasis f fun t : Finset α ↦ s \ ⋃ y ∈ t, { x | (x, y) ∈ d } := .iInf_principal fun _ _ ↦ diff_subset_diff_right ∘ biUnion_subset_biUnion_left have : Filter.NeBot f := hb.1.neBot_iff.2 fun _ ↦ diff_nonempty.2 <| hd_cover _ (Finset.finite_toSet _) have : f ≤ 𝓟 s := iInf_le_of_le ∅ (by simp) refine ⟨f, ‹_›, ‹_›, fun c hcf hc => ?_⟩ rcases mem_prod_same_iff.1 (hc.2 hd) with ⟨m, hm, hmd⟩ rcases hc.1.nonempty_of_mem hm with ⟨y, hym⟩ have : s \ {x | (x, y) ∈ d} ∈ c := by simpa using hcf (hb.mem {y}) rcases hc.1.nonempty_of_mem (inter_mem hm this) with ⟨z, hzm, -, hyz⟩ exact hyz (hmd ⟨hzm, hym⟩) theorem totallyBounded_iff_ultrafilter {s : Set α} : TotallyBounded s ↔ ∀ f : Ultrafilter α, ↑f ≤ 𝓟 s → Cauchy (f : Filter α) := by refine ⟨fun hs f => f.cauchy_of_totallyBounded hs, fun H => totallyBounded_iff_filter.2 ?_⟩ intro f hf hfs exact ⟨Ultrafilter.of f, Ultrafilter.of_le f, H _ ((Ultrafilter.of_le f).trans hfs)⟩ theorem isCompact_iff_totallyBounded_isComplete {s : Set α} : IsCompact s ↔ TotallyBounded s ∧ IsComplete s := ⟨fun hs => ⟨totallyBounded_iff_ultrafilter.2 fun f hf => let ⟨_, _, fx⟩ := isCompact_iff_ultrafilter_le_nhds.1 hs f hf cauchy_nhds.mono fx, fun f fc fs => let ⟨a, as, fa⟩ := @hs f fc.1 fs ⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩, fun ⟨ht, hc⟩ => isCompact_iff_ultrafilter_le_nhds.2 fun f hf => hc _ (totallyBounded_iff_ultrafilter.1 ht f hf) hf⟩ protected theorem IsCompact.totallyBounded {s : Set α} (h : IsCompact s) : TotallyBounded s := (isCompact_iff_totallyBounded_isComplete.1 h).1 protected theorem IsCompact.isComplete {s : Set α} (h : IsCompact s) : IsComplete s := (isCompact_iff_totallyBounded_isComplete.1 h).2 -- see Note [lower instance priority] instance (priority := 100) complete_of_compact {α : Type u} [UniformSpace α] [CompactSpace α] : CompleteSpace α := ⟨fun hf => by simpa using (isCompact_iff_totallyBounded_isComplete.1 isCompact_univ).2 _ hf⟩ theorem isCompact_of_totallyBounded_isClosed [CompleteSpace α] {s : Set α} (ht : TotallyBounded s) (hc : IsClosed s) : IsCompact s := (@isCompact_iff_totallyBounded_isComplete α _ s).2 ⟨ht, hc.isComplete⟩ /-- Every Cauchy sequence over `ℕ` is totally bounded. -/ theorem CauchySeq.totallyBounded_range {s : ℕ → α} (hs : CauchySeq s) : TotallyBounded (range s) := by intro a ha obtain ⟨n, hn⟩ := cauchySeq_iff.1 hs a ha refine ⟨s '' { k | k ≤ n }, (finite_le_nat _).image _, ?_⟩ rw [range_subset_iff, biUnion_image] intro m rw [mem_iUnion₂] rcases le_total m n with hm | hm exacts [⟨m, hm, refl_mem_uniformity ha⟩, ⟨n, le_refl n, hn m hm n le_rfl⟩] /-- Given a family of points `xs n`, a family of entourages `V n` of the diagonal and a family of natural numbers `u n`, the intersection over `n` of the `V n`-neighborhood of `xs 1, ..., xs (u n)`. Designed to be relatively compact when `V n` tends to the diagonal. -/ def interUnionBalls (xs : ℕ → α) (u : ℕ → ℕ) (V : ℕ → Set (α × α)) : Set α := ⋂ n, ⋃ m ≤ u n, UniformSpace.ball (xs m) (Prod.swap ⁻¹' V n) lemma totallyBounded_interUnionBalls {p : ℕ → Prop} {U : ℕ → Set (α × α)} (H : (uniformity α).HasBasis p U) (xs : ℕ → α) (u : ℕ → ℕ) : TotallyBounded (interUnionBalls xs u U) := by rw [Filter.HasBasis.totallyBounded_iff H] intro i _ have h_subset : interUnionBalls xs u U ⊆ ⋃ m ≤ u i, UniformSpace.ball (xs m) (Prod.swap ⁻¹' U i) := fun x hx ↦ Set.mem_iInter.1 hx i classical refine ⟨Finset.image xs (Finset.range (u i + 1)), Finset.finite_toSet _, fun x hx ↦ ?_⟩ simp only [Finset.coe_image, Finset.coe_range, mem_image, mem_Iio, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, Nat.lt_succ_iff] exact h_subset hx /-- The construction `interUnionBalls` is used to have a relatively compact set. -/ theorem isCompact_closure_interUnionBalls {p : ℕ → Prop} {U : ℕ → Set (α × α)} (H : (uniformity α).HasBasis p U) [CompleteSpace α] (xs : ℕ → α) (u : ℕ → ℕ) : IsCompact (closure (interUnionBalls xs u U)) := by rw [isCompact_iff_totallyBounded_isComplete] refine ⟨TotallyBounded.closure ?_, isClosed_closure.isComplete⟩ exact totallyBounded_interUnionBalls H xs u /-! ### Sequentially complete space In this section we prove that a uniform space is complete provided that it is sequentially complete (i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set. In particular, this applies to (e)metric spaces, see the files `Topology/MetricSpace/EmetricSpace` and `Topology/MetricSpace/Basic`. More precisely, we assume that there is a sequence of entourages `U_n` such that any other entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/ namespace SequentiallyComplete variable {f : Filter α} (hf : Cauchy f) {U : ℕ → Set (α × α)} (U_mem : ∀ n, U n ∈ 𝓤 α) open Set Finset noncomputable section /-- An auxiliary sequence of sets approximating a Cauchy filter. -/ def setSeqAux (n : ℕ) : { s : Set α // s ∈ f ∧ s ×ˢ s ⊆ U n } := Classical.indefiniteDescription _ <| (cauchy_iff.1 hf).2 (U n) (U_mem n) /-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides an antitone sequence of sets `s n ∈ f` such that `s n ×ˢ s n ⊆ U`. -/ def setSeq (n : ℕ) : Set α := ⋂ m ∈ Set.Iic n, (setSeqAux hf U_mem m).val theorem setSeq_mem (n : ℕ) : setSeq hf U_mem n ∈ f := (biInter_mem (finite_le_nat n)).2 fun m _ => (setSeqAux hf U_mem m).2.1 theorem setSeq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : setSeq hf U_mem n ⊆ setSeq hf U_mem m := biInter_subset_biInter_left <| Iic_subset_Iic.2 h theorem setSeq_sub_aux (n : ℕ) : setSeq hf U_mem n ⊆ setSeqAux hf U_mem n := biInter_subset_of_mem right_mem_Iic theorem setSeq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) : setSeq hf U_mem m ×ˢ setSeq hf U_mem n ⊆ U N := fun p hp => by refine (setSeqAux hf U_mem N).2.2 ⟨?_, ?_⟩ <;> apply setSeq_sub_aux · exact setSeq_mono hf U_mem hm hp.1 · exact setSeq_mono hf U_mem hn hp.2 /-- A sequence of points such that `seq n ∈ setSeq n`. Here `setSeq` is an antitone sequence of sets `setSeq n ∈ f` with diameters controlled by a given sequence of entourages. -/ def seq (n : ℕ) : α := (hf.1.nonempty_of_mem (setSeq_mem hf U_mem n)).choose theorem seq_mem (n : ℕ) : seq hf U_mem n ∈ setSeq hf U_mem n := (hf.1.nonempty_of_mem (setSeq_mem hf U_mem n)).choose_spec theorem seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) : (seq hf U_mem m, seq hf U_mem n) ∈ U N := setSeq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩ theorem seq_is_cauchySeq (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) : CauchySeq <| seq hf U_mem := cauchySeq_of_controlled U U_le <| seq_pair_mem hf U_mem /-- If the sequence `SequentiallyComplete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/ theorem le_nhds_of_seq_tendsto_nhds (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s) ⦃a : α⦄ (ha : Tendsto (seq hf U_mem) atTop (𝓝 a)) : f ≤ 𝓝 a := le_nhds_of_cauchy_adhp_aux (fun s hs => by rcases U_le s hs with ⟨m, hm⟩ rcases tendsto_atTop'.1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩ refine ⟨setSeq hf U_mem (max m n), setSeq_mem hf U_mem _, ?_, seq hf U_mem (max m n), ?_, seq_mem hf U_mem _⟩ · have := le_max_left m n exact Set.Subset.trans (setSeq_prod_subset hf U_mem this this) hm · exact hm (hn _ <| le_max_right m n)) end end SequentiallyComplete namespace UniformSpace open SequentiallyComplete variable [IsCountablyGenerated (𝓤 α)] /-- A uniform space is complete provided that (a) its uniformity filter has a countable basis; (b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/ theorem complete_of_convergent_controlled_sequences (U : ℕ → Set (α × α)) (U_mem : ∀ n, U n ∈ 𝓤 α) (HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, Tendsto u atTop (𝓝 a)) : CompleteSpace α := by obtain ⟨U', -, hU'⟩ := (𝓤 α).exists_antitone_seq have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α := fun n => inter_mem (U_mem n) (hU'.2 ⟨n, Subset.refl _⟩) refine ⟨fun hf => (HU (seq hf Hmem) fun N m n hm hn => ?_).imp <| le_nhds_of_seq_tendsto_nhds _ _ fun s hs => ?_⟩ · exact inter_subset_left (seq_pair_mem hf Hmem hm hn) · rcases hU'.1 hs with ⟨N, hN⟩ exact ⟨N, Subset.trans inter_subset_right hN⟩ /-- A sequentially complete uniform space with a countable basis of the uniformity filter is complete. -/ theorem complete_of_cauchySeq_tendsto (H' : ∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) : CompleteSpace α := let ⟨U', _, hU'⟩ := (𝓤 α).exists_antitone_seq complete_of_convergent_controlled_sequences U' (fun n => hU'.2 ⟨n, Subset.refl _⟩) fun u hu => H' u <| cauchySeq_of_controlled U' (fun _ hs => hU'.1 hs) hu variable (α) -- TODO: move to `Topology.UniformSpace.Basic` instance (priority := 100) firstCountableTopology : FirstCountableTopology α := ⟨fun a => by rw [nhds_eq_comap_uniformity]; infer_instance⟩ /-- A separable uniform space with countably generated uniformity filter is second countable: one obtains a countable basis by taking the balls centered at points in a dense subset, and with rational "radii" from a countable open symmetric antitone basis of `𝓤 α`. We do not register this as an instance, as there is already an instance going in the other direction from second countable spaces to separable spaces, and we want to avoid loops. -/ theorem secondCountable_of_separable [SeparableSpace α] : SecondCountableTopology α := by rcases exists_countable_dense α with ⟨s, hsc, hsd⟩ obtain ⟨t : ℕ → Set (α × α), hto : ∀ i : ℕ, t i ∈ (𝓤 α).sets ∧ IsOpen (t i) ∧ IsSymmetricRel (t i), h_basis : (𝓤 α).HasAntitoneBasis t⟩ := (@uniformity_hasBasis_open_symmetric α _).exists_antitone_subbasis choose ht_mem hto hts using hto refine ⟨⟨⋃ x ∈ s, range fun k => ball x (t k), hsc.biUnion fun x _ => countable_range _, ?_⟩⟩ refine (isTopologicalBasis_of_isOpen_of_nhds ?_ ?_).eq_generateFrom · simp only [mem_iUnion₂, mem_range] rintro _ ⟨x, _, k, rfl⟩ exact isOpen_ball x (hto k) · intro x V hxV hVo simp only [mem_iUnion₂, mem_range, exists_prop] rcases UniformSpace.mem_nhds_iff.1 (IsOpen.mem_nhds hVo hxV) with ⟨U, hU, hUV⟩ rcases comp_symm_of_uniformity hU with ⟨U', hU', _, hUU'⟩ rcases h_basis.toHasBasis.mem_iff.1 hU' with ⟨k, -, hk⟩ rcases hsd.inter_open_nonempty (ball x <| t k) (isOpen_ball x (hto k)) ⟨x, UniformSpace.mem_ball_self _ (ht_mem k)⟩ with ⟨y, hxy, hys⟩ refine ⟨_, ⟨y, hys, k, rfl⟩, (hts k).subset hxy, fun z hz => ?_⟩ exact hUV (ball_subset_of_comp_subset (hk hxy) hUU' (hk hz)) end UniformSpace
Piecewise.lean
/- Copyright (c) 2025 Mitchell Horner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Horner -/ import Mathlib.Analysis.Convex.Function /-! # Convex and concave piecewise functions This file proves convex and concave theorems for piecewise functions. ## Main statements * `convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici` is the proof that the piecewise function `(Set.Iic e).piecewise f g` of a function `f` decreasing and convex on `Set.Iic e` and a function `g` increasing and convex on `Set.Ici e`, such that `f e = g e`, is convex on the universal set. This version has the boundary point included in the left-hand function. See `convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic` for the version with the boundary point included in the right-hand function. See concave version(s) `concaveOn_univ_piecewise_Iic_of_monotoneOn_Iic_antitoneOn_Ici` and `concaveOn_univ_piecewise_Ici_of_antitoneOn_Ici_monotoneOn_Iic`. -/ variable {𝕜 E β : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [Module 𝕜 β] [PosSMulMono 𝕜 β] {e : E} {f g : E → β} /-- The piecewise function `(Set.Iic e).piecewise f g` of a function `f` decreasing and convex on `Set.Iic e` and a function `g` increasing and convex on `Set.Ici e`, such that `f e = g e`, is convex on the universal set. -/ theorem convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici (hf : ConvexOn 𝕜 (Set.Iic e) f) (hg : ConvexOn 𝕜 (Set.Ici e) g) (h_anti : AntitoneOn f (Set.Iic e)) (h_mono : MonotoneOn g (Set.Ici e)) (h_eq : f e = g e) : ConvexOn 𝕜 Set.univ ((Set.Iic e).piecewise f g) := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ ?_⟩ by_cases hx : x ≤ e <;> by_cases hy : y ≤ e <;> push_neg at hx hy · have hc : a • x + b • y ≤ e := (Convex.combo_le_max x y ha hb hab).trans (max_le hx hy) rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hx, Set.piecewise_eq_of_mem (Set.Iic e) f g hy, Set.piecewise_eq_of_mem (Set.Iic e) f g hc] exact hf.2 hx hy ha hb hab · rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hx, Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hy)] by_cases hc : a • x + b • y ≤ e <;> push_neg at hc · rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hc] have hc' : a • x + b • e ≤ a • x + b • y := by gcongr trans a • f x + b • f e · exact (h_anti (hc'.trans hc) hc hc').trans (hf.2 hx Set.right_mem_Iic ha hb hab) · rw [h_eq] gcongr exact h_mono Set.left_mem_Ici hy.le hy.le · rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hc)] have hc' : a • x + b • y ≤ a • e + b • y := by gcongr trans a • g e + b • g y · exact (h_mono hc.le (hc.le.trans hc') hc').trans (hg.2 Set.left_mem_Ici hy.le ha hb hab) · rw [← h_eq] gcongr exact h_anti hx Set.right_mem_Iic hx · rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hx), Set.piecewise_eq_of_mem (Set.Iic e) f g hy] by_cases hc : a • x + b • y ≤ e <;> push_neg at hc · rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hc] have hc' : a • e + b • y ≤ a • x + b • y := by gcongr trans a • f e + b • f y · exact (h_anti (hc'.trans hc) hc hc').trans (hf.2 Set.right_mem_Iic hy ha hb hab) · rw [h_eq] gcongr exact h_mono Set.left_mem_Ici hx.le hx.le · rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hc)] have hc' : a • x + b • y ≤ a • x + b • e := by gcongr trans a • g x + b • g e · exact (h_mono hc.le (hc.le.trans hc') hc').trans (hg.2 hx.le Set.left_mem_Ici ha hb hab) · rw [← h_eq] gcongr exact h_anti hy Set.right_mem_Iic hy · have hc : e < a • x + b • y := (lt_min hx hy).trans_le (Convex.min_le_combo x y ha hb hab) rw [(Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hx), (Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hy), (Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hc)] exact hg.2 hx.le hy.le ha hb hab /-- The piecewise function `(Set.Ici e).piecewise f g` of a function `f` increasing and convex on `Set.Ici e` and a function `g` decreasing and convex on `Set.Iic e`, such that `f e = g e`, is convex on the universal set. -/ theorem convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic (hf : ConvexOn 𝕜 (Set.Ici e) f) (hg : ConvexOn 𝕜 (Set.Iic e) g) (h_mono : MonotoneOn f (Set.Ici e)) (h_anti : AntitoneOn g (Set.Iic e)) (h_eq : f e = g e) : ConvexOn 𝕜 Set.univ ((Set.Ici e).piecewise f g) := by have h_piecewise_Ici_eq_piecewise_Iic : (Set.Ici e).piecewise f g = (Set.Iic e).piecewise g f := by ext x; by_cases hx : x = e <;> simp [Set.piecewise, @le_iff_lt_or_eq _ _ x e, ← @ite_not _ (e ≤ _), hx, h_eq] rw [h_piecewise_Ici_eq_piecewise_Iic] exact convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici hg hf h_anti h_mono h_eq.symm /-- The piecewise function `(Set.Iic e).piecewise f g` of a function `f` increasing and concave on `Set.Iic e` and a function `g` decreasing and concave on `Set.Ici e`, such that `f e = g e`, is concave on the universal set. -/ theorem concaveOn_univ_piecewise_Iic_of_monotoneOn_Iic_antitoneOn_Ici (hf : ConcaveOn 𝕜 (Set.Iic e) f) (hg : ConcaveOn 𝕜 (Set.Ici e) g) (h_mono : MonotoneOn f (Set.Iic e)) (h_anti : AntitoneOn g (Set.Ici e)) (h_eq : f e = g e) : ConcaveOn 𝕜 Set.univ ((Set.Iic e).piecewise f g) := by rw [← neg_convexOn_iff, ← Set.piecewise_neg] exact convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici hf.neg hg.neg h_mono.neg h_anti.neg (neg_inj.mpr h_eq) /-- The piecewise function `(Set.Ici e).piecewise f g` of a function `f` decreasing and concave on `Set.Ici e` and a function `g` increasing and concave on `Set.Iic e`, such that `f e = g e`, is concave on the universal set. -/ theorem concaveOn_univ_piecewise_Ici_of_antitoneOn_Ici_monotoneOn_Iic (hf : ConcaveOn 𝕜 (Set.Ici e) f) (hg : ConcaveOn 𝕜 (Set.Iic e) g) (h_anti : AntitoneOn f (Set.Ici e)) (h_mono : MonotoneOn g (Set.Iic e)) (h_eq : f e = g e) : ConcaveOn 𝕜 Set.univ ((Set.Ici e).piecewise f g) := by rw [← neg_convexOn_iff, ← Set.piecewise_neg] exact convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic hf.neg hg.neg h_anti.neg h_mono.neg (neg_inj.mpr h_eq)
ParallelPair.lean
/- Copyright (c) 2025 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Comma.Final import Mathlib.CategoryTheory.Limits.Indization.IndObject /-! # Parallel pairs of natural transformations between ind-objects We show that if `A` and `B` are ind-objects and `f` and `g` are natural transformations between `A` and `B`, then there is a small filtered category `I` such that `A`, `B`, `f` and `g` are commonly presented by diagrams and natural transformations in `I ⥤ C`. ## References * [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Proposition 6.1.15 (though our proof is more direct). -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Limits Functor variable {C : Type u₁} [Category.{v₁} C] /-- Structure containing data exhibiting two parallel natural transformations `f` and `g` between presheaves `A` and `B` as induced by a natural transformation in a functor category exhibiting `A` and `B` as ind-objects. -/ structure IndParallelPairPresentation {A B : Cᵒᵖ ⥤ Type v₁} (f g : A ⟶ B) where /-- The indexing category. -/ I : Type v₁ /-- Category instance on the indexing category. -/ [ℐ : SmallCategory I] [hI : IsFiltered I] /-- The diagram presenting `A`. -/ F₁ : I ⥤ C /-- The diagram presenting `B`. -/ F₂ : I ⥤ C /-- The cocone on `F₁` with apex `A`. -/ ι₁ : F₁ ⋙ yoneda ⟶ (Functor.const I).obj A /-- The cocone on `F₁` with apex `A` is a colimit cocone. -/ isColimit₁ : IsColimit (Cocone.mk A ι₁) /-- The cocone on `F₂` with apex `B`. -/ ι₂ : F₂ ⋙ yoneda ⟶ (Functor.const I).obj B /-- The cocone on `F₂` with apex `B` is a colimit cocone. -/ isColimit₂ : IsColimit (Cocone.mk B ι₂) /-- The natural transformation presenting `f`. -/ φ : F₁ ⟶ F₂ /-- The natural transformation presenting `g`. -/ ψ : F₁ ⟶ F₂ /-- `f` is in fact presented by `φ`. -/ hf : f = IsColimit.map isColimit₁ (Cocone.mk B ι₂) (whiskerRight φ yoneda) /-- `g` is in fact presented by `ψ`. -/ hg : g = IsColimit.map isColimit₁ (Cocone.mk B ι₂) (whiskerRight ψ yoneda) instance {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : SmallCategory P.I := P.ℐ instance {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : IsFiltered P.I := P.hI namespace NonemptyParallelPairPresentationAux variable {A B : Cᵒᵖ ⥤ Type v₁} (f g : A ⟶ B) (P₁ : IndObjectPresentation A) (P₂ : IndObjectPresentation B) /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev K : Type v₁ := Comma ((P₁.toCostructuredArrow ⋙ CostructuredArrow.map f).prod' (P₁.toCostructuredArrow ⋙ CostructuredArrow.map g)) (P₂.toCostructuredArrow.prod' P₂.toCostructuredArrow) /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev F₁ : K f g P₁ P₂ ⥤ C := Comma.fst _ _ ⋙ P₁.F /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev F₂ : K f g P₁ P₂ ⥤ C := Comma.snd _ _ ⋙ P₂.F /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev ι₁ : F₁ f g P₁ P₂ ⋙ yoneda ⟶ (Functor.const (K f g P₁ P₂)).obj A := whiskerLeft (Comma.fst _ _) P₁.ι /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable abbrev isColimit₁ : IsColimit (Cocone.mk A (ι₁ f g P₁ P₂)) := (Functor.Final.isColimitWhiskerEquiv _ _).symm P₁.isColimit /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ abbrev ι₂ : F₂ f g P₁ P₂ ⋙ yoneda ⟶ (Functor.const (K f g P₁ P₂)).obj B := whiskerLeft (Comma.snd _ _) P₂.ι /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable abbrev isColimit₂ : IsColimit (Cocone.mk B (ι₂ f g P₁ P₂)) := (Functor.Final.isColimitWhiskerEquiv _ _).symm P₂.isColimit /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ def ϕ : F₁ f g P₁ P₂ ⟶ F₂ f g P₁ P₂ where app h := h.hom.1.left naturality _ _ h := by have := h.w simp only [Functor.prod'_obj, Functor.comp_obj, prod_Hom, Functor.prod'_map, Functor.comp_map, prod_comp, Prod.mk.injEq, CostructuredArrow.hom_eq_iff, CostructuredArrow.map_obj_left, IndObjectPresentation.toCostructuredArrow_obj_left, CostructuredArrow.comp_left, CostructuredArrow.map_map_left, IndObjectPresentation.toCostructuredArrow_map_left] at this exact this.1 theorem hf : f = IsColimit.map (isColimit₁ f g P₁ P₂) (Cocone.mk B (ι₂ f g P₁ P₂)) (whiskerRight (ϕ f g P₁ P₂) yoneda) := by refine (isColimit₁ f g P₁ P₂).hom_ext (fun i => ?_) rw [IsColimit.ι_map] simpa using i.hom.1.w.symm /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ def ψ : F₁ f g P₁ P₂ ⟶ F₂ f g P₁ P₂ where app h := h.hom.2.left naturality _ _ h := by have := h.w simp only [Functor.prod'_obj, Functor.comp_obj, prod_Hom, Functor.prod'_map, Functor.comp_map, prod_comp, Prod.mk.injEq, CostructuredArrow.hom_eq_iff, CostructuredArrow.map_obj_left, IndObjectPresentation.toCostructuredArrow_obj_left, CostructuredArrow.comp_left, CostructuredArrow.map_map_left, IndObjectPresentation.toCostructuredArrow_map_left] at this exact this.2 theorem hg : g = IsColimit.map (isColimit₁ f g P₁ P₂) (Cocone.mk B (ι₂ f g P₁ P₂)) (whiskerRight (ψ f g P₁ P₂) yoneda) := by refine (isColimit₁ f g P₁ P₂).hom_ext (fun i => ?_) rw [IsColimit.ι_map] simpa using i.hom.2.w.symm attribute [local instance] Comma.isFiltered_of_final in /-- Implementation; see `nonempty_indParallelPairPresentation`. -/ noncomputable def presentation : IndParallelPairPresentation f g where I := K f g P₁ P₂ F₁ := F₁ f g P₁ P₂ F₂ := F₂ f g P₁ P₂ ι₁ := ι₁ f g P₁ P₂ isColimit₁ := isColimit₁ f g P₁ P₂ ι₂ := ι₂ f g P₁ P₂ isColimit₂ := isColimit₂ f g P₁ P₂ φ := ϕ f g P₁ P₂ ψ := ψ f g P₁ P₂ hf := hf f g P₁ P₂ hg := hg f g P₁ P₂ end NonemptyParallelPairPresentationAux theorem nonempty_indParallelPairPresentation {A B : Cᵒᵖ ⥤ Type v₁} (hA : IsIndObject A) (hB : IsIndObject B) (f g : A ⟶ B) : Nonempty (IndParallelPairPresentation f g) := ⟨NonemptyParallelPairPresentationAux.presentation f g hA.presentation hB.presentation⟩ namespace IndParallelPairPresentation /-- Given an `IndParallelPairPresentation f g`, we can understand the parallel pair `(f, g)` as the colimit of `(P.φ, P.ψ)` in `Cᵒᵖ ⥤ Type v`. -/ noncomputable def parallelPairIsoParallelPairCompYoneda {A B : Cᵒᵖ ⥤ Type v₁} {f g : A ⟶ B} (P : IndParallelPairPresentation f g) : parallelPair f g ≅ parallelPair P.φ P.ψ ⋙ (whiskeringRight _ _ _).obj yoneda ⋙ colim := parallelPair.ext (P.isColimit₁.coconePointUniqueUpToIso (colimit.isColimit _)) (P.isColimit₂.coconePointUniqueUpToIso (colimit.isColimit _)) (P.isColimit₁.hom_ext (fun j => by simp [P.hf, P.isColimit₁.ι_map_assoc, P.isColimit₁.comp_coconePointUniqueUpToIso_hom_assoc, P.isColimit₂.comp_coconePointUniqueUpToIso_hom])) (P.isColimit₁.hom_ext (fun j => by simp [P.hg, P.isColimit₁.ι_map_assoc, P.isColimit₁.comp_coconePointUniqueUpToIso_hom_assoc, P.isColimit₂.comp_coconePointUniqueUpToIso_hom])) end IndParallelPairPresentation end CategoryTheory
Arg.lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.SpecialFunctions.Complex.Arg /-! # Rays in the complex numbers This file links the definition `SameRay ℝ x y` with the equality of arguments of complex numbers, the usual way this is considered. ## Main statements * `Complex.sameRay_iff` : Two complex numbers are on the same ray iff one of them is zero, or they have the same argument. * `Complex.abs_add_eq/Complex.abs_sub_eq`: If two non zero complex numbers have the same argument, then the triangle inequality is an equality. -/ variable {x y : ℂ} namespace Complex theorem sameRay_iff : SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := by rcases eq_or_ne x 0 with (rfl | hx) · simp rcases eq_or_ne y 0 with (rfl | hy) · simp simp only [hx, hy, sameRay_iff_norm_smul_eq, arg_eq_arg_iff hx hy] field_simp [hx, hy] rw [mul_comm, eq_comm] theorem sameRay_iff_arg_div_eq_zero : SameRay ℝ x y ↔ arg (x / y) = 0 := by rw [← Real.Angle.toReal_zero, ← arg_coe_angle_eq_iff_eq_toReal, sameRay_iff] by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] simp [hx, hy, arg_div_coe_angle, sub_eq_zero] theorem norm_add_eq_iff : ‖x + y‖ = ‖x‖ + ‖y‖ ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := sameRay_iff_norm_add.symm.trans sameRay_iff theorem norm_sub_eq_iff : ‖x - y‖ = |‖x‖ - ‖y‖| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := sameRay_iff_norm_sub.symm.trans sameRay_iff theorem sameRay_of_arg_eq (h : x.arg = y.arg) : SameRay ℝ x y := sameRay_iff.mpr <| Or.inr <| Or.inr h theorem norm_add_eq (h : x.arg = y.arg) : ‖x + y‖ = ‖x‖ + ‖y‖ := (sameRay_of_arg_eq h).norm_add theorem norm_sub_eq (h : x.arg = y.arg) : ‖x - y‖ = ‖‖x‖ - ‖y‖‖ := (sameRay_of_arg_eq h).norm_sub @[deprecated (since := "2025-02-17")] alias abs_add_eq_iff := norm_add_eq_iff @[deprecated (since := "2025-02-17")] alias abs_sub_eq_iff := norm_sub_eq_iff @[deprecated (since := "2025-02-17")] alias abs_add_eq := norm_add_eq @[deprecated (since := "2025-02-17")] alias abs_sub_eq := norm_sub_eq end Complex
polyXY.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 seq. From mathcomp Require Import fintype tuple finfun bigop fingroup perm div. From mathcomp Require Import ssralg zmodp matrix mxalgebra. From mathcomp Require Import poly polydiv mxpoly binomial. (******************************************************************************) (* This file provides additional primitives and theory for bivariate *) (* polynomials (polynomials of two variables), represented as polynomials *) (* with (univariate) polynomial coefficients : *) (* 'Y == the (generic) second variable (:= 'X%:P). *) (* p^:P == the bivariate polynomial p['X], for p univariate. *) (* := map_poly polyC p (this notation is defined in poly.v). *) (* u.[x, y] == the bivariate polynomial u evaluated at 'X = x, 'Y = y. *) (* := u.[x%:P].[y]. *) (* sizeY u == the size of u in 'Y (1 + the 'Y-degree of u, if u != 0). *) (* := \max_(i < size u) size u`_i. *) (* swapXY u == the bivariate polynomial u['Y, 'X], for u bivariate. *) (* poly_XaY p == the bivariate polynomial p['X + 'Y], for p univariate. *) (* := p^:P \Po ('X + 'Y). *) (* poly_XmY p == the bivariate polynomial p['X * 'Y], for p univariate. *) (* := P^:P \Po ('X * 'Y). *) (* sub_annihilant p q == for univariate p, q != 0, a nonzero polynomial whose *) (* roots include all the differences of roots of p and q, in *) (* all field extensions (:= resultant (poly_XaY p) q^:P). *) (* div_annihilant p q == for polynomials p != 0, q with q.[0] != 0, a nonzero *) (* polynomial whose roots include all the quotients of roots *) (* of p by roots of q, in all field extensions *) (* (:= resultant (poly_XmY p) q^:P). *) (* The latter two "annhilants" provide uniform witnesses for an alternative *) (* proof of the closure of the algebraicOver predicate (see mxpoly.v). The *) (* fact that the annhilant does not depend on the particular choice of roots *) (* of p and q is crucial for the proof of the Primitive Element Theorem (file *) (* separable.v). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import GRing.Theory. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Local Notation eval := horner_eval. Notation "'Y" := 'X%:P : ring_scope. Notation "p ^:P" := (p ^ polyC) (format "p ^:P") : ring_scope. Notation "p .[ x , y ]" := (p.[x%:P].[y]) (left associativity, format "p .[ x , y ]") : ring_scope. Section PolyXY_NzRing. Variable R : nzRingType. Implicit Types (u : {poly {poly R}}) (p q : {poly R}) (x : R). Fact swapXY_key : unit. Proof. by []. Qed. Definition swapXY_def u : {poly {poly R}} := (u ^ map_poly polyC).['Y]. Definition swapXY := locked_with swapXY_key swapXY_def. Canonical swapXY_unlockable := [unlockable fun swapXY]. Definition sizeY u : nat := \max_(i < size u) (size u`_i). Definition poly_XaY p : {poly {poly R}} := p^:P \Po ('X + 'Y). Definition poly_XmY p : {poly {poly R}} := p^:P \Po ('X * 'Y). Definition sub_annihilant p q := resultant (poly_XaY p) q^:P. Definition div_annihilant p q := resultant (poly_XmY p) q^:P. Lemma swapXY_polyC p : swapXY p%:P = p^:P. Proof. by rewrite unlock map_polyC hornerC. Qed. Lemma swapXY_X : swapXY 'X = 'Y. Proof. by rewrite unlock map_polyX hornerX. Qed. Lemma swapXY_Y : swapXY 'Y = 'X. Proof. by rewrite swapXY_polyC map_polyX. Qed. Lemma swapXY_is_zmod_morphism : zmod_morphism swapXY. Proof. by move=> u v; rewrite unlock rmorphB !hornerE. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_zmod_morphism` instead")] Definition swapXY_is_additive := swapXY_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_zmod_morphism. Lemma coef_swapXY u i j : (swapXY u)`_i`_j = u`_j`_i. Proof. elim/poly_ind: u => [|u p IHu] in i j *; first by rewrite raddf0 !coef0. rewrite raddfD !coefD /= swapXY_polyC coef_map /= !coefC coefMX. rewrite !(fun_if (fun q : {poly R} => q`_i)) coef0 -IHu; congr (_ + _). by rewrite unlock rmorphM /= map_polyX hornerMX coefMC coefMX. Qed. Lemma swapXYK : involutive swapXY. Proof. by move=> u; apply/polyP=> i; apply/polyP=> j; rewrite !coef_swapXY. Qed. Lemma swapXY_map_polyC p : swapXY p^:P = p%:P. Proof. by rewrite -swapXY_polyC swapXYK. Qed. Lemma swapXY_eq0 u : (swapXY u == 0) = (u == 0). Proof. by rewrite (inv_eq swapXYK) raddf0. Qed. Lemma swapXY_is_monoid_morphism : monoid_morphism swapXY. Proof. split=> [|u v]; first by rewrite swapXY_polyC map_polyC. apply/polyP=> i; apply/polyP=> j; rewrite coef_swapXY !coefM !coef_sum. rewrite (eq_bigr _ (fun _ _ => coefM _ _ _)) exchange_big /=. apply: eq_bigr => j1 _; rewrite coefM; apply: eq_bigr=> i1 _. by rewrite !coef_swapXY. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `swapXY_is_monoid_morphism` instead")] Definition swapXY_is_multiplicative := (fun g => (g.2,g.1)) swapXY_is_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly {poly R}} {poly {poly R}} swapXY swapXY_is_monoid_morphism. Lemma swapXY_is_scalable : scalable_for (map_poly polyC \; *%R) swapXY. Proof. by move=> p u /=; rewrite -mul_polyC rmorphM /= swapXY_polyC. Qed. HB.instance Definition _ := GRing.isScalable.Build {poly R} {poly {poly R}} {poly {poly R}} (map_poly polyC \; *%R) swapXY swapXY_is_scalable. Lemma swapXY_comp_poly p u : swapXY (p^:P \Po u) = p^:P \Po swapXY u. Proof. rewrite -horner_map; congr _.[_]; rewrite -!map_poly_comp /=. by apply: eq_map_poly => x; rewrite /= swapXY_polyC map_polyC. Qed. Lemma max_size_coefXY u i : size u`_i <= sizeY u. Proof. have [ltiu | /(nth_default 0)->] := ltnP i (size u); last by rewrite size_poly0. exact: (bigmax_sup (Ordinal ltiu)). Qed. Lemma max_size_lead_coefXY u : size (lead_coef u) <= sizeY u. Proof. by rewrite lead_coefE max_size_coefXY. Qed. Lemma max_size_evalX u : size u.['X] <= sizeY u + (size u).-1. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // size_polyXn addnS. by rewrite leq_add ?max_size_coefXY //= -ltnS (leq_trans _ (leqSpred _)). Qed. Lemma max_size_evalC u x : size u.[x%:P] <= sizeY u. Proof. rewrite horner_coef (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP=> i _. rewrite (leq_trans (size_polyMleq _ _)) // -polyC_exp size_polyC addnC -subn1. by rewrite (leq_trans _ (max_size_coefXY _ i)) // leq_subLR leq_add2r leq_b1. Qed. Lemma sizeYE u : sizeY u = size (swapXY u). Proof. apply/eqP; rewrite eqn_leq; apply/andP; split. apply/bigmax_leqP=> /= i _; apply/leq_sizeP => j /(nth_default 0) u_j_0. by rewrite -coef_swapXY u_j_0 coef0. apply/leq_sizeP=> j le_uY_j; apply/polyP=> i; rewrite coef_swapXY coef0. by rewrite nth_default // (leq_trans _ le_uY_j) ?max_size_coefXY. Qed. Lemma sizeY_eq0 u : (sizeY u == 0) = (u == 0). Proof. by rewrite sizeYE size_poly_eq0 swapXY_eq0. Qed. Lemma sizeY_mulX u : sizeY (u * 'X) = sizeY u. Proof. rewrite !sizeYE rmorphM /= swapXY_X rreg_size //. by have /monic_comreg[_ /rreg_lead] := monicX R. Qed. Lemma swapXY_poly_XaY p : swapXY (poly_XaY p) = poly_XaY p. Proof. by rewrite swapXY_comp_poly rmorphD /= swapXY_X swapXY_Y addrC. Qed. Lemma swapXY_poly_XmY p : swapXY (poly_XmY p) = poly_XmY p. Proof. by rewrite swapXY_comp_poly rmorphM /= swapXY_X swapXY_Y commr_polyX. Qed. Lemma poly_XaY0 : poly_XaY 0 = 0. Proof. by rewrite /poly_XaY rmorph0 comp_poly0. Qed. Lemma poly_XmY0 : poly_XmY 0 = 0. Proof. by rewrite /poly_XmY rmorph0 comp_poly0. Qed. End PolyXY_NzRing. Prenex Implicits swapXY sizeY poly_XaY poly_XmY sub_annihilant div_annihilant. Prenex Implicits swapXYK. Lemma swapXY_map (R S : nzRingType) (f : {additive R -> S}) u : swapXY (u ^ map_poly f) = swapXY u ^ map_poly f. Proof. by apply/polyP=> i; apply/polyP=> j; rewrite !(coef_map, coef_swapXY). Qed. Section PolyXY_ComNzRing. Variable R : comNzRingType. Implicit Types (u : {poly {poly R}}) (p : {poly R}) (x y : R). Lemma horner_swapXY u x : (swapXY u).[x%:P] = u ^ eval x. Proof. apply/polyP=> i /=; rewrite coef_map /= /eval horner_coef coef_sum -sizeYE. rewrite (horner_coef_wide _ (max_size_coefXY u i)); apply: eq_bigr=> j _. by rewrite -polyC_exp coefMC coef_swapXY. Qed. Lemma horner_polyC u x : u.[x%:P] = swapXY u ^ eval x. Proof. by rewrite -horner_swapXY swapXYK. Qed. Lemma horner2_swapXY u x y : (swapXY u).[x, y] = u.[y, x]. Proof. by rewrite horner_swapXY -{1}(hornerC y x) horner_map. Qed. Lemma horner_poly_XaY p v : (poly_XaY p).[v] = p \Po (v + 'X). Proof. by rewrite horner_comp !hornerE. Qed. Lemma horner_poly_XmY p v : (poly_XmY p).[v] = p \Po (v * 'X). Proof. by rewrite horner_comp !hornerE. Qed. End PolyXY_ComNzRing. Section PolyXY_Idomain. Variable R : idomainType. Implicit Types (p q : {poly R}) (x y : R). Lemma size_poly_XaY p : size (poly_XaY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XaddC // size_map_polyC. Qed. Lemma poly_XaY_eq0 p : (poly_XaY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XaY. Qed. Lemma size_poly_XmY p : size (poly_XmY p) = size p. Proof. by rewrite size_comp_poly2 ?size_XmulC ?polyX_eq0 ?size_map_polyC. Qed. Lemma poly_XmY_eq0 p : (poly_XmY p == 0) = (p == 0). Proof. by rewrite -!size_poly_eq0 size_poly_XmY. Qed. Lemma lead_coef_poly_XaY p : lead_coef (poly_XaY p) = (lead_coef p)%:P. Proof. rewrite lead_coef_comp ?size_XaddC // -['Y]opprK -polyCN lead_coefXsubC. by rewrite expr1n mulr1 lead_coef_map_inj //; apply: polyC_inj. Qed. Lemma sub_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (sub_annihilant p q).[y] = uv.1.[x, y] * p.[x + y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XaY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma sub_annihilantP p q x y : p != 0 -> q != 0 -> p.[x] = 0 -> q.[y] = 0 -> (sub_annihilant p q).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := sub_annihilant_in_ideal p_gt1 q_gt1. by rewrite (addrC y) subrK px0 qy0 !mulr0 addr0. Qed. Lemma sub_annihilant_neq0 p q : p != 0 -> q != 0 -> sub_annihilant p q != 0. Proof. rewrite resultant_eq0; set p1 := poly_XaY p => nz_p nz_q. have [nz_p1 nz_q1]: p1 != 0 /\ q^:P != 0 by rewrite poly_XaY_eq0 map_polyC_eq0. rewrite -leqNgt eq_leq //; apply/eqP/Bezout_coprimepPn=> // [[[u v]]] /=. rewrite !size_poly_gt0 -andbA => /and4P[nz_u ltuq nz_v _] Duv. have /eqP/= := congr1 (size \o (lead_coef \o swapXY)) Duv. rewrite ltn_eqF // !rmorphM !lead_coefM (leq_trans (leq_ltn_trans _ ltuq)) //=. rewrite -{2}[u]swapXYK -sizeYE swapXY_poly_XaY lead_coef_poly_XaY. by rewrite mulrC mul_polyC size_scale ?max_size_lead_coefXY ?lead_coef_eq0. rewrite swapXY_map_polyC lead_coefC size_map_polyC. set v1 := lead_coef _; have nz_v1: v1 != 0 by rewrite lead_coef_eq0 swapXY_eq0. rewrite [leqRHS]polySpred ?mulf_neq0 // size_mul //. by rewrite (polySpred nz_v1) addnC addnS polySpred // ltnS leq_addr. Qed. Lemma div_annihilant_in_ideal p q : 1 < size p -> 1 < size q -> {uv : {poly {poly R}} * {poly {poly R}} | size uv.1 < size q /\ size uv.2 < size p & forall x y, (div_annihilant p q).[y] = uv.1.[x, y] * p.[x * y] + uv.2.[x, y] * q.[x]}. Proof. rewrite -size_poly_XmY -(size_map_polyC q) => p1_gt1 q1_gt1. have [uv /= [ub_u ub_v Dr]] := resultant_in_ideal p1_gt1 q1_gt1. exists uv => // x y; rewrite -[r in r.[y]](hornerC _ x%:P) Dr. by rewrite !(hornerE, horner_comp). Qed. Lemma div_annihilant_neq0 p q : p != 0 -> q.[0] != 0 -> div_annihilant p q != 0. Proof. have factorX u: u != 0 -> root u 0 -> exists2 v, v != 0 & u = v * 'X. move=> nz_u /factor_theorem[v]; rewrite subr0 => Du; exists v => //. by apply: contraNneq nz_u => v0; rewrite Du v0 mul0r. have nzX: 'X != 0 := monic_neq0 (monicX _); have rootC0 := root_polyC _ 0. rewrite resultant_eq0 -leqNgt -rootE // => nz_p nz_q0; apply/eq_leq/eqP. have nz_q: q != 0 by apply: contraNneq nz_q0 => ->; rewrite root0. apply/Bezout_coprimepPn; rewrite ?map_polyC_eq0 ?poly_XmY_eq0 // => [[uv]]. rewrite !size_poly_gt0 -andbA ltnNge => /and4P[nz_u /negP ltuq nz_v _] Duv. pose u := swapXY uv.1; pose v := swapXY uv.2. suffices{ltuq}: size q <= sizeY u by rewrite sizeYE swapXYK -size_map_polyC. have{nz_u nz_v} [nz_u nz_v Dvu]: [/\ u != 0, v != 0 & q *: v = u * poly_XmY p]. rewrite !swapXY_eq0; split=> //; apply: (can_inj swapXYK). by rewrite linearZ rmorphM /= !swapXYK swapXY_poly_XmY Duv mulrC. have{Duv} [n ltvn]: {n | size v < n} by exists (size v).+1. elim: n {uv} => // n IHn in p (v) (u) nz_u nz_v Dvu nz_p ltvn *. have Dp0: root (poly_XmY p) 0 = root p 0 by rewrite root_comp !hornerE rootC0. have Dv0: root u 0 || root p 0 = root v 0 by rewrite -Dp0 -rootM -Dvu rootZ. have [v0_0 | nz_v0] := boolP (root v 0); last first. have nz_p0: ~~ root p 0 by apply: contra nz_v0; rewrite -Dv0 orbC => ->. apply: (@leq_trans (size (q * v.[0]))). by rewrite size_mul // (polySpred nz_v0) addnS leq_addr. rewrite -hornerZ Dvu !(horner_comp, hornerE) horner_map mulrC size_Cmul //. by rewrite horner_coef0 max_size_coefXY. have [v1 nz_v1 Dv] := factorX _ _ nz_v v0_0; rewrite Dv size_mulX // in ltvn. have /orP[/factorX[//|u1 nz_u1 Du] | p0_0]: root u 0 || root p 0 by rewrite Dv0. rewrite Du sizeY_mulX; apply: IHn nz_u1 nz_v1 _ nz_p ltvn. by apply: (mulIf (nzX _)); rewrite mulrAC -scalerAl -Du -Dv. have /factorX[|v2 nz_v2 Dv1]: root (swapXY v1) 0; rewrite ?swapXY_eq0 //. suffices: root (swapXY v1 * 'Y) 0 by rewrite mulrC mul_polyC rootZ ?polyX_eq0. have: root (swapXY (q *: v)) 0. by rewrite Dvu rmorphM rootM /= swapXY_poly_XmY Dp0 p0_0 orbT. by rewrite linearZ /= rootM rootC0 (negPf nz_q0) /= Dv rmorphM /= swapXY_X. rewrite ltnS (canRL swapXYK Dv1) -sizeYE sizeY_mulX sizeYE in ltvn. have [p1 nz_p1 Dp] := factorX _ _ nz_p p0_0. apply: IHn nz_u _ _ nz_p1 ltvn; first by rewrite swapXY_eq0. have: 'X * 'Y != 0 :> {poly {poly R}} by rewrite mulf_neq0 ?polyC_eq0 ?nzX. move/mulIf; apply. rewrite -scalerAl mulrA mulrAC -{1}swapXY_X -rmorphM /= -Dv1 swapXYK -Dv Dvu. by rewrite /poly_XmY Dp rmorphM /= map_polyX comp_polyM comp_polyX mulrA. Qed. End PolyXY_Idomain. Section PolyXY_Field. Variables (F E : fieldType) (FtoE : {rmorphism F -> E}). Local Notation pFtoE := (map_poly (GRing.RMorphism.sort FtoE)). Lemma div_annihilantP (p q : {poly E}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> p.[x] = 0 -> q.[y] = 0 -> (div_annihilant p q).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0. have p_gt1: size p > 1 by have /rootP/root_size_gt1-> := px0. have q_gt1: size q > 1 by have /rootP/root_size_gt1-> := qy0. have [uv /= _ /(_ y)->] := div_annihilant_in_ideal p_gt1 q_gt1. by rewrite (mulrC y) divfK // px0 qy0 !mulr0 addr0. Qed. Lemma map_sub_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 ->(p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (sub_annihilant p q ^ FtoE).[x - y] = 0. Proof. move=> nz_p nz_q px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XaY_eq0 //. rewrite map_comp_poly rmorphD /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp sub_annihilantP ?pFto0. Qed. Lemma map_div_annihilantP (p q : {poly F}) (x y : E) : p != 0 -> q != 0 -> y != 0 -> (p ^ FtoE).[x] = 0 -> (q ^ FtoE).[y] = 0 -> (div_annihilant p q ^ FtoE).[x / y] = 0. Proof. move=> nz_p nz_q nz_y px0 qy0; have pFto0 := map_poly_eq0 FtoE. rewrite map_resultant ?pFto0 ?lead_coef_eq0 ?map_poly_eq0 ?poly_XmY_eq0 //. rewrite map_comp_poly rmorphM /= map_polyC /= !map_polyX -!map_poly_comp /=. by rewrite !(eq_map_poly (map_polyC _)) !map_poly_comp div_annihilantP ?pFto0. Qed. Lemma root_annihilant x p (pEx := (p ^ pFtoE).[x%:P]) : pEx != 0 -> algebraicOver FtoE x -> exists2 r : {poly F}, r != 0 & forall y, root pEx y -> root (r ^ FtoE) y. Proof. move=> nz_px [q nz_q qx0]. have [/size1_polyC Dp | p_gt1] := leqP (size p) 1. by rewrite {}/pEx Dp map_polyC hornerC map_poly_eq0 in nz_px *; exists p`_0. have nz_p: p != 0 by rewrite -size_poly_gt0 ltnW. have [m le_qm] := ubnP (size q); elim: m => // m IHm in q le_qm nz_q qx0 *. have nz_q1: q^:P != 0 by rewrite map_poly_eq0. have sz_q1: size q^:P = size q by rewrite size_map_polyC. have q1_gt1: size q^:P > 1. by rewrite sz_q1 -(size_map_poly FtoE) (root_size_gt1 _ qx0) ?map_poly_eq0. have [uv _ Dr] := resultant_in_ideal p_gt1 q1_gt1; set r := resultant p _ in Dr. have /eqP q1x0: (q^:P ^ pFtoE).[x%:P] == 0. by rewrite -swapXY_polyC -swapXY_map horner_swapXY !map_polyC polyC_eq0. have [|r_nz] := boolP (r == 0); last first. exists r => // y pxy0; rewrite -[r ^ _](hornerC _ x%:P) -map_polyC Dr. by rewrite rmorphD !rmorphM !hornerE q1x0 mulr0 addr0 rootM pxy0 orbT. rewrite resultant_eq0 => /gtn_eqF/Bezout_coprimepPn[]// [q2 p1] /=. rewrite size_poly_gt0 sz_q1 => /andP[/andP[nz_q2 ltq2] _] Dq. pose n := (size (lead_coef q2)).-1; pose q3 := map_poly (coefp n) q2. have nz_q3: q3 != 0 by rewrite map_poly_eq0_id0 ?lead_coef_eq0. apply: (IHm q3); rewrite ?(leq_ltn_trans (size_poly _ _)) ?(leq_trans ltq2) //. have /polyP/(_ n)/eqP: (q2 ^ pFtoE).[x%:P] = 0. apply: (mulIf nz_px); rewrite -hornerM -rmorphM Dq rmorphM hornerM /= q1x0. by rewrite mul0r mulr0. rewrite coef0; congr (_ == 0); rewrite !horner_coef coef_sum. rewrite size_map_poly !size_map_poly_id0 ?map_poly_eq0 ?lead_coef_eq0 //. by apply: eq_bigr => i _; rewrite -rmorphXn coefMC !coef_map. Qed. Lemma algebraic_root_polyXY x y : (let pEx p := (p ^ map_poly FtoE).[x%:P] in exists2 p, pEx p != 0 & root (pEx p) y) -> algebraicOver FtoE x -> algebraicOver FtoE y. Proof. by case=> p nz_px pxy0 /(root_annihilant nz_px)[r]; exists r; auto. Qed. End PolyXY_Field.
all_solvable.v
From mathcomp Require Export abelian. From mathcomp Require Export alt. From mathcomp Require Export burnside_app. From mathcomp Require Export center. From mathcomp Require Export commutator. From mathcomp Require Export cyclic. From mathcomp Require Export extraspecial. From mathcomp Require Export extremal. From mathcomp Require Export finmodule. From mathcomp Require Export frobenius. From mathcomp Require Export gfunctor. From mathcomp Require Export gseries. From mathcomp Require Export hall. From mathcomp Require Export jordanholder. From mathcomp Require Export maximal. From mathcomp Require Export nilpotent. From mathcomp Require Export pgroup. From mathcomp Require Export primitive_action. From mathcomp Require Export sylow.
CondexpL1.lean
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL2 import Mathlib.MeasureTheory.Measure.Real /-! # Conditional expectation in L1 This file contains two more steps of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. The conditional expectation of an `L²` function is defined in `MeasureTheory.Function.ConditionalExpectation.CondexpL2`. In this file, we perform two steps. * Show that the conditional expectation of the indicator of a measurable set with finite measure is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set with value `x`. * Extend that map to `condExpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`). ## Main definitions * `condExpL1`: Conditional expectation of a function as a linear map from `L1` to itself. -/ noncomputable section open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap open scoped NNReal ENNReal Topology MeasureTheory namespace MeasureTheory variable {α F F' G G' 𝕜 : Type*} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- F' for integrals on a Lp submodule [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F'] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] section CondexpInd /-! ## Conditional expectation of an indicator as a continuous linear map. The goal of this section is to build `condExpInd (hm : m ≤ m0) (μ : Measure α) (s : Set s) : G →L[ℝ] α →₁[μ] G`, which takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`, seen as an element of `α →₁[μ] G`. -/ variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedSpace ℝ G] section CondexpIndL1Fin /-- Conditional expectation of the indicator of a measurable set with finite measure, as a function in L1. -/ def condExpIndL1Fin (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : α →₁[μ] G := (integrable_condExpIndSMul hm hs hμs x).toL1 _ theorem condExpIndL1Fin_ae_eq_condExpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condExpIndL1Fin hm hs hμs x =ᵐ[μ] condExpIndSMul hm hs hμs x := (integrable_condExpIndSMul hm hs hμs x).coeFn_toL1 variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] -- Porting note: this lemma fills the hole in `refine' (MemLp.coeFn_toLp _) ...` -- which is not automatically filled in Lean 4 private theorem q {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {x : G} : MemLp (condExpIndSMul hm hs hμs x) 1 μ := by rw [memLp_one_iff_integrable]; apply integrable_condExpIndSMul theorem condExpIndL1Fin_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condExpIndL1Fin hm hs hμs (x + y) = condExpIndL1Fin hm hs hμs x + condExpIndL1Fin hm hs hμs y := by ext1 refine (MemLp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine EventuallyEq.trans ?_ (EventuallyEq.add (MemLp.coeFn_toLp q).symm (MemLp.coeFn_toLp q).symm) rw [condExpIndSMul_add] refine (Lp.coeFn_add _ _).trans (Eventually.of_forall fun a => ?_) rfl theorem condExpIndL1Fin_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condExpIndL1Fin hm hs hμs (c • x) = c • condExpIndL1Fin hm hs hμs x := by ext1 refine (MemLp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condExpIndSMul_smul hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] theorem condExpIndL1Fin_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condExpIndL1Fin hm hs hμs (c • x) = c • condExpIndL1Fin hm hs hμs x := by ext1 refine (MemLp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condExpIndSMul_smul' hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] theorem norm_condExpIndL1Fin_le (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : ‖condExpIndL1Fin hm hs hμs x‖ ≤ μ.real s * ‖x‖ := by rw [L1.norm_eq_integral_norm, ← ENNReal.toReal_ofReal (norm_nonneg x), measureReal_def, ← ENNReal.toReal_mul, ← ENNReal.ofReal_le_iff_le_toReal (ENNReal.mul_ne_top hμs ENNReal.ofReal_ne_top), ofReal_integral_norm_eq_lintegral_enorm] swap; · rw [← memLp_one_iff_integrable]; exact Lp.memLp _ have h_eq : ∫⁻ a, ‖condExpIndL1Fin hm hs hμs x a‖ₑ ∂μ = ∫⁻ a, ‖condExpIndSMul hm hs hμs x a‖ₑ ∂μ := by refine lintegral_congr_ae ?_ refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x).mono fun z hz => ?_ dsimp only rw [hz] rw [h_eq, ofReal_norm_eq_enorm] exact lintegral_nnnorm_condExpIndSMul_le hm hs hμs x theorem condExpIndL1Fin_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) : condExpIndL1Fin hm (hs.union ht) ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne x = condExpIndL1Fin hm hs hμs x + condExpIndL1Fin hm ht hμt x := by ext1 have hμst := measure_union_ne_top hμs hμt refine (condExpIndL1Fin_ae_eq_condExpIndSMul hm (hs.union ht) hμst x).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm have hs_eq := condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x have ht_eq := condExpIndL1Fin_ae_eq_condExpIndSMul hm ht hμt x refine EventuallyEq.trans ?_ (EventuallyEq.add hs_eq.symm ht_eq.symm) rw [condExpIndSMul] rw [indicatorConstLp_disjoint_union hs ht hμs hμt hst (1 : ℝ)] rw [(condExpL2 ℝ ℝ hm).map_add] push_cast rw [((toSpanSingleton ℝ x).compLpL 2 μ).map_add] refine (Lp.coeFn_add _ _).trans ?_ filter_upwards with y using rfl end CondexpIndL1Fin section CondexpIndL1 open scoped Classical in /-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets which are not both measurable and of finite measure is not used: we set it to 0. -/ def condExpIndL1 {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) (s : Set α) [SigmaFinite (μ.trim hm)] (x : G) : α →₁[μ] G := if hs : MeasurableSet s ∧ μ s ≠ ∞ then condExpIndL1Fin hm hs.1 hs.2 x else 0 variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] theorem condExpIndL1_of_measurableSet_of_measure_ne_top (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condExpIndL1 hm μ s x = condExpIndL1Fin hm hs hμs x := by simp only [condExpIndL1, And.intro hs hμs, dif_pos, Ne, not_false_iff, and_self_iff] theorem condExpIndL1_of_measure_eq_top (hμs : μ s = ∞) (x : G) : condExpIndL1 hm μ s x = 0 := by simp only [condExpIndL1, hμs, not_true, Ne, dif_neg, not_false_iff, and_false] theorem condExpIndL1_of_not_measurableSet (hs : ¬MeasurableSet s) (x : G) : condExpIndL1 hm μ s x = 0 := by simp only [condExpIndL1, hs, dif_neg, not_false_iff, false_and] theorem condExpIndL1_add (x y : G) : condExpIndL1 hm μ s (x + y) = condExpIndL1 hm μ s x + condExpIndL1 hm μ s y := by by_cases hs : MeasurableSet s swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [zero_add] by_cases hμs : μ s = ∞ · simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [zero_add] · simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs] exact condExpIndL1Fin_add hs hμs x y theorem condExpIndL1_smul (c : ℝ) (x : G) : condExpIndL1 hm μ s (c • x) = c • condExpIndL1 hm μ s x := by by_cases hs : MeasurableSet s swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [smul_zero] by_cases hμs : μ s = ∞ · simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [smul_zero] · simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs] exact condExpIndL1Fin_smul hs hμs c x theorem condExpIndL1_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (x : F) : condExpIndL1 hm μ s (c • x) = c • condExpIndL1 hm μ s x := by by_cases hs : MeasurableSet s swap; · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [smul_zero] by_cases hμs : μ s = ∞ · simp_rw [condExpIndL1_of_measure_eq_top hμs]; rw [smul_zero] · simp_rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs] exact condExpIndL1Fin_smul' hs hμs c x theorem norm_condExpIndL1_le (x : G) : ‖condExpIndL1 hm μ s x‖ ≤ μ.real s * ‖x‖ := by by_cases hs : MeasurableSet s swap · simp_rw [condExpIndL1_of_not_measurableSet hs]; rw [Lp.norm_zero] exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _) by_cases hμs : μ s = ∞ · rw [condExpIndL1_of_measure_eq_top hμs x, Lp.norm_zero] exact mul_nonneg ENNReal.toReal_nonneg (norm_nonneg _) · rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs x] exact norm_condExpIndL1Fin_le hs hμs x theorem continuous_condExpIndL1 : Continuous fun x : G => condExpIndL1 hm μ s x := continuous_of_linear_of_bound condExpIndL1_add condExpIndL1_smul norm_condExpIndL1_le theorem condExpIndL1_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) : condExpIndL1 hm μ (s ∪ t) x = condExpIndL1 hm μ s x + condExpIndL1 hm μ t x := by have hμst : μ (s ∪ t) ≠ ∞ := ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne rw [condExpIndL1_of_measurableSet_of_measure_ne_top hs hμs x, condExpIndL1_of_measurableSet_of_measure_ne_top ht hμt x, condExpIndL1_of_measurableSet_of_measure_ne_top (hs.union ht) hμst x] exact condExpIndL1Fin_disjoint_union hs ht hμs hμt hst x end CondexpIndL1 variable (G) /-- Conditional expectation of the indicator of a set, as a linear map from `G` to L1. -/ def condExpInd {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)] (s : Set α) : G →L[ℝ] α →₁[μ] G where toFun := condExpIndL1 hm μ s map_add' := condExpIndL1_add map_smul' := condExpIndL1_smul cont := continuous_condExpIndL1 variable {G} theorem condExpInd_ae_eq_condExpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condExpInd G hm μ s x =ᵐ[μ] condExpIndSMul hm hs hμs x := by refine EventuallyEq.trans ?_ (condExpIndL1Fin_ae_eq_condExpIndSMul hm hs hμs x) simp [condExpInd, condExpIndL1, hs, hμs] variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] theorem aestronglyMeasurable_condExpInd (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : AEStronglyMeasurable[m] (condExpInd G hm μ s x) μ := (aestronglyMeasurable_condExpIndSMul hm hs hμs x).congr (condExpInd_ae_eq_condExpIndSMul hm hs hμs x).symm @[simp] theorem condExpInd_empty : condExpInd G hm μ ∅ = (0 : G →L[ℝ] α →₁[μ] G) := by ext1 x ext1 refine (condExpInd_ae_eq_condExpIndSMul hm MeasurableSet.empty (by simp) x).trans ?_ rw [condExpIndSMul_empty] refine (Lp.coeFn_zero G 2 μ).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_zero G 1 μ).symm rfl theorem condExpInd_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜) (x : F) : condExpInd F hm μ s (c • x) = c • condExpInd F hm μ s x := condExpIndL1_smul' c x theorem norm_condExpInd_apply_le (x : G) : ‖condExpInd G hm μ s x‖ ≤ μ.real s * ‖x‖ := norm_condExpIndL1_le x theorem norm_condExpInd_le : ‖(condExpInd G hm μ s : G →L[ℝ] α →₁[μ] G)‖ ≤ μ.real s := ContinuousLinearMap.opNorm_le_bound _ ENNReal.toReal_nonneg norm_condExpInd_apply_le theorem condExpInd_disjoint_union_apply (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : Disjoint s t) (x : G) : condExpInd G hm μ (s ∪ t) x = condExpInd G hm μ s x + condExpInd G hm μ t x := condExpIndL1_disjoint_union hs ht hμs hμt hst x theorem condExpInd_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : Disjoint s t) : (condExpInd G hm μ (s ∪ t) : G →L[ℝ] α →₁[μ] G) = condExpInd G hm μ s + condExpInd G hm μ t := by ext1 x; push_cast; exact condExpInd_disjoint_union_apply hs ht hμs hμt hst x variable (G) theorem dominatedFinMeasAdditive_condExpInd (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)] : DominatedFinMeasAdditive μ (condExpInd G hm μ : Set α → G →L[ℝ] α →₁[μ] G) 1 := ⟨fun _ _ => condExpInd_disjoint_union, fun _ _ _ => norm_condExpInd_le.trans (one_mul _).symm.le⟩ variable {G} theorem setIntegral_condExpInd (hs : MeasurableSet[m] s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (x : G') : ∫ a in s, condExpInd G' hm μ t x a ∂μ = μ.real (t ∩ s) • x := calc ∫ a in s, condExpInd G' hm μ t x a ∂μ = ∫ a in s, condExpIndSMul hm ht hμt x a ∂μ := setIntegral_congr_ae (hm s hs) ((condExpInd_ae_eq_condExpIndSMul hm ht hμt x).mono fun _ hx _ => hx) _ = μ.real (t ∩ s) • x := setIntegral_condExpIndSMul hs ht hμs hμt x theorem condExpInd_of_measurable (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : G) : condExpInd G hm μ s c = indicatorConstLp 1 (hm s hs) hμs c := by ext1 refine EventuallyEq.trans ?_ indicatorConstLp_coeFn.symm refine (condExpInd_ae_eq_condExpIndSMul hm (hm s hs) hμs c).trans ?_ refine (condExpIndSMul_ae_eq_smul hm (hm s hs) hμs c).trans ?_ rw [condExpL2_indicator_of_measurable hm hs hμs (1 : ℝ)] refine (@indicatorConstLp_coeFn α _ _ 2 μ _ s (hm s hs) hμs (1 : ℝ)).mono fun x hx => ?_ dsimp only rw [hx] by_cases hx_mem : x ∈ s <;> simp [hx_mem] theorem condExpInd_nonneg {E} [NormedAddCommGroup E] [PartialOrder E] [NormedSpace ℝ E] [OrderedSMul ℝ E] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) (hx : 0 ≤ x) : 0 ≤ condExpInd E hm μ s x := by rw [← coeFn_le] refine EventuallyLE.trans_eq ?_ (condExpInd_ae_eq_condExpIndSMul hm hs hμs x).symm exact (coeFn_zero E 1 μ).trans_le (condExpIndSMul_nonneg hs hμs x hx) end CondexpInd section CondexpL1 variable {m m0 : MeasurableSpace α} {μ : Measure α} {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] {f g : α → F'} {s : Set α} variable (F') /-- Conditional expectation of a function as a linear map from `α →₁[μ] F'` to itself. -/ def condExpL1CLM (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)] : (α →₁[μ] F') →L[ℝ] α →₁[μ] F' := L1.setToL1 (dominatedFinMeasAdditive_condExpInd F' hm μ) variable {F'} theorem condExpL1CLM_smul (c : 𝕜) (f : α →₁[μ] F') : condExpL1CLM F' hm μ (c • f) = c • condExpL1CLM F' hm μ f := by refine L1.setToL1_smul (dominatedFinMeasAdditive_condExpInd F' hm μ) ?_ c f exact fun c s x => condExpInd_smul' c x theorem condExpL1CLM_indicatorConstLp (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : F') : (condExpL1CLM F' hm μ) (indicatorConstLp 1 hs hμs x) = condExpInd F' hm μ s x := L1.setToL1_indicatorConstLp (dominatedFinMeasAdditive_condExpInd F' hm μ) hs hμs x theorem condExpL1CLM_indicatorConst (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : F') : (condExpL1CLM F' hm μ) ↑(simpleFunc.indicatorConst 1 hs hμs x) = condExpInd F' hm μ s x := by rw [Lp.simpleFunc.coe_indicatorConst]; exact condExpL1CLM_indicatorConstLp hs hμs x /-- Auxiliary lemma used in the proof of `setIntegral_condExpL1CLM`. -/ theorem setIntegral_condExpL1CLM_of_measure_ne_top (f : α →₁[μ] F') (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ := by refine @Lp.induction _ _ _ _ _ _ _ ENNReal.one_ne_top (fun f : α →₁[μ] F' => ∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ) ?_ ?_ (isClosed_eq ?_ ?_) f · intro x t ht hμt simp_rw [condExpL1CLM_indicatorConst ht hμt.ne x] rw [Lp.simpleFunc.coe_indicatorConst, setIntegral_indicatorConstLp (hm _ hs)] exact setIntegral_condExpInd hs ht hμs hμt.ne x · intro f g hf_Lp hg_Lp _ hf hg simp_rw [(condExpL1CLM F' hm μ).map_add] rw [setIntegral_congr_ae (hm s hs) ((Lp.coeFn_add (condExpL1CLM F' hm μ (hf_Lp.toLp f)) (condExpL1CLM F' hm μ (hg_Lp.toLp g))).mono fun x hx _ => hx)] rw [setIntegral_congr_ae (hm s hs) ((Lp.coeFn_add (hf_Lp.toLp f) (hg_Lp.toLp g)).mono fun x hx _ => hx)] simp_rw [Pi.add_apply] rw [integral_add (L1.integrable_coeFn _).integrableOn (L1.integrable_coeFn _).integrableOn, integral_add (L1.integrable_coeFn _).integrableOn (L1.integrable_coeFn _).integrableOn, hf, hg] · exact (continuous_setIntegral s).comp (condExpL1CLM F' hm μ).continuous · exact continuous_setIntegral s /-- The integral of the conditional expectation `condExpL1CLM` over an `m`-measurable set is equal to the integral of `f` on that set. See also `setIntegral_condExp`, the similar statement for `condExp`. -/ theorem setIntegral_condExpL1CLM (f : α →₁[μ] F') (hs : MeasurableSet[m] s) : ∫ x in s, condExpL1CLM F' hm μ f x ∂μ = ∫ x in s, f x ∂μ := by let S := spanningSets (μ.trim hm) have hS_meas : ∀ i, MeasurableSet[m] (S i) := measurableSet_spanningSets (μ.trim hm) have hS_meas0 : ∀ i, MeasurableSet (S i) := fun i => hm _ (hS_meas i) have hs_eq : s = ⋃ i, S i ∩ s := by simp_rw [Set.inter_comm] rw [← Set.inter_iUnion, iUnion_spanningSets (μ.trim hm), Set.inter_univ] have hS_finite : ∀ i, μ (S i ∩ s) < ∞ := by refine fun i => (measure_mono Set.inter_subset_left).trans_lt ?_ have hS_finite_trim := measure_spanningSets_lt_top (μ.trim hm) i rwa [trim_measurableSet_eq hm (hS_meas i)] at hS_finite_trim have h_mono : Monotone fun i => S i ∩ s := by intro i j hij x simp_rw [Set.mem_inter_iff] exact fun h => ⟨monotone_spanningSets (μ.trim hm) hij h.1, h.2⟩ have h_eq_forall : (fun i => ∫ x in S i ∩ s, condExpL1CLM F' hm μ f x ∂μ) = fun i => ∫ x in S i ∩ s, f x ∂μ := funext fun i => setIntegral_condExpL1CLM_of_measure_ne_top f (@MeasurableSet.inter α m _ _ (hS_meas i) hs) (hS_finite i).ne have h_right : Tendsto (fun i => ∫ x in S i ∩ s, f x ∂μ) atTop (𝓝 (∫ x in s, f x ∂μ)) := by have h := tendsto_setIntegral_of_monotone (fun i => (hS_meas0 i).inter (hm s hs)) h_mono (L1.integrable_coeFn f).integrableOn rwa [← hs_eq] at h have h_left : Tendsto (fun i => ∫ x in S i ∩ s, condExpL1CLM F' hm μ f x ∂μ) atTop (𝓝 (∫ x in s, condExpL1CLM F' hm μ f x ∂μ)) := by have h := tendsto_setIntegral_of_monotone (fun i => (hS_meas0 i).inter (hm s hs)) h_mono (L1.integrable_coeFn (condExpL1CLM F' hm μ f)).integrableOn rwa [← hs_eq] at h rw [h_eq_forall] at h_left exact tendsto_nhds_unique h_left h_right theorem aestronglyMeasurable_condExpL1CLM (f : α →₁[μ] F') : AEStronglyMeasurable[m] (condExpL1CLM F' hm μ f) μ := by refine @Lp.induction _ _ _ _ _ _ _ ENNReal.one_ne_top (fun f : α →₁[μ] F' => AEStronglyMeasurable[m] (condExpL1CLM F' hm μ f) μ) ?_ ?_ ?_ f · intro c s hs hμs rw [condExpL1CLM_indicatorConst hs hμs.ne c] exact aestronglyMeasurable_condExpInd hs hμs.ne c · intro f g hf hg _ hfm hgm rw [(condExpL1CLM F' hm μ).map_add] exact (hfm.add hgm).congr (coeFn_add ..).symm · have : {f : Lp F' 1 μ | AEStronglyMeasurable[m] (condExpL1CLM F' hm μ f) μ} = condExpL1CLM F' hm μ ⁻¹' {f | AEStronglyMeasurable[m] f μ} := rfl rw [this] refine IsClosed.preimage (condExpL1CLM F' hm μ).continuous ?_ exact isClosed_aestronglyMeasurable hm theorem condExpL1CLM_lpMeas (f : lpMeas F' ℝ m 1 μ) : condExpL1CLM F' hm μ (f : α →₁[μ] F') = ↑f := by let g := lpMeasToLpTrimLie F' ℝ 1 μ hm f have hfg : f = (lpMeasToLpTrimLie F' ℝ 1 μ hm).symm g := by simp only [g, LinearIsometryEquiv.symm_apply_apply] rw [hfg] refine @Lp.induction α F' m _ 1 (μ.trim hm) _ ENNReal.coe_ne_top (fun g : α →₁[μ.trim hm] F' => condExpL1CLM F' hm μ ((lpMeasToLpTrimLie F' ℝ 1 μ hm).symm g : α →₁[μ] F') = ↑((lpMeasToLpTrimLie F' ℝ 1 μ hm).symm g)) ?_ ?_ ?_ g · intro c s hs hμs rw [@Lp.simpleFunc.coe_indicatorConst _ _ m, lpMeasToLpTrimLie_symm_indicator hs hμs.ne c, condExpL1CLM_indicatorConstLp] exact condExpInd_of_measurable hs ((le_trim hm).trans_lt hμs).ne c · intro f g hf hg _ hf_eq hg_eq rw [LinearIsometryEquiv.map_add] push_cast rw [map_add, hf_eq, hg_eq] · refine isClosed_eq ?_ ?_ · refine (condExpL1CLM F' hm μ).continuous.comp (continuous_induced_dom.comp ?_) exact LinearIsometryEquiv.continuous _ · refine continuous_induced_dom.comp ?_ exact LinearIsometryEquiv.continuous _ theorem condExpL1CLM_of_aestronglyMeasurable' (f : α →₁[μ] F') (hfm : AEStronglyMeasurable[m] f μ) : condExpL1CLM F' hm μ f = f := condExpL1CLM_lpMeas (⟨f, hfm⟩ : lpMeas F' ℝ m 1 μ) /-- Conditional expectation of a function, in L1. Its value is 0 if the function is not integrable. The function-valued `condExp` should be used instead in most cases. -/ def condExpL1 (hm : m ≤ m0) (μ : Measure α) [SigmaFinite (μ.trim hm)] (f : α → F') : α →₁[μ] F' := setToFun μ (condExpInd F' hm μ) (dominatedFinMeasAdditive_condExpInd F' hm μ) f theorem condExpL1_undef (hf : ¬Integrable f μ) : condExpL1 hm μ f = 0 := setToFun_undef (dominatedFinMeasAdditive_condExpInd F' hm μ) hf theorem condExpL1_eq (hf : Integrable f μ) : condExpL1 hm μ f = condExpL1CLM F' hm μ (hf.toL1 f) := setToFun_eq (dominatedFinMeasAdditive_condExpInd F' hm μ) hf @[simp] theorem condExpL1_zero : condExpL1 hm μ (0 : α → F') = 0 := setToFun_zero _ @[simp] theorem condExpL1_measure_zero (hm : m ≤ m0) : condExpL1 hm (0 : Measure α) f = 0 := setToFun_measure_zero _ rfl theorem aestronglyMeasurable_condExpL1 {f : α → F'} : AEStronglyMeasurable[m] (condExpL1 hm μ f) μ := by by_cases hf : Integrable f μ · rw [condExpL1_eq hf] exact aestronglyMeasurable_condExpL1CLM _ · rw [condExpL1_undef hf] exact stronglyMeasurable_zero.aestronglyMeasurable.congr (coeFn_zero ..).symm theorem condExpL1_congr_ae (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (h : f =ᵐ[μ] g) : condExpL1 hm μ f = condExpL1 hm μ g := setToFun_congr_ae _ h theorem integrable_condExpL1 (f : α → F') : Integrable (condExpL1 hm μ f) μ := L1.integrable_coeFn _ /-- The integral of the conditional expectation `condExpL1` over an `m`-measurable set is equal to the integral of `f` on that set. See also `setIntegral_condExp`, the similar statement for `condExp`. -/ theorem setIntegral_condExpL1 (hf : Integrable f μ) (hs : MeasurableSet[m] s) : ∫ x in s, condExpL1 hm μ f x ∂μ = ∫ x in s, f x ∂μ := by simp_rw [condExpL1_eq hf] rw [setIntegral_condExpL1CLM (hf.toL1 f) hs] exact setIntegral_congr_ae (hm s hs) (hf.coeFn_toL1.mono fun x hx _ => hx) theorem condExpL1_add (hf : Integrable f μ) (hg : Integrable g μ) : condExpL1 hm μ (f + g) = condExpL1 hm μ f + condExpL1 hm μ g := setToFun_add _ hf hg theorem condExpL1_neg (f : α → F') : condExpL1 hm μ (-f) = -condExpL1 hm μ f := setToFun_neg _ f theorem condExpL1_smul (c : 𝕜) (f : α → F') : condExpL1 hm μ (c • f) = c • condExpL1 hm μ f := by refine setToFun_smul _ ?_ c f exact fun c _ x => condExpInd_smul' c x theorem condExpL1_sub (hf : Integrable f μ) (hg : Integrable g μ) : condExpL1 hm μ (f - g) = condExpL1 hm μ f - condExpL1 hm μ g := setToFun_sub _ hf hg theorem condExpL1_of_aestronglyMeasurable' (hfm : AEStronglyMeasurable[m] f μ) (hfi : Integrable f μ) : condExpL1 hm μ f =ᵐ[μ] f := by rw [condExpL1_eq hfi] refine EventuallyEq.trans ?_ (Integrable.coeFn_toL1 hfi) rw [condExpL1CLM_of_aestronglyMeasurable'] exact hfm.congr hfi.coeFn_toL1.symm theorem condExpL1_mono {E} [NormedAddCommGroup E] [PartialOrder E] [OrderClosedTopology E] [IsOrderedAddMonoid E] [CompleteSpace E] [NormedSpace ℝ E] [OrderedSMul ℝ E] {f g : α → E} (hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) : condExpL1 hm μ f ≤ᵐ[μ] condExpL1 hm μ g := by rw [coeFn_le] have h_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x : E, 0 ≤ x → 0 ≤ condExpInd E hm μ s x := fun s hs hμs x hx => condExpInd_nonneg hs hμs.ne x hx exact setToFun_mono (dominatedFinMeasAdditive_condExpInd E hm μ) h_nonneg hf hg hfg end CondexpL1 end MeasureTheory
Equiv.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Control.Traversable.Lemmas import Mathlib.Logic.Equiv.Defs import Batteries.Tactic.SeqFocus /-! # Transferring `Traversable` instances along isomorphisms This file allows to transfer `Traversable` instances along isomorphisms. ## Main declarations * `Equiv.map`: Turns functorially a function `α → β` into a function `t' α → t' β` using the functor `t` and the equivalence `Π α, t α ≃ t' α`. * `Equiv.functor`: `Equiv.map` as a functor. * `Equiv.traverse`: Turns traversably a function `α → m β` into a function `t' α → m (t' β)` using the traversable functor `t` and the equivalence `Π α, t α ≃ t' α`. * `Equiv.traversable`: `Equiv.traverse` as a traversable functor. * `Equiv.isLawfulTraversable`: `Equiv.traverse` as a lawful traversable functor. -/ universe u namespace Equiv section Functor -- Porting note: `parameter` doesn't seem to work yet. variable {t t' : Type u → Type u} (eqv : ∀ α, t α ≃ t' α) variable [Functor t] open Functor /-- Given a functor `t`, a function `t' : Type u → Type u`, and equivalences `t α ≃ t' α` for all `α`, then every function `α → β` can be mapped to a function `t' α → t' β` functorially (see `Equiv.functor`). -/ protected def map {α β : Type u} (f : α → β) (x : t' α) : t' β := eqv β <| map f ((eqv α).symm x) /-- The function `Equiv.map` transfers the functoriality of `t` to `t'` using the equivalences `eqv`. -/ protected def functor : Functor t' where map := Equiv.map eqv variable [LawfulFunctor t] protected theorem id_map {α : Type u} (x : t' α) : Equiv.map eqv id x = x := by simp [Equiv.map, id_map] protected theorem comp_map {α β γ : Type u} (g : α → β) (h : β → γ) (x : t' α) : Equiv.map eqv (h ∘ g) x = Equiv.map eqv h (Equiv.map eqv g x) := by simp [Equiv.map, Function.comp_def] protected theorem lawfulFunctor : @LawfulFunctor _ (Equiv.functor eqv) := -- Porting note: why is `_inst` required here? let _inst := Equiv.functor eqv; { map_const := fun {_ _} => rfl id_map := Equiv.id_map eqv comp_map := Equiv.comp_map eqv } protected theorem lawfulFunctor' [F : Functor t'] (h₀ : ∀ {α β} (f : α → β), Functor.map f = Equiv.map eqv f) (h₁ : ∀ {α β} (f : β), Functor.mapConst f = (Equiv.map eqv ∘ Function.const α) f) : LawfulFunctor t' := by have : F = Equiv.functor eqv := by cases F dsimp [Equiv.functor] congr <;> ext <;> dsimp only <;> [rw [← h₀]; rw [← h₁]] <;> rfl subst this exact Equiv.lawfulFunctor eqv end Functor section Traversable variable {t t' : Type u → Type u} (eqv : ∀ α, t α ≃ t' α) variable [Traversable t] variable {m : Type u → Type u} [Applicative m] variable {α β : Type u} /-- Like `Equiv.map`, a function `t' : Type u → Type u` can be given the structure of a traversable functor using a traversable functor `t'` and equivalences `t α ≃ t' α` for all α. See `Equiv.traversable`. -/ protected def traverse (f : α → m β) (x : t' α) : m (t' β) := eqv β <$> traverse f ((eqv α).symm x) theorem traverse_def (f : α → m β) (x : t' α) : Equiv.traverse eqv f x = eqv β <$> traverse f ((eqv α).symm x) := rfl /-- The function `Equiv.traverse` transfers a traversable functor instance across the equivalences `eqv`. -/ protected def traversable : Traversable t' where toFunctor := Equiv.functor eqv traverse := Equiv.traverse eqv end Traversable section Equiv variable {t t' : Type u → Type u} (eqv : ∀ α, t α ≃ t' α) -- Is this to do with the fact it lives in `Type (u+1)` not `Prop`? variable [Traversable t] [LawfulTraversable t] variable {F G : Type u → Type u} [Applicative F] [Applicative G] variable [LawfulApplicative F] [LawfulApplicative G] variable (η : ApplicativeTransformation F G) variable {α β γ : Type u} open LawfulTraversable Functor protected theorem id_traverse (x : t' α) : Equiv.traverse eqv (pure : α → Id α) x = pure x := by rw [Equiv.traverse, id_traverse, map_pure, apply_symm_apply] protected theorem traverse_eq_map_id (f : α → β) (x : t' α) : Equiv.traverse eqv ((pure : β → Id β) ∘ f) x = pure (Equiv.map eqv f x) := by simp only [Equiv.traverse, traverse_eq_map_id]; rfl protected theorem comp_traverse (f : β → F γ) (g : α → G β) (x : t' α) : Equiv.traverse eqv (Comp.mk ∘ Functor.map f ∘ g) x = Comp.mk (Equiv.traverse eqv f <$> Equiv.traverse eqv g x) := by rw [traverse_def, comp_traverse, Comp.map_mk] simp only [map_map, traverse_def, symm_apply_apply] protected theorem naturality (f : α → F β) (x : t' α) : η (Equiv.traverse eqv f x) = Equiv.traverse eqv (@η _ ∘ f) x := by simp only [Equiv.traverse, functor_norm] /-- The fact that `t` is a lawful traversable functor carries over the equivalences to `t'`, with the traversable functor structure given by `Equiv.traversable`. -/ protected theorem isLawfulTraversable : @LawfulTraversable t' (Equiv.traversable eqv) := -- Porting note: Same `_inst` local variable problem. let _inst := Equiv.traversable eqv; { toLawfulFunctor := Equiv.lawfulFunctor eqv id_traverse := Equiv.id_traverse eqv comp_traverse := Equiv.comp_traverse eqv traverse_eq_map_id := Equiv.traverse_eq_map_id eqv naturality := Equiv.naturality eqv } /-- If the `Traversable t'` instance has the properties that `map`, `map_const`, and `traverse` are equal to the ones that come from carrying the traversable functor structure from `t` over the equivalences, then the fact that `t` is a lawful traversable functor carries over as well. -/ protected theorem isLawfulTraversable' [Traversable t'] (h₀ : ∀ {α β} (f : α → β), map f = Equiv.map eqv f) (h₁ : ∀ {α β} (f : β), mapConst f = (Equiv.map eqv ∘ Function.const α) f) (h₂ : ∀ {F : Type u → Type u} [Applicative F], ∀ [LawfulApplicative F] {α β} (f : α → F β), traverse f = Equiv.traverse eqv f) : LawfulTraversable t' where -- we can't use the same approach as for `lawful_functor'` because -- h₂ needs a `LawfulApplicative` assumption toLawfulFunctor := Equiv.lawfulFunctor' eqv @h₀ @h₁ id_traverse _ := by rw [h₂, Equiv.id_traverse] comp_traverse _ _ _ := by rw [h₂, Equiv.comp_traverse, h₂]; congr; rw [h₂] traverse_eq_map_id _ _ := by rw [h₂, Equiv.traverse_eq_map_id, h₀] naturality _ _ _ _ _ := by rw [h₂, Equiv.naturality, h₂] end Equiv end Equiv
Cardinal.lean
/- Copyright (c) 2025 Peter Nelson and Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson, Junyan Xu -/ import Mathlib.Data.Matroid.Map import Mathlib.Data.Matroid.Rank.ENat import Mathlib.Data.Matroid.Rank.Finite import Mathlib.SetTheory.Cardinal.Arithmetic /-! # Cardinal-valued rank In a finitary matroid, all bases have the same cardinality. In fact, something stronger holds: if each of `I` and `J` is a basis for a set `X`, then `#(I \ J) = #(J \ I)` and (consequently) `#I = #J`. This file introduces a typeclass `InvariantCardinalRank` that applies to any matroid such that this property holds for all `I`, `J` and `X`. A matroid satisfying this condition has a well-defined cardinality-valued rank function, both for itself and all its minors. # Main Declarations * `Matroid.InvariantCardinalRank` : a typeclass capturing the idea that a matroid and all its minors have a well-behaved cardinal-valued rank function. * `Matroid.cRank M` is the supremum of the cardinalities of the bases of matroid `M`. * `Matroid.cRk M X` is the supremum of the cardinalities of the bases of a set `X` in a matroid `M`. * `invariantCardinalRank_of_finitary` is the instance showing that `Finitary` matroids are `InvariantCardinalRank`. * `cRk_inter_add_cRk_union_le` states that cardinal rank is submodular. # Notes It is not (provably) the case that all matroids are `InvariantCardinalRank`, since the equicardinality of bases in general matroids is independent of ZFC (see the module docstring of `Mathlib/Data/Matroid/Basic.lean`). Lemmas like `Matroid.Base.cardinalMk_diff_comm` become true for all matroids only if they are weakened by replacing `Cardinal.mk` with the cruder `ℕ∞`-valued `Set.encard`. The `ℕ∞`-valued rank and rank functions `Matroid.eRank` and `Matroid.eRk`, which have a more unconditionally strong API, are developed in `Mathlib/Data/Matroid/Rank/ENat.lean`. # Implementation Details Since the functions `cRank` and `cRk` are defined as suprema, independently of the `Matroid.InvariantCardinalRank` typeclass, they are well-defined for all matroids. However, for matroids that do not satisfy `InvariantCardinalRank`, they are badly behaved. For instance, in general `cRk` is not submodular, and its value may differ on a set `X` and the closure of `X`. We state and prove theorems without `InvariantCardinalRank` whenever possible, which sometime makes their proofs longer than they would be with the instance. # TODO * Higgs' theorem : if the generalized continuum hypothesis holds, then every matroid is `InvariantCardinalRank`. -/ universe u v variable {α : Type u} {β : Type v} {f : α → β} {M : Matroid α} {I J B B' X Y : Set α} open Cardinal Set namespace Matroid section Rank variable {κ : Cardinal} /-- The rank (supremum of the cardinalities of bases) of a matroid `M` as a `Cardinal`. See `Matroid.eRank` for a better-behaved `ℕ∞`-valued version. -/ noncomputable def cRank (M : Matroid α) := ⨆ B : {B // M.IsBase B}, #B /-- The rank (supremum of the cardinalities of bases) of a set `X` in a matroid `M`, as a `Cardinal`. See `Matroid.eRk` for a better-behaved `ℕ∞`-valued version. -/ noncomputable def cRk (M : Matroid α) (X : Set α) := (M ↾ X).cRank theorem IsBase.cardinalMk_le_cRank (hB : M.IsBase B) : #B ≤ M.cRank := le_ciSup (f := fun B : {B // M.IsBase B} ↦ #B.1) (bddAbove_range _) ⟨B, hB⟩ theorem Indep.cardinalMk_le_cRank (ind : M.Indep I) : #I ≤ M.cRank := have ⟨B, isBase, hIB⟩ := ind.exists_isBase_superset le_ciSup_of_le (bddAbove_range _) ⟨B, isBase⟩ (mk_le_mk_of_subset hIB) theorem cRank_eq_iSup_cardinalMk_indep : M.cRank = ⨆ I : {I // M.Indep I}, #I := (ciSup_le' fun B ↦ le_ciSup_of_le (bddAbove_range _) ⟨B, B.2.indep⟩ <| by rfl).antisymm <| ciSup_le' fun I ↦ have ⟨B, isBase, hIB⟩ := I.2.exists_isBase_superset le_ciSup_of_le (bddAbove_range _) ⟨B, isBase⟩ (mk_le_mk_of_subset hIB) theorem IsBasis'.cardinalMk_le_cRk (hIX : M.IsBasis' I X) : #I ≤ M.cRk X := (isBase_restrict_iff'.2 hIX).cardinalMk_le_cRank theorem IsBasis.cardinalMk_le_cRk (hIX : M.IsBasis I X) : #I ≤ M.cRk X := hIX.isBasis'.cardinalMk_le_cRk theorem cRank_le_iff : M.cRank ≤ κ ↔ ∀ ⦃B⦄, M.IsBase B → #B ≤ κ := ⟨fun h _ hB ↦ (hB.cardinalMk_le_cRank.trans h), fun h ↦ ciSup_le fun ⟨_, hB⟩ ↦ h hB⟩ theorem cRk_le_iff : M.cRk X ≤ κ ↔ ∀ ⦃I⦄, M.IsBasis' I X → #I ≤ κ := by simp_rw [cRk, cRank_le_iff, isBase_restrict_iff'] theorem Indep.cardinalMk_le_cRk_of_subset (hI : M.Indep I) (hIX : I ⊆ X) : #I ≤ M.cRk X := let ⟨_, hJ, hIJ⟩ := hI.subset_isBasis'_of_subset hIX (mk_le_mk_of_subset hIJ).trans hJ.cardinalMk_le_cRk theorem cRk_le_cardinalMk (M : Matroid α) (X : Set α) : M.cRk X ≤ #X := ciSup_le fun ⟨_, hI⟩ ↦ mk_le_mk_of_subset hI.subset_ground @[simp] theorem cRk_ground (M : Matroid α) : M.cRk M.E = M.cRank := by rw [cRk, restrict_ground_eq_self] @[simp] theorem cRank_restrict (M : Matroid α) (X : Set α) : (M ↾ X).cRank = M.cRk X := rfl theorem cRk_mono (M : Matroid α) : Monotone M.cRk := by simp only [Monotone, le_eq_subset, cRk_le_iff] intro X Y hXY I hIX obtain ⟨J, hJ, hIJ⟩ := hIX.indep.subset_isBasis'_of_subset (hIX.subset.trans hXY) exact (mk_le_mk_of_subset hIJ).trans hJ.cardinalMk_le_cRk theorem cRk_le_of_subset (M : Matroid α) (hXY : X ⊆ Y) : M.cRk X ≤ M.cRk Y := M.cRk_mono hXY @[simp] theorem cRk_inter_ground (M : Matroid α) (X : Set α) : M.cRk (X ∩ M.E) = M.cRk X := (M.cRk_le_of_subset inter_subset_left).antisymm <| cRk_le_iff.2 fun _ h ↦ h.isBasis_inter_ground.cardinalMk_le_cRk theorem cRk_restrict_subset (M : Matroid α) (hYX : Y ⊆ X) : (M ↾ X).cRk Y = M.cRk Y := by have aux : ∀ ⦃I⦄, M.IsBasis' I Y ↔ (M ↾ X).IsBasis' I Y := by simp_rw [isBasis'_restrict_iff, inter_eq_self_of_subset_left hYX, iff_self_and] exact fun I h ↦ h.subset.trans hYX simp_rw [le_antisymm_iff, cRk_le_iff] exact ⟨fun I hI ↦ (aux.2 hI).cardinalMk_le_cRk, fun I hI ↦ (aux.1 hI).cardinalMk_le_cRk⟩ theorem cRk_restrict (M : Matroid α) (X Y : Set α) : (M ↾ X).cRk Y = M.cRk (X ∩ Y) := by rw [← cRk_inter_ground, restrict_ground_eq, cRk_restrict_subset _ inter_subset_right, inter_comm] theorem Indep.cRk_eq_cardinalMk (hI : M.Indep I) : #I = M.cRk I := (M.cRk_le_cardinalMk I).antisymm' (hI.isBasis_self.cardinalMk_le_cRk) @[simp] theorem cRk_map_image_lift (M : Matroid α) (hf : InjOn f M.E) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) : lift.{u,v} ((M.map f hf).cRk (f '' X)) = lift (M.cRk X) := by nth_rw 1 [cRk, cRank, le_antisymm_iff, lift_iSup (bddAbove_range _), cRk, cRank, cRk, cRank] nth_rw 2 [lift_iSup (bddAbove_range _)] simp only [ciSup_le_iff (bddAbove_range _), ge_iff_le, Subtype.forall, isBase_restrict_iff', isBasis'_iff_isBasis hX, isBasis'_iff_isBasis (show f '' X ⊆ (M.map f hf).E from image_mono hX)] refine ⟨fun I hI ↦ ?_, fun I hI ↦ ?_⟩ · obtain ⟨I, X', hIX, rfl, hXX'⟩ := map_isBasis_iff'.1 hI rw [mk_image_eq_of_injOn_lift _ _ (hf.mono hIX.indep.subset_ground), lift_le] obtain rfl : X = X' := by rwa [hf.image_eq_image_iff hX hIX.subset_ground] at hXX' exact hIX.cardinalMk_le_cRk rw [← mk_image_eq_of_injOn_lift _ _ (hf.mono hI.indep.subset_ground), lift_le] exact (hI.map hf).cardinalMk_le_cRk @[simp] theorem cRk_map_image {β : Type u} {f : α → β} (M : Matroid α) (hf : InjOn f M.E) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) : (M.map f hf).cRk (f '' X) = M.cRk X := lift_inj.1 <| M.cRk_map_image_lift .. theorem cRk_map_eq {β : Type u} {f : α → β} {X : Set β} (M : Matroid α) (hf : InjOn f M.E) : (M.map f hf).cRk X = M.cRk (f ⁻¹' X) := by rw [← M.cRk_inter_ground, ← M.cRk_map_image hf _, image_preimage_inter, ← map_ground _ _ hf, cRk_inter_ground] @[simp] theorem cRk_comap_lift (M : Matroid β) (f : α → β) (X : Set α) : lift.{v,u} ((M.comap f).cRk X) = lift (M.cRk (f '' X)) := by nth_rw 1 [cRk, cRank, le_antisymm_iff, lift_iSup (bddAbove_range _), cRk, cRank, cRk, cRank] nth_rw 2 [lift_iSup (bddAbove_range _)] simp only [ciSup_le_iff (bddAbove_range _), ge_iff_le, Subtype.forall, isBase_restrict_iff', comap_isBasis'_iff, and_imp] refine ⟨fun I hI hfI hIX ↦ ?_, fun I hIX ↦ ?_⟩ · rw [← mk_image_eq_of_injOn_lift _ _ hfI, lift_le] exact hI.cardinalMk_le_cRk obtain ⟨I₀, hI₀X, rfl, hfI₀⟩ := show ∃ I₀ ⊆ X, f '' I₀ = I ∧ InjOn f I₀ by obtain ⟨I₀, hI₀ss, hbij⟩ := exists_subset_bijOn (f ⁻¹' I ∩ X) f refine ⟨I₀, hI₀ss.trans inter_subset_right, ?_, hbij.injOn⟩ rw [hbij.image_eq, image_preimage_inter, inter_eq_self_of_subset_left hIX.subset] rw [mk_image_eq_of_injOn_lift _ _ hfI₀, lift_le] exact IsBasis'.cardinalMk_le_cRk <| comap_isBasis'_iff.2 ⟨hIX, hfI₀, hI₀X⟩ @[simp] theorem cRk_comap {β : Type u} (M : Matroid β) (f : α → β) (X : Set α) : (M.comap f).cRk X = M.cRk (f '' X) := lift_inj.1 <| M.cRk_comap_lift .. end Rank section Invariant /-- A class stating that cardinality-valued rank is well-defined (i.e. all bases are equicardinal) for a matroid `M` and its minors. Notably, this holds for `Finitary` matroids; see `Matroid.invariantCardinalRank_of_finitary`. -/ @[mk_iff] class InvariantCardinalRank (M : Matroid α) : Prop where forall_card_isBasis_diff : ∀ ⦃I J X⦄, M.IsBasis I X → M.IsBasis J X → #(I \ J : Set α) = #(J \ I : Set α) variable [InvariantCardinalRank M] theorem IsBasis.cardinalMk_diff_comm (hIX : M.IsBasis I X) (hJX : M.IsBasis J X) : #(I \ J : Set α) = #(J \ I : Set α) := InvariantCardinalRank.forall_card_isBasis_diff hIX hJX theorem IsBasis'.cardinalMk_diff_comm (hIX : M.IsBasis' I X) (hJX : M.IsBasis' J X) : #(I \ J : Set α) = #(J \ I : Set α) := hIX.isBasis_inter_ground.cardinalMk_diff_comm hJX.isBasis_inter_ground theorem IsBase.cardinalMk_diff_comm (hB : M.IsBase B) (hB' : M.IsBase B') : #(B \ B' : Set α) = #(B' \ B : Set α) := hB.isBasis_ground.cardinalMk_diff_comm hB'.isBasis_ground theorem IsBasis.cardinalMk_eq (hIX : M.IsBasis I X) (hJX : M.IsBasis J X) : #I = #J := by rw [← diff_union_inter I J, mk_union_of_disjoint (disjoint_sdiff_left.mono_right inter_subset_right), hIX.cardinalMk_diff_comm hJX, ← mk_union_of_disjoint (disjoint_sdiff_left.mono_right inter_subset_left), inter_comm, diff_union_inter] theorem IsBasis'.cardinalMk_eq (hIX : M.IsBasis' I X) (hJX : M.IsBasis' J X) : #I = #J := hIX.isBasis_inter_ground.cardinalMk_eq hJX.isBasis_inter_ground theorem IsBase.cardinalMk_eq (hB : M.IsBase B) (hB' : M.IsBase B') : #B = #B' := hB.isBasis_ground.cardinalMk_eq hB'.isBasis_ground theorem Indep.cardinalMk_le_isBase (hI : M.Indep I) (hB : M.IsBase B) : #I ≤ #B := have ⟨_B', hB', hIB'⟩ := hI.exists_isBase_superset hB'.cardinalMk_eq hB ▸ mk_le_mk_of_subset hIB' theorem Indep.cardinalMk_le_isBasis' (hI : M.Indep I) (hJ : M.IsBasis' J X) (hIX : I ⊆ X) : #I ≤ #J := have ⟨_J', hJ', hIJ'⟩ := hI.subset_isBasis'_of_subset hIX hJ'.cardinalMk_eq hJ ▸ mk_le_mk_of_subset hIJ' theorem Indep.cardinalMk_le_isBasis (hI : M.Indep I) (hJ : M.IsBasis J X) (hIX : I ⊆ X) : #I ≤ #J := hI.cardinalMk_le_isBasis' hJ.isBasis' hIX theorem IsBase.cardinalMk_eq_cRank (hB : M.IsBase B) : #B = M.cRank := by have hrw : ∀ B' : {B : Set α // M.IsBase B}, #B' = #B := fun B' ↦ B'.2.cardinalMk_eq hB simp [cRank, hrw] /-- Restrictions of matroids with cardinal rank functions have cardinal rank functions. -/ instance invariantCardinalRank_restrict [InvariantCardinalRank M] : InvariantCardinalRank (M ↾ X) := by refine ⟨fun I J Y hI hJ ↦ ?_⟩ rw [isBasis_restrict_iff'] at hI hJ exact hI.1.cardinalMk_diff_comm hJ.1 theorem IsBasis'.cardinalMk_eq_cRk (hIX : M.IsBasis' I X) : #I = M.cRk X := by rw [cRk, (isBase_restrict_iff'.2 hIX).cardinalMk_eq_cRank] theorem IsBasis.cardinalMk_eq_cRk (hIX : M.IsBasis I X) : #I = M.cRk X := hIX.isBasis'.cardinalMk_eq_cRk @[simp] theorem cRk_closure (M : Matroid α) [InvariantCardinalRank M] (X : Set α) : M.cRk (M.closure X) = M.cRk X := by obtain ⟨I, hI⟩ := M.exists_isBasis' X rw [← hI.isBasis_closure_right.cardinalMk_eq_cRk, ← hI.cardinalMk_eq_cRk] theorem cRk_closure_congr (hXY : M.closure X = M.closure Y) : M.cRk X = M.cRk Y := by rw [← cRk_closure, hXY, cRk_closure] theorem Spanning.cRank_le_cardinalMk (h : M.Spanning X) : M.cRank ≤ #X := have ⟨_B, hB, hBX⟩ := h.exists_isBase_subset (hB.cardinalMk_eq_cRank).symm.trans_le (mk_le_mk_of_subset hBX) variable (M : Matroid α) [InvariantCardinalRank M] (e : α) (X Y : Set α) @[simp] theorem cRk_union_closure_right_eq : M.cRk (X ∪ M.closure Y) = M.cRk (X ∪ Y) := M.cRk_closure_congr (M.closure_union_closure_right_eq _ _) @[simp] theorem cRk_union_closure_left_eq : M.cRk (M.closure X ∪ Y) = M.cRk (X ∪ Y) := M.cRk_closure_congr (M.closure_union_closure_left_eq _ _) @[simp] theorem cRk_insert_closure_eq : M.cRk (insert e (M.closure X)) = M.cRk (insert e X) := by rw [← union_singleton, cRk_union_closure_left_eq, union_singleton] theorem cRk_union_closure_eq : M.cRk (M.closure X ∪ M.closure Y) = M.cRk (X ∪ Y) := by simp /-- The `Cardinal` rank function is submodular. -/ theorem cRk_inter_add_cRk_union_le : M.cRk (X ∩ Y) + M.cRk (X ∪ Y) ≤ M.cRk X + M.cRk Y := by obtain ⟨Ii, hIi⟩ := M.exists_isBasis' (X ∩ Y) obtain ⟨IX, hIX, hIX'⟩ := hIi.indep.subset_isBasis'_of_subset (hIi.subset.trans inter_subset_left) obtain ⟨IY, hIY, hIY'⟩ := hIi.indep.subset_isBasis'_of_subset (hIi.subset.trans inter_subset_right) rw [← cRk_union_closure_eq, ← hIX.closure_eq_closure, ← hIY.closure_eq_closure, cRk_union_closure_eq, ← hIi.cardinalMk_eq_cRk, ← hIX.cardinalMk_eq_cRk, ← hIY.cardinalMk_eq_cRk, ← mk_union_add_mk_inter, add_comm] exact add_le_add (M.cRk_le_cardinalMk _) (mk_le_mk_of_subset (subset_inter hIX' hIY')) end Invariant section Instances /-- `Finitary` matroids have a cardinality-valued rank function. -/ instance invariantCardinalRank_of_finitary [Finitary M] : InvariantCardinalRank M := by suffices aux : ∀ ⦃B B'⦄ ⦃N : Matroid α⦄, Finitary N → N.IsBase B → N.IsBase B' → #(B \ B' : Set α) ≤ #(B' \ B : Set α) from ⟨fun I J X hI hJ ↦ (aux (restrict_finitary X) hI.isBase_restrict hJ.isBase_restrict).antisymm (aux (restrict_finitary X) hJ.isBase_restrict hI.isBase_restrict)⟩ intro B B' N hfin hB hB' by_cases h : (B' \ B).Finite · rw [← cast_ncard h, ← cast_ncard, hB.ncard_diff_comm hB'] exact (hB'.diff_finite_comm hB).mp h rw [← Set.Infinite, ← infinite_coe_iff] at h have (a : α) (ha : a ∈ B' \ B) : ∃ S : Set α, Finite S ∧ S ⊆ B ∧ ¬ N.Indep (insert a S) := by have := (hB.insert_dep ⟨hB'.subset_ground ha.1, ha.2⟩).1 contrapose! this exact Finitary.indep_of_forall_finite _ fun J hJ fin ↦ (this (J \ {a}) fin.diff.to_subtype <| diff_singleton_subset_iff.mpr hJ).subset (subset_insert_diff_singleton ..) choose S S_fin hSB dep using this let U := ⋃ a : ↥(B' \ B), S a a.2 suffices B \ B' ⊆ U by refine (mk_le_mk_of_subset this).trans <| (mk_iUnion_le ..).trans <| (mul_le_max_of_aleph0_le_left (by simp)).trans ?_ simp only [sup_le_iff, le_refl, true_and] exact ciSup_le' fun e ↦ (lt_aleph0_of_finite _).le.trans <| by simp rw [← diff_inter_self_eq_diff, diff_subset_iff, inter_comm] have hUB : (B ∩ B') ∪ U ⊆ B := union_subset inter_subset_left (iUnion_subset fun e ↦ (hSB e.1 e.2)) by_contra hBU have ⟨a, ha, ind⟩ := hB.exists_insert_of_ssubset ⟨hUB, hBU⟩ hB' have : a ∈ B' \ B := ⟨ha.1, fun haB ↦ ha.2 (.inl ⟨haB, ha.1⟩)⟩ refine dep a this (ind.subset <| insert_subset_insert <| .trans ?_ subset_union_right) exact subset_iUnion_of_subset ⟨a, this⟩ subset_rfl instance invariantCardinalRank_map (M : Matroid α) [InvariantCardinalRank M] (hf : InjOn f M.E) : InvariantCardinalRank (M.map f hf) := by refine ⟨fun I J X hI hJ ↦ ?_⟩ obtain ⟨I, X, hIX, rfl, rfl⟩ := map_isBasis_iff'.1 hI obtain ⟨J, X', hJX, rfl, h'⟩ := map_isBasis_iff'.1 hJ obtain rfl : X = X' := by rwa [InjOn.image_eq_image_iff hf hIX.subset_ground hJX.subset_ground] at h' have hcard := hIX.cardinalMk_diff_comm hJX rwa [← lift_inj.{u,v}, ← mk_image_eq_of_injOn_lift _ _ (hf.mono ((hIX.indep.diff _).subset_ground)), ← mk_image_eq_of_injOn_lift _ _ (hf.mono ((hJX.indep.diff _).subset_ground)), lift_inj, (hf.mono hIX.indep.subset_ground).image_diff, (hf.mono hJX.indep.subset_ground).image_diff, inter_comm, hf.image_inter hJX.indep.subset_ground hIX.indep.subset_ground, diff_inter_self_eq_diff, diff_self_inter] at hcard instance invariantCardinalRank_comap (M : Matroid β) [InvariantCardinalRank M] (f : α → β) : InvariantCardinalRank (M.comap f) := by refine ⟨fun I J X hI hJ ↦ ?_⟩ obtain ⟨hI, hfI, hIX⟩ := comap_isBasis_iff.1 hI obtain ⟨hJ, hfJ, hJX⟩ := comap_isBasis_iff.1 hJ rw [← lift_inj.{u,v}, ← mk_image_eq_of_injOn_lift _ _ (hfI.mono diff_subset), ← mk_image_eq_of_injOn_lift _ _ (hfJ.mono diff_subset), lift_inj, hfI.image_diff, hfJ.image_diff, ← diff_union_diff_cancel inter_subset_left (image_inter_subset f I J), inter_comm, diff_inter_self_eq_diff, mk_union_of_disjoint, hI.cardinalMk_diff_comm hJ, ← diff_union_diff_cancel inter_subset_left (image_inter_subset f J I), inter_comm, diff_inter_self_eq_diff, mk_union_of_disjoint, inter_comm J I] <;> exact disjoint_sdiff_left.mono_right (diff_subset.trans inter_subset_left) end Instances theorem rankFinite_iff_cRank_lt_aleph0 : M.RankFinite ↔ M.cRank < ℵ₀ := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨?_⟩⟩ · have ⟨B, hB, fin⟩ := h exact hB.cardinalMk_eq_cRank ▸ lt_aleph0_iff_finite.mpr fin have ⟨B, hB⟩ := M.exists_isBase simp_rw [← finite_coe_iff, ← lt_aleph0_iff_finite] exact ⟨B, hB, hB.cardinalMk_le_cRank.trans_lt h⟩ theorem rankInfinite_iff_aleph0_le_cRank : M.RankInfinite ↔ ℵ₀ ≤ M.cRank := by rw [← not_lt, ← rankFinite_iff_cRank_lt_aleph0, not_rankFinite_iff] theorem isRkFinite_iff_cRk_lt_aleph0 : M.IsRkFinite X ↔ M.cRk X < ℵ₀ := by rw [IsRkFinite, rankFinite_iff_cRank_lt_aleph0, cRank_restrict] theorem Indep.isBase_of_cRank_le [M.RankFinite] (ind : M.Indep I) (le : M.cRank ≤ #I) : M.IsBase I := ind.isBase_of_maximal fun _J ind_J hIJ ↦ ind.finite.eq_of_subset_of_encard_le hIJ <| toENat.monotone' <| ind_J.cardinalMk_le_cRank.trans le theorem Spanning.isBase_of_le_cRank [M.RankFinite] (h : M.Spanning X) (le : #X ≤ M.cRank) : M.IsBase X := by have ⟨B, hB, hBX⟩ := h.exists_isBase_subset rwa [← hB.finite.eq_of_subset_of_encard_le hBX (toENat.monotone' <| le.trans hB.cardinalMk_eq_cRank.ge)] theorem Indep.isBase_of_cRank_le_of_finite (ind : M.Indep I) (le : M.cRank ≤ #I) (fin : I.Finite) : M.IsBase I := have := rankFinite_iff_cRank_lt_aleph0.mpr (le.trans_lt <| lt_aleph0_iff_finite.mpr fin) ind.isBase_of_cRank_le le theorem Spanning.isBase_of_le_cRank_of_finite (h : M.Spanning X) (le : #X ≤ M.cRank) (fin : X.Finite) : M.IsBase X := have ⟨_B, hB, hBX⟩ := h.exists_isBase_subset have := hB.rankFinite_of_finite (fin.subset hBX) h.isBase_of_le_cRank le @[simp] theorem toENat_cRank_eq (M : Matroid α) : M.cRank.toENat = M.eRank := by obtain h | h := M.rankFinite_or_rankInfinite · obtain ⟨B, hB⟩ := M.exists_isBase rw [← hB.cardinalMk_eq_cRank, ← hB.encard_eq_eRank, toENat_cardinalMk] simp [rankInfinite_iff_aleph0_le_cRank.1 h] @[simp] theorem toENat_cRk_eq (M : Matroid α) (X : Set α) : (M.cRk X).toENat = M.eRk X := by rw [cRk, toENat_cRank_eq, eRk] end Matroid
HasConicalPullbacks.lean
/- Copyright (c) 2025 Jon Eugster. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Jon Eugster, Emily Riehl -/ import Mathlib.CategoryTheory.Enriched.Limits.HasConicalLimits /-! # Existence of conical pullbacks -/ universe w v' v u u' namespace CategoryTheory.Enriched open Limits variable (V : Type u') [Category.{v'} V] [MonoidalCategory V] variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C] /-- `HasPullback f g` represents the mere existence of a conical limit cone for the pair of morphisms `f : X ⟶ Z` and `g : Y ⟶ Z` -/ abbrev HasConicalPullback {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) := HasConicalLimit V (cospan f g) /-- ensure conical pullbacks are pullbacks -/ example {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [HasConicalPullback V f g] : HasPullback f g := inferInstance variable (C) /-- `HasConicalPullbacks` represents the existence of conical pullback for every pair of morphisms -/ abbrev HasConicalPullbacks : Prop := HasConicalLimitsOfShape WalkingCospan V C /-- ensure pullbacks exist of existence of conical pullbacks -/ example [HasConicalPullbacks V C] : HasPullbacks C := inferInstance end CategoryTheory.Enriched
ChevalleyWarning.lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.FieldTheory.Finite.Basic /-! # The Chevalley–Warning theorem This file contains a proof of the Chevalley–Warning theorem. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Main results 1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`) such that the total degree of `f` is less than `(q-1)` times the cardinality of `σ`. Then the evaluation of `f` on all points of `σ → K` (aka `K^σ`) sums to `0`. (`sum_eval_eq_zero`) 2. The Chevalley–Warning theorem (`char_dvd_card_solutions_of_sum_lt`). Let `f i` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) such that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by the characteristic of `K`. ## Notation - `K` is a finite field - `q` is notation for the cardinality of `K` - `σ` is the indexing type for the variables of a multivariate polynomial ring over `K` -/ universe u v section FiniteField open MvPolynomial open Function hiding eval open Finset FiniteField variable {K σ ι : Type*} [Fintype K] [Field K] [Fintype σ] [DecidableEq σ] local notation "q" => Fintype.card K theorem MvPolynomial.sum_eval_eq_zero (f : MvPolynomial σ K) (h : f.totalDegree < (q - 1) * Fintype.card σ) : ∑ x, eval x f = 0 := by haveI : DecidableEq K := Classical.decEq K calc ∑ x, eval x f = ∑ x : σ → K, ∑ d ∈ f.support, f.coeff d * ∏ i, x i ^ d i := by simp only [eval_eq'] _ = ∑ d ∈ f.support, ∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i := sum_comm _ = 0 := sum_eq_zero ?_ intro d hd obtain ⟨i, hi⟩ : ∃ i, d i < q - 1 := f.exists_degree_lt (q - 1) h hd calc (∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i) = f.coeff d * ∑ x : σ → K, ∏ i, x i ^ d i := (mul_sum ..).symm _ = 0 := (mul_eq_zero.mpr ∘ Or.inr) ?_ calc (∑ x : σ → K, ∏ i, x i ^ d i) = ∑ x₀ : { j // j ≠ i } → K, ∑ x : { x : σ → K // x ∘ (↑) = x₀ }, ∏ j, (x : σ → K) j ^ d j := (Fintype.sum_fiberwise _ _).symm _ = 0 := Fintype.sum_eq_zero _ ?_ intro x₀ let e : K ≃ { x // x ∘ ((↑) : _ → σ) = x₀ } := (Equiv.subtypeEquivCodomain _).symm calc (∑ x : { x : σ → K // x ∘ (↑) = x₀ }, ∏ j, (x : σ → K) j ^ d j) = ∑ a : K, ∏ j : σ, (e a : σ → K) j ^ d j := (e.sum_comp _).symm _ = ∑ a : K, (∏ j, x₀ j ^ d j) * a ^ d i := Fintype.sum_congr _ _ ?_ _ = (∏ j, x₀ j ^ d j) * ∑ a : K, a ^ d i := by rw [mul_sum] _ = 0 := by rw [sum_pow_lt_card_sub_one K _ hi, mul_zero] intro a let e' : { j // j = i } ⊕ { j // j ≠ i } ≃ σ := Equiv.sumCompl _ letI : Unique { j // j = i } := { default := ⟨i, rfl⟩ uniq := fun ⟨j, h⟩ => Subtype.val_injective h } calc (∏ j : σ, (e a : σ → K) j ^ d j) = (e a : σ → K) i ^ d i * ∏ j : { j // j ≠ i }, (e a : σ → K) j ^ d j := by rw [← e'.prod_comp, Fintype.prod_sum_type, univ_unique, prod_singleton]; rfl _ = a ^ d i * ∏ j : { j // j ≠ i }, (e a : σ → K) j ^ d j := by rw [Equiv.subtypeEquivCodomain_symm_apply_eq] _ = a ^ d i * ∏ j, x₀ j ^ d j := congr_arg _ (Fintype.prod_congr _ _ ?_) -- see below _ = (∏ j, x₀ j ^ d j) * a ^ d i := mul_comm _ _ -- the remaining step of the calculation above rintro ⟨j, hj⟩ change (e a : σ → K) j ^ d j = x₀ ⟨j, hj⟩ ^ d j rw [Equiv.subtypeEquivCodomain_symm_apply_ne] variable [DecidableEq K] (p : ℕ) [CharP K p] /-- The **Chevalley–Warning theorem**, finitary version. Let `(f i)` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_sum_lt {s : Finset ι} {f : ι → MvPolynomial σ K} (h : (∑ i ∈ s, (f i).totalDegree) < Fintype.card σ) : p ∣ Fintype.card { x : σ → K // ∀ i ∈ s, eval x (f i) = 0 } := by have hq : 0 < q - 1 := by rw [← Fintype.card_units, Fintype.card_pos_iff]; exact ⟨1⟩ let S : Finset (σ → K) := {x | ∀ i ∈ s, eval x (f i) = 0} have hS (x : σ → K) : x ∈ S ↔ ∀ i ∈ s, eval x (f i) = 0 := by simp [S] /- The polynomial `F = ∏ i ∈ s, (1 - (f i)^(q - 1))` has the nice property that it takes the value `1` on elements of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` while it is `0` outside that locus. Hence the sum of its values is equal to the cardinality of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` modulo `p`. -/ let F : MvPolynomial σ K := ∏ i ∈ s, (1 - f i ^ (q - 1)) have hF : ∀ x, eval x F = if x ∈ S then 1 else 0 := by intro x calc eval x F = ∏ i ∈ s, eval x (1 - f i ^ (q - 1)) := eval_prod s _ x _ = if x ∈ S then 1 else 0 := ?_ simp only [(eval x).map_sub, (eval x).map_pow, (eval x).map_one] split_ifs with hx · apply Finset.prod_eq_one intro i hi rw [hS] at hx rw [hx i hi, zero_pow hq.ne', sub_zero] · obtain ⟨i, hi, hx⟩ : ∃ i ∈ s, eval x (f i) ≠ 0 := by simpa [hS, not_forall, Classical.not_imp] using hx apply Finset.prod_eq_zero hi rw [pow_card_sub_one_eq_one (eval x (f i)) hx, sub_self] -- In particular, we can now show: have key : ∑ x, eval x F = Fintype.card { x : σ → K // ∀ i ∈ s, eval x (f i) = 0 } := by rw [Fintype.card_of_subtype S hS, card_eq_sum_ones, Nat.cast_sum, Nat.cast_one, ← Fintype.sum_extend_by_zero S, sum_congr rfl fun x _ => hF x] -- With these preparations under our belt, we will approach the main goal. change p ∣ Fintype.card { x // ∀ i : ι, i ∈ s → eval x (f i) = 0 } rw [← CharP.cast_eq_zero_iff K, ← key] change (∑ x, eval x F) = 0 -- We are now ready to apply the main machine, proven before. apply F.sum_eval_eq_zero -- It remains to verify the crucial assumption of this machine show F.totalDegree < (q - 1) * Fintype.card σ calc F.totalDegree ≤ ∑ i ∈ s, (1 - f i ^ (q - 1)).totalDegree := totalDegree_finset_prod s _ _ ≤ ∑ i ∈ s, (q - 1) * (f i).totalDegree := sum_le_sum fun i _ => ?_ -- see ↓ _ = (q - 1) * ∑ i ∈ s, (f i).totalDegree := (mul_sum ..).symm _ < (q - 1) * Fintype.card σ := by rwa [mul_lt_mul_left hq] -- Now we prove the remaining step from the preceding calculation change (1 - f i ^ (q - 1)).totalDegree ≤ (q - 1) * (f i).totalDegree calc (1 - f i ^ (q - 1)).totalDegree ≤ max (1 : MvPolynomial σ K).totalDegree (f i ^ (q - 1)).totalDegree := totalDegree_sub _ _ _ ≤ (f i ^ (q - 1)).totalDegree := by simp _ ≤ (q - 1) * (f i).totalDegree := totalDegree_pow _ _ /-- The **Chevalley–Warning theorem**, `Fintype` version. Let `(f i)` be a finite family of multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`. Then the number of common solutions of the `f i` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_fintype_sum_lt [Fintype ι] {f : ι → MvPolynomial σ K} (h : (∑ i, (f i).totalDegree) < Fintype.card σ) : p ∣ Fintype.card { x : σ → K // ∀ i, eval x (f i) = 0 } := by simpa using char_dvd_card_solutions_of_sum_lt p h /-- The **Chevalley–Warning theorem**, unary version. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the total degree of `f` is less than the cardinality of `σ`. Then the number of solutions of `f` is divisible by `p`. See `char_dvd_card_solutions_of_sum_lt` for a version that takes a family of polynomials `f i`. -/ theorem char_dvd_card_solutions {f : MvPolynomial σ K} (h : f.totalDegree < Fintype.card σ) : p ∣ Fintype.card { x : σ → K // eval x f = 0 } := by let F : Unit → MvPolynomial σ K := fun _ => f have : (∑ i : Unit, (F i).totalDegree) < Fintype.card σ := h convert char_dvd_card_solutions_of_sum_lt p this aesop /-- The **Chevalley–Warning theorem**, binary version. Let `f₁`, `f₂` be two multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`. Assume that the sum of the total degrees of `f₁` and `f₂` is less than the cardinality of `σ`. Then the number of common solutions of the `f₁` and `f₂` is divisible by `p`. -/ theorem char_dvd_card_solutions_of_add_lt {f₁ f₂ : MvPolynomial σ K} (h : f₁.totalDegree + f₂.totalDegree < Fintype.card σ) : p ∣ Fintype.card { x : σ → K // eval x f₁ = 0 ∧ eval x f₂ = 0 } := by let F : Bool → MvPolynomial σ K := fun b => cond b f₂ f₁ have : (∑ b : Bool, (F b).totalDegree) < Fintype.card σ := (add_comm _ _).trans_lt h simpa only [Bool.forall_bool] using char_dvd_card_solutions_of_fintype_sum_lt p this end FiniteField
archimedean.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 choice. From mathcomp Require Import fintype bigop order ssralg poly ssrnum ssrint. (******************************************************************************) (* Archimedean structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* This file defines some numeric structures extended with the Archimedean *) (* axiom. To use this file, insert "Import Num.Theory." and optionally *) (* "Import Num.Def." before your scripts as in the ssrnum library. *) (* The modules provided by this library subsume those from ssrnum. *) (* *) (* This file defines the following structures: *) (* *) (* archiNumDomainType == numDomainType with the Archimedean axiom *) (* The HB class is called ArchiNumDomain. *) (* archiNumFieldType == numFieldType with the Archimedean axiom *) (* The HB class is called ArchiNumField. *) (* archiClosedFieldType == closedFieldType with the Archimedean axiom *) (* The HB class is called ArchiClosedField. *) (* archiRealDomainType == realDomainType with the Archimedean axiom *) (* The HB class is called ArchiRealDomain. *) (* archiRealFieldType == realFieldType with the Archimedean axiom *) (* The HB class is called ArchiRealField. *) (* archiRcfType == rcfType with the Archimedean axiom *) (* The HB class is called ArchiRealClosedField. *) (* *) (* Over these structures, we have the following operations: *) (* x \is a Num.int <=> x is an integer, i.e., x = m%:~R for some m : int *) (* x \is a Num.nat <=> x is a natural number, i.e., x = m%:R for some m : nat*) (* Num.floor x == the m : int such that m%:~R <= x < (m + 1)%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.ceil x == the m : int such that (m - 1)%:~R < x <= m%:~R *) (* when x \is a Num.real, otherwise 0%Z *) (* Num.truncn x == the n : nat such that n%:R <= x < n.+1%:R *) (* when 0 <= n, otherwise 0%N *) (* Num.bound x == an upper bound for x, i.e., an n such that `|x| < n%:R *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Local Open Scope ring_scope. Import Order.TTheory GRing.Theory Num.Theory. Module Num. Import Num.Def. HB.mixin Record NumDomain_hasFloorCeilTruncn R of Num.NumDomain R := { floor : R -> int; ceil : R -> int; truncn : R -> nat; int_num_subdef : pred R; nat_num_subdef : pred R; floor_subproof : forall x, if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0; ceil_subproof : forall x, ceil x = - floor (- x); truncn_subproof : forall x, truncn x = if floor x is Posz n then n else 0; int_num_subproof : forall x, reflect (exists n, x = n%:~R) (int_num_subdef x); nat_num_subproof : forall x, reflect (exists n, x = n%:R) (nat_num_subdef x); }. #[short(type="archiNumDomainType")] HB.structure Definition ArchiNumDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.NumDomain R }. Module ArchiNumDomainExports. Bind Scope ring_scope with ArchiNumDomain.sort. End ArchiNumDomainExports. HB.export ArchiNumDomainExports. #[short(type="archiNumFieldType")] HB.structure Definition ArchiNumField := { R of NumDomain_hasFloorCeilTruncn R & Num.NumField R }. Module ArchiNumFieldExports. Bind Scope ring_scope with ArchiNumField.sort. End ArchiNumFieldExports. HB.export ArchiNumFieldExports. #[short(type="archiClosedFieldType")] HB.structure Definition ArchiClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.ClosedField R }. Module ArchiClosedFieldExports. Bind Scope ring_scope with ArchiClosedField.sort. End ArchiClosedFieldExports. HB.export ArchiClosedFieldExports. #[short(type="archiRealDomainType")] HB.structure Definition ArchiRealDomain := { R of NumDomain_hasFloorCeilTruncn R & Num.RealDomain R }. Module ArchiRealDomainExports. Bind Scope ring_scope with ArchiRealDomain.sort. End ArchiRealDomainExports. HB.export ArchiRealDomainExports. #[short(type="archiRealFieldType")] HB.structure Definition ArchiRealField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealField R }. Module ArchiRealFieldExports. Bind Scope ring_scope with ArchiRealField.sort. End ArchiRealFieldExports. HB.export ArchiRealFieldExports. #[short(type="archiRcfType")] HB.structure Definition ArchiRealClosedField := { R of NumDomain_hasFloorCeilTruncn R & Num.RealClosedField R }. Module ArchiRealClosedFieldExports. Bind Scope ring_scope with ArchiRealClosedField.sort. End ArchiRealClosedFieldExports. HB.export ArchiRealClosedFieldExports. Section Def. Context {R : archiNumDomainType}. Definition nat_num : qualifier 1 R := [qualify a x : R | nat_num_subdef x]. Definition int_num : qualifier 1 R := [qualify a x : R | int_num_subdef x]. Definition bound (x : R) := (truncn `|x|).+1. End Def. Arguments floor {R} : rename, simpl never. Arguments ceil {R} : rename, simpl never. Arguments truncn {R} : rename, simpl never. Arguments nat_num {R} : simpl never. Arguments int_num {R} : simpl never. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Module Def. Export ssrnum.Num.Def. Notation truncn := truncn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")] Notation trunc := truncn. Notation floor := floor. Notation ceil := ceil. Notation nat_num := nat_num. Notation int_num := int_num. Notation archi_bound := bound. End Def. Module intArchimedean. Section intArchimedean. Implicit Types n : int. Lemma floorP n : if n \is Rreal then n%:~R <= n < (n + 1)%:~R else n == 0. Proof. by rewrite num_real !intz ltzD1 lexx. Qed. Lemma intrP n : reflect (exists m, n = m%:~R) true. Proof. by apply: ReflectT; exists n; rewrite intz. Qed. Lemma natrP n : reflect (exists m, n = m%:R) (0 <= n). Proof. apply: (iffP idP); last by case=> m ->; rewrite ler0n. by case: n => // n _; exists n; rewrite natz. Qed. End intArchimedean. End intArchimedean. #[export] HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build int id id _ xpredT Rnneg_pred intArchimedean.floorP (fun=> esym (opprK _)) (fun=> erefl) intArchimedean.intrP intArchimedean.natrP. Module Import Theory. Export ssrnum.Num.Theory. Section ArchiNumDomainTheory. Variable R : archiNumDomainType. Implicit Types x y z : R. Local Notation truncn := (@truncn R). Local Notation floor := (@floor R). Local Notation ceil := (@ceil R). Local Notation nat_num := (@Def.nat_num R). Local Notation int_num := (@Def.int_num R). Local Lemma floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. exact: floor_subproof. Qed. Lemma floorNceil x : floor x = - ceil (- x). Proof. by rewrite ceil_subproof !opprK. Qed. Lemma ceilNfloor x : ceil x = - floor (- x). Proof. exact: ceil_subproof. Qed. Lemma truncEfloor x : truncn x = if floor x is Posz n then n else 0. Proof. exact: truncn_subproof. Qed. Lemma natrP x : reflect (exists n, x = n%:R) (x \is a nat_num). Proof. exact: nat_num_subproof. Qed. Lemma intrP x : reflect (exists m, x = m%:~R) (x \is a int_num). Proof. exact: int_num_subproof. Qed. (* int_num and nat_num *) Lemma intr_int m : m%:~R \is a int_num. Proof. by apply/intrP; exists m. Qed. Lemma natr_nat n : n%:R \is a nat_num. Proof. by apply/natrP; exists n. Qed. #[local] Hint Resolve intr_int natr_nat : core. Lemma rpred_int_num (S : subringClosed R) x : x \is a int_num -> x \in S. Proof. by move=> /intrP[n ->]; rewrite rpred_int. Qed. Lemma rpred_nat_num (S : semiringClosed R) x : x \is a nat_num -> x \in S. Proof. by move=> /natrP[n ->]; apply: rpred_nat. Qed. Lemma int_num0 : 0 \is a int_num. Proof. exact: (intr_int 0). Qed. Lemma int_num1 : 1 \is a int_num. Proof. exact: (intr_int 1). Qed. Lemma nat_num0 : 0 \is a nat_num. Proof. exact: (natr_nat 0). Qed. Lemma nat_num1 : 1 \is a nat_num. Proof. exact: (natr_nat 1). Qed. #[local] Hint Resolve int_num0 int_num1 nat_num0 nat_num1 : core. Fact int_num_subring : subring_closed int_num. Proof. by split=> // _ _ /intrP[n ->] /intrP[m ->]; rewrite -(intrB, intrM). Qed. #[export] HB.instance Definition _ := GRing.isSubringClosed.Build R int_num_subdef int_num_subring. Fact nat_num_semiring : semiring_closed nat_num. Proof. by do 2![split] => //= _ _ /natrP[n ->] /natrP[m ->]; rewrite -(natrD, natrM). Qed. #[export] HB.instance Definition _ := GRing.isSemiringClosed.Build R nat_num_subdef nat_num_semiring. Lemma Rreal_nat : {subset nat_num <= Rreal}. Proof. exact: rpred_nat_num. Qed. Lemma intr_nat : {subset nat_num <= int_num}. Proof. by move=> _ /natrP[n ->]; rewrite pmulrn intr_int. Qed. Lemma Rreal_int : {subset int_num <= Rreal}. Proof. exact: rpred_int_num. Qed. Lemma intrE x : (x \is a int_num) = (x \is a nat_num) || (- x \is a nat_num). Proof. apply/idP/orP => [/intrP[[n|n] ->]|[]/intr_nat]; rewrite ?rpredN //. by left; apply/natrP; exists n. by rewrite NegzE intrN opprK; right; apply/natrP; exists n.+1. Qed. Lemma intr_normK x : x \is a int_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_int/real_normK. Qed. Lemma natr_normK x : x \is a nat_num -> `|x| ^+ 2 = x ^+ 2. Proof. by move/Rreal_nat/real_normK. Qed. Lemma natr_norm_int x : x \is a int_num -> `|x| \is a nat_num. Proof. by move=> /intrP[m ->]; rewrite -intr_norm rpred_nat_num ?natr_nat. Qed. Lemma natr_ge0 x : x \is a nat_num -> 0 <= x. Proof. by move=> /natrP[n ->]; apply: ler0n. Qed. Lemma natr_gt0 x : x \is a nat_num -> (0 < x) = (x != 0). Proof. by move/natr_ge0; case: comparableP. Qed. Lemma natrEint x : (x \is a nat_num) = (x \is a int_num) && (0 <= x). Proof. apply/idP/andP=> [Nx | [Zx x_ge0]]; first by rewrite intr_nat ?natr_ge0. by rewrite -(ger0_norm x_ge0) natr_norm_int. Qed. Lemma intrEge0 x : 0 <= x -> (x \is a int_num) = (x \is a nat_num). Proof. by rewrite natrEint andbC => ->. Qed. Lemma intrEsign x : x \is a int_num -> x = (-1) ^+ (x < 0)%R * `|x|. Proof. by move/Rreal_int/realEsign. Qed. Lemma norm_natr x : x \is a nat_num -> `|x| = x. Proof. by move/natr_ge0/ger0_norm. Qed. Lemma natr_exp_even x n : ~~ odd n -> x \is a int_num -> x ^+ n \is a nat_num. Proof. move=> n_oddF x_intr. by rewrite natrEint rpredX //= real_exprn_even_ge0 // Rreal_int. Qed. Lemma norm_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= `|x|. Proof. rewrite -normr_eq0 => /natr_norm_int/natrP[n ->]. by rewrite pnatr_eq0 ler1n lt0n. Qed. Lemma sqr_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= x ^+ 2. Proof. by move=> Zx nz_x; rewrite -intr_normK // expr_ge1 ?normr_ge0 ?norm_intr_ge1. Qed. Lemma intr_ler_sqr x : x \is a int_num -> x <= x ^+ 2. Proof. move=> Zx; have [-> | nz_x] := eqVneq x 0; first by rewrite expr0n. apply: le_trans (_ : `|x| <= _); first by rewrite real_ler_norm ?Rreal_int. by rewrite -intr_normK // ler_eXnr // norm_intr_ge1. Qed. (* floor and int_num *) Lemma real_floor_itv x : x \is Rreal -> (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. by case: ifP (floorP x). Qed. Lemma real_floor_le x : x \is Rreal -> (floor x)%:~R <= x. Proof. by case/real_floor_itv/andP. Qed. Lemma real_floorD1_gt x : x \is Rreal -> x < (floor x + 1)%:~R. Proof. by case/real_floor_itv/andP. Qed. Lemma floor_def x m : m%:~R <= x < (m + 1)%:~R -> floor x = m. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eq_le -!ltzD1. move: (ger_real lemx); rewrite realz => /real_floor_itv/andP[lefx ltxf1]. by rewrite -!(ltr_int R) 2?(@le_lt_trans _ _ x). Qed. (* TODO: rename to real_floor_ge_int, once the currently deprecated one has been removed *) Lemma real_floor_ge_int_tmp x n : x \is Rreal -> (n <= floor x) = (n%:~R <= x). Proof. move=> /real_floor_itv /andP[lefx ltxf1]; apply/idP/idP => lenx. by apply: le_trans lefx; rewrite ler_int. by rewrite -ltzD1 -(ltr_int R); apply: le_lt_trans ltxf1. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_floor_ge_int_tmp instead.")] Lemma real_floor_ge_int x n : x \is Rreal -> (n%:~R <= x) = (n <= floor x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma real_floor_lt_int x n : x \is Rreal -> (floor x < n) = (x < n%:~R). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_floor_ge_int_tmp -?ltNge. Qed. Lemma real_floor_eq x n : x \is Rreal -> (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_floor_itv|exact: floor_def]. Qed. Lemma le_floor : {homo floor : x y / x <= y}. Proof. move=> x y lexy; move: (floorP x) (floorP y); rewrite (ger_real lexy). case: ifP => [_ /andP[lefx _] /andP[_] | _ /eqP-> /eqP-> //]. by move=> /(le_lt_trans lexy) /(le_lt_trans lefx); rewrite ltr_int ltzD1. Qed. Lemma intrKfloor : cancel intr floor. Proof. by move=> m; apply: floor_def; rewrite lexx rmorphD ltrDl ltr01. Qed. Lemma natr_int n : n%:R \is a int_num. Proof. by rewrite intrE natr_nat. Qed. #[local] Hint Resolve natr_int : core. Lemma intrEfloor x : x \is a int_num = ((floor x)%:~R == x). Proof. by apply/intrP/eqP => [[n ->] | <-]; [rewrite intrKfloor | exists (floor x)]. Qed. Lemma floorK : {in int_num, cancel floor intr}. Proof. by move=> z; rewrite intrEfloor => /eqP. Qed. Lemma floor0 : floor 0 = 0. Proof. exact: intrKfloor 0. Qed. Lemma floor1 : floor 1 = 1. Proof. exact: intrKfloor 1. Qed. #[local] Hint Resolve floor0 floor1 : core. Lemma real_floorDzr : {in int_num & Rreal, {morph floor : x y / x + y}}. Proof. move=> _ y /intrP[m ->] Ry; apply: floor_def. by rewrite -addrA 2!rmorphD /= intrKfloor lerD2l ltrD2l real_floor_itv. Qed. Lemma real_floorDrz : {in Rreal & int_num, {morph floor : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_floorDzr // addrC. Qed. Lemma floorN : {in int_num, {morph floor : x / - x}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphN !intrKfloor. Qed. Lemma floorM : {in int_num &, {morph floor : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKfloor. Qed. Lemma floorX n : {in int_num, {morph floor : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKfloor. Qed. Lemma real_floor_ge0 x : x \is Rreal -> (0 <= floor x) = (0 <= x). Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed. Lemma floor_lt0 x : (floor x < 0) = (x < 0). Proof. case: ifP (floorP x) => [xr _ | xr /eqP <-]; first by rewrite real_floor_lt_int. by rewrite ltxx; apply/esym/(contraFF _ xr)/ltr0_real. Qed. Lemma real_floor_le0 x : x \is Rreal -> (floor x <= 0) = (x < 1). Proof. by move=> ?; rewrite -ltzD1 add0r real_floor_lt_int. Qed. Lemma floor_gt0 x : (floor x > 0) = (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]. by rewrite gtz0_ge1 real_floor_ge_int_tmp. by rewrite ltxx; apply/esym/(contraFF _ xr)/ger1_real. Qed. Lemma floor_neq0 x : (floor x != 0) = (x < 0) || (x >= 1). Proof. case: ifP (floorP x) => [xr _ | xr /eqP->]; rewrite ?eqxx/=. by rewrite neq_lt floor_lt0 floor_gt0. by apply/esym/(contraFF _ xr) => /orP[/ltr0_real|/ger1_real]. Qed. Lemma floorpK : {in polyOver int_num, cancel (map_poly floor) (map_poly intr)}. Proof. move=> p /(all_nthP 0) Zp; apply/polyP=> i. rewrite coef_map coef_map_id0 //= -[p]coefK coef_poly. by case: ifP => [/Zp/floorK // | _]; rewrite floor0. Qed. Lemma floorpP (p : {poly R}) : p \is a polyOver int_num -> {q | p = map_poly intr q}. Proof. by exists (map_poly floor p); rewrite floorpK. Qed. (* ceil and int_num *) Lemma real_ceil_itv x : x \is Rreal -> (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. rewrite ceilNfloor -opprD !intrN ltrNl lerNr andbC -realN. exact: real_floor_itv. Qed. Lemma real_ceilB1_lt x : x \is Rreal -> (ceil x - 1)%:~R < x. Proof. by case/real_ceil_itv/andP. Qed. Lemma real_ceil_ge x : x \is Rreal -> x <= (ceil x)%:~R. Proof. by case/real_ceil_itv/andP. Qed. Lemma ceil_def x m : (m - 1)%:~R < x <= m%:~R -> ceil x = m. Proof. rewrite -ltrN2 -lerN2 andbC -!intrN opprD opprK ceilNfloor. by move=> /floor_def ->; rewrite opprK. Qed. (* TODO: rename to real_ceil_le_int, once the currently deprecated one has been removed *) Lemma real_ceil_le_int_tmp x n : x \is Rreal -> (ceil x <= n) = (x <= n%:~R). Proof. rewrite ceilNfloor lerNl -realN => /real_floor_ge_int_tmp ->. by rewrite intrN lerN2. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use real_ceil_le_int_tmp instead.")] Lemma real_ceil_le_int x n : x \is Rreal -> x <= n%:~R = (ceil x <= n). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma real_ceil_gt_int x n : x \is Rreal -> (n < ceil x) = (n%:~R < x). Proof. by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_ceil_le_int_tmp ?ltNge. Qed. Lemma real_ceil_eq x n : x \is Rreal -> (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: real_ceil_itv|exact: ceil_def]. Qed. (* TODO: rename to le_ceil, once the currently deprecated one has been removed *) Lemma le_ceil_tmp : {homo ceil : x y / x <= y}. Proof. by move=> x y lexy; rewrite !ceilNfloor lerN2 le_floor ?lerN2. Qed. Lemma intrKceil : cancel intr ceil. Proof. by move=> m; rewrite ceilNfloor -intrN intrKfloor opprK. Qed. Lemma intrEceil x : x \is a int_num = ((ceil x)%:~R == x). Proof. by rewrite -rpredN intrEfloor -eqr_oppLR -intrN -ceilNfloor. Qed. Lemma ceilK : {in int_num, cancel ceil intr}. Proof. by move=> z; rewrite intrEceil => /eqP. Qed. Lemma ceil0 : ceil 0 = 0. Proof. exact: intrKceil 0. Qed. Lemma ceil1 : ceil 1 = 1. Proof. exact: intrKceil 1. Qed. #[local] Hint Resolve ceil0 ceil1 : core. Lemma real_ceilDzr : {in int_num & Rreal, {morph ceil : x y / x + y}}. Proof. move=> x y x_int y_real. by rewrite ceilNfloor opprD real_floorDzr ?rpredN // opprD -!ceilNfloor. Qed. Lemma real_ceilDrz : {in Rreal & int_num, {morph ceil : x y / x + y}}. Proof. by move=> x y xr yz; rewrite addrC real_ceilDzr // addrC. Qed. Lemma ceilN : {in int_num, {morph ceil : x / - x}}. Proof. by move=> ? ?; rewrite !ceilNfloor !opprK floorN. Qed. Lemma ceilM : {in int_num &, {morph ceil : x y / x * y}}. Proof. by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKceil. Qed. Lemma ceilX n : {in int_num, {morph ceil : x / x ^+ n}}. Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKceil. Qed. Lemma real_ceil_ge0 x : x \is Rreal -> (0 <= ceil x) = (-1 < x). Proof. by move=> ?; rewrite ceilNfloor oppr_ge0 real_floor_le0 ?realN 1?ltrNl. Qed. Lemma ceil_lt0 x : (ceil x < 0) = (x <= -1). Proof. by rewrite ceilNfloor oppr_lt0 floor_gt0 lerNr. Qed. Lemma real_ceil_le0 x : x \is Rreal -> (ceil x <= 0) = (x <= 0). Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed. Lemma ceil_gt0 x : (ceil x > 0) = (x > 0). Proof. by rewrite ceilNfloor oppr_gt0 floor_lt0 oppr_lt0. Qed. Lemma ceil_neq0 x : (ceil x != 0) = (x <= -1) || (x > 0). Proof. by rewrite ceilNfloor oppr_eq0 floor_neq0 oppr_lt0 lerNr orbC. Qed. Lemma real_ceil_floor x : x \is Rreal -> ceil x = floor x + (x \isn't a int_num). Proof. case Ix: (x \is a int_num) => Rx /=. by apply/eqP; rewrite addr0 ceilNfloor eqr_oppLR floorN. apply/ceil_def; rewrite addrK; move: (real_floor_itv Rx). by rewrite le_eqVlt -intrEfloor Ix /= => /andP[-> /ltW]. Qed. (* Relating Cnat and oldCnat. *) Lemma truncn_floor x : truncn x = if 0 <= x then `|floor x|%N else 0%N. Proof. move: (floorP x); rewrite truncEfloor realE. have [/le_floor|_]/= := boolP (0 <= x); first by rewrite floor0; case: floor. by case: ifP => [/le_floor|_ /eqP->//]; rewrite floor0; case: floor => [[]|]. Qed. (* trunc and nat_num *) Local Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite truncn_floor. case: (boolP (0 <= x)) => //= /[dup] /le_floor + /ger0_real/real_floor_itv. by rewrite floor0; case: (floor x) => // n _; rewrite absz_nat addrC -intS. Qed. Lemma truncn_itv x : 0 <= x -> (truncn x)%:R <= x < (truncn x).+1%:R. Proof. by move=> x_ge0; move: (truncnP x); rewrite x_ge0. Qed. Lemma truncn_le x : (truncn x)%:R <= x = (0 <= x). Proof. by case: ifP (truncnP x) => [+ /andP[] | + /eqP->//]. Qed. Lemma real_truncnS_gt x : x \is Rreal -> x < (truncn x).+1%:R. Proof. by move/real_ge0P => [/truncn_itv/andP[]|/lt_le_trans->]. Qed. Lemma truncn_def x n : n%:R <= x < n.+1%:R -> truncn x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/truncn_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Lemma truncn_ge_nat x n : 0 <= x -> (n <= truncn x)%N = (n%:R <= x). Proof. move=> /truncn_itv /andP[letx ltxt1]; apply/idP/idP => lenx. by apply: le_trans letx; rewrite ler_nat. by rewrite -ltnS -(ltr_nat R); apply: le_lt_trans ltxt1. Qed. Lemma truncn_gt_nat x n : (n < truncn x)%N = (n.+1%:R <= x). Proof. case: ifP (truncnP x) => [x0 _ | x0 /eqP->]; first by rewrite truncn_ge_nat. by rewrite ltn0; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn_lt_nat x n : 0 <= x -> (truncn x < n)%N = (x < n%:R). Proof. by move=> ?; rewrite real_ltNge ?ger0_real// ltnNge truncn_ge_nat. Qed. Lemma real_truncn_le_nat x n : x \is Rreal -> (truncn x <= n)%N = (x < n.+1%:R). Proof. by move=> ?; rewrite real_ltNge// leqNgt truncn_gt_nat. Qed. Lemma truncn_eq x n : 0 <= x -> (truncn x == n) = (n%:R <= x < n.+1%:R). Proof. by move=> xr; apply/eqP/idP => [<-|]; [exact: truncn_itv|exact: truncn_def]. Qed. Lemma le_truncn : {homo truncn : x y / x <= y >-> (x <= y)%N}. Proof. move=> x y lexy; move: (truncnP x) (truncnP y). case: ifP => [x0 /andP[letx _] | x0 /eqP->//]. case: ifP => [y0 /andP[_] | y0 /eqP->]; [|by rewrite (le_trans x0 lexy) in y0]. by move=> /(le_lt_trans lexy) /(le_lt_trans letx); rewrite ltr_nat ltnS. Qed. Lemma natrK : cancel (GRing.natmul 1) truncn. Proof. by move=> m; apply: truncn_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Lemma natrEtruncn x : (x \is a nat_num) = ((truncn x)%:R == x). Proof. by apply/natrP/eqP => [[n ->]|<-]; [rewrite natrK | exists (truncn x)]. Qed. Lemma archi_boundP x : 0 <= x -> x < (bound x)%:R. Proof. move=> x_ge0; case/truncn_itv/andP: (normr_ge0 x) => _. exact/le_lt_trans/real_ler_norm/ger0_real. Qed. Lemma truncnK : {in nat_num, cancel truncn (GRing.natmul 1)}. Proof. by move=> x; rewrite natrEtruncn => /eqP. Qed. Lemma truncn0 : truncn 0 = 0%N. Proof. exact: natrK 0%N. Qed. Lemma truncn1 : truncn 1 = 1%N. Proof. exact: natrK 1%N. Qed. #[local] Hint Resolve truncn0 truncn1 : core. Lemma truncnD : {in nat_num & Rnneg, {morph truncn : x y / x + y >-> (x + y)%N}}. Proof. move=> _ y /natrP[n ->] y_ge0; apply: truncn_def. by rewrite -addnS !natrD !natrK lerD2l ltrD2l truncn_itv. Qed. Lemma truncnM : {in nat_num &, {morph truncn : x y / x * y >-> (x * y)%N}}. Proof. by move=> _ _ /natrP[n1 ->] /natrP[n2 ->]; rewrite -natrM !natrK. Qed. Lemma truncnX n : {in nat_num, {morph truncn : x / x ^+ n >-> (x ^ n)%N}}. Proof. by move=> _ /natrP[n1 ->]; rewrite -natrX !natrK. Qed. Lemma truncn_gt0 x : (0 < truncn x)%N = (1 <= x). Proof. case: ifP (truncnP x) => [x0 | x0 /eqP<-]; first by rewrite truncn_ge_nat. by rewrite ltnn; apply/esym/(contraFF _ x0)/le_trans. Qed. Lemma truncn0Pn x : reflect (truncn x = 0%N) (~~ (1 <= x)). Proof. by rewrite -truncn_gt0 -eqn0Ngt; apply: eqP. Qed. Lemma sum_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\sum_(i <- r | P i) truncn (F i))%:R = \sum_(i <- r | P i) F i. Proof. by rewrite natr_sum => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma prod_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) -> (\prod_(i <- r | P i) truncn (F i))%:R = \prod_(i <- r | P i) F i. Proof. by rewrite natr_prod => natr; apply: eq_bigr => i /natr /truncnK. Qed. Lemma natr_sum_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \sum_(i | P i) F i = 1 -> {i : I | [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]}. Proof. move=> natF /eqP; rewrite -sum_truncnK// -[1]/1%:R eqr_nat => /sum_nat_eq1 exi. have [i /and3P[Pi /eqP f1 /forallP a]] : {i : I | [&& P i, truncn (F i) == 1 & [forall j : I, ((j != i) ==> P j ==> (truncn (F j) == 0))]]}. apply/sigW; have [i [Pi /eqP f1 a]] := exi; exists i; apply/and3P; split=> //. by apply/forallP => j; apply/implyP => ji; apply/implyP => Pj; apply/eqP/a. exists i; split=> [//||j ji Pj]; rewrite -[LHS]truncnK ?natF ?f1//; apply/eqP. by rewrite -[0]/0%:R eqr_nat; apply: implyP Pj; apply: implyP ji; apply: a. Qed. Lemma natr_mul_eq1 x y : x \is a nat_num -> y \is a nat_num -> (x * y == 1) = (x == 1) && (y == 1). Proof. by do 2!move/truncnK <-; rewrite -natrM !pnatr_eq1 muln_eq1. Qed. Lemma natr_prod_eq1 (I : finType) (P : pred I) (F : I -> R) : (forall i, P i -> F i \is a nat_num) -> \prod_(i | P i) F i = 1 -> forall i, P i -> F i = 1. Proof. move=> natF /eqP; rewrite -prod_truncnK// -[1]/1%:R eqr_nat prod_nat_seq_eq1. move/allP => a i Pi; apply/eqP; rewrite -[F i]truncnK ?natF// eqr_nat. by apply: implyP Pi; apply: a; apply: mem_index_enum. Qed. (* predCmod *) Variables (U V : lmodType R) (f : {additive U -> V}). Lemma raddfZ_nat a u : a \is a nat_num -> f (a *: u) = a *: f u. Proof. by move=> /natrP[n ->]; apply: raddfZnat. Qed. Lemma rpredZ_nat (S : addrClosed V) : {in nat_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /natrP[n ->]; apply: rpredZnat. Qed. Lemma raddfZ_int a u : a \is a int_num -> f (a *: u) = a *: f u. Proof. by move=> /intrP[m ->]; rewrite !scaler_int raddfMz. Qed. Lemma rpredZ_int (S : zmodClosed V) : {in int_num & S, forall z u, z *: u \in S}. Proof. by move=> _ u /intrP[m ->] ?; rewrite scaler_int rpredMz. Qed. (* autC *) Implicit Type nu : {rmorphism R -> R}. Lemma aut_natr nu : {in nat_num, nu =1 id}. Proof. by move=> _ /natrP[n ->]; apply: rmorph_nat. Qed. Lemma aut_intr nu : {in int_num, nu =1 id}. Proof. by move=> _ /intrP[m ->]; apply: rmorph_int. Qed. End ArchiNumDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_itv.")] Notation trunc_itv := truncn_itv. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_def.")] Notation trunc_def := truncn_def. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnK.")] Notation truncK := truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0.")] Notation trunc0 := truncn0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn1.")] Notation trunc1 := truncn1. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnD.")] Notation truncD := truncnD. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnM.")] Notation truncM := truncnM. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnX.")] Notation truncX := truncnX. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_gt0.")] Notation trunc_gt0 := truncn_gt0. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0Pn.")] Notation trunc0Pn := truncn0Pn. #[deprecated(since="mathcomp 2.4.0", note="Renamed to sum_truncnK.")] Notation sum_truncK := sum_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to prod_truncnK.")] Notation prod_truncK := prod_truncnK. #[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_floor.")] Notation trunc_floor := truncn_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floor_le.")] Notation real_ge_floor := real_floor_le. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floorD1_gt.")] Notation real_lt_succ_floor := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceilB1_lt.")] Notation real_gt_pred_ceil := real_floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceil_ge.")] Notation real_le_ceil := real_ceil_ge. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_floor.")] Notation floor_le := le_floor. #[deprecated(since="mathcomp 2.4.0", note="Renamed to le_ceil.")] Notation ceil_le := le_ceil_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to natrEtruncn.")] Notation natrE := natrEtruncn. Arguments natrK {R} _%_N. Arguments intrKfloor {R}. Arguments intrKceil {R}. Arguments natrP {R x}. Arguments intrP {R x}. #[global] Hint Resolve truncn0 truncn1 : core. #[global] Hint Resolve floor0 floor1 : core. #[global] Hint Resolve ceil0 ceil1 : core. #[global] Hint Extern 0 (is_true (_%:R \is a nat_num)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:R \in nat_num_subdef)) => apply: natr_nat : core. #[global] Hint Extern 0 (is_true (_%:~R \is a int_num)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:~R \in int_num_subdef)) => apply: intr_int : core. #[global] Hint Extern 0 (is_true (_%:R \is a int_num)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (_%:R \in int_num_subdef)) => apply: natr_int : core. #[global] Hint Extern 0 (is_true (0 \is a nat_num)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (0 \in nat_num_subdef)) => apply: nat_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a nat_num)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: nat_num1 : core. #[global] Hint Extern 0 (is_true (0 \is a int_num)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (0 \in int_num_subdef)) => apply: int_num0 : core. #[global] Hint Extern 0 (is_true (1 \is a int_num)) => apply: int_num1 : core. #[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: int_num1 : core. Section ArchiRealDomainTheory. Variables (R : archiRealDomainType). Implicit Type x : R. Lemma upper_nthrootP x i : (bound x <= i)%N -> x < 2%:R ^+ i. Proof. case/truncn_itv/andP: (normr_ge0 x) => _ /ltr_normlW xlt le_b_i. by rewrite (lt_le_trans xlt) // -natrX ler_nat (ltn_trans le_b_i) // ltn_expl. Qed. Lemma truncnS_gt x : x < (truncn x).+1%:R. Proof. exact: real_truncnS_gt. Qed. Lemma truncn_le_nat x n : (truncn x <= n)%N = (x < n.+1%:R). Proof. exact: real_truncn_le_nat. Qed. Lemma floor_itv x : (floor x)%:~R <= x < (floor x + 1)%:~R. Proof. exact: real_floor_itv. Qed. (* TODO: rename to floor_le, once the deprecated one has been removed *) Lemma floor_le_tmp x : (floor x)%:~R <= x. Proof. exact: real_floor_le. Qed. Lemma floorD1_gt x : x < (floor x + 1)%:~R. Proof. exact: real_floorD1_gt. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use floor_ge_int_tmp instead.")] Lemma floor_ge_int x n : n%:~R <= x = (n <= floor x). Proof. by rewrite real_floor_ge_int_tmp. Qed. (* TODO: rename to floor_ge_int, once the currently deprecated one has been removed *) Lemma floor_ge_int_tmp x n : (n <= floor x) = (n%:~R <= x). Proof. exact: real_floor_ge_int_tmp. Qed. Lemma floor_lt_int x n : (floor x < n) = (x < n%:~R). Proof. exact: real_floor_lt_int. Qed. Lemma floor_eq x n : (floor x == n) = (n%:~R <= x < (n + 1)%:~R). Proof. exact: real_floor_eq. Qed. Lemma floorDzr : {in @int_num R, {morph floor : x y / x + y}}. Proof. by move=> x xz y; apply/real_floorDzr/num_real. Qed. Lemma floorDrz x y : y \is a int_num -> floor (x + y) = floor x + floor y. Proof. by move=> yz; apply/real_floorDrz/yz/num_real. Qed. Lemma floor_ge0 x : (0 <= floor x) = (0 <= x). Proof. exact: real_floor_ge0. Qed. Lemma floor_le0 x : (floor x <= 0) = (x < 1). Proof. exact: real_floor_le0. Qed. Lemma ceil_itv x : (ceil x - 1)%:~R < x <= (ceil x)%:~R. Proof. exact: real_ceil_itv. Qed. Lemma ceilB1_lt x : (ceil x - 1)%:~R < x. Proof. exact: real_ceilB1_lt. Qed. Lemma ceil_ge x : x <= (ceil x)%:~R. Proof. exact: real_ceil_ge. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use ceil_le_int_tmp instead.")] Lemma ceil_le_int x n : x <= n%:~R = (ceil x <= n). Proof. by rewrite real_ceil_le_int_tmp. Qed. (* TODO: rename to ceil_le_int, once the currently deprecated one has been removed *) Lemma ceil_le_int_tmp x n : (ceil x <= n) = (x <= n%:~R). Proof. exact: real_ceil_le_int_tmp. Qed. Lemma ceil_gt_int x n : (n < ceil x) = (n%:~R < x). Proof. exact: real_ceil_gt_int. Qed. Lemma ceil_eq x n : (ceil x == n) = ((n - 1)%:~R < x <= n%:~R). Proof. exact: real_ceil_eq. Qed. Lemma ceilDzr : {in @int_num R, {morph ceil : x y / x + y}}. Proof. by move=> x xz y; apply/real_ceilDzr/num_real. Qed. Lemma ceilDrz x y : y \is a int_num -> ceil (x + y) = ceil x + ceil y. Proof. by move=> yz; apply/real_ceilDrz/yz/num_real. Qed. Lemma ceil_ge0 x : (0 <= ceil x) = (-1 < x). Proof. exact: real_ceil_ge0. Qed. Lemma ceil_le0 x : (ceil x <= 0) = (x <= 0). Proof. exact: real_ceil_le0. Qed. Lemma ceil_floor x : ceil x = floor x + (x \isn't a int_num). Proof. exact: real_ceil_floor. Qed. End ArchiRealDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floor_le_tmp.")] Notation ge_floor := floor_le_tmp. #[deprecated(since="mathcomp 2.4.0", note="Renamed to floorD1_gt.")] Notation lt_succ_floor := floorD1_gt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceilB1_lt.")] Notation gt_pred_ceil := ceilB1_lt. #[deprecated(since="mathcomp 2.4.0", note="Renamed to ceil_ge.")] Notation le_ceil := ceil_ge. Section ArchiNumFieldTheory. (* autLmodC *) Variables (R : archiNumFieldType) (nu : {rmorphism R -> R}). Lemma natr_aut x : (nu x \is a nat_num) = (x \is a nat_num). Proof. by apply/idP/idP=> /[dup] ? /(aut_natr nu) => [/fmorph_inj <-| ->]. Qed. Lemma intr_aut x : (nu x \is a int_num) = (x \is a int_num). Proof. by rewrite !intrE -rmorphN !natr_aut. Qed. End ArchiNumFieldTheory. Section ArchiClosedFieldTheory. Variable R : archiClosedFieldType. Implicit Type x : R. Lemma conj_natr x : x \is a nat_num -> x^* = x. Proof. by move/Rreal_nat/CrealP. Qed. Lemma conj_intr x : x \is a int_num -> x^* = x. Proof. by move/Rreal_int/CrealP. Qed. End ArchiClosedFieldTheory. Section ZnatPred. Lemma Znat_def (n : int) : (n \is a nat_num) = (0 <= n). Proof. by []. Qed. Lemma ZnatP (m : int) : reflect (exists n : nat, m = n) (m \is a nat_num). Proof. by case: m => m; constructor; [exists m | case]. Qed. End ZnatPred. End Theory. (* Factories *) HB.factory Record NumDomain_hasTruncn R of Num.NumDomain R := { trunc : R -> nat; nat_num : pred R; int_num : pred R; truncP : forall x, if 0 <= x then (trunc x)%:R <= x < (trunc x).+1%:R else trunc x == 0; natrE : forall x, nat_num x = ((trunc x)%:R == x); intrE : forall x, int_num x = nat_num x || nat_num (- x); }. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn instead.")] Notation NumDomain_isArchimedean R := (NumDomain_hasTruncn R) (only parsing). Module NumDomain_isArchimedean. #[deprecated(since="mathcomp 2.4.0", note="Use NumDomain_hasTruncn.Build instead.")] Notation Build T U := (NumDomain_hasTruncn.Build T U) (only parsing). End NumDomain_isArchimedean. HB.builders Context R of NumDomain_hasTruncn R. Fact trunc_itv x : 0 <= x -> (trunc x)%:R <= x < (trunc x).+1%:R. Proof. by move=> x_ge0; move: (truncP x); rewrite x_ge0. Qed. Definition floor (x : R) : int := if 0 <= x then Posz (trunc x) else if x < 0 then - Posz (trunc (- x) + ~~ int_num x) else 0. Fact floorP x : if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0. Proof. rewrite /floor intrE !natrE negb_or realE. case: (comparableP x 0) (@trunc_itv x) => //=; try by rewrite -PoszD addn1 -pmulrn => _ ->. move=> x_lt0 _; move: (truncP x); rewrite lt_geF // => /eqP ->. rewrite gt_eqF //=; move: x_lt0. rewrite [_ + 1]addrC -opprB !intrN lerNl ltrNr andbC -oppr_gt0. move: {x}(- x) => x x_gt0; rewrite PoszD -addrA -PoszD. have ->: Posz ((trunc x)%:R != x) - 1 = - Posz ((trunc x)%:R == x) by case: eqP. have := trunc_itv (ltW x_gt0); rewrite le_eqVlt. case: eqVneq => /=; last first. by rewrite subr0 addn1 -!pmulrn => _ /andP[-> /ltW ->]. by rewrite intrB mulr1z addn0 -!pmulrn => -> _; rewrite gtrBl lexx andbT. Qed. Fact truncE x : trunc x = if floor x is Posz n then n else 0. Proof. rewrite /floor. case: (comparableP x 0) (truncP x) => [+ /eqP ->| |_ /eqP ->|] //=. by case: (_ + _)%N. Qed. Fact trunc_def x n : n%:R <= x < n.+1%:R -> trunc x = n. Proof. case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS. have/trunc_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n. by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x). Qed. Fact natrK : cancel (GRing.natmul 1) trunc. Proof. by move=> m; apply: trunc_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed. Fact intrP x : reflect (exists n, x = n%:~R) (int_num x). Proof. rewrite intrE !natrE; apply: (iffP idP) => [|[n ->]]; last first. by case: n => n; rewrite ?NegzE ?opprK natrK eqxx // orbT. rewrite -eqr_oppLR !pmulrn -intrN. by move=> /orP[] /eqP<-; [exists (trunc x) | exists (- Posz (trunc (- x)))]. Qed. Fact natrP x : reflect (exists n, x = n%:R) (nat_num x). Proof. rewrite natrE. by apply: (iffP eqP) => [<-|[n ->]]; [exists (trunc x) | rewrite natrK]. Qed. HB.instance Definition _ := @NumDomain_hasFloorCeilTruncn.Build R floor _ trunc int_num nat_num floorP (fun=> erefl) truncE intrP natrP. HB.end. HB.factory Record NumDomain_bounded_isArchimedean R of Num.NumDomain R := { archi_bound_subproof : Num.archimedean_axiom R }. HB.builders Context R of NumDomain_bounded_isArchimedean R. Implicit Type x : R. Definition bound x := sval (sigW (archi_bound_subproof x)). Lemma boundP x : 0 <= x -> x < (bound x)%:R. Proof. by move/ger0_norm=> {1}<-; rewrite /bound; case: (sigW _). Qed. Fact truncn_subproof x : {m | 0 <= x -> m%:R <= x < m.+1%:R }. Proof. have [Rx | _] := boolP (0 <= x); last by exists 0%N. have/ex_minnP[n lt_x_n1 min_n]: exists n, x < n.+1%:R. by exists (bound x); rewrite (lt_trans (boundP Rx)) ?ltr_nat. exists n => _; rewrite {}lt_x_n1 andbT; case: n min_n => //= n min_n. rewrite real_leNgt ?rpred_nat ?ger0_real //; apply/negP => /min_n. by rewrite ltnn. Qed. Definition truncn x := if 0 <= x then sval (truncn_subproof x) else 0%N. Lemma truncnP x : if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N. Proof. rewrite /truncn; case: truncn_subproof => // n hn. by case: ifP => x_ge0; rewrite ?(ifT _ _ x_ge0) ?(ifF _ _ x_ge0) // hn. Qed. HB.instance Definition _ := NumDomain_hasTruncn.Build R truncnP (fun => erefl) (fun => erefl). HB.end. Module Exports. HB.reexport. End Exports. (* Not to pollute the local namespace, we define Num.nat and Num.int here. *) Notation nat := nat_num. Notation int := int_num. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain instead.")] Notation ArchiDomain T := (ArchiRealDomain T). Module ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.type instead.")] Notation type := ArchiRealDomain.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.copy instead.")] Notation copy T C := (ArchiRealDomain.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain.on instead.")] Notation on T := (ArchiRealDomain.on T). End ArchiDomain. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField instead.")] Notation ArchiField T := (ArchiRealField T). Module ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.type instead.")] Notation type := ArchiRealField.type. #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.copy instead.")] Notation copy T C := (ArchiRealField.copy T C). #[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.on instead.")] Notation on T := (ArchiRealField.on T). End ArchiField. #[deprecated(since="mathcomp 2.3.0", note="Use real_floorDzr instead.")] Notation floorD := real_floorDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation ceilD := real_ceilDzr. #[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")] Notation real_ceilD := real_ceilDzr. End Num. Export Num.Exports. #[deprecated(since="mathcomp 2.3.0", note="Use archiRealDomainType instead.")] Notation archiDomainType := archiRealDomainType (only parsing). #[deprecated(since="mathcomp 2.3.0", note="Use archiRealFieldType instead.")] Notation archiFieldType := archiRealFieldType (only parsing).
cc.lean
import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Set.Insert import Mathlib.Data.Vector.Defs import Mathlib.Tactic.CC set_option linter.unusedVariables false /-- warning: The tactic `cc` is deprecated since 2025-07-31, please use `grind` instead. Please report any regressions at https://github.com/leanprover/lean4/issues/. Note that `cc` supports some goals that `grind` doesn't, but these rely on higher-order unification and can result in unpredictable performance. If a downstream library is relying on this functionality, please report this in an issue and we'll help find a solution. -/ #guard_msgs in example (a b : Nat) : a = b → a = b := by cc -- Turn off the warning for the rest of the file set_option mathlib.tactic.cc.warning false section CC1 open List (Vector) open Mathlib.Tactic.CC open Lean Meta Elab Tactic /-- info: {{b, if b > 0 then a else b, c, a}, {ℕ, ℕ}, {True, f (b + b) b = f (a + c) c, False}, {f (b + b), f (a + c)}, {f (b + b) b, f (a + c) c}, {0, d + if b > 0 then a else b}, {b + b, a + c}} --- info: >>> Equivalence roots [b, ℕ, True, f (b + b), f (b + b) b, 0, b + b] --- info: >>> b's equivalence class [a, c, if b > 0 then a else b, b] -/ #guard_msgs in example (a b c d : Nat) (f : Nat → Nat → Nat) : a = b → b = c → d + (if b > 0 then a else b) = 0 → f (b + b) b ≠ f (a + c) c → False := by intro _ _ _ h run_tac withMainContext do let s ← CCState.mkUsingHs logInfo (toMessageData s) let some (_, t₁, t₂) ← liftM <| getFVarFromUserName `h >>= inferType >>= matchNe? | failure let b ← getFVarFromUserName `b let d ← getFVarFromUserName `d guard s.inconsistent guard (s.eqcSize b = 4) guard !(s.inSingletonEqc b) guard (s.inSingletonEqc d) logInfo (m!">>> Equivalence roots" ++ .ofFormat .line ++ toMessageData s.roots) logInfo (m!">>> b's equivalence class" ++ .ofFormat .line ++ toMessageData (s.eqcOf b)) let pr ← s.eqvProof t₁ t₂ let spr ← Term.exprToSyntax pr evalTactic <| ← `(tactic| have h := $spr; contradiction) example (a b : Nat) (f : Nat → Nat) : a = b → f a = f b := by cc example (a b : Nat) (f : Nat → Nat) : a = b → f a ≠ f b → False := by cc example (a b : Nat) (f : Nat → Nat) : a = b → f (f a) ≠ f (f b) → False := by cc example (a b c : Nat) (f : Nat → Nat) : a = b → c = b → f (f a) ≠ f (f c) → False := by cc example (a b c : Nat) (f : Nat → Nat → Nat) : a = b → c = b → f (f a b) a ≠ f (f c c) c → False := by cc example (a b c : Nat) (f : Nat → Nat → Nat) : a = b → c = b → f (f a b) a = f (f c c) c := by cc example (a b c d : Nat) : a ≍ b → b = c → c ≍ d → a ≍ d := by cc example (a b c d : Nat) : a = b → b = c → c ≍ d → a ≍ d := by cc example (a b c d : Nat) : a = b → b ≍ c → c ≍ d → a ≍ d := by cc example (a b c d : Nat) : a ≍ b → b ≍ c → c = d → a ≍ d := by cc example (a b c d : Nat) : a ≍ b → b = c → c = d → a ≍ d := by cc example (a b c d : Nat) : a = b → b = c → c = d → a ≍ d := by cc example (a b c d : Nat) : a = b → b ≍ c → c = d → a ≍ d := by cc axiom f₁ : {α : Type} → α → α → α axiom g₁ : Nat → Nat example (a b c : Nat) : a = b → g₁ a ≍ g₁ b := by cc example (a b c : Nat) : a = b → c = b → f₁ (f₁ a b) (g₁ c) = f₁ (f₁ c a) (g₁ b) := by cc example (a b c d e x y : Nat) : a = b → a = x → b = y → c = d → c = e → c = b → a = e := by cc example (f : ℕ → ℕ) (x : ℕ) (H1 : f (f (f x)) = x) (H2 : f (f (f (f (f x)))) = x) : f x = x := by cc end CC1 section CC2 axiom f₂ (a b : Nat) : a > b → Nat axiom g₂ : Nat → Nat example (a₁ a₂ b₁ b₂ c d : Nat) (H₁ : a₁ > b₁) (H₂ : a₂ > b₂) : a₁ = c → a₂ = c → b₁ = d → d = b₂ → g₂ (g₂ (f₂ a₁ b₁ H₁)) = g₂ (g₂ (f₂ a₂ b₂ H₂)) := by cc example (a₁ a₂ b₁ b₂ c d : Nat) : a₁ = c → a₂ = c → b₁ = d → d = b₂ → a₁ + b₁ + a₁ = a₂ + b₂ + c := by cc example (a b c : Prop) : (a ↔ b) → ((a ∧ (c ∨ b)) ↔ (b ∧ (c ∨ a))) := by cc example (a b c d : Prop) [d₁ : Decidable a] [d₂ : Decidable b] [d₃ : Decidable c] [d₄ : Decidable d] : (a ↔ b) → (c ↔ d) → ((if (a ∧ c) then True else False) ↔ (if (b ∧ d) then True else False)) := by cc example (a b c d : Prop) (x y z : Nat) [d₁ : Decidable a] [d₂ : Decidable b] [d₃ : Decidable c] [d₄ : Decidable d] : (a ↔ b) → (c ↔ d) → x = y → ((if (a ∧ c ∧ a) then x else y) = (if (b ∧ d ∧ b) then y else x)) := by cc end CC2 section CC3 example (a b : Nat) : (a = b ↔ a = b) := by cc example (a b : Nat) : (a = b) = (b = a) := by cc example (a b : Nat) : (a = b) ≍ (b = a) := by cc example (p : Nat → Nat → Prop) (f : Nat → Nat) (a b c d : Nat) : p (f a) (f b) → a = c → b = d → b = c → p (f c) (f c) := by cc example (p : Nat → Nat → Prop) (a b c d : Nat) : p a b → a = c → b = d → p c d := by cc example (p : Nat → Nat → Prop) (f : Nat → Nat) (a b c d : Nat) : p (f (f (f (f (f (f a)))))) (f (f (f (f (f (f b)))))) → a = c → b = d → b = c → p (f (f (f (f (f (f c)))))) (f (f (f (f (f (f c)))))) := by cc axiom R : Nat → Nat → Prop example (a b c : Nat) : a = b → R a b → R a a := by cc example (a b c : Prop) : a = b → b = c → (a ↔ c) := by cc example (a b c : Prop) : a = b → b ≍ c → (a ↔ c) := by cc example (a b c : Nat) : a ≍ b → b = c → a ≍ c := by cc example (a b c : Nat) : a ≍ b → b = c → a = c := by cc example (a b c d : Nat) : a ≍ b → b ≍ c → c ≍ d → a = d := by cc example (a b c d : Nat) : a ≍ b → b = c → c ≍ d → a = d := by cc example (a b c : Prop) : a = b → b = c → (a ↔ c) := by cc example (a b c : Prop) : a ≍ b → b = c → (a ↔ c) := by cc example (a b c d : Prop) : a ≍ b → b ≍ c → c ≍ d → (a ↔ d) := by cc def foo (a b c d : Prop) : a ≍ b → b = c → c ≍ d → (a ↔ d) := by cc example (a b c : Nat) (f : Nat → Nat) : a ≍ b → b = c → f a ≍ f c := by cc example (a b c : Nat) (f : Nat → Nat) : a ≍ b → b = c → f a = f c := by cc example (a b c d : Nat) (f : Nat → Nat) : a ≍ b → b = c → c ≍ f d → f a = f (f d) := by cc end CC3 section CC4 universe u open Mathlib axiom app : {α : Type u} → {n m : Nat} → List.Vector α m → List.Vector α n → List.Vector α (m + n) example (n1 n2 n3 : Nat) (v1 w1 : List.Vector Nat n1) (w1' : List.Vector Nat n3) (v2 w2 : List.Vector Nat n2) : n1 = n3 → v1 = w1 → w1 ≍ w1' → v2 = w2 → app v1 v2 ≍ app w1' w2 := by cc example (n1 n2 n3 : Nat) (v1 w1 : List.Vector Nat n1) (w1' : List.Vector Nat n3) (v2 w2 : List.Vector Nat n2) : n1 ≍ n3 → v1 = w1 → w1 ≍ w1' → v2 ≍ w2 → app v1 v2 ≍ app w1' w2 := by cc example (n1 n2 n3 : Nat) (v1 w1 v : List.Vector Nat n1) (w1' : List.Vector Nat n3) (v2 w2 w : List.Vector Nat n2) : n1 ≍ n3 → v1 = w1 → w1 ≍ w1' → v2 ≍ w2 → app w1' w2 ≍ app v w → app v1 v2 = app v w := by cc end CC4 section CC5 namespace LocalAxioms axiom A : Type axiom B : A → Type axiom C : (a : A) → B a → Type axiom D : (a : A) → (ba : B a) → C a ba → Type axiom E : (a : A) → (ba : B a) → (cba : C a ba) → D a ba cba → Type axiom F : (a : A) → (ba : B a) → (cba : C a ba) → (dcba : D a ba cba) → E a ba cba dcba → Type axiom C_ss : ∀ a ba, Lean.Meta.FastSubsingleton (C a ba) axiom a1 : A axiom a2 : A axiom a3 : A axiom mk_B1 : (a : _) → B a axiom mk_B2 : (a : _) → B a axiom mk_C1 : {a : _} → (ba : _) → C a ba axiom mk_C2 : {a : _} → (ba : _) → C a ba axiom tr_B : {a : _} → B a → B a axiom x : A → A axiom y : A → A axiom z : A → A axiom f : {a : A} → {ba : B a} → (cba : C a ba) → D a ba cba axiom f' : {a : A} → {ba : B a} → (cba : C a ba) → D a ba cba axiom g : {a : A} → {ba : B a} → {cba : C a ba} → (dcba : D a ba cba) → E a ba cba dcba axiom h : {a : A} → {ba : B a} → {cba : C a ba} → {dcba : D a ba cba} → (edcba : E a ba cba dcba) → F a ba cba dcba edcba attribute [instance] C_ss example : ∀ (a a' : A), a ≍ a' → mk_B1 a ≍ mk_B1 a' := by cc example : ∀ (a a' : A), a ≍ a' → mk_B2 a ≍ mk_B2 a' := by cc example : ∀ (a a' : A) (h : a = a') (b : B a), h ▸ b ≍ b := by cc example : a1 ≍ y a2 → mk_B1 a1 ≍ mk_B1 (y a2) := by cc example : a1 ≍ x a2 → a2 ≍ y a1 → mk_B1 (x (y a1)) ≍ mk_B1 (x (y (x a2))) := by cc example : a1 ≍ y a2 → mk_B1 a1 ≍ mk_B2 (y a2) → f (mk_C1 (mk_B2 a1)) ≍ f (mk_C2 (mk_B1 (y a2))) := by cc example : a1 ≍ y a2 → tr_B (mk_B1 a1) ≍ mk_B2 (y a2) → f (mk_C1 (mk_B2 a1)) ≍ f (mk_C2 (tr_B (mk_B1 (y a2)))) := by cc example : a1 ≍ y a2 → mk_B1 a1 ≍ (mk_B2 (y a2)) → g (f (mk_C1 (mk_B2 a1))) ≍ g (f (mk_C2 (mk_B1 (y a2)))) := by cc example : a1 ≍ y a2 → tr_B (mk_B1 a1) ≍ mk_B2 (y a2) → g (f (mk_C1 (mk_B2 a1))) ≍ g (f (mk_C2 (tr_B (mk_B1 (y a2))))) := by cc example : a1 ≍ y a2 → a2 ≍ z a3 → a3 ≍ x a1 → mk_B1 a1 ≍ mk_B2 (y (z (x a1))) → f (mk_C1 (mk_B2 (y (z (x a1))))) ≍ f' (mk_C2 (mk_B1 a1)) → g (f (mk_C1 (mk_B2 (y (z (x a1)))))) ≍ g (f' (mk_C2 (mk_B1 a1))) := by cc example : a1 ≍ y a2 → a2 ≍ z a3 → a3 ≍ x a1 → mk_B1 a1 ≍ mk_B2 (y (z (x a1))) → f (mk_C1 (mk_B2 (y (z (x a1))))) ≍ f' (mk_C2 (mk_B1 a1)) → f' (mk_C1 (mk_B1 a1)) ≍ f (mk_C2 (mk_B2 (y (z (x a1))))) → g (f (mk_C1 (mk_B1 (y (z (x a1)))))) ≍ g (f' (mk_C2 (mk_B2 a1))) := by cc example : a1 ≍ y a2 → a2 ≍ z a3 → a3 ≍ x a1 → tr_B (mk_B1 a1) ≍ mk_B2 (y (z (x a1))) → f (mk_C1 (mk_B2 (y (z (x a1))))) ≍ f' (mk_C2 (tr_B (mk_B1 a1))) → f' (mk_C1 (tr_B (mk_B1 a1))) ≍ f (mk_C2 (mk_B2 (y (z (x a1))))) → g (f (mk_C1 (tr_B (mk_B1 (y (z (x a1))))))) ≍ g (f' (mk_C2 (mk_B2 a1))) := by cc end LocalAxioms end CC5 section CC6 example (a b c a' b' c' : Nat) : a = a' → b = b' → c = c' → a + b + c + a = a' + b' + c' + a' := by cc example (a b : Unit) : a = b := by cc example (a b : Nat) (h₁ : a = 0) (h₂ : b = 0) : a = b → h₁ ≍ h₂ := by cc axiom inv' : (a : Nat) → a ≠ 0 → Nat example (a b : Nat) (h₁ : a ≠ 0) (h₂ : b ≠ 0) : a = b → inv' a h₁ = inv' b h₂ := by cc example (C : Nat → Type) (f : (n : _) → C n → C n) (n m : Nat) (c : C n) (d : C m) : f n ≍ f m → c ≍ d → n ≍ m → f n c ≍ f m d := by cc end CC6 section CC7 example (f g : {α : Type} → α → α → α) (h : Nat → Nat) (a b : Nat) : h = f a → h b = f a b := by cc example (f g : {α : Type} → (a b : α) → {x : α // x ≠ b}) (h : (b : Nat) → {x : Nat // x ≠ b}) (a b₁ b₂ : Nat) : h = f a → b₁ = b₂ → h b₁ ≍ f a b₂ := by cc example (f : Nat → Nat → Nat) (a b c d : Nat) : c = d → f a = f b → f a c = f b d := by cc example (f : Nat → Nat → Nat) (a b c d : Nat) : c ≍ d → f a ≍ f b → f a c ≍ f b d := by cc end CC7 section CCAC1 example (a b c : Nat) (f : Nat → Nat) : f (a + b + c) = f (c + b + a) := by cc example (a b c : Nat) (f : Nat → Nat) : a + b = c → f (c + c) = f (a + b + c) := by cc end CCAC1 section CCAC2 example (a b c d : Nat) (f : Nat → Nat → Nat) : b + a = d → f (a + b + c) a = f (c + d) a := by cc end CCAC2 section CCAC3 example (a b c d e : Nat) (f : Nat → Nat → Nat) : b + a = d → b + c = e → f (a + b + c) (a + b + c) = f (c + d) (a + e) := by cc example (a b c d e : Nat) (f : Nat → Nat → Nat) : b + a = d + d → b + c = e + e → f (a + b + c) (a + b + c) = f (c + d + d) (e + a + e) := by cc section universe u variable {α : Type u} variable (op : α → α → α) variable [Std.Associative op] variable [Std.Commutative op] lemma ex₁ (a b c d e : α) (f : α → α → α) : op b a = op d d → op b c = op e e → f (op a (op b c)) (op (op a b) c) = f (op (op c d) d) (op e (op a e)) := by cc end end CCAC3 section CCAC4 section universe u variable {α : Type u} example (a b c d₁ d₂ e₁ e₂ : Set α) (f : Set α → Set α → Set α) : b ∪ a = d₁ ∪ d₂ → b ∪ c = e₂ ∪ e₁ → f (a ∪ b ∪ c) (a ∪ b ∪ c) = f (c ∪ d₂ ∪ d₁) (e₂ ∪ a ∪ e₁) := by cc end end CCAC4 section CCAC5 universe u variable {α : Type u} variable [CommRing α] example (x1 x2 x3 x4 x5 x6 : α) : x1*x4 = x1 → x3*x6 = x5*x5 → x5 = x4 → x6 = x2 → x1 = x1*(x6*x3) := by cc example (y1 y2 x2 x3 x4 x5 x6 : α) : (y1 + y2)*x4 = (y2 + y1) → x3*x6 = x5*x5 → x5 = x4 → x6 = x2 → (y2 + y1) = (y1 + y2)*(x6*x3) := by cc example (y1 y2 y3 x2 x3 x4 x5 x6 : α) : (y1 + y2)*x4 = (y3 + y1) → x3*x6 = x5*x5 → x5 = x4 → x6 = x2 → y2 = y3 → (y2 + y1) = (y1 + y3)*(x6*x3) := by cc end CCAC5 section CCConstructors example (a b : Nat) (s t : List Nat) : a :: s = b :: t → a ≠ b → False := by cc example (a b : Nat) (s t : List Nat) : a :: s = b :: t → t ≠ s → False := by cc example (a c b : Nat) (s t : List Nat) : a :: s = b :: t → a ≠ c → c = b → False := by cc example (a c b : Nat) (s t : List Nat) : a :: a :: s = a :: b :: t → a ≠ c → c = b → False := by cc example (a b : Nat) (s t r : List Nat) : a :: s = r → r = b :: t → a ≠ b → False := by cc example (a b : Nat) (s t r : List Nat) : a :: s = r → r = b :: t → a = b := by cc example (a b : Nat) (s t r : List Nat) : List.cons a = List.cons b → a = b := by intro h1 /- In the current implementation, `cc` does not "complete" partially applied constructor applications. So, the following one should fail. -/ try cc /- Complete it manually. TODO(Leo): we can automate it for inhabited types. -/ have h := congr_fun h1 [] cc inductive Foo | mk1 : Nat → Nat → Foo | mk2 : Nat → Nat → Foo example (a b : Nat) : Foo.mk1 a = Foo.mk2 b → False := by intro h1 /- In the current implementation, `cc` does not "complete" partially applied constructor applications. So, the following one should fail. -/ try cc have h := congr_fun h1 0 cc universe u inductive Vec (α : Type u) : Nat → Type (max 1 u) | nil : Vec α 0 | cons : ∀ {n}, α → Vec α n → Vec α (Nat.succ n) example (α : Type u) (a b c d : α) (n : Nat) (s t : Vec α n) : Vec.cons a s = Vec.cons b t → a ≠ b → False := by cc example (α : Type u) (a b c d : α) (n : Nat) (s t : Vec α n) : Vec.cons a s = Vec.cons b t → t ≠ s → False := by cc example (α : Type u) (a b c d : α) (n : Nat) (s t : Vec α n) : Vec.cons a (Vec.cons a s) = Vec.cons a (Vec.cons b t) → b ≠ c → c = a → False := by cc end CCConstructors section CCProj example (a b c d : Nat) (f : Nat → Nat × Nat) : (f d).1 ≠ a → f d = (b, c) → b = a → False := by cc def ex₂ (a b c d : Nat) (f : Nat → Nat × Nat) : (f d).2 ≠ a → f d = (b, c) → c = a → False := by cc example (a b c : Nat) (f : Nat → Nat) : (f b, c).1 ≠ f a → f b = f c → a = c → False := by cc end CCProj section CCValue example (a b : Nat) : a = 1 → b = 2 → a = b → False := by cc example (a b c : Int) : a = 1 → c = -2 → a = b → c = b → False := by cc example (a b : Char) : a = 'h' → b = 'w' → a = b → False := by cc example (a b : String) : a = "hello" → b = "world" → a = b → False := by cc example (a b c : String) : a = c → a = "hello" → c = "world" → c = b → False := by cc local instance instOfNatNat' (n : ℕ) : OfNat ℕ n where ofNat := n example : @OfNat.ofNat ℕ (nat_lit 0) (instOfNatNat _) = @OfNat.ofNat ℕ (nat_lit 0) (instOfNatNat' _) := by cc end CCValue section Config /-! Tests for the configuration options -/ /-- `ignoreInstances := false` means instances won't be unified. -/ example {G : Type*} [AddCommMonoid G] (a b : G) : @HAdd.hAdd _ _ _ (@instHAdd _ (@AddSemigroup.toAdd _ AddCommSemigroup.toAddSemigroup)) a b = @HAdd.hAdd _ _ _ (@instHAdd _ (@AddSemigroup.toAdd _ AddMonoid.toAddSemigroup)) a b := by success_if_fail_with_msg "cc tactic failed" cc -ignoreInstances -ac cc -ac end Config section Lean3Issue1442 def Rel : ℤ × ℤ → ℤ × ℤ → Prop | (n₁, d₁), (n₂, d₂) => n₁ * d₂ = n₂ * d₁ def mul' : ℤ × ℤ → ℤ × ℤ → ℤ × ℤ | (n₁, d₁), (n₂, d₂) => ⟨n₁ * n₂, d₁ * d₂⟩ example : ∀ (a b c d : ℤ × ℤ), Rel a c → Rel b d → Rel (mul' a b) (mul' c d) := fun (n₁, d₁) (n₂, d₂) (n₃, d₃) (n₄, d₄) => fun (h₁ : n₁ * d₃ = n₃ * d₁) (h₂ : n₂ * d₄ = n₄ * d₂) => show (n₁ * n₂) * (d₃ * d₄) = (n₃ * n₄) * (d₁ * d₂) by cc end Lean3Issue1442 section Lean3Issue1608 example {α : Type} {a b : α} (h : ¬ (a = b)) : b ≠ a := by cc example {α : Type} {a b : α} (h : ¬ (a = b)) : ¬ (b = a) := by cc end Lean3Issue1608 section lit example : nat_lit 0 = nat_lit 0 := by cc example : "Miyahara Kō" = "Miyahara Kō" := by cc end lit section CCPanic example (n k : ℤ) (hnk : n = 2 * k + 1) (hk : (2 * k + 1) * (2 * k + 1 + 1) = 2 * ((2 * k + 1) * (k + 1))) : n * (n + 1) = 2 * ((2 * k + 1) * (k + 1)) := by cc end CCPanic
Finsupp.lean
/- Copyright (c) 2024 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.Group.Subgroup.Lattice /-! # Connection between `Subgroup.closure` and `Finsupp.prod` -/ assert_not_exists Field namespace Subgroup variable {M : Type*} [CommGroup M] {ι : Type*} (f : ι → M) (x : M) @[to_additive] theorem exists_finsupp_of_mem_closure_range (hx : x ∈ closure (Set.range f)) : ∃ a : ι →₀ ℤ, x = a.prod (f · ^ ·) := by classical induction hx using closure_induction with | mem x h => obtain ⟨i, rfl⟩ := h; exact ⟨Finsupp.single i 1, by simp⟩ | one => use 0; simp | mul x y hx hy hx' hy' => obtain ⟨⟨v, rfl⟩, w, rfl⟩ := And.intro hx' hy' use v + w rw [Finsupp.prod_add_index] · simp · simp [zpow_add] | inv x hx hx' => obtain ⟨a, rfl⟩ := hx' use -a rw [Finsupp.prod_neg_index] · simp · simp variable {f x} in @[to_additive] theorem mem_closure_range_iff : x ∈ closure (Set.range f) ↔ ∃ a : ι →₀ ℤ, x = a.prod (f · ^ ·) := by refine ⟨exists_finsupp_of_mem_closure_range f x, ?_⟩ rintro ⟨a, rfl⟩ exact Submonoid.prod_mem _ fun i hi ↦ zpow_mem (subset_closure (Set.mem_range_self i)) _ @[to_additive] theorem exists_of_mem_closure_range [Fintype ι] (hx : x ∈ closure (Set.range f)) : ∃ a : ι → ℤ, x = ∏ i, f i ^ a i := by obtain ⟨a, rfl⟩ := exists_finsupp_of_mem_closure_range f x hx exact ⟨a, by simp⟩ variable {f x} in @[to_additive] theorem mem_closure_range_iff_of_fintype [Fintype ι] : x ∈ closure (Set.range f) ↔ ∃ a : ι → ℤ, x = ∏ i, f i ^ a i := by rw [Finsupp.equivFunOnFinite.symm.exists_congr_left, mem_closure_range_iff] simp end Subgroup
Bundled.lean
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.ModelTheory.ElementarySubstructures import Mathlib.CategoryTheory.ConcreteCategory.Bundled /-! # Bundled First-Order Structures This file bundles types together with their first-order structure. ## Main Definitions - `FirstOrder.Language.Theory.ModelType` is the type of nonempty models of a particular theory. - `FirstOrder.Language.equivSetoid` is the isomorphism equivalence relation on bundled structures. ## TODO - Define category structures on bundled structures and models. -/ universe u v w w' x variable {L : FirstOrder.Language.{u, v}} protected instance CategoryTheory.Bundled.structure {L : FirstOrder.Language.{u, v}} (M : CategoryTheory.Bundled.{w} L.Structure) : L.Structure M := M.str open FirstOrder Cardinal namespace Equiv variable (L) {M : Type w} variable [L.Structure M] {N : Type w'} (g : M ≃ N) /-- A type bundled with the structure induced by an equivalence. -/ @[simps] def bundledInduced : CategoryTheory.Bundled.{w'} L.Structure := ⟨N, g.inducedStructure⟩ /-- An equivalence of types as a first-order equivalence to the bundled structure on the codomain. -/ @[simp] def bundledInducedEquiv : M ≃[L] g.bundledInduced L := g.inducedStructureEquiv end Equiv namespace FirstOrder namespace Language /-- The equivalence relation on bundled `L.Structure`s indicating that they are isomorphic. -/ instance equivSetoid : Setoid (CategoryTheory.Bundled L.Structure) where r M N := Nonempty (M ≃[L] N) iseqv := ⟨fun M => ⟨Equiv.refl L M⟩, fun {_ _} => Nonempty.map Equiv.symm, fun {_ _} _ => Nonempty.map2 fun MN NP => NP.comp MN⟩ variable (T : L.Theory) namespace Theory /-- The type of nonempty models of a first-order theory. -/ structure ModelType where /-- The underlying type for the models -/ Carrier : Type w [struc : L.Structure Carrier] [is_model : T.Model Carrier] [nonempty' : Nonempty Carrier] -- Porting note: In Lean4, other instances precedes `FirstOrder.Language.Theory.ModelType.struc`, -- it's issues in `ModelTheory.Satisfiability`. So, we increase these priorities. attribute [instance 2000] ModelType.struc ModelType.is_model ModelType.nonempty' namespace ModelType attribute [coe] ModelType.Carrier instance instCoeSort : CoeSort T.ModelType (Type w) := ⟨ModelType.Carrier⟩ /-- The object in the category of R-algebras associated to a type equipped with the appropriate typeclasses. -/ def of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : T.ModelType := ⟨M⟩ @[simp] theorem coe_of (M : Type w) [L.Structure M] [M ⊨ T] [Nonempty M] : (of T M : Type w) = M := rfl instance instNonempty (M : T.ModelType) : Nonempty M := inferInstance section Inhabited attribute [local instance] Inhabited.trivialStructure instance instInhabited : Inhabited (ModelType.{u, v, w} (∅ : L.Theory)) := ⟨ModelType.of _ PUnit⟩ end Inhabited variable {T} /-- Maps a bundled model along a bijection. -/ def equivInduced {M : ModelType.{u, v, w} T} {N : Type w'} (e : M ≃ N) : ModelType.{u, v, w'} T where Carrier := N struc := e.inducedStructure is_model := @StrongHomClass.theory_model L M N _ e.inducedStructure T _ _ _ e.inducedStructureEquiv _ nonempty' := e.symm.nonempty instance of_small (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] [h : Small.{w'} M] : Small.{w'} (ModelType.of T M) := h /-- Shrinks a small model to a particular universe. -/ noncomputable def shrink (M : ModelType.{u, v, w} T) [Small.{w'} M] : ModelType.{u, v, w'} T := equivInduced (equivShrink M) /-- Lifts a model to a particular universe. -/ def ulift (M : ModelType.{u, v, w} T) : ModelType.{u, v, max w w'} T := equivInduced (Equiv.ulift.{w', w}.symm : M ≃ _) /-- The reduct of any model of `φ.onTheory T` is a model of `T`. -/ @[simps] def reduct {L' : Language} (φ : L →ᴸ L') (M : (φ.onTheory T).ModelType) : T.ModelType where Carrier := M struc := φ.reduct M nonempty' := M.nonempty' is_model := (@LHom.onTheory_model L L' M (φ.reduct M) _ φ _ T).1 M.is_model /-- When `φ` is injective, `defaultExpansion` expands a model of `T` to a model of `φ.onTheory T` arbitrarily. -/ @[simps] noncomputable def defaultExpansion {L' : Language} {φ : L →ᴸ L'} (h : φ.Injective) [∀ (n) (f : L'.Functions n), Decidable (f ∈ Set.range fun f : L.Functions n => φ.onFunction f)] [∀ (n) (r : L'.Relations n), Decidable (r ∈ Set.range fun r : L.Relations n => φ.onRelation r)] (M : T.ModelType) [Inhabited M] : (φ.onTheory T).ModelType where Carrier := M struc := φ.defaultExpansion M nonempty' := M.nonempty' is_model := (@LHom.onTheory_model L L' M _ (φ.defaultExpansion M) φ (h.isExpansionOn_default M) T).2 M.is_model instance leftStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) : L.Structure M := (LHom.sumInl : L →ᴸ L.sum L').reduct M instance rightStructure {L' : Language} {T : (L.sum L').Theory} (M : T.ModelType) : L'.Structure M := (LHom.sumInr : L' →ᴸ L.sum L').reduct M /-- A model of a theory is also a model of any subtheory. -/ @[simps] def subtheoryModel (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) : T'.ModelType where Carrier := M is_model := ⟨fun _φ hφ => realize_sentence_of_mem T (h hφ)⟩ instance subtheoryModel_models (M : T.ModelType) {T' : L.Theory} (h : T' ⊆ T) : M.subtheoryModel h ⊨ T := M.is_model end ModelType variable {T} /-- Bundles `M ⊨ T` as a `T.ModelType`. -/ def Model.bundled {M : Type w} [LM : L.Structure M] [ne : Nonempty M] (h : M ⊨ T) : T.ModelType := @ModelType.of L T M LM h ne @[simp] theorem coe_of {M : Type w} [L.Structure M] [Nonempty M] (h : M ⊨ T) : (h.bundled : Type w) = M := rfl end Theory /-- A structure that is elementarily equivalent to a model, bundled as a model. -/ def ElementarilyEquivalent.toModel {M : T.ModelType} {N : Type*} [LN : L.Structure N] (h : M ≅[L] N) : T.ModelType where Carrier := N struc := LN nonempty' := h.nonempty is_model := h.theory_model /-- An elementary substructure of a bundled model as a bundled model. -/ def ElementarySubstructure.toModel {M : T.ModelType} (S : L.ElementarySubstructure M) : T.ModelType := S.elementarilyEquivalent.symm.toModel T instance ElementarySubstructure.toModel.instSmall {M : T.ModelType} (S : L.ElementarySubstructure M) [h : Small.{w, x} S] : Small.{w, x} (S.toModel T) := h end Language end FirstOrder
Log.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.Algebra.Order.Floor.Semiring import Mathlib.Data.Nat.Log /-! # Integer logarithms in a field with respect to a natural base This file defines two `ℤ`-valued analogs of the logarithm of `r : R` with base `b : ℕ`: * `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `↑b^k ≤ r`. * `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r ≤ ↑b^k`. Note that `Int.log` gives the position of the left-most non-zero digit: ```lean #eval (Int.log 10 (0.09 : ℚ), Int.log 10 (0.10 : ℚ), Int.log 10 (0.11 : ℚ)) -- (-2, -1, -1) #eval (Int.log 10 (9 : ℚ), Int.log 10 (10 : ℚ), Int.log 10 (11 : ℚ)) -- (0, 1, 1) ``` which means it can be used for computing digit expansions ```lean import Data.Fin.VecNotation import Mathlib.Data.Rat.Floor def digits (b : ℕ) (q : ℚ) (n : ℕ) : ℕ := ⌊q * ((b : ℚ) ^ (n - Int.log b q))⌋₊ % b #eval digits 10 (1/7) ∘ ((↑) : Fin 8 → ℕ) -- ![1, 4, 2, 8, 5, 7, 1, 4] ``` ## Main results * For `Int.log`: * `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`, `(b : R) ^ log b r ≤ r < (b : R) ^ (log b r + 1)`. * `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`. * For `Int.clog`: * `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`, `(b : R) ^ (clog b r - 1) < r ≤ (b : R) ^ clog b r`. * `Int.clog_zpow_gi`: the galois insertion between `Int.clog` and `zpow`. * `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions. -/ assert_not_exists Finset variable {R : Type*} [Semifield R] [LinearOrder R] [IsStrictOrderedRing R] [FloorSemiring R] namespace Int /-- The greatest power of `b` such that `b ^ log b r ≤ r`. -/ def log (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.log b ⌊r⌋₊ else -Nat.clog b ⌈r⁻¹⌉₊ omit [IsStrictOrderedRing R] in theorem log_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : log b r = Nat.log b ⌊r⌋₊ := if_pos hr theorem log_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : log b r = -Nat.clog b ⌈r⁻¹⌉₊ := by obtain rfl | hr := hr.eq_or_lt · rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_ge @[simp, norm_cast] theorem log_natCast (b : ℕ) (n : ℕ) : log b (n : R) = Nat.log b n := by cases n · simp [log_of_right_le_one] · rw [log_of_one_le_right, Nat.floor_natCast] simp @[simp] theorem log_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] : log b (ofNat(n) : R) = Nat.log b ofNat(n) := log_natCast b n theorem log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (r : R) : log b r = 0 := by rcases le_total 1 r with h | h · rw [log_of_one_le_right _ h, Nat.log_of_left_le_one hb, Int.ofNat_zero] · rw [log_of_right_le_one _ h, Nat.clog_of_left_le_one hb, Int.ofNat_zero, neg_zero] theorem log_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : log b r = 0 := by rw [log_of_right_le_one _ (hr.trans zero_le_one), Nat.clog_of_right_le_one ((Nat.ceil_eq_zero.mpr <| inv_nonpos.2 hr).trans_le zero_le_one), Int.ofNat_zero, neg_zero] theorem zpow_log_le_self {b : ℕ} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ log b r ≤ r := by rcases le_total 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [zpow_natCast, ← Nat.cast_pow, ← Nat.le_floor_iff hr.le] exact Nat.pow_log_le_self b (Nat.floor_pos.mpr hr1).ne' · rw [log_of_right_le_one _ hr1, zpow_neg, zpow_natCast, ← Nat.cast_pow] exact inv_le_of_inv_le₀ hr (Nat.ceil_le.1 <| Nat.le_pow_clog hb _) theorem lt_zpow_succ_log_self {b : ℕ} (hb : 1 < b) (r : R) : r < (b : R) ^ (log b r + 1) := by rcases le_or_gt r 0 with hr | hr · rw [log_of_right_le_zero _ hr, zero_add, zpow_one] exact hr.trans_lt (zero_lt_one.trans_le <| mod_cast hb.le) rcases le_or_gt 1 r with hr1 | hr1 · rw [log_of_one_le_right _ hr1] rw [Int.ofNat_add_one_out, zpow_natCast, ← Nat.cast_pow] apply Nat.lt_of_floor_lt exact Nat.lt_pow_succ_log_self hb _ · rw [log_of_right_le_one _ hr1.le] have hcri : 1 < r⁻¹ := (one_lt_inv₀ hr).2 hr1 have : 1 ≤ Nat.clog b ⌈r⁻¹⌉₊ := Nat.succ_le_of_lt (Nat.clog_pos hb <| Nat.one_lt_cast.1 <| hcri.trans_le (Nat.le_ceil _)) rw [neg_add_eq_sub, ← neg_sub, ← Int.ofNat_one, ← Int.ofNat_sub this, zpow_neg, zpow_natCast, lt_inv_comm₀ hr (pow_pos (Nat.cast_pos.mpr <| zero_lt_one.trans hb) _), ← Nat.cast_pow] refine Nat.lt_ceil.1 ?_ exact Nat.pow_pred_clog_lt_self hb <| Nat.one_lt_cast.1 <| hcri.trans_le <| Nat.le_ceil _ @[simp] theorem log_zero_right (b : ℕ) : log b (0 : R) = 0 := log_of_right_le_zero b le_rfl @[simp] theorem log_one_right (b : ℕ) : log b (1 : R) = 0 := by rw [log_of_one_le_right _ le_rfl, Nat.floor_one, Nat.log_one_right, Int.ofNat_zero] omit [IsStrictOrderedRing R] in @[simp] theorem log_zero_left (r : R) : log 0 r = 0 := by simp only [log, Nat.log_zero_left, Nat.cast_zero, Nat.clog_zero_left, neg_zero, ite_self] omit [IsStrictOrderedRing R] in @[simp] theorem log_one_left (r : R) : log 1 r = 0 := by by_cases hr : 1 ≤ r · simp_all only [log, ↓reduceIte, Nat.log_one_left, Nat.cast_zero] · simp only [log, Nat.log_one_left, Nat.cast_zero, Nat.clog_one_left, neg_zero, ite_self] theorem log_zpow {b : ℕ} (hb : 1 < b) (z : ℤ) : log b (b ^ z : R) = z := by obtain ⟨n, rfl | rfl⟩ := Int.eq_nat_or_neg z · rw [log_of_one_le_right _ (one_le_zpow₀ (mod_cast hb.le) <| Int.natCast_nonneg _), zpow_natCast, ← Nat.cast_pow, Nat.floor_natCast, Nat.log_pow hb] · rw [log_of_right_le_one _ (zpow_le_one_of_nonpos₀ (mod_cast hb.le) <| neg_nonpos.2 (Int.natCast_nonneg _)), zpow_neg, inv_inv, zpow_natCast, ← Nat.cast_pow, Nat.ceil_natCast, Nat.clog_pow _ _ hb] @[mono, gcongr] theorem log_mono_right {b : ℕ} {r₁ r₂ : R} (h₀ : 0 < r₁) (h : r₁ ≤ r₂) : log b r₁ ≤ log b r₂ := by rcases le_total r₁ 1 with h₁ | h₁ <;> rcases le_total r₂ 1 with h₂ | h₂ · rw [log_of_right_le_one _ h₁, log_of_right_le_one _ h₂] gcongr · rw [log_of_right_le_one _ h₁, log_of_one_le_right _ h₂] exact (neg_nonpos.mpr (Int.natCast_nonneg _)).trans (Int.natCast_nonneg _) · obtain rfl := le_antisymm h (h₂.trans h₁) rfl · rw [log_of_one_le_right _ h₁, log_of_one_le_right _ h₂] gcongr variable (R) in /-- Over suitable subtypes, `zpow` and `Int.log` form a galois coinsertion -/ def zpowLogGi {b : ℕ} (hb : 1 < b) : GaloisCoinsertion (fun z : ℤ => Subtype.mk ((b : R) ^ z) <| zpow_pos (mod_cast zero_lt_one.trans hb) z) fun r : Set.Ioi (0 : R) => Int.log b (r : R) := GaloisCoinsertion.monotoneIntro (fun r₁ _ => log_mono_right r₁.2) (fun _ _ hz => Subtype.coe_le_coe.mp <| (zpow_right_strictMono₀ <| mod_cast hb).monotone hz) (fun r => Subtype.coe_le_coe.mp <| zpow_log_le_self hb r.2) fun _ => log_zpow (R := R) hb _ /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem lt_zpow_iff_log_lt {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : r < (b : R) ^ x ↔ log b r < x := @GaloisConnection.lt_iff_lt _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem zpow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : (b : R) ^ x ≤ r ↔ x ≤ log b r := @GaloisConnection.le_iff_le _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ /-- The least power of `b` such that `r ≤ b ^ log b r`. -/ def clog (b : ℕ) (r : R) : ℤ := if 1 ≤ r then Nat.clog b ⌈r⌉₊ else -Nat.log b ⌊r⁻¹⌋₊ omit [IsStrictOrderedRing R] in theorem clog_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : clog b r = Nat.clog b ⌈r⌉₊ := if_pos hr theorem clog_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : clog b r = -Nat.log b ⌊r⁻¹⌋₊ := by obtain rfl | hr := hr.eq_or_lt · rw [clog, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] · exact if_neg hr.not_ge theorem clog_of_right_le_zero (b : ℕ) {r : R} (hr : r ≤ 0) : clog b r = 0 := by rw [clog, if_neg (hr.trans_lt zero_lt_one).not_ge, neg_eq_zero, Int.natCast_eq_zero, Nat.log_eq_zero_iff] rcases le_or_gt b 1 with hb | hb · exact Or.inr hb · refine Or.inl (lt_of_le_of_lt ?_ hb) exact Nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) @[simp] theorem clog_inv (b : ℕ) (r : R) : clog b r⁻¹ = -log b r := by rcases lt_or_ge 0 r with hrp | hrp · obtain hr | hr := le_total 1 r · rw [clog_of_right_le_one _ (inv_le_one_of_one_le₀ hr), log_of_one_le_right _ hr, inv_inv] · rw [clog_of_one_le_right _ ((one_le_inv₀ hrp).2 hr), log_of_right_le_one _ hr, neg_neg] · rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero] @[simp] theorem log_inv (b : ℕ) (r : R) : log b r⁻¹ = -clog b r := by rw [← inv_inv r, clog_inv, neg_neg, inv_inv] -- note this is useful for writing in reverse theorem neg_log_inv_eq_clog (b : ℕ) (r : R) : -log b r⁻¹ = clog b r := by rw [log_inv, neg_neg] theorem neg_clog_inv_eq_log (b : ℕ) (r : R) : -clog b r⁻¹ = log b r := by rw [clog_inv, neg_neg] @[simp, norm_cast] theorem clog_natCast (b : ℕ) (n : ℕ) : clog b (n : R) = Nat.clog b n := by rcases n with - | n · simp [clog_of_right_le_one] · rw [clog_of_one_le_right, (Nat.ceil_eq_iff (Nat.succ_ne_zero n)).mpr] <;> simp @[simp] theorem clog_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] : clog b (ofNat(n) : R) = Nat.clog b ofNat(n) := clog_natCast b n theorem clog_of_left_le_one {b : ℕ} (hb : b ≤ 1) (r : R) : clog b r = 0 := by rw [← neg_log_inv_eq_clog, log_of_left_le_one hb, neg_zero] theorem self_le_zpow_clog {b : ℕ} (hb : 1 < b) (r : R) : r ≤ (b : R) ^ clog b r := by rcases le_or_gt r 0 with hr | hr · rw [clog_of_right_le_zero _ hr, zpow_zero] exact hr.trans zero_le_one rw [← neg_log_inv_eq_clog, zpow_neg, le_inv_comm₀ hr (zpow_pos ..)] · exact zpow_log_le_self hb (inv_pos.mpr hr) · exact Nat.cast_pos.mpr (zero_le_one.trans_lt hb) theorem zpow_pred_clog_lt_self {b : ℕ} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ (clog b r - 1) < r := by rw [← neg_log_inv_eq_clog, ← neg_add', zpow_neg, inv_lt_comm₀ _ hr] · exact lt_zpow_succ_log_self hb _ · exact zpow_pos (Nat.cast_pos.mpr <| zero_le_one.trans_lt hb) _ @[simp] theorem clog_zero_right (b : ℕ) : clog b (0 : R) = 0 := clog_of_right_le_zero _ le_rfl @[simp] theorem clog_one_right (b : ℕ) : clog b (1 : R) = 0 := by rw [clog_of_one_le_right _ le_rfl, Nat.ceil_one, Nat.clog_one_right, Int.ofNat_zero] omit [IsStrictOrderedRing R] in @[simp] theorem clog_zero_left (r : R) : clog 0 r = 0 := by by_cases hr : 1 ≤ r · simp only [clog, Nat.clog_zero_left, Nat.cast_zero, Nat.log_zero_left, neg_zero, ite_self] · simp only [clog, hr, ite_cond_eq_false, Nat.log_zero_left, Nat.cast_zero, neg_zero] omit [IsStrictOrderedRing R] in @[simp] theorem clog_one_left (r : R) : clog 1 r = 0 := by simp only [clog, Nat.log_one_left, Nat.cast_zero, Nat.clog_one_left, neg_zero, ite_self] theorem clog_zpow {b : ℕ} (hb : 1 < b) (z : ℤ) : clog b (b ^ z : R) = z := by rw [← neg_log_inv_eq_clog, ← zpow_neg, log_zpow hb, neg_neg] @[mono] theorem clog_mono_right {b : ℕ} {r₁ r₂ : R} (h₀ : 0 < r₁) (h : r₁ ≤ r₂) : clog b r₁ ≤ clog b r₂ := by rw [← neg_log_inv_eq_clog, ← neg_log_inv_eq_clog, neg_le_neg_iff] gcongr exact inv_pos.2 (h₀.trans_le h) variable (R) in /-- Over suitable subtypes, `Int.clog` and `zpow` form a galois insertion -/ def clogZPowGi {b : ℕ} (hb : 1 < b) : GaloisInsertion (fun r : Set.Ioi (0 : R) => Int.clog b (r : R)) fun z : ℤ => ⟨(b : R) ^ z, zpow_pos (mod_cast zero_lt_one.trans hb) z⟩ := GaloisInsertion.monotoneIntro (fun _ _ hz => Subtype.coe_le_coe.mp <| (zpow_right_strictMono₀ <| mod_cast hb).monotone hz) (fun r₁ _ => clog_mono_right r₁.2) (fun _ => Subtype.coe_le_coe.mp <| self_le_zpow_clog hb _) fun _ => clog_zpow (R := R) hb _ /-- `Int.clog b` and `zpow b` (almost) form a Galois connection. -/ theorem zpow_lt_iff_lt_clog {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : (b : R) ^ x < r ↔ x < clog b r := (@GaloisConnection.lt_iff_lt _ _ _ _ _ _ (clogZPowGi R hb).gc ⟨r, hr⟩ x).symm /-- `Int.clog b` and `zpow b` (almost) form a Galois connection. -/ theorem le_zpow_iff_clog_le {b : ℕ} (hb : 1 < b) {x : ℤ} {r : R} (hr : 0 < r) : r ≤ (b : R) ^ x ↔ clog b r ≤ x := (@GaloisConnection.le_iff_le _ _ _ _ _ _ (clogZPowGi R hb).gc ⟨r, hr⟩ x).symm end Int
test_ssrAC.v
From mathcomp Require Import all_boot ssralg. Section Tests. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite orbACA. Abort. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite (AC (2*2) ((1*3)*(2*4))). Abort. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite orb.[AC (2*2) ((1*3)*(2*4))]. Qed. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite -addnA addnAC addnA addnAC. Abort. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite (ACl (1*3*2*4)). Abort. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite addn.[ACl 1*3*2*4]. Qed. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite -GRing.addrA GRing.addrAC GRing.addrA GRing.addrAC. Abort. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite (ACl (1*3*2*4)). Abort. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite (@GRing.add R).[ACl 1*3*2*4]. Qed. Local Open Scope ring_scope. Import GRing.Theory. Lemma test_mulr (R : comRingType) (x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 : R) (x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 : R) : (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) = (x0 * x2 * x4 * x9) * (x1 * x3 * x5 * x7) * x6 * x8 * (x10 * x12 * x14 * x19) * (x11 * x13 * x15 * x17) * x16 * x18 * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9)* (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) . Proof. pose s := ((2 * 4 * 9 * 1 * 3 * 5 * 7 * 6 * 8 * 20 * 21 * 22 * 23) * 25 * 26 * 27 * 28 * (29 * 30 * 31) * 32 * 33 * 34 * 35 * 36 * 37 * 38 * 39 * 40 * 41 * (10 * 12 * 14 * 19 * 11 * 13 * 15 * 17 * 16 * 18 * 24) * (42 * 43 * 44 * 45 * 46 * 47 * 48 * 49) * 50 * 52 * 53 * 54 * 55 * 56 * 57 * 58 * 59 * 51* 60 * 62 * 63 * 64 * 65 * 66 * 67 * 68 * 69 * 61* 70 * 72 * 73 * 74 * 75 * 76 * 77 * 78 * 79 * 71 * 80 * 82 * 83 * 84 * 85 * 86 * 87 * 88 * 89 * 81* 90 * 92 * 93 * 94 * 95 * 96 * 97 * 98 * 99 * 91 * 100 * ((102 * 104 * 109 * 101 * 103 * 105 * 107 * 106 * 108 * 120 * 121 * 122 * 123) * 125 * 126 * 127 * 128 * (129 * 130 * 131) * 132 * 133 * 134 * 135 * 136 * 137 * 138 * 139 * 140 * 141 * (110 * 112 * 114 * 119 * 111 * 113 * 115 * 117 * 116 * 118 * 124) * (142 * 143 * 144 * 145 * 146 * 147 * 148 * 149) * 150 * 152 * 153 * 154 * 155 * 156 * 157 * 158 * 159 * 151* 160 * 162 * 163 * 164 * 165 * 166 * 167 * 168 * 169 * 161* 170 * 172 * 173 * 174 * 175 * 176 * 177 * 178 * 179 * 171 * 180 * 182 * 183 * 184 * 185 * 186 * 187 * 188 * 189 * 181* 190 * 192 * 193 * 194 * 195 * 196 * 197 * 198 * 199 * 191) )%AC. time have := (@GRing.mul R).[ACl s]. time rewrite (@GRing.mul R).[ACl s]. Abort. End Tests.
import_all.lean
import Lean import Std import Qq import Batteries import Aesop import ProofWidgets import Mathlib import Plausible /-! Verify that Mathlib and all its upstream dependencies can be simultaneously imported. We don't `import Cli` or `import ImportGraph` here as these are only used by scripts, and may not have been built during CI when we run the tests. -/
Subgroup.lean
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Data.Fintype.Perm /-! # Lemmas about subgroups within the permutations (self-equivalences) of a type `α` This file provides extra lemmas about some `Subgroup`s that exist within `Equiv.Perm α`. `GroupTheory.Subgroup` depends on `GroupTheory.Perm.Basic`, so these need to be in a separate file. It also provides decidable instances on membership in these subgroups, since `MonoidHom.decidableMemRange` cannot be inferred without the help of a lambda. The presence of these instances induces a `Fintype` instance on the `QuotientGroup.Quotient` of these subgroups. -/ assert_not_exists Field namespace Equiv namespace Perm universe u instance sumCongrHom.decidableMemRange {α β : Type*} [DecidableEq α] [DecidableEq β] [Fintype α] [Fintype β] : DecidablePred (· ∈ (sumCongrHom α β).range) := fun _ => inferInstance @[simp] theorem sumCongrHom.card_range {α β : Type*} [Fintype (sumCongrHom α β).range] [Fintype (Perm α × Perm β)] : Fintype.card (sumCongrHom α β).range = Fintype.card (Perm α × Perm β) := Fintype.card_eq.mpr ⟨(ofInjective (sumCongrHom α β) sumCongrHom_injective).symm⟩ instance sigmaCongrRightHom.decidableMemRange {α : Type*} {β : α → Type*} [DecidableEq α] [∀ a, DecidableEq (β a)] [Fintype α] [∀ a, Fintype (β a)] : DecidablePred (· ∈ (sigmaCongrRightHom β).range) := fun _ => inferInstance @[simp] theorem sigmaCongrRightHom.card_range {α : Type*} {β : α → Type*} [Fintype (sigmaCongrRightHom β).range] [Fintype (∀ a, Perm (β a))] : Fintype.card (sigmaCongrRightHom β).range = Fintype.card (∀ a, Perm (β a)) := Fintype.card_eq.mpr ⟨(ofInjective (sigmaCongrRightHom β) sigmaCongrRightHom_injective).symm⟩ instance subtypeCongrHom.decidableMemRange {α : Type*} (p : α → Prop) [DecidablePred p] [Fintype (Perm { a // p a } × Perm { a // ¬p a })] [DecidableEq (Perm α)] : DecidablePred (· ∈ (subtypeCongrHom p).range) := fun _ => inferInstance @[simp] theorem subtypeCongrHom.card_range {α : Type*} (p : α → Prop) [DecidablePred p] [Fintype (subtypeCongrHom p).range] [Fintype (Perm { a // p a } × Perm { a // ¬p a })] : Fintype.card (subtypeCongrHom p).range = Fintype.card (Perm { a // p a } × Perm { a // ¬p a }) := Fintype.card_eq.mpr ⟨(ofInjective (subtypeCongrHom p) (subtypeCongrHom_injective p)).symm⟩ /-- **Cayley's theorem**: Every group G is isomorphic to a subgroup of the symmetric group acting on `G`. Note that we generalize this to an arbitrary "faithful" group action by `G`. Setting `H = G` recovers the usual statement of Cayley's theorem via `RightCancelMonoid.faithfulSMul` -/ noncomputable def subgroupOfMulAction (G H : Type*) [Group G] [MulAction G H] [FaithfulSMul G H] : G ≃* (MulAction.toPermHom G H).range := MulEquiv.ofLeftInverse' _ (Classical.choose_spec MulAction.toPerm_injective.hasLeftInverse) end Perm end Equiv
AdjointFunctorTheorems.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.Comma.StructuredArrow.Small import Mathlib.CategoryTheory.Generator.Basic import Mathlib.CategoryTheory.Limits.ConeCategory import Mathlib.CategoryTheory.Limits.Constructions.WeaklyInitial import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic import Mathlib.CategoryTheory.Subobject.Comma /-! # Adjoint functor theorem This file proves the (general) adjoint functor theorem, in the form: * If `G : D ⥤ C` preserves limits and `D` has limits, and satisfies the solution set condition, then it has a left adjoint: `isRightAdjointOfPreservesLimitsOfIsCoseparating`. We show that the converse holds, i.e. that if `G` has a left adjoint then it satisfies the solution set condition, see `solutionSetCondition_of_isRightAdjoint` (the file `CategoryTheory/Adjunction/Limits` already shows it preserves limits). We define the *solution set condition* for the functor `G : D ⥤ C` to mean, for every object `A : C`, there is a set-indexed family ${f_i : A ⟶ G (B_i)}$ such that any morphism `A ⟶ G X` factors through one of the `f_i`. This file also proves the special adjoint functor theorem, in the form: * If `G : D ⥤ C` preserves limits and `D` is complete, well-powered and has a small coseparating set, then `G` has a left adjoint: `isRightAdjointOfPreservesLimitsOfIsCoseparating` Finally, we prove the following corollaries of the special adjoint functor theorem: * If `C` is complete, well-powered and has a small coseparating set, then it is cocomplete: `hasColimits_of_hasLimits_of_isCoseparating`, `hasColimits_of_hasLimits_of_hasCoseparator` * If `C` is cocomplete, co-well-powered and has a small separating set, then it is complete: `hasLimits_of_hasColimits_of_isSeparating`, `hasLimits_of_hasColimits_of_hasSeparator` -/ universe v u u' namespace CategoryTheory open Limits variable {J : Type v} variable {C : Type u} [Category.{v} C] /-- The functor `G : D ⥤ C` satisfies the *solution set condition* if for every `A : C`, there is a family of morphisms `{f_i : A ⟶ G (B_i) // i ∈ ι}` such that given any morphism `h : A ⟶ G X`, there is some `i ∈ ι` such that `h` factors through `f_i`. The key part of this definition is that the indexing set `ι` lives in `Type v`, where `v` is the universe of morphisms of the category: this is the "smallness" condition which allows the general adjoint functor theorem to go through. -/ def SolutionSetCondition {D : Type u} [Category.{v} D] (G : D ⥤ C) : Prop := ∀ A : C, ∃ (ι : Type v) (B : ι → D) (f : ∀ i : ι, A ⟶ G.obj (B i)), ∀ (X) (h : A ⟶ G.obj X), ∃ (i : ι) (g : B i ⟶ X), f i ≫ G.map g = h section GeneralAdjointFunctorTheorem variable {D : Type u} [Category.{v} D] variable (G : D ⥤ C) /-- If `G : D ⥤ C` is a right adjoint it satisfies the solution set condition. -/ theorem solutionSetCondition_of_isRightAdjoint [G.IsRightAdjoint] : SolutionSetCondition G := by intro A refine ⟨PUnit, fun _ => G.leftAdjoint.obj A, fun _ => (Adjunction.ofIsRightAdjoint G).unit.app A, ?_⟩ intro B h refine ⟨PUnit.unit, ((Adjunction.ofIsRightAdjoint G).homEquiv _ _).symm h, ?_⟩ rw [← Adjunction.homEquiv_unit, Equiv.apply_symm_apply] /-- The general adjoint functor theorem says that if `G : D ⥤ C` preserves limits and `D` has them, if `G` satisfies the solution set condition then `G` is a right adjoint. -/ lemma isRightAdjoint_of_preservesLimits_of_solutionSetCondition [HasLimits D] [PreservesLimits G] (hG : SolutionSetCondition G) : G.IsRightAdjoint := by refine @isRightAdjointOfStructuredArrowInitials _ _ _ _ G ?_ intro A specialize hG A choose ι B f g using hG let B' : ι → StructuredArrow A G := fun i => StructuredArrow.mk (f i) have hB' : ∀ A' : StructuredArrow A G, ∃ i, Nonempty (B' i ⟶ A') := by intro A' obtain ⟨i, _, t⟩ := g _ A'.hom exact ⟨i, ⟨StructuredArrow.homMk _ t⟩⟩ obtain ⟨T, hT⟩ := has_weakly_initial_of_weakly_initial_set_and_hasProducts hB' apply hasInitial_of_weakly_initial_and_hasWideEqualizers hT end GeneralAdjointFunctorTheorem section SpecialAdjointFunctorTheorem variable {D : Type u'} [Category.{v} D] /-- The special adjoint functor theorem: if `G : D ⥤ C` preserves limits and `D` is complete, well-powered and has a small coseparating set, then `G` has a left adjoint. -/ lemma isRightAdjoint_of_preservesLimits_of_isCoseparating [HasLimits D] [WellPowered.{v} D] {𝒢 : Set D} [Small.{v} 𝒢] (h𝒢 : IsCoseparating 𝒢) (G : D ⥤ C) [PreservesLimits G] : G.IsRightAdjoint := have : ∀ A, HasInitial (StructuredArrow A G) := fun A => hasInitial_of_isCoseparating (StructuredArrow.isCoseparating_proj_preimage A G h𝒢) isRightAdjointOfStructuredArrowInitials _ /-- The special adjoint functor theorem: if `F : C ⥤ D` preserves colimits and `C` is cocomplete, well-copowered and has a small separating set, then `F` has a right adjoint. -/ lemma isLeftAdjoint_of_preservesColimits_of_isSeparating [HasColimits C] [WellPowered.{v} Cᵒᵖ] {𝒢 : Set C} [Small.{v} 𝒢] (h𝒢 : IsSeparating 𝒢) (F : C ⥤ D) [PreservesColimits F] : F.IsLeftAdjoint := have : ∀ A, HasTerminal (CostructuredArrow F A) := fun A => hasTerminal_of_isSeparating (CostructuredArrow.isSeparating_proj_preimage F A h𝒢) isLeftAdjoint_of_costructuredArrowTerminals _ end SpecialAdjointFunctorTheorem namespace Limits /-- A consequence of the special adjoint functor theorem: if `C` is complete, well-powered and has a small coseparating set, then it is cocomplete. -/ theorem hasColimits_of_hasLimits_of_isCoseparating [HasLimits C] [WellPowered.{v} C] {𝒢 : Set C} [Small.{v} 𝒢] (h𝒢 : IsCoseparating 𝒢) : HasColimits C := { has_colimits_of_shape := fun _ _ => hasColimitsOfShape_iff_isRightAdjoint_const.2 (isRightAdjoint_of_preservesLimits_of_isCoseparating h𝒢 _) } /-- A consequence of the special adjoint functor theorem: if `C` is cocomplete, well-copowered and has a small separating set, then it is complete. -/ theorem hasLimits_of_hasColimits_of_isSeparating [HasColimits C] [WellPowered.{v} Cᵒᵖ] {𝒢 : Set C} [Small.{v} 𝒢] (h𝒢 : IsSeparating 𝒢) : HasLimits C := { has_limits_of_shape := fun _ _ => hasLimitsOfShape_iff_isLeftAdjoint_const.2 (isLeftAdjoint_of_preservesColimits_of_isSeparating h𝒢 _) } /-- A consequence of the special adjoint functor theorem: if `C` is complete, well-powered and has a separator, then it is complete. -/ theorem hasLimits_of_hasColimits_of_hasSeparator [HasColimits C] [HasSeparator C] [WellPowered.{v} Cᵒᵖ] : HasLimits C := hasLimits_of_hasColimits_of_isSeparating <| isSeparator_separator C /-- A consequence of the special adjoint functor theorem: if `C` is complete, well-powered and has a coseparator, then it is cocomplete. -/ theorem hasColimits_of_hasLimits_of_hasCoseparator [HasLimits C] [HasCoseparator C] [WellPowered.{v} C] : HasColimits C := hasColimits_of_hasLimits_of_isCoseparating <| isCoseparator_coseparator C end Limits end CategoryTheory
Finsupp.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, Antoine Chambert-Loir -/ import Mathlib.Algebra.DirectSum.Finsupp import Mathlib.LinearAlgebra.DirectSum.TensorProduct import Mathlib.LinearAlgebra.Finsupp.SumProd /-! # Results on finitely supported functions. * `TensorProduct.finsuppLeft`, the tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarLeft`, the tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppRight`, the tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` * `TensorProduct.finsuppScalarRight`, the tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ N` * `TensorProduct.finsuppLeft'`, if `M` is an `S`-module, then the tensor product of `ι →₀ M` and `N` is `S`-linearly equivalent to `ι →₀ M ⊗[R] N` * `finsuppTensorFinsupp`, the tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. ## Case of MvPolynomial These functions apply to `MvPolynomial`, one can define ``` noncomputable def MvPolynomial.rTensor' : MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) := TensorProduct.finsuppLeft' noncomputable def MvPolynomial.rTensor : MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N := TensorProduct.finsuppScalarLeft ``` However, to be actually usable, these definitions need lemmas to be given in companion PR. ## Case of `Polynomial` `Polynomial` is a structure containing a `Finsupp`, so these functions can't be applied directly to `Polynomial`. Some linear equivs need to be added to mathlib for that. This belongs to a companion PR. ## TODO * generalize to `MonoidAlgebra`, `AlgHom ` * reprove `TensorProduct.finsuppLeft'` using existing heterobasic version of `TensorProduct.congr` -/ noncomputable section open DirectSum TensorProduct open Set LinearMap Submodule section TensorProduct variable (R : Type*) [CommSemiring R] (M : Type*) [AddCommMonoid M] [Module R M] (N : Type*) [AddCommMonoid N] [Module R N] namespace TensorProduct variable (ι : Type*) [DecidableEq ι] /-- The tensor product of `ι →₀ M` and `N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/ noncomputable def finsuppLeft : (ι →₀ M) ⊗[R] N ≃ₗ[R] ι →₀ M ⊗[R] N := congr (finsuppLEquivDirectSum R M ι) (.refl R N) ≪≫ₗ directSumLeft R (fun _ ↦ M) N ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm variable {R M N ι} lemma finsuppLeft_apply_tmul (p : ι →₀ M) (n : N) : finsuppLeft R M N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n) := by induction p using Finsupp.induction_linear with | zero => simp | add f g hf hg => simp [add_tmul, map_add, hf, hg, Finsupp.sum_add_index] | single => simp [finsuppLeft] @[simp] lemma finsuppLeft_apply_tmul_apply (p : ι →₀ M) (n : N) (i : ι) : finsuppLeft R M N ι (p ⊗ₜ[R] n) i = p i ⊗ₜ[R] n := by rw [finsuppLeft_apply_tmul, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same] theorem finsuppLeft_apply (t : (ι →₀ M) ⊗[R] N) (i : ι) : finsuppLeft R M N ι t i = rTensor N (Finsupp.lapply i) t := by induction t with | zero => simp | tmul f n => simp only [finsuppLeft_apply_tmul_apply, rTensor_tmul, Finsupp.lapply_apply] | add x y hx hy => simp [map_add, hx, hy] @[simp] lemma finsuppLeft_symm_apply_single (i : ι) (m : M) (n : N) : (finsuppLeft R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) = Finsupp.single i m ⊗ₜ[R] n := by simp [finsuppLeft] variable (R M N ι) /-- The tensor product of `M` and `ι →₀ N` is linearly equivalent to `ι →₀ M ⊗[R] N` -/ noncomputable def finsuppRight : M ⊗[R] (ι →₀ N) ≃ₗ[R] ι →₀ M ⊗[R] N := congr (.refl R M) (finsuppLEquivDirectSum R N ι) ≪≫ₗ directSumRight R M (fun _ : ι ↦ N) ≪≫ₗ (finsuppLEquivDirectSum R _ ι).symm variable {R M N ι} lemma finsuppRight_apply_tmul (m : M) (p : ι →₀ N) : finsuppRight R M N ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (m ⊗ₜ[R] n) := by induction p using Finsupp.induction_linear with | zero => simp | add f g hf hg => simp [tmul_add, map_add, hf, hg, Finsupp.sum_add_index] | single => simp [finsuppRight] @[simp] lemma finsuppRight_apply_tmul_apply (m : M) (p : ι →₀ N) (i : ι) : finsuppRight R M N ι (m ⊗ₜ[R] p) i = m ⊗ₜ[R] p i := by rw [finsuppRight_apply_tmul, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same] theorem finsuppRight_apply (t : M ⊗[R] (ι →₀ N)) (i : ι) : finsuppRight R M N ι t i = lTensor M (Finsupp.lapply i) t := by induction t with | zero => simp | tmul m f => simp [finsuppRight_apply_tmul_apply] | add x y hx hy => simp [map_add, hx, hy] @[simp] lemma finsuppRight_symm_apply_single (i : ι) (m : M) (n : N) : (finsuppRight R M N ι).symm (Finsupp.single i (m ⊗ₜ[R] n)) = m ⊗ₜ[R] Finsupp.single i n := by simp [finsuppRight] variable {S : Type*} [CommSemiring S] [Algebra R S] [Module S M] [IsScalarTower R S M] lemma finsuppLeft_smul' (s : S) (t : (ι →₀ M) ⊗[R] N) : finsuppLeft R M N ι (s • t) = s • finsuppLeft R M N ι t := by induction t with | zero => simp | add x y hx hy => simp [hx, hy] | tmul p n => ext; simp [smul_tmul', finsuppLeft_apply_tmul_apply] variable (R M N ι S) /-- When `M` is also an `S`-module, then `TensorProduct.finsuppLeft R M N`` is an `S`-linear equiv -/ noncomputable def finsuppLeft' : (ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ M ⊗[R] N where __ := finsuppLeft R M N ι map_smul' := finsuppLeft_smul' variable {R M N ι S} lemma finsuppLeft'_apply (x : (ι →₀ M) ⊗[R] N) : finsuppLeft' R M N ι S x = finsuppLeft R M N ι x := rfl /- -- TODO : reprove using the existing heterobasic lemmas noncomputable example : (ι →₀ M) ⊗[R] N ≃ₗ[S] ι →₀ (M ⊗[R] N) := by have f : (⨁ (i₁ : ι), M) ⊗[R] N ≃ₗ[S] ⨁ (i : ι), M ⊗[R] N := sorry exact (AlgebraTensorModule.congr (finsuppLEquivDirectSum S M ι) (.refl R N)).trans (f.trans (finsuppLEquivDirectSum S (M ⊗[R] N) ι).symm) -/ variable (R M N ι) /-- The tensor product of `ι →₀ R` and `N` is linearly equivalent to `ι →₀ N` -/ noncomputable def finsuppScalarLeft : (ι →₀ R) ⊗[R] N ≃ₗ[R] ι →₀ N := finsuppLeft R R N ι ≪≫ₗ (Finsupp.mapRange.linearEquiv (TensorProduct.lid R N)) variable {R M N ι} @[simp] lemma finsuppScalarLeft_apply_tmul_apply (p : ι →₀ R) (n : N) (i : ι) : finsuppScalarLeft R N ι (p ⊗ₜ[R] n) i = p i • n := by simp [finsuppScalarLeft] lemma finsuppScalarLeft_apply_tmul (p : ι →₀ R) (n : N) : finsuppScalarLeft R N ι (p ⊗ₜ[R] n) = p.sum fun i m ↦ Finsupp.single i (m • n) := by ext i rw [finsuppScalarLeft_apply_tmul_apply, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same] lemma finsuppScalarLeft_apply (pn : (ι →₀ R) ⊗[R] N) (i : ι) : finsuppScalarLeft R N ι pn i = TensorProduct.lid R N ((Finsupp.lapply i).rTensor N pn) := by simp [finsuppScalarLeft, finsuppLeft_apply] @[simp] lemma finsuppScalarLeft_symm_apply_single (i : ι) (n : N) : (finsuppScalarLeft R N ι).symm (Finsupp.single i n) = (Finsupp.single i 1) ⊗ₜ[R] n := by simp [finsuppScalarLeft, finsuppLeft_symm_apply_single] variable (R M N ι) /-- The tensor product of `M` and `ι →₀ R` is linearly equivalent to `ι →₀ M` -/ noncomputable def finsuppScalarRight : M ⊗[R] (ι →₀ R) ≃ₗ[R] ι →₀ M := finsuppRight R M R ι ≪≫ₗ Finsupp.mapRange.linearEquiv (TensorProduct.rid R M) variable {R M N ι} @[simp] lemma finsuppScalarRight_apply_tmul_apply (m : M) (p : ι →₀ R) (i : ι) : finsuppScalarRight R M ι (m ⊗ₜ[R] p) i = p i • m := by simp [finsuppScalarRight] lemma finsuppScalarRight_apply_tmul (m : M) (p : ι →₀ R) : finsuppScalarRight R M ι (m ⊗ₜ[R] p) = p.sum fun i n ↦ Finsupp.single i (n • m) := by ext i rw [finsuppScalarRight_apply_tmul_apply, Finsupp.sum_apply, Finsupp.sum_eq_single i (fun _ _ ↦ Finsupp.single_eq_of_ne) (by simp), Finsupp.single_eq_same] lemma finsuppScalarRight_apply (t : M ⊗[R] (ι →₀ R)) (i : ι) : finsuppScalarRight R M ι t i = TensorProduct.rid R M ((Finsupp.lapply i).lTensor M t) := by simp [finsuppScalarRight, finsuppRight_apply] @[simp] lemma finsuppScalarRight_symm_apply_single (i : ι) (m : M) : (finsuppScalarRight R M ι).symm (Finsupp.single i m) = m ⊗ₜ[R] (Finsupp.single i 1) := by simp [finsuppScalarRight, finsuppRight_symm_apply_single] end TensorProduct end TensorProduct variable (R S M N ι κ : Type*) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [Semiring S] [Algebra R S] theorem Finsupp.linearCombination_one_tmul [DecidableEq ι] {v : ι → M} : (linearCombination S ((1 : S) ⊗ₜ[R] v ·)).restrictScalars R = (linearCombination R v).lTensor S ∘ₗ (finsuppScalarRight R S ι).symm := by ext; simp [smul_tmul'] variable [Module S M] [IsScalarTower R S M] open scoped Classical in /-- The tensor product of `ι →₀ M` and `κ →₀ N` is linearly equivalent to `(ι × κ) →₀ (M ⊗ N)`. -/ def finsuppTensorFinsupp : (ι →₀ M) ⊗[R] (κ →₀ N) ≃ₗ[S] ι × κ →₀ M ⊗[R] N := TensorProduct.AlgebraTensorModule.congr (finsuppLEquivDirectSum S M ι) (finsuppLEquivDirectSum R N κ) ≪≫ₗ ((TensorProduct.directSum R S (fun _ : ι => M) fun _ : κ => N) ≪≫ₗ (finsuppLEquivDirectSum S (M ⊗[R] N) (ι × κ)).symm) @[simp] theorem finsuppTensorFinsupp_single (i : ι) (m : M) (k : κ) (n : N) : finsuppTensorFinsupp R S M N ι κ (Finsupp.single i m ⊗ₜ Finsupp.single k n) = Finsupp.single (i, k) (m ⊗ₜ n) := by simp [finsuppTensorFinsupp] @[simp] theorem finsuppTensorFinsupp_apply (f : ι →₀ M) (g : κ →₀ N) (i : ι) (k : κ) : finsuppTensorFinsupp R S M N ι κ (f ⊗ₜ g) (i, k) = f i ⊗ₜ g k := by induction f using Finsupp.induction_linear with | zero => simp | add f₁ f₂ hf₁ hf₂ => simp [add_tmul, hf₁, hf₂] | single i' m => induction g using Finsupp.induction_linear with | zero => simp | add g₁ g₂ hg₁ hg₂ => simp [tmul_add, hg₁, hg₂] | single k' n => classical simp_rw [finsuppTensorFinsupp_single, Finsupp.single_apply, Prod.mk_inj, ite_and] split_ifs <;> simp @[simp] theorem finsuppTensorFinsupp_symm_single (i : ι × κ) (m : M) (n : N) : (finsuppTensorFinsupp R S M N ι κ).symm (Finsupp.single i (m ⊗ₜ n)) = Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 n := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsupp_single _ _ _ _ _ _ _ _ _ _).symm /-- A variant of `finsuppTensorFinsupp` where the first module is the ground ring. -/ def finsuppTensorFinsuppLid : (ι →₀ R) ⊗[R] (κ →₀ N) ≃ₗ[R] ι × κ →₀ N := finsuppTensorFinsupp R R R N ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.lid R N) @[simp] theorem finsuppTensorFinsuppLid_apply_apply (f : ι →₀ R) (g : κ →₀ N) (a : ι) (b : κ) : finsuppTensorFinsuppLid R N ι κ (f ⊗ₜ[R] g) (a, b) = f a • g b := by simp [finsuppTensorFinsuppLid] @[simp] theorem finsuppTensorFinsuppLid_single_tmul_single (a : ι) (b : κ) (r : R) (n : N) : finsuppTensorFinsuppLid R N ι κ (Finsupp.single a r ⊗ₜ[R] Finsupp.single b n) = Finsupp.single (a, b) (r • n) := by simp [finsuppTensorFinsuppLid] @[simp] theorem finsuppTensorFinsuppLid_symm_single_smul (i : ι × κ) (r : R) (n : N) : (finsuppTensorFinsuppLid R N ι κ).symm (Finsupp.single i (r • n)) = Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 n := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppLid_single_tmul_single ..).symm /-- A variant of `finsuppTensorFinsupp` where the second module is the ground ring. -/ def finsuppTensorFinsuppRid : (ι →₀ M) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ M := finsuppTensorFinsupp R R M R ι κ ≪≫ₗ Finsupp.lcongr (Equiv.refl _) (TensorProduct.rid R M) @[simp] theorem finsuppTensorFinsuppRid_apply_apply (f : ι →₀ M) (g : κ →₀ R) (a : ι) (b : κ) : finsuppTensorFinsuppRid R M ι κ (f ⊗ₜ[R] g) (a, b) = g b • f a := by simp [finsuppTensorFinsuppRid] @[simp] theorem finsuppTensorFinsuppRid_single_tmul_single (a : ι) (b : κ) (m : M) (r : R) : finsuppTensorFinsuppRid R M ι κ (Finsupp.single a m ⊗ₜ[R] Finsupp.single b r) = Finsupp.single (a, b) (r • m) := by simp [finsuppTensorFinsuppRid] @[simp] theorem finsuppTensorFinsuppRid_symm_single_smul (i : ι × κ) (m : M) (r : R) : (finsuppTensorFinsuppRid R M ι κ).symm (Finsupp.single i (r • m)) = Finsupp.single i.1 m ⊗ₜ Finsupp.single i.2 r := Prod.casesOn i fun _ _ => (LinearEquiv.symm_apply_eq _).2 (finsuppTensorFinsuppRid_single_tmul_single ..).symm /-- A variant of `finsuppTensorFinsupp` where both modules are the ground ring. -/ def finsuppTensorFinsupp' : (ι →₀ R) ⊗[R] (κ →₀ R) ≃ₗ[R] ι × κ →₀ R := finsuppTensorFinsuppLid R R ι κ @[simp] theorem finsuppTensorFinsupp'_apply_apply (f : ι →₀ R) (g : κ →₀ R) (a : ι) (b : κ) : finsuppTensorFinsupp' R ι κ (f ⊗ₜ[R] g) (a, b) = f a * g b := finsuppTensorFinsuppLid_apply_apply R R ι κ f g a b @[simp] theorem finsuppTensorFinsupp'_single_tmul_single (a : ι) (b : κ) (r₁ r₂ : R) : finsuppTensorFinsupp' R ι κ (Finsupp.single a r₁ ⊗ₜ[R] Finsupp.single b r₂) = Finsupp.single (a, b) (r₁ * r₂) := finsuppTensorFinsuppLid_single_tmul_single R R ι κ a b r₁ r₂ theorem finsuppTensorFinsupp'_symm_single_mul (i : ι × κ) (r₁ r₂ : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i (r₁ * r₂)) = Finsupp.single i.1 r₁ ⊗ₜ Finsupp.single i.2 r₂ := finsuppTensorFinsuppLid_symm_single_smul R R ι κ i r₁ r₂ theorem finsuppTensorFinsupp'_symm_single_eq_single_one_tmul (i : ι × κ) (r : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) = Finsupp.single i.1 1 ⊗ₜ Finsupp.single i.2 r := by nth_rw 1 [← one_mul r] exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _ theorem finsuppTensorFinsupp'_symm_single_eq_tmul_single_one (i : ι × κ) (r : R) : (finsuppTensorFinsupp' R ι κ).symm (Finsupp.single i r) = Finsupp.single i.1 r ⊗ₜ Finsupp.single i.2 1 := by nth_rw 1 [← mul_one r] exact finsuppTensorFinsupp'_symm_single_mul R ι κ i _ _ theorem finsuppTensorFinsuppLid_self : finsuppTensorFinsuppLid R R ι κ = finsuppTensorFinsupp' R ι κ := rfl theorem finsuppTensorFinsuppRid_self : finsuppTensorFinsuppRid R R ι κ = finsuppTensorFinsupp' R ι κ := by rw [finsuppTensorFinsupp', finsuppTensorFinsuppLid, finsuppTensorFinsuppRid, TensorProduct.lid_eq_rid] end
Functor.lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Simon Hudon, Kenny Lau -/ import Mathlib.Data.Multiset.Bind import Mathlib.Control.Traversable.Lemmas import Mathlib.Control.Traversable.Instances /-! # Functoriality of `Multiset`. -/ universe u namespace Multiset open List instance functor : Functor Multiset where map := @map @[simp] theorem fmap_def {α' β'} {s : Multiset α'} (f : α' → β') : f <$> s = s.map f := rfl instance : LawfulFunctor Multiset where id_map := by simp comp_map := by simp map_const {_ _} := rfl open LawfulTraversable CommApplicative variable {F : Type u → Type u} [Applicative F] [CommApplicative F] variable {α' β' : Type u} (f : α' → F β') /-- Map each element of a `Multiset` to an action, evaluate these actions in order, and collect the results. -/ def traverse : Multiset α' → F (Multiset β') := by refine Quotient.lift (Functor.map ofList ∘ Traversable.traverse f) ?_ introv p; unfold Function.comp induction p with | nil => rfl | @cons x l₁ l₂ _ h => have : Multiset.cons <$> f x <*> ofList <$> Traversable.traverse f l₁ = Multiset.cons <$> f x <*> ofList <$> Traversable.traverse f l₂ := by rw [h] simpa [functor_norm] using this | swap x y l => have : (fun a b (l : List β') ↦ (↑(a :: b :: l) : Multiset β')) <$> f y <*> f x = (fun a b l ↦ ↑(a :: b :: l)) <$> f x <*> f y := by rw [CommApplicative.commutative_map] congr 2 funext a b l simpa [flip] using Perm.swap a b l simp [Function.comp_def, this, functor_norm] | trans => simp [*] instance : Monad Multiset := { Multiset.functor with pure := fun x ↦ {x} bind := @bind } @[simp] theorem pure_def {α} : (pure : α → Multiset α) = singleton := rfl @[simp] theorem bind_def {α β} : (· >>= ·) = @bind α β := rfl instance : LawfulMonad Multiset := LawfulMonad.mk' (bind_pure_comp := fun _ _ ↦ by simp only [pure_def, bind_def, bind_singleton, fmap_def]) (id_map := fun _ ↦ by simp only [fmap_def, id_eq, map_id']) (pure_bind := fun _ _ ↦ by simp only [pure_def, bind_def, singleton_bind]) (bind_assoc := @bind_assoc) open Functor open Traversable @[simp] theorem map_comp_coe {α β} (h : α → β) : Functor.map h ∘ ofList = (ofList ∘ Functor.map h : List α → Multiset β) := by funext; simp only [Function.comp_apply, fmap_def, map_coe, List.map_eq_map] theorem id_traverse {α : Type*} (x : Multiset α) : traverse (pure : α → Id α) x = pure x := by refine Quotient.inductionOn x ?_ intro simp [traverse] theorem comp_traverse {G H : Type _ → Type _} [Applicative G] [Applicative H] [CommApplicative G] [CommApplicative H] {α β γ : Type _} (g : α → G β) (h : β → H γ) (x : Multiset α) : traverse (Comp.mk ∘ Functor.map h ∘ g) x = Comp.mk (Functor.map (traverse h) (traverse g x)) := by refine Quotient.inductionOn x ?_ intro simp only [traverse, quot_mk_to_coe, lift_coe, Function.comp_apply, Functor.map_map, functor_norm] theorem map_traverse {G : Type* → Type _} [Applicative G] [CommApplicative G] {α β γ : Type _} (g : α → G β) (h : β → γ) (x : Multiset α) : Functor.map (Functor.map h) (traverse g x) = traverse (Functor.map h ∘ g) x := by refine Quotient.inductionOn x ?_ intro simp only [traverse, quot_mk_to_coe, lift_coe, Function.comp_apply, Functor.map_map] rw [Traversable.map_traverse'] simp only [fmap_def, Function.comp_apply, Functor.map_map, List.map_eq_map, map_coe] theorem traverse_map {G : Type* → Type _} [Applicative G] [CommApplicative G] {α β γ : Type _} (g : α → β) (h : β → G γ) (x : Multiset α) : traverse h (map g x) = traverse (h ∘ g) x := by refine Quotient.inductionOn x ?_ intro simp only [traverse, quot_mk_to_coe, map_coe, lift_coe, Function.comp_apply] rw [← Traversable.traverse_map h g, List.map_eq_map] theorem naturality {G H : Type _ → Type _} [Applicative G] [Applicative H] [CommApplicative G] [CommApplicative H] (eta : ApplicativeTransformation G H) {α β : Type _} (f : α → G β) (x : Multiset α) : eta (traverse f x) = traverse (@eta _ ∘ f) x := by refine Quotient.inductionOn x ?_ intro simp only [quot_mk_to_coe, traverse, lift_coe, Function.comp_apply, ApplicativeTransformation.preserves_map, LawfulTraversable.naturality] end Multiset
ContinuousAffineMap.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.Analysis.Normed.Affine.Isometry import Mathlib.Topology.Algebra.ContinuousAffineMap import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace /-! # Continuous affine maps between normed spaces. This file develops the theory of continuous affine maps between affine spaces modelled on normed spaces. In the particular case that the affine spaces are just normed vector spaces `V`, `W`, we define a norm on the space of continuous affine maps by defining the norm of `f : V →ᴬ[𝕜] W` to be `‖f‖ = max ‖f 0‖ ‖f.cont_linear‖`. This is chosen so that we have a linear isometry: `(V →ᴬ[𝕜] W) ≃ₗᵢ[𝕜] W × (V →L[𝕜] W)`. The abstract picture is that for an affine space `P` modelled on a vector space `V`, together with a vector space `W`, there is an exact sequence of `𝕜`-modules: `0 → C → A → L → 0` where `C`, `A` are the spaces of constant and affine maps `P → W` and `L` is the space of linear maps `V → W`. Any choice of a base point in `P` corresponds to a splitting of this sequence so in particular if we take `P = V`, using `0 : V` as the base point provides a splitting, and we prove this is an isometric decomposition. On the other hand, choosing a base point breaks the affine invariance so the norm fails to be submultiplicative: for a composition of maps, we have only `‖f.comp g‖ ≤ ‖f‖ * ‖g‖ + ‖f 0‖`. ## Main definitions: * `ContinuousAffineMap.contLinear` * `ContinuousAffineMap.hasNorm` * `ContinuousAffineMap.norm_comp_le` * `ContinuousAffineMap.toConstProdContinuousLinearMap` -/ namespace ContinuousAffineMap variable {𝕜 R V W W₂ P Q Q₂ : Type*} variable [NormedAddCommGroup V] [MetricSpace P] [NormedAddTorsor V P] variable [NormedAddCommGroup W] [MetricSpace Q] [NormedAddTorsor W Q] variable [NormedAddCommGroup W₂] [MetricSpace Q₂] [NormedAddTorsor W₂ Q₂] variable [NormedField R] [NormedSpace R V] [NormedSpace R W] [NormedSpace R W₂] variable [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 V] [NormedSpace 𝕜 W] [NormedSpace 𝕜 W₂] /-- The linear map underlying a continuous affine map is continuous. -/ def contLinear (f : P →ᴬ[R] Q) : V →L[R] W := { f.linear with toFun := f.linear cont := by rw [AffineMap.continuous_linear_iff]; exact f.cont } @[simp] theorem coe_contLinear (f : P →ᴬ[R] Q) : (f.contLinear : V → W) = f.linear := rfl @[simp] theorem coe_contLinear_eq_linear (f : P →ᴬ[R] Q) : (f.contLinear : V →ₗ[R] W) = (f : P →ᵃ[R] Q).linear := by ext; rfl @[simp] theorem coe_mk_const_linear_eq_linear (f : P →ᵃ[R] Q) (h) : ((⟨f, h⟩ : P →ᴬ[R] Q).contLinear : V → W) = f.linear := rfl theorem coe_linear_eq_coe_contLinear (f : P →ᴬ[R] Q) : ((f : P →ᵃ[R] Q).linear : V → W) = (⇑f.contLinear : V → W) := rfl @[simp] theorem comp_contLinear (f : P →ᴬ[R] Q) (g : Q →ᴬ[R] Q₂) : (g.comp f).contLinear = g.contLinear.comp f.contLinear := rfl @[simp] theorem map_vadd (f : P →ᴬ[R] Q) (p : P) (v : V) : f (v +ᵥ p) = f.contLinear v +ᵥ f p := f.map_vadd' p v @[simp] theorem contLinear_map_vsub (f : P →ᴬ[R] Q) (p₁ p₂ : P) : f.contLinear (p₁ -ᵥ p₂) = f p₁ -ᵥ f p₂ := f.toAffineMap.linearMap_vsub p₁ p₂ @[simp] theorem const_contLinear (q : Q) : (const R P q).contLinear = 0 := rfl theorem contLinear_eq_zero_iff_exists_const (f : P →ᴬ[R] Q) : f.contLinear = 0 ↔ ∃ q, f = const R P q := by have h₁ : f.contLinear = 0 ↔ (f : P →ᵃ[R] Q).linear = 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ <;> ext · rw [← coe_contLinear_eq_linear, h]; rfl · rw [← coe_linear_eq_coe_contLinear, h]; rfl have h₂ : ∀ q : Q, f = const R P q ↔ (f : P →ᵃ[R] Q) = AffineMap.const R P q := by intro q refine ⟨fun h => ?_, fun h => ?_⟩ <;> ext · rw [h]; rfl · rw [← coe_toAffineMap, h, AffineMap.const_apply, coe_const, Function.const_apply] simp_rw [h₁, h₂] exact (f : P →ᵃ[R] Q).linear_eq_zero_iff_exists_const @[simp] theorem to_affine_map_contLinear (f : V →L[R] W) : f.toContinuousAffineMap.contLinear = f := by ext rfl @[simp] theorem zero_contLinear : (0 : P →ᴬ[R] W).contLinear = 0 := rfl @[simp] theorem add_contLinear (f g : P →ᴬ[R] W) : (f + g).contLinear = f.contLinear + g.contLinear := rfl @[simp] theorem sub_contLinear (f g : P →ᴬ[R] W) : (f - g).contLinear = f.contLinear - g.contLinear := rfl @[simp] theorem neg_contLinear (f : P →ᴬ[R] W) : (-f).contLinear = -f.contLinear := rfl @[simp] theorem smul_contLinear (t : R) (f : P →ᴬ[R] W) : (t • f).contLinear = t • f.contLinear := rfl theorem decomp (f : V →ᴬ[R] W) : (f : V → W) = f.contLinear + Function.const V (f 0) := by rcases f with ⟨f, h⟩ rw [coe_mk_const_linear_eq_linear, coe_mk, f.decomp, Pi.add_apply, LinearMap.map_zero, zero_add, ← Function.const_def] /-- The space of continuous affine maps from `P` to `Q` is an affine space over the space of continuous affine maps from `P` to `W`. -/ instance : AddTorsor (P →ᴬ[R] W) (P →ᴬ[R] Q) where vadd f g := { __ := f.toAffineMap +ᵥ g.toAffineMap, cont := f.cont.vadd g.cont } zero_vadd _ := ext fun _ ↦ zero_vadd _ _ add_vadd _ _ _ := ext fun _ ↦ add_vadd _ _ _ vsub f g := { __ := f.toAffineMap -ᵥ g.toAffineMap, cont := f.cont.vsub g.cont } vsub_vadd' _ _ := ext fun _ ↦ vsub_vadd _ _ vadd_vsub' _ _ := ext fun _ ↦ vadd_vsub _ _ @[simp] lemma vadd_apply (f : P →ᴬ[R] W) (g : P →ᴬ[R] Q) (p : P) : (f +ᵥ g) p = f p +ᵥ g p := rfl @[simp] lemma vsub_apply (f g : P →ᴬ[R] Q) (p : P) : (f -ᵥ g) p = f p -ᵥ g p := rfl @[simp] lemma vadd_toAffineMap (f : P →ᴬ[R] W) (g : P →ᴬ[R] Q) : (f +ᵥ g).toAffineMap = f.toAffineMap +ᵥ g.toAffineMap := rfl @[simp] lemma vsub_toAffineMap (f g : P →ᴬ[R] Q) : (f -ᵥ g).toAffineMap = f.toAffineMap -ᵥ g.toAffineMap := rfl section NormedSpaceStructure variable (f : V →ᴬ[𝕜] W) /-- Note that unlike the operator norm for linear maps, this norm is _not_ submultiplicative: we do _not_ necessarily have `‖f.comp g‖ ≤ ‖f‖ * ‖g‖`. See `norm_comp_le` for what we can say. -/ noncomputable instance hasNorm : Norm (V →ᴬ[𝕜] W) := ⟨fun f => max ‖f 0‖ ‖f.contLinear‖⟩ theorem norm_def : ‖f‖ = max ‖f 0‖ ‖f.contLinear‖ := rfl theorem norm_contLinear_le : ‖f.contLinear‖ ≤ ‖f‖ := le_max_right _ _ theorem norm_image_zero_le : ‖f 0‖ ≤ ‖f‖ := le_max_left _ _ @[simp] theorem norm_eq (h : f 0 = 0) : ‖f‖ = ‖f.contLinear‖ := calc ‖f‖ = max ‖f 0‖ ‖f.contLinear‖ := by rw [norm_def] _ = max 0 ‖f.contLinear‖ := by rw [h, norm_zero] _ = ‖f.contLinear‖ := max_eq_right (norm_nonneg _) noncomputable instance : NormedAddCommGroup (V →ᴬ[𝕜] W) := AddGroupNorm.toNormedAddCommGroup { toFun := fun f => max ‖f 0‖ ‖f.contLinear‖ map_zero' := by simp [(ContinuousAffineMap.zero_apply)] neg' := fun f => by simp [(ContinuousAffineMap.neg_apply)] add_le' := fun f g => by simp only [coe_add, max_le_iff, Pi.add_apply, add_contLinear] exact ⟨(norm_add_le _ _).trans (add_le_add (le_max_left _ _) (le_max_left _ _)), (norm_add_le _ _).trans (add_le_add (le_max_right _ _) (le_max_right _ _))⟩ eq_zero_of_map_eq_zero' := fun f h₀ => by rcases max_eq_iff.mp h₀ with (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩) <;> rw [h₁] at h₂ · rw [norm_le_zero_iff, contLinear_eq_zero_iff_exists_const] at h₂ obtain ⟨q, rfl⟩ := h₂ simp only [norm_eq_zero, coe_const, Function.const_apply] at h₁ rw [h₁] rfl · rw [norm_eq_zero, contLinear_eq_zero_iff_exists_const] at h₁ obtain ⟨q, rfl⟩ := h₁ simp only [norm_le_zero_iff, coe_const, Function.const_apply] at h₂ rw [h₂] rfl } noncomputable instance : NormedSpace 𝕜 (V →ᴬ[𝕜] W) where norm_smul_le t f := by simp only [norm_def, coe_smul, Pi.smul_apply, norm_smul, smul_contLinear, ← mul_max_of_nonneg _ _ (norm_nonneg t), le_refl] theorem norm_comp_le (g : W₂ →ᴬ[𝕜] V) : ‖f.comp g‖ ≤ ‖f‖ * ‖g‖ + ‖f 0‖ := by rw [norm_def, max_le_iff] constructor · calc ‖f.comp g 0‖ = ‖f (g 0)‖ := by simp _ = ‖f.contLinear (g 0) + f 0‖ := by rw [f.decomp]; simp _ ≤ ‖f.contLinear‖ * ‖g 0‖ + ‖f 0‖ := ((norm_add_le _ _).trans (add_le_add_right (f.contLinear.le_opNorm _) _)) _ ≤ ‖f‖ * ‖g‖ + ‖f 0‖ := add_le_add_right (mul_le_mul f.norm_contLinear_le g.norm_image_zero_le (norm_nonneg _) (norm_nonneg _)) _ · calc ‖(f.comp g).contLinear‖ ≤ ‖f.contLinear‖ * ‖g.contLinear‖ := (g.comp_contLinear f).symm ▸ f.contLinear.opNorm_comp_le _ _ ≤ ‖f‖ * ‖g‖ := (mul_le_mul f.norm_contLinear_le g.norm_contLinear_le (norm_nonneg _) (norm_nonneg _)) _ ≤ ‖f‖ * ‖g‖ + ‖f 0‖ := by rw [le_add_iff_nonneg_right]; apply norm_nonneg variable (𝕜 V W) /-- The space of affine maps between two normed spaces is linearly isometric to the product of the codomain with the space of linear maps, by taking the value of the affine map at `(0 : V)` and the linear part. -/ noncomputable def toConstProdContinuousLinearMap : (V →ᴬ[𝕜] W) ≃ₗᵢ[𝕜] W × (V →L[𝕜] W) where toFun f := ⟨f 0, f.contLinear⟩ invFun p := p.2.toContinuousAffineMap + const 𝕜 V p.1 left_inv f := by ext rw [f.decomp] simp only [coe_add, ContinuousLinearMap.coe_toContinuousAffineMap, Pi.add_apply, coe_const] right_inv := by rintro ⟨v, f⟩; ext <;> simp map_add' _ _ := rfl map_smul' _ _ := rfl norm_map' _ := rfl @[simp] theorem toConstProdContinuousLinearMap_fst (f : V →ᴬ[𝕜] W) : (toConstProdContinuousLinearMap 𝕜 V W f).fst = f 0 := rfl @[simp] theorem toConstProdContinuousLinearMap_snd (f : V →ᴬ[𝕜] W) : (toConstProdContinuousLinearMap 𝕜 V W f).snd = f.contLinear := rfl end NormedSpaceStructure end ContinuousAffineMap
Basic.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Function.SimpleFunc /-! # Lower Lebesgue integral for `ℝ≥0∞`-valued functions We define the lower Lebesgue integral of an `ℝ≥0∞`-valued function. ## Notation We introduce the following notation for the lower Lebesgue integral of a function `f : α → ℝ≥0∞`. * `∫⁻ x, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` with respect to a measure `μ`; * `∫⁻ x, f x`: integral of a function `f : α → ℝ≥0∞` with respect to the canonical measure `volume` on `α`; * `∫⁻ x in s, f x ∂μ`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to a measure `μ`, defined as `∫⁻ x, f x ∂(μ.restrict s)`; * `∫⁻ x in s, f x`: integral of a function `f : α → ℝ≥0∞` over a set `s` with respect to the canonical measure `volume`, defined as `∫⁻ x, f x ∂(volume.restrict s)`. -/ assert_not_exists Module.Basis Norm MeasureTheory.MeasurePreserving MeasureTheory.Measure.dirac open Set hiding restrict restrict_apply open Filter ENNReal Topology NNReal namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc variable {α β γ : Type*} open SimpleFunc variable {m : MeasurableSpace α} {μ ν : Measure α} {s : Set α} /-- The **lower Lebesgue integral** of a function `f` with respect to a measure `μ`. -/ noncomputable irreducible_def lintegral (μ : Measure α) (f : α → ℝ≥0∞) : ℝ≥0∞ := ⨆ (g : α →ₛ ℝ≥0∞) (_ : ⇑g ≤ f), g.lintegral μ /-! In the notation for integrals, an expression like `∫⁻ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫⁻ x, f x = 0` will be parsed incorrectly. -/ @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => lintegral μ r @[inherit_doc MeasureTheory.lintegral] notation3 "∫⁻ "(...)", "r:60:(scoped f => lintegral volume f) => r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => lintegral (Measure.restrict μ s) r @[inherit_doc MeasureTheory.lintegral] notation3"∫⁻ "(...)" in "s", "r:60:(scoped f => lintegral (Measure.restrict volume s) f) => r theorem SimpleFunc.lintegral_eq_lintegral {m : MeasurableSpace α} (f : α →ₛ ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = f.lintegral μ := by rw [MeasureTheory.lintegral] exact le_antisymm (iSup₂_le fun g hg => lintegral_mono hg <| le_rfl) (le_iSup₂_of_le f le_rfl le_rfl) @[mono] theorem lintegral_mono' {m : MeasurableSpace α} ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := by rw [lintegral, lintegral] exact iSup_mono fun φ => iSup_mono' fun hφ => ⟨le_trans hφ hfg, lintegral_mono (le_refl φ) hμν⟩ -- version where `hfg` is an explicit forall, so that `@[gcongr]` can recognize it @[gcongr] theorem lintegral_mono_fn' (h2 : μ ≤ ν) ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂ν := lintegral_mono' h2 hfg theorem lintegral_mono ⦃f g : α → ℝ≥0∞⦄ (hfg : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono' (le_refl μ) hfg @[deprecated lintegral_mono (since := "2025-07-10")] theorem lintegral_mono_fn ⦃f g : α → ℝ≥0∞⦄ (hfg : ∀ x, f x ≤ g x) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono hfg theorem lintegral_mono_nnreal {f g : α → ℝ≥0} (h : f ≤ g) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := lintegral_mono fun a => ENNReal.coe_le_coe.2 (h a) theorem iSup_lintegral_measurable_le_eq_lintegral (f : α → ℝ≥0∞) : ⨆ (g : α → ℝ≥0∞) (_ : Measurable g) (_ : g ≤ f), ∫⁻ a, g a ∂μ = ∫⁻ a, f a ∂μ := by apply le_antisymm · exact iSup_le fun i => iSup_le fun _ => iSup_le fun h'i => lintegral_mono h'i · rw [lintegral] refine iSup₂_le fun i hi => le_iSup₂_of_le i i.measurable <| le_iSup_of_le hi ?_ exact le_of_eq (i.lintegral_eq_lintegral _).symm theorem lintegral_mono_set {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ⊆ t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono hst (le_refl μ)) (le_refl f) theorem lintegral_mono_set' {_ : MeasurableSpace α} ⦃μ : Measure α⦄ {s t : Set α} {f : α → ℝ≥0∞} (hst : s ≤ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in t, f x ∂μ := lintegral_mono' (Measure.restrict_mono' hst (le_refl μ)) (le_refl f) theorem monotone_lintegral {_ : MeasurableSpace α} (μ : Measure α) : Monotone (lintegral μ) := lintegral_mono @[simp] theorem lintegral_const (c : ℝ≥0∞) : ∫⁻ _, c ∂μ = c * μ univ := by rw [← SimpleFunc.const_lintegral, ← SimpleFunc.lintegral_eq_lintegral, SimpleFunc.coe_const] rfl theorem lintegral_zero : ∫⁻ _ : α, 0 ∂μ = 0 := by simp theorem lintegral_zero_fun : lintegral μ (0 : α → ℝ≥0∞) = 0 := lintegral_zero theorem lintegral_one : ∫⁻ _, (1 : ℝ≥0∞) ∂μ = μ univ := by rw [lintegral_const, one_mul] theorem setLIntegral_const (s : Set α) (c : ℝ≥0∞) : ∫⁻ _ in s, c ∂μ = c * μ s := by rw [lintegral_const, Measure.restrict_apply_univ] theorem setLIntegral_one (s) : ∫⁻ _ in s, 1 ∂μ = μ s := by rw [setLIntegral_const, one_mul] lemma iInf_mul_le_lintegral (f : α → ℝ≥0∞) : (⨅ x, f x) * μ .univ ≤ ∫⁻ x, f x ∂μ := by calc (⨅ x, f x) * μ .univ _ = ∫⁻ y, ⨅ x, f x ∂μ := by simp _ ≤ ∫⁻ x, f x ∂μ := by gcongr; exact iInf_le _ _ lemma lintegral_le_iSup_mul (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ ≤ (⨆ x, f x) * μ .univ := by calc ∫⁻ x, f x ∂μ _ ≤ ∫⁻ y, ⨆ x, f x ∂μ := by gcongr; exact le_iSup _ _ _ = (⨆ x, f x) * μ .univ := by simp variable (μ) in /-- For any function `f : α → ℝ≥0∞`, there exists a measurable function `g ≤ f` with the same integral. -/ theorem exists_measurable_le_lintegral_eq (f : α → ℝ≥0∞) : ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by rcases eq_or_ne (∫⁻ a, f a ∂μ) 0 with h₀ | h₀ · exact ⟨0, measurable_zero, zero_le f, h₀.trans lintegral_zero.symm⟩ rcases exists_seq_strictMono_tendsto' h₀.bot_lt with ⟨L, _, hLf, hL_tendsto⟩ have : ∀ n, ∃ g : α → ℝ≥0∞, Measurable g ∧ g ≤ f ∧ L n < ∫⁻ a, g a ∂μ := by intro n simpa only [← iSup_lintegral_measurable_le_eq_lintegral f, lt_iSup_iff, exists_prop] using (hLf n).2 choose g hgm hgf hLg using this refine ⟨fun x => ⨆ n, g n x, .iSup hgm, fun x => iSup_le fun n => hgf n x, le_antisymm ?_ ?_⟩ · refine le_of_tendsto' hL_tendsto fun n => (hLg n).le.trans <| lintegral_mono fun x => ?_ exact le_iSup (fun n => g n x) n · exact lintegral_mono fun x => iSup_le fun n => hgf n x /-- `∫⁻ a in s, f a ∂μ` is defined as the supremum of integrals of simple functions `φ : α →ₛ ℝ≥0∞` such that `φ ≤ f`. This lemma says that it suffices to take functions `φ : α →ₛ ℝ≥0`. -/ theorem lintegral_eq_nnreal {m : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : Measure α) : ∫⁻ a, f a ∂μ = ⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ x, ↑(φ x) ≤ f x), (φ.map ((↑) : ℝ≥0 → ℝ≥0∞)).lintegral μ := by rw [lintegral] refine le_antisymm (iSup₂_le fun φ hφ ↦ ?_) (iSup_mono' fun φ ↦ ⟨φ.map ((↑) : ℝ≥0 → ℝ≥0∞), le_rfl⟩) by_cases h : ∀ᵐ a ∂μ, φ a ≠ ∞ · let ψ := φ.map ENNReal.toNNReal replace h : ψ.map ((↑) : ℝ≥0 → ℝ≥0∞) =ᵐ[μ] φ := h.mono fun a => ENNReal.coe_toNNReal have : ∀ x, ↑(ψ x) ≤ f x := fun x => le_trans ENNReal.coe_toNNReal_le_self (hφ x) exact le_iSup₂_of_le (φ.map ENNReal.toNNReal) this (ge_of_eq <| lintegral_congr h) · have h_meas : μ (φ ⁻¹' {∞}) ≠ 0 := mt measure_zero_iff_ae_notMem.1 h refine le_trans le_top (ge_of_eq <| (iSup_eq_top _).2 fun b hb => ?_) obtain ⟨n, hn⟩ : ∃ n : ℕ, b < n * μ (φ ⁻¹' {∞}) := exists_nat_mul_gt h_meas (ne_of_lt hb) use (const α (n : ℝ≥0)).restrict (φ ⁻¹' {∞}) simp only [lt_iSup_iff, exists_prop, coe_restrict, φ.measurableSet_preimage, coe_const, ENNReal.coe_indicator, map_coe_ennreal_restrict, SimpleFunc.map_const, ENNReal.coe_natCast, restrict_const_lintegral] refine ⟨indicator_le fun x hx => le_trans ?_ (hφ _), hn⟩ simp only [mem_preimage, mem_singleton_iff] at hx simp only [hx, le_top] theorem exists_simpleFunc_forall_lintegral_sub_lt_of_pos {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ φ : α →ₛ ℝ≥0, (∀ x, ↑(φ x) ≤ f x) ∧ ∀ ψ : α →ₛ ℝ≥0, (∀ x, ↑(ψ x) ≤ f x) → (map (↑) (ψ - φ)).lintegral μ < ε := by rw [lintegral_eq_nnreal] at h have := ENNReal.lt_add_right h hε erw [ENNReal.biSup_add] at this <;> [skip; exact ⟨0, fun x => zero_le _⟩] simp_rw [lt_iSup_iff, iSup_lt_iff, iSup_le_iff] at this rcases this with ⟨φ, hle : ∀ x, ↑(φ x) ≤ f x, b, hbφ, hb⟩ refine ⟨φ, hle, fun ψ hψ => ?_⟩ have : (map (↑) φ).lintegral μ ≠ ∞ := ne_top_of_le_ne_top h (by exact le_iSup₂ (α := ℝ≥0∞) φ hle) rw [← ENNReal.add_lt_add_iff_left this, ← add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine (hb _ fun x => le_trans ?_ (max_le (hle x) (hψ x))).trans_lt hbφ norm_cast simp only [add_apply, sub_apply, add_tsub_eq_max] rfl theorem iSup_lintegral_le {ι : Sort*} (f : ι → α → ℝ≥0∞) : ⨆ i, ∫⁻ a, f i a ∂μ ≤ ∫⁻ a, ⨆ i, f i a ∂μ := by simp only [← iSup_apply] exact (monotone_lintegral μ).le_map_iSup theorem iSup₂_lintegral_le {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ⨆ (i) (j), ∫⁻ a, f i j a ∂μ ≤ ∫⁻ a, ⨆ (i) (j), f i j a ∂μ := by convert (monotone_lintegral μ).le_map_iSup₂ f with a simp only [iSup_apply] theorem le_iInf_lintegral {ι : Sort*} (f : ι → α → ℝ≥0∞) : ∫⁻ a, ⨅ i, f i a ∂μ ≤ ⨅ i, ∫⁻ a, f i a ∂μ := by simp only [← iInf_apply] exact (monotone_lintegral μ).map_iInf_le theorem le_iInf₂_lintegral {ι : Sort*} {ι' : ι → Sort*} (f : ∀ i, ι' i → α → ℝ≥0∞) : ∫⁻ a, ⨅ (i) (h : ι' i), f i h a ∂μ ≤ ⨅ (i) (h : ι' i), ∫⁻ a, f i h a ∂μ := by convert (monotone_lintegral μ).map_iInf₂_le f with a simp only [iInf_apply] theorem lintegral_mono_ae {f g : α → ℝ≥0∞} (h : ∀ᵐ a ∂μ, f a ≤ g a) : ∫⁻ a, f a ∂μ ≤ ∫⁻ a, g a ∂μ := by rcases exists_measurable_superset_of_null h with ⟨t, hts, ht, ht0⟩ have : ∀ᵐ x ∂μ, x ∉ t := measure_zero_iff_ae_notMem.1 ht0 rw [lintegral, lintegral] refine iSup₂_le fun s hfs ↦ le_iSup₂_of_le (s.restrict tᶜ) ?_ ?_ · intro a by_cases h : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, h, not_true, not_false_eq_true, indicator_of_notMem, zero_le, not_false_eq_true, indicator_of_mem] exact le_trans (hfs a) (by_contradiction fun hnfg => h (hts hnfg)) · refine le_of_eq (SimpleFunc.lintegral_congr <| this.mono fun a hnt => ?_) by_cases hat : a ∈ t <;> simp only [restrict_apply s ht.compl, mem_compl_iff, hat, not_true, not_false_eq_true, indicator_of_notMem, not_false_eq_true, indicator_of_mem] exact (hnt hat).elim /-- Lebesgue integral over a set is monotone in function. This version assumes that the upper estimate is an a.e. measurable function and the estimate holds a.e. on the set. See also `setLIntegral_mono_ae'` for a version that assumes measurability of the set but assumes no regularity of either function. -/ theorem setLIntegral_mono_ae {s : Set α} {f g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.restrict s)) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := by rcases exists_measurable_le_lintegral_eq (μ.restrict s) f with ⟨f', hf'm, hle, hf'⟩ rw [hf'] apply lintegral_mono_ae rw [ae_restrict_iff₀] · exact hfg.mono fun x hx hxs ↦ (hle x).trans (hx hxs) · exact nullMeasurableSet_le hf'm.aemeasurable hg theorem setLIntegral_mono {s : Set α} {f g : α → ℝ≥0∞} (hg : Measurable g) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := setLIntegral_mono_ae hg.aemeasurable (ae_of_all _ hfg) theorem setLIntegral_mono_ae' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := lintegral_mono_ae <| (ae_restrict_iff' hs).2 hfg theorem setLIntegral_mono' {s : Set α} {f g : α → ℝ≥0∞} (hs : MeasurableSet s) (hfg : ∀ x ∈ s, f x ≤ g x) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ := setLIntegral_mono_ae' hs (ae_of_all _ hfg) theorem setLIntegral_le_lintegral (s : Set α) (f : α → ℝ≥0∞) : ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x, f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl lemma iInf_mul_le_setLIntegral (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : (⨅ x ∈ s, f x) * μ s ≤ ∫⁻ x in s, f x ∂μ := by calc (⨅ x ∈ s, f x) * μ s _ = ∫⁻ y in s, ⨅ x ∈ s, f x ∂μ := by simp _ ≤ ∫⁻ x in s, f x ∂μ := setLIntegral_mono' hs fun x hx ↦ iInf₂_le x hx lemma setLIntegral_le_iSup_mul (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : ∫⁻ x in s, f x ∂μ ≤ (⨆ x ∈ s, f x) * μ s := by calc ∫⁻ x in s, f x ∂μ _ ≤ ∫⁻ y in s, ⨆ x ∈ s, f x ∂μ := setLIntegral_mono' hs fun x hx ↦ le_iSup₂ (f := fun x _ ↦ f x) x hx _ = (⨆ x ∈ s, f x) * μ s := by simp theorem lintegral_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := le_antisymm (lintegral_mono_ae <| h.le) (lintegral_mono_ae <| h.symm.le) theorem lintegral_congr {f g : α → ℝ≥0∞} (h : ∀ a, f a = g a) : ∫⁻ a, f a ∂μ = ∫⁻ a, g a ∂μ := by simp only [h] theorem setLIntegral_congr {f : α → ℝ≥0∞} {s t : Set α} (h : s =ᵐ[μ] t) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := by rw [Measure.restrict_congr_set h] theorem setLIntegral_congr_fun_ae {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := by rw [lintegral_congr_ae] rw [EventuallyEq] rwa [ae_restrict_iff' hs] theorem setLIntegral_congr_fun {f g : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hfg : EqOn f g s) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ := setLIntegral_congr_fun_ae hs <| Eventually.of_forall hfg lemma setLIntegral_eq_zero {f : α → ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (h's : EqOn f 0 s) : ∫⁻ x in s, f x ∂μ = 0 := by simp [setLIntegral_congr_fun hs h's] section theorem lintegral_eq_zero_of_ae_eq_zero {f : α → ℝ≥0∞} (h : f =ᵐ[μ] 0) : ∫⁻ a, f a ∂μ = 0 := (lintegral_congr_ae h).trans lintegral_zero /-- The Lebesgue integral is zero iff the function is a.e. zero. The measurability assumption is necessary, otherwise there are counterexamples: for instance, the conclusion fails if `f` is the characteristic function of a Vitali set. -/ @[simp] theorem lintegral_eq_zero_iff' {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := by -- The proof implicitly uses Markov's inequality, -- but it has been inlined for the sake of imports refine ⟨fun h ↦ ?_, lintegral_eq_zero_of_ae_eq_zero⟩ have meas_levels_0 : ∀ ε > 0, μ { x | ε ≤ f x } = 0 := fun ε εpos ↦ by by_contra! h'; rw [← zero_lt_iff] at h' refine ((mul_pos_iff.mpr ⟨εpos, h'⟩).trans_le ?_).ne' h calc _ ≥ ∫⁻ a in {x | ε ≤ f x}, f a ∂μ := setLIntegral_le_lintegral _ _ _ ≥ ∫⁻ _ in {x | ε ≤ f x}, ε ∂μ := setLIntegral_mono_ae hf.restrict (ae_of_all μ fun _ ↦ id) _ = _ := setLIntegral_const _ _ obtain ⟨u, -, bu, tu⟩ := exists_seq_strictAnti_tendsto' (α := ℝ≥0∞) zero_lt_one have u_union : {x | f x ≠ 0} = ⋃ n, {x | u n ≤ f x} := by ext x; rw [mem_iUnion, mem_setOf_eq, ← zero_lt_iff] rw [ENNReal.tendsto_atTop_zero] at tu constructor <;> intro h' · obtain ⟨n, hn⟩ := tu _ h'; use n, hn _ le_rfl · obtain ⟨n, hn⟩ := h'; exact (bu n).1.trans_le hn have res := measure_iUnion_null_iff.mpr fun n ↦ meas_levels_0 _ (bu n).1 rwa [← u_union] at res /-- The measurability assumption is necessary, otherwise there are counterexamples: for instance, the conclusion fails if `f` is the characteristic function of a Vitali set. -/ @[simp] theorem lintegral_eq_zero_iff {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a, f a ∂μ = 0 ↔ f =ᵐ[μ] 0 := lintegral_eq_zero_iff' hf.aemeasurable /-- The measurability assumption is necessary, otherwise there are counterexamples: for instance, the conclusion fails if `s = univ` and `f` is the characteristic function of a Vitali set. -/ theorem setLIntegral_eq_zero_iff' {s : Set α} (hs : MeasurableSet s) {f : α → ℝ≥0∞} (hf : AEMeasurable f (μ.restrict s)) : ∫⁻ a in s, f a ∂μ = 0 ↔ ∀ᵐ x ∂μ, x ∈ s → f x = 0 := (lintegral_eq_zero_iff' hf).trans (ae_restrict_iff' hs) theorem setLIntegral_eq_zero_iff {s : Set α} (hs : MeasurableSet s) {f : α → ℝ≥0∞} (hf : Measurable f) : ∫⁻ a in s, f a ∂μ = 0 ↔ ∀ᵐ x ∂μ, x ∈ s → f x = 0 := setLIntegral_eq_zero_iff' hs hf.aemeasurable theorem lintegral_pos_iff_support {f : α → ℝ≥0∞} (hf : Measurable f) : (0 < ∫⁻ a, f a ∂μ) ↔ 0 < μ (Function.support f) := by simp [pos_iff_ne_zero, hf, Filter.EventuallyEq, ae_iff, Function.support] theorem setLIntegral_pos_iff {f : α → ℝ≥0∞} (hf : Measurable f) {s : Set α} : 0 < ∫⁻ a in s, f a ∂μ ↔ 0 < μ (Function.support f ∩ s) := by rw [lintegral_pos_iff_support hf, Measure.restrict_apply (measurableSet_support hf)] @[deprecated (since := "2025-04-22")] alias setLintegral_pos_iff := setLIntegral_pos_iff end /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. This lemma states this fact in terms of `ε` and `δ`. -/ theorem exists_pos_setLIntegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ δ > 0, ∀ s, μ s < δ → ∫⁻ x in s, f x ∂μ < ε := by rcases exists_between (pos_iff_ne_zero.mpr hε) with ⟨ε₂, hε₂0, hε₂ε⟩ rcases exists_between hε₂0 with ⟨ε₁, hε₁0, hε₁₂⟩ rcases exists_simpleFunc_forall_lintegral_sub_lt_of_pos h hε₁0.ne' with ⟨φ, _, hφ⟩ rcases φ.exists_forall_le with ⟨C, hC⟩ use (ε₂ - ε₁) / C, ENNReal.div_pos_iff.2 ⟨(tsub_pos_iff_lt.2 hε₁₂).ne', ENNReal.coe_ne_top⟩ refine fun s hs => lt_of_le_of_lt ?_ hε₂ε simp only [lintegral_eq_nnreal, iSup_le_iff] intro ψ hψ calc (map (↑) ψ).lintegral (μ.restrict s) ≤ (map (↑) φ).lintegral (μ.restrict s) + (map (↑) (ψ - φ)).lintegral (μ.restrict s) := by rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add] refine SimpleFunc.lintegral_mono (fun x => ?_) le_rfl simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add, SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)] _ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by gcongr refine le_trans ?_ (hφ _ hψ).le exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self _ ≤ (SimpleFunc.const α (C : ℝ≥0∞)).lintegral (μ.restrict s) + ε₁ := by gcongr exact fun x ↦ ENNReal.coe_le_coe.2 (hC x) _ = C * μ s + ε₁ := by simp only [← SimpleFunc.lintegral_eq_lintegral, coe_const, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, Function.const] _ ≤ C * ((ε₂ - ε₁) / C) + ε₁ := by gcongr _ ≤ ε₂ - ε₁ + ε₁ := by gcongr; apply mul_div_le _ = ε₂ := tsub_add_cancel_of_le hε₁₂.le /-- If `f` has finite integral, then `∫⁻ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ theorem tendsto_setLIntegral_zero {ι} {f : α → ℝ≥0∞} (h : ∫⁻ x, f x ∂μ ≠ ∞) {l : Filter ι} {s : ι → Set α} (hl : Tendsto (μ ∘ s) l (𝓝 0)) : Tendsto (fun i => ∫⁻ x in s i, f x ∂μ) l (𝓝 0) := by simp only [ENNReal.nhds_zero, tendsto_iInf, tendsto_principal, mem_Iio, ← pos_iff_ne_zero] at hl ⊢ intro ε ε0 rcases exists_pos_setLIntegral_lt_of_measure_lt h ε0.ne' with ⟨δ, δ0, hδ⟩ exact (hl δ δ0).mono fun i => hδ _ @[simp] theorem lintegral_smul_measure {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂c • μ = c • ∫⁻ a, f a ∂μ := by simp only [lintegral, iSup_subtype', SimpleFunc.lintegral_smul, ENNReal.smul_iSup] lemma setLIntegral_smul_measure {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂(c • μ) = c • ∫⁻ a in s, f a ∂μ := by rw [Measure.restrict_smul, lintegral_smul_measure] @[simp] theorem lintegral_zero_measure {m : MeasurableSpace α} (f : α → ℝ≥0∞) : ∫⁻ a, f a ∂(0 : Measure α) = 0 := by simp [lintegral] @[simp] theorem lintegral_add_measure (f : α → ℝ≥0∞) (μ ν : Measure α) : ∫⁻ a, f a ∂(μ + ν) = ∫⁻ a, f a ∂μ + ∫⁻ a, f a ∂ν := by simp only [lintegral, SimpleFunc.lintegral_add, iSup_subtype'] refine (ENNReal.iSup_add_iSup ?_).symm rintro ⟨φ, hφ⟩ ⟨ψ, hψ⟩ refine ⟨⟨φ ⊔ ψ, sup_le hφ hψ⟩, ?_⟩ gcongr exacts [le_sup_left, le_sup_right] @[simp] theorem lintegral_finset_sum_measure {ι} (s : Finset ι) (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂(∑ i ∈ s, μ i) = ∑ i ∈ s, ∫⁻ a, f a ∂μ i := let F : Measure α →+ ℝ≥0∞ := { toFun := (lintegral · f), map_zero' := lintegral_zero_measure f, map_add' := lintegral_add_measure f } map_sum F μ s @[simp] theorem lintegral_sum_measure {m : MeasurableSpace α} {ι} (f : α → ℝ≥0∞) (μ : ι → Measure α) : ∫⁻ a, f a ∂Measure.sum μ = ∑' i, ∫⁻ a, f a ∂μ i := by simp_rw [ENNReal.tsum_eq_iSup_sum, ← lintegral_finset_sum_measure, lintegral, SimpleFunc.lintegral_sum, ENNReal.tsum_eq_iSup_sum, SimpleFunc.lintegral_finset_sum, iSup_comm (ι := Finset ι)] theorem hasSum_lintegral_measure {ι} {_ : MeasurableSpace α} (f : α → ℝ≥0∞) (μ : ι → Measure α) : HasSum (fun i => ∫⁻ a, f a ∂μ i) (∫⁻ a, f a ∂Measure.sum μ) := (lintegral_sum_measure f μ).symm ▸ ENNReal.summable.hasSum @[simp] theorem lintegral_of_isEmpty {α} [MeasurableSpace α] [IsEmpty α] (μ : Measure α) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = 0 := by have : Subsingleton (Measure α) := inferInstance convert lintegral_zero_measure f theorem setLIntegral_empty (f : α → ℝ≥0∞) : ∫⁻ x in ∅, f x ∂μ = 0 := by rw [Measure.restrict_empty, lintegral_zero_measure] theorem setLIntegral_univ (f : α → ℝ≥0∞) : ∫⁻ x in univ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [Measure.restrict_univ] theorem setLIntegral_measure_zero (s : Set α) (f : α → ℝ≥0∞) (hs' : μ s = 0) : ∫⁻ x in s, f x ∂μ = 0 := by convert lintegral_zero_measure _ exact Measure.restrict_eq_zero.2 hs' -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₁ {f f' : α → β} (h : f =ᵐ[μ] f') (g : β → ℝ≥0∞) : ∫⁻ a, g (f a) ∂μ = ∫⁻ a, g (f' a) ∂μ := lintegral_congr_ae <| h.mono fun a h => by dsimp only; rw [h] -- TODO: Need a better way of rewriting inside of an integral theorem lintegral_rw₂ {f₁ f₁' : α → β} {f₂ f₂' : α → γ} (h₁ : f₁ =ᵐ[μ] f₁') (h₂ : f₂ =ᵐ[μ] f₂') (g : β → γ → ℝ≥0∞) : ∫⁻ a, g (f₁ a) (f₂ a) ∂μ = ∫⁻ a, g (f₁' a) (f₂' a) ∂μ := lintegral_congr_ae <| h₁.mp <| h₂.mono fun _ h₂ h₁ => by dsimp only; rw [h₁, h₂] theorem lintegral_indicator_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a, s.indicator f a ∂μ ≤ ∫⁻ a in s, f a ∂μ := by simp only [lintegral] apply iSup_le (fun g ↦ (iSup_le (fun hg ↦ ?_))) have : g ≤ f := hg.trans (indicator_le_self s f) refine le_iSup_of_le g (le_iSup_of_le this (le_of_eq ?_)) rw [lintegral_restrict, SimpleFunc.lintegral] congr with t by_cases H : t = 0 · simp [H] congr with x simp only [mem_preimage, mem_singleton_iff, mem_inter_iff, iff_self_and] rintro rfl contrapose! H simpa [H] using hg x @[simp] theorem lintegral_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by apply le_antisymm (lintegral_indicator_le f s) simp only [lintegral, ← restrict_lintegral_eq_lintegral_restrict _ hs, iSup_subtype'] refine iSup_mono' (Subtype.forall.2 fun φ hφ => ?_) refine ⟨⟨φ.restrict s, fun x => ?_⟩, le_rfl⟩ simp [hφ x, hs, indicator_le_indicator] lemma setLIntegral_indicator {s t : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : ∫⁻ a in t, s.indicator f a ∂μ = ∫⁻ a in s ∩ t, f a ∂μ := by rw [lintegral_indicator hs, Measure.restrict_restrict hs] theorem lintegral_indicator₀ {s : Set α} (hs : NullMeasurableSet s μ) (f : α → ℝ≥0∞) : ∫⁻ a, s.indicator f a ∂μ = ∫⁻ a in s, f a ∂μ := by rw [← lintegral_congr_ae (indicator_ae_eq_of_ae_eq_set hs.toMeasurable_ae_eq), lintegral_indicator (measurableSet_toMeasurable _ _), Measure.restrict_congr_set hs.toMeasurable_ae_eq] lemma setLIntegral_indicator₀ (f : α → ℝ≥0∞) {s t : Set α} (hs : NullMeasurableSet s (μ.restrict t)) : ∫⁻ a in t, s.indicator f a ∂μ = ∫⁻ a in s ∩ t, f a ∂μ := by rw [lintegral_indicator₀ hs, Measure.restrict_restrict₀ hs] theorem lintegral_indicator_const_le (s : Set α) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ ≤ c * μ s := (lintegral_indicator_le _ _).trans (setLIntegral_const s c).le theorem lintegral_indicator_const₀ {s : Set α} (hs : NullMeasurableSet s μ) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := by rw [lintegral_indicator₀ hs, setLIntegral_const] theorem lintegral_indicator_const {s : Set α} (hs : MeasurableSet s) (c : ℝ≥0∞) : ∫⁻ a, s.indicator (fun _ => c) a ∂μ = c * μ s := lintegral_indicator_const₀ hs.nullMeasurableSet c lemma setLIntegral_eq_of_support_subset {s : Set α} {f : α → ℝ≥0∞} (hsf : f.support ⊆ s) : ∫⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂μ := by apply le_antisymm (setLIntegral_le_lintegral s fun x ↦ f x) apply le_trans (le_of_eq _) (lintegral_indicator_le _ _) congr with x simp only [indicator] split_ifs with h · rfl · exact Function.support_subset_iff'.1 hsf x h theorem setLIntegral_eq_const {f : α → ℝ≥0∞} (hf : Measurable f) (r : ℝ≥0∞) : ∫⁻ x in { x | f x = r }, f x ∂μ = r * μ { x | f x = r } := by have : ∀ x ∈ { x | f x = r }, f x = r := fun _ hx => hx rw [setLIntegral_congr_fun _ this] · rw [lintegral_const, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] · exact hf (measurableSet_singleton r) theorem lintegral_indicator_one_le (s : Set α) : ∫⁻ a, s.indicator 1 a ∂μ ≤ μ s := (lintegral_indicator_const_le _ _).trans <| (one_mul _).le @[simp] theorem lintegral_indicator_one₀ {s : Set α} (hs : NullMeasurableSet s μ) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := (lintegral_indicator_const₀ hs _).trans <| one_mul _ theorem lintegral_indicator_one {s : Set α} (hs : MeasurableSet s) : ∫⁻ a, s.indicator 1 a ∂μ = μ s := by simp [hs] theorem Measure.ext_iff_lintegral (ν : Measure α) : μ = ν ↔ ∀ f : α → ℝ≥0∞, Measurable f → ∫⁻ a, f a ∂μ = ∫⁻ a, f a ∂ν := by refine ⟨fun h _ _ ↦ by rw [h], ?_⟩ intro h ext s hs simp only [← lintegral_indicator_one hs] exact h (s.indicator 1) ((measurable_indicator_const_iff 1).mpr hs) theorem Measure.ext_of_lintegral (ν : Measure α) (hμν : ∀ f : α → ℝ≥0∞, Measurable f → ∫⁻ a, f a ∂μ = ∫⁻ a, f a ∂ν) : μ = ν := (μ.ext_iff_lintegral ν).mpr hμν open Measure open scoped Function -- required for scoped `on` notation theorem lintegral_iUnion₀ [Countable β] {s : β → Set α} (hm : ∀ i, NullMeasurableSet (s i) μ) (hd : Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := by simp only [Measure.restrict_iUnion_ae hd hm, lintegral_sum_measure] theorem lintegral_iUnion [Countable β] {s : β → Set α} (hm : ∀ i, MeasurableSet (s i)) (hd : Pairwise (Disjoint on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ = ∑' i, ∫⁻ a in s i, f a ∂μ := lintegral_iUnion₀ (fun i => (hm i).nullMeasurableSet) hd.aedisjoint f theorem lintegral_biUnion₀ {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, NullMeasurableSet (s i) μ) (hd : t.Pairwise (AEDisjoint μ on s)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := by haveI := ht.toEncodable rw [biUnion_eq_iUnion, lintegral_iUnion₀ (SetCoe.forall'.1 hm) (hd.subtype _ _)] theorem lintegral_biUnion {t : Set β} {s : β → Set α} (ht : t.Countable) (hm : ∀ i ∈ t, MeasurableSet (s i)) (hd : t.PairwiseDisjoint s) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i ∈ t, s i, f a ∂μ = ∑' i : t, ∫⁻ a in s i, f a ∂μ := lintegral_biUnion₀ ht (fun i hi => (hm i hi).nullMeasurableSet) hd.aedisjoint f theorem lintegral_biUnion_finset₀ {s : Finset β} {t : β → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on t)) (hm : ∀ b ∈ s, NullMeasurableSet (t b) μ) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := by simp only [← Finset.mem_coe, lintegral_biUnion₀ s.countable_toSet hm hd, ← Finset.tsum_subtype'] theorem lintegral_biUnion_finset {s : Finset β} {t : β → Set α} (hd : Set.PairwiseDisjoint (↑s) t) (hm : ∀ b ∈ s, MeasurableSet (t b)) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ b ∈ s, t b, f a ∂μ = ∑ b ∈ s, ∫⁻ a in t b, f a ∂μ := lintegral_biUnion_finset₀ hd.aedisjoint (fun b hb => (hm b hb).nullMeasurableSet) f theorem lintegral_iUnion_le [Countable β] (s : β → Set α) (f : α → ℝ≥0∞) : ∫⁻ a in ⋃ i, s i, f a ∂μ ≤ ∑' i, ∫⁻ a in s i, f a ∂μ := by rw [← lintegral_sum_measure] exact lintegral_mono' restrict_iUnion_le le_rfl theorem lintegral_union {f : α → ℝ≥0∞} {A B : Set α} (hB : MeasurableSet B) (hAB : Disjoint A B) : ∫⁻ a in A ∪ B, f a ∂μ = ∫⁻ a in A, f a ∂μ + ∫⁻ a in B, f a ∂μ := by rw [restrict_union hAB hB, lintegral_add_measure] theorem lintegral_union_le (f : α → ℝ≥0∞) (s t : Set α) : ∫⁻ a in s ∪ t, f a ∂μ ≤ ∫⁻ a in s, f a ∂μ + ∫⁻ a in t, f a ∂μ := by rw [← lintegral_add_measure] exact lintegral_mono' (restrict_union_le _ _) le_rfl theorem lintegral_inter_add_diff {B : Set α} (f : α → ℝ≥0∞) (A : Set α) (hB : MeasurableSet B) : ∫⁻ x in A ∩ B, f x ∂μ + ∫⁻ x in A \ B, f x ∂μ = ∫⁻ x in A, f x ∂μ := by rw [← lintegral_add_measure, restrict_inter_add_diff _ hB] theorem lintegral_add_compl (f : α → ℝ≥0∞) {A : Set α} (hA : MeasurableSet A) : ∫⁻ x in A, f x ∂μ + ∫⁻ x in Aᶜ, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [← lintegral_add_measure, Measure.restrict_add_restrict_compl hA] lemma lintegral_piecewise (hs : MeasurableSet s) (f g : α → ℝ≥0∞) [∀ j, Decidable (j ∈ s)] : ∫⁻ a, s.piecewise f g a ∂μ = ∫⁻ a in s, f a ∂μ + ∫⁻ a in sᶜ, g a ∂μ := by rw [← lintegral_add_compl _ hs] congr 1 · exact setLIntegral_congr_fun hs <| fun _ ↦ Set.piecewise_eq_of_mem _ _ _ · exact setLIntegral_congr_fun hs.compl <| fun _ ↦ Set.piecewise_eq_of_notMem _ _ _ theorem setLIntegral_compl {f : α → ℝ≥0∞} {s : Set α} (hsm : MeasurableSet s) (hfs : ∫⁻ x in s, f x ∂μ ≠ ∞) : ∫⁻ x in sᶜ, f x ∂μ = ∫⁻ x, f x ∂μ - ∫⁻ x in s, f x ∂μ := by rw [← lintegral_add_compl (μ := μ) f hsm, ENNReal.add_sub_cancel_left hfs] @[deprecated (since := "2025-04-22")] alias setLintegral_compl := setLIntegral_compl theorem setLIntegral_iUnion_of_directed {ι : Type*} [Countable ι] (f : α → ℝ≥0∞) {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : ∫⁻ x in ⋃ i, s i, f x ∂μ = ⨆ i, ∫⁻ x in s i, f x ∂μ := by simp only [lintegral_def, iSup_comm (ι := ι), SimpleFunc.lintegral_restrict_iUnion_of_directed _ hd] theorem lintegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : ∫⁻ x, max (f x) (g x) ∂μ = ∫⁻ x in { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in { x | g x < f x }, f x ∂μ := by have hm : MeasurableSet { x | f x ≤ g x } := measurableSet_le hf hg rw [← lintegral_add_compl (fun x => max (f x) (g x)) hm] simp only [← compl_setOf, ← not_le] refine congr_arg₂ (· + ·) (setLIntegral_congr_fun hm ?_) (setLIntegral_congr_fun hm.compl ?_) exacts [fun x => max_eq_right (a := f x) (b := g x), fun x (hx : ¬ f x ≤ g x) => max_eq_left (not_le.1 hx).le] theorem setLIntegral_max {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) (s : Set α) : ∫⁻ x in s, max (f x) (g x) ∂μ = ∫⁻ x in s ∩ { x | f x ≤ g x }, g x ∂μ + ∫⁻ x in s ∩ { x | g x < f x }, f x ∂μ := by rw [lintegral_max hf hg, restrict_restrict, restrict_restrict, inter_comm s, inter_comm s] exacts [measurableSet_lt hg hf, measurableSet_le hf hg] /-- Lebesgue integral of a bounded function over a set of finite measure is finite. Note that this lemma assumes no regularity of either `f` or `s`. -/ theorem setLIntegral_lt_top_of_le_nnreal {s : Set α} (hs : μ s ≠ ∞) {f : α → ℝ≥0∞} (hbdd : ∃ y : ℝ≥0, ∀ x ∈ s, f x ≤ y) : ∫⁻ x in s, f x ∂μ < ∞ := by obtain ⟨M, hM⟩ := hbdd refine lt_of_le_of_lt (setLIntegral_mono measurable_const hM) ?_ simp [ENNReal.mul_lt_top, hs.lt_top] /-- Lebesgue integral of a bounded function over a set of finite measure is finite. Note that this lemma assumes no regularity of either `f` or `s`. -/ theorem setLIntegral_lt_top_of_bddAbove {s : Set α} (hs : μ s ≠ ∞) {f : α → ℝ≥0} (hbdd : BddAbove (f '' s)) : ∫⁻ x in s, f x ∂μ < ∞ := setLIntegral_lt_top_of_le_nnreal hs <| hbdd.imp fun _M hM _x hx ↦ ENNReal.coe_le_coe.2 <| hM (mem_image_of_mem f hx) theorem setLIntegral_lt_top_of_isCompact [TopologicalSpace α] {s : Set α} (hs : μ s ≠ ∞) (hsc : IsCompact s) {f : α → ℝ≥0} (hf : Continuous f) : ∫⁻ x in s, f x ∂μ < ∞ := setLIntegral_lt_top_of_bddAbove hs (hsc.image hf).bddAbove end MeasureTheory
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, Chris Hughes, Mario Carneiro -/ import Mathlib.Algebra.Ring.Action.End import Mathlib.RingTheory.Finiteness.Cardinality import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.LocalRing.RingHom.Basic /-! # Residue Field of local rings We prove basic properties of the residue field of a local ring. -/ variable {R S T : Type*} namespace IsLocalRing section variable [CommRing R] [IsLocalRing R] [CommRing S] [IsLocalRing S] [CommRing T] [IsLocalRing T] lemma residue_def (x) : residue R x = Ideal.Quotient.mk (maximalIdeal R) x := rfl lemma ker_residue : RingHom.ker (residue R) = maximalIdeal R := Ideal.mk_ker @[simp] lemma residue_eq_zero_iff (x : R) : residue R x = 0 ↔ x ∈ maximalIdeal R := by rw [← RingHom.mem_ker, ker_residue] lemma residue_ne_zero_iff_isUnit (x : R) : residue R x ≠ 0 ↔ IsUnit x := by simp lemma residue_surjective : Function.Surjective (IsLocalRing.residue R) := Ideal.Quotient.mk_surjective variable (R) instance ResidueField.algebra {R₀} [CommRing R₀] [Algebra R₀ R] : Algebra R₀ (ResidueField R) := Ideal.Quotient.algebra _ instance {R₁ R₂} [CommRing R₁] [CommRing R₂] [Algebra R₁ R₂] [Algebra R₁ R] [Algebra R₂ R] [IsScalarTower R₁ R₂ R] : IsScalarTower R₁ R₂ (IsLocalRing.ResidueField R) := by delta IsLocalRing.ResidueField; infer_instance @[simp] theorem ResidueField.algebraMap_eq : algebraMap R (ResidueField R) = residue R := rfl instance : IsLocalHom (IsLocalRing.residue R) := ⟨fun _ ha => Classical.not_not.mp (Ideal.Quotient.eq_zero_iff_mem.not.mp (isUnit_iff_ne_zero.mp ha))⟩ instance {R₀} [CommRing R₀] [Algebra R₀ R] [Module.Finite R₀ R] : Module.Finite R₀ (ResidueField R) := .of_surjective (IsScalarTower.toAlgHom R₀ R _).toLinearMap Ideal.Quotient.mk_surjective variable {R} namespace ResidueField /-- A local ring homomorphism into a field can be descended onto the residue field. -/ def lift {R S : Type*} [CommRing R] [IsLocalRing R] [Field S] (f : R →+* S) [IsLocalHom f] : IsLocalRing.ResidueField R →+* S := Ideal.Quotient.lift _ f fun a ha => by_contradiction fun h => ha (isUnit_of_map_unit f a (isUnit_iff_ne_zero.mpr h)) theorem lift_comp_residue {R S : Type*} [CommRing R] [IsLocalRing R] [Field S] (f : R →+* S) [IsLocalHom f] : (lift f).comp (residue R) = f := RingHom.ext fun _ => rfl @[simp] theorem lift_residue_apply {R S : Type*} [CommRing R] [IsLocalRing R] [Field S] (f : R →+* S) [IsLocalHom f] (x) : lift f (residue R x) = f x := rfl /-- The map on residue fields induced by a local homomorphism between local rings -/ noncomputable def map (f : R →+* S) [IsLocalHom f] : ResidueField R →+* ResidueField S := Ideal.Quotient.lift (maximalIdeal R) ((Ideal.Quotient.mk _).comp f) fun a ha => by unfold ResidueField rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem] exact map_nonunit f a ha /-- Applying `IsLocalRing.ResidueField.map` to the identity ring homomorphism gives the identity ring homomorphism. -/ @[simp] theorem map_id : IsLocalRing.ResidueField.map (RingHom.id R) = RingHom.id (IsLocalRing.ResidueField R) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl /-- The composite of two `IsLocalRing.ResidueField.map`s is the `IsLocalRing.ResidueField.map` of the composite. -/ theorem map_comp (f : T →+* R) (g : R →+* S) [IsLocalHom f] [IsLocalHom g] : IsLocalRing.ResidueField.map (g.comp f) = (IsLocalRing.ResidueField.map g).comp (IsLocalRing.ResidueField.map f) := Ideal.Quotient.ringHom_ext <| RingHom.ext fun _ => rfl theorem map_comp_residue (f : R →+* S) [IsLocalHom f] : (ResidueField.map f).comp (residue R) = (residue S).comp f := rfl theorem map_residue (f : R →+* S) [IsLocalHom f] (r : R) : ResidueField.map f (residue R r) = residue S (f r) := rfl theorem map_id_apply (x : ResidueField R) : map (RingHom.id R) x = x := DFunLike.congr_fun map_id x @[simp] theorem map_map (f : R →+* S) (g : S →+* T) (x : ResidueField R) [IsLocalHom f] [IsLocalHom g] : map g (map f x) = map (g.comp f) x := DFunLike.congr_fun (map_comp f g).symm x /-- A ring isomorphism defines an isomorphism of residue fields. -/ @[simps apply] noncomputable def mapEquiv (f : R ≃+* S) : IsLocalRing.ResidueField R ≃+* IsLocalRing.ResidueField S where toFun := map (f : R →+* S) invFun := map (f.symm : S →+* R) left_inv x := by simp only [map_map, RingEquiv.symm_comp, map_id, RingHom.id_apply] right_inv x := by simp only [map_map, RingEquiv.comp_symm, map_id, RingHom.id_apply] map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ @[simp] theorem mapEquiv.symm (f : R ≃+* S) : (mapEquiv f).symm = mapEquiv f.symm := rfl @[simp] theorem mapEquiv_trans (e₁ : R ≃+* S) (e₂ : S ≃+* T) : mapEquiv (e₁.trans e₂) = (mapEquiv e₁).trans (mapEquiv e₂) := RingEquiv.toRingHom_injective <| map_comp (e₁ : R →+* S) (e₂ : S →+* T) @[simp] theorem mapEquiv_refl : mapEquiv (RingEquiv.refl R) = RingEquiv.refl _ := RingEquiv.toRingHom_injective map_id /-- The group homomorphism from `RingAut R` to `RingAut k` where `k` is the residue field of `R`. -/ @[simps] noncomputable def mapAut : RingAut R →* RingAut (IsLocalRing.ResidueField R) where toFun := mapEquiv map_mul' e₁ e₂ := mapEquiv_trans e₂ e₁ map_one' := mapEquiv_refl section MulSemiringAction variable (G : Type*) [Group G] [MulSemiringAction G R] /-- If `G` acts on `R` as a `MulSemiringAction`, then it also acts on `IsLocalRing.ResidueField R`. -/ noncomputable instance : MulSemiringAction G (IsLocalRing.ResidueField R) := MulSemiringAction.compHom _ <| mapAut.comp (MulSemiringAction.toRingAut G R) @[simp] theorem residue_smul (g : G) (r : R) : residue R (g • r) = g • residue R r := rfl end MulSemiringAction section FiniteDimensional variable [Algebra R S] [IsLocalHom (algebraMap R S)] noncomputable instance : Algebra (ResidueField R) (ResidueField S) := (ResidueField.map (algebraMap R S)).toAlgebra instance : IsScalarTower R (ResidueField R) (ResidueField S) := IsScalarTower.of_algebraMap_eq (congrFun rfl) instance finite_of_module_finite [Module.Finite R S] : Module.Finite (ResidueField R) (ResidueField S) := .of_restrictScalars_finite R _ _ lemma finite_of_finite [Module.Finite R S] (hfin : Finite (ResidueField R)) : Finite (ResidueField S) := Module.finite_of_finite (ResidueField R) end FiniteDimensional end ResidueField theorem isLocalHom_residue : IsLocalHom (IsLocalRing.residue R) := by constructor intro a ha by_contra h rw [residue_def, Ideal.Quotient.eq_zero_iff_mem.mpr ((IsLocalRing.mem_maximalIdeal _).mpr h)] at ha exact ha.ne_zero rfl end end IsLocalRing