filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
path.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq.
(******************************************************************************)
(* The basic theory of paths over an eqType; this file is essentially a *)
(* complement to seq.v. Paths are non-empty sequences that obey a progression *)
(* relation. They are passed around in three parts: the head and tail of the *)
(* sequence, and a proof of a (boolean) predicate asserting the progression. *)
(* This "exploded" view is rarely embarrassing, as the first two parameters *)
(* are usually inferred from the type of the third; on the contrary, it saves *)
(* the hassle of constantly constructing and destructing a dependent record. *)
(* We define similarly cycles, for which we allow the empty sequence, *)
(* which represents a non-rooted empty cycle; by contrast, the "empty" path *)
(* from a point x is the one-item sequence containing only x. *)
(* We allow duplicates; uniqueness, if desired (as is the case for several *)
(* geometric constructions), must be asserted separately. We do provide *)
(* shorthand, but only for cycles, because the equational properties of *)
(* "path" and "uniq" are unfortunately incompatible (esp. wrt "cat"). *)
(* We define notations for the common cases of function paths, where the *)
(* progress relation is actually a function. In detail: *)
(* path e x p == x :: p is an e-path [:: x_0; x_1; ... ; x_n], i.e., we *)
(* have e x_i x_{i+1} for all i < n. The path x :: p starts *)
(* at x and ends at last x p. *)
(* fpath f x p == x :: p is an f-path, where f is a function, i.e., p is of *)
(* the form [:: f x; f (f x); ...]. This is just a notation *)
(* for path (frel f) x p. *)
(* sorted e s == s is an e-sorted sequence: either s = [::], or s = x :: p *)
(* is an e-path (this is often used with e = leq or ltn). *)
(* cycle e c == c is an e-cycle: either c = [::], or c = x :: p with *)
(* x :: (rcons p x) an e-path. *)
(* fcycle f c == c is an f-cycle, for a function f. *)
(* traject f x n == the f-path of size n starting at x *)
(* := [:: x; f x; ...; iter n.-1 f x] *)
(* looping f x n == the f-paths of size greater than n starting at x loop *)
(* back, or, equivalently, traject f x n contains all *)
(* iterates of f at x. *)
(* merge e s1 s2 == the e-sorted merge of sequences s1 and s2: this is always *)
(* a permutation of s1 ++ s2, and is e-sorted when s1 and s2 *)
(* are and e is total. *)
(* sort e s == a permutation of the sequence s, that is e-sorted when e *)
(* is total (computed by a merge sort with the merge function *)
(* above). This sort function is also designed to be stable. *)
(* mem2 s x y == x, then y occur in the sequence (path) s; this is *)
(* non-strict: mem2 s x x = (x \in s). *)
(* next c x == the successor of the first occurrence of x in the sequence *)
(* c (viewed as a cycle), or x if x \notin c. *)
(* prev c x == the predecessor of the first occurrence of x in the *)
(* sequence c (viewed as a cycle), or x if x \notin c. *)
(* arc c x y == the sub-arc of the sequence c (viewed as a cycle) starting *)
(* at the first occurrence of x in c, and ending just before *)
(* the next occurrence of y (in cycle order); arc c x y *)
(* returns an unspecified sub-arc of c if x and y do not both *)
(* occur in c. *)
(* ucycle e c <-> ucycleb e c (ucycle e c is a Coercion target of type Prop) *)
(* ufcycle f c <-> c is a simple f-cycle, for a function f. *)
(* shorten x p == the tail a duplicate-free subpath of x :: p with the same *)
(* endpoints (x and last x p), obtained by removing all loops *)
(* from x :: p. *)
(* rel_base e e' h b <-> the function h is a functor from relation e to *)
(* relation e', EXCEPT at points whose image under h satisfy *)
(* the "base" predicate b: *)
(* e' (h x) (h y) = e x y UNLESS b (h x) holds *)
(* This is the statement of the side condition of the path *)
(* functorial mapping lemma map_path. *)
(* fun_base f f' h b <-> the function h is a functor from function f to f', *)
(* except at the preimage of predicate b under h. *)
(* We also provide three segmenting dependently-typed lemmas (splitP, splitPl *)
(* and splitPr) whose elimination split a path x0 :: p at an internal point x *)
(* as follows: *)
(* - splitP applies when x \in p; it replaces p with (rcons p1 x ++ p2), so *)
(* that x appears explicitly at the end of the left part. The elimination *)
(* of splitP will also simultaneously replace take (index x p) with p1 and *)
(* drop (index x p).+1 p with p2. *)
(* - splitPl applies when x \in x0 :: p; it replaces p with p1 ++ p2 and *)
(* simultaneously generates an equation x = last x0 p1. *)
(* - splitPr applies when x \in p; it replaces p with (p1 ++ x :: p2), so x *)
(* appears explicitly at the start of the right part. *)
(* The parts p1 and p2 are computed using index/take/drop in all cases, but *)
(* only splitP attempts to substitute the explicit values. The substitution *)
(* of p can be deferred using the dependent equation generation feature of *)
(* ssreflect, e.g.: case/splitPr def_p: {1}p / x_in_p => [p1 p2] generates *)
(* the equation p = p1 ++ p2 instead of performing the substitution outright. *)
(* Similarly, eliminating the loop removal lemma shortenP simultaneously *)
(* replaces shorten e x p with a fresh constant p', and last x p with *)
(* last x p'. *)
(* Note that although all "path" functions actually operate on the *)
(* underlying sequence, we provide a series of lemmas that define their *)
(* interaction with the path and cycle predicates, e.g., the cat_path equation*)
(* can be used to split the path predicate after splitting the underlying *)
(* sequence. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Section Paths.
Variables (n0 : nat) (T : Type).
Section Path.
Variables (x0_cycle : T) (e : rel T).
Fixpoint path x (p : seq T) :=
if p is y :: p' then e x y && path y p' else true.
Lemma cat_path x p1 p2 : path x (p1 ++ p2) = path x p1 && path (last x p1) p2.
Proof. by elim: p1 x => [|y p1 Hrec] x //=; rewrite Hrec -!andbA. Qed.
Lemma rcons_path x p y : path x (rcons p y) = path x p && e (last x p) y.
Proof. by rewrite -cats1 cat_path /= andbT. Qed.
Lemma take_path x p i : path x p -> path x (take i p).
Proof. elim: p x i => [//| x p] IHp x' [//| i] /= /andP[-> ?]; exact: IHp. Qed.
Lemma pathP x p x0 :
reflect (forall i, i < size p -> e (nth x0 (x :: p) i) (nth x0 p i))
(path x p).
Proof.
elim: p x => [|y p IHp] x /=; first by left.
apply: (iffP andP) => [[e_xy /IHp e_p [] //] | e_p].
by split; [apply: (e_p 0) | apply/(IHp y) => i; apply: e_p i.+1].
Qed.
Definition cycle p := if p is x :: p' then path x (rcons p' x) else true.
Lemma cycle_path p : cycle p = path (last x0_cycle p) p.
Proof. by case: p => //= x p; rewrite rcons_path andbC. Qed.
Lemma cycle_catC p q : cycle (p ++ q) = cycle (q ++ p).
Proof.
case: p q => [|x p] [|y q]; rewrite /= ?cats0 //=.
by rewrite !rcons_path !cat_path !last_cat /= -!andbA; do !bool_congr.
Qed.
Lemma rot_cycle p : cycle (rot n0 p) = cycle p.
Proof. by rewrite cycle_catC cat_take_drop. Qed.
Lemma rotr_cycle p : cycle (rotr n0 p) = cycle p.
Proof. by rewrite -rot_cycle rotrK. Qed.
Definition sorted s := if s is x :: s' then path x s' else true.
Lemma sortedP s x :
reflect (forall i, i.+1 < size s -> e (nth x s i) (nth x s i.+1)) (sorted s).
Proof. by case: s => *; [constructor|apply: (iffP (pathP _ _ _)); apply]. Qed.
Lemma path_sorted x s : path x s -> sorted s.
Proof. by case: s => //= y s /andP[]. Qed.
Lemma path_min_sorted x s : all (e x) s -> path x s = sorted s.
Proof. by case: s => //= y s /andP [->]. Qed.
Lemma pairwise_sorted s : pairwise e s -> sorted s.
Proof. by elim: s => //= x s IHs /andP[/path_min_sorted -> /IHs]. Qed.
Lemma sorted_cat_cons s1 x s2 :
sorted (s1 ++ x :: s2) = sorted (rcons s1 x) && path x s2.
Proof.
by case: s1 => [ | e1 s1] //=; rewrite -cat_rcons cat_path last_rcons.
Qed.
End Path.
Section PathEq.
Variables (e e' : rel T).
Lemma rev_path x p :
path e (last x p) (rev (belast x p)) = path (fun z => e^~ z) x p.
Proof.
elim: p x => //= y p IHp x; rewrite rev_cons rcons_path -{}IHp andbC.
by rewrite -(last_cons x) -rev_rcons -lastI rev_cons last_rcons.
Qed.
Lemma rev_cycle p : cycle e (rev p) = cycle (fun z => e^~ z) p.
Proof.
case: p => //= x p; rewrite -rev_path last_rcons belast_rcons rev_cons.
by rewrite -[in LHS]cats1 cycle_catC.
Qed.
Lemma rev_sorted p : sorted e (rev p) = sorted (fun z => e^~ z) p.
Proof. by case: p => //= x p; rewrite -rev_path lastI rev_rcons. Qed.
Lemma path_relI x s :
path [rel x y | e x y && e' x y] x s = path e x s && path e' x s.
Proof. by elim: s x => //= y s IHs x; rewrite andbACA IHs. Qed.
Lemma cycle_relI s :
cycle [rel x y | e x y && e' x y] s = cycle e s && cycle e' s.
Proof. by case: s => [|? ?]; last apply: path_relI. Qed.
Lemma sorted_relI s :
sorted [rel x y | e x y && e' x y] s = sorted e s && sorted e' s.
Proof. by case: s; last apply: path_relI. Qed.
End PathEq.
Section SubPath_in.
Variable (P : {pred T}) (e e' : rel T).
Hypothesis (ee' : {in P &, subrel e e'}).
Lemma sub_in_path x s : all P (x :: s) -> path e x s -> path e' x s.
Proof.
by elim: s x => //= y s ihs x /and3P [? ? ?] /andP [/ee' -> //]; apply/ihs/andP.
Qed.
Lemma sub_in_cycle s : all P s -> cycle e s -> cycle e' s.
Proof.
case: s => //= x s /andP [Px Ps].
by apply: sub_in_path; rewrite /= all_rcons Px.
Qed.
Lemma sub_in_sorted s : all P s -> sorted e s -> sorted e' s.
Proof. by case: s => //; apply: sub_in_path. Qed.
End SubPath_in.
Section EqPath_in.
Variable (P : {pred T}) (e e' : rel T).
Hypothesis (ee' : {in P &, e =2 e'}).
Let e_e' : {in P &, subrel e e'}. Proof. by move=> ? ? ? ?; rewrite ee'. Qed.
Let e'_e : {in P &, subrel e' e}. Proof. by move=> ? ? ? ?; rewrite ee'. Qed.
Lemma eq_in_path x s : all P (x :: s) -> path e x s = path e' x s.
Proof. by move=> Pxs; apply/idP/idP; apply: sub_in_path Pxs. Qed.
Lemma eq_in_cycle s : all P s -> cycle e s = cycle e' s.
Proof. by move=> Ps; apply/idP/idP; apply: sub_in_cycle Ps. Qed.
Lemma eq_in_sorted s : all P s -> sorted e s = sorted e' s.
Proof. by move=> Ps; apply/idP/idP; apply: sub_in_sorted Ps. Qed.
End EqPath_in.
Section SubPath.
Variables e e' : rel T.
Lemma sub_path : subrel e e' -> forall x p, path e x p -> path e' x p.
Proof. by move=> ? ? ?; apply/sub_in_path/all_predT; apply: in2W. Qed.
Lemma sub_cycle : subrel e e' -> subpred (cycle e) (cycle e').
Proof. by move=> ee' [] // ? ?; apply: sub_path. Qed.
Lemma sub_sorted : subrel e e' -> subpred (sorted e) (sorted e').
Proof. by move=> ee' [] //=; apply: sub_path. Qed.
Lemma eq_path : e =2 e' -> path e =2 path e'.
Proof. by move=> ? ? ?; apply/eq_in_path/all_predT; apply: in2W. Qed.
Lemma eq_cycle : e =2 e' -> cycle e =1 cycle e'.
Proof. by move=> ee' [] // ? ?; apply: eq_path. Qed.
Lemma eq_sorted : e =2 e' -> sorted e =1 sorted e'.
Proof. by move=> ee' [] // ? ?; apply: eq_path. Qed.
End SubPath.
Section Transitive_in.
Variables (P : {pred T}) (leT : rel T).
Lemma order_path_min_in x s :
{in P & &, transitive leT} -> all P (x :: s) -> path leT x s -> all (leT x) s.
Proof.
move=> leT_tr; elim: s => //= y s ihs /and3P [Px Py Ps] /andP [xy ys].
rewrite xy {}ihs ?Px //=; case: s Ps ys => //= z s /andP [Pz Ps] /andP [yz ->].
by rewrite (leT_tr _ _ _ Py Px Pz).
Qed.
Hypothesis leT_tr : {in P & &, transitive leT}.
Lemma path_sorted_inE x s :
all P (x :: s) -> path leT x s = all (leT x) s && sorted leT s.
Proof.
move=> Pxs; apply/idP/idP => [xs|/andP[/path_min_sorted<-//]].
by rewrite (order_path_min_in leT_tr) //; apply: path_sorted xs.
Qed.
Lemma sorted_pairwise_in s : all P s -> sorted leT s = pairwise leT s.
Proof.
by elim: s => //= x s IHs /andP [Px Ps]; rewrite path_sorted_inE ?IHs //= Px.
Qed.
Lemma path_pairwise_in x s :
all P (x :: s) -> path leT x s = pairwise leT (x :: s).
Proof. by move=> Pxs; rewrite -sorted_pairwise_in. Qed.
Lemma cat_sorted2 s s' : sorted leT (s ++ s') -> sorted leT s * sorted leT s'.
Proof. by case: s => //= x s; rewrite cat_path => /andP[-> /path_sorted]. Qed.
Lemma sorted_mask_in m s : all P s -> sorted leT s -> sorted leT (mask m s).
Proof.
by move=> Ps; rewrite !sorted_pairwise_in ?all_mask //; exact: pairwise_mask.
Qed.
Lemma sorted_filter_in a s : all P s -> sorted leT s -> sorted leT (filter a s).
Proof. rewrite filter_mask; exact: sorted_mask_in. Qed.
Lemma path_mask_in x m s :
all P (x :: s) -> path leT x s -> path leT x (mask m s).
Proof. exact/(sorted_mask_in (true :: m)). Qed.
Lemma path_filter_in x a s :
all P (x :: s) -> path leT x s -> path leT x (filter a s).
Proof. by move=> Pxs; rewrite filter_mask; exact: path_mask_in. Qed.
Lemma sorted_ltn_nth_in x0 s : all P s -> sorted leT s ->
{in [pred n | n < size s] &, {homo nth x0 s : i j / i < j >-> leT i j}}.
Proof. by move=> Ps; rewrite sorted_pairwise_in //; apply/pairwiseP. Qed.
Hypothesis leT_refl : {in P, reflexive leT}.
Lemma sorted_leq_nth_in x0 s : all P s -> sorted leT s ->
{in [pred n | n < size s] &, {homo nth x0 s : i j / i <= j >-> leT i j}}.
Proof.
move=> Ps s_sorted x y xs ys; rewrite leq_eqVlt=> /predU1P[->|].
exact/leT_refl/all_nthP.
exact: sorted_ltn_nth_in.
Qed.
End Transitive_in.
Section Transitive.
Variable (leT : rel T).
Lemma order_path_min x s : transitive leT -> path leT x s -> all (leT x) s.
Proof.
by move=> leT_tr; apply/order_path_min_in/all_predT => //; apply: in3W.
Qed.
Hypothesis leT_tr : transitive leT.
Lemma path_le x x' s : leT x x' -> path leT x' s -> path leT x s.
Proof.
by case: s => [//| x'' s xlex' /= /andP[x'lex'' ->]]; rewrite (leT_tr xlex').
Qed.
Let leT_tr' : {in predT & &, transitive leT}. Proof. exact: in3W. Qed.
Lemma path_sortedE x s : path leT x s = all (leT x) s && sorted leT s.
Proof. exact/path_sorted_inE/all_predT. Qed.
Lemma sorted_pairwise s : sorted leT s = pairwise leT s.
Proof. exact/sorted_pairwise_in/all_predT. Qed.
Lemma path_pairwise x s : path leT x s = pairwise leT (x :: s).
Proof. exact/path_pairwise_in/all_predT. Qed.
Lemma sorted_mask m s : sorted leT s -> sorted leT (mask m s).
Proof. exact/sorted_mask_in/all_predT. Qed.
Lemma sorted_filter a s : sorted leT s -> sorted leT (filter a s).
Proof. exact/sorted_filter_in/all_predT. Qed.
Lemma path_mask x m s : path leT x s -> path leT x (mask m s).
Proof. exact/path_mask_in/all_predT. Qed.
Lemma path_filter x a s : path leT x s -> path leT x (filter a s).
Proof. exact/path_filter_in/all_predT. Qed.
Lemma sorted_ltn_nth x0 s : sorted leT s ->
{in [pred n | n < size s] &, {homo nth x0 s : i j / i < j >-> leT i j}}.
Proof. exact/sorted_ltn_nth_in/all_predT. Qed.
Hypothesis leT_refl : reflexive leT.
Lemma sorted_leq_nth x0 s : sorted leT s ->
{in [pred n | n < size s] &, {homo nth x0 s : i j / i <= j >-> leT i j}}.
Proof. exact/sorted_leq_nth_in/all_predT. Qed.
Lemma take_sorted n s : sorted leT s -> sorted leT (take n s).
Proof. by rewrite -[s in sorted _ s](cat_take_drop n) => /cat_sorted2[]. Qed.
Lemma drop_sorted n s : sorted leT s -> sorted leT (drop n s).
Proof. by rewrite -[s in sorted _ s](cat_take_drop n) => /cat_sorted2[]. Qed.
End Transitive.
End Paths.
Arguments pathP {T e x p}.
Arguments sortedP {T e s}.
Arguments path_sorted {T e x s}.
Arguments path_min_sorted {T e x s}.
Arguments order_path_min_in {T P leT x s}.
Arguments path_sorted_inE {T P leT} leT_tr {x s}.
Arguments sorted_pairwise_in {T P leT} leT_tr {s}.
Arguments path_pairwise_in {T P leT} leT_tr {x s}.
Arguments sorted_mask_in {T P leT} leT_tr {m s}.
Arguments sorted_filter_in {T P leT} leT_tr {a s}.
Arguments path_mask_in {T P leT} leT_tr {x m s}.
Arguments path_filter_in {T P leT} leT_tr {x a s}.
Arguments sorted_ltn_nth_in {T P leT} leT_tr x0 {s}.
Arguments sorted_leq_nth_in {T P leT} leT_tr leT_refl x0 {s}.
Arguments order_path_min {T leT x s}.
Arguments path_sortedE {T leT} leT_tr x s.
Arguments sorted_pairwise {T leT} leT_tr s.
Arguments path_pairwise {T leT} leT_tr x s.
Arguments sorted_mask {T leT} leT_tr m {s}.
Arguments sorted_filter {T leT} leT_tr a {s}.
Arguments path_mask {T leT} leT_tr {x} m {s}.
Arguments path_filter {T leT} leT_tr {x} a {s}.
Arguments sorted_ltn_nth {T leT} leT_tr x0 {s}.
Arguments sorted_leq_nth {T leT} leT_tr leT_refl x0 {s}.
Section HomoPath.
Variables (T T' : Type) (P : {pred T}) (f : T -> T') (e : rel T) (e' : rel T').
Lemma path_map x s : path e' (f x) (map f s) = path (relpre f e') x s.
Proof. by elim: s x => //= y s <-. Qed.
Lemma cycle_map s : cycle e' (map f s) = cycle (relpre f e') s.
Proof. by case: s => //= ? ?; rewrite -map_rcons path_map. Qed.
Lemma sorted_map s : sorted e' (map f s) = sorted (relpre f e') s.
Proof. by case: s; last apply: path_map. Qed.
Lemma homo_path_in x s : {in P &, {homo f : x y / e x y >-> e' x y}} ->
all P (x :: s) -> path e x s -> path e' (f x) (map f s).
Proof. by move=> f_mono; rewrite path_map; apply: sub_in_path. Qed.
Lemma homo_cycle_in s : {in P &, {homo f : x y / e x y >-> e' x y}} ->
all P s -> cycle e s -> cycle e' (map f s).
Proof. by move=> f_mono; rewrite cycle_map; apply: sub_in_cycle. Qed.
Lemma homo_sorted_in s : {in P &, {homo f : x y / e x y >-> e' x y}} ->
all P s -> sorted e s -> sorted e' (map f s).
Proof. by move=> f_mono; rewrite sorted_map; apply: sub_in_sorted. Qed.
Lemma mono_path_in x s : {in P &, {mono f : x y / e x y >-> e' x y}} ->
all P (x :: s) -> path e' (f x) (map f s) = path e x s.
Proof. by move=> f_mono; rewrite path_map; apply: eq_in_path. Qed.
Lemma mono_cycle_in s : {in P &, {mono f : x y / e x y >-> e' x y}} ->
all P s -> cycle e' (map f s) = cycle e s.
Proof. by move=> f_mono; rewrite cycle_map; apply: eq_in_cycle. Qed.
Lemma mono_sorted_in s : {in P &, {mono f : x y / e x y >-> e' x y}} ->
all P s -> sorted e' (map f s) = sorted e s.
Proof. by case: s => // x s; apply: mono_path_in. Qed.
Lemma homo_path x s : {homo f : x y / e x y >-> e' x y} ->
path e x s -> path e' (f x) (map f s).
Proof. by move=> f_homo; rewrite path_map; apply: sub_path. Qed.
Lemma homo_cycle : {homo f : x y / e x y >-> e' x y} ->
{homo map f : s / cycle e s >-> cycle e' s}.
Proof. by move=> f_homo s hs; rewrite cycle_map (sub_cycle _ hs). Qed.
Lemma homo_sorted : {homo f : x y / e x y >-> e' x y} ->
{homo map f : s / sorted e s >-> sorted e' s}.
Proof. by move/homo_path => ? []. Qed.
Lemma mono_path x s : {mono f : x y / e x y >-> e' x y} ->
path e' (f x) (map f s) = path e x s.
Proof. by move=> f_mon; rewrite path_map; apply: eq_path. Qed.
Lemma mono_cycle : {mono f : x y / e x y >-> e' x y} ->
{mono map f : s / cycle e s >-> cycle e' s}.
Proof. by move=> ? ?; rewrite cycle_map; apply: eq_cycle. Qed.
Lemma mono_sorted : {mono f : x y / e x y >-> e' x y} ->
{mono map f : s / sorted e s >-> sorted e' s}.
Proof. by move=> f_mon [] //= x s; apply: mono_path. Qed.
End HomoPath.
Arguments path_map {T T' f e'}.
Arguments cycle_map {T T' f e'}.
Arguments sorted_map {T T' f e'}.
Arguments homo_path_in {T T' P f e e' x s}.
Arguments homo_cycle_in {T T' P f e e' s}.
Arguments homo_sorted_in {T T' P f e e' s}.
Arguments mono_path_in {T T' P f e e' x s}.
Arguments mono_cycle_in {T T' P f e e' s}.
Arguments mono_sorted_in {T T' P f e e' s}.
Arguments homo_path {T T' f e e' x s}.
Arguments homo_cycle {T T' f e e'}.
Arguments homo_sorted {T T' f e e'}.
Arguments mono_path {T T' f e e' x s}.
Arguments mono_cycle {T T' f e e'}.
Arguments mono_sorted {T T' f e e'}.
Section CycleAll2Rel.
Lemma cycle_all2rel (T : Type) (leT : rel T) :
transitive leT -> forall s, cycle leT s = all2rel leT s.
Proof.
move=> leT_tr; elim=> //= x s IHs.
rewrite allrel_cons2 -{}IHs // (path_sortedE leT_tr) /= all_rcons -rev_sorted.
rewrite rev_rcons /= (path_sortedE (rev_trans leT_tr)) all_rev !andbA.
case: (boolP (leT x x && _ && _)) => //=.
case: s => //= y s /and3P[/and3P[_ xy _] yx sx].
rewrite rev_sorted rcons_path /= (leT_tr _ _ _ _ xy) ?andbT //.
by case: (lastP s) sx => //= {}s z; rewrite all_rcons last_rcons => /andP [->].
Qed.
Lemma cycle_all2rel_in (T : Type) (P : {pred T}) (leT : rel T) :
{in P & &, transitive leT} ->
forall s, all P s -> cycle leT s = all2rel leT s.
Proof.
move=> /in3_sig leT_tr _ /all_sigP [s ->].
by rewrite cycle_map allrel_mapl allrel_mapr; apply: cycle_all2rel.
Qed.
End CycleAll2Rel.
Section PreInSuffix.
Variables (T : eqType) (e : rel T).
Implicit Type s : seq T.
Local Notation path := (path e).
Local Notation sorted := (sorted e).
Lemma prefix_path x s1 s2 : prefix s1 s2 -> path x s2 -> path x s1.
Proof. by rewrite prefixE => /eqP <-; exact: take_path. Qed.
Lemma prefix_sorted s1 s2 : prefix s1 s2 -> sorted s2 -> sorted s1.
Proof. by rewrite prefixE => /eqP <-; exact: take_sorted. Qed.
Lemma infix_sorted s1 s2 : infix s1 s2 -> sorted s2 -> sorted s1.
Proof. by rewrite infixE => /eqP <- ?; apply/take_sorted/drop_sorted. Qed.
Lemma suffix_sorted s1 s2 : suffix s1 s2 -> sorted s2 -> sorted s1.
Proof. by rewrite suffixE => /eqP <-; exact: drop_sorted. Qed.
End PreInSuffix.
Section EqSorted.
Variables (T : eqType) (leT : rel T).
Implicit Type s : seq T.
Local Notation path := (path leT).
Local Notation sorted := (sorted leT).
Lemma subseq_path_in x s1 s2 :
{in x :: s2 & &, transitive leT} -> subseq s1 s2 -> path x s2 -> path x s1.
Proof. by move=> tr /subseqP [m _ ->]; apply/(path_mask_in tr). Qed.
Lemma subseq_sorted_in s1 s2 :
{in s2 & &, transitive leT} -> subseq s1 s2 -> sorted s2 -> sorted s1.
Proof. by move=> tr /subseqP [m _ ->]; apply/(sorted_mask_in tr). Qed.
Lemma sorted_ltn_index_in s : {in s & &, transitive leT} -> sorted s ->
{in s &, forall x y, index x s < index y s -> leT x y}.
Proof.
case: s => // x0 s' leT_tr s_sorted x y xs ys.
move/(sorted_ltn_nth_in leT_tr x0 (allss (_ :: _)) s_sorted).
by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply.
Qed.
Lemma sorted_leq_index_in s :
{in s & &, transitive leT} -> {in s, reflexive leT} -> sorted s ->
{in s &, forall x y, index x s <= index y s -> leT x y}.
Proof.
case: s => // x0 s' leT_tr leT_refl s_sorted x y xs ys.
move/(sorted_leq_nth_in leT_tr leT_refl x0 (allss (_ :: _)) s_sorted).
by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply.
Qed.
Hypothesis leT_tr : transitive leT.
Lemma subseq_path x s1 s2 : subseq s1 s2 -> path x s2 -> path x s1.
Proof. by apply: subseq_path_in; apply: in3W. Qed.
Lemma subseq_sorted s1 s2 : subseq s1 s2 -> sorted s2 -> sorted s1.
Proof. by apply: subseq_sorted_in; apply: in3W. Qed.
Lemma sorted_uniq : irreflexive leT -> forall s, sorted s -> uniq s.
Proof. by move=> irr s; rewrite sorted_pairwise //; apply/pairwise_uniq. Qed.
Lemma sorted_eq : antisymmetric leT ->
forall s1 s2, sorted s1 -> sorted s2 -> perm_eq s1 s2 -> s1 = s2.
Proof.
by move=> leT_asym s1 s2; rewrite !sorted_pairwise //; apply: pairwise_eq.
Qed.
Lemma irr_sorted_eq : irreflexive leT ->
forall s1 s2, sorted s1 -> sorted s2 -> s1 =i s2 -> s1 = s2.
Proof.
move=> leT_irr s1 s2 s1_sort s2_sort eq_s12.
have: antisymmetric leT.
by move=> m n /andP[? ltnm]; case/idP: (leT_irr m); apply: leT_tr ltnm.
by move/sorted_eq; apply=> //; apply: uniq_perm => //; apply: sorted_uniq.
Qed.
Lemma sorted_ltn_index s :
sorted s -> {in s &, forall x y, index x s < index y s -> leT x y}.
Proof.
case: s => // x0 s' s_sorted x y xs ys /(sorted_ltn_nth leT_tr x0 s_sorted).
by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply.
Qed.
Lemma undup_path x s : path x s -> path x (undup s).
Proof. exact/subseq_path/undup_subseq. Qed.
Lemma undup_sorted s : sorted s -> sorted (undup s).
Proof. exact/subseq_sorted/undup_subseq. Qed.
Hypothesis leT_refl : reflexive leT.
Lemma sorted_leq_index s :
sorted s -> {in s &, forall x y, index x s <= index y s -> leT x y}.
Proof.
case: s => // x0 s' s_sorted x y xs ys.
move/(sorted_leq_nth leT_tr leT_refl x0 s_sorted).
by rewrite ?nth_index ?[_ \in gtn _]index_mem //; apply.
Qed.
End EqSorted.
Arguments sorted_ltn_index_in {T leT s} leT_tr s_sorted.
Arguments sorted_leq_index_in {T leT s} leT_tr leT_refl s_sorted.
Arguments sorted_ltn_index {T leT} leT_tr {s}.
Arguments sorted_leq_index {T leT} leT_tr leT_refl {s}.
Section EqSorted_in.
Variables (T : eqType) (leT : rel T).
Implicit Type s : seq T.
Lemma sorted_uniq_in s :
{in s & &, transitive leT} -> {in s, irreflexive leT} ->
sorted leT s -> uniq s.
Proof.
move=> /in3_sig leT_tr /in1_sig leT_irr; case/all_sigP: (allss s) => s' ->.
by rewrite sorted_map (map_inj_uniq val_inj); exact: sorted_uniq.
Qed.
Lemma sorted_eq_in s1 s2 :
{in s1 & &, transitive leT} -> {in s1 &, antisymmetric leT} ->
sorted leT s1 -> sorted leT s2 -> perm_eq s1 s2 -> s1 = s2.
Proof.
move=> /in3_sig leT_tr /in2_sig/(_ _ _ _)/val_inj leT_anti + + /[dup] s1s2.
have /all_sigP[s1' ->] := allss s1.
have /all_sigP[{s1s2}s2 ->] : all [in s1] s2 by rewrite -(perm_all _ s1s2).
by rewrite !sorted_map => ss1' ss2 /(perm_map_inj val_inj)/(sorted_eq leT_tr)->.
Qed.
Lemma irr_sorted_eq_in s1 s2 :
{in s1 & &, transitive leT} -> {in s1, irreflexive leT} ->
sorted leT s1 -> sorted leT s2 -> s1 =i s2 -> s1 = s2.
Proof.
move=> /in3_sig leT_tr /in1_sig leT_irr + + /[dup] s1s2.
have /all_sigP[s1' ->] := allss s1.
have /all_sigP[s2' ->] : all [in s1] s2 by rewrite -(eq_all_r s1s2).
rewrite !sorted_map => ss1' ss2' {}s1s2; congr map.
by apply: (irr_sorted_eq leT_tr) => // x; rewrite -!(mem_map val_inj).
Qed.
End EqSorted_in.
Section EqPath.
Variables (n0 : nat) (T : eqType) (e : rel T).
Implicit Type p : seq T.
Variant split x : seq T -> seq T -> seq T -> Type :=
Split p1 p2 : split x (rcons p1 x ++ p2) p1 p2.
Lemma splitP p x (i := index x p) :
x \in p -> split x p (take i p) (drop i.+1 p).
Proof. by rewrite -has_pred1 => /split_find[? ? ? /eqP->]; constructor. Qed.
Variant splitl x1 x : seq T -> Type :=
Splitl p1 p2 of last x1 p1 = x : splitl x1 x (p1 ++ p2).
Lemma splitPl x1 p x : x \in x1 :: p -> splitl x1 x p.
Proof.
rewrite inE; case: eqP => [->| _ /splitP[]]; first by rewrite -(cat0s p).
by split; apply: last_rcons.
Qed.
Variant splitr x : seq T -> Type :=
Splitr p1 p2 : splitr x (p1 ++ x :: p2).
Lemma splitPr p x : x \in p -> splitr x p.
Proof. by case/splitP=> p1 p2; rewrite cat_rcons. Qed.
Fixpoint next_at x y0 y p :=
match p with
| [::] => if x == y then y0 else x
| y' :: p' => if x == y then y' else next_at x y0 y' p'
end.
Definition next p x := if p is y :: p' then next_at x y y p' else x.
Fixpoint prev_at x y0 y p :=
match p with
| [::] => if x == y0 then y else x
| y' :: p' => if x == y' then y else prev_at x y0 y' p'
end.
Definition prev p x := if p is y :: p' then prev_at x y y p' else x.
Lemma next_nth p x :
next p x = if x \in p then
if p is y :: p' then nth y p' (index x p) else x
else x.
Proof.
case: p => //= y0 p.
elim: p {2 3 5}y0 => [|y' p IHp] y /=; rewrite (eq_sym y) inE;
by case: ifP => // _; apply: IHp.
Qed.
Lemma prev_nth p x :
prev p x = if x \in p then
if p is y :: p' then nth y p (index x p') else x
else x.
Proof.
case: p => //= y0 p; rewrite inE orbC.
elim: p {2 5}y0 => [|y' p IHp] y; rewrite /= ?inE // (eq_sym y').
by case: ifP => // _; apply: IHp.
Qed.
Lemma mem_next p x : (next p x \in p) = (x \in p).
Proof.
rewrite next_nth; case p_x: (x \in p) => //.
case: p (index x p) p_x => [|y0 p'] //= i _; rewrite inE.
have [lt_ip | ge_ip] := ltnP i (size p'); first by rewrite orbC mem_nth.
by rewrite nth_default ?eqxx.
Qed.
Lemma mem_prev p x : (prev p x \in p) = (x \in p).
Proof.
rewrite prev_nth; case p_x: (x \in p) => //; case: p => [|y0 p] // in p_x *.
by apply mem_nth; rewrite /= ltnS index_size.
Qed.
(* ucycleb is the boolean predicate, but ucycle is defined as a Prop *)
(* so that it can be used as a coercion target. *)
Definition ucycleb p := cycle e p && uniq p.
Definition ucycle p : Prop := cycle e p && uniq p.
(* Projections, used for creating local lemmas. *)
Lemma ucycle_cycle p : ucycle p -> cycle e p.
Proof. by case/andP. Qed.
Lemma ucycle_uniq p : ucycle p -> uniq p.
Proof. by case/andP. Qed.
Lemma next_cycle p x : cycle e p -> x \in p -> e x (next p x).
Proof.
case: p => //= y0 p; elim: p {1 3 5}y0 => [|z p IHp] y /=; rewrite inE.
by rewrite andbT; case: (x =P y) => // ->.
by case/andP=> eyz /IHp; case: (x =P y) => // ->.
Qed.
Lemma prev_cycle p x : cycle e p -> x \in p -> e (prev p x) x.
Proof.
case: p => //= y0 p; rewrite inE orbC.
elim: p {1 5}y0 => [|z p IHp] y /=; rewrite ?inE.
by rewrite andbT; case: (x =P y0) => // ->.
by case/andP=> eyz /IHp; case: (x =P z) => // ->.
Qed.
Lemma rot_ucycle p : ucycle (rot n0 p) = ucycle p.
Proof. by rewrite /ucycle rot_uniq rot_cycle. Qed.
Lemma rotr_ucycle p : ucycle (rotr n0 p) = ucycle p.
Proof. by rewrite /ucycle rotr_uniq rotr_cycle. Qed.
(* The "appears no later" partial preorder defined by a path. *)
Definition mem2 p x y := y \in drop (index x p) p.
Lemma mem2l p x y : mem2 p x y -> x \in p.
Proof.
by rewrite /mem2 -!index_mem size_drop ltn_subRL; apply/leq_ltn_trans/leq_addr.
Qed.
Lemma mem2lf {p x y} : x \notin p -> mem2 p x y = false.
Proof. exact/contraNF/mem2l. Qed.
Lemma mem2r p x y : mem2 p x y -> y \in p.
Proof.
by rewrite -[in y \in p](cat_take_drop (index x p) p) mem_cat orbC /mem2 => ->.
Qed.
Lemma mem2rf {p x y} : y \notin p -> mem2 p x y = false.
Proof. exact/contraNF/mem2r. Qed.
Lemma mem2_cat p1 p2 x y :
mem2 (p1 ++ p2) x y = mem2 p1 x y || mem2 p2 x y || (x \in p1) && (y \in p2).
Proof.
rewrite [LHS]/mem2 index_cat fun_if if_arg !drop_cat addKn.
case: ifPn => [p1x | /mem2lf->]; last by rewrite ltnNge leq_addr orbF.
by rewrite index_mem p1x mem_cat -orbA (orb_idl (@mem2r _ _ _)).
Qed.
Lemma mem2_splice p1 p3 x y p2 :
mem2 (p1 ++ p3) x y -> mem2 (p1 ++ p2 ++ p3) x y.
Proof.
by rewrite !mem2_cat mem_cat andb_orr orbC => /or3P[]->; rewrite ?orbT.
Qed.
Lemma mem2_splice1 p1 p3 x y z :
mem2 (p1 ++ p3) x y -> mem2 (p1 ++ z :: p3) x y.
Proof. exact: mem2_splice [::z]. Qed.
Lemma mem2_cons x p y z :
mem2 (x :: p) y z = (if x == y then z \in x :: p else mem2 p y z).
Proof. by rewrite [LHS]/mem2 /=; case: ifP. Qed.
Lemma mem2_seq1 x y z : mem2 [:: x] y z = (y == x) && (z == x).
Proof. by rewrite mem2_cons eq_sym inE. Qed.
Lemma mem2_last y0 p x : mem2 p x (last y0 p) = (x \in p).
Proof.
apply/idP/idP; first exact: mem2l; rewrite -index_mem /mem2 => p_x.
by rewrite -nth_last -(subnKC p_x) -nth_drop mem_nth // size_drop subnSK.
Qed.
Lemma mem2l_cat {p1 p2 x} : x \notin p1 -> mem2 (p1 ++ p2) x =1 mem2 p2 x.
Proof. by move=> p1'x y; rewrite mem2_cat (negPf p1'x) mem2lf ?orbF. Qed.
Lemma mem2r_cat {p1 p2 x y} : y \notin p2 -> mem2 (p1 ++ p2) x y = mem2 p1 x y.
Proof.
by move=> p2'y; rewrite mem2_cat (negPf p2'y) -orbA orbC andbF mem2rf.
Qed.
Lemma mem2lr_splice {p1 p2 p3 x y} :
x \notin p2 -> y \notin p2 -> mem2 (p1 ++ p2 ++ p3) x y = mem2 (p1 ++ p3) x y.
Proof.
move=> p2'x p2'y; rewrite catA !mem2_cat !mem_cat.
by rewrite (negPf p2'x) (negPf p2'y) (mem2lf p2'x) andbF !orbF.
Qed.
Lemma mem2E s x y :
mem2 s x y = subseq (if x == y then [:: x] else [:: x; y]) s.
Proof.
elim: s => [| h s]; first by case: ifP.
rewrite mem2_cons => ->.
do 2 rewrite inE (fun_if subseq) !if_arg !sub1seq /=.
by have [->|] := eqVneq; case: eqVneq.
Qed.
Variant split2r x y : seq T -> Type :=
Split2r p1 p2 of y \in x :: p2 : split2r x y (p1 ++ x :: p2).
Lemma splitP2r p x y : mem2 p x y -> split2r x y p.
Proof.
move=> pxy; have px := mem2l pxy.
have:= pxy; rewrite /mem2 (drop_nth x) ?index_mem ?nth_index //.
by case/splitP: px => p1 p2; rewrite cat_rcons.
Qed.
Fixpoint shorten x p :=
if p is y :: p' then
if x \in p then shorten x p' else y :: shorten y p'
else [::].
Variant shorten_spec x p : T -> seq T -> Type :=
ShortenSpec p' of path e x p' & uniq (x :: p') & {subset p' <= p} :
shorten_spec x p (last x p') p'.
Lemma shortenP x p : path e x p -> shorten_spec x p (last x p) (shorten x p).
Proof.
move=> e_p; have: x \in x :: p by apply: mem_head.
elim: p x {1 3 5}x e_p => [|y2 p IHp] x y1.
by rewrite mem_seq1 => _ /eqP->.
rewrite inE orbC /= => /andP[ey12 {}/IHp IHp].
case: ifPn => [y2p_x _ | not_y2p_x /eqP def_x].
have [p' e_p' Up' p'p] := IHp _ y2p_x.
by split=> // y /p'p; apply: predU1r.
have [p' e_p' Up' p'p] := IHp y2 (mem_head y2 p).
have{} p'p z: z \in y2 :: p' -> z \in y2 :: p.
by rewrite !inE; case: (z == y2) => // /p'p.
rewrite -(last_cons y1) def_x; split=> //=; first by rewrite ey12.
by rewrite (contra (p'p y1)) -?def_x.
Qed.
End EqPath.
(* Ordered paths and sorting. *)
Section SortSeq.
Variables (T : Type) (leT : rel T).
Fixpoint merge s1 :=
if s1 is x1 :: s1' then
let fix merge_s1 s2 :=
if s2 is x2 :: s2' then
if leT x1 x2 then x1 :: merge s1' s2 else x2 :: merge_s1 s2'
else s1 in
merge_s1
else id.
Arguments merge !s1 !s2 : rename.
Fixpoint merge_sort_push s1 ss :=
match ss with
| [::] :: ss' | [::] as ss' => s1 :: ss'
| s2 :: ss' => [::] :: merge_sort_push (merge s2 s1) ss'
end.
Fixpoint merge_sort_pop s1 ss :=
if ss is s2 :: ss' then merge_sort_pop (merge s2 s1) ss' else s1.
Fixpoint merge_sort_rec ss s :=
if s is [:: x1, x2 & s'] then
let s1 := if leT x1 x2 then [:: x1; x2] else [:: x2; x1] in
merge_sort_rec (merge_sort_push s1 ss) s'
else merge_sort_pop s ss.
Definition sort := merge_sort_rec [::].
(* The following definition `sort_rec1` is an auxiliary function for *)
(* inductive reasoning on `sort`. One can rewrite `sort le s` to *)
(* `sort_rec1 le [::] s` by `sortE` and apply the simple structural induction *)
(* on `s` to reason about it. *)
Fixpoint sort_rec1 ss s :=
if s is x :: s then sort_rec1 (merge_sort_push [:: x] ss) s else
merge_sort_pop [::] ss.
Lemma sortE s : sort s = sort_rec1 [::] s.
Proof.
transitivity (sort_rec1 [:: nil] s); last by case: s.
rewrite /sort; move: [::] {2}_.+1 (ltnSn (size s)./2) => ss n.
by elim: n => // n IHn in ss s *; case: s => [|x [|y s]] //= /IHn->.
Qed.
Lemma count_merge (p : pred T) s1 s2 :
count p (merge s1 s2) = count p (s1 ++ s2).
Proof.
rewrite count_cat; elim: s1 s2 => // x s1 IH1.
elim=> //= [|y s2 IH2]; first by rewrite addn0.
by case: leT; rewrite /= ?IH1 ?IH2 !addnA [_ + p y]addnAC [p x + p y]addnC.
Qed.
Lemma size_merge s1 s2 : size (merge s1 s2) = size (s1 ++ s2).
Proof. exact: (count_merge predT). Qed.
Lemma allrel_merge s1 s2 : allrel leT s1 s2 -> merge s1 s2 = s1 ++ s2.
Proof.
elim: s1 s2 => [|x s1 IHs1] [|y s2]; rewrite ?cats0 //=.
by rewrite allrel_consl /= -andbA => /and3P [-> _ /IHs1->].
Qed.
Lemma count_sort (p : pred T) s : count p (sort s) = count p s.
Proof.
rewrite sortE -[RHS]/(sumn [seq count p x | x <- [::]] + count p s).
elim: s [::] => [|x s ihs] ss.
rewrite [LHS]/=; elim: ss [::] => //= s ss ihss t.
by rewrite ihss count_merge count_cat addnCA addnA.
rewrite {}ihs -[in RHS]cat1s count_cat addnA; congr addn; rewrite addnC.
elim: {x s} ss [:: x] => [|[|x s] ss ihss] t //.
by rewrite [LHS]/= add0n ihss count_merge count_cat -addnA addnCA.
Qed.
Lemma pairwise_sort s : pairwise leT s -> sort s = s.
Proof.
pose catss := foldr (fun x => cat ^~ x) (Nil T).
rewrite -{1 3}[s]/(catss [::] ++ s) sortE; elim: s [::] => /= [|x s ihs] ss.
elim: ss [::] => //= s ss ihss t; rewrite -catA => ssst.
rewrite -ihss ?allrel_merge //; move: ssst; rewrite !pairwise_cat.
by case/and4P.
rewrite (catA _ [:: _]) => ssxs.
suff x_ss_E: catss (merge_sort_push [:: x] ss) = catss ([:: x] :: ss).
by rewrite -[catss _ ++ _]/(catss ([:: x] :: ss)) -x_ss_E ihs // x_ss_E.
move: ssxs; rewrite pairwise_cat => /and3P [_ + _].
elim: ss [:: x] => {x s ihs} //= -[|x s] ss ihss t h_pairwise;
rewrite /= cats0 // allrel_merge ?ihss ?catA //.
by move: h_pairwise; rewrite -catA !pairwise_cat => /and4P [].
Qed.
Remark size_merge_sort_push s1 :
let graded ss := forall i, size (nth [::] ss i) \in pred2 0 (2 ^ (i + 1)) in
size s1 = 2 -> {homo merge_sort_push s1 : ss / graded ss}.
Proof.
set n := {2}1; rewrite -[RHS]/(2 ^ n) => graded sz_s1 ss.
elim: ss => [|s2 ss IHss] in (n) graded s1 sz_s1 * => sz_ss i //=.
by case: i => [|[]] //; rewrite sz_s1 inE eqxx orbT.
case: s2 i => [|x s2] [|i] //= in sz_ss *; first by rewrite sz_s1 inE eqxx orbT.
exact: (sz_ss i.+1).
rewrite addSnnS; apply: IHss i => [|i]; last by rewrite -addSnnS (sz_ss i.+1).
by rewrite size_merge size_cat sz_s1 (eqP (sz_ss 0)) addnn expnS mul2n.
Qed.
Section Stability.
Variable leT' : rel T.
Hypothesis (leT_total : total leT) (leT'_tr : transitive leT').
Let leT_lex := [rel x y | leT x y && (leT y x ==> leT' x y)].
Lemma merge_stable_path x s1 s2 :
allrel leT' s1 s2 -> path leT_lex x s1 -> path leT_lex x s2 ->
path leT_lex x (merge s1 s2).
Proof.
elim: s1 s2 x => //= x s1 ih1; elim => //= y s2 ih2 h.
rewrite allrel_cons2 => /and4P [xy' xs2 ys1 s1s2] /andP [hx xs1] /andP [hy ys2].
case: ifP => xy /=; rewrite (hx, hy) /=.
- by apply: ih1; rewrite ?allrel_consr ?ys1 //= xy xy' implybT.
- by apply: ih2; have:= leT_total x y; rewrite ?allrel_consl ?xs2 ?xy //= => ->.
Qed.
Lemma merge_stable_sorted s1 s2 :
allrel leT' s1 s2 -> sorted leT_lex s1 -> sorted leT_lex s2 ->
sorted leT_lex (merge s1 s2).
Proof.
case: s1 s2 => [|x s1] [|y s2] //=; rewrite allrel_consl allrel_consr /= -andbA.
case/and4P => [xy' xs2 ys1 s1s2] xs1 ys2; rewrite -/(merge (_ :: _)).
by case: ifP (leT_total x y) => /= xy yx; apply/merge_stable_path;
rewrite /= ?(allrel_consl, allrel_consr, xs2, ys1, xy, yx, xy', implybT).
Qed.
End Stability.
Hypothesis leT_total : total leT.
Let leElex : leT =2 [rel x y | leT x y && (leT y x ==> true)].
Proof. by move=> ? ? /=; rewrite implybT andbT. Qed.
Lemma merge_path x s1 s2 :
path leT x s1 -> path leT x s2 -> path leT x (merge s1 s2).
Proof. by rewrite !(eq_path leElex); apply/merge_stable_path/allrelT. Qed.
Lemma merge_sorted s1 s2 :
sorted leT s1 -> sorted leT s2 -> sorted leT (merge s1 s2).
Proof. by rewrite !(eq_sorted leElex); apply/merge_stable_sorted/allrelT. Qed.
Hypothesis leT_tr : transitive leT.
Lemma sorted_merge s t : sorted leT (s ++ t) -> merge s t = s ++ t.
Proof. by rewrite sorted_pairwise // pairwise_cat => /and3P[/allrel_merge]. Qed.
Lemma sorted_sort s : sorted leT s -> sort s = s.
Proof. by rewrite sorted_pairwise //; apply/pairwise_sort. Qed.
Lemma mergeA : associative merge.
Proof.
elim=> // x xs IHxs; elim=> // y ys IHys; elim=> [|z zs IHzs] /=.
by case: ifP.
case: ifP; case: ifP => /= lexy leyz.
- by rewrite lexy (leT_tr lexy leyz) -IHxs /= leyz.
- by rewrite lexy leyz -IHys.
- case: ifP => lexz; first by rewrite -IHxs //= leyz.
by rewrite -!/(merge (_ :: _)) IHzs /= lexy.
- suff->: leT x z = false by rewrite leyz // -!/(merge (_ :: _)) IHzs /= lexy.
by apply/contraFF/leT_tr: leyz; have := leT_total x y; rewrite lexy.
Qed.
End SortSeq.
Arguments merge {T} relT !s1 !s2 : rename.
Arguments size_merge {T} leT s1 s2.
Arguments allrel_merge {T leT s1 s2}.
Arguments pairwise_sort {T leT s}.
Arguments merge_path {T leT} leT_total {x s1 s2}.
Arguments merge_sorted {T leT} leT_total {s1 s2}.
Arguments sorted_merge {T leT} leT_tr {s t}.
Arguments sorted_sort {T leT} leT_tr {s}.
Arguments mergeA {T leT} leT_total leT_tr.
Section SortMap.
Variables (T T' : Type) (f : T' -> T).
Section Monotonicity.
Variables (leT' : rel T') (leT : rel T).
Hypothesis f_mono : {mono f : x y / leT' x y >-> leT x y}.
Lemma map_merge : {morph map f : s1 s2 / merge leT' s1 s2 >-> merge leT s1 s2}.
Proof.
elim=> //= x s1 IHs1; elim => [|y s2 IHs2] //=; rewrite f_mono.
by case: leT'; rewrite /= ?IHs1 ?IHs2.
Qed.
Lemma map_sort : {morph map f : s1 / sort leT' s1 >-> sort leT s1}.
Proof.
move=> s; rewrite !sortE -[[::] in RHS]/(map (map f) [::]).
elim: s [::] => /= [|x s ihs] ss; rewrite -/(map f [::]) -/(map f [:: _]);
first by elim: ss [::] => //= x ss ihss ?; rewrite ihss map_merge.
rewrite ihs -/(map f [:: x]); congr sort_rec1.
by elim: ss [:: x] => {x s ihs} [|[|x s] ss ihss] //= ?; rewrite ihss map_merge.
Qed.
End Monotonicity.
Variable leT : rel T.
Lemma merge_map s1 s2 :
merge leT (map f s1) (map f s2) = map f (merge (relpre f leT) s1 s2).
Proof. exact/esym/map_merge. Qed.
Lemma sort_map s : sort leT (map f s) = map f (sort (relpre f leT) s).
Proof. exact/esym/map_sort. Qed.
End SortMap.
Arguments map_merge {T T' f leT' leT}.
Arguments map_sort {T T' f leT' leT}.
Arguments merge_map {T T' f leT}.
Arguments sort_map {T T' f leT}.
Lemma sorted_sort_in T (P : {pred T}) (leT : rel T) :
{in P & &, transitive leT} ->
forall s : seq T, all P s -> sorted leT s -> sort leT s = s.
Proof.
move=> /in3_sig ? _ /all_sigP[s ->].
by rewrite sort_map sorted_map => /sorted_sort->.
Qed.
Arguments sorted_sort_in {T P leT} leT_tr {s}.
Section EqSortSeq.
Variables (T : eqType) (leT : rel T).
Lemma perm_merge s1 s2 : perm_eql (merge leT s1 s2) (s1 ++ s2).
Proof. by apply/permPl/permP => ?; rewrite count_merge. Qed.
Lemma mem_merge s1 s2 : merge leT s1 s2 =i s1 ++ s2.
Proof. by apply: perm_mem; rewrite perm_merge. Qed.
Lemma merge_uniq s1 s2 : uniq (merge leT s1 s2) = uniq (s1 ++ s2).
Proof. by apply: perm_uniq; rewrite perm_merge. Qed.
Lemma perm_sort s : perm_eql (sort leT s) s.
Proof. by apply/permPl/permP => ?; rewrite count_sort. Qed.
Lemma mem_sort s : sort leT s =i s. Proof. exact/perm_mem/permPl/perm_sort. Qed.
Lemma sort_uniq s : uniq (sort leT s) = uniq s.
Proof. exact/perm_uniq/permPl/perm_sort. Qed.
Lemma eq_count_merge (p : pred T) s1 s1' s2 s2' :
count p s1 = count p s1' -> count p s2 = count p s2' ->
count p (merge leT s1 s2) = count p (merge leT s1' s2').
Proof. by rewrite !count_merge !count_cat => -> ->. Qed.
End EqSortSeq.
Lemma perm_iota_sort (T : Type) (leT : rel T) x0 s :
{i_s : seq nat | perm_eq i_s (iota 0 (size s)) &
sort leT s = map (nth x0 s) i_s}.
Proof.
exists (sort (relpre (nth x0 s) leT) (iota 0 (size s))).
by rewrite perm_sort.
by rewrite -[s in LHS](mkseq_nth x0) sort_map.
Qed.
Lemma all_merge (T : Type) (P : {pred T}) (leT : rel T) s1 s2 :
all P (merge leT s1 s2) = all P s1 && all P s2.
Proof.
elim: s1 s2 => //= x s1 IHs1; elim=> [|y s2 IHs2]; rewrite ?andbT //=.
by case: ifP => _; rewrite /= ?IHs1 ?IHs2 //=; bool_congr.
Qed.
Lemma all_sort (T : Type) (P : {pred T}) (leT : rel T) s :
all P (sort leT s) = all P s.
Proof.
case: s => // x s; move: (x :: s) => {}s.
by rewrite -(mkseq_nth x s) sort_map !all_map; apply/perm_all/permPl/perm_sort.
Qed.
Lemma size_sort (T : Type) (leT : rel T) s : size (sort leT s) = size s.
Proof. exact: (count_sort _ predT). Qed.
Lemma ltn_sorted_uniq_leq s : sorted ltn s = uniq s && sorted leq s.
Proof.
rewrite (sorted_pairwise leq_trans) (sorted_pairwise ltn_trans) uniq_pairwise.
by rewrite -pairwise_relI; apply/eq_pairwise => ? ?; rewrite ltn_neqAle.
Qed.
Lemma gtn_sorted_uniq_geq s : sorted gtn s = uniq s && sorted geq s.
Proof. by rewrite -rev_sorted ltn_sorted_uniq_leq rev_sorted rev_uniq. Qed.
Lemma iota_sorted i n : sorted leq (iota i n).
Proof. by elim: n i => // [[|n] //= IHn] i; rewrite IHn leqW. Qed.
Lemma iota_ltn_sorted i n : sorted ltn (iota i n).
Proof. by rewrite ltn_sorted_uniq_leq iota_sorted iota_uniq. Qed.
Section Stability_iota.
Variables (leN : rel nat) (leN_total : total leN).
Let lt_lex := [rel n m | leN n m && (leN m n ==> (n < m))].
Let Fixpoint push_invariant (ss : seq (seq nat)) :=
if ss is s :: ss' then
[&& sorted lt_lex s, allrel gtn s (flatten ss') & push_invariant ss']
else
true.
Let push_stable s1 ss :
push_invariant (s1 :: ss) -> push_invariant (merge_sort_push leN s1 ss).
Proof.
elim: ss s1 => [] // [] //= m s2 ss ihss s1; rewrite -cat_cons allrel_catr.
move=> /and5P[sorted_s1 /andP[s1s2 s1ss] sorted_s2 s2ss hss]; apply: ihss.
rewrite /= hss andbT merge_stable_sorted //=; last by rewrite allrelC.
by apply/allrelP => ? ?; rewrite mem_merge mem_cat => /orP[]; apply/allrelP.
Qed.
Let pop_stable s1 ss :
push_invariant (s1 :: ss) -> sorted lt_lex (merge_sort_pop leN s1 ss).
Proof.
elim: ss s1 => [s1 /and3P[]|s2 ss ihss s1] //=; rewrite allrel_catr.
move=> /and5P[sorted_s1 /andP[s1s2 s1ss] sorted_s2 s2ss hss]; apply: ihss.
rewrite /= hss andbT merge_stable_sorted //=; last by rewrite allrelC.
by apply/allrelP => ? ?; rewrite mem_merge mem_cat => /orP[]; apply/allrelP.
Qed.
Lemma sort_iota_stable n : sorted lt_lex (sort leN (iota 0 n)).
Proof.
rewrite sortE.
have/andP[]: all (gtn 0) (flatten [::]) && push_invariant [::] by [].
elim: n 0 [::] => [|n ihn] m ss hss1 hss2; first exact: pop_stable.
apply/ihn/push_stable; last by rewrite /= allrel1l hss1.
have: all (gtn m.+1) (flatten ([:: m] :: ss)).
by rewrite /= leqnn; apply: sub_all hss1 => ? /leqW.
elim: ss [:: _] {hss1 hss2} => [|[|? ?] ? ihss] //= ? ?.
by rewrite ihss //= all_cat all_merge -andbA andbCA -!all_cat.
Qed.
End Stability_iota.
Lemma sort_pairwise_stable T (leT leT' : rel T) :
total leT -> forall s : seq T, pairwise leT' s ->
sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s).
Proof.
move=> leT_total s pairwise_s; case Ds: s => // [x s1].
rewrite -{s1}Ds -(mkseq_nth x s) sort_map.
apply/homo_sorted_in/sort_iota_stable/(fun _ _ => leT_total _ _)/allss => y z.
rewrite !mem_sort !mem_iota !leq0n add0n /= => ys zs /andP [->] /=.
by case: (leT _ _); first apply: pairwiseP.
Qed.
Lemma sort_stable T (leT leT' : rel T) :
total leT -> transitive leT' -> forall s : seq T, sorted leT' s ->
sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s).
Proof.
move=> leT_total leT'_tr s; rewrite sorted_pairwise //.
exact: sort_pairwise_stable.
Qed.
Lemma sort_stable_in T (P : {pred T}) (leT leT' : rel T) :
{in P &, total leT} -> {in P & &, transitive leT'} ->
forall s : seq T, all P s -> sorted leT' s ->
sorted [rel x y | leT x y && (leT y x ==> leT' x y)] (sort leT s).
Proof.
move=> /in2_sig leT_total /in3_sig leT_tr _ /all_sigP[s ->].
by rewrite sort_map !sorted_map; apply: sort_stable.
Qed.
Lemma filter_sort T (leT : rel T) :
total leT -> transitive leT ->
forall p s, filter p (sort leT s) = sort leT (filter p s).
Proof.
move=> leT_total leT_tr p s; case Ds: s => // [x s1].
pose leN := relpre (nth x s) leT.
pose lt_lex := [rel n m | leN n m && (leN m n ==> (n < m))].
have lt_lex_tr: transitive lt_lex.
rewrite /lt_lex /leN => ? ? ? /= /andP [xy xy'] /andP [yz yz'].
rewrite (leT_tr _ _ _ xy yz); apply/implyP => zx; move: xy' yz'.
by rewrite (leT_tr _ _ _ yz zx) (leT_tr _ _ _ zx xy); apply: ltn_trans.
rewrite -{s1}Ds -(mkseq_nth x s) !(filter_map, sort_map); congr map.
apply/(@irr_sorted_eq _ lt_lex); rewrite /lt_lex /leN //=.
- by move=> ?; rewrite /= ltnn implybF andbN.
- exact/sorted_filter/sort_iota_stable.
- exact/sort_stable/sorted_filter/iota_ltn_sorted/ltn_trans/ltn_trans.
- by move=> ?; rewrite !(mem_filter, mem_sort).
Qed.
Lemma filter_sort_in T (P : {pred T}) (leT : rel T) :
{in P &, total leT} -> {in P & &, transitive leT} ->
forall p s, all P s -> filter p (sort leT s) = sort leT (filter p s).
Proof.
move=> /in2_sig leT_total /in3_sig leT_tr p _ /all_sigP[s ->].
by rewrite !(sort_map, filter_map) filter_sort.
Qed.
Section Stability_mask.
Variables (T : Type) (leT : rel T).
Variables (leT_total : total leT) (leT_tr : transitive leT).
Lemma mask_sort s m :
{m_s : bitseq | mask m_s (sort leT s) = sort leT (mask m s)}.
Proof.
case Ds: {-}s => [|x s1]; [by rewrite Ds; case: m; exists [::] | clear s1 Ds].
rewrite -(mkseq_nth x s) -map_mask !sort_map.
exists [seq i \in mask m (iota 0 (size s)) |
i <- sort (xrelpre (nth x s) leT) (iota 0 (size s))].
rewrite -map_mask -filter_mask [in RHS]mask_filter ?iota_uniq ?filter_sort //.
by move=> ? ? ?; exact: leT_tr.
Qed.
Lemma sorted_mask_sort s m :
sorted leT (mask m s) -> {m_s | mask m_s (sort leT s) = mask m s}.
Proof. by move/(sorted_sort leT_tr) <-; exact: mask_sort. Qed.
End Stability_mask.
Section Stability_mask_in.
Variables (T : Type) (P : {pred T}) (leT : rel T).
Hypothesis leT_total : {in P &, total leT}.
Hypothesis leT_tr : {in P & &, transitive leT}.
Let le_sT := relpre (val : sig P -> _) leT.
Let le_sT_total : total le_sT := in2_sig leT_total.
Let le_sT_tr : transitive le_sT := in3_sig leT_tr.
Lemma mask_sort_in s m :
all P s -> {m_s : bitseq | mask m_s (sort leT s) = sort leT (mask m s)}.
Proof.
move=> /all_sigP [{}s ->]; case: (mask_sort (leT := le_sT) _ _ s m) => //.
by move=> m' m'E; exists m'; rewrite -map_mask !sort_map -map_mask m'E.
Qed.
Lemma sorted_mask_sort_in s m :
all P s -> sorted leT (mask m s) -> {m_s | mask m_s (sort leT s) = mask m s}.
Proof.
move=> ? /(sorted_sort_in leT_tr _) <-; [exact: mask_sort_in | exact: all_mask].
Qed.
End Stability_mask_in.
Section Stability_subseq.
Variables (T : eqType) (leT : rel T).
Variables (leT_total : total leT) (leT_tr : transitive leT).
Lemma subseq_sort : {homo sort leT : t s / subseq t s}.
Proof.
move=> _ s /subseqP [m _ ->]; have [m' <-] := mask_sort leT_total leT_tr s m.
exact: mask_subseq.
Qed.
Lemma sorted_subseq_sort t s :
subseq t s -> sorted leT t -> subseq t (sort leT s).
Proof. by move=> subseq_ts /(sorted_sort leT_tr) <-; exact: subseq_sort. Qed.
Lemma mem2_sort s x y : leT x y -> mem2 s x y -> mem2 (sort leT s) x y.
Proof.
move=> lexy /[!mem2E] /subseq_sort.
by case: eqP => // _; rewrite {1}/sort /= lexy /=.
Qed.
End Stability_subseq.
Section Stability_subseq_in.
Variables (T : eqType) (leT : rel T).
Lemma subseq_sort_in t s :
{in s &, total leT} -> {in s & &, transitive leT} ->
subseq t s -> subseq (sort leT t) (sort leT s).
Proof.
move=> leT_total leT_tr /subseqP [m _ ->].
have [m' <-] := mask_sort_in leT_total leT_tr m (allss _).
exact: mask_subseq.
Qed.
Lemma sorted_subseq_sort_in t s :
{in s &, total leT} -> {in s & &, transitive leT} ->
subseq t s -> sorted leT t -> subseq t (sort leT s).
Proof.
move=> ? leT_tr ? /(sorted_sort_in leT_tr) <-; last exact/allP/mem_subseq.
exact: subseq_sort_in.
Qed.
Lemma mem2_sort_in s :
{in s &, total leT} -> {in s & &, transitive leT} ->
forall x y, leT x y -> mem2 s x y -> mem2 (sort leT s) x y.
Proof.
move=> leT_total leT_tr x y lexy; rewrite !mem2E.
by move/subseq_sort_in; case: (_ == _); rewrite /sort /= ?lexy; apply.
Qed.
End Stability_subseq_in.
Lemma sort_sorted T (leT : rel T) :
total leT -> forall s, sorted leT (sort leT s).
Proof.
move=> leT_total s; apply/sub_sorted/sort_stable => //= [? ? /andP[] //|].
by case: s => // x s; elim: s x => /=.
Qed.
Lemma sort_sorted_in T (P : {pred T}) (leT : rel T) :
{in P &, total leT} -> forall s : seq T, all P s -> sorted leT (sort leT s).
Proof.
by move=> /in2_sig ? _ /all_sigP[s ->]; rewrite sort_map sorted_map sort_sorted.
Qed.
Arguments sort_sorted {T leT} leT_total s.
Arguments sort_sorted_in {T P leT} leT_total {s}.
Lemma perm_sortP (T : eqType) (leT : rel T) :
total leT -> transitive leT -> antisymmetric leT ->
forall s1 s2, reflect (sort leT s1 = sort leT s2) (perm_eq s1 s2).
Proof.
move=> leT_total leT_tr leT_asym s1 s2.
apply: (iffP idP) => eq12; last by rewrite -(perm_sort leT) eq12 perm_sort.
apply: (sorted_eq leT_tr leT_asym); rewrite ?sort_sorted //.
by rewrite perm_sort (permPl eq12) -(perm_sort leT).
Qed.
Lemma perm_sort_inP (T : eqType) (leT : rel T) (s1 s2 : seq T) :
{in s1 &, total leT} -> {in s1 & &, transitive leT} ->
{in s1 &, antisymmetric leT} ->
reflect (sort leT s1 = sort leT s2) (perm_eq s1 s2).
Proof.
move=> /in2_sig leT_total /in3_sig leT_tr /in2_sig/(_ _ _ _)/val_inj leT_asym.
apply: (iffP idP) => s1s2; last by rewrite -(perm_sort leT) s1s2 perm_sort.
move: (s1s2); have /all_sigP[s1' ->] := allss s1.
have /all_sigP[{s1s2}s2 ->] : all [in s1] s2 by rewrite -(perm_all _ s1s2).
by rewrite !sort_map => /(perm_map_inj val_inj) /(perm_sortP leT_total)->.
Qed.
Lemma homo_sort_map (T : Type) (T' : eqType) (f : T -> T') leT leT' :
antisymmetric (relpre f leT') -> transitive (relpre f leT') -> total leT ->
{homo f : x y / leT x y >-> leT' x y} ->
forall s : seq T, sort leT' (map f s) = map f (sort leT s).
Proof.
move=> leT'_asym leT'_trans leT_total f_homo s; case Ds: s => // [x s'].
rewrite -{}Ds -(mkseq_nth x s) [in RHS]sort_map -!map_comp /comp.
apply: (@sorted_eq_in _ leT') => [? ? ?|? ?|||]; rewrite ?mem_sort.
- by move=> /mapP[? _ ->] /mapP[? _ ->] /mapP[? _ ->]; apply/leT'_trans.
- by move=> /mapP[? _ ->] /mapP[? _ ->] /leT'_asym ->.
- apply: (sort_sorted_in _ (allss _)) => _ _ /mapP[y _ ->] /mapP[z _ ->].
by case/orP: (leT_total (nth x s y) (nth x s z)) => /f_homo ->; rewrite ?orbT.
- by rewrite map_comp -sort_map; exact/homo_sorted/sort_sorted.
- by rewrite perm_sort perm_map // perm_sym perm_sort.
Qed.
Lemma homo_sort_map_in
(T : Type) (T' : eqType) (P : {pred T}) (f : T -> T') leT leT' :
{in P &, antisymmetric (relpre f leT')} ->
{in P & &, transitive (relpre f leT')} -> {in P &, total leT} ->
{in P &, {homo f : x y / leT x y >-> leT' x y}} ->
forall s : seq T, all P s ->
sort leT' [seq f x | x <- s] = [seq f x | x <- sort leT s].
Proof.
move=> /in2_sig leT'_asym /in3_sig leT'_trans /in2_sig leT_total.
move=> /in2_sig f_homo _ /all_sigP[s ->].
rewrite [in RHS]sort_map -!map_comp /comp.
by apply: homo_sort_map => // ? ? /leT'_asym /val_inj.
Qed.
(* Function trajectories. *)
Notation fpath f := (path (coerced_frel f)).
Notation fcycle f := (cycle (coerced_frel f)).
Notation ufcycle f := (ucycle (coerced_frel f)).
Prenex Implicits path next prev cycle ucycle mem2.
Section Trajectory.
Variables (T : Type) (f : T -> T).
Fixpoint traject x n := if n is n'.+1 then x :: traject (f x) n' else [::].
Lemma trajectS x n : traject x n.+1 = x :: traject (f x) n.
Proof. by []. Qed.
Lemma trajectSr x n : traject x n.+1 = rcons (traject x n) (iter n f x).
Proof. by elim: n x => //= n IHn x; rewrite IHn -iterSr. Qed.
Lemma last_traject x n : last x (traject (f x) n) = iter n f x.
Proof. by case: n => // n; rewrite iterSr trajectSr last_rcons. Qed.
Lemma traject_iteri x n :
traject x n = iteri n (fun i => rcons^~ (iter i f x)) [::].
Proof. by elim: n => //= n <-; rewrite -trajectSr. Qed.
Lemma size_traject x n : size (traject x n) = n.
Proof. by elim: n x => //= n IHn x //=; rewrite IHn. Qed.
Lemma nth_traject i n : i < n -> forall x, nth x (traject x n) i = iter i f x.
Proof.
elim: n => // n IHn; rewrite ltnS => le_i_n x.
rewrite trajectSr nth_rcons size_traject.
by case: ltngtP le_i_n => [? _||->] //; apply: IHn.
Qed.
Lemma trajectD m n x :
traject x (m + n) = traject x m ++ traject (iter m f x) n.
Proof. by elim: m => //m IHm in x *; rewrite addSn !trajectS IHm -iterSr. Qed.
Lemma take_traject n k x : k <= n -> take k (traject x n) = traject x k.
Proof. by move=> /subnKC<-; rewrite trajectD take_size_cat ?size_traject. Qed.
End Trajectory.
Section EqTrajectory.
Variables (T : eqType) (f : T -> T).
Lemma eq_fpath f' : f =1 f' -> fpath f =2 fpath f'.
Proof. by move/eq_frel/eq_path. Qed.
Lemma eq_fcycle f' : f =1 f' -> fcycle f =1 fcycle f'.
Proof. by move/eq_frel/eq_cycle. Qed.
Lemma fpathE x p : fpath f x p -> p = traject f (f x) (size p).
Proof. by elim: p => //= y p IHp in x * => /andP[/eqP{y}<- /IHp<-]. Qed.
Lemma fpathP x p : reflect (exists n, p = traject f (f x) n) (fpath f x p).
Proof.
apply: (iffP idP) => [/fpathE->|[n->]]; first by exists (size p).
by elim: n => //= n IHn in x *; rewrite eqxx IHn.
Qed.
Lemma fpath_traject x n : fpath f x (traject f (f x) n).
Proof. by apply/(fpathP x); exists n. Qed.
Definition looping x n := iter n f x \in traject f x n.
Lemma loopingP x n :
reflect (forall m, iter m f x \in traject f x n) (looping x n).
Proof.
apply: (iffP idP) => loop_n; last exact: loop_n.
case: n => // n in loop_n *; elim=> [|m /= IHm]; first exact: mem_head.
move: (fpath_traject x n) loop_n; rewrite /looping !iterS -last_traject /=.
move: (iter m f x) IHm => y /splitPl[p1 p2 def_y].
rewrite cat_path last_cat def_y; case: p2 => // z p2 /and3P[_ /eqP-> _] _.
by rewrite inE mem_cat mem_head !orbT.
Qed.
Lemma trajectP x n y :
reflect (exists2 i, i < n & y = iter i f x) (y \in traject f x n).
Proof.
elim: n x => [|n IHn] x /=; first by right; case.
rewrite inE; have [-> | /= neq_xy] := eqP; first by left; exists 0.
apply: {IHn}(iffP (IHn _)) => [[i] | [[|i]]] // lt_i_n ->.
by exists i.+1; rewrite ?iterSr.
by exists i; rewrite ?iterSr.
Qed.
Lemma looping_uniq x n : uniq (traject f x n.+1) = ~~ looping x n.
Proof.
rewrite /looping; elim: n x => [|n IHn] x //.
rewrite [n.+1 in LHS]lock [iter]lock /= -!lock {}IHn -iterSr -negb_or inE.
congr (~~ _); apply: orb_id2r => /trajectP no_loop.
apply/idP/eqP => [/trajectP[m le_m_n def_x] | {1}<-]; last first.
by rewrite iterSr -last_traject mem_last.
have loop_m: looping x m.+1 by rewrite /looping iterSr -def_x mem_head.
have/trajectP[[|i] // le_i_m def_fn1x] := loopingP _ _ loop_m n.+1.
by case: no_loop; exists i; rewrite -?iterSr // -ltnS (leq_trans le_i_m).
Qed.
End EqTrajectory.
Arguments fpathP {T f x p}.
Arguments loopingP {T f x n}.
Arguments trajectP {T f x n y}.
Prenex Implicits traject.
Section Fcycle.
Variables (T : eqType) (f : T -> T) (p : seq T) (f_p : fcycle f p).
Lemma nextE (x : T) (p_x : x \in p) : next p x = f x.
Proof. exact/esym/eqP/(next_cycle f_p). Qed.
Lemma mem_fcycle : {homo f : x / x \in p}.
Proof. by move=> x xp; rewrite -nextE// mem_next. Qed.
Lemma inj_cycle : {in p &, injective f}.
Proof.
apply: can_in_inj (iter (size p).-1 f) _ => x /rot_to[i q rip].
have /fpathE qxE : fcycle f (x :: q) by rewrite -rip rot_cycle.
have -> : size p = size (rcons q x) by rewrite size_rcons -(size_rot i) rip.
by rewrite -iterSr -last_traject prednK -?qxE ?size_rcons// last_rcons.
Qed.
End Fcycle.
Section UniqCycle.
Variables (n0 : nat) (T : eqType) (e : rel T) (p : seq T).
Hypothesis Up : uniq p.
Lemma prev_next : cancel (next p) (prev p).
Proof.
move=> x; rewrite prev_nth mem_next next_nth; case p_x: (x \in p) => //.
case Dp: p Up p_x => // [y q]; rewrite [uniq _]/= -Dp => /andP[q'y Uq] p_x.
rewrite -[RHS](nth_index y p_x); congr (nth y _ _); set i := index x p.
have: i <= size q by rewrite -index_mem -/i Dp in p_x.
case: ltngtP => // [lt_i_q|->] _; first by rewrite index_uniq.
by apply/eqP; rewrite nth_default // eqn_leq index_size leqNgt index_mem.
Qed.
Lemma next_prev : cancel (prev p) (next p).
Proof.
move=> x; rewrite next_nth mem_prev prev_nth; case p_x: (x \in p) => //.
case def_p: p p_x => // [y q]; rewrite -def_p => p_x.
rewrite index_uniq //; last by rewrite def_p ltnS index_size.
case q_x: (x \in q); first exact: nth_index.
rewrite nth_default; last by rewrite leqNgt index_mem q_x.
by apply/eqP; rewrite def_p inE q_x orbF eq_sym in p_x.
Qed.
Lemma cycle_next : fcycle (next p) p.
Proof.
case def_p: p Up => [|x q] Uq //; rewrite -[in next _]def_p.
apply/(pathP x)=> i; rewrite size_rcons => le_i_q.
rewrite -cats1 -cat_cons nth_cat le_i_q /= next_nth {}def_p mem_nth //.
rewrite index_uniq // nth_cat /= ltn_neqAle andbC -ltnS le_i_q.
by case: (i =P _) => //= ->; rewrite subnn nth_default.
Qed.
Lemma cycle_prev : cycle (fun x y => x == prev p y) p.
Proof.
apply: etrans cycle_next; symmetry; case def_p: p => [|x q] //.
by apply: eq_path; rewrite -def_p; apply: (can2_eq prev_next next_prev).
Qed.
Lemma cycle_from_next : (forall x, x \in p -> e x (next p x)) -> cycle e p.
Proof.
case: p (next p) cycle_next => //= [x q] n; rewrite -(belast_rcons x q x).
move: {q}(rcons q x) => q n_q /allP.
by elim: q x n_q => //= _ q IHq x /andP[/eqP <- n_q] /andP[-> /IHq->].
Qed.
Lemma cycle_from_prev : (forall x, x \in p -> e (prev p x) x) -> cycle e p.
Proof.
move=> e_p; apply: cycle_from_next => x.
by rewrite -mem_next => /e_p; rewrite prev_next.
Qed.
Lemma next_rot : next (rot n0 p) =1 next p.
Proof.
move=> x; have n_p := cycle_next; rewrite -(rot_cycle n0) in n_p.
case p_x: (x \in p); last by rewrite !next_nth mem_rot p_x.
by rewrite (eqP (next_cycle n_p _)) ?mem_rot.
Qed.
Lemma prev_rot : prev (rot n0 p) =1 prev p.
Proof.
move=> x; have p_p := cycle_prev; rewrite -(rot_cycle n0) in p_p.
case p_x: (x \in p); last by rewrite !prev_nth mem_rot p_x.
by rewrite (eqP (prev_cycle p_p _)) ?mem_rot.
Qed.
End UniqCycle.
Section UniqRotrCycle.
Variables (n0 : nat) (T : eqType) (p : seq T).
Hypothesis Up : uniq p.
Lemma next_rotr : next (rotr n0 p) =1 next p. Proof. exact: next_rot. Qed.
Lemma prev_rotr : prev (rotr n0 p) =1 prev p. Proof. exact: prev_rot. Qed.
End UniqRotrCycle.
Section UniqCycleRev.
Variable T : eqType.
Implicit Type p : seq T.
Lemma prev_rev p : uniq p -> prev (rev p) =1 next p.
Proof.
move=> Up x; case p_x: (x \in p); last first.
by rewrite next_nth prev_nth mem_rev p_x.
case/rot_to: p_x (Up) => [i q def_p] Urp; rewrite -rev_uniq in Urp.
rewrite -(prev_rotr i Urp); do 2 rewrite -(prev_rotr 1) ?rotr_uniq //.
rewrite -rev_rot -(next_rot i Up) {i p Up Urp}def_p.
by case: q => // y q; rewrite !rev_cons !(=^~ rcons_cons, rotr1_rcons) /= eqxx.
Qed.
Lemma next_rev p : uniq p -> next (rev p) =1 prev p.
Proof. by move=> Up x; rewrite -[p in RHS]revK prev_rev // rev_uniq. Qed.
End UniqCycleRev.
Section MapPath.
Variables (T T' : Type) (h : T' -> T) (e : rel T) (e' : rel T').
Definition rel_base (b : pred T) :=
forall x' y', ~~ b (h x') -> e (h x') (h y') = e' x' y'.
Lemma map_path b x' p' (Bb : rel_base b) :
~~ has (preim h b) (belast x' p') ->
path e (h x') (map h p') = path e' x' p'.
Proof. by elim: p' x' => [|y' p' IHp'] x' //= /norP[/Bb-> /IHp'->]. Qed.
End MapPath.
Section MapEqPath.
Variables (T T' : eqType) (h : T' -> T) (e : rel T) (e' : rel T').
Hypothesis Ih : injective h.
Lemma mem2_map x' y' p' : mem2 (map h p') (h x') (h y') = mem2 p' x' y'.
Proof. by rewrite [LHS]/mem2 (index_map Ih) -map_drop mem_map. Qed.
Lemma next_map p : uniq p -> forall x, next (map h p) (h x) = h (next p x).
Proof.
move=> Up x; case p_x: (x \in p); last by rewrite !next_nth (mem_map Ih) p_x.
case/rot_to: p_x => i p' def_p.
rewrite -(next_rot i Up); rewrite -(map_inj_uniq Ih) in Up.
rewrite -(next_rot i Up) -map_rot {i p Up}def_p /=.
by case: p' => [|y p''] //=; rewrite !eqxx.
Qed.
Lemma prev_map p : uniq p -> forall x, prev (map h p) (h x) = h (prev p x).
Proof.
move=> Up x; rewrite -[x in LHS](next_prev Up) -(next_map Up).
by rewrite prev_next ?map_inj_uniq.
Qed.
End MapEqPath.
Definition fun_base (T T' : eqType) (h : T' -> T) f f' :=
rel_base h (frel f) (frel f').
Section CycleArc.
Variable T : eqType.
Implicit Type p : seq T.
Definition arc p x y := let px := rot (index x p) p in take (index y px) px.
Lemma arc_rot i p : uniq p -> {in p, arc (rot i p) =2 arc p}.
Proof.
move=> Up x p_x y; congr (fun q => take (index y q) q); move: Up p_x {y}.
rewrite -{1 2 5 6}(cat_take_drop i p) /rot cat_uniq => /and3P[_ Up12 _].
rewrite !drop_cat !take_cat !index_cat mem_cat orbC.
case p2x: (x \in drop i p) => /= => [_ | p1x].
rewrite index_mem p2x [x \in _](negbTE (hasPn Up12 _ p2x)) /= addKn.
by rewrite ltnNge leq_addr catA.
by rewrite p1x index_mem p1x addKn ltnNge leq_addr /= catA.
Qed.
Lemma left_arc x y p1 p2 (p := x :: p1 ++ y :: p2) :
uniq p -> arc p x y = x :: p1.
Proof.
rewrite /arc /p [index x _]/= eqxx rot0 -cat_cons cat_uniq index_cat.
move: (x :: p1) => xp1 /and3P[_ /norP[/= /negbTE-> _] _].
by rewrite eqxx addn0 take_size_cat.
Qed.
Lemma right_arc x y p1 p2 (p := x :: p1 ++ y :: p2) :
uniq p -> arc p y x = y :: p2.
Proof.
rewrite -[p]cat_cons -rot_size_cat rot_uniq => Up.
by rewrite arc_rot ?left_arc ?mem_head.
Qed.
Variant rot_to_arc_spec p x y :=
RotToArcSpec i p1 p2 of x :: p1 = arc p x y
& y :: p2 = arc p y x
& rot i p = x :: p1 ++ y :: p2 :
rot_to_arc_spec p x y.
Lemma rot_to_arc p x y :
uniq p -> x \in p -> y \in p -> x != y -> rot_to_arc_spec p x y.
Proof.
move=> Up p_x p_y ne_xy; case: (rot_to p_x) (p_y) (Up) => [i q def_p] q_y.
rewrite -(mem_rot i) def_p inE eq_sym (negbTE ne_xy) in q_y.
rewrite -(rot_uniq i) def_p.
case/splitPr: q / q_y def_p => q1 q2 def_p Uq12; exists i q1 q2 => //.
by rewrite -(arc_rot i Up p_x) def_p left_arc.
by rewrite -(arc_rot i Up p_y) def_p right_arc.
Qed.
End CycleArc.
Prenex Implicits arc.
|
inertia.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path.
From mathcomp Require Import choice fintype div tuple finfun bigop prime order.
From mathcomp Require Import ssralg ssrnum finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action zmodp cyclic center.
From mathcomp Require Import gproduct commutator gseries nilpotent pgroup.
From mathcomp Require Import sylow maximal frobenius matrix mxalgebra.
From mathcomp Require Import mxrepresentation vector algC classfun character.
From mathcomp Require Import archimedean.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
(******************************************************************************)
(* This file contains the definitions and properties of inertia groups: *)
(* (phi ^ y)%CF == the y-conjugate of phi : 'CF(G), i.e., the class *)
(* function mapping x ^ y to phi x provided y normalises G. *)
(* We take (phi ^ y)%CF = phi when y \notin 'N(G). *)
(* (phi ^: G)%CF == the sequence of all distinct conjugates of phi : 'CF(H) *)
(* by all y in G. *)
(* 'I[phi] == the inertia group of phi : CF(H), i.e., the set of y *)
(* such that (phi ^ y)%CF = phi AND H :^ y = y. *)
(* 'I_G[phi] == the inertia group of phi in G, i.e., G :&: 'I[phi]. *)
(* conjg_Iirr i y == the index j : Iirr G such that ('chi_i ^ y)%CF = 'chi_j. *)
(* cfclass_Iirr G i == the image of G under conjg_Iirr i, i.e., the set of j *)
(* such that 'chi_j \in ('chi_i ^: G)%CF. *)
(* mul_Iirr i j == the index k such that 'chi_j * 'chi_i = 'chi[G]_k, *)
(* or 0 if 'chi_j * 'chi_i is reducible. *)
(* mul_mod_Iirr i j := mul_Iirr i (mod_Iirr j), for j : Iirr (G / H). *)
(******************************************************************************)
Reserved Notation "''I[' phi ]" (format "''I[' phi ]").
Reserved Notation "''I_' G [ phi ]" (G at level 2, format "''I_' G [ phi ]").
Section ConjDef.
Variables (gT : finGroupType) (B : {set gT}) (y : gT) (phi : 'CF(B)).
Local Notation G := <<B>>.
Fact cfConjg_subproof :
is_class_fun G [ffun x => phi (if y \in 'N(G) then x ^ y^-1 else x)].
Proof.
apply: intro_class_fun => [x z _ Gz | x notGx].
have [nGy | _] := ifP; last by rewrite cfunJgen.
by rewrite -conjgM conjgC conjgM cfunJgen // memJ_norm ?groupV.
by rewrite cfun0gen //; case: ifP => // nGy; rewrite memJ_norm ?groupV.
Qed.
Definition cfConjg := Cfun 1 cfConjg_subproof.
End ConjDef.
Prenex Implicits cfConjg.
Notation "f ^ y" := (cfConjg y f) : cfun_scope.
Section Conj.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Type phi : 'CF(G).
Lemma cfConjgE phi y x : y \in 'N(G) -> (phi ^ y)%CF x = phi (x ^ y^-1)%g.
Proof. by rewrite cfunElock genGid => ->. Qed.
Lemma cfConjgEJ phi y x : y \in 'N(G) -> (phi ^ y)%CF (x ^ y) = phi x.
Proof. by move/cfConjgE->; rewrite conjgK. Qed.
Lemma cfConjgEout phi y : y \notin 'N(G) -> (phi ^ y = phi)%CF.
Proof.
by move/negbTE=> notNy; apply/cfunP=> x; rewrite !cfunElock genGid notNy.
Qed.
Lemma cfConjgEin phi y (nGy : y \in 'N(G)) :
(phi ^ y)%CF = cfIsom (norm_conj_isom nGy) phi.
Proof.
apply/cfun_inP=> x Gx.
by rewrite cfConjgE // -{2}[x](conjgKV y) cfIsomE ?memJ_norm ?groupV.
Qed.
Lemma cfConjgMnorm phi :
{in 'N(G) &, forall y z, phi ^ (y * z) = (phi ^ y) ^ z}%CF.
Proof.
move=> y z nGy nGz.
by apply/cfunP=> x; rewrite !cfConjgE ?groupM // invMg conjgM.
Qed.
Lemma cfConjg_id phi y : y \in G -> (phi ^ y)%CF = phi.
Proof.
move=> Gy; apply/cfunP=> x; have nGy := subsetP (normG G) y Gy.
by rewrite -(cfunJ _ _ Gy) cfConjgEJ.
Qed.
(* Isaacs' 6.1.b *)
Lemma cfConjgM L phi :
G <| L -> {in L &, forall y z, phi ^ (y * z) = (phi ^ y) ^ z}%CF.
Proof. by case/andP=> _ /subsetP nGL; apply: sub_in2 (cfConjgMnorm phi). Qed.
Lemma cfConjgJ1 phi : (phi ^ 1)%CF = phi.
Proof. by apply/cfunP=> x; rewrite cfConjgE ?group1 // invg1 conjg1. Qed.
Lemma cfConjgK y : cancel (cfConjg y) (cfConjg y^-1 : 'CF(G) -> 'CF(G)).
Proof.
move=> phi; apply/cfunP=> x; rewrite !cfunElock groupV /=.
by case: ifP => -> //; rewrite conjgKV.
Qed.
Lemma cfConjgKV y : cancel (cfConjg y^-1) (cfConjg y : 'CF(G) -> 'CF(G)).
Proof. by move=> phi /=; rewrite -{1}[y]invgK cfConjgK. Qed.
Lemma cfConjg1 phi y : (phi ^ y)%CF 1%g = phi 1%g.
Proof. by rewrite cfunElock conj1g if_same. Qed.
Fact cfConjg_is_linear y : linear (cfConjg y : 'CF(G) -> 'CF(G)).
Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock. Qed.
HB.instance Definition _ y := GRing.isSemilinear.Build _ _ _ _ (cfConjg y)
(GRing.semilinear_linear (cfConjg_is_linear y)).
Lemma cfConjg_cfuniJ A y : y \in 'N(G) -> ('1_A ^ y)%CF = '1_(A :^ y) :> 'CF(G).
Proof.
move=> nGy; apply/cfunP=> x; rewrite !cfunElock genGid nGy -sub_conjgV.
by rewrite -class_lcoset -class_rcoset norm_rlcoset ?memJ_norm ?groupV.
Qed.
Lemma cfConjg_cfuni A y : y \in 'N(A) -> ('1_A ^ y)%CF = '1_A :> 'CF(G).
Proof.
by have [/cfConjg_cfuniJ-> /normP-> | /cfConjgEout] := boolP (y \in 'N(G)).
Qed.
Lemma cfConjg_cfun1 y : (1 ^ y)%CF = 1 :> 'CF(G).
Proof.
by rewrite -cfuniG; have [/cfConjg_cfuni|/cfConjgEout] := boolP (y \in 'N(G)).
Qed.
Fact cfConjg_is_monoid_morphism y : monoid_morphism (cfConjg y : _ -> 'CF(G)).
Proof.
split=> [|phi psi]; first exact: cfConjg_cfun1.
by apply/cfunP=> x; rewrite !cfunElock.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfConjg_is_monoid_morphism` instead")]
Definition cfConjg_is_multiplicative y :=
(fun g => (g.2,g.1)) (cfConjg_is_monoid_morphism y).
HB.instance Definition _ y := GRing.isMonoidMorphism.Build _ _ (cfConjg y)
(cfConjg_is_monoid_morphism y).
Lemma cfConjg_eq1 phi y : ((phi ^ y)%CF == 1) = (phi == 1).
Proof. by apply: rmorph_eq1; apply: can_inj (cfConjgK y). Qed.
Lemma cfAutConjg phi u y : cfAut u (phi ^ y) = (cfAut u phi ^ y)%CF.
Proof. by apply/cfunP=> x; rewrite !cfunElock. Qed.
Lemma conj_cfConjg phi y : (phi ^ y)^*%CF = (phi^* ^ y)%CF.
Proof. exact: cfAutConjg. Qed.
Lemma cfker_conjg phi y : y \in 'N(G) -> cfker (phi ^ y) = cfker phi :^ y.
Proof.
move=> nGy; rewrite cfConjgEin // cfker_isom.
by rewrite morphim_conj (setIidPr (cfker_sub _)).
Qed.
Lemma cfDetConjg phi y : cfDet (phi ^ y) = (cfDet phi ^ y)%CF.
Proof.
have [nGy | not_nGy] := boolP (y \in 'N(G)); last by rewrite !cfConjgEout.
by rewrite !cfConjgEin cfDetIsom.
Qed.
End Conj.
Section Inertia.
Variable gT : finGroupType.
Definition inertia (B : {set gT}) (phi : 'CF(B)) :=
[set y in 'N(B) | (phi ^ y)%CF == phi].
Local Notation "''I[' phi ]" := (inertia phi) : group_scope.
Local Notation "''I_' G [ phi ]" := (G%g :&: 'I[phi]) : group_scope.
Fact group_set_inertia (H : {group gT}) phi : group_set 'I[phi : 'CF(H)].
Proof.
apply/group_setP; split; first by rewrite inE group1 /= cfConjgJ1.
move=> y z /setIdP[nHy /eqP n_phi_y] /setIdP[nHz n_phi_z].
by rewrite inE groupM //= cfConjgMnorm ?n_phi_y.
Qed.
Canonical inertia_group H phi := Group (@group_set_inertia H phi).
Local Notation "''I[' phi ]" := (inertia_group phi) : Group_scope.
Local Notation "''I_' G [ phi ]" := (G :&: 'I[phi])%G : Group_scope.
Variables G H : {group gT}.
Implicit Type phi : 'CF(H).
Lemma inertiaJ phi y : y \in 'I[phi] -> (phi ^ y)%CF = phi.
Proof. by case/setIdP=> _ /eqP->. Qed.
Lemma inertia_valJ phi x y : y \in 'I[phi] -> phi (x ^ y)%g = phi x.
Proof. by case/setIdP=> nHy /eqP {1}<-; rewrite cfConjgEJ. Qed.
(* To disambiguate basic inclucion lemma names we capitalize Inertia for *)
(* lemmas concerning the localized inertia group 'I_G[phi]. *)
Lemma Inertia_sub phi : 'I_G[phi] \subset G.
Proof. exact: subsetIl. Qed.
Lemma norm_inertia phi : 'I[phi] \subset 'N(H).
Proof. by rewrite ['I[_]]setIdE subsetIl. Qed.
Lemma sub_inertia phi : H \subset 'I[phi].
Proof.
by apply/subsetP=> y Hy; rewrite inE cfConjg_id ?(subsetP (normG H)) /=.
Qed.
Lemma normal_inertia phi : H <| 'I[phi].
Proof. by rewrite /normal sub_inertia norm_inertia. Qed.
Lemma sub_Inertia phi : H \subset G -> H \subset 'I_G[phi].
Proof. by rewrite subsetI sub_inertia andbT. Qed.
Lemma norm_Inertia phi : 'I_G[phi] \subset 'N(H).
Proof. by rewrite setIC subIset ?norm_inertia. Qed.
Lemma normal_Inertia phi : H \subset G -> H <| 'I_G[phi].
Proof. by rewrite /normal norm_Inertia andbT; apply: sub_Inertia. Qed.
Lemma cfConjg_eqE phi :
H <| G ->
{in G &, forall y z, (phi ^ y == phi ^ z)%CF = (z \in 'I_G[phi] :* y)}.
Proof.
case/andP=> _ nHG y z Gy; rewrite -{1 2}[z](mulgKV y) groupMr // mem_rcoset.
move: {z}(z * _)%g => z Gz; rewrite 2!inE Gz cfConjgMnorm ?(subsetP nHG) //=.
by rewrite eq_sym (can_eq (cfConjgK y)).
Qed.
Lemma cent_sub_inertia phi : 'C(H) \subset 'I[phi].
Proof.
apply/subsetP=> y cHy; have nHy := subsetP (cent_sub H) y cHy.
rewrite inE nHy; apply/eqP/cfun_inP=> x Hx; rewrite cfConjgE //.
by rewrite /conjg invgK mulgA (centP cHy) ?mulgK.
Qed.
Lemma cent_sub_Inertia phi : 'C_G(H) \subset 'I_G[phi].
Proof. exact: setIS (cent_sub_inertia phi). Qed.
Lemma center_sub_Inertia phi : H \subset G -> 'Z(G) \subset 'I_G[phi].
Proof.
by move/centS=> sHG; rewrite setIS // (subset_trans sHG) // cent_sub_inertia.
Qed.
Lemma conjg_inertia phi y : y \in 'N(H) -> 'I[phi] :^ y = 'I[phi ^ y].
Proof.
move=> nHy; apply/setP=> z; rewrite !['I[_]]setIdE conjIg conjGid // !in_setI.
apply/andb_id2l=> nHz; rewrite mem_conjg !inE.
by rewrite !cfConjgMnorm ?in_group ?(can2_eq (cfConjgKV y) (cfConjgK y)) ?invgK.
Qed.
Lemma inertia0 : 'I[0 : 'CF(H)] = 'N(H).
Proof. by apply/setP=> x; rewrite !inE linear0 eqxx andbT. Qed.
Lemma inertia_add phi psi : 'I[phi] :&: 'I[psi] \subset 'I[phi + psi].
Proof.
rewrite !['I[_]]setIdE -setIIr setIS //.
by apply/subsetP=> x /[!(inE, linearD)]/= /andP[/eqP-> /eqP->].
Qed.
Lemma inertia_sum I r (P : pred I) (Phi : I -> 'CF(H)) :
'N(H) :&: \bigcap_(i <- r | P i) 'I[Phi i]
\subset 'I[\sum_(i <- r | P i) Phi i].
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_Ipsi]; first by rewrite setIT inertia0.
by rewrite setICA; apply: subset_trans (setIS _ sK_Ipsi) (inertia_add _ _).
Qed.
Lemma inertia_scale a phi : 'I[phi] \subset 'I[a *: phi].
Proof.
apply/subsetP=> x /setIdP[nHx /eqP Iphi_x].
by rewrite inE nHx linearZ /= Iphi_x.
Qed.
Lemma inertia_scale_nz a phi : a != 0 -> 'I[a *: phi] = 'I[phi].
Proof.
move=> nz_a; apply/eqP.
by rewrite eqEsubset -{2}(scalerK nz_a phi) !inertia_scale.
Qed.
Lemma inertia_opp phi : 'I[- phi] = 'I[phi].
Proof. by rewrite -scaleN1r inertia_scale_nz // oppr_eq0 oner_eq0. Qed.
Lemma inertia1 : 'I[1 : 'CF(H)] = 'N(H).
Proof. by apply/setP=> x; rewrite inE rmorph1 eqxx andbT. Qed.
Lemma Inertia1 : H <| G -> 'I_G[1 : 'CF(H)] = G.
Proof. by rewrite inertia1 => /normal_norm/setIidPl. Qed.
Lemma inertia_mul phi psi : 'I[phi] :&: 'I[psi] \subset 'I[phi * psi].
Proof.
rewrite !['I[_]]setIdE -setIIr setIS //.
by apply/subsetP=> x /[!(inE, rmorphM)]/= /andP[/eqP-> /eqP->].
Qed.
Lemma inertia_prod I r (P : pred I) (Phi : I -> 'CF(H)) :
'N(H) :&: \bigcap_(i <- r | P i) 'I[Phi i]
\subset 'I[\prod_(i <- r | P i) Phi i].
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite inertia1 setIT.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (inertia_mul _ _).
Qed.
Lemma inertia_injective (chi : 'CF(H)) :
{in H &, injective chi} -> 'I[chi] = 'C(H).
Proof.
move=> inj_chi; apply/eqP; rewrite eqEsubset cent_sub_inertia andbT.
apply/subsetP=> y Ichi_y; have /setIdP[nHy _] := Ichi_y.
apply/centP=> x Hx; apply/esym/commgP/conjg_fixP.
by apply/inj_chi; rewrite ?memJ_norm ?(inertia_valJ _ Ichi_y).
Qed.
Lemma inertia_irr_prime p i :
#|H| = p -> prime p -> i != 0 -> 'I['chi[H]_i] = 'C(H).
Proof. by move=> <- pr_H /(irr_prime_injP pr_H); apply: inertia_injective. Qed.
Lemma inertia_irr0 : 'I['chi[H]_0] = 'N(H).
Proof. by rewrite irr0 inertia1. Qed.
(* Isaacs' 6.1.c *)
Lemma cfConjg_iso y : isometry (cfConjg y : 'CF(H) -> 'CF(H)).
Proof.
move=> phi psi; congr (_ * _).
have [nHy | not_nHy] := boolP (y \in 'N(H)); last by rewrite !cfConjgEout.
rewrite (reindex_astabs 'J y) ?astabsJ //=.
by apply: eq_bigr=> x _; rewrite !cfConjgEJ.
Qed.
(* Isaacs' 6.1.d *)
Lemma cfdot_Res_conjg psi phi y :
y \in G -> '['Res[H, G] psi, phi ^ y] = '['Res[H] psi, phi].
Proof.
move=> Gy; rewrite -(cfConjg_iso y _ phi); congr '[_, _]; apply/cfunP=> x.
rewrite !cfunElock !genGid; case nHy: (y \in 'N(H)) => //.
by rewrite !(fun_if psi) cfunJ ?memJ_norm ?groupV.
Qed.
(* Isaac's 6.1.e *)
Lemma cfConjg_char (chi : 'CF(H)) y :
chi \is a character -> (chi ^ y)%CF \is a character.
Proof.
have [nHy Nchi | /cfConjgEout-> //] := boolP (y \in 'N(H)).
by rewrite cfConjgEin cfIsom_char.
Qed.
Lemma cfConjg_lin_char (chi : 'CF(H)) y :
chi \is a linear_char -> (chi ^ y)%CF \is a linear_char.
Proof. by case/andP=> Nchi chi1; rewrite qualifE/= cfConjg1 cfConjg_char. Qed.
Lemma cfConjg_irr y chi : chi \in irr H -> (chi ^ y)%CF \in irr H.
Proof. by rewrite !irrEchar cfConjg_iso => /andP[/cfConjg_char->]. Qed.
Definition conjg_Iirr i y := cfIirr ('chi[H]_i ^ y)%CF.
Lemma conjg_IirrE i y : 'chi_(conjg_Iirr i y) = ('chi_i ^ y)%CF.
Proof. by rewrite cfIirrE ?cfConjg_irr ?mem_irr. Qed.
Lemma conjg_IirrK y : cancel (conjg_Iirr^~ y) (conjg_Iirr^~ y^-1%g).
Proof. by move=> i; apply/irr_inj; rewrite !conjg_IirrE cfConjgK. Qed.
Lemma conjg_IirrKV y : cancel (conjg_Iirr^~ y^-1%g) (conjg_Iirr^~ y).
Proof. by rewrite -{2}[y]invgK; apply: conjg_IirrK. Qed.
Lemma conjg_Iirr_inj y : injective (conjg_Iirr^~ y).
Proof. exact: can_inj (conjg_IirrK y). Qed.
Lemma conjg_Iirr_eq0 i y : (conjg_Iirr i y == 0) = (i == 0).
Proof. by rewrite -!irr_eq1 conjg_IirrE cfConjg_eq1. Qed.
Lemma conjg_Iirr0 x : conjg_Iirr 0 x = 0.
Proof. by apply/eqP; rewrite conjg_Iirr_eq0. Qed.
Lemma cfdot_irr_conjg i y :
H <| G -> y \in G -> '['chi_i, 'chi_i ^ y]_H = (y \in 'I_G['chi_i])%:R.
Proof.
move=> nsHG Gy; rewrite -conjg_IirrE cfdot_irr -(inj_eq irr_inj) conjg_IirrE.
by rewrite -{1}['chi_i]cfConjgJ1 cfConjg_eqE ?mulg1.
Qed.
Definition cfclass (A : {set gT}) (phi : 'CF(A)) (B : {set gT}) :=
[seq (phi ^ repr Tx)%CF | Tx in rcosets 'I_B[phi] B].
Local Notation "phi ^: G" := (cfclass phi G) : cfun_scope.
Lemma size_cfclass i : size ('chi[H]_i ^: G)%CF = #|G : 'I_G['chi_i]|.
Proof. by rewrite size_map -cardE. Qed.
Lemma cfclassP (A : {group gT}) phi psi :
reflect (exists2 y, y \in A & psi = phi ^ y)%CF (psi \in phi ^: A)%CF.
Proof.
apply: (iffP imageP) => [[_ /rcosetsP[y Ay ->] ->] | [y Ay ->]].
by case: repr_rcosetP => z /setIdP[Az _]; exists (z * y)%g; rewrite ?groupM.
without loss nHy: y Ay / y \in 'N(H).
have [nHy | /cfConjgEout->] := boolP (y \in 'N(H)); first exact.
by move/(_ 1%g); rewrite !group1 !cfConjgJ1; apply.
exists ('I_A[phi] :* y); first by rewrite -rcosetE imset_f.
case: repr_rcosetP => z /setIP[_ /setIdP[nHz /eqP Tz]].
by rewrite cfConjgMnorm ?Tz.
Qed.
Lemma cfclassInorm phi : (phi ^: 'N_G(H) =i phi ^: G)%CF.
Proof.
move=> xi; apply/cfclassP/cfclassP=> [[x /setIP[Gx _] ->] | [x Gx ->]].
by exists x.
have [Nx | /cfConjgEout-> //] := boolP (x \in 'N(H)).
by exists x; first apply/setIP.
by exists 1%g; rewrite ?group1 ?cfConjgJ1.
Qed.
Lemma cfclass_refl phi : phi \in (phi ^: G)%CF.
Proof. by apply/cfclassP; exists 1%g => //; rewrite cfConjgJ1. Qed.
Lemma cfclass_transr phi psi :
(psi \in phi ^: G)%CF -> (phi ^: G =i psi ^: G)%CF.
Proof.
rewrite -cfclassInorm; case/cfclassP=> x Gx -> xi; rewrite -!cfclassInorm.
have nHN: {subset 'N_G(H) <= 'N(H)} by apply/subsetP; apply: subsetIr.
apply/cfclassP/cfclassP=> [[y Gy ->] | [y Gy ->]].
by exists (x^-1 * y)%g; rewrite -?cfConjgMnorm ?groupM ?groupV ?nHN // mulKVg.
by exists (x * y)%g; rewrite -?cfConjgMnorm ?groupM ?nHN.
Qed.
Lemma cfclass_sym phi psi : (psi \in phi ^: G)%CF = (phi \in psi ^: G)%CF.
Proof. by apply/idP/idP=> /cfclass_transr <-; apply: cfclass_refl. Qed.
Lemma cfclass_uniq phi : H <| G -> uniq (phi ^: G)%CF.
Proof.
move=> nsHG; rewrite map_inj_in_uniq ?enum_uniq // => Ty Tz; rewrite !mem_enum.
move=> {Ty}/rcosetsP[y Gy ->] {Tz}/rcosetsP[z Gz ->] /eqP.
case: repr_rcosetP => u Iphi_u; case: repr_rcosetP => v Iphi_v.
have [[Gu _] [Gv _]] := (setIdP Iphi_u, setIdP Iphi_v).
rewrite cfConjg_eqE ?groupM // => /rcoset_eqP.
by rewrite !rcosetM (rcoset_id Iphi_v) (rcoset_id Iphi_u).
Qed.
Lemma cfclass_invariant phi : G \subset 'I[phi] -> (phi ^: G)%CF = phi.
Proof.
move/setIidPl=> IGphi; rewrite /cfclass IGphi // rcosets_id.
by rewrite /(image _ _) enum_set1 /= repr_group cfConjgJ1.
Qed.
Lemma cfclass1 : H <| G -> (1 ^: G)%CF = [:: 1 : 'CF(H)].
Proof. by move/normal_norm=> nHG; rewrite cfclass_invariant ?inertia1. Qed.
Definition cfclass_Iirr (A : {set gT}) i := conjg_Iirr i @: A.
Lemma cfclass_IirrE i j :
(j \in cfclass_Iirr G i) = ('chi_j \in 'chi_i ^: G)%CF.
Proof.
apply/imsetP/cfclassP=> [[y Gy ->] | [y]]; exists y; rewrite ?conjg_IirrE //.
by apply: irr_inj; rewrite conjg_IirrE.
Qed.
Lemma eq_cfclass_IirrE i j :
(cfclass_Iirr G j == cfclass_Iirr G i) = (j \in cfclass_Iirr G i).
Proof.
apply/eqP/idP=> [<- | iGj]; first by rewrite cfclass_IirrE cfclass_refl.
by apply/setP=> k; rewrite !cfclass_IirrE in iGj *; apply/esym/cfclass_transr.
Qed.
Lemma im_cfclass_Iirr i :
H <| G -> perm_eq [seq 'chi_j | j in cfclass_Iirr G i] ('chi_i ^: G)%CF.
Proof.
move=> nsHG; have UchiG := cfclass_uniq 'chi_i nsHG.
apply: uniq_perm; rewrite ?(map_inj_uniq irr_inj) ?enum_uniq // => phi.
apply/imageP/idP=> [[j iGj ->] | /cfclassP[y]]; first by rewrite -cfclass_IirrE.
by exists (conjg_Iirr i y); rewrite ?imset_f ?conjg_IirrE.
Qed.
Lemma card_cfclass_Iirr i : H <| G -> #|cfclass_Iirr G i| = #|G : 'I_G['chi_i]|.
Proof.
move=> nsHG; rewrite -size_cfclass -(perm_size (im_cfclass_Iirr i nsHG)).
by rewrite size_map -cardE.
Qed.
Lemma reindex_cfclass R idx (op : Monoid.com_law idx) (F : 'CF(H) -> R) i :
H <| G ->
\big[op/idx]_(chi <- ('chi_i ^: G)%CF) F chi
= \big[op/idx]_(j | 'chi_j \in ('chi_i ^: G)%CF) F 'chi_j.
Proof.
move/im_cfclass_Iirr/(perm_big _) <-; rewrite big_image /=.
by apply: eq_bigl => j; rewrite cfclass_IirrE.
Qed.
Lemma cfResInd j:
H <| G ->
'Res[H] ('Ind[G] 'chi_j) = #|H|%:R^-1 *: (\sum_(y in G) 'chi_j ^ y)%CF.
Proof.
case/andP=> [sHG /subsetP nHG].
rewrite (reindex_inj invg_inj); apply/cfun_inP=> x Hx.
rewrite cfResE // cfIndE // ?cfunE ?sum_cfunE; congr (_ * _).
by apply: eq_big => [y | y Gy]; rewrite ?cfConjgE ?groupV ?invgK ?nHG.
Qed.
(* This is Isaacs, Theorem (6.2) *)
Lemma Clifford_Res_sum_cfclass i j :
H <| G -> j \in irr_constt ('Res[H, G] 'chi_i) ->
'Res[H] 'chi_i =
'['Res[H] 'chi_i, 'chi_j] *: (\sum_(chi <- ('chi_j ^: G)%CF) chi).
Proof.
move=> nsHG chiHj; have [sHG /subsetP nHG] := andP nsHG.
rewrite reindex_cfclass //= big_mkcond.
rewrite {1}['Res _]cfun_sum_cfdot linear_sum /=; apply: eq_bigr => k _.
have [[y Gy ->] | ] := altP (cfclassP _ _ _); first by rewrite cfdot_Res_conjg.
apply: contraNeq; rewrite scaler0 scaler_eq0 orbC => /norP[_ chiHk].
have{chiHk chiHj}: '['Res[H] ('Ind[G] 'chi_j), 'chi_k] != 0.
rewrite !inE !cfdot_Res_l in chiHj chiHk *.
apply: contraNneq chiHk; rewrite cfdot_sum_irr => /psumr_eq0P/(_ i isT)/eqP.
rewrite -cfdotC cfdotC mulf_eq0 conjC_eq0 (negbTE chiHj) /= => -> // i1.
by rewrite -cfdotC natr_ge0 // rpredM ?Cnat_cfdot_char ?cfInd_char ?irr_char.
rewrite cfResInd // cfdotZl mulf_eq0 cfdot_suml => /norP[_].
apply: contraR => chiGk'j; rewrite big1 // => x Gx; apply: contraNeq chiGk'j.
rewrite -conjg_IirrE cfdot_irr pnatr_eq0; case: (_ =P k) => // <- _.
by rewrite conjg_IirrE; apply/cfclassP; exists x.
Qed.
Lemma cfRes_Ind_invariant psi :
H <| G -> G \subset 'I[psi] -> 'Res ('Ind[G, H] psi) = #|G : H|%:R *: psi.
Proof.
case/andP=> sHG _ /subsetP IGpsi; apply/cfun_inP=> x Hx.
rewrite cfResE ?cfIndE ?natf_indexg // cfunE -mulrA mulrCA; congr (_ * _).
by rewrite mulr_natl -sumr_const; apply: eq_bigr => y /IGpsi/inertia_valJ->.
Qed.
(* This is Isaacs, Corollary (6.7). *)
Corollary constt0_Res_cfker i :
H <| G -> 0 \in irr_constt ('Res[H] 'chi[G]_i) -> H \subset cfker 'chi[G]_i.
Proof.
move=> nsHG /(Clifford_Res_sum_cfclass nsHG); have [sHG nHG] := andP nsHG.
rewrite irr0 cfdot_Res_l cfclass1 // big_seq1 cfInd_cfun1 //.
rewrite cfdotZr conjC_nat => def_chiH.
apply/subsetP=> x Hx; rewrite cfkerEirr inE -!(cfResE _ sHG) //.
by rewrite def_chiH !cfunE cfun11 cfun1E Hx.
Qed.
(* This is Isaacs, Lemma (6.8). *)
Lemma dvdn_constt_Res1_irr1 i j :
H <| G -> j \in irr_constt ('Res[H, G] 'chi_i) ->
exists n, 'chi_i 1%g = n%:R * 'chi_j 1%g.
Proof.
move=> nsHG chiHj; have [sHG nHG] := andP nsHG; rewrite -(cfResE _ sHG) //.
rewrite {1}(Clifford_Res_sum_cfclass nsHG chiHj) cfunE sum_cfunE.
have /natrP[n ->]: '['Res[H] 'chi_i, 'chi_j] \in Num.nat.
by rewrite Cnat_cfdot_char ?cfRes_char ?irr_char.
exists (n * size ('chi_j ^: G)%CF)%N; rewrite natrM -mulrA; congr (_ * _).
rewrite mulr_natl -[size _]card_ord big_tnth -sumr_const; apply: eq_bigr => k _.
by have /cfclassP[y Gy ->]:= mem_tnth k (in_tuple _); rewrite cfConjg1.
Qed.
Lemma cfclass_Ind phi psi :
H <| G -> psi \in (phi ^: G)%CF -> 'Ind[G] phi = 'Ind[G] psi.
Proof.
move=> nsHG /cfclassP[y Gy ->]; have [sHG /subsetP nHG] := andP nsHG.
apply/cfun_inP=> x Hx; rewrite !cfIndE //; congr (_ * _).
rewrite (reindex_acts 'R _ (groupVr Gy)) ?astabsR //=.
by apply: eq_bigr => z Gz; rewrite conjgM cfConjgE ?nHG.
Qed.
End Inertia.
Arguments inertia {gT B%_g} phi%_CF.
Arguments cfclass {gT A%_g} phi%_CF B%_g.
Arguments conjg_Iirr_inj {gT H} y [i1 i2] : rename.
Notation "''I[' phi ] " := (inertia phi) : group_scope.
Notation "''I[' phi ] " := (inertia_group phi) : Group_scope.
Notation "''I_' G [ phi ] " := (G%g :&: 'I[phi]) : group_scope.
Notation "''I_' G [ phi ] " := (G :&: 'I[phi])%G : Group_scope.
Notation "phi ^: G" := (cfclass phi G) : cfun_scope.
Section ConjRestrict.
Variables (gT : finGroupType) (G H K : {group gT}).
Lemma cfConjgRes_norm phi y :
y \in 'N(K) -> y \in 'N(H) -> ('Res[K, H] phi ^ y)%CF = 'Res (phi ^ y)%CF.
Proof.
move=> nKy nHy; have [sKH | not_sKH] := boolP (K \subset H); last first.
by rewrite !cfResEout // rmorph_alg cfConjg1.
by apply/cfun_inP=> x Kx; rewrite !(cfConjgE, cfResE) ?memJ_norm ?groupV.
Qed.
Lemma cfConjgRes phi y :
H <| G -> K <| G -> y \in G -> ('Res[K, H] phi ^ y)%CF = 'Res (phi ^ y)%CF.
Proof.
move=> /andP[_ nHG] /andP[_ nKG] Gy.
by rewrite cfConjgRes_norm ?(subsetP nHG) ?(subsetP nKG).
Qed.
Lemma sub_inertia_Res phi :
G \subset 'N(K) -> 'I_G[phi] \subset 'I_G['Res[K, H] phi].
Proof.
move=> nKG; apply/subsetP=> y /setIP[Gy /setIdP[nHy /eqP Iphi_y]].
by rewrite 2!inE Gy cfConjgRes_norm ?(subsetP nKG) ?Iphi_y /=.
Qed.
Lemma cfConjgInd_norm phi y :
y \in 'N(K) -> y \in 'N(H) -> ('Ind[H, K] phi ^ y)%CF = 'Ind (phi ^ y)%CF.
Proof.
move=> nKy nHy; have [sKH | not_sKH] := boolP (K \subset H).
by rewrite !cfConjgEin (cfIndIsom (norm_conj_isom nHy)).
rewrite !cfIndEout // linearZ -(cfConjg_iso y) rmorph1 /=; congr (_ *: _).
by rewrite cfConjg_cfuni ?norm1 ?inE.
Qed.
Lemma cfConjgInd phi y :
H <| G -> K <| G -> y \in G -> ('Ind[H, K] phi ^ y)%CF = 'Ind (phi ^ y)%CF.
Proof.
move=> /andP[_ nHG] /andP[_ nKG] Gy.
by rewrite cfConjgInd_norm ?(subsetP nHG) ?(subsetP nKG).
Qed.
Lemma sub_inertia_Ind phi :
G \subset 'N(H) -> 'I_G[phi] \subset 'I_G['Ind[H, K] phi].
Proof.
move=> nHG; apply/subsetP=> y /setIP[Gy /setIdP[nKy /eqP Iphi_y]].
by rewrite 2!inE Gy cfConjgInd_norm ?(subsetP nHG) ?Iphi_y /=.
Qed.
End ConjRestrict.
Section MoreInertia.
Variables (gT : finGroupType) (G H : {group gT}) (i : Iirr H).
Let T := 'I_G['chi_i].
Lemma inertia_id : 'I_T['chi_i] = T. Proof. by rewrite -setIA setIid. Qed.
Lemma cfclass_inertia : ('chi[H]_i ^: T)%CF = [:: 'chi_i].
Proof.
rewrite /cfclass inertia_id rcosets_id /(image _ _) enum_set1 /=.
by rewrite repr_group cfConjgJ1.
Qed.
End MoreInertia.
Section ConjMorph.
Variables (aT rT : finGroupType) (D G H : {group aT}) (f : {morphism D >-> rT}).
Lemma cfConjgMorph (phi : 'CF(f @* H)) y :
y \in D -> y \in 'N(H) -> (cfMorph phi ^ y)%CF = cfMorph (phi ^ f y).
Proof.
move=> Dy nHy; have [sHD | not_sHD] := boolP (H \subset D); last first.
by rewrite !cfMorphEout // rmorph_alg cfConjg1.
apply/cfun_inP=> x Gx; rewrite !(cfConjgE, cfMorphE) ?memJ_norm ?groupV //.
by rewrite morphJ ?morphV ?groupV // (subsetP sHD).
by rewrite (subsetP (morphim_norm _ _)) ?mem_morphim.
Qed.
Lemma inertia_morph_pre (phi : 'CF(f @* H)) :
H <| G -> G \subset D -> 'I_G[cfMorph phi] = G :&: f @*^-1 'I_(f @* G)[phi].
Proof.
case/andP=> sHG nHG sGD; have sHD := subset_trans sHG sGD.
apply/setP=> y; rewrite !in_setI; apply: andb_id2l => Gy.
have [Dy nHy] := (subsetP sGD y Gy, subsetP nHG y Gy).
rewrite Dy inE nHy 4!inE mem_morphim // -morphimJ ?(normP nHy) // subxx /=.
rewrite cfConjgMorph //; apply/eqP/eqP=> [Iphi_y | -> //].
by apply/cfun_inP=> _ /morphimP[x Dx Hx ->]; rewrite -!cfMorphE ?Iphi_y.
Qed.
Lemma inertia_morph_im (phi : 'CF(f @* H)) :
H <| G -> G \subset D -> f @* 'I_G[cfMorph phi] = 'I_(f @* G)[phi].
Proof.
move=> nsHG sGD; rewrite inertia_morph_pre // morphim_setIpre.
by rewrite (setIidPr _) ?Inertia_sub.
Qed.
Variables (R S : {group rT}).
Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}).
Hypotheses (isoG : isom G R g) (isoH : isom H S h).
Hypotheses (eq_hg : {in H, h =1 g}) (sHG : H \subset G).
(* This does not depend on the (isoG : isom G R g) assumption. *)
Lemma cfConjgIsom phi y :
y \in G -> y \in 'N(H) -> (cfIsom isoH phi ^ g y)%CF = cfIsom isoH (phi ^ y).
Proof.
move=> Gy nHy; have [_ defS] := isomP isoH.
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
apply/cfun_inP=> gx; rewrite -{1}defS => /morphimP[x Gx Hx ->] {gx}.
rewrite cfConjgE; last by rewrite -defS inE -morphimJ ?(normP nHy).
by rewrite -morphV -?morphJ -?eq_hg ?cfIsomE ?cfConjgE ?memJ_norm ?groupV.
Qed.
Lemma inertia_isom phi : 'I_R[cfIsom isoH phi] = g @* 'I_G[phi].
Proof.
have [[_ defS] [injg <-]] := (isomP isoH, isomP isoG).
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
rewrite /inertia !setIdE morphimIdom setIA -{1}defS -injm_norm ?injmI //.
apply/setP=> gy /[!inE]; apply: andb_id2l => /morphimP[y Gy nHy ->] {gy}.
rewrite cfConjgIsom // -sub1set -morphim_set1 // injmSK ?sub1set //= inE.
apply/eqP/eqP=> [Iphi_y | -> //].
by apply/cfun_inP=> x Hx; rewrite -!(cfIsomE isoH) ?Iphi_y.
Qed.
End ConjMorph.
Section ConjQuotient.
Variables gT : finGroupType.
Implicit Types G H K : {group gT}.
Lemma cfConjgMod_norm H K (phi : 'CF(H / K)) y :
y \in 'N(K) -> y \in 'N(H) -> ((phi %% K) ^ y)%CF = (phi ^ coset K y %% K)%CF.
Proof. exact: cfConjgMorph. Qed.
Lemma cfConjgMod G H K (phi : 'CF(H / K)) y :
H <| G -> K <| G -> y \in G ->
((phi %% K) ^ y)%CF = (phi ^ coset K y %% K)%CF.
Proof.
move=> /andP[_ nHG] /andP[_ nKG] Gy.
by rewrite cfConjgMod_norm ?(subsetP nHG) ?(subsetP nKG).
Qed.
Lemma cfConjgQuo_norm H K (phi : 'CF(H)) y :
y \in 'N(K) -> y \in 'N(H) -> ((phi / K) ^ coset K y)%CF = (phi ^ y / K)%CF.
Proof.
move=> nKy nHy; have keryK: (K \subset cfker (phi ^ y)) = (K \subset cfker phi).
by rewrite cfker_conjg // -{1}(normP nKy) conjSg.
have [kerK | not_kerK] := boolP (K \subset cfker phi); last first.
by rewrite !cfQuoEout ?rmorph_alg ?cfConjg1 ?keryK.
apply/cfun_inP=> _ /morphimP[x nKx Hx ->].
have nHyb: coset K y \in 'N(H / K) by rewrite inE -morphimJ ?(normP nHy).
rewrite !(cfConjgE, cfQuoEnorm) ?keryK // ?in_setI ?Hx //.
rewrite -morphV -?morphJ ?groupV // cfQuoEnorm //.
by rewrite inE memJ_norm ?Hx ?groupJ ?groupV.
Qed.
Lemma cfConjgQuo G H K (phi : 'CF(H)) y :
H <| G -> K <| G -> y \in G ->
((phi / K) ^ coset K y)%CF = (phi ^ y / K)%CF.
Proof.
move=> /andP[_ nHG] /andP[_ nKG] Gy.
by rewrite cfConjgQuo_norm ?(subsetP nHG) ?(subsetP nKG).
Qed.
Lemma inertia_mod_pre G H K (phi : 'CF(H / K)) :
H <| G -> K <| G -> 'I_G[phi %% K] = G :&: coset K @*^-1 'I_(G / K)[phi].
Proof. by move=> nsHG /andP[_]; apply: inertia_morph_pre. Qed.
Lemma inertia_mod_quo G H K (phi : 'CF(H / K)) :
H <| G -> K <| G -> ('I_G[phi %% K] / K)%g = 'I_(G / K)[phi].
Proof. by move=> nsHG /andP[_]; apply: inertia_morph_im. Qed.
Lemma inertia_quo G H K (phi : 'CF(H)) :
H <| G -> K <| G -> K \subset cfker phi ->
'I_(G / K)[phi / K] = ('I_G[phi] / K)%g.
Proof.
move=> nsHG nsKG kerK; rewrite -inertia_mod_quo ?cfQuoK //.
by rewrite (normalS _ (normal_sub nsHG)) // (subset_trans _ (cfker_sub phi)).
Qed.
End ConjQuotient.
Section InertiaSdprod.
Variables (gT : finGroupType) (K H G : {group gT}).
Hypothesis defG : K ><| H = G.
Lemma cfConjgSdprod phi y :
y \in 'N(K) -> y \in 'N(H) ->
(cfSdprod defG phi ^ y = cfSdprod defG (phi ^ y))%CF.
Proof.
move=> nKy nHy.
have nGy: y \in 'N(G) by rewrite -sub1set -(sdprodW defG) normsM ?sub1set.
rewrite -{2}[phi](cfSdprodK defG) cfConjgRes_norm // cfRes_sdprodK //.
by rewrite cfker_conjg // -{1}(normP nKy) conjSg cfker_sdprod.
Qed.
Lemma inertia_sdprod (L : {group gT}) phi :
L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfSdprod defG phi] = 'I_L[phi].
Proof.
move=> nKL nHL; have nGL: L \subset 'N(G) by rewrite -(sdprodW defG) normsM.
apply/setP=> z; rewrite !in_setI ![z \in 'I[_]]inE; apply: andb_id2l => Lz.
rewrite cfConjgSdprod ?(subsetP nKL) ?(subsetP nHL) ?(subsetP nGL) //=.
by rewrite (can_eq (cfSdprodK defG)).
Qed.
End InertiaSdprod.
Section InertiaDprod.
Variables (gT : finGroupType) (G K H : {group gT}).
Implicit Type L : {group gT}.
Hypothesis KxH : K \x H = G.
Lemma cfConjgDprodl phi y :
y \in 'N(K) -> y \in 'N(H) ->
(cfDprodl KxH phi ^ y = cfDprodl KxH (phi ^ y))%CF.
Proof. by move=> nKy nHy; apply: cfConjgSdprod. Qed.
Lemma cfConjgDprodr psi y :
y \in 'N(K) -> y \in 'N(H) ->
(cfDprodr KxH psi ^ y = cfDprodr KxH (psi ^ y))%CF.
Proof. by move=> nKy nHy; apply: cfConjgSdprod. Qed.
Lemma cfConjgDprod phi psi y :
y \in 'N(K) -> y \in 'N(H) ->
(cfDprod KxH phi psi ^ y = cfDprod KxH (phi ^ y) (psi ^ y))%CF.
Proof. by move=> nKy nHy; rewrite rmorphM /= cfConjgDprodl ?cfConjgDprodr. Qed.
Lemma inertia_dprodl L phi :
L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfDprodl KxH phi] = 'I_L[phi].
Proof. by move=> nKL nHL; apply: inertia_sdprod. Qed.
Lemma inertia_dprodr L psi :
L \subset 'N(K) -> L \subset 'N(H) -> 'I_L[cfDprodr KxH psi] = 'I_L[psi].
Proof. by move=> nKL nHL; apply: inertia_sdprod. Qed.
Lemma inertia_dprod L (phi : 'CF(K)) (psi : 'CF(H)) :
L \subset 'N(K) -> L \subset 'N(H) -> phi 1%g != 0 -> psi 1%g != 0 ->
'I_L[cfDprod KxH phi psi] = 'I_L[phi] :&: 'I_L[psi].
Proof.
move=> nKL nHL nz_phi nz_psi; apply/eqP; rewrite eqEsubset subsetI.
rewrite -{1}(inertia_scale_nz psi nz_phi) -{1}(inertia_scale_nz phi nz_psi).
rewrite -(cfDprod_Resl KxH) -(cfDprod_Resr KxH) !sub_inertia_Res //=.
by rewrite -inertia_dprodl -?inertia_dprodr // -setIIr setIS ?inertia_mul.
Qed.
Lemma inertia_dprod_irr L i j :
L \subset 'N(K) -> L \subset 'N(H) ->
'I_L[cfDprod KxH 'chi_i 'chi_j] = 'I_L['chi_i] :&: 'I_L['chi_j].
Proof. by move=> nKL nHL; rewrite inertia_dprod ?irr1_neq0. Qed.
End InertiaDprod.
Section InertiaBigdprod.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Implicit Type L : {group gT}.
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Section ConjBig.
Variable y : gT.
Hypothesis nAy: forall i, P i -> y \in 'N(A i).
Lemma cfConjgBigdprodi i (phi : 'CF(A i)) :
(cfBigdprodi defG phi ^ y = cfBigdprodi defG (phi ^ y))%CF.
Proof.
rewrite cfConjgDprodl; try by case: ifP => [/nAy// | _]; rewrite norm1 inE.
congr (cfDprodl _ _); case: ifP => [Pi | _].
by rewrite cfConjgRes_norm ?nAy.
by apply/cfun_inP=> _ /set1P->; rewrite !(cfRes1, cfConjg1).
rewrite -sub1set norms_gen ?norms_bigcup // sub1set.
by apply/bigcapP=> j /andP[/nAy].
Qed.
Lemma cfConjgBigdprod phi :
(cfBigdprod defG phi ^ y = cfBigdprod defG (fun i => phi i ^ y))%CF.
Proof.
by rewrite rmorph_prod /=; apply: eq_bigr => i _; apply: cfConjgBigdprodi.
Qed.
End ConjBig.
Section InertiaBig.
Variable L : {group gT}.
Hypothesis nAL : forall i, P i -> L \subset 'N(A i).
Lemma inertia_bigdprodi i (phi : 'CF(A i)) :
P i -> 'I_L[cfBigdprodi defG phi] = 'I_L[phi].
Proof.
move=> Pi; rewrite inertia_dprodl ?Pi ?cfRes_id ?nAL //.
by apply/norms_gen/norms_bigcup/bigcapsP=> j /andP[/nAL].
Qed.
Lemma inertia_bigdprod phi (Phi := cfBigdprod defG phi) :
Phi 1%g != 0 -> 'I_L[Phi] = L :&: \bigcap_(i | P i) 'I_L[phi i].
Proof.
move=> nz_Phi; apply/eqP; rewrite eqEsubset; apply/andP; split.
rewrite subsetI Inertia_sub; apply/bigcapsP=> i Pi.
have [] := cfBigdprodK nz_Phi Pi; move: (_ / _) => a nz_a <-.
by rewrite inertia_scale_nz ?sub_inertia_Res //= ?nAL.
rewrite subsetI subsetIl; apply: subset_trans (inertia_prod _ _ _).
apply: setISS.
by rewrite -(bigdprodWY defG) norms_gen ?norms_bigcup //; apply/bigcapsP.
apply/bigcapsP=> i Pi; rewrite (bigcap_min i) //.
by rewrite -inertia_bigdprodi ?subsetIr.
Qed.
Lemma inertia_bigdprod_irr Iphi (phi := fun i => 'chi_(Iphi i)) :
'I_L[cfBigdprod defG phi] = L :&: \bigcap_(i | P i) 'I_L[phi i].
Proof.
rewrite inertia_bigdprod // -[cfBigdprod _ _]cfIirrE ?irr1_neq0 //.
by apply: cfBigdprod_irr => i _; apply: mem_irr.
Qed.
End InertiaBig.
End InertiaBigdprod.
Section ConsttInertiaBijection.
Variables (gT : finGroupType) (H G : {group gT}) (t : Iirr H).
Hypothesis nsHG : H <| G.
Local Notation theta := 'chi_t.
Local Notation T := 'I_G[theta]%G.
Local Notation "` 'T'" := 'I_(gval G)[theta] (format "` 'T'") : group_scope.
Let calA := irr_constt ('Ind[T] theta).
Let calB := irr_constt ('Ind[G] theta).
Local Notation AtoB := (Ind_Iirr G).
(* This is Isaacs, Theorem (6.11). *)
Theorem constt_Inertia_bijection :
[/\ (*a*) {in calA, forall s, 'Ind[G] 'chi_s \in irr G},
(*b*) {in calA &, injective (Ind_Iirr G)},
Ind_Iirr G @: calA =i calB,
(*c*) {in calA, forall s (psi := 'chi_s) (chi := 'Ind[G] psi),
[predI irr_constt ('Res chi) & calA] =i pred1 s}
& (*d*) {in calA, forall s (psi := 'chi_s) (chi := 'Ind[G] psi),
'['Res psi, theta] = '['Res chi, theta]}].
Proof.
have [sHG sTG]: H \subset G /\ T \subset G by rewrite subsetIl normal_sub.
have nsHT : H <| T := normal_Inertia theta sHG; have sHT := normal_sub nsHT.
have AtoB_P s (psi := 'chi_s) (chi := 'Ind[G] psi): s \in calA ->
[/\ chi \in irr G, AtoB s \in calB & '['Res psi, theta] = '['Res chi, theta]].
- rewrite constt_Ind_Res => sHt; have [r sGr] := constt_cfInd_irr s sTG.
rewrite constt_Ind_Res.
have rTs: s \in irr_constt ('Res[T] 'chi_r) by rewrite -constt_Ind_Res.
have NrT: 'Res[T] 'chi_r \is a character by rewrite cfRes_char ?irr_char.
have rHt: t \in irr_constt ('Res[H] 'chi_r).
by have:= constt_Res_trans NrT rTs sHt; rewrite cfResRes.
pose e := '['Res[H] 'chi_r, theta]; set f := '['Res[H] psi, theta].
have DrH: 'Res[H] 'chi_r = e *: \sum_(xi <- (theta ^: G)%CF) xi.
exact: Clifford_Res_sum_cfclass.
have DpsiH: 'Res[H] psi = f *: theta.
rewrite (Clifford_Res_sum_cfclass nsHT sHt).
by rewrite cfclass_invariant ?subsetIr ?big_seq1.
have ub_chi_r: 'chi_r 1%g <= chi 1%g ?= iff ('chi_r == chi).
have Nchi: chi \is a character by rewrite cfInd_char ?irr_char.
have [chi1 Nchi1->] := constt_charP _ Nchi sGr.
rewrite addrC cfunE -leifBLR subrr eq_sym -subr_eq0 addrK.
by split; rewrite ?char1_ge0 // eq_sym char1_eq0.
have lb_chi_r: chi 1%g <= 'chi_r 1%g ?= iff (f == e).
rewrite cfInd1 // -(cfRes1 H) DpsiH -(cfRes1 H 'chi_r) DrH !cfunE sum_cfunE.
rewrite (eq_big_seq (fun _ => theta 1%g)) => [|i]; last first.
by case/cfclassP=> y _ ->; rewrite cfConjg1.
rewrite reindex_cfclass //= sumr_const -(eq_card (cfclass_IirrE _ _)).
rewrite mulr_natl mulrnAr card_cfclass_Iirr //.
rewrite (mono_leif (ler_pMn2r (indexg_gt0 G T))).
rewrite (mono_leif (ler_pM2r (irr1_gt0 t))); apply: leif_eq.
by rewrite /e -(cfResRes _ sHT) ?cfdot_Res_ge_constt.
have [_ /esym] := leif_trans ub_chi_r lb_chi_r; rewrite eqxx.
by case/andP=> /eqP Dchi /eqP->; rewrite cfIirrE -/chi -?Dchi ?mem_irr.
have part_c: {in calA, forall s (chi := 'Ind[G] 'chi_s),
[predI irr_constt ('Res[T] chi) & calA] =i pred1 s}.
- move=> s As chi s1; have [irr_chi _ /eqP Dchi_theta] := AtoB_P s As.
have chiTs: s \in irr_constt ('Res[T] chi).
by rewrite irr_consttE cfdot_Res_l irrWnorm ?oner_eq0.
apply/andP/eqP=> [[/= chiTs1 As1] | -> //].
apply: contraTeq Dchi_theta => s's1; rewrite lt_eqF // -/chi.
have [|phi Nphi DchiT] := constt_charP _ _ chiTs.
by rewrite cfRes_char ?cfInd_char ?irr_char.
have [|phi1 Nphi1 Dphi] := constt_charP s1 Nphi _.
rewrite irr_consttE -(canLR (addKr _) DchiT) addrC cfdotBl cfdot_irr.
by rewrite mulrb ifN_eqC ?subr0.
rewrite -(cfResRes chi sHT sTG) DchiT Dphi !rmorphD !cfdotDl /=.
rewrite -ltrBDl subrr ltr_wpDr ?lt_def //;
rewrite natr_ge0 ?Cnat_cfdot_char ?cfRes_char ?irr_char //.
by rewrite andbT -irr_consttE -constt_Ind_Res.
do [split=> //; try by move=> s /AtoB_P[]] => [s1 s2 As1 As2 | r].
have [[irr_s1G _ _] [irr_s2G _ _]] := (AtoB_P _ As1, AtoB_P _ As2).
move/(congr1 (tnth (irr G))); rewrite !cfIirrE // => eq_s12_G.
apply/eqP; rewrite -[_ == _]part_c // inE /= As1 -eq_s12_G.
by rewrite -As1 [_ && _]part_c // inE /=.
apply/imsetP/idP=> [[s /AtoB_P[_ BsG _] -> //] | Br].
have /exists_inP[s rTs As]: [exists s in irr_constt ('Res 'chi_r), s \in calA].
rewrite -negb_forall_in; apply: contra Br => /eqfun_inP => o_tT_rT.
rewrite -(cfIndInd _ sTG sHT) -cfdot_Res_r ['Res _]cfun_sum_constt.
by rewrite cfdot_sumr big1 // => i rTi; rewrite cfdotZr o_tT_rT ?mulr0.
exists s => //; have [/irrP[r1 DsG] _ _] := AtoB_P s As.
by apply/eqP; rewrite /AtoB -constt_Ind_Res DsG irrK constt_irr in rTs *.
Qed.
End ConsttInertiaBijection.
Section ExtendInvariantIrr.
Variable gT : finGroupType.
Implicit Types G H K L M N : {group gT}.
Section ConsttIndExtendible.
Variables (G N : {group gT}) (t : Iirr N) (c : Iirr G).
Let theta := 'chi_t.
Let chi := 'chi_c.
Definition mul_Iirr b := cfIirr ('chi_b * chi).
Definition mul_mod_Iirr (b : Iirr (G / N)) := mul_Iirr (mod_Iirr b).
Hypotheses (nsNG : N <| G) (cNt : 'Res[N] chi = theta).
Let sNG : N \subset G. Proof. exact: normal_sub. Qed.
Let nNG : G \subset 'N(N). Proof. exact: normal_norm. Qed.
Lemma extendible_irr_invariant : G \subset 'I[theta].
Proof.
apply/subsetP=> y Gy; have nNy := subsetP nNG y Gy.
rewrite inE nNy; apply/eqP/cfun_inP=> x Nx; rewrite cfConjgE // -cNt.
by rewrite !cfResE ?memJ_norm ?cfunJ ?groupV.
Qed.
Let IGtheta := extendible_irr_invariant.
(* This is Isaacs, Theorem (6.16) *)
Theorem constt_Ind_mul_ext f (phi := 'chi_f) (psi := phi * theta) :
G \subset 'I[phi] -> psi \in irr N ->
let calS := irr_constt ('Ind phi) in
[/\ {in calS, forall b, 'chi_b * chi \in irr G},
{in calS &, injective mul_Iirr},
irr_constt ('Ind psi) =i [seq mul_Iirr b | b in calS]
& 'Ind psi = \sum_(b in calS) '['Ind phi, 'chi_b] *: 'chi_(mul_Iirr b)].
Proof.
move=> IGphi irr_psi calS.
have IGpsi: G \subset 'I[psi].
by rewrite (subset_trans _ (inertia_mul _ _)) // subsetI IGphi.
pose e b := '['Ind[G] phi, 'chi_b]; pose d b g := '['chi_b * chi, 'chi_g * chi].
have Ne b: e b \in Num.nat by rewrite Cnat_cfdot_char ?cfInd_char ?irr_char.
have egt0 b: b \in calS -> e b > 0 by rewrite natr_gt0.
have DphiG: 'Ind phi = \sum_(b in calS) e b *: 'chi_b := cfun_sum_constt _.
have DpsiG: 'Ind psi = \sum_(b in calS) e b *: 'chi_b * chi.
by rewrite /psi -cNt cfIndM // DphiG mulr_suml.
pose d_delta := [forall b in calS, forall g in calS, d b g == (b == g)%:R].
have charMchi b: 'chi_b * chi \is a character by rewrite rpredM ?irr_char.
have [_]: '['Ind[G] phi] <= '['Ind[G] psi] ?= iff d_delta.
pose sum_delta := \sum_(b in calS) e b * \sum_(g in calS) e g * (b == g)%:R.
pose sum_d := \sum_(b in calS) e b * \sum_(g in calS) e g * d b g.
have ->: '['Ind[G] phi] = sum_delta.
rewrite DphiG cfdot_suml; apply: eq_bigr => b _; rewrite cfdotZl cfdot_sumr.
by congr (_ * _); apply: eq_bigr => g; rewrite cfdotZr cfdot_irr conj_natr.
have ->: '['Ind[G] psi] = sum_d.
rewrite DpsiG cfdot_suml; apply: eq_bigr => b _.
rewrite -scalerAl cfdotZl cfdot_sumr; congr (_ * _).
by apply: eq_bigr => g _; rewrite -scalerAl cfdotZr conj_natr.
have eMmono := mono_leif (ler_pM2l (egt0 _ _)).
apply: leif_sum => b /eMmono->; apply: leif_sum => g /eMmono->.
split; last exact: eq_sym.
have /natrP[n Dd]: d b g \in Num.nat by rewrite Cnat_cfdot_char.
have [Db | _] := eqP; rewrite Dd leC_nat // -ltC_nat -Dd Db cfnorm_gt0.
by rewrite -char1_eq0 // cfunE mulf_neq0 ?irr1_neq0.
rewrite -!cfdot_Res_l ?cfRes_Ind_invariant // !cfdotZl cfnorm_irr irrWnorm //.
rewrite eqxx => /esym/forall_inP/(_ _ _)/eqfun_inP; rewrite /d /= => Dd.
have irrMchi: {in calS, forall b, 'chi_b * chi \in irr G}.
by move=> b Sb; rewrite /= irrEchar charMchi Dd ?eqxx.
have injMchi: {in calS &, injective mul_Iirr}.
move=> b g Sb Sg /(congr1 (fun s => '['chi_s, 'chi_(mul_Iirr g)]))/eqP.
by rewrite cfnorm_irr !cfIirrE ?irrMchi ?Dd // pnatr_eq1; case: (b =P g).
have{DpsiG} ->: 'Ind psi = \sum_(b in calS) e b *: 'chi_(mul_Iirr b).
by rewrite DpsiG; apply: eq_bigr => b Sb; rewrite -scalerAl cfIirrE ?irrMchi.
split=> // i; rewrite irr_consttE cfdot_suml;
apply/idP/idP=> [|/imageP[b Sb ->]].
apply: contraR => N'i; rewrite big1 // => b Sb.
rewrite cfdotZl cfdot_irr mulrb ifN_eqC ?mulr0 //.
by apply: contraNneq N'i => ->; apply: image_f.
rewrite gt_eqF // (bigD1 b) //= cfdotZl cfnorm_irr mulr1 ltr_wpDr ?egt0 //.
apply: sumr_ge0 => g /andP[Sg _]; rewrite cfdotZl cfdot_irr.
by rewrite mulr_ge0 ?ler0n ?natr_ge0.
Qed.
(* This is Isaacs, Corollary (6.17) (due to Gallagher). *)
Corollary constt_Ind_ext :
[/\ forall b : Iirr (G / N), 'chi_(mod_Iirr b) * chi \in irr G,
injective mul_mod_Iirr,
irr_constt ('Ind theta) =i codom mul_mod_Iirr
& 'Ind theta = \sum_b 'chi_b 1%g *: 'chi_(mul_mod_Iirr b)].
Proof.
have IHchi0: G \subset 'I['chi[N]_0] by rewrite inertia_irr0.
have [] := constt_Ind_mul_ext IHchi0; rewrite irr0 ?mul1r ?mem_irr //.
set psiG := 'Ind 1 => irrMchi injMchi constt_theta {2}->.
have dot_psiG b: '[psiG, 'chi_(mod_Iirr b)] = 'chi[G / N]_b 1%g.
rewrite mod_IirrE // -cfdot_Res_r cfRes_sub_ker ?cfker_mod //.
by rewrite cfdotZr cfnorm1 mulr1 conj_natr ?cfMod1 ?Cnat_irr1.
have mem_psiG (b : Iirr (G / N)): mod_Iirr b \in irr_constt psiG.
by rewrite irr_consttE dot_psiG irr1_neq0.
have constt_psiG b: (b \in irr_constt psiG) = (N \subset cfker 'chi_b).
apply/idP/idP=> [psiGb | /quo_IirrK <- //].
by rewrite constt0_Res_cfker // -constt_Ind_Res irr0.
split=> [b | b g /injMchi/(can_inj (mod_IirrK nsNG))-> // | b0 | ].
- exact: irrMchi.
- rewrite constt_theta.
apply/imageP/imageP=> [][b psiGb ->]; last by exists (mod_Iirr b).
by exists (quo_Iirr N b) => //; rewrite /mul_mod_Iirr quo_IirrK -?constt_psiG.
rewrite (reindex_onto _ _ (in1W (mod_IirrK nsNG))) /=.
apply/esym/eq_big => b; first by rewrite constt_psiG quo_IirrKeq.
by rewrite -dot_psiG /mul_mod_Iirr => /eqP->.
Qed.
End ConsttIndExtendible.
(* This is Isaacs, Theorem (6.19). *)
Theorem invariant_chief_irr_cases G K L s (theta := 'chi[K]_s) :
chief_factor G L K -> abelian (K / L) -> G \subset 'I[theta] ->
let t := #|K : L| in
[\/ 'Res[L] theta \in irr L,
exists2 e, exists p, 'Res[L] theta = e%:R *: 'chi_p & (e ^ 2)%N = t
| exists2 p, injective p & 'Res[L] theta = \sum_(i < t) 'chi_(p i)].
Proof.
case/andP=> /maxgroupP[/andP[ltLK nLG] maxL] nsKG abKbar IGtheta t.
have [sKG nKG] := andP nsKG; have sLG := subset_trans (proper_sub ltLK) sKG.
have nsLG: L <| G by apply/andP.
have nsLK := normalS (proper_sub ltLK) sKG nsLG; have [sLK nLK] := andP nsLK.
have [p0 sLp0] := constt_cfRes_irr L s; rewrite -/theta in sLp0.
pose phi := 'chi_p0; pose T := 'I_G[phi].
have sTG: T \subset G := subsetIl G _.
have /eqP mulKT: (K * T)%g == G.
rewrite eqEcard mulG_subG sKG sTG -LagrangeMr -indexgI -(Lagrange sTG) /= -/T.
rewrite mulnC leq_mul // setIA (setIidPl sKG) -!size_cfclass // -/phi.
rewrite uniq_leq_size ?cfclass_uniq // => _ /cfclassP[x Gx ->].
have: conjg_Iirr p0 x \in irr_constt ('Res theta).
have /inertiaJ <-: x \in 'I[theta] := subsetP IGtheta x Gx.
by rewrite -(cfConjgRes _ nsKG) // irr_consttE conjg_IirrE // cfConjg_iso.
apply: contraR; rewrite -conjg_IirrE // => not_sLp0x.
rewrite (Clifford_Res_sum_cfclass nsLK sLp0) cfdotZl cfdot_suml.
rewrite big1_seq ?mulr0 // => _ /cfclassP[y Ky ->]; rewrite -conjg_IirrE //.
rewrite cfdot_irr mulrb ifN_eq ?(contraNneq _ not_sLp0x) // => <-.
by rewrite conjg_IirrE //; apply/cfclassP; exists y.
have nsKT_G: K :&: T <| G.
rewrite /normal subIset ?sKG // -mulKT setIA (setIidPl sKG) mulG_subG.
rewrite normsIG // sub_der1_norm ?subsetIl //.
exact: subset_trans (der1_min nLK abKbar) (sub_Inertia _ sLK).
have [e DthL]: exists e, 'Res theta = e%:R *: \sum_(xi <- (phi ^: K)%CF) xi.
rewrite (Clifford_Res_sum_cfclass nsLK sLp0) -/phi; set e := '[_, _].
exists (Num.truncn e).
by rewrite truncnK ?Cnat_cfdot_char ?cfRes_char ?irr_char.
have [defKT | ltKT_K] := eqVneq (K :&: T) K; last first.
have defKT: K :&: T = L.
apply: maxL; last by rewrite subsetI sLK sub_Inertia.
by rewrite normal_norm // properEneq ltKT_K subsetIl.
have t_cast: size (phi ^: K)%CF = t.
by rewrite size_cfclass //= -{2}(setIidPl sKG) -setIA defKT.
pose phiKt := Tuple (introT eqP t_cast); pose p i := cfIirr (tnth phiKt i).
have pK i: 'chi_(p i) = (phi ^: K)%CF`_i.
rewrite cfIirrE; first by rewrite (tnth_nth 0).
by have /cfclassP[y _ ->] := mem_tnth i phiKt; rewrite cfConjg_irr ?mem_irr.
constructor 3; exists p => [i j /(congr1 (tnth (irr L)))/eqP| ].
by apply: contraTeq; rewrite !pK !nth_uniq ?t_cast ?cfclass_uniq.
have{} DthL: 'Res theta = e%:R *: \sum_(i < t) (phi ^: K)%CF`_i.
by rewrite DthL (big_nth 0) big_mkord t_cast.
suffices /eqP e1: e == 1 by rewrite DthL e1 scale1r; apply: eq_bigr.
have Dth1: theta 1%g = e%:R * t%:R * phi 1%g.
rewrite -[t]card_ord -mulrA -(cfRes1 L) DthL cfunE; congr (_ * _).
rewrite mulr_natl -sumr_const sum_cfunE -t_cast; apply: eq_bigr => i _.
by have /cfclassP[y _ ->] := mem_nth 0 (valP i); rewrite cfConjg1.
rewrite eqn_leq lt0n (contraNneq _ (irr1_neq0 s)); last first.
by rewrite Dth1 => ->; rewrite !mul0r.
rewrite -leC_nat -(ler_pM2r (gt0CiG K L)) -/t -(ler_pM2r (irr1_gt0 p0)).
rewrite mul1r -Dth1 -cfInd1 //.
by rewrite char1_ge_constt ?cfInd_char ?irr_char ?constt_Ind_Res.
have IKphi: 'I_K[phi] = K by rewrite -{1}(setIidPl sKG) -setIA.
have{} DthL: 'Res[L] theta = e%:R *: phi.
by rewrite DthL -[rhs in (_ ^: rhs)%CF]IKphi cfclass_inertia big_seq1.
pose mmLth := @mul_mod_Iirr K L s.
have linKbar := char_abelianP _ abKbar.
have LmodL i: ('chi_i %% L)%CF \is a linear_char := cfMod_lin_char (linKbar i).
have mmLthE i: 'chi_(mmLth i) = ('chi_i %% L)%CF * theta.
by rewrite cfIirrE ?mod_IirrE // mul_lin_irr ?mem_irr.
have mmLthL i: 'Res[L] 'chi_(mmLth i) = 'Res[L] theta.
rewrite mmLthE rmorphM /= cfRes_sub_ker ?cfker_mod ?lin_char1 //.
by rewrite scale1r mul1r.
have [inj_Mphi | /injectivePn[i [j i'j eq_mm_ij]]] := boolP (injectiveb mmLth).
suffices /eqP e1: e == 1 by constructor 1; rewrite DthL e1 scale1r mem_irr.
rewrite eqn_leq lt0n (contraNneq _ (irr1_neq0 s)); last first.
by rewrite -(cfRes1 L) DthL cfunE => ->; rewrite !mul0r.
rewrite -leq_sqr -leC_nat natrX -(ler_pM2r (irr1_gt0 p0)) -mulrA mul1r.
have ->: e%:R * 'chi_p0 1%g = 'Res[L] theta 1%g by rewrite DthL cfunE.
rewrite cfRes1 -(ler_pM2l (gt0CiG K L)) -cfInd1 // -/phi.
rewrite -card_quotient // -card_Iirr_abelian // mulr_natl.
rewrite ['Ind phi]cfun_sum_cfdot sum_cfunE (bigID [in codom mmLth]) /=.
rewrite ler_wpDr ?sumr_ge0 // => [i _|].
by rewrite char1_ge0 ?rpredZ_nat ?Cnat_cfdot_char ?cfInd_char ?irr_char.
rewrite -big_uniq //= big_image -sumr_const ler_sum // => i _.
rewrite cfunE -[in leRHS](cfRes1 L) -cfdot_Res_r mmLthL cfRes1.
by rewrite DthL cfdotZr rmorph_nat cfnorm_irr mulr1.
constructor 2; exists e; first by exists p0.
pose mu := (('chi_i / 'chi_j)%R %% L)%CF; pose U := cfker mu.
have lin_mu: mu \is a linear_char by rewrite cfMod_lin_char ?rpred_div.
have Uj := lin_char_unitr (linKbar j).
have ltUK: U \proper K.
rewrite /proper cfker_sub /U; have /irrP[k Dmu] := lin_char_irr lin_mu.
rewrite Dmu subGcfker -irr_eq1 -Dmu cfMod_eq1 //.
by rewrite (can2_eq (divrK Uj) (mulrK Uj)) mul1r (inj_eq irr_inj).
suffices: theta \in 'CF(K, L).
rewrite -cfnorm_Res_leif // DthL cfnormZ !cfnorm_irr !mulr1 normr_nat.
by rewrite -natrX eqC_nat => /eqP.
have <-: gcore U G = L.
apply: maxL; last by rewrite sub_gcore ?cfker_mod.
by rewrite gcore_norm (sub_proper_trans (gcore_sub _ _)).
apply/cfun_onP=> x; apply: contraNeq => nz_th_x.
apply/bigcapP=> y /(subsetP IGtheta)/setIdP[nKy /eqP th_y].
apply: contraR nz_th_x; rewrite mem_conjg -{}th_y cfConjgE {nKy}//.
move: {x y}(x ^ _) => x U'x; have [Kx | /cfun0-> //] := boolP (x \in K).
have /eqP := congr1 (fun k => (('chi_j %% L)%CF^-1 * 'chi_k) x) eq_mm_ij.
rewrite -rmorphV // !mmLthE !mulrA -!rmorphM mulVr // rmorph1 !cfunE.
rewrite (mulrC _^-1) -/mu -subr_eq0 -mulrBl cfun1E Kx mulf_eq0 => /orP[]//.
rewrite mulrb subr_eq0 -(lin_char1 lin_mu) [_ == _](contraNF _ U'x) //.
by rewrite /U cfkerEchar ?lin_charW // inE Kx.
Qed.
(* This is Isaacs, Corollary (6.19). *)
Corollary cfRes_prime_irr_cases G N s p (chi := 'chi[G]_s) :
N <| G -> #|G : N| = p -> prime p ->
[\/ 'Res[N] chi \in irr N
| exists2 c, injective c & 'Res[N] chi = \sum_(i < p) 'chi_(c i)].
Proof.
move=> /andP[sNG nNG] iGN pr_p.
have chiefGN: chief_factor G N G.
apply/andP; split=> //; apply/maxgroupP.
split=> [|M /andP[/andP[sMG ltMG] _] sNM].
by rewrite /proper sNG -indexg_gt1 iGN prime_gt1.
apply/esym/eqP; rewrite eqEsubset sNM -indexg_eq1 /= eq_sym.
rewrite -(eqn_pmul2l (indexg_gt0 G M)) muln1 Lagrange_index // iGN.
by apply/eqP/prime_nt_dvdP; rewrite ?indexg_eq1 // -iGN indexgS.
have abGbar: abelian (G / N).
by rewrite cyclic_abelian ?prime_cyclic ?card_quotient ?iGN.
have IGchi: G \subset 'I[chi] by apply: sub_inertia.
have [] := invariant_chief_irr_cases chiefGN abGbar IGchi; first by left.
case=> e _ /(congr1 (fun m => odd (logn p m)))/eqP/idPn[].
by rewrite lognX mul2n odd_double iGN logn_prime // eqxx.
by rewrite iGN; right.
Qed.
(* This is Isaacs, Corollary (6.20). *)
Corollary prime_invariant_irr_extendible G N s p :
N <| G -> #|G : N| = p -> prime p -> G \subset 'I['chi_s] ->
{t | 'Res[N, G] 'chi_t = 'chi_s}.
Proof.
move=> nsNG iGN pr_p IGchi.
have [t sGt] := constt_cfInd_irr s (normal_sub nsNG); exists t.
have [e DtN]: exists e, 'Res 'chi_t = e%:R *: 'chi_s.
rewrite constt_Ind_Res in sGt.
rewrite (Clifford_Res_sum_cfclass nsNG sGt) cfclass_invariant // big_seq1.
set e := '[_, _]; exists (Num.truncn e).
by rewrite truncnK ?Cnat_cfdot_char ?cfRes_char ?irr_char.
have [/irrWnorm/eqP | [c injc DtNc]] := cfRes_prime_irr_cases t nsNG iGN pr_p.
rewrite DtN cfnormZ cfnorm_irr normr_nat mulr1 -natrX pnatr_eq1.
by rewrite muln_eq1 andbb => /eqP->; rewrite scale1r.
have nz_e: e != 0.
have: 'Res[N] 'chi_t != 0 by rewrite cfRes_eq0 // ?irr_char ?irr_neq0.
by rewrite DtN; apply: contraNneq => ->; rewrite scale0r.
have [i s'ci]: exists i, c i != s.
pose i0 := Ordinal (prime_gt0 pr_p); pose i1 := Ordinal (prime_gt1 pr_p).
have [<- | ] := eqVneq (c i0) s; last by exists i0.
by exists i1; rewrite (inj_eq injc).
have /esym/eqP/idPn[] := congr1 (cfdotr 'chi_(c i)) DtNc; rewrite {1}DtN /=.
rewrite cfdot_suml cfdotZl cfdot_irr mulrb ifN_eqC // mulr0.
rewrite (bigD1 i) //= cfnorm_irr big1 ?addr0 ?oner_eq0 // => j i'j.
by rewrite cfdot_irr mulrb ifN_eq ?(inj_eq injc).
Qed.
(* This is Isaacs, Lemma (6.24). *)
Lemma extend_to_cfdet G N s c0 u :
let theta := 'chi_s in let lambda := cfDet theta in let mu := 'chi_u in
N <| G -> coprime #|G : N| (Num.truncn (theta 1%g)) ->
'Res[N, G] 'chi_c0 = theta -> 'Res[N, G] mu = lambda ->
exists2 c, 'Res 'chi_c = theta /\ cfDet 'chi_c = mu
& forall c1, 'Res 'chi_c1 = theta -> cfDet 'chi_c1 = mu -> c1 = c.
Proof.
move=> theta lambda mu nsNG; set e := #|G : N|; set f := Num.truncn _.
set eta := 'chi_c0 => co_e_f etaNth muNlam; have [sNG nNG] := andP nsNG.
have fE: f%:R = theta 1%g by rewrite truncnK ?Cnat_irr1.
pose nu := cfDet eta; have lin_nu: nu \is a linear_char := cfDet_lin_char _.
have nuNlam: 'Res nu = lambda by rewrite -cfDetRes ?irr_char ?etaNth.
have lin_lam: lambda \is a linear_char := cfDet_lin_char _.
have lin_mu: mu \is a linear_char.
by have:= lin_lam; rewrite -muNlam; apply: cfRes_lin_lin; apply: irr_char.
have [Unu Ulam] := (lin_char_unitr lin_nu, lin_char_unitr lin_lam).
pose alpha := mu / nu.
have alphaN_1: 'Res[N] alpha = 1 by rewrite rmorph_div //= muNlam nuNlam divrr.
have lin_alpha: alpha \is a linear_char by apply: rpred_div.
have alpha_e: alpha ^+ e = 1.
have kerNalpha: N \subset cfker alpha.
by rewrite -subsetIidl -cfker_Res ?lin_charW // alphaN_1 cfker_cfun1.
apply/eqP; rewrite -(cfQuoK nsNG kerNalpha) -rmorphXn cfMod_eq1 //.
rewrite -dvdn_cforder /e -card_quotient //.
by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char.
have det_alphaXeta b: cfDet (alpha ^+ b * eta) = alpha ^+ (b * f) * nu.
by rewrite cfDet_mul_lin ?rpredX ?irr_char // -exprM -(cfRes1 N) etaNth.
have [b bf_mod_e]: exists b, b * f = 1 %[mod e].
rewrite -(chinese_modl co_e_f 1 0) /chinese !mul0n addn0 !mul1n mulnC.
by exists (egcdn f e).1.
have alpha_bf: alpha ^+ (b * f) = alpha.
by rewrite -(expr_mod _ alpha_e) bf_mod_e expr_mod.
have /irrP[c Dc]: alpha ^+ b * eta \in irr G.
by rewrite mul_lin_irr ?rpredX ?mem_irr.
have chiN: 'Res 'chi_c = theta.
by rewrite -Dc rmorphM rmorphXn /= alphaN_1 expr1n mul1r.
have det_chi: cfDet 'chi_c = mu by rewrite -Dc det_alphaXeta alpha_bf divrK.
exists c => // c2 c2Nth det_c2_mu; apply: irr_inj.
have [irrMc _ imMc _] := constt_Ind_ext nsNG chiN.
have /codomP[s2 Dc2]: c2 \in codom (@mul_mod_Iirr G N c).
by rewrite -imMc constt_Ind_Res c2Nth constt_irr ?inE.
have{} Dc2: 'chi_c2 = ('chi_s2 %% N)%CF * 'chi_c.
by rewrite Dc2 cfIirrE // mod_IirrE.
have s2_lin: 'chi_s2 \is a linear_char.
rewrite qualifE/= irr_char; apply/eqP/(mulIf (irr1_neq0 c)).
rewrite mul1r -[in RHS](cfRes1 N) chiN -c2Nth cfRes1.
by rewrite Dc2 cfunE cfMod1.
have s2Xf_1: 'chi_s2 ^+ f = 1.
apply/(can_inj (cfModK nsNG))/(mulIr (lin_char_unitr lin_mu))/esym.
rewrite rmorph1 rmorphXn /= mul1r -{1}det_c2_mu Dc2 -det_chi.
by rewrite cfDet_mul_lin ?cfMod_lin_char ?irr_char // -(cfRes1 N) chiN.
suffices /eqP s2_1: 'chi_s2 == 1 by rewrite Dc2 s2_1 rmorph1 mul1r.
rewrite -['chi_s2]expr1 -dvdn_cforder -(eqnP co_e_f) dvdn_gcd.
by rewrite /e -card_quotient ?cforder_lin_char_dvdG //= dvdn_cforder s2Xf_1.
Qed.
(* This is Isaacs, Theorem (6.25). *)
Theorem solvable_irr_extendible_from_det G N s (theta := 'chi[N]_s) :
N <| G -> solvable (G / N) ->
G \subset 'I[theta] -> coprime #|G : N| (Num.truncn (theta 1%g)) ->
[exists c, 'Res 'chi[G]_c == theta]
= [exists u, 'Res 'chi[G]_u == cfDet theta].
Proof.
set e := #|G : N|; set f := Num.truncn _ => nsNG solG IGtheta co_e_f.
apply/exists_eqP/exists_eqP=> [[c cNth] | [u uNdth]].
have /lin_char_irr/irrP[u Du] := cfDet_lin_char 'chi_c.
by exists u; rewrite -Du -cfDetRes ?irr_char ?cNth.
move: {2}e.+1 (ltnSn e) => m.
elim: m => // m IHm in G u e nsNG solG IGtheta co_e_f uNdth *.
rewrite ltnS => le_e; have [sNG nNG] := andP nsNG.
have [<- | ltNG] := eqsVneq N G; first by exists s; rewrite cfRes_id.
have [G0 maxG0 sNG0]: {G0 | maxnormal (gval G0) G G & N \subset G0}.
by apply: maxgroup_exists; rewrite properEneq ltNG sNG.
have [/andP[ltG0G nG0G] maxG0_P] := maxgroupP maxG0.
set mu := 'chi_u in uNdth; have lin_mu: mu \is a linear_char.
by rewrite qualifE/= irr_char -(cfRes1 N) uNdth /= lin_char1 ?cfDet_lin_char.
have sG0G := proper_sub ltG0G; have nsNG0 := normalS sNG0 sG0G nsNG.
have nsG0G: G0 <| G by apply/andP.
have /lin_char_irr/irrP[u0 Du0] := cfRes_lin_char G0 lin_mu.
have u0Ndth: 'Res 'chi_u0 = cfDet theta by rewrite -Du0 cfResRes.
have IG0theta: G0 \subset 'I[theta].
by rewrite (subset_trans sG0G) // -IGtheta subsetIr.
have coG0f: coprime #|G0 : N| f by rewrite (coprime_dvdl _ co_e_f) ?indexSg.
have{m IHm le_e} [c0 c0Ns]: exists c0, 'Res 'chi[G0]_c0 = theta.
have solG0: solvable (G0 / N) := solvableS (quotientS N sG0G) solG.
apply: IHm nsNG0 solG0 IG0theta coG0f u0Ndth (leq_trans _ le_e).
by rewrite -(ltn_pmul2l (cardG_gt0 N)) !Lagrange ?proper_card.
have{c0 c0Ns} [c0 [c0Ns dc0_u0] Uc0] := extend_to_cfdet nsNG0 coG0f c0Ns u0Ndth.
have IGc0: G \subset 'I['chi_c0].
apply/subsetP=> x Gx; rewrite inE (subsetP nG0G) //= -conjg_IirrE.
apply/eqP; congr 'chi__; apply: Uc0; rewrite conjg_IirrE.
by rewrite -(cfConjgRes _ nsG0G nsNG) // c0Ns inertiaJ ?(subsetP IGtheta).
by rewrite cfDetConjg dc0_u0 -Du0 (cfConjgRes _ _ nsG0G) // cfConjg_id.
have prG0G: prime #|G : G0|.
have [h injh im_h] := third_isom sNG0 nsNG nsG0G.
rewrite -card_quotient // -im_h // card_injm //.
rewrite simple_sol_prime 1?quotient_sol //.
by rewrite /simple -(injm_minnormal injh) // im_h // maxnormal_minnormal.
have [t tG0c0] := prime_invariant_irr_extendible nsG0G (erefl _) prG0G IGc0.
by exists t; rewrite /theta -c0Ns -tG0c0 cfResRes.
Qed.
(* This is Isaacs, Theorem (6.26). *)
Theorem extend_linear_char_from_Sylow G N (lambda : 'CF(N)) :
N <| G -> lambda \is a linear_char -> G \subset 'I[lambda] ->
(forall p, p \in \pi('o(lambda)%CF) ->
exists2 Hp : {group gT},
[/\ N \subset Hp, Hp \subset G & p.-Sylow(G / N) (Hp / N)%g]
& exists u, 'Res 'chi[Hp]_u = lambda) ->
exists u, 'Res[N, G] 'chi_u = lambda.
Proof.
set m := 'o(lambda)%CF => nsNG lam_lin IGlam p_ext_lam.
have [sNG nNG] := andP nsNG; have linN := @cfRes_lin_lin _ _ N.
wlog [p p_lam]: lambda @m lam_lin IGlam p_ext_lam /
exists p : nat, \pi(m) =i (p : nat_pred).
- move=> IHp; have [linG [cf [inj_cf _ lin_cf onto_cf]]] := lin_char_group N.
case=> cf1 cfM cfX _ cf_order; have [lam cf_lam] := onto_cf _ lam_lin.
pose mu p := cf lam.`_p; pose pi_m p := p \in \pi(m).
have Dm: m = #[lam] by rewrite /m cfDet_order_lin // cf_lam cf_order.
have Dlambda: lambda = \prod_(p < m.+1 | pi_m p) mu p.
rewrite -(big_morph cf cfM cf1) big_mkcond cf_lam /pi_m Dm; congr (cf _).
rewrite -{1}[lam]prod_constt big_mkord; apply: eq_bigr => p _.
by case: ifPn => // p'lam; apply/constt1P; rewrite /p_elt p'natEpi.
have lin_mu p: mu p \is a linear_char by rewrite /mu cfX -cf_lam rpredX.
suffices /fin_all_exists [u uNlam] (p : 'I_m.+1):
exists u, pi_m p -> 'Res[N, G] 'chi_u = mu p.
- pose nu := \prod_(p < m.+1 | pi_m p) 'chi_(u p).
have lin_nu: nu \is a linear_char.
by apply: rpred_prod => p m_p; rewrite linN ?irr_char ?uNlam.
have /irrP[u1 Dnu] := lin_char_irr lin_nu.
by exists u1; rewrite Dlambda -Dnu rmorph_prod; apply: eq_bigr.
have [m_p | _] := boolP (pi_m p); last by exists 0.
have o_mu: \pi('o(mu p)%CF) =i (p : nat_pred).
rewrite cfDet_order_lin // cf_order orderE /=.
have [|pr_p _ [k ->]] := pgroup_pdiv (p_elt_constt p lam).
by rewrite cycle_eq1 (sameP eqP constt1P) /p_elt p'natEpi // negbK -Dm.
by move=> q; rewrite pi_of_exp // pi_of_prime.
have IGmu: G \subset 'I[mu p].
rewrite (subset_trans IGlam) // /mu cfX -cf_lam.
elim: (chinese _ _ _ _) => [|k IHk]; first by rewrite inertia1 norm_inertia.
by rewrite exprS (subset_trans _ (inertia_mul _ _)) // subsetIidl.
have [q||u] := IHp _ (lin_mu p) IGmu; [ | by exists p | by exists u].
rewrite o_mu => /eqnP-> {q}.
have [Hp sylHp [u uNlam]] := p_ext_lam p m_p; exists Hp => //.
rewrite /mu cfX -cf_lam -uNlam -rmorphXn /=; set nu := _ ^+ _.
have /lin_char_irr/irrP[v ->]: nu \is a linear_char; last by exists v.
by rewrite rpredX // linN ?irr_char ?uNlam.
have pi_m_p: p \in \pi(m) by rewrite p_lam !inE.
have [pr_p mgt0]: prime p /\ (m > 0)%N.
by have:= pi_m_p; rewrite mem_primes => /and3P[].
have p_m: p.-nat m by rewrite -(eq_pnat _ p_lam) pnat_pi.
have{p_ext_lam} [H [sNH sHG sylHbar] [v vNlam]] := p_ext_lam p pi_m_p.
have co_p_GH: coprime p #|G : H|.
rewrite -(index_quotient_eq _ sHG nNG) ?subIset ?sNH ?orbT //.
by rewrite (pnat_coprime (pnat_id pr_p)) //; have [] := and3P sylHbar.
have lin_v: 'chi_v \is a linear_char by rewrite linN ?irr_char ?vNlam.
pose nuG := 'Ind[G] 'chi_v.
have [c vGc co_p_f]: exists2 c, c \in irr_constt nuG & ~~ (p %| 'chi_c 1%g)%C.
apply/exists_inP; rewrite -negb_forall_in.
apply: contraL co_p_GH => /forall_inP p_dv_v1.
rewrite prime_coprime // negbK -dvdC_nat -[rhs in (_ %| rhs)%C]mulr1.
rewrite -(lin_char1 lin_v) -cfInd1 // ['Ind _]cfun_sum_constt /=.
rewrite sum_cfunE rpred_sum // => i /p_dv_v1 p_dv_chi1i.
rewrite cfunE dvdC_mull // intr_nat //.
by rewrite Cnat_cfdot_char ?cfInd_char ?irr_char.
pose f := Num.truncn ('chi_c 1%g); pose b := (egcdn f m).1.
have fK: f%:R = 'chi_c 1%g by rewrite truncnK ?Cnat_irr1.
have fb_mod_m: f * b = 1 %[mod m].
have co_m_f: coprime m f.
by rewrite (pnat_coprime p_m) ?p'natE // -dvdC_nat CdivE fK.
by rewrite -(chinese_modl co_m_f 1 0) /chinese !mul0n addn0 mul1n.
have /irrP[s Dlam] := lin_char_irr lam_lin.
have cHv: v \in irr_constt ('Res[H] 'chi_c) by rewrite -constt_Ind_Res.
have{cHv} cNs: s \in irr_constt ('Res[N] 'chi_c).
rewrite -(cfResRes _ sNH) ?(constt_Res_trans _ cHv) ?cfRes_char ?irr_char //.
by rewrite vNlam Dlam constt_irr !inE.
have DcN: 'Res[N] 'chi_c = lambda *+ f.
have:= Clifford_Res_sum_cfclass nsNG cNs.
rewrite cfclass_invariant -Dlam // big_seq1 Dlam => DcN.
have:= cfRes1 N 'chi_c; rewrite DcN cfunE -Dlam lin_char1 // mulr1 => ->.
by rewrite -scaler_nat fK.
have /lin_char_irr/irrP[d Dd]: cfDet 'chi_c ^+ b \is a linear_char.
by rewrite rpredX // cfDet_lin_char.
exists d; rewrite -{}Dd rmorphXn /= -cfDetRes ?irr_char // DcN.
rewrite cfDetMn ?lin_charW // -exprM cfDet_id //.
rewrite -(expr_mod _ (exp_cforder _)) -cfDet_order_lin // -/m.
by rewrite fb_mod_m /m cfDet_order_lin // expr_mod ?exp_cforder.
Qed.
(* This is Isaacs, Corollary (6.27). *)
Corollary extend_coprime_linear_char G N (lambda : 'CF(N)) :
N <| G -> lambda \is a linear_char -> G \subset 'I[lambda] ->
coprime #|G : N| 'o(lambda)%CF ->
exists u, [/\ 'Res 'chi[G]_u = lambda, 'o('chi_u)%CF = 'o(lambda)%CF
& forall v,
'Res 'chi_v = lambda -> coprime #|G : N| 'o('chi_v)%CF ->
v = u].
Proof.
set e := #|G : N| => nsNG lam_lin IGlam co_e_lam; have [sNG nNG] := andP nsNG.
have [p lam_p | v vNlam] := extend_linear_char_from_Sylow nsNG lam_lin IGlam.
exists N; last first.
by have /irrP[u ->] := lin_char_irr lam_lin; exists u; rewrite cfRes_id.
split=> //; rewrite trivg_quotient /pHall sub1G pgroup1 indexg1.
rewrite card_quotient //= -/e (pi'_p'nat _ lam_p) //.
rewrite -coprime_pi' ?indexg_gt0 1?coprime_sym //.
by have:= lam_p; rewrite mem_primes => /and3P[].
set nu := 'chi_v in vNlam.
have lin_nu: nu \is a linear_char.
by rewrite (@cfRes_lin_lin _ _ N) ?vNlam ?irr_char.
have [b be_mod_lam]: exists b, b * e = 1 %[mod 'o(lambda)%CF].
rewrite -(chinese_modr co_e_lam 0 1) /chinese !mul0n !mul1n mulnC.
by set b := _.1; exists b.
have /irrP[u Du]: nu ^+ (b * e) \in irr G by rewrite lin_char_irr ?rpredX.
exists u; set mu := 'chi_u in Du *.
have uNlam: 'Res mu = lambda.
rewrite cfDet_order_lin // in be_mod_lam.
rewrite -Du rmorphXn /= vNlam -(expr_mod _ (exp_cforder _)) //.
by rewrite be_mod_lam expr_mod ?exp_cforder.
have lin_mu: mu \is a linear_char by rewrite -Du rpredX.
have o_mu: ('o(mu) = 'o(lambda))%CF.
have dv_o_lam_mu: 'o(lambda)%CF %| 'o(mu)%CF.
by rewrite !cfDet_order_lin // -uNlam cforder_Res.
have kerNnu_olam: N \subset cfker (nu ^+ 'o(lambda)%CF).
rewrite -subsetIidl -cfker_Res ?rpredX ?irr_char //.
by rewrite rmorphXn /= vNlam cfDet_order_lin // exp_cforder cfker_cfun1.
apply/eqP; rewrite eqn_dvd dv_o_lam_mu andbT cfDet_order_lin //.
rewrite dvdn_cforder -Du exprAC -dvdn_cforder dvdn_mull //.
rewrite -(cfQuoK nsNG kerNnu_olam) cforder_mod // /e -card_quotient //.
by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char ?rpredX.
split=> // t tNlam co_e_t.
have lin_t: 'chi_t \is a linear_char.
by rewrite (@cfRes_lin_lin _ _ N) ?tNlam ?irr_char.
have Ut := lin_char_unitr lin_t.
have kerN_mu_t: N \subset cfker (mu / 'chi_t)%R.
rewrite -subsetIidl -cfker_Res ?lin_charW ?rpred_div ?rmorph_div //.
by rewrite /= uNlam tNlam divrr ?lin_char_unitr ?cfker_cfun1.
have co_e_mu_t: coprime e #[(mu / 'chi_t)%R]%CF.
suffices dv_o_mu_t: #[(mu / 'chi_t)%R]%CF %| 'o(mu)%CF * 'o('chi_t)%CF.
by rewrite (coprime_dvdr dv_o_mu_t) // coprimeMr o_mu co_e_lam.
rewrite !cfDet_order_lin //; apply/dvdn_cforderP=> x Gx.
rewrite invr_lin_char // !cfunE exprMn -rmorphXn {2}mulnC /=.
by rewrite !(dvdn_cforderP _) ?conjC1 ?mulr1 // dvdn_mulr.
have /eqP mu_t_1: mu / 'chi_t == 1.
rewrite -(dvdn_cforder (_ / _)%R 1) -(eqnP co_e_mu_t) dvdn_gcd dvdnn andbT.
rewrite -(cfQuoK nsNG kerN_mu_t) cforder_mod // /e -card_quotient //.
by rewrite cforder_lin_char_dvdG ?cfQuo_lin_char ?rpred_div.
by apply: irr_inj; rewrite -['chi_t]mul1r -mu_t_1 divrK.
Qed.
(* This is Isaacs, Corollary (6.28). *)
Corollary extend_solvable_coprime_irr G N t (theta := 'chi[N]_t) :
N <| G -> solvable (G / N) -> G \subset 'I[theta] ->
coprime #|G : N| ('o(theta)%CF * Num.truncn (theta 1%g)) ->
exists c, [/\ 'Res 'chi[G]_c = theta, 'o('chi_c)%CF = 'o(theta)%CF
& forall d,
'Res 'chi_d = theta -> coprime #|G : N| 'o('chi_d)%CF ->
d = c].
Proof.
set e := #|G : N|; set f := Num.truncn _ => nsNG solG IGtheta.
rewrite coprimeMr => /andP[co_e_th co_e_f].
have [sNG nNG] := andP nsNG; pose lambda := cfDet theta.
have lin_lam: lambda \is a linear_char := cfDet_lin_char theta.
have IGlam: G \subset 'I[lambda].
apply/subsetP=> y /(subsetP IGtheta)/setIdP[nNy /eqP th_y].
by rewrite inE nNy /= -cfDetConjg th_y.
have co_e_lam: coprime e 'o(lambda)%CF by rewrite cfDet_order_lin.
have [//|u [uNlam o_u Uu]] := extend_coprime_linear_char nsNG lin_lam IGlam.
have /exists_eqP[c cNth]: [exists c, 'Res 'chi[G]_c == theta].
rewrite solvable_irr_extendible_from_det //.
by apply/exists_eqP; exists u.
have{c cNth} [c [cNth det_c] Uc] := extend_to_cfdet nsNG co_e_f cNth uNlam.
have lin_u: 'chi_u \is a linear_char by rewrite -det_c cfDet_lin_char.
exists c; split=> // [|c0 c0Nth co_e_c0].
by rewrite !cfDet_order_lin // -det_c in o_u.
have lin_u0: cfDet 'chi_c0 \is a linear_char := cfDet_lin_char 'chi_c0.
have /irrP[u0 Du0] := lin_char_irr lin_u0.
have co_e_u0: coprime e 'o('chi_u0)%CF by rewrite -Du0 cfDet_order_lin.
have eq_u0u: u0 = u by apply: Uu; rewrite // -Du0 -cfDetRes ?irr_char ?c0Nth.
by apply: Uc; rewrite // Du0 eq_u0u.
Qed.
End ExtendInvariantIrr.
Section Frobenius.
Variables (gT : finGroupType) (G K : {group gT}).
(* Because he only defines Frobenius groups in chapter 7, Isaacs does not *)
(* state these theorems using the Frobenius property. *)
Hypothesis frobGK : [Frobenius G with kernel K].
(* This is Isaacs, Theorem 6.34(a1). *)
Theorem inertia_Frobenius_ker i : i != 0 -> 'I_G['chi[K]_i] = K.
Proof.
have [_ _ nsKG regK] := Frobenius_kerP frobGK; have [sKG nKG] := andP nsKG.
move=> nzi; apply/eqP; rewrite eqEsubset sub_Inertia // andbT.
apply/subsetP=> x /setIP[Gx /setIdP[nKx /eqP x_stab_i]].
have actIirrK: is_action G (@conjg_Iirr _ K).
split=> [y j k eq_jk | j y z Gy Gz].
by apply/irr_inj/(can_inj (cfConjgK y)); rewrite -!conjg_IirrE eq_jk.
by apply: irr_inj; rewrite !conjg_IirrE (cfConjgM _ nsKG).
pose ito := Action actIirrK; pose cto := ('Js \ (subsetT G))%act.
have acts_Js : [acts G, on classes K | 'Js].
apply/subsetP=> y Gy; have nKy := subsetP nKG y Gy.
rewrite !inE; apply/subsetP=> _ /imsetP[z Gz ->] /[!inE]/=.
rewrite -class_rcoset norm_rlcoset // class_lcoset.
by apply: imset_f; rewrite memJ_norm.
have acts_cto : [acts G, on classes K | cto] by rewrite astabs_ract subsetIidl.
pose m := #|'Fix_(classes K | cto)[x]|.
have def_m: #|'Fix_ito[x]| = m.
apply: card_afix_irr_classes => // j y _ Ky /imsetP[_ /imsetP[z Kz ->] ->].
by rewrite conjg_IirrE cfConjgEJ // cfunJ.
have: (m != 1)%N.
rewrite -def_m (cardD1 (0 : Iirr K)) (cardD1 i) !(inE, sub1set) /=.
by rewrite conjg_Iirr0 nzi eqxx -(inj_eq irr_inj) conjg_IirrE x_stab_i eqxx.
apply: contraR => notKx; apply/cards1P; exists 1%g; apply/esym/eqP.
rewrite eqEsubset !(sub1set, inE) classes1 /= conjs1g eqxx /=.
apply/subsetP=> _ /setIP[/imsetP[y Ky ->] /afix1P /= cyKx].
have /imsetP[z Kz def_yx]: y ^ x \in y ^: K.
by rewrite -cyKx; apply: imset_f; apply: class_refl.
rewrite inE classG_eq1; apply: contraR notKx => nty.
rewrite -(groupMr x (groupVr Kz)).
apply: (subsetP (regK y _)); first exact/setD1P.
rewrite !inE groupMl // groupV (subsetP sKG) //=.
by rewrite conjg_set1 conjgM def_yx conjgK.
Qed.
(* This is Isaacs, Theorem 6.34(a2) *)
Theorem irr_induced_Frobenius_ker i : i != 0 -> 'Ind[G, K] 'chi_i \in irr G.
Proof.
move/inertia_Frobenius_ker/group_inj=> defK.
have [_ _ nsKG _] := Frobenius_kerP frobGK.
have [] := constt_Inertia_bijection i nsKG; rewrite defK cfInd_id => -> //.
by rewrite constt_irr !inE.
Qed.
(* This is Isaacs, Theorem 6.34(b) *)
Theorem Frobenius_Ind_irrP j :
reflect (exists2 i, i != 0 & 'chi_j = 'Ind[G, K] 'chi_i)
(~~ (K \subset cfker 'chi_j)).
Proof.
have [_ _ nsKG _] := Frobenius_kerP frobGK; have [sKG nKG] := andP nsKG.
apply: (iffP idP) => [not_chijK1 | [i nzi ->]]; last first.
by rewrite cfker_Ind_irr ?sub_gcore // subGcfker.
have /neq0_has_constt[i chijKi]: 'Res[K] 'chi_j != 0 by apply: Res_irr_neq0.
have nz_i: i != 0.
by apply: contraNneq not_chijK1 => i0; rewrite constt0_Res_cfker // -i0.
have /irrP[k def_chik] := irr_induced_Frobenius_ker nz_i.
have: '['chi_j, 'chi_k] != 0 by rewrite -def_chik -cfdot_Res_l.
by rewrite cfdot_irr pnatr_eq0; case: (j =P k) => // ->; exists i.
Qed.
End Frobenius.
|
LowDegree.lean
|
/-
Copyright (c) 2025 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.GroupTheory.Abelianization.Defs
import Mathlib.RepresentationTheory.Homological.GroupHomology.Basic
import Mathlib.RepresentationTheory.Invariants
/-!
# The low-degree homology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file contains specialised API for
the cycles and group homology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2.
In `Mathlib/RepresentationTheory/Homological/GroupHomology/Basic.lean`, we define the `n`th group
homology of `A` to be the homology of a complex `inhomogeneousChains A`, whose objects are
`(Fin n →₀ G) → A`; this is unnecessarily unwieldy in low degree.
Given an additive abelian group `A` with an appropriate scalar action of `G`, we provide support
for turning a finsupp `f : G →₀ A` satisfying the 1-cycle identity into an element of the
`cycles₁` of the representation on `A` corresponding to the scalar action. We also do this for
0-boundaries, 1-boundaries, 2-cycles and 2-boundaries.
The file also contains an identification between the definitions in
`Mathlib/RepresentationTheory/Homological/GroupHomology/Basic.lean`, `groupHomology.cycles A n`, and
the `cyclesₙ` in this file for `n = 1, 2`, as well as an isomorphism
`groupHomology.cycles A 0 ≅ A.V`.
Moreover, we provide API for the natural maps `cyclesₙ A → Hn A` for `n = 1, 2`.
We show that when the representation on `A` is trivial, `H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A`.
## Main definitions
* `groupHomology.H0Iso A`: isomorphism between `H₀(G, A)` and the coinvariants `A_G` of the
`G`-representation on `A`.
* `groupHomology.H1π A`: epimorphism from the 1-cycles (i.e. `Z₁(G, A) := Ker(d₀ : (G →₀ A) → A`)
to `H₁(G, A)`.
* `groupHomology.H2π A`: epimorphism from the 2-cycles
(i.e. `Z₂(G, A) := Ker(d₁ : (G² →₀ A) → (G →₀ A)`) to `H₂(G, A)`.
* `groupHomology.H1AddEquivOfIsTrivial`: an isomorphism `H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A` when the
representation on `A` is trivial.
-/
universe v u
noncomputable section
open CategoryTheory Limits Representation Rep Finsupp
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
namespace groupHomology
section Chains
/-- The 0th object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `A` as a `k`-module. -/
def chainsIso₀ : (inhomogeneousChains A).X 0 ≅ A.V :=
(LinearEquiv.finsuppUnique _ _ _).toModuleIso
/-- The 1st object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G →₀ A` as a `k`-module. -/
def chainsIso₁ : (inhomogeneousChains A).X 1 ≅ ModuleCat.of k (G →₀ A) :=
(Finsupp.domLCongr (Equiv.funUnique (Fin 1) G)).toModuleIso
/-- The 2nd object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G² →₀ A` as a `k`-module. -/
def chainsIso₂ : (inhomogeneousChains A).X 2 ≅ ModuleCat.of k (G × G →₀ A) :=
(Finsupp.domLCongr (piFinTwoEquiv fun _ => G)).toModuleIso
/-- The 3rd object in the complex of inhomogeneous chains of `A : Rep k G` is isomorphic
to `G³ → A` as a `k`-module. -/
def chainsIso₃ : (inhomogeneousChains A).X 3 ≅ ModuleCat.of k (G × G × G →₀ A) :=
(Finsupp.domLCongr ((Fin.consEquiv _).symm.trans
((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G)))).toModuleIso
end Chains
section Differentials
/-- The 0th differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G →₀ A) → A`. It is defined by `single g a ↦ ρ_A(g⁻¹)(a) - a.` -/
def d₁₀ : ModuleCat.of k (G →₀ A) ⟶ A.V :=
ModuleCat.ofHom <| lsum k fun g => A.ρ g⁻¹ - LinearMap.id
@[simp]
theorem d₁₀_single (g : G) (a : A) : d₁₀ A (single g a) = A.ρ g⁻¹ a - a := by
simp [d₁₀]
theorem d₁₀_single_one (a : A) : d₁₀ A (single 1 a) = 0 := by
simp [d₁₀]
theorem d₁₀_single_inv (g : G) (a : A) :
d₁₀ A (single g⁻¹ a) = - d₁₀ A (single g (A.ρ g a)) := by
simp [d₁₀]
theorem range_d₁₀_eq_coinvariantsKer :
LinearMap.range (d₁₀ A).hom = Coinvariants.ker A.ρ := by
symm
apply Submodule.span_eq_of_le
· rintro _ ⟨x, rfl⟩
use single x.1⁻¹ x.2
simp [d₁₀]
· rintro x ⟨y, hy⟩
induction y using Finsupp.induction generalizing x with
| zero => simp [← hy]
| single_add _ _ _ _ _ h =>
simpa [← hy, add_sub_add_comm, sum_add_index, d₁₀_single (G := G)]
using Submodule.add_mem _ (Coinvariants.mem_ker_of_eq _ _ _ rfl) (h rfl)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma d₁₀_comp_coinvariantsMk : d₁₀ A ≫ (coinvariantsMk k G).app A = 0 := by
ext
simp [d₁₀]
/-- The 0th differential in the complex of inhomogeneous chains of a `G`-representation `A` as a
linear map into the `k`-submodule of `A` spanned by elements of the form
`ρ(g)(x) - x, g ∈ G, x ∈ A`. -/
def chains₁ToCoinvariantsKer :
ModuleCat.of k (G →₀ A) ⟶ ModuleCat.of k (Coinvariants.ker A.ρ) :=
ModuleCat.ofHom <| (d₁₀ A).hom.codRestrict _ <|
range_d₁₀_eq_coinvariantsKer A ▸ LinearMap.mem_range_self _
@[simp]
theorem d₁₀_eq_zero_of_isTrivial [A.IsTrivial] : d₁₀ A = 0 := by
ext
simp [d₁₀]
/-- The 1st differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G² →₀ A) → (G →₀ A)`. It is defined by
`a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def d₂₁ : ModuleCat.of k (G × G →₀ A) ⟶ ModuleCat.of k (G →₀ A) :=
ModuleCat.ofHom <| lsum k fun g => lsingle g.2 ∘ₗ A.ρ g.1⁻¹ - lsingle (g.1 * g.2) + lsingle g.1
variable {A}
@[simp]
lemma d₂₁_single (g : G × G) (a : A) :
d₂₁ A (single g a) = single g.2 (A.ρ g.1⁻¹ a) - single (g.1 * g.2) a + single g.1 a := by
simp [d₂₁]
lemma d₂₁_single_one_fst (g : G) (a : A) :
d₂₁ A (single (1, g) a) = single 1 a := by
simp [d₂₁]
lemma d₂₁_single_one_snd (g : G) (a : A) :
d₂₁ A (single (g, 1) a) = single 1 (A.ρ g⁻¹ a) := by
simp [d₂₁]
lemma d₂₁_single_inv_self_ρ_sub_self_inv (g : G) (a : A) :
d₂₁ A (single (g⁻¹, g) (A.ρ g⁻¹ a) - single (g, g⁻¹) a) =
single 1 a - single 1 (A.ρ g⁻¹ a) := by
simp only [map_sub, d₂₁_single (G := G), inv_inv, self_inv_apply, inv_mul_cancel,
mul_inv_cancel]
abel
lemma d₂₁_single_self_inv_ρ_sub_inv_self (g : G) (a : A) :
d₂₁ A (single (g, g⁻¹) (A.ρ g a) - single (g⁻¹, g) a) =
single 1 a - single 1 (A.ρ g a) := by
simp only [map_sub, d₂₁_single (G := G), inv_self_apply, mul_inv_cancel, inv_inv,
inv_mul_cancel]
abel
lemma d₂₁_single_ρ_add_single_inv_mul (g h : G) (a : A) :
d₂₁ A (single (g, h) (A.ρ g a) + single (g⁻¹, g * h) a) =
single g (A.ρ g a) + single g⁻¹ a := by
simp only [map_add, d₂₁_single (G := G), inv_self_apply, inv_inv, inv_mul_cancel_left]
abel
lemma d₂₁_single_inv_mul_ρ_add_single (g h : G) (a : A) :
d₂₁ A (single (g⁻¹, g * h) (A.ρ g⁻¹ a) + single (g, h) a) =
single g⁻¹ (A.ρ g⁻¹ a) + single g a := by
simp only [map_add, d₂₁_single (G := G), inv_inv, self_inv_apply, inv_mul_cancel_left]
abel
variable (A) in
/-- The 2nd differential in the complex of inhomogeneous chains of `A : Rep k G`, as a
`k`-linear map `(G³ →₀ A) → (G² →₀ A)`. It is defined by
`a·(g₁, g₂, g₃) ↦ ρ_A(g₁⁻¹)(a)·(g₂, g₃) - a·(g₁g₂, g₃) + a·(g₁, g₂g₃) - a·(g₁, g₂)`. -/
def d₃₂ : ModuleCat.of k (G × G × G →₀ A) ⟶ ModuleCat.of k (G × G →₀ A) :=
ModuleCat.ofHom <| lsum k fun g =>
lsingle (g.2.1, g.2.2) ∘ₗ A.ρ g.1⁻¹ - lsingle (g.1 * g.2.1, g.2.2) +
lsingle (g.1, g.2.1 * g.2.2) - lsingle (g.1, g.2.1)
@[simp]
lemma d₃₂_single (g : G × G × G) (a : A) :
d₃₂ A (single g a) = single (g.2.1, g.2.2) (A.ρ g.1⁻¹ a) - single (g.1 * g.2.1, g.2.2) a +
single (g.1, g.2.1 * g.2.2) a - single (g.1, g.2.1) a := by
simp [d₃₂]
lemma d₃₂_single_one_fst (g h : G) (a : A) :
d₃₂ A (single (1, g, h) a) = single (1, g * h) a - single (1, g) a := by
simp [d₃₂]
lemma d₃₂_single_one_snd (g h : G) (a : A) :
d₃₂ A (single (g, 1, h) a) = single (1, h) (A.ρ g⁻¹ a) - single (g, 1) a := by
simp [d₃₂]
lemma d₃₂_single_one_thd (g h : G) (a : A) :
d₃₂ A (single (g, h, 1) a) = single (h, 1) (A.ρ g⁻¹ a) - single (g * h, 1) a := by
simp [d₃₂]
variable (A)
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₁₀` gives a simpler expression for the 0th differential: that is, the following
square commutes:
```
C₁(G, A) --d 1 0--> C₀(G, A)
| |
| |
| |
v v
(G →₀ A) ----d₁₀----> A
```
where the vertical arrows are `chainsIso₁` and `chainsIso₀` respectively.
-/
theorem comp_d₁₀_eq :
(chainsIso₁ A).hom ≫ d₁₀ A = (inhomogeneousChains A).d 1 0 ≫ (chainsIso₀ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₀, chainsIso₁, d₁₀_single (G := G),
Unique.eq_default (α := Fin 0 → G), sub_eq_add_neg, inhomogeneousChains.d_single (G := G)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₁₀_comp_inv :
(chainsIso₁ A).inv ≫ (inhomogeneousChains A).d 1 0 = d₁₀ A ≫ (chainsIso₀ A).inv :=
(CommSq.horiz_inv ⟨comp_d₁₀_eq A⟩).w
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₂₁` gives a simpler expression for the 1st differential: that is, the following
square commutes:
```
C₂(G, A) --d 2 1--> C₁(G, A)
| |
| |
| |
v v
(G² →₀ A) --d₂₁--> (G →₀ A)
```
where the vertical arrows are `chainsIso₂` and `chainsIso₁` respectively.
-/
theorem comp_d₂₁_eq :
(chainsIso₂ A).hom ≫ d₂₁ A = (inhomogeneousChains A).d 2 1 ≫ (chainsIso₁ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₁, add_assoc, chainsIso₂, d₂₁_single (G := G),
-Finsupp.domLCongr_apply, domLCongr_single, sub_eq_add_neg, Fin.contractNth,
inhomogeneousChains.d_single (G := G)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₂₁_comp_inv :
(chainsIso₂ A).inv ≫ (inhomogeneousChains A).d 2 1 = d₂₁ A ≫ (chainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨comp_d₂₁_eq A⟩).w
/-- Let `C(G, A)` denote the complex of inhomogeneous chains of `A : Rep k G`. This lemma
says `d₃₂` gives a simpler expression for the 2nd differential: that is, the following
square commutes:
```
C₃(G, A) --d 3 2--> C₂(G, A)
| |
| |
| |
v v
(G³ →₀ A) --d₃₂--> (G² →₀ A)
```
where the vertical arrows are `chainsIso₃` and `chainsIso₂` respectively.
-/
theorem comp_d₃₂_eq :
(chainsIso₃ A).hom ≫ d₃₂ A = (inhomogeneousChains A).d 3 2 ≫ (chainsIso₂ A).hom :=
ModuleCat.hom_ext <| lhom_ext fun _ _ => by
simp [inhomogeneousChains.d_def, chainsIso₂, pow_succ, chainsIso₃,
-domLCongr_apply, domLCongr_single, d₃₂, Fin.sum_univ_three,
Fin.contractNth, Fin.tail_def, sub_eq_add_neg, add_assoc,
inhomogeneousChains.d_single (G := G), add_rotate' (-(single (_ * _, _) _)),
add_left_comm (single (_, _ * _) _)]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem eq_d₃₂_comp_inv :
(chainsIso₃ A).inv ≫ (inhomogeneousChains A).d 3 2 = d₃₂ A ≫ (chainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨comp_d₃₂_eq A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₂₁_comp_d₁₀ : d₂₁ A ≫ d₁₀ A = 0 := by
ext x g
simp [d₁₀, d₂₁, sum_add_index', sum_sub_index, sub_sub_sub_comm, add_sub_add_comm]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem d₃₂_comp_d₂₁ : d₃₂ A ≫ d₂₁ A = 0 := by
simp [← cancel_mono (chainsIso₁ A).inv, ← eq_d₂₁_comp_inv, ← eq_d₃₂_comp_inv_assoc]
open ShortComplex
/-- The (exact) short complex `(G →₀ A) ⟶ A ⟶ A.ρ.coinvariants`. -/
@[simps! -isSimp f g]
def shortComplexH0 : ShortComplex (ModuleCat k) :=
mk _ _ (d₁₀_comp_coinvariantsMk A)
/-- The short complex `(G² →₀ A) --d₂₁--> (G →₀ A) --d₁₀--> A`. -/
@[simps! -isSimp f g]
def shortComplexH1 : ShortComplex (ModuleCat k) :=
mk _ _ (d₂₁_comp_d₁₀ A)
/-- The short complex `(G³ →₀ A) --d₃₂--> (G² →₀ A) --d₂₁--> (G →₀ A)`. -/
@[simps! -isSimp f g]
def shortComplexH2 : ShortComplex (ModuleCat k) :=
mk _ _ (d₃₂_comp_d₂₁ A)
end Differentials
section Cycles
/-- The 1-cycles `Z₁(G, A)` of `A : Rep k G`, defined as the kernel of the map
`(G →₀ A) → A` defined by `single g a ↦ ρ_A(g⁻¹)(a) - a`. -/
def cycles₁ : Submodule k (G →₀ A) := LinearMap.ker (d₁₀ A).hom
/-- The 2-cycles `Z₂(G, A)` of `A : Rep k G`, defined as the kernel of the map
`(G² →₀ A) → (G →₀ A)` defined by `a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def cycles₂ : Submodule k (G × G →₀ A) := LinearMap.ker (d₂₁ A).hom
variable {A}
theorem mem_cycles₁_iff (x : G →₀ A) :
x ∈ cycles₁ A ↔ x.sum (fun g a => A.ρ g⁻¹ a) = x.sum (fun _ a => a) := by
change x.sum (fun g a => A.ρ g⁻¹ a - a) = 0 ↔ _
rw [sum_sub, sub_eq_zero]
theorem single_mem_cycles₁_iff (g : G) (a : A) :
single g a ∈ cycles₁ A ↔ A.ρ g a = a := by
simp [mem_cycles₁_iff, ← (A.ρ.apply_bijective g).1.eq_iff (a := A.ρ g⁻¹ a), eq_comm]
theorem single_mem_cycles₁_of_mem_invariants (g : G) (a : A) (ha : a ∈ A.ρ.invariants) :
single g a ∈ cycles₁ A :=
(single_mem_cycles₁_iff g a).2 (ha g)
theorem d₂₁_apply_mem_cycles₁ (x : G × G →₀ A) :
d₂₁ A x ∈ cycles₁ A :=
congr($(d₂₁_comp_d₁₀ A) x)
variable (A) in
theorem cycles₁_eq_top_of_isTrivial [A.IsTrivial] : cycles₁ A = ⊤ := by
rw [cycles₁, d₁₀_eq_zero_of_isTrivial, ModuleCat.hom_zero, LinearMap.ker_zero]
variable (A) in
/-- The natural inclusion `Z₁(G, A) ⟶ C₁(G, A)` is an isomorphism when the representation
on `A` is trivial. -/
def cycles₁IsoOfIsTrivial [A.IsTrivial] :
ModuleCat.of k (cycles₁ A) ≅ ModuleCat.of k (G →₀ A) :=
(LinearEquiv.ofTop _ (cycles₁_eq_top_of_isTrivial A)).toModuleIso
@[simp]
lemma cycles₁IsoOfIsTrivial_hom_apply [A.IsTrivial] (x : cycles₁ A) :
(cycles₁IsoOfIsTrivial A).hom x = x.1 := rfl
@[simp]
lemma cycles₁IsoOfIsTrivial_inv_apply [A.IsTrivial] (x : G →₀ A) :
((cycles₁IsoOfIsTrivial A).inv x).1 = x := rfl
theorem mem_cycles₂_iff (x : G × G →₀ A) :
x ∈ cycles₂ A ↔ x.sum (fun g a => single g.2 (A.ρ g.1⁻¹ a) + single g.1 a) =
x.sum (fun g a => single (g.1 * g.2) a) := by
change x.sum (fun g a => _) = 0 ↔ _
simp [sub_add_eq_add_sub, sub_eq_zero]
theorem single_mem_cycles₂_iff_inv (g : G × G) (a : A) :
single g a ∈ cycles₂ A ↔ single g.2 (A.ρ g.1⁻¹ a) + single g.1 a = single (g.1 * g.2) a := by
simp [mem_cycles₂_iff]
theorem single_mem_cycles₂_iff (g : G × G) (a : A) :
single g a ∈ cycles₂ A ↔
single (g.1 * g.2) (A.ρ g.1 a) = single g.2 a + single g.1 (A.ρ g.1 a) := by
rw [← (mapRange_injective (α := G) _ (map_zero _) (A.ρ.apply_bijective g.1⁻¹).1).eq_iff]
simp [mem_cycles₂_iff, mapRange_add, eq_comm]
theorem d₃₂_apply_mem_cycles₂ (x : G × G × G →₀ A) :
d₃₂ A x ∈ cycles₂ A :=
congr($(d₃₂_comp_d₂₁ A) x)
end Cycles
section Boundaries
/-- The 1-boundaries `B₁(G, A)` of `A : Rep k G`, defined as the image of the map
`(G² →₀ A) → (G →₀ A)` defined by `a·(g₁, g₂) ↦ ρ_A(g₁⁻¹)(a)·g₂ - a·g₁g₂ + a·g₁`. -/
def boundaries₁ : Submodule k (G →₀ A) :=
LinearMap.range (d₂₁ A).hom
/-- The 2-boundaries `B₂(G, A)` of `A : Rep k G`, defined as the image of the map
`(G³ →₀ A) → (G² →₀ A)` defined by
`a·(g₁, g₂, g₃) ↦ ρ_A(g₁⁻¹)(a)·(g₂, g₃) - a·(g₁g₂, g₃) + a·(g₁, g₂g₃) - a·(g₁, g₂)`. -/
def boundaries₂ : Submodule k (G × G →₀ A) :=
LinearMap.range (d₃₂ A).hom
variable {A}
section
lemma mem_cycles₁_of_mem_boundaries₁ (f : G →₀ A) (h : f ∈ boundaries₁ A) :
f ∈ cycles₁ A := by
rcases h with ⟨x, rfl⟩
exact d₂₁_apply_mem_cycles₁ x
variable (A) in
lemma boundaries₁_le_cycles₁ : boundaries₁ A ≤ cycles₁ A :=
mem_cycles₁_of_mem_boundaries₁
variable (A) in
/-- The natural inclusion `B₁(G, A) →ₗ[k] Z₁(G, A)`. -/
abbrev boundariesToCycles₁ : boundaries₁ A →ₗ[k] cycles₁ A :=
Submodule.inclusion (boundaries₁_le_cycles₁ A)
@[simp]
lemma boundariesToCycles₁_apply (x : boundaries₁ A) :
(boundariesToCycles₁ A x).1 = x.1 := rfl
end
theorem single_one_mem_boundaries₁ (a : A) :
single 1 a ∈ boundaries₁ A := by
use single (1, 1) a
simp [d₂₁]
theorem single_ρ_self_add_single_inv_mem_boundaries₁ (g : G) (a : A) :
single g (A.ρ g a) + single g⁻¹ a ∈ boundaries₁ A := by
rw [← d₂₁_single_ρ_add_single_inv_mul g 1]
exact Set.mem_range_self _
theorem single_inv_ρ_self_add_single_mem_boundaries₁ (g : G) (a : A) :
single g⁻¹ (A.ρ g⁻¹ a) + single g a ∈ boundaries₁ A := by
rw [← d₂₁_single_inv_mul_ρ_add_single g 1]
exact Set.mem_range_self _
section
lemma mem_cycles₂_of_mem_boundaries₂ (x : G × G →₀ A) (h : x ∈ boundaries₂ A) :
x ∈ cycles₂ A := by
rcases h with ⟨x, rfl⟩
exact d₃₂_apply_mem_cycles₂ x
variable (A) in
lemma boundaries₂_le_cycles₂ : boundaries₂ A ≤ cycles₂ A :=
mem_cycles₂_of_mem_boundaries₂
variable (A) in
/-- The natural inclusion `B₂(G, A) →ₗ[k] Z₂(G, A)`. -/
abbrev boundariesToCycles₂ : boundaries₂ A →ₗ[k] cycles₂ A :=
Submodule.inclusion (boundaries₂_le_cycles₂ A)
@[simp]
lemma boundariesToCycles₂_apply (x : boundaries₂ A) :
(boundariesToCycles₂ A x).1 = x.1 := rfl
end
lemma single_one_fst_sub_single_one_fst_mem_boundaries₂ (g h : G) (a : A) :
single (1, g * h) a - single (1, g) a ∈ boundaries₂ A := by
use single (1, g, h) a
simp [d₃₂]
lemma single_one_fst_sub_single_one_snd_mem_boundaries₂ (g h : G) (a : A) :
single (1, h) (A.ρ g⁻¹ a) - single (g, 1) a ∈ boundaries₂ A := by
use single (g, 1, h) a
simp [d₃₂]
lemma single_one_snd_sub_single_one_fst_mem_boundaries₂ (g h : G) (a : A) :
single (g, 1) (A.ρ g a) - single (1, h) a ∈ boundaries₂ A := by
use single (g, 1, h) (A.ρ g (-a))
simp [d₃₂_single (G := G)]
lemma single_one_snd_sub_single_one_snd_mem_boundaries₂ (g h : G) (a : A) :
single (h, 1) (A.ρ g⁻¹ a) - single (g * h, 1) a ∈ boundaries₂ A := by
use single (g, h, 1) a
simp [d₃₂]
end Boundaries
section IsCycle
section
variable {G A : Type*} [Mul G] [Inv G] [AddCommGroup A] [SMul G A]
/-- A finsupp `∑ aᵢ·gᵢ : G →₀ A` satisfies the 1-cycle condition if `∑ gᵢ⁻¹ • aᵢ = ∑ aᵢ`. -/
def IsCycle₁ (x : G →₀ A) : Prop := x.sum (fun g a => g⁻¹ • a) = x.sum (fun _ a => a)
/-- A finsupp `∑ aᵢ·(gᵢ, hᵢ) : G × G →₀ A` satisfies the 2-cycle condition if
`∑ (gᵢ⁻¹ • aᵢ)·hᵢ + aᵢ·gᵢ = ∑ aᵢ·gᵢhᵢ`. -/
def IsCycle₂ (x : G × G →₀ A) : Prop :=
x.sum (fun g a => single g.2 (g.1⁻¹ • a) + single g.1 a) =
x.sum (fun g a => single (g.1 * g.2) a)
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [DistribMulAction G A]
@[simp]
theorem single_isCycle₁_iff (g : G) (a : A) :
IsCycle₁ (single g a) ↔ g • a = a := by
rw [← (MulAction.bijective g⁻¹).1.eq_iff]
simp [IsCycle₁, eq_comm]
theorem single_isCycle₁_of_mem_fixedPoints
(g : G) (a : A) (ha : a ∈ MulAction.fixedPoints G A) :
IsCycle₁ (single g a) := by
simp_all [IsCycle₁]
theorem single_isCycle₂_iff_inv (g : G × G) (a : A) :
IsCycle₂ (single g a) ↔
single g.2 (g.1⁻¹ • a) + single g.1 a = single (g.1 * g.2) a := by
simp [IsCycle₂]
@[simp]
theorem single_isCycle₂_iff (g : G × G) (a : A) :
IsCycle₂ (single g a) ↔
single g.2 a + single g.1 (g.1 • a) = single (g.1 * g.2) (g.1 • a) := by
rw [← (Finsupp.mapRange_injective (α := G) _ (smul_zero _) (MulAction.bijective g.1⁻¹).1).eq_iff]
simp [mapRange_add, IsCycle₂]
end
end IsCycle
section IsBoundary
section
variable {G A : Type*} [Mul G] [Inv G] [AddCommGroup A] [SMul G A]
variable (G) in
/-- A term `x : A` satisfies the 0-boundary condition if there exists a finsupp
`∑ aᵢ·gᵢ : G →₀ A` such that `∑ gᵢ⁻¹ • aᵢ - aᵢ = x`. -/
def IsBoundary₀ (a : A) : Prop :=
∃ (x : G →₀ A), x.sum (fun g z => g⁻¹ • z - z) = a
/-- A finsupp `x : G →₀ A` satisfies the 1-boundary condition if there's a finsupp
`∑ aᵢ·(gᵢ, hᵢ) : G × G →₀ A` such that `∑ (gᵢ⁻¹ • aᵢ)·hᵢ - aᵢ·gᵢhᵢ + aᵢ·gᵢ = x`. -/
def IsBoundary₁ (x : G →₀ A) : Prop :=
∃ y : G × G →₀ A, y.sum
(fun g a => single g.2 (g.1⁻¹ • a) - single (g.1 * g.2) a + single g.1 a) = x
/-- A finsupp `x : G × G →₀ A` satsfies the 2-boundary condition if there's a finsupp
`∑ aᵢ·(gᵢ, hᵢ, jᵢ) : G × G × G →₀ A` such that
`∑ (gᵢ⁻¹ • aᵢ)·(hᵢ, jᵢ) - aᵢ·(gᵢhᵢ, jᵢ) + aᵢ·(gᵢ, hᵢjᵢ) - aᵢ·(gᵢ, hᵢ) = x.` -/
def IsBoundary₂ (x : G × G →₀ A) : Prop :=
∃ y : G × G × G →₀ A, y.sum (fun g a => single (g.2.1, g.2.2) (g.1⁻¹ • a) -
single (g.1 * g.2.1, g.2.2) a + single (g.1, g.2.1 * g.2.2) a - single (g.1, g.2.1) a) = x
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [DistribMulAction G A]
variable (G) in
theorem isBoundary₀_iff (a : A) :
IsBoundary₀ G a ↔ ∃ x : G →₀ A, x.sum (fun g z => g • z - z) = a := by
constructor
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (- (g⁻¹ • a)))
simp_all [sum_neg_index, sum_sum_index, neg_add_eq_sub]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (- (g • a)))
simp_all [sum_neg_index, sum_sum_index, neg_add_eq_sub]
theorem isBoundary₁_iff (x : G →₀ A) :
IsBoundary₁ x ↔ ∃ y : G × G →₀ A, y.sum
(fun g a => single g.2 a - single (g.1 * g.2) (g.1 • a) + single g.1 (g.1 • a)) = x := by
constructor
· rintro ⟨y, hy⟩
use y.sum (fun g a => single g (g.1⁻¹ • a))
simp_all [sum_sum_index]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (g.1 • a))
simp_all [sum_sum_index]
theorem isBoundary₂_iff (x : G × G →₀ A) :
IsBoundary₂ x ↔ ∃ y : G × G × G →₀ A, y.sum
(fun g a => single (g.2.1, g.2.2) a - single (g.1 * g.2.1, g.2.2) (g.1 • a) +
single (g.1, g.2.1 * g.2.2) (g.1 • a) - single (g.1, g.2.1) (g.1 • a)) = x := by
constructor
· rintro ⟨y, hy⟩
use y.sum (fun g a => single g (g.1⁻¹ • a))
simp_all [sum_sum_index]
· rintro ⟨x, hx⟩
use x.sum (fun g a => single g (g.1 • a))
simp_all [sum_sum_index]
end
end IsBoundary
section ofDistribMulAction
variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A]
[DistribMulAction G A] [SMulCommClass G k A]
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a term
`x : A` satisfying the 0-boundary condition, this produces an element of the kernel of the quotient
map `A → A_G` for the representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def coinvariantsKerOfIsBoundary₀ (x : A) (hx : IsBoundary₀ G x) :
Coinvariants.ker (Representation.ofDistribMulAction k G A) :=
⟨x, by
rcases (isBoundary₀_iff G x).1 hx with ⟨y, rfl⟩
exact Submodule.finsuppSum_mem _ _ _ _ fun g _ => Coinvariants.mem_ker_of_eq g (y g) _ rfl⟩
theorem isBoundary₀_of_mem_coinvariantsKer
(x : A) (hx : x ∈ Coinvariants.ker (Representation.ofDistribMulAction k G A)) :
IsBoundary₀ G x :=
Submodule.span_induction (fun _ ⟨g, hg⟩ => ⟨single g.1⁻¹ g.2, by simp_all⟩) ⟨0, by simp⟩
(fun _ _ _ _ ⟨X, hX⟩ ⟨Y, hY⟩ => ⟨X + Y, by simp_all [sum_add_index', add_sub_add_comm]⟩)
(fun r _ _ ⟨X, hX⟩ => ⟨r • X, by simp [← hX, sum_smul_index', smul_comm, smul_sub, smul_sum]⟩)
hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G →₀ A` satisfying the 1-cycle condition, produces a 1-cycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cyclesOfIsCycle₁ (x : G →₀ A) (hx : IsCycle₁ x) :
cycles₁ (Rep.ofDistribMulAction k G A) :=
⟨x, (mem_cycles₁_iff (A := Rep.ofDistribMulAction k G A) x).2 hx⟩
theorem isCycle₁_of_mem_cycles₁
(x : G →₀ A) (hx : x ∈ cycles₁ (Rep.ofDistribMulAction k G A)) :
IsCycle₁ x := by
simpa using (mem_cycles₁_iff (A := Rep.ofDistribMulAction k G A) x).1 hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G →₀ A` satisfying the 1-boundary condition, produces a 1-boundary for the representation
on `A` induced by the `DistribMulAction`. -/
@[simps]
def boundariesOfIsBoundary₁ (x : G →₀ A) (hx : IsBoundary₁ x) :
boundaries₁ (Rep.ofDistribMulAction k G A) :=
⟨x, hx⟩
theorem isBoundary₁_of_mem_boundaries₁
(x : G →₀ A) (hx : x ∈ boundaries₁ (Rep.ofDistribMulAction k G A)) :
IsBoundary₁ x := hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G × G →₀ A` satisfying the 2-cycle condition, produces a 2-cycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def cyclesOfIsCycle₂ (x : G × G →₀ A) (hx : IsCycle₂ x) :
cycles₂ (Rep.ofDistribMulAction k G A) :=
⟨x, (mem_cycles₂_iff (A := Rep.ofDistribMulAction k G A) x).2 hx⟩
theorem isCycle₂_of_mem_cycles₂
(x : G × G →₀ A) (hx : x ∈ cycles₂ (Rep.ofDistribMulAction k G A)) :
IsCycle₂ x := (mem_cycles₂_iff (A := Rep.ofDistribMulAction k G A) x).1 hx
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a finsupp
`x : G × G →₀ A` satisfying the 2-boundary condition, produces a 2-boundary for the
representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def boundariesOfIsBoundary₂ (x : G × G →₀ A) (hx : IsBoundary₂ x) :
boundaries₂ (Rep.ofDistribMulAction k G A) :=
⟨x, hx⟩
theorem isBoundary₂_of_mem_boundaries₂
(x : G × G →₀ A) (hx : x ∈ boundaries₂ (Rep.ofDistribMulAction k G A)) :
IsBoundary₂ x := hx
end ofDistribMulAction
open ShortComplex
section cyclesIso₀
instance : Epi (shortComplexH0 A).g := inferInstanceAs <| Epi ((coinvariantsMk k G).app A)
lemma shortComplexH0_exact : (shortComplexH0 A).Exact := by
rw [ShortComplex.moduleCat_exact_iff]
intro x (hx : Coinvariants.mk _ _ = 0)
rw [Coinvariants.mk_eq_zero, ← range_d₁₀_eq_coinvariantsKer] at hx
rcases hx with ⟨x, hx, rfl⟩
use x
rfl
/-- The 0-cycles of the complex of inhomogeneous chains of `A` are isomorphic to `A`. -/
def cyclesIso₀ : cycles A 0 ≅ A.V :=
(inhomogeneousChains A).iCyclesIso _ 0 (by aesop) (by aesop) ≪≫ chainsIso₀ A
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesIso₀_inv_comp_iCycles :
(cyclesIso₀ A).inv ≫ iCycles A 0 = (chainsIso₀ A).inv := by
simp [cyclesIso₀]
/-- The arrow `(G →₀ A) --d₁₀--> A` is isomorphic to the differential
`(inhomogeneousChains A).d 1 0` of the complex of inhomogeneous chains of `A`. -/
@[simps! hom_left hom_right inv_left inv_right]
def d₁₀ArrowIso :
Arrow.mk ((inhomogeneousChains A).d 1 0) ≅ Arrow.mk (d₁₀ A) :=
Arrow.isoMk (chainsIso₁ A) (chainsIso₀ A) (comp_d₁₀_eq A)
/-- The 0-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`A.ρ.coinvariants`, which is a simpler type. -/
def opcyclesIso₀ : (inhomogeneousChains A).opcycles 0 ≅ (coinvariantsFunctor k G).obj A :=
CokernelCofork.mapIsoOfIsColimit
((inhomogeneousChains A).opcyclesIsCokernel 1 0 (by simp)) (shortComplexH0_exact A).gIsCokernel
(d₁₀ArrowIso A)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma pOpcycles_comp_opcyclesIso_hom :
(inhomogeneousChains A).pOpcycles 0 ≫ (opcyclesIso₀ A).hom =
(chainsIso₀ A).hom ≫ (coinvariantsMk k G).app A :=
CokernelCofork.π_mapOfIsColimit (φ := (d₁₀ArrowIso A).hom) _ _
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma coinvariantsMk_comp_opcyclesIso₀_inv :
(coinvariantsMk k G).app A ≫ (opcyclesIso₀ A).inv =
(chainsIso₀ A).inv ≫ (inhomogeneousChains A).pOpcycles 0 :=
(CommSq.vert_inv ⟨pOpcycles_comp_opcyclesIso_hom A⟩).w
lemma cyclesMk₀_eq (x : A) :
cyclesMk 0 0 (by simp) ((chainsIso₀ A).inv x) (by simp) = (cyclesIso₀ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 0).1 inferInstance <| by rw [iCycles_mk]; simp
end cyclesIso₀
section isoCycles₁
/-- The short complex `(G² →₀ A) --d₂₁--> (G →₀ A) --d₁₀--> A` is isomorphic to the 1st
short complex associated to the complex of inhomogeneous chains of `A`. -/
@[simps! hom inv]
def isoShortComplexH1 : (inhomogeneousChains A).sc 1 ≅ shortComplexH1 A :=
(inhomogeneousChains A).isoSc' 2 1 0 (by simp) (by simp) ≪≫
isoMk (chainsIso₂ A) (chainsIso₁ A) (chainsIso₀ A) (comp_d₂₁_eq A) (comp_d₁₀_eq A)
/-- The 1-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`cycles₁ A`, which is a simpler type. -/
def isoCycles₁ : cycles A 1 ≅ ModuleCat.of k (cycles₁ A) :=
cyclesMapIso' (isoShortComplexH1 A) ((inhomogeneousChains A).sc 1).leftHomologyData
(shortComplexH1 A).moduleCatLeftHomologyData
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₁_hom_comp_i :
(isoCycles₁ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.i =
iCycles A 1 ≫ (chainsIso₁ A).hom := by
simp [isoCycles₁, iCycles, HomologicalComplex.iCycles, ShortComplex.iCycles]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₁_inv_comp_iCycles :
(isoCycles₁ A).inv ≫ iCycles A 1 =
(shortComplexH1 A).moduleCatLeftHomologyData.i ≫ (chainsIso₁ A).inv :=
(CommSq.horiz_inv ⟨isoCycles₁_hom_comp_i A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCycles_comp_isoCycles₁_hom :
toCycles A 2 1 ≫ (isoCycles₁ A).hom =
(chainsIso₂ A).hom ≫ (shortComplexH1 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH1 A).moduleCatLeftHomologyData.i, comp_d₂₁_eq,
shortComplexH1_f]
lemma cyclesMk₁_eq (x : cycles₁ A) :
cyclesMk 1 0 (by simp) ((chainsIso₁ A).inv x) (by simp) = (isoCycles₁ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 1).1 inferInstance <| by
rw [iCycles_mk]
simp only [ChainComplex.of_x, isoCycles₁_inv_comp_iCycles_apply]
rfl
end isoCycles₁
section isoCycles₂
/-- The short complex `(G³ →₀ A) --d₃₂--> (G² →₀ A) --d₂₁--> (G →₀ A)` is isomorphic to the 2nd
short complex associated to the complex of inhomogeneous chains of `A`. -/
@[simps! hom inv]
def isoShortComplexH2 : (inhomogeneousChains A).sc 2 ≅ shortComplexH2 A :=
(inhomogeneousChains A).isoSc' 3 2 1 (by simp) (by simp) ≪≫
isoMk (chainsIso₃ A) (chainsIso₂ A) (chainsIso₁ A) (comp_d₃₂_eq A) (comp_d₂₁_eq A)
/-- The 2-cycles of the complex of inhomogeneous chains of `A` are isomorphic to
`cycles₂ A`, which is a simpler type. -/
def isoCycles₂ : cycles A 2 ≅ ModuleCat.of k (cycles₂ A) :=
cyclesMapIso' (isoShortComplexH2 A) ((inhomogeneousChains A).sc 2).leftHomologyData
(shortComplexH2 A).moduleCatLeftHomologyData
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₂_hom_comp_i :
(isoCycles₂ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.i =
iCycles A 2 ≫ (chainsIso₂ A).hom := by
simp [isoCycles₂, iCycles, HomologicalComplex.iCycles, ShortComplex.iCycles]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma isoCycles₂_inv_comp_iCycles :
(isoCycles₂ A).inv ≫ iCycles A 2 =
(shortComplexH2 A).moduleCatLeftHomologyData.i ≫ (chainsIso₂ A).inv :=
(CommSq.horiz_inv ⟨isoCycles₂_hom_comp_i A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma toCycles_comp_isoCycles₂_hom :
toCycles A 3 2 ≫ (isoCycles₂ A).hom =
(chainsIso₃ A).hom ≫ (shortComplexH2 A).moduleCatLeftHomologyData.f' := by
simp [← cancel_mono (shortComplexH2 A).moduleCatLeftHomologyData.i, comp_d₃₂_eq,
shortComplexH2_f]
lemma cyclesMk₂_eq (x : cycles₂ A) :
cyclesMk 2 1 (by simp) ((chainsIso₂ A).inv x) (by simp) = (isoCycles₂ A).inv x :=
(ModuleCat.mono_iff_injective <| iCycles A 2).1 inferInstance <| by
rw [iCycles_mk]
simp only [ChainComplex.of_x, isoCycles₂_inv_comp_iCycles_apply]
rfl
end isoCycles₂
section Homology
section H0
/-- Shorthand for the 0th group homology of a `k`-linear `G`-representation `A`, `H₀(G, A)`,
defined as the 0th homology of the complex of inhomogeneous chains of `A`. -/
abbrev H0 := groupHomology A 0
/-- The 0th group homology of `A`, defined as the 0th homology of the complex of inhomogeneous
chains, is isomorphic to the invariants of the representation on `A`. -/
def H0Iso : H0 A ≅ (coinvariantsFunctor k G).obj A :=
(ChainComplex.isoHomologyι₀ _) ≪≫ opcyclesIso₀ A
/-- The quotient map from `A` to `H₀(G, A)`. -/
def H0π : A.V ⟶ H0 A := (cyclesIso₀ A).inv ≫ π A 0
instance : Epi (H0π A) := by unfold H0π; infer_instance
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H0Iso_hom :
π A 0 ≫ (H0Iso A).hom = (cyclesIso₀ A).hom ≫ (coinvariantsMk k G).app A := by
simp [H0Iso, cyclesIso₀]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma coinvariantsMk_comp_H0Iso_inv :
(coinvariantsMk k G).app A ≫ (H0Iso A).inv = H0π A :=
(CommSq.vert_inv ⟨π_comp_H0Iso_hom A⟩).w
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma H0π_comp_H0Iso_hom :
H0π A ≫ (H0Iso A).hom = (coinvariantsMk k G).app A := by
simp [H0π]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma cyclesIso₀_comp_H0π :
(cyclesIso₀ A).hom ≫ H0π A = π A 0 := by
simp [H0π]
@[elab_as_elim]
theorem H0_induction_on {C : H0 A → Prop} (x : H0 A)
(h : ∀ x : A, C (H0π A x)) : C x :=
groupHomology_induction_on x fun y => by simpa using h ((cyclesIso₀ A).hom y)
section IsTrivial
variable [A.IsTrivial]
/-- When the representation on `A` is trivial, then `H₀(G, A)` is all of `A.` -/
def H0IsoOfIsTrivial :
H0 A ≅ A.V :=
((inhomogeneousChains A).isoHomologyπ 1 0 (by simp) <| by
ext; simp [inhomogeneousChains.d_def, inhomogeneousChains.d_single (G := G),
Unique.eq_default (α := Fin 0 → G)]).symm ≪≫ cyclesIso₀ A
@[simp]
theorem H0IsoOfIsTrivial_inv_eq_π :
(H0IsoOfIsTrivial A).inv = H0π A := rfl
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem π_comp_H0IsoOfIsTrivial_hom :
π A 0 ≫ (H0IsoOfIsTrivial A).hom = (cyclesIso₀ A).hom := by
simp [H0IsoOfIsTrivial]
end IsTrivial
end H0
section H1
/-- Shorthand for the 1st group homology of a `k`-linear `G`-representation `A`, `H₁(G, A)`,
defined as the 1st homology of the complex of inhomogeneous chains of `A`. -/
abbrev H1 := groupHomology A 1
/-- The quotient map from the 1-cycles of `A`, as a submodule of `G →₀ A`, to `H₁(G, A)`. -/
def H1π : ModuleCat.of k (cycles₁ A) ⟶ H1 A :=
(isoCycles₁ A).inv ≫ π A 1
instance : Epi (H1π A) := by unfold H1π; infer_instance
variable {A}
lemma H1π_eq_zero_iff (x : cycles₁ A) : H1π A x = 0 ↔ x.1 ∈ boundaries₁ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH1 A).inv
(shortComplexH1 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousChains A).sc 1).leftHomologyIso.hom
simp only [H1π, isoCycles₁, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, boundaries₁, shortComplexH1, cycles₁]
lemma H1π_eq_iff (x y : cycles₁ A) :
H1π A x = H1π A y ↔ x.1 - y.1 ∈ boundaries₁ A := by
rw [← sub_eq_zero, ← map_sub, H1π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H1_induction_on {C : H1 A → Prop} (x : H1 A) (h : ∀ x : cycles₁ A, C (H1π A x)) :
C x :=
groupHomology_induction_on x fun y => by simpa [H1π] using h ((isoCycles₁ A).hom y)
variable (A)
/-- The 1st group homology of `A`, defined as the 1st homology of the complex of inhomogeneous
chains, is isomorphic to `cycles₁ A ⧸ boundaries₁ A`, which is a simpler type. -/
def H1Iso : H1 A ≅ (shortComplexH1 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH1 A) _ _)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H1Iso_hom :
π A 1 ≫ (H1Iso A).hom = (isoCycles₁ A).hom ≫
(shortComplexH1 A).moduleCatLeftHomologyData.π := by
simp [H1Iso, isoCycles₁, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H1Iso_inv :
(shortComplexH1 A).moduleCatLeftHomologyData.π ≫ (H1Iso A).inv = H1π A :=
(CommSq.vert_inv ⟨π_comp_H1Iso_hom A⟩).w
section IsTrivial
variable [A.IsTrivial]
open TensorProduct
/-- If a `G`-representation on `A` is trivial, this is the natural map `Gᵃᵇ → A → H₁(G, A)`
sending `⟦g⟧, a` to `⟦single g a⟧`. -/
def mkH1OfIsTrivial : Additive (Abelianization G) →ₗ[ℤ] A →ₗ[ℤ] H1 A :=
AddMonoidHom.toIntLinearMap <| AddMonoidHom.toMultiplicative'.symm <| Abelianization.lift {
toFun g := Multiplicative.ofAdd (AddMonoidHom.toIntLinearMap (AddMonoidHomClass.toAddMonoidHom
((H1π A).hom ∘ₗ (cycles₁IsoOfIsTrivial A).inv.hom ∘ₗ lsingle g)))
map_one' := Multiplicative.toAdd.injective <|
LinearMap.ext fun _ => (H1π_eq_zero_iff _).2 <| single_one_mem_boundaries₁ _
map_mul' g h := Multiplicative.toAdd.injective <| LinearMap.ext fun a => by
simpa [← map_add] using ((H1π_eq_iff _ _).2 ⟨single (g, h) a, by
simp [cycles₁IsoOfIsTrivial, sub_add_eq_add_sub, add_comm (single h a),
d₂₁_single (A := A)]⟩).symm }
variable {A} in
@[simp]
lemma mkH1OfIsTrivial_apply (g : G) (a : A) :
mkH1OfIsTrivial A (Additive.ofMul (Abelianization.of g)) a =
H1π A ((cycles₁IsoOfIsTrivial A).inv (single g a)) := rfl
/-- If a `G`-representation on `A` is trivial, this is the natural map `H₁(G, A) → Gᵃᵇ ⊗[ℤ] A`
sending `⟦single g a⟧` to `⟦g⟧ ⊗ₜ a`. -/
def H1ToTensorOfIsTrivial : H1 A →ₗ[ℤ] (Additive <| Abelianization G) ⊗[ℤ] A :=
((QuotientAddGroup.lift _ ((Finsupp.liftAddHom fun g => AddMonoidHomClass.toAddMonoidHom
(TensorProduct.mk ℤ _ _ (Additive.ofMul (Abelianization.of g)))).comp
(cycles₁ A).toAddSubgroup.subtype) fun ⟨y, hy⟩ ⟨z, hz⟩ => AddMonoidHom.mem_ker.2 <| by
simp [← hz, d₂₁, sum_sum_index, sum_add_index', tmul_add, sum_sub_index, tmul_sub,
shortComplexH1]).comp <| AddMonoidHomClass.toAddMonoidHom (H1Iso A).hom.hom).toIntLinearMap
variable {A} in
@[simp]
lemma H1ToTensorOfIsTrivial_H1π_single (g : G) (a : A) :
H1ToTensorOfIsTrivial A (H1π A <| (cycles₁IsoOfIsTrivial A).inv (single g a)) =
Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a := by
simp only [H1ToTensorOfIsTrivial, H1π, AddMonoidHom.coe_toIntLinearMap, AddMonoidHom.coe_comp]
change QuotientAddGroup.lift _ _ _ ((H1Iso A).hom _) = _
simp [π_comp_H1Iso_hom_apply, Submodule.Quotient.mk, QuotientAddGroup.lift, AddCon.lift,
AddCon.liftOn, AddSubgroup.subtype, cycles₁IsoOfIsTrivial]
/-- If a `G`-representation on `A` is trivial, this is the group isomorphism between
`H₁(G, A) ≃+ Gᵃᵇ ⊗[ℤ] A` defined by `⟦single g a⟧ ↦ ⟦g⟧ ⊗ a`. -/
@[simps! -isSimp]
def H1AddEquivOfIsTrivial :
H1 A ≃+ (Additive <| Abelianization G) ⊗[ℤ] A :=
LinearEquiv.toAddEquiv <| LinearEquiv.ofLinear
(H1ToTensorOfIsTrivial A) (lift <| mkH1OfIsTrivial A)
(ext <| LinearMap.toAddMonoidHom_injective <| by
ext g a
simp [TensorProduct.mk_apply, TensorProduct.lift.tmul, mkH1OfIsTrivial_apply,
H1ToTensorOfIsTrivial_H1π_single g a])
(LinearMap.toAddMonoidHom_injective <|
(H1Iso A).symm.toLinearEquiv.toAddEquiv.comp_left_injective <|
QuotientAddGroup.addMonoidHom_ext _ <|
(cycles₁IsoOfIsTrivial A).symm.toLinearEquiv.toAddEquiv.comp_left_injective <| by
ext
simp only [H1ToTensorOfIsTrivial, Iso.toLinearEquiv, AddMonoidHom.coe_comp,
LinearMap.toAddMonoidHom_coe, LinearMap.coe_comp, AddMonoidHom.coe_toIntLinearMap]
change TensorProduct.lift _ (QuotientAddGroup.lift _ _ _ ((H1Iso A).hom _)) = _
simpa [AddSubgroup.subtype, cycles₁IsoOfIsTrivial_inv_apply (A := A),
-π_comp_H1Iso_inv_apply] using (π_comp_H1Iso_inv_apply A _).symm)
@[simp]
lemma H1AddEquivOfIsTrivial_single (g : G) (a : A) :
H1AddEquivOfIsTrivial A (H1π A <| (cycles₁IsoOfIsTrivial A).inv (single g a)) =
Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a := by
rw [H1AddEquivOfIsTrivial_apply, H1ToTensorOfIsTrivial_H1π_single g a]
@[simp]
lemma H1AddEquivOfIsTrivial_symm_tmul (g : G) (a : A) :
(H1AddEquivOfIsTrivial A).symm (Additive.ofMul (Abelianization.of g) ⊗ₜ[ℤ] a) =
H1π A ((cycles₁IsoOfIsTrivial A).inv <| single g a) := by
rfl
end IsTrivial
end H1
section H2
/-- Shorthand for the 2nd group homology of a `k`-linear `G`-representation `A`, `H₂(G, A)`,
defined as the 2nd homology of the complex of inhomogeneous chains of `A`. -/
abbrev H2 := groupHomology A 2
/-- The quotient map from the 2-cycles of `A`, as a submodule of `G × G →₀ A`, to `H₂(G, A)`. -/
def H2π : ModuleCat.of k (cycles₂ A) ⟶ H2 A :=
(isoCycles₂ A).inv ≫ π A 2
instance : Epi (H2π A) := by unfold H2π; infer_instance
variable {A}
lemma H2π_eq_zero_iff (x : cycles₂ A) : H2π A x = 0 ↔ x.1 ∈ boundaries₂ A := by
have h := leftHomologyπ_naturality'_assoc (isoShortComplexH2 A).inv
(shortComplexH2 A).moduleCatLeftHomologyData (leftHomologyData _)
((inhomogeneousChains A).sc 2).leftHomologyIso.hom
simp only [H2π, isoCycles₂, π, HomologicalComplex.homologyπ, homologyπ,
cyclesMapIso'_inv, leftHomologyπ, ← h, ← leftHomologyMapIso'_inv, ModuleCat.hom_comp,
LinearMap.coe_comp, Function.comp_apply, map_eq_zero_iff _
((ModuleCat.mono_iff_injective <| _).1 inferInstance)]
simp [LinearMap.range_codRestrict, boundaries₂, shortComplexH2, cycles₂]
lemma H2π_eq_iff (x y : cycles₂ A) :
H2π A x = H2π A y ↔ x.1 - y.1 ∈ boundaries₂ A := by
rw [← sub_eq_zero, ← map_sub, H2π_eq_zero_iff]
rfl
@[elab_as_elim]
theorem H2_induction_on {C : H2 A → Prop} (x : H2 A) (h : ∀ x : cycles₂ A, C (H2π A x)) :
C x :=
groupHomology_induction_on x (fun y => by simpa [H2π] using h ((isoCycles₂ A).hom y))
variable (A)
/-- The 2nd group homology of `A`, defined as the 2nd homology of the complex of inhomogeneous
chains, is isomorphic to `cycles₂ A ⧸ boundaries₂ A`, which is a simpler type. -/
def H2Iso : H2 A ≅ (shortComplexH2 A).moduleCatLeftHomologyData.H :=
(leftHomologyIso _).symm ≪≫ (leftHomologyMapIso' (isoShortComplexH2 A) _ _)
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H2Iso_hom :
π A 2 ≫ (H2Iso A).hom = (isoCycles₂ A).hom ≫
(shortComplexH2 A).moduleCatLeftHomologyData.π := by
simp [H2Iso, isoCycles₂, π, HomologicalComplex.homologyπ, leftHomologyπ]
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma π_comp_H2Iso_inv :
(shortComplexH2 A).moduleCatLeftHomologyData.π ≫ (H2Iso A).inv = H2π A :=
(CommSq.vert_inv ⟨π_comp_H2Iso_hom A⟩).w
end H2
end Homology
end groupHomology
|
Basic.lean
|
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Sub.Unbundled.Basic
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Even
/-!
# Lemmas about subtraction in unbundled canonically ordered monoids
-/
variable {α : Type*}
section CanonicallyOrderedAddCommMonoid
variable [AddCommMonoid α] [PartialOrder α] [CanonicallyOrderedAdd α]
[Sub α] [OrderedSub α] {a b c : α}
theorem add_tsub_cancel_iff_le : a + (b - a) = b ↔ a ≤ b :=
⟨fun h => le_iff_exists_add.mpr ⟨b - a, h.symm⟩, add_tsub_cancel_of_le⟩
theorem tsub_add_cancel_iff_le : b - a + a = b ↔ a ≤ b := by
rw [add_comm]
exact add_tsub_cancel_iff_le
-- This was previously a `@[simp]` lemma, but it is not necessarily a good idea, e.g. in
-- `example (h : n - m = 0) : a + (n - m) = a := by simp_all`
theorem tsub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b := by
rw [← nonpos_iff_eq_zero, tsub_le_iff_left, add_zero]
alias ⟨_, tsub_eq_zero_of_le⟩ := tsub_eq_zero_iff_le
@[simp]
theorem tsub_self (a : α) : a - a = 0 :=
tsub_eq_zero_of_le le_rfl
theorem tsub_le_self : a - b ≤ a :=
tsub_le_iff_left.mpr <| le_add_left le_rfl
@[simp]
theorem zero_tsub (a : α) : 0 - a = 0 :=
tsub_eq_zero_of_le <| zero_le a
theorem tsub_self_add (a b : α) : a - (a + b) = 0 :=
tsub_eq_zero_of_le <| self_le_add_right _ _
theorem tsub_pos_iff_not_le : 0 < a - b ↔ ¬a ≤ b := by
rw [pos_iff_ne_zero, Ne, tsub_eq_zero_iff_le]
theorem tsub_pos_of_lt (h : a < b) : 0 < b - a :=
tsub_pos_iff_not_le.mpr h.not_ge
theorem tsub_lt_of_lt (h : a < b) : a - c < b :=
lt_of_le_of_lt tsub_le_self h
namespace AddLECancellable
protected theorem tsub_le_tsub_iff_left (ha : AddLECancellable a) (hc : AddLECancellable c)
(h : c ≤ a) : a - b ≤ a - c ↔ c ≤ b := by
refine ⟨?_, fun h => tsub_le_tsub_left h a⟩
rw [tsub_le_iff_left, ← hc.add_tsub_assoc_of_le h, hc.le_tsub_iff_right (h.trans le_add_self),
add_comm b]
apply ha
protected theorem tsub_right_inj (ha : AddLECancellable a) (hb : AddLECancellable b)
(hc : AddLECancellable c) (hba : b ≤ a) (hca : c ≤ a) : a - b = a - c ↔ b = c := by
simp_rw [le_antisymm_iff, ha.tsub_le_tsub_iff_left hb hba, ha.tsub_le_tsub_iff_left hc hca,
and_comm]
end AddLECancellable
/-! #### Lemmas where addition is order-reflecting. -/
section Contra
variable [AddLeftReflectLE α]
theorem tsub_le_tsub_iff_left (h : c ≤ a) : a - b ≤ a - c ↔ c ≤ b :=
Contravariant.AddLECancellable.tsub_le_tsub_iff_left Contravariant.AddLECancellable h
theorem tsub_right_inj (hba : b ≤ a) (hca : c ≤ a) : a - b = a - c ↔ b = c :=
Contravariant.AddLECancellable.tsub_right_inj Contravariant.AddLECancellable
Contravariant.AddLECancellable hba hca
variable (α)
/-- A `CanonicallyOrderedAddCommMonoid` with ordered subtraction and order-reflecting addition is
cancellative. This is not an instance as it would form a typeclass loop.
See note [reducible non-instances]. -/
abbrev CanonicallyOrderedAddCommMonoid.toAddCancelCommMonoid : AddCancelCommMonoid α :=
{ (by infer_instance : AddCommMonoid α) with
add_left_cancel := fun a b c h => by
simpa only [add_tsub_cancel_left] using congr_arg (fun x => x - a) h }
end Contra
end CanonicallyOrderedAddCommMonoid
/-! ### Lemmas in a linearly canonically ordered monoid. -/
section CanonicallyLinearOrderedAddCommMonoid
variable [AddCommMonoid α] [LinearOrder α] [CanonicallyOrderedAdd α] [Sub α] [OrderedSub α]
{a b c : α}
@[simp]
theorem tsub_pos_iff_lt : 0 < a - b ↔ b < a := by rw [tsub_pos_iff_not_le, not_le]
theorem tsub_eq_tsub_min (a b : α) : a - b = a - min a b := by
rcases le_total a b with h | h
· rw [min_eq_left h, tsub_self, tsub_eq_zero_of_le h]
· rw [min_eq_right h]
namespace AddLECancellable
omit [CanonicallyOrderedAdd α] in
protected theorem lt_tsub_iff_right (hc : AddLECancellable c) : a < b - c ↔ a + c < b :=
⟨lt_imp_lt_of_le_imp_le tsub_le_iff_right.mpr, hc.lt_tsub_of_add_lt_right⟩
omit [CanonicallyOrderedAdd α] in
protected theorem lt_tsub_iff_left (hc : AddLECancellable c) : a < b - c ↔ c + a < b :=
⟨lt_imp_lt_of_le_imp_le tsub_le_iff_left.mpr, hc.lt_tsub_of_add_lt_left⟩
protected theorem tsub_lt_tsub_iff_right (hc : AddLECancellable c) (h : c ≤ a) :
a - c < b - c ↔ a < b := by rw [hc.lt_tsub_iff_left, add_tsub_cancel_of_le h]
protected theorem tsub_lt_self (ha : AddLECancellable a) (h₁ : 0 < a) (h₂ : 0 < b) : a - b < a := by
refine tsub_le_self.lt_of_ne fun h => ?_
rw [← h, tsub_pos_iff_lt] at h₁
exact h₂.not_ge (ha.add_le_iff_nonpos_left.1 <| add_le_of_le_tsub_left_of_le h₁.le h.ge)
protected theorem tsub_lt_self_iff (ha : AddLECancellable a) : a - b < a ↔ 0 < a ∧ 0 < b := by
refine
⟨fun h => ⟨(zero_le _).trans_lt h, (zero_le b).lt_of_ne ?_⟩, fun h => ha.tsub_lt_self h.1 h.2⟩
rintro rfl
rw [tsub_zero] at h
exact h.false
/-- See `lt_tsub_iff_left_of_le_of_le` for a weaker statement in a partial order. -/
protected theorem tsub_lt_tsub_iff_left_of_le (ha : AddLECancellable a) (hb : AddLECancellable b)
(h : b ≤ a) : a - b < a - c ↔ c < b :=
lt_iff_lt_of_le_iff_le <| ha.tsub_le_tsub_iff_left hb h
end AddLECancellable
section Contra
variable [AddLeftReflectLE α]
/-- This lemma also holds for `ENNReal`, but we need a different proof for that. -/
theorem tsub_lt_tsub_iff_right (h : c ≤ a) : a - c < b - c ↔ a < b :=
Contravariant.AddLECancellable.tsub_lt_tsub_iff_right h
theorem tsub_lt_self : 0 < a → 0 < b → a - b < a :=
Contravariant.AddLECancellable.tsub_lt_self
@[simp] theorem tsub_lt_self_iff : a - b < a ↔ 0 < a ∧ 0 < b :=
Contravariant.AddLECancellable.tsub_lt_self_iff
/-- See `lt_tsub_iff_left_of_le_of_le` for a weaker statement in a partial order. -/
theorem tsub_lt_tsub_iff_left_of_le (h : b ≤ a) : a - b < a - c ↔ c < b :=
Contravariant.AddLECancellable.tsub_lt_tsub_iff_left_of_le Contravariant.AddLECancellable h
lemma tsub_tsub_eq_min (a b : α) : a - (a - b) = min a b := by
rw [tsub_eq_tsub_min _ b, tsub_tsub_cancel_of_le (min_le_left a _)]
end Contra
/-! ### Lemmas about `max` and `min`. -/
theorem tsub_add_eq_max : a - b + b = max a b := by
rcases le_total a b with h | h
· rw [max_eq_right h, tsub_eq_zero_of_le h, zero_add]
· rw [max_eq_left h, tsub_add_cancel_of_le h]
theorem add_tsub_eq_max : a + (b - a) = max a b := by rw [add_comm, max_comm, tsub_add_eq_max]
theorem tsub_min : a - min a b = a - b := by
rcases le_total a b with h | h
· rw [min_eq_left h, tsub_self, tsub_eq_zero_of_le h]
· rw [min_eq_right h]
theorem tsub_add_min : a - b + min a b = a := by
rw [← tsub_min, @tsub_add_cancel_of_le]
apply min_le_left
-- `Odd.tsub` requires `CanonicallyLinearOrderedSemiring`, which we don't have
lemma Even.tsub [AddLeftReflectLE α] {m n : α} (hm : Even m) (hn : Even n) :
Even (m - n) := by
obtain ⟨a, rfl⟩ := hm
obtain ⟨b, rfl⟩ := hn
refine ⟨a - b, ?_⟩
obtain h | h := le_total a b
· rw [tsub_eq_zero_of_le h, tsub_eq_zero_of_le (add_le_add h h), add_zero]
· exact (tsub_add_tsub_comm h h).symm
end CanonicallyLinearOrderedAddCommMonoid
|
KleinFour.lean
|
/-
Copyright (c) 2023 Newell Jensen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Newell Jensen
-/
import Mathlib.GroupTheory.SpecificGroups.Cyclic
/-!
# Klein Four Group
The Klein (Vierergruppe) four-group is a non-cyclic abelian group with four elements, in which
each element is self-inverse and in which composing any two of the three non-identity elements
produces the third one.
## Main definitions
* `IsKleinFour` : A mixin class which states that the group has order four and exponent two.
* `mulEquiv'` : An equivalence between a Klein four-group and a group of exponent two which
preserves the identity is in fact an isomorphism.
* `mulEquiv`: Any two Klein four-groups are isomorphic via any identity preserving equivalence.
## References
* https://en.wikipedia.org/wiki/Klein_four-group
* https://en.wikipedia.org/wiki/Alternating_group
## TODO
* Prove an `IsKleinFour` group is isomorphic to the normal subgroup of `alternatingGroup (Fin 4)`
with the permutation cycles `V = {(), (1 2)(3 4), (1 3)(2 4), (1 4)(2 3)}`. This is the kernel
of the surjection of `alternatingGroup (Fin 4)` onto `alternatingGroup (Fin 3) ≃ (ZMod 3)`.
In other words, we have the exact sequence `V → A₄ → A₃`.
* The outer automorphism group of `A₆` is the Klein four-group `V = (ZMod 2) × (ZMod 2)`,
and is related to the outer automorphism of `S₆`. The extra outer automorphism in `A₆`
swaps the 3-cycles (like `(1 2 3)`) with elements of shape `3²` (like `(1 2 3)(4 5 6)`).
## Tags
non-cyclic abelian group
-/
/-! # Klein four-groups as a mixin class -/
/-- An (additive) Klein four-group is an (additive) group of cardinality four and exponent two. -/
class IsAddKleinFour (G : Type*) [AddGroup G] : Prop where
card_four : Nat.card G = 4
exponent_two : AddMonoid.exponent G = 2
/-- A Klein four-group is a group of cardinality four and exponent two. -/
@[to_additive existing IsAddKleinFour]
class IsKleinFour (G : Type*) [Group G] : Prop where
card_four : Nat.card G = 4
exponent_two : Monoid.exponent G = 2
attribute [simp] IsKleinFour.card_four IsKleinFour.exponent_two
IsAddKleinFour.card_four IsAddKleinFour.exponent_two
instance : IsAddKleinFour (ZMod 2 × ZMod 2) where
card_four := by simp
exponent_two := by simp [AddMonoid.exponent_prod]
instance {G : Type*} [Group G] [IsKleinFour G] : IsAddKleinFour (Additive G) where
card_four := by rw [← IsKleinFour.card_four (G := G)]; congr!
exponent_two := by simp
instance {G : Type*} [AddGroup G] [IsAddKleinFour G] : IsKleinFour (Multiplicative G) where
card_four := by rw [← IsAddKleinFour.card_four (G := G)]; congr!
exponent_two := by simp
namespace IsKleinFour
/-- This instance is scoped, because it always applies (which makes linting and typeclass inference
potentially *a lot* slower). -/
@[to_additive]
scoped instance instFinite {G : Type*} [Group G] [IsKleinFour G] : Finite G :=
Nat.finite_of_card_ne_zero <| by simp [IsKleinFour.card_four]
@[to_additive (attr := simp)]
lemma card_four' {G : Type*} [Group G] [Fintype G] [IsKleinFour G] :
Fintype.card G = 4 :=
Nat.card_eq_fintype_card (α := G).symm ▸ IsKleinFour.card_four
open Finset
variable {G : Type*} [Group G] [IsKleinFour G]
@[to_additive]
lemma not_isCyclic : ¬IsCyclic G :=
fun h ↦ by simpa using h.exponent_eq_card
@[to_additive]
lemma inv_eq_self (x : G) : x⁻¹ = x := inv_eq_self_of_exponent_two (by simp) x
/- this is not an appropriate global `simp` lemma for a `Prop`-mixin class. Indeed, if it were
then every time Lean sees `·⁻¹` it would try to apply `inv_eq_self` which would trigger
type class inference to try and synthesize an `IsKleinFour` instance. -/
scoped[IsKleinFour] attribute [simp] inv_eq_self
scoped[IsAddKleinFour] attribute [simp] neg_eq_self
@[to_additive]
lemma mul_self (x : G) : x * x = 1 := by
rw [mul_eq_one_iff_eq_inv, inv_eq_self]
@[to_additive]
lemma eq_finset_univ [Fintype G] [DecidableEq G]
{x y : G} (hx : x ≠ 1) (hy : y ≠ 1) (hxy : x ≠ y) : {x * y, x, y, (1 : G)} = Finset.univ := by
apply Finset.eq_univ_of_card
rw [card_four']
repeat rw [card_insert_of_notMem]
on_goal 4 => simpa using mul_notMem_of_exponent_two (by simp) hx hy hxy
all_goals simp_all
@[to_additive]
lemma eq_mul_of_ne_all {x y z : G} (hx : x ≠ 1)
(hy : y ≠ 1) (hxy : x ≠ y) (hz : z ≠ 1) (hzx : z ≠ x) (hzy : z ≠ y) : z = x * y := by
classical
let _ := Fintype.ofFinite G
apply eq_of_mem_insert_of_notMem <| (eq_finset_univ hx hy hxy).symm ▸ mem_univ _
simpa only [mem_singleton, mem_insert, not_or] using ⟨hzx, hzy, hz⟩
variable {G₁ G₂ : Type*} [Group G₁] [Group G₂] [IsKleinFour G₁]
/-- An equivalence between an `IsKleinFour` group `G₁` and a group `G₂` of exponent two which sends
`1 : G₁` to `1 : G₂` is in fact an isomorphism. -/
@[to_additive /-- An equivalence between an `IsAddKleinFour` group `G₁` and a group `G₂` of exponent
two which sends `0 : G₁` to `0 : G₂` is in fact an isomorphism. -/]
def mulEquiv' (e : G₁ ≃ G₂) (he : e 1 = 1) (h : Monoid.exponent G₂ = 2) : G₁ ≃* G₂ where
toEquiv := e
map_mul' := by
let _inst₁ := Fintype.ofFinite G₁
let _inst₂ := Fintype.ofEquiv G₁ e
intro x y
by_cases hx : x = 1 <;> by_cases hy : y = 1
all_goals try simp only [hx, hy, mul_one, one_mul, Equiv.toFun_as_coe, he]
by_cases hxy : x = y
· simp [hxy, mul_self, ← pow_two (e y), h ▸ Monoid.pow_exponent_eq_one (e y), he]
· classical
have univ₂ : {e (x * y), e x, e y, (1 : G₂)} = Finset.univ := by
simpa [map_univ_equiv e, map_insert, he]
using congr(Finset.map e.toEmbedding $(eq_finset_univ hx hy hxy))
rw [← Ne, ← e.injective.ne_iff] at hx hy hxy
rw [he] at hx hy
symm
apply eq_of_mem_insert_of_notMem <| univ₂.symm ▸ mem_univ _
simpa using mul_notMem_of_exponent_two h hx hy hxy
/-- Any two `IsKleinFour` groups are isomorphic via any equivalence which sends the identity of one
group to the identity of the other. -/
@[to_additive /-- Any two `IsAddKleinFour` groups are isomorphic via any
equivalence which sends the identity of one group to the identity of the other. -/]
abbrev mulEquiv [IsKleinFour G₂] (e : G₁ ≃ G₂) (he : e 1 = 1) : G₁ ≃* G₂ :=
mulEquiv' e he exponent_two
/-- Any two `IsKleinFour` groups are isomorphic. -/
@[to_additive /-- Any two `IsAddKleinFour` groups are isomorphic. -/]
lemma nonempty_mulEquiv [IsKleinFour G₂] : Nonempty (G₁ ≃* G₂) := by
classical
let _inst₁ := Fintype.ofFinite G₁
let _inst₁ := Fintype.ofFinite G₂
exact ⟨mulEquiv ((Fintype.equivOfCardEq <| by simp).setValue 1 1) <| by simp⟩
end IsKleinFour
|
CanonicalBilinear.lean
|
/-
Copyright (c) 2024 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Ring.SumsOfSquares
import Mathlib.LinearAlgebra.RootSystem.RootPositive
/-!
# The canonical bilinear form on a finite root pairing
Given a finite root pairing, we define a canonical map from weight space to coweight space, and the
corresponding bilinear form. This form is symmetric and Weyl-invariant, and if the base ring is
linearly ordered, then the form is root-positive, positive-semidefinite on the weight space, and
positive-definite on the span of roots.
From these facts, it is easy to show that Coxeter weights in a finite root pairing are bounded
above by 4. Thus, the pairings of roots and coroots in a crystallographic root pairing are
restricted to a small finite set of possibilities.
Another application is to the faithfulness of the Weyl group action on roots, and finiteness of the
Weyl group.
## Main definitions:
* `RootPairing.Polarization`: A distinguished linear map from the weight space to the coweight
space.
* `RootPairing.RootForm` : The bilinear form on weight space corresponding to `Polarization`.
## Main results:
* `RootPairing.rootForm_self_sum_of_squares` : The inner product of any
weight vector is a sum of squares.
* `RootPairing.rootForm_reflection_reflection_apply` : `RootForm` is invariant with respect
to reflections.
* `RootPairing.rootForm_self_smul_coroot`: The inner product of a root with itself
times the corresponding coroot is equal to two times Polarization applied to the root.
* `RootPairing.exists_ge_zero_eq_rootForm`: `RootForm` is positive semidefinite.
## References:
* [N. Bourbaki, *Lie groups and Lie algebras. Chapters 4--6*][bourbaki1968]
* [M. Demazure, *SGA III, Exposé XXI, Données Radicielles*][demazure1970]
-/
open Set Function
open Module hiding reflection
open Submodule (span)
noncomputable section
variable {ι R M N : Type*}
namespace RootPairing
variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
(P : RootPairing ι R M N)
section Fintype
variable [Fintype ι]
/-- An invariant linear map from weight space to coweight space. -/
def Polarization : M →ₗ[R] N :=
∑ i, LinearMap.toSpanSingleton R N (P.coroot i) ∘ₗ P.coroot' i
@[simp]
lemma Polarization_apply (x : M) :
P.Polarization x = ∑ i, P.coroot' i x • P.coroot i := by
simp [Polarization]
/-- An invariant linear map from coweight space to weight space. -/
def CoPolarization : N →ₗ[R] M :=
P.flip.Polarization
@[simp]
lemma CoPolarization_apply (x : N) :
P.CoPolarization x = ∑ i, P.root' i x • P.root i :=
P.flip.Polarization_apply x
lemma CoPolarization_eq : P.CoPolarization = P.flip.Polarization :=
rfl
/-- An invariant inner product on the weight space. -/
def RootForm : LinearMap.BilinForm R M :=
∑ i, (P.coroot' i).smulRight (P.coroot' i)
/-- An invariant inner product on the coweight space. -/
def CorootForm : LinearMap.BilinForm R N :=
P.flip.RootForm
lemma rootForm_apply_apply (x y : M) : P.RootForm x y =
∑ i, P.coroot' i x * P.coroot' i y := by
simp [RootForm]
lemma corootForm_apply_apply (x y : N) : P.CorootForm x y =
∑ i, P.root' i x * P.root' i y :=
P.flip.rootForm_apply_apply x y
lemma toPerfectPairing_apply_apply_Polarization (x y : M) :
P.toPerfectPairing y (P.Polarization x) = P.RootForm x y := by
simp [RootForm]
lemma toPerfectPairing_apply_CoPolarization (x : N) :
P.toPerfectPairing (P.CoPolarization x) = P.CorootForm x := by
ext y
exact P.flip.toPerfectPairing_apply_apply_Polarization x y
lemma flip_comp_polarization_eq_rootForm :
P.flip.toLinearMap ∘ₗ P.Polarization = P.RootForm := by
ext; simp [rootForm_apply_apply, RootPairing.flip]
lemma self_comp_coPolarization_eq_corootForm :
P.toLinearMap ∘ₗ P.CoPolarization = P.CorootForm :=
P.flip.flip_comp_polarization_eq_rootForm
lemma polarization_apply_eq_zero_iff (m : M) :
P.Polarization m = 0 ↔ P.RootForm m = 0 := by
rw [← flip_comp_polarization_eq_rootForm]
refine ⟨fun h ↦ by simp [h], fun h ↦ ?_⟩
change P.toDualRight (P.Polarization m) = 0 at h
simp only [EmbeddingLike.map_eq_zero_iff] at h
exact h
lemma coPolarization_apply_eq_zero_iff (n : N) :
P.CoPolarization n = 0 ↔ P.CorootForm n = 0 :=
P.flip.polarization_apply_eq_zero_iff n
lemma ker_polarization_eq_ker_rootForm :
LinearMap.ker P.Polarization = LinearMap.ker P.RootForm := by
ext; simp only [LinearMap.mem_ker, P.polarization_apply_eq_zero_iff]
lemma ker_copolarization_eq_ker_corootForm :
LinearMap.ker P.CoPolarization = LinearMap.ker P.CorootForm :=
P.flip.ker_polarization_eq_ker_rootForm
lemma rootForm_symmetric :
LinearMap.IsSymm P.RootForm := by
simp [LinearMap.isSymm_def, mul_comm, rootForm_apply_apply]
@[simp]
lemma rootForm_reflection_reflection_apply (i : ι) (x y : M) :
P.RootForm (P.reflection i x) (P.reflection i y) = P.RootForm x y := by
simp only [rootForm_apply_apply, coroot'_reflection]
exact Fintype.sum_equiv (P.reflectionPerm i)
(fun j ↦ (P.coroot' (P.reflectionPerm i j) x) * (P.coroot' (P.reflectionPerm i j) y))
(fun j ↦ P.coroot' j x * P.coroot' j y) (congrFun rfl)
lemma rootForm_self_sum_of_squares (x : M) :
IsSumSq (P.RootForm x x) :=
P.rootForm_apply_apply x x ▸ IsSumSq.sum_mul_self Finset.univ _
lemma rootForm_root_self (j : ι) :
P.RootForm (P.root j) (P.root j) = ∑ (i : ι), (P.pairing j i) * (P.pairing j i) := by
simp [rootForm_apply_apply]
theorem range_polarization_domRestrict_le_span_coroot :
LinearMap.range (P.Polarization.domRestrict (P.rootSpan R)) ≤ P.corootSpan R := by
intro y hy
obtain ⟨x, hx⟩ := hy
rw [← hx, LinearMap.domRestrict_apply, Polarization_apply]
refine (Submodule.mem_span_range_iff_exists_fun R).mpr ?_
use fun i => (P.toPerfectPairing x) (P.coroot i)
simp
theorem corootSpan_dualAnnihilator_le_ker_rootForm :
(P.corootSpan R).dualAnnihilator.map P.toDualLeft.symm ≤ LinearMap.ker P.RootForm := by
rw [P.corootSpan_dualAnnihilator_map_eq_iInf_ker_coroot']
intro x hx
ext y
simp only [coroot', Submodule.mem_iInf, LinearMap.mem_ker, PerfectPairing.flip_apply_apply] at hx
simp [rootForm_apply_apply, hx]
theorem rootSpan_dualAnnihilator_le_ker_rootForm :
(P.rootSpan R).dualAnnihilator.map P.toDualRight.symm ≤ LinearMap.ker P.CorootForm :=
P.flip.corootSpan_dualAnnihilator_le_ker_rootForm
end Fintype
section IsValuedIn
variable (S : Type*) [CommRing S] [Algebra S R] [FaithfulSMul S R] [Module S M]
[IsScalarTower S R M] [Module S N] [IsScalarTower S R N] [P.IsValuedIn S] [Fintype ι] {i j : ι}
/-- Polarization restricted to `S`-span of roots. -/
def PolarizationIn : P.rootSpan S →ₗ[S] N :=
∑ i : ι, LinearMap.toSpanSingleton S N (P.coroot i) ∘ₗ P.coroot'In S i
omit [IsScalarTower S R N] in
lemma PolarizationIn_apply (x : P.rootSpan S) :
P.PolarizationIn S x = ∑ i, P.coroot'In S i x • P.coroot i := by
simp [PolarizationIn]
lemma PolarizationIn_eq (x : P.rootSpan S) :
P.PolarizationIn S x = P.Polarization x := by
simp only [PolarizationIn, LinearMap.coeFn_sum, LinearMap.coe_comp, Finset.sum_apply, comp_apply,
LinearMap.toSpanSingleton_apply, Polarization_apply, PerfectPairing.flip_apply_apply]
refine Finset.sum_congr rfl fun i hi ↦ ?_
rw [algebra_compatible_smul R (P.coroot'In S i x) (P.coroot i), algebraMap_coroot'In_apply,
PerfectPairing.flip_apply_apply]
lemma range_polarizationIn :
Submodule.map P.Polarization (P.rootSpan R) = LinearMap.range (P.PolarizationIn R) := by
ext x
simp [PolarizationIn_eq]
/-- Polarization restricted to `S`-span of roots. -/
def CoPolarizationIn : P.corootSpan S →ₗ[S] M :=
P.flip.PolarizationIn S
omit [IsScalarTower S R M] in
lemma CoPolarizationIn_apply (x : P.corootSpan S) :
P.CoPolarizationIn S x = ∑ i, P.root'In S i x • P.root i :=
P.flip.PolarizationIn_apply S x
lemma CoPolarizationIn_eq (x : P.corootSpan S) :
P.CoPolarizationIn S x = P.CoPolarization x :=
P.flip.PolarizationIn_eq S x
/-- A canonical bilinear form on the span of roots in a finite root pairing, taking values in a
commutative ring, where the root-coroot pairing takes values in that ring. -/
def RootFormIn : LinearMap.BilinForm S (P.rootSpan S) :=
∑ i, (P.coroot'In S i).smulRight (P.coroot'In S i)
omit [Module S N] [IsScalarTower S R N] in
@[simp]
lemma algebraMap_rootFormIn (x y : P.rootSpan S) :
(algebraMap S R) (P.RootFormIn S x y) = P.RootForm x y := by
simp [RootFormIn, rootForm_apply_apply]
lemma toPerfectPairing_apply_PolarizationIn (x y : P.rootSpan S) :
P.toPerfectPairing y (P.PolarizationIn S x) =
(algebraMap S R) (P.RootFormIn S x y) := by
rw [PolarizationIn_eq, algebraMap_rootFormIn]
exact toPerfectPairing_apply_apply_Polarization P x y
omit [IsScalarTower S R N] in
lemma range_polarizationIn_le_span_coroot :
LinearMap.range (P.PolarizationIn S) ≤ P.corootSpan S := by
intro x hx
obtain ⟨y, hy⟩ := hx
rw [PolarizationIn_apply] at hy
exact (Submodule.mem_span_range_iff_exists_fun S).mpr
(Exists.intro (fun i ↦ (P.coroot'In S i) y) hy)
/-- A version of SGA3 XXI Lemma 1.2.1 (10), adapted to change of rings. -/
lemma rootFormIn_self_smul_coroot (i : ι) :
P.RootFormIn S (P.rootSpanMem S i) (P.rootSpanMem S i) • P.coroot i =
2 • P.PolarizationIn S (P.rootSpanMem S i) := by
have hP : P.PolarizationIn S (P.rootSpanMem S i) =
∑ j : ι, P.pairingIn S i (P.reflectionPerm i j) • P.coroot (P.reflectionPerm i j) := by
simp_rw [PolarizationIn_apply, coroot'In_rootSpanMem_eq_pairingIn]
exact (Fintype.sum_equiv (P.reflectionPerm i)
(fun j ↦ P.pairingIn S i (P.reflectionPerm i j) • P.coroot (P.reflectionPerm i j))
(fun j ↦ P.pairingIn S i j • P.coroot j) (congrFun rfl)).symm
rw [two_nsmul]
nth_rw 2 [hP]
rw [PolarizationIn_apply]
simp only [coroot'In_rootSpanMem_eq_pairingIn, pairingIn_reflectionPerm,
pairingIn_reflectionPerm_self_left, ← reflectionPerm_coroot, neg_smul,
smul_sub, sub_neg_eq_add]
rw [Finset.sum_add_distrib, ← add_assoc, ← sub_eq_iff_eq_add, RootFormIn]
simp only [LinearMap.coeFn_sum, LinearMap.coe_smulRight, Finset.sum_apply,
coroot'In_rootSpanMem_eq_pairingIn, LinearMap.smul_apply, smul_eq_mul, Finset.sum_smul,
root_coroot_eq_pairing, Finset.sum_neg_distrib, add_neg_cancel, sub_eq_zero]
refine Finset.sum_congr rfl ?_
intro j hj
rw [← P.algebraMap_pairingIn S, IsScalarTower.algebraMap_smul, ← mul_smul]
lemma prod_rootFormIn_smul_coroot_mem_range_PolarizationIn (i : ι) :
(∏ j : ι, P.RootFormIn S (P.rootSpanMem S j) (P.rootSpanMem S j)) • P.coroot i ∈
LinearMap.range (P.PolarizationIn S) := by
obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem
(fun j ↦ P.RootFormIn S (P.rootSpanMem S j) (P.rootSpanMem S j))
(Finset.mem_univ i)
rw [hc, mul_comm, mul_smul, rootFormIn_self_smul_coroot]
refine LinearMap.mem_range.mpr ?_
use c • 2 • (P.rootSpanMem S i)
rw [map_smul, two_smul, two_smul, map_add]
end IsValuedIn
section MoreFintype
variable [Fintype ι]
/-- A version of SGA3 XXI Lemma 1.2.1 (10). -/
lemma rootForm_self_smul_coroot (i : ι) :
(P.RootForm (P.root i) (P.root i)) • P.coroot i = 2 • P.Polarization (P.root i) := by
have : (algebraMap R R) ((P.RootFormIn R) (P.rootSpanMem R i) (P.rootSpanMem R i)) • P.coroot i =
2 • P.Polarization (P.root i) := by
rw [Algebra.algebraMap_self_apply, P.rootFormIn_self_smul_coroot R i, PolarizationIn_eq]
rw [← this, algebraMap_rootFormIn]
lemma corootForm_self_smul_root (i : ι) :
(P.CorootForm (P.coroot i) (P.coroot i)) • P.root i = 2 • P.CoPolarization (P.coroot i) :=
rootForm_self_smul_coroot (P.flip) i
lemma four_nsmul_coPolarization_compl_polarization_apply_root (i : ι) :
(4 • P.CoPolarization ∘ₗ P.Polarization) (P.root i) =
(P.RootForm (P.root i) (P.root i) * P.CorootForm (P.coroot i) (P.coroot i)) • P.root i := by
rw [LinearMap.smul_apply, LinearMap.comp_apply, show 4 = 2 * 2 from rfl, mul_smul, ← map_nsmul,
← rootForm_self_smul_coroot, map_smul, smul_comm, ← corootForm_self_smul_root, smul_smul]
lemma four_smul_rootForm_sq_eq_coxeterWeight_smul (i j : ι) :
4 • (P.RootForm (P.root i) (P.root j)) ^ 2 = P.coxeterWeight i j •
(P.RootForm (P.root i) (P.root i) * P.RootForm (P.root j) (P.root j)) := by
have hij : 4 • (P.RootForm (P.root i)) (P.root j) =
2 • P.toPerfectPairing (P.root j) (2 • P.Polarization (P.root i)) := by
rw [← toPerfectPairing_apply_apply_Polarization, LinearMap.map_smul_of_tower, ← smul_assoc,
Nat.nsmul_eq_mul]
have hji : 2 • (P.RootForm (P.root i)) (P.root j) =
P.toPerfectPairing (P.root i) (2 • P.Polarization (P.root j)) := by
rw [show (P.RootForm (P.root i)) (P.root j) = (P.RootForm (P.root j)) (P.root i) by
apply (rootForm_symmetric P).eq, ← toPerfectPairing_apply_apply_Polarization,
LinearMap.map_smul_of_tower]
rw [sq, nsmul_eq_mul, ← mul_assoc, ← nsmul_eq_mul, hij, ← rootForm_self_smul_coroot,
smul_mul_assoc 2, ← mul_smul_comm, hji, ← rootForm_self_smul_coroot, map_smul, ← pairing,
map_smul, ← pairing, smul_eq_mul, smul_eq_mul, smul_eq_mul, coxeterWeight]
ring
lemma prod_rootForm_smul_coroot_mem_range_domRestrict (i : ι) :
(∏ a : ι, P.RootForm (P.root a) (P.root a)) • P.coroot i ∈
LinearMap.range (P.Polarization.domRestrict (P.rootSpan R)) := by
obtain ⟨c, hc⟩ := Finset.dvd_prod_of_mem (fun a ↦ P.RootForm (P.root a) (P.root a))
(Finset.mem_univ i)
rw [hc, mul_comm, mul_smul, rootForm_self_smul_coroot]
refine LinearMap.mem_range.mpr ?_
use ⟨c • 2 • P.root i, by aesop⟩
simp
end MoreFintype
section IsValuedInOrdered
variable (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S]
[Algebra S R] [FaithfulSMul S R] [Module S M]
[IsScalarTower S R M] [P.IsValuedIn S] [Fintype ι] {i j : ι}
/-- The bilinear form of a finite root pairing taking values in a linearly-ordered ring, as a
root-positive form. -/
def posRootForm : P.RootPositiveForm S where
form := P.RootForm
symm := P.rootForm_symmetric
isOrthogonal_reflection := P.rootForm_reflection_reflection_apply
exists_eq i j := ⟨∑ k, P.pairingIn S i k * P.pairingIn S j k, by simp [rootForm_apply_apply]⟩
exists_pos_eq i := by
refine ⟨∑ k, P.pairingIn S i k ^ 2, ?_, by simp [sq, rootForm_apply_apply]⟩
exact Finset.sum_pos' (fun j _ ↦ sq_nonneg _) ⟨i, by simp⟩
lemma algebraMap_posRootForm_posForm (x y : span S (range P.root)) :
(algebraMap S R) ((P.posRootForm S).posForm x y) = P.RootForm x y := by
rw [RootPositiveForm.algebraMap_posForm]
simp [posRootForm]
@[simp]
lemma posRootForm_eq :
(P.posRootForm S).posForm = P.RootFormIn S := by
ext
apply FaithfulSMul.algebraMap_injective S R
simp only [algebraMap_posRootForm_posForm, algebraMap_rootFormIn]
theorem exists_ge_zero_eq_rootForm (x : M) (hx : x ∈ span S (range P.root)) :
∃ s ≥ 0, algebraMap S R s = P.RootForm x x := by
refine ⟨(P.posRootForm S).posForm ⟨x, hx⟩ ⟨x, hx⟩, IsSumSq.nonneg ?_, by simp [posRootForm]⟩
choose s hs using P.coroot'_apply_apply_mem_of_mem_span S hx
suffices (P.posRootForm S).posForm ⟨x, hx⟩ ⟨x, hx⟩ = ∑ i, s i * s i from
this ▸ IsSumSq.sum_mul_self Finset.univ s
apply FaithfulSMul.algebraMap_injective S R
simp only [posRootForm, RootPositiveForm.algebraMap_posForm, map_sum, map_mul]
simp [hs, rootForm_apply_apply]
lemma posRootForm_posForm_apply_apply (x y : P.rootSpan S) : (P.posRootForm S).posForm x y =
∑ i, P.coroot'In S i x * P.coroot'In S i y := by
refine (FaithfulSMul.algebraMap_injective S R) ?_
simp [posRootForm, rootForm_apply_apply]
lemma zero_le_posForm (x : span S (range P.root)) :
0 ≤ (P.posRootForm S).posForm x x := by
obtain ⟨s, _, hs⟩ := P.exists_ge_zero_eq_rootForm S x.1 x.2
have : s = (P.posRootForm S).posForm x x :=
FaithfulSMul.algebraMap_injective S R <| (P.algebraMap_posRootForm_posForm S x x) ▸ hs
rwa [← this]
omit [Fintype ι]
variable [Finite ι]
lemma zero_lt_pairingIn_iff' :
0 < P.pairingIn S i j ↔ 0 < P.pairingIn S j i :=
let _i : Fintype ι := Fintype.ofFinite ι
zero_lt_pairingIn_iff (P.posRootForm S) i j
lemma pairingIn_lt_zero_iff :
P.pairingIn S i j < 0 ↔ P.pairingIn S j i < 0 := by
simpa using P.zero_lt_pairingIn_iff' S (i := i) (j := P.reflectionPerm j j)
lemma pairingIn_le_zero_iff [NeZero (2 : R)] [NoZeroSMulDivisors R M] :
P.pairingIn S i j ≤ 0 ↔ P.pairingIn S j i ≤ 0 := by
rcases eq_or_ne (P.pairingIn S i j) 0 with hij | hij <;>
rcases eq_or_ne (P.pairingIn S j i) 0 with hji | hji
· rw [hij, hji]
· rw [hij, P.pairingIn_eq_zero_iff.mp hij]
· rw [hji, P.pairingIn_eq_zero_iff.mp hji]
· rw [le_iff_eq_or_lt, le_iff_eq_or_lt, or_iff_right hij, or_iff_right hji]
exact P.pairingIn_lt_zero_iff S
end IsValuedInOrdered
end RootPairing
|
SetLike.lean
|
/-
Copyright (c) 2024 Sven Manthe. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sven Manthe
-/
import Mathlib.Order.CompleteSublattice
/-!
# `SetLike` instance for elements of `CompleteSublattice (Set X)`
This file provides lemmas for the `SetLike` instance for elements of `CompleteSublattice (Set X)`
-/
attribute [local instance] SetLike.instSubtypeSet
namespace Sublattice
variable {X : Type*} {L : Sublattice (Set X)}
variable {S T : L} {x : X}
@[ext] lemma ext_mem (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h
lemma mem_subtype : x ∈ L.subtype T ↔ x ∈ T := Iff.rfl
@[simp] lemma setLike_mem_inf : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := by simp [← mem_subtype]
@[simp] lemma setLike_mem_sup : x ∈ S ⊔ T ↔ x ∈ S ∨ x ∈ T := by simp [← mem_subtype]
@[simp] lemma setLike_mem_coe : x ∈ T.val ↔ x ∈ T := Iff.rfl
end Sublattice
namespace CompleteSublattice
variable {X : Type*} {L : CompleteSublattice (Set X)}
variable {S T : L} {𝒮 : Set L} {I : Sort*} {f : I → L} {x : X}
@[ext] lemma ext (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h
lemma mem_subtype : x ∈ L.subtype T ↔ x ∈ T := Iff.rfl
@[simp] lemma mem_inf : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := by simp [← mem_subtype]
@[simp] lemma mem_sInf : x ∈ sInf 𝒮 ↔ ∀ T ∈ 𝒮, x ∈ T := by simp [← mem_subtype]
@[simp] lemma mem_iInf : x ∈ ⨅ i : I, f i ↔ ∀ i : I, x ∈ f i := by simp [← mem_subtype]
@[simp] lemma mem_top : x ∈ (⊤ : L) := by simp [← mem_subtype]
@[simp] lemma mem_sup : x ∈ S ⊔ T ↔ x ∈ S ∨ x ∈ T := by simp [← mem_subtype]
@[simp] lemma mem_sSup : x ∈ sSup 𝒮 ↔ ∃ T ∈ 𝒮, x ∈ T := by simp [← mem_subtype]
@[simp] lemma mem_iSup : x ∈ ⨆ i : I, f i ↔ ∃ i : I, x ∈ f i := by simp [← mem_subtype]
@[simp] lemma notMem_bot : x ∉ (⊥ : L) := by simp [← mem_subtype]
@[deprecated (since := "2025-05-23")] alias not_mem_bot := notMem_bot
end CompleteSublattice
|
Inverse.lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.Group.Units.Basic
import Mathlib.RingTheory.MvPowerSeries.Basic
import Mathlib.RingTheory.MvPowerSeries.NoZeroDivisors
import Mathlib.RingTheory.LocalRing.Basic
/-!
# Formal (multivariate) power series - Inverses
This file defines multivariate formal power series and develops the basic
properties of these objects, when it comes about multiplicative inverses.
For `φ : MvPowerSeries σ R` and `u : Rˣ` is the constant coefficient of `φ`,
`MvPowerSeries.invOfUnit φ u` is a formal power series such,
and `MvPowerSeries.mul_invOfUnit` proves that `φ * invOfUnit φ u = 1`.
The construction of the power series `invOfUnit` is done by writing that
relation and solving and for its coefficients by induction.
Over a field, all power series `φ` have an “inverse” `MvPowerSeries.inv φ`,
which is `0` if and only if the constant coefficient of `φ` is zero
(by `MvPowerSeries.inv_eq_zero`),
and `MvPowerSeries.mul_inv_cancel` asserts the equality `φ * φ⁻¹ = 1` when
the constant coefficient of `φ` is nonzero.
Instances are defined:
* Formal power series over a local ring form a local ring.
* The morphism `MvPowerSeries.map σ f : MvPowerSeries σ A →* MvPowerSeries σ B`
induced by a local morphism `f : A →+* B` (`IsLocalHom f`)
of commutative rings is a *local* morphism.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
namespace MvPowerSeries
open Finsupp
variable {σ R : Type*}
section Ring
variable [Ring R]
/-
The inverse of a multivariate formal power series is defined by
well-founded recursion on the coefficients of the inverse.
-/
/-- Auxiliary definition that unifies
the totalised inverse formal power series `(_)⁻¹` and
the inverse formal power series that depends on
an inverse of the constant coefficient `invOfUnit`. -/
protected noncomputable def inv.aux (a : R) (φ : MvPowerSeries σ R) : MvPowerSeries σ R
| n =>
letI := Classical.decEq σ
if n = 0 then a
else
-a *
∑ x ∈ antidiagonal n, if _ : x.2 < n then coeff R x.1 φ * inv.aux a φ x.2 else 0
termination_by n => n
theorem coeff_inv_aux [DecidableEq σ] (n : σ →₀ ℕ) (a : R) (φ : MvPowerSeries σ R) :
coeff R n (inv.aux a φ) =
if n = 0 then a
else
-a *
∑ x ∈ antidiagonal n, if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv.aux a φ) else 0 :=
show inv.aux a φ n = _ by
cases Subsingleton.elim ‹DecidableEq σ› (Classical.decEq σ)
rw [inv.aux]
rfl
/-- A multivariate formal power series is invertible if the constant coefficient is invertible. -/
def invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) : MvPowerSeries σ R :=
inv.aux (↑u⁻¹) φ
theorem coeff_invOfUnit [DecidableEq σ] (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (u : Rˣ) :
coeff R n (invOfUnit φ u) =
if n = 0 then ↑u⁻¹
else
-↑u⁻¹ *
∑ x ∈ antidiagonal n,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (invOfUnit φ u) else 0 := by
convert coeff_inv_aux n (↑u⁻¹) φ
@[simp]
theorem constantCoeff_invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) :
constantCoeff σ R (invOfUnit φ u) = ↑u⁻¹ := by
classical
rw [← coeff_zero_eq_constantCoeff_apply, coeff_invOfUnit, if_pos rfl]
@[simp]
theorem mul_invOfUnit (φ : MvPowerSeries σ R) (u : Rˣ) (h : constantCoeff σ R φ = u) :
φ * invOfUnit φ u = 1 :=
ext fun n =>
letI := Classical.decEq (σ →₀ ℕ)
if H : n = 0 then by
rw [H]
simp [h]
else by
classical
have : ((0 : σ →₀ ℕ), n) ∈ antidiagonal n := by rw [mem_antidiagonal, zero_add]
rw [coeff_one, if_neg H, coeff_mul, ← Finset.insert_erase this,
Finset.sum_insert (Finset.notMem_erase _ _), coeff_zero_eq_constantCoeff_apply, h,
coeff_invOfUnit, if_neg H, neg_mul, mul_neg, Units.mul_inv_cancel_left, ←
Finset.insert_erase this, Finset.sum_insert (Finset.notMem_erase _ _),
Finset.insert_erase this, if_neg (not_lt_of_ge <| le_rfl), zero_add, add_comm, ←
sub_eq_add_neg, sub_eq_zero, Finset.sum_congr rfl]
rintro ⟨i, j⟩ hij
rw [Finset.mem_erase, mem_antidiagonal] at hij
obtain ⟨h₁, h₂⟩ := hij
subst n
rw [if_pos]
suffices 0 + j < i + j by simpa
apply add_lt_add_right
constructor
· intro s
exact Nat.zero_le _
· intro H
apply h₁
suffices i = 0 by simp [this]
ext1 s
exact Nat.eq_zero_of_le_zero (H s)
-- TODO : can one prove equivalence?
@[simp]
theorem invOfUnit_mul (φ : MvPowerSeries σ R) (u : Rˣ) (h : constantCoeff σ R φ = u) :
invOfUnit φ u * φ = 1 := by
rw [← mul_cancel_right_mem_nonZeroDivisors (r := φ.invOfUnit u), mul_assoc, one_mul,
mul_invOfUnit _ _ h, mul_one]
apply mem_nonZeroDivisors_of_constantCoeff
simp only [constantCoeff_invOfUnit, IsUnit.mem_nonZeroDivisors (Units.isUnit u⁻¹)]
theorem isUnit_iff_constantCoeff {φ : MvPowerSeries σ R} :
IsUnit φ ↔ IsUnit (constantCoeff σ R φ) := by
constructor
· exact IsUnit.map _
· intro ⟨u, hu⟩
exact ⟨⟨_, φ.invOfUnit u, mul_invOfUnit φ u hu.symm, invOfUnit_mul φ u hu.symm⟩, rfl⟩
end Ring
section CommRing
variable [CommRing R]
/-- Multivariate formal power series over a local ring form a local ring. -/
instance [IsLocalRing R] : IsLocalRing (MvPowerSeries σ R) :=
IsLocalRing.of_isUnit_or_isUnit_one_sub_self <| by
intro φ
obtain ⟨u, h⟩ | ⟨u, h⟩ := IsLocalRing.isUnit_or_isUnit_one_sub_self (constantCoeff σ R φ) <;>
[left; right] <;>
· refine isUnit_of_mul_eq_one _ _ (mul_invOfUnit _ u ?_)
simpa using h.symm
-- TODO(jmc): once adic topology lands, show that this is complete
end CommRing
section IsLocalRing
variable {S : Type*} [CommRing R] [CommRing S] (f : R →+* S) [IsLocalHom f]
-- Thanks to the linter for informing us that this instance does
-- not actually need R and S to be local rings!
/-- The map between multivariate formal power series over the same indexing set
induced by a local ring hom `A → B` is local -/
@[instance]
theorem map.isLocalHom : IsLocalHom (map σ f) :=
⟨by
rintro φ ⟨ψ, h⟩
replace h := congr_arg (constantCoeff σ S) h
rw [constantCoeff_map] at h
have : IsUnit (constantCoeff σ S ↑ψ) := isUnit_constantCoeff _ ψ.isUnit
rw [h] at this
rcases isUnit_of_map_unit f _ this with ⟨c, hc⟩
exact isUnit_of_mul_eq_one φ (invOfUnit φ c) (mul_invOfUnit φ c hc.symm)⟩
end IsLocalRing
section Field
open MvPowerSeries
variable {k : Type*} [Field k]
/-- The inverse `1/f` of a multivariable power series `f` over a field -/
protected def inv (φ : MvPowerSeries σ k) : MvPowerSeries σ k :=
inv.aux (constantCoeff σ k φ)⁻¹ φ
instance : Inv (MvPowerSeries σ k) :=
⟨MvPowerSeries.inv⟩
theorem coeff_inv [DecidableEq σ] (n : σ →₀ ℕ) (φ : MvPowerSeries σ k) :
coeff k n φ⁻¹ =
if n = 0 then (constantCoeff σ k φ)⁻¹
else
-(constantCoeff σ k φ)⁻¹ *
∑ x ∈ antidiagonal n, if x.2 < n then coeff k x.1 φ * coeff k x.2 φ⁻¹ else 0 :=
coeff_inv_aux n _ φ
@[simp]
theorem constantCoeff_inv (φ : MvPowerSeries σ k) :
constantCoeff σ k φ⁻¹ = (constantCoeff σ k φ)⁻¹ := by
classical
rw [← coeff_zero_eq_constantCoeff_apply, coeff_inv, if_pos rfl]
theorem inv_eq_zero {φ : MvPowerSeries σ k} : φ⁻¹ = 0 ↔ constantCoeff σ k φ = 0 :=
⟨fun h => by simpa using congr_arg (constantCoeff σ k) h, fun h =>
ext fun n => by
classical
rw [coeff_inv]
split_ifs <;>
simp only [h, map_zero, zero_mul, inv_zero, neg_zero]⟩
@[simp]
theorem zero_inv : (0 : MvPowerSeries σ k)⁻¹ = 0 := by
rw [inv_eq_zero, constantCoeff_zero]
@[simp]
theorem invOfUnit_eq (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) :
invOfUnit φ (Units.mk0 _ h) = φ⁻¹ :=
rfl
@[simp]
theorem invOfUnit_eq' (φ : MvPowerSeries σ k) (u : Units k) (h : constantCoeff σ k φ = u) :
invOfUnit φ u = φ⁻¹ := by
rw [← invOfUnit_eq φ (h.symm ▸ u.ne_zero)]
apply congrArg (invOfUnit φ)
rw [Units.ext_iff]
exact h.symm
@[simp]
protected theorem mul_inv_cancel (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) :
φ * φ⁻¹ = 1 := by rw [← invOfUnit_eq φ h, mul_invOfUnit φ (Units.mk0 _ h) rfl]
@[simp]
protected theorem inv_mul_cancel (φ : MvPowerSeries σ k) (h : constantCoeff σ k φ ≠ 0) :
φ⁻¹ * φ = 1 := by rw [mul_comm, φ.mul_inv_cancel h]
protected theorem eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : MvPowerSeries σ k}
(h : constantCoeff σ k φ₃ ≠ 0) : φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ :=
⟨fun k => by simp [k, mul_assoc, MvPowerSeries.inv_mul_cancel _ h], fun k => by
simp [← k, mul_assoc, MvPowerSeries.mul_inv_cancel _ h]⟩
protected theorem eq_inv_iff_mul_eq_one {φ ψ : MvPowerSeries σ k} (h : constantCoeff σ k ψ ≠ 0) :
φ = ψ⁻¹ ↔ φ * ψ = 1 := by rw [← MvPowerSeries.eq_mul_inv_iff_mul_eq h, one_mul]
protected theorem inv_eq_iff_mul_eq_one {φ ψ : MvPowerSeries σ k} (h : constantCoeff σ k ψ ≠ 0) :
ψ⁻¹ = φ ↔ φ * ψ = 1 := by rw [eq_comm, MvPowerSeries.eq_inv_iff_mul_eq_one h]
@[simp]
protected theorem mul_inv_rev (φ ψ : MvPowerSeries σ k) :
(φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ := by
by_cases h : constantCoeff σ k (φ * ψ) = 0
· rw [inv_eq_zero.mpr h]
simp only [map_mul, mul_eq_zero] at h
-- we don't have `NoZeroDivisors (MvPowerSeries σ k)` yet,
rcases h with h | h <;> simp [inv_eq_zero.mpr h]
· rw [MvPowerSeries.inv_eq_iff_mul_eq_one h]
simp only [not_or, map_mul, mul_eq_zero] at h
rw [← mul_assoc, mul_assoc _⁻¹, MvPowerSeries.inv_mul_cancel _ h.left, mul_one,
MvPowerSeries.inv_mul_cancel _ h.right]
instance : InvOneClass (MvPowerSeries σ k) :=
{ inferInstanceAs (One (MvPowerSeries σ k)),
inferInstanceAs (Inv (MvPowerSeries σ k)) with
inv_one := by
rw [MvPowerSeries.inv_eq_iff_mul_eq_one, mul_one]
simp }
@[simp]
theorem C_inv (r : k) : (C σ k r)⁻¹ = C σ k r⁻¹ := by
rcases eq_or_ne r 0 with (rfl | hr)
· simp
rw [MvPowerSeries.inv_eq_iff_mul_eq_one, ← map_mul, inv_mul_cancel₀ hr, map_one]
simpa using hr
@[simp]
theorem X_inv (s : σ) : (X s : MvPowerSeries σ k)⁻¹ = 0 := by
rw [inv_eq_zero, constantCoeff_X]
@[simp]
theorem smul_inv (r : k) (φ : MvPowerSeries σ k) : (r • φ)⁻¹ = r⁻¹ • φ⁻¹ := by
simp [smul_eq_C_mul, mul_comm]
end Field
end MvPowerSeries
end
|
check-yaml.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 Lean.Util.SearchPath
import Mathlib.Lean.CoreM
import Mathlib.Tactic.ToExpr
/-! # Script to check `undergrad.yaml`, `overview.yaml`, `100.yaml` and `1000.yaml`
This assumes `yaml_check.py` has first translated these to `json` files.
It verifies that the referenced declarations exist, and prints an error otherwise.
-/
open IO.FS Lean Lean.Elab
open Lean Core Elab Command
abbrev DBFile := Array (String × Name)
def readJsonFile (α) [FromJson α] (path : System.FilePath) : IO α := do
let _ : MonadExceptOf String IO := ⟨throw ∘ IO.userError, fun x _ => x⟩
liftExcept <| fromJson? <|← liftExcept <| Json.parse <|← IO.FS.readFile path
def databases : List String :=
["undergrad", "overview", "100", "1000"]
def processDb (decls : ConstMap) : String → IO Bool
| file => do
let lines ← readJsonFile DBFile s!"{file}.json"
let missing := lines.filter (fun l ↦ !(decls.contains l.2))
if 0 < missing.size then
IO.println s!"Entries in `docs/{file}.yaml` refer to {missing.size} declaration(s) that don't exist. \
Please correct the following:"
for p in missing do
IO.println s!" {p.1}: {p.2}"
IO.println ""
return true
else
return false
unsafe def main : IO Unit := do
let searchPath ← addSearchPathFromEnv (← getBuiltinSearchPath (← findSysroot))
CoreM.withImportModules #[`Mathlib, `Archive]
(searchPath := searchPath) (trustLevel := 1024) do
let decls := (← getEnv).constants
let results ← databases.mapM (fun p ↦ processDb decls p)
if results.any id then
IO.Process.exit 1
|
Pi.lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Multiset.Bind
/-!
# The cartesian product of multisets
## Main definitions
* `Multiset.pi`: Cartesian product of multisets indexed by a multiset.
-/
namespace Multiset
section Pi
open Function
namespace Pi
variable {α : Type*} [DecidableEq α] {δ : α → Sort*}
/-- Given `δ : α → Sort*`, `Pi.empty δ` is the trivial dependent function out of the empty
multiset. -/
def empty (δ : α → Sort*) : ∀ a ∈ (0 : Multiset α), δ a :=
nofun
variable (m : Multiset α) (a : α)
/-- Given `δ : α → Sort*`, a multiset `m` and a term `a`, as well as a term `b : δ a` and a
function `f` such that `f a' : δ a'` for all `a'` in `m`, `Pi.cons m a b f` is a function `g` such
that `g a'' : δ a''` for all `a''` in `a ::ₘ m`. -/
def cons (b : δ a) (f : ∀ a ∈ m, δ a) : ∀ a' ∈ a ::ₘ m, δ a' :=
fun a' ha' => if h : a' = a then Eq.ndrec b h.symm else f a' <| (mem_cons.1 ha').resolve_left h
variable {m a}
theorem cons_same {b : δ a} {f : ∀ a ∈ m, δ a} (h : a ∈ a ::ₘ m) :
cons m a b f a h = b :=
dif_pos rfl
theorem cons_ne {a a' : α} {b : δ a} {f : ∀ a ∈ m, δ a} (h' : a' ∈ a ::ₘ m)
(h : a' ≠ a) : Pi.cons m a b f a' h' = f a' ((mem_cons.1 h').resolve_left h) :=
dif_neg h
theorem cons_swap {a a' : α} {b : δ a} {b' : δ a'} {m : Multiset α} {f : ∀ a ∈ m, δ a}
(h : a ≠ a') : Pi.cons (a' ::ₘ m) a b (Pi.cons m a' b' f) ≍
Pi.cons (a ::ₘ m) a' b' (Pi.cons m a b f) := by
apply hfunext rfl
simp only [heq_iff_eq]
rintro a'' _ rfl
refine hfunext (by rw [Multiset.cons_swap]) fun ha₁ ha₂ _ => ?_
rcases Decidable.ne_or_eq a'' a with (h₁ | rfl)
on_goal 1 => rcases Decidable.eq_or_ne a'' a' with (rfl | h₂)
all_goals simp [*, Pi.cons_same, Pi.cons_ne]
@[simp]
theorem cons_eta {m : Multiset α} {a : α} (f : ∀ a' ∈ a ::ₘ m, δ a') :
(cons m a (f _ (mem_cons_self _ _)) fun a' ha' => f a' (mem_cons_of_mem ha')) = f := by
ext a' h'
by_cases h : a' = a
· subst h
rw [Pi.cons_same]
· rw [Pi.cons_ne _ h]
theorem cons_map (b : δ a) (f : ∀ a' ∈ m, δ a')
{δ' : α → Sort*} (φ : ∀ ⦃a'⦄, δ a' → δ' a') :
Pi.cons _ _ (φ b) (fun a' ha' ↦ φ (f a' ha')) = (fun a' ha' ↦ φ ((cons _ _ b f) a' ha')) := by
ext a' ha'
refine (congrArg₂ _ ?_ rfl).trans (apply_dite (@φ _) (a' = a) _ _).symm
ext rfl
rfl
theorem forall_rel_cons_ext {r : ∀ ⦃a⦄, δ a → δ a → Prop} {b₁ b₂ : δ a} {f₁ f₂ : ∀ a' ∈ m, δ a'}
(hb : r b₁ b₂) (hf : ∀ (a : α) (ha : a ∈ m), r (f₁ a ha) (f₂ a ha)) :
∀ a ha, r (cons _ _ b₁ f₁ a ha) (cons _ _ b₂ f₂ a ha) := by
intro a ha
dsimp [cons]
split_ifs with H
· cases H
exact hb
· exact hf _ _
theorem cons_injective {a : α} {b : δ a} {s : Multiset α} (hs : a ∉ s) :
Function.Injective (Pi.cons s a b) := fun f₁ f₂ eq =>
funext fun a' =>
funext fun h' =>
have ne : a ≠ a' := fun h => hs <| h.symm ▸ h'
have : a' ∈ a ::ₘ s := mem_cons_of_mem h'
calc
f₁ a' h' = Pi.cons s a b f₁ a' this := by rw [Pi.cons_ne this ne.symm]
_ = Pi.cons s a b f₂ a' this := by rw [eq]
_ = f₂ a' h' := by rw [Pi.cons_ne this ne.symm]
end Pi
section
variable {α : Type*} [DecidableEq α] {β : α → Type*}
/-- `pi m t` constructs the Cartesian product over `t` indexed by `m`. -/
def pi (m : Multiset α) (t : ∀ a, Multiset (β a)) : Multiset (∀ a ∈ m, β a) :=
m.recOn {Pi.empty β}
(fun a m (p : Multiset (∀ a ∈ m, β a)) => (t a).bind fun b => p.map <| Pi.cons m a b)
(by
intro a a' m n
by_cases eq : a = a'
· subst eq; rfl
· simp only [map_bind, map_map, comp_apply, bind_bind (t a') (t a)]
apply bind_hcongr
· rw [cons_swap a a']
intro b _
apply bind_hcongr
· rw [cons_swap a a']
intro b' _
apply map_hcongr
· rw [cons_swap a a']
intro f _
exact Pi.cons_swap eq)
@[simp]
theorem pi_zero (t : ∀ a, Multiset (β a)) : pi 0 t = {Pi.empty β} :=
rfl
@[simp]
theorem pi_cons (m : Multiset α) (t : ∀ a, Multiset (β a)) (a : α) :
pi (a ::ₘ m) t = (t a).bind fun b => (pi m t).map <| Pi.cons m a b :=
recOn_cons a m
theorem card_pi (m : Multiset α) (t : ∀ a, Multiset (β a)) :
card (pi m t) = prod (m.map fun a => card (t a)) :=
Multiset.induction_on m (by simp) (by simp +contextual)
protected theorem Nodup.pi {s : Multiset α} {t : ∀ a, Multiset (β a)} :
Nodup s → (∀ a ∈ s, Nodup (t a)) → Nodup (pi s t) :=
Multiset.induction_on s (fun _ _ => nodup_singleton _)
(by
intro a s ih hs ht
have has : a ∉ s := by simp only [nodup_cons] at hs; exact hs.1
have hs : Nodup s := by simp only [nodup_cons] at hs; exact hs.2
simp only [pi_cons, nodup_bind]
refine
⟨fun b _ => ((ih hs) fun a' h' => ht a' <| mem_cons_of_mem h').map (Pi.cons_injective has),
?_⟩
refine (ht a <| mem_cons_self _ _).pairwise ?_
exact fun b₁ _ b₂ _ neb =>
disjoint_map_map.2 fun f _ g _ eq =>
have : Pi.cons s a b₁ f a (mem_cons_self _ _) = Pi.cons s a b₂ g a (mem_cons_self _ _) :=
by rw [eq]
neb <| show b₁ = b₂ by rwa [Pi.cons_same, Pi.cons_same] at this)
theorem mem_pi (m : Multiset α) (t : ∀ a, Multiset (β a)) :
∀ f : ∀ a ∈ m, β a, f ∈ pi m t ↔ ∀ (a) (h : a ∈ m), f a h ∈ t a := by
intro f
induction' m using Multiset.induction_on with a m ih
· have : f = Pi.empty β := funext (fun _ => funext fun h => (notMem_zero _ h).elim)
simp only [this, pi_zero, mem_singleton, true_iff]
intro _ h; exact (notMem_zero _ h).elim
simp_rw [pi_cons, mem_bind, mem_map, ih]
constructor
· rintro ⟨b, hb, f', hf', rfl⟩ a' ha'
by_cases h : a' = a
· subst h
rwa [Pi.cons_same]
· rw [Pi.cons_ne _ h]
apply hf'
· intro hf
refine ⟨_, hf a (mem_cons_self _ _), _, fun a ha => hf a (mem_cons_of_mem ha), ?_⟩
rw [Pi.cons_eta]
end
end Pi
end Multiset
|
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.
|
Zero.lean
|
/-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
/-!
# Preservation of zero objects and zero morphisms
We define the class `PreservesZeroMorphisms` and show basic properties.
## Main results
We provide the following results:
* Left adjoints and right adjoints preserve zero morphisms;
* full functors preserve zero morphisms;
* if both categories involved have a zero object, then a functor preserves zero morphisms if and
only if it preserves the zero object;
* functors which preserve initial or terminal objects preserve zero morphisms.
-/
universe v u v₁ v₂ v₃ u₁ u₂ u₃
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory.Functor
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{E : Type u₃} [Category.{v₃} E]
section ZeroMorphisms
variable [HasZeroMorphisms C] [HasZeroMorphisms D] [HasZeroMorphisms E]
/-- A functor preserves zero morphisms if it sends zero morphisms to zero morphisms. -/
class PreservesZeroMorphisms (F : C ⥤ D) : Prop where
/-- For any pair objects `F (0: X ⟶ Y) = (0 : F X ⟶ F Y)` -/
map_zero : ∀ X Y : C, F.map (0 : X ⟶ Y) = 0 := by aesop
@[simp]
protected theorem map_zero (F : C ⥤ D) [PreservesZeroMorphisms F] (X Y : C) :
F.map (0 : X ⟶ Y) = 0 :=
PreservesZeroMorphisms.map_zero _ _
lemma map_isZero (F : C ⥤ D) [PreservesZeroMorphisms F] {X : C} (hX : IsZero X) :
IsZero (F.obj X) := by
simp only [IsZero.iff_id_eq_zero] at hX ⊢
rw [← F.map_id, hX, F.map_zero]
theorem zero_of_map_zero (F : C ⥤ D) [PreservesZeroMorphisms F] [Faithful F] {X Y : C} (f : X ⟶ Y)
(h : F.map f = 0) : f = 0 :=
F.map_injective <| h.trans <| Eq.symm <| F.map_zero _ _
theorem map_eq_zero_iff (F : C ⥤ D) [PreservesZeroMorphisms F] [Faithful F] {X Y : C} {f : X ⟶ Y} :
F.map f = 0 ↔ f = 0 :=
⟨F.zero_of_map_zero _, by
rintro rfl
exact F.map_zero _ _⟩
instance (priority := 100) preservesZeroMorphisms_of_isLeftAdjoint (F : C ⥤ D) [IsLeftAdjoint F] :
PreservesZeroMorphisms F where
map_zero X Y := by
let adj := Adjunction.ofIsLeftAdjoint F
calc
F.map (0 : X ⟶ Y) = F.map 0 ≫ F.map (adj.unit.app Y) ≫ adj.counit.app (F.obj Y) := ?_
_ = F.map 0 ≫ F.map ((rightAdjoint F).map (0 : F.obj X ⟶ _)) ≫ adj.counit.app (F.obj Y) := ?_
_ = 0 := ?_
· rw [Adjunction.left_triangle_components]
exact (Category.comp_id _).symm
· simp only [← Category.assoc, ← F.map_comp, zero_comp]
· simp only [Adjunction.counit_naturality, comp_zero]
instance (priority := 100) preservesZeroMorphisms_of_isRightAdjoint (G : C ⥤ D) [IsRightAdjoint G] :
PreservesZeroMorphisms G where
map_zero X Y := by
let adj := Adjunction.ofIsRightAdjoint G
calc
G.map (0 : X ⟶ Y) = adj.unit.app (G.obj X) ≫ G.map (adj.counit.app X) ≫ G.map 0 := ?_
_ = adj.unit.app (G.obj X) ≫ G.map ((leftAdjoint G).map (0 : _ ⟶ G.obj X)) ≫ G.map 0 := ?_
_ = 0 := ?_
· rw [Adjunction.right_triangle_components_assoc]
· simp only [← G.map_comp, comp_zero]
· simp only [id_obj, comp_obj, Adjunction.unit_naturality_assoc, zero_comp]
instance (priority := 100) preservesZeroMorphisms_of_full (F : C ⥤ D) [Full F] :
PreservesZeroMorphisms F where
map_zero X Y :=
calc
F.map (0 : X ⟶ Y) = F.map (0 ≫ F.preimage (0 : F.obj Y ⟶ F.obj Y)) := by rw [zero_comp]
_ = 0 := by rw [F.map_comp, F.map_preimage, comp_zero]
instance preservesZeroMorphisms_comp (F : C ⥤ D) (G : D ⥤ E)
[F.PreservesZeroMorphisms] [G.PreservesZeroMorphisms] :
(F ⋙ G).PreservesZeroMorphisms := ⟨by simp⟩
lemma preservesZeroMorphisms_of_iso {F₁ F₂ : C ⥤ D} [F₁.PreservesZeroMorphisms] (e : F₁ ≅ F₂) :
F₂.PreservesZeroMorphisms where
map_zero X Y := by simp only [← cancel_epi (e.hom.app X), ← e.hom.naturality,
F₁.map_zero, zero_comp, comp_zero]
instance preservesZeroMorphisms_evaluation_obj (j : D) :
PreservesZeroMorphisms ((evaluation D C).obj j) where
instance (F : C ⥤ D ⥤ E) [∀ X, (F.obj X).PreservesZeroMorphisms] :
F.flip.PreservesZeroMorphisms where
instance (F : C ⥤ D ⥤ E) [F.PreservesZeroMorphisms] (Y : D) :
(F.flip.obj Y).PreservesZeroMorphisms where
omit [HasZeroMorphisms C] in
@[simp] lemma whiskerRight_zero {F G : C ⥤ D} (H : D ⥤ E) [H.PreservesZeroMorphisms] :
whiskerRight (0 : F ⟶ G) H = 0 := by cat_disch
end ZeroMorphisms
section ZeroObject
variable [HasZeroObject C] [HasZeroObject D]
open ZeroObject
variable [HasZeroMorphisms C] [HasZeroMorphisms D] (F : C ⥤ D)
/-- A functor that preserves zero morphisms also preserves the zero object. -/
@[simps]
def mapZeroObject [PreservesZeroMorphisms F] : F.obj 0 ≅ 0 where
hom := 0
inv := 0
hom_inv_id := by rw [← F.map_id, id_zero, F.map_zero, zero_comp]
inv_hom_id := by rw [id_zero, comp_zero]
variable {F}
theorem preservesZeroMorphisms_of_map_zero_object (i : F.obj 0 ≅ 0) : PreservesZeroMorphisms F where
map_zero X Y :=
calc
F.map (0 : X ⟶ Y) = F.map (0 : X ⟶ 0) ≫ F.map 0 := by rw [← Functor.map_comp, comp_zero]
_ = F.map 0 ≫ (i.hom ≫ i.inv) ≫ F.map 0 := by rw [Iso.hom_inv_id, Category.id_comp]
_ = 0 := by simp only [zero_of_to_zero i.hom, zero_comp, comp_zero]
instance (priority := 100) preservesZeroMorphisms_of_preserves_initial_object
[PreservesColimit (Functor.empty.{0} C) F] : PreservesZeroMorphisms F :=
preservesZeroMorphisms_of_map_zero_object <|
F.mapIso HasZeroObject.zeroIsoInitial ≪≫
PreservesInitial.iso F ≪≫ HasZeroObject.zeroIsoInitial.symm
instance (priority := 100) preservesZeroMorphisms_of_preserves_terminal_object
[PreservesLimit (Functor.empty.{0} C) F] : PreservesZeroMorphisms F :=
preservesZeroMorphisms_of_map_zero_object <|
F.mapIso HasZeroObject.zeroIsoTerminal ≪≫
PreservesTerminal.iso F ≪≫ HasZeroObject.zeroIsoTerminal.symm
variable (F)
/-- Preserving zero morphisms implies preserving terminal objects. -/
lemma preservesTerminalObject_of_preservesZeroMorphisms [PreservesZeroMorphisms F] :
PreservesLimit (Functor.empty.{0} C) F :=
preservesTerminal_of_iso F <|
F.mapIso HasZeroObject.zeroIsoTerminal.symm ≪≫ mapZeroObject F ≪≫ HasZeroObject.zeroIsoTerminal
/-- Preserving zero morphisms implies preserving terminal objects. -/
lemma preservesInitialObject_of_preservesZeroMorphisms [PreservesZeroMorphisms F] :
PreservesColimit (Functor.empty.{0} C) F :=
preservesInitial_of_iso F <|
HasZeroObject.zeroIsoInitial.symm ≪≫
(mapZeroObject F).symm ≪≫ (F.mapIso HasZeroObject.zeroIsoInitial.symm).symm
end ZeroObject
section
variable [HasZeroObject D] [HasZeroMorphisms D]
(G : C ⥤ D) (hG : IsZero G) (J : Type*) [Category J]
include hG
/-- A zero functor preserves limits. -/
lemma preservesLimitsOfShape_of_isZero : PreservesLimitsOfShape J G where
preservesLimit {K} := ⟨fun _ => ⟨by
rw [Functor.isZero_iff] at hG
exact IsLimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩⟩
/-- A zero functor preserves colimits. -/
lemma preservesColimitsOfShape_of_isZero : PreservesColimitsOfShape J G where
preservesColimit {K} := ⟨fun _ => ⟨by
rw [Functor.isZero_iff] at hG
exact IsColimit.ofIsZero _ ((K ⋙ G).isZero (fun X ↦ hG _)) (hG _)⟩⟩
/-- A zero functor preserves limits. -/
lemma preservesLimitsOfSize_of_isZero : PreservesLimitsOfSize.{v, u} G where
preservesLimitsOfShape := G.preservesLimitsOfShape_of_isZero hG _
/-- A zero functor preserves colimits. -/
lemma preservesColimitsOfSize_of_isZero : PreservesColimitsOfSize.{v, u} G where
preservesColimitsOfShape := G.preservesColimitsOfShape_of_isZero hG _
end
end CategoryTheory.Functor
|
Defs.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.Bounds.Basic
import Mathlib.Order.SetNotation
import Mathlib.Order.WellFounded
/-!
# Definitions of conditionally complete lattices
A conditionally complete lattice is a lattice in which every non-empty bounded subset `s`
has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`.
Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders.
The theory is very comparable to the theory of complete lattices, except that suitable
boundedness and nonemptiness assumptions have to be added to most statements.
We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove
most useful properties of `sSup` and `sInf` in conditionally complete lattices.
To differentiate the statements between complete lattices and conditionally complete
lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`.
For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`,
while `csInf_le` is the same statement in conditionally complete lattices
with an additional assumption that `s` is bounded below.
-/
open Set
variable {α β γ : Type*} {ι : Sort*}
/-- A conditionally complete lattice is a lattice in which
every nonempty subset which is bounded above has a supremum, and
every nonempty subset which is bounded below has an infimum.
Typical examples are real numbers or natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete lattices, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLattice (α : Type*) extends Lattice α, SupSet α, InfSet α where
/-- `a ≤ sSup s` for all `a ∈ s`. -/
le_csSup : ∀ s a, BddAbove s → a ∈ s → a ≤ sSup s
/-- `sSup s ≤ a` for all `a ∈ upperBounds s`. -/
csSup_le : ∀ s a, Set.Nonempty s → a ∈ upperBounds s → sSup s ≤ a
/-- `sInf s ≤ a` for all `a ∈ s`. -/
csInf_le : ∀ s a, BddBelow s → a ∈ s → sInf s ≤ a
/-- `a ≤ sInf s` for all `a ∈ lowerBounds s`. -/
le_csInf : ∀ s a, Set.Nonempty s → a ∈ lowerBounds s → a ≤ sInf s
/-- A conditionally complete linear order is a linear order in which
every nonempty subset which is bounded above has a supremum, and
every nonempty subset which is bounded below has an infimum.
Typical examples are real numbers or natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete linear orders, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLinearOrder (α : Type*)
extends ConditionallyCompleteLattice α, Ord α where
/-- A `ConditionallyCompleteLinearOrder` is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
toDecidableLE : DecidableLE α
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
toDecidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ toDecidableLE
/-- In a `ConditionallyCompleteLinearOrder`, we assume the order relations are all decidable. -/
toDecidableLT : DecidableLT α := @decidableLTOfDecidableLE _ _ toDecidableLE
/-- If a set is not bounded above, its supremum is by convention `sSup ∅`. -/
csSup_of_not_bddAbove : ∀ s, ¬BddAbove s → sSup s = sSup (∅ : Set α)
/-- If a set is not bounded below, its infimum is by convention `sInf ∅`. -/
csInf_of_not_bddBelow : ∀ s, ¬BddBelow s → sInf s = sInf (∅ : Set α)
compare a b := compareOfLessAndEq a b
/-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/
compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by
compareOfLessAndEq_rfl
/-- A conditionally complete linear order with `Bot` is a linear order with least element, in which
every nonempty subset which is bounded above has a supremum, and every nonempty subset (necessarily
bounded below) has an infimum. A typical example is the natural numbers.
To differentiate the statements from the corresponding statements in (unconditional)
complete linear orders, we prefix `sInf` and `sSup` by a `c` everywhere. The same statements should
hold in both worlds, sometimes with additional assumptions of nonemptiness or
boundedness. -/
class ConditionallyCompleteLinearOrderBot (α : Type*) extends ConditionallyCompleteLinearOrder α,
OrderBot α where
/-- The supremum of the empty set is special-cased to `⊥` -/
csSup_empty : sSup ∅ = ⊥
-- see Note [lower instance priority]
attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot
open scoped Classical in
/-- A well founded linear order is conditionally complete, with a bottom element. -/
noncomputable abbrev WellFoundedLT.conditionallyCompleteLinearOrderBot (α : Type*)
[i₁ : LinearOrder α] [i₂ : OrderBot α] [h : WellFoundedLT α] :
ConditionallyCompleteLinearOrderBot α :=
{ i₁, i₂, LinearOrder.toLattice with
sInf := fun s => if hs : s.Nonempty then h.wf.min s hs else ⊥
csInf_le := fun s a _ has => by
have s_ne : s.Nonempty := ⟨a, has⟩
simpa [s_ne] using not_lt.1 (h.wf.not_lt_min s s_ne has)
le_csInf := fun s a hs has => by
simp only [hs, dif_pos]
exact has (h.wf.min_mem s hs)
sSup := fun s => if hs : (upperBounds s).Nonempty then h.wf.min _ hs else ⊥
le_csSup := fun s a hs has => by
have h's : (upperBounds s).Nonempty := hs
simp only [h's, dif_pos]
exact h.wf.min_mem _ h's has
csSup_le := fun s a _ has => by
have h's : (upperBounds s).Nonempty := ⟨a, has⟩
simp only [h's, dif_pos]
simpa using h.wf.not_lt_min _ h's has
csSup_empty := by simpa using eq_bot_iff.2 (not_lt.1 <| h.wf.not_lt_min _ _ <| mem_univ ⊥)
csSup_of_not_bddAbove := by
intro s H
have B : ¬((upperBounds s).Nonempty) := H
simp only [B, dite_false, upperBounds_empty, univ_nonempty, dite_true]
exact le_antisymm bot_le (WellFounded.min_le _ (mem_univ _))
csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim }
/-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `sup` function
that returns the least upper bound of a nonempty set which is bounded above. Usually this
constructor provides poor definitional equalities. If other fields are known explicitly, they
should be provided; for example, if `inf` is known explicitly, construct the
`ConditionallyCompleteLattice` instance as
```
instance : ConditionallyCompleteLattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, sInf
..conditionallyCompleteLatticeOfsSup my_T _ }
```
-/
def conditionallyCompleteLatticeOfsSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α]
(bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α))
(bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α))
(isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) :
ConditionallyCompleteLattice α :=
{ H1, H2 with
sup := fun a b => sSup {a, b}
le_sup_left := fun a b =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _)
le_sup_right := fun a b =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).1
(mem_insert_of_mem _ (mem_singleton _))
sup_le := fun a b _ hac hbc =>
(isLUB_sSup {a, b} (bddAbove_pair a b) (insert_nonempty _ _)).2
(forall_insert_of_forall (forall_eq.mpr hbc) hac)
inf := fun a b => sSup (lowerBounds {a, b})
inf_le_left := fun a b =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
(bddBelow_pair a b)).2
fun _ hc => hc <| mem_insert _ _
inf_le_right := fun a b =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
(bddBelow_pair a b)).2
fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _)
le_inf := fun c a b hca hcb =>
(isLUB_sSup (lowerBounds {a, b}) (Nonempty.bddAbove_lowerBounds ⟨a, mem_insert _ _⟩)
⟨c, forall_insert_of_forall (forall_eq.mpr hcb) hca⟩).1
(forall_insert_of_forall (forall_eq.mpr hcb) hca)
sInf := fun s => sSup (lowerBounds s)
csSup_le := fun s a hs ha => (isLUB_sSup s ⟨a, ha⟩ hs).2 ha
le_csSup := fun s a hs ha => (isLUB_sSup s hs ⟨a, ha⟩).1 ha
csInf_le := fun s a hs ha =>
(isLUB_sSup (lowerBounds s) (Nonempty.bddAbove_lowerBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha
le_csInf := fun s a hs ha =>
(isLUB_sSup (lowerBounds s) hs.bddAbove_lowerBounds ⟨a, ha⟩).1 ha }
/-- Create a `ConditionallyCompleteLattice` from a `PartialOrder` and `inf` function
that returns the greatest lower bound of a nonempty set which is bounded below. Usually this
constructor provides poor definitional equalities. If other fields are known explicitly, they
should be provided; for example, if `inf` is known explicitly, construct the
`ConditionallyCompleteLattice` instance as
```
instance : ConditionallyCompleteLattice my_T :=
{ inf := better_inf,
le_inf := ...,
inf_le_right := ...,
inf_le_left := ...
-- don't care to fix sup, sSup
..conditionallyCompleteLatticeOfsInf my_T _ }
```
-/
def conditionallyCompleteLatticeOfsInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α]
(bddAbove_pair : ∀ a b : α, BddAbove ({a, b} : Set α))
(bddBelow_pair : ∀ a b : α, BddBelow ({a, b} : Set α))
(isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) :
ConditionallyCompleteLattice α :=
{ H1, H2 with
inf := fun a b => sInf {a, b}
inf_le_left := fun a b =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1 (mem_insert _ _)
inf_le_right := fun a b =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).1
(mem_insert_of_mem _ (mem_singleton _))
le_inf := fun _ a b hca hcb =>
(isGLB_sInf {a, b} (bddBelow_pair a b) (insert_nonempty _ _)).2
(forall_insert_of_forall (forall_eq.mpr hcb) hca)
sup := fun a b => sInf (upperBounds {a, b})
le_sup_left := fun a b =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
(bddAbove_pair a b)).2
fun _ hc => hc <| mem_insert _ _
le_sup_right := fun a b =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
(bddAbove_pair a b)).2
fun _ hc => hc <| mem_insert_of_mem _ (mem_singleton _)
sup_le := fun a b c hac hbc =>
(isGLB_sInf (upperBounds {a, b}) (Nonempty.bddBelow_upperBounds ⟨a, mem_insert _ _⟩)
⟨c, forall_insert_of_forall (forall_eq.mpr hbc) hac⟩).1
(forall_insert_of_forall (forall_eq.mpr hbc) hac)
sSup := fun s => sInf (upperBounds s)
le_csInf := fun s a hs ha => (isGLB_sInf s ⟨a, ha⟩ hs).2 ha
csInf_le := fun s a hs ha => (isGLB_sInf s hs ⟨a, ha⟩).1 ha
le_csSup := fun s a hs ha =>
(isGLB_sInf (upperBounds s) (Nonempty.bddBelow_upperBounds ⟨a, ha⟩) hs).2 fun _ hb => hb ha
csSup_le := fun s a hs ha =>
(isGLB_sInf (upperBounds s) hs.bddBelow_upperBounds ⟨a, ha⟩).1 ha }
/-- A version of `conditionallyCompleteLatticeOfsSup` when we already know that `α` is a lattice.
This should only be used when it is both hard and unnecessary to provide `inf` explicitly. -/
def conditionallyCompleteLatticeOfLatticeOfsSup (α : Type*) [H1 : Lattice α] [SupSet α]
(isLUB_sSup : ∀ s : Set α, BddAbove s → s.Nonempty → IsLUB s (sSup s)) :
ConditionallyCompleteLattice α :=
{ H1,
conditionallyCompleteLatticeOfsSup α
(fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩)
(fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩)
isLUB_sSup with }
/-- A version of `conditionallyCompleteLatticeOfsInf` when we already know that `α` is a lattice.
This should only be used when it is both hard and unnecessary to provide `sup` explicitly. -/
def conditionallyCompleteLatticeOfLatticeOfsInf (α : Type*) [H1 : Lattice α] [InfSet α]
(isGLB_sInf : ∀ s : Set α, BddBelow s → s.Nonempty → IsGLB s (sInf s)) :
ConditionallyCompleteLattice α :=
{ H1,
conditionallyCompleteLatticeOfsInf α
(fun a b => ⟨a ⊔ b, forall_insert_of_forall (forall_eq.mpr le_sup_right) le_sup_left⟩)
(fun a b => ⟨a ⊓ b, forall_insert_of_forall (forall_eq.mpr inf_le_right) inf_le_left⟩)
isGLB_sInf with }
|
Products.lean
|
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Products
/-!
# (Co)products in functor categories
Given `f : α → D ⥤ C`, we prove the isomorphisms
`(∏ᶜ f).obj d ≅ ∏ᶜ (fun s => (f s).obj d)` and `(∐ f).obj d ≅ ∐ (fun s => (f s).obj d)`.
-/
universe w v v₁ v₂ u u₁ u₂
namespace CategoryTheory.Limits
variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D]
{α : Type w}
section Product
variable [HasLimitsOfShape (Discrete α) C]
/-- Evaluating a product of functors amounts to taking the product of the evaluations. -/
noncomputable def piObjIso (f : α → D ⥤ C) (d : D) : (∏ᶜ f).obj d ≅ ∏ᶜ (fun s => (f s).obj d) :=
limitObjIsoLimitCompEvaluation (Discrete.functor f) d ≪≫
HasLimit.isoOfNatIso (Discrete.compNatIsoDiscrete _ _)
@[reassoc (attr := simp)]
theorem piObjIso_hom_comp_π (f : α → D ⥤ C) (d : D) (s : α) :
(piObjIso f d).hom ≫ Pi.π (fun s => (f s).obj d) s = (Pi.π f s).app d := by
simp [piObjIso]
@[reassoc (attr := simp)]
theorem piObjIso_inv_comp_π (f : α → D ⥤ C) (d : D) (s : α) :
(piObjIso f d).inv ≫ (Pi.π f s).app d = Pi.π (fun s => (f s).obj d) s := by
simp [piObjIso]
@[deprecated (since := "2025-02-23")]
alias piObjIso_inv_comp_pi := piObjIso_inv_comp_π
end Product
section Coproduct
variable [HasColimitsOfShape (Discrete α) C]
/-- Evaluating a coproduct of functors amounts to taking the coproduct of the evaluations. -/
noncomputable def sigmaObjIso (f : α → D ⥤ C) (d : D) : (∐ f).obj d ≅ ∐ (fun s => (f s).obj d) :=
colimitObjIsoColimitCompEvaluation (Discrete.functor f) d ≪≫
HasColimit.isoOfNatIso (Discrete.compNatIsoDiscrete _ _)
@[reassoc (attr := simp)]
theorem ι_comp_sigmaObjIso_hom (f : α → D ⥤ C) (d : D) (s : α) :
(Sigma.ι f s).app d ≫ (sigmaObjIso f d).hom = Sigma.ι (fun s => (f s).obj d) s := by
simp [sigmaObjIso]
@[reassoc (attr := simp)]
theorem ι_comp_sigmaObjIso_inv (f : α → D ⥤ C) (d : D) (s : α) :
Sigma.ι (fun s => (f s).obj d) s ≫ (sigmaObjIso f d).inv = (Sigma.ι f s).app d := by
simp [sigmaObjIso]
end Coproduct
end CategoryTheory.Limits
|
Basic.lean
|
/-
Copyright (c) 2024 Judith Ludwig, Florent Schaffhauser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Judith Ludwig, Florent Schaffhauser, Yunzhou Xie, Jujian Zhang
-/
import Mathlib.LinearAlgebra.TensorProduct.Quotient
import Mathlib.RingTheory.Flat.Stability
/-!
# Faithfully flat modules
A module `M` over a commutative ring `R` is *faithfully flat* if it is flat and `IM ≠ M` whenever
`I` is a maximal ideal of `R`.
## Main declaration
- `Module.FaithfullyFlat`: the predicate asserting that an `R`-module `M` is faithfully flat.
## Main theorems
- `Module.FaithfullyFlat.iff_flat_and_proper_ideal`: an `R`-module `M` is faithfully flat iff it is
flat and for all proper ideals `I` of `R`, `I • M ≠ M`.
- `Module.FaithfullyFlat.iff_flat_and_rTensor_faithful`: an `R`-module `M` is faithfully flat iff it
is flat and tensoring with `M` is faithful, i.e. `N ≠ 0` implies `N ⊗ M ≠ 0`.
- `Module.FaithfullyFlat.iff_flat_and_lTensor_faithful`: an `R`-module `M` is faithfully flat iff it
is flat and tensoring with `M` is faithful, i.e. `N ≠ 0` implies `M ⊗ N ≠ 0`.
- `Module.FaithfullyFlat.iff_exact_iff_rTensor_exact`: an `R`-module `M` is faithfully flat iff
tensoring with `M` preserves and reflects exact sequences, i.e. the sequence `N₁ → N₂ → N₃` is
exact *iff* the sequence `N₁ ⊗ M → N₂ ⊗ M → N₃ ⊗ M` is exact.
- `Module.FaithfullyFlat.iff_exact_iff_lTensor_exact`: an `R`-module `M` is faithfully flat iff
tensoring with `M` preserves and reflects exact sequences, i.e. the sequence `N₁ → N₂ → N₃` is
exact *iff* the sequence `M ⊗ N₁ → M ⊗ N₂ → M ⊗ N₃` is exact.
- `Module.FaithfullyFlat.iff_zero_iff_lTensor_zero`: an `R`-module `M` is faithfully flat iff for
all linear maps `f : N → N'`, `f = 0` iff `M ⊗ f = 0`.
- `Module.FaithfullyFlat.iff_zero_iff_rTensor_zero`: an `R`-module `M` is faithfully flat iff for
all linear maps `f : N → N'`, `f = 0` iff `f ⊗ M = 0`.
- `Module.FaithfullyFlat.of_linearEquiv`: modules linearly equivalent to a flat modules are flat
- `Module.FaithfullyFlat.trans`: if `S` is `R`-faithfully flat and `M` is `S`-faithfully flat, then
`M` is `R`-faithfully flat.
- `Module.FaithfullyFlat.self`: the `R`-module `R` is faithfully flat.
-/
universe u v
open TensorProduct DirectSum
namespace Module
variable (R : Type u) (M : Type v) [CommRing R] [AddCommGroup M] [Module R M]
/--
A module `M` over a commutative ring `R` is *faithfully flat* if it is flat and,
for all `R`-linear maps `f : N → N'` such that `id ⊗ f = 0`, we have `f = 0`.
-/
@[mk_iff] class FaithfullyFlat : Prop extends Module.Flat R M where
submodule_ne_top : ∀ ⦃m : Ideal R⦄ (_ : Ideal.IsMaximal m), m • (⊤ : Submodule R M) ≠ ⊤
namespace FaithfullyFlat
instance self : FaithfullyFlat R R where
submodule_ne_top m h r := Ideal.eq_top_iff_one _ |>.not.1 h.ne_top <| by
simpa using show 1 ∈ (m • ⊤ : Ideal R) from r.symm ▸ ⟨⟩
section proper_ideal
lemma iff_flat_and_proper_ideal :
FaithfullyFlat R M ↔
(Flat R M ∧ ∀ (I : Ideal R), I ≠ ⊤ → I • (⊤ : Submodule R M) ≠ ⊤) := by
rw [faithfullyFlat_iff]
refine ⟨fun ⟨flat, h⟩ => ⟨flat, fun I hI r => ?_⟩, fun h => ⟨h.1, fun m hm => h.2 _ hm.ne_top⟩⟩
obtain ⟨m, hm, le⟩ := I.exists_le_maximal hI
exact h hm <| eq_top_iff.2 <| show ⊤ ≤ m • ⊤ from r ▸ Submodule.smul_mono le (by simp [r])
lemma iff_flat_and_ideal_smul_eq_top :
FaithfullyFlat R M ↔
(Flat R M ∧ ∀ (I : Ideal R), I • (⊤ : Submodule R M) = ⊤ → I = ⊤) :=
iff_flat_and_proper_ideal R M |>.trans <| and_congr_right_iff.2 fun _ => iff_of_eq <|
forall_congr fun I => eq_iff_iff.2 <| by tauto
end proper_ideal
section faithful
instance rTensor_nontrivial
[fl : FaithfullyFlat R M] (N : Type*) [AddCommGroup N] [Module R N] [Nontrivial N] :
Nontrivial (N ⊗[R] M) := by
obtain ⟨n, hn⟩ := nontrivial_iff_exists_ne (0 : N) |>.1 inferInstance
let I := (Submodule.span R {n}).annihilator
by_cases I_ne_top : I = ⊤
· rw [Ideal.eq_top_iff_one, Submodule.mem_annihilator_span_singleton, one_smul] at I_ne_top
contradiction
let inc : R ⧸ I →ₗ[R] N := Submodule.liftQ _ ((LinearMap.lsmul R N).flip n) <| fun r hr => by
simpa only [LinearMap.mem_ker, LinearMap.flip_apply, LinearMap.lsmul_apply,
Submodule.mem_annihilator_span_singleton, I] using hr
have injective_inc : Function.Injective inc := LinearMap.ker_eq_bot.1 <| eq_bot_iff.2 <| by
intro r hr
induction r using Quotient.inductionOn' with | h r =>
simpa only [Submodule.Quotient.mk''_eq_mk, Submodule.mem_bot, Submodule.Quotient.mk_eq_zero,
Submodule.mem_annihilator_span_singleton, LinearMap.mem_ker, Submodule.liftQ_apply,
LinearMap.flip_apply, LinearMap.lsmul_apply, I, inc] using hr
have ne_top := iff_flat_and_proper_ideal R M |>.1 fl |>.2 I I_ne_top
refine subsingleton_or_nontrivial _ |>.resolve_left fun rid => ?_
exact False.elim <| ne_top <| Submodule.subsingleton_quotient_iff_eq_top.1 <|
Function.Injective.comp (g := LinearMap.rTensor M inc)
(fl.toFlat.rTensor_preserves_injective_linearMap inc injective_inc)
((quotTensorEquivQuotSMul M I).symm.injective) |>.subsingleton
instance lTensor_nontrivial
[FaithfullyFlat R M] (N : Type*) [AddCommGroup N] [Module R N] [Nontrivial N] :
Nontrivial (M ⊗[R] N) :=
TensorProduct.comm R M N |>.toEquiv.nontrivial
lemma rTensor_reflects_triviality
[FaithfullyFlat R M] (N : Type*) [AddCommGroup N] [Module R N]
[h : Subsingleton (N ⊗[R] M)] : Subsingleton N := by
revert h; change _ → _; contrapose
simp only [not_subsingleton_iff_nontrivial]
intro h
infer_instance
lemma lTensor_reflects_triviality
[FaithfullyFlat R M] (N : Type*) [AddCommGroup N] [Module R N]
[Subsingleton (M ⊗[R] N)] :
Subsingleton N := by
haveI : Subsingleton (N ⊗[R] M) := (TensorProduct.comm R N M).toEquiv.injective.subsingleton
apply rTensor_reflects_triviality R M
attribute [-simp] Ideal.Quotient.mk_eq_mk in
lemma iff_flat_and_rTensor_faithful :
FaithfullyFlat R M ↔
(Flat R M ∧
∀ (N : Type max u v) [AddCommGroup N] [Module R N],
Nontrivial N → Nontrivial (N ⊗[R] M)) := by
refine ⟨fun fl => ⟨inferInstance, rTensor_nontrivial R M⟩, fun ⟨flat, faithful⟩ => ⟨?_⟩⟩
intro m hm rid
specialize faithful (ULift (R ⧸ m)) inferInstance
haveI : Nontrivial ((R ⧸ m) ⊗[R] M) :=
(congr (ULift.moduleEquiv : ULift (R ⧸ m) ≃ₗ[R] R ⧸ m)
(LinearEquiv.refl R M)).symm.toEquiv.nontrivial
have := (quotTensorEquivQuotSMul M m).toEquiv.symm.nontrivial
haveI H : Subsingleton (M ⧸ m • (⊤ : Submodule R M)) := by
rwa [Submodule.subsingleton_quotient_iff_eq_top]
rw [← not_nontrivial_iff_subsingleton] at H
contradiction
lemma iff_flat_and_rTensor_reflects_triviality :
FaithfullyFlat R M ↔
(Flat R M ∧
∀ (N : Type max u v) [AddCommGroup N] [Module R N],
Subsingleton (N ⊗[R] M) → Subsingleton N) :=
iff_flat_and_rTensor_faithful R M |>.trans <| and_congr_right_iff.2 fun _ => iff_of_eq <|
forall_congr fun N => forall_congr fun _ => forall_congr fun _ => iff_iff_eq.1 <| by
simp only [← not_subsingleton_iff_nontrivial]; tauto
lemma iff_flat_and_lTensor_faithful :
FaithfullyFlat R M ↔
(Flat R M ∧
∀ (N : Type max u v) [AddCommGroup N] [Module R N],
Nontrivial N → Nontrivial (M ⊗[R] N)) :=
iff_flat_and_rTensor_faithful R M |>.trans
⟨fun ⟨flat, faithful⟩ => ⟨flat, fun N _ _ _ =>
letI := faithful N inferInstance; (TensorProduct.comm R M N).toEquiv.nontrivial⟩,
fun ⟨flat, faithful⟩ => ⟨flat, fun N _ _ _ =>
letI := faithful N inferInstance; (TensorProduct.comm R M N).symm.toEquiv.nontrivial⟩⟩
lemma iff_flat_and_lTensor_reflects_triviality :
FaithfullyFlat R M ↔
(Flat R M ∧
∀ (N : Type max u v) [AddCommGroup N] [Module R N],
Subsingleton (M ⊗[R] N) → Subsingleton N) :=
iff_flat_and_lTensor_faithful R M |>.trans <| and_congr_right_iff.2 fun _ => iff_of_eq <|
forall_congr fun N => forall_congr fun _ => forall_congr fun _ => iff_iff_eq.1 <| by
simp only [← not_subsingleton_iff_nontrivial]; tauto
end faithful
/-- If `M` is a faithfully flat `R`-module and `N` is `R`-linearly isomorphic to `M`, then
`N` is faithfully flat. -/
lemma of_linearEquiv {N : Type*} [AddCommGroup N] [Module R N] [FaithfullyFlat R M]
(e : N ≃ₗ[R] M) : FaithfullyFlat R N := by
rw [iff_flat_and_lTensor_faithful]
exact ⟨Flat.of_linearEquiv e,
fun P _ _ hP ↦ (TensorProduct.congr e (LinearEquiv.refl R P)).toEquiv.nontrivial⟩
section
/-- A direct sum of faithfully flat `R`-modules is faithfully flat. -/
instance directSum {ι : Type*} [Nonempty ι] (M : ι → Type*) [∀ i, AddCommGroup (M i)]
[∀ i, Module R (M i)] [∀ i, FaithfullyFlat R (M i)] : FaithfullyFlat R (⨁ i, M i) := by
classical
rw [iff_flat_and_lTensor_faithful]
refine ⟨inferInstance, fun N _ _ hN ↦ ?_⟩
obtain ⟨i⟩ := ‹Nonempty ι›
obtain ⟨x, y, hxy⟩ := Nontrivial.exists_pair_ne (α := M i ⊗[R] N)
haveI : Nontrivial (⨁ (i : ι), M i ⊗[R] N) :=
⟨DirectSum.of _ i x, DirectSum.of _ i y, fun h ↦ hxy (DirectSum.of_injective i h)⟩
apply (TensorProduct.directSumLeft R M N).toEquiv.nontrivial
/-- Free `R`-modules over discrete types are flat. -/
instance finsupp (ι : Type v) [Nonempty ι] : FaithfullyFlat R (ι →₀ R) := by
classical exact of_linearEquiv _ _ (finsuppLEquivDirectSum R R ι)
end
/-- Any free, nontrivial `R`-module is flat. -/
instance [Nontrivial M] [Module.Free R M] : FaithfullyFlat R M :=
of_linearEquiv _ _ (Free.chooseBasis R M).repr
section
variable {N : Type*} [AddCommGroup N] [Module R N]
@[simp]
lemma subsingleton_tensorProduct_iff_right [Module.FaithfullyFlat R M] :
Subsingleton (M ⊗[R] N) ↔ Subsingleton N :=
⟨fun _ ↦ lTensor_reflects_triviality R M N, fun _ ↦ inferInstance⟩
@[simp]
lemma subsingleton_tensorProduct_iff_left [Module.FaithfullyFlat R N] :
Subsingleton (M ⊗[R] N) ↔ Subsingleton M :=
⟨fun _ ↦ rTensor_reflects_triviality R N M, fun _ ↦ inferInstance⟩
@[simp]
lemma nontrivial_tensorProduct_iff_right [Module.FaithfullyFlat R M] :
Nontrivial (M ⊗[R] N) ↔ Nontrivial N := by
simp [← not_iff_not, not_nontrivial_iff_subsingleton]
@[simp]
lemma nontrivial_tensorProduct_iff_left [Module.FaithfullyFlat R N] :
Nontrivial (M ⊗[R] N) ↔ Nontrivial M := by
simp [← not_iff_not, not_nontrivial_iff_subsingleton]
end
section exact
/-!
### Faithfully flat modules and exact sequences
In this section we prove that an `R`-module `M` is faithfully flat iff tensoring with `M`
preserves and reflects exact sequences.
Let `N₁ -l₁₂-> N₂ -l₂₃-> N₃` be two linear maps.
- We first show that if `N₁ ⊗ M -> N₂ ⊗ M -> N₃ ⊗ M` is exact, then `N₁ -l₁₂-> N₂ -l₂₃-> N₃` is a
complex, i.e. `range l₁₂ ≤ ker l₂₃`.
This is `range_le_ker_of_exact_rTensor`.
- Then in `rTensor_reflects_exact`, we show `ker l₂₃ = range l₁₂` by considering the cohomology
`ker l₂₃ ⧸ range l₁₂`.
This shows that when `M` is faithfully flat, `- ⊗ M` reflects exact sequences. For details, see
comments in the proof. Since `M` is flat, `- ⊗ M` preserves exact sequences.
On the other hand, if `- ⊗ M` preserves and reflects exact sequences, then `M` is faithfully flat.
- `M` is flat because `- ⊗ M` preserves exact sequences.
- We need to show that if `N ⊗ M = 0` then `N = 0`. Consider the sequence `N -0-> N -0-> 0`. After
tensoring with `M`, we get `N ⊗ M -0-> N ⊗ M -0-> 0` which is exact because `N ⊗ M = 0`.
Since `- ⊗ M` reflects exact sequences, `N = 0`.
-/
section arbitrary_universe
variable {N1 : Type*} [AddCommGroup N1] [Module R N1]
variable {N2 : Type*} [AddCommGroup N2] [Module R N2]
variable {N3 : Type*} [AddCommGroup N3] [Module R N3]
variable (l12 : N1 →ₗ[R] N2) (l23 : N2 →ₗ[R] N3)
/--
If `M` is faithfully flat, then exactness of `N₁ ⊗ M -> N₂ ⊗ M -> N₃ ⊗ M` implies that the
composition `N₁ -> N₂ -> N₃` is `0`.
Implementation detail, please use `rTensor_reflects_exact` instead.
-/
lemma range_le_ker_of_exact_rTensor [fl : FaithfullyFlat R M]
(ex : Function.Exact (l12.rTensor M) (l23.rTensor M)) :
LinearMap.range l12 ≤ LinearMap.ker l23 := by
-- let `n1 ∈ N1`. We need to show `l23 (l12 n1) = 0`. Suppose this is not the case.
rintro _ ⟨n1, rfl⟩
rw [LinearMap.mem_ker]
by_contra! hn1
-- Let `E` be the submodule spanned by `l23 (l12 n1)`. Then because `l23 (l12 n1) ≠ 0`, we have
-- `E ≠ 0`.
let E : Submodule R N3 := Submodule.span R {l23 (l12 n1)}
have hE : Nontrivial E :=
⟨0, ⟨⟨l23 (l12 n1), Submodule.mem_span_singleton_self _⟩, Subtype.coe_ne_coe.1 hn1.symm⟩⟩
-- Since `N1 ⊗ M -> N2 ⊗ M -> N3 ⊗ M` is exact, we have `l23 (l12 n1) ⊗ₜ m = 0` for all `m : M`.
have eq1 : ∀ (m : M), l23 (l12 n1) ⊗ₜ[R] m = 0 := fun m ↦
ex.apply_apply_eq_zero (n1 ⊗ₜ[R] m)
-- Then `E ⊗ M = 0`. Indeed,
have eq0 : (⊤ : Submodule R (E ⊗[R] M)) = ⊥ := by
-- suppose `x ∈ E ⊗ M`. We will show `x = 0`.
ext x
simp only [Submodule.mem_top, Submodule.mem_bot, true_iff]
have mem : x ∈ (⊤ : Submodule R _) := ⟨⟩
rw [← TensorProduct.span_tmul_eq_top, Submodule.mem_span_set] at mem
obtain ⟨c, hc, rfl⟩ := mem
choose b a hy using hc
let r : ⦃a : E ⊗[R] M⦄ → a ∈ ↑c.support → R := fun a ha =>
Submodule.mem_span_singleton.1 (b ha).2 |>.choose
have hr : ∀ ⦃i : E ⊗[R] M⦄ (hi : i ∈ c.support), b hi =
r hi • ⟨l23 (l12 n1), Submodule.mem_span_singleton_self _⟩ := fun a ha =>
Subtype.ext <| Submodule.mem_span_singleton.1 (b ha).2 |>.choose_spec.symm
-- Since `M` is flat and `E -> N1` is injective, we only need to check that x = 0
-- in `N1 ⊗ M`. We write `x = ∑ μᵢ • (l23 (l12 n1)) ⊗ mᵢ = ∑ μᵢ • 0 = 0`
-- (remember `E = span {l23 (l12 n1)}` and `eq1`)
refine Finset.sum_eq_zero fun i hi => show c i • i = 0 from
(Module.Flat.rTensor_preserves_injective_linearMap (M := M) E.subtype <|
Submodule.injective_subtype E) ?_
rw [← hy hi, hr hi, smul_tmul, map_smul, LinearMap.rTensor_tmul, Submodule.subtype_apply, eq1,
smul_zero, map_zero]
have : Subsingleton (E ⊗[R] M) := subsingleton_iff_forall_eq 0 |>.2 fun x =>
show x ∈ (⊥ : Submodule R _) from eq0 ▸ ⟨⟩
-- but `E ⊗ M = 0` implies `E = 0` because `M` is faithfully flat and this is a contradiction.
exact not_subsingleton_iff_nontrivial.2 inferInstance <| fl.rTensor_reflects_triviality R M E
lemma rTensor_reflects_exact [fl : FaithfullyFlat R M]
(ex : Function.Exact (l12.rTensor M) (l23.rTensor M)) :
Function.Exact l12 l23 := LinearMap.exact_iff.2 <| by
have complex : LinearMap.range l12 ≤ LinearMap.ker l23 := range_le_ker_of_exact_rTensor R M _ _ ex
-- By the previous lemma we have that range l12 ≤ ker l23 and hence the quotient
-- H := ker l23 ⧸ range l12 makes sense.
-- Hence our goal ker l23 = range l12 follows from the claim that H = 0.
let H := LinearMap.ker l23 ⧸ LinearMap.range (Submodule.inclusion complex)
suffices triv_coh : Subsingleton H by
rw [Submodule.subsingleton_quotient_iff_eq_top, Submodule.range_inclusion,
Submodule.comap_subtype_eq_top] at triv_coh
exact le_antisymm triv_coh complex
-- Since `M` is faithfully flat, we need only to show that `H ⊗ M` is trivial.
suffices Subsingleton (H ⊗[R] M) from rTensor_reflects_triviality R M H
let e : H ⊗[R] M ≃ₗ[R] _ := TensorProduct.quotientTensorEquiv _ _
-- Note that `H ⊗ M` is isomorphic to `ker l12 ⊗ M ⧸ range ((range l12 ⊗ M) -> (ker l23 ⊗ M))`.
-- So the problem is reduced to proving surjectivity of `range l12 ⊗ M → ker l23 ⊗ M`.
rw [e.toEquiv.subsingleton_congr, Submodule.subsingleton_quotient_iff_eq_top,
LinearMap.range_eq_top]
intro x
induction x using TensorProduct.induction_on with
| zero => exact ⟨0, by simp⟩
-- let `x ⊗ m` be an element in `ker l23 ⊗ M`, then `x ⊗ m` is in the kernel of `l23 ⊗ 𝟙M`.
-- Since `N1 ⊗ M -l12 ⊗ M-> N2 ⊗ M -l23 ⊗ M-> N3 ⊗ M` is exact, we have that `x ⊗ m` is in
-- the range of `l12 ⊗ 𝟙M`, i.e. `x ⊗ m = (l12 ⊗ 𝟙M) y` for some `y ∈ N1 ⊗ M` as elements of
-- `N2 ⊗ M`. We need to prove that `x ⊗ m = (l12 ⊗ 𝟙M) y` still holds in `(ker l23) ⊗ M`.
-- This is okay because `M` is flat and `ker l23 -> N2` is injective.
| tmul x m =>
rcases x with ⟨x, (hx : l23 x = 0)⟩
have mem : x ⊗ₜ[R] m ∈ LinearMap.ker (l23.rTensor M) := by simp [hx]
rw [LinearMap.exact_iff.1 ex] at mem
obtain ⟨y, hy⟩ := mem
refine ⟨LinearMap.rTensor M (LinearMap.rangeRestrict _ ∘ₗ LinearMap.rangeRestrict l12) y,
Module.Flat.rTensor_preserves_injective_linearMap (LinearMap.ker l23).subtype
Subtype.val_injective ?_⟩
simp only [LinearMap.comp_codRestrict, LinearMap.rTensor_tmul, Submodule.coe_subtype, ← hy]
rw [← LinearMap.comp_apply, ← LinearMap.rTensor_def, ← LinearMap.rTensor_comp,
← LinearMap.comp_apply, ← LinearMap.rTensor_comp, LinearMap.comp_assoc,
LinearMap.subtype_comp_codRestrict, ← LinearMap.comp_assoc, Submodule.subtype_comp_inclusion,
LinearMap.subtype_comp_codRestrict]
| add x y hx hy =>
obtain ⟨x, rfl⟩ := hx; obtain ⟨y, rfl⟩ := hy
exact ⟨x + y, by simp⟩
lemma lTensor_reflects_exact [fl : FaithfullyFlat R M]
(ex : Function.Exact (l12.lTensor M) (l23.lTensor M)) :
Function.Exact l12 l23 :=
rTensor_reflects_exact R M _ _ <| ex.of_ladder_linearEquiv_of_exact
(e₁ := TensorProduct.comm _ _ _) (e₂ := TensorProduct.comm _ _ _)
(e₃ := TensorProduct.comm _ _ _) (by ext; rfl) (by ext; rfl)
@[simp]
lemma rTensor_exact_iff_exact [FaithfullyFlat R M] :
Function.Exact (l12.rTensor M) (l23.rTensor M) ↔ Function.Exact l12 l23 :=
⟨fun ex ↦ rTensor_reflects_exact R M l12 l23 ex, fun e ↦ Module.Flat.rTensor_exact _ e⟩
@[simp]
lemma lTensor_exact_iff_exact [FaithfullyFlat R M] :
Function.Exact (l12.lTensor M) (l23.lTensor M) ↔ Function.Exact l12 l23 :=
⟨fun ex ↦ lTensor_reflects_exact R M l12 l23 ex, fun e ↦ Module.Flat.lTensor_exact _ e⟩
section
variable {N N' : Type*} [AddCommGroup N] [AddCommGroup N'] [Module R N] [Module R N']
(f : N →ₗ[R] N')
@[simp]
lemma lTensor_injective_iff_injective [Module.FaithfullyFlat R M] :
Function.Injective (f.lTensor M) ↔ Function.Injective f := by
rw [← LinearMap.exact_zero_iff_injective (M ⊗[R] Unit), ← LinearMap.exact_zero_iff_injective Unit]
conv_rhs => rw [← lTensor_exact_iff_exact R M]
simp
@[simp]
lemma lTensor_surjective_iff_surjective [Module.FaithfullyFlat R M] :
Function.Surjective (f.lTensor M) ↔ Function.Surjective f := by
rw [← LinearMap.exact_zero_iff_surjective (M ⊗[R] Unit),
← LinearMap.exact_zero_iff_surjective Unit]
conv_rhs => rw [← lTensor_exact_iff_exact R M]
simp
end
end arbitrary_universe
section fixed_universe
lemma iff_exact_iff_rTensor_exact :
FaithfullyFlat R M ↔
(∀ {N1 : Type max u v} [AddCommGroup N1] [Module R N1]
{N2 : Type max u v} [AddCommGroup N2] [Module R N2]
{N3 : Type max u v} [AddCommGroup N3] [Module R N3]
(l12 : N1 →ₗ[R] N2) (l23 : N2 →ₗ[R] N3),
Function.Exact l12 l23 ↔ Function.Exact (l12.rTensor M) (l23.rTensor M)) :=
⟨fun fl _ _ _ _ _ _ _ _ _ l12 l23 => (rTensor_exact_iff_exact R M l12 l23).symm, fun iff_exact =>
iff_flat_and_rTensor_reflects_triviality _ _ |>.2
⟨Flat.iff_rTensor_exact.2 <| fun _ _ _ => iff_exact .. |>.1,
fun N _ _ h => subsingleton_iff_forall_eq 0 |>.2 <| fun y => by
simpa [eq_comm] using (iff_exact (0 : PUnit →ₗ[R] N) (0 : N →ₗ[R] PUnit) |>.2 fun x => by
simpa using Subsingleton.elim _ _) y⟩⟩
lemma iff_exact_iff_lTensor_exact :
FaithfullyFlat R M ↔
(∀ {N1 : Type max u v} [AddCommGroup N1] [Module R N1]
{N2 : Type max u v} [AddCommGroup N2] [Module R N2]
{N3 : Type max u v} [AddCommGroup N3] [Module R N3]
(l12 : N1 →ₗ[R] N2) (l23 : N2 →ₗ[R] N3),
Function.Exact l12 l23 ↔ Function.Exact (l12.lTensor M) (l23.lTensor M)) := by
simp only [iff_exact_iff_rTensor_exact, LinearMap.rTensor_exact_iff_lTensor_exact]
end fixed_universe
end exact
section linearMap
/-!
### Faithfully flat modules and linear maps
In this section we prove that an `R`-module `M` is faithfully flat iff the following holds:
- `M` is flat
- for any `R`-linear map `f : N → N'`, `f` = 0 iff `f ⊗ 𝟙M = 0` iff `𝟙M ⊗ f = 0`
-/
section arbitrary_universe
/--
If `M` is a faithfully flat module, then for all linear maps `f`, the map `id ⊗ f = 0`, if and only
if `f = 0`. -/
lemma zero_iff_lTensor_zero [h : FaithfullyFlat R M]
{N : Type*} [AddCommGroup N] [Module R N]
{N' : Type*} [AddCommGroup N'] [Module R N'] (f : N →ₗ[R] N') :
f = 0 ↔ LinearMap.lTensor M f = 0 :=
⟨fun hf => hf.symm ▸ LinearMap.lTensor_zero M, fun hf => by
have := lTensor_reflects_exact R M f LinearMap.id (by
rw [LinearMap.exact_iff, hf, LinearMap.range_zero, LinearMap.ker_eq_bot]
apply Module.Flat.lTensor_preserves_injective_linearMap
exact fun _ _ h => h)
ext x; simpa using this (f x)⟩
/--
If `M` is a faithfully flat module, then for all linear maps `f`, the map `f ⊗ id = 0`, if and only
if `f = 0`. -/
lemma zero_iff_rTensor_zero [h: FaithfullyFlat R M]
{N : Type*} [AddCommGroup N] [Module R N]
{N' : Type*} [AddCommGroup N'] [Module R N']
(f : N →ₗ[R] N') :
f = 0 ↔ LinearMap.rTensor M f = 0 :=
zero_iff_lTensor_zero R M f |>.trans
⟨fun h => by ext n m; exact (TensorProduct.comm R N' M).injective <|
(by simpa using congr($h (m ⊗ₜ n))), fun h => by
ext m n; exact (TensorProduct.comm R M N').injective <| (by simpa using congr($h (n ⊗ₜ m)))⟩
/-- If `A` is a faithfully flat `R`-algebra, and `m` is a term of an `R`-module `M`,
then `1 ⊗ₜ[R] m = 0` if and only if `m = 0`. -/
@[simp]
theorem one_tmul_eq_zero_iff {A : Type*} [Ring A] [Algebra R A] [FaithfullyFlat R A] (m : M) :
(1:A) ⊗ₜ[R] m = 0 ↔ m = 0 := by
constructor; swap
· rintro rfl; rw [tmul_zero]
intro h
let f : R →ₗ[R] M := (LinearMap.lsmul R M).flip m
suffices f = 0 by simpa [f] using DFunLike.congr_fun this 1
rw [Module.FaithfullyFlat.zero_iff_lTensor_zero R A]
ext a
apply_fun (a • ·) at h
rw [smul_zero, smul_tmul', smul_eq_mul, mul_one] at h
simpa [f]
end arbitrary_universe
section fixed_universe
/--
An `R`-module `M` is faithfully flat iff it is flat and for all linear maps `f`, the map
`id ⊗ f = 0`, if and only if `f = 0`. -/
lemma iff_zero_iff_lTensor_zero :
FaithfullyFlat R M ↔
(Module.Flat R M ∧
(∀ {N : Type max u v} [AddCommGroup N] [Module R N]
{N' : Type max u v} [AddCommGroup N'] [Module R N']
(f : N →ₗ[R] N'), f.lTensor M = 0 ↔ f = 0)) :=
⟨fun fl => ⟨inferInstance, fun f => zero_iff_lTensor_zero R M f |>.symm⟩,
fun ⟨flat, Z⟩ => iff_flat_and_lTensor_reflects_triviality R M |>.2 ⟨flat, fun N _ _ _ => by
have := Z (LinearMap.id : N →ₗ[R] N) |>.1 (by ext; exact Subsingleton.elim _ _)
rw [subsingleton_iff_forall_eq 0]
exact fun y => congr($this y)⟩⟩
/--
An `R`-module `M` is faithfully flat iff it is flat and for all linear maps `f`, the map
`id ⊗ f = 0`, if and only if `f = 0`. -/
lemma iff_zero_iff_rTensor_zero :
FaithfullyFlat R M ↔
(Module.Flat R M ∧
(∀ {N : Type max u v} [AddCommGroup N] [Module R N]
{N' : Type max u v} [AddCommGroup N'] [Module R N']
(f : N →ₗ[R] N'), f.rTensor M = 0 ↔ (f = 0))) :=
⟨fun fl => ⟨inferInstance, fun f => zero_iff_rTensor_zero R M f |>.symm⟩,
fun ⟨flat, Z⟩ => iff_flat_and_rTensor_reflects_triviality R M |>.2 ⟨flat, fun N _ _ _ => by
have := Z (LinearMap.id : N →ₗ[R] N) |>.1 (by ext; exact Subsingleton.elim _ _)
rw [subsingleton_iff_forall_eq 0]
exact fun y => congr($this y)⟩⟩
end fixed_universe
end linearMap
section trans
open TensorProduct LinearMap
variable (R : Type*) [CommRing R]
variable (S : Type*) [CommRing S] [Algebra R S]
variable (M : Type*) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M]
variable [FaithfullyFlat R S] [FaithfullyFlat S M]
include S in
/-- If `S` is a faithfully flat `R`-algebra, then any faithfully flat `S`-Module is faithfully flat
as an `R`-module. -/
theorem trans : FaithfullyFlat R M := by
rw [iff_zero_iff_lTensor_zero]
refine ⟨Module.Flat.trans R S M, @fun N _ _ N' _ _ f => ⟨fun aux => ?_, fun eq => eq ▸ by simp⟩⟩
rw [zero_iff_lTensor_zero (R:= R) (M := S) f,
show f.lTensor S = (AlgebraTensorModule.map (A:= S) LinearMap.id f).restrictScalars R by aesop,
show (0 : S ⊗[R] N →ₗ[R] S ⊗[R] N') = (0 : S ⊗[R] N →ₗ[S] S ⊗[R] N').restrictScalars R by rfl,
restrictScalars_inj, zero_iff_lTensor_zero (R:= S) (M := M)]
ext m n
apply_fun AlgebraTensorModule.cancelBaseChange R S S M N' using LinearEquiv.injective _
simpa using congr($aux (m ⊗ₜ[R] n))
end trans
/-- Faithful flatness is preserved by arbitrary base change. -/
instance (S : Type*) [CommRing S] [Algebra R S] [Module.FaithfullyFlat R M] :
Module.FaithfullyFlat S (S ⊗[R] M) := by
rw [Module.FaithfullyFlat.iff_flat_and_rTensor_reflects_triviality]
refine ⟨inferInstance, fun N _ _ hN ↦ ?_⟩
let _ : Module R N := Module.compHom N (algebraMap R S)
have : IsScalarTower R S N := IsScalarTower.of_algebraMap_smul fun r ↦ congrFun rfl
have := (AlgebraTensorModule.cancelBaseChange R S S N M).symm.subsingleton
exact FaithfullyFlat.rTensor_reflects_triviality R M N
end FaithfullyFlat
/-- Flat descends along faithfully flat ring maps. -/
lemma Flat.of_flat_tensorProduct (S : Type*) [CommRing S] [Algebra R S]
[Module.FaithfullyFlat R S] [Module.Flat S (S ⊗[R] M)] : Module.Flat R M := by
rw [Module.Flat.iff_lTensor_preserves_injective_linearMap]
intro N P _ _ _ _ f hf
have : Flat R (S ⊗[R] M) := Flat.trans _ S _
rw [← FaithfullyFlat.lTensor_injective_iff_injective R S]
have : LinearMap.lTensor S (LinearMap.lTensor M f) =
(TensorProduct.assoc _ _ _ _).toLinearMap ∘ₗ LinearMap.lTensor (S ⊗[R] M) f ∘ₗ
(TensorProduct.assoc _ _ _ _).symm.toLinearMap := by
ext
simp
simpa [this] using Flat.lTensor_preserves_injective_linearMap f hf
lemma Flat.iff_flat_tensorProduct (S : Type*) [CommRing S] [Algebra R S]
[Module.FaithfullyFlat R S] : Module.Flat S (S ⊗[R] M) ↔ Module.Flat R M :=
⟨fun _ ↦ .of_flat_tensorProduct R M S, fun _ ↦ inferInstance⟩
end Module
|
Equivs.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.DualNumber
import Mathlib.Algebra.QuaternionBasis
import Mathlib.Data.Complex.Module
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.CliffordAlgebra.Star
import Mathlib.LinearAlgebra.QuadraticForm.Prod
/-!
# Other constructions isomorphic to Clifford Algebras
This file contains isomorphisms showing that other types are equivalent to some `CliffordAlgebra`.
## Rings
* `CliffordAlgebraRing.equiv`: any ring is equivalent to a `CliffordAlgebra` over a
zero-dimensional vector space.
## Complex numbers
* `CliffordAlgebraComplex.equiv`: the `Complex` numbers are equivalent as an `ℝ`-algebra to a
`CliffordAlgebra` over a one-dimensional vector space with a quadratic form that satisfies
`Q (ι Q 1) = -1`.
* `CliffordAlgebraComplex.toComplex`: the forward direction of this equiv
* `CliffordAlgebraComplex.ofComplex`: the reverse direction of this equiv
We show additionally that this equivalence sends `Complex.conj` to `CliffordAlgebra.involute` and
vice-versa:
* `CliffordAlgebraComplex.toComplex_involute`
* `CliffordAlgebraComplex.ofComplex_conj`
Note that in this algebra `CliffordAlgebra.reverse` is the identity and so the clifford conjugate
is the same as `CliffordAlgebra.involute`.
## Quaternion algebras
* `CliffordAlgebraQuaternion.equiv`: a `QuaternionAlgebra` over `R` is equivalent as an
`R`-algebra to a clifford algebra over `R × R`, sending `i` to `(0, 1)` and `j` to `(1, 0)`.
* `CliffordAlgebraQuaternion.toQuaternion`: the forward direction of this equiv
* `CliffordAlgebraQuaternion.ofQuaternion`: the reverse direction of this equiv
We show additionally that this equivalence sends `QuaternionAlgebra.conj` to the clifford conjugate
and vice-versa:
* `CliffordAlgebraQuaternion.toQuaternion_star`
* `CliffordAlgebraQuaternion.ofQuaternion_star`
## Dual numbers
* `CliffordAlgebraDualNumber.equiv`: `R[ε]` is equivalent as an `R`-algebra to a clifford
algebra over `R` where `Q = 0`.
-/
open CliffordAlgebra
/-! ### The clifford algebra isomorphic to a ring -/
namespace CliffordAlgebraRing
open scoped ComplexConjugate
variable {R : Type*} [CommRing R]
@[simp]
theorem ι_eq_zero : ι (0 : QuadraticForm R Unit) = 0 :=
Subsingleton.elim _ _
/-- Since the vector space is empty the ring is commutative. -/
instance : CommRing (CliffordAlgebra (0 : QuadraticForm R Unit)) where
mul_comm := fun x y => by
induction x using CliffordAlgebra.induction with
| algebraMap r => apply Algebra.commutes
| ι x => simp
| add x₁ x₂ hx₁ hx₂ => rw [mul_add, add_mul, hx₁, hx₂]
| mul x₁ x₂ hx₁ hx₂ => rw [mul_assoc, hx₂, ← mul_assoc, hx₁, ← mul_assoc]
theorem reverse_apply (x : CliffordAlgebra (0 : QuadraticForm R Unit)) :
x.reverse = x := by
induction x using CliffordAlgebra.induction with
| algebraMap r => exact reverse.commutes _
| ι x => rw [ι_eq_zero, LinearMap.zero_apply, reverse.map_zero]
| mul x₁ x₂ hx₁ hx₂ => rw [reverse.map_mul, mul_comm, hx₁, hx₂]
| add x₁ x₂ hx₁ hx₂ => rw [reverse.map_add, hx₁, hx₂]
@[simp]
theorem reverse_eq_id :
(reverse : CliffordAlgebra (0 : QuadraticForm R Unit) →ₗ[R] _) = LinearMap.id :=
LinearMap.ext reverse_apply
@[simp]
theorem involute_eq_id :
(involute : CliffordAlgebra (0 : QuadraticForm R Unit) →ₐ[R] _) = AlgHom.id R _ := by ext; simp
/-- The clifford algebra over a 0-dimensional vector space is isomorphic to its scalars. -/
protected def equiv : CliffordAlgebra (0 : QuadraticForm R Unit) ≃ₐ[R] R :=
AlgEquiv.ofAlgHom
(CliffordAlgebra.lift (0 : QuadraticForm R Unit) <|
⟨0, fun _ : Unit => (zero_mul (0 : R)).trans (algebraMap R _).map_zero.symm⟩)
(Algebra.ofId R _) (by ext)
(by ext : 1; rw [ι_eq_zero, LinearMap.comp_zero, LinearMap.comp_zero])
end CliffordAlgebraRing
/-! ### The clifford algebra isomorphic to the complex numbers -/
namespace CliffordAlgebraComplex
open scoped ComplexConjugate
/-- The quadratic form sending elements to the negation of their square. -/
def Q : QuadraticForm ℝ ℝ :=
-QuadraticMap.sq
@[simp]
theorem Q_apply (r : ℝ) : Q r = -(r * r) :=
rfl
/-- Intermediate result for `CliffordAlgebraComplex.equiv`: clifford algebras over
`CliffordAlgebraComplex.Q` above can be converted to `ℂ`. -/
def toComplex : CliffordAlgebra Q →ₐ[ℝ] ℂ :=
CliffordAlgebra.lift Q
⟨LinearMap.toSpanSingleton _ _ Complex.I, fun r => by
dsimp [LinearMap.toSpanSingleton, LinearMap.id]
rw [mul_mul_mul_comm]
simp⟩
@[simp]
theorem toComplex_ι (r : ℝ) : toComplex (ι Q r) = r • Complex.I :=
CliffordAlgebra.lift_ι_apply _ _ r
/-- `CliffordAlgebra.involute` is analogous to `Complex.conj`. -/
@[simp]
theorem toComplex_involute (c : CliffordAlgebra Q) :
toComplex (involute c) = conj (toComplex c) := by
have : toComplex (involute (ι Q 1)) = conj (toComplex (ι Q 1)) := by
simp only [involute_ι, toComplex_ι, map_neg, one_smul, Complex.conj_I]
suffices toComplex.comp involute = Complex.conjAe.toAlgHom.comp toComplex by
exact AlgHom.congr_fun this c
ext : 2
exact this
/-- Intermediate result for `CliffordAlgebraComplex.equiv`: `ℂ` can be converted to
`CliffordAlgebraComplex.Q` above can be converted to. -/
def ofComplex : ℂ →ₐ[ℝ] CliffordAlgebra Q :=
Complex.lift
⟨CliffordAlgebra.ι Q 1, by
rw [CliffordAlgebra.ι_sq_scalar, Q_apply, one_mul, RingHom.map_neg, RingHom.map_one]⟩
@[simp]
theorem ofComplex_I : ofComplex Complex.I = ι Q 1 :=
Complex.liftAux_apply_I _ (by simp)
@[simp]
theorem toComplex_comp_ofComplex : toComplex.comp ofComplex = AlgHom.id ℝ ℂ := by
ext1
dsimp only [AlgHom.comp_apply, Subtype.coe_mk, AlgHom.id_apply]
rw [ofComplex_I, toComplex_ι, one_smul]
@[simp]
theorem toComplex_ofComplex (c : ℂ) : toComplex (ofComplex c) = c :=
AlgHom.congr_fun toComplex_comp_ofComplex c
@[simp]
theorem ofComplex_comp_toComplex : ofComplex.comp toComplex = AlgHom.id ℝ (CliffordAlgebra Q) := by
ext
dsimp only [LinearMap.comp_apply, Subtype.coe_mk, AlgHom.id_apply, AlgHom.toLinearMap_apply,
AlgHom.comp_apply]
rw [toComplex_ι, one_smul, ofComplex_I]
@[simp]
theorem ofComplex_toComplex (c : CliffordAlgebra Q) : ofComplex (toComplex c) = c :=
AlgHom.congr_fun ofComplex_comp_toComplex c
/-- The clifford algebras over `CliffordAlgebraComplex.Q` is isomorphic as an `ℝ`-algebra to `ℂ`. -/
@[simps!]
protected def equiv : CliffordAlgebra Q ≃ₐ[ℝ] ℂ :=
AlgEquiv.ofAlgHom toComplex ofComplex toComplex_comp_ofComplex ofComplex_comp_toComplex
/-- The clifford algebra is commutative since it is isomorphic to the complex numbers.
TODO: prove this is true for all `CliffordAlgebra`s over a 1-dimensional vector space. -/
instance : CommRing (CliffordAlgebra Q) where
mul_comm := fun x y =>
CliffordAlgebraComplex.equiv.injective <| by
rw [map_mul, mul_comm, map_mul]
/-- `reverse` is a no-op over `CliffordAlgebraComplex.Q`. -/
theorem reverse_apply (x : CliffordAlgebra Q) : x.reverse = x := by
induction x using CliffordAlgebra.induction with
| algebraMap r => exact reverse.commutes _
| ι x => rw [reverse_ι]
| mul x₁ x₂ hx₁ hx₂ => rw [reverse.map_mul, mul_comm, hx₁, hx₂]
| add x₁ x₂ hx₁ hx₂ => rw [reverse.map_add, hx₁, hx₂]
@[simp]
theorem reverse_eq_id : (reverse : CliffordAlgebra Q →ₗ[ℝ] _) = LinearMap.id :=
LinearMap.ext reverse_apply
/-- `Complex.conj` is analogous to `CliffordAlgebra.involute`. -/
@[simp]
theorem ofComplex_conj (c : ℂ) : ofComplex (conj c) = involute (ofComplex c) :=
CliffordAlgebraComplex.equiv.injective <| by
rw [equiv_apply, equiv_apply, toComplex_involute, toComplex_ofComplex, toComplex_ofComplex]
end CliffordAlgebraComplex
/-! ### The clifford algebra isomorphic to the quaternions -/
namespace CliffordAlgebraQuaternion
open scoped Quaternion
open QuaternionAlgebra
variable {R : Type*} [CommRing R] (c₁ c₂ : R)
/-- `Q c₁ c₂` is a quadratic form over `R × R` such that `CliffordAlgebra (Q c₁ c₂)` is isomorphic
as an `R`-algebra to `ℍ[R,c₁,c₂]`. -/
def Q : QuadraticForm R (R × R) :=
(c₁ • QuadraticMap.sq).prod (c₂ • QuadraticMap.sq)
@[simp]
theorem Q_apply (v : R × R) : Q c₁ c₂ v = c₁ * (v.1 * v.1) + c₂ * (v.2 * v.2) :=
rfl
/-- The quaternion basis vectors within the algebra. -/
@[simps i j k]
def quaternionBasis : QuaternionAlgebra.Basis (CliffordAlgebra (Q c₁ c₂)) c₁ 0 c₂ where
i := ι (Q c₁ c₂) (1, 0)
j := ι (Q c₁ c₂) (0, 1)
k := ι (Q c₁ c₂) (1, 0) * ι (Q c₁ c₂) (0, 1)
i_mul_i := by
rw [ι_sq_scalar, Q_apply, ← Algebra.algebraMap_eq_smul_one]
simp
j_mul_j := by
rw [ι_sq_scalar, Q_apply, ← Algebra.algebraMap_eq_smul_one]
simp
i_mul_j := rfl
j_mul_i := by
rw [zero_smul, zero_sub, eq_neg_iff_add_eq_zero, ι_mul_ι_add_swap, QuadraticMap.polar]
simp
variable {c₁ c₂}
/-- Intermediate result of `CliffordAlgebraQuaternion.equiv`: clifford algebras over
`CliffordAlgebraQuaternion.Q` can be converted to `ℍ[R,c₁,c₂]`. -/
def toQuaternion : CliffordAlgebra (Q c₁ c₂) →ₐ[R] ℍ[R,c₁,0,c₂] :=
CliffordAlgebra.lift (Q c₁ c₂)
⟨{ toFun := fun v => (⟨0, v.1, v.2, 0⟩ : ℍ[R,c₁,0,c₂])
map_add' := fun v₁ v₂ => by simp
map_smul' := fun r v => by dsimp; rw [mul_zero] }, fun v => by
dsimp
ext
all_goals dsimp; ring⟩
@[simp]
theorem toQuaternion_ι (v : R × R) :
toQuaternion (ι (Q c₁ c₂) v) = (⟨0, v.1, v.2, 0⟩ : ℍ[R,c₁,0,c₂]) :=
CliffordAlgebra.lift_ι_apply _ _ v
/-- The "clifford conjugate" maps to the quaternion conjugate. -/
theorem toQuaternion_star (c : CliffordAlgebra (Q c₁ c₂)) :
toQuaternion (star c) = star (toQuaternion c) := by
simp only [CliffordAlgebra.star_def']
induction c using CliffordAlgebra.induction with
| algebraMap r => simp
| ι x => simp
| mul x₁ x₂ hx₁ hx₂ => simp [hx₁, hx₂]
| add x₁ x₂ hx₁ hx₂ => simp [hx₁, hx₂]
/-- Map a quaternion into the clifford algebra. -/
def ofQuaternion : ℍ[R,c₁,0,c₂] →ₐ[R] CliffordAlgebra (Q c₁ c₂) :=
(quaternionBasis c₁ c₂).liftHom
@[simp]
theorem ofQuaternion_mk (a₁ a₂ a₃ a₄ : R) :
ofQuaternion (⟨a₁, a₂, a₃, a₄⟩ : ℍ[R,c₁,0,c₂]) =
algebraMap R _ a₁ + a₂ • ι (Q c₁ c₂) (1, 0) + a₃ • ι (Q c₁ c₂) (0, 1) +
a₄ • (ι (Q c₁ c₂) (1, 0) * ι (Q c₁ c₂) (0, 1)) :=
rfl
@[simp]
theorem ofQuaternion_comp_toQuaternion :
ofQuaternion.comp toQuaternion = AlgHom.id R (CliffordAlgebra (Q c₁ c₂)) := by
ext : 1
dsimp -- before we end up with two goals and have to do this twice
ext
all_goals
dsimp
rw [toQuaternion_ι]
dsimp
simp only [zero_smul, one_smul, zero_add, add_zero, RingHom.map_zero]
@[simp]
theorem ofQuaternion_toQuaternion (c : CliffordAlgebra (Q c₁ c₂)) :
ofQuaternion (toQuaternion c) = c :=
AlgHom.congr_fun ofQuaternion_comp_toQuaternion c
@[simp]
theorem toQuaternion_comp_ofQuaternion :
toQuaternion.comp ofQuaternion = AlgHom.id R ℍ[R,c₁,0,c₂] := by
ext : 1 <;> simp
@[simp]
theorem toQuaternion_ofQuaternion (q : ℍ[R,c₁,0,c₂]) : toQuaternion (ofQuaternion q) = q :=
AlgHom.congr_fun toQuaternion_comp_ofQuaternion q
/-- The clifford algebra over `CliffordAlgebraQuaternion.Q c₁ c₂` is isomorphic as an `R`-algebra
to `ℍ[R,c₁,c₂]`. -/
@[simps!]
protected def equiv : CliffordAlgebra (Q c₁ c₂) ≃ₐ[R] ℍ[R,c₁,0,c₂] :=
AlgEquiv.ofAlgHom toQuaternion ofQuaternion toQuaternion_comp_ofQuaternion
ofQuaternion_comp_toQuaternion
/-- The quaternion conjugate maps to the "clifford conjugate" (aka `star`). -/
@[simp]
theorem ofQuaternion_star (q : ℍ[R,c₁,0,c₂]) : ofQuaternion (star q) = star (ofQuaternion q) :=
CliffordAlgebraQuaternion.equiv.injective <| by
rw [equiv_apply, equiv_apply, toQuaternion_star, toQuaternion_ofQuaternion,
toQuaternion_ofQuaternion]
end CliffordAlgebraQuaternion
/-! ### The clifford algebra isomorphic to the dual numbers -/
namespace CliffordAlgebraDualNumber
open scoped DualNumber
open DualNumber TrivSqZeroExt
variable {R : Type*} [CommRing R]
theorem ι_mul_ι (r₁ r₂) : ι (0 : QuadraticForm R R) r₁ * ι (0 : QuadraticForm R R) r₂ = 0 := by
rw [← mul_one r₁, ← mul_one r₂, ← smul_eq_mul r₁, ← smul_eq_mul r₂, LinearMap.map_smul,
LinearMap.map_smul, smul_mul_smul_comm, ι_sq_scalar, QuadraticMap.zero_apply, RingHom.map_zero,
smul_zero]
/-- The clifford algebra over a 1-dimensional vector space with 0 quadratic form is isomorphic to
the dual numbers. -/
protected def equiv : CliffordAlgebra (0 : QuadraticForm R R) ≃ₐ[R] R[ε] :=
AlgEquiv.ofAlgHom
(CliffordAlgebra.lift (0 : QuadraticForm R R) ⟨inrHom R _, fun m => inr_mul_inr _ m m⟩)
(DualNumber.lift ⟨
(Algebra.ofId _ _, ι (R := R) _ 1),
ι_mul_ι (1 : R) 1,
fun _ => (Algebra.commutes _ _).symm⟩)
(by
ext : 1
-- This used to be a single `simp` before https://github.com/leanprover/lean4/pull/2644
simp only [QuadraticMap.zero_apply, AlgHom.coe_comp, Function.comp_apply, lift_apply_eps,
AlgHom.coe_id, id_eq]
erw [lift_ι_apply]
simp)
-- This used to be a single `simp` before https://github.com/leanprover/lean4/pull/2644
(by
ext : 2
simp only [QuadraticMap.zero_apply, AlgHom.comp_toLinearMap, LinearMap.coe_comp,
Function.comp_apply, AlgHom.toLinearMap_apply, AlgHom.toLinearMap_id, LinearMap.id_comp]
erw [lift_ι_apply]
simp)
@[simp]
theorem equiv_ι (r : R) : CliffordAlgebraDualNumber.equiv (ι (R := R) _ r) = r • ε :=
(lift_ι_apply _ _ r).trans (inr_eq_smul_eps _)
@[simp]
theorem equiv_symm_eps :
CliffordAlgebraDualNumber.equiv.symm (eps : R[ε]) = ι (0 : QuadraticForm R R) 1 :=
DualNumber.lift_apply_eps _
end CliffordAlgebraDualNumber
|
Sl2.lean
|
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.OfAssociative
import Mathlib.LinearAlgebra.Eigenspace.Basic
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
/-!
# The Lie algebra `sl₂` and its representations
The Lie algebra `sl₂` is the unique simple Lie algebra of minimal rank, 1, and as such occupies a
distinguished position in the general theory. This file provides some basic definitions and results
about `sl₂`.
## Main definitions:
* `IsSl2Triple`: a structure representing a triple of elements in a Lie algebra which satisfy the
standard relations for `sl₂`.
* `IsSl2Triple.HasPrimitiveVectorWith`: a structure representing a primitive vector in a
representation of a Lie algebra relative to a distinguished `sl₂` triple.
* `IsSl2Triple.HasPrimitiveVectorWith.exists_nat`: the eigenvalue of a primitive vector must be a
natural number if the representation is finite-dimensional.
-/
variable (R L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
open LieModule Set
variable {L} in
/-- An `sl₂` triple within a Lie ring `L` is a triple of elements `h`, `e`, `f` obeying relations
which ensure that the Lie subalgebra they generate is equivalent to `sl₂`. -/
structure IsSl2Triple (h e f : L) : Prop where
h_ne_zero : h ≠ 0
lie_e_f : ⁅e, f⁆ = h
lie_h_e_nsmul : ⁅h, e⁆ = 2 • e
lie_h_f_nsmul : ⁅h, f⁆ = - (2 • f)
namespace IsSl2Triple
variable {L M}
variable {h e f : L}
lemma symm (ht : IsSl2Triple h e f) : IsSl2Triple (-h) f e where
h_ne_zero := by simpa using ht.h_ne_zero
lie_e_f := by rw [← neg_eq_iff_eq_neg, lie_skew, ht.lie_e_f]
lie_h_e_nsmul := by rw [neg_lie, neg_eq_iff_eq_neg, ht.lie_h_f_nsmul]
lie_h_f_nsmul := by rw [neg_lie, neg_inj, ht.lie_h_e_nsmul]
@[simp] lemma symm_iff : IsSl2Triple (-h) f e ↔ IsSl2Triple h e f :=
⟨fun t ↦ neg_neg h ▸ t.symm, symm⟩
lemma lie_h_e_smul (t : IsSl2Triple h e f) : ⁅h, e⁆ = (2 : R) • e := by
simp [t.lie_h_e_nsmul, two_smul]
lemma lie_lie_smul_f (t : IsSl2Triple h e f) : ⁅h, f⁆ = -((2 : R) • f) := by
simp [t.lie_h_f_nsmul, two_smul]
lemma e_ne_zero (t : IsSl2Triple h e f) : e ≠ 0 := by
have := t.h_ne_zero
contrapose! this
simpa [this] using t.lie_e_f.symm
lemma f_ne_zero (t : IsSl2Triple h e f) : f ≠ 0 := by
have := t.h_ne_zero
contrapose! this
simpa [this] using t.lie_e_f.symm
variable {R}
/-- Given a representation of a Lie algebra with distinguished `sl₂` triple, a vector is said to be
primitive if it is a simultaneous eigenvector for the action of both `h`, `e`, and the eigenvalue
for `e` is zero. -/
structure HasPrimitiveVectorWith (t : IsSl2Triple h e f) (m : M) (μ : R) : Prop where
ne_zero : m ≠ 0
lie_h : ⁅h, m⁆ = μ • m
lie_e : ⁅e, m⁆ = 0
/-- Given a representation of a Lie algebra with distinguished `sl₂` triple, a simultaneous
eigenvector for the action of both `h` and `e` necessarily has eigenvalue zero for `e`. -/
lemma HasPrimitiveVectorWith.mk' [NoZeroSMulDivisors ℤ M] (t : IsSl2Triple h e f) (m : M) (μ ρ : R)
(hm : m ≠ 0) (hm' : ⁅h, m⁆ = μ • m) (he : ⁅e, m⁆ = ρ • m) :
HasPrimitiveVectorWith t m μ where
ne_zero := hm
lie_h := hm'
lie_e := by
suffices 2 • ⁅e, m⁆ = 0 by simpa using this
rw [← nsmul_lie, ← t.lie_h_e_nsmul, lie_lie, hm', lie_smul, he, lie_smul, hm',
smul_smul, smul_smul, mul_comm ρ μ, sub_self]
variable (R) in
open Submodule in
/-- The subalgebra associated to an `sl₂` triple. -/
def toLieSubalgebra (t : IsSl2Triple h e f) :
LieSubalgebra R L where
__ := span R {e, f, h}
lie_mem' {x y} hx hy := by
simp only [carrier_eq_coe, SetLike.mem_coe] at hx hy ⊢
induction hx using span_induction with
| zero => simp
| add u v hu hv hu' hv' => simpa only [add_lie] using add_mem hu' hv'
| smul t u hu hu' => simpa only [smul_lie] using smul_mem _ t hu'
| mem u hu =>
induction hy using span_induction with
| zero => simp
| add u v hu hv hu' hv' => simpa only [lie_add] using add_mem hu' hv'
| smul t u hv hv' => simpa only [lie_smul] using smul_mem _ t hv'
| mem v hv =>
simp only [mem_insert_iff, mem_singleton_iff] at hu hv
rcases hu with rfl | rfl | rfl <;>
rcases hv with rfl | rfl | rfl <;> (try simp only [lie_self, zero_mem])
· rw [t.lie_e_f]
apply subset_span
simp
· rw [← lie_skew, t.lie_h_e_nsmul, neg_mem_iff]
apply nsmul_mem <| subset_span _
simp
· rw [← lie_skew, t.lie_e_f, neg_mem_iff]
apply subset_span
simp
· rw [← lie_skew, t.lie_h_f_nsmul, neg_neg]
apply nsmul_mem <| subset_span _
simp
· rw [t.lie_h_e_nsmul]
apply nsmul_mem <| subset_span _
simp
· rw [t.lie_h_f_nsmul, neg_mem_iff]
apply nsmul_mem <| subset_span _
simp
lemma mem_toLieSubalgebra_iff {x : L} {t : IsSl2Triple h e f} :
x ∈ t.toLieSubalgebra R ↔ ∃ c₁ c₂ c₃ : R, x = c₁ • e + c₂ • f + c₃ • ⁅e, f⁆ := by
simp_rw [t.lie_e_f, toLieSubalgebra, ← LieSubalgebra.mem_toSubmodule, Submodule.mem_span_triple,
eq_comm]
namespace HasPrimitiveVectorWith
variable {m : M} {μ : R} {t : IsSl2Triple h e f}
local notation "ψ" n => ((toEnd R L M f) ^ n) m
-- Although this is true by definition, we include this lemma (and the assumption) to mirror the API
-- for `lie_h_pow_toEnd_f` and `lie_e_pow_succ_toEnd_f`.
set_option linter.unusedVariables false in
@[nolint unusedArguments]
lemma lie_f_pow_toEnd_f (P : HasPrimitiveVectorWith t m μ) (n : ℕ) :
⁅f, ψ n⁆ = ψ (n + 1) := by
simp [pow_succ']
variable (P : HasPrimitiveVectorWith t m μ)
include P
lemma lie_h_pow_toEnd_f (n : ℕ) :
⁅h, ψ n⁆ = (μ - 2 * n) • ψ n := by
induction n with
| zero => simpa using P.lie_h
| succ n ih =>
rw [pow_succ', Module.End.mul_apply, toEnd_apply_apply, Nat.cast_add, Nat.cast_one,
leibniz_lie h, t.lie_lie_smul_f R, ← neg_smul, ih, lie_smul, smul_lie, ← add_smul]
congr
ring
lemma lie_e_pow_succ_toEnd_f (n : ℕ) :
⁅e, ψ (n + 1)⁆ = ((n + 1) * (μ - n)) • ψ n := by
induction n with
| zero =>
simp only [zero_add, pow_one, toEnd_apply_apply, Nat.cast_zero, sub_zero, one_mul,
pow_zero, Module.End.one_apply, leibniz_lie e, t.lie_e_f, P.lie_e, P.lie_h, lie_zero,
add_zero]
| succ n ih =>
rw [pow_succ', Module.End.mul_apply, toEnd_apply_apply, leibniz_lie e, t.lie_e_f,
lie_h_pow_toEnd_f P, ih, lie_smul, lie_f_pow_toEnd_f P, ← add_smul,
Nat.cast_add, Nat.cast_one]
congr
ring
/-- The eigenvalue of a primitive vector must be a natural number if the representation is
finite-dimensional. -/
lemma exists_nat [IsNoetherian R M] [NoZeroSMulDivisors R M] [IsDomain R] [CharZero R] :
∃ n : ℕ, μ = n := by
suffices ∃ n : ℕ, (ψ n) = 0 by
obtain ⟨n, hn₁, hn₂⟩ := Nat.exists_not_and_succ_of_not_zero_of_exists P.ne_zero this
refine ⟨n, ?_⟩
have := lie_e_pow_succ_toEnd_f P n
rw [hn₂, lie_zero, eq_comm, smul_eq_zero_iff_left hn₁, mul_eq_zero, sub_eq_zero] at this
exact this.resolve_left <| Nat.cast_add_one_ne_zero n
have hs : (range <| fun (n : ℕ) ↦ μ - 2 * n).Infinite := by
rw [infinite_range_iff (fun n m ↦ by simp)]; infer_instance
by_contra! contra
exact hs ((toEnd R L M h).eigenvectors_linearIndependent
{μ - 2 * n | n : ℕ}
(fun ⟨s, hs⟩ ↦ ψ Classical.choose hs)
(fun ⟨r, hr⟩ ↦ by simp [lie_h_pow_toEnd_f P, Classical.choose_spec hr, contra,
Module.End.hasEigenvector_iff])).finite
lemma pow_toEnd_f_ne_zero_of_eq_nat
[CharZero R] [NoZeroSMulDivisors R M]
{n : ℕ} (hn : μ = n) {i} (hi : i ≤ n) : (ψ i) ≠ 0 := by
intro H
induction i
· exact P.ne_zero (by simpa using H)
· next i IH =>
have : ((i + 1) * (n - i) : ℤ) • (toEnd R L M f ^ i) m = 0 := by
have := congr_arg (⁅e, ·⁆) H
simpa [← Int.cast_smul_eq_zsmul R, P.lie_e_pow_succ_toEnd_f, hn] using this
rw [← Int.cast_smul_eq_zsmul R, smul_eq_zero, Int.cast_eq_zero, mul_eq_zero, sub_eq_zero,
Nat.cast_inj, ← @Nat.cast_one ℤ, ← Nat.cast_add, Nat.cast_eq_zero] at this
simp only [add_eq_zero, one_ne_zero, and_false, false_or] at this
exact (hi.trans_eq (this.resolve_right (IH (i.le_succ.trans hi)))).not_gt i.lt_succ_self
lemma pow_toEnd_f_eq_zero_of_eq_nat
[IsNoetherian R M] [NoZeroSMulDivisors R M] [IsDomain R] [CharZero R]
{n : ℕ} (hn : μ = n) : (ψ (n + 1)) = 0 := by
by_contra h
have : t.HasPrimitiveVectorWith (ψ (n + 1)) (n - 2 * (n + 1) : R) :=
{ ne_zero := h
lie_h := (P.lie_h_pow_toEnd_f _).trans (by simp [hn])
lie_e := (P.lie_e_pow_succ_toEnd_f _).trans (by simp [hn]) }
obtain ⟨m, hm⟩ := this.exists_nat
have : (n : ℤ) < m + 2 * (n + 1) := by omega
exact this.ne (Int.cast_injective (α := R) <| by simpa [sub_eq_iff_eq_add] using hm)
end HasPrimitiveVectorWith
end IsSl2Triple
|
LiouvilleNumber.lean
|
/-
Copyright (c) 2020 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Jujian Zhang
-/
import Mathlib.NumberTheory.Transcendental.Liouville.Basic
/-!
# Liouville constants
This file contains a construction of a family of Liouville numbers, indexed by a natural number $m$.
The most important property is that they are examples of transcendental real numbers.
This fact is recorded in `transcendental_liouvilleNumber`.
More precisely, for a real number $m$, Liouville's constant is
$$
\sum_{i=0}^\infty\frac{1}{m^{i!}}.
$$
The series converges only for $1 < m$. However, there is no restriction on $m$, since,
if the series does not converge, then the sum of the series is defined to be zero.
We prove that, for $m \in \mathbb{N}$ satisfying $2 \le m$, Liouville's constant associated to $m$
is a transcendental number. Classically, the Liouville number for $m = 2$ is the one called
``Liouville's constant''.
## Implementation notes
The indexing $m$ is eventually a natural number satisfying $2 ≤ m$. However, we prove the first few
lemmas for $m \in \mathbb{R}$.
-/
noncomputable section
open scoped Nat
open Real Finset
/-- For a real number `m`, Liouville's constant is
$$
\sum_{i=0}^\infty\frac{1}{m^{i!}}.
$$
The series converges only for `1 < m`. However, there is no restriction on `m`, since,
if the series does not converge, then the sum of the series is defined to be zero.
-/
def liouvilleNumber (m : ℝ) : ℝ :=
∑' i : ℕ, 1 / m ^ i !
namespace LiouvilleNumber
/-- `LiouvilleNumber.partialSum` is the sum of the first `k + 1` terms of Liouville's constant,
i.e.
$$
\sum_{i=0}^k\frac{1}{m^{i!}}.
$$
-/
def partialSum (m : ℝ) (k : ℕ) : ℝ :=
∑ i ∈ range (k + 1), 1 / m ^ i !
/-- `LiouvilleNumber.remainder` is the sum of the series of the terms in `liouvilleNumber m`
starting from `k+1`, i.e
$$
\sum_{i=k+1}^\infty\frac{1}{m^{i!}}.
$$
-/
def remainder (m : ℝ) (k : ℕ) : ℝ :=
∑' i, 1 / m ^ (i + (k + 1))!
/-!
We start with simple observations.
-/
protected theorem summable {m : ℝ} (hm : 1 < m) : Summable fun i : ℕ => 1 / m ^ i ! :=
summable_one_div_pow_of_le hm Nat.self_le_factorial
theorem remainder_summable {m : ℝ} (hm : 1 < m) (k : ℕ) :
Summable fun i : ℕ => 1 / m ^ (i + (k + 1))! := by
convert (summable_nat_add_iff (k + 1)).2 (LiouvilleNumber.summable hm)
theorem remainder_pos {m : ℝ} (hm : 1 < m) (k : ℕ) : 0 < remainder m k :=
(remainder_summable hm k).tsum_pos (fun _ => by positivity) 0 (by positivity)
theorem partialSum_succ (m : ℝ) (n : ℕ) :
partialSum m (n + 1) = partialSum m n + 1 / m ^ (n + 1)! :=
sum_range_succ _ _
/-- Split the sum defining a Liouville number into the first `k` terms and the rest. -/
theorem partialSum_add_remainder {m : ℝ} (hm : 1 < m) (k : ℕ) :
partialSum m k + remainder m k = liouvilleNumber m :=
(LiouvilleNumber.summable hm).sum_add_tsum_nat_add _
/-! We now prove two useful inequalities, before collecting everything together. -/
/-- An upper estimate on the remainder. This estimate works with `m ∈ ℝ` satisfying `1 < m` and is
stronger than the estimate `LiouvilleNumber.remainder_lt` below. However, the latter estimate is
more useful for the proof. -/
theorem remainder_lt' (n : ℕ) {m : ℝ} (m1 : 1 < m) :
remainder m n < (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) :=
-- two useful inequalities
have m0 : 0 < m := zero_lt_one.trans m1
have mi : 1 / m < 1 := (div_lt_one m0).mpr m1
-- to show the strict inequality between these series, we prove that:
calc
(∑' i, 1 / m ^ (i + (n + 1))!) < ∑' i, 1 / m ^ (i + (n + 1)!) :=
-- 1. the second series dominates the first
Summable.tsum_lt_tsum (fun b => one_div_pow_le_one_div_pow_of_le m1.le
(b.add_factorial_succ_le_factorial_add_succ n))
-- 2. the term with index `i = 2` of the first series is strictly smaller than
-- the corresponding term of the second series
(one_div_pow_strictAnti m1 (n.add_factorial_succ_lt_factorial_add_succ (i := 2) le_rfl))
-- 3. the first series is summable
(remainder_summable m1 n)
-- 4. the second series is summable, since its terms grow quickly
(summable_one_div_pow_of_le m1 fun _ => le_self_add)
-- split the sum in the exponent and massage
_ = ∑' i : ℕ, (1 / m) ^ i * (1 / m ^ (n + 1)!) := by
simp only [pow_add, one_div, mul_inv, inv_pow]
-- factor the constant `(1 / m ^ (n + 1)!)` out of the series
_ = (∑' i, (1 / m) ^ i) * (1 / m ^ (n + 1)!) := tsum_mul_right
-- the series is the geometric series
_ = (1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) := by rw [tsum_geometric_of_lt_one (by positivity) mi]
theorem aux_calc (n : ℕ) {m : ℝ} (hm : 2 ≤ m) :
(1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 1 / (m ^ n !) ^ n :=
calc
(1 - 1 / m)⁻¹ * (1 / m ^ (n + 1)!) ≤ 2 * (1 / m ^ (n + 1)!) := by
-- the second factors coincide (and are non-negative),
-- the first factors satisfy the inequality `sub_one_div_inv_le_two`
gcongr; exact sub_one_div_inv_le_two hm
_ = 2 / m ^ (n + 1)! := mul_one_div 2 _
_ = 2 / m ^ (n ! * (n + 1)) := (congr_arg (2 / ·) (congr_arg (Pow.pow m) (mul_comm _ _)))
_ ≤ 1 / (m ^ n !) ^ n := by
-- Clear denominators and massage*
rw [← pow_mul, div_le_div_iff₀, one_mul, mul_add_one, pow_add, mul_comm 2]
· gcongr
-- `2 ≤ m ^ n!` is a consequence of monotonicity of exponentiation at `2 ≤ m`.
exact hm.trans <| le_self_pow₀ (one_le_two.trans hm) <| by positivity
all_goals positivity
/-- An upper estimate on the remainder. This estimate works with `m ∈ ℝ` satisfying `2 ≤ m` and is
weaker than the estimate `LiouvilleNumber.remainder_lt'` above. However, this estimate is
more useful for the proof. -/
theorem remainder_lt (n : ℕ) {m : ℝ} (m2 : 2 ≤ m) : remainder m n < 1 / (m ^ n !) ^ n :=
(remainder_lt' n <| one_lt_two.trans_le m2).trans_le (aux_calc _ m2)
/-! Starting from here, we specialize to the case in which `m` is a natural number. -/
/-- The sum of the `k` initial terms of the Liouville number to base `m` is a ratio of natural
numbers where the denominator is `m ^ k!`. -/
theorem partialSum_eq_rat {m : ℕ} (hm : 0 < m) (k : ℕ) :
∃ p : ℕ, partialSum m k = p / ((m ^ k ! :) : ℝ) := by
induction k with
| zero => exact ⟨1, by rw [partialSum, range_one, sum_singleton, Nat.cast_one, Nat.factorial,
pow_one, pow_one]⟩
| succ k h =>
rcases h with ⟨p_k, h_k⟩
use p_k * m ^ ((k + 1)! - k !) + 1
rw [partialSum_succ, h_k, div_add_div, div_eq_div_iff, add_mul]
· norm_cast
rw [add_mul, one_mul, Nat.factorial_succ, add_mul, one_mul, add_tsub_cancel_right, pow_add]
simp [mul_assoc]
all_goals positivity
end LiouvilleNumber
open LiouvilleNumber
theorem liouville_liouvilleNumber {m : ℕ} (hm : 2 ≤ m) : Liouville (liouvilleNumber m) := by
-- two useful inequalities
have mZ1 : 1 < (m : ℤ) := by norm_cast
have m1 : 1 < (m : ℝ) := by norm_cast
intro n
-- the first `n` terms sum to `p / m ^ k!`
rcases partialSum_eq_rat (zero_lt_two.trans_le hm) n with ⟨p, hp⟩
refine ⟨p, m ^ n !, one_lt_pow₀ mZ1 n.factorial_ne_zero, ?_⟩
push_cast
rw [Nat.cast_pow] at hp
-- separate out the sum of the first `n` terms and the rest
rw [← partialSum_add_remainder m1 n, ← hp]
have hpos := remainder_pos m1 n
simpa [abs_of_pos hpos, hpos.ne'] using @remainder_lt n m (by assumption_mod_cast)
theorem transcendental_liouvilleNumber {m : ℕ} (hm : 2 ≤ m) :
Transcendental ℤ (liouvilleNumber m) :=
(liouville_liouvilleNumber hm).transcendental
|
UnifTight.lean
|
/-
Copyright (c) 2023 Igor Khavkine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Igor Khavkine
-/
import Mathlib.MeasureTheory.Function.ConvergenceInMeasure
import Mathlib.MeasureTheory.Function.UniformIntegrable
/-!
# Uniform tightness
This file contains the definitions for uniform tightness for a family of Lp functions.
It is used as a hypothesis to the version of Vitali's convergence theorem for Lp spaces
that works also for spaces of infinite measure. This version of Vitali's theorem
is also proved later in the file.
## Main definitions
* `MeasureTheory.UnifTight`:
A sequence of functions `f` is uniformly tight in `L^p` if for all `ε > 0`, there
exists some measurable set `s` with finite measure such that the Lp-norm of
`f i` restricted to `sᶜ` is smaller than `ε` for all `i`.
# Main results
* `MeasureTheory.unifTight_finite`: a finite sequence of Lp functions is uniformly
tight.
* `MeasureTheory.tendsto_Lp_of_tendsto_ae`: a sequence of Lp functions which is uniformly
integrable and uniformly tight converges in Lp if it converges almost everywhere.
* `MeasureTheory.tendstoInMeasure_iff_tendsto_Lp`: Vitali convergence theorem:
a sequence of Lp functions converges in Lp if and only if it is uniformly integrable,
uniformly tight and converges in measure.
## Tags
uniform integrable, uniformly tight, Vitali convergence theorem
-/
namespace MeasureTheory
open Set Filter Topology MeasureTheory NNReal ENNReal
variable {α β ι : Type*} {m : MeasurableSpace α} {μ : Measure α} [NormedAddCommGroup β]
section UnifTight
/- This follows closely the `UnifIntegrable` section
from `Mathlib/MeasureTheory/Functions/UniformIntegrable.lean`. -/
variable {f g : ι → α → β} {p : ℝ≥0∞}
/-- A sequence of functions `f` is uniformly tight in `L^p` if for all `ε > 0`, there
exists some measurable set `s` with finite measure such that the Lp-norm of
`f i` restricted to `sᶜ` is smaller than `ε` for all `i`. -/
def UnifTight {_ : MeasurableSpace α} (f : ι → α → β) (p : ℝ≥0∞) (μ : Measure α) : Prop :=
∀ ⦃ε : ℝ≥0⦄, 0 < ε → ∃ s : Set α, μ s ≠ ∞ ∧ ∀ i, eLpNorm (sᶜ.indicator (f i)) p μ ≤ ε
theorem unifTight_iff_ennreal {_ : MeasurableSpace α} (f : ι → α → β) (p : ℝ≥0∞) (μ : Measure α) :
UnifTight f p μ ↔ ∀ ⦃ε : ℝ≥0∞⦄, 0 < ε → ∃ s : Set α,
μ s ≠ ∞ ∧ ∀ i, eLpNorm (sᶜ.indicator (f i)) p μ ≤ ε := by
simp only [ENNReal.forall_ennreal, ENNReal.coe_pos]
refine (and_iff_left ?_).symm
simp only [zero_lt_top, le_top, implies_true, and_true, true_implies]
use ∅; simpa only [measure_empty] using zero_ne_top
theorem unifTight_iff_real {_ : MeasurableSpace α} (f : ι → α → β) (p : ℝ≥0∞) (μ : Measure α) :
UnifTight f p μ ↔ ∀ ⦃ε : ℝ⦄, 0 < ε → ∃ s : Set α,
μ s ≠ ∞ ∧ ∀ i, eLpNorm (sᶜ.indicator (f i)) p μ ≤ .ofReal ε := by
refine ⟨fun hut rε hrε ↦ hut (Real.toNNReal_pos.mpr hrε), fun hut ε hε ↦ ?_⟩
obtain ⟨s, hμs, hfε⟩ := hut hε
use s, hμs; intro i
exact (hfε i).trans_eq (ofReal_coe_nnreal (p := ε))
namespace UnifTight
theorem eventually_cofinite_indicator (hf : UnifTight f p μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∀ᶠ s in μ.cofinite.smallSets, ∀ i, eLpNorm (s.indicator (f i)) p μ ≤ ε := by
by_cases hε_top : ε = ∞
· subst hε_top; simp
rcases hf (pos_iff_ne_zero.2 (toNNReal_ne_zero.mpr ⟨hε,hε_top⟩)) with ⟨s, hμs, hfs⟩
refine (eventually_smallSets' ?_).2 ⟨sᶜ, ?_, fun i ↦ (coe_toNNReal hε_top) ▸ hfs i⟩
· intro s t hst ht i
exact (eLpNorm_mono <| norm_indicator_le_of_subset hst _).trans (ht i)
· rwa [Measure.compl_mem_cofinite, lt_top_iff_ne_top]
protected theorem exists_measurableSet_indicator (hf : UnifTight f p μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ s, MeasurableSet s ∧ μ s < ∞ ∧ ∀ i, eLpNorm (sᶜ.indicator (f i)) p μ ≤ ε :=
let ⟨s, hμs, hsm, hfs⟩ := (hf.eventually_cofinite_indicator hε).exists_measurable_mem_of_smallSets
⟨sᶜ, hsm.compl, hμs, by rwa [compl_compl s]⟩
protected theorem add (hf : UnifTight f p μ) (hg : UnifTight g p μ)
(hf_meas : ∀ i, AEStronglyMeasurable (f i) μ) (hg_meas : ∀ i, AEStronglyMeasurable (g i) μ) :
UnifTight (f + g) p μ := fun ε hε ↦ by
rcases exists_Lp_half β μ p (coe_ne_zero.mpr hε.ne') with ⟨η, hη_pos, hη⟩
by_cases hη_top : η = ∞
· replace hη := hη_top ▸ hη
refine ⟨∅, (by simp), fun i ↦ ?_⟩
simp only [compl_empty, indicator_univ, Pi.add_apply]
exact (hη (f i) (g i) (hf_meas i) (hg_meas i) le_top le_top).le
obtain ⟨s, hμs, hsm, hfs, hgs⟩ :
∃ s ∈ μ.cofinite, MeasurableSet s ∧
(∀ i, eLpNorm (s.indicator (f i)) p μ ≤ η) ∧
(∀ i, eLpNorm (s.indicator (g i)) p μ ≤ η) :=
((hf.eventually_cofinite_indicator hη_pos.ne').and
(hg.eventually_cofinite_indicator hη_pos.ne')).exists_measurable_mem_of_smallSets
refine ⟨sᶜ, ne_of_lt hμs, fun i ↦ ?_⟩
have η_cast : ↑η.toNNReal = η := coe_toNNReal hη_top
calc
eLpNorm (indicator sᶜᶜ (f i + g i)) p μ
= eLpNorm (indicator s (f i) + indicator s (g i)) p μ := by rw [compl_compl, indicator_add']
_ ≤ ε := le_of_lt <|
hη _ _ ((hf_meas i).indicator hsm) ((hg_meas i).indicator hsm)
(η_cast ▸ hfs i) (η_cast ▸ hgs i)
protected theorem neg (hf : UnifTight f p μ) : UnifTight (-f) p μ := by
simp_rw [UnifTight, Pi.neg_apply, Set.indicator_neg', eLpNorm_neg]
exact hf
protected theorem sub (hf : UnifTight f p μ) (hg : UnifTight g p μ)
(hf_meas : ∀ i, AEStronglyMeasurable (f i) μ) (hg_meas : ∀ i, AEStronglyMeasurable (g i) μ) :
UnifTight (f - g) p μ := by
rw [sub_eq_add_neg]
exact hf.add hg.neg hf_meas fun i => (hg_meas i).neg
protected theorem aeeq (hf : UnifTight f p μ) (hfg : ∀ n, f n =ᵐ[μ] g n) :
UnifTight g p μ := by
intro ε hε
obtain ⟨s, hμs, hfε⟩ := hf hε
refine ⟨s, hμs, fun n => (le_of_eq <| eLpNorm_congr_ae ?_).trans (hfε n)⟩
filter_upwards [hfg n] with x hx
simp only [indicator, mem_compl_iff, hx]
end UnifTight
/-- If two functions agree a.e., then one is tight iff the other is tight. -/
theorem unifTight_congr_ae {g : ι → α → β} (hfg : ∀ n, f n =ᵐ[μ] g n) :
UnifTight f p μ ↔ UnifTight g p μ :=
⟨fun h => h.aeeq hfg, fun h => h.aeeq fun i => (hfg i).symm⟩
/-- A constant sequence is tight. -/
theorem unifTight_const {g : α → β} (hp_ne_top : p ≠ ∞) (hg : MemLp g p μ) :
UnifTight (fun _ : ι => g) p μ := by
intro ε hε
by_cases hε_top : ε = ∞
· exact ⟨∅, (by simp), fun _ => hε_top.symm ▸ le_top⟩
obtain ⟨s, _, hμs, hgε⟩ := hg.exists_eLpNorm_indicator_compl_lt hp_ne_top (coe_ne_zero.mpr hε.ne')
exact ⟨s, ne_of_lt hμs, fun _ => hgε.le⟩
/-- A single function is tight. -/
theorem unifTight_of_subsingleton [Subsingleton ι] (hp_top : p ≠ ∞)
{f : ι → α → β} (hf : ∀ i, MemLp (f i) p μ) : UnifTight f p μ := fun ε hε ↦ by
by_cases hε_top : ε = ∞
· exact ⟨∅, by simp, fun _ => hε_top.symm ▸ le_top⟩
by_cases hι : Nonempty ι
case neg => exact ⟨∅, (by simp), fun i => False.elim <| hι <| Nonempty.intro i⟩
obtain ⟨i⟩ := hι
obtain ⟨s, _, hμs, hfε⟩ := (hf i).exists_eLpNorm_indicator_compl_lt hp_top (coe_ne_zero.2 hε.ne')
refine ⟨s, ne_of_lt hμs, fun j => ?_⟩
convert hfε.le
open Fin.NatCast in -- TODO: should this be refactored to avoid needing the coercion?
/-- This lemma is less general than `MeasureTheory.unifTight_finite` which applies to
all sequences indexed by a finite type. -/
private theorem unifTight_fin (hp_top : p ≠ ∞) {n : ℕ} {f : Fin n → α → β}
(hf : ∀ i, MemLp (f i) p μ) : UnifTight f p μ := by
revert f
induction n with
| zero => exact fun {f} hf ↦ unifTight_of_subsingleton hp_top hf
| succ n h =>
intro f hfLp ε hε
by_cases hε_top : ε = ∞
· exact ⟨∅, (by simp), fun _ => hε_top.symm ▸ le_top⟩
let g : Fin n → α → β := fun k => f k
have hgLp : ∀ i, MemLp (g i) p μ := fun i => hfLp i
obtain ⟨S, hμS, hFε⟩ := h hgLp hε
obtain ⟨s, _, hμs, hfε⟩ :=
(hfLp n).exists_eLpNorm_indicator_compl_lt hp_top (coe_ne_zero.2 hε.ne')
refine ⟨s ∪ S, (by measurability), fun i => ?_⟩
by_cases hi : i.val < n
· rw [(_ : f i = g ⟨i.val, hi⟩)]
· rw [compl_union, ← indicator_indicator]
apply (eLpNorm_indicator_le _).trans
exact hFε (Fin.castLT i hi)
· simp only [Fin.coe_eq_castSucc, Fin.castSucc_mk, g]
· rw [(_ : i = n)]
· rw [compl_union, inter_comm, ← indicator_indicator]
exact (eLpNorm_indicator_le _).trans hfε.le
· have hi' := Fin.is_lt i
rw [Nat.lt_succ_iff] at hi'
rw [not_lt] at hi
simp [← le_antisymm hi' hi]
/-- A finite sequence of Lp functions is uniformly tight. -/
theorem unifTight_finite [Finite ι] (hp_top : p ≠ ∞) {f : ι → α → β}
(hf : ∀ i, MemLp (f i) p μ) : UnifTight f p μ := fun ε hε ↦ by
obtain ⟨n, hn⟩ := Finite.exists_equiv_fin ι
set g : Fin n → α → β := f ∘ hn.some.symm
have hg : ∀ i, MemLp (g i) p μ := fun _ => hf _
obtain ⟨s, hμs, hfε⟩ := unifTight_fin hp_top hg hε
refine ⟨s, hμs, fun i => ?_⟩
simpa only [g, Function.comp_apply, Equiv.symm_apply_apply] using hfε (hn.some i)
end UnifTight
section VitaliConvergence
variable {μ : Measure α} {p : ℝ≥0∞} {f : ℕ → α → β} {g : α → β}
/-! Both directions and an iff version of Vitali's convergence theorem on measure spaces
of not necessarily finite volume. See `Thm III.6.15` of Dunford & Schwartz, Part I (1958). -/
/- We start with the reverse direction. We only need to show that uniform tightness follows
from convergence in Lp. Mathlib already has the analogous `unifIntegrable_of_tendsto_Lp`
and `tendstoInMeasure_of_tendsto_eLpNorm`. -/
/-- Intermediate lemma for `unifTight_of_tendsto_Lp`. -/
private theorem unifTight_of_tendsto_Lp_zero (hp' : p ≠ ∞) (hf : ∀ n, MemLp (f n) p μ)
(hf_tendsto : Tendsto (fun n ↦ eLpNorm (f n) p μ) atTop (𝓝 0)) : UnifTight f p μ := by
intro ε hε
rw [ENNReal.tendsto_atTop_zero] at hf_tendsto
obtain ⟨N, hNε⟩ := hf_tendsto ε (by simpa only [gt_iff_lt, ENNReal.coe_pos])
let F : Fin N → α → β := fun n => f n
have hF : ∀ n, MemLp (F n) p μ := fun n => hf n
obtain ⟨s, hμs, hFε⟩ := unifTight_fin hp' hF hε
refine ⟨s, hμs, fun n => ?_⟩
by_cases hn : n < N
· exact hFε ⟨n, hn⟩
· exact (eLpNorm_indicator_le _).trans (hNε n (not_lt.mp hn))
/-- Convergence in Lp implies uniform tightness. -/
private theorem unifTight_of_tendsto_Lp (hp' : p ≠ ∞) (hf : ∀ n, MemLp (f n) p μ)
(hg : MemLp g p μ) (hfg : Tendsto (fun n => eLpNorm (f n - g) p μ) atTop (𝓝 0)) :
UnifTight f p μ := by
have : f = (fun _ => g) + fun n => f n - g := by ext1 n; simp
rw [this]
refine UnifTight.add ?_ ?_ (fun _ => hg.aestronglyMeasurable)
fun n => (hf n).1.sub hg.aestronglyMeasurable
· exact unifTight_const hp' hg
· exact unifTight_of_tendsto_Lp_zero hp' (fun n => (hf n).sub hg) hfg
/- Next we deal with the forward direction. The `MemLp` and `TendstoInMeasure` hypotheses
are unwrapped and strengthened (by known lemmas) to also have the `StronglyMeasurable`
and a.e. convergence hypotheses. The bulk of the proof is done under these stronger hypotheses. -/
/-- Bulk of the proof under strengthened hypotheses. Invoked from `tendsto_Lp_of_tendsto_ae`. -/
private theorem tendsto_Lp_of_tendsto_ae_of_meas (hp : 1 ≤ p) (hp' : p ≠ ∞)
{f : ℕ → α → β} {g : α → β} (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hg' : MemLp g p μ) (hui : UnifIntegrable f p μ) (hut : UnifTight f p μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) :
Tendsto (fun n => eLpNorm (f n - g) p μ) atTop (𝓝 0) := by
rw [ENNReal.tendsto_atTop_zero]
intro ε hε
by_cases hfinε : ε ≠ ∞; swap
· rw [not_ne_iff.mp hfinε]; exact ⟨0, fun n _ => le_top⟩
by_cases hμ : μ = 0
· rw [hμ]; use 0; intro n _; rw [eLpNorm_measure_zero]; exact zero_le ε
have hε' : 0 < ε / 3 := ENNReal.div_pos hε.ne' (ofNat_ne_top)
-- use tightness to divide the domain into interior and exterior
obtain ⟨Eg, hmEg, hμEg, hgε⟩ := MemLp.exists_eLpNorm_indicator_compl_lt hp' hg' hε'.ne'
obtain ⟨Ef, hmEf, hμEf, hfε⟩ := hut.exists_measurableSet_indicator hε'.ne'
have hmE := hmEf.union hmEg
have hfmE := (measure_union_le Ef Eg).trans_lt (add_lt_top.mpr ⟨hμEf, hμEg⟩)
set E : Set α := Ef ∪ Eg
-- use uniform integrability to get control on the limit over E
have hgE' := MemLp.restrict E hg'
have huiE := hui.restrict E
have hfgE : (∀ᵐ x ∂(μ.restrict E), Tendsto (fun n => f n x) atTop (𝓝 (g x))) :=
ae_restrict_of_ae hfg
-- `tendsto_Lp_of_tendsto_ae_of_meas` needs to
-- synthesize an argument `[IsFiniteMeasure (μ.restrict E)]`.
-- It is enough to have in the context a term of `Fact (μ E < ∞)`, which is our `ffmE` below,
-- which is automatically fed into `Restrict.isFiniteInstance`.
have ffmE := Fact.mk hfmE
have hInner := tendsto_Lp_finite_of_tendsto_ae_of_meas hp hp' hf hg hgE' huiE hfgE
rw [ENNReal.tendsto_atTop_zero] at hInner
-- get a sufficiently large N for given ε, and consider any n ≥ N
obtain ⟨N, hfngε⟩ := hInner (ε / 3) hε'
use N; intro n hn
-- get interior estimates
have hmfngE : AEStronglyMeasurable _ μ := (((hf n).sub hg).indicator hmE).aestronglyMeasurable
have hfngEε := calc
eLpNorm (E.indicator (f n - g)) p μ
= eLpNorm (f n - g) p (μ.restrict E) := eLpNorm_indicator_eq_eLpNorm_restrict hmE
_ ≤ ε / 3 := hfngε n hn
-- get exterior estimates
have hmgEc : AEStronglyMeasurable _ μ := (hg.indicator hmE.compl).aestronglyMeasurable
have hgEcε := calc
eLpNorm (Eᶜ.indicator g) p μ
≤ eLpNorm (Efᶜ.indicator (Egᶜ.indicator g)) p μ := by
unfold E; rw [compl_union, ← indicator_indicator]
_ ≤ eLpNorm (Egᶜ.indicator g) p μ := eLpNorm_indicator_le _
_ ≤ ε / 3 := hgε.le
have hmfnEc : AEStronglyMeasurable _ μ := ((hf n).indicator hmE.compl).aestronglyMeasurable
have hfnEcε : eLpNorm (Eᶜ.indicator (f n)) p μ ≤ ε / 3 := calc
eLpNorm (Eᶜ.indicator (f n)) p μ
≤ eLpNorm (Egᶜ.indicator (Efᶜ.indicator (f n))) p μ := by
unfold E; rw [compl_union, inter_comm, ← indicator_indicator]
_ ≤ eLpNorm (Efᶜ.indicator (f n)) p μ := eLpNorm_indicator_le _
_ ≤ ε / 3 := hfε n
have hmfngEc : AEStronglyMeasurable _ μ :=
(((hf n).sub hg).indicator hmE.compl).aestronglyMeasurable
have hfngEcε := calc
eLpNorm (Eᶜ.indicator (f n - g)) p μ
= eLpNorm (Eᶜ.indicator (f n) - Eᶜ.indicator g) p μ := by
rw [(Eᶜ.indicator_sub' _ _)]
_ ≤ eLpNorm (Eᶜ.indicator (f n)) p μ + eLpNorm (Eᶜ.indicator g) p μ := by
apply eLpNorm_sub_le (by assumption) (by assumption) hp
_ ≤ ε / 3 + ε / 3 := add_le_add hfnEcε hgEcε
-- finally, combine interior and exterior estimates
calc
eLpNorm (f n - g) p μ
= eLpNorm (Eᶜ.indicator (f n - g) + E.indicator (f n - g)) p μ := by
congr; exact (E.indicator_compl_add_self _).symm
_ ≤ eLpNorm (indicator Eᶜ (f n - g)) p μ + eLpNorm (indicator E (f n - g)) p μ := by
apply eLpNorm_add_le (by assumption) (by assumption) hp
_ ≤ (ε / 3 + ε / 3) + ε / 3 := add_le_add hfngEcε hfngEε
_ = ε := by simp only [ENNReal.add_thirds]
/-- Lemma used in `tendsto_Lp_of_tendsto_ae`. -/
private theorem ae_tendsto_ae_congr {f f' : ℕ → α → β} {g g' : α → β}
(hff' : ∀ (n : ℕ), f n =ᵐ[μ] f' n) (hgg' : g =ᵐ[μ] g')
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) :
∀ᵐ x ∂μ, Tendsto (fun n => f' n x) atTop (𝓝 (g' x)) := by
have hff'' := eventually_countable_forall.mpr hff'
filter_upwards [hff'', hgg', hfg] with x hff'x hgg'x hfgx
apply Tendsto.congr hff'x
rw [← hgg'x]; exact hfgx
/-- Forward direction of Vitali's convergence theorem, with a.e. instead of `InMeasure`
convergence -/
theorem tendsto_Lp_of_tendsto_ae (hp : 1 ≤ p) (hp' : p ≠ ∞)
{f : ℕ → α → β} {g : α → β} (haef : ∀ n, AEStronglyMeasurable (f n) μ)
(hg' : MemLp g p μ) (hui : UnifIntegrable f p μ) (hut : UnifTight f p μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) :
Tendsto (fun n => eLpNorm (f n - g) p μ) atTop (𝓝 0) := by
-- come up with an a.e. equal strongly measurable replacement `f` for `g`
have hf := fun n => (haef n).stronglyMeasurable_mk
have hff' := fun n => (haef n).ae_eq_mk (μ := μ)
have hui' := hui.ae_eq hff'
have hut' := hut.aeeq hff'
have hg := hg'.aestronglyMeasurable.stronglyMeasurable_mk
have hgg' := hg'.aestronglyMeasurable.ae_eq_mk (μ := μ)
have hg'' := hg'.ae_eq hgg'
have haefg' := ae_tendsto_ae_congr hff' hgg' hfg
set f' := fun n => (haef n).mk (μ := μ)
set g' := hg'.aestronglyMeasurable.mk (μ := μ)
have haefg (n : ℕ) : f n - g =ᵐ[μ] f' n - g' := (hff' n).sub hgg'
have hsnfg (n : ℕ) := eLpNorm_congr_ae (p := p) (haefg n)
apply Filter.Tendsto.congr (fun n => (hsnfg n).symm)
exact tendsto_Lp_of_tendsto_ae_of_meas hp hp' hf hg hg'' hui' hut' haefg'
/-- Forward direction of Vitali's convergence theorem:
if `f` is a sequence of uniformly integrable, uniformly tight functions that converge in
measure to some function `g` in a finite measure space, then `f` converge in Lp to `g`. -/
theorem tendsto_Lp_of_tendstoInMeasure (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ n, AEStronglyMeasurable (f n) μ) (hg : MemLp g p μ)
(hui : UnifIntegrable f p μ) (hut : UnifTight f p μ)
(hfg : TendstoInMeasure μ f atTop g) : Tendsto (fun n ↦ eLpNorm (f n - g) p μ) atTop (𝓝 0) := by
refine tendsto_of_subseq_tendsto fun ns hns => ?_
obtain ⟨ms, _, hms'⟩ := TendstoInMeasure.exists_seq_tendsto_ae fun ε hε => (hfg ε hε).comp hns
exact ⟨ms,
tendsto_Lp_of_tendsto_ae hp hp' (fun _ => hf _) hg
(fun ε hε => -- `UnifIntegrable` on a subsequence
let ⟨δ, hδ, hδ'⟩ := hui hε
⟨δ, hδ, fun i s hs hμs => hδ' _ s hs hμs⟩)
(fun ε hε => -- `UnifTight` on a subsequence
let ⟨s, hμs, hfε⟩ := hut hε
⟨s, hμs, fun i => hfε _⟩)
hms'⟩
/-- **Vitali's convergence theorem** (non-finite measure version).
A sequence of functions `f` converges to `g` in Lp
if and only if it is uniformly integrable, uniformly tight and converges to `g` in measure. -/
theorem tendstoInMeasure_iff_tendsto_Lp (hp : 1 ≤ p) (hp' : p ≠ ∞)
(hf : ∀ n, MemLp (f n) p μ) (hg : MemLp g p μ) :
TendstoInMeasure μ f atTop g ∧ UnifIntegrable f p μ ∧ UnifTight f p μ
↔ Tendsto (fun n => eLpNorm (f n - g) p μ) atTop (𝓝 0) where
mp h := tendsto_Lp_of_tendstoInMeasure hp hp' (fun n => (hf n).1) hg h.2.1 h.2.2 h.1
mpr h := ⟨tendstoInMeasure_of_tendsto_eLpNorm (lt_of_lt_of_le zero_lt_one hp).ne'
(fun n => (hf n).aestronglyMeasurable) hg.aestronglyMeasurable h,
unifIntegrable_of_tendsto_Lp hp hp' hf hg h,
unifTight_of_tendsto_Lp hp' hf hg h⟩
end VitaliConvergence
end MeasureTheory
|
Basic.lean
|
/-
Copyright (c) 2025 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Morphisms.QuasiCompact
import Mathlib.AlgebraicGeometry.Properties
/-!
# Ideal sheaves on schemes
We define ideal sheaves of schemes and provide various constructors for it.
## Main definition
* `AlgebraicGeometry.Scheme.IdealSheafData`: A structure that contains the data to uniquely define
an ideal sheaf, consisting of
1. an ideal `I(U) ≤ Γ(X, U)` for every affine open `U`
2. a proof that `I(D(f)) = I(U)_f` for every affine open `U` and every section `f : Γ(X, U)`.
* `AlgebraicGeometry.Scheme.IdealSheafData.ofIdeals`:
The largest ideal sheaf contained in a family of ideals.
* `AlgebraicGeometry.Scheme.IdealSheafData.equivOfIsAffine`:
Over affine schemes, ideal sheaves are in bijection with ideals of the global sections.
* `AlgebraicGeometry.Scheme.IdealSheafData.support`: The support of an ideal sheaf.
* `AlgebraicGeometry.Scheme.IdealSheafData.vanishingIdeal`: The vanishing ideal of a set.
* `AlgebraicGeometry.Scheme.Hom.ker`: The kernel of a morphism.
## Main results
* `AlgebraicGeometry.Scheme.IdealSheafData.gc`:
`support` and `vanishingIdeal` forms a galois connection.
* `AlgebraicGeometry.Scheme.Hom.support_ker`: The support of a kernel of a quasi-compact morphism
is the closure of the range.
## Implementation detail
Ideal sheaves are not yet defined in this file as actual subsheaves of `𝒪ₓ`.
Instead, for the ease of development and application,
we define the structure `IdealSheafData` containing all necessary data to uniquely define an
ideal sheaf. This should be refactored as a constructor for ideal sheaves once they are introduced
into mathlib.
-/
open CategoryTheory TopologicalSpace
universe u
namespace AlgebraicGeometry.Scheme
variable {X : Scheme.{u}}
/--
A structure that contains the data to uniquely define an ideal sheaf, consisting of
1. an ideal `I(U) ≤ Γ(X, U)` for every affine open `U`
2. a proof that `I(D(f)) = I(U)_f` for every affine open `U` and every section `f : Γ(X, U)`
3. a subset of `X` equal to the support.
Also see `Scheme.IdealSheafData.mkOfMemSupportIff` for a constructor with the condition on the
support being (usually) easier to prove.
-/
structure IdealSheafData (X : Scheme.{u}) : Type u where
/-- The component of an ideal sheaf at an affine open. -/
ideal : ∀ U : X.affineOpens, Ideal Γ(X, U)
/-- Also see `AlgebraicGeometry.Scheme.IdealSheafData.map_ideal` -/
map_ideal_basicOpen : ∀ (U : X.affineOpens) (f : Γ(X, U)),
(ideal U).map (X.presheaf.map (homOfLE <| X.basicOpen_le f).op).hom =
ideal (X.affineBasicOpen f)
/-- The support of an ideal sheaf. Use `IdealSheafData.support` instead for most occasions. -/
supportSet : Set X := ⋂ U, X.zeroLocus (U := U.1) (ideal U)
supportSet_eq_iInter_zeroLocus : supportSet = ⋂ U, X.zeroLocus (U := U.1) (ideal U) := by rfl
namespace IdealSheafData
@[ext]
protected lemma ext {I J : X.IdealSheafData} (h : I.ideal = J.ideal) : I = J := by
obtain ⟨i, _, s, hs⟩ := I
obtain ⟨j, _, t, ht⟩ := J
subst h
congr
rw [hs, ht]
section Order
instance : PartialOrder (IdealSheafData X) := PartialOrder.lift ideal fun _ _ ↦ IdealSheafData.ext
lemma le_def {I J : IdealSheafData X} : I ≤ J ↔ ∀ U, I.ideal U ≤ J.ideal U := .rfl
instance : CompleteSemilatticeSup (IdealSheafData X) where
sSup s :=
{ ideal := sSup (ideal '' s),
map_ideal_basicOpen := by
have : sSup (ideal '' s) = ⨆ i : s, ideal i.1 := by
conv_lhs => rw [← Subtype.range_val (s := s), ← Set.range_comp]
rfl
simp only [this, iSup_apply, Ideal.map_iSup, map_ideal_basicOpen, implies_true] }
le_sSup s x hxs := le_sSup (s := ideal '' s) ⟨_, hxs, rfl⟩
sSup_le s i hi := sSup_le (s := ideal '' s) (Set.forall_mem_image.mpr hi)
/-- The largest ideal sheaf contained in a family of ideals. -/
def ofIdeals (I : ∀ U : X.affineOpens, Ideal Γ(X, U)) : IdealSheafData X :=
sSup { J : IdealSheafData X | J.ideal ≤ I }
lemma ideal_ofIdeals_le (I : ∀ U : X.affineOpens, Ideal Γ(X, U)) :
(ofIdeals I).ideal ≤ I :=
sSup_le (Set.forall_mem_image.mpr fun _ ↦ id)
/-- The galois coinsertion between ideal sheaves and arbitrary families of ideals. -/
protected def gci : GaloisCoinsertion ideal (ofIdeals (X := X)) where
choice I hI :=
{ ideal := I
map_ideal_basicOpen U f :=
(ideal_ofIdeals_le I).antisymm hI ▸ (ofIdeals I).map_ideal_basicOpen U f }
gc _ _ := ⟨(le_sSup ·), (le_trans · (ideal_ofIdeals_le _))⟩
u_l_le _ := sSup_le fun _ ↦ id
choice_eq I hI := IdealSheafData.ext (hI.antisymm (ideal_ofIdeals_le I))
lemma strictMono_ideal : StrictMono (ideal (X := X)) := IdealSheafData.gci.strictMono_l
lemma ideal_mono : Monotone (ideal (X := X)) := strictMono_ideal.monotone
lemma ofIdeals_mono : Monotone (ofIdeals (X := X)) := IdealSheafData.gci.gc.monotone_u
lemma ofIdeals_ideal (I : IdealSheafData X) : ofIdeals I.ideal = I := IdealSheafData.gci.u_l_eq _
lemma le_ofIdeals_iff {I : IdealSheafData X} {J} : I ≤ ofIdeals J ↔ I.ideal ≤ J :=
IdealSheafData.gci.gc.le_iff_le.symm
instance : OrderTop (IdealSheafData X) where
top.ideal := ⊤
top.map_ideal_basicOpen := by simp [Ideal.map_top]
top.supportSet := ⊥
top.supportSet_eq_iInter_zeroLocus := by
ext x
simpa using (isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ x) isOpen_univ
le_top I U := le_top
instance : OrderBot (IdealSheafData X) where
bot.ideal := ⊥
bot.map_ideal_basicOpen := by simp
bot.supportSet := ⊤
bot.supportSet_eq_iInter_zeroLocus := by ext; simp
bot_le I U := bot_le
instance : SemilatticeInf (IdealSheafData X) where
inf I J :=
{ ideal := I.ideal ⊓ J.ideal
map_ideal_basicOpen U f := by
dsimp
have : (X.presheaf.map (homOfLE (X.basicOpen_le f)).op).hom = algebraMap _ _ := rfl
have inst := U.2.isLocalization_basicOpen f
rw [← I.map_ideal_basicOpen U f, ← J.map_ideal_basicOpen U f, this]
ext x
obtain ⟨x, s, rfl⟩ := IsLocalization.mk'_surjective (.powers f) x
simp only [IsLocalization.mk'_mem_map_algebraMap_iff, Submonoid.mem_powers_iff, Ideal.mem_inf,
exists_exists_eq_and]
refine ⟨fun ⟨n, h₁, h₂⟩ ↦ ⟨⟨n, h₁⟩, ⟨n, h₂⟩⟩, ?_⟩
rintro ⟨⟨n₁, h₁⟩, ⟨n₂, h₂⟩⟩
refine ⟨n₁ + n₂, ?_, ?_⟩
· rw [add_comm, pow_add, mul_assoc]; exact Ideal.mul_mem_left _ _ h₁
· rw [pow_add, mul_assoc]; exact Ideal.mul_mem_left _ _ h₂ }
inf_le_left I J U := inf_le_left
inf_le_right I J U := inf_le_right
le_inf I J K hIJ hIK U := le_inf (hIJ U) (hIK U)
instance : CompleteLattice (IdealSheafData X) where
__ := inferInstanceAs (OrderTop (IdealSheafData X))
__ := inferInstanceAs (OrderBot (IdealSheafData X))
__ := inferInstanceAs (SemilatticeInf (IdealSheafData X))
__ := inferInstanceAs (CompleteSemilatticeSup (IdealSheafData X))
__ := IdealSheafData.gci.liftCompleteLattice
@[simp]
lemma ideal_top : ideal (X := X) ⊤ = ⊤ := rfl
@[simp]
lemma ideal_bot : ideal (X := X) ⊥ = ⊥ := rfl
@[simp]
lemma ideal_sup {I J : IdealSheafData X} : (I ⊔ J).ideal = I.ideal ⊔ J.ideal := rfl
@[simp]
lemma ideal_sSup {I : Set (IdealSheafData X)} : (sSup I).ideal = sSup (ideal '' I) := rfl
@[simp]
lemma ideal_iSup {ι : Type*} {I : ι → IdealSheafData X} : (iSup I).ideal = ⨆ i, (I i).ideal := by
rw [← sSup_range, ← sSup_range, ideal_sSup, ← Set.range_comp, Function.comp_def]
@[simp]
lemma ideal_inf {I J : IdealSheafData X} : (I ⊓ J).ideal = I.ideal ⊓ J.ideal := rfl
@[simp]
lemma ideal_biInf {ι : Type*} (I : ι → IdealSheafData X) {s : Set ι} (hs : s.Finite) :
(⨅ i ∈ s, I i).ideal = ⨅ i ∈ s, (I i).ideal := by
refine hs.induction_on _ (by simp) fun {i s} his hs e ↦ ?_
simp only [iInf_insert, e, ideal_inf]
@[simp]
lemma ideal_iInf {ι : Type*} (I : ι → IdealSheafData X) [Finite ι] :
(⨅ i, I i).ideal = ⨅ i, (I i).ideal := by
simpa using ideal_biInf I Set.finite_univ
end Order
variable (I : IdealSheafData X)
section map_ideal
/-- subsumed by `IdealSheafData.map_ideal` below. -/
private lemma map_ideal_basicOpen_of_eq
{U V : X.affineOpens} (f : Γ(X, U)) (hV : V = X.affineBasicOpen f) :
(I.ideal U).map (X.presheaf.map
(homOfLE (X := X.Opens) (hV.trans_le (X.affineBasicOpen_le f))).op).hom =
I.ideal V := by
subst hV; exact I.map_ideal_basicOpen _ _
lemma map_ideal {U V : X.affineOpens} (h : U ≤ V) :
(I.ideal V).map (X.presheaf.map (homOfLE h).op).hom = I.ideal U := by
rw [U.2.ideal_ext_iff]
intro x hxU
obtain ⟨f, g, hfg, hxf⟩ := exists_basicOpen_le_affine_inter U.2 V.2 x ⟨hxU, h hxU⟩
have := I.map_ideal_basicOpen_of_eq (V := X.affineBasicOpen g) f (Subtype.ext hfg.symm)
rw [← I.map_ideal_basicOpen] at this
apply_fun Ideal.map (X.presheaf.germ (X.basicOpen g) x (hfg ▸ hxf)).hom at this
simp only [Ideal.map_map, ← CommRingCat.hom_comp, affineBasicOpen_coe, X.presheaf.germ_res]
at this ⊢
simp only [homOfLE_leOfHom, TopCat.Presheaf.germ_res', this]
/-- A form of `map_ideal` that is easier to rewrite with. -/
lemma map_ideal' {U V : X.affineOpens} (h : Opposite.op V.1 ⟶ .op U.1) :
(I.ideal V).map (X.presheaf.map h).hom = I.ideal U :=
map_ideal _ _
lemma ideal_le_comap_ideal {U V : X.affineOpens} (h : U ≤ V) :
I.ideal V ≤ (I.ideal U).comap (X.presheaf.map (homOfLE h).op).hom := by
rw [← Ideal.map_le_iff_le_comap, ← I.map_ideal h]
end map_ideal
section support
lemma mem_supportSet_iff {I : IdealSheafData X} {x} :
x ∈ I.supportSet ↔ ∀ U, x ∈ X.zeroLocus (U := U.1) (I.ideal U) :=
(Set.ext_iff.mp I.supportSet_eq_iInter_zeroLocus _).trans Set.mem_iInter
lemma supportSet_subset_zeroLocus (I : IdealSheafData X) (U : X.affineOpens) :
I.supportSet ⊆ X.zeroLocus (U := U.1) (I.ideal U) :=
I.supportSet_eq_iInter_zeroLocus.trans_subset (Set.iInter_subset _ _)
lemma zeroLocus_inter_subset_supportSet (I : IdealSheafData X) (U : X.affineOpens) :
X.zeroLocus (U := U.1) (I.ideal U) ∩ U ⊆ I.supportSet := by
rw [I.supportSet_eq_iInter_zeroLocus]
refine Set.subset_iInter fun V ↦ ?_
apply (X.codisjoint_zeroLocus (U := V) (I.ideal V)).symm.left_le_of_le_inf_right
rintro x ⟨⟨hx, hxU⟩, hxV⟩
simp only [Scheme.mem_zeroLocus_iff, SetLike.mem_coe] at hx ⊢
intro s hfU hxs
obtain ⟨f, g, hfg, hxf⟩ := exists_basicOpen_le_affine_inter U.2 V.2 x ⟨hxU, hxV⟩
have inst := U.2.isLocalization_basicOpen f
have := (I.map_ideal (U := X.affineBasicOpen f) (hfg.trans_le (X.basicOpen_le g))).le
(Ideal.mem_map_of_mem _ hfU)
rw [← I.map_ideal_basicOpen] at this
obtain ⟨⟨s', ⟨_, n, rfl⟩⟩, hs'⟩ :=
(IsLocalization.mem_map_algebraMap_iff (.powers f) Γ(X, X.basicOpen f)).mp this
apply_fun (x ∈ X.basicOpen ·) at hs'
refine hx s' s'.2 ?_
cases n <;>
simpa [RingHom.algebraMap_toAlgebra, ← hfg, hxf, hxs, Scheme.basicOpen_pow] using hs'
lemma mem_supportSet_iff_of_mem {I : IdealSheafData X} {x} {U : X.affineOpens} (hxU : x ∈ U.1) :
x ∈ I.supportSet ↔ x ∈ X.zeroLocus (U := U.1) (I.ideal U) :=
⟨I.supportSet_eq_iInter_zeroLocus ▸ fun h ↦ Set.iInter_subset _ U h,
fun h ↦ I.zeroLocus_inter_subset_supportSet U ⟨h, hxU⟩⟩
lemma supportSet_inter (I : IdealSheafData X) (U : X.affineOpens) :
I.supportSet ∩ U = X.zeroLocus (U := U.1) (I.ideal U) ∩ U := by
ext x
by_cases hxU : x ∈ U.1
· simp [hxU, mem_supportSet_iff_of_mem hxU]
· simp [hxU]
lemma isClosed_supportSet (I : IdealSheafData X) : IsClosed I.supportSet := by
rw [TopologicalSpace.IsOpenCover.isClosed_iff_coe_preimage (iSup_affineOpens_eq_top X)]
intro U
refine ⟨(X.zeroLocus (U := U.1) (I.ideal U))ᶜ, (X.zeroLocus_isClosed _).isOpen_compl, ?_⟩
simp only [Set.preimage_compl, compl_inj_iff]
apply Subtype.val_injective.image_injective
simp [Set.image_preimage_eq_inter_range, I.supportSet_inter]
/-- The support of an ideal sheaf. Also see `IdealSheafData.mem_support_iff_of_mem`. -/
def support : Closeds X := ⟨I.supportSet, I.isClosed_supportSet⟩
lemma coe_support_eq_eq_iInter_zeroLocus :
(I.support : Set X) = ⋂ U, X.zeroLocus (U := U.1) (I.ideal U) :=
I.supportSet_eq_iInter_zeroLocus
lemma mem_support_iff {I : IdealSheafData X} {x} :
x ∈ I.support ↔ ∀ U, x ∈ X.zeroLocus (U := U.1) (I.ideal U) :=
(Set.ext_iff.mp I.supportSet_eq_iInter_zeroLocus _).trans Set.mem_iInter
lemma mem_support_iff_of_mem {I : IdealSheafData X} {x : X} {U : X.affineOpens} (h : x ∈ U.1) :
x ∈ I.support ↔ x ∈ X.zeroLocus (U := U.1) (I.ideal U) := by
simpa [-mem_zeroLocus_iff, h] using congr(x ∈ $(I.supportSet_inter U))
lemma coe_support_inter (I : IdealSheafData X) (U : X.affineOpens) :
(I.support : Set X) ∩ U = X.zeroLocus (U := U.1) (I.ideal U) ∩ U :=
I.supportSet_inter U
/-- Custom simps projection for `IdealSheafData`. -/
def Simps.coe_support : Set X := I.support
initialize_simps_projections IdealSheafData (supportSet → coe_support, as_prefix coe_support)
/-- A useful constructor of `IdealSheafData`
with the condition on `supportSet` being easier to check. -/
@[simps ideal coe_support]
def mkOfMemSupportIff
(ideal : ∀ U : X.affineOpens, Ideal Γ(X, U))
(map_ideal_basicOpen : ∀ (U : X.affineOpens) (f : Γ(X, U)),
(ideal U).map (X.presheaf.map (homOfLE <| X.basicOpen_le f).op).hom =
ideal (X.affineBasicOpen f))
(supportSet : Set X)
(supportSet_inter :
∀ U : X.affineOpens, ∀ x ∈ U.1, x ∈ supportSet ↔ x ∈ X.zeroLocus (U := U.1) (ideal U)) :
X.IdealSheafData where
ideal := ideal
map_ideal_basicOpen := map_ideal_basicOpen
supportSet := supportSet
supportSet_eq_iInter_zeroLocus := by
let I' : X.IdealSheafData := { ideal := ideal, map_ideal_basicOpen := map_ideal_basicOpen }
change supportSet = I'.supportSet
ext x
obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ :=
(isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ x) isOpen_univ
exact (supportSet_inter ⟨U, hU⟩ x hxU).trans
(I'.mem_support_iff_of_mem (U := ⟨U, hU⟩) hxU).symm
@[simp]
lemma support_top : support (X := X) ⊤ = ⊥ := rfl
@[simp]
lemma support_bot : support (X := X) ⊥ = ⊤ := rfl
lemma support_antitone : Antitone (support (X := X)) := by
intro I J h
rw [← SetLike.coe_subset_coe, I.coe_support_eq_eq_iInter_zeroLocus,
J.coe_support_eq_eq_iInter_zeroLocus]
exact Set.iInter_mono fun U ↦ X.zeroLocus_mono (h U)
@[simp]
lemma support_eq_bot_iff : support I = ⊥ ↔ I = ⊤ := by
refine ⟨fun H ↦ top_le_iff.mp fun U ↦ ?_, by simp +contextual⟩
have := (U.2.fromSpec_image_zeroLocus _).trans_subset
((zeroLocus_inter_subset_supportSet I U).trans H.le)
simp only [Set.subset_empty_iff, Set.image_eq_empty, Closeds.coe_bot] at this
simp [PrimeSpectrum.zeroLocus_empty_iff_eq_top.mp this]
end support
section IsAffine
/-- The ideal sheaf induced by an ideal of the global sections. -/
@[simps! ideal coe_support]
def ofIdealTop (I : Ideal Γ(X, ⊤)) : IdealSheafData X :=
mkOfMemSupportIff
(fun U ↦ I.map (X.presheaf.map (homOfLE le_top).op).hom)
(fun U f ↦ by rw [Ideal.map_map, ← CommRingCat.hom_comp, ← Functor.map_comp]; rfl)
(X.zeroLocus (U := ⊤) I)
(fun U x hxU ↦ by
simp only [Ideal.map, zeroLocus_span, zeroLocus_map, Set.mem_union, Set.mem_compl_iff,
SetLike.mem_coe, hxU, not_true_eq_false, iff_self_or, IsEmpty.forall_iff])
lemma le_of_isAffine [IsAffine X] {I J : IdealSheafData X}
(H : I.ideal ⟨⊤, isAffineOpen_top X⟩ ≤ J.ideal ⟨⊤, isAffineOpen_top X⟩) : I ≤ J := by
intro U
rw [← map_ideal (U := U) (V := ⟨⊤, isAffineOpen_top X⟩) I (le_top (a := U.1)),
← map_ideal (U := U) (V := ⟨⊤, isAffineOpen_top X⟩) J (le_top (a := U.1))]
exact Ideal.map_mono H
lemma ext_of_isAffine [IsAffine X] {I J : IdealSheafData X}
(H : I.ideal ⟨⊤, isAffineOpen_top X⟩ = J.ideal ⟨⊤, isAffineOpen_top X⟩) : I = J :=
(le_of_isAffine H.le).antisymm (le_of_isAffine H.ge)
/-- Over affine schemes, ideal sheaves are in bijection with ideals of the global sections. -/
@[simps]
def equivOfIsAffine [IsAffine X] : IdealSheafData X ≃o Ideal Γ(X, ⊤) where
toFun := (ideal · ⟨⊤, isAffineOpen_top X⟩)
invFun := ofIdealTop
left_inv I := ext_of_isAffine (by simp)
right_inv I := by simp
map_rel_iff' {I J} := ⟨le_of_isAffine, (· _)⟩
end IsAffine
section ofIsClosed
open _root_.PrimeSpectrum TopologicalSpace
@[deprecated (since := "2025-08-10")] alias Scheme.zeroLocus_radical :=
AlgebraicGeometry.Scheme.zeroLocus_radical
/-- The radical of a ideal sheaf. -/
@[simps! ideal]
def radical (I : IdealSheafData X) : IdealSheafData X :=
mkOfMemSupportIff
(fun U ↦ (I.ideal U).radical)
(fun U f ↦
letI : Algebra Γ(X, U) Γ(X, X.affineBasicOpen f) :=
(X.presheaf.map (homOfLE (X.basicOpen_le f)).op).hom.toAlgebra
have : IsLocalization.Away f Γ(X, X.basicOpen f) := U.2.isLocalization_of_eq_basicOpen _ _ rfl
(IsLocalization.map_radical (.powers f) Γ(X, X.basicOpen f) (I.ideal U)).trans
congr($(I.map_ideal_basicOpen U f).radical))
I.supportSet
(fun U x hx ↦ by
simp only [mem_supportSet_iff_of_mem hx, AlgebraicGeometry.Scheme.zeroLocus_radical])
@[simp]
lemma support_radical (I : IdealSheafData X) : I.radical.support = I.support := rfl
/-- The nilradical of a scheme. -/
def _root_.AlgebraicGeometry.Scheme.nilradical (X : Scheme.{u}) : IdealSheafData X :=
.radical ⊥
@[simp]
lemma _root_.AlgebraicGeometry.Scheme.support_nilradical (X : Scheme.{u}) :
X.nilradical.support = ⊤ := rfl
lemma le_radical : I ≤ I.radical := fun _ ↦ Ideal.le_radical
@[simp]
lemma radical_top : radical (X := X) ⊤ = ⊤ := top_le_iff.mp (le_radical _)
lemma radical_bot : radical ⊥ = nilradical X := rfl
lemma radical_sup {I J : IdealSheafData X} :
radical (I ⊔ J) = radical (radical I ⊔ radical J) := by
ext U : 2
exact (Ideal.radical_sup (I.ideal U) (J.ideal U))
@[simp]
lemma radical_inf {I J : IdealSheafData X} :
radical (I ⊓ J) = (radical I ⊓ radical J) := by
ext U : 2
simp only [radical_ideal, ideal_inf, Pi.inf_apply, Ideal.radical_inf]
/-- The vanishing ideal sheaf of a closed set,
which is the largest ideal sheaf whose support is equal to it.
The reduced induced scheme structure on the closed set is the quotient of this ideal. -/
@[simps! ideal coe_support]
nonrec def vanishingIdeal (Z : Closeds X) : IdealSheafData X :=
mkOfMemSupportIff
(fun U ↦ vanishingIdeal (U.2.fromSpec.base ⁻¹' Z))
(fun U f ↦ by
let F := X.presheaf.map (homOfLE (X.basicOpen_le f)).op
apply le_antisymm
· rw [Ideal.map_le_iff_le_comap]
intro x hx
suffices ∀ p, (X.affineBasicOpen f).2.fromSpec.base p ∈ Z → F.hom x ∈ p.asIdeal by
simpa [PrimeSpectrum.mem_vanishingIdeal] using this
intro x hxZ
refine (PrimeSpectrum.mem_vanishingIdeal _ _).mp hx
((Spec.map (X.presheaf.map (homOfLE _).op)).base x) ?_
rwa [Set.mem_preimage, ← Scheme.comp_base_apply,
IsAffineOpen.map_fromSpec _ (X.affineBasicOpen f).2]
· letI : Algebra Γ(X, U) Γ(X, X.affineBasicOpen f) := F.hom.toAlgebra
have : IsLocalization.Away f Γ(X, X.basicOpen f) :=
U.2.isLocalization_of_eq_basicOpen _ _ rfl
intro x hx
dsimp only at hx ⊢
have : Topology.IsOpenEmbedding (Spec.map F).base :=
localization_away_isOpenEmbedding Γ(X, X.basicOpen f) f
rw [← U.2.map_fromSpec (X.affineBasicOpen f).2 (homOfLE (X.basicOpen_le f)).op,
Scheme.comp_base, TopCat.coe_comp, Set.preimage_comp] at hx
generalize U.2.fromSpec.base ⁻¹' Z = Z' at hx ⊢
replace hx : x ∈ vanishingIdeal ((Spec.map F).base ⁻¹' Z') := hx
obtain ⟨I, hI, e⟩ :=
(isClosed_iff_zeroLocus_radical_ideal _).mp (isClosed_closure (s := Z'))
rw [← vanishingIdeal_closure,
← this.isOpenMap.preimage_closure_eq_closure_preimage this.continuous, e] at hx
rw [← vanishingIdeal_closure, e]
erw [preimage_comap_zeroLocus] at hx
rwa [← PrimeSpectrum.zeroLocus_span, ← Ideal.map, vanishingIdeal_zeroLocus_eq_radical,
← RingHom.algebraMap_toAlgebra (X.presheaf.map _).hom,
← IsLocalization.map_radical (.powers f), ← vanishingIdeal_zeroLocus_eq_radical] at hx)
Z
(fun U x hxU ↦ by
trans x ∈ X.zeroLocus (U := U.1) (vanishingIdeal (U.2.fromSpec.base.hom ⁻¹' Z)) ∩ U.1
· rw [← U.2.fromSpec_image_zeroLocus, zeroLocus_vanishingIdeal_eq_closure,
← U.2.fromSpec.isOpenEmbedding.isOpenMap.preimage_closure_eq_closure_preimage
U.2.fromSpec.base.1.2,
Set.image_preimage_eq_inter_range, Z.isClosed.closure_eq, IsAffineOpen.range_fromSpec]
simp [hxU]
· simp [hxU])
lemma le_support_iff_le_vanishingIdeal {I : X.IdealSheafData} {Z : Closeds X} :
Z ≤ I.support ↔ I ≤ vanishingIdeal Z := by
simp only [le_def, vanishingIdeal_ideal, ← PrimeSpectrum.subset_zeroLocus_iff_le_vanishingIdeal]
trans ∀ U : X.affineOpens, (Z : Set X) ∩ U ⊆ I.support ∩ U
· refine ⟨fun H U x hx ↦ ⟨H hx.1, hx.2⟩, fun H x hx ↦ ?_⟩
obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ :=
(isBasis_affine_open X).exists_subset_of_mem_open (Set.mem_univ x) isOpen_univ
exact (H ⟨U, hU⟩ ⟨hx, hxU⟩).1
refine forall_congr' fun U ↦ ?_
rw [coe_support_inter, ← Set.image_subset_image_iff U.2.fromSpec.isOpenEmbedding.injective,
Set.image_preimage_eq_inter_range, IsAffineOpen.fromSpec_image_zeroLocus,
IsAffineOpen.range_fromSpec]
@[deprecated (since := "2025-05-16")]
alias subset_support_iff_le_vanishingIdeal := le_support_iff_le_vanishingIdeal
/-- `support` and `vanishingIdeal` forms a galois connection.
This is the global version of `PrimeSpectrum.gc`. -/
lemma gc : @GaloisConnection X.IdealSheafData (Closeds X)ᵒᵈ _ _ (support ·) (vanishingIdeal ·) :=
fun _ _ ↦ le_support_iff_le_vanishingIdeal
lemma vanishingIdeal_antimono {S T : Closeds X} (h : S ≤ T) : vanishingIdeal T ≤ vanishingIdeal S :=
gc.monotone_u h
lemma vanishingIdeal_support {I : IdealSheafData X} :
vanishingIdeal I.support = I.radical := by
ext U : 2
dsimp
rw [← vanishingIdeal_zeroLocus_eq_radical]
congr 1
apply U.2.fromSpec.isOpenEmbedding.injective.image_injective
rw [Set.image_preimage_eq_inter_range, IsAffineOpen.range_fromSpec,
IsAffineOpen.fromSpec_image_zeroLocus, coe_support_inter]
@[simp] lemma vanishingIdeal_bot : vanishingIdeal (X := X) ⊥ = ⊤ := gc.u_top
@[simp] lemma vanishingIdeal_top : vanishingIdeal (X := X) ⊤ = X.nilradical := by
rw [← support_bot, vanishingIdeal_support, nilradical]
@[simp] lemma vanishingIdeal_iSup {ι : Sort*} (Z : ι → Closeds X) :
vanishingIdeal (iSup Z) = ⨅ i, vanishingIdeal (Z i) := gc.u_iInf
@[simp] lemma vanishingIdeal_sSup (Z : Set (Closeds X)) :
vanishingIdeal (sSup Z) = ⨅ z ∈ Z, vanishingIdeal z := gc.u_sInf
@[simp] lemma vanishingIdeal_sup (Z Z' : TopologicalSpace.Closeds X) :
vanishingIdeal (Z ⊔ Z') = vanishingIdeal Z ⊓ vanishingIdeal Z' := gc.u_inf
@[simp] lemma support_sup (I J : X.IdealSheafData) :
(I ⊔ J).support = I.support ⊓ J.support := gc.l_sup
@[simp] lemma support_iSup {ι : Sort*} (I : ι → X.IdealSheafData) :
(iSup I).support = ⨅ i, (I i).support := gc.l_iSup
@[simp] lemma support_sSup (I : Set X.IdealSheafData) :
(sSup I).support = ⨅ i ∈ I, i.support := gc.l_sSup
end ofIsClosed
end IdealSheafData
section IsReduced
lemma nilradical_eq_bot [IsReduced X] : X.nilradical = ⊥ := by
ext; simp [nilradical, Ideal.radical_eq_iff.mpr (Ideal.isRadical_bot)]
lemma IdealSheafData.support_eq_top_iff [IsReduced X] {I : X.IdealSheafData} :
I.support = ⊤ ↔ I = ⊥ := by
rw [← top_le_iff, le_support_iff_le_vanishingIdeal,
vanishingIdeal_top, nilradical_eq_bot, le_bot_iff]
end IsReduced
section ker
open IdealSheafData
variable {Y Z : Scheme.{u}}
/-- The kernel of a morphism,
defined as the largest (quasi-coherent) ideal sheaf contained in the component-wise kernel.
This is usually only well-behaved when `f` is quasi-compact. -/
def Hom.ker (f : X.Hom Y) : IdealSheafData Y :=
ofIdeals fun U ↦ RingHom.ker (f.app U).hom
lemma Hom.ideal_ker_le (f : X.Hom Y) (U : Y.affineOpens) :
f.ker.ideal U ≤ RingHom.ker (f.app U).hom :=
ideal_ofIdeals_le _ _
@[simp]
lemma Hom.ker_apply (f : X.Hom Y) [QuasiCompact f] (U : Y.affineOpens) :
f.ker.ideal U = RingHom.ker (f.app U).hom := by
let I : IdealSheafData Y := ⟨fun U ↦ RingHom.ker (f.app U).hom, ?_, _, rfl⟩
· exact congr($(ofIdeals_ideal I).ideal U)
intro U s
apply le_antisymm
· refine Ideal.map_le_iff_le_comap.mpr fun x hx ↦ ?_
simp_rw [RingHom.comap_ker, ← CommRingCat.hom_comp, Scheme.affineBasicOpen_coe, f.naturality,
CommRingCat.hom_comp, ← RingHom.comap_ker]
exact Ideal.ker_le_comap _ hx
· intro x hx
have := U.2.isLocalization_basicOpen s
obtain ⟨x, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (.powers s) x
refine (IsLocalization.mk'_mem_map_algebraMap_iff _ _ _ _ _).mpr ?_
suffices ∃ (V : X.Opens) (hV : V = X.basicOpen ((f.app U).hom s)),
letI := hV.trans_le (X.basicOpen_le _); ((f.app U).hom x |_ V) = 0 by
obtain ⟨_, rfl, H⟩ := this
obtain ⟨n, hn⟩ := exists_pow_mul_eq_zero_of_res_basicOpen_eq_zero_of_isCompact
X (U := f ⁻¹ᵁ U) (QuasiCompact.isCompact_preimage (f := f) _ U.1.2 U.2.isCompact)
(f.app U x) (f.app U s) H
exact ⟨_, ⟨n, rfl⟩, by simpa using hn⟩
refine ⟨f ⁻¹ᵁ Y.basicOpen s, by simp, ?_⟩
replace hx : (Y.presheaf.map (homOfLE (Y.basicOpen_le s)).op ≫ f.app _).hom x = 0 := by
trans (f.app (Y.basicOpen s)).hom (algebraMap Γ(Y, U) _ x)
· simp [-NatTrans.naturality, RingHom.algebraMap_toAlgebra]
· simp only [Scheme.affineBasicOpen_coe, RingHom.mem_ker] at hx
rw [← IsLocalization.mk'_spec' (M := .powers s), map_mul, hx, mul_zero]
rwa [f.naturality] at hx
lemma Hom.le_ker_comp (f : X ⟶ Y) (g : Y.Hom Z) : g.ker ≤ (f ≫ g).ker := by
refine ofIdeals_mono fun U ↦ ?_
rw [Scheme.comp_app f g U, CommRingCat.hom_comp, ← RingHom.comap_ker]
exact Ideal.ker_le_comap _
lemma ker_eq_top_of_isEmpty (f : X.Hom Y) [IsEmpty X] : f.ker = ⊤ :=
top_le_iff.mp (le_ofIdeals_iff.mpr fun U x _ ↦ by simpa using Subsingleton.elim _ _)
@[simp]
lemma Hom.ker_eq_bot_of_isIso (f : X ⟶ Y) [IsIso f] : f.ker = ⊥ := by
ext U
simp [map_eq_zero_iff _ (ConcreteCategory.bijective_of_isIso (f.app U)).1]
lemma Hom.ker_comp_of_isIso (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] : (f ≫ g).ker = g.ker :=
(f.le_ker_comp g).antisymm' (((inv f).le_ker_comp _).trans (by simp))
lemma ker_of_isAffine {X Y : Scheme} (f : X ⟶ Y) [IsAffine Y] :
f.ker = ofIdealTop (RingHom.ker f.appTop.hom) := by
refine (le_of_isAffine ((f.ideal_ker_le _).trans (by simp))).antisymm
(le_ofIdeals_iff.mpr fun U ↦ ?_)
simp only [ofIdealTop_ideal, homOfLE_leOfHom, Ideal.map_le_iff_le_comap, RingHom.comap_ker,
← CommRingCat.hom_comp, f.naturality]
intro x
simp +contextual
lemma Hom.range_subset_ker_support (f : X.Hom Y) :
Set.range f.base ⊆ f.ker.support := by
rintro _ ⟨x, rfl⟩
obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ :=
(isBasis_affine_open Y).exists_subset_of_mem_open (Set.mem_univ (f.base x)) isOpen_univ
refine ((coe_support_inter f.ker ⟨U, hU⟩).ge ⟨?_, hxU⟩).1
simp only [Scheme.mem_zeroLocus_iff, SetLike.mem_coe]
intro s hs hxs
have : x ∈ f ⁻¹ᵁ Y.basicOpen s := hxs
rwa [Scheme.preimage_basicOpen, RingHom.mem_ker.mp (f.ideal_ker_le _ hs),
Scheme.basicOpen_zero] at this
lemma Hom.ker_eq_top_iff_isEmpty (f : X.Hom Y) : f.ker = ⊤ ↔ IsEmpty X :=
⟨fun H ↦ by simpa [H] using f.range_subset_ker_support, fun _ ↦ ker_eq_top_of_isEmpty f⟩
lemma Hom.iInf_ker_openCover_map_comp_apply
(f : X.Hom Y) [QuasiCompact f] (𝒰 : X.OpenCover) (U : Y.affineOpens) :
⨅ i, (𝒰.map i ≫ f).ker.ideal U = f.ker.ideal U := by
refine le_antisymm ?_ (le_iInf fun i ↦ (𝒰.map i).le_ker_comp f U)
intro s hs
simp only [Hom.ker_apply, RingHom.mem_ker]
apply X.IsSheaf.section_ext
rintro x hxU
obtain ⟨i, x, rfl⟩ := 𝒰.exists_eq x
simp only [homOfLE_leOfHom, map_zero, exists_and_left]
refine ⟨𝒰.map i ''ᵁ 𝒰.map i ⁻¹ᵁ f ⁻¹ᵁ U.1, ⟨_, hxU, rfl⟩,
Set.image_preimage_subset (𝒰.map i).base (f ⁻¹ᵁ U), ?_⟩
apply ((𝒰.map i).appIso _).commRingCatIsoToRingEquiv.injective
rw [map_zero, ← RingEquiv.coe_toRingHom, Iso.commRingCatIsoToRingEquiv_toRingHom,
Scheme.Hom.appIso_hom']
simp only [homOfLE_leOfHom, Scheme.Hom.app_eq_appLE, ← RingHom.comp_apply,
← CommRingCat.hom_comp, Scheme.Hom.appLE_map, Scheme.appLE_comp_appLE]
simpa [Scheme.Hom.appLE] using ideal_ker_le _ _ (Ideal.mem_iInf.mp hs i)
lemma Hom.iInf_ker_openCover_map_comp (f : X ⟶ Y) [QuasiCompact f] (𝒰 : X.OpenCover) :
⨅ i, (𝒰.map i ≫ f).ker = f.ker := by
refine le_antisymm ?_ (le_iInf fun i ↦ (𝒰.map i).le_ker_comp f)
refine iInf_le_iff.mpr fun I hI U ↦ ?_
rw [← f.iInf_ker_openCover_map_comp_apply 𝒰, le_iInf_iff]
exact fun i ↦ hI i U
lemma Hom.iUnion_support_ker_openCover_map_comp
(f : X.Hom Y) [QuasiCompact f] (𝒰 : X.OpenCover) [Finite 𝒰.J] :
⋃ i, ((𝒰.map i ≫ f).ker.support : Set Y) = f.ker.support := by
cases isEmpty_or_nonempty 𝒰.J
· have : IsEmpty X := Function.isEmpty 𝒰.f
simp [ker_eq_top_of_isEmpty]
suffices ∀ U : Y.affineOpens,
(⋃ i, (𝒰.map i ≫ f).ker.support) ∩ U = (f.ker.support ∩ U : Set Y) by
ext x
obtain ⟨_, ⟨U, hU, rfl⟩, hxU, -⟩ :=
(isBasis_affine_open Y).exists_subset_of_mem_open (Set.mem_univ x) isOpen_univ
simpa [hxU] using congr(x ∈ $(this ⟨U, hU⟩))
intro U
simp only [Set.iUnion_inter, coe_support_inter, ← f.iInf_ker_openCover_map_comp_apply 𝒰,
Scheme.zeroLocus_iInf_of_nonempty]
lemma ker_morphismRestrict_ideal (f : X.Hom Y) [QuasiCompact f]
(U : Y.Opens) (V : U.toScheme.affineOpens) :
(f ∣_ U).ker.ideal V = f.ker.ideal ⟨U.ι ''ᵁ V, V.2.image_of_isOpenImmersion _⟩ := by
have inst : QuasiCompact (f ∣_ U) := MorphismProperty.of_isPullback
(isPullback_morphismRestrict _ _).flip inferInstance
ext x
simpa [Scheme.Hom.appLE] using map_eq_zero_iff _
(ConcreteCategory.bijective_of_isIso
(X.presheaf.map (eqToHom (image_morphismRestrict_preimage f U V)).op)).1
lemma ker_ideal_of_isPullback_of_isOpenImmersion {X Y U V : Scheme.{u}}
(f : X ⟶ Y) (f' : U ⟶ V) (iU : U ⟶ X) (iV : V ⟶ Y) [IsOpenImmersion iV]
[QuasiCompact f] (H : IsPullback f' iU iV f) (W) :
f'.ker.ideal W =
(f.ker.ideal ⟨iV ''ᵁ W, W.2.image_of_isOpenImmersion _⟩).comap (iV.appIso W).inv.hom := by
have : QuasiCompact f' := MorphismProperty.of_isPullback H.flip inferInstance
have : IsOpenImmersion iU := MorphismProperty.of_isPullback H inferInstance
ext x
have : iU ''ᵁ f' ⁻¹ᵁ W = f ⁻¹ᵁ iV ''ᵁ W :=
IsOpenImmersion.image_preimage_eq_preimage_image_of_isPullback H W
let e : Γ(X, f ⁻¹ᵁ iV ''ᵁ W) ≅ Γ(U, f' ⁻¹ᵁ W) :=
X.presheaf.mapIso (eqToIso this).op ≪≫ iU.appIso _
have : (iV.appIso W).inv ≫ f.app _ = f'.app W ≫ e.inv := by
rw [Iso.inv_comp_eq, ← Category.assoc, Iso.eq_comp_inv]
simp only [Scheme.Hom.app_eq_appLE, Iso.trans_hom, Functor.mapIso_hom, Iso.op_hom, eqToIso.hom,
eqToHom_op, Scheme.Hom.appIso_hom', Scheme.Hom.map_appLE, e, Scheme.appLE_comp_appLE, H.w]
simp only [Scheme.Hom.ker_apply, RingHom.mem_ker, Ideal.mem_comap, ← RingHom.comp_apply,
← CommRingCat.hom_comp, this]
simpa using (map_eq_zero_iff _ (ConcreteCategory.bijective_of_isIso e.inv).1).symm
lemma Hom.support_ker (f : X.Hom Y) [QuasiCompact f] :
f.ker.support = closure (Set.range f.base) := by
apply subset_antisymm
· wlog hY : ∃ S, Y = Spec S
· intro x hx
let 𝒰 := Y.affineCover
obtain ⟨i, x, rfl⟩ := 𝒰.exists_eq x
have inst : QuasiCompact (𝒰.pullbackHom f i) :=
MorphismProperty.pullback_snd _ _ inferInstance
have := this (𝒰.pullbackHom f i) ⟨_, rfl⟩
((coe_support_inter _ ⟨⊤, isAffineOpen_top _⟩).ge ⟨?_, Set.mem_univ x⟩).1
· have := image_closure_subset_closure_image (f := (𝒰.map i).base)
(𝒰.map i).base.1.2 (Set.mem_image_of_mem _ this)
rw [← Set.range_comp, ← TopCat.coe_comp, ← Scheme.comp_base, 𝒰.pullbackHom_map] at this
exact closure_mono (Set.range_comp_subset_range _ _) this
· rw [← (𝒰.map i).isOpenEmbedding.injective.mem_set_image, Scheme.image_zeroLocus,
ker_ideal_of_isPullback_of_isOpenImmersion f (𝒰.pullbackHom f i)
((𝒰.pullbackCover f).map i) (𝒰.map i) (IsPullback.of_hasPullback _ _).flip,
Ideal.coe_comap, Set.image_preimage_eq]
· exact ⟨((coe_support_inter _ _).le ⟨hx, by simp⟩).1, ⟨_, rfl⟩⟩
· exact (ConcreteCategory.bijective_of_isIso ((𝒰.map i).appIso ⊤).inv).2
obtain ⟨S, rfl⟩ := hY
wlog hX : ∃ R, X = Spec R generalizing X S
· intro x hx
have inst : CompactSpace X := HasAffineProperty.iff_of_isAffine.mp ‹QuasiCompact f›
let 𝒰 := X.affineCover.finiteSubcover
obtain ⟨_, ⟨i, rfl⟩, hx⟩ := (f.iUnion_support_ker_openCover_map_comp 𝒰).ge hx
have inst : QuasiCompact (𝒰.map i ≫ f) := HasAffineProperty.iff_of_isAffine.mpr
(by change CompactSpace (Spec _); infer_instance)
exact closure_mono (Set.range_comp_subset_range _ _) (this S (𝒰.map i ≫ f) ⟨_, rfl⟩ hx)
obtain ⟨R, rfl⟩ := hX
obtain ⟨φ, rfl⟩ := Spec.map_surjective f
rw [ker_of_isAffine, coe_support_ofIdealTop, Spec_zeroLocus, ← Ideal.coe_comap,
RingHom.comap_ker, ← PrimeSpectrum.closure_range_comap, ← CommRingCat.hom_comp,
← Scheme.ΓSpecIso_inv_naturality]
simp only [CommRingCat.hom_comp, PrimeSpectrum.comap_comp, ContinuousMap.coe_comp]
exact closure_mono (Set.range_comp_subset_range _ (Spec.map φ).base)
· rw [(support _).isClosed.closure_subset_iff]
exact f.range_subset_ker_support
/-- The functor taking a morphism into `Y` to its kernel as an ideal sheaf on `Y`. -/
@[simps]
def kerFunctor (Y : Scheme.{u}) : (Over Y)ᵒᵖ ⥤ IdealSheafData Y where
obj f := f.unop.hom.ker
map {f g} hfg := homOfLE <| by simpa only [Functor.id_obj, Functor.const_obj_obj,
OrderDual.toDual_le_toDual, ← Over.w hfg.unop] using hfg.unop.left.le_ker_comp f.unop.hom
map_id _ := Subsingleton.elim _ _
map_comp _ _ := Subsingleton.elim _ _
end ker
end Scheme
end AlgebraicGeometry
|
HomLift.lean
|
/-
Copyright (c) 2024 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Lezeau, Calle Sönne
-/
import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.CommSq
/-!
# HomLift
Given a functor `p : 𝒳 ⥤ 𝒮`, this file provides API for expressing the fact that `p(φ) = f`
for given morphisms `φ` and `f`. The reason this API is needed is because, in general, `p.map φ = f`
does not make sense when the domain and/or codomain of `φ` and `f` are not definitionally equal.
## Main definition
Given morphism `φ : a ⟶ b` in `𝒳` and `f : R ⟶ S` in `𝒮`, `p.IsHomLift f φ` is a class, defined
using the auxiliary inductive type `IsHomLiftAux` which expresses the fact that `f = p(φ)`.
We also define a macro `subst_hom_lift p f φ` which can be used to substitute `f` with `p(φ)` in a
goal, this tactic is just short for `obtain ⟨⟩ := Functor.IsHomLift.cond (p:=p) (f:=f) (φ:=φ)`, and
it is used to make the code more readable.
-/
universe u₁ v₁ u₂ v₂
open CategoryTheory Category
variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒳] [Category.{v₂} 𝒮] (p : 𝒳 ⥤ 𝒮)
namespace CategoryTheory
/-- Helper-type for defining `IsHomLift`. -/
inductive IsHomLiftAux : ∀ {R S : 𝒮} {a b : 𝒳} (_ : R ⟶ S) (_ : a ⟶ b), Prop
| map {a b : 𝒳} (φ : a ⟶ b) : IsHomLiftAux (p.map φ) φ
/-- Given a functor `p : 𝒳 ⥤ 𝒮`, an arrow `φ : a ⟶ b` in `𝒳` and an arrow `f : R ⟶ S` in `𝒮`,
`p.IsHomLift f φ` expresses the fact that `φ` lifts `f` through `p`.
This is often drawn as:
```
a --φ--> b
- -
| |
v v
R --f--> S
``` -/
class Functor.IsHomLift {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) : Prop where
cond : IsHomLiftAux p f φ
/-- `subst_hom_lift p f φ` tries to substitute `f` with `p(φ)` by using `p.IsHomLift f φ` -/
macro "subst_hom_lift" p:term:max f:term:max φ:term:max : tactic =>
`(tactic| obtain ⟨⟩ := Functor.IsHomLift.cond (p := $p) (f := $f) (φ := $φ))
namespace IsHomLift
/-- For any arrow `φ : a ⟶ b` in `𝒳`, `φ` lifts the arrow `p.map φ` in the base `𝒮`. -/
@[simp]
instance map {a b : 𝒳} (φ : a ⟶ b) : p.IsHomLift (p.map φ) φ where
cond := by constructor
@[simp]
instance (a : 𝒳) : p.IsHomLift (𝟙 (p.obj a)) (𝟙 a) := by
rw [← p.map_id]; infer_instance
protected lemma id {p : 𝒳 ⥤ 𝒮} {R : 𝒮} {a : 𝒳} (ha : p.obj a = R) : p.IsHomLift (𝟙 R) (𝟙 a) := by
cases ha; infer_instance
section
variable {R S : 𝒮} {a b : 𝒳}
lemma domain_eq (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] : p.obj a = R := by
subst_hom_lift p f φ; rfl
lemma codomain_eq (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] : p.obj b = S := by
subst_hom_lift p f φ; rfl
variable (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ]
lemma fac : f = eqToHom (domain_eq p f φ).symm ≫ p.map φ ≫ eqToHom (codomain_eq p f φ) := by
subst_hom_lift p f φ; simp
lemma fac' : p.map φ = eqToHom (domain_eq p f φ) ≫ f ≫ eqToHom (codomain_eq p f φ).symm := by
subst_hom_lift p f φ; simp
lemma commSq : CommSq (p.map φ) (eqToHom (domain_eq p f φ)) (eqToHom (codomain_eq p f φ)) f where
w := by simp only [fac p f φ, eqToHom_trans_assoc, eqToHom_refl, id_comp]
end
lemma eq_of_isHomLift {a b : 𝒳} (f : p.obj a ⟶ p.obj b) (φ : a ⟶ b) [p.IsHomLift f φ] :
f = p.map φ := by
simp only [fac p f φ, eqToHom_refl, comp_id, id_comp]
lemma of_fac {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S)
(h : f = eqToHom ha.symm ≫ p.map φ ≫ eqToHom hb) : p.IsHomLift f φ := by
subst ha hb h; simp
lemma of_fac' {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S)
(h : p.map φ = eqToHom ha ≫ f ≫ eqToHom hb.symm) : p.IsHomLift f φ := by
subst ha hb
obtain rfl : f = p.map φ := by simpa using h.symm
infer_instance
lemma of_commsq {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S)
(h : p.map φ ≫ eqToHom hb = (eqToHom ha) ≫ f) : p.IsHomLift f φ := by
subst ha hb
obtain rfl : f = p.map φ := by simpa using h.symm
infer_instance
lemma of_commSq {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (ha : p.obj a = R) (hb : p.obj b = S)
(h : CommSq (p.map φ) (eqToHom ha) (eqToHom hb) f) : p.IsHomLift f φ :=
of_commsq p f φ ha hb h.1
instance comp {R S T : 𝒮} {a b c : 𝒳} (f : R ⟶ S) (g : S ⟶ T) (φ : a ⟶ b)
(ψ : b ⟶ c) [p.IsHomLift f φ] [p.IsHomLift g ψ] : p.IsHomLift (f ≫ g) (φ ≫ ψ) := by
apply of_commSq
-- This line transforms the first goal in suitable form; the last line closes all three goals.
on_goal 1 => rw [p.map_comp]
apply CommSq.horiz_comp (commSq p f φ) (commSq p g ψ)
/-- If `φ : a ⟶ b` and `ψ : b ⟶ c` lift `𝟙 R`, then so does `φ ≫ ψ` -/
instance comp_of_lift_id (R : 𝒮) {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c)
[p.IsHomLift (𝟙 R) φ] [p.IsHomLift (𝟙 R) ψ] : p.IsHomLift (𝟙 R) (φ ≫ ψ) :=
comp_id (𝟙 R) ▸ comp p (𝟙 R) (𝟙 R) φ ψ
instance comp_lift_id_right {a b c : 𝒳} {S T : 𝒮} (f : S ⟶ T) (φ : a ⟶ b) [p.IsHomLift f φ]
(ψ : b ⟶ c) [p.IsHomLift (𝟙 T) ψ] : p.IsHomLift f (φ ≫ ψ) := by
simpa using inferInstanceAs (p.IsHomLift (f ≫ 𝟙 T) (φ ≫ ψ))
/-- If `φ : a ⟶ b` lifts `f` and `ψ : b ⟶ c` lifts `𝟙 T`, then `φ ≫ ψ` lifts `f` -/
lemma comp_lift_id_right' {R S : 𝒮} {a b c : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ]
(T : 𝒮) (ψ : b ⟶ c) [p.IsHomLift (𝟙 T) ψ] : p.IsHomLift f (φ ≫ ψ) := by
obtain rfl : S = T := by rw [← codomain_eq p f φ, domain_eq p (𝟙 T) ψ]
infer_instance
instance comp_lift_id_left {a b c : 𝒳} {S T : 𝒮} (f : S ⟶ T) (ψ : b ⟶ c) [p.IsHomLift f ψ]
(φ : a ⟶ b) [p.IsHomLift (𝟙 S) φ] : p.IsHomLift f (φ ≫ ψ) := by
simpa using inferInstanceAs (p.IsHomLift (𝟙 S ≫ f) (φ ≫ ψ))
/-- If `φ : a ⟶ b` lifts `𝟙 T` and `ψ : b ⟶ c` lifts `f`, then `φ ≫ ψ` lifts `f` -/
lemma comp_lift_id_left' {a b c : 𝒳} (R : 𝒮) (φ : a ⟶ b) [p.IsHomLift (𝟙 R) φ]
{S T : 𝒮} (f : S ⟶ T) (ψ : b ⟶ c) [p.IsHomLift f ψ] : p.IsHomLift f (φ ≫ ψ) := by
obtain rfl : R = S := by rw [← codomain_eq p (𝟙 R) φ, domain_eq p f ψ]
infer_instance
lemma eqToHom_domain_lift_id {p : 𝒳 ⥤ 𝒮} {a b : 𝒳} (hab : a = b) {R : 𝒮} (hR : p.obj a = R) :
p.IsHomLift (𝟙 R) (eqToHom hab) := by
subst hR hab; simp
lemma eqToHom_codomain_lift_id {p : 𝒳 ⥤ 𝒮} {a b : 𝒳} (hab : a = b) {S : 𝒮} (hS : p.obj b = S) :
p.IsHomLift (𝟙 S) (eqToHom hab) := by
subst hS hab; simp
lemma id_lift_eqToHom_domain {p : 𝒳 ⥤ 𝒮} {R S : 𝒮} (hRS : R = S) {a : 𝒳} (ha : p.obj a = R) :
p.IsHomLift (eqToHom hRS) (𝟙 a) := by
subst hRS ha; simp
lemma id_lift_eqToHom_codomain {p : 𝒳 ⥤ 𝒮} {R S : 𝒮} (hRS : R = S) {b : 𝒳} (hb : p.obj b = S) :
p.IsHomLift (eqToHom hRS) (𝟙 b) := by
subst hRS hb; simp
section
variable {R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ]
instance comp_id_lift : p.IsHomLift f (𝟙 a ≫ φ) := by
simp_all
instance id_comp_lift : p.IsHomLift f (φ ≫ 𝟙 b) := by
simp_all
instance lift_id_comp : p.IsHomLift (𝟙 R ≫ f) φ := by
simp_all
instance lift_comp_id : p.IsHomLift (f ≫ 𝟙 S) φ := by
simp_all
instance comp_eqToHom_lift {a' : 𝒳} (h : a' = a) : p.IsHomLift f (eqToHom h ≫ φ) := by
subst h; simp_all
instance eqToHom_comp_lift {b' : 𝒳} (h : b = b') : p.IsHomLift f (φ ≫ eqToHom h) := by
subst h; simp_all
instance lift_eqToHom_comp {R' : 𝒮} (h : R' = R) : p.IsHomLift (eqToHom h ≫ f) φ := by
subst h; simp_all
instance lift_comp_eqToHom {S' : 𝒮} (h : S = S') : p.IsHomLift (f ≫ eqToHom h) φ := by
subst h; simp_all
end
@[simp]
lemma comp_eqToHom_lift_iff {R S : 𝒮} {a' a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : a' = a) :
p.IsHomLift f (eqToHom h ≫ φ) ↔ p.IsHomLift f φ where
mp hφ' := by subst h; simpa using hφ'
mpr _ := inferInstance
@[simp]
lemma eqToHom_comp_lift_iff {R S : 𝒮} {a b b' : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : b = b') :
p.IsHomLift f (φ ≫ eqToHom h) ↔ p.IsHomLift f φ where
mp hφ' := by subst h; simpa using hφ'
mpr _ := inferInstance
@[simp]
lemma lift_eqToHom_comp_iff {R' R S : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : R' = R) :
p.IsHomLift (eqToHom h ≫ f) φ ↔ p.IsHomLift f φ where
mp hφ' := by subst h; simpa using hφ'
mpr _ := inferInstance
@[simp]
lemma lift_comp_eqToHom_iff {R S S' : 𝒮} {a b : 𝒳} (f : R ⟶ S) (φ : a ⟶ b) (h : S = S') :
p.IsHomLift (f ≫ eqToHom h) φ ↔ p.IsHomLift f φ where
mp := fun hφ' => by subst h; simpa using hφ'
mpr := fun _ => inferInstance
section
variable {R S : 𝒮} {a b : 𝒳}
/-- Given a morphism `f : R ⟶ S`, and an isomorphism `φ : a ≅ b` lifting `f`, `isoOfIsoLift f φ` is
the isomorphism `Φ : R ≅ S` with `Φ.hom = f` induced from `φ` -/
@[simps hom]
def isoOfIsoLift (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] :
R ≅ S where
hom := f
inv := eqToHom (codomain_eq p f φ.hom).symm ≫ (p.mapIso φ).inv ≫ eqToHom (domain_eq p f φ.hom)
hom_inv_id := by subst_hom_lift p f φ.hom; simp [← p.map_comp]
inv_hom_id := by subst_hom_lift p f φ.hom; simp [← p.map_comp]
@[simp]
lemma isoOfIsoLift_inv_hom_id (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] :
(isoOfIsoLift p f φ).inv ≫ f = 𝟙 S :=
(isoOfIsoLift p f φ).inv_hom_id
@[simp]
lemma isoOfIsoLift_hom_inv_id (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] :
f ≫ (isoOfIsoLift p f φ).inv = 𝟙 R :=
(isoOfIsoLift p f φ).hom_inv_id
/-- If `φ : a ⟶ b` lifts `f : R ⟶ S` and `φ` is an isomorphism, then so is `f`. -/
lemma isIso_of_lift_isIso (f : R ⟶ S) (φ : a ⟶ b) [p.IsHomLift f φ] [IsIso φ] : IsIso f :=
(fac p f φ) ▸ inferInstance
/-- Given `φ : a ≅ b` and `f : R ≅ S`, such that `φ.hom` lifts `f.hom`, then `φ.inv` lifts
`f.inv`. -/
instance inv_lift_inv (f : R ≅ S) (φ : a ≅ b) [p.IsHomLift f.hom φ.hom] :
p.IsHomLift f.inv φ.inv := by
apply of_commSq
apply CommSq.horiz_inv (f := p.mapIso φ) (commSq p f.hom φ.hom)
/-- Given `φ : a ≅ b` and `f : R ⟶ S`, such that `φ.hom` lifts `f`, then `φ.inv` lifts the
inverse of `f` given by `isoOfIsoLift`. -/
instance inv_lift (f : R ⟶ S) (φ : a ≅ b) [p.IsHomLift f φ.hom] :
p.IsHomLift (isoOfIsoLift p f φ).inv φ.inv := by
apply of_commSq
apply CommSq.horiz_inv (f := p.mapIso φ) (by apply commSq p f φ.hom)
/-- If `φ : a ⟶ b` lifts `f : R ⟶ S` and both are isomorphisms, then `φ⁻¹` lifts `f⁻¹`. -/
protected instance inv (f : R ⟶ S) (φ : a ⟶ b) [IsIso f] [IsIso φ] [p.IsHomLift f φ] :
p.IsHomLift (inv f) (inv φ) :=
have : p.IsHomLift (asIso f).hom (asIso φ).hom := by simp_all
IsHomLift.inv_lift_inv p (asIso f) (asIso φ)
end
/-- If `φ : a ≅ b` is an isomorphism lifting `𝟙 S` for some `S : 𝒮`, then `φ⁻¹` also
lifts `𝟙 S`. -/
instance lift_id_inv (S : 𝒮) {a b : 𝒳} (φ : a ≅ b) [p.IsHomLift (𝟙 S) φ.hom] :
p.IsHomLift (𝟙 S) φ.inv :=
have : p.IsHomLift (asIso (𝟙 S)).hom φ.hom := by simp_all
(IsIso.inv_id (X := S)) ▸ (IsHomLift.inv_lift_inv p (asIso (𝟙 S)) φ)
instance lift_id_inv_isIso (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsIso φ] [p.IsHomLift (𝟙 S) φ] :
p.IsHomLift (𝟙 S) (inv φ) :=
(IsIso.inv_id (X := S)) ▸ (IsHomLift.inv p _ φ)
end IsHomLift
end CategoryTheory
|
morphism.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 fintype finfun bigop finset fingroup.
(******************************************************************************)
(* This file contains the definitions of: *)
(* *)
(* {morphism D >-> rT} == *)
(* the structure type of functions that are group morphisms mapping a *)
(* domain set D : {set aT} to a type rT; rT must have a finGroupType *)
(* structure, and D is usually a group (most of the theory expects this). *)
(* mfun == the coercion projecting {morphism D >-> rT} to aT -> rT *)
(* *)
(* Basic examples: *)
(* idm D == the identity morphism with domain D, or more precisely *)
(* the identity function, but with a canonical *)
(* {morphism G -> gT} structure. *)
(* trivm D == the trivial morphism with domain D. *)
(* If f has a {morphism D >-> rT} structure *)
(* 'dom f == D, the domain of f. *)
(* f @* A == the image of A by f, where f is defined. *)
(* := f @: (D :&: A) *)
(* f @*^-1 R == the pre-image of R by f, where f is defined. *)
(* := D :&: f @^-1: R *)
(* 'ker f == the kernel of f. *)
(* := f @*^-1 1 *)
(* 'ker_G f == the kernel of f restricted to G. *)
(* := G :&: 'ker f (this is a pure notation) *)
(* 'injm f <=> f injective on D. *)
(* <-> ker f \subset 1 (this is a pure notation) *)
(* invm injf == the inverse morphism of f, with domain f @* D, when f *)
(* is injective (injf : 'injm f). *)
(* restrm f sDom == the restriction of f to a subset A of D, given *)
(* (sDom : A \subset D); restrm f sDom is transparently *)
(* identical to f; the restrmP and domP lemmas provide *)
(* opaque restrictions. *)
(* *)
(* G \isog H <=> G and H are isomorphic as groups. *)
(* H \homg G <=> H is a homomorphic image of G. *)
(* isom G H f <=> f maps G isomorphically to H, provided D contains G. *)
(* := f @: G^# == H^# *)
(* *)
(* If, moreover, g : {morphism G >-> gT} with G : {group aT}, *)
(* factm sKer sDom == the (natural) factor morphism mapping f @* G to g @* G *)
(* with sDom : G \subset D, sKer : 'ker f \subset 'ker g. *)
(* ifactm injf g == the (natural) factor morphism mapping f @* G to g @* G *)
(* when f is injective (injf : 'injm f); here g must *)
(* denote an actual morphism structure, not its function *)
(* projection. *)
(* *)
(* If g has a {morphism G >-> aT} structure for any G : {group gT}, then *)
(* f \o g has a canonical {morphism g @*^-1 D >-> rT} structure. *)
(* *)
(* Finally, for an arbitrary function f : aT -> rT *)
(* morphic D f <=> f preserves group multiplication in D, i.e., *)
(* f (x * y) = (f x) * (f y) for all x, y in D. *)
(* morphm fM == a function identical to f, but with a canonical *)
(* {morphism D >-> rT} structure, given fM : morphic D f. *)
(* misom D C f <=> f is a morphism that maps D isomorphically to C. *)
(* := morphic D f && isom D C f *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Reserved Notation "x \isog y" (at level 70).
Section MorphismStructure.
Variables aT rT : finGroupType.
Structure morphism (D : {set aT}) : Type := Morphism {
mfun :> aT -> FinGroup.sort rT;
_ : {in D &, {morph mfun : x y / x * y}}
}.
(* We give the 'lightest' possible specification to define morphisms: local *)
(* congruence, in D, with the group law of aT. We then provide the properties *)
(* for the 'textbook' notion of morphism, when the required structures are *)
(* available (e.g. its domain is a group). *)
Definition morphism_for D of phant rT := morphism D.
Definition clone_morphism D f :=
let: Morphism _ fM := f
return {type of @Morphism D for f} -> morphism_for D (Phant rT)
in fun k => k fM.
Variables (D A : {set aT}) (R : {set rT}) (x : aT) (y : rT) (f : aT -> rT).
Variant morphim_spec : Prop := MorphimSpec z & z \in D & z \in A & y = f z.
Lemma morphimP : reflect morphim_spec (y \in f @: (D :&: A)).
Proof.
apply: (iffP imsetP) => [] [z]; first by case/setIP; exists z.
by exists z; first apply/setIP.
Qed.
Lemma morphpreP : reflect (x \in D /\ f x \in R) (x \in D :&: f @^-1: R).
Proof. by rewrite !inE; apply: andP. Qed.
End MorphismStructure.
Notation "{ 'morphism' D >-> T }" := (morphism_for D (Phant T))
(format "{ 'morphism' D >-> T }") : type_scope.
Notation "[ 'morphism' D 'of' f ]" :=
(@clone_morphism _ _ D _ (fun fM => @Morphism _ _ D f fM))
(format "[ 'morphism' D 'of' f ]") : form_scope.
Notation "[ 'morphism' 'of' f ]" := (clone_morphism (@Morphism _ _ _ f))
(format "[ 'morphism' 'of' f ]") : form_scope.
Arguments morphimP {aT rT D A y f}.
Arguments morphpreP {aT rT D R x f}.
(* Domain, image, preimage, kernel, using phantom types to infer the domain. *)
Section MorphismOps1.
Variables (aT rT : finGroupType) (D : {set aT}) (f : {morphism D >-> rT}).
Lemma morphM : {in D &, {morph f : x y / x * y}}.
Proof. by case f. Qed.
Notation morPhantom := (phantom (aT -> rT)).
Definition MorPhantom := Phantom (aT -> rT).
Definition dom of morPhantom f := D.
Definition morphim of morPhantom f := fun A => f @: (D :&: A).
Definition morphpre of morPhantom f := fun R : {set rT} => D :&: f @^-1: R.
Definition ker mph := morphpre mph 1.
End MorphismOps1.
Arguments morphim _ _ _%_g _ _ _%_g.
Arguments morphpre _ _ _%_g _ _ _%_g.
Notation "''dom' f" := (dom (MorPhantom f))
(at level 10, f at level 8, format "''dom' f") : group_scope.
Notation "''ker' f" := (ker (MorPhantom f))
(at level 10, f at level 8, format "''ker' f") : group_scope.
Notation "''ker_' H f" := (H :&: 'ker f)
(at level 10, H at level 2, f at level 8, format "''ker_' H f")
: group_scope.
Notation "f @* A" := (morphim (MorPhantom f) A)
(at level 24, format "f @* A") : group_scope.
Notation "f @*^-1 R" := (morphpre (MorPhantom f) R)
(at level 24, format "f @*^-1 R") : group_scope.
Notation "''injm' f" := (pred_of_set ('ker f) \subset pred_of_set 1)
(at level 10, f at level 8, format "''injm' f") : group_scope.
Section MorphismTheory.
Variables aT rT : finGroupType.
Implicit Types A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Types R S : {set rT}.
Implicit Types M : {group rT}.
(* Most properties of morphims hold only when the domain is a group. *)
Variables (D : {group aT}) (f : {morphism D >-> rT}).
Lemma morph1 : f 1 = 1.
Proof. by apply: (mulgI (f 1)); rewrite -morphM ?mulg1. Qed.
Lemma morph_prod I r (P : pred I) F :
(forall i, P i -> F i \in D) ->
f (\prod_(i <- r | P i) F i) = \prod_( i <- r | P i) f (F i).
Proof.
move=> D_F; elim/(big_load (fun x => x \in D)): _.
elim/big_rec2: _ => [|i _ x Pi [Dx <-]]; first by rewrite morph1.
by rewrite groupM ?morphM // D_F.
Qed.
Lemma morphV : {in D, {morph f : x / x^-1}}.
Proof.
move=> x Dx; apply: (mulgI (f x)).
by rewrite -morphM ?groupV // !mulgV morph1.
Qed.
Lemma morphJ : {in D &, {morph f : x y / x ^ y}}.
Proof. by move=> * /=; rewrite !morphM ?morphV // ?groupM ?groupV. Qed.
Lemma morphX n : {in D, {morph f : x / x ^+ n}}.
Proof.
by elim: n => [|n IHn] x Dx; rewrite ?morph1 // !expgS morphM ?(groupX, IHn).
Qed.
Lemma morphR : {in D &, {morph f : x y / [~ x, y]}}.
Proof. by move=> * /=; rewrite morphM ?(groupV, groupJ) // morphJ ?morphV. Qed.
(* Morphic image, preimage properties w.r.t. set-theoretic operations. *)
Lemma morphimE A : f @* A = f @: (D :&: A). Proof. by []. Qed.
Lemma morphpreE R : f @*^-1 R = D :&: f @^-1: R. Proof. by []. Qed.
Lemma kerE : 'ker f = f @*^-1 1. Proof. by []. Qed.
Lemma morphimEsub A : A \subset D -> f @* A = f @: A.
Proof. by move=> sAD; rewrite /morphim (setIidPr sAD). Qed.
Lemma morphimEdom : f @* D = f @: D.
Proof. exact: morphimEsub. Qed.
Lemma morphimIdom A : f @* (D :&: A) = f @* A.
Proof. by rewrite /morphim setIA setIid. Qed.
Lemma morphpreIdom R : D :&: f @*^-1 R = f @*^-1 R.
Proof. by rewrite /morphim setIA setIid. Qed.
Lemma morphpreIim R : f @*^-1 (f @* D :&: R) = f @*^-1 R.
Proof.
apply/setP=> x; rewrite morphimEdom !inE.
by case Dx: (x \in D); rewrite // imset_f.
Qed.
Lemma morphimIim A : f @* D :&: f @* A = f @* A.
Proof. by apply/setIidPr; rewrite imsetS // setIid subsetIl. Qed.
Lemma mem_morphim A x : x \in D -> x \in A -> f x \in f @* A.
Proof. by move=> Dx Ax; apply/morphimP; exists x. Qed.
Lemma mem_morphpre R x : x \in D -> f x \in R -> x \in f @*^-1 R.
Proof. by move=> Dx Rfx; apply/morphpreP. Qed.
Lemma morphimS A B : A \subset B -> f @* A \subset f @* B.
Proof. by move=> sAB; rewrite imsetS ?setIS. Qed.
Lemma morphim_sub A : f @* A \subset f @* D.
Proof. by rewrite imsetS // setIid subsetIl. Qed.
Lemma leq_morphim A : #|f @* A| <= #|A|.
Proof.
by apply: (leq_trans (leq_imset_card _ _)); rewrite subset_leq_card ?subsetIr.
Qed.
Lemma morphpreS R S : R \subset S -> f @*^-1 R \subset f @*^-1 S.
Proof. by move=> sRS; rewrite setIS ?preimsetS. Qed.
Lemma morphpre_sub R : f @*^-1 R \subset D.
Proof. exact: subsetIl. Qed.
Lemma morphim_setIpre A R : f @* (A :&: f @*^-1 R) = f @* A :&: R.
Proof.
apply/setP=> fa; apply/morphimP/setIP=> [[a Da] | [/morphimP[a Da Aa ->] Rfa]].
by rewrite !inE Da /= => /andP[Aa Rfa] ->; rewrite mem_morphim.
by exists a; rewrite // !inE Aa Da.
Qed.
Lemma morphim0 : f @* set0 = set0.
Proof. by rewrite morphimE setI0 imset0. Qed.
Lemma morphim_eq0 A : A \subset D -> (f @* A == set0) = (A == set0).
Proof. by rewrite imset_eq0 => /setIidPr->. Qed.
Lemma morphim_set1 x : x \in D -> f @* [set x] = [set f x].
Proof. by rewrite /morphim -sub1set => /setIidPr->; apply: imset_set1. Qed.
Lemma morphim1 : f @* 1 = 1.
Proof. by rewrite morphim_set1 ?morph1. Qed.
Lemma morphimV A : f @* A^-1 = (f @* A)^-1.
Proof.
wlog suffices: A / f @* A^-1 \subset (f @* A)^-1.
by move=> IH; apply/eqP; rewrite eqEsubset IH -invSg invgK -{1}(invgK A) IH.
apply/subsetP=> _ /morphimP[x Dx Ax' ->]; rewrite !inE in Ax' *.
by rewrite -morphV // imset_f // inE groupV Dx.
Qed.
Lemma morphpreV R : f @*^-1 R^-1 = (f @*^-1 R)^-1.
Proof.
apply/setP=> x; rewrite !inE groupV; case Dx: (x \in D) => //=.
by rewrite morphV.
Qed.
Lemma morphimMl A B : A \subset D -> f @* (A * B) = f @* A * f @* B.
Proof.
move=> sAD; rewrite /morphim setIC -group_modl // (setIidPr sAD).
apply/setP=> fxy; apply/idP/idP.
case/imsetP=> _ /imset2P[x y Ax /setIP[Dy By] ->] ->{fxy}.
by rewrite morphM // (subsetP sAD, imset2_f) // imset_f // inE By.
case/imset2P=> _ _ /imsetP[x Ax ->] /morphimP[y Dy By ->] ->{fxy}.
by rewrite -morphM // (subsetP sAD, imset_f) // mem_mulg // inE By.
Qed.
Lemma morphimMr A B : B \subset D -> f @* (A * B) = f @* A * f @* B.
Proof.
move=> sBD; apply: invg_inj.
by rewrite invMg -!morphimV invMg morphimMl // -invGid invSg.
Qed.
Lemma morphpreMl R S :
R \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S.
Proof.
move=> sRfD; apply/setP=> x; rewrite !inE.
apply/andP/imset2P=> [[Dx] | [y z]]; last first.
rewrite !inE => /andP[Dy Rfy] /andP[Dz Rfz] ->.
by rewrite ?(groupM, morphM, imset2_f).
case/imset2P=> fy fz Rfy Rfz def_fx.
have /morphimP[y Dy _ def_fy]: fy \in f @* D := subsetP sRfD fy Rfy.
exists y (y^-1 * x); last by rewrite mulKVg.
by rewrite !inE Dy -def_fy.
by rewrite !inE groupM ?(morphM, morphV, groupV) // def_fx -def_fy mulKg.
Qed.
Lemma morphimJ A x : x \in D -> f @* (A :^ x) = f @* A :^ f x.
Proof.
move=> Dx; rewrite !conjsgE morphimMl ?(morphimMr, sub1set, groupV) //.
by rewrite !(morphim_set1, groupV, morphV).
Qed.
Lemma morphpreJ R x : x \in D -> f @*^-1 (R :^ f x) = f @*^-1 R :^ x.
Proof.
move=> Dx; apply/setP=> y; rewrite conjIg !inE conjGid // !mem_conjg inE.
by case Dy: (y \in D); rewrite // morphJ ?(morphV, groupV).
Qed.
Lemma morphim_class x A :
x \in D -> A \subset D -> f @* (x ^: A) = f x ^: f @* A.
Proof.
move=> Dx sAD; rewrite !morphimEsub ?class_subG // /class -!imset_comp.
by apply: eq_in_imset => y Ay /=; rewrite morphJ // (subsetP sAD).
Qed.
Lemma classes_morphim A :
A \subset D -> classes (f @* A) = [set f @* xA | xA in classes A].
Proof.
move=> sAD; rewrite morphimEsub // /classes -!imset_comp.
apply: eq_in_imset => x /(subsetP sAD) Dx /=.
by rewrite morphim_class ?morphimEsub.
Qed.
Lemma morphimT : f @* setT = f @* D.
Proof. by rewrite -morphimIdom setIT. Qed.
Lemma morphimU A B : f @* (A :|: B) = f @* A :|: f @* B.
Proof. by rewrite -imsetU -setIUr. Qed.
Lemma morphimI A B : f @* (A :&: B) \subset f @* A :&: f @* B.
Proof. by rewrite subsetI // ?morphimS ?(subsetIl, subsetIr). Qed.
Lemma morphpre0 : f @*^-1 set0 = set0.
Proof. by rewrite morphpreE preimset0 setI0. Qed.
Lemma morphpreT : f @*^-1 setT = D.
Proof. by rewrite morphpreE preimsetT setIT. Qed.
Lemma morphpreU R S : f @*^-1 (R :|: S) = f @*^-1 R :|: f @*^-1 S.
Proof. by rewrite -setIUr -preimsetU. Qed.
Lemma morphpreI R S : f @*^-1 (R :&: S) = f @*^-1 R :&: f @*^-1 S.
Proof. by rewrite -setIIr -preimsetI. Qed.
Lemma morphpreD R S : f @*^-1 (R :\: S) = f @*^-1 R :\: f @*^-1 S.
Proof. by apply/setP=> x /[!inE]; case: (x \in D). Qed.
(* kernel, domain properties *)
Lemma kerP x : x \in D -> reflect (f x = 1) (x \in 'ker f).
Proof. by move=> Dx; rewrite 2!inE Dx; apply: set1P. Qed.
Lemma dom_ker : {subset 'ker f <= D}.
Proof. by move=> x /morphpreP[]. Qed.
Lemma mker x : x \in 'ker f -> f x = 1.
Proof. by move=> Kx; apply/kerP=> //; apply: dom_ker. Qed.
Lemma mkerl x y : x \in 'ker f -> y \in D -> f (x * y) = f y.
Proof. by move=> Kx Dy; rewrite morphM // ?(dom_ker, mker Kx, mul1g). Qed.
Lemma mkerr x y : x \in D -> y \in 'ker f -> f (x * y) = f x.
Proof. by move=> Dx Ky; rewrite morphM // ?(dom_ker, mker Ky, mulg1). Qed.
Lemma rcoset_kerP x y :
x \in D -> y \in D -> reflect (f x = f y) (x \in 'ker f :* y).
Proof.
move=> Dx Dy; rewrite mem_rcoset !inE groupM ?morphM ?groupV //=.
by rewrite morphV // -eq_mulgV1; apply: eqP.
Qed.
Lemma ker_rcoset x y :
x \in D -> y \in D -> f x = f y -> exists2 z, z \in 'ker f & x = z * y.
Proof. by move=> Dx Dy eqfxy; apply/rcosetP; apply/rcoset_kerP. Qed.
Lemma ker_norm : D \subset 'N('ker f).
Proof.
apply/subsetP=> x Dx /[1!inE]; apply/subsetP=> _ /imsetP[y Ky ->].
by rewrite !inE groupJ ?morphJ // ?dom_ker //= mker ?conj1g.
Qed.
Lemma ker_normal : 'ker f <| D.
Proof. by rewrite /(_ <| D) subsetIl ker_norm. Qed.
Lemma morphimGI G A : 'ker f \subset G -> f @* (G :&: A) = f @* G :&: f @* A.
Proof.
move=> sKG; apply/eqP; rewrite eqEsubset morphimI setIC.
apply/subsetP=> _ /setIP[/morphimP[x Dx Ax ->] /morphimP[z Dz Gz]].
case/ker_rcoset=> {Dz}// y Ky def_x.
have{z Gz y Ky def_x} Gx: x \in G by rewrite def_x groupMl // (subsetP sKG).
by rewrite imset_f ?inE // Dx Gx Ax.
Qed.
Lemma morphimIG A G : 'ker f \subset G -> f @* (A :&: G) = f @* A :&: f @* G.
Proof. by move=> sKG; rewrite setIC morphimGI // setIC. Qed.
Lemma morphimD A B : f @* A :\: f @* B \subset f @* (A :\: B).
Proof.
rewrite subDset -morphimU morphimS //.
by rewrite setDE setUIr setUCr setIT subsetUr.
Qed.
Lemma morphimDG A G : 'ker f \subset G -> f @* (A :\: G) = f @* A :\: f @* G.
Proof.
move=> sKG; apply/eqP; rewrite eqEsubset morphimD andbT !setDE subsetI.
rewrite morphimS ?subsetIl // -[~: f @* G]setU0 -subDset setDE setCK.
by rewrite -morphimIG //= setIAC -setIA setICr setI0 morphim0.
Qed.
Lemma morphimD1 A : (f @* A)^# \subset f @* A^#.
Proof. by rewrite -!set1gE -morphim1 morphimD. Qed.
(* group structure preservation *)
Lemma morphpre_groupset M : group_set (f @*^-1 M).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?(morph1, group1) //.
by case/andP=> Dx Mfx /andP[Dy Mfy]; rewrite morphM ?groupM.
Qed.
Lemma morphim_groupset G : group_set (f @* G).
Proof.
apply/group_setP; split=> [|_ _ /morphimP[x Dx Gx ->] /morphimP[y Dy Gy ->]].
by rewrite -morph1 imset_f ?group1.
by rewrite -morphM ?imset_f ?inE ?groupM.
Qed.
Canonical morphpre_group fPh M :=
@group _ (morphpre fPh M) (morphpre_groupset M).
Canonical morphim_group fPh G := @group _ (morphim fPh G) (morphim_groupset G).
Canonical ker_group fPh : {group aT} := Eval hnf in [group of ker fPh].
Lemma morph_dom_groupset : group_set (f @: D).
Proof. by rewrite -morphimEdom groupP. Qed.
Canonical morph_dom_group := group morph_dom_groupset.
Lemma morphpreMr R S :
S \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S.
Proof.
move=> sSfD; apply: invg_inj.
by rewrite invMg -!morphpreV invMg morphpreMl // -invSg invgK invGid.
Qed.
Lemma morphimK A : A \subset D -> f @*^-1 (f @* A) = 'ker f * A.
Proof.
move=> sAD; apply/setP=> x; rewrite !inE.
apply/idP/idP=> [/andP[Dx /morphimP[y Dy Ay eqxy]] | /imset2P[z y Kz Ay ->{x}]].
rewrite -(mulgKV y x) mem_mulg // !inE !(groupM, morphM, groupV) //.
by rewrite morphV //= eqxy mulgV.
have [Dy Dz]: y \in D /\ z \in D by rewrite (subsetP sAD) // dom_ker.
by rewrite groupM // morphM // mker // mul1g imset_f // inE Dy.
Qed.
Lemma morphimGK G : 'ker f \subset G -> G \subset D -> f @*^-1 (f @* G) = G.
Proof. by move=> sKG sGD; rewrite morphimK // mulSGid. Qed.
Lemma morphpre_set1 x : x \in D -> f @*^-1 [set f x] = 'ker f :* x.
Proof. by move=> Dx; rewrite -morphim_set1 // morphimK ?sub1set. Qed.
Lemma morphpreK R : R \subset f @* D -> f @* (f @*^-1 R) = R.
Proof.
move=> sRfD; apply/setP=> y; apply/morphimP/idP=> [[x _] | Ry].
by rewrite !inE; case/andP=> _ Rfx ->.
have /morphimP[x Dx _ defy]: y \in f @* D := subsetP sRfD y Ry.
by exists x; rewrite // !inE Dx -defy.
Qed.
Lemma morphim_ker : f @* 'ker f = 1.
Proof. by rewrite morphpreK ?sub1G. Qed.
Lemma ker_sub_pre M : 'ker f \subset f @*^-1 M.
Proof. by rewrite morphpreS ?sub1G. Qed.
Lemma ker_normal_pre M : 'ker f <| f @*^-1 M.
Proof. by rewrite /normal ker_sub_pre subIset ?ker_norm. Qed.
Lemma morphpreSK R S :
R \subset f @* D -> (f @*^-1 R \subset f @*^-1 S) = (R \subset S).
Proof.
move=> sRfD; apply/idP/idP=> [sf'RS|]; last exact: morphpreS.
suffices: R \subset f @* D :&: S by rewrite subsetI sRfD.
rewrite -(morphpreK sRfD) -[_ :&: S]morphpreK (morphimS, subsetIl) //.
by rewrite morphpreI morphimGK ?subsetIl // setIA setIid.
Qed.
Lemma sub_morphim_pre A R :
A \subset D -> (f @* A \subset R) = (A \subset f @*^-1 R).
Proof.
move=> sAD; rewrite -morphpreSK (morphimS, morphimK) //.
apply/idP/idP; first by apply: subset_trans; apply: mulG_subr.
by move/(mulgS ('ker f)); rewrite -morphpreMl ?(sub1G, mul1g).
Qed.
Lemma morphpre_proper R S :
R \subset f @* D -> S \subset f @* D ->
(f @*^-1 R \proper f @*^-1 S) = (R \proper S).
Proof. by move=> dQ dR; rewrite /proper !morphpreSK. Qed.
Lemma sub_morphpre_im R G :
'ker f \subset G -> G \subset D -> R \subset f @* D ->
(f @*^-1 R \subset G) = (R \subset f @* G).
Proof. by symmetry; rewrite -morphpreSK ?morphimGK. Qed.
Lemma ker_trivg_morphim A :
(A \subset 'ker f) = (A \subset D) && (f @* A \subset [1]).
Proof.
case sAD: (A \subset D); first by rewrite sub_morphim_pre.
by rewrite subsetI sAD.
Qed.
Lemma morphimSK A B :
A \subset D -> (f @* A \subset f @* B) = (A \subset 'ker f * B).
Proof.
move=> sAD; transitivity (A \subset 'ker f * (D :&: B)).
by rewrite -morphimK ?subsetIl // -sub_morphim_pre // /morphim setIA setIid.
by rewrite setIC group_modl (subsetIl, subsetI) // andbC sAD.
Qed.
Lemma morphimSGK A G :
A \subset D -> 'ker f \subset G -> (f @* A \subset f @* G) = (A \subset G).
Proof. by move=> sGD skfK; rewrite morphimSK // mulSGid. Qed.
Lemma ltn_morphim A : [1] \proper 'ker_A f -> #|f @* A| < #|A|.
Proof.
case/properP; rewrite sub1set => /setIP[A1 _] [x /setIP[Ax kx] x1].
rewrite (cardsD1 1 A) A1 ltnS -{1}(setD1K A1) morphimU morphim1.
rewrite (setUidPr _) ?sub1set; last first.
by rewrite -(mker kx) mem_morphim ?(dom_ker kx) // inE x1.
by rewrite (leq_trans (leq_imset_card _ _)) ?subset_leq_card ?subsetIr.
Qed.
(* injectivity of image and preimage *)
Lemma morphpre_inj :
{in [pred R : {set rT} | R \subset f @* D] &, injective (fun R => f @*^-1 R)}.
Proof. exact: can_in_inj morphpreK. Qed.
Lemma morphim_injG :
{in [pred G : {group aT} | 'ker f \subset G & G \subset D] &,
injective (fun G => f @* G)}.
Proof.
move=> G H /andP[sKG sGD] /andP[sKH sHD] eqfGH.
by apply: val_inj; rewrite /= -(morphimGK sKG sGD) eqfGH morphimGK.
Qed.
Lemma morphim_inj G H :
('ker f \subset G) && (G \subset D) ->
('ker f \subset H) && (H \subset D) ->
f @* G = f @* H -> G :=: H.
Proof. by move=> nsGf nsHf /morphim_injG->. Qed.
(* commutation with generated groups and cycles *)
Lemma morphim_gen A : A \subset D -> f @* <<A>> = <<f @* A>>.
Proof.
move=> sAD; apply/eqP.
rewrite eqEsubset andbC gen_subG morphimS; last exact: subset_gen.
by rewrite sub_morphim_pre gen_subG // -sub_morphim_pre // subset_gen.
Qed.
Lemma morphim_cycle x : x \in D -> f @* <[x]> = <[f x]>.
Proof. by move=> Dx; rewrite morphim_gen (sub1set, morphim_set1). Qed.
Lemma morphimY A B :
A \subset D -> B \subset D -> f @* (A <*> B) = f @* A <*> f @* B.
Proof. by move=> sAD sBD; rewrite morphim_gen ?morphimU // subUset sAD. Qed.
Lemma morphpre_gen R :
1 \in R -> R \subset f @* D -> f @*^-1 <<R>> = <<f @*^-1 R>>.
Proof.
move=> R1 sRfD; apply/eqP.
rewrite eqEsubset andbC gen_subG morphpreS; last exact: subset_gen.
rewrite -{1}(morphpreK sRfD) -morphim_gen ?subsetIl // morphimGK //=.
by rewrite sub_gen // setIS // preimsetS ?sub1set.
by rewrite gen_subG subsetIl.
Qed.
(* commutator, normaliser, normal, center properties*)
Lemma morphimR A B :
A \subset D -> B \subset D -> f @* [~: A, B] = [~: f @* A, f @* B].
Proof.
move/subsetP=> sAD /subsetP sBD.
rewrite morphim_gen; last first; last congr <<_>>.
by apply/subsetP=> _ /imset2P[x y Ax By ->]; rewrite groupR; auto.
apply/setP=> fz; apply/morphimP/imset2P=> [[z _] | [fx fy]].
case/imset2P=> x y Ax By -> -> {z fz}.
have Dx := sAD x Ax; have Dy := sBD y By.
by exists (f x) (f y); rewrite ?(imset_f, morphR) // ?(inE, Dx, Dy).
case/morphimP=> x Dx Ax ->{fx}; case/morphimP=> y Dy By ->{fy} -> {fz}.
by exists [~ x, y]; rewrite ?(inE, morphR, groupR, imset2_f).
Qed.
Lemma morphim_norm A : f @* 'N(A) \subset 'N(f @* A).
Proof.
apply/subsetP=> fx; case/morphimP=> x Dx Nx -> {fx}.
by rewrite inE -morphimJ ?(normP Nx).
Qed.
Lemma morphim_norms A B : A \subset 'N(B) -> f @* A \subset 'N(f @* B).
Proof.
by move=> nBA; apply: subset_trans (morphim_norm B); apply: morphimS.
Qed.
Lemma morphim_subnorm A B : f @* 'N_A(B) \subset 'N_(f @* A)(f @* B).
Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_norm B)). Qed.
Lemma morphim_normal A B : A <| B -> f @* A <| f @* B.
Proof. by case/andP=> sAB nAB; rewrite /(_ <| _) morphimS // morphim_norms. Qed.
Lemma morphim_cent1 x : x \in D -> f @* 'C[x] \subset 'C[f x].
Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_norm. Qed.
Lemma morphim_cent1s A x : x \in D -> A \subset 'C[x] -> f @* A \subset 'C[f x].
Proof.
by move=> Dx cAx; apply: subset_trans (morphim_cent1 Dx); apply: morphimS.
Qed.
Lemma morphim_subcent1 A x : x \in D -> f @* 'C_A[x] \subset 'C_(f @* A)[f x].
Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_subnorm. Qed.
Lemma morphim_cent A : f @* 'C(A) \subset 'C(f @* A).
Proof.
apply/bigcapsP=> fx; case/morphimP=> x Dx Ax ->{fx}.
by apply: subset_trans (morphim_cent1 Dx); apply: morphimS; apply: bigcap_inf.
Qed.
Lemma morphim_cents A B : A \subset 'C(B) -> f @* A \subset 'C(f @* B).
Proof.
by move=> cBA; apply: subset_trans (morphim_cent B); apply: morphimS.
Qed.
Lemma morphim_subcent A B : f @* 'C_A(B) \subset 'C_(f @* A)(f @* B).
Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_cent B)). Qed.
Lemma morphim_abelian A : abelian A -> abelian (f @* A).
Proof. exact: morphim_cents. Qed.
Lemma morphpre_norm R : f @*^-1 'N(R) \subset 'N(f @*^-1 R).
Proof.
by apply/subsetP=> x /[!inE] /andP[Dx Nfx]; rewrite -morphpreJ ?morphpreS.
Qed.
Lemma morphpre_norms R S : R \subset 'N(S) -> f @*^-1 R \subset 'N(f @*^-1 S).
Proof.
by move=> nSR; apply: subset_trans (morphpre_norm S); apply: morphpreS.
Qed.
Lemma morphpre_normal R S :
R \subset f @* D -> S \subset f @* D -> (f @*^-1 R <| f @*^-1 S) = (R <| S).
Proof.
move=> sRfD sSfD; apply/idP/andP=> [|[sRS nSR]].
by move/morphim_normal; rewrite !morphpreK //; case/andP.
by rewrite /(_ <| _) (subset_trans _ (morphpre_norm _)) morphpreS.
Qed.
Lemma morphpre_subnorm R S : f @*^-1 'N_R(S) \subset 'N_(f @*^-1 R)(f @*^-1 S).
Proof. by rewrite morphpreI setIS ?morphpre_norm. Qed.
Lemma morphim_normG G :
'ker f \subset G -> G \subset D -> f @* 'N(G) = 'N_(f @* D)(f @* G).
Proof.
move=> sKG sGD; apply/eqP; rewrite eqEsubset -{1}morphimIdom morphim_subnorm.
rewrite -(morphpreK (subsetIl _ _)) morphimS //= morphpreI subIset // orbC.
by rewrite -{2}(morphimGK sKG sGD) morphpre_norm.
Qed.
Lemma morphim_subnormG A G :
'ker f \subset G -> G \subset D -> f @* 'N_A(G) = 'N_(f @* A)(f @* G).
Proof.
move=> sKB sBD; rewrite morphimIG ?normsG // morphim_normG //.
by rewrite setICA setIA morphimIim.
Qed.
Lemma morphpre_cent1 x : x \in D -> 'C_D[x] \subset f @*^-1 'C[f x].
Proof.
move=> Dx; rewrite -sub_morphim_pre ?subsetIl //.
by apply: subset_trans (morphim_cent1 Dx); rewrite morphimS ?subsetIr.
Qed.
Lemma morphpre_cent1s R x :
x \in D -> R \subset f @* D -> f @*^-1 R \subset 'C[x] -> R \subset 'C[f x].
Proof. by move=> Dx sRfD; move/(morphim_cent1s Dx); rewrite morphpreK. Qed.
Lemma morphpre_subcent1 R x :
x \in D -> 'C_(f @*^-1 R)[x] \subset f @*^-1 'C_R[f x].
Proof.
move=> Dx; rewrite -morphpreIdom -setIA setICA morphpreI setIS //.
exact: morphpre_cent1.
Qed.
Lemma morphpre_cent A : 'C_D(A) \subset f @*^-1 'C(f @* A).
Proof.
rewrite -sub_morphim_pre ?subsetIl // morphimGI ?(subsetIl, subIset) // orbC.
by rewrite (subset_trans (morphim_cent _)).
Qed.
Lemma morphpre_cents A R :
R \subset f @* D -> f @*^-1 R \subset 'C(A) -> R \subset 'C(f @* A).
Proof. by move=> sRfD; move/morphim_cents; rewrite morphpreK. Qed.
Lemma morphpre_subcent R A : 'C_(f @*^-1 R)(A) \subset f @*^-1 'C_R(f @* A).
Proof.
by rewrite -morphpreIdom -setIA setICA morphpreI setIS //; apply: morphpre_cent.
Qed.
(* local injectivity properties *)
Lemma injmP : reflect {in D &, injective f} ('injm f).
Proof.
apply: (iffP subsetP) => [injf x y Dx Dy | injf x /= Kx].
by case/ker_rcoset=> // z /injf/set1P->; rewrite mul1g.
have Dx := dom_ker Kx; apply/set1P/injf => //.
by apply/rcoset_kerP; rewrite // mulg1.
Qed.
Lemma card_im_injm : (#|f @* D| == #|D|) = 'injm f.
Proof. by rewrite morphimEdom (sameP imset_injP injmP). Qed.
Section Injective.
Hypothesis injf : 'injm f.
Lemma ker_injm : 'ker f = 1.
Proof. exact/trivgP. Qed.
Lemma injmK A : A \subset D -> f @*^-1 (f @* A) = A.
Proof. by move=> sAD; rewrite morphimK // ker_injm // mul1g. Qed.
Lemma injm_morphim_inj A B :
A \subset D -> B \subset D -> f @* A = f @* B -> A = B.
Proof. by move=> sAD sBD eqAB; rewrite -(injmK sAD) eqAB injmK. Qed.
Lemma card_injm A : A \subset D -> #|f @* A| = #|A|.
Proof.
move=> sAD; rewrite morphimEsub // card_in_imset //.
exact: (sub_in2 (subsetP sAD) (injmP injf)).
Qed.
Lemma order_injm x : x \in D -> #[f x] = #[x].
Proof.
by move=> Dx; rewrite orderE -morphim_cycle // card_injm ?cycle_subG.
Qed.
Lemma injm1 x : x \in D -> f x = 1 -> x = 1.
Proof. by move=> Dx; move/(kerP Dx); rewrite ker_injm; move/set1P. Qed.
Lemma morph_injm_eq1 x : x \in D -> (f x == 1) = (x == 1).
Proof. by move=> Dx; rewrite -morph1 (inj_in_eq (injmP injf)) ?group1. Qed.
Lemma injmSK A B :
A \subset D -> (f @* A \subset f @* B) = (A \subset B).
Proof. by move=> sAD; rewrite morphimSK // ker_injm mul1g. Qed.
Lemma sub_morphpre_injm R A :
A \subset D -> R \subset f @* D ->
(f @*^-1 R \subset A) = (R \subset f @* A).
Proof. by move=> sAD sRfD; rewrite -morphpreSK ?injmK. Qed.
Lemma injm_eq A B : A \subset D -> B \subset D -> (f @* A == f @* B) = (A == B).
Proof. by move=> sAD sBD; rewrite !eqEsubset !injmSK. Qed.
Lemma morphim_injm_eq1 A : A \subset D -> (f @* A == 1) = (A == 1).
Proof. by move=> sAD; rewrite -morphim1 injm_eq ?sub1G. Qed.
Lemma injmI A B : f @* (A :&: B) = f @* A :&: f @* B.
Proof.
rewrite -morphimIdom setIIr -4!(injmK (subsetIl D _), =^~ morphimIdom).
by rewrite -morphpreI morphpreK // subIset ?morphim_sub.
Qed.
Lemma injmD1 A : f @* A^# = (f @* A)^#.
Proof. by have:= morphimDG A injf; rewrite morphim1. Qed.
Lemma nclasses_injm A : A \subset D -> #|classes (f @* A)| = #|classes A|.
Proof.
move=> sAD; rewrite classes_morphim // card_in_imset //.
move=> _ _ /imsetP[x Ax ->] /imsetP[y Ay ->].
by apply: injm_morphim_inj; rewrite // class_subG ?(subsetP sAD).
Qed.
Lemma injm_norm A : A \subset D -> f @* 'N(A) = 'N_(f @* D)(f @* A).
Proof.
move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subnorm.
rewrite -sub_morphpre_injm ?subsetIl // morphpreI injmK // setIS //.
by rewrite -{2}(injmK sAD) morphpre_norm.
Qed.
Lemma injm_norms A B :
A \subset D -> B \subset D -> (f @* A \subset 'N(f @* B)) = (A \subset 'N(B)).
Proof. by move=> sAD sBD; rewrite -injmSK // injm_norm // subsetI morphimS. Qed.
Lemma injm_normal A B :
A \subset D -> B \subset D -> (f @* A <| f @* B) = (A <| B).
Proof. by move=> sAD sBD; rewrite /normal injmSK ?injm_norms. Qed.
Lemma injm_subnorm A B : B \subset D -> f @* 'N_A(B) = 'N_(f @* A)(f @* B).
Proof. by move=> sBD; rewrite injmI injm_norm // setICA setIA morphimIim. Qed.
Lemma injm_cent1 x : x \in D -> f @* 'C[x] = 'C_(f @* D)[f x].
Proof. by move=> Dx; rewrite injm_norm ?morphim_set1 ?sub1set. Qed.
Lemma injm_subcent1 A x : x \in D -> f @* 'C_A[x] = 'C_(f @* A)[f x].
Proof. by move=> Dx; rewrite injm_subnorm ?morphim_set1 ?sub1set. Qed.
Lemma injm_cent A : A \subset D -> f @* 'C(A) = 'C_(f @* D)(f @* A).
Proof.
move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subcent.
apply/subsetP=> fx; case/setIP; case/morphimP=> x Dx _ ->{fx} cAfx.
rewrite mem_morphim // inE Dx -sub1set centsC cent_set1 -injmSK //.
by rewrite injm_cent1 // subsetI morphimS // -cent_set1 centsC sub1set.
Qed.
Lemma injm_cents A B :
A \subset D -> B \subset D -> (f @* A \subset 'C(f @* B)) = (A \subset 'C(B)).
Proof. by move=> sAD sBD; rewrite -injmSK // injm_cent // subsetI morphimS. Qed.
Lemma injm_subcent A B : B \subset D -> f @* 'C_A(B) = 'C_(f @* A)(f @* B).
Proof. by move=> sBD; rewrite injmI injm_cent // setICA setIA morphimIim. Qed.
Lemma injm_abelian A : A \subset D -> abelian (f @* A) = abelian A.
Proof.
by move=> sAD; rewrite /abelian -subsetIidl -injm_subcent // injmSK ?subsetIidl.
Qed.
End Injective.
Lemma eq_morphim (g : {morphism D >-> rT}):
{in D, f =1 g} -> forall A, f @* A = g @* A.
Proof.
by move=> efg A; apply: eq_in_imset; apply: sub_in1 efg => x /setIP[].
Qed.
Lemma eq_in_morphim B A (g : {morphism B >-> rT}) :
D :&: A = B :&: A -> {in A, f =1 g} -> f @* A = g @* A.
Proof.
move=> eqDBA eqAfg; rewrite /morphim /= eqDBA.
by apply: eq_in_imset => x /setIP[_]/eqAfg.
Qed.
End MorphismTheory.
Notation "''ker' f" := (ker_group (MorPhantom f)) : Group_scope.
Notation "''ker_' G f" := (G :&: 'ker f)%G : Group_scope.
Notation "f @* G" := (morphim_group (MorPhantom f) G) : Group_scope.
Notation "f @*^-1 M" := (morphpre_group (MorPhantom f) M) : Group_scope.
Notation "f @: D" := (morph_dom_group f D) : Group_scope.
Arguments injmP {aT rT D f}.
Arguments morphpreK {aT rT D f} [R] sRf.
Section IdentityMorphism.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Type G : {group gT}.
Definition idm of {set gT} := fun x : gT => x : FinGroup.sort gT.
Lemma idm_morphM A : {in A & , {morph idm A : x y / x * y}}.
Proof. by []. Qed.
Canonical idm_morphism A := Morphism (@idm_morphM A).
Lemma injm_idm G : 'injm (idm G).
Proof. by apply/injmP=> x y _ _. Qed.
Lemma ker_idm G : 'ker (idm G) = 1.
Proof. by apply/trivgP; apply: injm_idm. Qed.
Lemma morphim_idm A B : B \subset A -> idm A @* B = B.
Proof.
rewrite /morphim /= /idm => /setIidPr->.
by apply/setP=> x; apply/imsetP/idP=> [[y By ->]|Bx]; last exists x.
Qed.
Lemma morphpre_idm A B : idm A @*^-1 B = A :&: B.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma im_idm A : idm A @* A = A.
Proof. exact: morphim_idm. Qed.
End IdentityMorphism.
Arguments idm {_} _%_g _%_g.
Section RestrictedMorphism.
Variables aT rT : finGroupType.
Variables A D : {set aT}.
Implicit Type B : {set aT}.
Implicit Type R : {set rT}.
Definition restrm of A \subset D := @id (aT -> FinGroup.sort rT).
Section Props.
Hypothesis sAD : A \subset D.
Variable f : {morphism D >-> rT}.
Local Notation fA := (restrm sAD (mfun f)).
Canonical restrm_morphism :=
@Morphism aT rT A fA (sub_in2 (subsetP sAD) (morphM f)).
Lemma morphim_restrm B : fA @* B = f @* (A :&: B).
Proof. by rewrite {2}/morphim setIA (setIidPr sAD). Qed.
Lemma restrmEsub B : B \subset A -> fA @* B = f @* B.
Proof. by rewrite morphim_restrm => /setIidPr->. Qed.
Lemma im_restrm : fA @* A = f @* A.
Proof. exact: restrmEsub. Qed.
Lemma morphpre_restrm R : fA @*^-1 R = A :&: f @*^-1 R.
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma ker_restrm : 'ker fA = 'ker_A f.
Proof. exact: morphpre_restrm. Qed.
Lemma injm_restrm : 'injm f -> 'injm fA.
Proof. by apply: subset_trans; rewrite ker_restrm subsetIr. Qed.
End Props.
Lemma restrmP (f : {morphism D >-> rT}) : A \subset 'dom f ->
{g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker_A f,
forall R, g @*^-1 R = A :&: f @*^-1 R
& forall B, B \subset A -> g @* B = f @* B]}.
Proof.
move=> sAD; exists (restrm_morphism sAD f).
split=> // [|R|B sBA]; first 1 [exact: ker_restrm | exact: morphpre_restrm].
by rewrite morphim_restrm (setIidPr sBA).
Qed.
Lemma domP (f : {morphism D >-> rT}) : 'dom f = A ->
{g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker f,
forall R, g @*^-1 R = f @*^-1 R
& forall B, g @* B = f @* B]}.
Proof. by move <-; exists f. Qed.
End RestrictedMorphism.
Arguments restrm {_ _ _%_g _%_g} _ _%_g.
Arguments restrmP {aT rT A D}.
Arguments domP {aT rT A D}.
Section TrivMorphism.
Variables aT rT : finGroupType.
Definition trivm of {set aT} & aT := 1 : FinGroup.sort rT.
Lemma trivm_morphM (A : {set aT}) : {in A &, {morph trivm A : x y / x * y}}.
Proof. by move=> x y /=; rewrite mulg1. Qed.
Canonical triv_morph A := Morphism (@trivm_morphM A).
Lemma morphim_trivm (G H : {group aT}) : trivm G @* H = 1.
Proof.
apply/setP=> /= y; rewrite inE; apply/idP/eqP=> [|->]; first by case/morphimP.
by apply/morphimP; exists (1 : aT); rewrite /= ?group1.
Qed.
Lemma ker_trivm (G : {group aT}) : 'ker (trivm G) = G.
Proof. by apply/setIidPl/subsetP=> x _; rewrite !inE /=. Qed.
End TrivMorphism.
Arguments trivm {aT rT} _%_g _%_g.
(* The composition of two morphisms is a Canonical morphism instance. *)
Section MorphismComposition.
Variables gT hT rT : finGroupType.
Variables (G : {group gT}) (H : {group hT}).
Variable f : {morphism G >-> hT}.
Variable g : {morphism H >-> rT}.
Local Notation gof := (mfun g \o mfun f).
Lemma comp_morphM : {in f @*^-1 H &, {morph gof: x y / x * y}}.
Proof.
by move=> x y; rewrite /= !inE => /andP[? ?] /andP[? ?]; rewrite !morphM.
Qed.
Canonical comp_morphism := Morphism comp_morphM.
Lemma ker_comp : 'ker gof = f @*^-1 'ker g.
Proof. by apply/setP=> x; rewrite !inE andbA. Qed.
Lemma injm_comp : 'injm f -> 'injm g -> 'injm gof.
Proof. by move=> injf; rewrite ker_comp; move/trivgP=> ->. Qed.
Lemma morphim_comp (A : {set gT}) : gof @* A = g @* (f @* A).
Proof.
apply/setP=> z; apply/morphimP/morphimP=> [[x]|[y Hy fAy ->{z}]].
rewrite !inE => /andP[Gx Hfx]; exists (f x) => //.
by apply/morphimP; exists x.
by case/morphimP: fAy Hy => x Gx Ax ->{y} Hfx; exists x; rewrite ?inE ?Gx.
Qed.
Lemma morphpre_comp (C : {set rT}) : gof @*^-1 C = f @*^-1 (g @*^-1 C).
Proof. by apply/setP=> z; rewrite !inE andbA. Qed.
End MorphismComposition.
(* The factor morphism *)
Section FactorMorphism.
Variables aT qT rT : finGroupType.
Variables G H : {group aT}.
Variable f : {morphism G >-> rT}.
Variable q : {morphism H >-> qT}.
Definition factm of 'ker q \subset 'ker f & G \subset H :=
fun x => f (repr (q @*^-1 [set x])).
Hypothesis sKqKf : 'ker q \subset 'ker f.
Hypothesis sGH : G \subset H.
Notation ff := (factm sKqKf sGH).
Lemma factmE x : x \in G -> ff (q x) = f x.
Proof.
rewrite /ff => Gx; have Hx := subsetP sGH x Gx.
have /mem_repr: x \in q @*^-1 [set q x] by rewrite !inE Hx /=.
case/morphpreP; move: (repr _) => y Hy /set1P.
by case/ker_rcoset=> // z Kz ->; rewrite mkerl ?(subsetP sKqKf).
Qed.
Lemma factm_morphM : {in q @* G &, {morph ff : x y / x * y}}.
Proof.
move=> _ _ /morphimP[x Hx Gx ->] /morphimP[y Hy Gy ->].
by rewrite -morphM ?factmE ?groupM // morphM.
Qed.
Canonical factm_morphism := Morphism factm_morphM.
Lemma morphim_factm (A : {set aT}) : ff @* (q @* A) = f @* A.
Proof.
rewrite -morphim_comp /= {1}/morphim /= morphimGK //; last first.
by rewrite (subset_trans sKqKf) ?subsetIl.
apply/setP=> y; apply/morphimP/morphimP;
by case=> x Gx Ax ->{y}; exists x; rewrite //= factmE.
Qed.
Lemma morphpre_factm (C : {set rT}) : ff @*^-1 C = q @* (f @*^-1 C).
Proof.
apply/setP=> y /[!inE]/=; apply/andP/morphimP=> [[]|[x Hx]]; last first.
by case/morphpreP=> Gx Cfx ->; rewrite factmE ?imset_f ?inE ?Hx.
case/morphimP=> x Hx Gx ->; rewrite factmE //.
by exists x; rewrite // !inE Gx.
Qed.
Lemma ker_factm : 'ker ff = q @* 'ker f.
Proof. exact: morphpre_factm. Qed.
Lemma injm_factm : 'injm f -> 'injm ff.
Proof. by rewrite ker_factm => /trivgP->; rewrite morphim1. Qed.
Lemma injm_factmP : reflect ('ker f = 'ker q) ('injm ff).
Proof.
rewrite ker_factm -morphimIdom sub_morphim_pre ?subsetIl //.
rewrite setIA (setIidPr sGH) (sameP setIidPr eqP) (setIidPl _) // eq_sym.
exact: eqP.
Qed.
Lemma ker_factm_loc (K : {group aT}) : 'ker_(q @* K) ff = q @* 'ker_K f.
Proof. by rewrite ker_factm -morphimIG. Qed.
End FactorMorphism.
Prenex Implicits factm.
Section InverseMorphism.
Variables aT rT : finGroupType.
Implicit Types A B : {set aT}.
Implicit Types C D : {set rT}.
Variables (G : {group aT}) (f : {morphism G >-> rT}).
Hypothesis injf : 'injm f.
Lemma invm_subker : 'ker f \subset 'ker (idm G).
Proof. by rewrite ker_idm. Qed.
Definition invm := factm invm_subker (subxx _).
Canonical invm_morphism := Eval hnf in [morphism of invm].
Lemma invmE : {in G, cancel f invm}.
Proof. exact: factmE. Qed.
Lemma invmK : {in f @* G, cancel invm f}.
Proof. by move=> fx; case/morphimP=> x _ Gx ->; rewrite invmE. Qed.
Lemma morphpre_invm A : invm @*^-1 A = f @* A.
Proof. by rewrite morphpre_factm morphpre_idm morphimIdom. Qed.
Lemma morphim_invm A : A \subset G -> invm @* (f @* A) = A.
Proof. by move=> sAG; rewrite morphim_factm morphim_idm. Qed.
Lemma morphim_invmE C : invm @* C = f @*^-1 C.
Proof.
rewrite -morphpreIdom -(morphim_invm (subsetIl _ _)).
by rewrite morphimIdom -morphpreIim morphpreK (subsetIl, morphimIdom).
Qed.
Lemma injm_proper A B :
A \subset G -> B \subset G -> (f @* A \proper f @* B) = (A \proper B).
Proof.
move=> dA dB; rewrite -morphpre_invm -(morphpre_invm B).
by rewrite morphpre_proper ?morphim_invm.
Qed.
Lemma injm_invm : 'injm invm.
Proof. by move/can_in_inj/injmP: invmK. Qed.
Lemma ker_invm : 'ker invm = 1.
Proof. by move/trivgP: injm_invm. Qed.
Lemma im_invm : invm @* (f @* G) = G.
Proof. exact: morphim_invm. Qed.
End InverseMorphism.
Prenex Implicits invm.
Section InjFactm.
Variables (gT aT rT : finGroupType) (D G : {group gT}).
Variables (g : {morphism G >-> rT}) (f : {morphism D >-> aT}) (injf : 'injm f).
Definition ifactm :=
tag (domP [morphism of g \o invm injf] (morphpre_invm injf G)).
Lemma ifactmE : {in D, forall x, ifactm (f x) = g x}.
Proof.
rewrite /ifactm => x Dx; case: domP => f' /= [def_f' _ _ _].
by rewrite {f'}def_f' //= invmE.
Qed.
Lemma morphim_ifactm (A : {set gT}) :
A \subset D -> ifactm @* (f @* A) = g @* A.
Proof.
rewrite /ifactm => sAD; case: domP => _ /= [_ _ _ ->].
by rewrite morphim_comp morphim_invm.
Qed.
Lemma im_ifactm : G \subset D -> ifactm @* (f @* G) = g @* G.
Proof. exact: morphim_ifactm. Qed.
Lemma morphpre_ifactm C : ifactm @*^-1 C = f @* (g @*^-1 C).
Proof.
rewrite /ifactm; case: domP => _ /= [_ _ -> _].
by rewrite morphpre_comp morphpre_invm.
Qed.
Lemma ker_ifactm : 'ker ifactm = f @* 'ker g.
Proof. exact: morphpre_ifactm. Qed.
Lemma injm_ifactm : 'injm g -> 'injm ifactm.
Proof. by rewrite ker_ifactm => /trivgP->; rewrite morphim1. Qed.
End InjFactm.
(* Reflected (boolean) form of morphism and isomorphism properties. *)
Section ReflectProp.
Variables aT rT : finGroupType.
Section Defs.
Variables (A : {set aT}) (B : {set rT}).
(* morphic is the morphM property of morphisms seen through morphicP. *)
Definition morphic (f : aT -> rT) :=
[forall u in [predX A & A], f (u.1 * u.2) == f u.1 * f u.2].
Definition isom f := f @: A^# == B^#.
Definition misom f := morphic f && isom f.
Definition isog := [exists f : {ffun aT -> rT}, misom f].
Section MorphicProps.
Variable f : aT -> rT.
Lemma morphicP : reflect {in A &, {morph f : x y / x * y}} (morphic f).
Proof.
apply: (iffP forallP) => [fM x y Ax Ay | fM [x y] /=].
by apply/eqP; have:= fM (x, y); rewrite inE /= Ax Ay.
by apply/implyP=> /andP[Ax Ay]; rewrite fM.
Qed.
Definition morphm of morphic f := f : aT -> FinGroup.sort rT.
Lemma morphmE fM : morphm fM = f. Proof. by []. Qed.
Canonical morphm_morphism fM := @Morphism _ _ A (morphm fM) (morphicP fM).
End MorphicProps.
Lemma misomP f : reflect {fM : morphic f & isom (morphm fM)} (misom f).
Proof. by apply: (iffP andP) => [] [fM fiso] //; exists fM. Qed.
Lemma misom_isog f : misom f -> isog.
Proof.
case/andP=> fM iso_f; apply/existsP; exists (finfun f).
apply/andP; split; last by rewrite /misom /isom !(eq_imset _ (ffunE f)).
by apply/forallP=> u; rewrite !ffunE; apply: forallP fM u.
Qed.
Lemma isom_isog (D : {group aT}) (f : {morphism D >-> rT}) :
A \subset D -> isom f -> isog.
Proof.
move=> sAD isof; apply: (@misom_isog f); rewrite /misom isof andbT.
by apply/morphicP; apply: (sub_in2 (subsetP sAD) (morphM f)).
Qed.
Lemma isog_isom : isog -> {f : {morphism A >-> rT} | isom f}.
Proof.
by case/existsP/sigW=> f /misomP[fM isom_f]; exists (morphm_morphism fM).
Qed.
End Defs.
Infix "\isog" := isog.
Arguments isom_isog [A B D].
(* The real reflection properties only hold for true groups and morphisms. *)
Section Main.
Variables (G : {group aT}) (H : {group rT}).
Lemma isomP (f : {morphism G >-> rT}) :
reflect ('injm f /\ f @* G = H) (isom G H f).
Proof.
apply: (iffP eqP) => [eqfGH | [injf <-]]; last first.
by rewrite -injmD1 // morphimEsub ?subsetDl.
split.
apply/subsetP=> x /morphpreP[Gx fx1]; have: f x \notin H^# by rewrite inE fx1.
by apply: contraR => ntx; rewrite -eqfGH imset_f // inE ntx.
rewrite morphimEdom -{2}(setD1K (group1 G)) imsetU eqfGH.
by rewrite imset_set1 morph1 setD1K.
Qed.
Lemma isogP :
reflect (exists2 f : {morphism G >-> rT}, 'injm f & f @* G = H) (G \isog H).
Proof.
apply: (iffP idP) => [/isog_isom[f /isomP[]] | [f injf fG]]; first by exists f.
by apply: (isom_isog f) => //; apply/isomP.
Qed.
Variable f : {morphism G >-> rT}.
Hypothesis isoGH : isom G H f.
Lemma isom_inj : 'injm f. Proof. by have /isomP[] := isoGH. Qed.
Lemma isom_im : f @* G = H. Proof. by have /isomP[] := isoGH. Qed.
Lemma isom_card : #|G| = #|H|.
Proof. by rewrite -isom_im card_injm ?isom_inj. Qed.
Lemma isom_sub_im : H \subset f @* G. Proof. by rewrite isom_im. Qed.
Definition isom_inv := restrm isom_sub_im (invm isom_inj).
End Main.
Variables (G : {group aT}) (f : {morphism G >-> rT}).
Lemma morphim_isom (H : {group aT}) (K : {group rT}) :
H \subset G -> isom H K f -> f @* H = K.
Proof. by case/(restrmP f)=> g [gf _ _ <- //]; rewrite -gf; case/isomP. Qed.
Lemma sub_isom (A : {set aT}) (C : {set rT}) :
A \subset G -> f @* A = C -> 'injm f -> isom A C f.
Proof.
move=> sAG; case: (restrmP f sAG) => g [_ _ _ img] <-{C} injf.
rewrite /isom -morphimEsub ?morphimDG ?morphim1 //.
by rewrite subDset setUC subsetU ?sAG.
Qed.
Lemma sub_isog (A : {set aT}) : A \subset G -> 'injm f -> isog A (f @* A).
Proof. by move=> sAG injf; apply: (isom_isog f sAG); apply: sub_isom. Qed.
Lemma restr_isom_to (A : {set aT}) (C R : {group rT}) (sAG : A \subset G) :
f @* A = C -> isom G R f -> isom A C (restrm sAG f).
Proof. by move=> defC /isomP[inj_f _]; apply: sub_isom. Qed.
Lemma restr_isom (A : {group aT}) (R : {group rT}) (sAG : A \subset G) :
isom G R f -> isom A (f @* A) (restrm sAG f).
Proof. exact: restr_isom_to. Qed.
End ReflectProp.
Arguments isom {_ _} _%_g _%_g _.
Arguments morphic {_ _} _%_g _.
Arguments misom _ _ _%_g _%_g _.
Arguments isog {_ _} _%_g _%_g.
Arguments morphicP {aT rT A f}.
Arguments misomP {aT rT A B f}.
Arguments isom_isog [aT rT A B D].
Arguments isomP {aT rT G H f}.
Arguments isogP {aT rT G H}.
Prenex Implicits morphm.
Notation "x \isog y":= (isog x y).
Section Isomorphisms.
Variables gT hT kT : finGroupType.
Variables (G : {group gT}) (H : {group hT}) (K : {group kT}).
Lemma idm_isom : isom G G (idm G).
Proof. exact: sub_isom (im_idm G) (injm_idm G). Qed.
Lemma isog_refl : G \isog G. Proof. exact: isom_isog idm_isom. Qed.
Lemma card_isog : G \isog H -> #|G| = #|H|.
Proof. by case/isogP=> f injf <-; apply: isom_card (f) _; apply/isomP. Qed.
Lemma isog_abelian : G \isog H -> abelian G = abelian H.
Proof. by case/isogP=> f injf <-; rewrite injm_abelian. Qed.
Lemma trivial_isog : G :=: 1 -> H :=: 1 -> G \isog H.
Proof.
move=> -> ->; apply/isogP.
exists [morphism of @trivm gT hT 1]; rewrite /= ?morphim1 //.
by rewrite ker_trivm; apply: subxx.
Qed.
Lemma isog_eq1 : G \isog H -> (G :==: 1) = (H :==: 1).
Proof. by move=> isoGH; rewrite !trivg_card1 card_isog. Qed.
Lemma isom_sym (f : {morphism G >-> hT}) (isoGH : isom G H f) :
isom H G (isom_inv isoGH).
Proof.
rewrite sub_isom 1?injm_restrm ?injm_invm // im_restrm.
by rewrite -(isom_im isoGH) im_invm.
Qed.
Lemma isog_symr : G \isog H -> H \isog G.
Proof. by case/isog_isom=> f /isom_sym/isom_isog->. Qed.
Lemma isog_trans : G \isog H -> H \isog K -> G \isog K.
Proof.
case/isogP=> f injf <-; case/isogP=> g injg <-.
have defG: f @*^-1 (f @* G) = G by rewrite morphimGK ?subsetIl.
rewrite -morphim_comp -{1 8}defG.
by apply/isogP; exists [morphism of g \o f]; rewrite ?injm_comp.
Qed.
Lemma nclasses_isog : G \isog H -> #|classes G| = #|classes H|.
Proof. by case/isogP=> f injf <-; rewrite nclasses_injm. Qed.
End Isomorphisms.
Section IsoBoolEquiv.
Variables gT hT kT : finGroupType.
Variables (G : {group gT}) (H : {group hT}) (K : {group kT}).
Lemma isog_sym : (G \isog H) = (H \isog G).
Proof. by apply/idP/idP; apply: isog_symr. Qed.
Lemma isog_transl : G \isog H -> (G \isog K) = (H \isog K).
Proof.
by move=> iso; apply/idP/idP; apply: isog_trans; rewrite // -isog_sym.
Qed.
Lemma isog_transr : G \isog H -> (K \isog G) = (K \isog H).
Proof.
by move=> iso; apply/idP/idP; move/isog_trans; apply; rewrite // -isog_sym.
Qed.
End IsoBoolEquiv.
Section Homg.
Implicit Types rT gT aT : finGroupType.
Definition homg rT aT (C : {set rT}) (D : {set aT}) :=
[exists (f : {ffun aT -> rT} | morphic D f), f @: D == C].
Lemma homgP rT aT (C : {set rT}) (D : {set aT}) :
reflect (exists f : {morphism D >-> rT}, f @* D = C) (homg C D).
Proof.
apply: (iffP exists_eq_inP) => [[f fM <-] | [f <-]].
by exists (morphm_morphism fM); rewrite /morphim /= setIid.
exists (finfun f); first by apply/morphicP=> x y Dx Dy; rewrite !ffunE morphM.
by rewrite /morphim setIid; apply: eq_imset => x; rewrite ffunE.
Qed.
Lemma morphim_homg aT rT (A D : {set aT}) (f : {morphism D >-> rT}) :
A \subset D -> homg (f @* A) A.
Proof.
move=> sAD; apply/homgP; exists (restrm_morphism sAD f).
by rewrite morphim_restrm setIid.
Qed.
Lemma leq_homg rT aT (C : {set rT}) (G : {group aT}) :
homg C G -> #|C| <= #|G|.
Proof. by case/homgP=> f <-; apply: leq_morphim. Qed.
Lemma homg_refl aT (A : {set aT}) : homg A A.
Proof. by apply/homgP; exists (idm_morphism A); rewrite im_idm. Qed.
Lemma homg_trans aT (B : {set aT}) rT (C : {set rT}) gT (G : {group gT}) :
homg C B -> homg B G -> homg C G.
Proof.
move=> homCB homBG; case/homgP: homBG homCB => fG <- /homgP[fK <-].
by rewrite -morphim_comp morphim_homg // -sub_morphim_pre.
Qed.
Lemma isogEcard rT aT (G : {group rT}) (H : {group aT}) :
(G \isog H) = (homg G H) && (#|H| <= #|G|).
Proof.
rewrite isog_sym; apply/isogP/andP=> [[f injf <-] | []].
by rewrite leq_eqVlt eq_sym card_im_injm injf morphim_homg.
case/homgP=> f <-; rewrite leq_eqVlt eq_sym card_im_injm.
by rewrite ltnNge leq_morphim orbF; exists f.
Qed.
Lemma isog_hom rT aT (G : {group rT}) (H : {group aT}) : G \isog H -> homg G H.
Proof. by rewrite isogEcard; case/andP. Qed.
Lemma isogEhom rT aT (G : {group rT}) (H : {group aT}) :
(G \isog H) = homg G H && homg H G.
Proof.
apply/idP/andP=> [isoGH | [homGH homHG]].
by rewrite !isog_hom // isog_sym.
by rewrite isogEcard homGH leq_homg.
Qed.
Lemma eq_homgl gT aT rT (G : {group gT}) (H : {group aT}) (K : {group rT}) :
G \isog H -> homg G K = homg H K.
Proof.
by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homg_trans.
Qed.
Lemma eq_homgr gT rT aT (G : {group gT}) (H : {group rT}) (K : {group aT}) :
G \isog H -> homg K G = homg K H.
Proof.
rewrite isogEhom => /andP[homGH homHG].
by apply/idP/idP=> homK; apply: homg_trans homK _.
Qed.
End Homg.
Arguments homg _ _ _%_g _%_g.
Notation "G \homg H" := (homg G H)
(at level 70, no associativity) : group_scope.
Arguments homgP {rT aT C D}.
(* Isomorphism between a group and its subtype. *)
Section SubMorphism.
Variables (gT : finGroupType) (G : {group gT}).
Canonical sgval_morphism := Morphism (@sgvalM _ G).
Canonical subg_morphism := Morphism (@subgM _ G).
Lemma injm_sgval : 'injm sgval.
Proof. exact/injmP/(in2W subg_inj). Qed.
Lemma injm_subg : 'injm (subg G).
Proof. exact/injmP/(can_in_inj subgK). Qed.
Hint Resolve injm_sgval injm_subg : core.
Lemma ker_sgval : 'ker sgval = 1. Proof. exact/trivgP. Qed.
Lemma ker_subg : 'ker (subg G) = 1. Proof. exact/trivgP. Qed.
Lemma im_subg : subg G @* G = [subg G].
Proof.
apply/eqP; rewrite -subTset morphimEdom.
by apply/subsetP=> u _; rewrite -(sgvalK u) imset_f ?subgP.
Qed.
Lemma sgval_sub A : sgval @* A \subset G.
Proof. by apply/subsetP=> x; case/imsetP=> u _ ->; apply: subgP. Qed.
Lemma sgvalmK A : subg G @* (sgval @* A) = A.
Proof.
apply/eqP; rewrite eqEcard !card_injm ?subsetT ?sgval_sub // leqnn andbT.
rewrite -morphim_comp; apply/subsetP=> _ /morphimP[v _ Av ->] /=.
by rewrite sgvalK.
Qed.
Lemma subgmK (A : {set gT}) : A \subset G -> sgval @* (subg G @* A) = A.
Proof.
move=> sAG; apply/eqP; rewrite eqEcard !card_injm ?subsetT //.
rewrite leqnn andbT -morphim_comp morphimE /= morphpreT.
by apply/subsetP=> _ /morphimP[v Gv Av ->] /=; rewrite subgK.
Qed.
Lemma im_sgval : sgval @* [subg G] = G.
Proof. by rewrite -{2}im_subg subgmK. Qed.
Lemma isom_subg : isom G [subg G] (subg G).
Proof. by apply/isomP; rewrite im_subg. Qed.
Lemma isom_sgval : isom [subg G] G sgval.
Proof. by apply/isomP; rewrite im_sgval. Qed.
Lemma isog_subg : isog G [subg G].
Proof. exact: isom_isog isom_subg. Qed.
End SubMorphism.
Arguments sgvalmK {gT G} A.
Arguments subgmK {gT G} [A] sAG.
|
Free.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.Star.Basic
import Mathlib.Algebra.FreeAlgebra
/-!
# A *-algebra structure on the free algebra.
Reversing words gives a *-structure on the free monoid or on the free algebra on a type.
## Implementation note
We have this in a separate file, rather than in `Algebra.FreeMonoid` and `Algebra.FreeAlgebra`,
to avoid importing `Algebra.Star.Basic` into the entire hierarchy.
-/
namespace FreeMonoid
variable {α : Type*}
instance : StarMul (FreeMonoid α) where
star := List.reverse
star_involutive := List.reverse_reverse
star_mul := fun _ _ => List.reverse_append
@[simp]
theorem star_of (x : α) : star (of x) = of x :=
rfl
/-- Note that `star_one` is already a global simp lemma, but this one works with dsimp too -/
@[simp]
theorem star_one : star (1 : FreeMonoid α) = 1 :=
rfl
end FreeMonoid
namespace FreeAlgebra
variable {R : Type*} [CommSemiring R] {X : Type*}
/-- The star ring formed by reversing the elements of products -/
instance : StarRing (FreeAlgebra R X) where
star := MulOpposite.unop ∘ lift R (MulOpposite.op ∘ ι R)
star_involutive x := by
simp only [Function.comp_apply]
let y := lift R (X := X) (MulOpposite.op ∘ ι R)
refine induction (motive := fun x ↦ (y (y x).unop).unop = x) _ _ ?_ ?_ ?_ ?_ x
· intros
simp only [AlgHom.commutes, MulOpposite.algebraMap_apply, MulOpposite.unop_op]
· intros
simp only [y, lift_ι_apply, Function.comp_apply, MulOpposite.unop_op]
· intros
simp only [*, map_mul, MulOpposite.unop_mul]
· intros
simp only [*, map_add, MulOpposite.unop_add]
star_mul a b := by simp only [Function.comp_apply, map_mul, MulOpposite.unop_mul]
star_add a b := by simp only [Function.comp_apply, map_add, MulOpposite.unop_add]
@[simp]
theorem star_ι (x : X) : star (ι R x) = ι R x := by simp [star, Star.star]
@[simp]
theorem star_algebraMap (r : R) : star (algebraMap R (FreeAlgebra R X) r) = algebraMap R _ r := by
simp [star, Star.star]
/-- `star` as an `AlgEquiv` -/
def starHom : FreeAlgebra R X ≃ₐ[R] (FreeAlgebra R X)ᵐᵒᵖ :=
{ starRingEquiv with commutes' := fun r => by simp [star_algebraMap] }
end FreeAlgebra
|
Subgroup.lean
|
/-
Copyright (c) 2024 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Algebra.GroupWithZero.Subgroup
import Mathlib.Algebra.Ring.Submonoid.Pointwise
import Mathlib.Algebra.Module.Defs
/-!
# Additive subgroups of rings
-/
open scoped Pointwise
variable {R M : Type*}
namespace AddSubgroup
section NonUnitalNonAssocRing
variable [NonUnitalNonAssocRing R]
/-- For additive subgroups `S` and `T` of a ring, the product of `S` and `T` as submonoids
is automatically a subgroup, which we define as the product of `S` and `T` as subgroups. -/
protected def mul : Mul (AddSubgroup R) where
mul M N :=
{ __ := M.toAddSubmonoid * N.toAddSubmonoid
neg_mem' := fun h ↦ AddSubmonoid.mul_induction_on h
(fun m hm n hn ↦ by rw [← neg_mul]; exact AddSubmonoid.mul_mem_mul (M.neg_mem hm) hn)
fun r₁ r₂ h₁ h₂ ↦ by rw [neg_add]; exact (M.1 * N.1).add_mem h₁ h₂ }
scoped[Pointwise] attribute [instance] AddSubgroup.mul
lemma mul_toAddSubmonoid (M N : AddSubgroup R) :
(M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl
end NonUnitalNonAssocRing
section Semiring
variable [Semiring R] [AddCommGroup M] [Module R M]
@[simp] protected lemma zero_smul (s : AddSubgroup M) : (0 : R) • s = ⊥ := by
simp [eq_bot_iff_forall, pointwise_smul_def]
end Semiring
end AddSubgroup
|
IntegralRNDeriv.lean
|
/-
Copyright (c) 2025 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Lorenzo Luccioli
-/
import Mathlib.Analysis.Convex.Continuous
import Mathlib.Analysis.Convex.Integral
import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym
/-!
# Integrals of functions of Radon-Nikodym derivatives
## Main statements
* `mul_le_integral_rnDeriv_of_ac`: for a convex continuous function `f` on `[0, ∞)`, if `μ`
is absolutely continuous with respect to `ν`, then
`ν.real univ * f (μ.real univ / ν.real univ) ≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν`.
-/
open Set
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ ν : Measure α} {f : ℝ → ℝ}
@[fun_prop]
lemma Measure.integrable_toReal_rnDeriv [IsFiniteMeasure μ] :
Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν :=
integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable
(Measure.lintegral_rnDeriv_lt_top _ _).ne
/-- For a convex continuous function `f` on `[0, ∞)`, if `μ` is absolutely continuous
with respect to a probability measure `ν`, then
`f μ.real univ ≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν`. -/
lemma le_integral_rnDeriv_of_ac [IsFiniteMeasure μ] [IsProbabilityMeasure ν]
(hf_cvx : ConvexOn ℝ (Ici 0) f) (hf_cont : ContinuousWithinAt f (Ici 0) 0)
(hf_int : Integrable (fun x ↦ f (μ.rnDeriv ν x).toReal) ν) (hμν : μ ≪ ν) :
f (μ.real univ) ≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν := by
have hf_cont' : ContinuousOn f (Ici 0) := by
intro x hx
rcases eq_or_lt_of_le (α := ℝ) (hx : 0 ≤ x) with rfl | hx_pos
· exact hf_cont
· have h := hf_cvx.continuousOn_interior x
simp only [nonempty_Iio, interior_Ici', mem_Ioi] at h
rw [continuousWithinAt_iff_continuousAt (Ioi_mem_nhds hx_pos)] at h
exact (h hx_pos).continuousWithinAt
calc f (μ.real univ)
= f (∫ x, (μ.rnDeriv ν x).toReal ∂ν) := by rw [Measure.integral_toReal_rnDeriv hμν]
_ ≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν := by
rw [← average_eq_integral, ← average_eq_integral]
exact ConvexOn.map_average_le hf_cvx hf_cont' isClosed_Ici (by simp)
Measure.integrable_toReal_rnDeriv hf_int
/-- For a convex continuous function `f` on `[0, ∞)`, if `μ` is absolutely continuous
with respect to `ν`, then
`ν.real univ * f (μ.real univ / ν.real univ) ≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν`. -/
lemma mul_le_integral_rnDeriv_of_ac [IsFiniteMeasure μ] [IsFiniteMeasure ν]
(hf_cvx : ConvexOn ℝ (Ici 0) f) (hf_cont : ContinuousWithinAt f (Ici 0) 0)
(hf_int : Integrable (fun x ↦ f (μ.rnDeriv ν x).toReal) ν) (hμν : μ ≪ ν) :
ν.real univ * f (μ.real univ / ν.real univ)
≤ ∫ x, f (μ.rnDeriv ν x).toReal ∂ν := by
by_cases hν : ν = 0
· simp [hν]
have : NeZero ν := ⟨hν⟩
let μ' := (ν univ)⁻¹ • μ
let ν' := (ν univ)⁻¹ • ν
have : IsFiniteMeasure μ' := μ.smul_finite (by simp [hν])
have hμν' : μ' ≪ ν' := hμν.smul _
have h_rnDeriv_eq : μ'.rnDeriv ν' =ᵐ[ν] μ.rnDeriv ν := by
have h1' : μ'.rnDeriv ν' =ᵐ[ν'] (ν univ)⁻¹ • μ.rnDeriv ν' :=
Measure.rnDeriv_smul_left_of_ne_top' (μ := ν') (ν := μ) (by simp [hν])
have h1 : μ'.rnDeriv ν' =ᵐ[ν] (ν univ)⁻¹ • μ.rnDeriv ν' := by
rwa [Measure.ae_smul_measure_eq] at h1'
simp
have h2 : μ.rnDeriv ν' =ᵐ[ν] (ν univ)⁻¹⁻¹ • μ.rnDeriv ν :=
Measure.rnDeriv_smul_right_of_ne_top' (μ := ν) (ν := μ) (by simp) (by simp [hν])
filter_upwards [h1, h2] with x h1 h2
rw [h1, Pi.smul_apply, smul_eq_mul, h2]
simp only [inv_inv, Pi.smul_apply, smul_eq_mul]
rw [← mul_assoc, ENNReal.inv_mul_cancel, one_mul]
· simp [hν]
· simp
have h_eq : ∫ x, f (μ'.rnDeriv ν' x).toReal ∂ν'
= (ν.real univ)⁻¹ * ∫ x, f ((μ.rnDeriv ν x).toReal) ∂ν := by
rw [integral_smul_measure, smul_eq_mul, ENNReal.toReal_inv]
congr 1
refine integral_congr_ae ?_
filter_upwards [h_rnDeriv_eq] with x hx
rw [hx]
have h : f (μ'.real univ) ≤ ∫ x, f (μ'.rnDeriv ν' x).toReal ∂ν' :=
le_integral_rnDeriv_of_ac hf_cvx hf_cont ?_ hμν'
swap
· refine Integrable.smul_measure ?_ (by simp [hν])
refine (integrable_congr ?_).mpr hf_int
filter_upwards [h_rnDeriv_eq] with x hx
rw [hx]
rw [h_eq, mul_comm, ← div_le_iff₀, div_eq_inv_mul, inv_inv] at h
· convert h
· simp only [div_eq_inv_mul, Measure.smul_apply, smul_eq_mul, ENNReal.toReal_mul,
ENNReal.toReal_inv, μ', measureReal_def]
· simp [ENNReal.toReal_pos_iff, hν, measureReal_def]
end MeasureTheory
|
NAry.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.Data.Finset.Lattice.Prod
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Set.Lattice.Image
/-!
# N-ary images of finsets
This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of
`Set.image2`. This is mostly useful to define pointwise operations.
## Notes
This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please
keep them in sync.
We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂`
and `Set.image2` already fulfills this task.
-/
open Function Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*}
namespace Finset
variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ']
[DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ}
{s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ}
/-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ :=
(s ×ˢ t).image <| uncurry f
@[simp]
theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by
simp [image₂, and_assoc]
@[simp, norm_cast]
theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) :
(image₂ f s t : Set γ) = Set.image2 f s t :=
Set.ext fun _ => mem_image₂
theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) :
#(image₂ f s t) ≤ #s * #t :=
card_image_le.trans_eq <| card_product _ _
theorem card_image₂_iff :
#(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by
rw [← card_product, ← coe_product]
exact card_image_iff
theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) :
#(image₂ f s t) = #s * #t :=
(card_image_of_injective _ hf.uncurry).trans <| card_product _ _
theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t :=
mem_image₂.2 ⟨a, ha, b, hb, rfl⟩
theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by
rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe]
@[gcongr]
theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by
rw [← coe_subset, coe_image₂, coe_image₂]
exact image2_subset hs ht
theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' :=
image₂_subset Subset.rfl ht
theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t :=
image₂_subset hs Subset.rfl
theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb
theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ => mem_image₂_of_mem ha
lemma forall_mem_image₂ {p : γ → Prop} :
(∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, forall_mem_image2]
lemma exists_mem_image₂ {p : γ → Prop} :
(∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, exists_mem_image2]
@[simp]
theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image₂
theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff]
theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α]
@[simp]
theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
rw [← coe_nonempty, coe_image₂]
exact image2_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty :=
image₂_nonempty_iff.2 ⟨hs, ht⟩
theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty :=
(image₂_nonempty_iff.1 h).1
theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty :=
(image₂_nonempty_iff.1 h).2
@[simp]
theorem image₂_empty_left : image₂ f ∅ t = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_empty_right : image₂ f s ∅ = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or]
@[simp]
theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b :=
ext fun x => by simp
@[simp]
theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b :=
ext fun x => by simp
theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) :=
image₂_singleton_left
theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp
theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_union_left
theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_union_right
@[simp]
theorem image₂_insert_left [DecidableEq α] :
image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_left
@[simp]
theorem image₂_insert_right [DecidableEq β] :
image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_right
theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) :
image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_inter_left hf
theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) :
image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_inter_right hf
theorem image₂_inter_subset_left [DecidableEq α] :
image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_left
theorem image₂_inter_subset_right [DecidableEq β] :
image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_right
theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
coe_injective <| by
push_cast
exact image2_congr h
/-- A common special case of `image₂_congr` -/
theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
image₂_congr fun a _ b _ => h a b
variable (s t)
theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by
rw [image₂_singleton_left, card_image_of_injective _ hf]
theorem card_image₂_singleton_right (hf : Injective fun a => f a b) :
#(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf]
theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) :
image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by
simp_rw [image₂_singleton_left, image_inter _ _ hf]
theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) :
image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by
simp_rw [image₂_singleton_right, image_inter _ _ hf]
theorem card_le_card_image₂_left {s : Finset α} (ha : a ∈ s) (hf : Injective (f a)) :
#t ≤ #(image₂ f s t) :=
card_le_card_of_injOn (f a) (fun _ hb ↦ mem_image₂_of_mem ha hb) hf.injOn
theorem card_le_card_image₂_right {t : Finset β} (hb : b ∈ t) (hf : Injective (f · b)) :
#s ≤ #(image₂ f s t) :=
card_le_card_of_injOn (f · b) (fun _ ha ↦ mem_image₂_of_mem ha hb) hf.injOn
variable {s t}
theorem biUnion_image_left : (s.biUnion fun a => t.image <| f a) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_left _
theorem biUnion_image_right : (t.biUnion fun b => s.image fun a => f a b) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_right _
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `Finset.image₂` of those operations.
The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that
`image₂ (*) f g = image₂ (*) g f` in a `CommSemigroup`.
-/
section
variable [DecidableEq δ]
theorem image_image₂ (f : α → β → γ) (g : γ → δ) :
(image₂ f s t).image g = image₂ (fun a b => g (f a b)) s t :=
coe_injective <| by
push_cast
exact image_image2 _ _
theorem image₂_image_left (f : γ → β → δ) (g : α → γ) :
image₂ f (s.image g) t = image₂ (fun a b => f (g a) b) s t :=
coe_injective <| by
push_cast
exact image2_image_left _ _
theorem image₂_image_right (f : α → γ → δ) (g : β → γ) :
image₂ f s (t.image g) = image₂ (fun a b => f a (g b)) s t :=
coe_injective <| by
push_cast
exact image2_image_right _ _
@[simp]
theorem image₂_mk_eq_product [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) :
image₂ Prod.mk s t = s ×ˢ t := by ext; simp [Prod.ext_iff]
@[simp]
theorem image₂_curry (f : α × β → γ) (s : Finset α) (t : Finset β) :
image₂ (curry f) s t = (s ×ˢ t).image f := rfl
@[simp]
theorem image_uncurry_product (f : α → β → γ) (s : Finset α) (t : Finset β) :
(s ×ˢ t).image (uncurry f) = image₂ f s t := rfl
theorem image₂_swap (f : α → β → γ) (s : Finset α) (t : Finset β) :
image₂ f s t = image₂ (fun a b => f b a) t s :=
coe_injective <| by
push_cast
exact image2_swap _ _ _
@[simp]
theorem image₂_left [DecidableEq α] (h : t.Nonempty) : image₂ (fun x _ => x) s t = s :=
coe_injective <| by
push_cast
exact image2_left h
@[simp]
theorem image₂_right [DecidableEq β] (h : s.Nonempty) : image₂ (fun _ y => y) s t = t :=
coe_injective <| by
push_cast
exact image2_right h
theorem image₂_assoc {γ : Type*} {u : Finset γ}
{f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε}
{g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) :=
coe_injective <| by
push_cast
exact image2_assoc h_assoc
theorem image₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image₂ f s t = image₂ g t s :=
(image₂_swap _ _ _).trans <| by simp_rw [h_comm]
theorem image₂_left_comm {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
image₂ f s (image₂ g t u) = image₂ g' t (image₂ f' s u) :=
coe_injective <| by
push_cast
exact image2_left_comm h_left_comm
theorem image₂_right_comm {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
image₂ f (image₂ g s t) u = image₂ g' (image₂ f' s u) t :=
coe_injective <| by
push_cast
exact image2_right_comm h_right_comm
theorem image₂_image₂_image₂_comm {γ δ : Type*} {u : Finset γ} {v : Finset δ} [DecidableEq ζ]
[DecidableEq ζ'] [DecidableEq ν] {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ}
{f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'}
(h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) :
image₂ f (image₂ g s t) (image₂ h u v) = image₂ f' (image₂ g' s u) (image₂ h' t v) :=
coe_injective <| by
push_cast
exact image2_image2_image2_comm h_comm
theorem image_image₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(image₂ f s t).image g = image₂ f' (s.image g₁) (t.image g₂) :=
coe_injective <| by
push_cast
exact image_image2_distrib h_distrib
/-- Symmetric statement to `Finset.image₂_image_left_comm`. -/
theorem image_image₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(image₂ f s t).image g = image₂ f' (s.image g') t :=
coe_injective <| by
push_cast
exact image_image2_distrib_left h_distrib
/-- Symmetric statement to `Finset.image_image₂_right_comm`. -/
theorem image_image₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
(image₂ f s t).image g = image₂ f' s (t.image g') :=
coe_injective <| by
push_cast
exact image_image2_distrib_right h_distrib
/-- Symmetric statement to `Finset.image_image₂_distrib_left`. -/
theorem image₂_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
image₂ f (s.image g) t = (image₂ f' s t).image g' :=
(image_image₂_distrib_left fun a b => (h_left_comm a b).symm).symm
/-- Symmetric statement to `Finset.image_image₂_distrib_right`. -/
theorem image_image₂_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
image₂ f s (t.image g) = (image₂ f' s t).image g' :=
(image_image₂_distrib_right fun a b => (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
theorem image₂_distrib_subset_left {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε}
(h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
image₂ f s (image₂ g t u) ⊆ image₂ g' (image₂ f₁ s t) (image₂ f₂ s u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_left h_distrib
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
theorem image₂_distrib_subset_right {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε}
(h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
image₂ f (image₂ g s t) u ⊆ image₂ g' (image₂ f₁ s u) (image₂ f₂ t u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_right h_distrib
theorem image_image₂_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
(image₂ f s t).image g = image₂ f' (t.image g₁) (s.image g₂) := by
rw [image₂_swap f]
exact image_image₂_distrib fun _ _ => h_antidistrib _ _
/-- Symmetric statement to `Finset.image₂_image_left_anticomm`. -/
theorem image_image₂_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'}
(h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) :
(image₂ f s t).image g = image₂ f' (t.image g') s :=
coe_injective <| by
push_cast
exact image_image2_antidistrib_left h_antidistrib
/-- Symmetric statement to `Finset.image_image₂_right_anticomm`. -/
theorem image_image₂_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'}
(h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) :
(image₂ f s t).image g = image₂ f' t (s.image g') :=
coe_injective <| by
push_cast
exact image_image2_antidistrib_right h_antidistrib
/-- Symmetric statement to `Finset.image_image₂_antidistrib_left`. -/
theorem image₂_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ}
(h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) :
image₂ f (s.image g) t = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm
/-- Symmetric statement to `Finset.image_image₂_antidistrib_right`. -/
theorem image_image₂_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ}
(h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) :
image₂ f s (t.image g) = (image₂ f' t s).image g' :=
(image_image₂_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm
/-- If `a` is a left identity for `f : α → β → β`, then `{a}` is a left identity for
`Finset.image₂ f`. -/
theorem image₂_left_identity {f : α → γ → γ} {a : α} (h : ∀ b, f a b = b) (t : Finset γ) :
image₂ f {a} t = t :=
coe_injective <| by rw [coe_image₂, coe_singleton, Set.image2_left_identity h]
/-- If `b` is a right identity for `f : α → β → α`, then `{b}` is a right identity for
`Finset.image₂ f`. -/
theorem image₂_right_identity {f : γ → β → γ} {b : β} (h : ∀ a, f a b = a) (s : Finset γ) :
image₂ f s {b} = s := by rw [image₂_singleton_right, funext h, image_id']
/-- If each partial application of `f` is injective, and images of `s` under those partial
applications are disjoint (but not necessarily distinct!), then the size of `t` divides the size of
`Finset.image₂ f s t`. -/
theorem card_dvd_card_image₂_right (hf : ∀ a ∈ s, Injective (f a))
(hs : ((fun a => t.image <| f a) '' s).PairwiseDisjoint id) : #t ∣ #(image₂ f s t) := by
classical
induction' s using Finset.induction with a s _ ih
· simp
specialize ih (forall_of_forall_insert hf)
(hs.subset <| Set.image_mono <| coe_subset.2 <| subset_insert _ _)
rw [image₂_insert_left]
by_cases h : Disjoint (image (f a) t) (image₂ f s t)
· rw [card_union_of_disjoint h]
exact Nat.dvd_add (card_image_of_injective _ <| hf _ <| mem_insert_self _ _).symm.dvd ih
simp_rw [← biUnion_image_left, disjoint_biUnion_right, not_forall] at h
obtain ⟨b, hb, h⟩ := h
rwa [union_eq_right.2]
exact (hs.eq (Set.mem_image_of_mem _ <| mem_insert_self _ _)
(Set.mem_image_of_mem _ <| mem_insert_of_mem hb) h).trans_subset
(image_subset_image₂_right hb)
/-- If each partial application of `f` is injective, and images of `t` under those partial
applications are disjoint (but not necessarily distinct!), then the size of `s` divides the size of
`Finset.image₂ f s t`. -/
theorem card_dvd_card_image₂_left (hf : ∀ b ∈ t, Injective fun a => f a b)
(ht : ((fun b => s.image fun a => f a b) '' t).PairwiseDisjoint id) :
#s ∣ #(image₂ f s t) := by rw [← image₂_swap]; exact card_dvd_card_image₂_right hf ht
/-- If a `Finset` is a subset of the image of two `Set`s under a binary operation,
then it is a subset of the `Finset.image₂` of two `Finset` subsets of these `Set`s. -/
theorem subset_set_image₂ {s : Set α} {t : Set β} (hu : ↑u ⊆ image2 f s t) :
∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ image₂ f s' t' := by
rw [← Set.image_prod, subset_set_image_iff] at hu
rcases hu with ⟨u, hu, rfl⟩
classical
use u.image Prod.fst, u.image Prod.snd
simp only [coe_image, Set.image_subset_iff, image₂_image_left, image₂_image_right,
image_subset_iff]
exact ⟨fun _ h ↦ (hu h).1, fun _ h ↦ (hu h).2, fun x hx ↦ mem_image₂_of_mem hx hx⟩
end
section UnionInter
variable [DecidableEq α] [DecidableEq β]
theorem image₂_inter_union_subset_union :
image₂ f (s ∩ s') (t ∪ t') ⊆ image₂ f s t ∪ image₂ f s' t' :=
coe_subset.1 <| by
push_cast
exact Set.image2_inter_union_subset_union
theorem image₂_union_inter_subset_union :
image₂ f (s ∪ s') (t ∩ t') ⊆ image₂ f s t ∪ image₂ f s' t' :=
coe_subset.1 <| by
push_cast
exact Set.image2_union_inter_subset_union
theorem image₂_inter_union_subset {f : α → α → β} {s t : Finset α} (hf : ∀ a b, f a b = f b a) :
image₂ f (s ∩ t) (s ∪ t) ⊆ image₂ f s t :=
coe_subset.1 <| by
push_cast
exact image2_inter_union_subset hf
theorem image₂_union_inter_subset {f : α → α → β} {s t : Finset α} (hf : ∀ a b, f a b = f b a) :
image₂ f (s ∪ t) (s ∩ t) ⊆ image₂ f s t :=
coe_subset.1 <| by
push_cast
exact image2_union_inter_subset hf
end UnionInter
section SemilatticeSup
variable [SemilatticeSup δ]
@[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂`
lemma sup'_image₂_le {g : γ → δ} {a : δ} (h : (image₂ f s t).Nonempty) :
sup' (image₂ f s t) h g ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, g (f x y) ≤ a := by
rw [sup'_le_iff, forall_mem_image₂]
lemma sup'_image₂_left (g : γ → δ) (h : (image₂ f s t).Nonempty) :
sup' (image₂ f s t) h g =
sup' s h.of_image₂_left fun x ↦ sup' t h.of_image₂_right (g <| f x ·) := by
simp only [image₂, sup'_image, sup'_product_left]; rfl
lemma sup'_image₂_right (g : γ → δ) (h : (image₂ f s t).Nonempty) :
sup' (image₂ f s t) h g =
sup' t h.of_image₂_right fun y ↦ sup' s h.of_image₂_left (g <| f · y) := by
simp only [image₂, sup'_image, sup'_product_right]; rfl
variable [OrderBot δ]
@[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂`
lemma sup_image₂_le {g : γ → δ} {a : δ} :
sup (image₂ f s t) g ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, g (f x y) ≤ a := by
rw [Finset.sup_le_iff, forall_mem_image₂]
variable (s t)
lemma sup_image₂_left (g : γ → δ) : sup (image₂ f s t) g = sup s fun x ↦ sup t (g <| f x ·) := by
simp only [image₂, sup_image, sup_product_left]; rfl
lemma sup_image₂_right (g : γ → δ) : sup (image₂ f s t) g = sup t fun y ↦ sup s (g <| f · y) := by
simp only [image₂, sup_image, sup_product_right]; rfl
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf δ]
@[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂`
lemma le_inf'_image₂ {g : γ → δ} {a : δ} (h : (image₂ f s t).Nonempty) :
a ≤ inf' (image₂ f s t) h g ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ g (f x y) := by
rw [le_inf'_iff, forall_mem_image₂]
lemma inf'_image₂_left (g : γ → δ) (h : (image₂ f s t).Nonempty) :
inf' (image₂ f s t) h g =
inf' s h.of_image₂_left fun x ↦ inf' t h.of_image₂_right (g <| f x ·) :=
sup'_image₂_left (δ := δᵒᵈ) g h
lemma inf'_image₂_right (g : γ → δ) (h : (image₂ f s t).Nonempty) :
inf' (image₂ f s t) h g =
inf' t h.of_image₂_right fun y ↦ inf' s h.of_image₂_left (g <| f · y) :=
sup'_image₂_right (δ := δᵒᵈ) g h
variable [OrderTop δ]
@[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂`
lemma le_inf_image₂ {g : γ → δ} {a : δ} :
a ≤ inf (image₂ f s t) g ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ g (f x y) :=
sup_image₂_le (δ := δᵒᵈ)
variable (s t)
lemma inf_image₂_left (g : γ → δ) : inf (image₂ f s t) g = inf s fun x ↦ inf t (g ∘ f x) :=
sup_image₂_left (δ := δᵒᵈ) ..
lemma inf_image₂_right (g : γ → δ) : inf (image₂ f s t) g = inf t fun y ↦ inf s (g <| f · y) :=
sup_image₂_right (δ := δᵒᵈ) ..
end SemilatticeInf
end Finset
open Finset
namespace Fintype
variable {ι : Type*} {α β γ : ι → Type*} [DecidableEq ι] [Fintype ι] [∀ i, DecidableEq (γ i)]
lemma piFinset_image₂ (f : ∀ i, α i → β i → γ i) (s : ∀ i, Finset (α i)) (t : ∀ i, Finset (β i)) :
piFinset (fun i ↦ image₂ (f i) (s i) (t i)) =
image₂ (fun a b i ↦ f _ (a i) (b i)) (piFinset s) (piFinset t) := by
ext; simp only [mem_piFinset, mem_image₂, Classical.skolem, forall_and, funext_iff]
end Fintype
namespace Set
variable [DecidableEq γ] {s : Set α} {t : Set β}
@[simp]
theorem toFinset_image2 (f : α → β → γ) (s : Set α) (t : Set β) [Fintype s] [Fintype t]
[Fintype (image2 f s t)] : (image2 f s t).toFinset = Finset.image₂ f s.toFinset t.toFinset :=
Finset.coe_injective <| by simp
theorem Finite.toFinset_image2 (f : α → β → γ) (hs : s.Finite) (ht : t.Finite)
(hf := hs.image2 f ht) : hf.toFinset = Finset.image₂ f hs.toFinset ht.toFinset :=
Finset.coe_injective <| by simp
end Set
|
poly.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 fintype bigop finset tuple div ssralg.
From mathcomp Require Import countalg binomial.
(******************************************************************************)
(* This file provides a library for univariate polynomials over ring *)
(* structures; it also provides an extended theory for polynomials whose *)
(* coefficients range over commutative rings and integral domains. *)
(* *)
(* {poly R} == the type of polynomials with coefficients of type R, *)
(* represented as lists with a non zero last element *)
(* (big endian representation); the coefficient type R *)
(* must have a canonical nzRingType structure cR. In *)
(* fact {poly R} denotes the concrete type polynomial *)
(* cR; R is just a phantom argument that lets type *)
(* inferencereconstruct the (hidden) nzRingType *)
(* structure cR. *)
(* p : seq R == the big-endian sequence of coefficients of p, via *)
(* the coercion polyseq : polynomial >-> seq. *)
(* Poly s == the polynomial with coefficient sequence s (ignoring *)
(* trailing zeroes). *)
(* \poly_(i < n) E(i) == the polynomial of degree at most n - 1 whose *)
(* coefficients are given by the general term E(i) *)
(* 0, 1, - p, p + q, == the usual ring operations: {poly R} has a canonical *)
(* p * q, p ^+ n, ... nzRingType structure, which is commutative / integral*)
(* when R is commutative / integral, respectively. *)
(* polyC c, c%:P == the constant polynomial c *)
(* 'X == the (unique) variable *)
(* 'X^n == a power of 'X; 'X^0 is 1, 'X^1 is convertible to 'X *)
(* p`_i == the coefficient of 'X^i in p; this is in fact just *)
(* the ring_scope notation generic seq-indexing using *)
(* nth 0%R, combined with the polyseq coercion. *)
(* *** The multi-rule coefE simplifies p`_i *)
(* coefp i == the linear function p |-> p`_i (self-exapanding). *)
(* size p == 1 + the degree of p, or 0 if p = 0 (this is the *)
(* generic seq function combined with polyseq). *)
(* lead_coef p == the coefficient of the highest monomial in p, or 0 *)
(* if p = 0 (hence lead_coef p = 0 iff p = 0) *)
(* p \is monic <=> lead_coef p == 1 (0 is not monic). *)
(* p \is a polyOver S <=> the coefficients of p satisfy S; S should have a *)
(* key that should be (at least) an addrPred. *)
(* p.[x] == the evaluation of a polynomial p at a point x using *)
(* the Horner scheme *)
(* *** The multi-rule hornerE (resp., hornerE_comm) unwinds *)
(* horner evaluation of a polynomial expression (resp., *)
(* in a non commutative ring, with side conditions). *)
(* p^`() == formal derivative of p *)
(* p^`(n) == formal n-derivative of p *)
(* p^`N(n) == formal n-derivative of p divided by n! *)
(* p \Po q == polynomial composition; because this is naturally a *)
(* a linear morphism in the first argument, this *)
(* notation is transposed (q comes before p for redex *)
(* selection, etc). *)
(* := \sum(i < size p) p`_i *: q ^+ i *)
(* odd_poly p == monomials of odd degree of p *)
(* even_poly p == monomials of even degree of p *)
(* take_poly n p == polynomial p without its monomials of degree >= n *)
(* drop_poly n p == polynomial p divided by X^n *)
(* comm_poly p x == x and p.[x] commute; this is a sufficient condition *)
(* for evaluating (q * p).[x] as q.[x] * p.[x] when R *)
(* is not commutative. *)
(* comm_coef p x == x commutes with all the coefficients of p (clearly, *)
(* this implies comm_poly p x). *)
(* root p x == x is a root of p, i.e., p.[x] = 0 *)
(* n.-unity_root x == x is an nth root of unity, i.e., a root of 'X^n - 1 *)
(* n.-primitive_root x == x is a primitive nth root of unity, i.e., n is the *)
(* least positive integer m > 0 such that x ^+ m = 1. *)
(* *** The submodule poly.UnityRootTheory can be used to *)
(* import selectively the part of the theory of roots *)
(* of unity that doesn't mention polynomials explicitly *)
(* map_poly f p == the image of the polynomial by the function f (which *)
(* (locally, p^f) is usually a ring morphism). *)
(* p^:P == p lifted to {poly {poly R}} (:= map_poly polyC p). *)
(* commr_rmorph f u == u commutes with the image of f (i.e., with all f x). *)
(* horner_morph cfu == given cfu : commr_rmorph f u, the function mapping p *)
(* to the value of map_poly f p at u; this is a ring *)
(* morphism from {poly R} to the codomain of f when f *)
(* is a ring morphism. *)
(* horner_eval u == the function mapping p to p.[u]; this function can *)
(* only be used for u in a commutative ring, so it is *)
(* always a linear ring morphism from {poly R} to R. *)
(* horner_alg a == given a in some R-algebra A, the function evaluating *)
(* a polynomial p at a; it is always a linear ring *)
(* morphism from {poly R} to A. *)
(* diff_roots x y == x and y are distinct roots; if R is a field, this *)
(* just means x != y, but this concept is generalized *)
(* to the case where R is only a ring with units (i.e., *)
(* a unitRingType); in which case it means that x and y *)
(* commute, and that the difference x - y is a unit *)
(* (i.e., has a multiplicative inverse) in R. *)
(* to just x != y). *)
(* uniq_roots s == s is a sequence or pairwise distinct roots, in the *)
(* sense of diff_roots p above. *)
(* *** We only show that these operations and properties are transferred by *)
(* morphisms whose domain is a field (thus ensuring injectivity). *)
(* We prove the factor_theorem, and the max_poly_roots inequality relating *)
(* the number of distinct roots of a polynomial and its size. *)
(* The some polynomial lemmas use following suffix interpretation : *)
(* C - constant polynomial (as in polyseqC : a%:P = nseq (a != 0) a). *)
(* X - the polynomial variable 'X (as in coefX : 'X`_i = (i == 1%N)). *)
(* Xn - power of 'X (as in monicXn : monic 'X^n). *)
(* *)
(* Pdeg2.Field (exported by the present library) : theory of the degree 2 *)
(* polynomials. *)
(* Pdeg2.FieldMonic : theory of Pdeg2.Field specialized to monic polynomials. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope unity_root_scope.
Import GRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "{ 'poly' T }" (format "{ 'poly' T }").
Reserved Notation "c %:P" (format "c %:P").
Reserved Notation "p ^:P" (format "p ^:P").
Reserved Notation "'X".
Reserved Notation "''X^' n" (at level 1, format "''X^' n").
Reserved Notation "\poly_ ( i < n ) E"
(at level 34, E at level 36, i, n at level 50,
format "\poly_ ( i < n ) E").
Reserved Notation "p \Po q" (at level 50).
Reserved Notation "p ^`N ( n )" (format "p ^`N ( n )").
Reserved Notation "n .-unity_root" (format "n .-unity_root").
Reserved Notation "n .-primitive_root" (format "n .-primitive_root").
Local Notation simp := Monoid.simpm.
Section Polynomial.
Variable R : nzSemiRingType.
(* Defines a polynomial as a sequence with <> 0 last element *)
Record polynomial := Polynomial {polyseq :> seq R; _ : last 1 polyseq != 0}.
HB.instance Definition _ := [isSub for polyseq].
HB.instance Definition _ := [Choice of polynomial by <:].
Lemma poly_inj : injective polyseq. Proof. exact: val_inj. Qed.
Definition coefp i (p : polynomial) := p`_i.
End Polynomial.
(* We need to break off the section here to let the Bind Scope directives *)
(* take effect. *)
Bind Scope ring_scope with polynomial.
Arguments polynomial R%_type.
Arguments polyseq {R} p%_R.
Arguments poly_inj {R} [p1%_R p2%_R] : rename.
Arguments coefp {R} i%_N / p%_R.
Notation "{ 'poly' T }" := (polynomial T) : type_scope.
Section SemiPolynomialTheory.
Variable R : nzSemiRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Definition lead_coef p := p`_(size p).-1.
Lemma lead_coefE p : lead_coef p = p`_(size p).-1. Proof. by []. Qed.
Definition poly_nil := @Polynomial R [::] (oner_neq0 R).
Definition polyC c : {poly R} := insubd poly_nil [:: c].
Local Notation "c %:P" := (polyC c).
(* Remember the boolean (c != 0) is coerced to 1 if true and 0 if false *)
Lemma polyseqC c : c%:P = nseq (c != 0) c :> seq R.
Proof. by rewrite val_insubd /=; case: (c == 0). Qed.
Lemma size_polyC c : size c%:P = (c != 0).
Proof. by rewrite polyseqC size_nseq. Qed.
Lemma coefC c i : c%:P`_i = if i == 0 then c else 0.
Proof. by rewrite polyseqC; case: i => [|[]]; case: eqP. Qed.
Lemma polyCK : cancel polyC (coefp 0).
Proof. by move=> c; rewrite [coefp 0 _]coefC. Qed.
Lemma polyC_inj : injective polyC.
Proof. by move=> c1 c2 eqc12; have:= coefC c2 0; rewrite -eqc12 coefC. Qed.
Lemma lead_coefC c : lead_coef c%:P = c.
Proof. by rewrite /lead_coef polyseqC; case: eqP. Qed.
(* Extensional interpretation (poly <=> nat -> R) *)
Lemma polyP p q : nth 0 p =1 nth 0 q <-> p = q.
Proof.
split=> [eq_pq | -> //]; apply: poly_inj.
without loss lt_pq: p q eq_pq / size p < size q.
move=> IH; case: (ltngtP (size p) (size q)); try by move/IH->.
by move/(@eq_from_nth _ 0); apply.
case: q => q nz_q /= in lt_pq eq_pq *; case/eqP: nz_q.
by rewrite (last_nth 0) -(subnKC lt_pq) /= -eq_pq nth_default ?leq_addr.
Qed.
Lemma size1_polyC p : size p <= 1 -> p = (p`_0)%:P.
Proof.
move=> le_p_1; apply/polyP=> i; rewrite coefC.
by case: i => // i; rewrite nth_default // (leq_trans le_p_1).
Qed.
(* Builds a polynomial by extension. *)
Definition cons_poly c p : {poly R} :=
if p is Polynomial ((_ :: _) as s) ns then
@Polynomial R (c :: s) ns
else c%:P.
Lemma polyseq_cons c p :
cons_poly c p = (if ~~ nilp p then c :: p else c%:P) :> seq R.
Proof. by case: p => [[]]. Qed.
Lemma size_cons_poly c p :
size (cons_poly c p) = (if nilp p && (c == 0) then 0 else (size p).+1).
Proof. by case: p => [[|c' s] _] //=; rewrite size_polyC; case: eqP. Qed.
Lemma coef_cons c p i : (cons_poly c p)`_i = if i == 0 then c else p`_i.-1.
Proof.
by case: p i => [[|c' s] _] [] //=; rewrite polyseqC; case: eqP => //= _ [].
Qed.
(* Build a polynomial directly from a list of coefficients. *)
Definition Poly := foldr cons_poly 0%:P.
Lemma PolyK c s : last c s != 0 -> Poly s = s :> seq R.
Proof.
case: s => {c}/= [_ |c s]; first by rewrite polyseqC eqxx.
elim: s c => /= [|a s IHs] c nz_c; rewrite polyseq_cons ?{}IHs //.
by rewrite !polyseqC !eqxx nz_c.
Qed.
Lemma polyseqK p : Poly p = p.
Proof. by apply: poly_inj; apply: PolyK (valP p). Qed.
Lemma size_Poly s : size (Poly s) <= size s.
Proof.
elim: s => [|c s IHs] /=; first by rewrite polyseqC eqxx.
by rewrite polyseq_cons; case: ifP => // _; rewrite size_polyC; case: (~~ _).
Qed.
Lemma coef_Poly s i : (Poly s)`_i = s`_i.
Proof.
by elim: s i => [|c s IHs] /= [|i]; rewrite !(coefC, eqxx, coef_cons) /=.
Qed.
(* Build a polynomial from an infinite sequence of coefficients and a bound. *)
Definition poly_expanded_def n E := Poly (mkseq E n).
Fact poly_key : unit. Proof. by []. Qed.
Definition poly := locked_with poly_key poly_expanded_def.
Canonical poly_unlockable := [unlockable fun poly].
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
Lemma polyseq_poly n E :
E n.-1 != 0 -> \poly_(i < n) E i = mkseq [eta E] n :> seq R.
Proof.
rewrite unlock; case: n => [|n] nzEn; first by rewrite polyseqC eqxx.
by rewrite (@PolyK 0) // -nth_last nth_mkseq size_mkseq.
Qed.
Lemma size_poly n E : size (\poly_(i < n) E i) <= n.
Proof. by rewrite unlock (leq_trans (size_Poly _)) ?size_mkseq. Qed.
Lemma size_poly_eq n E : E n.-1 != 0 -> size (\poly_(i < n) E i) = n.
Proof. by move/polyseq_poly->; apply: size_mkseq. Qed.
Lemma coef_poly n E k : (\poly_(i < n) E i)`_k = (if k < n then E k else 0).
Proof.
rewrite unlock coef_Poly.
have [lt_kn | le_nk] := ltnP k n; first by rewrite nth_mkseq.
by rewrite nth_default // size_mkseq.
Qed.
Lemma lead_coef_poly n E :
n > 0 -> E n.-1 != 0 -> lead_coef (\poly_(i < n) E i) = E n.-1.
Proof.
by case: n => // n _ nzE; rewrite /lead_coef size_poly_eq // coef_poly leqnn.
Qed.
Lemma coefK p : \poly_(i < size p) p`_i = p.
Proof.
by apply/polyP=> i; rewrite coef_poly; case: ltnP => // /(nth_default 0)->.
Qed.
(* Nmodule structure for polynomial *)
Definition add_poly_def p q := \poly_(i < maxn (size p) (size q)) (p`_i + q`_i).
Fact add_poly_key : unit. Proof. by []. Qed.
Definition add_poly := locked_with add_poly_key add_poly_def.
Canonical add_poly_unlockable := [unlockable fun add_poly].
Fact coef_add_poly p q i : (add_poly p q)`_i = p`_i + q`_i.
Proof.
rewrite unlock coef_poly; case: leqP => //.
by rewrite geq_max => /andP[le_p_i le_q_i]; rewrite !nth_default ?add0r.
Qed.
Fact add_polyA : associative add_poly.
Proof. by move=> p q r; apply/polyP=> i; rewrite !coef_add_poly addrA. Qed.
Fact add_polyC : commutative add_poly.
Proof. by move=> p q; apply/polyP=> i; rewrite !coef_add_poly addrC. Qed.
Fact add_poly0 : left_id 0%:P add_poly.
Proof.
by move=> p; apply/polyP=> i; rewrite coef_add_poly coefC if_same add0r.
Qed.
HB.instance Definition _ := GRing.isNmodule.Build (polynomial R)
add_polyA add_polyC add_poly0.
(* Properties of the zero polynomial *)
Lemma polyC0 : 0%:P = 0 :> {poly R}. Proof. by []. Qed.
Lemma polyseq0 : (0 : {poly R}) = [::] :> seq R.
Proof. by rewrite polyseqC eqxx. Qed.
Lemma size_poly0 : size (0 : {poly R}) = 0%N.
Proof. by rewrite polyseq0. Qed.
Lemma coef0 i : (0 : {poly R})`_i = 0.
Proof. by rewrite coefC if_same. Qed.
Lemma lead_coef0 : lead_coef 0 = 0 :> R. Proof. exact: lead_coefC. Qed.
Lemma size_poly_eq0 p : (size p == 0) = (p == 0).
Proof. by rewrite size_eq0 -polyseq0. Qed.
Lemma size_poly_leq0 p : (size p <= 0) = (p == 0).
Proof. by rewrite leqn0 size_poly_eq0. Qed.
Lemma size_poly_leq0P p : reflect (p = 0) (size p <= 0).
Proof. by apply: (iffP idP); rewrite size_poly_leq0; move/eqP. Qed.
Lemma size_poly_gt0 p : (0 < size p) = (p != 0).
Proof. by rewrite lt0n size_poly_eq0. Qed.
Lemma gt_size_poly_neq0 p n : (size p > n)%N -> p != 0.
Proof. by move=> /(leq_ltn_trans _) h; rewrite -size_poly_eq0 lt0n_neq0 ?h. Qed.
Lemma nil_poly p : nilp p = (p == 0).
Proof. exact: size_poly_eq0. Qed.
Lemma poly0Vpos p : {p = 0} + {size p > 0}.
Proof. by rewrite lt0n size_poly_eq0; case: eqVneq; [left | right]. Qed.
Lemma polySpred p : p != 0 -> size p = (size p).-1.+1.
Proof. by rewrite -size_poly_eq0 -lt0n => /prednK. Qed.
Lemma lead_coef_eq0 p : (lead_coef p == 0) = (p == 0).
Proof.
rewrite -nil_poly /lead_coef nth_last.
by case: p => [[|x s] /= /negbTE // _]; rewrite eqxx.
Qed.
Lemma polyC_eq0 (c : R) : (c%:P == 0) = (c == 0).
Proof. by rewrite -nil_poly polyseqC; case: (c == 0). Qed.
Lemma size_poly1P p : reflect (exists2 c, c != 0 & p = c%:P) (size p == 1).
Proof.
apply: (iffP eqP) => [pC | [c nz_c ->]]; last by rewrite size_polyC nz_c.
have def_p: p = (p`_0)%:P by rewrite -size1_polyC ?pC.
by exists p`_0; rewrite // -polyC_eq0 -def_p -size_poly_eq0 pC.
Qed.
Lemma size_polyC_leq1 (c : R) : (size c%:P <= 1)%N.
Proof. by rewrite size_polyC; case: (c == 0). Qed.
Lemma leq_sizeP p i : reflect (forall j, i <= j -> p`_j = 0) (size p <= i).
Proof.
apply: (iffP idP) => [hp j hij| hp].
by apply: nth_default; apply: leq_trans hij.
case: (eqVneq p) (lead_coef_eq0 p) => [->|p0]; first by rewrite size_poly0.
rewrite leqNgt; apply/contraFN => hs.
by apply/eqP/hp; rewrite -ltnS (ltn_predK hs).
Qed.
(* Size, leading coef, morphism properties of coef *)
Lemma coefD p q i : (p + q)`_i = p`_i + q`_i.
Proof. exact: coef_add_poly. Qed.
Lemma polyCD : {morph polyC : a b / a + b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefD !coefC ?addr0. Qed.
Lemma size_polyD p q : size (p + q) <= maxn (size p) (size q).
Proof. by rewrite -[+%R]/add_poly unlock; exact: size_poly. Qed.
Lemma size_polyDl p q : size p > size q -> size (p + q) = size p.
Proof.
move=> ltqp; rewrite -[+%R]/add_poly unlock size_poly_eq (maxn_idPl (ltnW _))//.
by rewrite addrC nth_default ?simp ?nth_last //; case: p ltqp => [[]].
Qed.
Lemma size_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) :
size (\sum_(i <- r | P i) F i) <= \max_(i <- r | P i) size (F i).
Proof.
elim/big_rec2: _ => [|i p q _ IHp]; first by rewrite size_poly0.
by rewrite -(maxn_idPr IHp) maxnA leq_max size_polyD.
Qed.
Lemma lead_coefDl p q : size p > size q -> lead_coef (p + q) = lead_coef p.
Proof.
move=> ltqp; rewrite /lead_coef coefD size_polyDl //.
by rewrite addrC nth_default ?simp // -ltnS (ltn_predK ltqp).
Qed.
Lemma lead_coefDr p q : size q > size p -> lead_coef (p + q) = lead_coef q.
Proof. by move/lead_coefDl<-; rewrite addrC. Qed.
(* Polynomial semiring structure. *)
Definition mul_poly_def p q :=
\poly_(i < (size p + size q).-1) (\sum_(j < i.+1) p`_j * q`_(i - j)).
Fact mul_poly_key : unit. Proof. by []. Qed.
Definition mul_poly := locked_with mul_poly_key mul_poly_def.
Canonical mul_poly_unlockable := [unlockable fun mul_poly].
Fact coef_mul_poly p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof.
rewrite unlock coef_poly -subn1 ltn_subRL add1n; case: leqP => // le_pq_i1.
rewrite big1 // => j _; have [lq_q_ij | gt_q_ij] := leqP (size q) (i - j).
by rewrite [q`__]nth_default ?mulr0.
rewrite nth_default ?mul0r // -(leq_add2r (size q)) (leq_trans le_pq_i1) //.
by rewrite -leq_subLR -subnSK.
Qed.
Fact coef_mul_poly_rev p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof.
rewrite coef_mul_poly (reindex_inj rev_ord_inj) /=.
by apply: eq_bigr => j _; rewrite (sub_ordK j).
Qed.
Fact mul_polyA : associative mul_poly.
Proof.
move=> p q r; apply/polyP=> i; rewrite coef_mul_poly coef_mul_poly_rev.
pose coef3 j k := p`_j * (q`_(i - j - k)%N * r`_k).
transitivity (\sum_(j < i.+1) \sum_(k < i.+1 | k <= i - j) coef3 j k).
apply: eq_bigr => /= j _; rewrite coef_mul_poly_rev big_distrr /=.
by rewrite (big_ord_narrow_leq (leq_subr _ _)).
rewrite (exchange_big_dep predT) //=; apply: eq_bigr => k _.
transitivity (\sum_(j < i.+1 | j <= i - k) coef3 j k).
apply: eq_bigl => j; rewrite -ltnS -(ltnS j) -!subSn ?leq_ord //.
by rewrite -subn_gt0 -(subn_gt0 j) -!subnDA addnC.
rewrite (big_ord_narrow_leq (leq_subr _ _)) coef_mul_poly big_distrl /=.
by apply: eq_bigr => j _; rewrite /coef3 -!subnDA addnC mulrA.
Qed.
Fact mul_1poly : left_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_poly1 : right_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_polyDl : left_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDl.
Qed.
Fact mul_polyDr : right_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDr.
Qed.
Fact mul_0poly : left_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact mul_poly0 : right_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact poly1_neq0 : 1%:P != 0 :> {poly R}.
Proof. by rewrite polyC_eq0 oner_neq0. Qed.
HB.instance Definition _ := GRing.Nmodule_isNzSemiRing.Build (polynomial R)
mul_polyA mul_1poly mul_poly1 mul_polyDl mul_polyDr mul_0poly mul_poly0
poly1_neq0.
Lemma polyC1 : 1%:P = 1 :> {poly R}. Proof. by []. Qed.
Lemma polyseq1 : (1 : {poly R}) = [:: 1] :> seq R.
Proof. by rewrite polyseqC oner_neq0. Qed.
Lemma size_poly1 : size (1 : {poly R}) = 1.
Proof. by rewrite polyseq1. Qed.
Lemma coef1 i : (1 : {poly R})`_i = (i == 0)%:R.
Proof. by case: i => [|i]; rewrite polyseq1 /= ?nth_nil. Qed.
Lemma lead_coef1 : lead_coef 1 = 1 :> R. Proof. exact: lead_coefC. Qed.
Lemma coefM p q i : (p * q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof. exact: coef_mul_poly. Qed.
Lemma coefMr p q i : (p * q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof. exact: coef_mul_poly_rev. Qed.
Lemma coef0M p q : (p * q)`_0 = p`_0 * q`_0.
Proof. by rewrite coefM big_ord1. Qed.
Lemma coef0_prod I rI (F : I -> {poly R}) P :
(\prod_(i <- rI| P i) F i)`_0 = \prod_(i <- rI | P i) (F i)`_0.
Proof. by apply: (big_morph _ coef0M); rewrite coef1 eqxx. Qed.
Lemma size_polyMleq p q : size (p * q) <= (size p + size q).-1.
Proof. by rewrite -[*%R]/mul_poly unlock size_poly. Qed.
Lemma mul_lead_coef p q :
lead_coef p * lead_coef q = (p * q)`_(size p + size q).-2.
Proof.
pose dp := (size p).-1; pose dq := (size q).-1.
have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 !mul0r coef0.
have [-> | nz_q] := eqVneq q 0; first by rewrite lead_coef0 !mulr0 coef0.
have ->: (size p + size q).-2 = (dp + dq)%N.
by do 2!rewrite polySpred // addSn addnC.
have lt_p_pq: dp < (dp + dq).+1 by rewrite ltnS leq_addr.
rewrite coefM (bigD1 (Ordinal lt_p_pq)) ?big1 ?simp ?addKn //= => i.
rewrite -val_eqE neq_ltn /= => /orP[lt_i_p | gt_i_p]; last first.
by rewrite nth_default ?mul0r //; rewrite -polySpred in gt_i_p.
rewrite [q`__]nth_default ?mulr0 //= -subSS -{1}addnS -polySpred //.
by rewrite addnC -addnBA ?leq_addr.
Qed.
Lemma size_proper_mul p q :
lead_coef p * lead_coef q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
apply: contraNeq; rewrite mul_lead_coef eqn_leq size_polyMleq -ltnNge => lt_pq.
by rewrite nth_default // -subn1 -(leq_add2l 1) -leq_subLR leq_sub2r.
Qed.
Lemma lead_coef_proper_mul p q :
let c := lead_coef p * lead_coef q in c != 0 -> lead_coef (p * q) = c.
Proof. by move=> /= nz_c; rewrite mul_lead_coef -size_proper_mul. Qed.
Lemma size_poly_prod_leq (I : finType) (P : pred I) (F : I -> {poly R}) :
size (\prod_(i | P i) F i) <= (\sum_(i | P i) size (F i)).+1 - #|P|.
Proof.
rewrite -sum1_card.
elim/big_rec3: _ => [|i n m p _ IHp]; first by rewrite size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
rewrite (leq_trans (size_polyMleq _ _)) // subnS -!subn1 leq_sub2r //.
rewrite -addnS -addnBA ?leq_add2l // ltnW // -subn_gt0 (leq_trans _ IHp) //.
by rewrite polySpred.
Qed.
Lemma coefCM c p i : (c%:P * p)`_i = c * p`_i.
Proof.
rewrite coefM big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma coefMC c p i : (p * c%:P)`_i = p`_i * c.
Proof.
rewrite coefMr big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma polyCM : {morph polyC : a b / a * b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefCM !coefC ?simp. Qed.
Lemma size_poly_exp_leq p n : size (p ^+ n) <= ((size p).-1 * n).+1.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1.
have [-> | nzp] := poly0Vpos p; first by rewrite exprS mul0r size_poly0.
rewrite exprS (leq_trans (size_polyMleq _ _)) //.
by rewrite -{1}(prednK nzp) mulnS -addnS leq_add2l.
Qed.
End SemiPolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyD`")]
Notation size_add := size_polyD (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyDl`")]
Notation size_addl := size_polyDl (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyMleq`")]
Notation size_mul_leq := size_polyMleq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_prod_leq`")]
Notation size_prod_leq := size_poly_prod_leq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_exp_leq`")]
Notation size_exp_leq := size_poly_exp_leq (only parsing).
Section PolynomialTheory.
Variable R : nzRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Local Notation "c %:P" := (polyC c).
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
(* Zmodule structure for polynomial *)
Definition opp_poly_def p := \poly_(i < size p) - p`_i.
Fact opp_poly_key : unit. Proof. by []. Qed.
Definition opp_poly := locked_with opp_poly_key opp_poly_def.
Canonical opp_poly_unlockable := [unlockable fun opp_poly].
Fact coef_opp_poly p i : (opp_poly p)`_i = - p`_i.
Proof.
rewrite unlock coef_poly /=.
by case: leqP => // le_p_i; rewrite nth_default ?oppr0.
Qed.
Fact add_polyN : left_inverse 0%:P opp_poly (@add_poly _).
Proof.
move=> p; apply/polyP=> i.
by rewrite coef_add_poly coef_opp_poly coefC if_same addNr.
Qed.
HB.instance Definition _ := GRing.Nmodule_isZmodule.Build (polynomial R)
add_polyN.
(* Size, leading coef, morphism properties of coef *)
Lemma coefN p i : (- p)`_i = - p`_i.
Proof. exact: coef_opp_poly. Qed.
Lemma coefB p q i : (p - q)`_i = p`_i - q`_i.
Proof. by rewrite coefD coefN. Qed.
HB.instance Definition _ i := GRing.isZmodMorphism.Build {poly R} R (coefp i)
(fun p => (coefB p)^~ i).
Lemma coefMn p n i : (p *+ n)`_i = p`_i *+ n.
Proof. exact: (raddfMn (coefp i)). Qed.
Lemma coefMNn p n i : (p *- n)`_i = p`_i *- n.
Proof. by rewrite coefN coefMn. Qed.
Lemma coef_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) k :
(\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k.
Proof. exact: (raddf_sum (coefp k)). Qed.
Lemma polyCN : {morph (@polyC R) : c / - c}.
Proof. by move=> c; apply/polyP=> [[|i]]; rewrite coefN !coefC ?oppr0. Qed.
Lemma polyCB : {morph (@polyC R) : a b / a - b}.
Proof. by move=> a b; rewrite polyCD polyCN. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build R {poly R} (@polyC _) polyCB.
Lemma polyCMn n : {morph (@polyC R) : c / c *+ n}. Proof. exact: raddfMn. Qed.
Lemma size_polyN p : size (- p) = size p.
Proof.
by apply/eqP; rewrite eqn_leq -{3}(opprK p) -[-%R]/opp_poly unlock !size_poly.
Qed.
Lemma lead_coefN p : lead_coef (- p) = - lead_coef p.
Proof. by rewrite /lead_coef size_polyN coefN. Qed.
(* Polynomial ring structure. *)
Fact polyC_is_monoid_morphism : monoid_morphism (@polyC R).
Proof. by split; last apply: polyCM. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `polyC_is_monoid_morphism` instead")]
Definition polyC_multiplicative :=
(fun g => (g.2, g.1)) polyC_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R {poly R} (@polyC R)
polyC_is_monoid_morphism.
Lemma polyC_exp n : {morph (@polyC R) : c / c ^+ n}. Proof. exact: rmorphXn. Qed.
Lemma polyC_natr n : n%:R%:P = n%:R :> {poly R}.
Proof. by rewrite rmorph_nat. Qed.
Lemma pchar_poly : [pchar {poly R}] =i [pchar R].
Proof.
move=> p; rewrite !inE; congr (_ && _).
apply/eqP/eqP=> [/(congr1 val) /=|]; last by rewrite -polyC_natr => ->.
by rewrite polyseq0 -polyC_natr polyseqC; case: eqP.
Qed.
Lemma size_Msign p n : size ((-1) ^+ n * p) = size p.
Proof.
by rewrite -signr_odd; case: (odd n); rewrite ?mul1r// mulN1r size_polyN.
Qed.
Fact coefp0_is_monoid_morphism : monoid_morphism (coefp 0 : {poly R} -> R).
Proof.
split=> [|p q]; first by rewrite polyCK.
by rewrite [coefp 0 _]coefM big_ord_recl big_ord0 addr0.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `coefp0_is_monoid_morphism` instead")]
Definition coefp0_multiplicative :=
(fun g => (g.2, g.1)) coefp0_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly R} R (coefp 0)
coefp0_is_monoid_morphism.
(* Algebra structure of polynomials. *)
Definition scale_poly_def a (p : {poly R}) := \poly_(i < size p) (a * p`_i).
Fact scale_poly_key : unit. Proof. by []. Qed.
Definition scale_poly := locked_with scale_poly_key scale_poly_def.
Canonical scale_poly_unlockable := [unlockable fun scale_poly].
Fact scale_polyE a p : scale_poly a p = a%:P * p.
Proof.
apply/polyP=> n; rewrite unlock coef_poly coefCM.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Fact scale_polyA a b p : scale_poly a (scale_poly b p) = scale_poly (a * b) p.
Proof. by rewrite !scale_polyE mulrA polyCM. Qed.
Fact scale_1poly : left_id 1 scale_poly.
Proof. by move=> p; rewrite scale_polyE mul1r. Qed.
Fact scale_polyDr a : {morph scale_poly a : p q / p + q}.
Proof. by move=> p q; rewrite !scale_polyE mulrDr. Qed.
Fact scale_polyDl p : {morph scale_poly^~ p : a b / a + b}.
Proof. by move=> a b /=; rewrite !scale_polyE raddfD mulrDl. Qed.
Fact scale_polyAl a p q : scale_poly a (p * q) = scale_poly a p * q.
Proof. by rewrite !scale_polyE mulrA. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R (polynomial R)
scale_polyA scale_1poly scale_polyDr scale_polyDl.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R (polynomial R)
scale_polyAl.
Lemma mul_polyC a p : a%:P * p = a *: p.
Proof. by rewrite -scale_polyE. Qed.
Lemma scale_polyC a b : a *: b%:P = (a * b)%:P.
Proof. by rewrite -mul_polyC polyCM. Qed.
Lemma alg_polyC a : a%:A = a%:P :> {poly R}.
Proof. by rewrite -mul_polyC mulr1. Qed.
Lemma coefZ a p i : (a *: p)`_i = a * p`_i.
Proof.
rewrite -[*:%R]/scale_poly unlock coef_poly.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Lemma size_scale_leq a p : size (a *: p) <= size p.
Proof. by rewrite -[*:%R]/scale_poly unlock size_poly. Qed.
HB.instance Definition _ i := GRing.isScalable.Build R {poly R} R *%R (coefp i)
(fun a => (coefZ a) ^~ i).
HB.instance Definition _ := GRing.Linear.on (coefp 0).
(* The indeterminate, at last! *)
Definition polyX_def := @Poly R [:: 0; 1].
Fact polyX_key : unit. Proof. by []. Qed.
Definition polyX : {poly R} := locked_with polyX_key polyX_def.
Canonical polyX_unlockable := [unlockable of polyX].
Local Notation "'X" := polyX.
Lemma polyseqX : 'X = [:: 0; 1] :> seq R.
Proof. by rewrite unlock !polyseq_cons nil_poly eqxx /= polyseq1. Qed.
Lemma size_polyX : size 'X = 2. Proof. by rewrite polyseqX. Qed.
Lemma polyX_eq0 : ('X == 0) = false.
Proof. by rewrite -size_poly_eq0 size_polyX. Qed.
Lemma coefX i : 'X`_i = (i == 1)%:R.
Proof. by case: i => [|[|i]]; rewrite polyseqX //= nth_nil. Qed.
Lemma lead_coefX : lead_coef 'X = 1.
Proof. by rewrite /lead_coef polyseqX. Qed.
Lemma commr_polyX p : GRing.comm p 'X.
Proof.
apply/polyP=> i; rewrite coefMr coefM.
by apply: eq_bigr => j _; rewrite coefX commr_nat.
Qed.
Lemma coefMX p i : (p * 'X)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof.
rewrite coefMr big_ord_recl coefX ?simp.
case: i => [|i]; rewrite ?big_ord0 //= big_ord_recl polyseqX subn1 /=.
by rewrite big1 ?simp // => j _; rewrite nth_nil !simp.
Qed.
Lemma coefXM p i : ('X * p)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof. by rewrite -commr_polyX coefMX. Qed.
Lemma cons_poly_def p a : cons_poly a p = p * 'X + a%:P.
Proof.
apply/polyP=> i; rewrite coef_cons coefD coefMX coefC.
by case: ifP; rewrite !simp.
Qed.
Lemma poly_ind (K : {poly R} -> Type) :
K 0 -> (forall p c, K p -> K (p * 'X + c%:P)) -> (forall p, K p).
Proof.
move=> K0 Kcons p; rewrite -[p]polyseqK.
by elim: {p}(p : seq R) => //= p c IHp; rewrite cons_poly_def; apply: Kcons.
Qed.
Lemma polyseqXaddC a : 'X + a%:P = [:: a; 1] :> seq R.
Proof. by rewrite -['X]mul1r -cons_poly_def polyseq_cons polyseq1. Qed.
Lemma polyseqXsubC a : 'X - a%:P = [:: - a; 1] :> seq R.
Proof. by rewrite -polyCN polyseqXaddC. Qed.
Lemma size_XsubC a : size ('X - a%:P) = 2.
Proof. by rewrite polyseqXsubC. Qed.
Lemma size_XaddC b : size ('X + b%:P) = 2.
Proof. by rewrite -[b]opprK rmorphN size_XsubC. Qed.
Lemma lead_coefXaddC a : lead_coef ('X + a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXaddC. Qed.
Lemma lead_coefXsubC a : lead_coef ('X - a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXsubC. Qed.
Lemma polyXsubC_eq0 a : ('X - a%:P == 0) = false.
Proof. by rewrite -nil_poly polyseqXsubC. Qed.
Lemma size_MXaddC p c :
size (p * 'X + c%:P) = (if (p == 0) && (c == 0) then 0 else (size p).+1).
Proof. by rewrite -cons_poly_def size_cons_poly nil_poly. Qed.
Lemma polyseqMX p : p != 0 -> p * 'X = 0 :: p :> seq R.
Proof.
by move=> nz_p; rewrite -[p * _]addr0 -cons_poly_def polyseq_cons nil_poly nz_p.
Qed.
Lemma size_mulX p : p != 0 -> size (p * 'X) = (size p).+1.
Proof. by move/polyseqMX->. Qed.
Lemma lead_coefMX p : lead_coef (p * 'X) = lead_coef p.
Proof.
have [-> | nzp] := eqVneq p 0; first by rewrite mul0r.
by rewrite /lead_coef !nth_last polyseqMX.
Qed.
Lemma size_XmulC a : a != 0 -> size ('X * a%:P) = 2.
Proof.
by move=> nz_a; rewrite -commr_polyX size_mulX ?polyC_eq0 ?size_polyC nz_a.
Qed.
Local Notation "''X^' n" := ('X ^+ n).
Lemma coefXn n i : 'X^n`_i = (i == n)%:R.
Proof.
by elim: n i => [|n IHn] [|i]; rewrite ?coef1 // exprS coefXM ?IHn.
Qed.
Lemma polyseqXn n : 'X^n = rcons (nseq n 0) 1 :> seq R.
Proof.
elim: n => [|n IHn]; rewrite ?polyseq1 // exprSr.
by rewrite polyseqMX -?size_poly_eq0 IHn ?size_rcons.
Qed.
Lemma size_polyXn n : size 'X^n = n.+1.
Proof. by rewrite polyseqXn size_rcons size_nseq. Qed.
Lemma commr_polyXn p n : GRing.comm p 'X^n.
Proof. exact/commrX/commr_polyX. Qed.
Lemma lead_coefXn n : lead_coef 'X^n = 1.
Proof. by rewrite /lead_coef nth_last polyseqXn last_rcons. Qed.
Lemma lead_coefXnaddC n c : 0 < n -> lead_coef ('X^n + c%:P) = 1.
Proof.
move=> n_gt0; rewrite lead_coefDl ?lead_coefXn//.
by rewrite size_polyC size_polyXn ltnS (leq_trans (leq_b1 _)).
Qed.
Lemma lead_coefXnsubC n c : 0 < n -> lead_coef ('X^n - c%:P) = 1.
Proof. by move=> n_gt0; rewrite -polyCN lead_coefXnaddC. Qed.
Lemma size_XnaddC n c : 0 < n -> size ('X^n + c%:P) = n.+1.
Proof.
by move=> *; rewrite size_polyDl ?size_polyXn// size_polyC; case: eqP.
Qed.
Lemma size_XnsubC n c : 0 < n -> size ('X^n - c%:P) = n.+1.
Proof. by move=> *; rewrite -polyCN size_XnaddC. Qed.
Lemma polyseqMXn n p : p != 0 -> p * 'X^n = ncons n 0 p :> seq R.
Proof.
case: n => [|n] nz_p; first by rewrite mulr1.
elim: n => [|n IHn]; first exact: polyseqMX.
by rewrite exprSr mulrA polyseqMX -?nil_poly IHn.
Qed.
Lemma coefMXn n p i : (p * 'X^n)`_i = if i < n then 0 else p`_(i - n).
Proof.
have [-> | /polyseqMXn->] := eqVneq p 0; last exact: nth_ncons.
by rewrite mul0r !coef0 if_same.
Qed.
Lemma size_mulXn n p : p != 0 -> size (p * 'X^n) = (n + size p)%N.
Proof.
elim: n p => [p p_neq0| n IH p p_neq0]; first by rewrite mulr1.
by rewrite exprS mulrA IH -?size_poly_eq0 size_mulX // addnS.
Qed.
Lemma coefXnM n p i : ('X^n * p)`_i = if i < n then 0 else p`_(i - n).
Proof. by rewrite -commr_polyXn coefMXn. Qed.
Lemma coef_sumMXn I (r : seq I) (P : pred I) (p : I -> R) (n : I -> nat) k :
(\sum_(i <- r | P i) p i *: 'X^(n i))`_k =
\sum_(i <- r | P i && (n i == k)) p i.
Proof.
rewrite coef_sum big_mkcondr; apply: eq_bigr => i Pi.
by rewrite coefZ coefXn mulr_natr mulrb eq_sym.
Qed.
(* Expansion of a polynomial as an indexed sum *)
Lemma poly_def n E : \poly_(i < n) E i = \sum_(i < n) E i *: 'X^i.
Proof. by apply/polyP => i; rewrite coef_sumMXn coef_poly big_ord1_eq. Qed.
(* Monic predicate *)
Definition monic_pred := fun p => lead_coef p == 1.
Arguments monic_pred _ /.
Definition monic := [qualify p | monic_pred p].
Lemma monicE p : (p \is monic) = (lead_coef p == 1). Proof. by []. Qed.
Lemma monicP p : reflect (lead_coef p = 1) (p \is monic).
Proof. exact: eqP. Qed.
Lemma monic1 : 1 \is monic. Proof. exact/eqP/lead_coef1. Qed.
Lemma monicX : 'X \is monic. Proof. exact/eqP/lead_coefX. Qed.
Lemma monicXn n : 'X^n \is monic. Proof. exact/eqP/lead_coefXn. Qed.
Lemma monic_neq0 p : p \is monic -> p != 0.
Proof. by rewrite -lead_coef_eq0 => /eqP->; apply: oner_neq0. Qed.
Lemma lead_coef_monicM p q : p \is monic -> lead_coef (p * q) = lead_coef q.
Proof.
have [-> | nz_q] := eqVneq q 0; first by rewrite mulr0.
by move/monicP=> mon_p; rewrite lead_coef_proper_mul mon_p mul1r ?lead_coef_eq0.
Qed.
Lemma lead_coef_Mmonic p q : q \is monic -> lead_coef (p * q) = lead_coef p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
by move/monicP=> mon_q; rewrite lead_coef_proper_mul mon_q mulr1 ?lead_coef_eq0.
Qed.
Lemma size_monicM p q :
p \is monic -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
move/monicP=> mon_p nz_q.
by rewrite size_proper_mul // mon_p mul1r lead_coef_eq0.
Qed.
Lemma size_Mmonic p q :
p != 0 -> q \is monic -> size (p * q) = (size p + size q).-1.
Proof.
move=> nz_p /monicP mon_q.
by rewrite size_proper_mul // mon_q mulr1 lead_coef_eq0.
Qed.
Lemma monicMl p q : p \is monic -> (p * q \is monic) = (q \is monic).
Proof. by move=> mon_p; rewrite !monicE lead_coef_monicM. Qed.
Lemma monicMr p q : q \is monic -> (p * q \is monic) = (p \is monic).
Proof. by move=> mon_q; rewrite !monicE lead_coef_Mmonic. Qed.
Fact monic_mulr_closed : mulr_closed monic.
Proof. by split=> [|p q mon_p]; rewrite (monic1, monicMl). Qed.
HB.instance Definition _ := GRing.isMulClosed.Build {poly R} monic_pred
monic_mulr_closed.
Lemma monic_exp p n : p \is monic -> p ^+ n \is monic.
Proof. exact: rpredX. Qed.
Lemma monic_prod I rI (P : pred I) (F : I -> {poly R}):
(forall i, P i -> F i \is monic) -> \prod_(i <- rI | P i) F i \is monic.
Proof. exact: rpred_prod. Qed.
Lemma monicXaddC c : 'X + c%:P \is monic.
Proof. exact/eqP/lead_coefXaddC. Qed.
Lemma monicXsubC c : 'X - c%:P \is monic.
Proof. exact/eqP/lead_coefXsubC. Qed.
Lemma monic_prod_XsubC I rI (P : pred I) (F : I -> R) :
\prod_(i <- rI | P i) ('X - (F i)%:P) \is monic.
Proof. by apply: monic_prod => i _; apply: monicXsubC. Qed.
Lemma lead_coef_prod_XsubC I rI (P : pred I) (F : I -> R) :
lead_coef (\prod_(i <- rI | P i) ('X - (F i)%:P)) = 1.
Proof. exact/eqP/monic_prod_XsubC. Qed.
Lemma size_prod_XsubC I rI (F : I -> R) :
size (\prod_(i <- rI) ('X - (F i)%:P)) = (size rI).+1.
Proof.
elim: rI => [|i r /= <-]; rewrite ?big_nil ?size_poly1 // big_cons.
rewrite size_monicM ?monicXsubC ?monic_neq0 ?monic_prod_XsubC //.
by rewrite size_XsubC.
Qed.
Lemma size_exp_XsubC n a : size (('X - a%:P) ^+ n) = n.+1.
Proof.
rewrite -[n]card_ord -prodr_const -big_filter size_prod_XsubC.
by have [e _ _ [_ ->]] := big_enumP.
Qed.
Lemma monicXnaddC n c : 0 < n -> 'X^n + c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnaddC. Qed.
Lemma monicXnsubC n c : 0 < n -> 'X^n - c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnsubC. Qed.
(* Some facts about regular elements. *)
Lemma lreg_lead p : GRing.lreg (lead_coef p) -> GRing.lreg p.
Proof.
move/mulrI_eq0=> reg_p; apply: mulrI0_lreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma rreg_lead p : GRing.rreg (lead_coef p) -> GRing.rreg p.
Proof.
move/mulIr_eq0=> reg_p; apply: mulIr0_rreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma lreg_lead0 p : GRing.lreg (lead_coef p) -> p != 0.
Proof. by move/lreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma rreg_lead0 p : GRing.rreg (lead_coef p) -> p != 0.
Proof. by move/rreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma lreg_size c p : GRing.lreg c -> size (c *: p) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite scaler0.
rewrite -mul_polyC size_proper_mul; first by rewrite size_polyC lreg_neq0.
by rewrite lead_coefC mulrI_eq0 ?lead_coef_eq0.
Qed.
Lemma lreg_polyZ_eq0 c p : GRing.lreg c -> (c *: p == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /lreg_size->. Qed.
Lemma lead_coef_lreg c p :
GRing.lreg c -> lead_coef (c *: p) = c * lead_coef p.
Proof. by move=> reg_c; rewrite !lead_coefE coefZ lreg_size. Qed.
Lemma rreg_size c p : GRing.rreg c -> size (p * c%:P) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
rewrite size_proper_mul; first by rewrite size_polyC rreg_neq0 ?addn1.
by rewrite lead_coefC mulIr_eq0 ?lead_coef_eq0.
Qed.
Lemma rreg_polyMC_eq0 c p : GRing.rreg c -> (p * c%:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /rreg_size->. Qed.
Lemma rreg_div0 q r d :
GRing.rreg (lead_coef d) -> size r < size d ->
(q * d + r == 0) = (q == 0) && (r == 0).
Proof.
move=> reg_d lt_r_d; rewrite addrC addr_eq0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r oppr0.
apply: contraTF lt_r_d => /eqP->; rewrite -leqNgt size_polyN.
rewrite size_proper_mul ?mulIr_eq0 ?lead_coef_eq0 //.
by rewrite (polySpred nz_q) leq_addl.
Qed.
Lemma monic_comreg p :
p \is monic -> GRing.comm p (lead_coef p)%:P /\ GRing.rreg (lead_coef p).
Proof. by move/monicP->; split; [apply: commr1 | apply: rreg1]. Qed.
Lemma monic_lreg p : p \is monic -> GRing.lreg p.
Proof. by move=> /eqP lp1; apply/lreg_lead; rewrite lp1; apply/lreg1. Qed.
Lemma monic_rreg p : p \is monic -> GRing.rreg p.
Proof. by move=> /eqP lp1; apply/rreg_lead; rewrite lp1; apply/rreg1. Qed.
(* Horner evaluation of polynomials *)
Implicit Types s rs : seq R.
Fixpoint horner_rec s x := if s is a :: s' then horner_rec s' x * x + a else 0.
Definition horner p := horner_rec p.
Local Notation "p .[ x ]" := (horner p x) : ring_scope.
Lemma horner0 x : (0 : {poly R}).[x] = 0.
Proof. by rewrite /horner polyseq0. Qed.
Lemma hornerC c x : (c%:P).[x] = c.
Proof. by rewrite /horner polyseqC; case: eqP; rewrite /= ?simp. Qed.
Lemma hornerX x : 'X.[x] = x.
Proof. by rewrite /horner polyseqX /= !simp. Qed.
Lemma horner_cons p c x : (cons_poly c p).[x] = p.[x] * x + c.
Proof.
rewrite /horner polyseq_cons; case: nilP => //= ->.
by rewrite !simp -/(_.[x]) hornerC.
Qed.
Lemma horner_coef0 p : p.[0] = p`_0.
Proof. by rewrite /horner; case: (p : seq R) => //= c p'; rewrite !simp. Qed.
Lemma hornerMXaddC p c x : (p * 'X + c%:P).[x] = p.[x] * x + c.
Proof. by rewrite -cons_poly_def horner_cons. Qed.
Lemma hornerMX p x : (p * 'X).[x] = p.[x] * x.
Proof. by rewrite -[p * 'X]addr0 hornerMXaddC addr0. Qed.
Lemma horner_Poly s x : (Poly s).[x] = horner_rec s x.
Proof. by elim: s => [|a s /= <-]; rewrite (horner0, horner_cons). Qed.
Lemma horner_coef p x : p.[x] = \sum_(i < size p) p`_i * x ^+ i.
Proof.
rewrite /horner.
elim: {p}(p : seq R) => /= [|a s ->]; first by rewrite big_ord0.
rewrite big_ord_recl simp addrC big_distrl /=.
by congr (_ + _); apply: eq_bigr => i _; rewrite -mulrA exprSr.
Qed.
Lemma horner_coef_wide n p x :
size p <= n -> p.[x] = \sum_(i < n) p`_i * x ^+ i.
Proof.
move=> le_p_n.
rewrite horner_coef (big_ord_widen n (fun i => p`_i * x ^+ i)) // big_mkcond.
by apply: eq_bigr => i _; case: ltnP => // le_p_i; rewrite nth_default ?simp.
Qed.
Lemma horner_poly n E x : (\poly_(i < n) E i).[x] = \sum_(i < n) E i * x ^+ i.
Proof.
rewrite (@horner_coef_wide n) ?size_poly //.
by apply: eq_bigr => i _; rewrite coef_poly ltn_ord.
Qed.
Lemma hornerN p x : (- p).[x] = - p.[x].
Proof.
rewrite -[-%R]/opp_poly unlock horner_poly horner_coef -sumrN /=.
by apply: eq_bigr => i _; rewrite mulNr.
Qed.
Lemma hornerD p q x : (p + q).[x] = p.[x] + q.[x].
Proof.
rewrite -[+%R]/(@add_poly R) unlock horner_poly; set m := maxn _ _.
rewrite !(@horner_coef_wide m) ?leq_max ?leqnn ?orbT // -big_split /=.
by apply: eq_bigr => i _; rewrite -mulrDl.
Qed.
Lemma hornerXsubC a x : ('X - a%:P).[x] = x - a.
Proof. by rewrite hornerD hornerN hornerC hornerX. Qed.
Lemma horner_sum I (r : seq I) (P : pred I) F x :
(\sum_(i <- r | P i) F i).[x] = \sum_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (horner0, hornerD). Qed.
Lemma hornerCM a p x : (a%:P * p).[x] = a * p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(mulr0, horner0).
by rewrite mulrDr mulrA -polyCM !hornerMXaddC IHp mulrDr mulrA.
Qed.
Lemma hornerZ c p x : (c *: p).[x] = c * p.[x].
Proof. by rewrite -mul_polyC hornerCM. Qed.
Lemma hornerMn n p x : (p *+ n).[x] = p.[x] *+ n.
Proof. by elim: n => [| n IHn]; rewrite ?horner0 // !mulrS hornerD IHn. Qed.
Definition comm_coef p x := forall i, p`_i * x = x * p`_i.
Definition comm_poly p x := x * p.[x] = p.[x] * x.
Lemma comm_coef_poly p x : comm_coef p x -> comm_poly p x.
Proof.
move=> cpx; rewrite /comm_poly !horner_coef big_distrl big_distrr /=.
by apply: eq_bigr => i _; rewrite /= mulrA -cpx -!mulrA commrX.
Qed.
Lemma comm_poly0 x : comm_poly 0 x.
Proof. by rewrite /comm_poly !horner0 !simp. Qed.
Lemma comm_poly1 x : comm_poly 1 x.
Proof. by rewrite /comm_poly !hornerC !simp. Qed.
Lemma comm_polyX x : comm_poly 'X x.
Proof. by rewrite /comm_poly !hornerX. Qed.
Lemma comm_polyD p q x: comm_poly p x -> comm_poly q x -> comm_poly (p + q) x.
Proof. by rewrite /comm_poly hornerD mulrDr mulrDl => -> ->. Qed.
Lemma commr_horner a b p : GRing.comm a b -> comm_coef p a -> GRing.comm a p.[b].
Proof.
move=> cab cpa; rewrite horner_coef; apply: commr_sum => i _.
by apply: commrM => //; apply: commrX.
Qed.
Lemma hornerM_comm p q x : comm_poly q x -> (p * q).[x] = p.[x] * q.[x].
Proof.
move=> comm_qx.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(simp, horner0).
rewrite mulrDl hornerD hornerCM -mulrA -commr_polyX mulrA hornerMX.
by rewrite {}IHp -mulrA -comm_qx mulrA -mulrDl hornerMXaddC.
Qed.
Lemma comm_polyM p q x: comm_poly p x -> comm_poly q x -> comm_poly (p * q) x.
Proof.
by move=> px qx; rewrite /comm_poly hornerM_comm// mulrA px -mulrA qx mulrA.
Qed.
Lemma horner_exp_comm p x n : comm_poly p x -> (p ^+ n).[x] = p.[x] ^+ n.
Proof.
move=> comm_px; elim: n => [|n IHn]; first by rewrite hornerC.
by rewrite !exprSr -IHn hornerM_comm.
Qed.
Lemma comm_poly_exp p n x: comm_poly p x -> comm_poly (p ^+ n) x.
Proof. by move=> px; rewrite /comm_poly !horner_exp_comm// commrX. Qed.
Lemma hornerXn x n : ('X^n).[x] = x ^+ n.
Proof. by rewrite horner_exp_comm /comm_poly hornerX. Qed.
Definition hornerE_comm :=
(hornerD, hornerN, hornerX, hornerC, horner_cons,
simp, hornerCM, hornerZ,
(fun p x => hornerM_comm p (comm_polyX x))).
Definition root p : pred R := fun x => p.[x] == 0.
Lemma mem_root p x : x \in root p = (p.[x] == 0).
Proof. by []. Qed.
Lemma rootE p x : (root p x = (p.[x] == 0)) * ((x \in root p) = (p.[x] == 0)).
Proof. by []. Qed.
Lemma rootP p x : reflect (p.[x] = 0) (root p x).
Proof. exact: eqP. Qed.
Lemma rootPt p x : reflect (p.[x] == 0) (root p x).
Proof. exact: idP. Qed.
Lemma rootPf p x : reflect ((p.[x] == 0) = false) (~~ root p x).
Proof. exact: negPf. Qed.
Lemma rootC a x : root a%:P x = (a == 0).
Proof. by rewrite rootE hornerC. Qed.
Lemma root0 x : root 0 x.
Proof. by rewrite rootC. Qed.
Lemma root1 x : ~~ root 1 x.
Proof. by rewrite rootC oner_eq0. Qed.
Lemma rootX x : root 'X x = (x == 0).
Proof. by rewrite rootE hornerX. Qed.
Lemma rootN p x : root (- p) x = root p x.
Proof. by rewrite rootE hornerN oppr_eq0. Qed.
Lemma root_size_gt1 a p : p != 0 -> root p a -> 1 < size p.
Proof.
rewrite ltnNge => nz_p; apply: contraL => /size1_polyC Dp.
by rewrite Dp rootC -polyC_eq0 -Dp.
Qed.
Lemma root_XsubC a x : root ('X - a%:P) x = (x == a).
Proof. by rewrite rootE hornerXsubC subr_eq0. Qed.
Lemma root_XaddC a x : root ('X + a%:P) x = (x == - a).
Proof. by rewrite -root_XsubC rmorphN opprK. Qed.
Theorem factor_theorem p a : reflect (exists q, p = q * ('X - a%:P)) (root p a).
Proof.
apply: (iffP eqP) => [pa0 | [q ->]]; last first.
by rewrite hornerM_comm /comm_poly hornerXsubC subrr ?simp.
exists (\poly_(i < size p) horner_rec (drop i.+1 p) a).
apply/polyP=> i; rewrite mulrBr coefB coefMX coefMC !coef_poly.
apply: canRL (addrK _) _; rewrite addrC; have [le_p_i | lt_i_p] := leqP.
rewrite nth_default // !simp drop_oversize ?if_same //.
exact: leq_trans (leqSpred _).
case: i => [|i] in lt_i_p *; last by rewrite ltnW // (drop_nth 0 lt_i_p).
by rewrite drop1 /= -{}pa0 /horner; case: (p : seq R) lt_i_p.
Qed.
Lemma multiplicity_XsubC p a :
{m | exists2 q, (p != 0) ==> ~~ root q a & p = q * ('X - a%:P) ^+ m}.
Proof.
have [n le_p_n] := ubnP (size p); elim: n => // n IHn in p le_p_n *.
have [-> | nz_p /=] := eqVneq p 0; first by exists 0, 0; rewrite ?mul0r.
have [/sig_eqW[p1 Dp] | nz_pa] := altP (factor_theorem p a); last first.
by exists 0%N, p; rewrite ?mulr1.
have nz_p1: p1 != 0 by apply: contraNneq nz_p => p1_0; rewrite Dp p1_0 mul0r.
have /IHn[m /sig2_eqW[q nz_qa Dp1]]: size p1 < n.
by rewrite Dp size_Mmonic ?monicXsubC // size_XsubC addn2 in le_p_n.
by exists m.+1, q; [rewrite nz_p1 in nz_qa | rewrite exprSr mulrA -Dp1].
Qed.
(* Roots of unity. *)
#[deprecated(since="mathcomp 2.3.0",note="Use size_XnsubC instead.")]
Lemma size_Xn_sub_1 n : n > 0 -> size ('X^n - 1 : {poly R}) = n.+1.
Proof. exact/size_XnsubC. Qed.
#[deprecated(since="mathcomp 2.3.0'",note="Use monicXnsubC instead.")]
Lemma monic_Xn_sub_1 n : n > 0 -> 'X^n - 1 \is monic.
Proof. exact/monicXnsubC. Qed.
Definition root_of_unity n : pred R := root ('X^n - 1).
Local Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Lemma unity_rootE n z : n.-unity_root z = (z ^+ n == 1).
Proof.
by rewrite /root_of_unity rootE hornerD hornerN hornerXn hornerC subr_eq0.
Qed.
Lemma unity_rootP n z : reflect (z ^+ n = 1) (n.-unity_root z).
Proof. by rewrite unity_rootE; apply: eqP. Qed.
Definition primitive_root_of_unity n z :=
(n > 0) && [forall i : 'I_n, i.+1.-unity_root z == (i.+1 == n)].
Local Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Lemma prim_order_exists n z :
n > 0 -> z ^+ n = 1 -> {m | m.-primitive_root z & (m %| n)}.
Proof.
move=> n_gt0 zn1.
have: exists m, (m > 0) && (z ^+ m == 1) by exists n; rewrite n_gt0 /= zn1.
case/ex_minnP=> m /andP[m_gt0 /eqP zm1] m_min.
exists m.
apply/andP; split=> //; apply/eqfunP=> [[i]] /=.
rewrite leq_eqVlt unity_rootE.
case: eqP => [-> _ | _]; first by rewrite zm1 eqxx.
by apply: contraTF => zi1; rewrite -leqNgt m_min.
have: n %% m < m by rewrite ltn_mod.
apply: contraLR; rewrite -lt0n -leqNgt => nm_gt0; apply: m_min.
by rewrite nm_gt0 /= expr_mod ?zn1.
Qed.
Section OnePrimitive.
Variables (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Lemma prim_order_gt0 : n > 0. Proof. by case/andP: prim_z. Qed.
Let n_gt0 := prim_order_gt0.
Lemma prim_expr_order : z ^+ n = 1.
Proof.
case/andP: prim_z => _; rewrite -(prednK n_gt0) => /forallP/(_ ord_max).
by rewrite unity_rootE eqxx eqb_id => /eqP.
Qed.
Lemma prim_expr_mod i : z ^+ (i %% n) = z ^+ i.
Proof. exact: expr_mod prim_expr_order. Qed.
Lemma prim_order_dvd i : (n %| i) = (z ^+ i == 1).
Proof.
move: n_gt0; rewrite -prim_expr_mod /dvdn -(ltn_mod i).
case: {i}(i %% n)%N => [|i] lt_i; first by rewrite !eqxx.
case/andP: prim_z => _ /forallP/(_ (Ordinal (ltnW lt_i)))/eqP.
by rewrite unity_rootE eqn_leq andbC leqNgt lt_i.
Qed.
Lemma eq_prim_root_expr i j : (z ^+ i == z ^+ j) = (i == j %[mod n]).
Proof.
wlog le_ji: i j / j <= i.
move=> IH; case: (leqP j i) => [|/ltnW] /IH //.
by rewrite eq_sym (eq_sym (j %% n)%N).
rewrite -{1}(subnKC le_ji) exprD -prim_expr_mod eqn_mod_dvd //.
rewrite prim_order_dvd; apply/eqP/eqP=> [|->]; last by rewrite mulr1.
move/(congr1 ( *%R (z ^+ (n - j %% n)))); rewrite mulrA -exprD.
by rewrite subnK ?prim_expr_order ?mul1r // ltnW ?ltn_mod.
Qed.
Lemma exp_prim_root k : (n %/ gcdn k n).-primitive_root (z ^+ k).
Proof.
set d := gcdn k n; have d_gt0: (0 < d)%N by rewrite gcdn_gt0 orbC n_gt0.
have [d_dv_k d_dv_n]: (d %| k /\ d %| n)%N by rewrite dvdn_gcdl dvdn_gcdr.
set q := (n %/ d)%N; rewrite /q.-primitive_root ltn_divRL // n_gt0.
apply/forallP=> i; rewrite unity_rootE -exprM -prim_order_dvd.
rewrite -(divnK d_dv_n) -/q -(divnK d_dv_k) mulnAC dvdn_pmul2r //.
apply/eqP; apply/idP/idP=> [|/eqP->]; last by rewrite dvdn_mull.
rewrite Gauss_dvdr; first by rewrite eqn_leq ltn_ord; apply: dvdn_leq.
by rewrite /coprime gcdnC -(eqn_pmul2r d_gt0) mul1n muln_gcdl !divnK.
Qed.
Lemma dvdn_prim_root m : (m %| n)%N -> m.-primitive_root (z ^+ (n %/ m)).
Proof.
set k := (n %/ m)%N => m_dv_n; rewrite -{1}(mulKn m n_gt0) -divnA // -/k.
by rewrite -{1}(@gcdn_idPl k n _) ?exp_prim_root // -(divnK m_dv_n) dvdn_mulr.
Qed.
Lemma prim_root_eq0 : (z == 0) = (n == 0%N).
Proof.
rewrite gtn_eqF//; apply/eqP => z0; have /esym/eqP := prim_expr_order.
by rewrite z0 expr0n gtn_eqF//= oner_eq0.
Qed.
End OnePrimitive.
Lemma prim_root_exp_coprime n z k :
n.-primitive_root z -> n.-primitive_root (z ^+ k) = coprime k n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
apply/idP/idP=> [prim_zk | co_k_n].
set d := gcdn k n; have dv_d_n: (d %| n)%N := dvdn_gcdr _ _.
rewrite /coprime -/d -(eqn_pmul2r n_gt0) mul1n -{2}(gcdnMl n d).
rewrite -{2}(divnK dv_d_n) (mulnC _ d) -muln_gcdr (gcdn_idPr _) //.
rewrite (prim_order_dvd prim_zk) -exprM -(prim_order_dvd prim_z).
by rewrite muln_divCA_gcd dvdn_mulr.
have zkn_1: z ^+ k ^+ n = 1 by rewrite exprAC (prim_expr_order prim_z) expr1n.
have{zkn_1} [m prim_zk dv_m_n]:= prim_order_exists n_gt0 zkn_1.
suffices /eqP <-: m == n by [].
rewrite eqn_dvd dv_m_n -(@Gauss_dvdr n k m) 1?coprime_sym //=.
by rewrite (prim_order_dvd prim_z) exprM (prim_expr_order prim_zk).
Qed.
(* Lifting a ring predicate to polynomials. *)
Implicit Type S : {pred R}.
Definition polyOver_pred S := fun p : {poly R} => all (mem S) p.
Arguments polyOver_pred _ _ /.
Definition polyOver S := [qualify a p | polyOver_pred S p].
Lemma polyOverS (S1 S2 : {pred R}) :
{subset S1 <= S2} -> {subset polyOver S1 <= polyOver S2}.
Proof.
by move=> sS12 p /(all_nthP 0)S1p; apply/(all_nthP 0)=> i /S1p; apply: sS12.
Qed.
Lemma polyOver0 S : 0 \is a polyOver S.
Proof. by rewrite qualifE /= polyseq0. Qed.
Lemma polyOver_poly S n E :
(forall i, i < n -> E i \in S) -> \poly_(i < n) E i \is a polyOver S.
Proof.
move=> S_E; apply/(all_nthP 0)=> i lt_i_p /=; rewrite coef_poly.
by case: ifP => [/S_E// | /idP[]]; apply: leq_trans lt_i_p (size_poly n E).
Qed.
Section PolyOverAdd.
Variable S : addrClosed R.
Lemma polyOverP {p} : reflect (forall i, p`_i \in S) (p \in polyOver S).
Proof.
apply: (iffP (all_nthP 0)) => [Sp i | Sp i _]; last exact: Sp.
by have [/Sp // | /(nth_default 0)->] := ltnP i (size p); apply: rpred0.
Qed.
Lemma polyOverC c : (c%:P \in polyOver S) = (c \in S).
Proof.
by rewrite [LHS]qualifE /= polyseqC; case: eqP => [->|] /=; rewrite ?andbT ?rpred0.
Qed.
Fact polyOver_addr_closed : addr_closed (polyOver S).
Proof.
split=> [|p q Sp Sq]; first exact: polyOver0.
by apply/polyOverP=> i; rewrite coefD rpredD ?(polyOverP _).
Qed.
HB.instance Definition _ := GRing.isAddClosed.Build {poly R} (polyOver_pred S)
polyOver_addr_closed.
End PolyOverAdd.
Section PolyOverSemiRing2.
Variable S : semiring2Closed R.
Lemma polyOver_mulr_2closed : GRing.mulr_2closed (polyOver S).
Proof.
move=> p q /polyOverP Sp /polyOverP Sq; apply/polyOverP=> i.
by rewrite coefM rpred_sum // => j _; rewrite rpredM.
Qed.
HB.instance Definition _ := GRing.isMul2Closed.Build {poly R} (polyOver_pred S)
polyOver_mulr_2closed.
End PolyOverSemiRing2.
Fact polyOverNr (zmodS : zmodClosed R) : oppr_closed (polyOver zmodS).
Proof.
by move=> p /polyOverP Sp; apply/polyOverP=> i; rewrite coefN rpredN.
Qed.
HB.instance Definition _ (zmodS : zmodClosed R) :=
GRing.isOppClosed.Build {poly R} (polyOver_pred zmodS) (@polyOverNr _).
Section PolyOverSemiring.
Variable S : semiringClosed R.
Fact polyOver_mul1_closed : 1 \in (polyOver S).
Proof. by rewrite polyOverC rpred1. Qed.
HB.instance Definition _ := GRing.isMul1Closed.Build {poly R} (polyOver_pred S)
polyOver_mul1_closed.
Lemma polyOverZ : {in S & polyOver S, forall c p, c *: p \is a polyOver S}.
Proof.
by move=> c p Sc /polyOverP Sp; apply/polyOverP=> i; rewrite coefZ rpredM ?Sp.
Qed.
Lemma polyOverX : 'X \in polyOver S.
Proof. by rewrite qualifE /= polyseqX /= rpred0 rpred1. Qed.
Lemma polyOverXn n : 'X^n \in polyOver S.
Proof. by rewrite rpredX// polyOverX. Qed.
Lemma rpred_horner : {in polyOver S & S, forall p x, p.[x] \in S}.
Proof.
move=> p x /polyOverP Sp Sx; rewrite horner_coef rpred_sum // => i _.
by rewrite rpredM ?rpredX.
Qed.
End PolyOverSemiring.
Section PolyOverRing.
Variable S : subringClosed R.
HB.instance Definition _ := GRing.MulClosed.on (polyOver_pred S).
Lemma polyOverXaddC c : ('X + c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnaddC n c : ('X^n + c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverXn// ?polyOverC. Qed.
Lemma polyOverXsubC c : ('X - c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnsubC n c : ('X^n - c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverXn// ?polyOverC. Qed.
End PolyOverRing.
(* Single derivative. *)
Definition deriv p := \poly_(i < (size p).-1) (p`_i.+1 *+ i.+1).
Local Notation "a ^` ()" := (deriv a).
Lemma coef_deriv p i : p^`()`_i = p`_i.+1 *+ i.+1.
Proof.
rewrite coef_poly -subn1 ltn_subRL.
by case: leqP => // /(nth_default 0) ->; rewrite mul0rn.
Qed.
Lemma polyOver_deriv (ringS : semiringClosed R) :
{in polyOver ringS, forall p, p^`() \is a polyOver ringS}.
Proof.
by move=> p /polyOverP Kp; apply/polyOverP=> i; rewrite coef_deriv rpredMn ?Kp.
Qed.
Lemma derivC c : c%:P^`() = 0.
Proof. by apply/polyP=> i; rewrite coef_deriv coef0 coefC mul0rn. Qed.
Lemma derivX : ('X)^`() = 1.
Proof. by apply/polyP=> [[|i]]; rewrite coef_deriv coef1 coefX ?mul0rn. Qed.
Lemma derivXn n : ('X^n)^`() = 'X^(n.-1) *+ n.
Proof.
case: n => [|n]; first exact: derivC.
apply/polyP=> i; rewrite coef_deriv coefMn !coefXn eqSS.
by case: eqP => [-> // | _]; rewrite !mul0rn.
Qed.
Fact deriv_is_linear : linear deriv.
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_deriv, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ deriv
(GRing.semilinear_linear deriv_is_linear).
Lemma deriv0 : 0^`() = 0.
Proof. exact: linear0. Qed.
Lemma derivD : {morph deriv : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivN : {morph deriv : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivB : {morph deriv : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivXsubC (a : R) : ('X - a%:P)^`() = 1.
Proof. by rewrite derivB derivX derivC subr0. Qed.
Lemma derivMn n p : (p *+ n)^`() = p^`() *+ n.
Proof. exact: linearMn. Qed.
Lemma derivMNn n p : (p *- n)^`() = p^`() *- n.
Proof. exact: linearMNn. Qed.
Lemma derivZ c p : (c *: p)^`() = c *: p^`().
Proof. exact: linearZ. Qed.
Lemma deriv_mulC c p : (c%:P * p)^`() = c%:P * p^`().
Proof. by rewrite !mul_polyC derivZ. Qed.
Lemma derivMXaddC p c : (p * 'X + c%:P)^`() = p + p^`() * 'X.
Proof.
apply/polyP=> i; rewrite raddfD /= derivC addr0 coefD !(coefMX, coef_deriv).
by case: i; rewrite ?addr0.
Qed.
Lemma derivM p q : (p * q)^`() = p^`() * q + p * q^`().
Proof.
elim/poly_ind: p => [|p b IHp]; first by rewrite !(mul0r, add0r, derivC).
rewrite mulrDl -mulrA -commr_polyX mulrA -[_ * 'X]addr0 raddfD /= !derivMXaddC.
by rewrite deriv_mulC IHp !mulrDl -!mulrA !commr_polyX !addrA.
Qed.
Definition derivE := Eval lazy beta delta [morphism_2 morphism_1] in
(derivZ, deriv_mulC, derivC, derivX, derivMXaddC, derivXsubC, derivM, derivB,
derivD, derivN, derivXn, derivM, derivMn).
(* Iterated derivative. *)
Definition derivn n p := iter n deriv p.
Local Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Lemma derivn0 p : p^`(0) = p.
Proof. by []. Qed.
Lemma derivn1 p : p^`(1) = p^`().
Proof. by []. Qed.
Lemma derivnS p n : p^`(n.+1) = p^`(n)^`().
Proof. by []. Qed.
Lemma derivSn p n : p^`(n.+1) = p^`()^`(n).
Proof. exact: iterSr. Qed.
Lemma coef_derivn n p i : p^`(n)`_i = p`_(n + i) *+ (n + i) ^_ n.
Proof.
elim: n i => [|n IHn] i; first by rewrite ffactn0 mulr1n.
by rewrite derivnS coef_deriv IHn -mulrnA ffactnSr addSnnS addKn.
Qed.
Lemma polyOver_derivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`(n) \is a polyOver ringS}.
Proof.
move=> p /polyOverP Kp /= n; apply/polyOverP=> i.
by rewrite coef_derivn rpredMn.
Qed.
Fact derivn_is_linear n : linear (derivn n).
Proof. by elim: n => // n IHn a p q; rewrite derivnS IHn linearP. Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (derivn n)
(GRing.semilinear_linear (derivn_is_linear n)).
Lemma derivnC c n : c%:P^`(n) = if n == 0 then c%:P else 0.
Proof. by case: n => // n; rewrite derivSn derivC linear0. Qed.
Lemma derivnD n : {morph derivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivnB n : {morph derivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivnMn n m p : (p *+ m)^`(n) = p^`(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma derivnMNn n m p : (p *- m)^`(n) = p^`(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma derivnN n : {morph derivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivnZ n : scalable (derivn n).
Proof. exact: linearZZ. Qed.
Lemma derivnXn m n : ('X^m)^`(n) = 'X^(m - n) *+ m ^_ n.
Proof.
apply/polyP=>i; rewrite coef_derivn coefMn !coefXn.
case: (ltnP m n) => [lt_m_n | le_m_n].
by rewrite eqn_leq leqNgt ltn_addr // mul0rn ffact_small.
by rewrite -{1 3}(subnKC le_m_n) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Lemma derivnMXaddC n p c :
(p * 'X + c%:P)^`(n.+1) = p^`(n) *+ n.+1 + p^`(n.+1) * 'X.
Proof.
elim: n => [|n IHn]; first by rewrite derivn1 derivMXaddC.
rewrite derivnS IHn derivD derivM derivX mulr1 derivMn -!derivnS.
by rewrite addrA addrAC -mulrSr.
Qed.
Lemma derivn_poly0 p n : size p <= n -> p^`(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_derivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma lt_size_deriv (p : {poly R}) : p != 0 -> size p^`() < size p.
Proof. by move=> /polySpred->; apply: size_poly. Qed.
(* A normalising version of derivation to get the division by n! in Taylor *)
Definition nderivn n p := \poly_(i < size p - n) (p`_(n + i) *+ 'C(n + i, n)).
Local Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Lemma coef_nderivn n p i : p^`N(n)`_i = p`_(n + i) *+ 'C(n + i, n).
Proof.
rewrite coef_poly ltn_subRL; case: leqP => // le_p_ni.
by rewrite nth_default ?mul0rn.
Qed.
(* Here is the division by n! *)
Lemma nderivn_def n p : p^`(n) = p^`N(n) *+ n`!.
Proof.
by apply/polyP=> i; rewrite coefMn coef_nderivn coef_derivn -mulrnA bin_ffact.
Qed.
Lemma polyOver_nderivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`N(n) \in polyOver ringS}.
Proof.
move=> p /polyOverP Sp /= n; apply/polyOverP=> i.
by rewrite coef_nderivn rpredMn.
Qed.
Lemma nderivn0 p : p^`N(0) = p.
Proof. by rewrite -[p^`N(0)](nderivn_def 0). Qed.
Lemma nderivn1 p : p^`N(1) = p^`().
Proof. by rewrite -[p^`N(1)](nderivn_def 1). Qed.
Lemma nderivnC c n : (c%:P)^`N(n) = if n == 0 then c%:P else 0.
Proof.
apply/polyP=> i; rewrite coef_nderivn.
by case: n => [|n]; rewrite ?bin0 // coef0 coefC mul0rn.
Qed.
Lemma nderivnXn m n : ('X^m)^`N(n) = 'X^(m - n) *+ 'C(m, n).
Proof.
apply/polyP=> i; rewrite coef_nderivn coefMn !coefXn.
have [lt_m_n | le_n_m] := ltnP m n.
by rewrite eqn_leq leqNgt ltn_addr // mul0rn bin_small.
by rewrite -{1 3}(subnKC le_n_m) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Fact nderivn_is_linear n : linear (nderivn n).
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_nderivn, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (nderivn n)
(GRing.semilinear_linear (nderivn_is_linear n)).
Lemma nderivnD n : {morph nderivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma nderivnB n : {morph nderivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma nderivnMn n m p : (p *+ m)^`N(n) = p^`N(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma nderivnMNn n m p : (p *- m)^`N(n) = p^`N(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma nderivnN n : {morph nderivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma nderivnZ n : scalable (nderivn n).
Proof. exact: linearZZ. Qed.
Lemma nderivnMXaddC n p c :
(p * 'X + c%:P)^`N(n.+1) = p^`N(n) + p^`N(n.+1) * 'X.
Proof.
apply/polyP=> i; rewrite coef_nderivn !coefD !coefMX coefC.
rewrite !addSn /= !coef_nderivn addr0 binS mulrnDr addrC; congr (_ + _).
by rewrite addSnnS; case: i; rewrite // addn0 bin_small.
Qed.
Lemma nderivn_poly0 p n : size p <= n -> p^`N(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_nderivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma nderiv_taylor p x h :
GRing.comm x h -> p.[x + h] = \sum_(i < size p) p^`N(i).[x] * h ^+ i.
Proof.
move/commrX=> cxh; elim/poly_ind: p => [|p c IHp].
by rewrite size_poly0 big_ord0 horner0.
rewrite hornerMXaddC size_MXaddC.
have [-> | nz_p] := eqVneq p 0.
rewrite horner0 !simp; have [-> | _] := c =P 0; first by rewrite big_ord0.
by rewrite size_poly0 big_ord_recl big_ord0 nderivn0 hornerC !simp.
rewrite big_ord_recl nderivn0 !simp hornerMXaddC addrAC; congr (_ + _).
rewrite mulrDr {}IHp !big_distrl polySpred //= big_ord_recl /= mulr1 -addrA.
rewrite nderivn0 /bump /(addn 1) /=; congr (_ + _).
rewrite !big_ord_recr /= nderivnMXaddC -mulrA -exprSr -polySpred // !addrA.
congr (_ + _); last by rewrite (nderivn_poly0 (leqnn _)) !simp.
rewrite addrC -big_split /=; apply: eq_bigr => i _.
by rewrite nderivnMXaddC !hornerE_comm /= mulrDl -!mulrA -exprSr cxh.
Qed.
Lemma nderiv_taylor_wide n p x h :
GRing.comm x h -> size p <= n ->
p.[x + h] = \sum_(i < n) p^`N(i).[x] * h ^+ i.
Proof.
move/nderiv_taylor=> -> le_p_n.
rewrite (big_ord_widen n (fun i => p^`N(i).[x] * h ^+ i)) // big_mkcond.
apply: eq_bigr => i _; case: leqP => // /nderivn_poly0->.
by rewrite horner0 simp.
Qed.
Lemma eq_poly n E1 E2 : (forall i, i < n -> E1 i = E2 i) ->
poly n E1 = poly n E2 :> {poly R}.
Proof. by move=> E; rewrite !poly_def; apply: eq_bigr => i _; rewrite E. Qed.
End PolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyN`")]
Notation size_opp := size_polyN (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_poly instead.")]
Notation char_poly := pchar_poly (only parsing).
Prenex Implicits polyC polyCK Poly polyseqK lead_coef root horner polyOver.
Arguments monic {R}.
Notation "\poly_ ( i < n ) E" := (poly n (fun i => E)) : ring_scope.
Notation "c %:P" := (polyC c) : ring_scope.
Notation "'X" := (polyX _) : ring_scope.
Notation "''X^' n" := ('X ^+ n) : ring_scope.
Notation "p .[ x ]" := (horner p x) : ring_scope.
Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Notation "a ^` ()" := (deriv a) : ring_scope.
Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Arguments monic_pred _ _ /.
Arguments monicP {R p}.
Arguments rootP {R p x}.
Arguments rootPf {R p x}.
Arguments rootPt {R p x}.
Arguments unity_rootP {R n z}.
Arguments polyOver_pred _ _ _ /.
Arguments polyOverP {R S p}.
Arguments polyC_inj {R} [x1 x2] eq_x12P.
Arguments eq_poly {R n} [E1] E2 eq_E12.
Section IdomainPrimRoot.
Variables (R : idomainType) (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Import prime.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma prim_root_pcharF p : (p %| n)%N -> p \in [pchar R] = false.
Proof.
move=> pn; apply: contraTF isT => pchar_p; have p_prime := pcharf_prime pchar_p.
have /dvdnP[[|k] n_eq_kp] := pn; first by rewrite n_eq_kp in (n_gt0).
have /eqP := prim_expr_order prim_z; rewrite n_eq_kp exprM.
rewrite -pFrobenius_autE -(pFrobenius_aut1 pchar_p) -subr_eq0 -rmorphB/=.
rewrite pFrobenius_autE expf_eq0// prime_gt0//= subr_eq0 => /eqP.
move=> /eqP; rewrite -(prim_order_dvd prim_z) n_eq_kp.
rewrite -[X in _ %| X]muln1 dvdn_pmul2l ?dvdn1// => /eqP peq1.
by rewrite peq1 in p_prime.
Qed.
Lemma pchar_prim_root : [pchar R]^'.-nat n.
Proof. by apply/pnatP=> // p pp pn; rewrite inE/= prim_root_pcharF. Qed.
Lemma prim_root_pi_eq0 m : \pi(n).-nat m -> m%:R != 0 :> R.
Proof.
by rewrite natf_neq0_pchar; apply: sub_in_pnat => p _; apply: pnatPpi pchar_prim_root.
Qed.
Lemma prim_root_dvd_eq0 m : (m %| n)%N -> m%:R != 0 :> R.
Proof.
case: m => [|m mn]; first by rewrite dvd0n gtn_eqF.
by rewrite prim_root_pi_eq0 ?(sub_in_pnat (in1W (pi_of_dvd mn _))) ?pnat_pi.
Qed.
Lemma prim_root_natf_neq0 : n%:R != 0 :> R.
Proof. by rewrite prim_root_dvd_eq0. Qed.
End IdomainPrimRoot.
#[deprecated(since="mathcomp 2.4.0", note="Use prim_root_pcharF instead.")]
Notation prim_root_charF := prim_root_pcharF (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_prim_root instead.")]
Notation char_prim_root := pchar_prim_root (only parsing).
(* Container morphism. *)
Section MapPoly.
Section Definitions.
Variables (aR rR : nzRingType) (f : aR -> rR).
Definition map_poly (p : {poly aR}) := \poly_(i < size p) f p`_i.
(* Alternative definition; the one above is more convenient because it lets *)
(* us use the lemmas on \poly, e.g., size (map_poly p) <= size p is an *)
(* instance of size_poly. *)
Lemma map_polyE p : map_poly p = Poly (map f p).
Proof.
rewrite /map_poly unlock; congr Poly.
apply: (@eq_from_nth _ 0); rewrite size_mkseq ?size_map // => i lt_i_p.
by rewrite [RHS](nth_map 0) ?nth_mkseq.
Qed.
Definition commr_rmorph u := forall x, GRing.comm u (f x).
Definition horner_morph u of commr_rmorph u := fun p => (map_poly p).[u].
End Definitions.
Variables aR rR : nzRingType.
Section Combinatorial.
Variables (iR : nzRingType) (f : aR -> rR).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma map_poly0 : 0^f = 0.
Proof. by rewrite map_polyE polyseq0. Qed.
Lemma eq_map_poly (g : aR -> rR) : f =1 g -> map_poly f =1 map_poly g.
Proof. by move=> eq_fg p; rewrite !map_polyE (eq_map eq_fg). Qed.
Lemma map_poly_id g (p : {poly iR}) :
{in (p : seq iR), g =1 id} -> map_poly g p = p.
Proof. by move=> g_id; rewrite map_polyE map_id_in ?polyseqK. Qed.
Lemma coef_map_id0 p i : f 0 = 0 -> (p^f)`_i = f p`_i.
Proof.
by move=> f0; rewrite coef_poly; case: ltnP => // le_p_i; rewrite nth_default.
Qed.
Lemma map_Poly_id0 s : f 0 = 0 -> (Poly s)^f = Poly (map f s).
Proof.
move=> f0; apply/polyP=> j; rewrite coef_map_id0 ?coef_Poly //.
have [/(nth_map 0 0)->// | le_s_j] := ltnP j (size s).
by rewrite !nth_default ?size_map.
Qed.
Lemma map_poly_comp_id0 (g : iR -> aR) p :
f 0 = 0 -> map_poly (f \o g) p = (map_poly g p)^f.
Proof. by move=> f0; rewrite map_polyE map_comp -map_Poly_id0 -?map_polyE. Qed.
Lemma size_map_poly_id0 p : f (lead_coef p) != 0 -> size p^f = size p.
Proof. by move=> nz_fp; apply: size_poly_eq. Qed.
Lemma map_poly_eq0_id0 p : f (lead_coef p) != 0 -> (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_map_poly_id0->. Qed.
Lemma lead_coef_map_id0 p :
f 0 = 0 -> f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof.
by move=> f0 nz_fp; rewrite lead_coefE coef_map_id0 ?size_map_poly_id0.
Qed.
Hypotheses (inj_f : injective f) (f_0 : f 0 = 0).
Lemma size_map_inj_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite map_poly0 !size_poly0.
by rewrite size_map_poly_id0 // -f_0 (inj_eq inj_f) lead_coef_eq0.
Qed.
Lemma map_inj_poly : injective (map_poly f).
Proof.
move=> p q /polyP eq_pq; apply/polyP=> i; apply: inj_f.
by rewrite -!coef_map_id0 ?eq_pq.
Qed.
Lemma lead_coef_map_inj p : lead_coef p^f = f (lead_coef p).
Proof. by rewrite !lead_coefE size_map_inj_poly coef_map_id0. Qed.
End Combinatorial.
Lemma map_polyK (f : aR -> rR) g :
cancel g f -> f 0 = 0 -> cancel (map_poly g) (map_poly f).
Proof.
by move=> gK f_0 p; rewrite /= -map_poly_comp_id0 ?map_poly_id // => x _ //=.
Qed.
Lemma eq_in_map_poly_id0 (f g : aR -> rR) (S : addrClosed aR) :
f 0 = 0 -> g 0 = 0 -> {in S, f =1 g} ->
{in polyOver S, map_poly f =1 map_poly g}.
Proof.
move=> f0 g0 eq_fg p pP; apply/polyP => i.
by rewrite !coef_map_id0// eq_fg// (polyOverP _).
Qed.
Lemma eq_in_map_poly (f g : {additive aR -> rR}) (S : addrClosed aR) :
{in S, f =1 g} -> {in polyOver S, map_poly f =1 map_poly g}.
Proof. by move=> /eq_in_map_poly_id0; apply; rewrite //?raddf0. Qed.
Section Additive.
Variables (iR : nzRingType) (f : {additive aR -> rR}).
Local Notation "p ^f" := (map_poly (GRing.Additive.sort f) p) : ring_scope.
Lemma coef_map p i : p^f`_i = f p`_i.
Proof. exact: coef_map_id0 (raddf0 f). Qed.
Lemma map_Poly s : (Poly s)^f = Poly (map f s).
Proof. exact: map_Poly_id0 (raddf0 f). Qed.
Lemma map_poly_comp (g : iR -> aR) p :
map_poly (f \o g) p = map_poly f (map_poly g p).
Proof. exact: map_poly_comp_id0 (raddf0 f). Qed.
Fact map_poly_is_zmod_morphism : zmod_morphism (map_poly f).
Proof. by move=> p q; apply/polyP=> i; rewrite !(coef_map, coefB) raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_zmod_morphism` instead")]
Definition map_poly_is_additive := map_poly_is_zmod_morphism.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_zmod_morphism.
Lemma map_polyC a : (a%:P)^f = (f a)%:P.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefC) -!mulrb raddfMn. Qed.
Lemma lead_coef_map_eq p :
f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof. exact: lead_coef_map_id0 (raddf0 f). Qed.
End Additive.
Variable f : {rmorphism aR -> rR}.
Implicit Types p : {poly aR}.
Local Notation "p ^f" := (map_poly (GRing.RMorphism.sort f) p) : ring_scope.
Fact map_poly_is_monoid_morphism : monoid_morphism (map_poly f).
Proof.
split=> [|p q]; apply/polyP=> i.
by rewrite !(coef_map, coef1) /= rmorph_nat.
rewrite coef_map /= !coefM /= !rmorph_sum; apply: eq_bigr => j _.
by rewrite !coef_map rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_monoid_morphism` instead")]
Definition map_poly_is_multiplicative :=
(fun g => (g.2, g.1)) map_poly_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_monoid_morphism.
Lemma map_polyZ c p : (c *: p)^f = f c *: p^f.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefZ) /= rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build aR {poly aR} {poly rR} (f \; *:%R) (map_poly f)
map_polyZ.
Lemma map_polyX : ('X)^f = 'X.
Proof. by apply/polyP=> i; rewrite coef_map !coefX /= rmorph_nat. Qed.
Lemma map_polyXn n : ('X^n)^f = 'X^n.
Proof. by rewrite rmorphXn /= map_polyX. Qed.
Lemma map_polyXaddC x : ('X + x%:P)^f = 'X + (f x)%:P.
Proof. by rewrite raddfD/= map_polyX map_polyC. Qed.
Lemma map_polyXsubC x : ('X - x%:P)^f = 'X - (f x)%:P.
Proof. by rewrite raddfB/= map_polyX map_polyC. Qed.
Lemma map_prod_XsubC I (rI : seq I) P F :
(\prod_(i <- rI | P i) ('X - (F i)%:P))^f =
\prod_(i <- rI | P i) ('X - (f (F i))%:P).
Proof.
by rewrite rmorph_prod//; apply/eq_bigr => x /=; rewrite map_polyXsubC.
Qed.
Lemma prod_map_poly (ar : seq aR) P :
\prod_(x <- map f ar | P x) ('X - x%:P) =
(\prod_(x <- ar | P (f x)) ('X - x%:P))^f.
Proof. by rewrite big_map map_prod_XsubC. Qed.
Lemma monic_map p : p \is monic -> p^f \is monic.
Proof.
move/monicP=> mon_p; rewrite monicE.
by rewrite lead_coef_map_eq mon_p /= rmorph1 ?oner_neq0.
Qed.
Lemma horner_map p x : p^f.[f x] = f p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(rmorph0, horner0).
rewrite hornerMXaddC !rmorphD !rmorphM /=.
by rewrite map_polyX map_polyC hornerMXaddC IHp.
Qed.
Lemma map_comm_poly p x : comm_poly p x -> comm_poly p^f (f x).
Proof. by rewrite /comm_poly horner_map -!rmorphM // => ->. Qed.
Lemma map_comm_coef p x : comm_coef p x -> comm_coef p^f (f x).
Proof. by move=> cpx i; rewrite coef_map -!rmorphM ?cpx. Qed.
Lemma rmorph_root p x : root p x -> root p^f (f x).
Proof. by move/eqP=> px0; rewrite rootE horner_map px0 rmorph0. Qed.
Lemma rmorph_unity_root n z : n.-unity_root z -> n.-unity_root (f z).
Proof.
move/rmorph_root; rewrite rootE rmorphB hornerD hornerN.
by rewrite /= map_polyXn rmorph1 hornerC hornerXn subr_eq0 unity_rootE.
Qed.
Section HornerMorph.
Variable u : rR.
Hypothesis cfu : commr_rmorph f u.
Lemma horner_morphC a : horner_morph cfu a%:P = f a.
Proof. by rewrite /horner_morph map_polyC hornerC. Qed.
Lemma horner_morphX : horner_morph cfu 'X = u.
Proof. by rewrite /horner_morph map_polyX hornerX. Qed.
Fact horner_is_linear : linear_for (f \; *%R) (horner_morph cfu).
Proof. by move=> c p q; rewrite /horner_morph linearP /= hornerD hornerZ. Qed.
Fact horner_is_monoid_morphism : monoid_morphism (horner_morph cfu).
Proof.
split=> [|p q]; first by rewrite /horner_morph rmorph1 hornerC.
rewrite /horner_morph rmorphM /= hornerM_comm //.
by apply: comm_coef_poly => i; rewrite coef_map cfu.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_is_monoid_morphism` instead")]
Definition horner_is_multiplicative :=
(fun g => (g.2, g.1)) horner_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isSemilinear.Build aR {poly aR} rR _ (horner_morph cfu)
(GRing.semilinear_linear horner_is_linear).
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} rR (horner_morph cfu)
horner_is_monoid_morphism.
End HornerMorph.
Lemma deriv_map p : p^f^`() = (p^`())^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_deriv) //= rmorphMn. Qed.
Lemma derivn_map p n : p^f^`(n) = (p^`(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_derivn) //= rmorphMn. Qed.
Lemma nderivn_map p n : p^f^`N(n) = (p^`N(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_nderivn) //= rmorphMn. Qed.
End MapPoly.
Lemma mapf_root (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R})
(p : {poly F}) (x : F) : root (map_poly f p) (f x) = root p x.
Proof. by rewrite !rootE horner_map fmorph_eq0. Qed.
(* Morphisms from the polynomial ring, and the initiality of polynomials *)
(* with respect to these. *)
Section MorphPoly.
Variable (aR rR : nzRingType) (pf : {rmorphism {poly aR} -> rR}).
Lemma poly_morphX_comm : commr_rmorph (pf \o polyC) (pf 'X).
Proof. by move=> a; rewrite /GRing.comm /= -!rmorphM // commr_polyX. Qed.
Lemma poly_initial : pf =1 horner_morph poly_morphX_comm.
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
by rewrite !rmorphD !rmorphM /= -{}IHp horner_morphC ?horner_morphX.
Qed.
End MorphPoly.
Notation "p ^:P" := (map_poly polyC p) : ring_scope.
Section PolyCompose.
Variable R : nzRingType.
Implicit Types p q : {poly R}.
Definition comp_poly q p := p^:P.[q].
Local Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma size_map_polyC p : size p^:P = size p.
Proof. exact/(size_map_inj_poly polyC_inj). Qed.
Lemma map_polyC_eq0 p : (p^:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_polyC. Qed.
Lemma root_polyC p x : root p^:P x%:P = root p x.
Proof. by rewrite rootE horner_map polyC_eq0. Qed.
Lemma comp_polyE p q : p \Po q = \sum_(i < size p) p`_i *: q^+i.
Proof.
by rewrite [p \Po q]horner_poly; apply: eq_bigr => i _; rewrite mul_polyC.
Qed.
Lemma coef_comp_poly p q n :
(p \Po q)`_n = \sum_(i < size p) p`_i * (q ^+ i)`_n.
Proof. by rewrite comp_polyE coef_sum; apply: eq_bigr => i; rewrite coefZ. Qed.
Lemma polyOver_comp (ringS : semiringClosed R) :
{in polyOver ringS &, forall p q, p \Po q \in polyOver ringS}.
Proof.
move=> p q /polyOverP Sp Sq; rewrite comp_polyE rpred_sum // => i _.
by rewrite polyOverZ ?rpredX.
Qed.
Lemma comp_polyCr p c : p \Po c%:P = p.[c]%:P.
Proof. exact: horner_map. Qed.
Lemma comp_poly0r p : p \Po 0 = (p`_0)%:P.
Proof. by rewrite comp_polyCr horner_coef0. Qed.
Lemma comp_polyC c p : c%:P \Po p = c%:P.
Proof. by rewrite /(_ \Po p) map_polyC hornerC. Qed.
Fact comp_poly_is_linear p : linear (comp_poly p).
Proof.
move=> a q r.
by rewrite /comp_poly rmorphD /= map_polyZ !hornerE_comm mul_polyC.
Qed.
HB.instance Definition _ p :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (comp_poly p)
(GRing.semilinear_linear (comp_poly_is_linear p)).
Lemma comp_poly0 p : 0 \Po p = 0.
Proof. exact: raddf0. Qed.
Lemma comp_polyD p q r : (p + q) \Po r = (p \Po r) + (q \Po r).
Proof. exact: raddfD. Qed.
Lemma comp_polyB p q r : (p - q) \Po r = (p \Po r) - (q \Po r).
Proof. exact: raddfB. Qed.
Lemma comp_polyZ c p q : (c *: p) \Po q = c *: (p \Po q).
Proof. exact: linearZZ. Qed.
Lemma comp_polyXr p : p \Po 'X = p.
Proof. by rewrite -{2}/(idfun p) poly_initial. Qed.
Lemma comp_polyX p : 'X \Po p = p.
Proof. by rewrite /(_ \Po p) map_polyX hornerX. Qed.
Lemma comp_poly_MXaddC c p q : (p * 'X + c%:P) \Po q = (p \Po q) * q + c%:P.
Proof.
by rewrite /(_ \Po q) rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC.
Qed.
Lemma comp_polyXaddC_K p z : (p \Po ('X + z%:P)) \Po ('X - z%:P) = p.
Proof.
have addzK: ('X + z%:P) \Po ('X - z%:P) = 'X.
by rewrite raddfD /= comp_polyC comp_polyX subrK.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_poly0.
rewrite comp_poly_MXaddC linearD /= comp_polyC {1}/comp_poly rmorphM /=.
by rewrite hornerM_comm /comm_poly -!/(_ \Po _) ?IHp ?addzK ?commr_polyX.
Qed.
Lemma size_comp_poly_leq p q :
size (p \Po q) <= ((size p).-1 * (size q).-1).+1.
Proof.
rewrite comp_polyE (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _))//.
rewrite (leq_trans (size_poly_exp_leq _ _))//.
by rewrite ltnS mulnC leq_mul // -{2}(subnKC (valP i)) leq_addr.
Qed.
Lemma comp_Xn_poly p n : 'X^n \Po p = p ^+ n.
Proof. by rewrite /(_ \Po p) map_polyXn hornerXn. Qed.
Lemma coef_comp_poly_Xn p n i : 0 < n ->
(p \Po 'X^n)`_i = if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; rewrite comp_polyE; under eq_bigr do rewrite -exprM mulnC.
rewrite coef_sumMXn/=; case: dvdnP => [[j ->]|nD]; last first.
by rewrite big1// => j /eqP ?; case: nD; exists j.
under eq_bigl do rewrite eqn_mul2r gtn_eqF//.
by rewrite big_ord1_eq if_nth ?leqVgt ?mulnK.
Qed.
Lemma comp_poly_Xn p n : 0 < n ->
p \Po 'X^n = \poly_(i < size p * n) if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; apply/polyP => i; rewrite coef_comp_poly_Xn // coef_poly.
case: dvdnP => [[k ->]|]; last by rewrite if_same.
by rewrite mulnK // ltn_mul2r n_gt0 if_nth ?leqVgt.
Qed.
End PolyCompose.
Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma map_comp_poly (aR rR : nzRingType) (f : {rmorphism aR -> rR}) p q :
map_poly f (p \Po q) = map_poly f p \Po map_poly f q.
Proof.
elim/poly_ind: p => [|p a IHp]; first by rewrite !raddf0.
rewrite comp_poly_MXaddC !rmorphD !rmorphM /= !map_polyC map_polyX.
by rewrite comp_poly_MXaddC -IHp.
Qed.
Section Surgery.
Variable R : nzRingType.
Implicit Type p q : {poly R}.
(* Even part of a polynomial *)
Definition even_poly p : {poly R} := \poly_(i < uphalf (size p)) p`_i.*2.
Lemma size_even_poly p : size (even_poly p) <= uphalf (size p).
Proof. exact: size_poly. Qed.
Lemma coef_even_poly p i : (even_poly p)`_i = p`_i.*2.
Proof. by rewrite coef_poly gtn_uphalf_double if_nth ?leqVgt. Qed.
Lemma even_polyE s p : size p <= s.*2 -> even_poly p = \poly_(i < s) p`_i.*2.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_even_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?leq_double.
Qed.
Lemma size_even_poly_eq p : odd (size p) ->
size (even_poly p) = uphalf (size p).
Proof.
move=> p_even; rewrite size_poly_eq// double_pred odd_uphalfK//=.
by rewrite lead_coef_eq0 -size_poly_eq0; case: size p_even.
Qed.
Lemma even_polyD p q : even_poly (p + q) = even_poly p + even_poly q.
Proof. by apply/polyP => i; rewrite !(coef_even_poly, coefD). Qed.
Lemma even_polyZ k p : even_poly (k *: p) = k *: even_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_even_poly). Qed.
Fact even_poly_is_linear : linear even_poly.
Proof. by move=> k p q; rewrite even_polyD even_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ even_poly
(GRing.semilinear_linear even_poly_is_linear).
Lemma even_polyC (c : R) : even_poly c%:P = c%:P.
Proof. by apply/polyP => i; rewrite coef_even_poly !coefC; case: i. Qed.
(* Odd part of a polynomial *)
Definition odd_poly p : {poly R} := \poly_(i < (size p)./2) p`_i.*2.+1.
Lemma size_odd_poly p : size (odd_poly p) <= (size p)./2.
Proof. exact: size_poly. Qed.
Lemma coef_odd_poly p i : (odd_poly p)`_i = p`_i.*2.+1.
Proof. by rewrite coef_poly gtn_half_double if_nth ?leqVgt. Qed.
Lemma odd_polyE s p :
size p <= s.*2.+1 -> odd_poly p = \poly_(i < s) p`_i.*2.+1.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_odd_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?ltnS ?leq_double.
Qed.
Lemma odd_polyC (c : R) : odd_poly c%:P = 0.
Proof. by apply/polyP => i; rewrite coef_odd_poly !coefC; case: i. Qed.
Lemma odd_polyD p q : odd_poly (p + q) = odd_poly p + odd_poly q.
Proof. by apply/polyP => i; rewrite !(coef_odd_poly, coefD). Qed.
Lemma odd_polyZ k p : odd_poly (k *: p) = k *: odd_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_odd_poly). Qed.
Fact odd_poly_is_linear : linear odd_poly.
Proof. by move=> k p q; rewrite odd_polyD odd_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ odd_poly
(GRing.semilinear_linear odd_poly_is_linear).
Lemma size_odd_poly_eq p : ~~ odd (size p) -> size (odd_poly p) = (size p)./2.
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite odd_polyC size_poly0.
move=> p_odd; rewrite size_poly_eq// -subn1 doubleB subn2 even_halfK//.
rewrite prednK ?lead_coef_eq0// ltn_predRL.
by move: p_neq0 p_odd; rewrite -size_poly_eq0; case: (size p) => [|[]].
Qed.
Lemma odd_polyMX p : odd_poly (p * 'X) = even_poly p.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC.
by apply/polyP => i; rewrite !coef_poly size_mulX // coefMX.
Qed.
Lemma even_polyMX p : even_poly (p * 'X) = odd_poly p * 'X.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC mul0r.
by apply/polyP => -[|i]; rewrite !(coefMX, coef_poly, if_same, size_mulX).
Qed.
Lemma sum_even_poly p :
\sum_(i < size p | ~~ odd i) p`_i *: 'X^i = even_poly p \Po 'X^2.
Proof.
apply/polyP => i; rewrite coef_comp_poly_Xn// coef_sumMXn coef_even_poly.
rewrite (big_ord1_cond_eq _ _ (negb \o _))/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
Lemma sum_odd_poly p :
\sum_(i < size p | odd i) p`_i *: 'X^i = (odd_poly p \Po 'X^2) * 'X.
Proof.
apply/polyP => i; rewrite coefMX coef_comp_poly_Xn// coef_sumMXn coef_odd_poly/=.
case: i => [|i]//=; first by rewrite big_andbC big1// => -[[|j]//].
rewrite big_ord1_cond_eq/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
(* Decomposition in odd and even part *)
Lemma poly_even_odd p : even_poly p \Po 'X^2 + (odd_poly p \Po 'X^2) * 'X = p.
Proof.
rewrite -sum_even_poly -sum_odd_poly addrC -(bigID _ xpredT).
by rewrite -[RHS]coefK poly_def.
Qed.
(* take and drop for polynomials *)
Definition take_poly m p := \poly_(i < m) p`_i.
Lemma size_take_poly m p : size (take_poly m p) <= m.
Proof. exact: size_poly. Qed.
Lemma coef_take_poly m p i : (take_poly m p)`_i = if i < m then p`_i else 0.
Proof. exact: coef_poly. Qed.
Lemma take_poly_id m p : size p <= m -> take_poly m p = p.
Proof.
move=> /leq_trans gep; apply/polyP => i; rewrite coef_poly if_nth//=.
by case: ltnP => // /gep->.
Qed.
Lemma take_polyD m p q : take_poly m (p + q) = take_poly m p + take_poly m q.
Proof.
by apply/polyP => i; rewrite !(coefD, coef_poly); case: leqP; rewrite ?add0r.
Qed.
Lemma take_polyZ k m p : take_poly m (k *: p) = k *: take_poly m p.
Proof.
apply/polyP => i; rewrite !(coefZ, coef_take_poly); case: leqP => //.
by rewrite mulr0.
Qed.
Fact take_poly_is_linear m : linear (take_poly m).
Proof. by move=> k p q; rewrite take_polyD take_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (take_poly m)
(GRing.semilinear_linear (take_poly_is_linear m)).
Lemma take_poly_sum m I r P (p : I -> {poly R}) :
take_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r| P i) take_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma take_poly0l p : take_poly 0 p = 0.
Proof. exact/size_poly_leq0P/size_take_poly. Qed.
Lemma take_poly0r m : take_poly m 0 = 0.
Proof. exact: linear0. Qed.
Lemma take_polyMXn m n p :
take_poly m (p * 'X^n) = take_poly (m - n) p * 'X^n.
Proof.
have [->|/eqP p_neq0] := p =P 0; first by rewrite !(mul0r, take_poly0r).
apply/polyP => i; rewrite !(coef_take_poly, coefMXn).
by have [iLn|nLi] := leqP n i; rewrite ?if_same// ltn_sub2rE.
Qed.
Lemma take_polyMXn_0 n p : take_poly n (p * 'X^n) = 0.
Proof. by rewrite take_polyMXn subnn take_poly0l mul0r. Qed.
Lemma take_polyDMXn n p q : size p <= n -> take_poly n (p + q * 'X^n) = p.
Proof. by move=> ?; rewrite take_polyD take_poly_id// take_polyMXn_0 addr0. Qed.
Definition drop_poly m p := \poly_(i < size p - m) p`_(i + m).
Lemma coef_drop_poly m p i : (drop_poly m p)`_i = p`_(i + m).
Proof. by rewrite coef_poly ltn_subRL addnC if_nth ?leqVgt. Qed.
Lemma drop_poly_eq0 m p : size p <= m -> drop_poly m p = 0.
Proof.
move=> sLm; apply/polyP => i; rewrite coef_poly coef0 ltn_subRL addnC.
by rewrite if_nth ?leqVgt// nth_default// (leq_trans _ (leq_addl _ _)).
Qed.
Lemma size_drop_poly n p : size (drop_poly n p) = (size p - n)%N.
Proof.
have [pLn|nLp] := leqP (size p) n.
by rewrite (eqP pLn) drop_poly_eq0 ?size_poly0.
have p_neq0 : p != 0 by rewrite -size_poly_gt0 (leq_trans _ nLp).
by rewrite size_poly_eq// predn_sub subnK ?lead_coef_eq0// -ltnS -polySpred.
Qed.
Lemma sum_drop_poly n p :
\sum_(n <= i < size p) p`_i *: 'X^i = drop_poly n p * 'X^n.
Proof.
rewrite (big_addn 0) big_mkord /drop_poly poly_def mulr_suml.
by apply: eq_bigr => i _; rewrite exprD scalerAl.
Qed.
Lemma drop_polyD m p q : drop_poly m (p + q) = drop_poly m p + drop_poly m q.
Proof. by apply/polyP => i; rewrite coefD !coef_drop_poly coefD. Qed.
Lemma drop_polyZ k m p : drop_poly m (k *: p) = k *: drop_poly m p.
Proof. by apply/polyP => i; rewrite coefZ !coef_drop_poly coefZ. Qed.
Fact drop_poly_is_linear m : linear (drop_poly m).
Proof. by move=> k p q; rewrite drop_polyD drop_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (drop_poly m)
(GRing.semilinear_linear (drop_poly_is_linear m)).
Lemma drop_poly_sum m I r P (p : I -> {poly R}) :
drop_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r | P i) drop_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma drop_poly0l p : drop_poly 0 p = p.
Proof. by apply/polyP => i; rewrite coef_poly subn0 addn0 if_nth ?leqVgt. Qed.
Lemma drop_poly0r m : drop_poly m 0 = 0. Proof. exact: linear0. Qed.
Lemma drop_polyMXn m n p :
drop_poly m (p * 'X^n) = drop_poly (m - n) p * 'X^(n - m).
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite mul0r !drop_poly0r mul0r.
apply/polyP => i; rewrite !(coefMXn, coef_drop_poly) ltn_subRL [(m + i)%N]addnC.
have [i_small|i_big]// := ltnP; congr nth.
by have [mn|/ltnW mn] := leqP m n;
rewrite (eqP mn) (addn0, subn0) (subnBA, addnBA).
Qed.
Lemma drop_polyMXn_id n p : drop_poly n (p * 'X^ n) = p.
Proof. by rewrite drop_polyMXn subnn drop_poly0l expr0 mulr1. Qed.
Lemma drop_polyDMXn n p q : size p <= n -> drop_poly n (p + q * 'X^n) = q.
Proof. by move=> ?; rewrite drop_polyD drop_poly_eq0// drop_polyMXn_id add0r. Qed.
Lemma poly_take_drop n p : take_poly n p + drop_poly n p * 'X^n = p.
Proof.
apply/polyP => i; rewrite coefD coefMXn coef_take_poly coef_drop_poly.
by case: ltnP => ni; rewrite ?addr0 ?add0r//= subnK.
Qed.
Lemma eqp_take_drop n p q :
take_poly n p = take_poly n q -> drop_poly n p = drop_poly n q -> p = q.
Proof.
by move=> tpq dpq; rewrite -[p](poly_take_drop n) -[q](poly_take_drop n) tpq dpq.
Qed.
End Surgery.
Definition coefE :=
(coef0, coef1, coefC, coefX, coefXn, coef_sumMXn,
coefZ, coefMC, coefCM, coefXnM, coefMXn, coefXM, coefMX, coefMNn, coefMn,
coefN, coefB, coefD, coef_even_poly, coef_odd_poly,
coef_take_poly, coef_drop_poly, coef_cons, coef_Poly, coef_poly,
coef_deriv, coef_nderivn, coef_derivn, coef_map, coef_sum,
coef_comp_poly_Xn, coef_comp_poly).
Section PolynomialComNzRing.
Variable R : comNzRingType.
Implicit Types p q : {poly R}.
Fact poly_mul_comm p q : p * q = q * p.
Proof.
apply/polyP=> i; rewrite coefM coefMr.
by apply: eq_bigr => j _; rewrite mulrC.
Qed.
HB.instance Definition _ := GRing.PzRing_hasCommutativeMul.Build (polynomial R)
poly_mul_comm.
HB.instance Definition _ := GRing.Lalgebra_isComAlgebra.Build R (polynomial R).
Lemma coef_prod_XsubC (ps : seq R) (n : nat) :
(n <= size ps)%N ->
(\prod_(p <- ps) ('X - p%:P))`_n =
(-1) ^+ (size ps - n)%N *
\sum_(I in {set 'I_(size ps)} | #|I| == (size ps - n)%N)
\prod_(i in I) ps`_i.
Proof.
move=> nle.
under eq_bigr => i _ do rewrite addrC -raddfN/=.
rewrite -{1}(in_tupleE ps) -(map_tnth_enum (_ ps)) big_map.
rewrite enumT bigA_distr /= coef_sum.
transitivity (\sum_(I in {set 'I_(size ps)}) if #|I| == (size ps - n)%N then
\prod_(i < size ps | i \in I) - ps`_i else 0).
apply eq_bigr => I _.
rewrite big_if/= big_const iter_mulr_1 -rmorph_prod/= coefCM coefXn.
under eq_bigr => i _ do rewrite (tnth_nth 0)/=.
rewrite -[#|I| == _](eqn_add2r n) subnK//.
rewrite -[X in (_ + _)%N == X]card_ord -(cardC I) eqn_add2l.
by case: ifP; rewrite ?mulr1 ?mulr0.
by rewrite -big_mkcond mulr_sumr/=; apply: eq_bigr => I /eqP <-; rewrite prodrN.
Qed.
Lemma coefPn_prod_XsubC (ps : seq R) : size ps != 0 ->
(\prod_(p <- ps) ('X - p%:P))`_(size ps).-1 =
- \sum_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC ?leq_pred// => ps0.
have -> : (size ps - (size ps).-1 = 1)%N.
by move: ps0; case: (size ps) => // n _; exact: subSnn.
rewrite expr1 mulN1r; congr GRing.opp.
set f : 'I_(size ps) -> {set 'I_(size ps)} := fun a => [set a].
transitivity (\sum_(I in imset f (mem setT)) \prod_(i in I) ps`_i).
apply: congr_big => // I /=.
by apply/cards1P/imsetP => [[a ->] | [a _ ->]]; exists a.
rewrite big_imset/=; last first.
by move=> i j _ _ ij; apply/set1P; rewrite -/(f j) -ij set11.
rewrite -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite big_set1 (tnth_nth 0).
Qed.
Lemma coef0_prod_XsubC (ps : seq R) :
(\prod_(p <- ps) ('X - p%:P))`_0 =
(-1) ^+ (size ps) * \prod_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC// subn0; congr GRing.mul.
transitivity (\sum_(I in [set setT : {set 'I_(size ps)}]) \prod_(i in I) ps`_i).
apply: congr_big =>// i/=.
apply/idP/set1P => [/eqP cardE | ->]; last by rewrite cardsT card_ord.
by apply/eqP; rewrite eqEcard subsetT cardsT card_ord cardE leqnn.
rewrite big_set1 -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite (tnth_nth 0).
Qed.
Lemma hornerM p q x : (p * q).[x] = p.[x] * q.[x].
Proof. by rewrite hornerM_comm //; apply: mulrC. Qed.
Lemma horner_exp p x n : (p ^+ n).[x] = p.[x] ^+ n.
Proof. by rewrite horner_exp_comm //; apply: mulrC. Qed.
Lemma horner_prod I r (P : pred I) (F : I -> {poly R}) x :
(\prod_(i <- r | P i) F i).[x] = \prod_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (hornerM, hornerC). Qed.
Definition hornerE :=
(hornerD, hornerN, hornerX, hornerC, horner_exp,
simp, hornerCM, hornerZ, hornerM, horner_cons).
Definition horner_eval (x : R) := horner^~ x.
Lemma horner_evalE x p : horner_eval x p = p.[x]. Proof. by []. Qed.
Fact horner_eval_is_linear x : linear_for *%R (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by move=> c p q; rewrite !evalE linearP.
Qed.
Fact horner_eval_is_monoid_morphism x : monoid_morphism (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by split=> [|p q]; rewrite !evalE ?rmorph1// rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_eval_is_monoid_morphism` instead")]
Definition horner_eval_is_multiplicative x :=
(fun g => (g.2, g.1)) (horner_eval_is_monoid_morphism x).
HB.instance Definition _ x :=
GRing.isSemilinear.Build R {poly R} R _ (horner_eval x)
(GRing.semilinear_linear (horner_eval_is_linear x)).
HB.instance Definition _ x :=
GRing.isMonoidMorphism.Build {poly R} R (horner_eval x)
(horner_eval_is_monoid_morphism x).
Section HornerAlg.
Variable A : algType R. (* For univariate polys, commutativity is not needed *)
Section Defs.
Variable a : A.
Lemma in_alg_comm : commr_rmorph (in_alg A) a.
Proof. move=> r /=; by rewrite /GRing.comm comm_alg. Qed.
Definition horner_alg := horner_morph in_alg_comm.
Lemma horner_algC c : horner_alg c%:P = c%:A.
Proof. exact: horner_morphC. Qed.
Lemma horner_algX : horner_alg 'X = a.
Proof. exact: horner_morphX. Qed.
HB.instance Definition _ := GRing.LRMorphism.on horner_alg.
End Defs.
Variable (pf : {lrmorphism {poly R} -> A}).
Lemma poly_alg_initial : pf =1 horner_alg (pf 'X).
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
rewrite !rmorphD !rmorphM /= -{}IHp horner_algC ?horner_algX.
by rewrite -alg_polyC rmorph_alg.
Qed.
End HornerAlg.
Fact comp_poly_is_monoid_morphism q : monoid_morphism (comp_poly q).
Proof.
split=> [|p1 p2]; first by rewrite comp_polyC.
by rewrite /comp_poly rmorphM hornerM_comm //; apply: mulrC.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `comp_poly_is_monoid_morphism` instead")]
Definition comp_poly_multiplicative q :=
(fun g => (g.2, g.1)) (comp_poly_is_monoid_morphism q).
HB.instance Definition _ q := GRing.isMonoidMorphism.Build _ _ (comp_poly q)
(comp_poly_is_monoid_morphism q).
Lemma comp_polyM p q r : (p * q) \Po r = (p \Po r) * (q \Po r).
Proof. exact: rmorphM. Qed.
Lemma comp_polyA p q r : p \Po (q \Po r) = (p \Po q) \Po r.
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_polyC.
by rewrite !comp_polyD !comp_polyM !comp_polyX IHp !comp_polyC.
Qed.
Lemma horner_comp p q x : (p \Po q).[x] = p.[q.[x]].
Proof. by apply: polyC_inj; rewrite -!comp_polyCr comp_polyA. Qed.
Lemma root_comp p q x : root (p \Po q) x = root p (q.[x]).
Proof. by rewrite !rootE horner_comp. Qed.
Lemma deriv_comp p q : (p \Po q) ^`() = (p ^`() \Po q) * q^`().
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(deriv0, comp_poly0) mul0r.
rewrite comp_poly_MXaddC derivD derivC derivM IHp derivMXaddC comp_polyD.
by rewrite comp_polyM comp_polyX addr0 addrC mulrAC -mulrDl.
Qed.
Lemma deriv_exp p n : (p ^+ n)^`() = p^`() * p ^+ n.-1 *+ n.
Proof.
elim: n => [|n IHn]; first by rewrite expr0 mulr0n derivC.
by rewrite exprS derivM {}IHn (mulrC p) mulrnAl -mulrA -exprSr mulrS; case n.
Qed.
Definition derivCE := (derivE, deriv_exp).
End PolynomialComNzRing.
Section PolynomialIdomain.
(* Integral domain structure on poly *)
Variable R : idomainType.
Implicit Types (a b x y : R) (p q r m : {poly R}).
Lemma size_mul p q : p != 0 -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
by move=> nz_p nz_q; rewrite -size_proper_mul ?mulf_neq0 ?lead_coef_eq0.
Qed.
Fact poly_idomainAxiom p q : p * q = 0 -> (p == 0) || (q == 0).
Proof.
move=> pq0; apply/norP=> [[p_nz q_nz]]; move/eqP: (size_mul p_nz q_nz).
by rewrite eq_sym pq0 size_poly0 (polySpred p_nz) (polySpred q_nz) addnS.
Qed.
Definition poly_unit : pred {poly R} :=
fun p => (size p == 1) && (p`_0 \in GRing.unit).
Definition poly_inv p := if p \in poly_unit then (p`_0)^-1%:P else p.
Fact poly_mulVp : {in poly_unit, left_inverse 1 poly_inv *%R}.
Proof.
move=> p Up; rewrite /poly_inv Up.
by case/andP: Up => /size_poly1P[c _ ->]; rewrite coefC -polyCM => /mulVr->.
Qed.
Fact poly_intro_unit p q : q * p = 1 -> p \in poly_unit.
Proof.
move=> pq1; apply/andP; split; last first.
apply/unitrP; exists q`_0.
by rewrite 2!mulrC -!/(coefp 0 _) -rmorphM pq1 rmorph1.
have: size (q * p) == 1 by rewrite pq1 size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r size_poly0.
rewrite size_mul // (polySpred nz_p) (polySpred nz_q) addnS addSn !eqSS.
by rewrite addn_eq0 => /andP[].
Qed.
Fact poly_inv_out : {in [predC poly_unit], poly_inv =1 id}.
Proof. by rewrite /poly_inv => p /negbTE/= ->. Qed.
HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build (polynomial R)
poly_mulVp poly_intro_unit poly_inv_out.
HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build (polynomial R)
poly_idomainAxiom.
Lemma poly_unitE p :
(p \in GRing.unit) = (size p == 1) && (p`_0 \in GRing.unit).
Proof. by []. Qed.
Lemma poly_invE p : p ^-1 = if p \in GRing.unit then (p`_0)^-1%:P else p.
Proof. by []. Qed.
Lemma polyCV c : c%:P^-1 = (c^-1)%:P.
Proof.
have [/rmorphV-> // | nUc] := boolP (c \in GRing.unit).
by rewrite !invr_out // poly_unitE coefC (negbTE nUc) andbF.
Qed.
Lemma rootM p q x : root (p * q) x = root p x || root q x.
Proof. by rewrite !rootE hornerM mulf_eq0. Qed.
Lemma rootZ x a p : a != 0 -> root (a *: p) x = root p x.
Proof. by move=> nz_a; rewrite -mul_polyC rootM rootC (negPf nz_a). Qed.
Lemma root_exp p n a: comm_poly p a -> (0 < n)%N -> root (p ^+ n) a = root p a.
Proof. by move=> ? n0; rewrite !rootE horner_exp_comm// expf_eq0 n0. Qed.
Lemma size_scale a p : a != 0 -> size (a *: p) = size p.
Proof. by move/lregP/lreg_size->. Qed.
Lemma size_Cmul a p : a != 0 -> size (a%:P * p) = size p.
Proof. by rewrite mul_polyC => /size_scale->. Qed.
Lemma lead_coefM p q : lead_coef (p * q) = lead_coef p * lead_coef q.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, lead_coef0).
have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, lead_coef0).
by rewrite lead_coef_proper_mul // mulf_neq0 ?lead_coef_eq0.
Qed.
Lemma lead_coef_prod I rI (P : {pred I}) (p : I -> {poly R}) :
lead_coef (\prod_(i <- rI | P i) p i) = \prod_(i <- rI | P i) lead_coef (p i).
Proof. by apply/big_morph/lead_coef1; apply: lead_coefM. Qed.
Lemma lead_coefZ a p : lead_coef (a *: p) = a * lead_coef p.
Proof. by rewrite -mul_polyC lead_coefM lead_coefC. Qed.
Lemma scale_poly_eq0 a p : (a *: p == 0) = (a == 0) || (p == 0).
Proof. by rewrite -mul_polyC mulf_eq0 polyC_eq0. Qed.
Lemma size_prod (I : finType) (P : pred I) (F : I -> {poly R}) :
(forall i, P i -> F i != 0) ->
size (\prod_(i | P i) F i) = ((\sum_(i | P i) size (F i)).+1 - #|P|)%N.
Proof.
move=> nzF; transitivity (\sum_(i | P i) (size (F i)).-1).+1; last first.
apply: canRL (addKn _) _; rewrite addnS -sum1_card -big_split /=.
by congr _.+1; apply: eq_bigr => i /nzF/polySpred.
elim/big_rec2: _ => [|i d p /nzF nzFi IHp]; first by rewrite size_poly1.
by rewrite size_mul // -?size_poly_eq0 IHp // addnS polySpred.
Qed.
Lemma size_prod_seq (I : eqType) (s : seq I) (F : I -> {poly R}) :
(forall i, i \in s -> F i != 0) ->
size (\prod_(i <- s) F i) = ((\sum_(i <- s) size (F i)).+1 - size s)%N.
Proof.
move=> nzF; rewrite big_tnth size_prod; last by move=> i; rewrite nzF ?mem_tnth.
by rewrite cardT /= size_enum_ord [in RHS]big_tnth.
Qed.
Lemma size_mul_eq1 p q : (size (p * q) == 1) = ((size p == 1) && (size q == 1)).
Proof.
have [->|pNZ] := eqVneq p 0; first by rewrite mul0r size_poly0.
have [->|qNZ] := eqVneq q 0; first by rewrite mulr0 size_poly0 andbF.
rewrite size_mul //.
by move: pNZ qNZ; rewrite -!size_poly_gt0; (do 2 case: size) => //= n [|[|]].
Qed.
Lemma size_prod_seq_eq1 (I : eqType) (s : seq I) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i && (i \in s) -> size (F i) = 1)
(size (\prod_(i <- s | P i) F i) == 1%N).
Proof.
rewrite (big_morph _ (id1:=true) size_mul_eq1) ?size_polyC ?oner_neq0//.
rewrite big_all_cond; apply/(iffP allP).
by move=> h i /andP[Pi ins]; apply/eqP/(implyP (h i ins) Pi).
by move=> h i ins; apply/implyP => Pi; rewrite h ?Pi.
Qed.
Lemma size_prod_eq1 (I : finType) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i -> size (F i) = 1)
(size (\prod_(i | P i) F i) == 1).
Proof.
apply: (iffP (size_prod_seq_eq1 _ _ _)) => Hi i.
by move=> Pi; apply: Hi; rewrite Pi /= mem_index_enum.
by rewrite mem_index_enum andbT; apply: Hi.
Qed.
Lemma size_exp p n : (size (p ^+ n)).-1 = ((size p).-1 * n)%N.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1 muln0.
have [-> | nz_p] := eqVneq p 0; first by rewrite exprS mul0r size_poly0.
rewrite exprS size_mul ?expf_neq0 // mulnS -{}IHn.
by rewrite polySpred // [size (p ^+ n)]polySpred ?expf_neq0 ?addnS.
Qed.
Lemma lead_coef_exp p n : lead_coef (p ^+ n) = lead_coef p ^+ n.
Proof.
elim: n => [|n IHn]; first by rewrite !expr0 lead_coef1.
by rewrite !exprS lead_coefM IHn.
Qed.
Lemma root_prod_XsubC rs x :
root (\prod_(a <- rs) ('X - a%:P)) x = (x \in rs).
Proof.
elim: rs => [|a rs IHrs]; first by rewrite rootE big_nil hornerC oner_eq0.
by rewrite big_cons rootM IHrs root_XsubC.
Qed.
Lemma root_exp_XsubC n a x : root (('X - a%:P) ^+ n.+1) x = (x == a).
Proof. by rewrite rootE horner_exp expf_eq0 [_ == 0]root_XsubC. Qed.
Lemma size_comp_poly p q :
(size (p \Po q)).-1 = ((size p).-1 * (size q).-1)%N.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite comp_poly0 size_poly0.
have [/size1_polyC-> | nc_q] := leqP (size q) 1.
by rewrite comp_polyCr !size_polyC -!sub1b -!subnS muln0.
have nz_q: q != 0 by rewrite -size_poly_eq0 -(subnKC nc_q).
rewrite mulnC comp_polyE (polySpred nz_p) /= big_ord_recr /= addrC.
rewrite size_polyDl size_scale ?lead_coef_eq0 ?size_exp //=.
rewrite [ltnRHS]polySpred ?expf_neq0 // ltnS size_exp.
rewrite (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _)) // polySpred ?expf_neq0 //.
by rewrite size_exp -(subnKC nc_q) ltn_pmul2l.
Qed.
Lemma lead_coef_comp p q : size q > 1 ->
lead_coef (p \Po q) = (lead_coef p) * lead_coef q ^+ (size p).-1.
Proof.
move=> q_gt1; rewrite !lead_coefE coef_comp_poly size_comp_poly.
have [->|nz_p] := eqVneq p 0; first by rewrite size_poly0 big_ord0 coef0 mul0r.
rewrite polySpred //= big_ord_recr /= big1 ?add0r => [|i _].
by rewrite -!lead_coefE -lead_coef_exp !lead_coefE size_exp mulnC.
rewrite [X in _ * X]nth_default ?mulr0 ?(leq_trans (size_poly_exp_leq _ _)) //.
by rewrite mulnC ltn_mul2r -subn1 subn_gt0 q_gt1 /=.
Qed.
Lemma comp_poly_eq0 p q : size q > 1 -> (p \Po q == 0) = (p == 0).
Proof.
move=> sq_gt1; rewrite -!lead_coef_eq0 lead_coef_comp //.
rewrite mulf_eq0 expf_eq0 !lead_coef_eq0 -[q == 0]size_poly_leq0.
by rewrite [_ <= 0]leqNgt (leq_ltn_trans _ sq_gt1) ?andbF ?orbF.
Qed.
Lemma size_comp_poly2 p q : size q = 2 -> size (p \Po q) = size p.
Proof.
move=> sq2; have [->|pN0] := eqVneq p 0; first by rewrite comp_polyC.
by rewrite polySpred ?size_comp_poly ?comp_poly_eq0 ?sq2 // muln1 polySpred.
Qed.
Lemma comp_poly2_eq0 p q : size q = 2 -> (p \Po q == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_comp_poly2->. Qed.
Theorem max_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq rs -> size rs < size p.
Proof.
elim: rs p => [p pn0 _ _ | r rs ihrs p pn0] /=; first by rewrite size_poly_gt0.
case/andP => rpr arrs /andP [rnrs urs]; case/factor_theorem: rpr => q epq.
have [q0 | ?] := eqVneq q 0; first by move: pn0; rewrite epq q0 mul0r eqxx.
have -> : size p = (size q).+1.
by rewrite epq size_Mmonic ?monicXsubC // size_XsubC addnC.
suff /eq_in_all h : {in rs, root q =1 root p} by apply: ihrs => //; rewrite h.
move=> x xrs; rewrite epq rootM root_XsubC orbC; case: (eqVneq x r) => // exr.
by move: rnrs; rewrite -exr xrs.
Qed.
Lemma roots_geq_poly_eq0 p (rs : seq R) : all (root p) rs -> uniq rs ->
(size rs >= size p)%N -> p = 0.
Proof. by move=> ??; apply: contraTeq => ?; rewrite leqNgt max_poly_roots. Qed.
End PolynomialIdomain.
(* FIXME: these are seamingly artificial ways to close the inheritance graph *)
(* We make parameters more and more precise to trigger completion by HB *)
HB.instance Definition _ (R : countNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countComNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countIdomainType) :=
[Countable of polynomial R by <:].
Section MapFieldPoly.
Variables (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R}).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma size_map_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite rmorph0 !size_poly0.
by rewrite size_poly_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma lead_coef_map p : lead_coef p^f = f (lead_coef p).
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(rmorph0, lead_coef0).
by rewrite lead_coef_map_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma map_poly_eq0 p : (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_poly. Qed.
Lemma map_poly_inj : injective (map_poly f).
Proof.
move=> p q eqfpq; apply/eqP; rewrite -subr_eq0 -map_poly_eq0.
by rewrite rmorphB /= eqfpq subrr.
Qed.
Lemma map_monic p : (p^f \is monic) = (p \is monic).
Proof. by rewrite [in LHS]monicE lead_coef_map fmorph_eq1. Qed.
Lemma map_poly_com p x : comm_poly p^f (f x).
Proof. exact: map_comm_poly (mulrC x _). Qed.
Lemma fmorph_root p x : root p^f (f x) = root p x.
Proof. by rewrite rootE horner_map // fmorph_eq0. Qed.
Lemma fmorph_unity_root n z : n.-unity_root (f z) = n.-unity_root z.
Proof. by rewrite !unity_rootE -(inj_eq (fmorph_inj f)) rmorphXn ?rmorph1. Qed.
Lemma fmorph_primitive_root n z :
n.-primitive_root (f z) = n.-primitive_root z.
Proof.
by congr (_ && _); apply: eq_forallb => i; rewrite fmorph_unity_root.
Qed.
End MapFieldPoly.
Arguments map_poly_inj {F R} f [p1 p2] : rename.
Section MaxRoots.
Variable R : unitRingType.
Implicit Types (x y : R) (rs : seq R) (p : {poly R}).
Definition diff_roots (x y : R) := (x * y == y * x) && (y - x \in GRing.unit).
Fixpoint uniq_roots rs :=
if rs is x :: rs' then all (diff_roots x) rs' && uniq_roots rs' else true.
Lemma uniq_roots_prod_XsubC p rs :
all (root p) rs -> uniq_roots rs ->
exists q, p = q * \prod_(z <- rs) ('X - z%:P).
Proof.
elim: rs => [|z rs IHrs] /=; first by rewrite big_nil; exists p; rewrite mulr1.
case/andP=> rpz rprs /andP[drs urs]; case: IHrs => {urs rprs}// q def_p.
have [|q' def_q] := factor_theorem q z _; last first.
by exists q'; rewrite big_cons mulrA -def_q.
rewrite {p}def_p in rpz.
elim/last_ind: rs drs rpz => [|rs t IHrs] /=; first by rewrite big_nil mulr1.
rewrite all_rcons => /andP[/andP[/eqP czt Uzt] /IHrs{}IHrs].
rewrite -cats1 big_cat big_seq1 /= mulrA rootE hornerM_comm; last first.
by rewrite /comm_poly hornerXsubC mulrBl mulrBr czt.
rewrite hornerXsubC -opprB mulrN oppr_eq0 -(mul0r (t - z)).
by rewrite (inj_eq (mulIr Uzt)) => /IHrs.
Qed.
Theorem max_ring_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq_roots rs -> size rs < size p.
Proof.
move=> nz_p _ /(@uniq_roots_prod_XsubC p)[// | q def_p]; rewrite def_p in nz_p *.
have nz_q: q != 0 by apply: contraNneq nz_p => ->; rewrite mul0r.
rewrite size_Mmonic ?monic_prod_XsubC // (polySpred nz_q) addSn /=.
by rewrite size_prod_XsubC leq_addl.
Qed.
Lemma all_roots_prod_XsubC p rs :
size p = (size rs).+1 -> all (root p) rs -> uniq_roots rs ->
p = lead_coef p *: \prod_(z <- rs) ('X - z%:P).
Proof.
move=> size_p /uniq_roots_prod_XsubC def_p Urs.
case/def_p: Urs => q -> {p def_p} in size_p *.
have [q0 | nz_q] := eqVneq q 0; first by rewrite q0 mul0r size_poly0 in size_p.
have{q nz_q size_p} /size_poly1P[c _ ->]: size q == 1.
rewrite -(eqn_add2r (size rs)) add1n -size_p.
by rewrite size_Mmonic ?monic_prod_XsubC // size_prod_XsubC addnS.
by rewrite lead_coef_Mmonic ?monic_prod_XsubC // lead_coefC mul_polyC.
Qed.
End MaxRoots.
Section FieldRoots.
Variable F : fieldType.
Implicit Types (p : {poly F}) (rs : seq F).
Lemma poly2_root p : size p = 2 -> {r | root p r}.
Proof.
case: p => [[|p0 [|p1 []]] //= nz_p1]; exists (- p0 / p1).
by rewrite /root addr_eq0 /= mul0r add0r mulrC divfK ?opprK.
Qed.
Lemma uniq_rootsE rs : uniq_roots rs = uniq rs.
Proof.
elim: rs => //= r rs ->; congr (_ && _); rewrite -has_pred1 -all_predC.
by apply: eq_all => t; rewrite /diff_roots mulrC eqxx unitfE subr_eq0.
Qed.
Lemma root_ZXsubC (a b r : F) : a != 0 ->
root (a *: 'X - b%:P) r = (r == b / a).
Proof.
move=> a0; rewrite rootE !hornerE.
by rewrite -[r in RHS]divr1 eqr_div ?oner_neq0// mulr1 mulrC subr_eq0.
Qed.
Section UnityRoots.
Variable n : nat.
Lemma max_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs <= n.
Proof.
move=> n_gt0 rs_n_1 Urs; have szPn := size_XnsubC (1 : F) n_gt0.
by rewrite -ltnS -szPn max_poly_roots -?size_poly_eq0 ?szPn.
Qed.
Lemma mem_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs = n ->
n.-unity_root =i rs.
Proof.
move=> n_gt0 rs_n_1 Urs sz_rs_n x; rewrite -topredE /=.
apply/idP/idP=> xn1; last exact: (allP rs_n_1).
apply: contraFT (ltnn n) => not_rs_x.
by rewrite -{1}sz_rs_n (@max_unity_roots (x :: rs)) //= ?xn1 ?not_rs_x.
Qed.
(* Showing the existence of a primitive root requires the theory in cyclic. *)
Variable z : F.
Hypothesis prim_z : n.-primitive_root z.
Let zn := [seq z ^+ i | i <- index_iota 0 n].
Lemma factor_Xn_sub_1 : \prod_(0 <= i < n) ('X - (z ^+ i)%:P) = 'X^n - 1.
Proof.
transitivity (\prod_(w <- zn) ('X - w%:P)); first by rewrite big_map.
have n_gt0: n > 0 := prim_order_gt0 prim_z.
rewrite (@all_roots_prod_XsubC _ ('X^n - 1) zn); first 1 last.
- by rewrite size_XnsubC // size_map size_iota subn0.
- apply/allP=> _ /mapP[i _ ->] /=; rewrite rootE !hornerE.
by rewrite exprAC (prim_expr_order prim_z) expr1n subrr.
- rewrite uniq_rootsE map_inj_in_uniq ?iota_uniq // => i j.
rewrite !mem_index_iota => ltin ltjn /eqP.
by rewrite (eq_prim_root_expr prim_z) !modn_small // => /eqP.
by rewrite (monicP (monicXnsubC 1 n_gt0)) scale1r.
Qed.
Lemma prim_rootP x : x ^+ n = 1 -> {i : 'I_n | x = z ^+ i}.
Proof.
move=> xn1; pose logx := [pred i : 'I_n | x == z ^+ i].
case: (pickP logx) => [i /eqP-> | no_i]; first by exists i.
case: notF; suffices{no_i}: x \in zn.
case/mapP=> i; rewrite mem_index_iota => lt_i_n def_x.
by rewrite -(no_i (Ordinal lt_i_n)) /= -def_x.
rewrite -root_prod_XsubC big_map factor_Xn_sub_1.
by rewrite [root _ x]unity_rootE xn1.
Qed.
End UnityRoots.
End FieldRoots.
Section MapPolyRoots.
Variables (F : fieldType) (R : unitRingType) (f : {rmorphism F -> R}).
Lemma map_diff_roots x y : diff_roots (f x) (f y) = (x != y).
Proof.
rewrite /diff_roots -rmorphB // fmorph_unit // subr_eq0 //.
by rewrite rmorph_comm // eqxx eq_sym.
Qed.
Lemma map_uniq_roots s : uniq_roots (map f s) = uniq s.
Proof.
elim: s => //= x s ->; congr (_ && _); elim: s => //= y s ->.
by rewrite map_diff_roots -negb_or.
Qed.
End MapPolyRoots.
Section AutPolyRoot.
(* The action of automorphisms on roots of unity. *)
Variable F : fieldType.
Implicit Types u v : {rmorphism F -> F}.
Lemma aut_prim_rootP u z n :
n.-primitive_root z -> {k | coprime k n & u z = z ^+ k}.
Proof.
move=> prim_z; have:= prim_z; rewrite -(fmorph_primitive_root u) => prim_uz.
have [[k _] /= def_uz] := prim_rootP prim_z (prim_expr_order prim_uz).
by exists k; rewrite // -(prim_root_exp_coprime _ prim_z) -def_uz.
Qed.
Lemma aut_unity_rootP u z n : n > 0 -> z ^+ n = 1 -> {k | u z = z ^+ k}.
Proof.
by move=> _ /prim_order_exists[// | m /(aut_prim_rootP u)[k]]; exists k.
Qed.
Lemma aut_unity_rootC u v z n : n > 0 -> z ^+ n = 1 -> u (v z) = v (u z).
Proof.
move=> n_gt0 /(aut_unity_rootP _ n_gt0) def_z.
have [[i def_uz] [j def_vz]] := (def_z u, def_z v).
by rewrite def_vz def_uz !rmorphXn /= def_vz def_uz exprAC.
Qed.
End AutPolyRoot.
Module UnityRootTheory.
Notation "n .-unity_root" := (root_of_unity n) : unity_root_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : unity_root_scope.
Open Scope unity_root_scope.
Definition unity_rootE := unity_rootE.
Definition unity_rootP := @unity_rootP.
Arguments unity_rootP {R n z}.
Definition prim_order_exists := prim_order_exists.
Notation prim_order_gt0 := prim_order_gt0.
Notation prim_expr_order := prim_expr_order.
Definition prim_expr_mod := prim_expr_mod.
Definition prim_order_dvd := prim_order_dvd.
Definition eq_prim_root_expr := eq_prim_root_expr.
Definition rmorph_unity_root := rmorph_unity_root.
Definition fmorph_unity_root := fmorph_unity_root.
Definition fmorph_primitive_root := fmorph_primitive_root.
Definition max_unity_roots := max_unity_roots.
Definition mem_unity_roots := mem_unity_roots.
Definition prim_rootP := prim_rootP.
End UnityRootTheory.
Module Export Pdeg2.
Module Export Field.
Section Pdeg2Field.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed.
Let aneq0 : a != 0.
Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed.
Let a2neq0 : 2 * a != 0. Proof. by rewrite mulf_neq0. Qed.
Let sqa2neq0 : (2 * a) ^+ 2 != 0. Proof. exact: expf_neq0. Qed.
Let aa4 : 4 * a * a = (2 * a)^+2.
Proof. by rewrite expr2 mulrACA mulrA -natrM. Qed.
Let splitr (x : F) : x = x / 2 + x / 2.
Proof.
by apply: (mulIf nz2); rewrite -mulrDl mulfVK// mulr_natr mulr2n.
Qed.
Let pE : p = a *: 'X^2 + b *: 'X + c%:P.
Proof.
apply/polyP => + /[!coefE] => -[|[|[|i]]] /=; rewrite !Monoid.simpm//.
by rewrite nth_default// degp.
Qed.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg2_poly_canonical :
p = a *: (('X + (b / (2 * a))%:P)^+2 - (delta / (4 * a ^+ 2))%:P).
Proof.
rewrite pE sqrrD -!addrA scalerDr; congr +%R; rewrite addrA scalerDr; congr +%R.
- rewrite -mulrDr -polyCD -!mul_polyC mulrA mulrAC -polyCM.
by rewrite [a * _]mulrC mulrDl invfM -!mulrA mulVf// mulr1 -splitr.
- rewrite [a ^+ 2]expr2 mulrA aa4 -polyC_exp -polyCB expr_div_n -mulrBl subKr.
by rewrite scale_polyC mulrCA mulrACA aa4 mulrCA mulfV// mulr1.
Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / (2 * a).
Let r2 := (- b + r) / (2 * a).
Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P).
Proof.
rewrite [p]deg2_poly_canonical//= -/a -/b -/c -/delta /r1 /r2.
rewrite ![(- b + _) * _]mulrDl 2!polyCD 2!opprD 2!addrA !mulNr !polyCN !opprK.
rewrite -scalerAl [in RHS]mulrC -subr_sqr -polyC_exp -[4]/(2 * 2)%:R natrM.
by rewrite -expr2 -exprMn [in RHS]exprMn exprVn r_sqrt_delta.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r2%:P)); rewrite deg2_poly_factor -!scalerAl mulrC.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r1%:P)); rewrite deg2_poly_factor -!scalerAl.
Qed.
End Pdeg2Field.
End Field.
Module FieldMonic.
Section Pdeg2FieldMonic.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Hypothesis monicp : p \is monic.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed.
Let delta := b ^+ 2 - 4 * c.
Lemma deg2_poly_canonical : p = (('X + (b / 2)%:P)^+2 - (delta / 4)%:P).
Proof. by rewrite [p]deg2_poly_canonical// -/a a1 scale1r expr1n !mulr1. Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / 2.
Let r2 := (- b + r) / 2.
Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P).
Proof.
by rewrite [p](@deg2_poly_factor _ _ _ _ r)// -/a a1 !mulr1 ?scale1r.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
rewrite /r1 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root1; rewrite // -/a a1 mulr1.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
rewrite /r2 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root2; rewrite // -/a a1 mulr1.
Qed.
End Pdeg2FieldMonic.
End FieldMonic.
End Pdeg2.
Section DecField.
Variable F : decFieldType.
Lemma dec_factor_theorem (p : {poly F}) :
{s : seq F & {q : {poly F} | p = q * \prod_(x <- s) ('X - x%:P)
/\ (q != 0 -> forall x, ~~ root q x)}}.
Proof.
pose polyT (p : seq F) := (foldr (fun c f => f * 'X_0 + c%:T) (0%R)%:T p)%T.
have eval_polyT (q : {poly F}) x : GRing.eval [:: x] (polyT q) = q.[x].
by rewrite /horner; elim: (val q) => //= ? ? ->.
have [n] := ubnP (size p); elim: n => // n IHn in p *.
have /decPcases /= := @satP F [::] ('exists 'X_0, polyT p == 0%T).
case: ifP => [_ /sig_eqW[x]|_ noroot]; last first.
exists [::], p; rewrite big_nil mulr1; split => // p_neq0 x.
by apply/negP=> /rootP rpx; apply: noroot; exists x; rewrite eval_polyT.
rewrite eval_polyT => /rootP/factor_theorem/sig_eqW[p1 ->].
have [->|nz_p1] := eqVneq p1 0; first by exists [::], 0; rewrite !mul0r eqxx.
rewrite size_Mmonic ?monicXsubC // size_XsubC addn2 => /IHn[s [q [-> irr_q]]].
by exists (rcons s x), q; rewrite -cats1 big_cat big_seq1 mulrA.
Qed.
End DecField.
Module PreClosedField.
Section UseAxiom.
Variable F : fieldType.
Hypothesis closedF : GRing.closed_field_axiom F.
Implicit Type p : {poly F}.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof.
have [-> | nz_p] := eqVneq p 0.
by rewrite size_poly0; left; exists 0; rewrite root0.
rewrite neq_ltn [in _ < 1]polySpred //=.
apply: (iffP idP) => [p_gt1 | [a]]; last exact: root_size_gt1.
pose n := (size p).-1; have n_gt0: n > 0 by rewrite -ltnS -polySpred.
have [a Dan] := closedF (fun i => - p`_i / lead_coef p) n_gt0.
exists a; apply/rootP; rewrite horner_coef polySpred // big_ord_recr /= -/n.
rewrite {}Dan mulr_sumr -big_split big1 //= => i _.
by rewrite -!mulrA mulrCA mulNr mulVKf ?subrr ?lead_coef_eq0.
Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof.
apply: (iffP idP) => [nz_p | [x]]; last first.
by apply: contraNneq => ->; apply: root0.
have [[x /rootP p1x0]|] := altP (closed_rootP (p - 1)).
by exists x; rewrite -[p](subrK 1) /root hornerD p1x0 add0r hornerC oner_eq0.
rewrite negbK => /size_poly1P[c _ /(canRL (subrK 1)) Dp].
by exists 0; rewrite Dp -raddfD polyC_eq0 rootC in nz_p *.
Qed.
End UseAxiom.
End PreClosedField.
Section ClosedField.
Variable F : closedFieldType.
Implicit Type p : {poly F}.
Let closedF := @solve_monicpoly F.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof. exact: PreClosedField.closed_rootP. Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof. exact: PreClosedField.closed_nonrootP. Qed.
Lemma closed_field_poly_normal p :
{r : seq F | p = lead_coef p *: \prod_(z <- r) ('X - z%:P)}.
Proof.
apply: sig_eqW; have [r [q [->]]] /= := dec_factor_theorem p.
have [->|] := eqVneq; first by exists [::]; rewrite mul0r lead_coef0 scale0r.
have [[x rqx ? /(_ isT x) /negP /(_ rqx)] //|] := altP (closed_rootP q).
rewrite negbK => /size_poly1P [c c_neq0-> _ _]; exists r.
rewrite mul_polyC lead_coefZ (monicP _) ?mulr1 //.
by rewrite monic_prod => // i; rewrite monicXsubC.
Qed.
End ClosedField.
|
FunctorCategory.lean
|
/-
Copyright (c) 2022 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Preadditive.FunctorCategory
import Mathlib.CategoryTheory.Linear.Basic
/-!
# Linear structure on functor categories
If `C` and `D` are categories and `D` is `R`-linear,
then `C ⥤ D` is also `R`-linear.
-/
namespace CategoryTheory
open CategoryTheory.Limits Linear
variable {R : Type*} [Semiring R]
variable {C D : Type*} [Category C] [Category D] [Preadditive D] [Linear R D]
instance functorCategoryLinear : Linear R (C ⥤ D) where
homModule F G :=
{ smul := fun r α =>
{ app := fun X => r • α.app X
naturality := by
intros
rw [comp_smul, smul_comp, α.naturality] }
one_smul := by
intros
ext
apply one_smul
zero_smul := by
intros
ext
apply zero_smul
smul_zero := by
intros
ext
apply smul_zero
add_smul := by
intros
ext
apply add_smul
smul_add := by
intros
ext
apply smul_add
mul_smul := by
intros
ext
apply mul_smul }
smul_comp := by
intros
ext
apply smul_comp
comp_smul := by
intros
ext
apply comp_smul
namespace NatTrans
variable {F G : C ⥤ D}
/-- Application of a natural transformation at a fixed object,
as group homomorphism -/
@[simps]
def appLinearMap (X : C) : (F ⟶ G) →ₗ[R] F.obj X ⟶ G.obj X where
toFun α := α.app X
map_add' _ _ := rfl
map_smul' _ _ := rfl
@[simp]
theorem app_smul (X : C) (r : R) (α : F ⟶ G) : (r • α).app X = r • α.app X :=
rfl
end NatTrans
end CategoryTheory
|
PUnit.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.Algebra.Group.Defs
/-!
# `PUnit` is a commutative group
This file collects facts about algebraic structures on the one-element type, e.g. that it is a
commutative ring.
-/
assert_not_exists MonoidWithZero
namespace PUnit
@[to_additive]
instance commGroup : CommGroup PUnit where
mul _ _ := unit
one := unit
inv _ := unit
div _ _ := unit
npow _ _ := unit
zpow _ _ := unit
mul_assoc _ _ _ := rfl
one_mul _ := rfl
mul_one _ := rfl
inv_mul_cancel _ := rfl
mul_comm _ _ := rfl
-- shortcut instances
@[to_additive] instance : One PUnit where one := unit
@[to_additive] instance : Mul PUnit where mul _ _ := unit
@[to_additive] instance : Div PUnit where div _ _ := unit
@[to_additive] instance : Inv PUnit where inv _ := unit
@[to_additive (attr := simp)] lemma one_eq : (1 : PUnit) = unit := rfl
-- note simp can prove this when the Boolean ring structure is introduced
@[to_additive] lemma mul_eq (x y : PUnit) : x * y = unit := rfl
@[to_additive (attr := simp)] lemma div_eq (x y : PUnit) : x / y = unit := rfl
@[to_additive (attr := simp)] lemma inv_eq (x : PUnit) : x⁻¹ = unit := rfl
end PUnit
|
IsolatedZeros.lean
|
/-
Copyright (c) 2025 Stefan Kebekus. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stefan Kebekus
-/
import Mathlib.Analysis.Meromorphic.Basic
/-!
# Principles of Isolated Zeros and Identity Principles for Meromorphic Functions
In line with results in `Mathlib.Analysis.Analytic.IsolatedZeros` and
`Mathlib.Analysis.Analytic.Uniqueness`, this file establishes principles of isolated zeros and
identity principles for meromorphic functions.
Compared to the results for analytic functions, the principles established here are a little more
complicated to state. This is because meromorphic functions can be modified at will along discrete
subsets and still remain meromorphic.
-/
variable
{𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{U : Set 𝕜} {x : 𝕜} {f g : 𝕜 → E}
open Filter Topology
namespace MeromorphicAt
/-!
## Principles of Isolated Zeros
-/
/--
The principle of isolated zeros: If `f` is meromorphic at `x`, then `f` vanishes eventually in a
punctured neighborhood of `x` iff it vanishes frequently in punctured neighborhoods.
See `AnalyticAt.frequently_zero_iff_eventually_zero` for a stronger result in the analytic case.
-/
theorem frequently_zero_iff_eventuallyEq_zero (hf : MeromorphicAt f x) :
(∃ᶠ z in 𝓝[≠] x, f z = 0) ↔ f =ᶠ[𝓝[≠] x] 0 :=
⟨hf.eventually_eq_zero_or_eventually_ne_zero.resolve_right, fun h ↦ h.frequently⟩
/--
Variant of the principle of isolated zeros: Let `U` be a subset of `𝕜` and assume that `x ∈ U` is
not an isolated point of `U`. If a function `f` is meromorphic at `x` and vanishes along a subset
that is codiscrete within `U`, then `f` vanishes in a punctured neighbourhood of `f`.
For a typical application, let `U` be a path in the complex plane and let `x` be one of the end
points. If `f` is meromorphic at `x` and vanishes on `U`, then it will vanish in a punctured
neighbourhood of `x`, which intersects `U` non-trivially but is not contained in `U`.
The assumption that `x` is not an isolated point of `U` is expressed as `AccPt x (𝓟 U)`. See
`accPt_iff_frequently` and `accPt_iff_frequently_nhdsNE` for useful reformulations.
-/
theorem eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin (hf : MeromorphicAt f x)
(h₁x : x ∈ U) (h₂x : AccPt x (𝓟 U)) (h : f =ᶠ[codiscreteWithin U] 0) :
f =ᶠ[𝓝[≠] x] 0 := by
rw [← hf.frequently_zero_iff_eventuallyEq_zero]
apply ((accPt_iff_frequently_nhdsNE.1 h₂x).and_eventually
(mem_codiscreteWithin_iff_forall_mem_nhdsNE.1 h x h₁x)).mp
filter_upwards
intro a
simp_rw [Pi.zero_apply]
rw [(by rfl : ({x | f x = 0} ∪ Uᶜ) a ↔ a ∈ {x | f x = 0} ∪ Uᶜ)]
simp_all
/-!
## Identity Principles
-/
/--
Formulation of `MeromorphicAt.frequently_zero_iff_eventuallyEq_zero` as an identity principle: If
`f` and `g` are meromorphic at `x`, then `f` and `g` agree eventually in a punctured neighborhood of
`x` iff they agree at points arbitrarily close to (but different from) `x`.
-/
theorem frequently_eq_iff_eventuallyEq (hf : MeromorphicAt f x) (hg : MeromorphicAt g x) :
(∃ᶠ z in 𝓝[≠] x, f z = g z) ↔ f =ᶠ[𝓝[≠] x] g := by
rw [eventuallyEq_iff_sub, ← (hf.sub hg).frequently_zero_iff_eventuallyEq_zero]
simp_rw [Pi.sub_apply, sub_eq_zero]
/--
Formulation of `MeromorphicAt.eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin` as an
identity principle: Let `U` be a subset of `𝕜` and assume that `x ∈ U` is not an isolated point of
`U`. If function `f` and `g` are meromorphic at `x` and agree along a subset that is codiscrete
within `U`, then `f` and `g` agree in a punctured neighbourhood of `f`.
-/
theorem eventuallyEq_nhdsNE_of_eventuallyEq_codiscreteWithin (hf : MeromorphicAt f x)
(hg : MeromorphicAt g x) (h₁x : x ∈ U) (h₂x : AccPt x (𝓟 U)) (h : f =ᶠ[codiscreteWithin U] g) :
f =ᶠ[𝓝[≠] x] g := by
rw [eventuallyEq_iff_sub] at *
apply (hf.sub hg).eventuallyEq_zero_nhdsNE_of_eventuallyEq_zero_codiscreteWithin h₁x h₂x h
end MeromorphicAt
|
Defs.lean
|
/-
Copyright (c) 2023 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Init.Data.ULift
import Init.Data.Fin.Fold
import Init.Data.List.Nat.Pairwise
import Init.Data.List.Nat.Range
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.RingTheory.Localization.NormTrace
import Mathlib.Analysis.Normed.Field.Lemmas
/-!
# Number field discriminant
This file defines the discriminant of a number field.
## Main definitions
* `NumberField.discr`: the absolute discriminant of a number field.
## Tags
number field, discriminant
-/
open Module
-- TODO: Rewrite some of the FLT results on the discriminant using the definitions and results of
-- this file
namespace NumberField
variable (K : Type*) [Field K] [NumberField K]
/-- The absolute discriminant of a number field. -/
noncomputable abbrev discr : ℤ := Algebra.discr ℤ (RingOfIntegers.basis K)
theorem coe_discr : (discr K : ℚ) = Algebra.discr ℚ (integralBasis K) :=
(Algebra.discr_localizationLocalization ℤ _ K (RingOfIntegers.basis K)).symm
theorem discr_ne_zero : discr K ≠ 0 := by
rw [← (Int.cast_injective (α := ℚ)).ne_iff, coe_discr]
exact Algebra.discr_not_zero_of_basis ℚ (integralBasis K)
theorem discr_eq_discr {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ (𝓞 K)) :
Algebra.discr ℤ b = discr K := by
let b₀ := Basis.reindex (RingOfIntegers.basis K) (Basis.indexEquiv (RingOfIntegers.basis K) b)
rw [Algebra.discr_eq_discr (𝓞 K) b b₀, Basis.coe_reindex, Algebra.discr_reindex]
theorem discr_eq_discr_of_algEquiv {L : Type*} [Field L] [NumberField L] (f : K ≃ₐ[ℚ] L) :
discr K = discr L := by
let f₀ : 𝓞 K ≃ₗ[ℤ] 𝓞 L := (f.restrictScalars ℤ).mapIntegralClosure.toLinearEquiv
rw [← Rat.intCast_inj, coe_discr, Algebra.discr_eq_discr_of_algEquiv (integralBasis K) f,
← discr_eq_discr L ((RingOfIntegers.basis K).map f₀)]
change _ = algebraMap ℤ ℚ _
rw [← Algebra.discr_localizationLocalization ℤ (nonZeroDivisors ℤ) L]
congr 1
ext
simp only [Function.comp_apply, integralBasis_apply, Basis.localizationLocalization_apply,
Basis.map_apply]
rfl
end NumberField
namespace Rat
open NumberField
/-- The absolute discriminant of the number field `ℚ` is 1. -/
@[simp]
theorem numberField_discr : discr ℚ = 1 := by
let b : Basis (Fin 1) ℤ (𝓞 ℚ) :=
Basis.map (Basis.singleton (Fin 1) ℤ) ringOfIntegersEquiv.toAddEquiv.toIntLinearEquiv.symm
calc NumberField.discr ℚ
_ = Algebra.discr ℤ b := by convert (discr_eq_discr ℚ b).symm
_ = Algebra.trace ℤ (𝓞 ℚ) (b default * b default) := by
rw [Algebra.discr_def, Matrix.det_unique, Algebra.traceMatrix_apply, Algebra.traceForm_apply]
_ = Algebra.trace ℤ (𝓞 ℚ) 1 := by
rw [Basis.map_apply, RingEquiv.toAddEquiv_eq_coe, ← AddEquiv.toIntLinearEquiv_symm,
AddEquiv.coe_toIntLinearEquiv, Basis.singleton_apply,
show (AddEquiv.symm ↑ringOfIntegersEquiv) (1 : ℤ) = ringOfIntegersEquiv.symm 1 by rfl,
map_one, mul_one]
_ = 1 := by rw [Algebra.trace_eq_matrix_trace b]; norm_num
alias _root_.NumberField.discr_rat := numberField_discr
end Rat
variable {ι ι'} (K) [Field K] [DecidableEq ι] [DecidableEq ι'] [Fintype ι] [Fintype ι']
/-- If `b` and `b'` are `ℚ`-bases of a number field `K` such that
`∀ i j, IsIntegral ℤ (b.toMatrix b' i j)` and `∀ i j, IsIntegral ℤ (b'.toMatrix b i j)` then
`discr ℚ b = discr ℚ b'`. -/
theorem Algebra.discr_eq_discr_of_toMatrix_coeff_isIntegral [NumberField K]
{b : Basis ι ℚ K} {b' : Basis ι' ℚ K} (h : ∀ i j, IsIntegral ℤ (b.toMatrix b' i j))
(h' : ∀ i j, IsIntegral ℤ (b'.toMatrix b i j)) : discr ℚ b = discr ℚ b' := by
replace h' : ∀ i j, IsIntegral ℤ (b'.toMatrix (b.reindex (b.indexEquiv b')) i j) := by
intro i j
convert h' i ((b.indexEquiv b').symm j)
simp [Basis.toMatrix_apply]
classical
rw [← (b.reindex (b.indexEquiv b')).toMatrix_map_vecMul b', discr_of_matrix_vecMul,
← one_mul (discr ℚ b), Basis.coe_reindex, discr_reindex]
congr
have hint : IsIntegral ℤ ((b.reindex (b.indexEquiv b')).toMatrix b').det :=
IsIntegral.det fun i j => h _ _
obtain ⟨r, hr⟩ := IsIntegrallyClosed.isIntegral_iff.1 hint
have hunit : IsUnit r := by
have : IsIntegral ℤ (b'.toMatrix (b.reindex (b.indexEquiv b'))).det :=
IsIntegral.det fun i j => h' _ _
obtain ⟨r', hr'⟩ := IsIntegrallyClosed.isIntegral_iff.1 this
refine isUnit_iff_exists_inv.2 ⟨r', ?_⟩
suffices algebraMap ℤ ℚ (r * r') = 1 by
rw [← RingHom.map_one (algebraMap ℤ ℚ)] at this
exact (IsFractionRing.injective ℤ ℚ) this
rw [RingHom.map_mul, hr, hr', ← Matrix.det_mul,
Basis.toMatrix_mul_toMatrix_flip, Matrix.det_one]
rw [← RingHom.map_one (algebraMap ℤ ℚ), ← hr]
rcases Int.isUnit_iff.1 hunit with hp | hm
· simp [hp]
· simp [hm]
|
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.
|
ProfiniteGrp.lean
|
import Mathlib
universe v u
open CategoryTheory ProfiniteGrp
set_option maxHeartbeats 10000
set_option synthInstance.maxHeartbeats 2000
variable {X Y Z : Type u} [Group X] [TopologicalSpace X] [IsTopologicalGroup X]
[CompactSpace X] [TotallyDisconnectedSpace X] [Group Y] [TopologicalSpace Y]
[IsTopologicalGroup Y] [CompactSpace Y] [TotallyDisconnectedSpace Y] [Group Z]
[TopologicalSpace Z] [IsTopologicalGroup Z] [CompactSpace Z] [TotallyDisconnectedSpace Z]
/- We test if all the coercions and `map_add` lemmas trigger correctly. -/
example : ⇑(𝟙 (of X)) = id := by simp
example (f : ContinuousMonoidHom X Y) : ⇑(ofHom f) = ⇑f := by simp
example (f : ContinuousMonoidHom X Y) (x : X) : (ofHom f) x = f x := by simp
example {U V W : ProfiniteGrp} (f : U ⟶ V) (g : V ⟶ W) : ⇑(f ≫ g) = ⇑g ∘ ⇑f := by simp
example (f : ContinuousMonoidHom X Y) (g : ContinuousMonoidHom Y Z) :
⇑(ofHom f ≫ ofHom g) = g ∘ f := by simp
example {W : ProfiniteGrp} (f : ContinuousMonoidHom X Y) (g : of Y ⟶ W) :
⇑(ofHom f ≫ g) = g ∘ f := by simp
example {U V : ProfiniteGrp} (f : U ⟶ V) (g : V ⟶ of Z) :
⇑(f ≫ g) = g ∘ f := by simp
example {V W : ProfiniteGrp} (f : of X ⟶ V) (g : V ⟶ W) :
⇑(f ≫ g) = g ∘ f := by simp
example {U V W : ProfiniteGrp} (f : U ⟶ V) (g : V ⟶ W) (u : U) : (f ≫ g) u = g (f u) := by
simp
example {U V : ProfiniteGrp} (e : U ≅ V) (u : U) : e.inv (e.hom u) = u := by simp
example {U V : ProfiniteGrp} (e : U ≅ V) (v : V) : e.hom (e.inv v) = v := by simp
example (U : ProfiniteGrp) : ⇑(𝟙 U) = id := by simp
example {M N : ProfiniteGrp.{u}} (f : M ⟶ N) (x y : M) : f (x * y) = f x * f y := by
simp
example {M N : ProfiniteGrp.{u}} (f : M ⟶ N) : f 1 = 1 := by
simp
|
ValuativeCriterion.lean
|
/-
Copyright (c) 2024 Andrew Yang, Qi Ge, Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang, Qi Ge, Christian Merten
-/
import Mathlib.AlgebraicGeometry.Morphisms.Immersion
import Mathlib.AlgebraicGeometry.Morphisms.Proper
import Mathlib.RingTheory.RingHom.Injective
import Mathlib.RingTheory.Valuation.LocalSubring
/-!
# Valuative criterion
## Main results
- `AlgebraicGeometry.UniversallyClosed.eq_valuativeCriterion`:
A morphism is universally closed if and only if
it is quasi-compact and satisfies the existence part of the valuative criterion.
- `AlgebraicGeometry.IsSeparated.eq_valuativeCriterion`:
A morphism is separated if and only if
it is quasi-separated and satisfies the uniqueness part of the valuative criterion.
- `AlgebraicGeometry.IsProper.eq_valuativeCriterion`:
A morphism is proper if and only if
it is qcqs and of fintite type and satisfies the valuative criterion.
## Future projects
Show that it suffices to check discrete valuation rings when the base is noetherian.
-/
open CategoryTheory CategoryTheory.Limits
namespace AlgebraicGeometry
universe u
/--
A valuative commutative square over a morphism `f : X ⟶ Y` is a square
```
Spec K ⟶ Y
| |
↓ ↓
Spec R ⟶ X
```
where `R` is a valuation ring, and `K` is its ring of fractions.
We are interested in finding lifts `Spec R ⟶ Y` of this diagram.
-/
structure ValuativeCommSq {X Y : Scheme.{u}} (f : X ⟶ Y) where
/-- The valuation ring of a valuative commutative square. -/
R : Type u
[commRing : CommRing R]
[domain : IsDomain R]
[valuationRing : ValuationRing R]
/-- The field of fractions of a valuative commutative square. -/
K : Type u
[field : Field K]
[algebra : Algebra R K]
[isFractionRing : IsFractionRing R K]
/-- The top map in a valuative commutative map. -/
(i₁ : Spec(K) ⟶ X)
/-- The bottom map in a valuative commutative map. -/
(i₂ : Spec(R) ⟶ Y)
(commSq : CommSq i₁ (Spec.map (CommRingCat.ofHom (algebraMap R K))) f i₂)
namespace ValuativeCommSq
attribute [instance] commRing domain valuationRing field algebra isFractionRing
end ValuativeCommSq
/-- A morphism `f : X ⟶ Y` satisfies the existence part of the valuative criterion if
every valuative commutative square over `f` has (at least) a lift. -/
def ValuativeCriterion.Existence : MorphismProperty Scheme :=
fun _ _ f ↦ ∀ S : ValuativeCommSq f, S.commSq.HasLift
/-- A morphism `f : X ⟶ Y` satisfies the uniqueness part of the valuative criterion if
every valuative commutative square over `f` has at most one lift. -/
def ValuativeCriterion.Uniqueness : MorphismProperty Scheme :=
fun _ _ f ↦ ∀ S : ValuativeCommSq f, Subsingleton S.commSq.LiftStruct
/-- A morphism `f : X ⟶ Y` satisfies the valuative criterion if
every valuative commutative square over `f` has a unique lift. -/
def ValuativeCriterion : MorphismProperty Scheme :=
fun _ _ f ↦ ∀ S : ValuativeCommSq f, Nonempty (Unique (S.commSq.LiftStruct))
variable {X Y : Scheme.{u}} (f : X ⟶ Y)
lemma ValuativeCriterion.iff {f : X ⟶ Y} :
ValuativeCriterion f ↔ Existence f ∧ Uniqueness f := by
change (∀ _, _) ↔ (∀ _, _) ∧ (∀ _, _)
simp_rw [← forall_and, unique_iff_subsingleton_and_nonempty, and_comm, CommSq.HasLift.iff]
lemma ValuativeCriterion.eq :
ValuativeCriterion = Existence ⊓ Uniqueness := by
ext X Y f
exact iff
lemma ValuativeCriterion.existence {f : X ⟶ Y} (h : ValuativeCriterion f) :
ValuativeCriterion.Existence f := (iff.mp h).1
lemma ValuativeCriterion.uniqueness {f : X ⟶ Y} (h : ValuativeCriterion f) :
ValuativeCriterion.Uniqueness f := (iff.mp h).2
namespace ValuativeCriterion.Existence
open IsLocalRing
@[stacks 01KE]
lemma specializingMap (H : ValuativeCriterion.Existence f) :
SpecializingMap f.base := by
intro x' y h
let stalk_y_to_residue_x' : Y.presheaf.stalk y ⟶ X.residueField x' :=
Y.presheaf.stalkSpecializes h ≫ f.stalkMap x' ≫ X.residue x'
obtain ⟨A, hA, hA_local⟩ := exists_factor_valuationRing stalk_y_to_residue_x'.hom
let stalk_y_to_A : Y.presheaf.stalk y ⟶ .of A :=
CommRingCat.ofHom (stalk_y_to_residue_x'.hom.codRestrict _ hA)
have w : X.fromSpecResidueField x' ≫ f =
Spec.map (CommRingCat.ofHom (algebraMap A (X.residueField x'))) ≫
Spec.map stalk_y_to_A ≫ Y.fromSpecStalk y := by
rw [Scheme.fromSpecResidueField, Category.assoc, ← Scheme.Spec_map_stalkMap_fromSpecStalk,
← Scheme.Spec_map_stalkSpecializes_fromSpecStalk h]
simp_rw [← Spec.map_comp_assoc]
rfl
obtain ⟨l, hl₁, hl₂⟩ := (H { R := A, K := X.residueField x', commSq := ⟨w⟩, .. }).exists_lift
dsimp only at hl₁ hl₂
refine ⟨l.base (closedPoint A), ?_, ?_⟩
· simp_rw [← Scheme.fromSpecResidueField_apply x' (closedPoint (X.residueField x')), ← hl₁]
exact (specializes_closedPoint _).map l.base.hom.2
· rw [← Scheme.comp_base_apply, hl₂]
simp only [Scheme.comp_coeBase, TopCat.coe_comp, Function.comp_apply]
have : (Spec.map stalk_y_to_A).base (closedPoint A) = closedPoint (Y.presheaf.stalk y) :=
comap_closedPoint (S := A) (stalk_y_to_residue_x'.hom.codRestrict A.toSubring hA)
rw [this, Y.fromSpecStalk_closedPoint]
instance {R S : CommRingCat} (e : R ≅ S) : IsLocalHom e.hom.hom :=
isLocalHom_of_isIso _
lemma of_specializingMap (H : (topologically @SpecializingMap).universally f) :
ValuativeCriterion.Existence f := by
rintro ⟨R, K, i₁, i₂, ⟨w⟩⟩
haveI : IsDomain (CommRingCat.of R) := ‹_›
haveI : ValuationRing (CommRingCat.of R) := ‹_›
letI : Field (CommRingCat.of K) := ‹_›
replace H := H (pullback.snd i₂ f) i₂ (pullback.fst i₂ f) (.of_hasPullback i₂ f)
let lft := pullback.lift (Spec.map (CommRingCat.ofHom (algebraMap R K))) i₁ w.symm
obtain ⟨x, h₁, h₂⟩ := @H (lft.base (closedPoint _)) _ (specializes_closedPoint (R := R) _)
let e : CommRingCat.of R ≅ Spec(R).presheaf.stalk ((pullback.fst i₂ f).base x) :=
(stalkClosedPointIso (.of R)).symm ≪≫
Spec(R).presheaf.stalkCongr (.of_eq h₂.symm)
let α := e.hom ≫ (pullback.fst i₂ f).stalkMap x
have : IsLocalHom e.hom.hom := isLocalHom_of_isIso e.hom
have : IsLocalHom α.hom := inferInstanceAs
(IsLocalHom (((pullback.fst i₂ f).stalkMap x).hom.comp e.hom.hom))
let β := (pullback i₂ f).presheaf.stalkSpecializes h₁ ≫ Scheme.stalkClosedPointTo lft
have hαβ : α ≫ β = CommRingCat.ofHom (algebraMap R K) := by
simp only [CommRingCat.coe_of, Iso.trans_hom, Iso.symm_hom, TopCat.Presheaf.stalkCongr_hom,
Category.assoc, α, e, β, stalkClosedPointIso_inv, StructureSheaf.toStalk]
change (Scheme.ΓSpecIso (.of R)).inv ≫ Spec(R).presheaf.germ _ _ _ ≫ _ = _
simp only [TopCat.Presheaf.germ_stalkSpecializes_assoc, Scheme.stalkMap_germ_assoc]
-- `map_top` introduces defeq problems, according to `check_compositions`.
-- This is probably the cause of the `erw` needed below.
simp only [TopologicalSpace.Opens.map_top]
rw [Scheme.germ_stalkClosedPointTo lft ⊤ trivial]
erw [← Scheme.comp_app_assoc lft (pullback.fst i₂ f)]
rw [pullback.lift_fst]
simp
have hbij := (bijective_rangeRestrict_comp_of_valuationRing (R := R) (K := K) α.hom β.hom
(CommRingCat.hom_ext_iff.mp hαβ))
let φ : (pullback i₂ f).presheaf.stalk x ⟶ CommRingCat.of R := CommRingCat.ofHom <|
(RingEquiv.ofBijective _ hbij).symm.toRingHom.comp β.hom.rangeRestrict
have hαφ : α ≫ φ = 𝟙 _ := by ext x; exact (RingEquiv.ofBijective _ hbij).symm_apply_apply x
have hαφ' : (pullback.fst i₂ f).stalkMap x ≫ φ = e.inv := by
rw [← cancel_epi e.hom, ← Category.assoc, hαφ, e.hom_inv_id]
have hφβ : φ ≫ CommRingCat.ofHom (algebraMap R K) = β :=
hαβ ▸ CommRingCat.hom_ext (RingHom.ext fun x ↦ congr_arg Subtype.val
((RingEquiv.ofBijective _ hbij).apply_symm_apply (β.hom.rangeRestrict x)))
refine ⟨⟨⟨Spec.map ((pullback.snd i₂ f).stalkMap x ≫ φ) ≫ X.fromSpecStalk _, ?_, ?_⟩⟩⟩
· simp only [← Spec.map_comp_assoc, Category.assoc, hφβ]
simp only [Spec.map_comp, Category.assoc, Scheme.Spec_map_stalkMap_fromSpecStalk,
Scheme.Spec_map_stalkSpecializes_fromSpecStalk_assoc, β]
-- This next line only fires as `rw`, not `simp`:
rw [Scheme.Spec_stalkClosedPointTo_fromSpecStalk_assoc]
simp [lft]
· simp only [Spec.map_comp, Category.assoc, Scheme.Spec_map_stalkMap_fromSpecStalk,
← pullback.condition]
rw [← Scheme.Spec_map_stalkMap_fromSpecStalk_assoc, ← Spec.map_comp_assoc, hαφ']
simp only [Iso.trans_inv, TopCat.Presheaf.stalkCongr_inv, Iso.symm_inv, Spec.map_comp,
Category.assoc, Scheme.Spec_map_stalkSpecializes_fromSpecStalk_assoc, e]
rw [← Spec_stalkClosedPointIso, ← Spec.map_comp_assoc,
Iso.inv_hom_id, Spec.map_id, Category.id_comp]
instance stableUnderBaseChange : ValuativeCriterion.Existence.IsStableUnderBaseChange := by
constructor
intros Y' X X' Y Y'_to_Y f X'_to_X f' hP hf commSq
let commSq' : ValuativeCommSq f :=
{ R := commSq.R
K := commSq.K
i₁ := commSq.i₁ ≫ X'_to_X
i₂ := commSq.i₂ ≫ Y'_to_Y
commSq := ⟨by simp only [Category.assoc, hP.w, reassoc_of% commSq.commSq.w]⟩ }
obtain ⟨l₀, hl₁, hl₂⟩ := (hf commSq').exists_lift
refine ⟨⟨⟨hP.lift l₀ commSq.i₂ (by simp_all only [commSq']), ?_, hP.lift_snd _ _ _⟩⟩⟩
apply hP.hom_ext
· simpa
· simp only [Category.assoc]
rw [hP.lift_snd]
rw [commSq.commSq.w]
@[stacks 01KE]
protected lemma eq :
ValuativeCriterion.Existence = (topologically @SpecializingMap).universally := by
ext
constructor
· intro _
apply MorphismProperty.universally_mono
· apply specializingMap
· rwa [MorphismProperty.IsStableUnderBaseChange.universally_eq]
· apply of_specializingMap
end ValuativeCriterion.Existence
/-- The **valuative criterion** for universally closed morphisms. -/
@[stacks 01KF]
lemma UniversallyClosed.eq_valuativeCriterion :
@UniversallyClosed = ValuativeCriterion.Existence ⊓ @QuasiCompact := by
rw [universallyClosed_eq_universallySpecializing, ValuativeCriterion.Existence.eq]
/-- The **valuative criterion** for universally closed morphisms. -/
@[stacks 01KF]
lemma UniversallyClosed.of_valuativeCriterion [QuasiCompact f]
(hf : ValuativeCriterion.Existence f) : UniversallyClosed f := by
rw [eq_valuativeCriterion]
exact ⟨hf, ‹_›⟩
section Uniqueness
/-- The **valuative criterion** for separated morphisms. -/
@[stacks 01L0]
lemma IsSeparated.of_valuativeCriterion [QuasiSeparated f]
(hf : ValuativeCriterion.Uniqueness f) : IsSeparated f where
diagonal_isClosedImmersion := by
suffices h : ValuativeCriterion.Existence (pullback.diagonal f) by
have : QuasiCompact (pullback.diagonal f) :=
AlgebraicGeometry.QuasiSeparated.diagonalQuasiCompact
apply IsClosedImmersion.of_isPreimmersion
apply IsClosedMap.isClosed_range
apply (topologically @IsClosedMap).universally_le
exact (UniversallyClosed.of_valuativeCriterion (pullback.diagonal f) h).out
intro S
have hc : CommSq S.i₁ (Spec.map (CommRingCat.ofHom (algebraMap S.R S.K)))
f (S.i₂ ≫ pullback.fst f f ≫ f) := ⟨by simp [← S.commSq.w_assoc]⟩
let S' : ValuativeCommSq f := ⟨S.R, S.K, S.i₁, S.i₂ ≫ pullback.fst f f ≫ f, hc⟩
have : Subsingleton S'.commSq.LiftStruct := hf S'
let S'l₁ : S'.commSq.LiftStruct := ⟨S.i₂ ≫ pullback.fst f f,
by simp [S', ← S.commSq.w_assoc], by simp [S']⟩
let S'l₂ : S'.commSq.LiftStruct := ⟨S.i₂ ≫ pullback.snd f f,
by simp [S', ← S.commSq.w_assoc], by simp [S', pullback.condition]⟩
have h₁₂ : S'l₁ = S'l₂ := Subsingleton.elim _ _
constructor
constructor
refine ⟨S.i₂ ≫ pullback.fst _ _, ?_, ?_⟩
· simp [← S.commSq.w_assoc]
· simp
apply IsPullback.hom_ext (IsPullback.of_hasPullback _ _)
· simp
· simp only [Category.assoc, pullback.diagonal_snd, Category.comp_id]
exact congrArg CommSq.LiftStruct.l h₁₂
@[stacks 01KZ]
lemma IsSeparated.valuativeCriterion [IsSeparated f] : ValuativeCriterion.Uniqueness f := by
intros S
constructor
rintro ⟨l₁, hl₁, hl₁'⟩ ⟨l₂, hl₂, hl₂'⟩
ext : 1
dsimp at *
have h := hl₁'.trans hl₂'.symm
let Z := pullback (pullback.diagonal f) (pullback.lift l₁ l₂ h)
let g : Z ⟶ Spec(S.R) := pullback.snd _ _
have : IsClosedImmersion g := MorphismProperty.pullback_snd _ _ inferInstance
have hZ : IsAffine Z := by
rw [@HasAffineProperty.iff_of_isAffine @IsClosedImmersion] at this
exact this.left
suffices IsIso g by
rw [← cancel_epi g]
conv_lhs => rw [← pullback.lift_fst l₁ l₂ h, ← pullback.condition_assoc]
conv_rhs => rw [← pullback.lift_snd l₁ l₂ h, ← pullback.condition_assoc]
simp
suffices h : Function.Bijective (g.appTop) by
refine (HasAffineProperty.iff_of_isAffine (P := MorphismProperty.isomorphisms Scheme)).mpr ?_
exact ⟨hZ, (ConcreteCategory.isIso_iff_bijective _).mpr h⟩
constructor
· let l : Spec(S.K) ⟶ Z :=
pullback.lift S.i₁ (Spec.map (CommRingCat.ofHom (algebraMap S.R S.K))) (by
apply IsPullback.hom_ext (IsPullback.of_hasPullback _ _)
· simpa using hl₁.symm
· simpa using hl₂.symm)
have hg : l ≫ g = Spec.map (CommRingCat.ofHom (algebraMap S.R S.K)) :=
pullback.lift_snd _ _ _
have : Function.Injective ((l ≫ g).appTop) := by
rw [hg]
let e := arrowIsoΓSpecOfIsAffine (CommRingCat.ofHom <| algebraMap S.R S.K)
let P : MorphismProperty CommRingCat :=
RingHom.toMorphismProperty <| fun f ↦ Function.Injective f
have : (RingHom.toMorphismProperty <| fun f ↦ Function.Injective f).RespectsIso :=
RingHom.toMorphismProperty_respectsIso_iff.mp RingHom.injective_respectsIso
change P _
rw [← MorphismProperty.arrow_mk_iso_iff (P := P) e]
exact FaithfulSMul.algebraMap_injective S.R S.K
rw [Scheme.comp_appTop] at this
exact Function.Injective.of_comp this
· rw [@HasAffineProperty.iff_of_isAffine @IsClosedImmersion] at this
exact this.right
/-- The **valuative criterion** for separated morphisms. -/
lemma IsSeparated.eq_valuativeCriterion :
@IsSeparated = ValuativeCriterion.Uniqueness ⊓ @QuasiSeparated := by
ext X Y f
exact ⟨fun _ ↦ ⟨IsSeparated.valuativeCriterion f, inferInstance⟩,
fun ⟨H, _⟩ ↦ .of_valuativeCriterion f H⟩
end Uniqueness
/-- The **valuative criterion** for proper morphisms. -/
@[stacks 0BX5]
lemma IsProper.eq_valuativeCriterion :
@IsProper = ValuativeCriterion ⊓ @QuasiCompact ⊓ @QuasiSeparated ⊓ @LocallyOfFiniteType := by
rw [isProper_eq, IsSeparated.eq_valuativeCriterion, ValuativeCriterion.eq,
UniversallyClosed.eq_valuativeCriterion]
simp_rw [inf_assoc]
ext X Y f
change _ ∧ _ ∧ _ ∧ _ ∧ _ ↔ _ ∧ _ ∧ _ ∧ _ ∧ _
tauto
/-- The **valuative criterion** for proper morphisms. -/
@[stacks 0BX5]
lemma IsProper.of_valuativeCriterion [QuasiCompact f] [QuasiSeparated f] [LocallyOfFiniteType f]
(H : ValuativeCriterion f) : IsProper f := by
rw [eq_valuativeCriterion]
exact ⟨⟨⟨‹_›, ‹_›⟩, ‹_›⟩, ‹_›⟩
end AlgebraicGeometry
|
Pretransitive.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Action.TypeTags
/-!
# Pretransitive group actions
This file defines a typeclass for pretransitive group actions.
## Notation
- `a • b` is used as notation for `SMul.smul a b`.
- `a +ᵥ b` is used as notation for `VAdd.vadd a b`.
## Implementation details
This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles.
More sophisticated lemmas belong in `GroupTheory.GroupAction`.
## Tags
group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M G α β : Type*}
/-!
### (Pre)transitive action
`M` acts pretransitively on `α` if for any `x y` there is `g` such that `g • x = y` (or `g +ᵥ x = y`
for an additive action). A transitive action should furthermore have `α` nonempty.
In this section we define typeclasses `MulAction.IsPretransitive` and
`AddAction.IsPretransitive` and provide `MulAction.exists_smul_eq`/`AddAction.exists_vadd_eq`,
`MulAction.surjective_smul`/`AddAction.surjective_vadd` as public interface to access this
property. We do not provide typeclasses `*Action.IsTransitive`; users should assume
`[MulAction.IsPretransitive M α] [Nonempty α]` instead.
-/
/-- `M` acts pretransitively on `α` if for any `x y` there is `g` such that `g +ᵥ x = y`.
A transitive action should furthermore have `α` nonempty. -/
class AddAction.IsPretransitive (M α : Type*) [VAdd M α] : Prop where
/-- There is `g` such that `g +ᵥ x = y`. -/
exists_vadd_eq : ∀ x y : α, ∃ g : M, g +ᵥ x = y
/-- `M` acts pretransitively on `α` if for any `x y` there is `g` such that `g • x = y`.
A transitive action should furthermore have `α` nonempty. -/
@[to_additive (attr := mk_iff)]
class MulAction.IsPretransitive (M α : Type*) [SMul M α] : Prop where
/-- There is `g` such that `g • x = y`. -/
exists_smul_eq : ∀ x y : α, ∃ g : M, g • x = y
@[to_additive]
instance MulAction.instIsPretransitiveOfSubsingleton
{M α : Type*} [Monoid M] [MulAction M α] [Subsingleton α] :
MulAction.IsPretransitive M α where
exists_smul_eq x y := ⟨1, by
simp only [one_smul, Subsingleton.elim x y] ⟩
namespace MulAction
variable (M) [SMul M α] [IsPretransitive M α]
@[to_additive]
lemma exists_smul_eq (x y : α) : ∃ m : M, m • x = y := IsPretransitive.exists_smul_eq x y
@[to_additive]
lemma surjective_smul (x : α) : Surjective fun c : M ↦ c • x := exists_smul_eq M x
/-- The left regular action of a group on itself is transitive. -/
@[to_additive /-- The regular action of a group on itself is transitive. -/]
instance Regular.isPretransitive [Group G] : IsPretransitive G G :=
⟨fun x y ↦ ⟨y * x⁻¹, inv_mul_cancel_right _ _⟩⟩
/-- The right regular action of a group on itself is transitive. -/
@[to_additive /-- The right regular action of an additive group on itself is transitive. -/]
instance Regular.isPretransitive_mulOpposite [Group G] : IsPretransitive Gᵐᵒᵖ G :=
⟨fun x y ↦ ⟨.op (x⁻¹ * y), mul_inv_cancel_left _ _⟩⟩
end MulAction
namespace MulAction
@[to_additive]
lemma IsPretransitive.of_smul_eq {M N α : Type*} [SMul M α] [SMul N α] [IsPretransitive M α]
(f : M → N) (hf : ∀ {c : M} {x : α}, f c • x = c • x) : IsPretransitive N α where
exists_smul_eq x y := (exists_smul_eq x y).elim fun m h ↦ ⟨f m, hf.trans h⟩
end MulAction
section CompatibleScalar
@[to_additive]
lemma MulAction.IsPretransitive.of_isScalarTower (M : Type*) {N α : Type*} [Monoid N] [SMul M N]
[MulAction N α] [SMul M α] [IsScalarTower M N α] [IsPretransitive M α] : IsPretransitive N α :=
of_smul_eq (fun x : M ↦ x • 1) (smul_one_smul N _ _)
end CompatibleScalar
/-! ### `Additive`, `Multiplicative` -/
section
open Additive Multiplicative
instance Additive.addAction_isPretransitive [Monoid α] [MulAction α β]
[MulAction.IsPretransitive α β] : AddAction.IsPretransitive (Additive α) β :=
⟨@MulAction.exists_smul_eq α _ _ _⟩
instance Multiplicative.mulAction_isPretransitive [AddMonoid α] [AddAction α β]
[AddAction.IsPretransitive α β] : MulAction.IsPretransitive (Multiplicative α) β :=
⟨@AddAction.exists_vadd_eq α _ _ _⟩
end
|
ProjectiveSeminorm.lean
|
/-
Copyright (c) 2024 Sophie Morel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sophie Morel
-/
import Mathlib.Analysis.NormedSpace.Multilinear.Basic
import Mathlib.LinearAlgebra.PiTensorProduct
/-!
# Projective seminorm on the tensor of a finite family of normed spaces.
Let `𝕜` be a nontrivially normed field and `E` be a family of normed `𝕜`-vector spaces `Eᵢ`,
indexed by a finite type `ι`. We define a seminorm on `⨂[𝕜] i, Eᵢ`, which we call the
"projective seminorm". For `x` an element of `⨂[𝕜] i, Eᵢ`, its projective seminorm is the
infimum over all expressions of `x` as `∑ j, ⨂ₜ[𝕜] mⱼ i` (with the `mⱼ` ∈ `Π i, Eᵢ`)
of `∑ j, Π i, ‖mⱼ i‖`.
In particular, every norm `‖.‖` on `⨂[𝕜] i, Eᵢ` satisfying `‖⨂ₜ[𝕜] i, m i‖ ≤ Π i, ‖m i‖`
for every `m` in `Π i, Eᵢ` is bounded above by the projective seminorm.
## Main definitions
* `PiTensorProduct.projectiveSeminorm`: The projective seminorm on `⨂[𝕜] i, Eᵢ`.
## Main results
* `PiTensorProduct.norm_eval_le_projectiveSeminorm`: If `f` is a continuous multilinear map on
`E = Π i, Eᵢ` and `x` is in `⨂[𝕜] i, Eᵢ`, then `‖f.lift x‖ ≤ projectiveSeminorm x * ‖f‖`.
## TODO
* If the base field is `ℝ` or `ℂ` (or more generally if the injection of `Eᵢ` into its bidual is
an isometry for every `i`), then we have `projectiveSeminorm ⨂ₜ[𝕜] i, mᵢ = Π i, ‖mᵢ‖`.
* The functoriality.
-/
universe uι u𝕜 uE uF
variable {ι : Type uι} [Fintype ι]
variable {𝕜 : Type u𝕜} [NontriviallyNormedField 𝕜]
variable {E : ι → Type uE} [∀ i, SeminormedAddCommGroup (E i)]
open scoped TensorProduct
namespace PiTensorProduct
/-- A lift of the projective seminorm to `FreeAddMonoid (𝕜 × Π i, Eᵢ)`, useful to prove the
properties of `projectiveSeminorm`.
-/
def projectiveSeminormAux : FreeAddMonoid (𝕜 × Π i, E i) → ℝ :=
fun p => (p.toList.map (fun p ↦ ‖p.1‖ * ∏ i, ‖p.2 i‖)).sum
theorem projectiveSeminormAux_nonneg (p : FreeAddMonoid (𝕜 × Π i, E i)) :
0 ≤ projectiveSeminormAux p := by
simp only [projectiveSeminormAux]
refine List.sum_nonneg ?_
intro a
simp only [List.mem_map, Prod.exists, forall_exists_index,
and_imp]
intro x m _ h
rw [← h]
exact mul_nonneg (norm_nonneg _) (Finset.prod_nonneg (fun _ _ ↦ norm_nonneg _))
theorem projectiveSeminormAux_add_le (p q : FreeAddMonoid (𝕜 × Π i, E i)) :
projectiveSeminormAux (p + q) ≤ projectiveSeminormAux p + projectiveSeminormAux q := by
simp [projectiveSeminormAux]
theorem projectiveSeminormAux_smul (p : FreeAddMonoid (𝕜 × Π i, E i)) (a : 𝕜) :
projectiveSeminormAux (p.map (fun (y : 𝕜 × Π i, E i) ↦ (a * y.1, y.2))) =
‖a‖ * projectiveSeminormAux p := by
simp [projectiveSeminormAux, Function.comp_def, mul_assoc, List.sum_map_mul_left]
variable [∀ i, NormedSpace 𝕜 (E i)]
theorem bddBelow_projectiveSemiNormAux (x : ⨂[𝕜] i, E i) :
BddBelow (Set.range (fun (p : lifts x) ↦ projectiveSeminormAux p.1)) := by
existsi 0
rw [mem_lowerBounds]
simp only [Set.mem_range, Subtype.exists, exists_prop, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
exact fun p _ ↦ projectiveSeminormAux_nonneg p
/-- The projective seminorm on `⨂[𝕜] i, Eᵢ`. It sends an element `x` of `⨂[𝕜] i, Eᵢ` to the
infimum over all expressions of `x` as `∑ j, ⨂ₜ[𝕜] mⱼ i` (with the `mⱼ` ∈ `Π i, Eᵢ`)
of `∑ j, Π i, ‖mⱼ i‖`.
-/
noncomputable def projectiveSeminorm : Seminorm 𝕜 (⨂[𝕜] i, E i) := by
refine Seminorm.ofSMulLE (fun x ↦ iInf (fun (p : lifts x) ↦ projectiveSeminormAux p.1)) ?_ ?_ ?_
· refine le_antisymm ?_ ?_
· refine ciInf_le_of_le (bddBelow_projectiveSemiNormAux (0 : ⨂[𝕜] i, E i)) ⟨0, lifts_zero⟩ ?_
rfl
· letI : Nonempty (lifts 0) := ⟨0, lifts_zero (R := 𝕜) (s := E)⟩
exact le_ciInf (fun p ↦ projectiveSeminormAux_nonneg p.1)
· intro x y
letI := nonempty_subtype.mpr (nonempty_lifts x); letI := nonempty_subtype.mpr (nonempty_lifts y)
exact le_ciInf_add_ciInf (fun p q ↦ ciInf_le_of_le (bddBelow_projectiveSemiNormAux _)
⟨p.1 + q.1, lifts_add p.2 q.2⟩ (projectiveSeminormAux_add_le p.1 q.1))
· intro a x
letI := nonempty_subtype.mpr (nonempty_lifts x)
rw [Real.mul_iInf_of_nonneg (norm_nonneg _)]
refine le_ciInf ?_
intro p
rw [← projectiveSeminormAux_smul]
exact ciInf_le_of_le (bddBelow_projectiveSemiNormAux _)
⟨(p.1.map (fun y ↦ (a * y.1, y.2))), lifts_smul p.2 a⟩ (le_refl _)
theorem projectiveSeminorm_apply (x : ⨂[𝕜] i, E i) :
projectiveSeminorm x = iInf (fun (p : lifts x) ↦ projectiveSeminormAux p.1) := rfl
theorem projectiveSeminorm_tprod_le (m : Π i, E i) :
projectiveSeminorm (⨂ₜ[𝕜] i, m i) ≤ ∏ i, ‖m i‖ := by
rw [projectiveSeminorm_apply]
convert ciInf_le (bddBelow_projectiveSemiNormAux _) ⟨FreeAddMonoid.of ((1 : 𝕜), m), ?_⟩
· simp [projectiveSeminormAux]
· rw [mem_lifts_iff, FreeAddMonoid.toList_of,List.map_singleton, List.sum_singleton, one_smul]
theorem norm_eval_le_projectiveSeminorm (x : ⨂[𝕜] i, E i) (G : Type*) [SeminormedAddCommGroup G]
[NormedSpace 𝕜 G] (f : ContinuousMultilinearMap 𝕜 E G) :
‖lift f.toMultilinearMap x‖ ≤ projectiveSeminorm x * ‖f‖ := by
letI := nonempty_subtype.mpr (nonempty_lifts x)
rw [projectiveSeminorm_apply, Real.iInf_mul_of_nonneg (norm_nonneg _)]
unfold projectiveSeminormAux
refine le_ciInf ?_
intro ⟨p, hp⟩
rw [mem_lifts_iff] at hp
conv_lhs => rw [← hp, ← List.sum_map_hom, ← Multiset.sum_coe]
refine le_trans (norm_multiset_sum_le _) ?_
simp only [Multiset.map_coe, List.map_map, Multiset.sum_coe]
rw [mul_comm, ← smul_eq_mul, List.smul_sum]
refine List.Forall₂.sum_le_sum ?_
simp only [smul_eq_mul, List.map_map, List.forall₂_map_right_iff, Function.comp_apply,
List.forall₂_map_left_iff, map_smul, lift.tprod, ContinuousMultilinearMap.coe_coe,
List.forall₂_same, Prod.forall]
intro a m _
rw [norm_smul, ← mul_assoc, mul_comm ‖f‖ _, mul_assoc]
exact mul_le_mul_of_nonneg_left (f.le_opNorm _) (norm_nonneg _)
end PiTensorProduct
|
finmodule.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype bigop ssralg finset fingroup.
From mathcomp Require Import morphism perm finalg action gproduct commutator .
From mathcomp Require Import cyclic.
(******************************************************************************)
(* This file regroups constructions and results that are based on the most *)
(* primitive version of representation theory -- viewing an abelian group as *)
(* the additive group of a (finite) Z-module. This includes the Gaschutz *)
(* splitting and transitivity theorem, from which we will later derive the *)
(* Schur-Zassenhaus theorem and the elementary abelian special case of *)
(* Maschke's theorem, the coprime abelian centraliser/commutator trivial *)
(* intersection theorem, which is used to show that p-groups under coprime *)
(* action factor into special groups, and the construction of the transfer *)
(* homomorphism and its expansion relative to a cycle, from which we derive *)
(* the Higman Focal Subgroup and the Burnside Normal Complement theorems. *)
(* The definitions and lemmas for the finite Z-module induced by an abelian *)
(* are packaged in an auxiliary FiniteModule submodule: they should not be *)
(* needed much outside this file, which contains all the results that exploit *)
(* this construction. *)
(* FiniteModule defines the Z[N(A)]-module associated with a finite abelian *)
(* abelian group A, given a proof (abelA : abelian A) : *)
(* fmod_of abelA == the type of elements of the module (similar to but *)
(* distinct from [subg A]). *)
(* fmod abelA x == the injection of x into fmod_of abelA if x \in A, else 0 *)
(* fmval u == the projection of u : fmod_of abelA onto A *)
(* u ^@ x == the action of x \in 'N(A) on u : fmod_of abelA *)
(* The transfer morphism is be constructed from a morphism f : H >-> rT, and *)
(* a group G, along with the two assumptions sHG : H \subset G and *)
(* abfH : abelian (f @* H): *)
(* transfer sGH abfH == the function gT -> FiniteModule.fmod_of abfH that *)
(* implements the transfer morphism induced by f on G. *)
(* The Lemma transfer_indep states that the transfer morphism can be expanded *)
(* using any transversal of the partition HG := rcosets H G of G. *)
(* Further, for any g \in G, HG :* <[g]> is also a partition of G (Lemma *)
(* rcosets_cycle_partition), and for any transversal X of HG :* <[g]> the *)
(* function r mapping x : gT to rcosets (H :* x) <[g]> is (constructively) a *)
(* bijection from X to the <[g]>-orbit partition of HG, and Lemma *)
(* transfer_cycle_expansion gives a simplified expansion of the transfer *)
(* morphism. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope GRing.Theory FinRing.Theory.
Local Open Scope ring_scope.
Module FiniteModule.
Reserved Notation "u ^@ x" (at level 31, left associativity).
Inductive fmod_of (gT : finGroupType) (A : {group gT}) (abelA : abelian A) :=
Fmod x & x \in A.
Bind Scope ring_scope with fmod_of.
Section OneFinMod.
(* TODO: understand why FinGroup has to be changed to BaseFinGroup here. *)
Let f2sub (gT : finGroupType) (A : {group gT}) (abA : abelian A) :=
fun u : fmod_of abA => let : Fmod x Ax := u in Subg Ax : BaseFinGroup.arg_sort _.
Local Coercion f2sub : fmod_of >-> BaseFinGroup.arg_sort.
Variables (gT : finGroupType) (A : {group gT}) (abelA : abelian A).
Local Notation fmodA := (fmod_of abelA).
Implicit Types (x y z : gT) (u v w : fmodA).
Let sub2f (s : [subg A]) := Fmod abelA (valP s).
Definition fmval u := val (f2sub u).
#[export]
HB.instance Definition _ := [isSub for fmval].
Local Notation valA := (val: fmodA -> gT) (only parsing).
#[export]
HB.instance Definition _ := [Finite of fmodA by <:].
Definition fmod x := sub2f (subg A x).
Definition actr u x := if x \in 'N(A) then fmod (fmval u ^ x) else u.
Definition fmod_opp u := sub2f u^-1.
Definition fmod_add u v := sub2f (u * v).
Fact fmod_add0r : left_id (sub2f 1) fmod_add.
Proof. by move=> u; apply: val_inj; apply: mul1g. Qed.
Fact fmod_addrA : associative fmod_add.
Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed.
Fact fmod_addNr : left_inverse (sub2f 1) fmod_opp fmod_add.
Proof. by move=> u; apply: val_inj; apply: mulVg. Qed.
Fact fmod_addrC : commutative fmod_add.
Proof. by case=> x Ax [y Ay]; apply: val_inj; apply: (centsP abelA). Qed.
#[export]
HB.instance Definition _ :=
GRing.isZmodule.Build fmodA fmod_addrA fmod_addrC fmod_add0r fmod_addNr.
(* TODO: Should isZmodule and the like be exported from ssralg *)
#[export]
HB.instance Definition _ := [finGroupMixin of fmodA for +%R].
Lemma fmodP u : val u \in A. Proof. exact: valP. Qed.
Lemma fmod_inj : injective fmval. Proof. exact: val_inj. Qed.
Lemma congr_fmod u v : u = v -> fmval u = fmval v.
Proof. exact: congr1. Qed.
Lemma fmvalA : {morph valA : x y / x + y >-> (x * y)%g}. Proof. by []. Qed.
Lemma fmvalN : {morph valA : x / - x >-> x^-1%g}. Proof. by []. Qed.
Lemma fmval0 : valA 0 = 1%g. Proof. by []. Qed.
Canonical fmval_morphism := @Morphism _ _ setT fmval (in2W fmvalA).
Definition fmval_sum := big_morph fmval fmvalA fmval0.
Lemma fmvalZ n : {morph valA : x / x *+ n >-> (x ^+ n)%g}.
Proof. by move=> u; rewrite /= morphX ?inE. Qed.
Lemma fmodKcond x : val (fmod x) = if x \in A then x else 1%g.
Proof. by rewrite /= /fmval /= val_insubd. Qed.
Lemma fmodK : {in A, cancel fmod val}. Proof. exact: subgK. Qed.
Lemma fmvalK : cancel val fmod.
Proof. by case=> x Ax; apply: val_inj; rewrite /fmod /= sgvalK. Qed.
Lemma fmod1 : fmod 1 = 0. Proof. by rewrite -fmval0 fmvalK. Qed.
Lemma fmodM : {in A &, {morph fmod : x y / (x * y)%g >-> x + y}}.
Proof. by move=> x y Ax Ay /=; apply: val_inj; rewrite /fmod morphM. Qed.
Canonical fmod_morphism := Morphism fmodM.
Lemma fmodX n : {in A, {morph fmod : x / (x ^+ n)%g >-> x *+ n}}.
Proof. exact: morphX. Qed.
Lemma fmodV : {morph fmod : x / x^-1%g >-> - x}.
Proof.
move=> x; apply: val_inj; rewrite fmvalN !fmodKcond groupV.
by case: (x \in A); rewrite ?invg1.
Qed.
Lemma injm_fmod : 'injm fmod.
Proof.
by apply/injmP=> x y Ax Ay []; move/val_inj; apply: (injmP (injm_subg A)).
Qed.
Notation "u ^@ x" := (actr u x) : ring_scope.
Lemma fmvalJcond u x :
val (u ^@ x) = if x \in 'N(A) then val u ^ x else val u.
Proof. by case: ifP => Nx; rewrite /actr Nx ?fmodK // memJ_norm ?fmodP. Qed.
Lemma fmvalJ u x : x \in 'N(A) -> val (u ^@ x) = val u ^ x.
Proof. by move=> Nx; rewrite fmvalJcond Nx. Qed.
Lemma fmodJ x y : y \in 'N(A) -> fmod (x ^ y) = fmod x ^@ y.
Proof.
move=> Ny; apply: val_inj; rewrite fmvalJ ?fmodKcond ?memJ_norm //.
by case: ifP => // _; rewrite conj1g.
Qed.
Fact actr_is_action : is_action 'N(A) actr.
Proof.
split=> [a u v eq_uv_a | u a b Na Nb].
case Na: (a \in 'N(A)); last by rewrite /actr Na in eq_uv_a.
by apply: val_inj; apply: (conjg_inj a); rewrite -!fmvalJ ?eq_uv_a.
by apply: val_inj; rewrite !fmvalJ ?groupM ?conjgM.
Qed.
Canonical actr_action := Action actr_is_action.
Notation "''M'" := actr_action : action_scope.
Lemma act0r x : 0 ^@ x = 0.
Proof. by rewrite /actr conj1g morph1 if_same. Qed.
Lemma actAr x : {morph actr^~ x : u v / u + v}.
Proof.
by move=> u v; apply: val_inj; rewrite !(fmvalA, fmvalJcond) conjMg; case: ifP.
Qed.
Definition actr_sum x := big_morph _ (actAr x) (act0r x).
Lemma actNr x : {morph actr^~ x : u / - u}.
Proof. by move=> u; apply: (addrI (u ^@ x)); rewrite -actAr !subrr act0r. Qed.
Lemma actZr x n : {morph actr^~ x : u / u *+ n}.
Proof.
by move=> u; elim: n => [|n IHn]; rewrite ?act0r // !mulrS actAr IHn.
Qed.
Fact actr_is_groupAction : is_groupAction setT 'M.
Proof.
move=> a Na /[1!inE]; apply/andP; split; first by apply/subsetP=> u _ /[1!inE].
by apply/morphicP=> u v _ _; rewrite !permE /= actAr.
Qed.
Canonical actr_groupAction := GroupAction actr_is_groupAction.
Notation "''M'" := actr_groupAction : groupAction_scope.
Lemma actr1 u : u ^@ 1 = u.
Proof. exact: act1. Qed.
Lemma actrM : {in 'N(A) &, forall x y u, u ^@ (x * y) = u ^@ x ^@ y}.
Proof.
by move=> x y Nx Ny /= u; apply: val_inj; rewrite !fmvalJ ?conjgM ?groupM.
Qed.
Lemma actrK x : cancel (actr^~ x) (actr^~ x^-1%g).
Proof.
move=> u; apply: val_inj; rewrite !fmvalJcond groupV.
by case: ifP => -> //; rewrite conjgK.
Qed.
Lemma actrKV x : cancel (actr^~ x^-1%g) (actr^~ x).
Proof. by move=> u; rewrite /= -{2}(invgK x) actrK. Qed.
End OneFinMod.
Bind Scope ring_scope with fmod_of.
Prenex Implicits fmval fmod actr.
Notation "u ^@ x" := (actr u x) : ring_scope.
Notation "''M'" := actr_action : action_scope.
Notation "''M'" := actr_groupAction : groupAction_scope.
Module Exports.
HB.reexport FiniteModule.
End Exports.
End FiniteModule.
HB.export FiniteModule.Exports.
Arguments FiniteModule.fmodK {gT A} abelA [x] Ax.
Arguments FiniteModule.fmvalK {gT A abelA} x.
Arguments FiniteModule.actrK {gT A abelA} x.
Arguments FiniteModule.actrKV {gT A abelA} x.
(* Still allow ring notations, but give priority to groups now. *)
Import FiniteModule GroupScope.
Section Gaschutz.
Variables (gT : finGroupType) (G H P : {group gT}).
Implicit Types K L : {group gT}.
Hypotheses (nsHG : H <| G) (sHP : H \subset P) (sPG : P \subset G).
Hypotheses (abelH : abelian H) (coHiPG : coprime #|H| #|G : P|).
Let sHG := normal_sub nsHG.
Let nHG := subsetP (normal_norm nsHG).
Let m := (expg_invn H #|G : P|).
Implicit Types a b : fmod_of abelH.
Local Notation fmod := (fmod abelH).
Theorem Gaschutz_split : [splits G, over H] = [splits P, over H].
Proof.
apply/splitsP/splitsP=> [[K /complP[tiHK eqHK]] | [Q /complP[tiHQ eqHQ]]].
exists (K :&: P)%G; rewrite inE setICA (setIidPl sHP) setIC tiHK eqxx.
by rewrite group_modl // eqHK (sameP eqP setIidPr).
have sQP: Q \subset P by rewrite -eqHQ mulG_subr.
pose rP x := repr (P :* x); pose pP x := x * (rP x)^-1.
have PpP x: pP x \in P by rewrite -mem_rcoset rcoset_repr rcoset_refl.
have rPmul x y: x \in P -> rP (x * y) = rP y.
by move=> Px; rewrite /rP rcosetM rcoset_id.
pose pQ x := remgr H Q x; pose rH x := pQ (pP x) * rP x.
have pQhq: {in H & Q, forall h q, pQ (h * q) = q} by apply: remgrMid.
have pQmul: {in P &, {morph pQ : x y / x * y}}.
by apply: remgrM; [apply/complP | apply: normalS (nsHG)].
have HrH x: rH x \in H :* x.
by rewrite rcoset_sym mem_rcoset invMg mulgA mem_divgr // eqHQ PpP.
have GrH x: x \in G -> rH x \in G.
move=> Gx; case/rcosetP: (HrH x) => y Hy ->.
by rewrite groupM // (subsetP sHG).
have rH_Pmul x y: x \in P -> rH (x * y) = pQ x * rH y.
by move=> Px; rewrite /rH mulgA -pQmul; first by rewrite /pP rPmul ?mulgA.
have rH_Hmul h y: h \in H -> rH (h * y) = rH y.
by move=> Hh; rewrite rH_Pmul ?(subsetP sHP) // -(mulg1 h) pQhq ?mul1g.
pose mu x y := fmod ((rH x * rH y)^-1 * rH (x * y)).
pose nu y := (\sum_(Px in rcosets P G) mu (repr Px) y)%R.
have rHmul: {in G &, forall x y, rH (x * y) = rH x * rH y * val (mu x y)}.
move=> x y Gx Gy; rewrite /= fmodK ?mulKVg // -mem_lcoset lcoset_sym.
rewrite -norm_rlcoset; last by rewrite nHG ?GrH ?groupM.
by rewrite (rcoset_eqP (HrH _)) -rcoset_mul ?nHG ?GrH // mem_mulg.
have actrH a x: x \in G -> (a ^@ rH x = a ^@ x)%R.
move=> Gx; apply: val_inj; rewrite /= !fmvalJ ?nHG ?GrH //.
case/rcosetP: (HrH x) => b /(fmodK abelH) <- ->; rewrite conjgM.
by congr (_ ^ _); rewrite conjgE -fmvalN -!fmvalA (addrC a) addKr.
have mu_Pmul x y z: x \in P -> mu (x * y) z = mu y z.
move=> Px; congr fmod; rewrite -mulgA !(rH_Pmul x) ?rPmul //.
by rewrite -mulgA invMg -mulgA mulKg.
have mu_Hmul x y z: x \in G -> y \in H -> mu x (y * z) = mu x z.
move=> Gx Hy; congr fmod; rewrite (mulgA x) (conjgCV x) -mulgA 2?rH_Hmul //.
by rewrite -mem_conjg (normP _) ?nHG.
have{mu_Hmul} nu_Hmul y z: y \in H -> nu (y * z) = nu z.
move=> Hy; apply: eq_bigr => _ /rcosetsP[x Gx ->]; apply: mu_Hmul y z _ Hy.
by rewrite -(groupMl _ (subsetP sPG _ (PpP x))) mulgKV.
have cocycle_mu: {in G & &, forall x y z,
mu (x * y)%g z + mu x y ^@ z = mu y z + mu x (y * z)%g}%R.
- move=> x y z Gx Gy Gz; apply: val_inj.
apply: (mulgI (rH x * rH y * rH z)).
rewrite -(actrH _ _ Gz) addrC [in LHS]fmvalA fmvalJ ?nHG ?GrH //.
rewrite mulgA -(mulgA _ (rH z)) -conjgC mulgA -!rHmul ?groupM //.
by rewrite mulgA -mulgA -2!(mulgA (rH x)) -!rHmul ?groupM.
move: mu => mu in rHmul mu_Pmul cocycle_mu nu nu_Hmul.
have{cocycle_mu} cocycle_nu: {in G &, forall y z,
nu z + nu y ^@ z = mu y z *+ #|G : P| + nu (y * z)%g}%R.
- move=> y z Gy Gz; rewrite /= (actr_sum z) /=.
have ->: (nu z = \sum_(Px in rcosets P G) mu (repr Px * y)%g z)%R.
rewrite /nu (reindex_acts _ (actsRs_rcosets P G) Gy) /=.
apply: eq_bigr => _ /rcosetsP[x Gx /= ->].
rewrite rcosetE -rcosetM.
case: repr_rcosetP=> p1 Pp1; case: repr_rcosetP=> p2 Pp2.
by rewrite -mulgA [x * y]lock !mu_Pmul.
rewrite -sumr_const -!big_split /=; apply: eq_bigr => _ /rcosetsP[x Gx ->].
rewrite -cocycle_mu //; case: repr_rcosetP => p1 Pp1.
by rewrite groupMr // (subsetP sPG).
move: nu => nu in nu_Hmul cocycle_nu.
pose f x := rH x * val (nu x *+ m)%R.
have{cocycle_nu} fM: {in G &, {morph f : x y / x * y}}.
move=> x y Gx Gy; rewrite /f ?rHmul // -3!mulgA; congr (_ * _).
rewrite (mulgA _ (rH y)) (conjgC _ (rH y)) -mulgA; congr (_ * _).
rewrite -fmvalJ ?actrH ?nHG ?GrH // -!fmvalA actZr -mulrnDl.
rewrite -(addrC (nu y)) cocycle_nu // mulrnDl !fmvalA; congr (_ * _).
by rewrite !fmvalZ expgK ?fmodP.
exists (Morphism fM @* G)%G; apply/complP; split.
apply/trivgP/subsetP=> x /setIP[Hx /morphimP[y _ Gy eq_x]].
apply/set1P; move: Hx; rewrite {x}eq_x /= groupMr ?subgP //.
rewrite -{1}(mulgKV y (rH y)) groupMl -?mem_rcoset // => Hy.
by rewrite -(mulg1 y) /f nu_Hmul // rH_Hmul //; apply: (morph1 (Morphism fM)).
apply/setP=> x; apply/mulsgP/idP=> [[h y Hh fy ->{x}] | Gx].
rewrite groupMl; last exact: (subsetP sHG).
case/morphimP: fy => z _ Gz ->{h Hh y}.
by rewrite /= /f groupMl ?GrH // (subsetP sHG) ?fmodP.
exists (x * (f x)^-1) (f x); last first; first by rewrite mulgKV.
by apply/morphimP; exists x.
rewrite -groupV invMg invgK -mulgA (conjgC (val _)) mulgA.
by rewrite groupMl -(mem_rcoset, mem_conjg) // (normP _) ?nHG ?fmodP.
Qed.
Theorem Gaschutz_transitive : {in [complements to H in G] &,
forall K L, K :&: P = L :&: P -> exists2 x, x \in H & L :=: K :^ x}.
Proof.
move=> K L /=; set Q := K :&: P => /complP[tiHK eqHK] cpHL QeqLP.
have [trHL eqHL] := complP cpHL.
pose nu x := fmod (divgr H L x^-1).
have sKG: {subset K <= G} by apply/subsetP; rewrite -eqHK mulG_subr.
have sLG: {subset L <= G} by apply/subsetP; rewrite -eqHL mulG_subr.
have val_nu x: x \in G -> val (nu x) = divgr H L x^-1.
by move=> Gx; rewrite fmodK // mem_divgr // eqHL groupV.
have nu_cocycle: {in G &, forall x y, nu (x * y)%g = nu x ^@ y + nu y}%R.
move=> x y Gx Gy; apply: val_inj; rewrite fmvalA fmvalJ ?nHG //.
rewrite !val_nu ?groupM // /divgr conjgE !mulgA mulgK.
by rewrite !(invMg, remgrM cpHL) ?groupV ?mulgA.
have nuL x: x \in L -> nu x = 0%R.
move=> Lx; apply: val_inj; rewrite val_nu ?sLG //.
by rewrite /divgr remgr_id ?groupV ?mulgV.
exists (fmval ((\sum_(X in rcosets Q K) nu (repr X)) *+ m)).
exact: fmodP.
apply/eqP; rewrite eq_sym eqEcard; apply/andP; split; last first.
by rewrite cardJg -(leq_pmul2l (cardG_gt0 H)) -!TI_cardMg // eqHL eqHK.
apply/subsetP=> _ /imsetP[x Kx ->]; rewrite conjgE mulgA (conjgC _ x).
have Gx: x \in G by rewrite sKG.
rewrite conjVg -mulgA -fmvalJ ?nHG // -fmvalN -fmvalA (_ : _ + _ = nu x)%R.
by rewrite val_nu // mulKVg groupV mem_remgr // eqHL groupV.
rewrite actZr -!mulNrn -mulrnDl actr_sum.
rewrite addrC (reindex_acts _ (actsRs_rcosets _ K) Kx) -sumrB /= -/Q.
rewrite (eq_bigr (fun _ => nu x)) => [|_ /imsetP[y Ky ->]]; last first.
rewrite !rcosetE -rcosetM QeqLP.
case: repr_rcosetP => z /setIP[Lz _]; case: repr_rcosetP => t /setIP[Lt _].
rewrite !nu_cocycle ?groupM ?(sKG y) // ?sLG //.
by rewrite (nuL z) ?(nuL t) // !act0r !add0r addrC addKr.
apply: val_inj; rewrite sumr_const !fmvalZ.
rewrite -{2}(expgK coHiPG (fmodP (nu x))); congr (_ ^+ _ ^+ _).
rewrite -[#|_|]divgS ?subsetIl // -(divnMl (cardG_gt0 H)).
rewrite -!TI_cardMg //; last by rewrite setIA setIAC (setIidPl sHP).
by rewrite group_modl // eqHK (setIidPr sPG) divgS.
Qed.
End Gaschutz.
(* This is the TI part of B & G, Proposition 1.6(d). *)
(* We go with B & G rather than Aschbacher and will derive 1.6(e) from (d), *)
(* rather than the converse, because the derivation of 24.6 from 24.3 in *)
(* Aschbacher requires a separate reduction to p-groups to yield 1.6(d), *)
(* making it altogether longer than the direct Gaschutz-style proof. *)
(* This Lemma is used in maximal.v for the proof of Aschbacher 24.7. *)
Lemma coprime_abel_cent_TI (gT : finGroupType) (A G : {group gT}) :
A \subset 'N(G) -> coprime #|G| #|A| -> abelian G -> 'C_[~: G, A](A) = 1.
Proof.
move=> nGA coGA abG; pose f x := val (\sum_(a in A) fmod abG x ^@ a)%R.
have fM: {in G &, {morph f : x y / x * y}}.
move=> x y Gx Gy /=; rewrite -fmvalA -big_split /=; congr (fmval _).
by apply: eq_bigr => a Aa; rewrite fmodM // actAr.
have nfA x a: a \in A -> f (x ^ a) = f x.
move=> Aa; rewrite {2}/f (reindex_inj (mulgI a)) /=; congr (fmval _).
apply: eq_big => [b | b Ab]; first by rewrite groupMl.
by rewrite -!fmodJ ?groupM ?(subsetP nGA) // conjgM.
have kerR: [~: G, A] \subset 'ker (Morphism fM).
rewrite gen_subG; apply/subsetP=> xa; case/imset2P=> x a Gx Aa -> {xa}.
have Gxa: x ^ a \in G by rewrite memJ_norm ?(subsetP nGA).
rewrite commgEl; apply/kerP; rewrite (groupM, morphM) ?(groupV, morphV) //=.
by rewrite nfA ?mulVg.
apply/trivgP; apply/subsetP=> x /setIP[Rx cAx]; apply/set1P.
have Gx: x \in G by apply: subsetP Rx; rewrite commg_subl.
rewrite -(expgK coGA Gx) (_ : x ^+ _ = 1) ?expg1n //.
rewrite -(fmodK abG Gx) -fmvalZ -(mker (subsetP kerR x Rx)); congr fmval.
rewrite -GRing.sumr_const; apply: eq_bigr => a Aa.
by rewrite -fmodJ ?(subsetP nGA) // /conjg (centP cAx) // mulKg.
Qed.
Section Transfer.
Variables (gT aT : finGroupType) (G H : {group gT}).
Variable alpha : {morphism H >-> aT}.
Hypotheses (sHG : H \subset G) (abelA : abelian (alpha @* H)).
Local Notation HG := (rcosets (gval H) (gval G)).
Fact transfer_morph_subproof : H \subset alpha @*^-1 (alpha @* H).
Proof. by rewrite -sub_morphim_pre. Qed.
Let fmalpha := restrm transfer_morph_subproof (fmod abelA \o alpha).
Let V (rX : {set gT} -> gT) g :=
\sum_(Hx in rcosets H G) fmalpha (rX Hx * g * (rX (Hx :* g))^-1).
Definition transfer g := V repr g.
(* This is Aschbacher (37.2). *)
Lemma transferM : {in G &, {morph transfer : x y / (x * y)%g >-> x + y}}.
Proof.
move=> s t Gs Gt /=.
rewrite [transfer t](reindex_acts 'Rs _ Gs) ?actsRs_rcosets //= -big_split /=.
apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM.
rewrite -zmodMgE -morphM -?mem_rcoset; first by rewrite !mulgA mulgKV rcosetM.
by rewrite rcoset_repr rcosetM mem_rcoset mulgK mem_repr_rcoset.
by rewrite rcoset_repr (rcosetM _ _ t) mem_rcoset mulgK mem_repr_rcoset.
Qed.
Canonical transfer_morphism := Morphism transferM.
(* This is Aschbacher (37.1). *)
Lemma transfer_indep X (rX := transversal_repr 1 X) :
is_transversal X HG G -> {in G, transfer =1 V rX}.
Proof.
move=> trX g Gg; have mem_rX := repr_mem_pblock trX 1; rewrite -/rX in mem_rX.
apply: (addrI (\sum_(Hx in HG) fmalpha (repr Hx * (rX Hx)^-1))).
rewrite {1}(reindex_acts 'Rs _ Gg) ?actsRs_rcosets // -!big_split /=.
apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM.
case: repr_rcosetP => h1 Hh1; case: repr_rcosetP => h2 Hh2.
have: H :* (x * g) \in rcosets H G by rewrite -rcosetE imset_f ?groupM.
have: H :* x \in rcosets H G by rewrite -rcosetE imset_f.
case/mem_rX/rcosetP=> h3 Hh3 -> /mem_rX/rcosetP[h4 Hh4 ->].
rewrite -!(mulgA h1) -!(mulgA h2) -!(mulgA h3) !(mulKVg, invMg).
by rewrite addrC -!zmodMgE -!morphM ?groupM ?groupV // -!mulgA !mulKg.
Qed.
Section FactorTransfer.
Variable g : gT.
Hypothesis Gg : g \in G.
Let sgG : <[g]> \subset G. Proof. by rewrite cycle_subG. Qed.
Let H_g_rcosets x : {set {set gT}} := rcosets (H :* x) <[g]>.
Let n_ x := #|<[g]> : H :* x|.
Lemma mulg_exp_card_rcosets x : x * (g ^+ n_ x) \in H :* x.
Proof.
rewrite /n_ /indexg -orbitRs -porbit_actperm ?inE //.
rewrite -{2}(iter_porbit (actperm 'Rs g) (H :* x)) -permX -morphX ?inE //.
by rewrite actpermE //= rcosetE -rcosetM rcoset_refl.
Qed.
Let HGg : {set {set {set gT}}} := orbit 'Rs <[g]> @: HG.
Let partHG : partition HG G := rcosets_partition sHG.
Let actsgHG : [acts <[g]>, on HG | 'Rs].
Proof. exact: subset_trans sgG (actsRs_rcosets H G). Qed.
Let partHGg : partition HGg HG := orbit_partition actsgHG.
Let injHGg : {in HGg &, injective cover}.
Proof. by have [] := partition_partition partHG partHGg. Qed.
Let defHGg : HG :* <[g]> = cover @: HGg.
Proof.
rewrite -imset_comp [_ :* _]imset2_set1r; apply: eq_imset => Hx /=.
by rewrite cover_imset -curry_imset2r.
Qed.
Lemma rcosets_cycle_partition : partition (HG :* <[g]>) G.
Proof. by rewrite defHGg; have [] := partition_partition partHG partHGg. Qed.
Variable X : {set gT}.
Hypothesis trX : is_transversal X (HG :* <[g]>) G.
Let sXG : {subset X <= G}. Proof. exact/subsetP/(transversal_sub trX). Qed.
Lemma rcosets_cycle_transversal : H_g_rcosets @: X = HGg.
Proof.
have sHXgHGg x: x \in X -> H_g_rcosets x \in HGg.
by move/sXG=> Gx; apply: imset_f; rewrite -rcosetE imset_f.
apply/setP=> Hxg; apply/imsetP/idP=> [[x /sHXgHGg HGgHxg -> //] | HGgHxg].
have [_ /rcosetsP[z Gz ->] ->] := imsetP HGgHxg.
pose Hzg := H :* z * <[g]>; pose x := transversal_repr 1 X Hzg.
have HGgHzg: Hzg \in HG :* <[g]>.
by rewrite mem_mulg ?set11 // -rcosetE imset_f.
have Hzg_x: x \in Hzg by rewrite (repr_mem_pblock trX).
exists x; first by rewrite (repr_mem_transversal trX).
case/mulsgP: Hzg_x => y u /rcoset_eqP <- /(orbit_act 'Rs) <- -> /=.
by rewrite rcosetE -rcosetM.
Qed.
Local Notation defHgX := rcosets_cycle_transversal.
Let injHg: {in X &, injective H_g_rcosets}.
Proof.
apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg.
by rewrite (card_in_imset injHGg).
Qed.
Lemma sum_index_rcosets_cycle : (\sum_(x in X) n_ x)%N = #|G : H|.
Proof. by rewrite [#|G : H|](card_partition partHGg) -defHgX big_imset. Qed.
Lemma transfer_cycle_expansion :
transfer g = \sum_(x in X) fmalpha ((g ^+ n_ x) ^ (x^-1)).
Proof.
pose Y := \bigcup_(x in X) [set x * g ^+ i | i : 'I_(n_ x)].
pose rY := transversal_repr 1 Y.
pose pcyc x := porbit (actperm 'Rs g) (H :* x).
pose traj x := traject (actperm 'Rs g) (H :* x) #|pcyc x|.
have Hgr_eq x: H_g_rcosets x = pcyc x.
by rewrite /H_g_rcosets -orbitRs -porbit_actperm ?inE.
have pcyc_eq x: pcyc x =i traj x by apply: porbit_traject.
have uniq_traj x: uniq (traj x) by apply: uniq_traject_porbit.
have n_eq x: n_ x = #|pcyc x| by rewrite -Hgr_eq.
have size_traj x: size (traj x) = n_ x by rewrite n_eq size_traject.
have nth_traj x j: j < n_ x -> nth (H :* x) (traj x) j = H :* (x * g ^+ j).
move=> lt_j_x; rewrite nth_traject -?n_eq //.
by rewrite -permX -morphX ?inE // actpermE //= rcosetE rcosetM.
have sYG: Y \subset G.
apply/bigcupsP=> x Xx; apply/subsetP=> _ /imsetP[i _ ->].
by rewrite groupM ?groupX // sXG.
have trY: is_transversal Y HG G.
apply/and3P; split=> //; apply/forall_inP=> Hy.
have /and3P[/eqP <- _ _] := partHGg; rewrite -defHgX cover_imset.
case/bigcupP=> x Xx; rewrite Hgr_eq pcyc_eq => /trajectP[i].
rewrite -n_eq -permX -morphX ?in_setT // actpermE /= rcosetE -rcosetM => lti.
set y := x * _ => ->{Hy}; pose oi := Ordinal lti.
have Yy: y \in Y by apply/bigcupP; exists x => //; apply/imsetP; exists oi.
apply/cards1P; exists y; apply/esym/eqP.
rewrite eqEsubset sub1set inE Yy rcoset_refl.
apply/subsetP=> _ /setIP[/bigcupP[x' Xx' /imsetP[j _ ->]] Hy_x'gj].
have eq_xx': x = x'.
apply: (pblock_inj trX) => //; have /andP[/and3P[_ tiX _] _] := trX.
have HGgHyg: H :* y * <[g]> \in HG :* <[g]>.
by rewrite mem_mulg ?set11 // -rcosetE imset_f ?(subsetP sYG).
rewrite !(def_pblock tiX HGgHyg) //.
by rewrite -[x'](mulgK (g ^+ j)) mem_mulg // groupV mem_cycle.
by rewrite -[x](mulgK (g ^+ i)) mem_mulg ?rcoset_refl // groupV mem_cycle.
apply/set1P; rewrite /y eq_xx'; congr (_ * _ ^+ _) => //; apply/eqP.
rewrite -(@nth_uniq _ (H :* x) (traj x)) ?size_traj // ?eq_xx' //.
by rewrite !nth_traj ?(rcoset_eqP Hy_x'gj) // -eq_xx'.
have rYE x i : x \in X -> i < n_ x -> rY (H :* x :* g ^+ i) = x * g ^+ i.
move=> Xx lt_i_x; rewrite -rcosetM; apply: (canLR_in (pblockK trY 1)).
by apply/bigcupP; exists x => //; apply/imsetP; exists (Ordinal lt_i_x).
apply/esym/def_pblock; last exact: rcoset_refl; first by case/and3P: partHG.
by rewrite -rcosetE imset_f ?groupM ?groupX // sXG.
rewrite (transfer_indep trY Gg) /V -/rY (set_partition_big _ partHGg) /=.
rewrite -defHgX big_imset /=; last first.
apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg.
by rewrite (card_in_imset injHGg).
apply eq_bigr=> x Xx; rewrite Hgr_eq (eq_bigl _ _ (pcyc_eq x)) -big_uniq //=.
have n_gt0: 0 < n_ x by rewrite indexg_gt0.
rewrite /traj -n_eq; case def_n: (n_ x) (n_gt0) => // [n] _.
rewrite conjgE invgK -{1}[H :* x]rcoset1 -{1}(expg0 g).
elim: {1 3}n 0%N (addn0 n) => [|m IHm] i def_i /=.
rewrite big_seq1 {i}[i]def_i rYE // ?def_n //.
rewrite -(mulgA _ _ g) -rcosetM -expgSr -[(H :* x) :* _]rcosetE.
rewrite -actpermE morphX ?inE // permX // -{2}def_n n_eq iter_porbit mulgA.
by rewrite -[H :* x]rcoset1 (rYE _ 0) ?mulg1.
rewrite big_cons rYE //; last by rewrite def_n -def_i ltnS leq_addl.
rewrite permE /= rcosetE -rcosetM -(mulgA _ _ g) -expgSr.
rewrite addSnnS in def_i; rewrite IHm //.
rewrite rYE //; last by rewrite def_n -def_i ltnS leq_addl.
by rewrite mulgV [fmalpha 1]morph1 add0r.
Qed.
End FactorTransfer.
End Transfer.
|
Extension.lean
|
/-
Copyright (c) 2023 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno
-/
import Mathlib.CategoryTheory.Bicategory.Basic
import Mathlib.CategoryTheory.Comma.StructuredArrow.Basic
/-!
# Extensions and lifts in bicategories
We introduce the concept of extensions and lifts within the bicategorical framework. These concepts
are defined by commutative diagrams in the (1-)categorical context. Within the bicategorical
framework, commutative diagrams are replaced by 2-morphisms. Depending on the orientation of the
2-morphisms, we define both left and right extensions (likewise for lifts). The use of left and
right here is a common one in the theory of Kan extensions.
## Implementation notes
We define extensions and lifts as objects in certain comma categories (`StructuredArrow` for left,
and `CostructuredArrow` for right). See the file `CategoryTheory.StructuredArrow` for properties
about these categories. We introduce some intuitive aliases. For example, `LeftExtension.extension`
is an alias for `Comma.right`.
## References
* https://ncatlab.org/nlab/show/lifts+and+extensions
* https://ncatlab.org/nlab/show/Kan+extension
-/
namespace CategoryTheory
namespace Bicategory
universe w v u
variable {B : Type u} [Bicategory.{w, v} B] {a b c : B}
/-- Triangle diagrams for (left) extensions.
```
b
△ \
| \ extension △
f | \ | unit
| ◿
a - - - ▷ c
g
```
-/
abbrev LeftExtension (f : a ⟶ b) (g : a ⟶ c) := StructuredArrow g (precomp _ f)
namespace LeftExtension
variable {f : a ⟶ b} {g : a ⟶ c}
/-- The extension of `g` along `f`. -/
abbrev extension (t : LeftExtension f g) : b ⟶ c := t.right
/-- The 2-morphism filling the triangle diagram. -/
abbrev unit (t : LeftExtension f g) : g ⟶ f ≫ t.extension := t.hom
/-- Construct a left extension from a 1-morphism and a 2-morphism. -/
abbrev mk (h : b ⟶ c) (unit : g ⟶ f ≫ h) : LeftExtension f g :=
StructuredArrow.mk unit
variable {s t : LeftExtension f g}
/-- To construct a morphism between left extensions, we need a 2-morphism between the extensions,
and to check that it is compatible with the units. -/
abbrev homMk (η : s.extension ⟶ t.extension) (w : s.unit ≫ f ◁ η = t.unit := by cat_disch) :
s ⟶ t :=
StructuredArrow.homMk η w
@[reassoc (attr := simp)]
theorem w (η : s ⟶ t) : s.unit ≫ f ◁ η.right = t.unit :=
StructuredArrow.w η
/-- The left extension along the identity. -/
def alongId (g : a ⟶ c) : LeftExtension (𝟙 a) g := .mk _ (λ_ g).inv
instance : Inhabited (LeftExtension (𝟙 a) g) := ⟨alongId g⟩
/-- Construct a left extension of `g : a ⟶ c` from a left extension of `g ≫ 𝟙 c`. -/
@[simps!]
def ofCompId (t : LeftExtension f (g ≫ 𝟙 c)) : LeftExtension f g :=
mk (extension t) ((ρ_ g).inv ≫ unit t)
/-- Whisker a 1-morphism to an extension.
```
b
△ \
| \ extension △
f | \ | unit
| ◿
a - - - ▷ c - - - ▷ x
g h
```
-/
def whisker (t : LeftExtension f g) {x : B} (h : c ⟶ x) : LeftExtension f (g ≫ h) :=
.mk _ <| t.unit ▷ h ≫ (α_ _ _ _).hom
@[simp]
theorem whisker_extension (t : LeftExtension f g) {x : B} (h : c ⟶ x) :
(t.whisker h).extension = t.extension ≫ h :=
rfl
@[simp]
theorem whisker_unit (t : LeftExtension f g) {x : B} (h : c ⟶ x) :
(t.whisker h).unit = t.unit ▷ h ≫ (α_ f t.extension h).hom :=
rfl
/-- Whiskering a 1-morphism is a functor. -/
@[simps]
def whiskering {x : B} (h : c ⟶ x) : LeftExtension f g ⥤ LeftExtension f (g ≫ h) where
obj t := t.whisker h
map η := LeftExtension.homMk (η.right ▷ h) <| by
simp [- LeftExtension.w, ← LeftExtension.w η]
/-- Define a morphism between left extensions by cancelling the whiskered identities. -/
@[simps! right]
def whiskerIdCancel
(s : LeftExtension f (g ≫ 𝟙 c)) {t : LeftExtension f g} (τ : s ⟶ t.whisker (𝟙 c)) :
s.ofCompId ⟶ t :=
LeftExtension.homMk (τ.right ≫ (ρ_ _).hom)
/-- Construct a morphism between whiskered extensions. -/
@[simps! right]
def whiskerHom (i : s ⟶ t) {x : B} (h : c ⟶ x) :
s.whisker h ⟶ t.whisker h :=
StructuredArrow.homMk (i.right ▷ h) <| by
rw [← cancel_mono (α_ _ _ _).inv]
calc
_ = (unit s ≫ f ◁ i.right) ▷ h := by simp [- LeftExtension.w]
_ = unit t ▷ h := congrArg (· ▷ h) (LeftExtension.w i)
_ = _ := by simp
/-- Construct an isomorphism between whiskered extensions. -/
def whiskerIso (i : s ≅ t) {x : B} (h : c ⟶ x) :
s.whisker h ≅ t.whisker h :=
Iso.mk (whiskerHom i.hom h) (whiskerHom i.inv h)
(StructuredArrow.hom_ext _ _ <|
calc
_ = (i.hom ≫ i.inv).right ▷ h := by simp [- Iso.hom_inv_id]
_ = 𝟙 _ := by simp [Iso.hom_inv_id])
(StructuredArrow.hom_ext _ _ <|
calc
_ = (i.inv ≫ i.hom).right ▷ h := by simp [- Iso.inv_hom_id]
_ = 𝟙 _ := by simp [Iso.inv_hom_id])
/-- The isomorphism between left extensions induced by a right unitor. -/
@[simps! hom_right inv_right]
def whiskerOfCompIdIsoSelf (t : LeftExtension f g) : (t.whisker (𝟙 c)).ofCompId ≅ t :=
StructuredArrow.isoMk (ρ_ (t.extension))
end LeftExtension
/-- Triangle diagrams for (left) lifts.
```
b
◹ |
lift / | △
/ | f | unit
/ ▽
c - - - ▷ a
g
```
-/
abbrev LeftLift (f : b ⟶ a) (g : c ⟶ a) := StructuredArrow g (postcomp _ f)
namespace LeftLift
variable {f : b ⟶ a} {g : c ⟶ a}
/-- The lift of `g` along `f`. -/
abbrev lift (t : LeftLift f g) : c ⟶ b := t.right
/-- The 2-morphism filling the triangle diagram. -/
abbrev unit (t : LeftLift f g) : g ⟶ t.lift ≫ f := t.hom
/-- Construct a left lift from a 1-morphism and a 2-morphism. -/
abbrev mk (h : c ⟶ b) (unit : g ⟶ h ≫ f) : LeftLift f g :=
StructuredArrow.mk unit
variable {s t : LeftLift f g}
/-- To construct a morphism between left lifts, we need a 2-morphism between the lifts,
and to check that it is compatible with the units. -/
abbrev homMk (η : s.lift ⟶ t.lift) (w : s.unit ≫ η ▷ f = t.unit := by cat_disch) :
s ⟶ t :=
StructuredArrow.homMk η w
@[reassoc (attr := simp)]
theorem w (h : s ⟶ t) : s.unit ≫ h.right ▷ f = t.unit :=
StructuredArrow.w h
/-- The left lift along the identity. -/
def alongId (g : c ⟶ a) : LeftLift (𝟙 a) g := .mk _ (ρ_ g).inv
instance : Inhabited (LeftLift (𝟙 a) g) := ⟨alongId g⟩
/-- Construct a left lift along `g : c ⟶ a` from a left lift along `𝟙 c ≫ g`. -/
@[simps!]
def ofIdComp (t : LeftLift f (𝟙 c ≫ g)) : LeftLift f g :=
mk (lift t) ((λ_ _).inv ≫ unit t)
/-- Whisker a 1-morphism to a lift.
```
b
◹ |
lift / | △
/ | f | unit
/ ▽
x - - - ▷ c - - - ▷ a
h g
```
-/
def whisker (t : LeftLift f g) {x : B} (h : x ⟶ c) : LeftLift f (h ≫ g) :=
.mk _ <| h ◁ t.unit ≫ (α_ _ _ _).inv
@[simp]
theorem whisker_lift (t : LeftLift f g) {x : B} (h : x ⟶ c) :
(t.whisker h).lift = h ≫ t.lift :=
rfl
@[simp]
theorem whisker_unit (t : LeftLift f g) {x : B} (h : x ⟶ c) :
(t.whisker h).unit = h ◁ t.unit ≫ (α_ h t.lift f).inv :=
rfl
/-- Whiskering a 1-morphism is a functor. -/
@[simps]
def whiskering {x : B} (h : x ⟶ c) : LeftLift f g ⥤ LeftLift f (h ≫ g) where
obj t := t.whisker h
map η := LeftLift.homMk (h ◁ η.right) <| by
dsimp only [whisker_lift, whisker_unit]
rw [← LeftLift.w η]
simp [- LeftLift.w]
/-- Define a morphism between left lifts by cancelling the whiskered identities. -/
@[simps! right]
def whiskerIdCancel
(s : LeftLift f (𝟙 c ≫ g)) {t : LeftLift f g} (τ : s ⟶ t.whisker (𝟙 c)) :
s.ofIdComp ⟶ t :=
LeftLift.homMk (τ.right ≫ (λ_ _).hom)
/-- Construct a morphism between whiskered lifts. -/
@[simps! right]
def whiskerHom (i : s ⟶ t) {x : B} (h : x ⟶ c) :
s.whisker h ⟶ t.whisker h :=
StructuredArrow.homMk (h ◁ i.right) <| by
rw [← cancel_mono (α_ h _ _).hom]
calc
_ = h ◁ (unit s ≫ i.right ▷ f) := by simp [- LeftLift.w]
_ = h ◁ unit t := congrArg (h ◁ ·) (LeftLift.w i)
_ = _ := by simp
/-- Construct an isomorphism between whiskered lifts. -/
def whiskerIso (i : s ≅ t) {x : B} (h : x ⟶ c) :
s.whisker h ≅ t.whisker h :=
Iso.mk (whiskerHom i.hom h) (whiskerHom i.inv h)
(StructuredArrow.hom_ext _ _ <|
calc
_ = h ◁ (i.hom ≫ i.inv).right := by simp [- Iso.hom_inv_id]
_ = 𝟙 _ := by simp [Iso.hom_inv_id])
(StructuredArrow.hom_ext _ _ <|
calc
_ = h ◁ (i.inv ≫ i.hom).right := by simp [- Iso.inv_hom_id]
_ = 𝟙 _ := by simp [Iso.inv_hom_id])
/-- The isomorphism between left lifts induced by a left unitor. -/
@[simps! hom_right inv_right]
def whiskerOfIdCompIsoSelf (t : LeftLift f g) : (t.whisker (𝟙 c)).ofIdComp ≅ t :=
StructuredArrow.isoMk (λ_ (lift t))
end LeftLift
/-- Triangle diagrams for (right) extensions.
```
b
△ \
| \ extension | counit
f | \ ▽
| ◿
a - - - ▷ c
g
```
-/
abbrev RightExtension (f : a ⟶ b) (g : a ⟶ c) := CostructuredArrow (precomp _ f) g
namespace RightExtension
variable {f : a ⟶ b} {g : a ⟶ c}
/-- The extension of `g` along `f`. -/
abbrev extension (t : RightExtension f g) : b ⟶ c := t.left
/-- The 2-morphism filling the triangle diagram. -/
abbrev counit (t : RightExtension f g) : f ≫ t.extension ⟶ g := t.hom
/-- Construct a right extension from a 1-morphism and a 2-morphism. -/
abbrev mk (h : b ⟶ c) (counit : f ≫ h ⟶ g) : RightExtension f g :=
CostructuredArrow.mk counit
/-- To construct a morphism between right extensions, we need a 2-morphism between the extensions,
and to check that it is compatible with the counits. -/
abbrev homMk {s t : RightExtension f g} (η : s.extension ⟶ t.extension)
(w : f ◁ η ≫ t.counit = s.counit) : s ⟶ t :=
CostructuredArrow.homMk η w
@[reassoc (attr := simp)]
theorem w {s t : RightExtension f g} (η : s ⟶ t) :
f ◁ η.left ≫ t.counit = s.counit :=
CostructuredArrow.w η
/-- The right extension along the identity. -/
def alongId (g : a ⟶ c) : RightExtension (𝟙 a) g := .mk _ (λ_ g).hom
instance : Inhabited (RightExtension (𝟙 a) g) := ⟨alongId g⟩
end RightExtension
/-- Triangle diagrams for (right) lifts.
```
b
◹ |
lift / | | counit
/ | f ▽
/ ▽
c - - - ▷ a
g
```
-/
abbrev RightLift (f : b ⟶ a) (g : c ⟶ a) := CostructuredArrow (postcomp _ f) g
namespace RightLift
variable {f : b ⟶ a} {g : c ⟶ a}
/-- The lift of `g` along `f`. -/
abbrev lift (t : RightLift f g) : c ⟶ b := t.left
/-- The 2-morphism filling the triangle diagram. -/
abbrev counit (t : RightLift f g) : t.lift ≫ f ⟶ g := t.hom
/-- Construct a right lift from a 1-morphism and a 2-morphism. -/
abbrev mk (h : c ⟶ b) (counit : h ≫ f ⟶ g) : RightLift f g :=
CostructuredArrow.mk counit
/-- To construct a morphism between right lifts, we need a 2-morphism between the lifts,
and to check that it is compatible with the counits. -/
abbrev homMk {s t : RightLift f g} (η : s.lift ⟶ t.lift) (w : η ▷ f ≫ t.counit = s.counit) :
s ⟶ t :=
CostructuredArrow.homMk η w
@[reassoc (attr := simp)]
theorem w {s t : RightLift f g} (h : s ⟶ t) :
h.left ▷ f ≫ t.counit = s.counit :=
CostructuredArrow.w h
/-- The right lift along the identity. -/
def alongId (g : c ⟶ a) : RightLift (𝟙 a) g := .mk _ (ρ_ g).hom
instance : Inhabited (RightLift (𝟙 a) g) := ⟨alongId g⟩
end RightLift
end Bicategory
end CategoryTheory
|
integral_char.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action countalg finalg zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow gseries.
From mathcomp Require Import nilpotent abelian ssrnum ssrint archimedean.
From mathcomp Require Import polydiv rat matrix mxalgebra intdiv mxpoly vector.
From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic.
From mathcomp Require Import algnum mxrepresentation classfun character.
(******************************************************************************)
(* This file provides some standard results based on integrality properties *)
(* of characters, such as theorem asserting that the degree of an irreducible *)
(* character of G divides the order of G (Isaacs 3.11), or the famous p^a.q^b *)
(* solvability theorem of Burnside. *)
(* Defined here: *)
(* 'K_k == the kth class sum in gring F G, where k : 'I_#|classes G|, and *)
(* F is inferred from the context. *)
(* := gset_mx F G (enum_val k) (see mxrepresentation.v). *)
(* --> The 'K_k form a basis of 'Z(group_ring F G)%MS. *)
(* gring_classM_coef i j k == the coordinate of 'K_i *m 'K_j on 'K_k; this *)
(* is usually abbreviated as a i j k. *)
(* gring_classM_coef_set A B z == the set of all (x, y) in setX A B such *)
(* that x * y = z; if A and B are respectively the ith and jth *)
(* conjugacy class of G, and z is in the kth conjugacy class, then *)
(* gring_classM_coef i j k is exactly the cardinal of this set. *)
(* 'omega_i[A] == the mode of 'chi[G]_i on (A \in 'Z(group_ring algC G))%MS, *)
(* i.e., the z such that gring_op 'Chi_i A = z%:M. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Lemma group_num_field_exists (gT : finGroupType) (G : {group gT}) :
{Qn : splittingFieldType rat & galois 1 {:Qn} &
{QnC : {rmorphism Qn -> algC}
& forall nuQn : argumentType [in 'Gal({:Qn} / 1)],
{nu : {rmorphism algC -> algC} |
{morph QnC: a / nuQn a >-> nu a}}
& {w : Qn & #|G|.-primitive_root w /\ <<1; w>>%VS = fullv
& forall (hT : finGroupType) (H : {group hT}) (phi : 'CF(H)),
phi \is a character ->
forall x, (#[x] %| #|G|)%N -> {a | QnC a = phi x}}}}.
Proof.
have [z prim_z] := C_prim_root_exists (cardG_gt0 G); set n := #|G| in prim_z *.
have [Qn [QnC [[|w []] // [Dz] genQn]]] := num_field_exists [:: z].
have prim_w: n.-primitive_root w by rewrite -Dz fmorph_primitive_root in prim_z.
have Q_Xn1: ('X^n - 1 : {poly Qn}) \is a polyOver 1%AS.
by rewrite rpredB ?rpred1 ?rpredX //= polyOverX.
have splitXn1: splittingFieldFor 1 ('X^n - 1) {:Qn}.
pose r := codom (fun i : 'I_n => w ^+ i).
have Dr: 'X^n - 1 = \prod_(y <- r) ('X - y%:P).
by rewrite -(factor_Xn_sub_1 prim_w) big_mkord big_image.
exists r; first by rewrite -Dr eqpxx.
apply/eqP; rewrite eqEsubv subvf -genQn adjoin_seqSr //; apply/allP=> /=.
by rewrite andbT -root_prod_XsubC -Dr; apply/unity_rootP/prim_expr_order.
have Qn_ax : FieldExt_isSplittingField _ Qn by constructor; exists ('X^n - 1).
exists (HB.pack_for (splittingFieldType rat) Qn Qn_ax).
apply/splitting_galoisField.
exists ('X^n - 1); split => //.
apply: separable_Xn_sub_1; rewrite -(fmorph_eq0 QnC) rmorph_nat.
by rewrite pnatr_eq0 -lt0n cardG_gt0.
exists QnC => [// nuQn|]; first exact: (extend_algC_subfield_aut QnC nuQn).
rewrite span_seq1 in genQn.
exists w => // hT H phi Nphi x x_dv_n.
apply: sig_eqW; have [rH ->] := char_reprP Nphi.
have [Hx | /cfun0->] := boolP (x \in H); last by exists 0; rewrite rmorph0.
have [e [_ [enx1 _] [-> _] _]] := repr_rsim_diag rH Hx.
have /fin_all_exists[k Dk] i: exists k, e 0 i = z ^+ k.
have [|k ->] := (prim_rootP prim_z) (e 0 i); last by exists k.
by have /dvdnP[q ->] := x_dv_n; rewrite mulnC exprM enx1 expr1n.
exists (\sum_i w ^+ k i); rewrite rmorph_sum; apply/eq_bigr => i _.
by rewrite rmorphXn /= Dz Dk.
Qed.
Section GenericClassSums.
(* This is Isaacs, Theorem (2.4), generalized to an arbitrary field, and with *)
(* the combinatorial definition of the coefficients exposed. *)
(* This part could move to mxrepresentation.*)
Variable (gT : finGroupType) (G : {group gT}) (F : fieldType).
Definition gring_classM_coef_set (Ki Kj : {set gT}) g :=
[set xy in [predX Ki & Kj] | let: (x, y) := xy in x * y == g]%g.
Definition gring_classM_coef (i j k : 'I_#|classes G|) :=
#|gring_classM_coef_set (enum_val i) (enum_val j) (repr (enum_val k))|.
Definition gring_class_sum (i : 'I_#|classes G|) := gset_mx F G (enum_val i).
Local Notation "''K_' i" := (gring_class_sum i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Local Notation a := gring_classM_coef.
Lemma gring_class_sum_central i : ('K_i \in 'Z(group_ring F G))%MS.
Proof. by rewrite -classg_base_center (eq_row_sub i) // rowK. Qed.
Lemma set_gring_classM_coef (i j k : 'I_#|classes G|) g :
g \in enum_val k ->
a i j k = #|gring_classM_coef_set (enum_val i) (enum_val j) g|.
Proof.
rewrite /a; have /repr_classesP[] := enum_valP k; move: (repr _) => g1 Gg1 ->.
have [/imsetP[zi Gzi ->] /imsetP[zj Gzj ->]] := (enum_valP i, enum_valP j).
move=> g1Gg; have Gg := subsetP (class_subG Gg1 (subxx _)) _ g1Gg.
set Aij := gring_classM_coef_set _ _.
without loss suffices IH: g g1 Gg Gg1 g1Gg / (#|Aij g1| <= #|Aij g|)%N.
by apply/eqP; rewrite eqn_leq !IH // class_sym.
have [w Gw Dg] := imsetP g1Gg; pose J2 (v : gT) xy := (xy.1 ^ v, xy.2 ^ v)%g.
have J2inj: injective (J2 w).
by apply: can_inj (J2 w^-1)%g _ => [[x y]]; rewrite /J2 /= !conjgK.
rewrite -(card_imset _ J2inj) subset_leq_card //; apply/subsetP.
move=> _ /imsetP[[x y] /setIdP[/andP[/= x1Gx y1Gy] Dxy1] ->] /[!inE]/=.
rewrite !(class_sym _ (_ ^ _)) !classGidl // class_sym x1Gx class_sym y1Gy.
by rewrite -conjMg (eqP Dxy1) /= -Dg.
Qed.
Theorem gring_classM_expansion i j : 'K_i *m 'K_j = \sum_k (a i j k)%:R *: 'K_k.
Proof.
have [/imsetP[zi Gzi dKi] /imsetP[zj Gzj dKj]] := (enum_valP i, enum_valP j).
pose aG := regular_repr F G; have sKG := subsetP (class_subG _ (subxx G)).
transitivity (\sum_(x in zi ^: G) \sum_(y in zj ^: G) aG (x * y)%g).
rewrite mulmx_suml -/aG dKi; apply: eq_bigr => x /sKG Gx.
rewrite mulmx_sumr -/aG dKj; apply: eq_bigr => y /sKG Gy.
by rewrite repr_mxM ?Gx ?Gy.
pose h2 xy : gT := (xy.1 * xy.2)%g.
pose h1 xy := enum_rank_in (classes1 G) (h2 xy ^: G).
rewrite pair_big (partition_big h1 xpredT) //=; apply: eq_bigr => k _.
rewrite (partition_big h2 [in enum_val k]) /= => [|[x y]]; last first.
case/andP=> /andP[/= /sKG Gx /sKG Gy] /eqP <-.
by rewrite enum_rankK_in ?class_refl ?mem_classes ?groupM ?Gx ?Gy.
rewrite scaler_sumr; apply: eq_bigr => g Kk_g; rewrite scaler_nat.
rewrite (set_gring_classM_coef _ _ Kk_g) -sumr_const; apply: eq_big => [] [x y].
rewrite !inE /= dKi dKj /h1 /h2 /=; apply: andb_id2r => /eqP ->.
have /imsetP[zk Gzk dKk] := enum_valP k; rewrite dKk in Kk_g.
by rewrite (class_eqP Kk_g) -dKk enum_valK_in eqxx andbT.
by rewrite /h2 /= => /andP[_ /eqP->].
Qed.
End GenericClassSums.
HB.lock Definition gring_irr_mode (gT : finGroupType) (G : {group gT})
(i : Iirr G) := ('chi_i 1%g)^-1 *: 'chi_i.
Canonical gring_irr_mode_unlockable := Unlockable gring_irr_mode.unlock.
Arguments gring_irr_mode {gT G%_G} i%_R _%_g : extra scopes.
Notation "''K_' i" := (gring_class_sum _ i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Notation "''omega_' i [ A ]" := (xcfun (gring_irr_mode i) A)
(i at level 2, format "''omega_' i [ A ]") : ring_scope.
Section IntegralChar.
Variables (gT : finGroupType) (G : {group gT}).
(* This is Isaacs, Corollary (3.6). *)
Lemma Aint_char (chi : 'CF(G)) x : chi \is a character -> chi x \in Aint.
Proof.
have [Gx /char_reprP[rG ->] {chi} | /cfun0->//] := boolP (x \in G).
have [e [_ [unit_e _] [-> _] _]] := repr_rsim_diag rG Gx.
rewrite rpred_sum // => i _; apply: (@Aint_unity_root #[x]) => //.
exact/unity_rootP.
Qed.
Lemma Aint_irr i x : 'chi[G]_i x \in Aint.
Proof. exact/Aint_char/irr_char. Qed.
Local Notation R_G := (group_ring algCfield G).
Local Notation a := gring_classM_coef.
(* This is Isaacs (2.25). *)
Lemma mx_irr_gring_op_center_scalar n (rG : mx_representation algCfield G n) A :
mx_irreducible rG -> (A \in 'Z(R_G))%MS -> is_scalar_mx (gring_op rG A).
Proof.
move/groupC=> irrG /center_mxP[R_A cGA].
apply: mx_abs_irr_cent_scalar irrG _ _; apply/centgmxP => x Gx.
by rewrite -(gring_opG rG Gx) -!gring_opM ?cGA // envelop_mx_id.
Qed.
Section GringIrrMode.
Variable i : Iirr G.
Let n := irr_degree (socle_of_Iirr i).
Let mxZn_inj: injective (@scalar_mx algCfield n).
Proof. by rewrite -[n]prednK ?irr_degree_gt0 //; apply: fmorph_inj. Qed.
Lemma cfRepr_gring_center n1 (rG : mx_representation algCfield G n1) A :
cfRepr rG = 'chi_i -> (A \in 'Z(R_G))%MS -> gring_op rG A = 'omega_i[A]%:M.
Proof.
move=> def_rG Z_A; rewrite unlock xcfunZl -{2}def_rG xcfun_repr.
have irr_rG: mx_irreducible rG.
have sim_rG: mx_rsim 'Chi_i rG by apply: cfRepr_inj; rewrite irrRepr.
exact: mx_rsim_irr sim_rG (socle_irr _).
have /is_scalar_mxP[e ->] := mx_irr_gring_op_center_scalar irr_rG Z_A.
congr _%:M; apply: (canRL (mulKf (irr1_neq0 i))).
by rewrite mulrC -def_rG cfunE repr_mx1 group1 -mxtraceZ scalemx1.
Qed.
Lemma irr_gring_center A :
(A \in 'Z(R_G))%MS -> gring_op 'Chi_i A = 'omega_i[A]%:M.
Proof. exact: cfRepr_gring_center (irrRepr i). Qed.
Lemma gring_irr_modeM A B :
(A \in 'Z(R_G))%MS -> (B \in 'Z(R_G))%MS ->
'omega_i[A *m B] = 'omega_i[A] * 'omega_i[B].
Proof.
move=> Z_A Z_B; have [[R_A cRA] [R_B cRB]] := (center_mxP Z_A, center_mxP Z_B).
apply: mxZn_inj; rewrite scalar_mxM -!irr_gring_center ?gring_opM //.
apply/center_mxP; split=> [|C R_C]; first exact: envelop_mxM.
by rewrite mulmxA cRA // -!mulmxA cRB.
Qed.
Lemma gring_mode_class_sum_eq (k : 'I_#|classes G|) g :
g \in enum_val k -> 'omega_i['K_k] = #|g ^: G|%:R * 'chi_i g / 'chi_i 1%g.
Proof.
have /imsetP[x Gx DxG] := enum_valP k; rewrite DxG => /imsetP[u Gu ->{g}].
rewrite unlock classGidl ?cfunJ {u Gu}// mulrC mulr_natl.
rewrite xcfunZl raddf_sum DxG -sumr_const /=; congr (_ * _).
by apply: eq_bigr => _ /imsetP[u Gu ->]; rewrite xcfunG ?groupJ ?cfunJ.
Qed.
(* This is Isaacs, Theorem (3.7). *)
Lemma Aint_gring_mode_class_sum k : 'omega_i['K_k] \in Aint.
Proof.
move: k; pose X := [tuple 'omega_i['K_k] | k < #|classes G| ].
have memX k: 'omega_i['K_k] \in X by apply: image_f.
have S_P := Cint_spanP X; set S := Cint_span X in S_P.
have S_X: {subset X <= S} by apply: mem_Cint_span.
have S_1: 1 \in S.
apply: S_X; apply/codomP; exists (enum_rank_in (classes1 G) 1%g).
rewrite (@gring_mode_class_sum_eq _ 1%g) ?enum_rankK_in ?classes1 //.
by rewrite mulfK ?irr1_neq0 // class1G cards1.
suffices Smul: mulr_closed S.
by move=> k; apply: fin_Csubring_Aint S_P _ _; rewrite ?S_X.
split=> // _ _ /S_P[x ->] /S_P[y ->].
rewrite mulr_sumr rpred_sum // => j _.
rewrite mulrzAr mulr_suml rpredMz ?rpred_sum // => k _.
rewrite mulrzAl rpredMz {x y}// !nth_mktuple.
rewrite -gring_irr_modeM ?gring_class_sum_central //.
rewrite gring_classM_expansion raddf_sum rpred_sum // => jk _.
by rewrite scaler_nat raddfMn rpredMn ?S_X ?memX.
Qed.
(* A more usable reformulation that does not involve the class sums. *)
Corollary Aint_class_div_irr1 x :
x \in G -> #|x ^: G|%:R * 'chi_i x / 'chi_i 1%g \in Aint.
Proof.
move=> Gx; have clGxG := mem_classes Gx; pose k := enum_rank_in clGxG (x ^: G).
have k_x: x \in enum_val k by rewrite enum_rankK_in // class_refl.
by rewrite -(gring_mode_class_sum_eq k_x) Aint_gring_mode_class_sum.
Qed.
(* This is Isaacs, Theorem (3.8). *)
Theorem coprime_degree_support_cfcenter g :
coprime (Num.truncn ('chi_i 1%g)) #|g ^: G| -> g \notin ('Z('chi_i))%CF ->
'chi_i g = 0.
Proof.
set m := Num.truncn _ => co_m_gG notZg.
have [Gg | /cfun0-> //] := boolP (g \in G).
have Dm: 'chi_i 1%g = m%:R by rewrite truncnK ?Cnat_irr1.
have m_gt0: (0 < m)%N by rewrite -ltC_nat -Dm irr1_gt0.
have nz_m: m%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n.
pose alpha := 'chi_i g / m%:R.
have a_lt1: `|alpha| < 1.
rewrite normrM normfV normr_nat -{2}(divff nz_m).
rewrite lt_def (can_eq (mulfVK nz_m)) eq_sym -{1}Dm -irr_cfcenterE // notZg.
by rewrite ler_pM2r ?invr_gt0 ?ltr0n // -Dm char1_ge_norm ?irr_char.
have Za: alpha \in Aint.
have [u _ /dvdnP[v eq_uv]] := Bezoutl #|g ^: G| m_gt0.
suffices ->: alpha = v%:R * 'chi_i g - u%:R * (alpha * #|g ^: G|%:R).
rewrite rpredB // rpredM ?rpred_nat ?Aint_irr //.
by rewrite mulrC mulrA -Dm Aint_class_div_irr1.
rewrite -mulrCA -[v%:R](mulfK nz_m) -!natrM -eq_uv (eqnP co_m_gG).
by rewrite mulrAC -mulrA -/alpha mulr_natl mulr_natr mulrS addrK.
have [Qn galQn [QnC gQnC [_ _ Qn_g]]] := group_num_field_exists <[g]>.
have{Qn_g} [a Da]: exists a, QnC a = alpha.
rewrite /alpha; have [a <-] := Qn_g _ G _ (irr_char i) g (dvdnn _).
by exists (a / m%:R); rewrite fmorph_div rmorph_nat.
have Za_nu nu: sval (gQnC nu) alpha \in Aint by rewrite Aint_aut.
have norm_a_nu nu: `|sval (gQnC nu) alpha| <= 1.
move: {nu}(sval _) => nu; rewrite fmorph_div rmorph_nat normrM normfV.
rewrite normr_nat -Dm -(ler_pM2r (irr1_gt0 (aut_Iirr nu i))) mul1r.
congr (_ <= _): (char1_ge_norm g (irr_char (aut_Iirr nu i))).
by rewrite !aut_IirrE !cfunE Dm rmorph_nat divfK.
pose beta := QnC (galNorm 1 {:Qn} a).
have Dbeta: beta = \prod_(nu in 'Gal({:Qn} / 1)) sval (gQnC nu) alpha.
rewrite /beta rmorph_prod. apply: eq_bigr => nu _.
by case: (gQnC nu) => f /= ->; rewrite Da.
have Zbeta: beta \in Num.int.
apply: Cint_rat_Aint; last by rewrite Dbeta rpred_prod.
rewrite /beta; have /vlineP[/= c ->] := mem_galNorm galQn (memvf a).
by rewrite alg_num_field fmorph_rat rpred_rat.
have [|nz_a] := boolP (alpha == 0).
by rewrite (can2_eq (divfK _) (mulfK _)) // mul0r => /eqP.
have: beta != 0 by rewrite Dbeta; apply/prodf_neq0 => nu _; rewrite fmorph_eq0.
move/(norm_intr_ge1 Zbeta); rewrite lt_geF //; apply: le_lt_trans a_lt1.
rewrite -[`|alpha|]mulr1 Dbeta (bigD1 1%g) ?group1 //= -Da.
case: (gQnC _) => /= _ <-.
rewrite gal_id normrM -subr_ge0 -mulrBr mulr_ge0 // Da subr_ge0.
elim/big_rec: _ => [|nu c _]; first by rewrite normr1 lexx.
apply: le_trans; rewrite -subr_ge0 -{1}[`|c|]mul1r normrM -mulrBl.
by rewrite mulr_ge0 // subr_ge0 norm_a_nu.
Qed.
End GringIrrMode.
(* This is Isaacs, Theorem (3.9). *)
Theorem primes_class_simple_gt1 C :
simple G -> ~~ abelian G -> C \in (classes G)^# -> (size (primes #|C|) > 1)%N.
Proof.
move=> simpleG not_cGG /setD1P[ntC /imsetP[g Gg defC]].
have{ntC} nt_g: g != 1%g by rewrite defC classG_eq1 in ntC.
rewrite ltnNge {C}defC; set m := #|_|; apply/negP=> p_natC.
have{p_natC} [p p_pr [a Dm]]: {p : nat & prime p & {a | m = p ^ a}%N}.
have /prod_prime_decomp->: (0 < m)%N by rewrite /m -index_cent1.
rewrite prime_decompE; case Dpr: (primes _) p_natC => [|p []] // _.
by exists 2%N => //; rewrite big_nil; exists 0.
rewrite big_seq1; exists p; last by exists (logn p m).
by have:= mem_primes p m; rewrite Dpr mem_head => /esym/and3P[].
have{simpleG} [ntG minG] := simpleP _ simpleG.
pose p_dv1 i := (p %| 'chi[G]_i 1%g)%C.
have p_dvd_supp_g i: ~~ p_dv1 i && (i != 0) -> 'chi_i g = 0.
rewrite /p_dv1 irr1_degree dvdC_nat -prime_coprime // => /andP[co_p_i1 nz_i].
have fful_i: cfker 'chi_i = [1].
have /minG[//|/eqP] := cfker_normal 'chi_i.
by rewrite eqEsubset subGcfker (negPf nz_i) andbF.
have trivZ: 'Z(G) = [1] by have /minG[|/center_idP/idPn] := center_normal G.
have trivZi: ('Z('chi_i))%CF = [1].
apply/trivgP; rewrite -quotient_sub1 ?norms1 //= -fful_i cfcenter_eq_center.
rewrite fful_i subG1 -(isog_eq1 (isog_center (quotient1_isog G))) /=.
by rewrite trivZ.
rewrite coprime_degree_support_cfcenter ?trivZi ?inE //.
by rewrite -/m Dm irr1_degree natrK coprime_sym coprimeXl.
pose alpha := \sum_(i | p_dv1 i && (i != 0)) 'chi_i 1%g / p%:R * 'chi_i g.
have nz_p: p%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n prime_gt0.
have Dalpha: alpha = - 1 / p%:R.
apply/(canRL (mulfK nz_p))/eqP; rewrite -addr_eq0 addrC; apply/eqP/esym.
transitivity (cfReg G g); first by rewrite cfRegE (negPf nt_g).
rewrite cfReg_sum sum_cfunE (bigD1 0) //= irr0 !cfunE cfun11 cfun1E Gg.
rewrite mulr1; congr (1 + _); rewrite (bigID p_dv1) /= addrC big_andbC.
rewrite big1 => [|i /p_dvd_supp_g chig0]; last by rewrite cfunE chig0 mulr0.
rewrite add0r big_andbC mulr_suml; apply: eq_bigr => i _.
by rewrite mulrAC divfK // cfunE.
suffices: (p %| 1)%C by rewrite (dvdC_nat p 1) dvdn1 -(subnKC (prime_gt1 p_pr)).
rewrite unfold_in (negPf nz_p).
rewrite Cint_rat_Aint ?rpred_div ?rpred1 ?rpred_nat //.
rewrite -rpredN // -mulNr -Dalpha rpred_sum // => i /andP[/dvdCP[c Zc ->] _].
by rewrite mulfK // rpredM ?Aint_irr ?Aint_Cint.
Qed.
End IntegralChar.
Section MoreIntegralChar.
Implicit Type gT : finGroupType.
(* This is Burnside's famous p^a.q^b theorem (Isaacs, Theorem (3.10)). *)
Theorem Burnside_p_a_q_b gT (G : {group gT}) :
(size (primes #|G|) <= 2)%N -> solvable G.
Proof.
move: {2}_.+1 (ltnSn #|G|) => n; elim: n => // n IHn in gT G *.
rewrite ltnS => leGn piGle2; have [simpleG | ] := boolP (simple G); last first.
rewrite negb_forall_in => /exists_inP[N sNG]; rewrite eq_sym.
have [->|] := eqVneq N G.
rewrite groupP /= genGid normG andbT eqb_id negbK => /eqP->.
exact: solvable1.
rewrite [N == G]eqEproper sNG eqbF_neg !negbK => ltNG /and3P[grN].
case/isgroupP: grN => {}N -> in sNG ltNG *; rewrite /= genGid => ntN nNG.
have nsNG: N <| G by apply/andP.
have dv_le_pi m: (m %| #|G| -> size (primes m) <= 2)%N.
move=> m_dv_G; apply: leq_trans piGle2.
by rewrite uniq_leq_size ?primes_uniq //; apply: pi_of_dvd.
rewrite (series_sol nsNG) !IHn ?dv_le_pi ?cardSg ?dvdn_quotient //.
by apply: leq_trans leGn; apply: ltn_quotient.
by apply: leq_trans leGn; apply: proper_card.
have [->|[p p_pr p_dv_G]] := trivgVpdiv G; first exact: solvable1.
have piGp: p \in \pi(G) by rewrite mem_primes p_pr cardG_gt0.
have [P sylP] := Sylow_exists p G; have [sPG pP p'GP] := and3P sylP.
have ntP: P :!=: 1%g by rewrite -rank_gt0 (rank_Sylow sylP) p_rank_gt0.
have /trivgPn[g /setIP[Pg cPg] nt_g]: 'Z(P) != 1%g.
by rewrite center_nil_eq1 // (pgroup_nil pP).
apply: abelian_sol; have: (size (primes #|g ^: G|) <= 1)%N.
rewrite -ltnS -[_.+1]/(size (p :: _)) (leq_trans _ piGle2) //.
rewrite -index_cent1 uniq_leq_size // => [/= | q].
rewrite primes_uniq -p'natEpi ?(pnat_dvd _ p'GP) ?indexgS //.
by rewrite subsetI sPG sub_cent1.
by rewrite inE => /predU1P[-> // |]; apply: pi_of_dvd; rewrite ?dvdn_indexg.
rewrite leqNgt; apply: contraR => /primes_class_simple_gt1-> //.
by rewrite !inE classG_eq1 nt_g mem_classes // (subsetP sPG).
Qed.
(* This is Isaacs, Theorem (3.11). *)
Theorem dvd_irr1_cardG gT (G : {group gT}) i : ('chi[G]_i 1%g %| #|G|)%C.
Proof.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //=.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite -[n in n / _]/(_ *+ true) -(eqxx i) -mulr_natr.
rewrite -first_orthogonality_relation mulVKf ?neq0CG //.
rewrite sum_by_classes => [|x y Gx Gy]; rewrite -?conjVg ?cfunJ //.
rewrite mulr_suml rpred_sum // => K /repr_classesP[Gx {1}->].
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
Qed.
(* This is Isaacs, Theorem (3.12). *)
Theorem dvd_irr1_index_center gT (G : {group gT}) i :
('chi[G]_i 1%g %| #|G : 'Z('chi_i)%CF|)%C.
Proof.
without loss fful: gT G i / cfaithful 'chi_i.
rewrite -{2}[i](quo_IirrK _ (subxx _)) 1?mod_IirrE ?cfModE ?cfker_normal //.
rewrite morph1; set i1 := quo_Iirr _ i => /(_ _ _ i1) IH.
have fful_i1: cfaithful 'chi_i1.
by rewrite quo_IirrE ?cfker_normal ?cfaithful_quo.
have:= IH fful_i1; rewrite cfcenter_fful_irr // -cfcenter_eq_center.
rewrite index_quotient_eq ?cfcenter_sub ?cfker_norm //.
by rewrite setIC subIset // normal_sub ?cfker_center_normal.
have [lambda lin_lambda Dlambda] := cfcenter_Res 'chi_i.
have DchiZ: {in G & 'Z(G), forall x y, 'chi_i (x * y)%g = 'chi_i x * lambda y}.
rewrite -(cfcenter_fful_irr fful) => x y Gx Zy.
apply: (mulfI (irr1_neq0 i)); rewrite mulrCA.
transitivity ('chi_i x * ('chi_i 1%g *: lambda) y); last by rewrite !cfunE.
rewrite -Dlambda cfResE ?cfcenter_sub //.
rewrite -irrRepr cfcenter_repr !cfunE in Zy *.
case/setIdP: Zy => Gy /is_scalar_mxP[e De].
rewrite repr_mx1 group1 (groupM Gx Gy) (repr_mxM _ Gx Gy) Gx Gy De.
by rewrite mul_mx_scalar mxtraceZ mulrCA mulrA mulrC -mxtraceZ scalemx1.
have inj_lambda: {in 'Z(G) &, injective lambda}.
rewrite -(cfcenter_fful_irr fful) => x y Zx Zy eq_xy.
apply/eqP; rewrite eq_mulVg1 -in_set1 (subsetP fful) // cfkerEirr inE.
apply/eqP; transitivity ('Res['Z('chi_i)%CF] 'chi_i (x^-1 * y)%g).
by rewrite cfResE ?cfcenter_sub // groupM ?groupV.
rewrite Dlambda !cfunE lin_charM ?groupV // -eq_xy -lin_charM ?groupV //.
by rewrite mulrC mulVg lin_char1 ?mul1r.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite (cfcenter_fful_irr fful) nCdivE natf_indexg ?center_sub //=.
have ->: #|G|%:R = \sum_(x in G) 'chi_i x * 'chi_i (x^-1)%g.
rewrite -[_%:R]mulr1; apply: canLR (mulVKf (neq0CG G)) _.
by rewrite first_orthogonality_relation eqxx.
rewrite (big_setID [set x | 'chi_i x == 0]) /= -setIdE.
rewrite big1 ?add0r => [| x /setIdP[_ /eqP->]]; last by rewrite mul0r.
pose h x := (x ^: G * 'Z(G))%g; rewrite (partition_big_imset h).
rewrite !mulr_suml rpred_sum //= => _ /imsetP[x /setDP[Gx nz_chi_x] ->].
have: #|x ^: G|%:R * ('chi_i x * 'chi_i x^-1%g) / 'chi_i 1%g \in Aint.
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
congr 2 (_ * _ \in Aint); apply: canRL (mulfK (neq0CG _)) _.
rewrite inE in nz_chi_x.
transitivity ('chi_i x * 'chi_i (x^-1)%g *+ #|h x|); last first.
rewrite -sumr_const.
apply: eq_big => [y | _ /mulsgP[_ z /imsetP[u Gu ->] Zz] ->].
rewrite !inE -andbA; apply/idP/and3P=> [|[_ _ /eqP <-]]; last first.
by rewrite -{1}[y]mulg1 mem_mulg ?class_refl.
case/mulsgP=> _ z /imsetP[u Gu ->] Zz ->; have /centerP[Gz cGz] := Zz.
rewrite groupM 1?DchiZ ?groupJ ?cfunJ //; split=> //.
by rewrite mulf_neq0 // lin_char_neq0 /= ?cfcenter_fful_irr.
rewrite -[z](mulKg u) -cGz // -conjMg /h classGidl {u Gu}//.
apply/eqP/setP=> w; apply/mulsgP/mulsgP=> [][_ z1 /imsetP[v Gv ->] Zz1 ->].
exists (x ^ v)%g (z * z1)%g; rewrite ?imset_f ?groupM //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg.
exists ((x * z) ^ v)%g (z^-1 * z1)%g; rewrite ?imset_f ?groupM ?groupV //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg mulKVg.
rewrite !irr_inv DchiZ ?groupJ ?cfunJ // rmorphM mulrACA -!normCK -exprMn.
by rewrite (normC_lin_char lin_lambda) ?mulr1 //= cfcenter_fful_irr.
rewrite mulrAC -natrM mulr_natl; congr (_ *+ _).
symmetry; rewrite /h /mulg /= /set_mulg [in _ @2: (_, _)]unlock cardsE.
rewrite -cardX card_in_image // => [] [y1 z1] [y2 z2] /=.
move=> /andP[/=/imsetP[u1 Gu1 ->] Zz1] /andP[/=/imsetP[u2 Gu2 ->] Zz2] {y1 y2}.
move=> eq12; have /eqP := congr1 'chi_i eq12.
rewrite !(cfunJ, DchiZ) ?groupJ // (can_eq (mulKf nz_chi_x)).
rewrite (inj_in_eq inj_lambda) // => /eqP eq_z12; rewrite eq_z12 in eq12 *.
by rewrite (mulIg _ _ _ eq12).
Qed.
(* This is Isaacs, Problem (3.7). *)
Lemma gring_classM_coef_sum_eq gT (G : {group gT}) j1 j2 k g1 g2 g :
let a := @gring_classM_coef gT G j1 j2 in let a_k := a k in
g1 \in enum_val j1 -> g2 \in enum_val j2 -> g \in enum_val k ->
let sum12g := \sum_i 'chi[G]_i g1 * 'chi_i g2 * ('chi_i g)^* / 'chi_i 1%g in
a_k%:R = (#|enum_val j1| * #|enum_val j2|)%:R / #|G|%:R * sum12g.
Proof.
move=> a /= Kg1 Kg2 Kg; rewrite mulrAC; apply: canRL (mulfK (neq0CG G)) _.
transitivity (\sum_j (#|G| * a j)%:R *+ (j == k) : algC).
by rewrite (bigD1 k) //= eqxx -natrM mulnC big1 ?addr0 // => j /negPf->.
have defK (j : 'I_#|classes G|) x: x \in enum_val j -> enum_val j = x ^: G.
by have /imsetP[y Gy ->] := enum_valP j => /class_eqP.
have Gg: g \in G.
by case/imsetP: (enum_valP k) Kg => x Gx -> /imsetP[y Gy ->]; apply: groupJ.
transitivity (\sum_j \sum_i 'omega_i['K_j] * 'chi_i 1%g * ('chi_i g)^* *+ a j).
apply: eq_bigr => j _; have /imsetP[z Gz Dj] := enum_valP j.
have Kz: z \in enum_val j by rewrite Dj class_refl.
rewrite -(Lagrange (subsetIl G 'C[z])) index_cent1 -mulnA natrM -mulrnAl.
have ->: (j == k) = (z \in enum_val k).
by rewrite -(inj_eq enum_val_inj); apply/eqP/idP=> [<-|/defK->].
rewrite (defK _ g) // -second_orthogonality_relation // mulr_suml.
apply: eq_bigr=> i _; rewrite natrM mulrA mulr_natr mulrC mulrA.
by rewrite (gring_mode_class_sum_eq i Kz) divfK ?irr1_neq0.
rewrite exchange_big /= mulr_sumr; apply: eq_bigr => i _.
transitivity ('omega_i['K_j1 *m 'K_j2] * 'chi_i 1%g * ('chi_i g)^*).
rewrite gring_classM_expansion -/a raddf_sum !mulr_suml /=.
by apply: eq_bigr => j _; rewrite xcfunZr -!mulrA mulr_natl.
rewrite !mulrA 2![_ / _]mulrAC (defK _ _ Kg1) (defK _ _ Kg2); congr (_ * _).
rewrite gring_irr_modeM ?gring_class_sum_central // mulnC natrM.
rewrite (gring_mode_class_sum_eq i Kg2) !mulrA divfK ?irr1_neq0 //.
by congr (_ * _); rewrite [_ * _]mulrC (gring_mode_class_sum_eq i Kg1) !mulrA.
Qed.
(* This is Isaacs, Problem (2.16). *)
Lemma index_support_dvd_degree gT (G H : {group gT}) chi :
H \subset G -> chi \is a character -> chi \in 'CF(G, H) ->
(H :==: 1%g) || abelian G ->
(#|G : H| %| chi 1%g)%C.
Proof.
move=> sHG Nchi Hchi ZHG.
suffices: (#|G : H| %| 'Res[H] chi 1%g)%C by rewrite cfResE ?group1.
rewrite ['Res _]cfun_sum_cfdot sum_cfunE rpred_sum // => i _.
rewrite cfunE dvdC_mulr ?intr_nat ?Cnat_irr1 //.
have [j ->]: exists j, 'chi_i = 'Res 'chi[G]_j.
case/predU1P: ZHG => [-> | cGG] in i *.
suffices ->: i = 0 by exists 0; rewrite !irr0 cfRes_cfun1 ?sub1G.
apply/val_inj; case: i => [[|i] //=]; rewrite ltnNge NirrE.
by rewrite (@leq_trans 1) // leqNgt classes_gt1 eqxx.
have linG := char_abelianP G cGG; have linG1 j := eqP (proj2 (andP (linG j))).
have /fin_all_exists[rH DrH] j: exists k, 'Res[H, G] 'chi_j = 'chi_k.
apply/irrP/lin_char_irr/andP.
by rewrite cfRes_char ?irr_char // cfRes1 ?linG1.
suffices{i} all_rH: codom rH =i Iirr H.
by exists (iinv (all_rH i)); rewrite DrH f_iinv.
apply/subset_cardP; last exact/subsetP; apply/esym/eqP.
rewrite card_Iirr_abelian ?(abelianS sHG) //.
rewrite -(eqn_pmul2r (indexg_gt0 G H)) Lagrange //; apply/eqP.
rewrite -sum_nat_const -card_Iirr_abelian // -sum1_card.
rewrite (partition_big rH [in codom rH]) /=; last exact: image_f.
have nsHG: H <| G by rewrite -sub_abelian_normal.
apply: eq_bigr => _ /codomP[i ->]; rewrite -card_quotient ?normal_norm //.
rewrite -card_Iirr_abelian ?quotient_abelian //.
have Mlin j1 j2: exists k, 'chi_j1 * 'chi_j2 = 'chi[G]_k.
exact/irrP/lin_char_irr/rpredM.
have /fin_all_exists[rQ DrQ] (j : Iirr (G / H)) := Mlin i (mod_Iirr j).
have mulJi: ('chi[G]_i)^*%CF * 'chi_i = 1.
apply/cfun_inP=> x Gx; rewrite !cfunE /= -lin_charV_conj ?linG // cfun1E Gx.
by rewrite lin_charV ?mulVf ?lin_char_neq0 ?linG.
have inj_rQ: injective rQ.
move=> j1 j2 /(congr1 (fun k => (('chi_i)^*%CF * 'chi_k) / H)%CF).
by rewrite -!DrQ !mulrA mulJi !mul1r !mod_IirrE ?cfModK // => /irr_inj.
rewrite -(card_imset _ inj_rQ) -sum1_card; apply: eq_bigl => j.
rewrite -(inj_eq irr_inj) -!DrH; apply/eqP/imsetP=> [eq_ij | [k _ ->]].
have [k Dk] := Mlin (conjC_Iirr i) j; exists (quo_Iirr H k) => //.
apply/irr_inj; rewrite -DrQ quo_IirrK //.
by rewrite -Dk conjC_IirrE mulrCA mulrA mulJi mul1r.
apply/subsetP=> x Hx; have Gx := subsetP sHG x Hx.
rewrite cfkerEirr inE linG1 -Dk conjC_IirrE; apply/eqP.
transitivity ((1 : 'CF(G)) x); last by rewrite cfun1E Gx.
by rewrite -mulJi !cfunE -!(cfResE _ sHG Hx) eq_ij.
rewrite -DrQ; apply/cfun_inP=> x Hx; rewrite !cfResE // cfunE mulrC.
by rewrite cfker1 ?linG1 ?mul1r ?(subsetP _ x Hx) // mod_IirrE ?cfker_mod.
have: (#|G : H| %| #|G : H|%:R * '[chi, 'chi_j])%C.
by rewrite dvdC_mulr ?intr_nat ?Cnat_cfdot_char_irr.
congr (_ %| _)%C; rewrite (cfdotEl _ Hchi) -(Lagrange sHG) mulnC natrM.
rewrite invfM -mulrA mulVKf ?neq0CiG //; congr (_ * _).
by apply: eq_bigr => x Hx; rewrite !cfResE.
Qed.
(* This is Isaacs, Theorem (3.13). *)
Theorem faithful_degree_p_part gT (p : nat) (G P : {group gT}) i :
cfaithful 'chi[G]_i -> p.-nat (Num.truncn ('chi_i 1%g)) ->
p.-Sylow(G) P -> abelian P ->
'chi_i 1%g = (#|G : 'Z(G)|`_p)%:R.
Proof.
have [p_pr | pr'p] := boolP (prime p); last first.
have p'n n: (n > 0)%N -> p^'.-nat n.
by move/p'natEpi->; rewrite mem_primes (negPf pr'p).
rewrite irr1_degree natrK => _ /pnat_1-> => [_ _|].
by rewrite part_p'nat ?p'n.
by rewrite p'n ?irr_degree_gt0.
move=> fful_i /p_natP[a Dchi1] sylP cPP.
have Dchi1C: 'chi_i 1%g = (p ^ a)%:R by rewrite -Dchi1 irr1_degree natrK.
have pa_dv_ZiG: (p ^ a %| #|G : 'Z(G)|)%N.
rewrite -dvdC_nat -[pa in (pa %| _)%C]Dchi1C -(cfcenter_fful_irr fful_i).
exact: dvd_irr1_index_center.
have [sPG pP p'PiG] := and3P sylP.
have ZchiP: 'Res[P] 'chi_i \in 'CF(P, P :&: 'Z(G)).
apply/cfun_onP=> x /[1!inE]; have [Px | /cfun0->//] := boolP (x \in P).
rewrite /= -(cfcenter_fful_irr fful_i) cfResE //.
apply: coprime_degree_support_cfcenter.
rewrite Dchi1 coprimeXl // prime_coprime // -p'natE //.
apply: pnat_dvd p'PiG; rewrite -index_cent1 indexgS // subsetI sPG.
by rewrite sub_cent1 (subsetP cPP).
have /andP[_ nZG] := center_normal G; have nZP := subset_trans sPG nZG.
apply/eqP; rewrite Dchi1C eqr_nat eqn_dvd -{1}(pfactorK a p_pr) -p_part.
rewrite partn_dvd //= -dvdC_nat -[pa in (_ %| pa)%C]Dchi1C -card_quotient //=.
rewrite -(card_Hall (quotient_pHall nZP sylP)) card_quotient // -indexgI.
rewrite -(cfResE _ sPG) // index_support_dvd_degree ?subsetIl ?cPP ?orbT //.
by rewrite cfRes_char ?irr_char.
Qed.
(* This is Isaacs, Lemma (3.14). *)
(* Note that the assumption that G be cyclic is unnecessary, as S will be *)
(* empty if this is not the case. *)
Lemma sum_norm2_char_generators gT (G : {group gT}) (chi : 'CF(G)) :
let S := [pred s | generator G s] in
chi \is a character -> {in S, forall s, chi s != 0} ->
\sum_(s in S) `|chi s| ^+ 2 >= #|S|%:R.
Proof.
move=> S Nchi nz_chi_S; pose n := #|G|.
have [g Sg | S_0] := pickP (generator G); last first.
by rewrite eq_card0 // big_pred0 ?lerr.
have defG: <[g]> = G by apply/esym/eqP.
have [cycG Gg]: cyclic G /\ g \in G by rewrite -defG cycle_cyclic cycle_id.
pose I := {k : 'I_n | coprime n k}; pose ItoS (k : I) := (g ^+ sval k)%g.
have imItoS: codom ItoS =i S.
move=> s; rewrite inE /= /ItoS /I /n /S -defG -orderE.
apply/codomP/idP=> [[[i cogi] ->] | Ss]; first by rewrite generator_coprime.
have [m ltmg Ds] := cyclePmin (cycle_generator Ss).
by rewrite Ds generator_coprime in Ss; apply: ex_intro (Sub (Sub m _) _) _.
have /injectiveP injItoS: injective ItoS.
move=> k1 k2 /eqP; apply: contraTeq.
by rewrite eq_expg_mod_order orderE defG -/n !modn_small.
have [Qn galQn [QnC gQnC [eps [pr_eps defQn] QnG]]] := group_num_field_exists G.
have{QnG} QnGg := QnG _ G _ _ g (order_dvdG Gg).
pose calG := 'Gal({:Qn} / 1).
have /fin_all_exists2[ItoQ inItoQ defItoQ] (k : I):
exists2 nu, nu \in calG & nu eps = eps ^+ val k.
- case: k => [[m _] /=]; rewrite coprime_sym => /Qn_aut_exists[nuC DnuC].
have [nuQ DnuQ] := restrict_aut_to_normal_num_field QnC nuC.
have hom_nu: kHom 1 {:Qn} (linfun nuQ).
rewrite k1HomE; apply/ahom_inP.
by split=> [u v | ]; rewrite !lfunE ?rmorphM ?rmorph1.
have [|nu cGnu Dnu] := kHom_to_gal _ (normalFieldf 1) hom_nu.
by rewrite !subvf.
exists nu => //; apply: (fmorph_inj QnC).
rewrite -Dnu ?memvf // lfunE DnuQ rmorphXn DnuC //.
by rewrite prim_expr_order // fmorph_primitive_root.
have{defQn} imItoQ: calG = ItoQ @: {:I}.
apply/setP=> nu; apply/idP/imsetP=> [cGnu | [k _ ->] //].
have pr_nu_e: n.-primitive_root (nu eps) by rewrite fmorph_primitive_root.
have [i Dnue] := prim_rootP pr_eps (prim_expr_order pr_nu_e).
rewrite Dnue prim_root_exp_coprime // coprime_sym in pr_nu_e.
apply: ex_intro2 (Sub i _) _ _ => //; apply/eqP.
rewrite /calG /= -defQn in ItoQ inItoQ defItoQ nu cGnu Dnue *.
by rewrite gal_adjoin_eq // defItoQ -Dnue.
have injItoQ: {in {:I} &, injective ItoQ}.
move=> k1 k2 _ _ /(congr1 (fun nu : gal_of _ => nu eps))/eqP.
by apply: contraTeq; rewrite !defItoQ (eq_prim_root_expr pr_eps) !modn_small.
pose pi1 := \prod_(s in S) chi s; pose pi2 := \prod_(s in S) `|chi s| ^+ 2.
have Qpi1: pi1 \in Crat.
have [a Da] := QnGg _ Nchi; suffices ->: pi1 = QnC (galNorm 1 {:Qn} a).
have /vlineP[q ->] := mem_galNorm galQn (memvf a).
by rewrite rmorphZ_num rmorph1 mulr1 Crat_rat.
rewrite /galNorm rmorph_prod -/calG imItoQ big_imset //=.
rewrite /pi1 -(eq_bigl _ _ imItoS) -big_uniq // big_image /=.
apply: eq_bigr => k _; have [nuC DnuC] := gQnC (ItoQ k); rewrite DnuC Da.
have [r ->] := char_sum_irr Nchi; rewrite !sum_cfunE rmorph_sum.
apply: eq_bigr => i _; have /QnGg[b Db] := irr_char i.
have Lchi_i: 'chi_i \is a linear_char by rewrite irr_cyclic_lin.
have /(prim_rootP pr_eps)[m Dem]: b ^+ n = 1.
apply/eqP; rewrite -(fmorph_eq1 QnC) rmorphXn /= Db -lin_charX //.
by rewrite -expg_mod_order orderE defG modnn lin_char1.
rewrite -Db /= -DnuC Dem rmorphXn /= defItoQ exprAC -{m}Dem rmorphXn /= {b}Db.
by rewrite lin_charX.
clear I ItoS imItoS injItoS ItoQ inItoQ defItoQ imItoQ injItoQ.
clear Qn galQn QnC gQnC eps pr_eps QnGg calG.
have{Qpi1} Zpi1: pi1 \in Num.int.
by rewrite Cint_rat_Aint // rpred_prod // => s _; apply: Aint_char.
have{pi1 Zpi1} pi2_ge1: 1 <= pi2.
have ->: pi2 = `|pi1| ^+ 2.
by rewrite (big_morph Num.norm (@normrM _) (@normr1 _)) -prodrXl.
by rewrite intr_normK // sqr_intr_ge1 //; apply/prodf_neq0.
have Sgt0: (#|S| > 0)%N by rewrite (cardD1 g) [g \in S]Sg.
rewrite -mulr_natr -ler_pdivlMr ?ltr0n //.
have n2chi_ge0 s: s \in S -> 0 <= `|chi s| ^+ 2 by rewrite exprn_ge0.
rewrite -(expr_ge1 Sgt0); last by rewrite divr_ge0 ?ler0n ?sumr_ge0.
by rewrite (le_trans pi2_ge1) // leif_AGM.
Qed.
(* This is Burnside's vanishing theorem (Isaacs, Theorem (3.15)). *)
Theorem nonlinear_irr_vanish gT (G : {group gT}) i :
'chi[G]_i 1%g > 1 -> exists2 x, x \in G & 'chi_i x = 0.
Proof.
move=> chi1gt1; apply/exists_eq_inP; apply: contraFT (lt_geF chi1gt1).
move=> /exists_inPn-nz_chi.
rewrite -(norm_natr (Cnat_irr1 i)) -(@expr_le1 _ 2)//.
rewrite -(lerD2r (#|G|%:R * '['chi_i])) {1}cfnorm_irr mulr1.
rewrite (cfnormE (cfun_onG _)) mulVKf ?neq0CG // (big_setD1 1%g) //=.
rewrite addrCA lerD2l (cardsD1 1%g) group1 mulrS lerD2l.
rewrite -sumr_const !(partition_big_imset (fun s => <[s]>)) /=.
apply: ler_sum => _ /imsetP[g /setD1P[ntg Gg] ->].
have sgG: <[g]> \subset G by rewrite cycle_subG.
pose S := [pred s | generator <[g]> s]; pose chi := 'Res[<[g]>] 'chi_i.
have defS: [pred s in G^# | <[s]> == <[g]>] =i S.
move=> s; rewrite inE /= eq_sym andb_idl // !inE -cycle_eq1 -cycle_subG.
by move/eqP <-; rewrite cycle_eq1 ntg.
have resS: {in S, 'chi_i =1 chi}.
by move=> s /cycle_generator=> g_s; rewrite cfResE ?cycle_subG.
rewrite !(eq_bigl _ _ defS) sumr_const.
rewrite (eq_bigr (fun s => `|chi s| ^+ 2)) => [|s /resS-> //].
apply: sum_norm2_char_generators => [|s Ss].
by rewrite cfRes_char ?irr_char.
by rewrite -resS // nz_chi ?(subsetP sgG) ?cycle_generator.
Qed.
End MoreIntegralChar.
|
Type.lean
|
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.GCDMonoid.Multiset
import Mathlib.Algebra.GCDMonoid.Nat
import Mathlib.Algebra.Group.TypeTags.Finite
import Mathlib.Combinatorics.Enumerative.Partition
import Mathlib.Data.List.Rotate
import Mathlib.GroupTheory.Perm.Closure
import Mathlib.GroupTheory.Perm.Cycle.Factors
import Mathlib.Tactic.NormNum.GCD
/-!
# Cycle Types
In this file we define the cycle type of a permutation.
## Main definitions
- `Equiv.Perm.cycleType σ` where `σ` is a permutation of a `Fintype`
- `Equiv.Perm.partition σ` where `σ` is a permutation of a `Fintype`
## Main results
- `sum_cycleType` : The sum of `σ.cycleType` equals `σ.support.card`
- `lcm_cycleType` : The lcm of `σ.cycleType` equals `orderOf σ`
- `isConj_iff_cycleType_eq` : Two permutations are conjugate if and only if they have the same
cycle type.
- `exists_prime_orderOf_dvd_card`: For every prime `p` dividing the order of a finite group `G`
there exists an element of order `p` in `G`. This is known as Cauchy's theorem.
-/
open scoped Finset
namespace Equiv.Perm
open List (Vector)
open Equiv List Multiset
variable {α : Type*} [Fintype α]
section CycleType
variable [DecidableEq α]
/-- The cycle type of a permutation -/
def cycleType (σ : Perm α) : Multiset ℕ :=
σ.cycleFactorsFinset.1.map (Finset.card ∘ support)
theorem cycleType_def (σ : Perm α) :
σ.cycleType = σ.cycleFactorsFinset.1.map (Finset.card ∘ support) :=
rfl
theorem cycleType_eq' {σ : Perm α} (s : Finset (Perm α)) (h1 : ∀ f : Perm α, f ∈ s → f.IsCycle)
(h2 : (s : Set (Perm α)).Pairwise Disjoint)
(h0 : s.noncommProd id (h2.imp fun _ _ => Disjoint.commute) = σ) :
σ.cycleType = s.1.map (Finset.card ∘ support) := by
rw [cycleType_def]
congr
rw [cycleFactorsFinset_eq_finset]
exact ⟨h1, h2, h0⟩
theorem cycleType_eq {σ : Perm α} (l : List (Perm α)) (h0 : l.prod = σ)
(h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) :
σ.cycleType = l.map (Finset.card ∘ support) := by
have hl : l.Nodup := nodup_of_pairwise_disjoint_cycles h1 h2
rw [cycleType_eq' l.toFinset]
· simp [List.dedup_eq_self.mpr hl, Function.comp_def]
· simpa using h1
· simpa [hl] using h2
· simp [hl, h0]
theorem CycleType.count_def {σ : Perm α} (n : ℕ) :
σ.cycleType.count n =
Fintype.card {c : σ.cycleFactorsFinset // #(c : Perm α).support = n } := by
-- work on the LHS
rw [cycleType, Multiset.count_eq_card_filter_eq]
-- rewrite the `Fintype.card` as a `Finset.card`
rw [Fintype.subtype_card, Finset.univ_eq_attach, Finset.filter_attach',
Finset.card_map, Finset.card_attach]
simp only [Function.comp_apply, Finset.card, Finset.filter_val,
Multiset.filter_map, Multiset.card_map]
congr 1
apply Multiset.filter_congr
intro d h
simp only [eq_comm, Finset.mem_val.mp h, exists_const]
@[simp]
theorem cycleType_eq_zero {σ : Perm α} : σ.cycleType = 0 ↔ σ = 1 := by
simp [cycleType_def, cycleFactorsFinset_eq_empty_iff]
@[simp]
theorem cycleType_one : (1 : Perm α).cycleType = 0 := cycleType_eq_zero.2 rfl
theorem card_cycleType_eq_zero {σ : Perm α} : Multiset.card σ.cycleType = 0 ↔ σ = 1 := by
rw [card_eq_zero, cycleType_eq_zero]
theorem card_cycleType_pos {σ : Perm α} : 0 < Multiset.card σ.cycleType ↔ σ ≠ 1 :=
pos_iff_ne_zero.trans card_cycleType_eq_zero.not
theorem two_le_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 2 ≤ n := by
simp only [cycleType_def, ← Finset.mem_def, Function.comp_apply, Multiset.mem_map,
mem_cycleFactorsFinset_iff] at h
obtain ⟨_, ⟨hc, -⟩, rfl⟩ := h
exact hc.two_le_card_support
theorem one_lt_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : 1 < n :=
two_le_of_mem_cycleType h
theorem IsCycle.cycleType {σ : Perm α} (hσ : IsCycle σ) : σ.cycleType = {#σ.support} :=
cycleType_eq [σ] (mul_one σ) (fun _τ hτ => (congr_arg IsCycle (List.mem_singleton.mp hτ)).mpr hσ)
(List.pairwise_singleton Disjoint σ)
theorem card_cycleType_eq_one {σ : Perm α} : Multiset.card σ.cycleType = 1 ↔ σ.IsCycle := by
rw [card_eq_one]
simp_rw [cycleType_def, Multiset.map_eq_singleton, ← Finset.singleton_val, Finset.val_inj,
cycleFactorsFinset_eq_singleton_iff]
grind
theorem Disjoint.cycleType {σ τ : Perm α} (h : Disjoint σ τ) :
(σ * τ).cycleType = σ.cycleType + τ.cycleType := by
rw [cycleType_def, cycleType_def, cycleType_def, h.cycleFactorsFinset_mul_eq_union, ←
Multiset.map_add, Finset.union_val, Multiset.add_eq_union_iff_disjoint.mpr _]
exact Finset.disjoint_val.2 h.disjoint_cycleFactorsFinset
@[simp]
theorem cycleType_inv (σ : Perm α) : σ⁻¹.cycleType = σ.cycleType :=
cycle_induction_on (P := fun τ : Perm α => τ⁻¹.cycleType = τ.cycleType) σ rfl
(fun σ hσ => by simp only [hσ.cycleType, hσ.inv.cycleType, support_inv])
fun σ τ hστ _ hσ hτ => by
simp only [mul_inv_rev, hστ.cycleType, hστ.symm.inv_left.inv_right.cycleType, hσ, hτ,
add_comm]
@[simp]
theorem cycleType_conj {σ τ : Perm α} : (τ * σ * τ⁻¹).cycleType = σ.cycleType := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => rw [hσ.cycleType, hσ.conj.cycleType, card_support_conj]
| induction_disjoint σ π hd _ hσ hπ =>
rw [← conj_mul, hd.cycleType, (hd.conj _).cycleType, hσ, hπ]
theorem sum_cycleType (σ : Perm α) : σ.cycleType.sum = #σ.support := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => rw [hσ.cycleType, Multiset.sum_singleton]
| induction_disjoint σ τ hd _ hσ hτ => rw [hd.cycleType, sum_add, hσ, hτ, hd.card_support_mul]
theorem card_fixedPoints (σ : Equiv.Perm α) :
Fintype.card (Function.fixedPoints σ) = Fintype.card α - σ.cycleType.sum := by
rw [Equiv.Perm.sum_cycleType, ← Finset.card_compl, Fintype.card_ofFinset]
congr; aesop
theorem sign_of_cycleType' (σ : Perm α) :
sign σ = (σ.cycleType.map fun n => -(-1 : ℤˣ) ^ n).prod := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => simp [hσ.cycleType, hσ.sign]
| induction_disjoint σ τ hd _ hσ hτ => simp [hσ, hτ, hd.cycleType]
theorem sign_of_cycleType (f : Perm α) :
sign f = (-1 : ℤˣ) ^ (f.cycleType.sum + Multiset.card f.cycleType) := by
rw [sign_of_cycleType']
induction f.cycleType using Multiset.induction_on with
| empty => rfl
| cons a s ihs =>
rw [Multiset.map_cons, Multiset.prod_cons, Multiset.sum_cons, Multiset.card_cons, ihs]
simp only [pow_add, pow_one, neg_mul, mul_neg, mul_assoc, mul_one]
@[simp]
theorem lcm_cycleType (σ : Perm α) : σ.cycleType.lcm = orderOf σ := by
induction σ using cycle_induction_on with
| base_one => simp
| base_cycles σ hσ => simp [hσ.cycleType, hσ.orderOf]
| induction_disjoint σ τ hd _ hσ hτ => simp [hd.cycleType, hd.orderOf, lcm_eq_nat_lcm, hσ, hτ]
theorem dvd_of_mem_cycleType {σ : Perm α} {n : ℕ} (h : n ∈ σ.cycleType) : n ∣ orderOf σ := by
rw [← lcm_cycleType]
exact dvd_lcm h
theorem orderOf_cycleOf_dvd_orderOf (f : Perm α) (x : α) : orderOf (cycleOf f x) ∣ orderOf f := by
by_cases hx : f x = x
· rw [← cycleOf_eq_one_iff] at hx
simp [hx]
· refine dvd_of_mem_cycleType ?_
rw [cycleType, Multiset.mem_map]
refine ⟨f.cycleOf x, ?_, ?_⟩
· rwa [← Finset.mem_def, cycleOf_mem_cycleFactorsFinset_iff, mem_support]
· simp [(isCycle_cycleOf _ hx).orderOf]
theorem two_dvd_card_support {σ : Perm α} (hσ : σ ^ 2 = 1) : 2 ∣ #σ.support :=
(congr_arg (Dvd.dvd 2) σ.sum_cycleType).mp
(Multiset.dvd_sum fun n hn => by
rw [_root_.le_antisymm
(Nat.le_of_dvd zero_lt_two <|
(dvd_of_mem_cycleType hn).trans <| orderOf_dvd_of_pow_eq_one hσ)
(two_le_of_mem_cycleType hn)])
theorem cycleType_prime_order {σ : Perm α} (hσ : (orderOf σ).Prime) :
∃ n : ℕ, σ.cycleType = Multiset.replicate (n + 1) (orderOf σ) := by
refine ⟨Multiset.card σ.cycleType - 1, eq_replicate.2 ⟨?_, fun n hn ↦ ?_⟩⟩
· rw [tsub_add_cancel_of_le]
rw [Nat.succ_le_iff, card_cycleType_pos, Ne, ← orderOf_eq_one_iff]
exact hσ.ne_one
· exact (hσ.eq_one_or_self_of_dvd n (dvd_of_mem_cycleType hn)).resolve_left
(one_lt_of_mem_cycleType hn).ne'
theorem pow_prime_eq_one_iff {σ : Perm α} {p : ℕ} [hp : Fact (Nat.Prime p)] :
σ ^ p = 1 ↔ ∀ c ∈ σ.cycleType, c = p := by
rw [← orderOf_dvd_iff_pow_eq_one, ← lcm_cycleType, Multiset.lcm_dvd]
apply forall_congr'
exact fun c ↦ ⟨fun hc h ↦ Or.resolve_left (hp.elim.eq_one_or_self_of_dvd c (hc h))
(Nat.ne_of_lt' (one_lt_of_mem_cycleType h)),
fun hc h ↦ by rw [hc h]⟩
theorem isCycle_of_prime_order {σ : Perm α} (h1 : (orderOf σ).Prime)
(h2 : #σ.support < 2 * orderOf σ) : σ.IsCycle := by
obtain ⟨n, hn⟩ := cycleType_prime_order h1
rw [← σ.sum_cycleType, hn, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id,
mul_lt_mul_right (orderOf_pos σ), Nat.succ_lt_succ_iff, Nat.lt_succ_iff, Nat.le_zero] at h2
rw [← card_cycleType_eq_one, hn, card_replicate, h2]
theorem cycleType_le_of_mem_cycleFactorsFinset {f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) :
f.cycleType ≤ g.cycleType := by
have hf' := mem_cycleFactorsFinset_iff.1 hf
rw [cycleType_def, cycleType_def, hf'.left.cycleFactorsFinset_eq_singleton]
refine map_le_map ?_
simpa only [Finset.singleton_val, singleton_le, Finset.mem_val] using hf
theorem Disjoint.cycleType_mul {f g : Perm α} (h : f.Disjoint g) :
(f * g).cycleType = f.cycleType + g.cycleType := by
simp only [Perm.cycleType]
rw [h.cycleFactorsFinset_mul_eq_union]
simp only [Finset.union_val, Function.comp_apply]
rw [← Multiset.add_eq_union_iff_disjoint.mpr _, Multiset.map_add]
simp only [Finset.disjoint_val, Disjoint.disjoint_cycleFactorsFinset h]
theorem Disjoint.cycleType_noncommProd {ι : Type*} {k : ι → Perm α} {s : Finset ι}
(hs : Set.Pairwise s fun i j ↦ Disjoint (k i) (k j))
(hs' : Set.Pairwise s fun i j ↦ Commute (k i) (k j) :=
hs.imp (fun _ _ ↦ Perm.Disjoint.commute)) :
(s.noncommProd k hs').cycleType = s.sum fun i ↦ (k i).cycleType := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert i s hi hrec =>
have hs' : (s : Set ι).Pairwise fun i j ↦ Disjoint (k i) (k j) :=
hs.mono (by simp only [Finset.coe_insert, Set.subset_insert])
rw [Finset.noncommProd_insert_of_notMem _ _ _ _ hi, Finset.sum_insert hi]
rw [Equiv.Perm.Disjoint.cycleType_mul, hrec hs']
apply disjoint_noncommProd_right
intro j hj
apply hs _ _ (ne_of_mem_of_not_mem hj hi).symm <;>
simp only [Finset.coe_insert, Set.mem_insert_iff, Finset.mem_coe, hj, or_true, true_or]
theorem cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub
{f g : Perm α} (hf : f ∈ g.cycleFactorsFinset) :
(g * f⁻¹).cycleType = g.cycleType - f.cycleType :=
add_right_cancel (b := f.cycleType) <| by
rw [← (disjoint_mul_inv_of_mem_cycleFactorsFinset hf).cycleType, inv_mul_cancel_right,
tsub_add_cancel_of_le (cycleType_le_of_mem_cycleFactorsFinset hf)]
theorem isConj_of_cycleType_eq {σ τ : Perm α} (h : cycleType σ = cycleType τ) : IsConj σ τ := by
induction σ using cycle_induction_on generalizing τ with
| base_one =>
rw [cycleType_one, eq_comm, cycleType_eq_zero] at h
rw [h]
| base_cycles σ hσ =>
have hτ := card_cycleType_eq_one.2 hσ
rw [h, card_cycleType_eq_one] at hτ
apply hσ.isConj hτ
rwa [hσ.cycleType, hτ.cycleType, Multiset.singleton_inj] at h
| induction_disjoint σ π hd hc hσ hπ =>
rw [hd.cycleType] at h
have h' : #σ.support ∈ τ.cycleType := by
simp [← h, hc.cycleType]
obtain ⟨σ', hσ'l, hσ'⟩ := Multiset.mem_map.mp h'
have key : IsConj (σ' * τ * σ'⁻¹) τ := (isConj_iff.2 ⟨σ', rfl⟩).symm
refine IsConj.trans ?_ key
rw [mul_assoc]
have hs : σ.cycleType = σ'.cycleType := by
rw [← Finset.mem_def, mem_cycleFactorsFinset_iff] at hσ'l
rw [hc.cycleType, ← hσ', hσ'l.left.cycleType]; rfl
refine hd.isConj_mul (hσ hs) (hπ ?_) ?_
· rw [cycleType_mul_inv_mem_cycleFactorsFinset_eq_sub, ← h, add_comm, hs,
add_tsub_cancel_right]
rwa [Finset.mem_def]
· exact (disjoint_mul_inv_of_mem_cycleFactorsFinset hσ'l).symm
theorem isConj_iff_cycleType_eq {σ τ : Perm α} : IsConj σ τ ↔ σ.cycleType = τ.cycleType :=
⟨fun h => by
obtain ⟨π, rfl⟩ := isConj_iff.1 h
rw [cycleType_conj], isConj_of_cycleType_eq⟩
@[simp]
theorem cycleType_extendDomain {β : Type*} [Fintype β] [DecidableEq β] {p : β → Prop}
[DecidablePred p] (f : α ≃ Subtype p) {g : Perm α} :
cycleType (g.extendDomain f) = cycleType g := by
induction g using cycle_induction_on with
| base_one => rw [extendDomain_one, cycleType_one, cycleType_one]
| base_cycles σ hσ =>
rw [(hσ.extendDomain f).cycleType, hσ.cycleType, card_support_extend_domain]
| induction_disjoint σ τ hd _ hσ hτ =>
rw [hd.cycleType, ← extendDomain_mul, (hd.extendDomain f).cycleType, hσ, hτ]
theorem cycleType_ofSubtype {p : α → Prop} [DecidablePred p] {g : Perm (Subtype p)} :
cycleType (ofSubtype g) = cycleType g :=
cycleType_extendDomain (Equiv.refl (Subtype p))
theorem mem_cycleType_iff {n : ℕ} {σ : Perm α} :
n ∈ cycleType σ ↔ ∃ c τ, σ = c * τ ∧ Disjoint c τ ∧ IsCycle c ∧ c.support.card = n := by
constructor
· intro h
obtain ⟨l, rfl, hlc, hld⟩ := truncCycleFactors σ
rw [cycleType_eq _ rfl hlc hld, Multiset.mem_coe, List.mem_map] at h
obtain ⟨c, cl, rfl⟩ := h
rw [(List.perm_cons_erase cl).pairwise_iff @(Disjoint.symmetric)] at hld
refine ⟨c, (l.erase c).prod, ?_, ?_, hlc _ cl, rfl⟩
· rw [← List.prod_cons, (List.perm_cons_erase cl).symm.prod_eq' (hld.imp Disjoint.commute)]
· exact disjoint_prod_right _ fun g => List.rel_of_pairwise_cons hld
· rintro ⟨c, t, rfl, hd, hc, rfl⟩
simp [hd.cycleType, hc.cycleType]
theorem le_card_support_of_mem_cycleType {n : ℕ} {σ : Perm α} (h : n ∈ cycleType σ) :
n ≤ #σ.support :=
(le_sum_of_mem h).trans (le_of_eq σ.sum_cycleType)
theorem cycleType_of_card_le_mem_cycleType_add_two {n : ℕ} {g : Perm α}
(hn2 : Fintype.card α < n + 2) (hng : n ∈ g.cycleType) : g.cycleType = {n} := by
obtain ⟨c, g', rfl, hd, hc, rfl⟩ := mem_cycleType_iff.1 hng
suffices g'1 : g' = 1 by
rw [hd.cycleType, hc.cycleType, g'1, cycleType_one, add_zero]
contrapose! hn2 with g'1
apply le_trans _ (c * g').support.card_le_univ
rw [hd.card_support_mul]
exact add_le_add_left (two_le_card_support_of_ne_one g'1) _
end CycleType
theorem card_compl_support_modEq [DecidableEq α] {p n : ℕ} [hp : Fact p.Prime] {σ : Perm α}
(hσ : σ ^ p ^ n = 1) : σ.supportᶜ.card ≡ Fintype.card α [MOD p] := by
rw [Nat.modEq_iff_dvd', ← Finset.card_compl, compl_compl, ← sum_cycleType]
· refine Multiset.dvd_sum fun k hk => ?_
obtain ⟨m, -, hm⟩ := (Nat.dvd_prime_pow hp.out).mp (orderOf_dvd_of_pow_eq_one hσ)
obtain ⟨l, -, rfl⟩ := (Nat.dvd_prime_pow hp.out).mp
((congr_arg _ hm).mp (dvd_of_mem_cycleType hk))
exact dvd_pow_self _ fun h => (one_lt_of_mem_cycleType hk).ne <| by rw [h, pow_zero]
· exact Finset.card_le_univ _
open Function in
/-- The number of fixed points of a `p ^ n`-th root of the identity function over a finite set
and the set's cardinality have the same residue modulo `p`, where `p` is a prime. -/
theorem card_fixedPoints_modEq [DecidableEq α] {f : Function.End α} {p n : ℕ}
[hp : Fact p.Prime] (hf : f ^ p ^ n = 1) :
Fintype.card α ≡ Fintype.card f.fixedPoints [MOD p] := by
let σ : α ≃ α := ⟨f, f ^ (p ^ n - 1),
leftInverse_iff_comp.mpr ((pow_sub_mul_pow f (Nat.one_le_pow n p hp.out.pos)).trans hf),
leftInverse_iff_comp.mpr ((pow_mul_pow_sub f (Nat.one_le_pow n p hp.out.pos)).trans hf)⟩
have hσ : σ ^ p ^ n = 1 := by
rw [DFunLike.ext'_iff, coe_pow]
exact (hom_coe_pow (fun g : Function.End α ↦ g) rfl (fun g h ↦ rfl) f (p ^ n)).symm.trans hf
suffices Fintype.card f.fixedPoints = (support σ)ᶜ.card from
this ▸ (card_compl_support_modEq hσ).symm
suffices f.fixedPoints = (support σ)ᶜ by
simp only [this]; apply Fintype.card_coe
simp [σ, Set.ext_iff, IsFixedPt]
theorem exists_fixed_point_of_prime {p n : ℕ} [hp : Fact p.Prime] (hα : ¬p ∣ Fintype.card α)
{σ : Perm α} (hσ : σ ^ p ^ n = 1) : ∃ a : α, σ a = a := by
classical
contrapose! hα
simp_rw [← mem_support, ← Finset.eq_univ_iff_forall] at hα
exact Nat.modEq_zero_iff_dvd.1 ((congr_arg _ (Finset.card_eq_zero.2 (compl_eq_bot.2 hα))).mp
(card_compl_support_modEq hσ).symm)
theorem exists_fixed_point_of_prime' {p n : ℕ} [hp : Fact p.Prime] (hα : p ∣ Fintype.card α)
{σ : Perm α} (hσ : σ ^ p ^ n = 1) {a : α} (ha : σ a = a) : ∃ b : α, σ b = b ∧ b ≠ a := by
classical
have h : ∀ b : α, b ∈ σ.supportᶜ ↔ σ b = b := fun b => by
rw [Finset.mem_compl, mem_support, Classical.not_not]
obtain ⟨b, hb1, hb2⟩ := Finset.exists_ne_of_one_lt_card (hp.out.one_lt.trans_le
(Nat.le_of_dvd (Finset.card_pos.mpr ⟨a, (h a).mpr ha⟩) (Nat.modEq_zero_iff_dvd.mp
((card_compl_support_modEq hσ).trans (Nat.modEq_zero_iff_dvd.mpr hα))))) a
exact ⟨b, (h b).mp hb1, hb2⟩
theorem isCycle_of_prime_order' {σ : Perm α} (h1 : (orderOf σ).Prime)
(h2 : Fintype.card α < 2 * orderOf σ) : σ.IsCycle := by
classical exact isCycle_of_prime_order h1 (lt_of_le_of_lt σ.support.card_le_univ h2)
theorem isCycle_of_prime_order'' {σ : Perm α} (h1 : (Fintype.card α).Prime)
(h2 : orderOf σ = Fintype.card α) : σ.IsCycle :=
isCycle_of_prime_order' ((congr_arg Nat.Prime h2).mpr h1) <| by
rw [← one_mul (Fintype.card α), ← h2, mul_lt_mul_right (orderOf_pos σ)]
exact one_lt_two
section Cauchy
variable (G : Type*) [Group G] (n : ℕ)
/-- The type of vectors with terms from `G`, length `n`, and product equal to `1:G`. -/
def vectorsProdEqOne : Set (List.Vector G n) :=
{ v | v.toList.prod = 1 }
namespace VectorsProdEqOne
theorem mem_iff {n : ℕ} (v : List.Vector G n) : v ∈ vectorsProdEqOne G n ↔ v.toList.prod = 1 :=
Iff.rfl
theorem zero_eq : vectorsProdEqOne G 0 = {Vector.nil} :=
Set.eq_singleton_iff_unique_mem.mpr ⟨Eq.refl (1 : G), fun v _ => v.eq_nil⟩
theorem one_eq : vectorsProdEqOne G 1 = {Vector.nil.cons 1} := by
simp_rw [Set.eq_singleton_iff_unique_mem, mem_iff, List.Vector.toList_singleton,
List.prod_singleton, List.Vector.head_cons, true_and]
exact fun v hv => v.cons_head_tail.symm.trans (congr_arg₂ Vector.cons hv v.tail.eq_nil)
instance zeroUnique : Unique (vectorsProdEqOne G 0) := by
rw [zero_eq]
exact Set.uniqueSingleton Vector.nil
instance oneUnique : Unique (vectorsProdEqOne G 1) := by
rw [one_eq]
exact Set.uniqueSingleton (Vector.nil.cons 1)
/-- Given a vector `v` of length `n`, make a vector of length `n + 1` whose product is `1`,
by appending the inverse of the product of `v`. -/
@[simps]
def vectorEquiv : List.Vector G n ≃ vectorsProdEqOne G (n + 1) where
toFun v := ⟨v.toList.prod⁻¹ ::ᵥ v, by
rw [mem_iff, Vector.toList_cons, List.prod_cons, inv_mul_cancel]⟩
invFun v := v.1.tail
left_inv v := v.tail_cons v.toList.prod⁻¹
right_inv v := Subtype.ext <|
calc
v.1.tail.toList.prod⁻¹ ::ᵥ v.1.tail = v.1.head ::ᵥ v.1.tail :=
congr_arg (· ::ᵥ v.1.tail) <| Eq.symm <| eq_inv_of_mul_eq_one_left <| by
rw [← List.prod_cons, ← Vector.toList_cons, v.1.cons_head_tail]
exact v.2
_ = v.1 := v.1.cons_head_tail
/-- Given a vector `v` of length `n` whose product is 1, make a vector of length `n - 1`,
by deleting the last entry of `v`. -/
def equivVector : ∀ n, vectorsProdEqOne G n ≃ List.Vector G (n - 1)
| 0 => (ofUnique (vectorsProdEqOne G 0) (vectorsProdEqOne G 1)).trans (vectorEquiv G 0).symm
| (n + 1) => (vectorEquiv G n).symm
instance [Fintype G] : Fintype (vectorsProdEqOne G n) :=
Fintype.ofEquiv (List.Vector G (n - 1)) (equivVector G n).symm
theorem card [Fintype G] : Fintype.card (vectorsProdEqOne G n) = Fintype.card G ^ (n - 1) :=
(Fintype.card_congr (equivVector G n)).trans (card_vector (n - 1))
variable {G n} {g : G}
variable (v : vectorsProdEqOne G n) (j k : ℕ)
/-- Rotate a vector whose product is 1. -/
def rotate : vectorsProdEqOne G n :=
⟨⟨_, (v.1.1.length_rotate k).trans v.1.2⟩, List.prod_rotate_eq_one_of_prod_eq_one v.2 k⟩
theorem rotate_zero : rotate v 0 = v :=
Subtype.ext (Subtype.ext v.1.1.rotate_zero)
theorem rotate_rotate : rotate (rotate v j) k = rotate v (j + k) :=
Subtype.ext (Subtype.ext (v.1.1.rotate_rotate j k))
theorem rotate_length : rotate v n = v :=
Subtype.ext (Subtype.ext ((congr_arg _ v.1.2.symm).trans v.1.1.rotate_length))
end VectorsProdEqOne
-- TODO: Make the `Finite` version of this theorem the default
/-- For every prime `p` dividing the order of a finite group `G` there exists an element of order
`p` in `G`. This is known as Cauchy's theorem. -/
theorem _root_.exists_prime_orderOf_dvd_card {G : Type*} [Group G] [Fintype G] (p : ℕ)
[hp : Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, orderOf x = p := by
have hp' : p - 1 ≠ 0 := mt tsub_eq_zero_iff_le.mp (not_le_of_gt hp.out.one_lt)
have Scard :=
calc
p ∣ Fintype.card G ^ (p - 1) := hdvd.trans (dvd_pow (dvd_refl _) hp')
_ = Fintype.card (vectorsProdEqOne G p) := (VectorsProdEqOne.card G p).symm
let f : ℕ → vectorsProdEqOne G p → vectorsProdEqOne G p := fun k v =>
VectorsProdEqOne.rotate v k
have hf1 : ∀ v, f 0 v = v := VectorsProdEqOne.rotate_zero
have hf2 : ∀ j k v, f k (f j v) = f (j + k) v := fun j k v =>
VectorsProdEqOne.rotate_rotate v j k
have hf3 : ∀ v, f p v = v := VectorsProdEqOne.rotate_length
let σ :=
Equiv.mk (f 1) (f (p - 1)) (fun s => by rw [hf2, add_tsub_cancel_of_le hp.out.one_lt.le, hf3])
fun s => by rw [hf2, tsub_add_cancel_of_le hp.out.one_lt.le, hf3]
have hσ : ∀ k v, (σ ^ k) v = f k v := fun k =>
Nat.rec (fun v => (hf1 v).symm) (fun k hk v => by
rw [pow_succ, Perm.mul_apply, hk (σ v), Nat.succ_eq_one_add, ← hf2 1 k]
simp only [σ, coe_fn_mk]) k
replace hσ : σ ^ p ^ 1 = 1 := Perm.ext fun v => by rw [pow_one, hσ, hf3, one_apply]
let v₀ : vectorsProdEqOne G p :=
⟨List.Vector.replicate p 1, (List.prod_replicate p 1).trans (one_pow p)⟩
have hv₀ : σ v₀ = v₀ := Subtype.ext (Subtype.ext (List.rotate_replicate (1 : G) p 1))
obtain ⟨v, hv1, hv2⟩ := exists_fixed_point_of_prime' Scard hσ hv₀
refine
Exists.imp (fun g hg => orderOf_eq_prime ?_ fun hg' => hv2 ?_)
(List.rotate_one_eq_self_iff_eq_replicate.mp (Subtype.ext_iff.mp (Subtype.ext_iff.mp hv1)))
· rw [← List.prod_replicate, ← v.1.2, ← hg, show v.val.val.prod = 1 from v.2]
· rw [Subtype.ext_iff_val, Subtype.ext_iff_val, hg, hg', v.1.2]
simp only [v₀, List.Vector.replicate]
-- TODO: Make the `Finite` version of this theorem the default
/-- For every prime `p` dividing the order of a finite additive group `G` there exists an element of
order `p` in `G`. This is the additive version of Cauchy's theorem. -/
theorem _root_.exists_prime_addOrderOf_dvd_card {G : Type*} [AddGroup G] [Fintype G] (p : ℕ)
[Fact p.Prime] (hdvd : p ∣ Fintype.card G) : ∃ x : G, addOrderOf x = p :=
@exists_prime_orderOf_dvd_card (Multiplicative G) _ _ _ _ (by convert hdvd)
attribute [to_additive existing] exists_prime_orderOf_dvd_card
-- TODO: Make the `Finite` version of this theorem the default
/-- For every prime `p` dividing the order of a finite group `G` there exists an element of order
`p` in `G`. This is known as Cauchy's theorem. -/
@[to_additive]
theorem _root_.exists_prime_orderOf_dvd_card' {G : Type*} [Group G] [Finite G] (p : ℕ)
[hp : Fact p.Prime] (hdvd : p ∣ Nat.card G) : ∃ x : G, orderOf x = p := by
have := Fintype.ofFinite G
rw [Nat.card_eq_fintype_card] at hdvd
exact exists_prime_orderOf_dvd_card p hdvd
end Cauchy
theorem subgroup_eq_top_of_swap_mem [DecidableEq α] {H : Subgroup (Perm α)}
[d : DecidablePred (· ∈ H)] {τ : Perm α} (h0 : (Fintype.card α).Prime)
(h1 : Fintype.card α ∣ Fintype.card H) (h2 : τ ∈ H) (h3 : IsSwap τ) : H = ⊤ := by
haveI : Fact (Fintype.card α).Prime := ⟨h0⟩
obtain ⟨σ, hσ⟩ := exists_prime_orderOf_dvd_card (Fintype.card α) h1
have hσ1 : orderOf (σ : Perm α) = Fintype.card α := (Subgroup.orderOf_coe σ).trans hσ
have hσ2 : IsCycle ↑σ := isCycle_of_prime_order'' h0 hσ1
have hσ3 : (σ : Perm α).support = ⊤ :=
Finset.eq_univ_of_card (σ : Perm α).support (hσ2.orderOf.symm.trans hσ1)
have hσ4 : Subgroup.closure {↑σ, τ} = ⊤ := closure_prime_cycle_swap h0 hσ2 hσ3 h3
rw [eq_top_iff, ← hσ4, Subgroup.closure_le, Set.insert_subset_iff, Set.singleton_subset_iff]
exact ⟨Subtype.mem σ, h2⟩
section Partition
variable [DecidableEq α]
/-- The partition corresponding to a permutation -/
def partition (σ : Perm α) : (Fintype.card α).Partition where
parts := σ.cycleType + Multiset.replicate (Fintype.card α - #σ.support) 1
parts_pos {n hn} := by
rcases mem_add.mp hn with hn | hn
· exact zero_lt_one.trans (one_lt_of_mem_cycleType hn)
· exact lt_of_lt_of_le zero_lt_one (ge_of_eq (Multiset.eq_of_mem_replicate hn))
parts_sum := by
rw [sum_add, sum_cycleType, Multiset.sum_replicate, nsmul_eq_mul, Nat.cast_id, mul_one,
add_tsub_cancel_of_le σ.support.card_le_univ]
theorem parts_partition {σ : Perm α} :
σ.partition.parts = σ.cycleType + Multiset.replicate (Fintype.card α - #σ.support) 1 :=
rfl
theorem filter_parts_partition_eq_cycleType {σ : Perm α} :
((partition σ).parts.filter fun n => 2 ≤ n) = σ.cycleType := by
rw [parts_partition, filter_add, Multiset.filter_eq_self.2 fun _ => two_le_of_mem_cycleType,
Multiset.filter_eq_nil.2 fun a h => ?_, add_zero]
rw [Multiset.eq_of_mem_replicate h]
decide
theorem partition_eq_of_isConj {σ τ : Perm α} : IsConj σ τ ↔ σ.partition = τ.partition := by
rw [isConj_iff_cycleType_eq]
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [Nat.Partition.ext_iff, parts_partition, parts_partition, ← sum_cycleType, ← sum_cycleType,
h]
· rw [← filter_parts_partition_eq_cycleType, ← filter_parts_partition_eq_cycleType, h]
end Partition
/-!
### 3-cycles
-/
/-- A three-cycle is a cycle of length 3. -/
def IsThreeCycle [DecidableEq α] (σ : Perm α) : Prop :=
σ.cycleType = {3}
namespace IsThreeCycle
variable [DecidableEq α] {σ : Perm α}
theorem cycleType (h : IsThreeCycle σ) : σ.cycleType = {3} :=
h
theorem card_support (h : IsThreeCycle σ) : #σ.support = 3 := by
rw [← sum_cycleType, h.cycleType, Multiset.sum_singleton]
theorem _root_.card_support_eq_three_iff : #σ.support = 3 ↔ σ.IsThreeCycle := by
refine ⟨fun h => ?_, IsThreeCycle.card_support⟩
by_cases h0 : σ.cycleType = 0
· rw [← sum_cycleType, h0, sum_zero] at h
exact (ne_of_lt zero_lt_three h).elim
obtain ⟨n, hn⟩ := exists_mem_of_ne_zero h0
by_cases h1 : σ.cycleType.erase n = 0
· rw [← sum_cycleType, ← cons_erase hn, h1, cons_zero, Multiset.sum_singleton] at h
rw [IsThreeCycle, ← cons_erase hn, h1, h, ← cons_zero]
obtain ⟨m, hm⟩ := exists_mem_of_ne_zero h1
rw [← sum_cycleType, ← cons_erase hn, ← cons_erase hm, Multiset.sum_cons, Multiset.sum_cons] at h
have : ∀ {k}, 2 ≤ m → 2 ≤ n → n + (m + k) = 3 → False := by omega
cases this (two_le_of_mem_cycleType (mem_of_mem_erase hm)) (two_le_of_mem_cycleType hn) h
theorem isCycle (h : IsThreeCycle σ) : IsCycle σ := by
rw [← card_cycleType_eq_one, h.cycleType, card_singleton]
theorem sign (h : IsThreeCycle σ) : sign σ = 1 := by
rw [Equiv.Perm.sign_of_cycleType, h.cycleType]
rfl
theorem inv {f : Perm α} (h : IsThreeCycle f) : IsThreeCycle f⁻¹ := by
rwa [IsThreeCycle, cycleType_inv]
@[simp]
theorem inv_iff {f : Perm α} : IsThreeCycle f⁻¹ ↔ IsThreeCycle f :=
⟨by
rw [← inv_inv f]
apply inv, inv⟩
theorem orderOf {g : Perm α} (ht : IsThreeCycle g) : orderOf g = 3 := by
rw [← lcm_cycleType, ht.cycleType, Multiset.lcm_singleton, normalize_eq]
theorem isThreeCycle_sq {g : Perm α} (ht : IsThreeCycle g) : IsThreeCycle (g * g) := by
rw [← pow_two, ← card_support_eq_three_iff, support_pow_coprime, ht.card_support]
rw [ht.orderOf]
norm_num
end IsThreeCycle
section
variable [DecidableEq α]
theorem isThreeCycle_swap_mul_swap_same {a b c : α} (ab : a ≠ b) (ac : a ≠ c) (bc : b ≠ c) :
IsThreeCycle (swap a b * swap a c) := by
suffices h : support (swap a b * swap a c) = {a, b, c} by
rw [← card_support_eq_three_iff, h]
simp [ab, ac, bc]
apply le_antisymm ((support_mul_le _ _).trans fun x => _) fun x hx => ?_
· simp [ab, ac]
· simp only [Finset.mem_insert, Finset.mem_singleton] at hx
rw [mem_support]
simp only [Perm.coe_mul, Function.comp_apply, Ne]
obtain rfl | rfl | rfl := hx
· rw [swap_apply_left, swap_apply_of_ne_of_ne ac.symm bc.symm]
exact ac.symm
· rw [swap_apply_of_ne_of_ne ab.symm bc, swap_apply_right]
exact ab
· rw [swap_apply_right, swap_apply_left]
exact bc
open Subgroup
theorem swap_mul_swap_same_mem_closure_three_cycles {a b c : α} (ab : a ≠ b) (ac : a ≠ c) :
swap a b * swap a c ∈ closure { σ : Perm α | IsThreeCycle σ } := by
by_cases bc : b = c
· subst bc
simp [one_mem]
exact subset_closure (isThreeCycle_swap_mul_swap_same ab ac bc)
theorem IsSwap.mul_mem_closure_three_cycles {σ τ : Perm α} (hσ : IsSwap σ) (hτ : IsSwap τ) :
σ * τ ∈ closure { σ : Perm α | IsThreeCycle σ } := by
obtain ⟨a, b, ab, rfl⟩ := hσ
obtain ⟨c, d, cd, rfl⟩ := hτ
by_cases ac : a = c
· subst ac
exact swap_mul_swap_same_mem_closure_three_cycles ab cd
have h' : swap a b * swap c d = swap a b * swap a c * (swap c a * swap c d) := by
simp [swap_comm c a, mul_assoc]
rw [h']
exact
mul_mem (swap_mul_swap_same_mem_closure_three_cycles ab ac)
(swap_mul_swap_same_mem_closure_three_cycles (Ne.symm ac) cd)
end
end Equiv.Perm
|
Basic.lean
|
/-
Copyright (c) 2025 María Inés de Frutos-Fernández, Filippo A. E. Nuccio. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández, Filippo A. E. Nuccio
-/
import Mathlib.Algebra.GroupWithZero.Range
import Mathlib.Algebra.Order.Group.Cyclic
import Mathlib.Analysis.Normed.Ring.Lemmas
import Mathlib.RingTheory.DedekindDomain.AdicValuation
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.RingTheory.PrincipalIdealDomainOfPrime
/-!
# Discrete Valuations
Given a linearly ordered commutative group with zero `Γ`, a valuation `v : A → Γ` on a ring `A` is
*discrete*, if there is an element `γ : Γˣ` that is `< 1` and generated the range of `v`,
implemented as `MonoidWithZeroHom.valueGroup v`. When `Γ := ℤₘ₀` (defined in
`Multiplicative.termℤₘ₀`), `γ` = ofAdd (-1)` and the condition of being discrete is
equivalent to asking that `ofAdd (-1 : ℤ)` belongs to the image, in turn equivalent to asking that
`1 : ℤ` belongs to the image of the corresponding *additive* valuation.
Note that this definition of discrete implies that the valuation is nontrivial and of rank one, as
is commonly assumed in number theory. To avoid potential confusion with other definitions of
discrete, we use the name `IsRankOneDiscrete` to refer to discrete valuations in this setting.
## Main Definitions
* `Valuation.IsRankOneDiscrete`: We define a `Γ`-valued valuation `v` to be discrete if if there is
an element `γ : Γˣ` that is `< 1` and generates the range of `v`.
* `Valuation.IsUniformizer`: Given a `Γ`-valued valuation `v` on a ring `R`, an element `π : R` is
a uniformizer if `v π` is a generator of the value group that is `<1`.
* `Valuation.Uniformizer`: A structure bundling an element of a ring and a proof that it is a
uniformizer.
## Main Results
* `Valuation.IsUniformizer.of_associated`: An element associated to a uniformizer is itself a
uniformizer.
* `Valuation.associated_of_isUniformizer`: If two elements are uniformizers, they are associated.
* `Valuation.IsUniformizer.is_generator` A generator of the maximal ideal is a uniformizer when
the valuation is discrete.
* `Valuation.IsRankOneDiscrete.mk'`: if the `valueGroup` of the valuation `v` is cyclic and
nontrivial, then `v` is discrete.
* `Valuation.exists_isUniformizer_of_isCyclic_of_nontrivial`: If `v` is a valuation on a field `K`
whose value group is cyclic and nontrivial, then there exists a uniformizer for `v`.
* `Valuation.isUniformizer_of_maximalIdeal_eq_span`: Given a discrete valuation `v` on a field `K`,
a generator of the maximal ideal of `v.valuationSubring` is a uniformizer for `v`.
* `Valuation.valuationSubring_isDiscreteValuationRing` : If `v` is a valuation on a field `K`
whose value group is cyclic and nontrivial, then `v.valuationSubring` is a discrete
valuation ring. This instance is the formalization of Chapter I, Section 1, Proposition 1 in
[serre1968].
* `IsDiscreteValuationRing.isRankOneDiscrete`: Given a DVR `A` and a field `K` satisfying
`IsFractionRing A K`, the valuation induced on `K` is discrete.
* `IsDiscreteValuationRing.equivValuationSubring` The ring isomorphism between a DVR and the
unit ball in its field of fractions endowed with the adic valuation of the maximal ideal.
## TODO
* Relate discrete valuations and discrete valuation rings (contained in the project
<https://github.com/mariainesdff/LocalClassFieldTheory>)
-/
namespace Valuation
open LinearOrderedCommGroup MonoidWithZeroHom Set Subgroup
variable {Γ : Type*} [LinearOrderedCommGroupWithZero Γ]
section Ring
variable {A : Type*} [Ring A] (v : Valuation A Γ)
/-- Given a linearly ordered commutative group with zero `Γ` such that `Γˣ` is
nontrivial cyclic, a valuation `v : A → Γ` on a ring `A` is *discrete*, if
`genLTOne Γˣ` belongs to the image. Note that the latter is equivalent to
asking that `1 : ℤ` belongs to the image of the corresponding additive valuation. -/
class IsRankOneDiscrete : Prop where
exists_generator_lt_one' : ∃ (γ : Γˣ), zpowers γ = (valueGroup v) ∧ γ < 1
namespace IsRankOneDiscrete
variable [IsRankOneDiscrete v]
lemma exists_generator_lt_one : ∃ (γ : Γˣ), zpowers γ = valueGroup v ∧ γ < 1 :=
exists_generator_lt_one'
/-- Given a discrete valuation `v`, `Valuation.IsRankOneDiscrete.generator` is a generator of
the value group that is `< 1`. -/
noncomputable def generator : Γˣ := (exists_generator_lt_one v).choose
lemma generator_zpowers_eq_valueGroup :
zpowers (generator v) = valueGroup v :=
(exists_generator_lt_one v).choose_spec.1
lemma generator_mem_valueGroup :
(IsRankOneDiscrete.generator v) ∈ valueGroup v := by
rw [← IsRankOneDiscrete.generator_zpowers_eq_valueGroup]
exact mem_zpowers (IsRankOneDiscrete.generator v)
lemma generator_lt_one : generator v < 1 :=
(exists_generator_lt_one v).choose_spec.2
lemma generator_ne_one : generator v ≠ 1 :=
ne_of_lt <| generator_lt_one v
lemma generator_zpowers_eq_range (K : Type*) [Field K] (w : Valuation K Γ) [IsRankOneDiscrete w] :
Units.val '' (zpowers (generator w)) = range w \ {0} := by
rw [generator_zpowers_eq_valueGroup, valueGroup_eq_range]
lemma generator_mem_range (K : Type*) [Field K] (w : Valuation K Γ) [IsRankOneDiscrete w] :
↑(generator w) ∈ range w := by
apply diff_subset
rw [← generator_zpowers_eq_range]
exact ⟨generator w, by simp⟩
lemma generator_ne_zero : (generator v : Γ) ≠ 0 := by simp
instance : IsCyclic <| valueGroup v := by
rw [isCyclic_iff_exists_zpowers_eq_top, ← generator_zpowers_eq_valueGroup]
use ⟨generator v, by simp⟩
rw [eq_top_iff]
rintro ⟨g, k, hk⟩
simp only [mem_top, forall_const]
use k
ext
simp [← hk]
instance : Nontrivial (valueGroup v) :=
⟨1, ⟨generator v, by simp [← generator_zpowers_eq_valueGroup]⟩, ne_of_gt <| generator_lt_one v⟩
instance [IsRankOneDiscrete v] : Nontrivial (valueMonoid v) := by
by_contra H
apply ((valueGroup v).nontrivial_iff_ne_bot).mp (by infer_instance)
apply closure_eq_bot_iff.mpr
rw [not_nontrivial_iff_subsingleton, subsingleton_iff] at H
intro x hx
specialize H ⟨x, hx⟩ ⟨1, one_mem_valueMonoid v⟩
simpa using H
instance [IsRankOneDiscrete v] : v.IsNontrivial := by
constructor
obtain ⟨⟨γ, π, hπ⟩, hγ⟩ := (nontrivial_iff_exists_ne (1 : valueMonoid v)).mp (by infer_instance)
use π
constructor
· simp [hπ]
· rw [hπ]
simp only [← MonoidWithZeroHom.coe_one, ne_eq, Subtype.mk.injEq] at hγ
simp [hγ, Units.val_eq_one]
lemma valueGroup_genLTOne_eq_generator : (valueGroup v).genLTOne = generator v :=
((valueGroup v).genLTOne_unique (generator_lt_one v) (generator_zpowers_eq_valueGroup v)).symm
end IsRankOneDiscrete
section IsRankOneDiscrete
variable [hv : IsRankOneDiscrete v]
/-- An element `π : A` is a uniformizer if `v π` is a generator of the value group that is `< 1`. -/
def IsUniformizer (π : A) : Prop := v π = hv.generator
variable {v} {π : A}
namespace IsUniformizer
theorem iff : v.IsUniformizer π ↔ v π = hv.generator := refl _
theorem ne_zero (hπ : IsUniformizer v π) : π ≠ 0 := by
intro h0
rw [h0, IsUniformizer, map_zero] at hπ
exact (Units.ne_zero _).symm hπ
@[simp]
lemma val (hπ : v.IsUniformizer π) : v π = hv.generator := hπ
lemma val_lt_one (hπ : v.IsUniformizer π) : v π < 1 := hπ ▸ hv.generator_lt_one
lemma val_ne_zero (hπ : v.IsUniformizer π) : v π ≠ 0 := by
by_contra h0
simp only [IsUniformizer, h0] at hπ
exact (Units.ne_zero _).symm hπ
theorem val_pos (hπ : IsUniformizer v π) : 0 < v π := by
rw [IsUniformizer.iff] at hπ; simp [zero_lt_iff, ne_eq, hπ]
lemma zpowers_eq_valueGroup (hπ : v.IsUniformizer π) :
valueGroup v = zpowers (Units.mk0 (v π) hπ.val_ne_zero) := by
rw [← (valueGroup v).genLTOne_zpowers_eq_top]
congr
simp only [val, Units.mk0_val, hπ]
exact IsRankOneDiscrete.valueGroup_genLTOne_eq_generator v
end IsUniformizer
variable (v) in
/-- The structure `Uniformizer` bundles together the term in the ring and a proof that it is a
uniformizer. -/
@[ext]
structure Uniformizer where
/-- The integer underlying a `Uniformizer` -/
val : v.integer
valuation_gt_one : v.IsUniformizer val
namespace Uniformizer
/-- A constructor for `Uniformizer`. -/
def mk' {x : A} (hx : v.IsUniformizer x) : v.Uniformizer where
val := ⟨x, le_of_lt hx.val_lt_one⟩
valuation_gt_one := hx
@[simp]
instance : Coe v.Uniformizer v.integer := ⟨fun π ↦ π.val⟩
theorem ne_zero (π : Uniformizer v) : π.1.1 ≠ 0 := π.2.ne_zero
end Uniformizer
end IsRankOneDiscrete
end Ring
section CommRing
variable {R : Type*} [CommRing R] {v : Valuation R Γ} [hv : IsRankOneDiscrete v]
theorem IsUniformizer.not_isUnit {π : v.integer} (hπ : IsUniformizer v π) : ¬ IsUnit π :=
fun h ↦ ne_of_gt hπ.val_lt_one (Integers.one_of_isUnit (integer.integers v) h).symm
end CommRing
section Ring
variable {R : Type*} [Ring R] (v : Valuation R Γ) [IsCyclic (valueGroup v)]
[Nontrivial (valueGroup v)]
instance IsRankOneDiscrete.mk' : IsRankOneDiscrete v :=
⟨(valueGroup v).genLTOne,
⟨(valueGroup v).genLTOne_zpowers_eq_top, (valueGroup v).genLTOne_lt_one⟩⟩
end Ring
section Field
open Ideal IsLocalRing Valuation.IsRankOneDiscrete
variable {K : Type*} [Field K] (v : Valuation K Γ)
/- When the valuation is defined over a field instead that simply on a (commutative) ring, we use
the notion of `valuationSubring` instead of the weaker one of `integer` to access the
corresponding API. -/
local notation "K₀" => v.valuationSubring
section IsNontrivial
variable [IsCyclic (valueGroup v)] [Nontrivial (valueGroup v)]
theorem exists_isUniformizer_of_isCyclic_of_nontrivial : ∃ π : K₀, IsUniformizer v (π : K) := by
simp only [IsUniformizer.iff, Subtype.exists, mem_valuationSubring_iff, exists_prop]
set g := (valueGroup v).genLTOne with hg
obtain ⟨⟨π, hπ⟩, hγ0⟩ : g.1 ∈ ((range v) \ {0}) := by
rw [← valueGroup_eq_range, hg]
exact mem_image_of_mem Units.val (valueGroup v).genLTOne_mem
use π
rw [hπ, hg]
exact ⟨le_of_lt (valueGroup v).genLTOne_lt_one, by rw [valueGroup_genLTOne_eq_generator]⟩
instance : Nonempty (Uniformizer v) :=
⟨⟨(exists_isUniformizer_of_isCyclic_of_nontrivial v).choose,
(exists_isUniformizer_of_isCyclic_of_nontrivial v).choose_spec⟩⟩
end IsNontrivial
section IsRankOneDiscrete
section Uniformizer
variable {v} [hv : v.IsRankOneDiscrete]
/-- An element associated to a uniformizer is itself a uniformizer. -/
theorem IsUniformizer.of_associated {π₁ π₂ : K₀} (h1 : IsUniformizer v π₁)
(H : Associated π₁ π₂) : IsUniformizer v π₂ := by
obtain ⟨u, hu⟩ := H
have : v (u.1 : K) = 1 := (Integers.isUnit_iff_valuation_eq_one <|integer.integers v).mp u.isUnit
rwa [IsUniformizer.iff, ← hu, Subring.coe_mul, map_mul, this, mul_one, ← IsUniformizer.iff]
/-- If two elements of `K₀` are uniformizers, then they are associated. -/
theorem associated_of_isUniformizer {π₁ π₂ : K₀} (h1 : IsUniformizer v π₁)
(h2 : IsUniformizer v π₂) : Associated π₁ π₂ := by
have hval : v ((π₁ : K)⁻¹ * π₂) = 1 := by
simp [IsUniformizer.iff.mp h1, IsUniformizer.iff.mp h2]
set p : v.integer := ⟨(π₁.1 : K)⁻¹ * π₂.1, (v.mem_integer_iff _).mpr (le_of_eq hval)⟩ with hp
use ((Integers.isUnit_iff_valuation_eq_one (x := p) <| integer.integers v).mpr hval).unit
apply_fun ((↑) : K₀ → K) using Subtype.val_injective
simp [hp, ← mul_assoc, mul_inv_cancel₀ h1.ne_zero]
theorem exists_pow_Uniformizer {r : K₀} (hr : r ≠ 0) (π : Uniformizer v) :
∃ n : ℕ, ∃ u : K₀ˣ, r = (π.1 ^ n).1 * u.1 := by
have hr₀ : v r ≠ 0 := by rw [ne_eq, zero_iff, Subring.coe_eq_zero_iff]; exact hr
set vr : Γˣ := Units.mk0 (v r) hr₀ with hvr_def
have hvr : vr ∈ (valueGroup v) := by
apply mem_valueGroup
rw [hvr_def, Units.val_mk0 hr₀]
exact mem_range_self _
rw [π.2.zpowers_eq_valueGroup, mem_zpowers_iff] at hvr
obtain ⟨m, hm⟩ := hvr
have hm' : v π.val ^ m = v r := by
rw [hvr_def] at hm
rw [← Units.val_mk0 hr₀, ← hm]
simp [Units.val_zpow_eq_zpow_val, Units.val_mk0]
have hm₀ : 0 ≤ m := by
rw [← zpow_le_one_iff_right_of_lt_one₀ π.2.val_pos π.2.val_lt_one, hm']
exact r.2
obtain ⟨n, hn⟩ := Int.eq_ofNat_of_zero_le hm₀
use n
have hpow : v (π.1.1 ^ (-m) * r) = 1 := by
rw [map_mul, map_zpow₀, ← hm', zpow_neg, hm', inv_mul_cancel₀ hr₀]
set a : K₀ := ⟨π.1.1 ^ (-m) * r, by apply le_of_eq hpow⟩ with ha
have ha₀ : (↑a : K) ≠ 0 := by
simp only [zpow_neg, ne_eq, mul_eq_zero, inv_eq_zero, ZeroMemClass.coe_eq_zero, not_or, ha]
refine ⟨?_, hr⟩
rw [hn, zpow_natCast, pow_eq_zero_iff', not_and_or]
exact Or.inl π.ne_zero
have h_unit_a : IsUnit a :=
Integers.isUnit_of_one (integer.integers v) (isUnit_iff_ne_zero.mpr ha₀) hpow
use h_unit_a.unit
rw [IsUnit.unit_spec, Subring.coe_pow, ha, ← mul_assoc, zpow_neg, hn, zpow_natCast,
mul_inv_cancel₀ (pow_ne_zero _ π.ne_zero), one_mul]
theorem Uniformizer.is_generator (π : Uniformizer v) :
maximalIdeal v.valuationSubring = Ideal.span {π.1} := by
apply (maximalIdeal.isMaximal _).eq_of_le
· intro h
rw [Ideal.span_singleton_eq_top] at h
apply π.2.not_isUnit h
· intro x hx
by_cases hx₀ : x = 0
· simp [hx₀]
· obtain ⟨n, ⟨u, hu⟩⟩ := exists_pow_Uniformizer hx₀ π
rw [← Subring.coe_mul, Subtype.coe_inj] at hu
have hn : Not (IsUnit x) := fun h ↦
(maximalIdeal.isMaximal _).ne_top (eq_top_of_isUnit_mem _ hx h)
replace hn : n ≠ 0 := fun h ↦ by
simp only [hu, h, pow_zero, one_mul, Units.isUnit, not_true] at hn
simp [Ideal.mem_span_singleton, hu, dvd_pow_self _ hn]
theorem IsUniformizer.is_generator {π : v.valuationSubring} (hπ : IsUniformizer v π) :
maximalIdeal v.valuationSubring = Ideal.span {π} :=
Uniformizer.is_generator ⟨π, hπ⟩
theorem pow_Uniformizer_is_pow_generator (π : Uniformizer v) (n : ℕ) :
maximalIdeal v.valuationSubring ^ n = Ideal.span {π.1 ^ n} := by
rw [← Ideal.span_singleton_pow, Uniformizer.is_generator]
end Uniformizer
end IsRankOneDiscrete
theorem valuationSubring_not_isField [Nontrivial ↥(valueGroup v)] [IsCyclic (valueGroup v)] :
¬ IsField K₀ := by
obtain ⟨π, hπ⟩ := exists_isUniformizer_of_isCyclic_of_nontrivial v
rintro ⟨-, -, h⟩
have := hπ.ne_zero
simp only [ne_eq, Subring.coe_eq_zero_iff] at this
specialize h this
rw [← isUnit_iff_exists_inv] at h
exact hπ.not_isUnit h
theorem isUniformizer_of_maximalIdeal_eq_span [v.IsRankOneDiscrete] {r : K₀}
(hr : maximalIdeal v.valuationSubring = Ideal.span {r}) :
IsUniformizer v r := by
have hr₀ : r ≠ 0 := by
intro h
rw [h, Set.singleton_zero, span_zero] at hr
exact Ring.ne_bot_of_isMaximal_of_not_isField (maximalIdeal.isMaximal v.valuationSubring)
(valuationSubring_not_isField v) hr
obtain ⟨π, hπ⟩ := exists_isUniformizer_of_isCyclic_of_nontrivial v
obtain ⟨n, u, hu⟩ := exists_pow_Uniformizer hr₀ ⟨π, hπ⟩
rw [Uniformizer.is_generator ⟨π, hπ⟩, span_singleton_eq_span_singleton] at hr
exact hπ.of_associated hr
theorem ideal_isPrincipal [IsCyclic (valueGroup v)] [Nontrivial (valueGroup v)] (I : Ideal K₀) :
I.IsPrincipal := by
suffices ∀ P : Ideal K₀, P.IsPrime → Submodule.IsPrincipal P by
exact (IsPrincipalIdealRing.of_prime this).principal I
intro P hP
by_cases h_ne_bot : P = ⊥
· rw [h_ne_bot]; exact bot_isPrincipal
· let π : Uniformizer v := Nonempty.some (by infer_instance)
obtain ⟨x, ⟨hx_mem, hx₀⟩⟩ := Submodule.exists_mem_ne_zero_of_ne_bot h_ne_bot
obtain ⟨n, ⟨u, hu⟩⟩ := exists_pow_Uniformizer hx₀ π
by_cases hn : n = 0
· rw [← Subring.coe_mul, hn, pow_zero, one_mul, SetLike.coe_eq_coe] at hu
refine (hP.ne_top (Ideal.eq_top_of_isUnit_mem P hx_mem ?_)).elim
simp only [hu, Units.isUnit]
· rw [← Subring.coe_mul, SetLike.coe_eq_coe] at hu
rw [hu, Ideal.mul_unit_mem_iff_mem P u.isUnit,
IsPrime.pow_mem_iff_mem hP _ (pos_iff_ne_zero.mpr hn), ← Ideal.span_singleton_le_iff_mem,
← π.is_generator ] at hx_mem
rw [← Ideal.IsMaximal.eq_of_le (IsLocalRing.maximalIdeal.isMaximal K₀) hP.ne_top hx_mem]
exact ⟨π.1, π.is_generator⟩
theorem valuationSubring_isPrincipalIdealRing [IsCyclic (valueGroup v)]
[Nontrivial (valueGroup v)] : IsPrincipalIdealRing K₀ := ⟨fun I ↦ ideal_isPrincipal v I⟩
/-- This is Chapter I, Section 1, Proposition 1 in Serre's Local Fields -/
instance valuationSubring_isDiscreteValuationRing [IsCyclic (valueGroup v)]
[Nontrivial (valueGroup v)] : IsDiscreteValuationRing K₀ where
toIsPrincipalIdealRing := valuationSubring_isPrincipalIdealRing v
toIsLocalRing := inferInstance
not_a_field' := by rw [ne_eq, ← isField_iff_maximalIdeal_eq]; exact valuationSubring_not_isField v
end Field
end Valuation
namespace IsDiscreteValuationRing
open IsDedekindDomain IsDedekindDomain.HeightOneSpectrum IsDiscreteValuationRing
IsLocalRing MonoidWithZeroHom Multiplicative Subring Valuation
variable (A K : Type*) [CommRing A] [IsDomain A] [IsDiscreteValuationRing A] [Field K]
[Algebra A K] [IsFractionRing A K]
/-- The maximal ideal of a discrete valuation ring. -/
def maximalIdeal : HeightOneSpectrum A where
asIdeal := IsLocalRing.maximalIdeal A
isPrime := Ideal.IsMaximal.isPrime (maximalIdeal.isMaximal A)
ne_bot := by simpa [ne_eq, ← isField_iff_maximalIdeal_eq] using not_isField A
instance isRankOneDiscrete :
IsRankOneDiscrete ((maximalIdeal A).valuation K) := by
have : Nontrivial ↥(valueGroup (valuation K (maximalIdeal A))) := by
let v := (maximalIdeal A).valuation K
let π := valuation_exists_uniformizer K (maximalIdeal A)|>.choose
have hπ : v π = ↑(ofAdd (-1 : ℤ)) :=
valuation_exists_uniformizer K (maximalIdeal A)|>.choose_spec
rw [Subgroup.nontrivial_iff_exists_ne_one]
use Units.mk0 (v π) (by simp [hπ])
constructor
· apply mem_valueGroup
simp only [Units.val_mk0, Set.mem_range]
use π
· simpa [hπ] using not_eq_of_beq_eq_false rfl
infer_instance
variable {A K}
open scoped WithZero
theorem exists_lift_of_le_one {x : K} (H : ((maximalIdeal A).valuation K) x ≤ (1 : ℤᵐ⁰)) :
∃ a : A, algebraMap A K a = x := by
obtain ⟨π, hπ⟩ := exists_irreducible A
obtain ⟨a, b, hb, h_frac⟩ := IsFractionRing.div_surjective (A := A) x
by_cases ha : a = 0
· rw [← h_frac]
use 0
rw [ha, map_zero, zero_div]
· rw [← h_frac] at H
obtain ⟨n, u, rfl⟩ := eq_unit_mul_pow_irreducible ha hπ
obtain ⟨m, w, rfl⟩ := eq_unit_mul_pow_irreducible (nonZeroDivisors.ne_zero hb) hπ
replace hb := (mul_mem_nonZeroDivisors.mp hb).2
rw [mul_comm (w : A) _, map_mul _ (u : A) _, map_mul _ _ (w : A), div_eq_mul_inv, mul_assoc,
Valuation.map_mul, Integers.one_of_isUnit' u.isUnit (valuation_le_one _), one_mul,
mul_inv, ← mul_assoc, Valuation.map_mul, map_mul, map_inv₀, map_inv₀,
Integers.one_of_isUnit' w.isUnit (valuation_le_one _), inv_one, mul_one, ← div_eq_mul_inv,
← map_div₀, ← IsFractionRing.mk'_mk_eq_div hb,
valuation_of_mk', map_pow, map_pow] at H
have h_mn : m ≤ n := by
have v_π_lt_one := (intValuation_lt_one_iff_dvd (maximalIdeal A) π).mpr
(dvd_of_eq ((irreducible_iff_uniformizer _).mp hπ))
have v_π_ne_zero : (maximalIdeal A).intValuation π ≠ 0 := intValuation_ne_zero _ _ hπ.ne_zero
zify
rw [← WithZero.coe_one, div_eq_mul_inv, ← zpow_natCast, ← zpow_natCast, ← ofAdd_zero,
← zpow_neg, ← zpow_add₀ v_π_ne_zero, ← sub_eq_add_neg] at H
rwa [← sub_nonneg, ← zpow_le_one_iff_right_of_lt_one₀ (zero_lt_iff.mpr v_π_ne_zero)
v_π_lt_one]
use u * π ^ (n - m) * w.2
simp only [← h_frac, Units.inv_eq_val_inv, _root_.map_mul, _root_.map_pow, map_units_inv,
mul_assoc, mul_div_assoc ((algebraMap A _) ↑u) _ _]
congr 1
rw [div_eq_mul_inv, mul_inv, mul_comm ((algebraMap A _) ↑w)⁻¹ _, ←
mul_assoc _ _ ((algebraMap A _) ↑w)⁻¹]
congr
rw [pow_sub₀ _ _ h_mn]
apply IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors
rw [mem_nonZeroDivisors_iff_ne_zero]
exact hπ.ne_zero
theorem map_algebraMap_eq_valuationSubring : Subring.map (algebraMap A K) ⊤ =
((maximalIdeal A).valuation K).valuationSubring.toSubring := by
ext
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· obtain ⟨_, _, rfl⟩ := Subring.mem_map.mp h
apply valuation_le_one
· obtain ⟨y, rfl⟩ := exists_lift_of_le_one h
rw [Subring.mem_map]
exact ⟨y, mem_top _, rfl⟩
/-- The ring isomorphism between a DVR `A` and the valuation subring of a field of fractions
of `A` endowed with the adic valuation of the maximal ideal. -/
noncomputable def equivValuationSubring :
A ≃+* ((maximalIdeal A).valuation K).valuationSubring :=
(topEquiv.symm.trans (equivMapOfInjective ⊤ (algebraMap A K)
(IsFractionRing.injective A _))).trans
(RingEquiv.subringCongr map_algebraMap_eq_valuationSubring)
end IsDiscreteValuationRing
|
Monotone.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, Yury Kudryashov
-/
import Mathlib.Tactic.Order
import Mathlib.Topology.Order.IsLUB
/-!
# Monotone functions on an order topology
This file contains lemmas about limits and continuity for monotone / antitone functions on
linearly-ordered sets (with the order topology). For example, we prove that a monotone function
has left and right limits at any point (`Monotone.tendsto_nhdsLT`, `Monotone.tendsto_nhdsGT`).
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
section LinearOrder
variable [LinearOrder α] [TopologicalSpace α] [OrderTopology α] [LinearOrder β]
{s : Set α} {x : α} {f : α → β}
lemma MonotoneOn.insert_of_continuousWithinAt [TopologicalSpace β] [OrderClosedTopology β]
(hf : MonotoneOn f s) (hx : ClusterPt x (𝓟 s)) (h'x : ContinuousWithinAt f s x) :
MonotoneOn f (insert x s) := by
have : (𝓝[s] x).NeBot := hx
apply monotoneOn_insert_iff.2 ⟨fun b hb hbx ↦ ?_, fun b hb hxb ↦ ?_, hf⟩
· rcases hbx.eq_or_lt with rfl | hbx
· exact le_rfl
simp [ContinuousWithinAt] at h'x
apply ge_of_tendsto h'x
have : s ∩ Ioi b ∈ 𝓝[s] x := inter_mem_nhdsWithin _ (Ioi_mem_nhds hbx)
filter_upwards [this] with y hy using hf hb hy.1 (le_of_lt hy.2)
· rcases hxb.eq_or_lt with rfl | hxb
· exact le_rfl
simp [ContinuousWithinAt] at h'x
apply le_of_tendsto h'x
have : s ∩ Iio b ∈ 𝓝[s] x := inter_mem_nhdsWithin _ (Iio_mem_nhds hxb)
filter_upwards [this] with y hy
exact hf hy.1 hb (le_of_lt hy.2)
/-- If a function is monotone on a set in a second countable topological space, then there
are only countably many points that have several preimages. -/
lemma MonotoneOn.countable_setOf_two_preimages [SecondCountableTopology α]
(hf : MonotoneOn f s) :
Set.Countable {c | ∃ x y, x ∈ s ∧ y ∈ s ∧ x < y ∧ f x = c ∧ f y = c} := by
nontriviality α
let t := {c | ∃ x, ∃ y, x ∈ s ∧ y ∈ s ∧ x < y ∧ f x = c ∧ f y = c}
have : ∀ c ∈ t, ∃ x, ∃ y, x ∈ s ∧ y ∈ s ∧ x < y ∧ f x = c ∧ f y = c := fun c hc ↦ hc
choose! x y hxs hys hxy hfx hfy using this
let u := x '' t
suffices H : Set.Countable (x '' t) by
have : Set.InjOn x t := by
intro c hc d hd hcd
have : f (x c) = f (x d) := by simp [hcd]
rwa [hfx _ hc, hfx _ hd] at this
exact countable_of_injective_of_countable_image this H
apply Set.PairwiseDisjoint.countable_of_Ioo (y := fun a ↦ y (f a)); swap
· rintro a ⟨c, hc, rfl⟩
rw [hfx _ hc]
exact hxy _ hc
simp only [PairwiseDisjoint, Set.Pairwise, mem_image, onFun, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
intro c hc d hd hcd
wlog H : c < d generalizing c d with h
· apply (h d hd c hc hcd.symm ?_).symm
have : c ≠ d := fun h ↦ hcd (congrArg x h)
order
simp only [disjoint_iff_forall_ne, mem_Ioo, ne_eq, and_imp]
rintro a xca ayc b xda ayd rfl
rw [hfx _ hc] at ayc
have : x d ≤ y c := (xda.trans ayc).le
have : f (x d) ≤ f (y c) := hf (hxs _ hd) (hys _ hc) this
rw [hfx _ hd, hfy _ hc] at this
exact not_le.2 H this
/-- If a function is monotone in a second countable topological space, then there
are only countably many points that have several preimages. -/
lemma Monotone.countable_setOf_two_preimages [SecondCountableTopology α]
(hf : Monotone f) :
Set.Countable {c | ∃ x y, x < y ∧ f x = c ∧ f y = c} := by
rw [← monotoneOn_univ] at hf
simpa using hf.countable_setOf_two_preimages
/-- If a function is antitone on a set in a second countable topological space, then there
are only countably many points that have several preimages. -/
lemma AntitoneOn.countable_setOf_two_preimages [SecondCountableTopology α]
(hf : AntitoneOn f s) :
Set.Countable {c | ∃ x y, x ∈ s ∧ y ∈ s ∧ x < y ∧ f x = c ∧ f y = c} :=
(MonotoneOn.countable_setOf_two_preimages hf.dual_right :)
/-- If a function is antitone in a second countable topological space, then there
are only countably many points that have several preimages. -/
lemma Antitone.countable_setOf_two_preimages [SecondCountableTopology α]
(hf : Antitone f) :
Set.Countable {c | ∃ x y, x < y ∧ f x = c ∧ f y = c} :=
(Monotone.countable_setOf_two_preimages hf.dual_right :)
section Continuity
variable [TopologicalSpace β] [OrderTopology β] [SecondCountableTopology β]
/-- In a second countable space, the set of points where a monotone function is not right-continuous
within a set is at most countable. Superseded by `MonotoneOn.countable_not_continuousWithinAt`
which gives the two-sided version. -/
theorem MonotoneOn.countable_not_continuousWithinAt_Ioi (hf : MonotoneOn f s) :
Set.Countable {x ∈ s | ¬ContinuousWithinAt f (s ∩ Ioi x) x} := by
apply (countable_image_lt_image_Ioi_within s f).mono
rintro x ⟨xs, hx : ¬ContinuousWithinAt f (s ∩ Ioi x) x⟩
dsimp only [mem_setOf_eq]
contrapose! hx
refine tendsto_order.2 ⟨fun m hm => ?_, fun u hu => ?_⟩
· filter_upwards [@self_mem_nhdsWithin _ _ x (s ∩ Ioi x)] with y hy
exact hm.trans_le (hf xs hy.1 (le_of_lt hy.2))
rcases hx xs u hu with ⟨v, vs, xv, fvu⟩
have : s ∩ Ioo x v ∈ 𝓝[s ∩ Ioi x] x := by simp [nhdsWithin_inter, mem_inf_of_left,
self_mem_nhdsWithin, mem_inf_of_right, Ioo_mem_nhdsGT xv]
filter_upwards [this] with y hy
exact (hf hy.1 vs hy.2.2.le).trans_lt fvu
/-- In a second countable space, the set of points where a monotone function is not left-continuous
within a set is at most countable. Superseded by `MonotoneOn.countable_not_continuousWithinAt`
which gives the two-sided version. -/
theorem MonotoneOn.countable_not_continuousWithinAt_Iio (hf : MonotoneOn f s) :
Set.Countable {x ∈ s | ¬ContinuousWithinAt f (s ∩ Iio x) x} :=
hf.dual.countable_not_continuousWithinAt_Ioi
/-- In a second countable space, the set of points where a monotone function is not continuous
within a set is at most countable. -/
theorem MonotoneOn.countable_not_continuousWithinAt (hf : MonotoneOn f s) :
Set.Countable {x ∈ s | ¬ContinuousWithinAt f s x} := by
apply (hf.countable_not_continuousWithinAt_Ioi.union hf.countable_not_continuousWithinAt_Iio).mono
refine compl_subset_compl.1 ?_
simp only [compl_union]
rintro x ⟨hx, h'x⟩
simp only [mem_compl_iff, mem_setOf_eq, not_and, not_not] at hx h'x ⊢
intro xs
exact continuousWithinAt_iff_continuous_left'_right'.2 ⟨h'x xs, hx xs⟩
/-- In a second countable space, the set of points where a monotone function is not continuous
is at most countable. -/
theorem Monotone.countable_not_continuousAt (hf : Monotone f) :
Set.Countable {x | ¬ContinuousAt f x} := by
simpa [continuousWithinAt_univ] using (hf.monotoneOn univ).countable_not_continuousWithinAt
/-- In a second countable space, the set of points where an antitone function is not continuous
within a set is at most countable. -/
theorem _root_.AntitoneOn.countable_not_continuousWithinAt
{s : Set α} (hf : AntitoneOn f s) :
Set.Countable {x ∈ s | ¬ContinuousWithinAt f s x} :=
hf.dual_right.countable_not_continuousWithinAt
/-- In a second countable space, the set of points where an antitone function is not continuous
is at most countable. -/
theorem Antitone.countable_not_continuousAt (hf : Antitone f) :
Set.Countable {x | ¬ContinuousAt f x} :=
hf.dual_right.countable_not_continuousAt
end Continuity
end LinearOrder
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderClosedTopology β]
/-- A monotone function continuous at the supremum of a nonempty set sends this supremum to
the supremum of the image of this set. -/
theorem MonotoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sSup A))
(Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sSup (f '' A) :=
--This is a particular case of the more general `IsLUB.isLUB_of_tendsto`
.symm <| ((isLUB_csSup A_nonemp A_bdd).isLUB_of_tendsto Mf A_nonemp <|
Cf.mono_left fun ⦃_⦄ a ↦ a).csSup_eq (A_nonemp.image f)
/-- A monotone function continuous at the supremum of a nonempty set sends this supremum to
the supremum of the image of this set. -/
theorem Monotone.map_csSup_of_continuousAt {f : α → β} {A : Set α}
(Cf : ContinuousAt f (sSup A)) (Mf : Monotone f) (A_nonemp : A.Nonempty)
(A_bdd : BddAbove A := by bddDefault) : f (sSup A) = sSup (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt Cf.continuousWithinAt
(Mf.monotoneOn _) A_nonemp A_bdd
/-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed
supremum to the indexed supremum of the composition. -/
theorem Monotone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Mf : Monotone f)
(bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨆ i, f (g i) := by
rw [iSup, Monotone.map_csSup_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iSup,
comp_def]
/-- A monotone function continuous at the infimum of a nonempty set sends this infimum to
the infimum of the image of this set. -/
theorem MonotoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sInf A))
(Mf : MonotoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sInf (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd
/-- A monotone function continuous at the infimum of a nonempty set sends this infimum to
the infimum of the image of this set. -/
theorem Monotone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A))
(Mf : Monotone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sInf (f '' A) :=
Monotone.map_csSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual A_nonemp A_bdd
/-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed
infimum to the indexed infimum of the composition. -/
theorem Monotone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Mf : Monotone f)
(bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨅ i, f (g i) := by
rw [iInf, Monotone.map_csInf_of_continuousAt Cf Mf (range_nonempty g) bdd, ← range_comp, iInf,
comp_def]
/-- An antitone function continuous at the infimum of a nonempty set sends this infimum to
the supremum of the image of this set. -/
theorem AntitoneOn.map_csInf_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sInf A))
(Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sSup (f '' A) :=
MonotoneOn.map_csInf_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the infimum of a nonempty set sends this infimum to
the supremum of the image of this set. -/
theorem Antitone.map_csInf_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sInf A))
(Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddBelow A := by bddDefault) :
f (sInf A) = sSup (f '' A) :=
Monotone.map_csInf_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed
infimum to the indexed supremum of the composition. -/
theorem Antitone.map_ciInf_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Af : Antitone f)
(bdd : BddBelow (range g) := by bddDefault) : f (⨅ i, g i) = ⨆ i, f (g i) := by
rw [iInf, Antitone.map_csInf_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iSup,
comp_def]
/-- An antitone function continuous at the supremum of a nonempty set sends this supremum to
the infimum of the image of this set. -/
theorem AntitoneOn.map_csSup_of_continuousWithinAt {f : α → β} {A : Set α}
(Cf : ContinuousWithinAt f A (sSup A))
(Af : AntitoneOn f A) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sInf (f '' A) :=
MonotoneOn.map_csSup_of_continuousWithinAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the supremum of a nonempty set sends this supremum to
the infimum of the image of this set. -/
theorem Antitone.map_csSup_of_continuousAt {f : α → β} {A : Set α} (Cf : ContinuousAt f (sSup A))
(Af : Antitone f) (A_nonemp : A.Nonempty) (A_bdd : BddAbove A := by bddDefault) :
f (sSup A) = sInf (f '' A) :=
Monotone.map_csSup_of_continuousAt (β := βᵒᵈ) Cf Af.dual_right A_nonemp A_bdd
/-- An antitone function continuous at the indexed supremum over a nonempty `Sort` sends this
indexed supremum to the indexed infimum of the composition. -/
theorem Antitone.map_ciSup_of_continuousAt {ι : Sort*} [Nonempty ι] {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Af : Antitone f)
(bdd : BddAbove (range g) := by bddDefault) : f (⨆ i, g i) = ⨅ i, f (g i) := by
rw [iSup, Antitone.map_csSup_of_continuousAt Cf Af (range_nonempty g) bdd, ← range_comp, iInf,
comp_def]
end ConditionallyCompleteLinearOrder
section CompleteLinearOrder
variable [CompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] [CompleteLinearOrder β]
[TopologicalSpace β] [OrderClosedTopology β]
theorem sSup_mem_closure {s : Set α} (hs : s.Nonempty) : sSup s ∈ closure s :=
(isLUB_sSup s).mem_closure hs
theorem sInf_mem_closure {s : Set α} (hs : s.Nonempty) : sInf s ∈ closure s :=
(isGLB_sInf s).mem_closure hs
theorem IsClosed.sSup_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sSup s ∈ s :=
(isLUB_sSup s).mem_of_isClosed hs hc
theorem IsClosed.sInf_mem {s : Set α} (hs : s.Nonempty) (hc : IsClosed s) : sInf s ∈ s :=
(isGLB_sInf s).mem_of_isClosed hs hc
/-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends
this supremum to the supremum of the image of this set. -/
theorem MonotoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sSup s))
(Mf : MonotoneOn f s) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) := by
rcases s.eq_empty_or_nonempty with h | h
· simp [h, fbot]
· exact Mf.map_csSup_of_continuousWithinAt Cf h
/-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends
this supremum to the supremum of the image of this set. -/
theorem Monotone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
(Mf : Monotone f) (fbot : f ⊥ = ⊥) : f (sSup s) = sSup (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt Cf.continuousWithinAt (Mf.monotoneOn _) fbot
/-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over
a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/
theorem Monotone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Mf : Monotone f) (fbot : f ⊥ = ⊥) :
f (⨆ i, g i) = ⨆ i, f (g i) := by
rw [iSup, Mf.map_sSup_of_continuousAt Cf fbot, ← range_comp, iSup, comp_def]
/-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends
this infimum to the infimum of the image of this set. -/
theorem MonotoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sInf s)) (Mf : MonotoneOn f s) (ftop : f ⊤ = ⊤) :
f (sInf s) = sInf (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends
this infimum to the infimum of the image of this set. -/
theorem Monotone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s))
(Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (sInf s) = sInf (f '' s) :=
Monotone.map_sSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over
a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/
theorem Monotone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Mf : Monotone f) (ftop : f ⊤ = ⊤) : f (iInf g) = iInf (f ∘ g) :=
Monotone.map_iSup_of_continuousAt (α := αᵒᵈ) (β := βᵒᵈ) Cf Mf.dual ftop
/-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends
this supremum to the infimum of the image of this set. -/
theorem AntitoneOn.map_sSup_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sSup s)) (Af : AntitoneOn f s) (fbot : f ⊥ = ⊤) :
f (sSup s) = sInf (f '' s) :=
MonotoneOn.map_sSup_of_continuousWithinAt
(show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sSup s) from Cf) Af fbot
/-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends
this supremum to the infimum of the image of this set. -/
theorem Antitone.map_sSup_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sSup s))
(Af : Antitone f) (fbot : f ⊥ = ⊤) : f (sSup s) = sInf (f '' s) :=
Monotone.map_sSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sSup s) from Cf) Af
fbot
/-- An antitone function sending `bot` to `top` is continuous at the indexed supremum over
a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/
theorem Antitone.map_iSup_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iSup g)) (Af : Antitone f) (fbot : f ⊥ = ⊤) :
f (⨆ i, g i) = ⨅ i, f (g i) :=
Monotone.map_iSup_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iSup g) from Cf) Af
fbot
/-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends
this infimum to the supremum of the image of this set. -/
theorem AntitoneOn.map_sInf_of_continuousWithinAt {f : α → β} {s : Set α}
(Cf : ContinuousWithinAt f s (sInf s)) (Af : AntitoneOn f s) (ftop : f ⊤ = ⊥) :
f (sInf s) = sSup (f '' s) :=
MonotoneOn.map_sInf_of_continuousWithinAt
(show ContinuousWithinAt (OrderDual.toDual ∘ f) s (sInf s) from Cf) Af ftop
/-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends
this infimum to the supremum of the image of this set. -/
theorem Antitone.map_sInf_of_continuousAt {f : α → β} {s : Set α} (Cf : ContinuousAt f (sInf s))
(Af : Antitone f) (ftop : f ⊤ = ⊥) : f (sInf s) = sSup (f '' s) :=
Monotone.map_sInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (sInf s) from Cf) Af
ftop
/-- If an antitone function sending `top` to `bot` is continuous at the indexed infimum over
a `Sort`, then it sends this indexed infimum to the indexed supremum of the composition. -/
theorem Antitone.map_iInf_of_continuousAt {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : ContinuousAt f (iInf g)) (Af : Antitone f) (ftop : f ⊤ = ⊥) : f (iInf g) = iSup (f ∘ g) :=
Monotone.map_iInf_of_continuousAt (show ContinuousAt (OrderDual.toDual ∘ f) (iInf g) from Cf) Af
ftop
end CompleteLinearOrder
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α]
theorem csSup_mem_closure {s : Set α} (hs : s.Nonempty) (B : BddAbove s) : sSup s ∈ closure s :=
(isLUB_csSup hs B).mem_closure hs
theorem csInf_mem_closure {s : Set α} (hs : s.Nonempty) (B : BddBelow s) : sInf s ∈ closure s :=
(isGLB_csInf hs B).mem_closure hs
theorem IsClosed.csSup_mem {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddAbove s) :
sSup s ∈ s :=
(isLUB_csSup hs B).mem_of_isClosed hs hc
theorem IsClosed.csInf_mem {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddBelow s) :
sInf s ∈ s :=
(isGLB_csInf hs B).mem_of_isClosed hs hc
theorem IsClosed.isLeast_csInf {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddBelow s) :
IsLeast s (sInf s) :=
⟨hc.csInf_mem hs B, (isGLB_csInf hs B).1⟩
theorem IsClosed.isGreatest_csSup {s : Set α} (hc : IsClosed s) (hs : s.Nonempty) (B : BddAbove s) :
IsGreatest s (sSup s) :=
IsClosed.isLeast_csInf (α := αᵒᵈ) hc hs B
lemma MonotoneOn.tendsto_nhdsWithin_Ioo_left {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo y x).Nonempty) (Mf : MonotoneOn f (Ioo y x))
(h_bdd : BddAbove (f '' Ioo y x)) :
Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Ioo y x))) := by
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· obtain ⟨z, ⟨yz, zx⟩, lz⟩ : ∃ a : α, a ∈ Ioo y x ∧ l < f a := by
simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
exists_lt_of_lt_csSup (h_nonempty.image _) hl
filter_upwards [Ioo_mem_nhdsLT zx] with w hw
exact lz.trans_le <| Mf ⟨yz, zx⟩ ⟨yz.trans_le hw.1.le, hw.2⟩ hw.1.le
· rcases h_nonempty with ⟨_, hy, hx⟩
filter_upwards [Ioo_mem_nhdsLT (hy.trans hx)] with w hw
exact (le_csSup h_bdd (mem_image_of_mem _ hw)).trans_lt hm
lemma MonotoneOn.tendsto_nhdsWithin_Ioo_right {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo x y).Nonempty) (Mf : MonotoneOn f (Ioo x y))
(h_bdd : BddBelow (f '' Ioo x y)) :
Tendsto f (𝓝[>] x) (𝓝 (sInf (f '' Ioo x y))) := by
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· rcases h_nonempty with ⟨p, hy, hx⟩
filter_upwards [Ioo_mem_nhdsGT (hy.trans hx)] with w hw
exact hl.trans_le <| csInf_le h_bdd (mem_image_of_mem _ hw)
· obtain ⟨z, ⟨xz, zy⟩, zm⟩ : ∃ a : α, a ∈ Ioo x y ∧ f a < m := by
simpa [mem_image, exists_prop, exists_exists_and_eq_and] using
exists_lt_of_csInf_lt (h_nonempty.image _) hm
filter_upwards [Ioo_mem_nhdsGT xz] with w hw
exact (Mf ⟨hw.1, hw.2.trans zy⟩ ⟨xz, zy⟩ hw.2.le).trans_lt zm
lemma MonotoneOn.tendsto_nhdsLT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} {x : α}
(Mf : MonotoneOn f (Iio x)) (h_bdd : BddAbove (f '' Iio x)) :
Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) := by
rcases eq_empty_or_nonempty (Iio x) with (h | h); · simp [h]
refine tendsto_order.2 ⟨fun l hl => ?_, fun m hm => ?_⟩
· obtain ⟨z, zx, lz⟩ : ∃ a : α, a < x ∧ l < f a := by
simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using
exists_lt_of_lt_csSup (h.image _) hl
filter_upwards [Ioo_mem_nhdsLT zx] with y hy using lz.trans_le (Mf zx hy.2 hy.1.le)
· refine mem_of_superset self_mem_nhdsWithin fun y hy => lt_of_le_of_lt ?_ hm
exact le_csSup h_bdd (mem_image_of_mem _ hy)
lemma MonotoneOn.tendsto_nhdsGT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} {x : α}
(Mf : MonotoneOn f (Ioi x)) (h_bdd : BddBelow (f '' Ioi x)) :
Tendsto f (𝓝[>] x) (𝓝 (sInf (f '' Ioi x))) :=
MonotoneOn.tendsto_nhdsLT (α := αᵒᵈ) (β := βᵒᵈ) Mf.dual h_bdd
/-- A monotone map has a limit to the left of any point `x`, equal to `sSup (f '' (Iio x))`. -/
theorem Monotone.tendsto_nhdsLT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β}
(Mf : Monotone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sSup (f '' Iio x))) :=
MonotoneOn.tendsto_nhdsLT (Mf.monotoneOn _) (Mf.map_bddAbove bddAbove_Iio)
/-- A monotone map has a limit to the right of any point `x`, equal to `sInf (f '' (Ioi x))`. -/
theorem Monotone.tendsto_nhdsGT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β}
(Mf : Monotone f) (x : α) : Tendsto f (𝓝[>] x) (𝓝 (sInf (f '' Ioi x))) :=
Monotone.tendsto_nhdsLT (α := αᵒᵈ) (β := βᵒᵈ) Mf.dual x
lemma AntitoneOn.tendsto_nhdsWithin_Ioo_left {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo y x).Nonempty) (Af : AntitoneOn f (Ioo y x))
(h_bdd : BddBelow (f '' Ioo y x)) :
Tendsto f (𝓝[<] x) (𝓝 (sInf (f '' Ioo y x))) :=
MonotoneOn.tendsto_nhdsWithin_Ioo_left h_nonempty Af.dual_right h_bdd
lemma AntitoneOn.tendsto_nhdsWithin_Ioo_right {α β : Type*} [LinearOrder α] [TopologicalSpace α]
[OrderTopology α] [ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β]
{f : α → β} {x y : α} (h_nonempty : (Ioo x y).Nonempty) (Af : AntitoneOn f (Ioo x y))
(h_bdd : BddAbove (f '' Ioo x y)) :
Tendsto f (𝓝[>] x) (𝓝 (sSup (f '' Ioo x y))) :=
MonotoneOn.tendsto_nhdsWithin_Ioo_right h_nonempty Af.dual_right h_bdd
lemma AntitoneOn.tendsto_nhdsLT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} {x : α}
(Af : AntitoneOn f (Iio x)) (h_bdd : BddBelow (f '' Iio x)) :
Tendsto f (𝓝[<] x) (𝓝 (sInf (f '' Iio x))) :=
MonotoneOn.tendsto_nhdsLT Af.dual_right h_bdd
lemma AntitoneOn.tendsto_nhdsGT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} {x : α}
(Af : AntitoneOn f (Ioi x)) (h_bdd : BddAbove (f '' Ioi x)) :
Tendsto f (𝓝[>] x) (𝓝 (sSup (f '' Ioi x))) :=
MonotoneOn.tendsto_nhdsGT Af.dual_right h_bdd
/-- An antitone map has a limit to the left of any point `x`, equal to `sInf (f '' (Iio x))`. -/
theorem Antitone.tendsto_nhdsLT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β}
(Af : Antitone f) (x : α) : Tendsto f (𝓝[<] x) (𝓝 (sInf (f '' Iio x))) :=
Monotone.tendsto_nhdsLT Af.dual_right x
/-- An antitone map has a limit to the right of any point `x`, equal to `sSup (f '' (Ioi x))`. -/
theorem Antitone.tendsto_nhdsGT {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
[ConditionallyCompleteLinearOrder β] [TopologicalSpace β] [OrderTopology β] {f : α → β}
(Af : Antitone f) (x : α) : Tendsto f (𝓝[>] x) (𝓝 (sSup (f '' Ioi x))) :=
Monotone.tendsto_nhdsGT Af.dual_right x
end ConditionallyCompleteLinearOrder
|
Basic.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.Group.Subgroup.Basic
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.GroupTheory.Subsemigroup.Center
import Mathlib.RingTheory.NonUnitalSubring.Defs
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# `NonUnitalSubring`s
Let `R` be a non-unital ring.
We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of
`R` to the non-unital subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R →ₙ+* S)`
`(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)`
* `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the
non-unital subrings.
* `NonUnitalSubring.center` : the center of a non-unital ring `R`.
* `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest
non-unital subring that includes the set.
* `NonUnitalSubring.gi` : `closure : Set M → NonUnitalSubring M` and coercion
`coe : NonUnitalSubring M → Set M`
form a `GaloisInsertion`.
* `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the
non-unital ring homomorphism `f`
* `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the
non-unital ring homomorphism `f`.
* `Prod A B : NonUnitalSubring (R × S)` : the product of non-unital subrings
* `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`.
* `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R →ₙ+* S`,
the non-unital subring of `R` where `f x = g x`
## Implementation notes
A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an
additive subgroup.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a non-unital subring's underlying set.
## Tags
non-unital subring
-/
universe u v w
section Basic
variable {R : Type u} {S : Type v} [NonUnitalNonAssocRing R]
namespace NonUnitalSubring
variable (s : NonUnitalSubring R)
/-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/
protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s :=
list_sum_mem
/-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is
in the `NonUnitalSubring`. -/
protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
(m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s :=
multiset_sum_mem _
/-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset`
is in the `NonUnitalSubring`. -/
protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
{ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s :=
sum_mem h
/-! ## top -/
/-- The non-unital subring `R` of the ring `R`. -/
instance : Top (NonUnitalSubring R) :=
⟨{ (⊤ : Subsemigroup R), (⊤ : AddSubgroup R) with }⟩
@[simp]
theorem mem_top (x : R) : x ∈ (⊤ : NonUnitalSubring R) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : NonUnitalSubring R) : Set R) = Set.univ :=
rfl
/-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/
@[simps!]
def topEquiv : (⊤ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv
end NonUnitalSubring
end Basic
section Hom
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R)
/-! ## comap -/
/-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) :
NonUnitalSubring R :=
{ s.toSubsemigroup.comap (f : R →ₙ* S), s.toAddSubgroup.comap (f : R →+ S) with
carrier := f ⁻¹' s.carrier }
@[simp]
theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s :=
rfl
@[simp]
theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s :=
Iff.rfl
theorem comap_comap (s : NonUnitalSubring T) (g : S →ₙ+* T) (f : R →ₙ+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! ## map -/
/-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) :
NonUnitalSubring S :=
{ s.toSubsemigroup.map (f : R →ₙ* S), s.toAddSubgroup.map (f : R →+ S) with
carrier := f '' s.carrier }
@[simp]
theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s :=
rfl
@[simp]
theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
Set.mem_image _ _ _
@[simp]
theorem map_id : s.map (NonUnitalRingHom.id R) = s :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (g : S →ₙ+* T) (f : R →ₙ+* S) : (s.map f).map g = s.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : F) :
GaloisConnection (map f : NonUnitalSubring R → NonUnitalSubring S) (comap f) := fun _S _T =>
map_le_iff_le_comap
/-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/
noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R → S)) :
s ≃+* s.map f :=
{
Equiv.Set.image f s
hf with
map_mul' := fun _ _ => Subtype.ext (map_mul f _ _)
map_add' := fun _ _ => Subtype.ext (map_add f _ _) }
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) :
(equivMapOfInjective s f hf x : S) = f x :=
rfl
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
(g : S →ₙ+* T) (f : R →ₙ+* S)
/-! ## range -/
/-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target.
See Note [range copy pattern]. -/
def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
(f : R →ₙ+* S) : NonUnitalSubring S :=
((⊤ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : (f.range : Set S) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : R →ₙ+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y :=
Iff.rfl
theorem range_eq_map (f : R →ₙ+* S) : f.range = NonUnitalSubring.map f ⊤ := by ext; simp
theorem mem_range_self (f : R →ₙ+* S) (x : R) : f x ∈ f.range :=
mem_range.mpr ⟨x, rfl⟩
theorem map_range : f.range.map g = (g.comp f).range := by
simpa only [range_eq_map] using (⊤ : NonUnitalSubring R).map_map g f
/-- The range of a ring homomorphism is a fintype, if the domain is a fintype.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype S`. -/
instance fintypeRange [Fintype R] [DecidableEq S] (f : R →ₙ+* S) : Fintype (range f) :=
Set.fintypeRange f
end NonUnitalRingHom
namespace NonUnitalSubring
section Order
variable {R : Type u} [NonUnitalNonAssocRing R]
/-! ## bot -/
instance : Bot (NonUnitalSubring R) :=
⟨(0 : R →ₙ+* R).range⟩
instance : Inhabited (NonUnitalSubring R) :=
⟨⊥⟩
theorem coe_bot : ((⊥ : NonUnitalSubring R) : Set R) = {0} :=
(NonUnitalRingHom.coe_range (0 : R →ₙ+* R)).trans (@Set.range_const R R _ 0)
theorem mem_bot {x : R} : x ∈ (⊥ : NonUnitalSubring R) ↔ x = 0 :=
show x ∈ ((⊥ : NonUnitalSubring R) : Set R) ↔ x = 0 by rw [coe_bot, Set.mem_singleton_iff]
/-! ## inf -/
/-- The inf of two `NonUnitalSubring`s is their intersection. -/
instance : Min (NonUnitalSubring R) :=
⟨fun s t =>
{ s.toSubsemigroup ⊓ t.toSubsemigroup, s.toAddSubgroup ⊓ t.toAddSubgroup with
carrier := s ∩ t }⟩
@[simp]
theorem coe_inf (p p' : NonUnitalSubring R) :
((p ⊓ p' : NonUnitalSubring R) : Set R) = (p : Set R) ∩ p' :=
rfl
@[simp]
theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
instance : InfSet (NonUnitalSubring R) :=
⟨fun s =>
NonUnitalSubring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t)
(⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)⟩
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalSubring R)) :
((sInf S : NonUnitalSubring R) : Set R) = ⋂ s ∈ S, ↑s :=
rfl
theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} : (↑(⨅ i, S i) : Set R) = ⋂ i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalSubring R} {x : R} :
(x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp]
theorem sInf_toSubsemigroup (s : Set (NonUnitalSubring R)) :
(sInf s).toSubsemigroup = ⨅ t ∈ s, NonUnitalSubring.toSubsemigroup t :=
mk'_toSubsemigroup _ _
@[simp]
theorem sInf_toAddSubgroup (s : Set (NonUnitalSubring R)) :
(sInf s).toAddSubgroup = ⨅ t ∈ s, NonUnitalSubring.toAddSubgroup t :=
mk'_toAddSubgroup _ _
/-- `NonUnitalSubring`s of a ring form a complete lattice. -/
instance : CompleteLattice (NonUnitalSubring R) :=
{ completeLatticeOfInf (NonUnitalSubring R) fun _s =>
IsGLB.of_image (@fun _ _ : NonUnitalSubring R => SetLike.coe_subset_coe)
isGLB_biInf with
bot := ⊥
bot_le := fun s _x hx => (mem_bot.mp hx).symm ▸ zero_mem s
top := ⊤
le_top := fun _ _ _ => trivial
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right
le_inf := fun _s _t₁ _t₂ h₁ h₂ _x hx => ⟨h₁ hx, h₂ hx⟩ }
theorem eq_top_iff' (A : NonUnitalSubring R) : A = ⊤ ↔ ∀ x : R, x ∈ A :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
end Order
/-! ## Center of a ring -/
section Center
variable {R : Type u}
section NonUnitalNonAssocRing
variable (R) [NonUnitalNonAssocRing R]
/-- The center of a ring `R` is the set of elements that commute with everything in `R` -/
def center : NonUnitalSubring R :=
{ NonUnitalSubsemiring.center R with
neg_mem' := Set.neg_mem_center }
theorem coe_center : ↑(center R) = Set.center R :=
rfl
@[simp]
theorem center_toNonUnitalSubsemiring :
(center R).toNonUnitalSubsemiring = NonUnitalSubsemiring.center R :=
rfl
/-- The center is commutative and associative. -/
instance center.instNonUnitalCommRing : NonUnitalCommRing (center R) :=
{ NonUnitalSubsemiring.center.instNonUnitalCommSemiring R,
inferInstanceAs <| NonUnitalNonAssocRing (center R) with }
variable {R}
/-- The center of isomorphic (not necessarily unital or associative) rings are isomorphic. -/
@[simps!] def centerCongr {S} [NonUnitalNonAssocRing S] (e : R ≃+* S) : center R ≃+* center S :=
NonUnitalSubsemiring.centerCongr e
/-- The center of a (not necessarily uintal or associative) ring
is isomorphic to the center of its opposite. -/
@[simps!] def centerToMulOpposite : center R ≃+* center Rᵐᵒᵖ :=
NonUnitalSubsemiring.centerToMulOpposite
end NonUnitalNonAssocRing
section NonUnitalRing
variable [NonUnitalRing R]
-- no instance diamond, unlike the unital version
example : (center.instNonUnitalCommRing _).toNonUnitalRing =
NonUnitalSubringClass.toNonUnitalRing (center R) := by
with_reducible_and_instances rfl
theorem mem_center_iff {z : R} : z ∈ center R ↔ ∀ g, g * z = z * g := Subsemigroup.mem_center_iff
instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (· ∈ center R) := fun _ =>
decidable_of_iff' _ mem_center_iff
@[simp]
theorem center_eq_top (R) [NonUnitalCommRing R] : center R = ⊤ :=
SetLike.coe_injective (Set.center_eq_univ R)
end NonUnitalRing
end Center
/-! ## `NonUnitalSubring` closure of a subset -/
variable {F : Type w} {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S]
/-- The `NonUnitalSubring` generated by a set. -/
def closure (s : Set R) : NonUnitalSubring R :=
sInf {S | s ⊆ S}
theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ ∀ S : NonUnitalSubring R, s ⊆ S → x ∈ S :=
mem_sInf
/-- The `NonUnitalSubring` generated by a set includes the set. -/
@[simp, aesop safe 20 (rule_sets := [SetLike])]
theorem subset_closure {s : Set R} : s ⊆ closure s := fun _x hx => mem_closure.2 fun _S hS => hS hx
@[aesop 80% (rule_sets := [SetLike])]
theorem mem_closure_of_mem {s : Set R} {x : R} (hx : x ∈ s) : x ∈ closure s := subset_closure hx
theorem notMem_of_notMem_closure {s : Set R} {P : R} (hP : P ∉ closure s) : P ∉ s := fun h =>
hP (subset_closure h)
@[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure
/-- A `NonUnitalSubring` `t` includes `closure s` if and only if it includes `s`. -/
@[simp]
theorem closure_le {s : Set R} {t : NonUnitalSubring R} : closure s ≤ t ↔ s ⊆ t :=
⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩
/-- `NonUnitalSubring` closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
@[gcongr]
theorem closure_mono ⦃s t : Set R⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 <| Set.Subset.trans h subset_closure
theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all
elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {s : Set R} {p : (x : R) → x ∈ closure s → Prop}
(mem : ∀ (x) (hx : x ∈ s), p x (subset_closure hx)) (zero : p 0 (zero_mem _))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy))
(neg : ∀ x hx, p x hx → p (-x) (neg_mem hx))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
{x} (hx : x ∈ closure s) : p x hx :=
let K : NonUnitalSubring R :=
{ carrier := { x | ∃ hx, p x hx }
mul_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, mul _ _ _ _ hpx hpy⟩
add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩
neg_mem' := fun ⟨_, hpx⟩ ↦ ⟨_, neg _ _ hpx⟩
zero_mem' := ⟨_, zero⟩ }
closure_le (t := K) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id
/-- An induction principle for closure membership, for predicates with two arguments. -/
@[elab_as_elim]
theorem closure_induction₂ {s : Set R} {p : (x y : R) → x ∈ closure s → y ∈ closure s → Prop}
(mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_closure hx) (subset_closure hy))
(zero_left : ∀ x hx, p 0 x (zero_mem _) hx) (zero_right : ∀ x hx, p x 0 hx (zero_mem _))
(neg_left : ∀ x y hx hy, p x y hx hy → p (-x) y (neg_mem hx) hy)
(neg_right : ∀ x y hx hy, p x y hx hy → p x (-y) hx (neg_mem hy))
(add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz)
(add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz))
(mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz)
(mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz))
{x y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) :
p x y hx hy := by
induction hy using closure_induction with
| mem z hz => induction hx using closure_induction with
| mem _ h => exact mem_mem _ _ h hz
| zero => exact zero_left _ _
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂
| neg _ _ h => exact neg_left _ _ _ _ h
| zero => exact zero_right x hx
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂
| neg _ _ h => exact neg_right _ _ _ _ h
theorem mem_closure_iff {s : Set R} {x} :
x ∈ closure s ↔ x ∈ AddSubgroup.closure (Subsemigroup.closure s : Set R) :=
⟨fun h => by
induction h using closure_induction with
| mem _ hx => exact AddSubgroup.subset_closure (Subsemigroup.subset_closure hx)
| zero => exact zero_mem _
| add _ _ _ _ hx hy => exact add_mem hx hy
| neg x _ hx => exact neg_mem hx
| mul _ _ _hx _hy hx hy =>
clear _hx _hy
induction hx, hy using AddSubgroup.closure_induction₂ with
| mem _ _ hx hy => exact AddSubgroup.subset_closure (mul_mem hx hy)
| one_left => simp
| one_right => simp
| mul_left _ _ _ _ _ _ h₁ h₂ => simpa [add_mul] using add_mem h₁ h₂
| mul_right _ _ _ _ _ _ h₁ h₂ => simpa [mul_add] using add_mem h₁ h₂
| inv_left _ _ _ _ h => simpa [neg_mul] using neg_mem h
| inv_right _ _ _ _ h => simpa [mul_neg] using neg_mem h,
fun h => by
induction h using AddSubgroup.closure_induction with
| mem _ hx => induction hx using Subsemigroup.closure_induction with
| mem _ h => exact subset_closure h
| mul _ _ _ _ h₁ h₂ => exact mul_mem h₁ h₂
| one => exact zero_mem _
| mul _ _ _ _ h₁ h₂ => exact add_mem h₁ h₂
| inv _ _ h => exact neg_mem h⟩
/-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/
def closureNonUnitalCommRingOfComm {R : Type u} [NonUnitalRing R] {s : Set R}
(hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) : NonUnitalCommRing (closure s) :=
{ (closure s).toNonUnitalRing with
mul_comm := fun ⟨x, hx⟩ ⟨y, hy⟩ => by
ext
simp only [MulMemClass.mk_mul_mk]
induction hx, hy using closure_induction₂ with
| mem_mem x y hx hy => exact hcomm x hx y hy
| zero_left x _ => exact Commute.zero_left x
| zero_right x _ => exact Commute.zero_right x
| mul_left _ _ _ _ _ _ h₁ h₂ => exact Commute.mul_left h₁ h₂
| mul_right _ _ _ _ _ _ h₁ h₂ => exact Commute.mul_right h₁ h₂
| add_left _ _ _ _ _ _ h₁ h₂ => exact Commute.add_left h₁ h₂
| add_right _ _ _ _ _ _ h₁ h₂ => exact Commute.add_right h₁ h₂
| neg_left _ _ _ _ h => exact Commute.neg_left h
| neg_right _ _ _ _ h => exact Commute.neg_right h }
variable (R) in
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure R _) SetLike.coe where
choice s _ := closure s
gc _s _t := closure_le
le_l_u _s := subset_closure
choice_eq _s _h := rfl
/-- Closure of a `NonUnitalSubring` `S` equals `S`. -/
@[simp]
theorem closure_eq (s : NonUnitalSubring R) : closure (s : Set R) = s :=
(NonUnitalSubring.gi R).l_u_eq s
@[simp]
theorem closure_empty : closure (∅ : Set R) = ⊥ :=
(NonUnitalSubring.gi R).gc.l_bot
@[simp]
theorem closure_univ : closure (Set.univ : Set R) = ⊤ :=
@coe_top R _ ▸ closure_eq ⊤
theorem closure_union (s t : Set R) : closure (s ∪ t) = closure s ⊔ closure t :=
(NonUnitalSubring.gi R).gc.l_sup
theorem closure_iUnion {ι} (s : ι → Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(NonUnitalSubring.gi R).gc.l_iSup
theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(NonUnitalSubring.gi R).gc.l_sSup
theorem map_sup (s t : NonUnitalSubring R) (f : F) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : F) (s : ι → NonUnitalSubring R) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem map_inf (s t : NonUnitalSubring R) (f : F) (hf : Function.Injective f) :
(s ⊓ t).map f = s.map f ⊓ t.map f := SetLike.coe_injective (Set.image_inter hf)
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : F) (hf : Function.Injective f)
(s : ι → NonUnitalSubring R) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
theorem comap_inf (s t : NonUnitalSubring S) (f : F) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ι : Sort*} (f : F) (s : ι → NonUnitalSubring S) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : R →ₙ+* S) : (⊥ : NonUnitalSubring R).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : R →ₙ+* S) : (⊤ : NonUnitalSubring S).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- Given `NonUnitalSubring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ×ˢ t`
as a `NonUnitalSubring` of `R × S`. -/
def prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : NonUnitalSubring (R × S) :=
{ s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubgroup.prod t.toAddSubgroup with
carrier := s ×ˢ t }
@[norm_cast]
theorem coe_prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) :
(s.prod t : Set (R × S)) = (s : Set R) ×ˢ t :=
rfl
theorem mem_prod {s : NonUnitalSubring R} {t : NonUnitalSubring S} {p : R × S} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[mono]
theorem prod_mono ⦃s₁ s₂ : NonUnitalSubring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : NonUnitalSubring S⦄
(ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
theorem prod_mono_right (s : NonUnitalSubring R) :
Monotone fun t : NonUnitalSubring S => s.prod t :=
prod_mono (le_refl s)
theorem prod_mono_left (t : NonUnitalSubring S) : Monotone fun s : NonUnitalSubring R => s.prod t :=
fun _s₁ _s₂ hs => prod_mono hs (le_refl t)
theorem prod_top (s : NonUnitalSubring R) :
s.prod (⊤ : NonUnitalSubring S) = s.comap (NonUnitalRingHom.fst R S) :=
ext fun x => by simp [mem_prod]
theorem top_prod (s : NonUnitalSubring S) :
(⊤ : NonUnitalSubring R).prod s = s.comap (NonUnitalRingHom.snd R S) :=
ext fun x => by simp [mem_prod]
@[simp]
theorem top_prod_top : (⊤ : NonUnitalSubring R).prod (⊤ : NonUnitalSubring S) = ⊤ :=
(top_prod _).trans <| comap_top _
/-- Product of `NonUnitalSubring`s is isomorphic to their product as rings. -/
def prodEquiv (s : NonUnitalSubring R) (t : NonUnitalSubring S) : s.prod t ≃+* s × t :=
{ Equiv.Set.prod (s : Set R) (t : Set S) with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- The underlying set of a non-empty directed Sup of `NonUnitalSubring`s is just a union of the
`NonUnitalSubring`s. Note that this fails without the directedness assumption (the union of two
`NonUnitalSubring`s is typically not a `NonUnitalSubring`) -/
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → NonUnitalSubring R}
(hS : Directed (· ≤ ·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
let U : NonUnitalSubring R :=
NonUnitalSubring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (⨆ i, (S i).toAddSubgroup)
(Subsemigroup.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS)
suffices ⨆ i, S i ≤ U by simpa [U] using @this x
exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → NonUnitalSubring R}
(hS : Directed (· ≤ ·) S) : ((⨆ i, S i : NonUnitalSubring R) : Set R) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) {x : R} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists,
exists_prop]
theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubring R} {x : S} :
x ∈ K.map (f : R →ₙ+* S) ↔ f.symm x ∈ K :=
@Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x
theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubring R) :
K.map (f : R →ₙ+* S) = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubring S) :
K.comap (f : R →ₙ+* S) = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
open NonUnitalSubring
/-- Restriction of a ring homomorphism to its range interpreted as a `NonUnitalSubring`.
This is the bundled version of `Set.rangeFactorization`. -/
def rangeRestrict (f : R →ₙ+* S) : R →ₙ+* f.range :=
NonUnitalRingHom.codRestrict f f.range fun x => ⟨x, rfl⟩
@[simp]
theorem coe_rangeRestrict (f : R →ₙ+* S) (x : R) : (f.rangeRestrict x : S) = f x :=
rfl
theorem rangeRestrict_surjective (f : R →ₙ+* S) : Function.Surjective f.rangeRestrict :=
fun ⟨_y, hy⟩ =>
let ⟨x, hx⟩ := mem_range.mp hy
⟨x, Subtype.ext hx⟩
theorem range_eq_top {f : R →ₙ+* S} :
f.range = (⊤ : NonUnitalSubring S) ↔ Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
@[simp]
theorem range_eq_top_of_surjective (f : R →ₙ+* S) (hf : Function.Surjective f) :
f.range = (⊤ : NonUnitalSubring S) :=
range_eq_top.2 hf
/-- The `NonUnitalSubring` of elements `x : R` such that `f x = g x`, i.e.,
the equalizer of f and g as a `NonUnitalSubring` of R -/
def eqLocus (f g : R →ₙ+* S) : NonUnitalSubring R :=
{ (f : R →ₙ* S).eqLocus g, (f : R →+ S).eqLocus g with carrier := {x | f x = g x} }
@[simp]
theorem eqLocus_same (f : R →ₙ+* S) : f.eqLocus f = ⊤ :=
SetLike.ext fun _ => eq_self_iff_true _
/-- If two ring homomorphisms are equal on a set, then they are equal on its
`NonUnitalSubring` closure. -/
theorem eqOn_set_closure {f g : R →ₙ+* S} {s : Set R} (h : Set.EqOn f g s) :
Set.EqOn f g (closure s) :=
show closure s ≤ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_set_top {f g : R →ₙ+* S} (h : Set.EqOn f g (⊤ : NonUnitalSubring R)) : f = g :=
ext fun _x => h trivial
theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊤) {f g : R →ₙ+* S} (h : s.EqOn f g) :
f = g :=
eq_of_eqOn_set_top <| hs ▸ eqOn_set_closure h
theorem closure_preimage_le (f : R →ₙ+* S) (s : Set S) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a ring homomorphism of the `NonUnitalSubring` generated by a set equals
the `NonUnitalSubring` generated by the image of the set. -/
theorem map_closure (f : R →ₙ+* S) (s : Set R) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (NonUnitalSubring.gi S).gc
(NonUnitalSubring.gi R).gc fun _ ↦ rfl
end NonUnitalRingHom
namespace NonUnitalSubring
variable {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
open NonUnitalRingHom
@[simp]
theorem range_subtype (s : NonUnitalSubring R) : (NonUnitalSubringClass.subtype s).range = s :=
SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe
theorem range_fst : NonUnitalRingHom.srange (fst R S) = ⊤ :=
NonUnitalSubsemiring.range_fst
theorem range_snd : NonUnitalRingHom.srange (snd R S) = ⊤ :=
NonUnitalSubsemiring.range_snd
end NonUnitalSubring
namespace RingEquiv
variable {R : Type u} {S : Type v} [NonUnitalRing R] [NonUnitalRing S] {s t : NonUnitalSubring R}
/-- Makes the identity isomorphism from a proof two `NonUnitalSubring`s of a multiplicative
monoid are equal. -/
def nonUnitalSubringCongr (h : s = t) : s ≃+* t :=
{
Equiv.setCongr <| congr_arg _ h with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its
`RingHom.range`. -/
def ofLeftInverse' {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f) : R ≃+* f.range :=
{ f.rangeRestrict with
toFun := fun x => f.rangeRestrict x
invFun := fun x => (g ∘ NonUnitalSubringClass.subtype f.range) x
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := NonUnitalRingHom.mem_range.mp x.prop
show f (g x) = x by rw [← hx', h x'] }
@[simp]
theorem ofLeftInverse'_apply {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f) (x : R) :
↑(ofLeftInverse' h x) = f x :=
rfl
@[simp]
theorem ofLeftInverse'_symm_apply {g : S → R} {f : R →ₙ+* S} (h : Function.LeftInverse g f)
(x : f.range) : (ofLeftInverse' h).symm x = g x :=
rfl
end RingEquiv
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S]
theorem closure_preimage_le (f : F) (s : Set S) :
closure ((f : R → S) ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
end NonUnitalSubring
end Hom
|
sylow.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import fintype prime bigop finset fingroup morphism.
From mathcomp Require Import automorphism quotient action cyclic gproduct .
From mathcomp Require Import gfunctor commutator pgroup center nilpotent.
(******************************************************************************)
(* The Sylow theorem and its consequences, including the Frattini argument, *)
(* the nilpotence of p-groups, and the Baer-Suzuki theorem. *)
(* This file also defines: *)
(* Zgroup G == G is a Z-group, i.e., has only cyclic Sylow p-subgroups. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
(* The mod p lemma for the action of p-groups. *)
Section ModP.
Variable (aT : finGroupType) (sT : finType) (D : {group aT}).
Variable to : action D sT.
Lemma pgroup_fix_mod (p : nat) (G : {group aT}) (S : {set sT}) :
p.-group G -> [acts G, on S | to] -> #|S| = #|'Fix_(S | to)(G)| %[mod p].
Proof.
move=> pG nSG; have sGD: G \subset D := acts_dom nSG.
apply/eqP; rewrite -(cardsID 'Fix_to(G)) eqn_mod_dvd (leq_addr, addKn) //.
have: [acts G, on S :\: 'Fix_to(G) | to]; last move/acts_sum_card_orbit <-.
rewrite actsD // -(setIidPr sGD); apply: subset_trans (acts_subnorm_fix _ _).
by rewrite setIS ?normG.
apply: dvdn_sum => _ /imsetP[x /setDP[_ nfx] ->].
have [k oGx]: {k | #|orbit to G x| = (p ^ k)%N}.
by apply: p_natP; apply: pnat_dvd pG; rewrite card_orbit_in ?dvdn_indexg.
case: k oGx => [/card_orbit1 fix_x | k ->]; last by rewrite expnS dvdn_mulr.
by case/afixP: nfx => a Ga; apply/set1P; rewrite -fix_x mem_orbit.
Qed.
End ModP.
Section ModularGroupAction.
Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}).
Variables (to : groupAction D R) (p : nat).
Implicit Types (G H : {group aT}) (M : {group rT}).
Lemma nontrivial_gacent_pgroup G M :
p.-group G -> p.-group M -> {acts G, on group M | to} ->
M :!=: 1 -> 'C_(M | to)(G) :!=: 1.
Proof.
move=> pG pM [nMG sMR] ntM; have [p_pr p_dv_M _] := pgroup_pdiv pM ntM.
rewrite -cardG_gt1 (leq_trans (prime_gt1 p_pr)) 1?dvdn_leq ?cardG_gt0 //= /dvdn.
by rewrite gacentE ?(acts_dom nMG) // setIA (setIidPl sMR) -pgroup_fix_mod.
Qed.
Lemma pcore_sub_astab_irr G M :
p.-group M -> M \subset R -> acts_irreducibly G M to ->
'O_p(G) \subset 'C_G(M | to).
Proof.
move=> pM sMR /mingroupP[/andP[ntM nMG] minM].
have /andP[sGpG nGpG]: 'O_p(G) <| G := gFnormal _ G.
have sGD := acts_dom nMG; have sGpD: 'O_p(G) \subset D := gFsub_trans _ sGD.
rewrite subsetI sGpG -gacentC //=; apply/setIidPl; apply: minM (subsetIl _ _).
rewrite nontrivial_gacent_pgroup ?pcore_pgroup //=; last first.
by split; rewrite ?gFsub_trans.
by apply: subset_trans (acts_subnorm_subgacent sGpD nMG); rewrite subsetI subxx.
Qed.
Lemma pcore_faithful_irr_act G M :
p.-group M -> M \subset R -> acts_irreducibly G M to ->
[faithful G, on M | to] ->
'O_p(G) = 1.
Proof.
move=> pM sMR irrG ffulG; apply/trivgP; apply: subset_trans ffulG.
exact: pcore_sub_astab_irr.
Qed.
End ModularGroupAction.
Section Sylow.
Variables (p : nat) (gT : finGroupType) (G : {group gT}).
Implicit Types P Q H K : {group gT}.
Theorem Sylow's_theorem :
[/\ forall P, [max P | p.-subgroup(G) P] = p.-Sylow(G) P,
[transitive G, on 'Syl_p(G) | 'JG],
forall P, p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)|
& prime p -> #|'Syl_p(G)| %% p = 1%N].
Proof.
pose maxp A P := [max P | p.-subgroup(A) P]; pose S := [set P | maxp G P].
pose oG := orbit 'JG%act G.
have actS: [acts G, on S | 'JG].
apply/subsetP=> x Gx; rewrite 3!inE; apply/subsetP=> P; rewrite 3!inE.
exact: max_pgroupJ.
have S_pG P: P \in S -> P \subset G /\ p.-group P.
by rewrite inE => /maxgroupp/andP[].
have SmaxN P Q: Q \in S -> Q \subset 'N(P) -> maxp 'N_G(P) Q.
rewrite inE => /maxgroupP[/andP[sQG pQ] maxQ] nPQ.
apply/maxgroupP; rewrite /psubgroup subsetI sQG nPQ.
by split=> // R; rewrite subsetI -andbA andbCA => /andP[_]; apply: maxQ.
have nrmG P: P \subset G -> P <| 'N_G(P).
by move=> sPG; rewrite /normal subsetIr subsetI sPG normG.
have sylS P: P \in S -> p.-Sylow('N_G(P)) P.
move=> S_P; have [sPG pP] := S_pG P S_P.
by rewrite normal_max_pgroup_Hall ?nrmG //; apply: SmaxN; rewrite ?normG.
have{SmaxN} defCS P: P \in S -> 'Fix_(S |'JG)(P) = [set P].
move=> S_P; apply/setP=> Q; rewrite {1}in_setI {1}afixJG.
apply/andP/set1P=> [[S_Q nQP]|->{Q}]; last by rewrite normG.
apply/esym/val_inj; case: (S_pG Q) => //= sQG _.
by apply: uniq_normal_Hall (SmaxN Q _ _ _) => //=; rewrite ?sylS ?nrmG.
have{defCS} oG_mod: {in S &, forall P Q, #|oG P| = (Q \in oG P) %[mod p]}.
move=> P Q S_P S_Q; have [sQG pQ] := S_pG _ S_Q.
have soP_S: oG P \subset S by rewrite acts_sub_orbit.
have /pgroup_fix_mod-> //: [acts Q, on oG P | 'JG].
apply/actsP=> x /(subsetP sQG) Gx R; apply: orbit_transl.
exact: mem_orbit.
rewrite -{1}(setIidPl soP_S) -setIA defCS // (cardsD1 Q) setDE.
by rewrite -setIA setICr setI0 cards0 addn0 inE set11 andbT.
have [P S_P]: exists P, P \in S.
have: p.-subgroup(G) 1 by rewrite /psubgroup sub1G pgroup1.
by case/(@maxgroup_exists _ (p.-subgroup(G))) => P; exists P; rewrite inE.
have trS: [transitive G, on S | 'JG].
apply/imsetP; exists P => //; apply/eqP.
rewrite eqEsubset andbC acts_sub_orbit // S_P; apply/subsetP=> Q S_Q.
have /[1!inE] /maxgroupP[/andP[_ pP]] := S_P.
have [-> max1 | ntP _] := eqVneq P 1%G.
move/andP/max1: (S_pG _ S_Q) => Q1.
by rewrite (group_inj (Q1 (sub1G Q))) orbit_refl.
have:= oG_mod _ _ S_P S_P; rewrite (oG_mod _ Q) // orbit_refl.
have p_gt1: p > 1 by apply: prime_gt1; case/pgroup_pdiv: pP.
by case: (Q \in oG P) => //; rewrite mod0n modn_small.
have oS1: prime p -> #|S| %% p = 1%N.
move/prime_gt1 => p_gt1.
by rewrite -(atransP trS P S_P) (oG_mod P P) // orbit_refl modn_small.
have oSiN Q: Q \in S -> #|S| = #|G : 'N_G(Q)|.
by move=> S_Q; rewrite -(atransP trS Q S_Q) card_orbit astab1JG.
have sylP: p.-Sylow(G) P.
rewrite pHallE; case: (S_pG P) => // -> /= pP.
case p_pr: (prime p); last first.
rewrite p_part lognE p_pr /= -trivg_card1; apply/idPn=> ntP.
by case/pgroup_pdiv: pP p_pr => // ->.
rewrite -(LagrangeI G 'N(P)) /= mulnC partnM ?cardG_gt0 // part_p'nat.
by rewrite mul1n (card_Hall (sylS P S_P)).
by rewrite p'natE // -indexgI -oSiN // /dvdn oS1.
have eqS Q: maxp G Q = p.-Sylow(G) Q.
apply/idP/idP=> [S_Q|]; last exact: Hall_max.
have{} S_Q: Q \in S by rewrite inE.
rewrite pHallE -(card_Hall sylP); case: (S_pG Q) => // -> _ /=.
by case: (atransP2 trS S_P S_Q) => x _ ->; rewrite cardJg.
have ->: 'Syl_p(G) = S by apply/setP=> Q; rewrite 2!inE.
by split=> // Q sylQ; rewrite -oSiN ?inE ?eqS.
Qed.
Lemma max_pgroup_Sylow P : [max P | p.-subgroup(G) P] = p.-Sylow(G) P.
Proof. by case Sylow's_theorem. Qed.
Lemma Sylow_superset Q :
Q \subset G -> p.-group Q -> {P : {group gT} | p.-Sylow(G) P & Q \subset P}.
Proof.
move=> sQG pQ.
have [|P] := @maxgroup_exists _ (p.-subgroup(G)) Q; first exact/andP.
by rewrite max_pgroup_Sylow; exists P.
Qed.
Lemma Sylow_exists : {P : {group gT} | p.-Sylow(G) P}.
Proof. by case: (Sylow_superset (sub1G G) (pgroup1 _ p)) => P; exists P. Qed.
Lemma Syl_trans : [transitive G, on 'Syl_p(G) | 'JG].
Proof. by case Sylow's_theorem. Qed.
Lemma Sylow_trans P Q :
p.-Sylow(G) P -> p.-Sylow(G) Q -> exists2 x, x \in G & Q :=: P :^ x.
Proof.
move=> sylP sylQ; have /[!inE] := (atransP2 Syl_trans) P Q.
by case=> // x Gx ->; exists x.
Qed.
Lemma Sylow_subJ P Q :
p.-Sylow(G) P -> Q \subset G -> p.-group Q ->
exists2 x, x \in G & Q \subset P :^ x.
Proof.
move=> sylP sQG pQ; have [Px sylPx] := Sylow_superset sQG pQ.
by have [x Gx ->] := Sylow_trans sylP sylPx; exists x.
Qed.
Lemma Sylow_Jsub P Q :
p.-Sylow(G) P -> Q \subset G -> p.-group Q ->
exists2 x, x \in G & Q :^ x \subset P.
Proof.
move=> sylP sQG pQ; have [x Gx] := Sylow_subJ sylP sQG pQ.
by exists x^-1; rewrite (groupV, sub_conjgV).
Qed.
Lemma card_Syl P : p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)|.
Proof. by case: Sylow's_theorem P. Qed.
Lemma card_Syl_dvd : #|'Syl_p(G)| %| #|G|.
Proof. by case Sylow_exists => P /card_Syl->; apply: dvdn_indexg. Qed.
Lemma card_Syl_mod : prime p -> #|'Syl_p(G)| %% p = 1%N.
Proof. by case Sylow's_theorem. Qed.
Lemma Frattini_arg H P : G <| H -> p.-Sylow(G) P -> G * 'N_H(P) = H.
Proof.
case/andP=> sGH nGH sylP; rewrite -normC ?subIset ?nGH ?orbT // -astab1JG.
move/subgroup_transitiveP: Syl_trans => ->; rewrite ?inE //.
apply/imsetP; exists P; rewrite ?inE //.
apply/eqP; rewrite eqEsubset -{1}((atransP Syl_trans) P) ?inE // imsetS //=.
by apply/subsetP=> _ /imsetP[x Hx ->]; rewrite inE -(normsP nGH x Hx) pHallJ2.
Qed.
End Sylow.
Section MoreSylow.
Variables (gT : finGroupType) (p : nat).
Implicit Types G H P : {group gT}.
Lemma Sylow_setI_normal G H P :
G <| H -> p.-Sylow(H) P -> p.-Sylow(G) (G :&: P).
Proof.
case/normalP=> sGH nGH sylP; have [Q sylQ] := Sylow_exists p G.
have /maxgroupP[/andP[sQG pQ] maxQ] := Hall_max sylQ.
have [R sylR sQR] := Sylow_superset (subset_trans sQG sGH) pQ.
have [[x Hx ->] pR] := (Sylow_trans sylR sylP, pHall_pgroup sylR).
rewrite -(nGH x Hx) -conjIg pHallJ2.
have /maxQ-> //: Q \subset G :&: R by rewrite subsetI sQG.
by rewrite /psubgroup subsetIl (pgroupS _ pR) ?subsetIr.
Qed.
Lemma normal_sylowP G :
reflect (exists2 P : {group gT}, p.-Sylow(G) P & P <| G)
(#|'Syl_p(G)| == 1%N).
Proof.
apply: (iffP idP) => [syl1 | [P sylP nPG]]; last first.
by rewrite (card_Syl sylP) (setIidPl _) (indexgg, normal_norm).
have [P sylP] := Sylow_exists p G; exists P => //.
rewrite /normal (pHall_sub sylP); apply/setIidPl; apply/eqP.
rewrite eqEcard subsetIl -(LagrangeI G 'N(P)) -indexgI /=.
by rewrite -(card_Syl sylP) (eqP syl1) muln1.
Qed.
Lemma trivg_center_pgroup P : p.-group P -> 'Z(P) = 1 -> P :=: 1.
Proof.
move=> pP Z1; apply/eqP/idPn=> ntP.
have{ntP} [p_pr p_dv_P _] := pgroup_pdiv pP ntP.
suff: p %| #|'Z(P)| by rewrite Z1 cards1 gtnNdvd ?prime_gt1.
by rewrite /center /dvdn -afixJ -pgroup_fix_mod // astabsJ normG.
Qed.
Lemma p2group_abelian P : p.-group P -> logn p #|P| <= 2 -> abelian P.
Proof.
move=> pP lePp2; pose Z := 'Z(P); have sZP: Z \subset P := center_sub P.
have [/(trivg_center_pgroup pP) ->|] := eqVneq Z 1; first exact: abelian1.
case/(pgroup_pdiv (pgroupS sZP pP)) => p_pr _ [k oZ].
apply: cyclic_center_factor_abelian.
have [->|] := eqVneq (P / Z) 1; first exact: cyclic1.
have pPq := quotient_pgroup 'Z(P) pP; case/(pgroup_pdiv pPq) => _ _ [j oPq].
rewrite prime_cyclic // oPq; case: j oPq lePp2 => //= j.
rewrite card_quotient ?gFnorm //.
by rewrite -(Lagrange sZP) lognM // => ->; rewrite oZ !pfactorK ?addnS.
Qed.
Lemma card_p2group_abelian P : prime p -> #|P| = (p ^ 2)%N -> abelian P.
Proof.
move=> primep oP; have pP: p.-group P by rewrite /pgroup oP pnatX pnat_id.
by rewrite (p2group_abelian pP) // oP pfactorK.
Qed.
Lemma Sylow_transversal_gen (T : {set {group gT}}) G :
(forall P, P \in T -> P \subset G) ->
(forall p, p \in \pi(G) -> exists2 P, P \in T & p.-Sylow(G) P) ->
<< \bigcup_(P in T) P >> = G.
Proof.
move=> G_T T_G; apply/eqP; rewrite eqEcard gen_subG.
apply/andP; split; first exact/bigcupsP.
apply: dvdn_leq (cardG_gt0 _) _; apply/dvdn_partP=> // q /T_G[P T_P sylP].
by rewrite -(card_Hall sylP); apply: cardSg; rewrite sub_gen // bigcup_sup.
Qed.
Lemma Sylow_gen G : <<\bigcup_(P : {group gT} | Sylow G P) P>> = G.
Proof.
set T := [set P : {group gT} | Sylow G P].
rewrite -{2}(@Sylow_transversal_gen T G) => [|P | q _].
- by congr <<_>>; apply: eq_bigl => P; rewrite inE.
- by rewrite inE => /and3P[].
by case: (Sylow_exists q G) => P sylP; exists P; rewrite // inE (p_Sylow sylP).
Qed.
End MoreSylow.
Section SomeHall.
Variable gT : finGroupType.
Implicit Types (p : nat) (pi : nat_pred) (G H K P R : {group gT}).
Lemma Hall_pJsub p pi G H P :
pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P ->
exists2 x, x \in G & P :^ x \subset H.
Proof.
move=> hallH pi_p sPG pP.
have [S sylS] := Sylow_exists p H; have sylS_G := subHall_Sylow hallH pi_p sylS.
have [x Gx sPxS] := Sylow_Jsub sylS_G sPG pP; exists x => //.
exact: subset_trans sPxS (pHall_sub sylS).
Qed.
Lemma Hall_psubJ p pi G H P :
pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P ->
exists2 x, x \in G & P \subset H :^ x.
Proof.
move=> hallH pi_p sPG pP; have [x Gx sPxH] := Hall_pJsub hallH pi_p sPG pP.
by exists x^-1; rewrite ?groupV -?sub_conjg.
Qed.
Lemma Hall_setI_normal pi G K H :
K <| G -> pi.-Hall(G) H -> pi.-Hall(K) (H :&: K).
Proof.
move=> nsKG hallH; have [sHG piH _] := and3P hallH.
have [sHK_H sHK_K] := (subsetIl H K, subsetIr H K).
rewrite pHallE sHK_K /= -(part_pnat_id (pgroupS sHK_H piH)); apply/eqP.
rewrite (widen_partn _ (subset_leq_card sHK_K)); apply: eq_bigr => p pi_p.
have [P sylP] := Sylow_exists p H.
have sylPK := Sylow_setI_normal nsKG (subHall_Sylow hallH pi_p sylP).
rewrite -!p_part -(card_Hall sylPK); symmetry; apply: card_Hall.
by rewrite (pHall_subl _ sHK_K) //= setIC setSI ?(pHall_sub sylP).
Qed.
Lemma coprime_mulG_setI_norm H G K R :
K * R = G -> G \subset 'N(H) -> coprime #|K| #|R| ->
(K :&: H) * (R :&: H) = G :&: H.
Proof.
move=> defG nHG coKR; apply/eqP; rewrite eqEcard mulG_subG /= -defG.
rewrite !setSI ?mulG_subl ?mulG_subr //=.
rewrite coprime_cardMg ?(coKR, coprimeSg (subsetIl _ _), coprime_sym) //=.
pose pi := \pi(K); have piK: pi.-group K by apply: pgroup_pi.
have pi'R: pi^'.-group R by rewrite /pgroup -coprime_pi' /=.
have [hallK hallR] := coprime_mulpG_Hall defG piK pi'R.
have nsHG: H :&: G <| G by rewrite /normal subsetIr normsI ?normG.
rewrite -!(setIC H) defG -(partnC pi (cardG_gt0 _)).
rewrite -(card_Hall (Hall_setI_normal nsHG hallR)) /= setICA.
rewrite -(card_Hall (Hall_setI_normal nsHG hallK)) /= setICA.
by rewrite -defG (setIidPl (mulG_subl _ _)) (setIidPl (mulG_subr _ _)).
Qed.
End SomeHall.
Section Nilpotent.
Variable gT : finGroupType.
Implicit Types (G H K P L : {group gT}) (p q : nat).
Lemma pgroup_nil p P : p.-group P -> nilpotent P.
Proof.
move: {2}_.+1 (ltnSn #|P|) => n.
elim: n gT P => // n IHn pT P; rewrite ltnS=> lePn pP.
have [Z1 | ntZ] := eqVneq 'Z(P) 1.
by rewrite (trivg_center_pgroup pP Z1) nilpotent1.
rewrite -quotient_center_nil IHn ?morphim_pgroup // (leq_trans _ lePn) //.
rewrite card_quotient ?normal_norm ?center_normal // -divgS ?subsetIl //.
by rewrite ltn_Pdiv // ltnNge -trivg_card_le1.
Qed.
Lemma pgroup_sol p P : p.-group P -> solvable P.
Proof. by move/pgroup_nil; apply: nilpotent_sol. Qed.
Lemma small_nil_class G : nil_class G <= 5 -> nilpotent G.
Proof.
move=> leK5; case: (ltnP 5 #|G|) => [lt5G | leG5 {leK5}].
by rewrite nilpotent_class (leq_ltn_trans leK5).
apply: pgroup_nil (pdiv #|G|) _ _; apply/andP; split=> //.
by case: #|G| leG5 => //; do 5!case=> //.
Qed.
Lemma nil_class2 G : (nil_class G <= 2) = (G^`(1) \subset 'Z(G)).
Proof.
rewrite subsetI der_sub; apply/idP/commG1P=> [clG2 | L3G1].
by apply/(lcn_nil_classP 2); rewrite ?small_nil_class ?(leq_trans clG2).
by apply/(lcn_nil_classP 2) => //; apply/lcnP; exists 2.
Qed.
Lemma nil_class3 G : (nil_class G <= 3) = ('L_3(G) \subset 'Z(G)).
Proof.
rewrite subsetI lcn_sub; apply/idP/commG1P=> [clG3 | L4G1].
by apply/(lcn_nil_classP 3); rewrite ?small_nil_class ?(leq_trans clG3).
by apply/(lcn_nil_classP 3) => //; apply/lcnP; exists 3.
Qed.
Lemma nilpotent_maxp_normal pi G H :
nilpotent G -> [max H | pi.-subgroup(G) H] -> H <| G.
Proof.
move=> nilG /maxgroupP[/andP[sHG piH] maxH].
have nHN: H <| 'N_G(H) by rewrite normal_subnorm.
have{maxH} hallH: pi.-Hall('N_G(H)) H.
apply: normal_max_pgroup_Hall => //; apply/maxgroupP.
rewrite /psubgroup normal_sub // piH; split=> // K.
by rewrite subsetI -andbA andbCA => /andP[_ /maxH].
rewrite /normal sHG; apply/setIidPl/esym.
apply: nilpotent_sub_norm; rewrite ?subsetIl ?setIS //= char_norms //.
by congr (_ \char _): (pcore_char pi 'N_G(H)); apply: normal_Hall_pcore.
Qed.
Lemma nilpotent_Hall_pcore pi G H :
nilpotent G -> pi.-Hall(G) H -> H :=: 'O_pi(G).
Proof.
move=> nilG hallH; have maxH := Hall_max hallH; apply/eqP.
rewrite eqEsubset pcore_max ?(pHall_pgroup hallH) //.
by rewrite (normal_sub_max_pgroup maxH) ?pcore_pgroup ?pcore_normal.
exact: nilpotent_maxp_normal maxH.
Qed.
Lemma nilpotent_pcore_Hall pi G : nilpotent G -> pi.-Hall(G) 'O_pi(G).
Proof.
move=> nilG; case: (@maxgroup_exists _ (psubgroup pi G) 1) => [|H maxH _].
by rewrite /psubgroup sub1G pgroup1.
have hallH := normal_max_pgroup_Hall maxH (nilpotent_maxp_normal nilG maxH).
by rewrite -(nilpotent_Hall_pcore nilG hallH).
Qed.
Lemma nilpotent_pcoreC pi G : nilpotent G -> 'O_pi(G) \x 'O_pi^'(G) = G.
Proof.
move=> nilG; have trO: 'O_pi(G) :&: 'O_pi^'(G) = 1.
by apply: coprime_TIg; apply: (@pnat_coprime pi); apply: pcore_pgroup.
rewrite dprodE //.
apply/eqP; rewrite eqEcard mul_subG ?pcore_sub // (TI_cardMg trO).
by rewrite !(card_Hall (nilpotent_pcore_Hall _ _)) // partnC ?leqnn.
rewrite (sameP commG1P trivgP) -trO subsetI commg_subl commg_subr.
by rewrite !gFsub_trans ?gFnorm.
Qed.
Lemma sub_nilpotent_cent2 H K G :
nilpotent G -> K \subset G -> H \subset G -> coprime #|K| #|H| ->
H \subset 'C(K).
Proof.
move=> nilG sKG sHG; rewrite coprime_pi' // => p'H.
have sub_Gp := sub_Hall_pcore (nilpotent_pcore_Hall _ nilG).
have [_ _ cGpp' _] := dprodP (nilpotent_pcoreC \pi(K) nilG).
by apply: centSS cGpp'; rewrite sub_Gp ?pgroup_pi.
Qed.
Lemma pi_center_nilpotent G : nilpotent G -> \pi('Z(G)) = \pi(G).
Proof.
move=> nilG; apply/eq_piP => /= p.
apply/idP/idP=> [|pG]; first exact: (piSg (center_sub _)).
move: (pG); rewrite !mem_primes !cardG_gt0; case/andP=> p_pr _.
pose Z := 'O_p(G) :&: 'Z(G); have ntZ: Z != 1.
rewrite meet_center_nil ?pcore_normal // trivg_card_le1 -ltnNge.
rewrite (card_Hall (nilpotent_pcore_Hall p nilG)) p_part.
by rewrite (ltn_exp2l 0 _ (prime_gt1 p_pr)) logn_gt0.
have pZ: p.-group Z := pgroupS (subsetIl _ _) (pcore_pgroup _ _).
have{ntZ pZ} [_ pZ _] := pgroup_pdiv pZ ntZ.
by rewrite p_pr (dvdn_trans pZ) // cardSg ?subsetIr.
Qed.
Lemma Sylow_subnorm p G P : p.-Sylow('N_G(P)) P = p.-Sylow(G) P.
Proof.
apply/idP/idP=> sylP; last first.
apply: pHall_subl (subsetIl _ _) (sylP).
by rewrite subsetI normG (pHall_sub sylP).
have [/subsetIP[sPG sPN] pP _] := and3P sylP.
have [Q sylQ sPQ] := Sylow_superset sPG pP; have [sQG pQ _] := and3P sylQ.
rewrite -(nilpotent_sub_norm (pgroup_nil pQ) sPQ) {sylQ}//.
rewrite subEproper eq_sym eqEcard subsetI sPQ sPN dvdn_leq //.
rewrite -(part_pnat_id (pgroupS (subsetIl _ _) pQ)) (card_Hall sylP).
by rewrite partn_dvd // cardSg ?setSI.
Qed.
End Nilpotent.
Lemma nil_class_pgroup (gT : finGroupType) (p : nat) (P : {group gT}) :
p.-group P -> nil_class P <= maxn 1 (logn p #|P|).-1.
Proof.
move=> pP; move def_c: (nil_class P) => c.
elim: c => // c IHc in gT P def_c pP *; set e := logn p _.
have nilP := pgroup_nil pP; have sZP := center_sub P.
have [e_le2 | e_gt2] := leqP e 2.
by rewrite -def_c leq_max nil_class1 (p2group_abelian pP).
have pPq: p.-group (P / 'Z(P)) by apply: quotient_pgroup.
rewrite -(subnKC e_gt2) ltnS (leq_trans (IHc _ _ _ pPq)) //.
by rewrite nil_class_quotient_center ?def_c.
rewrite geq_max /= -add1n -leq_subLR -subn1 -subnDA -subSS leq_sub2r //.
rewrite ltn_log_quotient //= -(setIidPr sZP) meet_center_nil //.
by rewrite -nil_class0 def_c.
Qed.
Definition Zgroup (gT : finGroupType) (A : {set gT}) :=
[forall (V : {group gT} | Sylow A V), cyclic V].
Section Zgroups.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Implicit Types G H K : {group gT}.
Lemma ZgroupS G H : H \subset G -> Zgroup G -> Zgroup H.
Proof.
move=> sHG /forallP zgG; apply/forall_inP=> V /SylowP[p p_pr /and3P[sVH]].
case/(Sylow_superset (subset_trans sVH sHG))=> P sylP sVP _.
by have:= zgG P; rewrite (p_Sylow sylP); apply: cyclicS.
Qed.
Lemma morphim_Zgroup G : Zgroup G -> Zgroup (f @* G).
Proof.
move=> zgG; wlog sGD: G zgG / G \subset D.
by rewrite -morphimIdom; apply; rewrite (ZgroupS _ zgG, subsetIl) ?subsetIr.
apply/forall_inP=> fV /SylowP[p pr_p sylfV].
have [P sylP] := Sylow_exists p G.
have [|z _ ->] := @Sylow_trans p _ _ (f @* P)%G _ _ sylfV.
by apply: morphim_pHall (sylP); apply: subset_trans (pHall_sub sylP) sGD.
by rewrite cyclicJ morphim_cyclic ?(forall_inP zgG) //; apply/SylowP; exists p.
Qed.
Lemma nil_Zgroup_cyclic G : Zgroup G -> nilpotent G -> cyclic G.
Proof.
have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn ZgG nilG.
have [->|[p pr_p pG]] := trivgVpdiv G; first by rewrite -cycle1 cycle_cyclic.
have /dprodP[_ defG Cpp' _] := nilpotent_pcoreC p nilG.
have /cyclicP[x def_p]: cyclic 'O_p(G).
have:= forallP ZgG 'O_p(G)%G.
by rewrite (p_Sylow (nilpotent_pcore_Hall p nilG)).
have /cyclicP[x' def_p']: cyclic 'O_p^'(G).
have sp'G := pcore_sub p^' G.
apply: IHn (leq_trans _ leGn) (ZgroupS sp'G _) (nilpotentS sp'G _) => //.
rewrite proper_card // properEneq sp'G andbT; case: eqP => //= def_p'.
by have:= pcore_pgroup p^' G; rewrite def_p' /pgroup p'natE ?pG.
apply/cyclicP; exists (x * x'); rewrite -{}defG def_p def_p' cycleM //.
by red; rewrite -(centsP Cpp') // (def_p, def_p') cycle_id.
by rewrite /order -def_p -def_p' (@pnat_coprime p) //; apply: pcore_pgroup.
Qed.
End Zgroups.
Arguments Zgroup {gT} A%_g.
Section NilPGroups.
Variables (p : nat) (gT : finGroupType).
Implicit Type G P N : {group gT}.
(* B & G 1.22 p.9 *)
Lemma normal_pgroup r P N :
p.-group P -> N <| P -> r <= logn p #|N| ->
exists Q : {group gT}, [/\ Q \subset N, Q <| P & #|Q| = (p ^ r)%N].
Proof.
elim: r gT P N => [|r IHr] gTr P N pP nNP le_r.
by exists (1%G : {group gTr}); rewrite sub1G normal1 cards1.
have [NZ_1 | ntNZ] := eqVneq (N :&: 'Z(P)) 1.
by rewrite (TI_center_nil (pgroup_nil pP)) // cards1 logn1 in le_r.
have: p.-group (N :&: 'Z(P)) by apply: pgroupS pP; rewrite /= setICA subsetIl.
case/pgroup_pdiv=> // p_pr /Cauchy[// | z].
rewrite -cycle_subG !subsetI => /and3P[szN szP cPz] ozp _.
have{cPz} nzP: P \subset 'N(<[z]>) by rewrite cents_norm // centsC.
have: N / <[z]> <| P / <[z]> by rewrite morphim_normal.
case/IHr=> [||Qb [sQNb nQPb]]; first exact: morphim_pgroup.
rewrite card_quotient ?(subset_trans (normal_sub nNP)) // -ltnS.
apply: (leq_trans le_r); rewrite -(Lagrange szN) [#|_|]ozp.
by rewrite lognM // ?prime_gt0 // logn_prime ?eqxx.
case/(inv_quotientN _): nQPb sQNb => [|Q -> szQ nQP]; first exact/andP.
have nzQ := subset_trans (normal_sub nQP) nzP.
rewrite quotientSGK // card_quotient // => sQN izQ.
by exists Q; split=> //; rewrite expnS -izQ -ozp Lagrange.
Qed.
Theorem Baer_Suzuki x G :
x \in G -> (forall y, y \in G -> p.-group <<[set x; x ^ y]>>) ->
x \in 'O_p(G).
Proof.
have [n] := ubnP #|G|; elim: n G x => // n IHn G x /ltnSE-leGn Gx pE.
set E := x ^: G; have{} pE: {in E &, forall x1 x2, p.-group <<[set x1; x2]>>}.
move=> _ _ /imsetP[y1 Gy1 ->] /imsetP[y2 Gy2 ->].
rewrite -(mulgKV y1 y2) conjgM -2!conjg_set1 -conjUg genJ pgroupJ.
by rewrite pE // groupMl ?groupV.
have sEG: <<E>> \subset G by rewrite gen_subG class_subG.
have nEG: G \subset 'N(E) by apply: class_norm.
have Ex: x \in E by apply: class_refl.
have [P Px sylP]: exists2 P : {group gT}, x \in P & p.-Sylow(<<E>>) P.
have sxxE: <<[set x; x]>> \subset <<E>> by rewrite genS // setUid sub1set.
have{sxxE} [P sylP sxxP] := Sylow_superset sxxE (pE _ _ Ex Ex).
by exists P => //; rewrite (subsetP sxxP) ?mem_gen ?setU11.
case sEP: (E \subset P).
apply: subsetP Ex; rewrite -gen_subG; apply: pcore_max.
by apply: pgroupS (pHall_pgroup sylP); rewrite gen_subG.
by rewrite /normal gen_subG class_subG // norms_gen.
pose P_yD D := [pred y in E :\: P | p.-group <<y |: D>>].
pose P_D := [pred D : {set gT} | D \subset P :&: E & [exists y, P_yD D y]].
have{Ex Px}: P_D [set x].
rewrite /= sub1set inE Px Ex; apply/existsP=> /=.
by case/subsetPn: sEP => y Ey Py; exists y; rewrite inE Ey Py pE.
case/(@maxset_exists _ P_D)=> D /maxsetP[]; rewrite {P_yD P_D}/=.
rewrite subsetI sub1set -andbA => /and3P[sDP sDE /existsP[y0]].
set B := _ |: D; rewrite inE -andbA => /and3P[Py0 Ey0 pB] maxD Dx.
have sDgE: D \subset <<E>> by apply: sub_gen.
have sDG: D \subset G by apply: subset_trans sEG.
have sBE: B \subset E by rewrite subUset sub1set Ey0.
have sBG: <<B>> \subset G by apply: subset_trans (genS _) sEG.
have sDB: D \subset B by rewrite subsetUr.
have defD: D :=: P :&: <<B>> :&: E.
apply/eqP; rewrite eqEsubset ?subsetI sDP sDE sub_gen //=.
apply/setUidPl; apply: maxD; last apply: subsetUl.
rewrite subUset subsetI sDP sDE setIAC subsetIl.
apply/existsP; exists y0; rewrite inE Py0 Ey0 /= setUA -/B.
by rewrite -[<<_>>]joing_idl joingE setKI genGid.
have nDD: D \subset 'N(D).
apply/subsetP=> z Dz; rewrite inE defD.
apply/subsetP=> _ /imsetP[y /setIP[PBy Ey] ->].
rewrite inE groupJ // ?inE ?(subsetP sDP) ?mem_gen ?setU1r //= memJ_norm //.
exact: (subsetP (subset_trans sDG nEG)).
case nDG: (G \subset 'N(D)).
apply: subsetP Dx; rewrite -gen_subG pcore_max ?(pgroupS (genS _) pB) //.
by rewrite /normal gen_subG sDG norms_gen.
have{n leGn IHn nDG} pN: p.-group <<'N_E(D)>>.
apply: pgroupS (pcore_pgroup p 'N_G(D)); rewrite gen_subG /=.
apply/subsetP=> x1 /setIP[Ex1 Nx1]; apply: IHn => [||y Ny].
- apply: leq_trans leGn; rewrite proper_card // /proper subsetIl.
by rewrite subsetI nDG andbF.
- by rewrite inE Nx1 (subsetP sEG) ?mem_gen.
have Ex1y: x1 ^ y \in E.
by rewrite -mem_conjgV (normsP nEG) // groupV; case/setIP: Ny.
by apply: pgroupS (genS _) (pE _ _ Ex1 Ex1y); apply/subsetP => u /[!inE].
have [y1 Ny1 Py1]: exists2 y1, y1 \in 'N_E(D) & y1 \notin P.
case sNN: ('N_<<B>>('N_<<B>>(D)) \subset 'N_<<B>>(D)).
exists y0 => //; have By0: y0 \in <<B>> by rewrite mem_gen ?setU11.
rewrite inE Ey0 -By0 -in_setI.
by rewrite -['N__(D)](nilpotent_sub_norm (pgroup_nil pB)) ?subsetIl.
case/subsetPn: sNN => z /setIP[Bz NNz]; rewrite inE Bz inE.
case/subsetPn=> y; rewrite mem_conjg => Dzy Dy.
have:= Dzy; rewrite {1}defD; do 2![case/setIP]=> _ Bzy Ezy.
have Ey: y \in E by rewrite -(normsP nEG _ (subsetP sBG z Bz)) mem_conjg.
have /setIP[By Ny]: y \in 'N_<<B>>(D).
by rewrite -(normP NNz) mem_conjg inE Bzy ?(subsetP nDD).
exists y; first by rewrite inE Ey.
by rewrite defD 2!inE Ey By !andbT in Dy.
have [y2 Ny2 Dy2]: exists2 y2, y2 \in 'N_(P :&: E)(D) & y2 \notin D.
case sNN: ('N_P('N_P(D)) \subset 'N_P(D)).
have [z /= Ez sEzP] := Sylow_Jsub sylP (genS sBE) pB.
have Gz: z \in G by apply: subsetP Ez.
have /subsetPn[y Bzy Dy]: ~~ (B :^ z \subset D).
apply/negP; move/subset_leq_card; rewrite cardJg cardsU1.
by rewrite {1}defD 2!inE (negPf Py0) ltnn.
exists y => //; apply: subsetP Bzy.
rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV // sBE.
have nilP := pgroup_nil (pHall_pgroup sylP).
by rewrite -['N__(_)](nilpotent_sub_norm nilP) ?subsetIl // -gen_subG genJ.
case/subsetPn: sNN => z /setIP[Pz NNz]; rewrite 2!inE Pz.
case/subsetPn=> y Dzy Dy; exists y => //; apply: subsetP Dzy.
rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV //.
by rewrite sDE -(normP NNz); rewrite conjSg subsetI sDP.
by apply: subsetP Pz; apply: (subset_trans (pHall_sub sylP)).
suff{Dy2} Dy2D: y2 |: D = D by rewrite -Dy2D setU11 in Dy2.
apply: maxD; last by rewrite subsetUr.
case/setIP: Ny2 => PEy2 Ny2; case/setIP: Ny1 => Ey1 Ny1.
rewrite subUset sub1set PEy2 subsetI sDP sDE.
apply/existsP; exists y1; rewrite inE Ey1 Py1; apply: pgroupS pN.
rewrite genS // !subUset !sub1set !in_setI Ey1 Ny1.
by case/setIP: PEy2 => _ ->; rewrite Ny2 subsetI sDE.
Qed.
End NilPGroups.
|
Basic.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.MetricSpace.Basic
/-!
# Metrizability of a T₃ topological space with second countable topology
In this file we define metrizable topological spaces, i.e., topological spaces for which there
exists a metric space structure that generates the same topology.
-/
open Filter Set Metric Topology
namespace TopologicalSpace
variable {ι X Y : Type*} {A : ι → Type*} [TopologicalSpace X] [TopologicalSpace Y] [Finite ι]
[∀ i, TopologicalSpace (A i)]
/-- A topological space is *pseudo metrizable* if there exists a pseudo metric space structure
compatible with the topology. To endow such a space with a compatible distance, use
`letI : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X`. -/
class PseudoMetrizableSpace (X : Type*) [t : TopologicalSpace X] : Prop where
exists_pseudo_metric : ∃ m : PseudoMetricSpace X, m.toUniformSpace.toTopologicalSpace = t
instance (priority := 100) _root_.PseudoMetricSpace.toPseudoMetrizableSpace {X : Type*}
[m : PseudoMetricSpace X] : PseudoMetrizableSpace X :=
⟨⟨m, rfl⟩⟩
/-- Construct on a metrizable space a metric compatible with the topology. -/
noncomputable def pseudoMetrizableSpacePseudoMetric (X : Type*) [TopologicalSpace X]
[h : PseudoMetrizableSpace X] : PseudoMetricSpace X :=
h.exists_pseudo_metric.choose.replaceTopology h.exists_pseudo_metric.choose_spec.symm
instance pseudoMetrizableSpace_prod [PseudoMetrizableSpace X] [PseudoMetrizableSpace Y] :
PseudoMetrizableSpace (X × Y) :=
letI : PseudoMetricSpace X := pseudoMetrizableSpacePseudoMetric X
letI : PseudoMetricSpace Y := pseudoMetrizableSpacePseudoMetric Y
inferInstance
/-- Given an inducing map of a topological space into a pseudo metrizable space, the source space
is also pseudo metrizable. -/
theorem _root_.Topology.IsInducing.pseudoMetrizableSpace [PseudoMetrizableSpace Y] {f : X → Y}
(hf : IsInducing f) : PseudoMetrizableSpace X :=
letI : PseudoMetricSpace Y := pseudoMetrizableSpacePseudoMetric Y
⟨⟨hf.comapPseudoMetricSpace, rfl⟩⟩
/-- Every pseudo-metrizable space is first countable. -/
instance (priority := 100) PseudoMetrizableSpace.firstCountableTopology
[h : PseudoMetrizableSpace X] : FirstCountableTopology X := by
rcases h with ⟨_, hm⟩
rw [← hm]
exact @UniformSpace.firstCountableTopology X PseudoMetricSpace.toUniformSpace
EMetric.instIsCountablyGeneratedUniformity
instance PseudoMetrizableSpace.subtype [PseudoMetrizableSpace X] (s : Set X) :
PseudoMetrizableSpace s :=
IsInducing.subtypeVal.pseudoMetrizableSpace
instance pseudoMetrizableSpace_pi [∀ i, PseudoMetrizableSpace (A i)] :
PseudoMetrizableSpace (∀ i, A i) := by
cases nonempty_fintype ι
letI := fun i => pseudoMetrizableSpacePseudoMetric (A i)
infer_instance
/-- A topological space is metrizable if there exists a metric space structure compatible with the
topology. To endow such a space with a compatible distance, use
`letI : MetricSpace X := TopologicalSpace.metrizableSpaceMetric X`. -/
class MetrizableSpace (X : Type*) [t : TopologicalSpace X] : Prop where
exists_metric : ∃ m : MetricSpace X, m.toUniformSpace.toTopologicalSpace = t
instance (priority := 100) _root_.MetricSpace.toMetrizableSpace {X : Type*} [m : MetricSpace X] :
MetrizableSpace X :=
⟨⟨m, rfl⟩⟩
instance (priority := 100) MetrizableSpace.toPseudoMetrizableSpace [h : MetrizableSpace X] :
PseudoMetrizableSpace X :=
let ⟨m, hm⟩ := h.1
⟨⟨m.toPseudoMetricSpace, hm⟩⟩
instance (priority := 100) PseudoMetrizableSpace.toMetrizableSpace
[T0Space X] [h : PseudoMetrizableSpace X] : MetrizableSpace X :=
letI := pseudoMetrizableSpacePseudoMetric X
⟨.ofT0PseudoMetricSpace X, rfl⟩
/-- Construct on a metrizable space a metric compatible with the topology. -/
noncomputable def metrizableSpaceMetric (X : Type*) [TopologicalSpace X] [h : MetrizableSpace X] :
MetricSpace X :=
h.exists_metric.choose.replaceTopology h.exists_metric.choose_spec.symm
instance (priority := 100) t2Space_of_metrizableSpace [MetrizableSpace X] : T2Space X :=
letI : MetricSpace X := metrizableSpaceMetric X
inferInstance
instance metrizableSpace_prod [MetrizableSpace X] [MetrizableSpace Y] : MetrizableSpace (X × Y) :=
letI : MetricSpace X := metrizableSpaceMetric X
letI : MetricSpace Y := metrizableSpaceMetric Y
inferInstance
/-- Given an embedding of a topological space into a metrizable space, the source space is also
metrizable. -/
theorem _root_.Topology.IsEmbedding.metrizableSpace [MetrizableSpace Y] {f : X → Y}
(hf : IsEmbedding f) : MetrizableSpace X :=
letI : MetricSpace Y := metrizableSpaceMetric Y
⟨⟨hf.comapMetricSpace f, rfl⟩⟩
instance MetrizableSpace.subtype [MetrizableSpace X] (s : Set X) : MetrizableSpace s :=
IsEmbedding.subtypeVal.metrizableSpace
instance metrizableSpace_pi [∀ i, MetrizableSpace (A i)] : MetrizableSpace (∀ i, A i) := by
cases nonempty_fintype ι
letI := fun i => metrizableSpaceMetric (A i)
infer_instance
theorem IsSeparable.secondCountableTopology [PseudoMetrizableSpace X] {s : Set X}
(hs : IsSeparable s) : SecondCountableTopology s := by
letI := pseudoMetrizableSpacePseudoMetric X
have := hs.separableSpace
exact UniformSpace.secondCountable_of_separable s
instance (X : Type*) [TopologicalSpace X] [c : CompactSpace X] [MetrizableSpace X] :
SecondCountableTopology X := by
obtain ⟨_, h⟩ := MetrizableSpace.exists_metric (X := X)
rw [← h] at c ⊢
infer_instance
end TopologicalSpace
|
Faithful.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.GroupWithZero.NeZero
/-!
# Faithful actions involving groups with zero
-/
assert_not_exists Equiv.Perm.equivUnitsEnd Prod.fst_mul Ring
open Function
variable {α : Type*}
/-- `Monoid.toMulAction` is faithful on nontrivial cancellative monoids with zero. -/
instance CancelMonoidWithZero.faithfulSMul [CancelMonoidWithZero α] [Nontrivial α] :
FaithfulSMul α α where eq_of_smul_eq_smul h := mul_left_injective₀ one_ne_zero (h 1)
|
WalkDecomp.lean
|
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Pim Otte
-/
import Mathlib.Combinatorics.SimpleGraph.Walk
/-!
# Decomposing walks
## Main definitions
- `takeUntil`: The path obtained by taking edges of an existing path until a given vertex.
- `dropUntil`: The path obtained by dropping edges of an existing path until a given vertex.
- `rotate`: Rotate a loop walk such that it is centered at the given vertex.
-/
namespace SimpleGraph.Walk
universe u
variable {V : Type u} {G : SimpleGraph V} {v w u : V}
/-! ### Walk decompositions -/
section WalkDecomp
variable [DecidableEq V]
/-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/
def takeUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk v u
| nil, u, h => by rw [mem_support_nil_iff.mp h]
| cons r p, u, h =>
if hx : v = u then
hx ▸ Walk.nil
else
cons r (takeUntil p u <| by
cases h
· exact (hx rfl).elim
· assumption)
@[simp] theorem takeUntil_nil {u : V} {h} : takeUntil (nil : G.Walk u u) u h = nil := rfl
lemma takeUntil_cons {v' : V} {p : G.Walk v' v} (hwp : w ∈ p.support) (h : u ≠ w)
(hadj : G.Adj u v') :
(p.cons hadj).takeUntil w (List.mem_of_mem_tail hwp) = (p.takeUntil w hwp).cons hadj := by
simp [Walk.takeUntil, h]
@[simp]
lemma takeUntil_first (p : G.Walk u v) :
p.takeUntil u p.start_mem_support = .nil := by cases p <;> simp [Walk.takeUntil]
@[simp]
lemma nil_takeUntil (p : G.Walk u v) (hwp : w ∈ p.support) :
(p.takeUntil w hwp).Nil ↔ u = w := by
refine ⟨?_, fun h => by subst h; simp⟩
intro hnil
cases p with
| nil => simp only [takeUntil, eq_mpr_eq_cast] at hnil; exact hnil.eq
| cons h q =>
simp only [support_cons, List.mem_cons] at hwp
obtain hl | hr := hwp
· exact hl.symm
· by_contra! hc
simp [takeUntil_cons hr hc] at hnil
/-- Given a vertex in the support of a path, give the path from (and including) that vertex to
the end. In other words, drop vertices from the front of a path until (and not including)
that vertex. -/
def dropUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk u w
| nil, u, h => by rw [mem_support_nil_iff.mp h]
| cons r p, u, h =>
if hx : v = u then by
subst u
exact cons r p
else dropUntil p u <| by
cases h
· exact (hx rfl).elim
· assumption
/-- The `takeUntil` and `dropUntil` functions split a walk into two pieces.
The lemma `SimpleGraph.Walk.count_support_takeUntil_eq_one` specifies where this split occurs. -/
@[simp]
theorem take_spec {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).append (p.dropUntil u h) = p := by
induction p
· rw [mem_support_nil_iff] at h
subst u
rfl
· cases h
· simp!
· simp! only
split_ifs with h' <;> subst_vars <;> simp [*]
theorem mem_support_iff_exists_append {V : Type u} {G : SimpleGraph V} {u v w : V}
{p : G.Walk u v} : w ∈ p.support ↔ ∃ (q : G.Walk u w) (r : G.Walk w v), p = q.append r := by
classical
constructor
· exact fun h => ⟨_, _, (p.take_spec h).symm⟩
· rintro ⟨q, r, rfl⟩
simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self_iff]
@[simp]
theorem count_support_takeUntil_eq_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).support.count u = 1 := by
induction p
· rw [mem_support_nil_iff] at h
subst u
simp
· cases h
· simp
· simp! only
split_ifs with h' <;> rw [eq_comm] at h' <;> subst_vars <;> simp! [*, List.count_cons]
theorem count_edges_takeUntil_le_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) (x : V) :
(p.takeUntil u h).edges.count s(u, x) ≤ 1 := by
induction p with
| nil =>
rw [mem_support_nil_iff] at h
subst u
simp
| cons ha p' ih =>
cases h
· simp
· simp! only
split_ifs with h'
· subst h'
simp
· rw [edges_cons, List.count_cons]
split_ifs with h''
· simp only [beq_iff_eq, Sym2.eq, Sym2.rel_iff'] at h''
obtain ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ := h''
· exact (h' rfl).elim
· cases p' <;> simp!
· apply ih
@[simp]
theorem takeUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w')
(h : u ∈ (p.copy hv hw).support) :
(p.copy hv hw).takeUntil u h = (p.takeUntil u (by subst_vars; exact h)).copy hv rfl := by
subst_vars
rfl
@[simp]
theorem dropUntil_copy {u v w v' w'} (p : G.Walk v w) (hv : v = v') (hw : w = w')
(h : u ∈ (p.copy hv hw).support) :
(p.copy hv hw).dropUntil u h = (p.dropUntil u (by subst_vars; exact h)).copy rfl hw := by
subst_vars
rfl
theorem support_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).support ⊆ p.support := fun x hx => by
rw [← take_spec p h, mem_support_append_iff]
exact Or.inl hx
theorem support_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.dropUntil u h).support ⊆ p.support := fun x hx => by
rw [← take_spec p h, mem_support_append_iff]
exact Or.inr hx
theorem darts_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).darts ⊆ p.darts := fun x hx => by
rw [← take_spec p h, darts_append, List.mem_append]
exact Or.inl hx
theorem darts_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.dropUntil u h).darts ⊆ p.darts := fun x hx => by
rw [← take_spec p h, darts_append, List.mem_append]
exact Or.inr hx
theorem edges_takeUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).edges ⊆ p.edges :=
List.map_subset _ (p.darts_takeUntil_subset h)
theorem edges_dropUntil_subset {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.dropUntil u h).edges ⊆ p.edges :=
List.map_subset _ (p.darts_dropUntil_subset h)
theorem length_takeUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.takeUntil u h).length ≤ p.length := by
have := congr_arg Walk.length (p.take_spec h)
rw [length_append] at this
exact Nat.le.intro this
theorem length_dropUntil_le {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) :
(p.dropUntil u h).length ≤ p.length := by
have := congr_arg Walk.length (p.take_spec h)
rw [length_append, add_comm] at this
exact Nat.le.intro this
lemma getVert_takeUntil {u v : V} {n : ℕ} {p : G.Walk u v} (hw : w ∈ p.support)
(hn : n ≤ (p.takeUntil w hw).length) : (p.takeUntil w hw).getVert n = p.getVert n := by
cases p with
| nil => simp only [support_nil, List.mem_singleton] at hw; aesop
| cons h q =>
by_cases huw : w = u
· subst huw
simp_all
simp only [support_cons, List.mem_cons, huw, false_or] at hw
by_cases hn0 : n = 0
· aesop
simp only [takeUntil_cons hw ((Ne.eq_def _ _).mpr huw).symm, length_cons,
getVert_cons _ _ hn0] at hn ⊢
apply q.getVert_takeUntil hw
omega
lemma snd_takeUntil (hsu : w ≠ u) (p : G.Walk u v) (h : w ∈ p.support) :
(p.takeUntil w h).snd = p.snd := by
apply p.getVert_takeUntil h
by_contra! hc
simp only [Nat.lt_one_iff, ← nil_iff_length_eq, nil_takeUntil] at hc
exact hsu hc.symm
lemma length_takeUntil_lt {u v w : V} {p : G.Walk v w} (h : u ∈ p.support) (huw : u ≠ w) :
(p.takeUntil u h).length < p.length := by
rw [(p.length_takeUntil_le h).lt_iff_ne]
exact fun hl ↦ huw (by simpa using (hl ▸ getVert_takeUntil h (by rfl) :
(p.takeUntil u h).getVert (p.takeUntil u h).length = p.getVert p.length))
lemma takeUntil_takeUntil {w x : V} (p : G.Walk u v) (hw : w ∈ p.support)
(hx : x ∈ (p.takeUntil w hw).support) :
(p.takeUntil w hw).takeUntil x hx = p.takeUntil x (p.support_takeUntil_subset hw hx) := by
induction p, w, hw using takeUntil.induct with
| case1 u v h =>
#adaptation_note
/-- Prior to `nightly-2025-02-24` this was just `aesop`. -/
simp at h
subst h
simp
| case2 _ _ q _ hadj hu' =>
simp only [takeUntil_first, support_nil, List.mem_singleton] at hx
subst hx
simp
| case3 a w' v' hadj q u' hu' hau' ih =>
rw [← Ne.eq_def] at hau'
simp only [support_cons, List.mem_cons, hau'.symm, false_or] at hu'
simp only [takeUntil_cons hu' hau' hadj, support_cons, List.mem_cons] at hx
by_cases hx' : x = a
· aesop
· replace hx : x ∈ (q.takeUntil u' hu').support := by simpa [hx'] using hx
push_neg at hx'
conv_lhs =>
enter [1]
rw [takeUntil_cons hu' hau' hadj]
rw [takeUntil_cons hx hx'.symm hadj, ih _, takeUntil_cons _ hx'.symm]
lemma notMem_support_takeUntil_support_takeUntil_subset {p : G.Walk u v} {w x : V} (h : x ≠ w)
(hw : w ∈ p.support) (hx : x ∈ (p.takeUntil w hw).support) :
w ∉ (p.takeUntil x (p.support_takeUntil_subset hw hx)).support := by
rw [← takeUntil_takeUntil p hw hx]
intro hw'
have h1 : (((p.takeUntil w hw).takeUntil x hx).takeUntil w hw').length
< ((p.takeUntil w hw).takeUntil x hx).length := by
exact length_takeUntil_lt _ h.symm
have h2 : ((p.takeUntil w hw).takeUntil x hx).length < (p.takeUntil w hw).length := by
exact length_takeUntil_lt _ h
simp only [takeUntil_takeUntil] at h1 h2
omega
@[deprecated (since := "2025-05-23")]
alias not_mem_support_takeUntil_support_takeUntil_subset :=
notMem_support_takeUntil_support_takeUntil_subset
/-- Rotate a loop walk such that it is centered at the given vertex. -/
def rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) : G.Walk u u :=
(c.dropUntil u h).append (c.takeUntil u h)
@[simp]
theorem support_rotate {u v : V} (c : G.Walk v v) (h : u ∈ c.support) :
(c.rotate h).support.tail ~r c.support.tail := by
simp only [rotate, tail_support_append]
apply List.IsRotated.trans List.isRotated_append
rw [← tail_support_append, take_spec]
theorem rotate_darts {u v : V} (c : G.Walk v v) (h : u ∈ c.support) :
(c.rotate h).darts ~r c.darts := by
simp only [rotate, darts_append]
apply List.IsRotated.trans List.isRotated_append
rw [← darts_append, take_spec]
theorem rotate_edges {u v : V} (c : G.Walk v v) (h : u ∈ c.support) :
(c.rotate h).edges ~r c.edges :=
(rotate_darts c h).map _
end WalkDecomp
/-- Given a walk `w` and a node in the support, there exists a natural `n`, such that given node
is the `n`-th node (zero-indexed) in the walk. In addition, `n` is at most the length of the path.
Due to the definition of `getVert` it would otherwise be legal to return a larger `n` for the last
node. -/
theorem mem_support_iff_exists_getVert {u v w : V} {p : G.Walk v w} :
u ∈ p.support ↔ ∃ n, p.getVert n = u ∧ n ≤ p.length := by
classical
constructor
· intro h
obtain ⟨q, r, hqr⟩ := SimpleGraph.Walk.mem_support_iff_exists_append.mp h
use q.length
rw [hqr, Walk.getVert_append]
simp only [lt_self_iff_false, ↓reduceIte, Nat.sub_self, getVert_zero, length_append,
Nat.le_add_right, and_self]
· rintro ⟨n, hn⟩
rw [mem_support_iff]
cases n with
| zero => aesop
| succ n =>
right
have hnp : ¬ p.Nil := by
rw [nil_iff_length_eq]
omega
rw [← support_tail_of_not_nil _ hnp, mem_support_iff_exists_getVert]
use n
rwa [getVert_tail, ← Nat.add_one_le_add_one_iff, length_tail_add_one hnp]
termination_by p.length
decreasing_by
· simp_wf
rw [Nat.lt_iff_add_one_le, length_tail_add_one hnp]
end SimpleGraph.Walk
|
OrderIso.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Order.Hom.Basic
/-!
# Inverse and multiplication as order isomorphisms in ordered groups
-/
open Function
universe u
variable {α : Type u}
section Group
variable [Group α]
section TypeclassesLeftRightLE
variable [LE α] [MulLeftMono α] [MulRightMono α] {a b : α}
section
variable (α)
/-- `x ↦ x⁻¹` as an order-reversing equivalence. -/
@[to_additive (attr := simps!) /-- `x ↦ -x` as an order-reversing equivalence. -/]
def OrderIso.inv : α ≃o αᵒᵈ where
toEquiv := (Equiv.inv α).trans OrderDual.toDual
map_rel_iff' {_ _} := inv_le_inv_iff (α := α)
end
@[to_additive neg_le]
theorem inv_le' : a⁻¹ ≤ b ↔ b⁻¹ ≤ a :=
(OrderIso.inv α).symm_apply_le
alias ⟨inv_le_of_inv_le', _⟩ := inv_le'
attribute [to_additive neg_le_of_neg_le] inv_le_of_inv_le'
@[to_additive le_neg]
theorem le_inv' : a ≤ b⁻¹ ↔ b ≤ a⁻¹ :=
(OrderIso.inv α).le_symm_apply
/-- `x ↦ a / x` as an order-reversing equivalence. -/
@[to_additive (attr := simps!) /-- `x ↦ a - x` as an order-reversing equivalence. -/]
def OrderIso.divLeft (a : α) : α ≃o αᵒᵈ where
toEquiv := (Equiv.divLeft a).trans OrderDual.toDual
map_rel_iff' {_ _} := div_le_div_iff_left (α := α) _
end TypeclassesLeftRightLE
end Group
alias ⟨le_inv_of_le_inv, _⟩ := le_inv'
attribute [to_additive] le_inv_of_le_inv
section Group
variable [Group α] [LE α]
section Right
variable [MulRightMono α] {a : α}
/-- `Equiv.mulRight` as an `OrderIso`. See also `OrderEmbedding.mulRight`. -/
@[to_additive (attr := simps! +simpRhs toEquiv apply)
/-- `Equiv.addRight` as an `OrderIso`. See also `OrderEmbedding.addRight`. -/]
def OrderIso.mulRight (a : α) : α ≃o α where
map_rel_iff' {_ _} := mul_le_mul_iff_right a
toEquiv := Equiv.mulRight a
@[to_additive (attr := simp)]
theorem OrderIso.mulRight_symm (a : α) : (OrderIso.mulRight a).symm = OrderIso.mulRight a⁻¹ := by
ext x
rfl
/-- `x ↦ x / a` as an order isomorphism. -/
@[to_additive (attr := simps!) /-- `x ↦ x - a` as an order isomorphism. -/]
def OrderIso.divRight (a : α) : α ≃o α where
toEquiv := Equiv.divRight a
map_rel_iff' {_ _} := div_le_div_iff_right a
end Right
section Left
variable [MulLeftMono α]
/-- `Equiv.mulLeft` as an `OrderIso`. See also `OrderEmbedding.mulLeft`. -/
@[to_additive (attr := simps! +simpRhs toEquiv apply)
/-- `Equiv.addLeft` as an `OrderIso`. See also `OrderEmbedding.addLeft`. -/]
def OrderIso.mulLeft (a : α) : α ≃o α where
map_rel_iff' {_ _} := mul_le_mul_iff_left a
toEquiv := Equiv.mulLeft a
@[to_additive (attr := simp)]
theorem OrderIso.mulLeft_symm (a : α) : (OrderIso.mulLeft a).symm = OrderIso.mulLeft a⁻¹ := by
ext x
rfl
end Left
end Group
|
Sequence.lean
|
/-
Copyright (c) 2024 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.Topology.Compactification.OnePoint.Basic
import Mathlib.Topology.Category.LightProfinite.Basic
/-!
# The light profinite set classifying convergent sequences
This files defines the light profinite set `ℕ∪{∞}`, defined as the one point compactification of
`ℕ`.
-/
open CategoryTheory OnePoint TopologicalSpace Topology
namespace LightProfinite
/-- The continuous map from `ℕ∪{∞}` to `ℝ` sending `n` to `1/(n+1)` and `∞` to `0`. -/
noncomputable def natUnionInftyEmbedding : C(OnePoint ℕ, ℝ) where
toFun
| ∞ => 0
| OnePoint.some n => 1 / (n + 1 : ℝ)
continuous_toFun := OnePoint.continuous_iff_from_nat _ |>.mpr
tendsto_one_div_add_atTop_nhds_zero_nat
/--
The continuous map from `ℕ∪{∞}` to `ℝ` sending `n` to `1/(n+1)` and `∞` to `0` is a closed
embedding.
-/
lemma isClosedEmbedding_natUnionInftyEmbedding : IsClosedEmbedding natUnionInftyEmbedding := by
refine .of_continuous_injective_isClosedMap
natUnionInftyEmbedding.continuous ?_ ?_
· rintro (_ | n) (_ | m) h
· rfl
· simp only [natUnionInftyEmbedding, one_div, ContinuousMap.coe_mk, zero_eq_inv] at h
assumption_mod_cast
· simp only [natUnionInftyEmbedding, one_div, ContinuousMap.coe_mk, inv_eq_zero] at h
assumption_mod_cast
· simp only [natUnionInftyEmbedding, one_div, ContinuousMap.coe_mk, inv_inj, add_left_inj,
Nat.cast_inj] at h
rw [h]
· exact fun _ hC => (hC.isCompact.image natUnionInftyEmbedding.continuous).isClosed
instance : MetrizableSpace (OnePoint ℕ) := isClosedEmbedding_natUnionInftyEmbedding.metrizableSpace
/-- The one point compactification of the natural numbers as a light profinite set. -/
abbrev NatUnionInfty : LightProfinite := of (OnePoint ℕ)
@[inherit_doc]
scoped notation "ℕ∪{∞}" => NatUnionInfty
instance : Coe ℕ ℕ∪{∞} := optionCoe
open Filter Topology
lemma continuous_iff_convergent {Y : Type*} [TopologicalSpace Y] (f : ℕ∪{∞} → Y) :
Continuous f ↔ Tendsto (fun x : ℕ ↦ f x) atTop (𝓝 (f ∞)) :=
continuous_iff_from_nat f
end LightProfinite
|
Sign.lean
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Data.Sign.Defs
import Mathlib.Topology.Order.Basic
/-!
# Topology on `SignType`
This file gives `SignType` the discrete topology, and proves continuity results for `SignType.sign`
in an `OrderTopology`.
-/
instance : TopologicalSpace SignType :=
⊥
instance : DiscreteTopology SignType :=
⟨rfl⟩
variable {α : Type*} [Zero α] [TopologicalSpace α]
section PartialOrder
variable [PartialOrder α] [DecidableLT α] [OrderTopology α]
theorem continuousAt_sign_of_pos {a : α} (h : 0 < a) : ContinuousAt SignType.sign a := by
refine (continuousAt_const : ContinuousAt (fun _ => (1 : SignType)) a).congr ?_
rw [Filter.EventuallyEq, eventually_nhds_iff]
exact ⟨{ x | 0 < x }, fun x hx => (sign_pos hx).symm, isOpen_lt' 0, h⟩
theorem continuousAt_sign_of_neg {a : α} (h : a < 0) : ContinuousAt SignType.sign a := by
refine (continuousAt_const : ContinuousAt (fun x => (-1 : SignType)) a).congr ?_
rw [Filter.EventuallyEq, eventually_nhds_iff]
exact ⟨{ x | x < 0 }, fun x hx => (sign_neg hx).symm, isOpen_gt' 0, h⟩
end PartialOrder
section LinearOrder
variable [LinearOrder α] [OrderTopology α]
theorem continuousAt_sign_of_ne_zero {a : α} (h : a ≠ 0) : ContinuousAt SignType.sign a := by
rcases h.lt_or_gt with (h_neg | h_pos)
· exact continuousAt_sign_of_neg h_neg
· exact continuousAt_sign_of_pos h_pos
end LinearOrder
|
PiProd.lean
|
/-
Copyright (c) 2024 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts
import Mathlib.CategoryTheory.Limits.Shapes.Products
/-!
# A product as a binary product
We write a product indexed by `I` as a binary product of the products indexed by a subset of `I`
and its complement.
-/
namespace CategoryTheory.Limits
variable {C I : Type*} [Category C] {X Y : I → C}
(f : (i : I) → X i ⟶ Y i) (P : I → Prop)
[HasProduct X] [HasProduct Y]
[HasProduct (fun (i : {x : I // P x}) ↦ X i.val)]
[HasProduct (fun (i : {x : I // ¬ P x}) ↦ X i.val)]
[HasProduct (fun (i : {x : I // P x}) ↦ Y i.val)]
[HasProduct (fun (i : {x : I // ¬ P x}) ↦ Y i.val)]
variable (X) in
/--
The projection maps of a product to the products indexed by a subset and its complement, as a
binary fan.
-/
noncomputable def Pi.binaryFanOfProp : BinaryFan (∏ᶜ (fun (i : {x : I // P x}) ↦ X i.val))
(∏ᶜ (fun (i : {x : I // ¬ P x}) ↦ X i.val)) :=
BinaryFan.mk (P := ∏ᶜ X) (Pi.map' Subtype.val fun _ ↦ 𝟙 _)
(Pi.map' Subtype.val fun _ ↦ 𝟙 _)
variable (X) in
/--
A product indexed by `I` is a binary product of the products indexed by a subset of `I` and its
complement.
-/
noncomputable def Pi.binaryFanOfPropIsLimit [∀ i, Decidable (P i)] :
IsLimit (Pi.binaryFanOfProp X P) :=
BinaryFan.isLimitMk
(fun s ↦ Pi.lift fun b ↦ if h : P b then
s.π.app ⟨WalkingPair.left⟩ ≫ Pi.π (fun (i : {x : I // P x}) ↦ X i.val) ⟨b, h⟩ else
s.π.app ⟨WalkingPair.right⟩ ≫ Pi.π (fun (i : {x : I // ¬ P x}) ↦ X i.val) ⟨b, h⟩)
(by aesop) (by aesop)
(fun _ _ h₁ h₂ ↦ Pi.hom_ext _ _ fun b ↦ by
by_cases h : P b
· simp [← h₁, dif_pos h]
· simp [← h₂, dif_neg h])
lemma hasBinaryProduct_of_products : HasBinaryProduct (∏ᶜ (fun (i : {x : I // P x}) ↦ X i.val))
(∏ᶜ (fun (i : {x : I // ¬ P x}) ↦ X i.val)) := by
classical exact ⟨Pi.binaryFanOfProp X P, Pi.binaryFanOfPropIsLimit X P⟩
attribute [local instance] hasBinaryProduct_of_products
lemma Pi.map_eq_prod_map [∀ i, Decidable (P i)] : Pi.map f =
((Pi.binaryFanOfPropIsLimit X P).conePointUniqueUpToIso (prodIsProd _ _)).hom ≫
prod.map (Pi.map (fun (i : {x : I // P x}) ↦ f i.val))
(Pi.map (fun (i : {x : I // ¬ P x}) ↦ f i.val)) ≫
((Pi.binaryFanOfPropIsLimit Y P).conePointUniqueUpToIso (prodIsProd _ _)).inv := by
rw [← Category.assoc, Iso.eq_comp_inv]
dsimp only [IsLimit.conePointUniqueUpToIso, binaryFanOfProp, prodIsProd]
apply prod.hom_ext
all_goals cat_disch
end CategoryTheory.Limits
|
Diam.lean
|
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import Mathlib.Topology.EMetricSpace.Pi
/-!
# Diameters of sets in extended metric spaces
-/
open Set Filter
open scoped Uniformity Topology Filter NNReal ENNReal Pointwise
universe u v w
variable {α β : Type*} {s : Set α} {x y z : α}
namespace EMetric
section
variable [PseudoEMetricSpace α]
/-- The diameter of a set in a pseudoemetric space, named `EMetric.diam` -/
noncomputable def diam (s : Set α) :=
⨆ (x ∈ s) (y ∈ s), edist x y
theorem diam_eq_sSup (s : Set α) : diam s = sSup (image2 edist s s) := sSup_image2.symm
theorem diam_le_iff {d : ℝ≥0∞} : diam s ≤ d ↔ ∀ x ∈ s, ∀ y ∈ s, edist x y ≤ d := by
simp only [diam, iSup_le_iff]
theorem diam_image_le_iff {d : ℝ≥0∞} {f : β → α} {s : Set β} :
diam (f '' s) ≤ d ↔ ∀ x ∈ s, ∀ y ∈ s, edist (f x) (f y) ≤ d := by
simp only [diam_le_iff, forall_mem_image]
theorem edist_le_of_diam_le {d} (hx : x ∈ s) (hy : y ∈ s) (hd : diam s ≤ d) : edist x y ≤ d :=
diam_le_iff.1 hd x hx y hy
/-- If two points belong to some set, their edistance is bounded by the diameter of the set -/
theorem edist_le_diam_of_mem (hx : x ∈ s) (hy : y ∈ s) : edist x y ≤ diam s :=
edist_le_of_diam_le hx hy le_rfl
/-- If the distance between any two points in a set is bounded by some constant, this constant
bounds the diameter. -/
theorem diam_le {d : ℝ≥0∞} (h : ∀ x ∈ s, ∀ y ∈ s, edist x y ≤ d) : diam s ≤ d :=
diam_le_iff.2 h
/-- The diameter of a subsingleton vanishes. -/
theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 :=
nonpos_iff_eq_zero.1 <| diam_le fun _x hx y hy => (hs hx hy).symm ▸ edist_self y ▸ le_rfl
/-- The diameter of the empty set vanishes -/
@[simp]
theorem diam_empty : diam (∅ : Set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- The diameter of a singleton vanishes -/
@[simp]
theorem diam_singleton : diam ({x} : Set α) = 0 :=
diam_subsingleton subsingleton_singleton
@[to_additive (attr := simp)]
theorem diam_one [One α] : diam (1 : Set α) = 0 :=
diam_singleton
theorem diam_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) :
diam (⋃ i ∈ o, s i) = ⨆ i ∈ o, diam (s i) := by cases o <;> simp
theorem diam_insert : diam (insert x s) = max (⨆ y ∈ s, edist x y) (diam s) :=
eq_of_forall_ge_iff fun d => by
simp only [diam_le_iff, forall_mem_insert, edist_self, edist_comm x, max_le_iff, iSup_le_iff,
zero_le, true_and, forall_and, and_self_iff, ← and_assoc]
theorem diam_pair : diam ({x, y} : Set α) = edist x y := by
simp only [iSup_singleton, diam_insert, diam_singleton, ENNReal.max_zero_right]
theorem diam_triple : diam ({x, y, z} : Set α) = max (max (edist x y) (edist x z)) (edist y z) := by
simp only [diam_insert, iSup_insert, iSup_singleton, diam_singleton, ENNReal.max_zero_right]
/-- The diameter is monotonous with respect to inclusion -/
@[gcongr]
theorem diam_mono {s t : Set α} (h : s ⊆ t) : diam s ≤ diam t :=
diam_le fun _x hx _y hy => edist_le_diam_of_mem (h hx) (h hy)
/-- The diameter of a union is controlled by the diameter of the sets, and the edistance
between two points in the sets. -/
theorem diam_union {t : Set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + edist x y + diam t := by
have A : ∀ a ∈ s, ∀ b ∈ t, edist a b ≤ diam s + edist x y + diam t := fun a ha b hb =>
calc
edist a b ≤ edist a x + edist x y + edist y b := edist_triangle4 _ _ _ _
_ ≤ diam s + edist x y + diam t :=
add_le_add (add_le_add (edist_le_diam_of_mem ha xs) le_rfl) (edist_le_diam_of_mem yt hb)
refine diam_le fun a ha b hb => ?_
rcases (mem_union _ _ _).1 ha with h'a | h'a <;> rcases (mem_union _ _ _).1 hb with h'b | h'b
· calc
edist a b ≤ diam s := edist_le_diam_of_mem h'a h'b
_ ≤ diam s + (edist x y + diam t) := le_self_add
_ = diam s + edist x y + diam t := (add_assoc _ _ _).symm
· exact A a h'a b h'b
· have Z := A b h'b a h'a
rwa [edist_comm] at Z
· calc
edist a b ≤ diam t := edist_le_diam_of_mem h'a h'b
_ ≤ diam s + edist x y + diam t := le_add_self
theorem diam_union' {t : Set α} (h : (s ∩ t).Nonempty) : diam (s ∪ t) ≤ diam s + diam t := by
let ⟨x, ⟨xs, xt⟩⟩ := h
simpa using diam_union xs xt
theorem diam_closedBall {r : ℝ≥0∞} : diam (closedBall x r) ≤ 2 * r :=
diam_le fun a ha b hb =>
calc
edist a b ≤ edist a x + edist b x := edist_triangle_right _ _ _
_ ≤ r + r := add_le_add ha hb
_ = 2 * r := (two_mul r).symm
theorem diam_ball {r : ℝ≥0∞} : diam (ball x r) ≤ 2 * r :=
le_trans (diam_mono ball_subset_closedBall) diam_closedBall
theorem diam_pi_le_of_le {X : β → Type*} [Fintype β] [∀ b, PseudoEMetricSpace (X b)]
{s : ∀ b : β, Set (X b)} {c : ℝ≥0∞} (h : ∀ b, diam (s b) ≤ c) : diam (Set.pi univ s) ≤ c := by
refine diam_le fun x hx y hy => edist_pi_le_iff.mpr ?_
rw [mem_univ_pi] at hx hy
exact fun b => diam_le_iff.1 (h b) (x b) (hx b) (y b) (hy b)
end
section
variable [EMetricSpace β] {s : Set β}
theorem diam_eq_zero_iff : diam s = 0 ↔ s.Subsingleton :=
⟨fun h _x hx _y hy => edist_le_zero.1 <| h ▸ edist_le_diam_of_mem hx hy, diam_subsingleton⟩
theorem diam_pos_iff : 0 < diam s ↔ s.Nontrivial := by
simp only [pos_iff_ne_zero, Ne, diam_eq_zero_iff, Set.not_subsingleton_iff]
theorem diam_pos_iff' : 0 < diam s ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y := by
simp only [diam_pos_iff, Set.Nontrivial]
end
end EMetric
|
Resolution.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Kim Morrison, Joël Riou
-/
import Mathlib.Algebra.Homology.QuasiIso
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.Algebra.Homology.SingleHomology
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
/-!
# Injective resolutions
An injective resolution `I : InjectiveResolution Z` of an object `Z : C` consists of
an `ℕ`-indexed cochain complex `I.cocomplex` of injective objects,
along with a quasi-isomorphism `I.ι` from the cochain complex consisting just of `Z`
in degree zero to `I.cocomplex`.
```
Z ----> 0 ----> ... ----> 0 ----> ...
| | |
| | |
v v v
I⁰ ---> I¹ ---> ... ----> Iⁿ ---> ...
```
-/
noncomputable section
universe v u
namespace CategoryTheory
open Limits HomologicalComplex CochainComplex
variable {C : Type u} [Category.{v} C] [HasZeroObject C] [HasZeroMorphisms C]
/--
An `InjectiveResolution Z` consists of a bundled `ℕ`-indexed cochain complex of injective objects,
along with a quasi-isomorphism from the complex consisting of just `Z` supported in degree `0`.
-/
structure InjectiveResolution (Z : C) where
/-- the cochain complex involved in the resolution -/
cocomplex : CochainComplex C ℕ
/-- the cochain complex must be degreewise injective -/
injective : ∀ n, Injective (cocomplex.X n) := by infer_instance
/-- the cochain complex must have homology -/
[hasHomology : ∀ i, cocomplex.HasHomology i]
/-- the morphism from the single cochain complex with `Z` in degree `0` -/
ι : (single₀ C).obj Z ⟶ cocomplex
/-- the morphism from the single cochain complex with `Z` in degree `0` is a quasi-isomorphism -/
quasiIso : QuasiIso ι := by infer_instance
open InjectiveResolution in
attribute [instance] injective hasHomology InjectiveResolution.quasiIso
/-- An object admits an injective resolution. -/
class HasInjectiveResolution (Z : C) : Prop where
out : Nonempty (InjectiveResolution Z)
attribute [inherit_doc HasInjectiveResolution] HasInjectiveResolution.out
section
variable (C)
/-- You will rarely use this typeclass directly: it is implied by the combination
`[EnoughInjectives C]` and `[Abelian C]`. -/
class HasInjectiveResolutions : Prop where
out : ∀ Z : C, HasInjectiveResolution Z
attribute [instance 100] HasInjectiveResolutions.out
end
namespace InjectiveResolution
variable {Z : C} (I : InjectiveResolution Z)
lemma cocomplex_exactAt_succ (n : ℕ) :
I.cocomplex.ExactAt (n + 1) := by
rw [← quasiIsoAt_iff_exactAt I.ι (n + 1) (exactAt_succ_single_obj _ _)]
infer_instance
lemma exact_succ (n : ℕ) :
(ShortComplex.mk _ _ (I.cocomplex.d_comp_d n (n + 1) (n + 2))).Exact :=
(HomologicalComplex.exactAt_iff' _ n (n + 1) (n + 2) (by simp)
(by simp only [CochainComplex.next]; rfl)).1 (I.cocomplex_exactAt_succ n)
@[simp]
theorem ι_f_succ (n : ℕ) : I.ι.f (n + 1) = 0 :=
(isZero_single_obj_X _ _ _ _ (by simp)).eq_of_src _ _
@[reassoc]
theorem ι_f_zero_comp_complex_d :
I.ι.f 0 ≫ I.cocomplex.d 0 1 = 0 := by
simp
theorem complex_d_comp (n : ℕ) :
I.cocomplex.d n (n + 1) ≫ I.cocomplex.d (n + 1) (n + 2) = 0 := by
simp
/-- The (limit) kernel fork given by the composition
`Z ⟶ I.cocomplex.X 0 ⟶ I.cocomplex.X 1` when `I : InjectiveResolution Z`. -/
@[simp]
def kernelFork : KernelFork (I.cocomplex.d 0 1) :=
KernelFork.ofι _ I.ι_f_zero_comp_complex_d
/-- `Z` is the kernel of `I.cocomplex.X 0 ⟶ I.cocomplex.X 1` when `I : InjectiveResolution Z`. -/
def isLimitKernelFork : IsLimit (I.kernelFork) := by
refine IsLimit.ofIsoLimit (I.cocomplex.cyclesIsKernel 0 1 (by simp)) (Iso.symm ?_)
refine Fork.ext ((singleObjHomologySelfIso _ _ _).symm ≪≫
isoOfQuasiIsoAt I.ι 0 ≪≫ I.cocomplex.isoHomologyπ₀.symm) ?_
rw [← cancel_epi (singleObjHomologySelfIso (ComplexShape.up ℕ) _ _).hom,
← cancel_epi (isoHomologyπ₀ _).hom,
← cancel_epi (singleObjCyclesSelfIso (ComplexShape.up ℕ) _ _).inv]
simp
instance (n : ℕ) : Mono (I.ι.f n) := by
cases n
· exact mono_of_isLimit_fork I.isLimitKernelFork
· rw [ι_f_succ]; infer_instance
variable (Z)
/-- An injective object admits a trivial injective resolution: itself in degree 0. -/
@[simps]
def self [Injective Z] : InjectiveResolution Z where
cocomplex := (CochainComplex.single₀ C).obj Z
ι := 𝟙 ((CochainComplex.single₀ C).obj Z)
injective n := by
cases n
· simpa
· apply IsZero.injective
apply HomologicalComplex.isZero_single_obj_X
simp
end InjectiveResolution
end CategoryTheory
|
Clear_.lean
|
/-
Copyright (c) 2022 Joshua Clune. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joshua Clune
-/
import Mathlib.Init
import Lean.Meta.Tactic.Clear
import Lean.Elab.Tactic.Basic
/-! # `clear_` tactic -/
namespace Mathlib.Tactic
open Lean Meta Elab.Tactic
/-- Clear all hypotheses starting with `_`, like `_match` and `_let_match`. -/
elab (name := clear_) "clear_" : tactic =>
liftMetaTactic1 fun goal ↦ do
let mut toClear := #[]
for decl in ← getLCtx do
if let Name.str _ str := decl.userName then
if !str.isEmpty && str.front == '_' then
if let none ← isClass? decl.type then
toClear := toClear.push decl.fvarId
goal.tryClearMany toClear
end Mathlib.Tactic
|
Core.lean
|
/-
Copyright (c) 2022 Mario Carneiro, Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Heather Macbeth, Yaël Dillies
-/
import Mathlib.Tactic.NormNum.Core
import Mathlib.Tactic.HaveI
import Mathlib.Algebra.Order.Invertible
import Mathlib.Algebra.Order.Ring.Cast
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Cast.Basic
import Qq
/-!
## `positivity` core functionality
This file sets up the `positivity` tactic and the `@[positivity]` attribute,
which allow for plugging in new positivity functionality around a positivity-based driver.
The actual behavior is in `@[positivity]`-tagged definitions in `Tactic.Positivity.Basic`
and elsewhere.
-/
open Lean
open Lean.Meta Qq Lean.Elab Term
/-- Attribute for identifying `positivity` extensions. -/
syntax (name := positivity) "positivity " term,+ : attr
lemma ne_of_ne_of_eq' {α : Sort*} {a c b : α} (hab : (a : α) ≠ c) (hbc : a = b) : b ≠ c := hbc ▸ hab
namespace Mathlib.Meta.Positivity
variable {u : Level} {α : Q(Type u)} (zα : Q(Zero $α)) (pα : Q(PartialOrder $α))
/-- The result of `positivity` running on an expression `e` of type `α`. -/
inductive Strictness (e : Q($α)) where
| positive (pf : Q(0 < $e))
| nonnegative (pf : Q(0 ≤ $e))
| nonzero (pf : Q($e ≠ 0))
| none
deriving Repr
/-- Gives a generic description of the `positivity` result. -/
def Strictness.toString {e : Q($α)} : Strictness zα pα e → String
| positive _ => "positive"
| nonnegative _ => "nonnegative"
| nonzero _ => "nonzero"
| none => "none"
/-- Extract a proof that `e` is positive, if possible, from `Strictness` information about `e`. -/
def Strictness.toPositive {e} : Strictness zα pα e → Option Q(0 < $e)
| .positive pf => some pf
| _ => .none
/-- Extract a proof that `e` is nonnegative, if possible, from `Strictness` information about `e`.
-/
def Strictness.toNonneg {e} : Strictness zα pα e → Option Q(0 ≤ $e)
| .positive pf => some q(le_of_lt $pf)
| .nonnegative pf => some pf
| _ => .none
/-- Extract a proof that `e` is nonzero, if possible, from `Strictness` information about `e`. -/
def Strictness.toNonzero {e} : Strictness zα pα e → Option Q($e ≠ 0)
| .positive pf => some q(ne_of_gt $pf)
| .nonzero pf => some pf
| _ => .none
/-- An extension for `positivity`. -/
structure PositivityExt where
/-- Attempts to prove an expression `e : α` is `>0`, `≥0`, or `≠0`. -/
eval {u : Level} {α : Q(Type u)} (zα : Q(Zero $α)) (pα : Q(PartialOrder $α)) (e : Q($α)) :
MetaM (Strictness zα pα e)
/-- Read a `positivity` extension from a declaration of the right type. -/
def mkPositivityExt (n : Name) : ImportM PositivityExt := do
let { env, opts, .. } ← read
IO.ofExcept <| unsafe env.evalConstCheck PositivityExt opts ``PositivityExt n
/-- Each `positivity` extension is labelled with a collection of patterns
which determine the expressions to which it should be applied. -/
abbrev Entry := Array (Array DiscrTree.Key) × Name
/-- Environment extensions for `positivity` declarations -/
initialize positivityExt : PersistentEnvExtension Entry (Entry × PositivityExt)
(List Entry × DiscrTree PositivityExt) ←
-- we only need this to deduplicate entries in the DiscrTree
have : BEq PositivityExt := ⟨fun _ _ => false⟩
let insert kss v dt := kss.foldl (fun dt ks => dt.insertCore ks v) dt
registerPersistentEnvExtension {
mkInitial := pure ([], {})
addImportedFn := fun s => do
let dt ← s.foldlM (init := {}) fun dt s => s.foldlM (init := dt) fun dt (kss, n) => do
pure (insert kss (← mkPositivityExt n) dt)
pure ([], dt)
addEntryFn := fun (entries, s) ((kss, n), ext) => ((kss, n) :: entries, insert kss ext s)
exportEntriesFn := fun s => s.1.reverse.toArray
}
initialize registerBuiltinAttribute {
name := `positivity
descr := "adds a positivity extension"
applicationTime := .afterCompilation
add := fun declName stx kind => match stx with
| `(attr| positivity $es,*) => do
unless kind == AttributeKind.global do
throwError "invalid attribute 'positivity', must be global"
let env ← getEnv
unless (env.getModuleIdxFor? declName).isNone do
throwError "invalid attribute 'positivity', declaration is in an imported module"
if (IR.getSorryDep env declName).isSome then return -- ignore in progress definitions
let ext ← mkPositivityExt declName
let keys ← MetaM.run' <| es.getElems.mapM fun stx => do
let e ← TermElabM.run' <| withSaveInfoContext <| withAutoBoundImplicit <|
withReader ({ · with ignoreTCFailures := true }) do
let e ← elabTerm stx none
let (_, _, e) ← lambdaMetaTelescope (← mkLambdaFVars (← getLCtx).getFVars e)
return e
DiscrTree.mkPath e
setEnv <| positivityExt.addEntry env ((keys, declName), ext)
| _ => throwUnsupportedSyntax
}
variable {A : Type*} {e : A}
lemma pos_of_isNat {n : ℕ} [Semiring A] [PartialOrder A] [IsOrderedRing A] [Nontrivial A]
(h : NormNum.IsNat e n) (w : Nat.ble 1 n = true) : 0 < (e : A) := by
rw [NormNum.IsNat.to_eq h rfl]
apply Nat.cast_pos.2
simpa using w
lemma pos_of_isNat' {n : ℕ}
[AddMonoidWithOne A] [PartialOrder A] [AddLeftMono A] [ZeroLEOneClass A] [h'' : NeZero (1 : A)]
(h : NormNum.IsNat e n) (w : Nat.ble 1 n = true) : 0 < (e : A) := by
rw [NormNum.IsNat.to_eq h rfl]
apply Nat.cast_pos'.2
simpa using w
lemma nonneg_of_isNat {n : ℕ} [Semiring A] [PartialOrder A] [IsOrderedRing A]
(h : NormNum.IsNat e n) : 0 ≤ (e : A) := by
rw [NormNum.IsNat.to_eq h rfl]
exact Nat.cast_nonneg n
lemma nonneg_of_isNat' {n : ℕ}
[AddMonoidWithOne A] [PartialOrder A] [AddLeftMono A] [ZeroLEOneClass A]
(h : NormNum.IsNat e n) : 0 ≤ (e : A) := by
rw [NormNum.IsNat.to_eq h rfl]
exact Nat.cast_nonneg' n
lemma nz_of_isNegNat {n : ℕ} [Ring A] [PartialOrder A] [IsStrictOrderedRing A]
(h : NormNum.IsInt e (.negOfNat n)) (w : Nat.ble 1 n = true) : (e : A) ≠ 0 := by
rw [NormNum.IsInt.neg_to_eq h rfl]
simp only [ne_eq, neg_eq_zero]
apply ne_of_gt
simpa using w
lemma pos_of_isNNRat {n d : ℕ} [Semiring A] [LinearOrder A] [IsStrictOrderedRing A] :
(NormNum.IsNNRat e n d) → (decide (0 < n)) → ((0 : A) < (e : A))
| ⟨inv, eq⟩, h => by
have pos_invOf_d : (0 < ⅟ (d : A)) := pos_invOf_of_invertible_cast d
have pos_n : (0 < (n : A)) := Nat.cast_pos (n := n) |>.2 (of_decide_eq_true h)
rw [eq]
exact mul_pos pos_n pos_invOf_d
lemma pos_of_isRat {n : ℤ} {d : ℕ} [Ring A] [LinearOrder A] [IsStrictOrderedRing A] :
(NormNum.IsRat e n d) → (decide (0 < n)) → ((0 : A) < (e : A))
| ⟨inv, eq⟩, h => by
have pos_invOf_d : (0 < ⅟(d : A)) := pos_invOf_of_invertible_cast d
have pos_n : (0 < (n : A)) := Int.cast_pos (n := n) |>.2 (of_decide_eq_true h)
rw [eq]
exact mul_pos pos_n pos_invOf_d
lemma nonneg_of_isNNRat {n d : ℕ} [Semiring A] [LinearOrder A] :
(NormNum.IsNNRat e n d) → (decide (n = 0)) → (0 ≤ (e : A))
| ⟨inv, eq⟩, h => by rw [eq, of_decide_eq_true h]; simp
lemma nonneg_of_isRat {n : ℤ} {d : ℕ} [Ring A] [LinearOrder A] :
(NormNum.IsRat e n d) → (decide (n = 0)) → (0 ≤ (e : A))
| ⟨inv, eq⟩, h => by rw [eq, of_decide_eq_true h]; simp
lemma nz_of_isRat {n : ℤ} {d : ℕ} [Ring A] [LinearOrder A] [IsStrictOrderedRing A] :
(NormNum.IsRat e n d) → (decide (n < 0)) → ((e : A) ≠ 0)
| ⟨inv, eq⟩, h => by
have pos_invOf_d : (0 < ⅟(d : A)) := pos_invOf_of_invertible_cast d
have neg_n : ((n : A) < 0) := Int.cast_lt_zero (n := n) |>.2 (of_decide_eq_true h)
have neg := mul_neg_of_neg_of_pos neg_n pos_invOf_d
rw [eq]
exact ne_iff_lt_or_gt.2 (Or.inl neg)
variable {zα pα} in
/-- Converts a `MetaM Strictness` which can fail
into one that never fails and returns `.none` instead. -/
def catchNone {e : Q($α)} (t : MetaM (Strictness zα pα e)) : MetaM (Strictness zα pα e) :=
try t catch e =>
trace[Tactic.positivity.failure] "{e.toMessageData}"
pure .none
variable {zα pα} in
/-- Converts a `MetaM Strictness` which can return `.none`
into one which never returns `.none` but fails instead. -/
def throwNone {m : Type → Type*} {e : Q($α)} [Monad m] [Alternative m]
(t : m (Strictness zα pα e)) : m (Strictness zα pα e) := do
match ← t with
| .none => failure
| r => pure r
/-- Attempts to prove a `Strictness` result when `e` evaluates to a literal number. -/
def normNumPositivity (e : Q($α)) : MetaM (Strictness zα pα e) := catchNone do
match ← NormNum.derive e with
| .isBool .. => failure
| .isNat _ lit p =>
if 0 < lit.natLit! then
-- NB. The `try` branch is actually a special case of the `catch` branch,
-- hence is not strictly necessary. However, this makes a small but measurable performance
-- difference, as synthesising the `try` classes is a bit faster.
try
let _a ← synthInstanceQ q(Semiring $α)
let _a ← synthInstanceQ q(PartialOrder $α)
let _a ← synthInstanceQ q(IsOrderedRing $α)
let _a ← synthInstanceQ q(Nontrivial $α)
assumeInstancesCommute
have p : Q(NormNum.IsNat $e $lit) := p
haveI' p' : Nat.ble 1 $lit =Q true := ⟨⟩
pure (.positive q(pos_of_isNat (A := $α) $p $p'))
catch e : Exception =>
trace[Tactic.positivity.failure] "{e.toMessageData}"
let _a ← synthInstanceQ q(AddMonoidWithOne $α)
let _a ← synthInstanceQ q(PartialOrder $α)
let _a ← synthInstanceQ q(AddLeftMono $α)
let _a ← synthInstanceQ q(ZeroLEOneClass $α)
let _a ← synthInstanceQ q(NeZero (1 : $α))
assumeInstancesCommute
have p : Q(NormNum.IsNat $e $lit) := p
haveI' p' : Nat.ble 1 $lit =Q true := ⟨⟩
pure (.positive q(pos_of_isNat' (A := $α) $p $p'))
else
-- NB. The `try` branch is actually a special case of the `catch` branch,
-- hence is not strictly necessary. However, this makes a small but measurable performance
-- difference, as synthesising the `try` classes is a bit faster.
try
let _a ← synthInstanceQ q(Semiring $α)
let _a ← synthInstanceQ q(PartialOrder $α)
let _a ← synthInstanceQ q(IsOrderedRing $α)
assumeInstancesCommute
have p : Q(NormNum.IsNat $e $lit) := p
pure (.nonnegative q(nonneg_of_isNat $p))
catch e : Exception =>
trace[Tactic.positivity.failure] "{e.toMessageData}"
let _a ← synthInstanceQ q(AddMonoidWithOne $α)
let _a ← synthInstanceQ q(PartialOrder $α)
let _a ← synthInstanceQ q(AddLeftMono $α)
let _a ← synthInstanceQ q(ZeroLEOneClass $α)
assumeInstancesCommute
have p : Q(NormNum.IsNat $e $lit) := p
pure (.nonnegative q(nonneg_of_isNat' $p))
| .isNegNat _ lit p =>
let _a ← synthInstanceQ q(Ring $α)
let _a ← synthInstanceQ q(PartialOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
have p : Q(NormNum.IsInt $e (Int.negOfNat $lit)) := p
haveI' p' : Nat.ble 1 $lit =Q true := ⟨⟩
pure (.nonzero q(nz_of_isNegNat $p $p'))
| .isNNRat _i q n d p =>
let _a ← synthInstanceQ q(Semiring $α)
let _a ← synthInstanceQ q(LinearOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
have p : Q(NormNum.IsNNRat $e $n $d) := p
if 0 < q then
haveI' w : decide (0 < $n) =Q true := ⟨⟩
pure (.positive q(pos_of_isNNRat $p $w))
else -- should not be reachable, but just in case
haveI' w : decide ($n = 0) =Q true := ⟨⟩
pure (.nonnegative q(nonneg_of_isNNRat $p $w))
| .isNegNNRat _i q n d p =>
let _a ← synthInstanceQ q(Ring $α)
let _a ← synthInstanceQ q(LinearOrder $α)
let _a ← synthInstanceQ q(IsStrictOrderedRing $α)
assumeInstancesCommute
have p : Q(NormNum.IsRat $e (.negOfNat $n) $d) := p
if q < 0 then
haveI' w : decide (Int.negOfNat $n < 0) =Q true := ⟨⟩
pure (.nonzero q(nz_of_isRat $p $w))
else -- should not be reachable, but just in case
haveI' w : decide (Int.negOfNat $n = 0) =Q true := ⟨⟩
pure (.nonnegative q(nonneg_of_isRat $p $w))
/-- Attempts to prove that `e ≥ 0` using `zero_le` in a `CanonicallyOrderedAdd` monoid. -/
def positivityCanon (e : Q($α)) : MetaM (Strictness zα pα e) := do
let _add ← synthInstanceQ q(AddMonoid $α)
let _le ← synthInstanceQ q(PartialOrder $α)
let _i ← synthInstanceQ q(CanonicallyOrderedAdd $α)
assumeInstancesCommute
pure (.nonnegative q(zero_le $e))
/-- A variation on `assumption` when the hypothesis is `lo ≤ e` where `lo` is a numeral. -/
def compareHypLE (lo e : Q($α)) (p₂ : Q($lo ≤ $e)) : MetaM (Strictness zα pα e) := do
match ← normNumPositivity zα pα lo with
| .positive p₁ => pure (.positive q(lt_of_lt_of_le $p₁ $p₂))
| .nonnegative p₁ => pure (.nonnegative q(le_trans $p₁ $p₂))
| _ => pure .none
/-- A variation on `assumption` when the hypothesis is `lo < e` where `lo` is a numeral. -/
def compareHypLT (lo e : Q($α)) (p₂ : Q($lo < $e)) : MetaM (Strictness zα pα e) := do
match ← normNumPositivity zα pα lo with
| .positive p₁ => pure (.positive q(lt_trans $p₁ $p₂))
| .nonnegative p₁ => pure (.positive q(lt_of_le_of_lt $p₁ $p₂))
| _ => pure .none
/-- A variation on `assumption` when the hypothesis is `x = e` where `x` is a numeral. -/
def compareHypEq (e x : Q($α)) (p₂ : Q($x = $e)) : MetaM (Strictness zα pα e) := do
match ← normNumPositivity zα pα x with
| .positive p₁ => pure (.positive q(lt_of_lt_of_eq $p₁ $p₂))
| .nonnegative p₁ => pure (.nonnegative q(le_of_le_of_eq $p₁ $p₂))
| .nonzero p₁ => pure (.nonzero q(ne_of_ne_of_eq' $p₁ $p₂))
| .none => pure .none
initialize registerTraceClass `Tactic.positivity
initialize registerTraceClass `Tactic.positivity.failure
/-- A variation on `assumption` which checks if the hypothesis `ldecl` is `a [</≤/=] e`
where `a` is a numeral. -/
def compareHyp (e : Q($α)) (ldecl : LocalDecl) : MetaM (Strictness zα pα e) := do
have e' : Q(Prop) := ldecl.type
let p : Q($e') := .fvar ldecl.fvarId
match e' with
| ~q(@LE.le.{u} $β $_le $lo $hi) =>
let .defEq (_ : $α =Q $β) ← isDefEqQ α β | return .none
let .defEq _ ← isDefEqQ e hi | return .none
match lo with
| ~q(0) =>
assertInstancesCommute
return .nonnegative q($p)
| _ => compareHypLE zα pα lo e p
| ~q(@LT.lt.{u} $β $_lt $lo $hi) =>
let .defEq (_ : $α =Q $β) ← isDefEqQ α β | return .none
let .defEq _ ← isDefEqQ e hi | return .none
match lo with
| ~q(0) =>
assertInstancesCommute
return .positive q($p)
| _ => compareHypLT zα pα lo e p
| ~q(@Eq.{u+1} $α' $lhs $rhs) =>
let .defEq (_ : $α =Q $α') ← isDefEqQ α α' | pure .none
match ← isDefEqQ e rhs with
| .defEq _ =>
match lhs with
| ~q(0) => pure <| .nonnegative q(le_of_eq $p)
| _ => compareHypEq zα pα e lhs q($p)
| .notDefEq =>
let .defEq _ ← isDefEqQ e lhs | pure .none
match rhs with
| ~q(0) => pure <| .nonnegative q(ge_of_eq $p)
| _ => compareHypEq zα pα e rhs q(Eq.symm $p)
| ~q(@Ne.{u + 1} $α' $lhs $rhs) =>
let .defEq (_ : $α =Q $α') ← isDefEqQ α α' | pure .none
match lhs, rhs with
| ~q(0), _ =>
let .defEq _ ← isDefEqQ e rhs | pure .none
pure <| .nonzero q(Ne.symm $p)
| _, ~q(0) =>
let .defEq _ ← isDefEqQ e lhs | pure .none
pure <| .nonzero q($p)
| _, _ => pure .none
| _ => pure .none
variable {zα pα} in
/-- The main combinator which combines multiple `positivity` results.
It assumes `t₁` has already been run for a result, and runs `t₂` and takes the best result.
It will skip `t₂` if `t₁` is already a proof of `.positive`, and can also combine
`.nonnegative` and `.nonzero` to produce a `.positive` result. -/
def orElse {e : Q($α)} (t₁ : Strictness zα pα e) (t₂ : MetaM (Strictness zα pα e)) :
MetaM (Strictness zα pα e) := do
match t₁ with
| .none => catchNone t₂
| p@(.positive _) => pure p
| .nonnegative p₁ =>
match ← catchNone t₂ with
| p@(.positive _) => pure p
| .nonzero p₂ => pure (.positive q(lt_of_le_of_ne' $p₁ $p₂))
| _ => pure (.nonnegative p₁)
| .nonzero p₁ =>
match ← catchNone t₂ with
| p@(.positive _) => pure p
| .nonnegative p₂ => pure (.positive q(lt_of_le_of_ne' $p₂ $p₁))
| _ => pure (.nonzero p₁)
/-- Run each registered `positivity` extension on an expression, returning a `NormNum.Result`. -/
def core (e : Q($α)) : MetaM (Strictness zα pα e) := do
let mut result := .none
trace[Tactic.positivity] "trying to prove positivity of {e}"
for ext in ← (positivityExt.getState (← getEnv)).2.getMatch e do
try
result ← orElse result <| ext.eval zα pα e
catch err =>
trace[Tactic.positivity] "{e} failed: {err.toMessageData}"
result ← orElse result <| normNumPositivity zα pα e
result ← orElse result <| positivityCanon zα pα e
if let .positive _ := result then
trace[Tactic.positivity] "{e} => {result.toString}"
return result
for ldecl in ← getLCtx do
if !ldecl.isImplementationDetail then
result ← orElse result <| compareHyp zα pα e ldecl
trace[Tactic.positivity] "{e} => {result.toString}"
throwNone (pure result)
private inductive OrderRel : Type
| le : OrderRel -- `0 ≤ a`
| lt : OrderRel -- `0 < a`
| ne : OrderRel -- `a ≠ 0`
| ne' : OrderRel -- `0 ≠ a`
end Meta.Positivity
namespace Meta.Positivity
/-- Given an expression `e`, use the core method of the `positivity` tactic to prove it positive,
or, failing that, nonnegative; return a boolean (signalling whether the strict or non-strict
inequality was established) together with the proof as an expression. -/
def bestResult (e : Expr) : MetaM (Bool × Expr) := do
let ⟨u, α, _⟩ ← inferTypeQ' e
let zα ← synthInstanceQ q(Zero $α)
let pα ← synthInstanceQ q(PartialOrder $α)
match ← try? (Meta.Positivity.core zα pα e) with
| some (.positive pf) => pure (true, pf)
| some (.nonnegative pf) => pure (false, pf)
| _ => throwError "could not establish the nonnegativity of {e}"
/-- Given an expression `e`, use the core method of the `positivity` tactic to prove it nonnegative.
-/
def proveNonneg (e : Expr) : MetaM Expr := do
let (strict, pf) ← bestResult e
if strict then mkAppM ``le_of_lt #[pf] else pure pf
/-- An auxiliary entry point to the `positivity` tactic. Given a proposition `t` of the form
`0 [≤/</≠] e`, attempts to recurse on the structure of `t` to prove it. It returns a proof
or fails. -/
def solve (t : Q(Prop)) : MetaM Expr := do
let rest {u : Level} (α : Q(Type u)) z e (relDesired : OrderRel) : MetaM Expr := do
let zα ← synthInstanceQ q(Zero $α)
assumeInstancesCommute
let .true ← isDefEq z q(0 : $α) | throwError "not a positivity goal"
let pα ← synthInstanceQ q(PartialOrder $α)
assumeInstancesCommute
let r ← catchNone <| Meta.Positivity.core zα pα e
let throw (a b : String) : MetaM Expr := throwError
"failed to prove {a}, but it would be possible to prove {b} if desired"
let p ← show MetaM Expr from match relDesired, r with
| .lt, .positive p
| .le, .nonnegative p
| .ne, .nonzero p => pure p
| .le, .positive p => pure q(le_of_lt $p)
| .ne, .positive p => pure q(ne_of_gt $p)
| .ne', .positive p => pure q(ne_of_lt $p)
| .ne', .nonzero p => pure q(Ne.symm $p)
| .lt, .nonnegative _ => throw "strict positivity" "nonnegativity"
| .lt, .nonzero _ => throw "strict positivity" "nonzeroness"
| .le, .nonzero _ => throw "nonnegativity" "nonzeroness"
| .ne, .nonnegative _
| .ne', .nonnegative _ => throw "nonzeroness" "nonnegativity"
| _, .none => throwError "failed to prove positivity/nonnegativity/nonzeroness"
pure p
match t with
| ~q(@LE.le $α $_a $z $e) => rest α z e .le
| ~q(@LT.lt $α $_a $z $e) => rest α z e .lt
| ~q($a ≠ ($b : ($α : Type _))) =>
let _zα ← synthInstanceQ q(Zero $α)
if ← isDefEq b q((0 : $α)) then
rest α b a .ne
else
let .true ← isDefEq a q((0 : $α)) | throwError "not a positivity goal"
rest α a b .ne'
| _ => throwError "not a positivity goal"
/-- The main entry point to the `positivity` tactic. Given a goal `goal` of the form `0 [≤/</≠] e`,
attempts to recurse on the structure of `e` to prove the goal.
It will either close `goal` or fail. -/
def positivity (goal : MVarId) : MetaM Unit := do
let t : Q(Prop) ← withReducible goal.getType'
let p ← solve t
goal.assign p
end Meta.Positivity
namespace Tactic.Positivity
open Tactic
/-- Tactic solving goals of the form `0 ≤ x`, `0 < x` and `x ≠ 0`. The tactic works recursively
according to the syntax of the expression `x`, if the atoms composing the expression all have
numeric lower bounds which can be proved positive/nonnegative/nonzero by `norm_num`. This tactic
either closes the goal or fails.
Examples:
```
example {a : ℤ} (ha : 3 < a) : 0 ≤ a ^ 3 + a := by positivity
example {a : ℤ} (ha : 1 < a) : 0 < |(3:ℤ) + a| := by positivity
example {b : ℤ} : 0 ≤ max (-3) (b ^ 2) := by positivity
```
-/
elab (name := positivity) "positivity" : tactic => do
liftMetaTactic fun g => do Meta.Positivity.positivity g; pure []
end Positivity
end Mathlib.Tactic
/-!
We set up `positivity` as a first-pass discharger for `gcongr` side goals.
-/
macro_rules | `(tactic| gcongr_discharger) => `(tactic| positivity)
/-!
We register `positivity` with the `hint` tactic.
-/
register_hint positivity
|
inequalities.lean
|
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.SuccessIfFailWithMsg
import Mathlib.Tactic.NormNum.OfScientific
namespace GCongrTests
private axiom test_sorry : ∀ {α}, α
/-! # Inequality tests for the `gcongr` tactic -/
open Nat Finset
-- We deliberately mock `ℝ` here so that we don't have to import the dependencies
axiom Real : Type
notation "ℝ" => Real
@[instance] axiom Real.field : Field ℝ
@[instance] axiom Real.linearOrder : LinearOrder ℝ
@[instance] axiom Real.isStrictOrderedRing : IsStrictOrderedRing ℝ
/-! ## Examples as a finishing tactic -/
example {x : ℤ} (hx : x ≥ 12) : x * x ^ 2 ≥ 12 * x ^ 2 := by gcongr
example {x y : ℤ} (hx : x ≥ 12) : y + x * x ≥ y + 12 * x := by gcongr
example {x y : ℤ} (hx : x ≥ 12) : y + x * x ≥ y + 12 * x := by rel [hx]
example {x : ℤ} (hx : x > 12) : x * x ^ 2 > 12 * x ^ 2 := by gcongr
example {x y : ℤ} (hx : x > 12) : y + x * x > y + 12 * x := by gcongr
-- not solved by `nlinarith` because of the cube
example {n m : ℤ} (hn : n ≥ 10) : n * n ^ 3 - m ≥ 10 * n ^ 3 - m := by gcongr
example {k m n : ℤ} (hn : n ≥ 10) : m + 7 * n * n ^ 2 - k ≥ m + 7 * 10 * n ^ 2 - k := by gcongr
example {k m n : ℤ} (hn : n ≥ 10) : m + 7 * n * n ^ 2 - k ≥ m + 7 * 10 * n ^ 2 - k := by rel [hn]
example {x : ℤ} (hx : x ≥ 12) : x ≥ 12 := by gcongr
example {x y : ℤ} (hx : x ≥ 12) : y + 8 * x ≥ y + 8 * 12 := by gcongr
example {a b x c d : ℝ} (h1 : a ≤ b) (h2 : c ≤ d) : x ^ 2 * a + c ≤ x ^ 2 * b + d := by
rel [h1, h2]
-- not solved by `nlinarith` because of the cube and the absolute value
example {a b c x y : ℤ} (hb : b ≥ 4) (hxy : x ≤ y) :
c + (3 * |a| ^ 3 * b + b * 7 + 14) * x ≤ c + (3 * |a| ^ 3 * b + b * 7 + 14) * y := by
gcongr
example {x y : ℤ} (hy : 3 ≤ y) (hx : x ≥ 9) : y + 2 * x ≥ 3 + 2 * 9 := by gcongr
example {b : ℤ} (h2 : b ≥ 3) : 2 * b + 5 ≥ 2 * 3 + 5 := by gcongr
example {x : ℝ} (h1 : x ≤ 3) : 4 * x - 3 ≤ 4 * 3 - 3 := by gcongr
example {x : ℝ} (h : x < 1) : 3 * x ≤ 3 * 1 := by gcongr
example {x : ℝ} (h1 : x < 3) : 4 * x - 3 < 4 * 3 - 3 := by gcongr
example {x : ℝ} (h : x < 1) : 3 * x < 3 * 1 := by gcongr
example {x y : ℝ} (h1 : 1 ≤ y) (h2 : x < 2) : x * y ≤ 2 * y := by gcongr
-- for this test to pass, need the check to ensure that leading function application is
-- syntactically (not just definitionally) the same on both sides.
example {a b c : ℚ} (h2 : 2 ≤ a + b) : 2 + c ≤ (a + b) + c := by gcongr
-- for this test to pass, need to ensure it's treated as a division, not a multiplication
example {a b : ℚ} (h1 : 3 ≤ a) (h2 : 4 ≤ b) : (3 + 4) / 2 ≤ (a + b) / 2 := by gcongr
-- for this test to pass, need to ensure it's treated as a division, not a multiplication
example {a : ℚ} (h1 : 3 ≤ a) : 3 / 2 ≤ a / 2 := by gcongr
example {a : ℝ} (h1 : 3 ≤ a) : 3 / 2 ≤ a / 2 := by gcongr
example {x y : ℝ} (h : 3 ≤ x) (h' : 1 ≤ y) : (3 + 1) / 2 ≤ (x + y) / 2 := by gcongr
example {x : ℝ} (h : x ≤ 3) : 0.1 * x ≤ 0.1 * 3 := by gcongr
example {x : ℝ} (h : x ≤ 3) : x / 10 ≤ 3 / 10 := by gcongr
example {x : ℝ} (h : x ≤ 3) : 1 / 10 * x ≤ 1 / 10 * 3 := by gcongr
example (a b c d : ℕ) (h1 : a ≤ b) (h2 : c ≤ d) : a * c ≤ b * d := by gcongr
-- this tests that the tactic prioritizes applying hypotheses (such as, here, `0 ≤ a ^ 6`) over the
-- greedy application of nonnegativity lemmas
example {a b : ℚ} (h : 0 ≤ a ^ 6) : 0 + b ≤ a ^ 6 + b := by gcongr
example {a b : ℚ} (h₁ : a ≤ b) (c : ℝ) : (a + c : ℝ) ≤ b + c := by gcongr
example {a b : ℚ} (h₁ : a < b) (c : ℝ) : (a + c : ℝ) < b + c := by gcongr
-- another priority test
example {k m n : ℤ} (H : m ^ 2 ≤ n ^ 2) : k + m ^ 2 ≤ k + n ^ 2 := by gcongr
-- test of behaviour when no lemmas are applicable
example (n k : ℕ) (H : n % k + 1 ≤ k % n + 1) : n % k ≤ k % n := by
success_if_fail_with_msg
"gcongr did not make progress"
(gcongr)
linarith
set_option linter.unusedVariables false in
example {x : ℤ} (hx : x ≥ 12) (h : Even x) : Even x := by
success_if_fail_with_msg "rel failed, goal not a relation" (rel [hx])
exact h
example {a b x c d : ℝ} (h1 : a ≤ b) (h2 : c ≤ d) (h3 : 1 ≤ x + 1) : x * a + c ≤ x * b + d := by
success_if_fail_with_msg
"rel failed, cannot prove goal by 'substituting' the listed relationships. \
The steps which could not be automatically justified were:\n0 ≤ x\nc ≤ d"
(rel [h1])
have : 0 ≤ x := by linarith
rel [h1, h2]
-- test for a missing `withContext`
example {x y : ℚ} {n : ℕ} (hx : 0 ≤ x) (hn : 0 < n) : y ≤ x := by
have h : x < y := test_sorry
have _this : x ^ n < y ^ n := by
rel [h] -- before bugfix: complained "unknown identifier 'h'"
exact test_sorry
/-! ## Non-finishing examples -/
example {a b x c d : ℝ} (h1 : a + 1 ≤ b + 1) (h2 : c + 2 ≤ d + 2) :
x ^ 2 * a + c ≤ x ^ 2 * b + d := by
gcongr <;> linarith
example {a b c d x : ℝ} (h : a + c + 1 ≤ b + d + 1) :
x ^ 2 * (a + c) + 5 ≤ x ^ 2 * (b + d) + 5 := by
gcongr x ^ 2 * ?_ + 5
linarith
example {x y z : ℝ} (h : 2 ≤ z) : z * |x + y| ≤ z * (|x| + |y|) := by gcongr; apply abs_add
example (A B C : ℝ) : |A + B| + C ≤ |A| + |B| + C := by gcongr; apply abs_add
example (A B C : ℝ) : |A + B| + C ≤ |A| + |B| + C := by gcongr ?_ + _; apply abs_add
example (A B C : ℝ) : |A + B| + C ≤ |A| + |B| + C := by gcongr ?_ + (A : ℝ); apply abs_add
example {n i : ℕ} (hi : i ∈ range n) : 2 ^ i ≤ 2 ^ n := by
gcongr
· norm_num
· apply le_of_lt
simpa using hi
example {n' : ℕ} (hn' : 6 ≤ n') : 2 ^ ((n' + 1) * (n' + 1)) ≤ 2 ^ (n' * n' + 4 * n') := by
gcongr
· norm_num
· linarith
example {F : ℕ → ℕ} (le_sum : ∀ {N : ℕ}, 6 ≤ N → 15 ≤ F N) {n' : ℕ} (hn' : 6 ≤ n') :
let A := F n';
A ! * (15 + 1) ^ n' ≤ A ! * (A + 1) ^ n' := by
intro A
gcongr
exact le_sum hn'
example {a : ℤ} {n : ℕ} (ha : ∀ i < n, 2 ^ i ≤ a) :
∏ i ∈ range n, (a - 2 ^ i) ≤ ∏ _i ∈ range n, a := by
gcongr with i
· intro i hi
simp only [mem_range] at hi
linarith [ha i hi]
· have : 0 ≤ 2 ^ i := by positivity
linarith
-- this tests that the match goes only as deep as is indicated by the template
example {a b c d e : ℝ} (_h1 : 0 ≤ b) (_h2 : 0 ≤ c) (hac : a * b + 1 ≤ c * d + 1) (_hbd : b ≤ d) :
a * b + e ≤ c * d + e := by
gcongr ?_ + _
guard_target =ₛ a * b ≤ c * d
linarith
-- test big operators
example (f g : ℕ → ℕ) (s : Finset ℕ) (h : ∀ i ∈ s, f i ≤ g i) :
∑ i ∈ s, (3 + f i ^ 2) ≤ ∑ i ∈ s, (3 + g i ^ 2) := by
gcongr with i hi
exact h i hi
-- this tests templates with binders
example (f g : ℕ → ℕ) (s : Finset ℕ) (h : ∀ i ∈ s, f i ^ 2 + 1 ≤ g i ^ 2 + 1) :
∑ i ∈ s, f i ^ 2 ≤ ∑ i ∈ s, g i ^ 2 := by
gcongr ∑ _i ∈ s, ?_ with i hi
linarith [h i hi]
-- this tests templates with binders
example (f g : ℕ → ℕ) (s : Finset ℕ) (h : ∀ i ∈ s, f i ^ 2 + 1 ≤ g i ^ 2 + 1) :
∑ i ∈ s, (3 + f i ^ 2) ≤ ∑ i ∈ s, (3 + g i ^ 2) := by
gcongr ∑ _i ∈ s, (3 + ?_) with i hi
linarith [h i hi]
example (f g : ℕ → ℕ) (s : Finset ℕ) (h : ∀ i ∈ s, f i ^ 2 + 1 ≤ g i ^ 2 + 1) :
∑ i ∈ s, (f i ^ 2 / 5) ≤ ∑ i ∈ s, (g i ^ 2 / 5) := by
gcongr 2 with i hi
linarith [h i hi]
axiom f : ℕ → ℕ
example {x y : ℕ} (h : f x ≤ f y) : f x ≤ f y := by
success_if_fail_with_msg
"Tactic `gcongr` failed: there is no `@[gcongr]` lemma for relation 'LE.le' and constant 'GCongrTests.f'.
x y : ℕ
h : GCongrTests.f x ≤ GCongrTests.f y
⊢ GCongrTests.f x ≤ GCongrTests.f y"
(gcongr f ?a)
exact h
example {x y : ℕ} (h : f x ≤ f y) : f x ^ 2 ≤ f y ^ 2 := by
success_if_fail_with_msg
"Tactic `gcongr` failed: there is no `@[gcongr]` lemma for relation 'LE.le' and constant 'GCongrTests.f'.
case hab
x y : ℕ
h : GCongrTests.f x ≤ GCongrTests.f y
⊢ GCongrTests.f x ≤ GCongrTests.f y"
(gcongr (f ?a) ^ 2)
gcongr
example (s : Finset ℕ) (h : ∀ i ∈ s, f i ≤ f (2 * i)) : ∑ i ∈ s, f i ≤ ∑ i ∈ s, f (2 * i) := by
gcongr
apply h
assumption
def dontUnfoldMe : Nat → List Bool → Nat
| 0, _ => 0
| n + 1, l => dontUnfoldMe n (true::l) + dontUnfoldMe n (false::l)
-- times out if a certain reducibility setting in `gcongr`'s implementation is not correct
example {x y : ℕ} (h : x ≤ y) (l) : dontUnfoldMe 14 l + x ≤ 0 + y := by
gcongr
guard_target = dontUnfoldMe 14 l ≤ 0
apply test_sorry
/-! Test that `gcongr` works well with proof arguments -/
example {α β : Type*} [SemilatticeSup α] (f : β → α)
{s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) :
s₁.sup' h₁ f ≤ s₂.sup' (h₁.mono h) f := by
gcongr
example {α β : Type*} [SemilatticeSup α] (f : β → α)
{s₁ s₂ : Finset β} (h : s₁ ⊆ s₂) (h₁ : s₁.Nonempty) (h₂ : s₂.Nonempty) :
s₁.sup' h₁ f ≤ s₂.sup' h₂ f := by
gcongr
/-! Test that `gcongr` can solve side goals of the form `∀ i, f i` when `f i` is in scope for
`positivity` -/
example {ι : Type*} [Fintype ι] {f g : ι → ℝ} : ∏ i, f i ^ 2 ≤ ∏ i, g i ^ 2 := by
gcongr with i _ i _
· guard_target = 0 ≤ f i
exact test_sorry
· guard_target = f i ≤ g i
exact test_sorry
/-! Test that `gcongr` can deal with `_ ≤ _ → _ ≤ _` and `_ < _ → _ < _` -/
example {a b : ℕ} (h1 : a ≤ 0) (h2 : 0 ≤ b) : b ≤ a + 1 → 0 ≤ 0 + 1 := by gcongr
example {a b : ℕ} (h1 : a ≤ 0) (_h2 : 0 ≤ b) : b ≤ a + 1 → b ≤ 0 + 1 := by gcongr
example {a b : ℕ} (_h1 : a ≤ 0) (h2 : 0 ≤ b) : b ≤ a + 1 → 0 ≤ a + 1 := by gcongr
example {a b : ℕ} (h1 : a ≤ 0) (h2 : 0 ≤ b) : b < a + 1 → 0 < 0 + 1 := by gcongr
example {a b : ℕ} (h1 : a ≤ 0) (_h2 : 0 ≤ b) : b < a + 1 → b < 0 + 1 := by gcongr
example {a b : ℕ} (_h1 : a ≤ 0) (h2 : 0 ≤ b) : b < a + 1 → 0 < a + 1 := by gcongr
/-! Test that `gcongr` with a pattern doesn't complain about type class inference problems. -/
example {a b : ℕ} (h1 : a ≤ 0) (h2 : 0 ≤ b) : b ≤ a + 1 → 0 ≤ 0 + 1 := by gcongr ?_ ≤ ?_ + _
end GCongrTests
|
Norm.lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Normed.Group.Basic
import Mathlib.Data.Complex.Basic
import Mathlib.Data.Real.Sqrt
/-!
# Norm on the complex numbers
-/
noncomputable section
open ComplexConjugate Topology Filter Set
namespace Complex
variable {z : ℂ}
instance instNorm : Norm ℂ where
norm z := √(normSq z)
theorem norm_def (z : ℂ) : ‖z‖ = √(normSq z) := rfl
theorem norm_mul_self_eq_normSq (z : ℂ) : ‖z‖ * ‖z‖ = normSq z :=
Real.mul_self_sqrt (normSq_nonneg _)
@[deprecated (since := "2025-02-16")] alias mul_self_abs := norm_mul_self_eq_normSq
private theorem norm_nonneg (z : ℂ) : 0 ≤ ‖z‖ :=
Real.sqrt_nonneg _
@[bound]
theorem abs_re_le_norm (z : ℂ) : |z.re| ≤ ‖z‖ := by
rw [mul_self_le_mul_self_iff (abs_nonneg z.re) (norm_nonneg _), abs_mul_abs_self,
norm_mul_self_eq_normSq]
apply re_sq_le_normSq
theorem re_le_norm (z : ℂ) : z.re ≤ ‖z‖ :=
(abs_le.1 (abs_re_le_norm _)).2
@[deprecated (since := "2025-02-16")] alias abs_re_le_abs := abs_re_le_norm
@[deprecated (since := "2025-02-16")] alias re_le_abs := re_le_norm
private theorem norm_add_le' (z w : ℂ) : ‖z + w‖ ≤ ‖z‖ + ‖w‖ :=
(mul_self_le_mul_self_iff (norm_nonneg (z + w)) (add_nonneg (norm_nonneg z)
(norm_nonneg w))).2 <| by
rw [norm_mul_self_eq_normSq, add_mul_self_eq, norm_mul_self_eq_normSq, norm_mul_self_eq_normSq,
add_right_comm, normSq_add, add_le_add_iff_left, mul_assoc, mul_le_mul_left (zero_lt_two' ℝ),
norm_def, norm_def, ← Real.sqrt_mul <| normSq_nonneg z, ← normSq_conj w, ← map_mul]
exact re_le_norm (z * conj w)
private theorem norm_eq_zero_iff {z : ℂ} : ‖z‖ = 0 ↔ z = 0 :=
(Real.sqrt_eq_zero <| normSq_nonneg _).trans normSq_eq_zero
private theorem norm_map_zero' : ‖(0 : ℂ)‖ = 0 :=
norm_eq_zero_iff.mpr rfl
private theorem norm_neg' (z : ℂ) : ‖-z‖ = ‖z‖ := by
rw [Complex.norm_def, norm_def, normSq_neg]
instance instNormedAddCommGroup : NormedAddCommGroup ℂ :=
AddGroupNorm.toNormedAddCommGroup
{ toFun := norm
map_zero' := norm_map_zero'
add_le' := norm_add_le'
neg' := norm_neg'
eq_zero_of_map_eq_zero' := fun _ ↦ norm_eq_zero_iff.mp }
/-- The complex absolute value function, defined as the Complex norm. -/
@[deprecated "use the norm instead" (since := "2025-02-16")]
protected noncomputable abbrev abs (z : ℂ) : ℝ := ‖z‖
@[deprecated (since := "2025-02-16")] alias abs_apply := norm_def
@[simp 1100]
protected theorem norm_mul (z w : ℂ) : ‖z * w‖ = ‖z‖ * ‖w‖ := by
rw [norm_def, norm_def, norm_def, normSq_mul, Real.sqrt_mul (normSq_nonneg _)]
@[simp 1100]
protected theorem norm_div (z w : ℂ) : ‖z / w‖ = ‖z‖ / ‖w‖ := by
rw [norm_def, norm_def, norm_def, normSq_div, Real.sqrt_div (normSq_nonneg _)]
instance isAbsoluteValueNorm : IsAbsoluteValue (‖·‖ : ℂ → ℝ) where
abv_nonneg' := norm_nonneg
abv_eq_zero' := norm_eq_zero_iff
abv_add' := norm_add_le
abv_mul' := Complex.norm_mul
protected theorem norm_pow (z : ℂ) (n : ℕ) : ‖z ^ n‖ = ‖z‖ ^ n :=
map_pow isAbsoluteValueNorm.abvHom _ _
protected theorem norm_zpow (z : ℂ) (n : ℤ) : ‖z ^ n‖ = ‖z‖ ^ n :=
map_zpow₀ isAbsoluteValueNorm.abvHom _ _
protected theorem norm_prod {ι : Type*} (s : Finset ι) (f : ι → ℂ) :
‖s.prod f‖ = s.prod fun i ↦ ‖f i‖ :=
map_prod isAbsoluteValueNorm.abvHom _ _
theorem norm_conj (z : ℂ) : ‖conj z‖ = ‖z‖ := by simp [norm_def]
@[deprecated (since := "2025-02-16")] protected alias abs_pow := Complex.norm_pow
@[deprecated (since := "2025-02-16")] alias abs_zpow := Complex.norm_zpow
@[deprecated (since := "2025-02-16")] alias abs_prod := Complex.norm_prod
@[deprecated (since := "2025-02-16")] alias abs_conj := norm_conj
@[deprecated (since := "2025-02-16")] protected alias abs_abs := abs_norm
@[simp] lemma norm_I : ‖I‖ = 1 := by simp [norm]
@[deprecated (since := "2025-02-16")] alias abs_I := norm_I
@[simp] lemma nnnorm_I : ‖I‖₊ = 1 := by simp [nnnorm]
@[simp 1100, norm_cast]
lemma norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := by
simp [norm_def, Real.sqrt_mul_self_eq_abs]
protected theorem norm_of_nonneg {r : ℝ} (h : 0 ≤ r) : ‖(r : ℂ)‖ = r :=
(norm_real _).trans (abs_of_nonneg h)
@[deprecated (since := "2025-02-16")] alias abs_ofReal := norm_real
@[deprecated (since := "2025-02-16")] protected alias abs_of_nonneg := Complex.norm_of_nonneg
@[simp, norm_cast]
lemma nnnorm_real (r : ℝ) : ‖(r : ℂ)‖₊ = ‖r‖₊ := by ext; exact norm_real _
@[simp 1100, norm_cast]
lemma norm_natCast (n : ℕ) : ‖(n : ℂ)‖ = n := Complex.norm_of_nonneg n.cast_nonneg
@[simp 1100]
lemma norm_ofNat (n : ℕ) [n.AtLeastTwo] :
‖(ofNat(n) : ℂ)‖ = OfNat.ofNat n := norm_natCast n
protected lemma norm_two : ‖(2 : ℂ)‖ = 2 := norm_ofNat 2
@[simp 1100, norm_cast]
lemma nnnorm_natCast (n : ℕ) : ‖(n : ℂ)‖₊ = n := Subtype.ext <| by simp
@[simp 1100]
lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] :
‖(ofNat(n) : ℂ)‖₊ = OfNat.ofNat n := nnnorm_natCast n
@[deprecated (since := "2025-02-16")] alias abs_natCast := norm_natCast
@[deprecated (since := "2025-02-16")] alias abs_ofNat := norm_ofNat
@[deprecated (since := "2025-02-16")] protected alias abs_two := Complex.norm_two
@[simp 1100, norm_cast]
lemma norm_intCast (n : ℤ) : ‖(n : ℂ)‖ = |(n : ℝ)| := by
rw [← ofReal_intCast, norm_real, Real.norm_eq_abs]
theorem norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by
rw [norm_intCast, ← Int.cast_abs, abs_of_nonneg hn]
@[simp 1100, norm_cast]
lemma norm_ratCast (q : ℚ) : ‖(q : ℂ)‖ = |(q : ℝ)| := norm_real _
@[simp 1100, norm_cast]
lemma norm_nnratCast (q : ℚ≥0) : ‖(q : ℂ)‖ = q := Complex.norm_of_nonneg q.cast_nonneg
@[simp 1100, norm_cast]
lemma nnnorm_ratCast (q : ℚ) : ‖(q : ℂ)‖₊ = ‖(q : ℝ)‖₊ := nnnorm_real q
@[simp 1100, norm_cast]
lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : ℂ)‖₊ = q := by simp [nnnorm]
@[deprecated (since := "2025-02-16")] alias abs_intCast := norm_intCast
lemma normSq_eq_norm_sq (z : ℂ) : normSq z = ‖z‖ ^ 2 := by
simp [norm_def, sq, Real.mul_self_sqrt (normSq_nonneg _)]
protected theorem sq_norm (z : ℂ) : ‖z‖ ^ 2 = normSq z := (normSq_eq_norm_sq z).symm
@[simp]
theorem sq_norm_sub_sq_re (z : ℂ) : ‖z‖ ^ 2 - z.re ^ 2 = z.im ^ 2 := by
rw [Complex.sq_norm, normSq_apply, ← sq, ← sq, add_sub_cancel_left]
@[simp]
theorem sq_norm_sub_sq_im (z : ℂ) : ‖z‖ ^ 2 - z.im ^ 2 = z.re ^ 2 := by
rw [← sq_norm_sub_sq_re, sub_sub_cancel]
lemma norm_add_mul_I (x y : ℝ) : ‖x + y * I‖ = √(x ^ 2 + y ^ 2) := by
rw [← normSq_add_mul_I]; rfl
lemma norm_eq_sqrt_sq_add_sq (z : ℂ) : ‖z‖ = √(z.re ^ 2 + z.im ^ 2) := by
rw [norm_def, normSq_apply, sq, sq]
@[deprecated (since := "2025-02-16")] alias normSq_eq_abs := normSq_eq_norm_sq
@[deprecated (since := "2025-02-16")] protected alias sq_abs := Complex.sq_norm
@[deprecated (since := "2025-02-16")] alias sq_abs_sub_sq_re := sq_norm_sub_sq_re
@[deprecated (since := "2025-02-16")] alias sq_abs_sub_sq_im := sq_norm_sub_sq_im
@[deprecated (since := "2025-02-16")] alias abs_add_mul_I := norm_add_mul_I
@[deprecated (since := "2025-02-16")] alias abs_eq_sqrt_sq_add_sq := norm_eq_sqrt_sq_add_sq
@[simp 1100]
protected theorem range_norm : range (‖·‖ : ℂ → ℝ) = Set.Ici 0 :=
Subset.antisymm (range_subset_iff.2 norm_nonneg) fun x hx ↦ ⟨x, Complex.norm_of_nonneg hx⟩
@[deprecated (since := "2025-02-16")] alias range_abs := Complex.range_norm
@[simp]
theorem range_normSq : range normSq = Ici 0 :=
Subset.antisymm (range_subset_iff.2 normSq_nonneg) fun x hx =>
⟨√x, by rw [normSq_ofReal, Real.mul_self_sqrt hx]⟩
theorem norm_le_abs_re_add_abs_im (z : ℂ) : ‖z‖ ≤ |z.re| + |z.im| := by
simpa [re_add_im] using norm_add_le (z.re : ℂ) (z.im * I)
@[bound]
theorem abs_im_le_norm (z : ℂ) : |z.im| ≤ ‖z‖ :=
Real.abs_le_sqrt <| by
rw [normSq_apply, ← sq, ← sq]
exact le_add_of_nonneg_left (sq_nonneg _)
theorem im_le_norm (z : ℂ) : z.im ≤ ‖z‖ :=
(abs_le.1 (abs_im_le_norm _)).2
@[simp]
theorem abs_re_lt_norm {z : ℂ} : |z.re| < ‖z‖ ↔ z.im ≠ 0 := by
rw [norm_def, Real.lt_sqrt (abs_nonneg _), normSq_apply, sq_abs, ← sq, lt_add_iff_pos_right,
mul_self_pos]
@[simp]
theorem abs_im_lt_norm {z : ℂ} : |z.im| < ‖z‖ ↔ z.re ≠ 0 := by
simpa using @abs_re_lt_norm (z * I)
@[simp]
lemma abs_re_eq_norm {z : ℂ} : |z.re| = ‖z‖ ↔ z.im = 0 :=
not_iff_not.1 <| (abs_re_le_norm z).lt_iff_ne.symm.trans abs_re_lt_norm
@[simp]
lemma abs_im_eq_norm {z : ℂ} : |z.im| = ‖z‖ ↔ z.re = 0 :=
not_iff_not.1 <| (abs_im_le_norm z).lt_iff_ne.symm.trans abs_im_lt_norm
@[deprecated (since := "2025-02-16")] alias abs_le_abs_re_add_abs_im := norm_le_abs_re_add_abs_im
@[deprecated (since := "2025-02-16")] alias abs_im_le_abs := abs_im_le_norm
@[deprecated (since := "2025-02-16")] alias im_le_abs := im_le_norm
@[deprecated (since := "2025-02-16")] alias abs_re_lt_abs := abs_re_lt_norm
@[deprecated (since := "2025-02-16")] alias abs_im_lt_abs := abs_im_lt_norm
@[deprecated (since := "2025-02-16")] alias abs_re_eq_abs := abs_re_eq_norm
@[deprecated (since := "2025-02-16")] alias abs_im_eq_abs := abs_im_eq_norm
theorem norm_le_sqrt_two_mul_max (z : ℂ) : ‖z‖ ≤ √2 * max |z.re| |z.im| := by
obtain ⟨x, y⟩ := z
simp only [norm_def, normSq_mk, norm_def, ← sq]
set m := max |x| |y|
have hm₀ : 0 ≤ m := by positivity
calc
√(x ^ 2 + y ^ 2) ≤ √(m ^ 2 + m ^ 2) := by
gcongr √(?_ + ?_) <;> rw [sq_le_sq, abs_of_nonneg hm₀]
exacts [le_max_left _ _, le_max_right _ _]
_ = √2 * m := by
rw [← two_mul, Real.sqrt_mul, Real.sqrt_sq] <;> positivity
theorem abs_re_div_norm_le_one (z : ℂ) : |z.re / ‖z‖| ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by
simp_rw [abs_div, abs_norm, div_le_iff₀ (norm_pos_iff.mpr hz), one_mul, abs_re_le_norm]
theorem abs_im_div_norm_le_one (z : ℂ) : |z.im / ‖z‖| ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one]
else by
simp_rw [_root_.abs_div, abs_norm, div_le_iff₀ (norm_pos_iff.mpr hz), one_mul, abs_im_le_norm]
@[deprecated (since := "2025-02-16")] alias abs_le_sqrt_two_mul_max := norm_le_sqrt_two_mul_max
@[deprecated (since := "2025-02-16")] alias abs_re_div_abs_le_one := abs_re_div_norm_le_one
@[deprecated (since := "2025-02-16")] alias abs_im_div_abs_le_one := abs_im_div_norm_le_one
theorem dist_eq (z w : ℂ) : dist z w = ‖z - w‖ := rfl
theorem dist_eq_re_im (z w : ℂ) : dist z w = √((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by
rw [sq, sq]
rfl
@[simp]
theorem dist_mk (x₁ y₁ x₂ y₂ : ℝ) :
dist (mk x₁ y₁) (mk x₂ y₂) = √((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) :=
dist_eq_re_im _ _
theorem dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by
rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, zero_add, Real.sqrt_sq_eq_abs, Real.dist_eq]
theorem nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im :=
NNReal.eq <| dist_of_re_eq h
theorem edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by
rw [edist_nndist, edist_nndist, nndist_of_re_eq h]
theorem dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by
rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, add_zero, Real.sqrt_sq_eq_abs, Real.dist_eq]
theorem nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re :=
NNReal.eq <| dist_of_im_eq h
theorem edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by
rw [edist_nndist, edist_nndist, nndist_of_im_eq h]
theorem dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by
rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, Real.dist_eq, sub_neg_eq_add, ← two_mul,
_root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)]
theorem nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * Real.nnabs z.im :=
NNReal.eq <| by rw [← dist_nndist, NNReal.coe_mul, NNReal.coe_two, Real.coe_nnabs, dist_conj_self]
theorem dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self]
theorem nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * Real.nnabs z.im := by
rw [nndist_comm, nndist_conj_self]
/-! ### Cauchy sequences -/
theorem isCauSeq_re (f : CauSeq ℂ (‖·‖)) : IsCauSeq abs fun n ↦ (f n).re := fun _ ε0 ↦
(f.cauchy ε0).imp fun i H j ij ↦
lt_of_le_of_lt (by simpa using abs_re_le_norm (f j - f i)) (H _ ij)
theorem isCauSeq_im (f : CauSeq ℂ (‖·‖)) : IsCauSeq abs fun n ↦ (f n).im := fun ε ε0 ↦
(f.cauchy ε0).imp fun i H j ij ↦ by
simpa only [← ofReal_sub, norm_real, sub_re] using (abs_im_le_norm _).trans_lt <| H _ ij
/-- The real part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cauSeqRe (f : CauSeq ℂ (‖·‖)) : CauSeq ℝ abs :=
⟨_, isCauSeq_re f⟩
/-- The imaginary part of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cauSeqIm (f : CauSeq ℂ (‖·‖)) : CauSeq ℝ abs :=
⟨_, isCauSeq_im f⟩
theorem isCauSeq_norm {f : ℕ → ℂ} (hf : IsCauSeq (‖·‖) f) :
IsCauSeq abs ((‖·‖) ∘ f) := fun ε ε0 ↦
let ⟨i, hi⟩ := hf ε ε0
⟨i, fun j hj ↦ lt_of_le_of_lt (abs_norm_sub_norm_le _ _) (hi j hj)⟩
/-- The limit of a Cauchy sequence of complex numbers. -/
noncomputable def limAux (f : CauSeq ℂ (‖·‖)) : ℂ :=
⟨CauSeq.lim (cauSeqRe f), CauSeq.lim (cauSeqIm f)⟩
theorem equiv_limAux (f : CauSeq ℂ (‖·‖)) :
f ≈ CauSeq.const (‖·‖) (limAux f) := fun ε ε0 ↦
(exists_forall_ge_and
(CauSeq.equiv_lim ⟨_, isCauSeq_re f⟩ _ (half_pos ε0))
(CauSeq.equiv_lim ⟨_, isCauSeq_im f⟩ _ (half_pos ε0))).imp
fun _ H j ij ↦ by
obtain ⟨H₁, H₂⟩ := H _ ij
apply lt_of_le_of_lt (norm_le_abs_re_add_abs_im _)
dsimp [limAux] at *
have := add_lt_add H₁ H₂
rwa [add_halves] at this
instance instIsComplete : CauSeq.IsComplete ℂ (‖·‖) :=
⟨fun f ↦ ⟨limAux f, equiv_limAux f⟩⟩
open CauSeq
theorem lim_eq_lim_im_add_lim_re (f : CauSeq ℂ (‖·‖)) :
lim f = ↑(lim (cauSeqRe f)) + ↑(lim (cauSeqIm f)) * I :=
lim_eq_of_equiv_const <|
letI : IsAbsoluteValue (‖·‖ : ℂ → ℝ) := inferInstance
calc
f ≈ _ := equiv_limAux f
_ = CauSeq.const (‖·‖) (↑(lim (cauSeqRe f)) + ↑(lim (cauSeqIm f)) * I) :=
CauSeq.ext fun _ ↦
Complex.ext (by simp [limAux, cauSeqRe, ofReal]) (by simp [limAux, cauSeqIm, ofReal])
theorem lim_re (f : CauSeq ℂ (‖·‖)) : lim (cauSeqRe f) = (lim f).re := by
rw [lim_eq_lim_im_add_lim_re]; simp [ofReal]
theorem lim_im (f : CauSeq ℂ (‖·‖)) : lim (cauSeqIm f) = (lim f).im := by
rw [lim_eq_lim_im_add_lim_re]; simp [ofReal]
theorem isCauSeq_conj (f : CauSeq ℂ (‖·‖)) :
IsCauSeq (‖·‖) fun n ↦ conj (f n) := fun ε ε0 ↦
let ⟨i, hi⟩ := f.2 ε ε0
⟨i, fun j hj => by
simp_rw [← RingHom.map_sub, norm_conj]; exact hi j hj⟩
/-- The complex conjugate of a complex Cauchy sequence, as a complex Cauchy sequence. -/
noncomputable def cauSeqConj (f : CauSeq ℂ (‖·‖)) : CauSeq ℂ (‖·‖) :=
⟨_, isCauSeq_conj f⟩
theorem lim_conj (f : CauSeq ℂ (‖·‖)) : lim (cauSeqConj f) = conj (lim f) :=
Complex.ext (by simp [cauSeqConj, (lim_re _).symm, cauSeqRe])
(by simp [cauSeqConj, (lim_im _).symm, cauSeqIm, (lim_neg _).symm]; rfl)
/-- The norm of a complex Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cauSeqNorm (f : CauSeq ℂ (‖·‖)) : CauSeq ℝ abs :=
⟨_, isCauSeq_norm f.2⟩
theorem lim_norm (f : CauSeq ℂ (‖·‖)) : lim (cauSeqNorm f) = ‖lim f‖ :=
lim_eq_of_equiv_const fun ε ε0 ↦
let ⟨i, hi⟩ := equiv_lim f ε ε0
⟨i, fun j hj => lt_of_le_of_lt (abs_norm_sub_norm_le _ _) (hi j hj)⟩
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs := isCauSeq_norm
@[deprecated (since := "2025-02-16")] alias cauSeqAbs := cauSeqNorm
@[deprecated (since := "2025-02-16")] alias lim_abs := lim_norm
lemma ne_zero_of_re_pos {s : ℂ} (hs : 0 < s.re) : s ≠ 0 :=
fun h ↦ (zero_re ▸ h ▸ hs).false
lemma ne_zero_of_one_lt_re {s : ℂ} (hs : 1 < s.re) : s ≠ 0 :=
ne_zero_of_re_pos <| zero_lt_one.trans hs
lemma re_neg_ne_zero_of_re_pos {s : ℂ} (hs : 0 < s.re) : (-s).re ≠ 0 :=
ne_iff_lt_or_gt.mpr <| Or.inl <| neg_re s ▸ (neg_lt_zero.mpr hs)
lemma re_neg_ne_zero_of_one_lt_re {s : ℂ} (hs : 1 < s.re) : (-s).re ≠ 0 :=
re_neg_ne_zero_of_re_pos <| zero_lt_one.trans hs
end Complex
|
Cotangent.lean
|
/-
Copyright (c) 2024 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Analysis.Complex.UpperHalfPlane.Exp
import Mathlib.Analysis.Complex.IntegerCompl
import Mathlib.Analysis.Complex.LocallyUniformLimit
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd
import Mathlib.Analysis.NormedSpace.MultipliableUniformlyOn
import Mathlib.NumberTheory.ModularForms.EisensteinSeries.Summable
/-!
# Cotangent
This file contains lemmas about the cotangent function, including useful series expansions.
In particular, we prove that
`π * cot (π * z) = π * I - 2 * π * I * ∑' n : ℕ, Complex.exp (2 * π * I * z) ^ n`
as well as the infinite sum representation of cotangent (also known as the Mittag-Leffler
expansion): `π * cot (π * z) = 1 / z + ∑' n : ℕ+, (1 / ((z : ℂ) - n) + 1 / (z + n))`.
-/
open Real Complex
open scoped UpperHalfPlane
lemma Complex.cot_eq_exp_ratio (z : ℂ) :
cot z = (Complex.exp (2 * I * z) + 1) / (I * (1 - Complex.exp (2 * I * z))) := by
rw [Complex.cot, Complex.sin, Complex.cos]
field_simp
have h1 : exp (z * I) + exp (-(z * I)) = exp (-(z * I)) * (exp (2 * I * z) + 1) := by
rw [mul_add, ← Complex.exp_add]
simp only [mul_one, add_left_inj]
ring_nf
have h2 : (exp (-(z * I)) - exp (z * I)) * I = exp (-(z * I)) * (I * (1 - exp (2 * I * z))) := by
ring_nf
rw [mul_assoc, ← Complex.exp_add]
ring_nf
rw [h1, h2, mul_div_mul_left _ _ (Complex.exp_ne_zero _)]
/- The version one probably wants to use more. -/
lemma Complex.cot_pi_eq_exp_ratio (z : ℂ) :
cot (π * z) = (Complex.exp (2 * π * I * z) + 1) / (I * (1 - Complex.exp (2 * π * I * z))) := by
rw [cot_eq_exp_ratio (π * z)]
ring_nf
/- This is the version one probably wants, which is why the pi's are there. -/
theorem pi_mul_cot_pi_q_exp (z : ℍ) :
π * cot (π * z) = π * I - 2 * π * I * ∑' n : ℕ, Complex.exp (2 * π * I * z) ^ n := by
have h1 : π * ((exp (2 * π * I * z) + 1) / (I * (1 - exp (2 * π * I * z)))) =
-π * I * ((exp (2 * π * I * z) + 1) * (1 / (1 - exp (2 * π * I * z)))) := by
simp only [div_mul_eq_div_mul_one_div, div_I, one_div, neg_mul, mul_neg, neg_inj]
ring
rw [cot_pi_eq_exp_ratio, h1, one_div, (tsum_geometric_of_norm_lt_one
(UpperHalfPlane.norm_exp_two_pi_I_lt_one z)).symm, add_comm, geom_series_mul_one_add
(Complex.exp (2 * π * I * (z : ℂ))) (UpperHalfPlane.norm_exp_two_pi_I_lt_one _)]
ring
section MittagLeffler
open Filter Function
open scoped Topology BigOperators Nat Complex
local notation "ℂ_ℤ" => integerComplement
variable {x : ℂ} {Z : Set ℂ}
/-- The main term in the infinite product for sine. -/
noncomputable abbrev sineTerm (x : ℂ) (n : ℕ) : ℂ := -x ^ 2 / (n + 1) ^ 2
lemma sineTerm_ne_zero {x : ℂ} (hx : x ∈ ℂ_ℤ) (n : ℕ) : 1 + sineTerm x n ≠ 0 := by
simp only [sineTerm, ne_eq]
rw [add_eq_zero_iff_eq_neg, neg_div', eq_div_iff]
· have := (integerComplement_pow_two_ne_pow_two hx (n + 1 : ℤ))
aesop
· simp [Nat.cast_add_one_ne_zero n]
theorem tendsto_euler_sin_prod' (h0 : x ≠ 0) :
Tendsto (fun n : ℕ ↦ ∏ i ∈ Finset.range n, (1 + sineTerm x i)) atTop
(𝓝 (sin (π * x) / (π * x))) := by
rw [show (sin (π * x) / (π * x)) = sin (π * x) * (1 / (π * x)) by ring]
apply (Filter.Tendsto.mul_const (b := 1 / (π * x)) (tendsto_euler_sin_prod x)).congr
exact fun n ↦ by field_simp [sineTerm, Real.pi_ne_zero, sub_eq_add_neg]
theorem multipliable_sineTerm (x : ℂ) : Multipliable fun i ↦ (1 + sineTerm x i) := by
apply multipliable_one_add_of_summable
have := summable_pow_div_add (x ^ 2) 2 1 Nat.one_lt_two
simpa [sineTerm] using this
lemma euler_sineTerm_tprod (hx : x ∈ ℂ_ℤ) :
∏' i : ℕ, (1 + sineTerm x i) = Complex.sin (π * x) / (π * x) := by
rw [← Multipliable.hasProd_iff (multipliable_sineTerm x) ,
Multipliable.hasProd_iff_tendsto_nat (multipliable_sineTerm x)]
exact tendsto_euler_sin_prod' (integerComplement.ne_zero hx)
private lemma sineTerm_bound_aux (hZ : IsCompact Z) :
∃ u : ℕ → ℝ, Summable u ∧ ∀ j z, z ∈ Z → ‖sineTerm z j‖ ≤ u j := by
have hf : ContinuousOn (fun x : ℂ => ‖-x ^ 2‖) Z := by
fun_prop
obtain ⟨s, hs⟩ := bddAbove_def.mp (IsCompact.bddAbove_image hZ hf)
refine ⟨fun n : ℕ => ‖(s : ℂ) / (n + 1) ^ 2‖, ?_, ?_⟩
· simpa using summable_pow_div_add (s : ℂ) 2 1 (Nat.one_lt_two)
· simp only [norm_neg, norm_pow, Set.mem_image, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂, sineTerm, norm_div, norm_real, norm_eq_abs] at *
intro n x hx
gcongr
apply le_trans (hs x hx) (le_abs_self s)
theorem multipliableUniformlyOn_euler_sin_prod_on_compact (hZC : IsCompact Z) :
MultipliableUniformlyOn (fun n : ℕ => fun z : ℂ => (1 + sineTerm z n)) {Z} := by
obtain ⟨u, hu, hu2⟩ := sineTerm_bound_aux hZC
refine Summable.multipliableUniformlyOn_nat_one_add hZC hu ?_ ?_
· filter_upwards with n z hz using hu2 n z hz
· fun_prop
theorem HasProdUniformlyOn_sineTerm_prod_on_compact (hZ2 : Z ⊆ ℂ_ℤ)
(hZC : IsCompact Z) :
HasProdUniformlyOn (fun n : ℕ => fun z : ℂ => (1 + sineTerm z n))
(fun x => (Complex.sin (↑π * x) / (↑π * x))) {Z} := by
apply (multipliableUniformlyOn_euler_sin_prod_on_compact hZC).hasProdUniformlyOn.congr_right
exact fun s hs x hx => euler_sineTerm_tprod (by aesop)
theorem HasProdLocallyUniformlyOn_euler_sin_prod :
HasProdLocallyUniformlyOn (fun n : ℕ => fun z : ℂ => (1 + sineTerm z n))
(fun x => (Complex.sin (π * x) / (π * x))) ℂ_ℤ := by
apply hasProdLocallyUniformlyOn_of_forall_compact isOpen_compl_range_intCast
exact fun _ hZ hZC => HasProdUniformlyOn_sineTerm_prod_on_compact hZ hZC
theorem sin_pi_z_ne_zero (hz : x ∈ ℂ_ℤ) : Complex.sin (π * x) ≠ 0 := by
apply Complex.sin_ne_zero_iff.2
intro k
nth_rw 2 [mul_comm]
exact Injective.ne (mul_right_injective₀ (ofReal_ne_zero.mpr Real.pi_ne_zero)) (by aesop)
theorem tendsto_logDeriv_euler_sin_div (hx : x ∈ ℂ_ℤ) :
Tendsto (fun n : ℕ ↦ logDeriv (fun z ↦ ∏ j ∈ Finset.range n, (1 + sineTerm z j)) x)
atTop (𝓝 <| logDeriv (fun t ↦ (Complex.sin (π * t) / (π * t))) x) := by
refine logDeriv_tendsto (isOpen_compl_range_intCast) ⟨x, hx⟩
HasProdLocallyUniformlyOn_euler_sin_prod.tendstoLocallyUniformlyOn_finsetRange ?_ ?_
· filter_upwards with n using by fun_prop
· simp only [ne_eq, div_eq_zero_iff, mul_eq_zero, ofReal_eq_zero, not_or]
exact ⟨sin_pi_z_ne_zero hx, Real.pi_ne_zero , integerComplement.ne_zero hx⟩
theorem logDeriv_sin_div_eq_cot (hz : x ∈ ℂ_ℤ) :
logDeriv (fun t ↦ (Complex.sin (π * t) / (π * t))) x = π * cot (π * x) - 1 / x := by
have : (fun t ↦ (Complex.sin (π * t)/ (π * t))) = fun z ↦
(Complex.sin ∘ fun t ↦ π * t) z / (π * z) := by simp
rw [this, logDeriv_div _ (by apply sin_pi_z_ne_zero hz) ?_
(DifferentiableAt.comp _ (Complex.differentiableAt_sin) (by fun_prop)) (by fun_prop),
logDeriv_comp (Complex.differentiableAt_sin) (by fun_prop), Complex.logDeriv_sin,
deriv_const_mul _ (by fun_prop), deriv_id'', logDeriv_const_mul, logDeriv_id']
· field_simp [mul_comm]
· simp
· simp only [ne_eq, mul_eq_zero, ofReal_eq_zero, not_or]
exact ⟨Real.pi_ne_zero, integerComplement.ne_zero hz⟩
/-- The term in the infinite sum expansion of cot. -/
noncomputable abbrev cotTerm (x : ℂ) (n : ℕ) : ℂ := 1 / (x - (n + 1)) + 1 / (x + (n + 1))
theorem logDeriv_sineTerm_eq_cotTerm (hx : x ∈ ℂ_ℤ) (i : ℕ) :
logDeriv (fun (z : ℂ) ↦ 1 + sineTerm z i) x = cotTerm x i := by
have h1 := integerComplement_add_ne_zero hx (i + 1)
have h2 : ((x : ℂ) - (i + 1)) ≠ 0 := by
simpa [sub_eq_add_neg] using integerComplement_add_ne_zero hx (-(i + 1))
have h3 : (i+1)^2 + -x^2 ≠ 0 := by
have := (integerComplement_pow_two_ne_pow_two hx ((i + 1) : ℤ))
rw [← sub_eq_add_neg, sub_ne_zero]
aesop
simp only [Int.cast_add, Int.cast_natCast, Int.cast_one, ne_eq, sineTerm, logDeriv_apply,
deriv_const_add', deriv_div_const, deriv.fun_neg', differentiableAt_fun_id, deriv_fun_pow,
Nat.cast_ofNat, Nat.add_one_sub_one, pow_one, deriv_id'', mul_one, cotTerm, one_div] at *
field_simp [Nat.cast_add_one_ne_zero i]
ring
lemma logDeriv_prod_sineTerm_eq_sum_cotTerm (hx : x ∈ ℂ_ℤ) (n : ℕ) :
logDeriv (fun (z : ℂ) ↦ ∏ j ∈ Finset.range n, (1 + sineTerm z j)) x =
∑ j ∈ Finset.range n, cotTerm x j := by
rw [logDeriv_prod]
· simp_rw [logDeriv_sineTerm_eq_cotTerm hx]
· exact fun i _ ↦ sineTerm_ne_zero hx i
· fun_prop
theorem tendsto_logDeriv_euler_cot_sub (hx : x ∈ ℂ_ℤ) :
Tendsto (fun n : ℕ => ∑ j ∈ Finset.range n, cotTerm x j) atTop
(𝓝 <| π * cot (π * x)- 1 / x) := by
simp_rw [← logDeriv_sin_div_eq_cot hx, ← logDeriv_prod_sineTerm_eq_sum_cotTerm hx]
simpa using tendsto_logDeriv_euler_sin_div hx
lemma cotTerm_identity (hz : x ∈ ℂ_ℤ) (n : ℕ) :
cotTerm x n = 2 * x * (1 / ((x + (n + 1)) * (x - (n + 1)))) := by
simp only [cotTerm]
rw [one_div_add_one_div]
· ring
· simpa [sub_eq_add_neg] using integerComplement_add_ne_zero hz (-(n + 1) : ℤ)
· simpa using (integerComplement_add_ne_zero hz ((n : ℤ) + 1))
theorem Summable_cotTerm (hz : x ∈ ℂ_ℤ) : Summable fun n ↦ cotTerm x n := by
rw [funext fun n ↦ cotTerm_identity hz n]
apply Summable.mul_left
suffices Summable fun i : ℕ ↦ (x - (↑i : ℂ))⁻¹ * (x + (↑i : ℂ))⁻¹ by
rw [← summable_nat_add_iff 1] at this
simpa using this
suffices Summable fun i : ℤ ↦ (x - (↑i : ℂ))⁻¹ * (x + (↑i : ℂ))⁻¹ by
apply this.comp_injective CharZero.cast_injective
apply (EisensteinSeries.summable_linear_sub_mul_linear_add x 1 1).congr
simp [mul_comm]
theorem cot_series_rep' (hz : x ∈ ℂ_ℤ) : π * cot (π * x) - 1 / x =
∑' n : ℕ, (1 / (x - (n + 1)) + 1 / (x + (n + 1))) := by
rw [HasSum.tsum_eq]
apply (Summable.hasSum_iff_tendsto_nat (Summable_cotTerm hz)).mpr
(tendsto_logDeriv_euler_cot_sub hz)
/-- The cotangent infinite sum representation. -/
theorem cot_series_rep (hz : x ∈ ℂ_ℤ) :
π * cot (π * x) = 1 / x + ∑' n : ℕ+, (1 / (x - n) + 1 / (x + n)) := by
have h0 := tsum_pnat_eq_tsum_succ fun n ↦ 1 / (x - n) + 1 / (x + n)
have h1 := cot_series_rep' hz
simp only [one_div, Nat.cast_add, Nat.cast_one] at *
rw [h0, ← h1]
ring
end MittagLeffler
|
bound.lean
|
/-
Copyright (c) 2024 Geoffrey Irving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Geoffrey Irving
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Tactic.Bound
/-!
## Tests for the `bound` tactic
-/
open Complex (abs)
open scoped NNReal
-- Tests that work with `bound`, but not `positivity`, `gcongr`, or `norm_num`
section bound_only
variable {a b c x y : ℝ} {z : ℂ} {n : ℕ}
example (h : x < y) : y - x > 0 := by bound
example (h : x < y) : Real.exp (y - x) > 1 := by bound
example (h : x < y) (y0 : 0 < y) : x / y < 1 := by bound
example (f : ℕ → ℝ) (h : ∀ n, f n ≥ 0) : f n ≥ 0 := by bound [h n]
example (x y : ℝ≥0) (h : x < y) : (x : ℝ) < y := by bound
example : dist a c ≤ dist a b + dist b c := by bound
example {α : Type} {s : Finset α} {f g : α → ℂ} : -- An example that requires function inference
‖s.sum (fun x ↦ f x + g x)‖ ≤ s.sum (fun x ↦ ‖f x + g x‖) := by bound
end bound_only
-- Calc example: A weak lower bound for `z ← z^2 + c`
example {c z : ℝ} (cz : ‖c‖ ≤ ‖z‖) (z3 : 3 ≤ ‖z‖) :
2 * ‖z‖ ≤ ‖z^2 + c‖ := by
calc ‖z^2 + c‖
_ ≥ ‖z^2‖ - ‖c‖ := by bound
_ ≥ ‖z^2‖ - ‖z‖ := by bound -- gcongr works here, not for the other two
_ ≥ (‖z‖ - 1) * ‖z‖ := by
rw [mul_comm, mul_sub_one, ← pow_two, ← norm_pow]
_ ≥ 2 * ‖z‖ := by bound
-- Testing branching functionality. None of these tests work with `positivity` or `bound`.
section guess_tests
variable {a b c : ℝ} {n m : ℕ}
example (h : a ≤ b) : a ≤ max b c := by bound
example (h : a ≤ c) : a ≤ max b c := by bound
example (h : a ≤ c) : min a b ≤ c := by bound
example (h : b ≤ c) : min a b ≤ c := by bound
example (h : a < b) : a < max b c := by bound
example (h : a < c) : a < max b c := by bound
example (h : a < c) : min a b < c := by bound
example (h : b < c) : min a b < c := by bound
example (a1 : 1 ≤ a) (h : m ≤ n) : a^m ≤ a^n := by bound
example (a0 : 0 ≤ a) (a1 : a ≤ 1) (h : n ≤ m) : a^m ≤ a^n := by bound
example (a1 : 1 ≤ a) (h : b ≤ c) : a^b ≤ a^c := by bound
example (a0 : 0 < a) (a1 : a ≤ 1) (h : c ≤ b) : a^b ≤ a^c := by bound
end guess_tests
section positive_tests
variable {n : ℕ} {x y : ℝ} {u : ℝ≥0} {z : ℂ}
example (h : 0 < x) : x^2 > 0 := by bound
example (h : x > 0) : x^2 > 0 := by bound
example (p : x > 0) (q : y > 0) : x * y > 0 := by bound
example (p : x > 0) (q : y > 0) : x / y > 0 := by bound
example : 0 < 4 := by bound
example : 0 < 7 := by bound
example : 0 < (4 : ℝ) := by bound
example : 0 < (7 : ℝ) := by bound
example : 0 < (1 : ℝ) := by bound
example (h : u > 0) : 0 < (u : ℝ) := by bound
example : 0 < 2^n := by bound
example : 0 < (1 : ℝ)⁻¹ := by bound
end positive_tests
section nonneg_tests
variable {n : ℕ} {x y : ℝ} {u : ℝ≥0} {z : ℂ}
example : 0 ≤ ‖z‖ := by bound
example : ‖z‖ ≥ 0 := by bound
example : x^2 ≥ 0 := by bound
example (p : x ≥ 0) (q : y ≥ 0) : x * y ≥ 0 := by bound
example (p : x ≥ 0) (q : y ≥ 0) : x / y ≥ 0 := by bound
example (p : x ≥ 0) (q : y ≥ 0) : x + y ≥ 0 := by bound
example : (n : ℝ) ≥ 0 := by bound
example : 0 ≤ 7 := by bound
example : 0 ≤ (7 : ℝ) := by bound
example : 0 ≤ (1 : ℝ) := by bound
example : 0 ≤ (u : ℝ) := by bound
example : 0 ≤ (0 : ℝ) := by bound
example : 0 ≤ 2^n := by bound
example : 0 ≤ (0 : ℝ)⁻¹ := by bound
end nonneg_tests
section bound_tests
variable {a b c x y : ℝ} {z : ℂ} {n : ℕ}
example : (1 : ℝ) < 4 := by bound
example : (2 : ℝ) < 4 := by bound
example (n : x ≥ 0) (h : x ≤ y) : x^2 ≤ y^2 := by bound
example (n : x ≥ 0) (h : x ≤ y) : y^2 ≥ x^2 := by bound
example (n : a ≥ 0) (h : x ≤ y) : a * x ≤ a * y := by bound
example (n : a ≥ 0) (h : x ≤ y) : x * a ≤ y * a := by bound
example (bp : b ≥ 0) (xp : x ≥ 0) (ab : a ≤ b) (xy : x ≤ y) : a * x ≤ b * y := by bound
example (h : x ≤ y) : ‖z‖ * x ≤ ‖z‖ * y := by bound
example (h : x ≤ y) : a + x ≤ a + y := by bound
example (h : x ≤ y) : x + a ≤ y + a := by bound
example (ab : a ≤ b) (xy : x ≤ y) : a + x ≤ b + y := by bound
example (h : x ≥ y) : a - x ≤ a - y := by bound
example (h : x ≤ y) : x - a ≤ y - a := by bound
example (ab : a ≤ b) (xy : x ≥ y) : a - x ≤ b - y := by bound
example (h : x > 0) : x ≥ 0 := by bound
example (hc : c ≥ 0) (h : a ≤ b) : a / c ≤ b / c := by bound
example (ha : a ≥ 0) (hc : c > 0) (h : b ≥ c) : a / b ≤ a / c := by bound
example (x y : ℝ) (x0 : 0 < x) (h : x ≤ y) : x.log ≤ y.log := by bound
end bound_tests
/-- This broke without appropriate `g.withContext` use in an older implementation of `bound`.
Leaving the test here just in case. -/
example {s : Set ℂ} (o : IsOpen s) (z) (h : z ∈ s) : ∃ r : ℝ, r > 0 := by
rw [Metric.isOpen_iff] at o
rcases o z h with ⟨t, tp, bs⟩
exists t/2
clear o h bs z s
bound
-- Test various elaboration issues
example {f : ℂ → ℂ} {z w : ℂ} {s r c e : ℝ}
(sc : ∀ {w}, ‖w - z‖ < s → ‖f w - f z‖ < e) (wz : ‖w - z‖ < s) (wr : ‖w‖ < r)
(h : ∀ z : ℂ, ‖z‖ < r → ‖f z‖ ≤ c * ‖z‖) :
‖f z‖ ≤ c * ‖w‖ + e := by
calc ‖f z‖ = ‖f w - (f w - f z)‖ := by ring_nf
_ ≤ ‖f w‖ + ‖f w - f z‖ := by bound
_ ≤ c * ‖w‖+ e := by bound [h w wr, sc wz]
-- A test that requires reduction to weak head normal form to work (surfaced by `Hartogs.lean`)
example (x y : ℝ) (h : x < y ∧ True) : x ≤ y := by
bound [h.1]
-- Used to fail with `unknown identifier n`, since I wasn't elaborating [] inside the goal
theorem test_unknown_identifier {f : ℕ → ℝ} (le : ∀ n, f n ≤ n) : ∀ n : ℕ, f n ≤ n := by
intro n; bound [le n]
|
ULiftable.lean
|
/-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Control.Monad.Basic
import Mathlib.Control.Monad.Cont
import Mathlib.Control.Monad.Writer
import Mathlib.Logic.Equiv.Basic
import Mathlib.Logic.Equiv.Functor
import Mathlib.Control.Lawful
/-!
# Universe lifting for type families
Some functors such as `Option` and `List` are universe polymorphic. Unlike
type polymorphism where `Option α` is a function application and reasoning and
generalizations that apply to functions can be used, `Option.{u}` and `Option.{v}`
are not one function applied to two universe names but one polymorphic definition
instantiated twice. This means that whatever works on `Option.{u}` is hard
to transport over to `Option.{v}`. `ULiftable` is an attempt at improving the situation.
`ULiftable Option.{u} Option.{v}` gives us a generic and composable way to use
`Option.{u}` in a context that requires `Option.{v}`. It is often used in tandem with
`ULift` but the two are purposefully decoupled.
## Main definitions
* `ULiftable` class
## Tags
universe polymorphism functor
-/
universe v u₀ u₁ v₀ v₁ v₂ w w₀ w₁
variable {s : Type u₀} {s' : Type u₁} {r r' w w' : Type*}
/-- Given a universe polymorphic type family `M.{u} : Type u₁ → Type
u₂`, this class convert between instantiations, from
`M.{u} : Type u₁ → Type u₂` to `M.{v} : Type v₁ → Type v₂` and back.
`f` is an outParam, because `g` can almost always be inferred from the current monad.
At any rate, the lift should be unique, as the intent is to only lift the same constants with
different universe parameters. -/
class ULiftable (f : outParam (Type u₀ → Type u₁)) (g : Type v₀ → Type v₁) where
congr {α β} : α ≃ β → f α ≃ g β
namespace ULiftable
/-- Not an instance as it is incompatible with `outParam`. In practice it seems not to be needed
anyway. -/
abbrev symm (f : Type u₀ → Type u₁) (g : Type v₀ → Type v₁) [ULiftable f g] : ULiftable g f where
congr e := (ULiftable.congr e.symm).symm
instance refl (f : Type u₀ → Type u₁) [Functor f] [LawfulFunctor f] : ULiftable f f where
congr e := Functor.mapEquiv _ e
/-- The most common practical use `ULiftable` (together with `down`), the function `up.{v}` takes
`x : M.{u} α` and lifts it to `M.{max u v} (ULift.{v} α)` -/
abbrev up {f : Type u₀ → Type u₁} {g : Type max u₀ v → Type v₁} [ULiftable f g] {α} :
f α → g (ULift.{v} α) :=
(ULiftable.congr Equiv.ulift.symm).toFun
/-- The most common practical use of `ULiftable` (together with `up`), the function `down.{v}` takes
`x : M.{max u v} (ULift.{v} α)` and lowers it to `M.{u} α` -/
abbrev down {f : Type u₀ → Type u₁} {g : Type max u₀ v → Type v₁} [ULiftable f g] {α} :
g (ULift.{v} α) → f α :=
(ULiftable.congr Equiv.ulift.symm).invFun
/-- convenient shortcut to avoid manipulating `ULift` -/
def adaptUp (F : Type v₀ → Type v₁) (G : Type max v₀ u₀ → Type u₁) [ULiftable F G] [Monad G] {α β}
(x : F α) (f : α → G β) : G β :=
up x >>= f ∘ ULift.down.{u₀}
/-- convenient shortcut to avoid manipulating `ULift` -/
def adaptDown {F : Type max u₀ v₀ → Type u₁} {G : Type v₀ → Type v₁} [L : ULiftable G F] [Monad F]
{α β} (x : F α) (f : α → G β) : G β :=
@down.{max u₀ v₀} G F L β <| x >>= @up.{max u₀ v₀} G F L β ∘ f
/-- map function that moves up universes -/
def upMap {F : Type u₀ → Type u₁} {G : Type max u₀ v₀ → Type v₁} [ULiftable F G] [Functor G]
{α β} (f : α → β) (x : F α) : G β :=
Functor.map (f ∘ ULift.down.{v₀}) (up x)
/-- map function that moves down universes -/
def downMap {F : Type max u₀ v₀ → Type u₁} {G : Type u₀ → Type v₁} [ULiftable G F]
[Functor F] {α β} (f : α → β) (x : F α) : G β :=
down (Functor.map (ULift.up.{v₀} ∘ f) x : F (ULift β))
/-- A version of `up` for a `PUnit` return type. -/
abbrev up' {f : Type u₀ → Type u₁} {g : Type v₀ → Type v₁} [ULiftable f g] :
f PUnit → g PUnit :=
ULiftable.congr Equiv.punitEquivPUnit
/-- A version of `down` for a `PUnit` return type. -/
abbrev down' {f : Type u₀ → Type u₁} {g : Type v₀ → Type v₁} [ULiftable f g] :
g PUnit → f PUnit :=
(ULiftable.congr Equiv.punitEquivPUnit).symm
theorem up_down {f : Type u₀ → Type u₁} {g : Type max u₀ v₀ → Type v₁} [ULiftable f g] {α}
(x : g (ULift.{v₀} α)) : up (down x : f α) = x :=
(ULiftable.congr Equiv.ulift.symm).right_inv _
theorem down_up {f : Type u₀ → Type u₁} {g : Type max u₀ v₀ → Type v₁} [ULiftable f g] {α}
(x : f α) : down (up x : g (ULift.{v₀} α)) = x :=
(ULiftable.congr Equiv.ulift.symm).left_inv _
end ULiftable
open ULift
instance instULiftableId : ULiftable Id Id where
congr F := F
/-- for specific state types, this function helps to create a uliftable instance -/
def StateT.uliftable' {m : Type u₀ → Type v₀} {m' : Type u₁ → Type v₁} [ULiftable m m']
(F : s ≃ s') : ULiftable (StateT s m) (StateT s' m') where
congr G :=
StateT.equiv <| Equiv.piCongr F fun _ => ULiftable.congr <| Equiv.prodCongr G F
instance {m m'} [ULiftable m m'] : ULiftable (StateT s m) (StateT (ULift s) m') :=
StateT.uliftable' Equiv.ulift.symm
instance StateT.instULiftableULiftULift {m m'} [ULiftable m m'] :
ULiftable (StateT (ULift.{max v₀ u₀} s) m) (StateT (ULift.{max v₁ u₀} s) m') :=
StateT.uliftable' <| Equiv.ulift.trans Equiv.ulift.symm
/-- for specific reader monads, this function helps to create a uliftable instance -/
def ReaderT.uliftable' {m m'} [ULiftable m m'] (F : s ≃ s') :
ULiftable (ReaderT s m) (ReaderT s' m') where
congr G := ReaderT.equiv <| Equiv.piCongr F fun _ => ULiftable.congr G
instance {m m'} [ULiftable m m'] : ULiftable (ReaderT s m) (ReaderT (ULift s) m') :=
ReaderT.uliftable' Equiv.ulift.symm
instance ReaderT.instULiftableULiftULift {m m'} [ULiftable m m'] :
ULiftable (ReaderT (ULift.{max v₀ u₀} s) m) (ReaderT (ULift.{max v₁ u₀} s) m') :=
ReaderT.uliftable' <| Equiv.ulift.trans Equiv.ulift.symm
/-- for specific continuation passing monads, this function helps to create a uliftable instance -/
def ContT.uliftable' {m m'} [ULiftable m m'] (F : r ≃ r') :
ULiftable (ContT r m) (ContT r' m') where
congr := ContT.equiv (ULiftable.congr F)
instance {s m m'} [ULiftable m m'] : ULiftable (ContT s m) (ContT (ULift s) m') :=
ContT.uliftable' Equiv.ulift.symm
instance ContT.instULiftableULiftULift {m m'} [ULiftable m m'] :
ULiftable (ContT (ULift.{max v₀ u₀} s) m) (ContT (ULift.{max v₁ u₀} s) m') :=
ContT.uliftable' <| Equiv.ulift.trans Equiv.ulift.symm
/-- for specific writer monads, this function helps to create a uliftable instance -/
def WriterT.uliftable' {m m'} [ULiftable m m'] (F : w ≃ w') :
ULiftable (WriterT w m) (WriterT w' m') where
congr G := WriterT.equiv <| ULiftable.congr <| Equiv.prodCongr G F
instance {m m'} [ULiftable m m'] : ULiftable (WriterT s m) (WriterT (ULift s) m') :=
WriterT.uliftable' Equiv.ulift.symm
instance WriterT.instULiftableULiftULift {m m'} [ULiftable m m'] :
ULiftable (WriterT (ULift.{max v₀ u₀} s) m) (WriterT (ULift.{max v₁ u₀} s) m') :=
WriterT.uliftable' <| Equiv.ulift.trans Equiv.ulift.symm
instance Except.instULiftable {ε : Type u₀} : ULiftable (Except.{u₀,v₁} ε) (Except.{u₀,v₂} ε) where
congr e :=
{ toFun := Except.map e
invFun := Except.map e.symm
left_inv := fun f => by cases f <;> simp [Except.map]
right_inv := fun f => by cases f <;> simp [Except.map] }
instance Option.instULiftable : ULiftable Option.{u₀} Option.{u₁} where
congr e :=
{ toFun := Option.map e
invFun := Option.map e.symm
left_inv := fun f => by cases f <;> simp
right_inv := fun f => by cases f <;> simp }
|
Field.lean
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Order.Filter.AtTopBot.Ring
/-!
# Convergence to ±infinity in linear ordered (semi)fields
-/
namespace Filter
variable {α β : Type*}
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α]
{l : Filter β} {f : β → α} {r c : α} {n : ℕ}
/-!
### Multiplication by constant: iff lemmas
-/
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_const_mul_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atTop :=
⟨fun h => h.atTop_of_const_mul₀ hr, fun h =>
Tendsto.atTop_of_const_mul₀ (inv_pos.2 hr) <| by simpa only [inv_mul_cancel_left₀ hr.ne'] ⟩
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
theorem tendsto_mul_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_pos hr
/-- If `r` is a positive constant, `x ↦ f x / r` tends to infinity along a filter
if and only if `f` tends to infinity along the same filter. -/
lemma tendsto_div_const_atTop_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atTop := by
simpa only [div_eq_mul_inv] using tendsto_mul_const_atTop_of_pos (inv_pos.2 hr)
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to infinity if and only if `0 < r`. -/
theorem tendsto_const_mul_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r := by
refine ⟨fun hrf => not_le.mp fun hr => ?_, fun hr => (tendsto_const_mul_atTop_of_pos hr).mpr h⟩
rcases ((h.eventually_ge_atTop 0).and (hrf.eventually_gt_atTop 0)).exists with ⟨x, hx, hrx⟩
exact (mul_nonpos_of_nonpos_of_nonneg hr hx).not_gt hrx
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to infinity if and only if `0 < r`. -/
theorem tendsto_mul_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_pos h]
/-- If `f` tends to infinity along a nontrivial filter `l`, then
`x ↦ f x * r` tends to infinity if and only if `0 < r`. -/
lemma tendsto_div_const_atTop_iff_pos [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r := by
simp only [div_eq_mul_inv, tendsto_mul_const_atTop_iff_pos h, inv_pos]
/-- If `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.const_mul_atTop'` instead. -/
theorem Tendsto.const_mul_atTop (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_pos hr).2 hf
/-- If a function `f` tends to infinity along a filter, then `f` multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`Filter.Tendsto.atTop_mul_const'` instead. -/
theorem Tendsto.atTop_mul_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_pos hr).2 hf
/-- If a function `f` tends to infinity along a filter, then `f` divided by a positive
constant also tends to infinity. -/
theorem Tendsto.atTop_div_const (hr : 0 < r) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x / r) l atTop := by
simpa only [div_eq_mul_inv] using hf.atTop_mul_const (inv_pos.2 hr)
theorem tendsto_const_mul_pow_atTop (hn : n ≠ 0) (hc : 0 < c) :
Tendsto (fun x => c * x ^ n) atTop atTop :=
Tendsto.const_mul_atTop hc (tendsto_pow_atTop hn)
theorem tendsto_const_mul_pow_atTop_iff :
Tendsto (fun x => c * x ^ n) atTop atTop ↔ n ≠ 0 ∧ 0 < c := by
refine ⟨fun h => ⟨?_, ?_⟩, fun h => tendsto_const_mul_pow_atTop h.1 h.2⟩
· rintro rfl
simp only [pow_zero, not_tendsto_const_atTop] at h
· rcases ((h.eventually_gt_atTop 0).and (eventually_ge_atTop 0)).exists with ⟨k, hck, hk⟩
exact pos_of_mul_pos_left hck (pow_nonneg hk _)
lemma tendsto_zpow_atTop_atTop {n : ℤ} (hn : 0 < n) : Tendsto (fun x : α ↦ x ^ n) atTop atTop := by
lift n to ℕ using hn.le; simp [(Int.natCast_pos.mp hn).ne']
end LinearOrderedSemifield
section LinearOrderedField
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α]
{l : Filter β} {f : β → α} {r : α}
/-- If `r` is a positive constant, `fun x ↦ r * f x` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_const_mul_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atBot := by
simpa only [← mul_neg, ← tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos hr
/-- If `r` is a positive constant, `fun x ↦ f x * r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
theorem tendsto_mul_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_pos hr
/-- If `r` is a positive constant, `fun x ↦ f x / r` tends to negative infinity along a filter
if and only if `f` tends to negative infinity along the same filter. -/
lemma tendsto_div_const_atBot_of_pos (hr : 0 < r) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_pos, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_const_mul_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atTop ↔ Tendsto f l atBot := by
simpa only [neg_mul, tendsto_neg_atBot_iff] using tendsto_const_mul_atBot_of_pos (neg_pos.2 hr)
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
theorem tendsto_mul_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atTop ↔ Tendsto f l atBot := by
simpa only [mul_comm] using tendsto_const_mul_atTop_of_neg hr
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to infinity along a filter `l`
if and only if `f` tends to negative infinity along `l`. -/
lemma tendsto_div_const_atTop_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atTop ↔ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_of_neg, hr]
/-- If `r` is a negative constant, `fun x ↦ r * f x` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_const_mul_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => r * f x) l atBot ↔ Tendsto f l atTop := by
simpa only [neg_mul, tendsto_neg_atTop_iff] using tendsto_const_mul_atTop_of_pos (neg_pos.2 hr)
/-- If `r` is a negative constant, `fun x ↦ f x * r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
theorem tendsto_mul_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x => f x * r) l atBot ↔ Tendsto f l atTop := by
simpa only [mul_comm] using tendsto_const_mul_atBot_of_neg hr
/-- If `r` is a negative constant, `fun x ↦ f x / r` tends to negative infinity along a filter `l`
if and only if `f` tends to infinity along `l`. -/
lemma tendsto_div_const_atBot_of_neg (hr : r < 0) :
Tendsto (fun x ↦ f x / r) l atBot ↔ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_of_neg, hr]
/-- The function `fun x ↦ r * f x` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_const_mul_atTop_iff [NeBot l] :
Tendsto (fun x => r * f x) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· simp [hr, hr.not_gt, tendsto_const_mul_atTop_of_neg]
· simp [not_tendsto_const_atTop]
· simp [hr, hr.not_gt, tendsto_const_mul_atTop_of_pos]
/-- The function `fun x ↦ f x * r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
theorem tendsto_mul_const_atTop_iff [NeBot l] :
Tendsto (fun x => f x * r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff]
/-- The function `fun x ↦ f x / r` tends to infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to infinity or `r < 0` and `f` tends to negative infinity. -/
lemma tendsto_div_const_atTop_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atTop ↔ 0 < r ∧ Tendsto f l atTop ∨ r < 0 ∧ Tendsto f l atBot := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff]
/-- The function `fun x ↦ r * f x` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_const_mul_atBot_iff [NeBot l] :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [← tendsto_neg_atTop_iff, ← mul_neg, tendsto_const_mul_atTop_iff, neg_neg]
/-- The function `fun x ↦ f x * r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
theorem tendsto_mul_const_atBot_iff [NeBot l] :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff]
/-- The function `fun x ↦ f x / r` tends to negative infinity along a nontrivial filter
if and only if `r > 0` and `f` tends to negative infinity or `r < 0` and `f` tends to infinity. -/
lemma tendsto_div_const_atBot_iff [NeBot l] :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r ∧ Tendsto f l atBot ∨ r < 0 ∧ Tendsto f l atTop := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ r * f x` tends to infinity if and only if `r < 0`. -/
theorem tendsto_const_mul_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop ↔ r < 0 := by
simp [tendsto_const_mul_atTop_iff, h, h.not_tendsto disjoint_atBot_atTop]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x * r` tends to infinity if and only if `r < 0`. -/
theorem tendsto_mul_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atTop_iff_neg h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`,
then `fun x ↦ f x / r` tends to infinity if and only if `r < 0`. -/
lemma tendsto_div_const_atTop_iff_neg [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atTop ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atTop_iff_neg h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ r * f x` tends to negative infinity if and only if `0 < r`. -/
theorem tendsto_const_mul_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot ↔ 0 < r := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atBot_atTop]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x * r` tends to negative infinity if and only if `0 < r`. -/
theorem tendsto_mul_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot ↔ 0 < r := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_pos h]
/-- If `f` tends to negative infinity along a nontrivial filter `l`, then
`fun x ↦ f x / r` tends to negative infinity if and only if `0 < r`. -/
lemma tendsto_div_const_atBot_iff_pos [NeBot l] (h : Tendsto f l atBot) :
Tendsto (fun x ↦ f x / r) l atBot ↔ 0 < r := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_pos h]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ r * f x` tends to negative infinity if and only if `r < 0`. -/
theorem tendsto_const_mul_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot ↔ r < 0 := by
simp [tendsto_const_mul_atBot_iff, h, h.not_tendsto disjoint_atTop_atBot]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x * r` tends to negative infinity if and only if `r < 0`. -/
theorem tendsto_mul_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot ↔ r < 0 := by
simp only [mul_comm _ r, tendsto_const_mul_atBot_iff_neg h]
/-- If `f` tends to infinity along a nontrivial filter,
`fun x ↦ f x / r` tends to negative infinity if and only if `r < 0`. -/
lemma tendsto_div_const_atBot_iff_neg [NeBot l] (h : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot ↔ r < 0 := by
simp [div_eq_mul_inv, tendsto_mul_const_atBot_iff_neg h]
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to negative infinity. -/
theorem Tendsto.const_mul_atTop_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_neg hr).2 hf
/-- If a function `f` tends to infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to negative infinity. -/
theorem Tendsto.atTop_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_neg hr).2 hf
/-- If a function `f` tends to infinity along a filter,
then `f` divided by a negative constant tends to negative infinity. -/
lemma Tendsto.atTop_div_const_of_neg (hr : r < 0) (hf : Tendsto f l atTop) :
Tendsto (fun x ↦ f x / r) l atBot := (tendsto_div_const_atBot_of_neg hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the left) also tends to negative infinity. -/
theorem Tendsto.const_mul_atBot (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atBot :=
(tendsto_const_mul_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` multiplied by
a positive constant (on the right) also tends to negative infinity. -/
theorem Tendsto.atBot_mul_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atBot :=
(tendsto_mul_const_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter, then `f` divided by
a positive constant also tends to negative infinity. -/
theorem Tendsto.atBot_div_const (hr : 0 < r) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x / r) l atBot := (tendsto_div_const_atBot_of_pos hr).2 hf
/-- If a function `f` tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the left) tends to positive infinity. -/
theorem Tendsto.const_mul_atBot_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => r * f x) l atTop :=
(tendsto_const_mul_atTop_of_neg hr).2 hf
/-- If a function tends to negative infinity along a filter,
then `f` multiplied by a negative constant (on the right) tends to positive infinity. -/
theorem Tendsto.atBot_mul_const_of_neg (hr : r < 0) (hf : Tendsto f l atBot) :
Tendsto (fun x => f x * r) l atTop :=
(tendsto_mul_const_atTop_of_neg hr).2 hf
theorem tendsto_neg_const_mul_pow_atTop {c : α} {n : ℕ} (hn : n ≠ 0) (hc : c < 0) :
Tendsto (fun x => c * x ^ n) atTop atBot :=
(tendsto_pow_atTop hn).const_mul_atTop_of_neg hc
theorem tendsto_const_mul_pow_atBot_iff {c : α} {n : ℕ} :
Tendsto (fun x => c * x ^ n) atTop atBot ↔ n ≠ 0 ∧ c < 0 := by
simp only [← tendsto_neg_atTop_iff, ← neg_mul, tendsto_const_mul_pow_atTop_iff, neg_pos]
end LinearOrderedField
end Filter
|
intdiv.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple prime order.
From mathcomp Require Import ssralg poly ssrnum ssrint matrix.
From mathcomp Require Import polydiv perm zmodp bigop.
(******************************************************************************)
(* This file provides various results on divisibility of integers. *)
(* It defines, for m, n, d : int, *)
(* (m %% d)%Z == the remainder of the Euclidean division of m by d; this is *)
(* the least non-negative element of the coset m + dZ when *)
(* d != 0, and m if d = 0. *)
(* (m %/ d)%Z == the quotient of the Euclidean division of m by d, such *)
(* that m = (m %/ d)%Z * d + (m %% d)%Z. Since for d != 0 the *)
(* remainder is non-negative, (m %/ d)%Z is non-zero for *)
(* negative m. *)
(* (d %| m)%Z <=> m is divisible by d; dvdz d is the (collective) predicate *)
(* for integers divisible by d, and (d %| m)%Z is actually *)
(* (transposing) notation for m \in dvdz d. *)
(* (m = n %[mod d])%Z, (m == n %[mod d])%Z, (m != n %[mod d])%Z *)
(* m and n are (resp. compare, don't compare) equal mod d. *)
(* gcdz m n == the (non-negative) greatest common divisor of m and n, *)
(* with gcdz 0 0 = 0. *)
(* lcmz m n == the (non-negative) least common multiple of m and n. *)
(* coprimez m n <=> m and n are coprime. *)
(* egcdz m n == the Bezout coefficients of the gcd of m and n: a pair *)
(* (u, v) of coprime integers such that u*m + v*n = gcdz m n. *)
(* Alternatively, a Bezoutz lemma states such u and v exist. *)
(* zchinese m1 m2 n1 n2 == for coprime m1 and m2, a solution to the Chinese *)
(* remainder problem for n1 and n2, i.e., and integer n such *)
(* that n = n1 %[mod m1] and n = n2 %[mod m2]. *)
(* zcontents p == the contents of p : {poly int}, that is, the gcd of the *)
(* coefficients of p, with the same sign as the lead *)
(* coefficient of p. *)
(* zprimitive p == the primitive part of p : {poly int}, i.e., p divided by *)
(* its contents. *)
(* int_Smith_normal_form :: a theorem asserting the existence of the Smith *)
(* normal form for integer matrices. *)
(* Note that many of the concepts and results in this file could and perhaps *)
(* should be generalized to the more general setting of integral, unique *)
(* factorization, principal ideal, or Euclidean domains. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Definition divz (m d : int) : int :=
let: (K, n) := match m with Posz n => (Posz, n) | Negz n => (Negz, n) end in
sgz d * K (n %/ `|d|)%N.
Definition modz (m d : int) : int := m - divz m d * d.
Definition dvdz d m := (`|d| %| `|m|)%N.
Definition gcdz m n := (gcdn `|m| `|n|)%:Z.
Definition lcmz m n := (lcmn `|m| `|n|)%:Z.
Definition egcdz m n : int * int :=
if m == 0 then (0, (-1) ^+ (n < 0)%R) else
let: (u, v) := egcdn `|m| `|n| in (sgz m * u, - (-1) ^+ (n < 0)%R * v%:Z).
Definition coprimez m n := (gcdz m n == 1).
Infix "%/" := divz : int_scope.
Infix "%%" := modz : int_scope.
Notation "d %| m" := (m \in dvdz d) : int_scope.
Notation "m = n %[mod d ]" := (modz m d = modz n d) : int_scope.
Notation "m == n %[mod d ]" := (modz m d == modz n d) : int_scope.
Notation "m <> n %[mod d ]" := (modz m d <> modz n d) : int_scope.
Notation "m != n %[mod d ]" := (modz m d != modz n d) : int_scope.
Lemma divz_nat (n d : nat) : (n %/ d)%Z = (n %/ d)%N.
Proof. by case: d => // d; rewrite /divz /= mul1r. Qed.
Lemma divzN m d : (m %/ - d)%Z = - (m %/ d)%Z.
Proof. by case: m => n; rewrite /divz /= sgzN abszN mulNr. Qed.
Lemma divz_abs (m d : int) : (m %/ `|d|)%Z = (-1) ^+ (d < 0)%R * (m %/ d)%Z.
Proof.
by rewrite {3}[d]intEsign !mulr_sign; case: ifP => -> //; rewrite divzN opprK.
Qed.
Lemma div0z d : (0 %/ d)%Z = 0.
Proof.
by rewrite -(canLR (signrMK _) (divz_abs _ _)) (divz_nat 0) div0n mulr0.
Qed.
Lemma divNz_nat m d : (d > 0)%N -> (Negz m %/ d)%Z = - (m %/ d).+1%:Z.
Proof. by case: d => // d _; apply: mul1r. Qed.
Lemma divz_eq m d : m = (m %/ d)%Z * d + (m %% d)%Z.
Proof. by rewrite addrC subrK. Qed.
Lemma modzN m d : (m %% - d)%Z = (m %% d)%Z.
Proof. by rewrite /modz divzN mulrNN. Qed.
Lemma modz_abs m d : (m %% `|d|%N)%Z = (m %% d)%Z.
Proof. by rewrite {2}[d]intEsign mulr_sign; case: ifP; rewrite ?modzN. Qed.
Lemma modz_nat (m d : nat) : (m %% d)%Z = (m %% d)%N.
Proof.
by apply: (canLR (addrK _)); rewrite addrC divz_nat {1}(divn_eq m d).
Qed.
Lemma modNz_nat m d : (d > 0)%N -> (Negz m %% d)%Z = d%:Z - 1 - (m %% d)%:Z.
Proof.
rewrite /modz => /divNz_nat->; apply: (canLR (addrK _)).
rewrite -!addrA -!opprD -!PoszD -opprB mulnSr !addnA PoszD addrK.
by rewrite addnAC -addnA mulnC -divn_eq.
Qed.
Lemma modz_ge0 m d : d != 0 -> 0 <= (m %% d)%Z.
Proof.
rewrite -absz_gt0 -modz_abs => d_gt0.
case: m => n; rewrite ?modNz_nat ?modz_nat // -addrA -opprD subr_ge0.
by rewrite lez_nat ltn_mod.
Qed.
Lemma divz0 m : (m %/ 0)%Z = 0. Proof. by case: m. Qed.
Lemma mod0z d : (0 %% d)%Z = 0. Proof. by rewrite /modz div0z mul0r subrr. Qed.
Lemma modz0 m : (m %% 0)%Z = m. Proof. by rewrite /modz mulr0 subr0. Qed.
Lemma divz_small m d : 0 <= m < `|d|%:Z -> (m %/ d)%Z = 0.
Proof.
rewrite -(canLR (signrMK _) (divz_abs _ _)); case: m => // n /divn_small.
by rewrite divz_nat => ->; rewrite mulr0.
Qed.
Lemma divzMDl q m d : d != 0 -> ((q * d + m) %/ d)%Z = q + (m %/ d)%Z.
Proof.
rewrite neq_lt -oppr_gt0 => nz_d.
wlog{nz_d} d_gt0: q d / d > 0; last case: d => // d in d_gt0 *.
move=> IH; case/orP: nz_d => /IH// /(_ (- q)).
by rewrite mulrNN !divzN -opprD => /oppr_inj.
wlog q_gt0: q m / q >= 0; last case: q q_gt0 => // q _.
move=> IH; case: q => n; first exact: IH; rewrite NegzE mulNr.
by apply: canRL (addKr _) _; rewrite -IH ?addNKr.
case: m => n; first by rewrite !divz_nat divnMDl.
have [le_qd_n | lt_qd_n] := leqP (q * d) n.
rewrite divNz_nat // NegzE -(subnKC le_qd_n) divnMDl //.
by rewrite -!addnS !PoszD !opprD !addNKr divNz_nat.
rewrite divNz_nat // NegzE -PoszM subzn // divz_nat.
apply: canRL (addrK _) _; congr _%:Z; rewrite addnC -divnMDl // mulSnr.
rewrite -{3}(subnKC (ltn_pmod n d_gt0)) addnA addnS -divn_eq addnAC.
by rewrite subnKC // divnMDl // divn_small ?addn0 // subnSK ?ltn_mod ?leq_subr.
Qed.
Lemma mulzK m d : d != 0 -> (m * d %/ d)%Z = m.
Proof. by move=> d_nz; rewrite -[m * d]addr0 divzMDl // div0z addr0. Qed.
Lemma mulKz m d : d != 0 -> (d * m %/ d)%Z = m.
Proof. by move=> d_nz; rewrite mulrC mulzK. Qed.
Lemma expzB p m n : p != 0 -> (m >= n)%N -> p ^+ (m - n) = (p ^+ m %/ p ^+ n)%Z.
Proof. by move=> p_nz /subnK{2}<-; rewrite exprD mulzK // expf_neq0. Qed.
Lemma modz1 m : (m %% 1)%Z = 0.
Proof. by case: m => n; rewrite (modNz_nat, modz_nat) ?modn1. Qed.
Lemma divz1 m : (m %/ 1)%Z = m. Proof. by rewrite -{1}[m]mulr1 mulzK. Qed.
Lemma divzz d : (d %/ d)%Z = (d != 0).
Proof. by have [-> // | d_nz] := eqVneq; rewrite -{1}[d]mul1r mulzK. Qed.
Lemma ltz_pmod m d : d > 0 -> (m %% d)%Z < d.
Proof.
case: m d => n [] // d d_gt0; first by rewrite modz_nat ltz_nat ltn_pmod.
by rewrite modNz_nat // -lezD1 addrAC subrK gerDl oppr_le0.
Qed.
Lemma ltz_mod m d : d != 0 -> (m %% d)%Z < `|d|.
Proof. by rewrite -absz_gt0 -modz_abs => d_gt0; apply: ltz_pmod. Qed.
Lemma divzMpl p m d : p > 0 -> (p * m %/ (p * d) = m %/ d)%Z.
Proof.
case: p => // p p_gt0; wlog d_gt0: d / d > 0; last case: d => // d in d_gt0 *.
by move=> IH; case/intP: d => [|d|d]; rewrite ?mulr0 ?divz0 ?mulrN ?divzN ?IH.
rewrite {1}(divz_eq m d) mulrDr mulrCA divzMDl ?mulf_neq0 ?gt_eqF // addrC.
rewrite divz_small ?add0r // PoszM pmulr_rge0 ?modz_ge0 ?gt_eqF //=.
by rewrite ltr_pM2l ?ltz_pmod.
Qed.
Arguments divzMpl [p m d].
Lemma divzMpr p m d : p > 0 -> (m * p %/ (d * p) = m %/ d)%Z.
Proof. by move=> p_gt0; rewrite -!(mulrC p) divzMpl. Qed.
Arguments divzMpr [p m d].
Lemma lez_floor m d : d != 0 -> (m %/ d)%Z * d <= m.
Proof. by rewrite -subr_ge0; apply: modz_ge0. Qed.
(* leq_mod does not extend to negative m. *)
Lemma lez_div m d : (`|(m %/ d)%Z| <= `|m|)%N.
Proof.
wlog d_gt0: d / d > 0; last case: d d_gt0 => // d d_gt0.
by move=> IH; case/intP: d => [|n|n]; rewrite ?divz0 ?divzN ?abszN // IH.
case: m => n; first by rewrite divz_nat leq_div.
by rewrite divNz_nat // NegzE !abszN ltnS leq_div.
Qed.
Lemma ltz_ceil m d : d > 0 -> m < ((m %/ d)%Z + 1) * d.
Proof.
by case: d => // d d_gt0; rewrite mulrDl mul1r -ltrBlDl ltz_mod ?gt_eqF.
Qed.
Lemma ltz_divLR m n d : d > 0 -> ((m %/ d)%Z < n) = (m < n * d).
Proof.
move=> d_gt0; apply/idP/idP.
by rewrite -[_ < n]lezD1 -(ler_pM2r d_gt0); exact/lt_le_trans/ltz_ceil.
by rewrite -(ltr_pM2r d_gt0 _ n); apply/le_lt_trans/lez_floor; rewrite gt_eqF.
Qed.
Lemma lez_divRL m n d : d > 0 -> (m <= (n %/ d)%Z) = (m * d <= n).
Proof. by move=> d_gt0; rewrite !leNgt ltz_divLR. Qed.
Lemma lez_pdiv2r d : 0 <= d -> {homo divz^~ d : m n / m <= n}.
Proof.
by case: d => [[|d]|]// _ [] m [] n //; rewrite /divz !mul1r; apply: leq_div2r.
Qed.
Lemma divz_ge0 m d : d > 0 -> ((m %/ d)%Z >= 0) = (m >= 0).
Proof. by case: d m => // d [] n d_gt0; rewrite (divz_nat, divNz_nat). Qed.
Lemma divzMA_ge0 m n p : n >= 0 -> (m %/ (n * p) = (m %/ n)%Z %/ p)%Z.
Proof.
case: n => // [[|n]] _; first by rewrite mul0r !divz0 div0z.
wlog p_gt0: p / p > 0; last case: p => // p in p_gt0 *.
by case/intP: p => [|p|p] IH; rewrite ?mulr0 ?divz0 ?mulrN ?divzN // IH.
rewrite {2}(divz_eq m (n.+1%:Z * p)) mulrA mulrAC !divzMDl // ?gt_eqF //.
rewrite [rhs in _ + rhs]divz_small ?addr0 // ltz_divLR // divz_ge0 //.
by rewrite mulrC ltz_pmod ?modz_ge0 ?gt_eqF ?pmulr_lgt0.
Qed.
Lemma modz_small m d : 0 <= m < d -> (m %% d)%Z = m.
Proof. by case: m d => //= m [] // d; rewrite modz_nat => /modn_small->. Qed.
Lemma modz_mod m d : ((m %% d)%Z = m %[mod d])%Z.
Proof.
rewrite -!(modz_abs _ d); case: {d}`|d|%N => [|d]; first by rewrite !modz0.
by rewrite modz_small ?modz_ge0 ?ltz_mod.
Qed.
Lemma modzMDl p m d : (p * d + m = m %[mod d])%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite mulr0 add0r.
by rewrite /modz divzMDl // mulrDl opprD addrACA subrr add0r.
Qed.
Lemma mulz_modr {p m d} : 0 < p -> p * (m %% d)%Z = ((p * m) %% (p * d))%Z.
Proof.
case: p => // p p_gt0; rewrite mulrBr; apply: canLR (addrK _) _.
by rewrite mulrCA -(divzMpl p_gt0) subrK.
Qed.
Lemma mulz_modl {p m d} : 0 < p -> (m %% d)%Z * p = ((m * p) %% (d * p))%Z.
Proof. by rewrite -!(mulrC p); apply: mulz_modr. Qed.
Lemma modzDl m d : (d + m = m %[mod d])%Z.
Proof. by rewrite -{1}[d]mul1r modzMDl. Qed.
Lemma modzDr m d : (m + d = m %[mod d])%Z.
Proof. by rewrite addrC modzDl. Qed.
Lemma modzz d : (d %% d)%Z = 0.
Proof. by rewrite -{1}[d]addr0 modzDl mod0z. Qed.
Lemma modzMl p d : (p * d %% d)%Z = 0.
Proof. by rewrite -[p * d]addr0 modzMDl mod0z. Qed.
Lemma modzMr p d : (d * p %% d)%Z = 0.
Proof. by rewrite mulrC modzMl. Qed.
Lemma modzDml m n d : ((m %% d)%Z + n = m + n %[mod d])%Z.
Proof. by rewrite {2}(divz_eq m d) -[_ * d + _ + n]addrA modzMDl. Qed.
Lemma modzDmr m n d : (m + (n %% d)%Z = m + n %[mod d])%Z.
Proof. by rewrite !(addrC m) modzDml. Qed.
Lemma modzDm m n d : ((m %% d)%Z + (n %% d)%Z = m + n %[mod d])%Z.
Proof. by rewrite modzDml modzDmr. Qed.
Lemma eqz_modDl p m n d : (p + m == p + n %[mod d])%Z = (m == n %[mod d])%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !modz0 (inj_eq (addrI p)).
apply/eqP/eqP=> eq_mn; last by rewrite -modzDmr eq_mn modzDmr.
by rewrite -(addKr p m) -modzDmr eq_mn modzDmr addKr.
Qed.
Lemma eqz_modDr p m n d : (m + p == n + p %[mod d])%Z = (m == n %[mod d])%Z.
Proof. by rewrite -!(addrC p) eqz_modDl. Qed.
Lemma modzMml m n d : ((m %% d)%Z * n = m * n %[mod d])%Z.
Proof. by rewrite {2}(divz_eq m d) [in RHS]mulrDl mulrAC modzMDl. Qed. (* FIXME: rewrite pattern *)
Lemma modzMmr m n d : (m * (n %% d)%Z = m * n %[mod d])%Z.
Proof. by rewrite !(mulrC m) modzMml. Qed.
Lemma modzMm m n d : ((m %% d)%Z * (n %% d)%Z = m * n %[mod d])%Z.
Proof. by rewrite modzMml modzMmr. Qed.
Lemma modzXm k m d : ((m %% d)%Z ^+ k = m ^+ k %[mod d])%Z.
Proof. by elim: k => // k IHk; rewrite !exprS -modzMmr IHk modzMm. Qed.
Lemma modzNm m d : (- (m %% d)%Z = - m %[mod d])%Z.
Proof. by rewrite -mulN1r modzMmr mulN1r. Qed.
Lemma modz_absm m d : ((-1) ^+ (m < 0)%R * (m %% d)%Z = `|m|%:Z %[mod d])%Z.
Proof. by rewrite modzMmr -abszEsign. Qed.
(** Divisibility **)
Lemma dvdzE d m : (d %| m)%Z = (`|d| %| `|m|)%N. Proof. by []. Qed.
Lemma dvdz0 d : (d %| 0)%Z. Proof. exact: dvdn0. Qed.
Lemma dvd0z n : (0 %| n)%Z = (n == 0). Proof. by rewrite -absz_eq0 -dvd0n. Qed.
Lemma dvdz1 d : (d %| 1)%Z = (`|d|%N == 1). Proof. exact: dvdn1. Qed.
Lemma dvd1z m : (1 %| m)%Z. Proof. exact: dvd1n. Qed.
Lemma dvdzz m : (m %| m)%Z. Proof. exact: dvdnn. Qed.
Lemma dvdz_mull d m n : (d %| n)%Z -> (d %| m * n)%Z.
Proof. by rewrite !dvdzE abszM; apply: dvdn_mull. Qed.
Lemma dvdz_mulr d m n : (d %| m)%Z -> (d %| m * n)%Z.
Proof. by move=> d_m; rewrite mulrC dvdz_mull. Qed.
#[global] Hint Resolve dvdz0 dvd1z dvdzz dvdz_mull dvdz_mulr : core.
Lemma dvdz_mul d1 d2 m1 m2 : (d1 %| m1 -> d2 %| m2 -> d1 * d2 %| m1 * m2)%Z.
Proof. by rewrite !dvdzE !abszM; apply: dvdn_mul. Qed.
Lemma dvdz_trans n d m : (d %| n -> n %| m -> d %| m)%Z.
Proof. by rewrite !dvdzE; apply: dvdn_trans. Qed.
Lemma dvdzP d m : reflect (exists q, m = q * d) (d %| m)%Z.
Proof.
apply: (iffP dvdnP) => [] [q Dm]; last by exists `|q|%N; rewrite Dm abszM.
exists ((-1) ^+ (m < 0)%R * q%:Z * (-1) ^+ (d < 0)%R).
by rewrite -!mulrA -abszEsign -PoszM -Dm -intEsign.
Qed.
Arguments dvdzP {d m}.
Lemma dvdz_mod0P d m : reflect (m %% d = 0)%Z (d %| m)%Z.
Proof.
apply: (iffP dvdzP) => [[q ->] | md0]; first by rewrite modzMl.
by rewrite (divz_eq m d) md0 addr0; exists (m %/ d)%Z.
Qed.
Arguments dvdz_mod0P {d m}.
Lemma dvdz_eq d m : (d %| m)%Z = ((m %/ d)%Z * d == m).
Proof. by rewrite (sameP dvdz_mod0P eqP) subr_eq0 eq_sym. Qed.
Lemma divzK d m : (d %| m)%Z -> (m %/ d)%Z * d = m.
Proof. by rewrite dvdz_eq => /eqP. Qed.
Lemma lez_divLR d m n : 0 < d -> (d %| m)%Z -> ((m %/ d)%Z <= n) = (m <= n * d).
Proof. by move=> /ler_pM2r <- /divzK->. Qed.
Lemma ltz_divRL d m n : 0 < d -> (d %| m)%Z -> (n < m %/ d)%Z = (n * d < m).
Proof. by move=> /ltr_pM2r/(_ n)<- /divzK->. Qed.
Lemma eqz_div d m n : d != 0 -> (d %| m)%Z -> (n == m %/ d)%Z = (n * d == m).
Proof. by move=> /mulIf/inj_eq <- /divzK->. Qed.
Lemma eqz_mul d m n : d != 0 -> (d %| m)%Z -> (m == n * d) = (m %/ d == n)%Z.
Proof. by move=> d_gt0 dv_d_m; rewrite eq_sym -eqz_div // eq_sym. Qed.
Lemma divz_mulAC d m n : (d %| m)%Z -> (m %/ d)%Z * n = (m * n %/ d)%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !divz0 mul0r.
by move/divzK=> {2} <-; rewrite mulrAC mulzK.
Qed.
Lemma mulz_divA d m n : (d %| n)%Z -> m * (n %/ d)%Z = (m * n %/ d)%Z.
Proof. by move=> dv_d_m; rewrite !(mulrC m) divz_mulAC. Qed.
Lemma mulz_divCA d m n :
(d %| m)%Z -> (d %| n)%Z -> m * (n %/ d)%Z = n * (m %/ d)%Z.
Proof. by move=> dv_d_m dv_d_n; rewrite mulrC divz_mulAC ?mulz_divA. Qed.
Lemma divzA m n p : (p %| n -> n %| m * p -> m %/ (n %/ p)%Z = m * p %/ n)%Z.
Proof.
move/divzK=> p_dv_n; have [->|] := eqVneq n 0; first by rewrite div0z !divz0.
rewrite -{1 2}p_dv_n mulf_eq0 => /norP[pn_nz p_nz] /divzK; rewrite mulrA p_dv_n.
by move/mulIf=> {1} <- //; rewrite mulzK.
Qed.
Lemma divzMA m n p : (n * p %| m -> m %/ (n * p) = (m %/ n)%Z %/ p)%Z.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 !divz0.
have [-> | nz_n] := eqVneq n 0; first by rewrite mul0r !divz0 div0z.
by move/divzK=> {2} <-; rewrite mulrA mulrAC !mulzK.
Qed.
Lemma divzAC m n p : (n * p %| m -> (m %/ n)%Z %/ p = (m %/ p)%Z %/ n)%Z.
Proof. by move=> np_dv_mn; rewrite -!divzMA // mulrC. Qed.
Lemma divzMl p m d : p != 0 -> (d %| m -> p * m %/ (p * d) = m %/ d)%Z.
Proof.
have [-> | nz_d nz_p] := eqVneq d 0; first by rewrite mulr0 !divz0.
by move/divzK=> {1}<-; rewrite mulrCA mulzK ?mulf_neq0.
Qed.
Lemma divzMr p m d : p != 0 -> (d %| m -> m * p %/ (d * p) = m %/ d)%Z.
Proof. by rewrite -!(mulrC p); apply: divzMl. Qed.
Lemma dvdz_mul2l p d m : p != 0 -> (p * d %| p * m)%Z = (d %| m)%Z.
Proof. by rewrite !dvdzE -absz_gt0 !abszM; apply: dvdn_pmul2l. Qed.
Arguments dvdz_mul2l [p d m].
Lemma dvdz_mul2r p d m : p != 0 -> (d * p %| m * p)%Z = (d %| m)%Z.
Proof. by rewrite !dvdzE -absz_gt0 !abszM; apply: dvdn_pmul2r. Qed.
Arguments dvdz_mul2r [p d m].
Lemma dvdz_exp2l p m n : (m <= n)%N -> (p ^+ m %| p ^+ n)%Z.
Proof. by rewrite dvdzE !abszX; apply: dvdn_exp2l. Qed.
Lemma dvdz_Pexp2l p m n : `|p| > 1 -> (p ^+ m %| p ^+ n)%Z = (m <= n)%N.
Proof. by rewrite dvdzE !abszX ltz_nat; apply: dvdn_Pexp2l. Qed.
Lemma dvdz_exp2r m n k : (m %| n -> m ^+ k %| n ^+ k)%Z.
Proof. by rewrite !dvdzE !abszX; apply: dvdn_exp2r. Qed.
Fact dvdz_zmod_closed d : zmod_closed (dvdz d).
Proof.
split=> [|_ _ /dvdzP[p ->] /dvdzP[q ->]]; first exact: dvdz0.
by rewrite -mulrBl dvdz_mull.
Qed.
HB.instance Definition _ d := GRing.isZmodClosed.Build int (dvdz d)
(dvdz_zmod_closed d).
Lemma dvdz_exp k d m : (0 < k)%N -> (d %| m -> d %| m ^+ k)%Z.
Proof. by case: k => // k _ d_dv_m; rewrite exprS dvdz_mulr. Qed.
Lemma eqz_mod_dvd d m n : (m == n %[mod d])%Z = (d %| m - n)%Z.
Proof.
apply/eqP/dvdz_mod0P=> eq_mn.
by rewrite -modzDml eq_mn modzDml subrr mod0z.
by rewrite -(subrK n m) -modzDml eq_mn add0r.
Qed.
Lemma divzDl m n d :
(d %| m)%Z -> ((m + n) %/ d)%Z = (m %/ d)%Z + (n %/ d)%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !divz0.
by move/divzK=> {1}<-; rewrite divzMDl.
Qed.
Lemma divzDr m n d :
(d %| n)%Z -> ((m + n) %/ d)%Z = (m %/ d)%Z + (n %/ d)%Z.
Proof. by move=> dv_n; rewrite addrC divzDl // addrC. Qed.
Lemma dvdz_pcharf (R : nzRingType) p : p \in [pchar R] ->
forall n : int, (p %| n)%Z = (n%:~R == 0 :> R).
Proof.
move=> pcharRp [] n; rewrite [LHS](dvdn_pcharf pcharRp)//.
by rewrite NegzE abszN rmorphN// oppr_eq0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use dvdz_pcharf instead.")]
Notation dvdz_charf chRp := (dvdz_pcharf chRp).
(* Greatest common divisor *)
Lemma gcdzz m : gcdz m m = `|m|%:Z. Proof. by rewrite /gcdz gcdnn. Qed.
Lemma gcdzC : commutative gcdz. Proof. by move=> m n; rewrite /gcdz gcdnC. Qed.
Lemma gcd0z m : gcdz 0 m = `|m|%:Z. Proof. by rewrite /gcdz gcd0n. Qed.
Lemma gcdz0 m : gcdz m 0 = `|m|%:Z. Proof. by rewrite /gcdz gcdn0. Qed.
Lemma gcd1z : left_zero 1 gcdz. Proof. by move=> m; rewrite /gcdz gcd1n. Qed.
Lemma gcdz1 : right_zero 1 gcdz. Proof. by move=> m; rewrite /gcdz gcdn1. Qed.
Lemma dvdz_gcdr m n : (gcdz m n %| n)%Z. Proof. exact: dvdn_gcdr. Qed.
Lemma dvdz_gcdl m n : (gcdz m n %| m)%Z. Proof. exact: dvdn_gcdl. Qed.
Lemma gcdz_eq0 m n : (gcdz m n == 0) = (m == 0) && (n == 0).
Proof. by rewrite -absz_eq0 eqn0Ngt gcdn_gt0 !negb_or -!eqn0Ngt !absz_eq0. Qed.
Lemma gcdNz m n : gcdz (- m) n = gcdz m n. Proof. by rewrite /gcdz abszN. Qed.
Lemma gcdzN m n : gcdz m (- n) = gcdz m n. Proof. by rewrite /gcdz abszN. Qed.
Lemma gcdz_modr m n : gcdz m (n %% m)%Z = gcdz m n.
Proof.
rewrite -modz_abs /gcdz; move/absz: m => m.
have [-> | m_gt0] := posnP m; first by rewrite modz0.
case: n => n; first by rewrite modz_nat gcdn_modr.
rewrite modNz_nat // NegzE abszN {2}(divn_eq n m) -addnS gcdnMDl.
rewrite -addrA -opprD -intS /=; set m1 := _.+1.
have le_m1m: (m1 <= m)%N by apply: ltn_pmod.
by rewrite subzn // !(gcdnC m) -{2 3}(subnK le_m1m) gcdnDl gcdnDr gcdnC.
Qed.
Lemma gcdz_modl m n : gcdz (m %% n)%Z n = gcdz m n.
Proof. by rewrite -!(gcdzC n) gcdz_modr. Qed.
Lemma gcdzMDl q m n : gcdz m (q * m + n) = gcdz m n.
Proof. by rewrite -gcdz_modr modzMDl gcdz_modr. Qed.
Lemma gcdzDl m n : gcdz m (m + n) = gcdz m n.
Proof. by rewrite -{2}(mul1r m) gcdzMDl. Qed.
Lemma gcdzDr m n : gcdz m (n + m) = gcdz m n.
Proof. by rewrite addrC gcdzDl. Qed.
Lemma gcdzMl n m : gcdz n (m * n) = `|n|%:Z.
Proof. by rewrite -[m * n]addr0 gcdzMDl gcdz0. Qed.
Lemma gcdzMr n m : gcdz n (n * m) = `|n|%:Z.
Proof. by rewrite mulrC gcdzMl. Qed.
Lemma gcdz_idPl {m n} : reflect (gcdz m n = `|m|%:Z) (m %| n)%Z.
Proof. by apply: (iffP gcdn_idPl) => [<- | []]. Qed.
Lemma gcdz_idPr {m n} : reflect (gcdz m n = `|n|%:Z) (n %| m)%Z.
Proof. by rewrite gcdzC; apply: gcdz_idPl. Qed.
Lemma expz_min e m n : e >= 0 -> e ^+ minn m n = gcdz (e ^+ m) (e ^+ n).
Proof.
by case: e => // e _; rewrite /gcdz !abszX -expn_min -natz -natrX !natz.
Qed.
Lemma dvdz_gcd p m n : (p %| gcdz m n)%Z = (p %| m)%Z && (p %| n)%Z.
Proof. exact: dvdn_gcd. Qed.
Lemma gcdzAC : right_commutative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnAC. Qed.
Lemma gcdzA : associative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnA. Qed.
Lemma gcdzCA : left_commutative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnCA. Qed.
Lemma gcdzACA : interchange gcdz gcdz.
Proof. by move=> m n p q; rewrite /gcdz gcdnACA. Qed.
Lemma mulz_gcdr m n p : `|m|%:Z * gcdz n p = gcdz (m * n) (m * p).
Proof. by rewrite -PoszM muln_gcdr -!abszM. Qed.
Lemma mulz_gcdl m n p : gcdz m n * `|p|%:Z = gcdz (m * p) (n * p).
Proof. by rewrite -PoszM muln_gcdl -!abszM. Qed.
Lemma mulz_divCA_gcd n m : n * (m %/ gcdz n m)%Z = m * (n %/ gcdz n m)%Z.
Proof. by rewrite mulz_divCA ?dvdz_gcdl ?dvdz_gcdr. Qed.
(* Least common multiple *)
Lemma dvdz_lcmr m n : (n %| lcmz m n)%Z.
Proof. exact: dvdn_lcmr. Qed.
Lemma dvdz_lcml m n : (m %| lcmz m n)%Z.
Proof. exact: dvdn_lcml. Qed.
Lemma dvdz_lcm d1 d2 m : ((lcmn d1 d2 %| m) = (d1 %| m) && (d2 %| m))%Z.
Proof. exact: dvdn_lcm. Qed.
Lemma lcmzC : commutative lcmz.
Proof. by move=> m n; rewrite /lcmz lcmnC. Qed.
Lemma lcm0z : left_zero 0 lcmz.
Proof. by move=> x; rewrite /lcmz absz0 lcm0n. Qed.
Lemma lcmz0 : right_zero 0 lcmz.
Proof. by move=> x; rewrite /lcmz absz0 lcmn0. Qed.
Lemma lcmz_ge0 m n : 0 <= lcmz m n.
Proof. by []. Qed.
Lemma lcmz_neq0 m n : (lcmz m n != 0) = (m != 0) && (n != 0).
Proof.
have [->|m_neq0] := eqVneq m 0; first by rewrite lcm0z.
have [->|n_neq0] := eqVneq n 0; first by rewrite lcmz0.
by rewrite gt_eqF// [0 < _]lcmn_gt0 !absz_gt0 m_neq0 n_neq0.
Qed.
(* Coprime factors *)
Lemma coprimezE m n : coprimez m n = coprime `|m| `|n|. Proof. by []. Qed.
Lemma coprimez_sym : symmetric coprimez.
Proof. by move=> m n; apply: coprime_sym. Qed.
Lemma coprimeNz m n : coprimez (- m) n = coprimez m n.
Proof. by rewrite coprimezE abszN. Qed.
Lemma coprimezN m n : coprimez m (- n) = coprimez m n.
Proof. by rewrite coprimezE abszN. Qed.
Variant egcdz_spec m n : int * int -> Type :=
EgcdzSpec u v of u * m + v * n = gcdz m n & coprimez u v
: egcdz_spec m n (u, v).
Lemma egcdzP m n : egcdz_spec m n (egcdz m n).
Proof.
rewrite /egcdz; have [-> | m_nz] := eqVneq.
by split; [rewrite -abszEsign gcd0z | rewrite coprimezE absz_sign].
have m_gt0 : (`|m| > 0)%N by rewrite absz_gt0.
case: egcdnP (coprime_egcdn `|n| m_gt0) => //= u v Duv _ co_uv; split.
rewrite !mulNr -!mulrA mulrCA -abszEsg mulrCA -abszEsign.
by rewrite -!PoszM Duv addnC PoszD addrK.
by rewrite coprimezE abszM absz_sg m_nz mul1n mulNr abszN abszMsign.
Qed.
Lemma Bezoutz m n : {u : int & {v : int | u * m + v * n = gcdz m n}}.
Proof. by exists (egcdz m n).1, (egcdz m n).2; case: egcdzP. Qed.
Lemma coprimezP m n :
reflect (exists uv, uv.1 * m + uv.2 * n = 1) (coprimez m n).
Proof.
apply: (iffP eqP) => [<-| [[u v] /= Duv]].
by exists (egcdz m n); case: egcdzP.
congr _%:Z; apply: gcdn_def; rewrite ?dvd1n // => d dv_d_n dv_d_m.
by rewrite -(dvdzE d 1) -Duv [m]intEsg [n]intEsg rpredD ?dvdz_mull.
Qed.
Lemma Gauss_dvdz m n p :
coprimez m n -> (m * n %| p)%Z = (m %| p)%Z && (n %| p)%Z.
Proof. by move/Gauss_dvd <-; rewrite -abszM. Qed.
Lemma Gauss_dvdzr m n p : coprimez m n -> (m %| n * p)%Z = (m %| p)%Z.
Proof. by rewrite dvdzE abszM => /Gauss_dvdr->. Qed.
Lemma Gauss_dvdzl m n p : coprimez m p -> (m %| n * p)%Z = (m %| n)%Z.
Proof. by rewrite mulrC; apply: Gauss_dvdzr. Qed.
Lemma Gauss_gcdzr p m n : coprimez p m -> gcdz p (m * n) = gcdz p n.
Proof. by rewrite /gcdz abszM => /Gauss_gcdr->. Qed.
Lemma Gauss_gcdzl p m n : coprimez p n -> gcdz p (m * n) = gcdz p m.
Proof. by move=> co_pn; rewrite mulrC Gauss_gcdzr. Qed.
Lemma coprimezMr p m n : coprimez p (m * n) = coprimez p m && coprimez p n.
Proof. by rewrite -coprimeMr -abszM. Qed.
Lemma coprimezMl p m n : coprimez (m * n) p = coprimez m p && coprimez n p.
Proof. by rewrite -coprimeMl -abszM. Qed.
Lemma coprimez_pexpl k m n : (0 < k)%N -> coprimez (m ^+ k) n = coprimez m n.
Proof. by rewrite /coprimez /gcdz abszX; apply: coprime_pexpl. Qed.
Lemma coprimez_pexpr k m n : (0 < k)%N -> coprimez m (n ^+ k) = coprimez m n.
Proof. by move=> k_gt0; rewrite !(coprimez_sym m) coprimez_pexpl. Qed.
Lemma coprimezXl k m n : coprimez m n -> coprimez (m ^+ k) n.
Proof. by rewrite /coprimez /gcdz abszX; apply: coprimeXl. Qed.
Lemma coprimezXr k m n : coprimez m n -> coprimez m (n ^+ k).
Proof. by rewrite !(coprimez_sym m); apply: coprimezXl. Qed.
Lemma coprimez_dvdl m n p : (m %| n)%N -> coprimez n p -> coprimez m p.
Proof. exact: coprime_dvdl. Qed.
Lemma coprimez_dvdr m n p : (m %| n)%N -> coprimez p n -> coprimez p m.
Proof. exact: coprime_dvdr. Qed.
Lemma dvdz_pexp2r m n k : (k > 0)%N -> (m ^+ k %| n ^+ k)%Z = (m %| n)%Z.
Proof. by rewrite dvdzE !abszX; apply: dvdn_pexp2r. Qed.
Section Chinese.
(***********************************************************************)
(* The chinese remainder theorem *)
(***********************************************************************)
Variables m1 m2 : int.
Hypothesis co_m12 : coprimez m1 m2.
Lemma zchinese_remainder x y :
(x == y %[mod m1 * m2])%Z = (x == y %[mod m1])%Z && (x == y %[mod m2])%Z.
Proof. by rewrite !eqz_mod_dvd Gauss_dvdz. Qed.
(***********************************************************************)
(* A function that solves the chinese remainder problem *)
(***********************************************************************)
Definition zchinese r1 r2 :=
r1 * m2 * (egcdz m1 m2).2 + r2 * m1 * (egcdz m1 m2).1.
Lemma zchinese_modl r1 r2 : (zchinese r1 r2 = r1 %[mod m1])%Z.
Proof.
rewrite /zchinese; have [u v /= Duv _] := egcdzP m1 m2.
rewrite -{2}[r1]mulr1 -((gcdz _ _ =P 1) co_m12) -Duv.
by rewrite mulrDr mulrAC addrC (mulrAC r2) !mulrA !modzMDl.
Qed.
Lemma zchinese_modr r1 r2 : (zchinese r1 r2 = r2 %[mod m2])%Z.
Proof.
rewrite /zchinese; have [u v /= Duv _] := egcdzP m1 m2.
rewrite -{2}[r2]mulr1 -((gcdz _ _ =P 1) co_m12) -Duv.
by rewrite mulrAC modzMDl mulrAC addrC mulrDr !mulrA modzMDl.
Qed.
Lemma zchinese_mod x : (x = zchinese (x %% m1)%Z (x %% m2)%Z %[mod m1 * m2])%Z.
Proof.
apply/eqP; rewrite zchinese_remainder //.
by rewrite zchinese_modl zchinese_modr !modz_mod !eqxx.
Qed.
End Chinese.
Section ZpolyScale.
Definition zcontents (p : {poly int}) : int :=
sgz (lead_coef p) * \big[gcdn/0]_(i < size p) `|(p`_i)%R|%N.
Lemma sgz_contents p : sgz (zcontents p) = sgz (lead_coef p).
Proof.
rewrite /zcontents mulrC sgzM sgz_id; set d := _%:Z.
have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 mulr0.
rewrite gtr0_sgz ?mul1r // ltz_nat polySpred ?big_ord_recr //= -lead_coefE.
by rewrite gcdn_gt0 orbC absz_gt0 lead_coef_eq0 nz_p.
Qed.
Lemma zcontents_eq0 p : (zcontents p == 0) = (p == 0).
Proof. by rewrite -sgz_eq0 sgz_contents sgz_eq0 lead_coef_eq0. Qed.
Lemma zcontents0 : zcontents 0 = 0.
Proof. by apply/eqP; rewrite zcontents_eq0. Qed.
Lemma zcontentsZ a p : zcontents (a *: p) = a * zcontents p.
Proof.
have [-> | nz_a] := eqVneq a 0; first by rewrite scale0r mul0r zcontents0.
rewrite {2}[a]intEsg mulrCA -mulrA -PoszM big_distrr /= mulrCA mulrA -sgzM.
rewrite -lead_coefZ; congr (_ * _%:Z); rewrite size_scale //.
by apply: eq_bigr => i _; rewrite coefZ abszM.
Qed.
Lemma zcontents_monic p : p \is monic -> zcontents p = 1.
Proof.
move=> mon_p; rewrite /zcontents polySpred ?monic_neq0 //.
by rewrite big_ord_recr /= -lead_coefE (monicP mon_p) gcdn1.
Qed.
Lemma dvdz_contents a p : (a %| zcontents p)%Z = (p \is a polyOver (dvdz a)).
Proof.
rewrite dvdzE abszM absz_sg lead_coef_eq0.
have [-> | nz_p] := eqVneq; first by rewrite mul0n dvdn0 rpred0.
rewrite mul1n; apply/dvdn_biggcdP/(all_nthP 0)=> a_dv_p i ltip /=.
exact: (a_dv_p (Ordinal ltip)).
exact: a_dv_p.
Qed.
Lemma map_poly_divzK {a} p :
p \is a polyOver (dvdz a) -> a *: map_poly (divz^~ a) p = p.
Proof.
move/polyOverP=> a_dv_p; apply/polyP=> i.
by rewrite coefZ coef_map_id0 ?div0z // mulrC divzK.
Qed.
Lemma polyOver_dvdzP a p :
reflect (exists q, p = a *: q) (p \is a polyOver (dvdz a)).
Proof.
apply: (iffP idP) => [/map_poly_divzK | [q ->]].
by exists (map_poly (divz^~ a) p).
by apply/polyOverP=> i; rewrite coefZ dvdz_mulr.
Qed.
Definition zprimitive p := map_poly (divz^~ (zcontents p)) p.
Lemma zpolyEprim p : p = zcontents p *: zprimitive p.
Proof. by rewrite map_poly_divzK // -dvdz_contents. Qed.
Lemma zprimitive0 : zprimitive 0 = 0.
Proof.
by apply/polyP=> i; rewrite coef0 coef_map_id0 ?div0z // zcontents0 divz0.
Qed.
Lemma zprimitive_eq0 p : (zprimitive p == 0) = (p == 0).
Proof.
apply/idP/idP=> /eqP p0; first by rewrite [p]zpolyEprim p0 scaler0.
by rewrite p0 zprimitive0.
Qed.
Lemma size_zprimitive p : size (zprimitive p) = size p.
Proof.
have [-> | ] := eqVneq p 0; first by rewrite zprimitive0.
by rewrite {1 3}[p]zpolyEprim scale_poly_eq0 => /norP[/size_scale-> _].
Qed.
Lemma sgz_lead_primitive p : sgz (lead_coef (zprimitive p)) = (p != 0).
Proof.
have [-> | nz_p] := eqVneq; first by rewrite zprimitive0 lead_coef0.
apply: (@mulfI _ (sgz (zcontents p))); first by rewrite sgz_eq0 zcontents_eq0.
by rewrite -sgzM mulr1 -lead_coefZ -zpolyEprim sgz_contents.
Qed.
Lemma zcontents_primitive p : zcontents (zprimitive p) = (p != 0).
Proof.
have [-> | nz_p] := eqVneq; first by rewrite zprimitive0 zcontents0.
apply: (@mulfI _ (zcontents p)); first by rewrite zcontents_eq0.
by rewrite mulr1 -zcontentsZ -zpolyEprim.
Qed.
Lemma zprimitive_id p : zprimitive (zprimitive p) = zprimitive p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !zprimitive0.
by rewrite {2}[zprimitive p]zpolyEprim zcontents_primitive nz_p scale1r.
Qed.
Lemma zprimitive_monic p : p \in monic -> zprimitive p = p.
Proof. by move=> mon_p; rewrite {2}[p]zpolyEprim zcontents_monic ?scale1r. Qed.
Lemma zprimitiveZ a p : a != 0 -> zprimitive (a *: p) = zprimitive p.
Proof.
have [-> | nz_p nz_a] := eqVneq p 0; first by rewrite scaler0.
apply: (@mulfI _ (a * zcontents p)%:P).
by rewrite polyC_eq0 mulf_neq0 ?zcontents_eq0.
by rewrite -{1}zcontentsZ !mul_polyC -zpolyEprim -scalerA -zpolyEprim.
Qed.
Lemma zprimitive_min p a q :
p != 0 -> p = a *: q ->
{b | sgz b = sgz (lead_coef q) & q = b *: zprimitive p}.
Proof.
move=> nz_p Dp; have /dvdzP/sig_eqW[b Db]: (a %| zcontents p)%Z.
by rewrite dvdz_contents; apply/polyOver_dvdzP; exists q.
suffices ->: q = b *: zprimitive p.
by rewrite lead_coefZ sgzM sgz_lead_primitive nz_p mulr1; exists b.
apply: (@mulfI _ a%:P).
by apply: contraNneq nz_p; rewrite Dp -mul_polyC => ->; rewrite mul0r.
by rewrite !mul_polyC -Dp scalerA mulrC -Db -zpolyEprim.
Qed.
Lemma zprimitive_irr p a q :
p != 0 -> zprimitive p = a *: q -> a = sgz (lead_coef q).
Proof.
move=> nz_p Dp; have: p = (a * zcontents p) *: q.
by rewrite mulrC -scalerA -Dp -zpolyEprim.
case/zprimitive_min=> // b <- /eqP.
rewrite Dp -{1}[q]scale1r scalerA -subr_eq0 -scalerBl scale_poly_eq0 subr_eq0.
have{Dp} /negPf->: q != 0.
by apply: contraNneq nz_p; rewrite -zprimitive_eq0 Dp => ->; rewrite scaler0.
by case: b a => [[|[|b]] | [|b]] [[|[|a]] | [|a]] //; rewrite mulr0.
Qed.
Lemma zcontentsM p q : zcontents (p * q) = zcontents p * zcontents q.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, zcontents0).
have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, zcontents0).
rewrite -[zcontents q]mulr1 {1}[p]zpolyEprim {1}[q]zpolyEprim.
rewrite -scalerAl -scalerAr !zcontentsZ; congr (_ * (_ * _)).
rewrite [zcontents _]intEsg sgz_contents lead_coefM sgzM !sgz_lead_primitive.
apply/eqP; rewrite nz_p nz_q !mul1r [_ == _]eqn_leq absz_gt0 zcontents_eq0.
rewrite mulf_neq0 ?zprimitive_eq0 // andbT leqNgt.
apply/negP=> /pdivP[r r_pr r_dv_d]; pose to_r : int -> 'F_r := intr.
have nz_prim_r q1: q1 != 0 -> map_poly to_r (zprimitive q1) != 0.
move=> nz_q1; apply: contraTneq (prime_gt1 r_pr) => r_dv_q1.
rewrite -leqNgt dvdn_leq // -(dvdzE r true) -nz_q1 -zcontents_primitive.
rewrite dvdz_contents; apply/polyOverP=> i /=; rewrite dvdzE /=.
have /polyP/(_ i)/eqP := r_dv_q1; rewrite coef_map coef0 /=.
rewrite {1}[_`_i]intEsign rmorphM /= rmorph_sign /= mulf_eq0 signr_eq0 /=.
by rewrite -val_eqE /= val_Fp_nat.
suffices{nz_prim_r} /idPn[]: map_poly to_r (zprimitive p * zprimitive q) == 0.
by rewrite rmorphM mulf_neq0 ?nz_prim_r.
rewrite [_ * _]zpolyEprim [zcontents _]intEsign mulrC -scalerA map_polyZ /=.
by rewrite scale_poly_eq0 -val_eqE /= val_Fp_nat ?(eqnP r_dv_d).
Qed.
Lemma zprimitiveM p q : zprimitive (p * q) = zprimitive p * zprimitive q.
Proof.
have [pq_0|] := eqVneq (p * q) 0.
rewrite pq_0; move/eqP: pq_0; rewrite mulf_eq0.
by case/pred2P=> ->; rewrite !zprimitive0 (mul0r, mulr0).
rewrite -zcontents_eq0 -polyC_eq0 => /mulfI; apply; rewrite !mul_polyC.
by rewrite -zpolyEprim zcontentsM -scalerA scalerAr scalerAl -!zpolyEprim.
Qed.
Lemma dvdpP_int p q : p %| q -> {r | q = zprimitive p * r}.
Proof.
case/Pdiv.Idomain.dvdpP/sig2_eqW=> [[c r] /= nz_c Dpr].
exists (zcontents q *: zprimitive r); rewrite -scalerAr.
by rewrite -zprimitiveM mulrC -Dpr zprimitiveZ // -zpolyEprim.
Qed.
End ZpolyScale.
(* Integral spans. *)
Lemma int_Smith_normal_form m n (M : 'M[int]_(m, n)) :
{L : 'M[int]_m & L \in unitmx &
{R : 'M[int]_n & R \in unitmx &
{d : seq int | sorted dvdz d &
M = L *m (\matrix_(i, j) (d`_i *+ (i == j :> nat))) *m R}}}.
Proof.
move: {2}_.+1 (ltnSn (m + n)) => mn.
elim: mn => // mn IHmn in m n M *; rewrite ltnS => le_mn.
have [[i j] nzMij | no_ij] := pickP (fun k => M k.1 k.2 != 0); last first.
do 2![exists 1%:M; first exact: unitmx1]; exists nil => //=.
apply/matrixP=> i j; apply/eqP; rewrite mulmx1 mul1mx mxE nth_nil mul0rn.
exact: negbFE (no_ij (i, j)).
do [case: m i => [[]//|m] i; case: n j => [[]//|n] j /=] in M nzMij le_mn *.
wlog Dj: j M nzMij / j = 0; last rewrite {j}Dj in nzMij.
case/(_ 0 (xcol j 0 M)); rewrite ?mxE ?tpermR // => L uL [R uR [d dvD dM]].
exists L => //; exists (xcol j 0 R); last exists d => //=.
by rewrite xcolE unitmx_mul uR unitmx_perm.
by rewrite xcolE !mulmxA -dM xcolE -mulmxA -perm_mxM tperm2 perm_mx1 mulmx1.
move Da: (M i 0) nzMij => a nz_a.
have [A leA] := ubnP `|a|; elim: A => // A IHa in a leA m n M i Da nz_a le_mn *.
wlog [j a'Mij]: m n M i Da le_mn / {j | ~~ (a %| M i j)%Z}; last first.
have nz_j: j != 0 by apply: contraNneq a'Mij => ->; rewrite Da.
case: n => [[[]//]|n] in j le_mn nz_j M a'Mij Da *.
wlog{nz_j} Dj: j M a'Mij Da / j = 1; last rewrite {j}Dj in a'Mij.
case/(_ 1 (xcol j 1 M)); rewrite ?mxE ?tpermR ?tpermD //.
move=> L uL [R uR [d dvD dM]]; exists L => //.
exists (xcol j 1 R); first by rewrite xcolE unitmx_mul uR unitmx_perm.
exists d; rewrite //= xcolE !mulmxA -dM xcolE -mulmxA -perm_mxM tperm2.
by rewrite perm_mx1 mulmx1.
have [u [v]] := Bezoutz a (M i 1); set b := gcdz _ _ => Db.
have{leA} ltA: (`|b| < A)%N.
rewrite -ltnS (leq_trans _ leA) // ltnS ltn_neqAle andbC.
rewrite dvdn_leq ?absz_gt0 ? dvdn_gcdl //=.
by rewrite (contraNneq _ a'Mij) ?dvdzE // => <-; apply: dvdn_gcdr.
pose t2 := [fun j : 'I_2 => [tuple _; _]`_j : int]; pose a1 := M i 1.
pose Uul := \matrix_(k, j) t2 (t2 u (- (a1 %/ b)%Z) j) (t2 v (a %/ b)%Z j) k.
pose U : 'M_(2 + n) := block_mx Uul 0 0 1%:M; pose M1 := M *m U.
have{nz_a} nz_b: b != 0 by rewrite gcdz_eq0 (negPf nz_a).
have uU: U \in unitmx.
rewrite unitmxE det_ublock det1 (expand_det_col _ 0) big_ord_recl big_ord1.
do 2!rewrite /cofactor [row' _ _]mx11_scalar !mxE det_scalar1 /=.
rewrite mulr1 mul1r mulN1r opprK -[_ + _](mulzK _ nz_b) mulrDl.
by rewrite -!mulrA !divzK ?dvdz_gcdl ?dvdz_gcdr // Db divzz nz_b unitr1.
have{} Db: M1 i 0 = b.
rewrite /M1 -(lshift0 n 1) [U]block_mxEh mul_mx_row row_mxEl.
rewrite -[M](@hsubmxK _ _ 2) (@mul_row_col _ _ 2) mulmx0 addr0 !mxE /=.
rewrite big_ord_recl big_ord1 !mxE /= [lshift _ _]((_ =P 0) _) // Da.
by rewrite [lshift _ _]((_ =P 1) _) // mulrC -(mulrC v).
have [L uL [R uR [d dvD dM1]]] := IHa b ltA _ _ M1 i Db nz_b le_mn.
exists L => //; exists (R *m invmx U); last exists d => //.
by rewrite unitmx_mul uR unitmx_inv.
by rewrite mulmxA -dM1 mulmxK.
move=> {A leA}IHa; wlog Di: i M Da / i = 0; last rewrite {i}Di in Da.
case/(_ 0 (xrow i 0 M)); rewrite ?mxE ?tpermR // => L uL [R uR [d dvD dM]].
exists (xrow i 0 L); first by rewrite xrowE unitmx_mul unitmx_perm.
exists R => //; exists d; rewrite //= xrowE -!mulmxA (mulmxA L) -dM xrowE.
by rewrite mulmxA -perm_mxM tperm2 perm_mx1 mul1mx.
without loss /forallP a_dvM0: / [forall j, a %| M 0%R j]%Z.
case: (altP forallP) => [_ IH|/forallPn/sigW/IHa IH _]; exact: IH.
without loss{Da a_dvM0} Da: M / forall j, M 0 j = a.
pose Uur := col' 0 (\row_j (1 - (M 0%R j %/ a)%Z)).
pose U : 'M_(1 + n) := block_mx 1 Uur 0 1%:M; pose M1 := M *m U.
have uU: U \in unitmx by rewrite unitmxE det_ublock !det1 mulr1.
case/(_ (M *m U)) => [j | L uL [R uR [d dvD dM]]].
rewrite -(lshift0 m 0) -[M](@submxK _ 1 _ 1) (@mulmx_block _ 1 m 1).
rewrite (@col_mxEu _ 1) !mulmx1 mulmx0 addr0 [ulsubmx _]mx11_scalar.
rewrite mul_scalar_mx !mxE !lshift0 Da.
case: splitP => [j0 _ | j1 Dj]; rewrite ?ord1 !mxE // lshift0 rshift1.
by rewrite mulrBr mulr1 mulrC divzK ?subrK.
exists L => //; exists (R * U^-1); first by rewrite unitmx_mul uR unitmx_inv.
by exists d; rewrite //= mulmxA -dM mulmxK.
without loss{IHa} /forallP/(_ (_, _))/= a_dvM: / [forall k, a %| M k.1 k.2]%Z.
case: (altP forallP) => [_|/forallPn/sigW [[i j] /= a'Mij] _]; first exact.
have [|||L uL [R uR [d dvD dM]]] := IHa _ _ M^T j; rewrite ?mxE 1?addnC //.
by exists i; rewrite mxE.
exists R^T; last exists L^T; rewrite ?unitmx_tr //; exists d => //.
rewrite -[M]trmxK dM !trmx_mul mulmxA; congr (_ *m _ *m _).
by apply/matrixP=> i1 j1 /[!mxE]; case: eqVneq => // ->.
without loss{nz_a a_dvM} a1: M a Da / a = 1.
pose M1 := map_mx (divz^~ a) M; case/(_ M1 1)=> // [k|L uL [R uR [d dvD dM]]].
by rewrite !mxE Da divzz nz_a.
exists L => //; exists R => //; exists [seq a * x | x <- d].
case: d dvD {dM} => //= x d; elim: d x => //= y d IHd x /andP[dv_xy /IHd].
by rewrite [dvdz _ _]dvdz_mul2l ?[_ \in _]dv_xy.
have ->: M = a *: M1 by apply/matrixP=> i j; rewrite !mxE mulrC divzK ?a_dvM.
rewrite dM scalemxAl scalemxAr; congr (_ *m _ *m _).
apply/matrixP=> i j; rewrite !mxE mulrnAr; congr (_ *+ _).
have [lt_i_d | le_d_i] := ltnP i (size d); first by rewrite (nth_map 0).
by rewrite !nth_default ?size_map ?mulr0.
rewrite {a}a1 -[m.+1]/(1 + m)%N -[n.+1]/(1 + n)%N in M Da *.
pose Mu := ursubmx M; pose Ml := dlsubmx M.
have{} Da: ulsubmx M = 1 by rewrite [_ M]mx11_scalar !mxE !lshift0 Da.
pose M1 := - (Ml *m Mu) + drsubmx M.
have [|L uL [R uR [d dvD dM1]]] := IHmn m n M1; first by rewrite -addnS ltnW.
exists (block_mx 1 0 Ml L).
by rewrite unitmxE det_lblock det_scalar1 mul1r.
exists (block_mx 1 Mu 0 R).
by rewrite unitmxE det_ublock det_scalar1 mul1r.
exists (1 :: d); set D1 := \matrix_(i, j) _ in dM1.
by rewrite /= path_min_sorted //; apply/allP => g _; apply: dvd1n.
rewrite [D in _ *m D *m _](_ : _ = block_mx 1 0 0 D1); last first.
by apply/matrixP=> i j; do 3?[rewrite ?mxE ?ord1 //=; case: splitP => ? ->].
rewrite !mulmx_block !(mul0mx, mulmx0, addr0) !mulmx1 add0r mul1mx -Da -dM1.
by rewrite addNKr submxK.
Qed.
|
DeltaGeneratedSpace.lean
|
/-
Copyright (c) 2024 Ben Eltschig. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ben Eltschig
-/
import Mathlib.Analysis.LocallyConvex.WithSeminorms
/-!
# Delta-generated topological spaces
This file defines delta-generated spaces, as topological spaces whose topology is coinduced by all
maps from euclidean spaces into them. This is the strongest topological property that holds for
all CW-complexes and is closed under quotients and disjoint unions; every delta-generated space is
locally path-connected, sequential and in particular compactly generated.
See https://ncatlab.org/nlab/show/Delta-generated+topological+space.
Adapted from `Mathlib/Topology/Compactness/CompactlyGeneratedSpace.lean`.
## TODO
* All locally path-connected first-countable spaces are delta-generated - in particular, all normed
spaces and convex subsets thereof, like the standard simplices and the unit interval.
* Delta-generated spaces are equivalently generated by the simplices Δⁿ.
* Delta-generated spaces are equivalently generated by the unit interval I.
-/
variable {X Y : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y]
open TopologicalSpace Topology
/-- The topology coinduced by all maps from ℝⁿ into a space. -/
def TopologicalSpace.deltaGenerated (X : Type*) [TopologicalSpace X] : TopologicalSpace X :=
⨆ f : (n : ℕ) × C(((Fin n) → ℝ), X), coinduced f.2 inferInstance
/-- The delta-generated topology is also coinduced by a single map out of a sigma type. -/
lemma deltaGenerated_eq_coinduced : deltaGenerated X = coinduced
(fun x : (f : (n : ℕ) × C(Fin n → ℝ, X)) × (Fin f.1 → ℝ) ↦ x.1.2 x.2) inferInstance := by
rw [deltaGenerated, instTopologicalSpaceSigma, coinduced_iSup]; rfl
/-- The delta-generated topology is at least as fine as the original one. -/
lemma deltaGenerated_le : deltaGenerated X ≤ tX :=
iSup_le_iff.mpr fun f ↦ f.2.continuous.coinduced_le
/-- A set is open in `deltaGenerated X` iff all its preimages under continuous functions ℝⁿ → X are
open. -/
lemma isOpen_deltaGenerated_iff {u : Set X} :
IsOpen[deltaGenerated X] u ↔ ∀ n (p : C(Fin n → ℝ, X)), IsOpen (p ⁻¹' u) := by
simp_rw [deltaGenerated, isOpen_iSup_iff, isOpen_coinduced, Sigma.forall]
/-- A map from ℝⁿ to X is continuous iff it is continuous regarding the
delta-generated topology on X. Outside of this file, use the more general
`continuous_to_deltaGenerated` instead. -/
private lemma continuous_euclidean_to_deltaGenerated {n : ℕ} {f : (Fin n → ℝ) → X} :
Continuous[_, deltaGenerated X] f ↔ Continuous f := by
simp_rw [continuous_iff_coinduced_le]
refine ⟨fun h ↦ h.trans deltaGenerated_le, fun h ↦ ?_⟩
simp_rw [deltaGenerated]
exact le_iSup_of_le (i := ⟨n, f, continuous_iff_coinduced_le.mpr h⟩) le_rfl
/-- `deltaGenerated` is idempotent as a function `TopologicalSpace X → TopologicalSpace X`. -/
lemma deltaGenerated_deltaGenerated_eq :
@deltaGenerated X (deltaGenerated X) = deltaGenerated X := by
ext u; simp_rw [isOpen_deltaGenerated_iff]; refine forall_congr' fun n ↦ ?_
-- somewhat awkward because `ContinuousMap` doesn't play well with multiple topologies.
refine ⟨fun h p ↦ h <| @ContinuousMap.mk _ _ _ (_) p ?_, fun h p ↦ h ⟨p, ?_⟩⟩
· exact continuous_euclidean_to_deltaGenerated.mpr p.2
· exact continuous_euclidean_to_deltaGenerated.mp <| @ContinuousMap.continuous_toFun _ _ _ (_) p
/-- A space is delta-generated if its topology is equal to the delta-generated topology, i.e.
coinduced by all continuous maps ℝⁿ → X. Since the delta-generated topology is always finer
than the original one, it suffices to show that it is also coarser. -/
class DeltaGeneratedSpace (X : Type*) [t : TopologicalSpace X] : Prop where
le_deltaGenerated : t ≤ deltaGenerated X
lemma eq_deltaGenerated [DeltaGeneratedSpace X] : tX = deltaGenerated X :=
eq_of_le_of_ge DeltaGeneratedSpace.le_deltaGenerated deltaGenerated_le
/-- A subset of a delta-generated space is open iff its preimage is open for every
continuous map from ℝⁿ to X. -/
lemma DeltaGeneratedSpace.isOpen_iff [DeltaGeneratedSpace X] {u : Set X} :
IsOpen u ↔ ∀ (n : ℕ) (p : ContinuousMap ((Fin n) → ℝ) X), IsOpen (p ⁻¹' u) := by
nth_rewrite 1 [eq_deltaGenerated (X := X)]; exact isOpen_deltaGenerated_iff
/-- A map out of a delta-generated space is continuous iff it preserves continuity of maps
from ℝⁿ into X. -/
lemma DeltaGeneratedSpace.continuous_iff [DeltaGeneratedSpace X] {f : X → Y} :
Continuous f ↔ ∀ (n : ℕ) (p : C(((Fin n) → ℝ), X)), Continuous (f ∘ p) := by
simp_rw [continuous_iff_coinduced_le]
nth_rewrite 1 [eq_deltaGenerated (X := X), deltaGenerated]
simp [coinduced_compose, Sigma.forall]
/-- A map out of a delta-generated space is continuous iff it is continuous with respect
to the delta-generated topology on the codomain. -/
lemma continuous_to_deltaGenerated [DeltaGeneratedSpace X] {f : X → Y} :
Continuous[_, deltaGenerated Y] f ↔ Continuous f := by
simp_rw [DeltaGeneratedSpace.continuous_iff, continuous_euclidean_to_deltaGenerated]
/-- The delta-generated topology on `X` does in fact turn `X` into a delta-generated space. -/
lemma deltaGeneratedSpace_deltaGenerated {X : Type*} {t : TopologicalSpace X} :
@DeltaGeneratedSpace X (@deltaGenerated X t) := by
let _ := @deltaGenerated X t; constructor; rw [@deltaGenerated_deltaGenerated_eq X t]
lemma deltaGenerated_mono {X : Type*} {t₁ t₂ : TopologicalSpace X} (h : t₁ ≤ t₂) :
@deltaGenerated X t₁ ≤ @deltaGenerated X t₂ := by
rw [← continuous_id_iff_le, @continuous_to_deltaGenerated _ _
(@deltaGenerated X t₁) t₂ deltaGeneratedSpace_deltaGenerated id]
exact continuous_id_iff_le.2 <| (@deltaGenerated_le X t₁).trans h
namespace DeltaGeneratedSpace
/-- Type synonym to be equipped with the delta-generated topology. -/
def of (X : Type*) := X
instance : TopologicalSpace (of X) := deltaGenerated X
instance : DeltaGeneratedSpace (of X) :=
deltaGeneratedSpace_deltaGenerated
/-- The natural map from `DeltaGeneratedSpace.of X` to `X`. -/
def counit : (of X) → X := id
lemma continuous_counit : Continuous (counit : _ → X) := by
rw [continuous_iff_coinduced_le]; exact deltaGenerated_le
/-- Delta-generated spaces are locally path-connected. -/
instance [DeltaGeneratedSpace X] : LocPathConnectedSpace X := by
rw [eq_deltaGenerated (X := X), deltaGenerated_eq_coinduced]
exact LocPathConnectedSpace.coinduced _
/-- Delta-generated spaces are sequential. -/
instance [DeltaGeneratedSpace X] : SequentialSpace X := by
rw [eq_deltaGenerated (X := X)]
exact SequentialSpace.iSup fun p ↦ SequentialSpace.coinduced p.2
end DeltaGeneratedSpace
omit tY in
/-- Any topology coinduced by a delta-generated topology is delta-generated. -/
lemma DeltaGeneratedSpace.coinduced [DeltaGeneratedSpace X] (f : X → Y) :
@DeltaGeneratedSpace Y (tX.coinduced f) :=
let _ := tX.coinduced f
⟨(continuous_to_deltaGenerated.2 continuous_coinduced_rng).coinduced_le⟩
/-- Suprema of delta-generated topologies are delta-generated. -/
protected lemma DeltaGeneratedSpace.iSup {X : Type*} {ι : Sort*} {t : ι → TopologicalSpace X}
(h : ∀ i, @DeltaGeneratedSpace X (t i)) : @DeltaGeneratedSpace X (⨆ i, t i) :=
let _ := ⨆ i, t i
⟨iSup_le_iff.2 fun i ↦ (h i).le_deltaGenerated.trans <| deltaGenerated_mono <| le_iSup t i⟩
/-- Suprema of delta-generated topologies are delta-generated. -/
protected lemma DeltaGeneratedSpace.sup {X : Type*} {t₁ t₂ : TopologicalSpace X}
(h₁ : @DeltaGeneratedSpace X t₁) (h₂ : @DeltaGeneratedSpace X t₂) :
@DeltaGeneratedSpace X (t₁ ⊔ t₂) := by
rw [sup_eq_iSup]
exact .iSup <| Bool.forall_bool.2 ⟨h₂, h₁⟩
/-- Quotients of delta-generated spaces are delta-generated. -/
lemma Topology.IsQuotientMap.deltaGeneratedSpace [DeltaGeneratedSpace X]
{f : X → Y} (h : IsQuotientMap f) : DeltaGeneratedSpace Y :=
h.2 ▸ DeltaGeneratedSpace.coinduced f
/-- Quotients of delta-generated spaces are delta-generated. -/
instance Quot.deltaGeneratedSpace [DeltaGeneratedSpace X] {r : X → X → Prop} :
DeltaGeneratedSpace (Quot r) :=
isQuotientMap_quot_mk.deltaGeneratedSpace
/-- Quotients of delta-generated spaces are delta-generated. -/
instance Quotient.deltaGeneratedSpace [DeltaGeneratedSpace X] {s : Setoid X} :
DeltaGeneratedSpace (Quotient s) :=
isQuotientMap_quotient_mk'.deltaGeneratedSpace
/-- Disjoint unions of delta-generated spaces are delta-generated. -/
instance Sum.deltaGeneratedSpace [DeltaGeneratedSpace X] [DeltaGeneratedSpace Y] :
DeltaGeneratedSpace (X ⊕ Y) :=
DeltaGeneratedSpace.sup (.coinduced Sum.inl) (.coinduced Sum.inr)
/-- Disjoint unions of delta-generated spaces are delta-generated. -/
instance Sigma.deltaGeneratedSpace {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
[∀ i, DeltaGeneratedSpace (X i)] : DeltaGeneratedSpace (Σ i, X i) :=
.iSup fun _ ↦ .coinduced _
|
Basic.lean
|
/-
Copyright (c) 2021 Henry Swanson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henry Swanson
-/
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.GroupTheory.Perm.Option
import Mathlib.Logic.Equiv.Defs
import Mathlib.Logic.Equiv.Option
import Mathlib.Tactic.ApplyFun
/-!
# Derangements on types
In this file we define `derangements α`, the set of derangements on a type `α`.
We also define some equivalences involving various subtypes of `Perm α` and `derangements α`:
* `derangementsOptionEquivSigmaAtMostOneFixedPoint`: An equivalence between
`derangements (Option α)` and the sigma-type `Σ a : α, {f : Perm α // fixed_points f ⊆ a}`.
* `derangementsRecursionEquiv`: An equivalence between `derangements (Option α)` and the
sigma-type `Σ a : α, (derangements (({a}ᶜ : Set α) : Type*) ⊕ derangements α)` which is later
used to inductively count the number of derangements.
In order to prove the above, we also prove some results about the effect of `Equiv.removeNone`
on derangements: `RemoveNone.fiber_none` and `RemoveNone.fiber_some`.
-/
open Equiv Function
/-- A permutation is a derangement if it has no fixed points. -/
def derangements (α : Type*) : Set (Perm α) :=
{ f : Perm α | ∀ x : α, f x ≠ x }
variable {α β : Type*}
theorem mem_derangements_iff_fixedPoints_eq_empty {f : Perm α} :
f ∈ derangements α ↔ fixedPoints f = ∅ :=
Set.eq_empty_iff_forall_notMem.symm
/-- If `α` is equivalent to `β`, then `derangements α` is equivalent to `derangements β`. -/
def Equiv.derangementsCongr (e : α ≃ β) : derangements α ≃ derangements β :=
e.permCongr.subtypeEquiv fun {f} => e.forall_congr <| by
intro b; simp only [ne_eq, permCongr_apply, symm_apply_apply, EmbeddingLike.apply_eq_iff_eq]
namespace derangements
/-- Derangements on a subtype are equivalent to permutations on the original type where points are
fixed iff they are not in the subtype. -/
protected def subtypeEquiv (p : α → Prop) [DecidablePred p] :
derangements (Subtype p) ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } :=
calc
derangements (Subtype p) ≃ { f : { f : Perm α // ∀ a, ¬p a → a ∈ fixedPoints f } //
∀ a, a ∈ fixedPoints f → ¬p a } := by
refine (Perm.subtypeEquivSubtypePerm p).subtypeEquiv fun f => ⟨fun hf a hfa ha => ?_, ?_⟩
· refine hf ⟨a, ha⟩ (Subtype.ext ?_)
simp_rw [mem_fixedPoints, IsFixedPt, Perm.subtypeEquivSubtypePerm,
Equiv.coe_fn_mk, Perm.ofSubtype_apply_of_mem _ ha] at hfa
assumption
rintro hf ⟨a, ha⟩ hfa
refine hf _ ?_ ha
simp only [Perm.subtypeEquivSubtypePerm_apply_coe, mem_fixedPoints]
dsimp [IsFixedPt]
simp_rw [Perm.ofSubtype_apply_of_mem _ ha, hfa]
_ ≃ { f : Perm α // ∃ _h : ∀ a, ¬p a → a ∈ fixedPoints f, ∀ a, a ∈ fixedPoints f → ¬p a } :=
subtypeSubtypeEquivSubtypeExists _ _
_ ≃ { f : Perm α // ∀ a, ¬p a ↔ a ∈ fixedPoints f } :=
subtypeEquivRight fun f => by
simp_rw [exists_prop, ← forall_and, ← iff_iff_implies_and_implies]
universe u
/-- The set of permutations that fix either `a` or nothing is equivalent to the sum of:
- derangements on `α`
- derangements on `α` minus `a`. -/
def atMostOneFixedPointEquivSum_derangements [DecidableEq α] (a : α) :
{ f : Perm α // fixedPoints f ⊆ {a} } ≃ (derangements ({a}ᶜ : Set α)) ⊕ (derangements α) :=
calc
{ f : Perm α // fixedPoints f ⊆ {a} } ≃
{ f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∈ fixedPoints f } ⊕
{ f : { f : Perm α // fixedPoints f ⊆ {a} } // a ∉ fixedPoints f } :=
(Equiv.sumCompl _).symm
_ ≃ { f : Perm α // fixedPoints f ⊆ {a} ∧ a ∈ fixedPoints f } ⊕
{ f : Perm α // fixedPoints f ⊆ {a} ∧ a ∉ fixedPoints f } := by
-- Porting note: `subtypeSubtypeEquivSubtypeInter` no longer works with placeholder `_`s.
refine Equiv.sumCongr ?_ ?_
· exact subtypeSubtypeEquivSubtypeInter
(fun x : Perm α => fixedPoints x ⊆ {a})
(a ∈ fixedPoints ·)
· exact subtypeSubtypeEquivSubtypeInter
(fun x : Perm α => fixedPoints x ⊆ {a})
(a ∉ fixedPoints ·)
_ ≃ { f : Perm α // fixedPoints f = {a} } ⊕ { f : Perm α // fixedPoints f = ∅ } := by
refine Equiv.sumCongr (subtypeEquivRight fun f => ?_) (subtypeEquivRight fun f => ?_)
· rw [Set.eq_singleton_iff_unique_mem, and_comm]
rfl
· rw [Set.eq_empty_iff_forall_notMem]
exact ⟨fun h x hx => h.2 (h.1 hx ▸ hx), fun h => ⟨fun x hx => (h _ hx).elim, h _⟩⟩
_ ≃ derangements ({a}ᶜ : Set α) ⊕ derangements α := by
refine
Equiv.sumCongr ((derangements.subtypeEquiv _).trans <|
subtypeEquivRight fun x => ?_).symm
(subtypeEquivRight fun f => mem_derangements_iff_fixedPoints_eq_empty.symm)
rw [eq_comm, Set.ext_iff]
simp_rw [Set.mem_compl_iff, Classical.not_not]
namespace Equiv
variable [DecidableEq α]
/-- The set of permutations `f` such that the preimage of `(a, f)` under
`Equiv.Perm.decomposeOption` is a derangement. -/
def RemoveNone.fiber (a : Option α) : Set (Perm α) :=
{ f : Perm α | (a, f) ∈ Equiv.Perm.decomposeOption '' derangements (Option α) }
theorem RemoveNone.mem_fiber (a : Option α) (f : Perm α) :
f ∈ RemoveNone.fiber a ↔
∃ F : Perm (Option α), F ∈ derangements (Option α) ∧ F none = a ∧ removeNone F = f := by
simp [RemoveNone.fiber, derangements]
theorem RemoveNone.fiber_none : RemoveNone.fiber (@none α) = ∅ := by
rw [Set.eq_empty_iff_forall_notMem]
intro f hyp
rw [RemoveNone.mem_fiber] at hyp
rcases hyp with ⟨F, F_derangement, F_none, _⟩
exact F_derangement none F_none
/-- For any `a : α`, the fiber over `some a` is the set of permutations
where `a` is the only possible fixed point. -/
theorem RemoveNone.fiber_some (a : α) :
RemoveNone.fiber (some a) = { f : Perm α | fixedPoints f ⊆ {a} } := by
ext f
constructor
· rw [RemoveNone.mem_fiber]
rintro ⟨F, F_derangement, F_none, rfl⟩ x x_fixed
rw [mem_fixedPoints_iff] at x_fixed
apply_fun some at x_fixed
rcases Fx : F (some x) with - | y
· rwa [removeNone_none F Fx, F_none, Option.some_inj, eq_comm] at x_fixed
· exfalso
rw [removeNone_some F ⟨y, Fx⟩] at x_fixed
exact F_derangement _ x_fixed
· intro h_opfp
use Equiv.Perm.decomposeOption.symm (some a, f)
constructor
· intro x
apply_fun fun x => Equiv.swap none (some a) x
simp only [Perm.decomposeOption_symm_apply, Perm.coe_mul]
rcases x with - | x
· simp
simp only [comp, optionCongr_apply, Option.map_some, swap_apply_self]
by_cases x_vs_a : x = a
· rw [x_vs_a, swap_apply_right]
apply Option.some_ne_none
have ne_1 : some x ≠ none := Option.some_ne_none _
have ne_2 : some x ≠ some a := (Option.some_injective α).ne_iff.mpr x_vs_a
rw [swap_apply_of_ne_of_ne ne_1 ne_2, (Option.some_injective α).ne_iff]
intro contra
exact x_vs_a (h_opfp contra)
· rw [apply_symm_apply]
end Equiv
section Option
variable [DecidableEq α]
/-- The set of derangements on `Option α` is equivalent to the union over `a : α`
of "permutations with `a` the only possible fixed point". -/
def derangementsOptionEquivSigmaAtMostOneFixedPoint :
derangements (Option α) ≃ Σ a : α, { f : Perm α | fixedPoints f ⊆ {a} } := by
have fiber_none_is_false : Equiv.RemoveNone.fiber (@none α) → False := by
rw [Equiv.RemoveNone.fiber_none]
exact IsEmpty.false
calc
derangements (Option α) ≃ Equiv.Perm.decomposeOption '' derangements (Option α) :=
Equiv.image _ _
_ ≃ Σ a : Option α, ↥(Equiv.RemoveNone.fiber a) := setProdEquivSigma _
_ ≃ Σ a : α, ↥(Equiv.RemoveNone.fiber (some a)) :=
sigmaOptionEquivOfSome _ fiber_none_is_false
_ ≃ Σ a : α, { f : Perm α | fixedPoints f ⊆ {a} } := by
simp_rw [Equiv.RemoveNone.fiber_some]
rfl
/-- The set of derangements on `Option α` is equivalent to the union over all `a : α` of
"derangements on `α` ⊕ derangements on `{a}ᶜ`". -/
def derangementsRecursionEquiv :
derangements (Option α) ≃
Σ a : α, derangements (({a}ᶜ : Set α) : Type _) ⊕ derangements α :=
derangementsOptionEquivSigmaAtMostOneFixedPoint.trans
(sigmaCongrRight atMostOneFixedPointEquivSum_derangements)
end Option
end derangements
|
Units.lean
|
/-
Copyright (c) 2021 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.Faithful
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Units.Defs
/-! # Group actions on and by `Mˣ`
This file provides the action of a unit on a type `α`, `SMul Mˣ α`, in the presence of
`SMul M α`, with the obvious definition stated in `Units.smul_def`. This definition preserves
`MulAction` and `DistribMulAction` structures too.
Additionally, a `MulAction G M` for some group `G` satisfying some additional properties admits a
`MulAction G Mˣ` structure, again with the obvious definition stated in `Units.coe_smul`.
These instances use a primed name.
The results are repeated for `AddUnits` and `VAdd` where relevant.
-/
assert_not_exists MonoidWithZero
variable {G H M N α : Type*}
namespace Units
@[to_additive] instance [Monoid M] [SMul M α] : SMul Mˣ α where smul m a := (m : M) • a
@[to_additive] lemma smul_def [Monoid M] [SMul M α] (m : Mˣ) (a : α) : m • a = (m : M) • a := rfl
@[to_additive, simp]
lemma smul_mk_apply {M α : Type*} [Monoid M] [SMul M α] (m n : M) (h₁) (h₂) (a : α) :
(⟨m, n, h₁, h₂⟩ : Mˣ) • a = m • a := rfl
@[simp]
lemma smul_isUnit [Monoid M] [SMul M α] {m : M} (hm : IsUnit m) (a : α) : hm.unit • a = m • a := rfl
@[to_additive]
lemma _root_.IsUnit.inv_smul [Monoid α] {a : α} (h : IsUnit a) : h.unit⁻¹ • a = 1 := h.val_inv_mul
@[to_additive]
instance [Monoid M] [SMul M α] [FaithfulSMul M α] : FaithfulSMul Mˣ α where
eq_of_smul_eq_smul h := Units.ext <| eq_of_smul_eq_smul h
@[to_additive]
instance instMulAction [Monoid M] [MulAction M α] : MulAction Mˣ α where
one_smul := one_smul M
mul_smul m n := mul_smul (m : M) n
@[to_additive]
instance smulCommClass_left [Monoid M] [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass Mˣ N α where smul_comm m n := smul_comm (m : M) n
@[to_additive]
instance smulCommClass_right [Monoid N] [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass M Nˣ α where smul_comm m n := smul_comm m (n : N)
@[to_additive]
instance [Monoid M] [SMul M N] [SMul M α] [SMul N α] [IsScalarTower M N α] :
IsScalarTower Mˣ N α where smul_assoc m n := smul_assoc (m : M) n
/-! ### Action of a group `G` on units of `M` -/
/-- If an action `G` associates and commutes with multiplication on `M`, then it lifts to an
action on `Mˣ`. Notably, this provides `MulAction Mˣ Nˣ` under suitable conditions. -/
@[to_additive]
instance mulAction' [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M]
[IsScalarTower G M M] : MulAction G Mˣ where
smul g m :=
⟨g • (m : M), (g⁻¹ • ((m⁻¹ : Mˣ) : M)),
by rw [smul_mul_smul_comm, Units.mul_inv, mul_inv_cancel, one_smul],
by rw [smul_mul_smul_comm, Units.inv_mul, inv_mul_cancel, one_smul]⟩
one_smul _ := Units.ext <| one_smul _ _
mul_smul _ _ _ := Units.ext <| mul_smul _ _ _
/-- This is not the usual `smul_eq_mul` because `mulAction'` creates a diamond.
Discussed [on Zulip](https://leanprover.zulipchat.com/#narrow/channel/113488-general/topic/units.2Emul_action'.20diamond/near/246400399). -/
@[simp]
lemma smul_eq_mul {M} [CommMonoid M] (u₁ u₂ : Mˣ) :
u₁ • u₂ = u₁ * u₂ := by
fail_if_success rfl -- there is an instance diamond here
ext
rfl
@[to_additive (attr := simp)]
lemma val_smul [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
(g : G) (m : Mˣ) : ↑(g • m) = g • (m : M) := rfl
/-- Note that this lemma exists more generally as the global `smul_inv` -/
@[to_additive (attr := simp)]
lemma smul_inv [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
(g : G) (m : Mˣ) : (g • m)⁻¹ = g⁻¹ • m⁻¹ := ext rfl
/-- Transfer `SMulCommClass G H M` to `SMulCommClass G H Mˣ`. -/
@[to_additive /-- Transfer `VAddCommClass G H M` to `VAddCommClass G H (AddUnits M)`. -/]
instance smulCommClass' [Group G] [Group H] [Monoid M] [MulAction G M] [SMulCommClass G M M]
[MulAction H M] [SMulCommClass H M M] [IsScalarTower G M M] [IsScalarTower H M M]
[SMulCommClass G H M] :
SMulCommClass G H Mˣ where smul_comm g h m := Units.ext <| smul_comm g h (m : M)
/-- Transfer `IsScalarTower G H M` to `IsScalarTower G H Mˣ`. -/
@[to_additive /-- Transfer `VAddAssocClass G H M` to `VAddAssocClass G H (AddUnits M)`. -/]
instance isScalarTower' [SMul G H] [Group G] [Group H] [Monoid M] [MulAction G M]
[SMulCommClass G M M] [MulAction H M] [SMulCommClass H M M] [IsScalarTower G M M]
[IsScalarTower H M M] [IsScalarTower G H M] :
IsScalarTower G H Mˣ where smul_assoc g h m := Units.ext <| smul_assoc g h (m : M)
/-- Transfer `IsScalarTower G M α` to `IsScalarTower G Mˣ α`. -/
@[to_additive /-- Transfer `VAddAssocClass G M α` to `VAddAssocClass G (AddUnits M) α`. -/]
instance isScalarTower'_left [Group G] [Monoid M] [MulAction G M] [SMul M α] [SMul G α]
[SMulCommClass G M M] [IsScalarTower G M M] [IsScalarTower G M α] :
IsScalarTower G Mˣ α where smul_assoc g m := smul_assoc g (m : M)
-- Just to prove this transfers a particularly useful instance.
example [Monoid M] [Monoid N] [MulAction M N] [SMulCommClass M N N] [IsScalarTower M N N] :
MulAction Mˣ Nˣ := Units.mulAction'
end Units
@[to_additive]
lemma IsUnit.smul [Group G] [Monoid M] [MulAction G M] [SMulCommClass G M M] [IsScalarTower G M M]
{m : M} (g : G) (h : IsUnit m) : IsUnit (g • m) :=
let ⟨u, hu⟩ := h
hu ▸ ⟨g • u, Units.val_smul _ _⟩
|
Group.lean
|
import Mathlib.Tactic.Group
variable {G : Type} [Group G]
example (a b c : G) : c*(a*b)*(b⁻¹*a⁻¹)*c = c*c := by group
example (a b c : G) : (b*c⁻¹)*c*(a*b)*(b⁻¹*a⁻¹)*c = b*c := by group
example (a b c : G) : c⁻¹*(b*c⁻¹)*c*(a*b)*(b⁻¹*a⁻¹*b⁻¹)*c = 1 := by group
-- The following is known as the Hall-Witt identity,
-- see e.g.
-- https://en.wikipedia.org/wiki/Three_subgroups_lemma#Proof_and_the_Hall%E2%80%93Witt_identity
example (g h k : G) : g*⁅⁅g⁻¹,h⁆,k⁆*g⁻¹*k*⁅⁅k⁻¹,g⁆,h⁆*k⁻¹*h*⁅⁅h⁻¹,k⁆,g⁆*h⁻¹ = 1 := by group
example (a : G) : a^2*a = a^3 := by group
example (n m : ℕ) (a : G) : a^n*a^m = a^(n+m) := by group
example (a b c : G) : c*(a*b^2)*((b*b)⁻¹*a⁻¹)*c = c*c := by group
example (n : ℕ) (a : G) : a^n*(a⁻¹)^n = 1 := by group
example (a : G) : a^2*a⁻¹*a⁻¹ = 1 := by group
example (n m : ℕ) (a : G) : a^n*a^m = a^(m+n) := by group
example (n : ℕ) (a : G) : a^(n-n) = 1 := by group
example (n : ℤ) (a : G) : a^(n-n) = 1 := by group
example (n : ℤ) (a : G) (h : a ^ (n * (n + 1) - n - n ^ 2) = a) : a = 1 := by
group at h
exact h.symm
example (a b c d : G) (h : c = (a * b ^ 2) * ((b * b)⁻¹ * a⁻¹) * d) : a*c*d⁻¹ = a := by
group at h
rw [h]
group
-- The next example can be expanded to require an arbitrarily high number of alternations
-- between simp and ring
example (n m : ℤ) (a b : G) : a^(m-n)*b^(m-n)*b^(n-m)*a^(n-m) = 1 := by group
example (n : ℤ) (a b : G) : a^n*b^n*a^n*a^n*a^(-n)*a^(-n)*b^(-n)*a^(-n) = 1 := by group
-- Test that group deals with `1⁻¹` properly
example (x y : G) : (x⁻¹ * (x * y) * y⁻¹)⁻¹ = 1 := by group
set_option linter.unusedTactic false in
example (x : G) (h : x = 1) : x = 1 := by
group
exact h
|
Basic.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.Data.Set.Lattice
import Mathlib.Order.ConditionallyCompleteLattice.Defs
/-!
# Theory of conditionally complete lattices
A conditionally complete lattice is a lattice in which every non-empty bounded subset `s`
has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`.
Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders.
The theory is very comparable to the theory of complete lattices, except that suitable
boundedness and nonemptiness assumptions have to be added to most statements.
We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove
most useful properties of `sSup` and `sInf` in conditionally complete lattices.
To differentiate the statements between complete lattices and conditionally complete
lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`.
For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`,
while `csInf_le` is the same statement in conditionally complete lattices
with an additional assumption that `s` is bounded below.
-/
-- Guard against import creep
assert_not_exists Multiset
open Function OrderDual Set
variable {α β γ : Type*} {ι : Sort*}
section
/-!
Extension of `sSup` and `sInf` from a preorder `α` to `WithTop α` and `WithBot α`
-/
variable [Preorder α]
open Classical in
noncomputable instance WithTop.instSupSet [SupSet α] :
SupSet (WithTop α) :=
⟨fun S =>
if ⊤ ∈ S then ⊤ else if BddAbove ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α) then
↑(sSup ((fun (a : α) ↦ (a : WithTop α)) ⁻¹' S : Set α)) else ⊤⟩
open Classical in
noncomputable instance WithTop.instInfSet [InfSet α] : InfSet (WithTop α) :=
⟨fun S => if S ⊆ {⊤} ∨ ¬BddBelow S then ⊤ else ↑(sInf ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α))⟩
noncomputable instance WithBot.instSupSet [SupSet α] : SupSet (WithBot α) :=
⟨(WithTop.instInfSet (α := αᵒᵈ)).sInf⟩
noncomputable instance WithBot.instInfSet [InfSet α] :
InfSet (WithBot α) :=
⟨(WithTop.instSupSet (α := αᵒᵈ)).sSup⟩
theorem WithTop.sSup_eq [SupSet α] {s : Set (WithTop α)} (hs : ⊤ ∉ s)
(hs' : BddAbove ((↑) ⁻¹' s : Set α)) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) :=
(if_neg hs).trans <| if_pos hs'
theorem WithTop.sInf_eq [InfSet α] {s : Set (WithTop α)} (hs : ¬s ⊆ {⊤}) (h's : BddBelow s) :
sInf s = ↑(sInf ((↑) ⁻¹' s) : α) :=
if_neg <| by simp [hs, h's]
theorem WithBot.sInf_eq [InfSet α] {s : Set (WithBot α)} (hs : ⊥ ∉ s)
(hs' : BddBelow ((↑) ⁻¹' s : Set α)) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) :=
(if_neg hs).trans <| if_pos hs'
theorem WithBot.sSup_eq [SupSet α] {s : Set (WithBot α)} (hs : ¬s ⊆ {⊥}) (h's : BddAbove s) :
sSup s = ↑(sSup ((↑) ⁻¹' s) : α) :=
WithTop.sInf_eq (α := αᵒᵈ) hs h's
@[simp]
theorem WithTop.sInf_empty [InfSet α] : sInf (∅ : Set (WithTop α)) = ⊤ :=
if_pos <| by simp
theorem WithTop.coe_sInf' [InfSet α] {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) :
↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by
classical
obtain ⟨x, hx⟩ := hs
change _ = ite _ _ _
split_ifs with h
· rcases h with h1 | h2
· cases h1 (mem_image_of_mem _ hx)
· exact (h2 (Monotone.map_bddBelow coe_mono h's)).elim
· rw [preimage_image_eq]
exact Option.some_injective _
theorem WithTop.coe_sSup' [SupSet α] {s : Set α} (hs : BddAbove s) :
↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by
classical
change _ = ite _ _ _
rw [if_neg, preimage_image_eq, if_pos hs]
· exact Option.some_injective _
· rintro ⟨x, _, ⟨⟩⟩
@[simp]
theorem WithBot.sSup_empty [SupSet α] : sSup (∅ : Set (WithBot α)) = ⊥ :=
WithTop.sInf_empty (α := αᵒᵈ)
@[norm_cast]
theorem WithBot.coe_sSup' [SupSet α] {s : Set α} (hs : s.Nonempty) (h's : BddAbove s) :
↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithBot α) :=
WithTop.coe_sInf' (α := αᵒᵈ) hs h's
@[norm_cast]
theorem WithBot.coe_sInf' [InfSet α] {s : Set α} (hs : BddBelow s) :
↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithBot α) :=
WithTop.coe_sSup' (α := αᵒᵈ) hs
end
instance ConditionallyCompleteLinearOrder.toLinearOrder [ConditionallyCompleteLinearOrder α] :
LinearOrder α :=
{ ‹ConditionallyCompleteLinearOrder α› with
min_def := fun a b ↦ by
by_cases hab : a = b
· simp [hab]
· rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂)
· simp [h₁]
· simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂]
max_def := fun a b ↦ by
by_cases hab : a = b
· simp [hab]
· rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂)
· simp [h₁]
· simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] }
-- see Note [lower instance priority]
attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot
-- see Note [lower instance priority]
/-- A complete lattice is a conditionally complete lattice, as there are no restrictions
on the properties of sInf and sSup in a complete lattice. -/
instance (priority := 100) CompleteLattice.toConditionallyCompleteLattice [CompleteLattice α] :
ConditionallyCompleteLattice α :=
{ ‹CompleteLattice α› with
le_csSup := by intros; apply le_sSup; assumption
csSup_le := by intros; apply sSup_le; assumption
csInf_le := by intros; apply sInf_le; assumption
le_csInf := by intros; apply le_sInf; assumption }
-- see Note [lower instance priority]
instance (priority := 100) CompleteLinearOrder.toConditionallyCompleteLinearOrderBot {α : Type*}
[h : CompleteLinearOrder α] : ConditionallyCompleteLinearOrderBot α :=
{ CompleteLattice.toConditionallyCompleteLattice, h with
csSup_empty := sSup_empty
csSup_of_not_bddAbove := fun s H ↦ (H (OrderTop.bddAbove s)).elim
csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim }
namespace OrderDual
instance instConditionallyCompleteLattice (α : Type*) [ConditionallyCompleteLattice α] :
ConditionallyCompleteLattice αᵒᵈ :=
{ OrderDual.instInf α, OrderDual.instSup α, OrderDual.instLattice α with
le_csSup := ConditionallyCompleteLattice.csInf_le (α := α)
csSup_le := ConditionallyCompleteLattice.le_csInf (α := α)
le_csInf := ConditionallyCompleteLattice.csSup_le (α := α)
csInf_le := ConditionallyCompleteLattice.le_csSup (α := α) }
instance (α : Type*) [ConditionallyCompleteLinearOrder α] : ConditionallyCompleteLinearOrder αᵒᵈ :=
{ OrderDual.instConditionallyCompleteLattice α, OrderDual.instLinearOrder α with
csSup_of_not_bddAbove := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow (α := α)
csInf_of_not_bddBelow := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove (α := α) }
end OrderDual
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] {s t : Set α} {a b : α}
theorem le_csSup (h₁ : BddAbove s) (h₂ : a ∈ s) : a ≤ sSup s :=
ConditionallyCompleteLattice.le_csSup s a h₁ h₂
theorem csSup_le (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, b ≤ a) : sSup s ≤ a :=
ConditionallyCompleteLattice.csSup_le s a h₁ h₂
theorem csInf_le (h₁ : BddBelow s) (h₂ : a ∈ s) : sInf s ≤ a :=
ConditionallyCompleteLattice.csInf_le s a h₁ h₂
theorem le_csInf (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, a ≤ b) : a ≤ sInf s :=
ConditionallyCompleteLattice.le_csInf s a h₁ h₂
theorem le_csSup_of_le (hs : BddAbove s) (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s :=
le_trans h (le_csSup hs hb)
theorem csInf_le_of_le (hs : BddBelow s) (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a :=
le_trans (csInf_le hs hb) h
@[gcongr low]
theorem csSup_le_csSup (ht : BddAbove t) (hs : s.Nonempty) (h : s ⊆ t) : sSup s ≤ sSup t :=
csSup_le hs fun _ ha => le_csSup ht (h ha)
@[gcongr low]
theorem csInf_le_csInf (ht : BddBelow t) (hs : s.Nonempty) (h : s ⊆ t) : sInf t ≤ sInf s :=
le_csInf hs fun _ ha => csInf_le ht (h ha)
theorem le_csSup_iff (h : BddAbove s) (hs : s.Nonempty) :
a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b :=
⟨fun h _ hb => le_trans h (csSup_le hs hb), fun hb => hb _ fun _ => le_csSup h⟩
theorem csInf_le_iff (h : BddBelow s) (hs : s.Nonempty) : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a :=
⟨fun h _ hb => le_trans (le_csInf hs hb) h, fun hb => hb _ fun _ => csInf_le h⟩
theorem isLUB_csSup (ne : s.Nonempty) (H : BddAbove s) : IsLUB s (sSup s) :=
⟨fun _ => le_csSup H, fun _ => csSup_le ne⟩
theorem isGLB_csInf (ne : s.Nonempty) (H : BddBelow s) : IsGLB s (sInf s) :=
⟨fun _ => csInf_le H, fun _ => le_csInf ne⟩
theorem IsLUB.csSup_eq (H : IsLUB s a) (ne : s.Nonempty) : sSup s = a :=
(isLUB_csSup ne ⟨a, H.1⟩).unique H
/-- A greatest element of a set is the supremum of this set. -/
theorem IsGreatest.csSup_eq (H : IsGreatest s a) : sSup s = a :=
H.isLUB.csSup_eq H.nonempty
theorem IsGreatest.csSup_mem (H : IsGreatest s a) : sSup s ∈ s :=
H.csSup_eq.symm ▸ H.1
theorem IsGLB.csInf_eq (H : IsGLB s a) (ne : s.Nonempty) : sInf s = a :=
(isGLB_csInf ne ⟨a, H.1⟩).unique H
/-- A least element of a set is the infimum of this set. -/
theorem IsLeast.csInf_eq (H : IsLeast s a) : sInf s = a :=
H.isGLB.csInf_eq H.nonempty
theorem IsLeast.csInf_mem (H : IsLeast s a) : sInf s ∈ s :=
H.csInf_eq.symm ▸ H.1
theorem subset_Icc_csInf_csSup (hb : BddBelow s) (ha : BddAbove s) : s ⊆ Icc (sInf s) (sSup s) :=
fun _ hx => ⟨csInf_le hb hx, le_csSup ha hx⟩
theorem csSup_le_iff (hb : BddAbove s) (hs : s.Nonempty) : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a :=
isLUB_le_iff (isLUB_csSup hs hb)
theorem le_csInf_iff (hb : BddBelow s) (hs : s.Nonempty) : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b :=
le_isGLB_iff (isGLB_csInf hs hb)
theorem csSup_lowerBounds_eq_csInf {s : Set α} (h : BddBelow s) (hs : s.Nonempty) :
sSup (lowerBounds s) = sInf s :=
(isLUB_csSup h <| hs.mono fun _ hx _ hy => hy hx).unique (isGLB_csInf hs h).isLUB
theorem csInf_upperBounds_eq_csSup {s : Set α} (h : BddAbove s) (hs : s.Nonempty) :
sInf (upperBounds s) = sSup s :=
(isGLB_csInf h <| hs.mono fun _ hx _ hy => hy hx).unique (isLUB_csSup hs h).isGLB
theorem csSup_lowerBounds_range [Nonempty β] {f : β → α} (hf : BddBelow (range f)) :
sSup (lowerBounds (range f)) = ⨅ i, f i :=
csSup_lowerBounds_eq_csInf hf <| range_nonempty _
theorem csInf_upperBounds_range [Nonempty β] {f : β → α} (hf : BddAbove (range f)) :
sInf (upperBounds (range f)) = ⨆ i, f i :=
csInf_upperBounds_eq_csSup hf <| range_nonempty _
theorem notMem_of_lt_csInf {x : α} {s : Set α} (h : x < sInf s) (hs : BddBelow s) : x ∉ s :=
fun hx => lt_irrefl _ (h.trans_le (csInf_le hs hx))
@[deprecated (since := "2025-05-23")] alias not_mem_of_lt_csInf := notMem_of_lt_csInf
theorem notMem_of_csSup_lt {x : α} {s : Set α} (h : sSup s < x) (hs : BddAbove s) : x ∉ s :=
notMem_of_lt_csInf (α := αᵒᵈ) h hs
@[deprecated (since := "2025-05-23")] alias not_mem_of_csSup_lt := notMem_of_csSup_lt
/-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b`
is larger than all elements of `s`, and that this is not the case of any `w<b`.
See `sSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/
theorem csSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.Nonempty) (H : ∀ a ∈ s, a ≤ b)
(H' : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b :=
(eq_of_le_of_not_lt (csSup_le hs H)) fun hb =>
let ⟨_, ha, ha'⟩ := H' _ hb
lt_irrefl _ <| ha'.trans_le <| le_csSup ⟨b, H⟩ ha
/-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b`
is smaller than all elements of `s`, and that this is not the case of any `w>b`.
See `sInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/
theorem csInf_eq_of_forall_ge_of_forall_gt_exists_lt :
s.Nonempty → (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b :=
csSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ)
/-- `b < sSup s` when there is an element `a` in `s` with `b < a`, when `s` is bounded above.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness above for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the `CompleteLattice` case. -/
theorem lt_csSup_of_lt (hs : BddAbove s) (ha : a ∈ s) (h : b < a) : b < sSup s :=
lt_of_lt_of_le h (le_csSup hs ha)
/-- `sInf s < b` when there is an element `a` in `s` with `a < b`, when `s` is bounded below.
This is essentially an iff, except that the assumptions for the two implications are
slightly different (one needs boundedness below for one direction, nonemptiness and linear
order for the other one), so we formulate separately the two implications, contrary to
the `CompleteLattice` case. -/
theorem csInf_lt_of_lt : BddBelow s → a ∈ s → a < b → sInf s < b :=
lt_csSup_of_lt (α := αᵒᵈ)
/-- If all elements of a nonempty set `s` are less than or equal to all elements
of a nonempty set `t`, then there exists an element between these sets. -/
theorem exists_between_of_forall_le (sne : s.Nonempty) (tne : t.Nonempty)
(hst : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : (upperBounds s ∩ lowerBounds t).Nonempty :=
⟨sInf t, fun x hx => le_csInf tne <| hst x hx, fun _ hy => csInf_le (sne.mono hst) hy⟩
/-- The supremum of a singleton is the element of the singleton -/
@[simp]
theorem csSup_singleton (a : α) : sSup {a} = a :=
isGreatest_singleton.csSup_eq
/-- The infimum of a singleton is the element of the singleton -/
@[simp]
theorem csInf_singleton (a : α) : sInf {a} = a :=
isLeast_singleton.csInf_eq
theorem csSup_pair (a b : α) : sSup {a, b} = a ⊔ b :=
(@isLUB_pair _ _ a b).csSup_eq (insert_nonempty _ _)
theorem csInf_pair (a b : α) : sInf {a, b} = a ⊓ b :=
(@isGLB_pair _ _ a b).csInf_eq (insert_nonempty _ _)
/-- If a set is bounded below and above, and nonempty, its infimum is less than or equal to
its supremum. -/
theorem csInf_le_csSup (hb : BddBelow s) (ha : BddAbove s) (ne : s.Nonempty) : sInf s ≤ sSup s :=
isGLB_le_isLUB (isGLB_csInf ne hb) (isLUB_csSup ne ha) ne
/-- The `sSup` of a union of two sets is the max of the suprema of each subset, under the
assumptions that all sets are bounded above and nonempty. -/
theorem csSup_union (hs : BddAbove s) (sne : s.Nonempty) (ht : BddAbove t) (tne : t.Nonempty) :
sSup (s ∪ t) = sSup s ⊔ sSup t :=
((isLUB_csSup sne hs).union (isLUB_csSup tne ht)).csSup_eq sne.inl
/-- The `sInf` of a union of two sets is the min of the infima of each subset, under the assumptions
that all sets are bounded below and nonempty. -/
theorem csInf_union (hs : BddBelow s) (sne : s.Nonempty) (ht : BddBelow t) (tne : t.Nonempty) :
sInf (s ∪ t) = sInf s ⊓ sInf t :=
csSup_union (α := αᵒᵈ) hs sne ht tne
/-- The supremum of an intersection of two sets is bounded by the minimum of the suprema of each
set, if all sets are bounded above and nonempty. -/
theorem csSup_inter_le (hs : BddAbove s) (ht : BddAbove t) (hst : (s ∩ t).Nonempty) :
sSup (s ∩ t) ≤ sSup s ⊓ sSup t :=
(csSup_le hst) fun _ hx => le_inf (le_csSup hs hx.1) (le_csSup ht hx.2)
/-- The infimum of an intersection of two sets is bounded below by the maximum of the
infima of each set, if all sets are bounded below and nonempty. -/
theorem le_csInf_inter :
BddBelow s → BddBelow t → (s ∩ t).Nonempty → sInf s ⊔ sInf t ≤ sInf (s ∩ t) :=
csSup_inter_le (α := αᵒᵈ)
/-- The supremum of `insert a s` is the maximum of `a` and the supremum of `s`, if `s` is
nonempty and bounded above. -/
@[simp]
theorem csSup_insert (hs : BddAbove s) (sne : s.Nonempty) : sSup (insert a s) = a ⊔ sSup s :=
((isLUB_csSup sne hs).insert a).csSup_eq (insert_nonempty a s)
/-- The infimum of `insert a s` is the minimum of `a` and the infimum of `s`, if `s` is
nonempty and bounded below. -/
@[simp]
theorem csInf_insert (hs : BddBelow s) (sne : s.Nonempty) : sInf (insert a s) = a ⊓ sInf s :=
csSup_insert (α := αᵒᵈ) hs sne
@[simp]
theorem csInf_Icc (h : a ≤ b) : sInf (Icc a b) = a :=
(isGLB_Icc h).csInf_eq (nonempty_Icc.2 h)
@[simp]
theorem csInf_Ici : sInf (Ici a) = a :=
isLeast_Ici.csInf_eq
@[simp]
theorem csInf_Ico (h : a < b) : sInf (Ico a b) = a :=
(isGLB_Ico h).csInf_eq (nonempty_Ico.2 h)
@[simp]
theorem csInf_Ioc [DenselyOrdered α] (h : a < b) : sInf (Ioc a b) = a :=
(isGLB_Ioc h).csInf_eq (nonempty_Ioc.2 h)
@[simp]
theorem csInf_Ioi [NoMaxOrder α] [DenselyOrdered α] : sInf (Ioi a) = a :=
csInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (fun _ => le_of_lt) fun w hw => by
simpa using exists_between hw
@[simp]
theorem csInf_Ioo [DenselyOrdered α] (h : a < b) : sInf (Ioo a b) = a :=
(isGLB_Ioo h).csInf_eq (nonempty_Ioo.2 h)
@[simp]
theorem csSup_Icc (h : a ≤ b) : sSup (Icc a b) = b :=
(isLUB_Icc h).csSup_eq (nonempty_Icc.2 h)
@[simp]
theorem csSup_Ico [DenselyOrdered α] (h : a < b) : sSup (Ico a b) = b :=
(isLUB_Ico h).csSup_eq (nonempty_Ico.2 h)
@[simp]
theorem csSup_Iic : sSup (Iic a) = a :=
isGreatest_Iic.csSup_eq
@[simp]
theorem csSup_Iio [NoMinOrder α] [DenselyOrdered α] : sSup (Iio a) = a :=
csSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (fun _ => le_of_lt) fun w hw => by
simpa [and_comm] using exists_between hw
@[simp]
theorem csSup_Ioc (h : a < b) : sSup (Ioc a b) = b :=
(isLUB_Ioc h).csSup_eq (nonempty_Ioc.2 h)
@[simp]
theorem csSup_Ioo [DenselyOrdered α] (h : a < b) : sSup (Ioo a b) = b :=
(isLUB_Ioo h).csSup_eq (nonempty_Ioo.2 h)
/-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that
1) `b` is an upper bound
2) every other upper bound `b'` satisfies `b ≤ b'`. -/
theorem csSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.Nonempty) (h_is_ub : ∀ a ∈ s, a ≤ b)
(h_b_le_ub : ∀ ub, (∀ a ∈ s, a ≤ ub) → b ≤ ub) : sSup s = b :=
(csSup_le hs h_is_ub).antisymm ((h_b_le_ub _) fun _ => le_csSup ⟨b, h_is_ub⟩)
lemma sup_eq_top_of_top_mem [OrderTop α] (h : ⊤ ∈ s) : sSup s = ⊤ :=
top_unique <| le_csSup (OrderTop.bddAbove s) h
lemma inf_eq_bot_of_bot_mem [OrderBot α] (h : ⊥ ∈ s) : sInf s = ⊥ :=
bot_unique <| csInf_le (OrderBot.bddBelow s) h
end ConditionallyCompleteLattice
instance Pi.conditionallyCompleteLattice {ι : Type*} {α : ι → Type*}
[∀ i, ConditionallyCompleteLattice (α i)] : ConditionallyCompleteLattice (∀ i, α i) :=
{ Pi.instLattice, Pi.supSet, Pi.infSet with
le_csSup := fun _ f ⟨g, hg⟩ hf i =>
le_csSup ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩
csSup_le := fun s _ hs hf i =>
(csSup_le (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ =>
hb ▸ hf hg i
csInf_le := fun _ f ⟨g, hg⟩ hf i =>
csInf_le ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩
le_csInf := fun s _ hs hf i =>
(le_csInf (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ =>
hb ▸ hf hg i }
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] {f : ι → α} {s : Set α} {a b : α}
/-- When `b < sSup s`, there is an element `a` in `s` with `b < a`, if `s` is nonempty and the order
is a linear order. -/
theorem exists_lt_of_lt_csSup (hs : s.Nonempty) (hb : b < sSup s) : ∃ a ∈ s, b < a := by
contrapose! hb
exact csSup_le hs hb
/-- When `sInf s < b`, there is an element `a` in `s` with `a < b`, if `s` is nonempty and the order
is a linear order. -/
theorem exists_lt_of_csInf_lt (hs : s.Nonempty) (hb : sInf s < b) : ∃ a ∈ s, a < b :=
exists_lt_of_lt_csSup (α := αᵒᵈ) hs hb
theorem lt_csSup_iff (hb : BddAbove s) (hs : s.Nonempty) : a < sSup s ↔ ∃ b ∈ s, a < b :=
lt_isLUB_iff <| isLUB_csSup hs hb
theorem csInf_lt_iff (hb : BddBelow s) (hs : s.Nonempty) : sInf s < a ↔ ∃ b ∈ s, b < a :=
isGLB_lt_iff <| isGLB_csInf hs hb
@[simp] lemma csSup_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup ∅ :=
ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove s hs
@[simp] lemma ciSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup ∅ :=
csSup_of_not_bddAbove hf
lemma csSup_eq_univ_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup univ := by
rw [csSup_of_not_bddAbove hs, csSup_of_not_bddAbove (s := univ)]
contrapose! hs
exact hs.mono (subset_univ _)
lemma ciSup_eq_univ_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup univ :=
csSup_eq_univ_of_not_bddAbove hf
@[simp] lemma csInf_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf ∅ :=
ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow s hs
@[simp] lemma ciInf_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf ∅ :=
csInf_of_not_bddBelow hf
lemma csInf_eq_univ_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf univ :=
csSup_eq_univ_of_not_bddAbove (α := αᵒᵈ) hs
lemma ciInf_eq_univ_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf univ :=
csInf_eq_univ_of_not_bddBelow hf
/-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then
`s` and `t` have the same supremum. This holds even when the sets may be empty or unbounded. -/
theorem csSup_eq_csSup_of_forall_exists_le {s t : Set α}
(hs : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) (ht : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) :
sSup s = sSup t := by
rcases eq_empty_or_nonempty s with rfl | s_ne
· have : t = ∅ := eq_empty_of_forall_notMem (fun y yt ↦ by simpa using ht y yt)
rw [this]
rcases eq_empty_or_nonempty t with rfl | t_ne
· have : s = ∅ := eq_empty_of_forall_notMem (fun x xs ↦ by simpa using hs x xs)
rw [this]
by_cases B : BddAbove s ∨ BddAbove t
· have Bs : BddAbove s := by
rcases B with hB|⟨b, hb⟩
· exact hB
· refine ⟨b, fun x hx ↦ ?_⟩
rcases hs x hx with ⟨y, hy, hxy⟩
exact hxy.trans (hb hy)
have Bt : BddAbove t := by
rcases B with ⟨b, hb⟩|hB
· refine ⟨b, fun y hy ↦ ?_⟩
rcases ht y hy with ⟨x, hx, hyx⟩
exact hyx.trans (hb hx)
· exact hB
apply le_antisymm
· apply csSup_le s_ne (fun x hx ↦ ?_)
rcases hs x hx with ⟨y, yt, hxy⟩
exact hxy.trans (le_csSup Bt yt)
· apply csSup_le t_ne (fun y hy ↦ ?_)
rcases ht y hy with ⟨x, xs, hyx⟩
exact hyx.trans (le_csSup Bs xs)
· simp [csSup_of_not_bddAbove, (not_or.1 B).1, (not_or.1 B).2]
/-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then
`s` and `t` have the same infimum. This holds even when the sets may be empty or unbounded. -/
theorem csInf_eq_csInf_of_forall_exists_le {s t : Set α}
(hs : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) (ht : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) :
sInf s = sInf t :=
csSup_eq_csSup_of_forall_exists_le (α := αᵒᵈ) hs ht
lemma sSup_iUnion_Iic (f : ι → α) : sSup (⋃ (i : ι), Iic (f i)) = ⨆ i, f i := by
apply csSup_eq_csSup_of_forall_exists_le
· rintro x ⟨-, ⟨i, rfl⟩, hi⟩
exact ⟨f i, mem_range_self _, hi⟩
· rintro x ⟨i, rfl⟩
exact ⟨f i, mem_iUnion_of_mem i le_rfl, le_rfl⟩
lemma sInf_iUnion_Ici (f : ι → α) : sInf (⋃ (i : ι), Ici (f i)) = ⨅ i, f i :=
sSup_iUnion_Iic (α := αᵒᵈ) f
theorem csInf_eq_bot_of_bot_mem [OrderBot α] {s : Set α} (hs : ⊥ ∈ s) : sInf s = ⊥ :=
eq_bot_iff.2 <| csInf_le (OrderBot.bddBelow s) hs
theorem csSup_eq_top_of_top_mem [OrderTop α] {s : Set α} (hs : ⊤ ∈ s) : sSup s = ⊤ :=
csInf_eq_bot_of_bot_mem (α := αᵒᵈ) hs
open Function
variable [WellFoundedLT α]
theorem sInf_eq_argmin_on (hs : s.Nonempty) : sInf s = argminOn id s hs :=
IsLeast.csInf_eq ⟨argminOn_mem _ _ _, fun _ ha => argminOn_le id _ ha⟩
theorem isLeast_csInf (hs : s.Nonempty) : IsLeast s (sInf s) := by
rw [sInf_eq_argmin_on hs]
exact ⟨argminOn_mem _ _ _, fun a ha => argminOn_le id _ ha⟩
theorem le_csInf_iff' (hs : s.Nonempty) : b ≤ sInf s ↔ b ∈ lowerBounds s :=
le_isGLB_iff (isLeast_csInf hs).isGLB
theorem csInf_mem (hs : s.Nonempty) : sInf s ∈ s :=
(isLeast_csInf hs).1
theorem MonotoneOn.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β}
(hf : MonotoneOn f s) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) :=
(hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm
theorem Monotone.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β}
(hf : Monotone f) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) :=
(hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm
end ConditionallyCompleteLinearOrder
/-!
### Lemmas about a conditionally complete linear order with bottom element
In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions.
-/
section ConditionallyCompleteLinearOrderBot
@[simp]
theorem csInf_univ [ConditionallyCompleteLattice α] [OrderBot α] : sInf (univ : Set α) = ⊥ :=
isLeast_univ.csInf_eq
variable [ConditionallyCompleteLinearOrderBot α] {s : Set α} {a : α}
@[simp]
theorem csSup_empty : (sSup ∅ : α) = ⊥ :=
ConditionallyCompleteLinearOrderBot.csSup_empty
theorem isLUB_csSup' {s : Set α} (hs : BddAbove s) : IsLUB s (sSup s) := by
rcases eq_empty_or_nonempty s with (rfl | hne)
· simp only [csSup_empty, isLUB_empty]
· exact isLUB_csSup hne hs
/-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted
from `csSup_le_iff`. -/
theorem csSup_le_iff' {s : Set α} (hs : BddAbove s) {a : α} : sSup s ≤ a ↔ ∀ x ∈ s, x ≤ a :=
isLUB_le_iff (isLUB_csSup' hs)
theorem csSup_le' {s : Set α} {a : α} (h : a ∈ upperBounds s) : sSup s ≤ a :=
(csSup_le_iff' ⟨a, h⟩).2 h
/-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted
from `lt_csSup_iff`. -/
theorem lt_csSup_iff' (hb : BddAbove s) : a < sSup s ↔ ∃ b ∈ s, a < b := by
simpa only [not_le, not_forall₂, exists_prop] using (csSup_le_iff' hb).not
theorem le_csSup_iff' {s : Set α} {a : α} (h : BddAbove s) :
a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b :=
⟨fun h _ hb => le_trans h (csSup_le' hb), fun hb => hb _ fun _ => le_csSup h⟩
theorem le_csInf_iff'' {s : Set α} {a : α} (ne : s.Nonempty) :
a ≤ sInf s ↔ ∀ b : α, b ∈ s → a ≤ b :=
le_csInf_iff (OrderBot.bddBelow _) ne
theorem csInf_le' (h : a ∈ s) : sInf s ≤ a := csInf_le (OrderBot.bddBelow _) h
theorem exists_lt_of_lt_csSup' {s : Set α} {a : α} (h : a < sSup s) : ∃ b ∈ s, a < b := by
contrapose! h
exact csSup_le' h
theorem notMem_of_lt_csInf' {x : α} {s : Set α} (h : x < sInf s) : x ∉ s :=
notMem_of_lt_csInf h (OrderBot.bddBelow s)
@[deprecated (since := "2025-05-23")] alias not_mem_of_lt_csInf' := notMem_of_lt_csInf'
@[gcongr mid]
theorem csInf_le_csInf' {s t : Set α} (h₁ : t.Nonempty) (h₂ : t ⊆ s) : sInf s ≤ sInf t :=
csInf_le_csInf (OrderBot.bddBelow s) h₁ h₂
@[gcongr mid]
theorem csSup_le_csSup' {s t : Set α} (h₁ : BddAbove t) (h₂ : s ⊆ t) : sSup s ≤ sSup t := by
rcases eq_empty_or_nonempty s with rfl | h
· rw [csSup_empty]
exact bot_le
· exact csSup_le_csSup h₁ h h₂
end ConditionallyCompleteLinearOrderBot
namespace WithTop
variable [ConditionallyCompleteLinearOrderBot α]
/-- The `sSup` of a non-empty set is its least upper bound for a conditionally
complete lattice with a top. -/
theorem isLUB_sSup' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)}
(hs : s.Nonempty) : IsLUB s (sSup s) := by
classical
constructor
· change ite _ _ _ ∈ _
split_ifs with h₁ h₂
· intro _ _
exact le_top
· rintro (⟨⟩ | a) ha
· contradiction
apply coe_le_coe.2
exact le_csSup h₂ ha
· intro _ _
exact le_top
· change ite _ _ _ ∈ _
split_ifs with h₁ h₂
· rintro (⟨⟩ | a) ha
· exact le_rfl
· exact False.elim (not_top_le_coe a (ha h₁))
· rintro (⟨⟩ | b) hb
· exact le_top
refine coe_le_coe.2 (csSup_le ?_ ?_)
· rcases hs with ⟨⟨⟩ | b, hb⟩
· exact absurd hb h₁
· exact ⟨b, hb⟩
· intro a ha
exact coe_le_coe.1 (hb ha)
· rintro (⟨⟩ | b) hb
· exact le_rfl
· exfalso
apply h₂
use b
intro a ha
exact coe_le_coe.1 (hb ha)
theorem isLUB_sSup (s : Set (WithTop α)) : IsLUB s (sSup s) := by
rcases s.eq_empty_or_nonempty with rfl | hs
· simp [sSup]
· exact isLUB_sSup' hs
/-- The `sInf` of a bounded-below set is its greatest lower bound for a conditionally
complete lattice with a top. -/
theorem isGLB_sInf' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)}
(hs : BddBelow s) : IsGLB s (sInf s) := by
classical
constructor
· change ite _ _ _ ∈ _
simp only [hs, not_true_eq_false, or_false]
split_ifs with h
· intro a ha
exact top_le_iff.2 (Set.mem_singleton_iff.1 (h ha))
· rintro (⟨⟩ | a) ha
· exact le_top
refine coe_le_coe.2 (csInf_le ?_ ha)
rcases hs with ⟨⟨⟩ | b, hb⟩
· exfalso
apply h
intro c hc
rw [mem_singleton_iff, ← top_le_iff]
exact hb hc
use b
intro c hc
exact coe_le_coe.1 (hb hc)
· change ite _ _ _ ∈ _
simp only [hs, not_true_eq_false, or_false]
split_ifs with h
· intro _ _
exact le_top
· rintro (⟨⟩ | a) ha
· exfalso
apply h
intro b hb
exact Set.mem_singleton_iff.2 (top_le_iff.1 (ha hb))
· refine coe_le_coe.2 (le_csInf ?_ ?_)
· classical
contrapose! h
rintro (⟨⟩ | a) ha
· exact mem_singleton ⊤
· exact (not_nonempty_iff_eq_empty.2 h ⟨a, ha⟩).elim
· intro b hb
rw [← coe_le_coe]
exact ha hb
theorem isGLB_sInf (s : Set (WithTop α)) : IsGLB s (sInf s) := by
by_cases hs : BddBelow s
· exact isGLB_sInf' hs
· exfalso
apply hs
use ⊥
intro _ _
exact bot_le
noncomputable instance : CompleteLinearOrder (WithTop α) where
__ := linearOrder
__ := linearOrder.toBiheytingAlgebra
le_sSup s := (isLUB_sSup s).1
sSup_le s := (isLUB_sSup s).2
le_sInf s := (isGLB_sInf s).2
sInf_le s := (isGLB_sInf s).1
/-- A version of `WithTop.coe_sSup'` with a more convenient but less general statement. -/
@[norm_cast]
theorem coe_sSup {s : Set α} (hb : BddAbove s) : ↑(sSup s) = (⨆ a ∈ s, ↑a : WithTop α) := by
rw [coe_sSup' hb, sSup_image]
/-- A version of `WithTop.coe_sInf'` with a more convenient but less general statement. -/
@[norm_cast]
theorem coe_sInf {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) :
↑(sInf s) = (⨅ a ∈ s, ↑a : WithTop α) := by
rw [coe_sInf' hs h's, sInf_image]
end WithTop
namespace Monotone
variable [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} (h_mono : Monotone f)
include h_mono
/-! A monotone function into a conditionally complete lattice preserves the ordering properties of
`sSup` and `sInf`. -/
theorem le_csSup_image {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddAbove s) :
f c ≤ sSup (f '' s) :=
le_csSup (map_bddAbove h_mono h_bdd) (mem_image_of_mem f hcs)
theorem csSup_image_le {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ upperBounds s) :
sSup (f '' s) ≤ f B :=
csSup_le (Nonempty.image f hs) (h_mono.mem_upperBounds_image hB)
-- Porting note: in mathlib3 `f'` is not needed
theorem csInf_image_le {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddBelow s) :
sInf (f '' s) ≤ f c := by
let f' : αᵒᵈ → βᵒᵈ := f
exact le_csSup_image (α := αᵒᵈ) (β := βᵒᵈ)
(show Monotone f' from fun x y hxy => h_mono hxy) hcs h_bdd
-- Porting note: in mathlib3 `f'` is not needed
theorem le_csInf_image {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ lowerBounds s) :
f B ≤ sInf (f '' s) := by
let f' : αᵒᵈ → βᵒᵈ := f
exact csSup_image_le (α := αᵒᵈ) (β := βᵒᵈ)
(show Monotone f' from fun x y hxy => h_mono hxy) hs hB
end Monotone
lemma MonotoneOn.csInf_eq_of_subset_of_forall_exists_le
[Preorder α] [ConditionallyCompleteLattice β] {f : α → β}
{s t : Set α} (ht : BddBelow (f '' t)) (hf : MonotoneOn f t)
(hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) :
sInf (f '' s) = sInf (f '' t) := by
obtain rfl | hs := Set.eq_empty_or_nonempty s
· obtain rfl : t = ∅ := by simpa [Set.eq_empty_iff_forall_notMem] using h
rfl
apply le_antisymm _ (csInf_le_csInf ht (hs.image _) (image_mono hst))
refine le_csInf ((hs.mono hst).image f) ?_
simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
intro a ha
obtain ⟨x, hxs, hxa⟩ := h a ha
exact csInf_le_of_le (ht.mono (image_mono hst)) ⟨x, hxs, rfl⟩ (hf (hst hxs) ha hxa)
lemma MonotoneOn.csSup_eq_of_subset_of_forall_exists_le
[Preorder α] [ConditionallyCompleteLattice β] {f : α → β}
{s t : Set α} (ht : BddAbove (f '' t)) (hf : MonotoneOn f t)
(hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) :
sSup (f '' s) = sSup (f '' t) :=
MonotoneOn.csInf_eq_of_subset_of_forall_exists_le (α := αᵒᵈ) (β := βᵒᵈ) ht hf.dual hst h
theorem MonotoneOn.sInf_image_Icc [Preorder α] [ConditionallyCompleteLattice β]
{f : α → β} {a b : α} (hab : a ≤ b)
(h' : MonotoneOn f (Icc a b)) : sInf (f '' Icc a b) = f a := by
refine IsGLB.csInf_eq ?_ ((nonempty_Icc.mpr hab).image f)
refine isGLB_iff_le_iff.mpr (fun b' ↦ ⟨?_, ?_⟩)
· intro hb'
rintro _ ⟨x, hx, rfl⟩
exact hb'.trans <| h' (left_mem_Icc.mpr hab) hx hx.1
· exact fun hb' ↦ hb' ⟨a, by simp [hab]⟩
theorem MonotoneOn.sSup_image_Icc [Preorder α] [ConditionallyCompleteLattice β]
{f : α → β} {a b : α} (hab : a ≤ b)
(h' : MonotoneOn f (Icc a b)) : sSup (f '' Icc a b) = f b := by
have : Icc a b = Icc (α := αᵒᵈ) (toDual b) (toDual a) := by rw [Icc_toDual]; rfl
rw [this] at h' ⊢
exact h'.dual_right.dual_left.sInf_image_Icc (β := βᵒᵈ) (α := αᵒᵈ) hab
theorem AntitoneOn.sInf_image_Icc [Preorder α] [ConditionallyCompleteLattice β]
{f : α → β} {a b : α} (hab : a ≤ b)
(h' : AntitoneOn f (Icc a b)) : sInf (f '' Icc a b) = f b := by
have : Icc a b = Icc (α := αᵒᵈ) (toDual b) (toDual a) := by rw [Icc_toDual]; rfl
rw [this] at h' ⊢
exact h'.dual_left.sInf_image_Icc (α := αᵒᵈ) hab
theorem AntitoneOn.sSup_image_Icc [Preorder α] [ConditionallyCompleteLattice β]
{f : α → β} {a b : α} (hab : a ≤ b)
(h' : AntitoneOn f (Icc a b)) : sSup (f '' Icc a b) = f a :=
h'.dual_right.sInf_image_Icc hab
/-!
### Supremum/infimum of `Set.image2`
A collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under
a binary function whose partial evaluations are lower/upper adjoints of Galois connections.
-/
section
variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β]
[ConditionallyCompleteLattice γ] {s : Set α} {t : Set β}
variable {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β}
theorem csSup_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) (hs₀ : s.Nonempty) (hs₁ : BddAbove s)
(ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (image2 l s t) = l (sSup s) (sSup t) := by
refine eq_of_forall_ge_iff fun c => ?_
rw [csSup_le_iff (hs₁.image2 (fun _ => (h₁ _).monotone_l) (fun _ => (h₂ _).monotone_l) ht₁)
(hs₀.image2 ht₀),
forall_mem_image2, forall₂_swap, (h₂ _).le_iff_le, csSup_le_iff ht₁ ht₀]
simp_rw [← (h₂ _).le_iff_le, (h₁ _).le_iff_le, csSup_le_iff hs₁ hs₀]
theorem csSup_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sSup s) (sInf t) :=
csSup_image2_eq_csSup_csSup (β := βᵒᵈ) h₁ h₂
theorem csSup_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sSup (image2 l s t) = l (sInf s) (sSup t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) h₁ h₂
theorem csSup_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b))
(h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sInf s) (sInf t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) :
s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sInf s) (sInf t) :=
csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) (γ := γᵒᵈ) (u₁ := l₁) (u₂ := l₂)
(fun _ => (h₁ _).dual) fun _ => (h₂ _).dual
theorem csInf_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sInf s) (sSup t) :=
csInf_image2_eq_csInf_csInf (β := βᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) :
s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sSup s) (sInf t) :=
csInf_image2_eq_csInf_csInf (α := αᵒᵈ) h₁ h₂
theorem csInf_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual))
(h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) :
s.Nonempty → BddAbove s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sSup s) (sSup t) :=
csInf_image2_eq_csInf_csInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂
end
section WithTopBot
/-!
### Complete lattice structure on `WithTop (WithBot α)`
If `α` is a `ConditionallyCompleteLattice`, then we show that `WithTop α` and `WithBot α`
also inherit the structure of conditionally complete lattices. Furthermore, we show
that `WithTop (WithBot α)` and `WithBot (WithTop α)` naturally inherit the structure of a
complete lattice. Note that for `α` a conditionally complete lattice, `sSup` and `sInf` both return
junk values for sets which are empty or unbounded. The extension of `sSup` to `WithTop α` fixes
the unboundedness problem and the extension to `WithBot α` fixes the problem with
the empty set.
This result can be used to show that the extended reals `[-∞, ∞]` are a complete linear order.
-/
/-- Adding a top element to a conditionally complete lattice
gives a conditionally complete lattice -/
noncomputable instance WithTop.conditionallyCompleteLattice {α : Type*}
[ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithTop α) :=
{ lattice, instSupSet, instInfSet with
le_csSup := fun _ a _ haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS
csSup_le := fun _ _ hS haS => (WithTop.isLUB_sSup' hS).2 haS
csInf_le := fun _ _ hS haS => (WithTop.isGLB_sInf' hS).1 haS
le_csInf := fun _ a _ haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS }
/-- Adding a bottom element to a conditionally complete lattice
gives a conditionally complete lattice -/
noncomputable instance WithBot.conditionallyCompleteLattice {α : Type*}
[ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithBot α) :=
{ WithBot.lattice with
le_csSup := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csInf_le
csSup_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csInf
csInf_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csSup
le_csInf := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csSup_le }
open Classical in
noncomputable instance WithTop.WithBot.completeLattice {α : Type*}
[ConditionallyCompleteLattice α] : CompleteLattice (WithTop (WithBot α)) :=
{ instInfSet, instSupSet, boundedOrder, lattice with
le_sSup := fun _ a haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS
sSup_le := fun S a ha => by
rcases S.eq_empty_or_nonempty with h | h
· change ite _ _ _ ≤ a
simp [h]
· exact (WithTop.isLUB_sSup' h).2 ha
sInf_le := fun S a haS =>
show ite _ _ _ ≤ a by
simp only [OrderBot.bddBelow, not_true_eq_false, or_false]
split_ifs with h₁
· cases a
· exact le_rfl
cases h₁ haS
· cases a
· exact le_top
· apply WithTop.coe_le_coe.2
refine csInf_le ?_ haS
use ⊥
intro b _
exact bot_le
le_sInf := fun _ a haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS }
noncomputable instance WithTop.WithBot.completeLinearOrder {α : Type*}
[ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithTop (WithBot α)) where
__ := completeLattice
__ := linearOrder
__ := linearOrder.toBiheytingAlgebra
noncomputable instance WithBot.WithTop.completeLattice {α : Type*}
[ConditionallyCompleteLattice α] : CompleteLattice (WithBot (WithTop α)) :=
{ instInfSet, instSupSet, instBoundedOrder, lattice with
le_sSup := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sInf_le
sSup_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sInf
sInf_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sSup
le_sInf := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sSup_le }
noncomputable instance WithBot.WithTop.completeLinearOrder {α : Type*}
[ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithBot (WithTop α)) where
__ := completeLattice
__ := linearOrder
__ := linearOrder.toBiheytingAlgebra
end WithTopBot
|
OpClass.lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Init
/-!
# Typeclasses for commuting heterogeneous operations
The three classes in this file are for two-argument functions where one input is of type `α`,
the output is of type `β` and the other input is of type `α` or `β`.
They express the property that permuting arguments of type `α` does not change the result.
## Main definitions
* `IsSymmOp`: for `op : α → α → β`, `op a b = op b a`.
* `LeftCommutative`: for `op : α → β → β`, `op a₁ (op a₂ b) = op a₂ (op a₁ b)`.
* `RightCommutative`: for `op : β → α → β`, `op (op b a₁) a₂ = op (op b a₂) a₁`.
-/
universe u v
variable {α : Sort u} {β : Sort v}
/-- `IsSymmOp op` where `op : α → α → β` says that `op` is a symmetric operation,
i.e. `op a b = op b a`.
It is the natural generalisation of `Std.Commutative` (`β = α`) and `IsSymm` (`β = Prop`). -/
class IsSymmOp (op : α → α → β) : Prop where
/-- A symmetric operation satisfies `op a b = op b a`. -/
symm_op : ∀ a b, op a b = op b a
/-- `LeftCommutative op` where `op : α → β → β` says that `op` is a left-commutative operation,
i.e. `op a₁ (op a₂ b) = op a₂ (op a₁ b)`. -/
class LeftCommutative (op : α → β → β) : Prop where
/-- A left-commutative operation satisfies `op a₁ (op a₂ b) = op a₂ (op a₁ b)`. -/
left_comm : (a₁ a₂ : α) → (b : β) → op a₁ (op a₂ b) = op a₂ (op a₁ b)
/-- `RightCommutative op` where `op : β → α → β` says that `op` is a right-commutative operation,
i.e. `op (op b a₁) a₂ = op (op b a₂) a₁`. -/
class RightCommutative (op : β → α → β) : Prop where
/-- A right-commutative operation satisfies `op (op b a₁) a₂ = op (op b a₂) a₁`. -/
right_comm : (b : β) → (a₁ a₂ : α) → op (op b a₁) a₂ = op (op b a₂) a₁
instance (priority := 100) isSymmOp_of_isCommutative (α : Sort u) (op : α → α → α)
[Std.Commutative op] : IsSymmOp op where symm_op := Std.Commutative.comm
theorem IsSymmOp.flip_eq (op : α → α → β) [IsSymmOp op] : flip op = op :=
funext fun a ↦ funext fun b ↦ (IsSymmOp.symm_op a b).symm
instance {f : α → β → β} [h : LeftCommutative f] : RightCommutative (fun x y ↦ f y x) :=
⟨fun _ _ _ ↦ (h.left_comm _ _ _).symm⟩
instance {f : β → α → β} [h : RightCommutative f] : LeftCommutative (fun x y ↦ f y x) :=
⟨fun _ _ _ ↦ (h.right_comm _ _ _).symm⟩
instance {f : α → α → α} [hc : Std.Commutative f] [ha : Std.Associative f] : LeftCommutative f :=
⟨fun a b c ↦ by rw [← ha.assoc, hc.comm a, ha.assoc]⟩
instance {f : α → α → α} [hc : Std.Commutative f] [ha : Std.Associative f] : RightCommutative f :=
⟨fun a b c ↦ by rw [ha.assoc, hc.comm b, ha.assoc]⟩
|
tuple.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.
From mathcomp Require Import seq choice fintype path.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(******************************************************************************)
(* This file defines tuples, i.e., sequences with a fixed (known) length, *)
(* and sequences with bounded length. *)
(* For tuples we define: *)
(* n.-tuple T == the type of n-tuples of elements of type T *)
(* [tuple of s] == the tuple whose underlying sequence (value) is s *)
(* The size of s must be known: specifically, Coq must *)
(* be able to infer a Canonical tuple projecting on s. *)
(* in_tuple s == the (size s).-tuple with value s *)
(* [tuple] == the empty tuple *)
(* [tuple x1; ..; xn] == the explicit n.-tuple <x1; ..; xn> *)
(* [tuple E | i < n] == the n.-tuple with general term E (i : 'I_n is bound *)
(* in E) *)
(* tcast Emn t == the m.-tuple t cast as an n.-tuple using Emn : m = n *)
(* As n.-tuple T coerces to seq t, all seq operations (size, nth, ...) can be *)
(* applied to t : n.-tuple T; we provide a few specialized instances when *)
(* avoids the need for a default value. *)
(* tsize t == the size of t (the n in n.-tuple T) *)
(* tnth t i == the i'th component of t, where i : 'I_n *)
(* [tnth t i] == the i'th component of t, where i : nat and i < n *)
(* is convertible to true *)
(* thead t == the first element of t, when n is m.+1 for some m *)
(* For bounded sequences we define: *)
(* n.-bseq T == the type of bounded sequences of elements of type T, *)
(* the length of a bounded sequence is smaller or *)
(* or equal to n *)
(* [bseq of s] == the bounded sequence whose underlying value is s *)
(* The size of s must be known. *)
(* in_bseq s == the (size s).-bseq with value s *)
(* [bseq] == the empty bseq *)
(* insub_bseq n s == the n.-bseq of value s if size s <= n, else [bseq] *)
(* [bseq x1; ..; xn] == the explicit n.-bseq <x1; ..; xn> *)
(* cast_bseq Emn t == the m.-bseq t cast as an n.-tuple using Emn : m = n *)
(* widen_bseq Lmn t == the m.-bseq t cast as an n.-tuple using Lmn : m <= n *)
(* Most seq constructors (cons, behead, cat, rcons, belast, take, drop, rot, *)
(* rotr, map, ...) can be used to build tuples and bounded sequences via *)
(* the [tuple of s] and [bseq of s] constructs respectively. *)
(* Tuples and bounded sequences are actually instances of subType of seq, *)
(* and inherit all combinatorial structures, including the finType structure. *)
(* Some useful lemmas and definitions: *)
(* tuple0 : [tuple] is the only 0.-tuple *)
(* bseq0 : [bseq] is the only 0.-bseq *)
(* tupleP : elimination view for n.+1.-tuple *)
(* ord_tuple n : the n.-tuple of all i : 'I_n *)
(******************************************************************************)
Section TupleDef.
Variables (n : nat) (T : Type).
Structure tuple_of : Type := Tuple {tval :> seq T; _ : size tval == n}.
HB.instance Definition _ := [isSub for tval].
Implicit Type t : tuple_of.
Definition tsize of tuple_of := n.
Lemma size_tuple t : size t = n.
Proof. exact: (eqP (valP t)). Qed.
Lemma tnth_default t : 'I_n -> T.
Proof. by rewrite -(size_tuple t); case: (tval t) => [|//] []. Qed.
Definition tnth t i := nth (tnth_default t i) t i.
Lemma tnth_nth x t i : tnth t i = nth x t i.
Proof. by apply: set_nth_default; rewrite size_tuple. Qed.
Lemma tnth_onth x t i : tnth t i = x <-> onth t i = Some x.
Proof.
rewrite (tnth_nth x) onthE (nth_map x) ?size_tuple//.
by split; [move->|case].
Qed.
Lemma map_tnth_enum t : map (tnth t) (enum 'I_n) = t.
Proof.
case def_t: {-}(val t) => [|x0 t'].
by rewrite [enum _]size0nil // -cardE card_ord -(size_tuple t) def_t.
apply: (@eq_from_nth _ x0) => [|i]; rewrite size_map.
by rewrite -cardE size_tuple card_ord.
move=> lt_i_e; have lt_i_n: i < n by rewrite -cardE card_ord in lt_i_e.
by rewrite (nth_map (Ordinal lt_i_n)) // (tnth_nth x0) nth_enum_ord.
Qed.
Lemma eq_from_tnth t1 t2 : tnth t1 =1 tnth t2 -> t1 = t2.
Proof.
by move/eq_map=> eq_t; apply: val_inj; rewrite /= -!map_tnth_enum eq_t.
Qed.
Definition tuple t mkT : tuple_of :=
mkT (let: Tuple _ tP := t return size t == n in tP).
Lemma tupleE t : tuple (fun sP => @Tuple t sP) = t.
Proof. by case: t. Qed.
End TupleDef.
Notation "n .-tuple" := (tuple_of n) (format "n .-tuple") : type_scope.
Notation "{ 'tuple' n 'of' T }" := (n.-tuple T : predArgType)
(only parsing) : type_scope.
Notation "[ 'tuple' 'of' s ]" := (tuple (fun sP => @Tuple _ _ s sP))
(format "[ 'tuple' 'of' s ]") : form_scope.
Notation "[ 'tnth' t i ]" := (tnth t (@Ordinal (tsize t) i (erefl true)))
(t, i at level 8, format "[ 'tnth' t i ]") : form_scope.
Canonical nil_tuple T := Tuple (isT : @size T [::] == 0).
Canonical cons_tuple n T x (t : n.-tuple T) :=
Tuple (valP t : size (x :: t) == n.+1).
Notation "[ 'tuple' x1 ; .. ; xn ]" := [tuple of x1 :: .. [:: xn] ..]
(format "[ 'tuple' '[' x1 ; '/' .. ; '/' xn ']' ]") : form_scope.
Notation "[ 'tuple' ]" := [tuple of [::]] (format "[ 'tuple' ]") : form_scope.
Section CastTuple.
Variable T : Type.
Definition in_tuple (s : seq T) := Tuple (eqxx (size s)).
Definition tcast m n (eq_mn : m = n) t :=
let: erefl in _ = n := eq_mn return n.-tuple T in t.
Lemma tcastE m n (eq_mn : m = n) t i :
tnth (tcast eq_mn t) i = tnth t (cast_ord (esym eq_mn) i).
Proof. by case: n / eq_mn in i *; rewrite cast_ord_id. Qed.
Lemma tcast_id n (eq_nn : n = n) t : tcast eq_nn t = t.
Proof. by rewrite (eq_axiomK eq_nn). Qed.
Lemma tcastK m n (eq_mn : m = n) : cancel (tcast eq_mn) (tcast (esym eq_mn)).
Proof. by case: n / eq_mn. Qed.
Lemma tcastKV m n (eq_mn : m = n) : cancel (tcast (esym eq_mn)) (tcast eq_mn).
Proof. by case: n / eq_mn. Qed.
Lemma tcast_trans m n p (eq_mn : m = n) (eq_np : n = p) t:
tcast (etrans eq_mn eq_np) t = tcast eq_np (tcast eq_mn t).
Proof. by case: n / eq_mn eq_np; case: p /. Qed.
Lemma tvalK n (t : n.-tuple T) : in_tuple t = tcast (esym (size_tuple t)) t.
Proof. by apply: val_inj => /=; case: _ / (esym _). Qed.
Lemma val_tcast m n (eq_mn : m = n) (t : m.-tuple T) :
tcast eq_mn t = t :> seq T.
Proof. by case: n / eq_mn. Qed.
Lemma in_tupleE s : in_tuple s = s :> seq T. Proof. by []. Qed.
End CastTuple.
Section SeqTuple.
Variables (n m : nat) (T U rT : Type).
Implicit Type t : n.-tuple T.
Lemma rcons_tupleP t x : size (rcons t x) == n.+1.
Proof. by rewrite size_rcons size_tuple. Qed.
Canonical rcons_tuple t x := Tuple (rcons_tupleP t x).
Lemma nseq_tupleP x : @size T (nseq n x) == n.
Proof. by rewrite size_nseq. Qed.
Canonical nseq_tuple x := Tuple (nseq_tupleP x).
Lemma iota_tupleP : size (iota m n) == n.
Proof. by rewrite size_iota. Qed.
Canonical iota_tuple := Tuple iota_tupleP.
Lemma behead_tupleP t : size (behead t) == n.-1.
Proof. by rewrite size_behead size_tuple. Qed.
Canonical behead_tuple t := Tuple (behead_tupleP t).
Lemma belast_tupleP x t : size (belast x t) == n.
Proof. by rewrite size_belast size_tuple. Qed.
Canonical belast_tuple x t := Tuple (belast_tupleP x t).
Lemma cat_tupleP t (u : m.-tuple T) : size (t ++ u) == n + m.
Proof. by rewrite size_cat !size_tuple. Qed.
Canonical cat_tuple t u := Tuple (cat_tupleP t u).
Lemma take_tupleP t : size (take m t) == minn m n.
Proof. by rewrite size_take size_tuple eqxx. Qed.
Canonical take_tuple t := Tuple (take_tupleP t).
Lemma drop_tupleP t : size (drop m t) == n - m.
Proof. by rewrite size_drop size_tuple. Qed.
Canonical drop_tuple t := Tuple (drop_tupleP t).
Lemma rev_tupleP t : size (rev t) == n.
Proof. by rewrite size_rev size_tuple. Qed.
Canonical rev_tuple t := Tuple (rev_tupleP t).
Lemma rot_tupleP t : size (rot m t) == n.
Proof. by rewrite size_rot size_tuple. Qed.
Canonical rot_tuple t := Tuple (rot_tupleP t).
Lemma rotr_tupleP t : size (rotr m t) == n.
Proof. by rewrite size_rotr size_tuple. Qed.
Canonical rotr_tuple t := Tuple (rotr_tupleP t).
Lemma map_tupleP f t : @size rT (map f t) == n.
Proof. by rewrite size_map size_tuple. Qed.
Canonical map_tuple f t := Tuple (map_tupleP f t).
Lemma scanl_tupleP f x t : @size rT (scanl f x t) == n.
Proof. by rewrite size_scanl size_tuple. Qed.
Canonical scanl_tuple f x t := Tuple (scanl_tupleP f x t).
Lemma pairmap_tupleP f x t : @size rT (pairmap f x t) == n.
Proof. by rewrite size_pairmap size_tuple. Qed.
Canonical pairmap_tuple f x t := Tuple (pairmap_tupleP f x t).
Lemma zip_tupleP t (u : n.-tuple U) : size (zip t u) == n.
Proof. by rewrite size1_zip !size_tuple. Qed.
Canonical zip_tuple t u := Tuple (zip_tupleP t u).
Lemma allpairs_tupleP f t (u : m.-tuple U) : @size rT (allpairs f t u) == n * m.
Proof. by rewrite size_allpairs !size_tuple. Qed.
Canonical allpairs_tuple f t u := Tuple (allpairs_tupleP f t u).
Lemma sort_tupleP r t : size (sort r t) == n.
Proof. by rewrite size_sort size_tuple. Qed.
Canonical sort_tuple r t := Tuple (sort_tupleP r t).
Definition thead (u : n.+1.-tuple T) := tnth u ord0.
Lemma tnth0 x t : tnth [tuple of x :: t] ord0 = x.
Proof. by []. Qed.
Lemma tnthS x t i : tnth [tuple of x :: t] (lift ord0 i) = tnth t i.
Proof. by rewrite (tnth_nth (tnth_default t i)). Qed.
Lemma theadE x t : thead [tuple of x :: t] = x.
Proof. by []. Qed.
Lemma tuple0 : all_equal_to ([tuple] : 0.-tuple T).
Proof. by move=> t; apply: val_inj; case: t => [[]]. Qed.
Variant tuple1_spec : n.+1.-tuple T -> Type :=
Tuple1spec x t : tuple1_spec [tuple of x :: t].
Lemma tupleP u : tuple1_spec u.
Proof.
case: u => [[|x s] //= sz_s]; pose t := @Tuple n _ s sz_s.
by rewrite (_ : Tuple _ = [tuple of x :: t]) //; apply: val_inj.
Qed.
Lemma tnth_map f t i : tnth [tuple of map f t] i = f (tnth t i) :> rT.
Proof. by apply: nth_map; rewrite size_tuple. Qed.
Lemma tnth_nseq x i : tnth [tuple of nseq n x] i = x.
Proof.
by rewrite !(tnth_nth (tnth_default (nseq_tuple x) i)) nth_nseq ltn_ord.
Qed.
End SeqTuple.
Lemma tnth_behead n T (t : n.+1.-tuple T) i :
tnth [tuple of behead t] i = tnth t (inord i.+1).
Proof. by case/tupleP: t => x t; rewrite !(tnth_nth x) inordK ?ltnS. Qed.
Lemma tuple_eta n T (t : n.+1.-tuple T) : t = [tuple of thead t :: behead t].
Proof. by case/tupleP: t => x t; apply: val_inj. Qed.
Section tnth_shift.
Context {T : Type} {n1 n2} (t1 : n1.-tuple T) (t2 : n2.-tuple T).
Lemma tnth_lshift i : tnth [tuple of t1 ++ t2] (lshift n2 i) = tnth t1 i.
Proof.
have x0 := tnth_default t1 i; rewrite !(tnth_nth x0).
by rewrite nth_cat size_tuple /= ltn_ord.
Qed.
Lemma tnth_rshift j : tnth [tuple of t1 ++ t2] (rshift n1 j) = tnth t2 j.
Proof.
have x0 := tnth_default t2 j; rewrite !(tnth_nth x0).
by rewrite nth_cat size_tuple ltnNge leq_addr /= addKn.
Qed.
End tnth_shift.
Section TupleQuantifiers.
Variables (n : nat) (T : Type).
Implicit Types (a : pred T) (t : n.-tuple T).
Lemma forallb_tnth a t : [forall i, a (tnth t i)] = all a t.
Proof.
apply: negb_inj; rewrite -has_predC -has_map negb_forall.
apply/existsP/(has_nthP true) => [[i a_t_i] | [i lt_i_n a_t_i]].
by exists i; rewrite ?size_tuple // -tnth_nth tnth_map.
rewrite size_tuple in lt_i_n; exists (Ordinal lt_i_n).
by rewrite -tnth_map (tnth_nth true).
Qed.
Lemma existsb_tnth a t : [exists i, a (tnth t i)] = has a t.
Proof. by apply: negb_inj; rewrite negb_exists -all_predC -forallb_tnth. Qed.
Lemma all_tnthP a t : reflect (forall i, a (tnth t i)) (all a t).
Proof. by rewrite -forallb_tnth; apply: forallP. Qed.
Lemma has_tnthP a t : reflect (exists i, a (tnth t i)) (has a t).
Proof. by rewrite -existsb_tnth; apply: existsP. Qed.
End TupleQuantifiers.
Arguments all_tnthP {n T a t}.
Arguments has_tnthP {n T a t}.
Section EqTuple.
Variables (n : nat) (T : eqType).
HB.instance Definition _ : hasDecEq (n.-tuple T) :=
[Equality of n.-tuple T by <:].
Canonical tuple_predType := PredType (pred_of_seq : n.-tuple T -> pred T).
Lemma eqEtuple (t1 t2 : n.-tuple T) :
(t1 == t2) = [forall i, tnth t1 i == tnth t2 i].
Proof. by apply/eqP/'forall_eqP => [->|/eq_from_tnth]. Qed.
Lemma memtE (t : n.-tuple T) : mem t = mem (tval t).
Proof. by []. Qed.
Lemma mem_tnth i (t : n.-tuple T) : tnth t i \in t.
Proof. by rewrite mem_nth ?size_tuple. Qed.
Lemma memt_nth x0 (t : n.-tuple T) i : i < n -> nth x0 t i \in t.
Proof. by move=> i_lt_n; rewrite mem_nth ?size_tuple. Qed.
Lemma tnthP (t : n.-tuple T) x : reflect (exists i, x = tnth t i) (x \in t).
Proof.
apply: (iffP idP) => [/(nthP x)[i ltin <-] | [i ->]]; last exact: mem_tnth.
by rewrite size_tuple in ltin; exists (Ordinal ltin); rewrite (tnth_nth x).
Qed.
Lemma seq_tnthP (s : seq T) x : x \in s -> {i | x = tnth (in_tuple s) i}.
Proof.
move=> s_x; pose i := index x s; have lt_i: i < size s by rewrite index_mem.
by exists (Ordinal lt_i); rewrite (tnth_nth x) nth_index.
Qed.
Lemma tuple_uniqP (t : n.-tuple T) : reflect (injective (tnth t)) (uniq t).
Proof.
case: {+}n => [|m] in t *; first by rewrite tuple0; constructor => -[].
pose x0 := tnth t ord0; apply/(equivP (uniqP x0)); split=> tinj i j.
by rewrite !(tnth_nth x0) => /tinj/val_inj; apply; rewrite size_tuple inE.
rewrite !size_tuple !inE => im jm; have := tinj (Ordinal im) (Ordinal jm).
by rewrite !(tnth_nth x0) => /[apply]-[].
Qed.
End EqTuple.
HB.instance Definition _ n (T : choiceType) :=
[Choice of n.-tuple T by <:].
HB.instance Definition _ n (T : countType) :=
[Countable of n.-tuple T by <:].
Module Type FinTupleSig.
Section FinTupleSig.
Variables (n : nat) (T : finType).
Parameter enum : seq (n.-tuple T).
Axiom enumP : Finite.axiom enum.
Axiom size_enum : size enum = #|T| ^ n.
End FinTupleSig.
End FinTupleSig.
Module FinTuple : FinTupleSig.
Section FinTuple.
Variables (n : nat) (T : finType).
Definition enum : seq (n.-tuple T) :=
let extend e := flatten (codom (fun x => map (cons x) e)) in
pmap insub (iter n extend [::[::]]).
Lemma enumP : Finite.axiom enum.
Proof.
case=> /= t t_n; rewrite -(count_map _ (pred1 t)) (pmap_filter (insubK _)).
rewrite count_filter -(@eq_count _ (pred1 t)) => [|s /=]; last first.
by rewrite isSome_insub; case: eqP=> // ->.
elim: n t t_n => [|m IHm] [|x t] //= {}/IHm; move: (iter m _ _) => em IHm.
transitivity (x \in T : nat); rewrite // -mem_enum codomE.
elim: (fintype.enum T) (enum_uniq T) => //= y e IHe /andP[/negPf ney].
rewrite count_cat count_map inE /preim /= [in LHS]/eq_op /= eq_sym => /IHe->.
by case: eqP => [->|_]; rewrite ?(ney, count_pred0, IHm).
Qed.
Lemma size_enum : size enum = #|T| ^ n.
Proof.
rewrite /= cardE size_pmap_sub; elim: n => //= m IHm.
rewrite expnS /codom /image_mem; elim: {2 3}(fintype.enum T) => //= x e IHe.
by rewrite count_cat {}IHe count_map IHm.
Qed.
End FinTuple.
End FinTuple.
Section UseFinTuple.
Variables (n : nat) (T : finType).
(* tuple_finMixin could, in principle, be made Canonical to allow for folding *)
(* Finite.enum of a finite tuple type (see comments around eqE in eqtype.v), *)
(* but in practice it will not work because the mixin_enum projector *)
(* has been buried under an opaque alias, to avoid some performance issues *)
(* during type inference. *)
HB.instance Definition _ := isFinite.Build (n.-tuple T) (@FinTuple.enumP n T).
Lemma card_tuple : #|{:n.-tuple T}| = #|T| ^ n.
Proof. by rewrite [#|_|]cardT enumT unlock FinTuple.size_enum. Qed.
Lemma enum_tupleP (A : {pred T}) : size (enum A) == #|A|.
Proof. by rewrite -cardE. Qed.
Canonical enum_tuple A := Tuple (enum_tupleP A).
Definition ord_tuple : n.-tuple 'I_n := Tuple (introT eqP (size_enum_ord n)).
Lemma val_ord_tuple : val ord_tuple = enum 'I_n. Proof. by []. Qed.
Lemma tuple_map_ord U (t : n.-tuple U) : t = [tuple of map (tnth t) ord_tuple].
Proof. by apply: val_inj => /=; rewrite map_tnth_enum. Qed.
Lemma tnth_ord_tuple i : tnth ord_tuple i = i.
Proof.
apply: val_inj; rewrite (tnth_nth i) -(nth_map _ 0) ?size_tuple //.
by rewrite /= enumT unlock val_ord_enum nth_iota.
Qed.
Section ImageTuple.
Variables (T' : Type) (f : T -> T') (A : {pred T}).
Canonical image_tuple : #|A|.-tuple T' := [tuple of image f A].
Canonical codom_tuple : #|T|.-tuple T' := [tuple of codom f].
End ImageTuple.
Section MkTuple.
Variables (T' : Type) (f : 'I_n -> T').
Definition mktuple := map_tuple f ord_tuple.
Lemma tnth_mktuple i : tnth mktuple i = f i.
Proof. by rewrite tnth_map tnth_ord_tuple. Qed.
Lemma nth_mktuple x0 (i : 'I_n) : nth x0 mktuple i = f i.
Proof. by rewrite -tnth_nth tnth_mktuple. Qed.
End MkTuple.
Lemma eq_mktuple T' (f1 f2 : 'I_n -> T') :
f1 =1 f2 -> mktuple f1 = mktuple f2.
Proof. by move=> eq_f; apply eq_from_tnth=> i; rewrite !tnth_map eq_f. Qed.
End UseFinTuple.
Notation "[ 'tuple' F | i < n ]" := (mktuple (fun i : 'I_n => F))
(i at level 0,
format "[ '[hv' 'tuple' F '/' | i < n ] ']'") : form_scope.
Arguments eq_mktuple {n T'} [f1] f2 eq_f12.
Section BseqDef.
Variables (n : nat) (T : Type).
Structure bseq_of : Type := Bseq {bseqval :> seq T; _ : size bseqval <= n}.
HB.instance Definition _ := [isSub for bseqval].
Implicit Type bs : bseq_of.
Lemma size_bseq bs : size bs <= n.
Proof. by case: bs. Qed.
Definition bseq bs mkB : bseq_of :=
mkB (let: Bseq _ bsP := bs return size bs <= n in bsP).
Lemma bseqE bs : bseq (fun sP => @Bseq bs sP) = bs.
Proof. by case: bs. Qed.
End BseqDef.
Canonical nil_bseq n T := Bseq (isT : @size T [::] <= n).
Canonical cons_bseq n T x (t : bseq_of n T) :=
Bseq (valP t : size (x :: t) <= n.+1).
Notation "n .-bseq" := (bseq_of n) (format "n .-bseq") : type_scope.
Notation "{ 'bseq' n 'of' T }" := (n.-bseq T : predArgType)
(only parsing) : type_scope.
Notation "[ 'bseq' 'of' s ]" := (bseq (fun sP => @Bseq _ _ s sP))
(format "[ 'bseq' 'of' s ]") : form_scope.
Notation "[ 'bseq' x1 ; .. ; xn ]" := [bseq of x1 :: .. [:: xn] ..]
(format "[ 'bseq' '[' x1 ; '/' .. ; '/' xn ']' ]") : form_scope.
Notation "[ 'bseq' ]" := [bseq of [::]] (format "[ 'bseq' ]") : form_scope.
Coercion bseq_of_tuple n T (t : n.-tuple T) : n.-bseq T :=
Bseq (eq_leq (size_tuple t)).
Definition insub_bseq n T (s : seq T) : n.-bseq T := insubd [bseq] s.
Lemma size_insub_bseq n T (s : seq T) : size (insub_bseq n s) <= size s.
Proof. by rewrite /insub_bseq /insubd; case: insubP => // ? ? ->. Qed.
Section CastBseq.
Variable T : Type.
Definition in_bseq (s : seq T) : (size s).-bseq T := Bseq (leqnn (size s)).
Definition cast_bseq m n (eq_mn : m = n) bs :=
let: erefl in _ = n := eq_mn return n.-bseq T in bs.
Definition widen_bseq m n (lemn : m <= n) (bs : m.-bseq T) : n.-bseq T :=
@Bseq n T bs (leq_trans (size_bseq bs) lemn).
Lemma cast_bseq_id n (eq_nn : n = n) bs : cast_bseq eq_nn bs = bs.
Proof. by rewrite (eq_axiomK eq_nn). Qed.
Lemma cast_bseqK m n (eq_mn : m = n) :
cancel (cast_bseq eq_mn) (cast_bseq (esym eq_mn)).
Proof. by case: n / eq_mn. Qed.
Lemma cast_bseqKV m n (eq_mn : m = n) :
cancel (cast_bseq (esym eq_mn)) (cast_bseq eq_mn).
Proof. by case: n / eq_mn. Qed.
Lemma cast_bseq_trans m n p (eq_mn : m = n) (eq_np : n = p) bs :
cast_bseq (etrans eq_mn eq_np) bs = cast_bseq eq_np (cast_bseq eq_mn bs).
Proof. by case: n / eq_mn eq_np; case: p /. Qed.
Lemma size_cast_bseq m n (eq_mn : m = n) (bs : m.-bseq T) :
size (cast_bseq eq_mn bs) = size bs.
Proof. by case: n / eq_mn. Qed.
Lemma widen_bseq_id n (lenn : n <= n) (bs : n.-bseq T) :
widen_bseq lenn bs = bs.
Proof. exact: val_inj. Qed.
Lemma cast_bseqEwiden m n (eq_mn : m = n) (bs : m.-bseq T) :
cast_bseq eq_mn bs = widen_bseq (eq_leq eq_mn) bs.
Proof. by case: n / eq_mn; rewrite widen_bseq_id. Qed.
Lemma widen_bseqK m n (lemn : m <= n) (lenm : n <= m) :
cancel (@widen_bseq m n lemn) (widen_bseq lenm).
Proof. by move=> t; apply: val_inj. Qed.
Lemma widen_bseq_trans m n p (lemn : m <= n) (lenp : n <= p) (bs : m.-bseq T) :
widen_bseq (leq_trans lemn lenp) bs = widen_bseq lenp (widen_bseq lemn bs).
Proof. exact/val_inj. Qed.
Lemma size_widen_bseq m n (lemn : m <= n) (bs : m.-bseq T) :
size (widen_bseq lemn bs) = size bs.
Proof. by []. Qed.
Lemma in_bseqE s : in_bseq s = s :> seq T. Proof. by []. Qed.
Lemma widen_bseq_in_bseq n (bs : n.-bseq T) :
widen_bseq (size_bseq bs) (in_bseq bs) = bs.
Proof. exact: val_inj. Qed.
End CastBseq.
Section SeqBseq.
Variables (n m : nat) (T U rT : Type).
Implicit Type s : n.-bseq T.
Lemma rcons_bseqP s x : size (rcons s x) <= n.+1.
Proof. by rewrite size_rcons ltnS size_bseq. Qed.
Canonical rcons_bseq s x := Bseq (rcons_bseqP s x).
Lemma behead_bseqP s : size (behead s) <= n.-1.
Proof. rewrite size_behead -!subn1; apply/leq_sub2r/size_bseq. Qed.
Canonical behead_bseq s := Bseq (behead_bseqP s).
Lemma belast_bseqP x s : size (belast x s) <= n.
Proof. by rewrite size_belast; apply/size_bseq. Qed.
Canonical belast_bseq x s := Bseq (belast_bseqP x s).
Lemma cat_bseqP s (s' : m.-bseq T) : size (s ++ s') <= n + m.
Proof. by rewrite size_cat; apply/leq_add/size_bseq/size_bseq. Qed.
Canonical cat_bseq s (s' : m.-bseq T) := Bseq (cat_bseqP s s').
Lemma take_bseqP s : size (take m s) <= n.
Proof.
by rewrite size_take_min (leq_trans _ (size_bseq s)) // geq_minr.
Qed.
Canonical take_bseq s := Bseq (take_bseqP s).
Lemma drop_bseqP s : size (drop m s) <= n - m.
Proof. by rewrite size_drop; apply/leq_sub2r/size_bseq. Qed.
Canonical drop_bseq s := Bseq (drop_bseqP s).
Lemma rev_bseqP s : size (rev s) <= n.
Proof. by rewrite size_rev size_bseq. Qed.
Canonical rev_bseq s := Bseq (rev_bseqP s).
Lemma rot_bseqP s : size (rot m s) <= n.
Proof. by rewrite size_rot size_bseq. Qed.
Canonical rot_bseq s := Bseq (rot_bseqP s).
Lemma rotr_bseqP s : size (rotr m s) <= n.
Proof. by rewrite size_rotr size_bseq. Qed.
Canonical rotr_bseq s := Bseq (rotr_bseqP s).
Lemma map_bseqP f s : @size rT (map f s) <= n.
Proof. by rewrite size_map size_bseq. Qed.
Canonical map_bseq f s := Bseq (map_bseqP f s).
Lemma scanl_bseqP f x s : @size rT (scanl f x s) <= n.
Proof. by rewrite size_scanl size_bseq. Qed.
Canonical scanl_bseq f x s := Bseq (scanl_bseqP f x s).
Lemma pairmap_bseqP f x s : @size rT (pairmap f x s) <= n.
Proof. by rewrite size_pairmap size_bseq. Qed.
Canonical pairmap_bseq f x s := Bseq (pairmap_bseqP f x s).
Lemma allpairs_bseqP f s (s' : m.-bseq U) : @size rT (allpairs f s s') <= n * m.
Proof. by rewrite size_allpairs; apply/leq_mul/size_bseq/size_bseq. Qed.
Canonical allpairs_bseq f s (s' : m.-bseq U) := Bseq (allpairs_bseqP f s s').
Lemma sort_bseqP r s : size (sort r s) <= n.
Proof. by rewrite size_sort size_bseq. Qed.
Canonical sort_bseq r s := Bseq (sort_bseqP r s).
Lemma bseq0 : all_equal_to ([bseq] : 0.-bseq T).
Proof. by move=> s; apply: val_inj; case: s => [[]]. Qed.
End SeqBseq.
HB.instance Definition bseq_hasDecEq n (T : eqType) :=
[Equality of n.-bseq T by <:].
Canonical bseq_predType n (T : eqType) :=
Eval hnf in PredType (fun t : n.-bseq T => mem_seq t).
Lemma membsE n (T : eqType) (bs : n.-bseq T) : mem bs = mem (bseqval bs).
Proof. by []. Qed.
HB.instance Definition bseq_hasChoice n (T : choiceType) :=
[Choice of n.-bseq T by <:].
HB.instance Definition bseq_isCountable n (T : countType) :=
[Countable of n.-bseq T by <:].
Definition bseq_tagged_tuple n T (s : n.-bseq T) : {k : 'I_n.+1 & k.-tuple T} :=
Tagged _ (in_tuple s : (Ordinal (size_bseq s : size s < n.+1)).-tuple _).
Arguments bseq_tagged_tuple {n T}.
Definition tagged_tuple_bseq n T (t : {k : 'I_n.+1 & k.-tuple T}) : n.-bseq T :=
widen_bseq (leq_ord (tag t)) (tagged t).
Arguments tagged_tuple_bseq {n T}.
Lemma bseq_tagged_tupleK {n T} :
cancel (@bseq_tagged_tuple n T) tagged_tuple_bseq.
Proof. by move=> bs; apply/val_inj. Qed.
Lemma tagged_tuple_bseqK {n T} :
cancel (@tagged_tuple_bseq n T) bseq_tagged_tuple.
Proof.
move=> [[k lt_kn] t]; apply: eq_existT_curried => [|k_eq]; apply/val_inj.
by rewrite /= size_tuple.
by refine (let: erefl := k_eq in _).
Qed.
Lemma bseq_tagged_tuple_bij {n T} : bijective (@bseq_tagged_tuple n T).
Proof. exact/Bijective/tagged_tuple_bseqK/bseq_tagged_tupleK. Qed.
Lemma tagged_tuple_bseq_bij {n T} : bijective (@tagged_tuple_bseq n T).
Proof. exact/Bijective/bseq_tagged_tupleK/tagged_tuple_bseqK. Qed.
#[global] Hint Resolve bseq_tagged_tuple_bij tagged_tuple_bseq_bij : core.
#[non_forgetful_inheritance]
HB.instance Definition _ n (T : finType) := isFinite.Build (n.-bseq T)
(pcan_enumP (can_pcan (@bseq_tagged_tupleK n T))).
|
sesquilinear.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple bigop ssralg finset fingroup.
From mathcomp Require Import zmodp poly order ssrnum matrix mxalgebra vector.
(******************************************************************************)
(* Sesquilinear forms *)
(* *)
(* e_ j := the row matrix with a 1 in column j *)
(* M ^ phi := map_mx phi M *)
(* Notation in scope sesquilinear_scope. *)
(* M ^t phi := (M ^T) ^ phi *)
(* Notation in scope sesquilinear_scope. *)
(* involutive_rmorphism R == the type of involutive functions *)
(* R has type nzRingType. *)
(* The HB class is InvolutiveRMorphism. *)
(* *)
(* {bilinear U -> U' -> V | s & s'} == the type of bilinear forms which are *)
(* essentially functions of type U -> U' -> V *)
(* U and U' are lmodType's, V is a zmodType, s and *)
(* s' are scaling operations of type R -> V -> V. *)
(* The HB class is Bilinear. *)
(* The factory bilinear_isBilinear provides a way *)
(* to instantiate a bilinear form from two *)
(* GRing.linear_for proofs. *)
(* {bilinear U -> V -> W | s } := {bilinear U -> V -> W | s.1 & s.2} *)
(* {bilinear U -> V -> W} := {bilinear U -> V -> W | *:%R & *:%R } *)
(* {biscalar U} := {bilinear U -> U -> _ | *%R & *%R } *)
(* *)
(* applyr f x := f ^~ x with f : U -> U' -> V *)
(* form theta M u v == form defined from a matrix M *)
(* := (u *m M *m (v ^t theta)) 0 0 *)
(* u and v are row vectors, M is a square matrix, *)
(* coefficients have type R : fieldType, *)
(* theta is a morphism *)
(* *)
(* {hermitian U for eps & theta} == hermitian/skew-hermitian form *)
(* eps is a boolean flag, *)
(* (false -> hermitian, true -> skew-hermitian), *)
(* theta is a function R -> R (R : nzRingType). *)
(* The HB class is Hermitian. *)
(* *%R is used as a the first scaling operator. *)
(* theta \; *R is used as the second scaling *)
(* operation of the bilinear form. *)
(* The archetypal case is theta being the complex *)
(* conjugate. *)
(* *)
(* M \is (eps, theta).-sesqui == M is a sesquilinear form *)
(* *)
(* orthomx theta M B == M-orthogonal complement of B *)
(* := kermx (M *m B ^t theta) *)
(* M is a square matrix representing a sesquilinear *)
(* form, B is a rectangle matrix representing a *)
(* subspace *)
(* (local notation: B ^_|_) *)
(* ortho theta M B == orthomx theta M B with theta a morphism *)
(* A '_|_ B := (A%MS <= B^_|_)%MS *)
(* This is a local notation. *)
(* rad theta M := ortho theta M 1%:M *)
(* (local notation: 1%:M^_|_) *)
(* *)
(* {symmetric U} == symmetric form *)
(* := {hermitian U for false & idfun} *)
(* {skew_symmetric U} == skew-symmetric form *)
(* := {hermitian U for true & idfun} *)
(* {hermitian_sym U for theta} := hermitian form using theta (eps = false) *)
(* {dot U for theta} == type of positive definite forms *)
(* The HB class is Dot. *)
(* *)
(* is_skew eps theta form := eps = true /\ theta = idfun *)
(* is_sym eps theta form := eps = false /\ theta = idfun *)
(* is_hermsym eps theta form := eps = false *)
(* *)
(* ortho_rec s1 s2 := elements of s1 and s2 are pairwise orthogonal *)
(* pairwise_orthogonal s == elements of s are pairwise orthogonal and *)
(* s does not contain 0 *)
(* orthogonal s1 s2 == the inner product of an element of S1 and *)
(* an element of S2 is 0 *)
(* := ortho_rec s1 s2 *)
(* orthonormal s == s is an orthonormal set of unit vectors *)
(* *)
(* isometry form1 form2 tau == tau is an isometry from form1 to form2 *)
(* form1 and form2 are hermitian forms. *)
(* {in D, isometry tau, to R} == local notation for now *)
(* *)
(* orthov (V : {vspace vT}) == the space orthogonal to V *)
(* *)
(* In the following definitions, we have f : {hermitian vT for eps & theta} *)
(* with vT : vectType F (F : fieldType): *)
(* nondegenerate f == f is non-degenerated *)
(* is_symplectic f == f is a symplectic bilinear form *)
(* is_orthogonal f == f is an orthogonal form *)
(* is_unitary f == f is a unitary form *)
(* *)
(* form_of_matrix theta M U V := \tr (U *m M *m (V ^t theta)) *)
(* matrix_of_form f := \matrix_(i, j) form 'e_i 'e_j *)
(* M \is hermitianmx eps theta == same as M \is (eps, theta).-sesqui *)
(* without the constraint that theta is a morphism *)
(* *)
(* symmetricmx := hermitianmx _ false idfun *)
(* skewmx := hermitianmx _ true idfun *)
(* hermsymmx := hermitianmx _ false conjC *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "M ^t phi"
(at level 39, left associativity, format "M ^t phi").
Reserved Notation "A ^!" (format "A ^!").
Reserved Notation "A ^_|_" (format "A ^_|_").
Reserved Notation "A ''_|_' B" (at level 69, format "A ''_|_' B").
Reserved Notation "eps_theta .-sesqui" (format "eps_theta .-sesqui").
Local Open Scope ring_scope.
Import GRing.Theory Order.Theory Num.Theory.
Notation "''e_' j" := (delta_mx 0 j)
(format "''e_' j", at level 8, j at level 2) : ring_scope.
Declare Scope sesquilinear_scope.
Delimit Scope sesquilinear_scope with sesqui.
Local Open Scope sesquilinear_scope.
Notation "M ^ phi" := (map_mx phi M) : sesquilinear_scope.
Notation "M ^t phi" := ((M ^T) ^ phi) : sesquilinear_scope.
(* TODO: move? *)
Lemma eq_map_mx_id (R : nzRingType) m n (M : 'M[R]_(m, n)) (f : R -> R) :
f =1 id -> M ^ f = M.
Proof. by move=> /eq_map_mx->; rewrite map_mx_id. Qed.
HB.mixin Record isInvolutive (R : nzRingType) (f : R -> R) :=
{ involutive_subproof : involutive f }.
(* TODO: move? *)
#[short(type="involutive_rmorphism")]
HB.structure Definition InvolutiveRMorphism (R : nzRingType) :=
{ f of @GRing.RMorphism R R f & @isInvolutive R f }.
Section InvolutiveTheory.
Variable R : nzRingType.
Let idfunK : involutive (@idfun R). Proof. by []. Qed.
HB.instance Definition _ := isInvolutive.Build _ _ idfunK.
Lemma rmorphK (f : involutive_rmorphism R) : involutive f.
Proof. by move: f => [? [? ? []]]. Qed.
End InvolutiveTheory.
Definition conjC {C : numClosedFieldType} (c : C) : C := c^*.
HB.instance Definition _ (C : numClosedFieldType) :=
GRing.RMorphism.on (@conjC C).
Section conjC_involutive.
Variable C : numClosedFieldType.
Let conjCfun_involutive : involutive (@conjC C). Proof. exact: conjCK. Qed.
HB.instance Definition _ :=
isInvolutive.Build _ (@conjC C) conjCfun_involutive.
End conjC_involutive.
Lemma map_mxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) :
(A ^ conjC) ^ conjC = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
(*Structure revop X Y Z (f : Y -> X -> Z) := RevOp {
fun_of_revop :> X -> Y -> Z;
_ : forall x, f x =1 fun_of_revop^~ x
}.
Notation "[ 'revop' revop 'of' op ]" :=
(@RevOp _ _ _ revop op (fun _ _ => erefl))
(format "[ 'revop' revop 'of' op ]") : form_scope.*)
HB.mixin Record isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : U -> U' -> V) := {
zmod_morphisml_subproof : forall u', zmod_morphism (f ^~ u') ;
zmod_morphismr_subproof : forall u, zmod_morphism (f u) ;
linearl_subproof : forall u', scalable_for s (f ^~ u') ;
linearr_subproof : forall u, scalable_for s' (f u)
}.
#[short(type="bilinear")]
HB.structure Definition Bilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) :=
{f of isBilinear R U U' V s s' f}.
Definition bilinear_for (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) :=
((forall u', GRing.linear_for (s : R -> V -> V) (f ^~ u'))
* (forall u, GRing.linear_for s' (f u)))%type.
HB.factory Record bilinear_isBilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V)
(f : U -> U' -> V) := {
bilinear_subproof : bilinear_for s s' f
}.
HB.builders Context R U U' V s s' f of bilinear_isBilinear R U U' V s s' f.
HB.instance Definition _ := isBilinear.Build R U U' V s s' f
(fun u' => zmod_morphism_linear (bilinear_subproof.1 u'))
(fun u => zmod_morphism_linear (bilinear_subproof.2 u))
(fun u' => scalable_linear (bilinear_subproof.1 u'))
(fun u => scalable_linear (bilinear_subproof.2 u)).
HB.end.
Module BilinearExports.
Module Bilinear.
Section bilinear.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Local Notation bilinear f := (bilinear_for *:%R *:%R f).
Local Notation biscalar f := (bilinear_for *%R *%R f).
(* Support for right-to-left rewriting with the generic linearZ rule. *)
Notation mapUUV := (@Bilinear.type R U U' V s s').
Definition map_class := mapUUV.
Definition map_at_left (a : R) := mapUUV.
Definition map_at_right (b : R) := mapUUV.
Definition map_at_both (a b : R) := mapUUV.
Structure map_for_left a s_a :=
MapForLeft {map_for_left_map : mapUUV; _ : s a = s_a }.
Structure map_for_right b s'_b :=
MapForRight {map_for_right_map : mapUUV; _ : s' b = s'_b }.
Structure map_for_both a b s_a s'_b :=
MapForBoth {map_for_both_map : mapUUV; _ : s a = s_a ; _ : s' b = s'_b }.
Definition unify_map_at_left a (f : map_at_left a) :=
MapForLeft f (erefl (s a)).
Definition unify_map_at_right b (f : map_at_right b) :=
MapForRight f (erefl (s' b)).
Definition unify_map_at_both a b (f : map_at_both a b) :=
MapForBoth f (erefl (s a)) (erefl (s' b)).
Structure wrapped := Wrap {unwrap : mapUUV}.
Definition wrap (f : map_class) := Wrap f.
End bilinear.
End Bilinear.
Notation "{ 'bilinear' U -> V -> W | s & t }" :=
(@Bilinear.type _ U%type V%type W%type s t)
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s & t }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W | s }" :=
({bilinear U -> V -> W | s.1 & s.2})
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W }" := {bilinear U -> V -> W | *:%R & *:%R}
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W }") : ring_scope.
Notation "{ 'biscalar' U }" := {bilinear U%type -> U%type -> _ | *%R & *%R}
(format "{ 'biscalar' U }") : ring_scope.
End BilinearExports.
Export BilinearExports.
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V)
(f : {bilinear U -> U' -> V | s & s'}) (u : U)
:= @GRing.isZmodMorphism.Build U' V (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : @bilinear R U U' V s s') (u : U)
:= @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
Section applyr.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s s' : R -> V -> V).
Definition applyr_head t (f : U -> U' -> V) u v := let: tt := t in f v u.
End applyr.
Notation applyr := (applyr_head tt).
Coercion Bilinear.map_for_left_map : Bilinear.map_for_left >-> Bilinear.type.
Coercion Bilinear.map_for_right_map : Bilinear.map_for_right >-> Bilinear.type.
Coercion Bilinear.map_for_both_map : Bilinear.map_for_both >-> Bilinear.type.
Coercion Bilinear.unify_map_at_left : Bilinear.map_at_left >-> Bilinear.map_for_left.
Coercion Bilinear.unify_map_at_right : Bilinear.map_at_right >-> Bilinear.map_for_right.
Coercion Bilinear.unify_map_at_both : Bilinear.map_at_both >-> Bilinear.map_for_both.
Canonical Bilinear.unify_map_at_left.
Canonical Bilinear.unify_map_at_right.
Canonical Bilinear.unify_map_at_both.
Coercion Bilinear.unwrap : Bilinear.wrapped >-> Bilinear.type.
Coercion Bilinear.wrap : Bilinear.map_class >-> Bilinear.wrapped.
Canonical Bilinear.wrap.
Section BilinearTheory.
Variable R : nzRingType.
Section GenericProperties.
Variables (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V).
Variable f : {bilinear U -> U' -> V | s & s'}.
Section GenericPropertiesr.
Variable z : U.
Lemma linear0r : f z 0 = 0. Proof. by rewrite raddf0. Qed.
Lemma linearNr : {morph f z : x / - x}. Proof. exact: raddfN. Qed.
Lemma linearDr : {morph f z : x y / x + y}. Proof. exact: raddfD. Qed.
Lemma linearBr : {morph f z : x y / x - y}. Proof. exact: raddfB. Qed.
Lemma linearMnr n : {morph f z : x / x *+ n}. Proof. exact: raddfMn. Qed.
Lemma linearMNnr n : {morph f z : x / x *- n}. Proof. exact: raddfMNn. Qed.
Lemma linear_sumr I r (P : pred I) E :
f z (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f z (E i).
Proof. exact: raddf_sum. Qed.
Lemma linearZr_LR : scalable_for s' (f z). Proof. exact: linearZ_LR. Qed.
Lemma linearPr a : {morph f z : u v / a *: u + v >-> s' a u + v}.
Proof. exact: linearP. Qed.
End GenericPropertiesr.
Lemma applyrE x : applyr f x =1 f^~ x. Proof. by []. Qed.
Section GenericPropertiesl.
Variable z : U'.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build _ _ (applyr f z) (@zmod_morphisml_subproof _ _ _ _ _ _ f z).
HB.instance Definition _ :=
GRing.isScalable.Build _ _ _ _ (applyr f z) (@linearl_subproof _ _ _ _ _ _ f z).
Lemma linear0l : f 0 z = 0. Proof. by rewrite -applyrE raddf0. Qed.
Lemma linearNl : {morph f^~ z : x / - x}.
Proof. by move=> ?; rewrite -applyrE raddfN. Qed.
Lemma linearDl : {morph f^~ z : x y / x + y}.
Proof. by move=> ? ?; rewrite -applyrE raddfD. Qed.
Lemma linearBl : {morph f^~ z : x y / x - y}.
Proof. by move=> ? ?; rewrite -applyrE raddfB. Qed.
Lemma linearMnl n : {morph f^~ z : x / x *+ n}.
Proof. by move=> ?; rewrite -applyrE raddfMn. Qed.
Lemma linearMNnl n : {morph f^~ z : x / x *- n}.
Proof. by move=> ?; rewrite -applyrE raddfMNn. Qed.
Lemma linear_sumlz I r (P : pred I) E :
f (\sum_(i <- r | P i) E i) z = \sum_(i <- r | P i) f (E i) z.
Proof. by rewrite -applyrE raddf_sum. Qed.
Lemma linearZl_LR : scalable_for s (f ^~ z).
Proof. by move=> ? ?; rewrite -applyrE linearZ_LR. Qed.
Lemma linearPl a : {morph f^~ z : u v / a *: u + v >-> s a u + v}.
Proof. by move=> ? ?; rewrite -applyrE linearP. Qed.
End GenericPropertiesl.
End GenericProperties.
Section BidirectionalLinearZ.
Variables (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Variables (S : nzRingType) (h : GRing.Scale.law S V) (h' : GRing.Scale.law S V).
Lemma linearZl z (c : S) (a : R) (h_c := h c)
(f : Bilinear.map_for_left U U' s s' a h_c) u :
f (a *: u) z = h_c (Bilinear.wrap f u z).
Proof. by rewrite linearZl_LR; case: f => f /= ->. Qed.
Lemma linearZr z c' b (h'_c' := h' c')
(f : Bilinear.map_for_right U U' s s' b h'_c') u :
f z (b *: u) = h'_c' (Bilinear.wrap f z u).
Proof. by rewrite linearZr_LR; case: f => f /= ->. Qed.
Lemma linearZlr c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h_c (h'_c' (Bilinear.wrap f u v)).
Proof. by rewrite linearZl_LR linearZ_LR; case: f => f /= -> ->. Qed.
Lemma linearZrl c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h'_c' (h_c (Bilinear.wrap f u v)).
Proof. by rewrite linearZ_LR/= linearZl_LR; case: f => f /= -> ->. Qed.
End BidirectionalLinearZ.
End BilinearTheory.
(* TODO
Canonical rev_mulmx (R : nzRingType) m n p := [revop mulmxr of @mulmx R m n p].
*)
(*Canonical mulmx_bilinear (R : comNzRingType) m n p := [bilinear of @mulmx R m n p].*)
Lemma mulmx_is_bilinear (R : comNzRingType) m n p : bilinear_for
(GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _)
(@mulmx R m n p).
Proof.
split=> [u'|u] a x y /=.
- by rewrite mulmxDl scalemxAl.
- by rewrite mulmxDr scalemxAr.
Qed.
HB.instance Definition _ (R : comNzRingType) m n p := bilinear_isBilinear.Build R
[the lmodType R of 'M[R]_(m, n)] [the lmodType R of 'M[R]_(n, p)]
[the zmodType of 'M[R]_(m, p)] _ _ (@mulmx R m n p)
(mulmx_is_bilinear R m n p).
Section BilinearForms.
Variables (R : fieldType) (theta : {rmorphism R -> R}).
Variables (n : nat) (M : 'M[R]_n).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Definition form u v := (u *m M *m (v ^t theta)) 0 0.
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma form0l u : '[0, u] = 0. Proof. by rewrite /form !mul0mx mxE. Qed.
Lemma form0r u : '[u, 0] = 0.
Proof. by rewrite /form trmx0 map_mx0 mulmx0 mxE. Qed.
Lemma formDl u v w : '[u + v, w] = '[u, w] + '[v, w].
Proof. by rewrite /form !mulmxDl mxE. Qed.
Lemma formDr u v w : '[u, v + w] = '[u, v] + '[u, w].
Proof. by rewrite /form linearD !map_mxD !mulmxDr mxE. Qed.
Lemma formZr a u v : '[u, a *: v] = theta a * '[u, v].
Proof. by rewrite /form !(linearZ, map_mxZ) /= mxE. Qed.
Lemma formZl a u v : '[a *: u, v] = a * '[u, v].
Proof.
by do !rewrite /form -[_ *: _ *m _]/(mulmxr _ _) linearZ /=; rewrite mxE.
Qed.
Lemma formNl u v : '[- u, v] = - '[u, v].
Proof. by rewrite -scaleN1r formZl mulN1r. Qed.
Lemma formNr u v : '[u, - v] = - '[u, v].
Proof. by rewrite -scaleN1r formZr rmorphN1 mulN1r. Qed.
Lemma formee i j : '['e_i, 'e_j] = M i j.
Proof.
rewrite /form -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE !mxE.
Qed.
Lemma form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof. by rewrite/form=> -> u v; rewrite mulmx0 mul0mx mxE. Qed.
End BilinearForms.
HB.mixin Record isHermitianSesquilinear (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : U -> U -> R) := {
hermitian_subproof : forall x y : U, f x y = (-1) ^+ eps * theta (f y x)
}.
HB.structure Definition Hermitian (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) :=
{f of @Bilinear R U U _ ( *%R ) (theta \; *%R) f &
@isHermitianSesquilinear R U eps theta f}.
Notation "{ 'hermitian' U 'for' eps & theta }" := (@Hermitian.type _ U eps theta)
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Variables (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R).
Implicit Types phU : phant U.
Local Coercion GRing.Scale.op : GRing.Scale.law >-> Funclass.
Definition axiom (f : U -> U -> R) :=
forall x y : U, f x y = (-1) ^+ eps * theta (f y x).
Record class_of (f : U -> U -> R) : Prop := Class {
base : Bilinear.class_of ( *%R) (theta \; *%R) f;
mixin : axiom f
}.*)
(*Canonical additiver (u : U) := Additive (base class u).
Canonical linearr (u : U) := Linear (base class u).
Canonical additivel (u' : U) := @GRing.Additive.Pack _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical linearl (u' : U) := @GRing.Linear.Pack _ _ _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical bilinear := @Bilinear.Pack _ _ _ _ _ _ (Phant (U -> U -> R)) cF (base class).*)
(*Module Exports.
Notation "{ 'hermitian' U 'for' eps & theta }" := (map eps theta (Phant U))
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
Coercion base : class_of >-> bilmorphism_for.
Coercion apply : map >-> Funclass.
Notation "[ 'hermitian' 'of' f 'as' g ]" := (@clone _ _ _ _ _ _ f g _ idfun idfun)
(format "[ 'hermitian' 'of' f 'as' g ]") : form_scope.
Notation "[ 'hermitian' 'of' f ]" := (@clone _ _ _ _ _ _ f f _ idfun idfun)
(format "[ 'hermitian' 'of' f ]") : form_scope.
Notation hermitian_for := Hermitian.axiom.
Notation Hermitian fM := (pack (Phant _) fM idfun).
Canonical additiver.
Canonical linearr.
Canonical additivel.
Canonical linearl.
Canonical bilinear.
Notation hermapplyr := (@applyr_head _ _ _ _ tt).
End Exports.
End Hermitian.
Include Hermitian.Exports.*)
Definition orthomx {R : fieldType} (theta : R -> R) n m M (B : 'M_(m, n)) : 'M_n :=
kermx (M *m (B ^t theta)).
Section Sesquilinear.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Section Def.
Variable eps_theta : bool * {rmorphism R -> R}.
Definition sesqui :=
[qualify M : 'M_n | M == ((-1) ^+ eps_theta.1) *: M ^t eps_theta.2].
Fact sesqui_key : pred_key sesqui. Proof. by []. Qed.
Canonical sesqui_keyed := KeyedQualifier sesqui_key.
End Def.
Local Notation "eps_theta .-sesqui" := (sesqui eps_theta).
Variables (eps : bool) (theta : {rmorphism R -> R}) (M : 'M[R]_n).
Local Notation "''[' u , v ]" := (form theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma sesquiE : (M \is (eps, theta).-sesqui) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma sesquiP : reflect (M = (-1) ^+ eps *: M ^t theta)
(M \is (eps, theta).-sesqui).
Proof. by rewrite sesquiE; exact/eqP. Qed.
Hypotheses (thetaK : involutive theta) (M_sesqui : M \is (eps, theta).-sesqui).
Lemma trmx_sesqui : M^T = (-1) ^+ eps *: M ^ theta.
Proof.
rewrite [in LHS](sesquiP _) // -mul_scalar_mx trmx_mul.
by rewrite tr_scalar_mx mul_mx_scalar map_trmx trmxK.
Qed.
Lemma maptrmx_sesqui : M^t theta = (-1) ^+ eps *: M.
Proof.
by rewrite trmx_sesqui map_mxZ rmorph_sign -map_mx_comp eq_map_mx_id.
Qed.
Lemma formC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof.
rewrite /form [M in LHS](sesquiP _) // -mulmxA !mxE rmorph_sum mulr_sumr.
apply: eq_bigr => /= i _; rewrite !(mxE, mulr_sumr, mulr_suml, rmorph_sum).
apply: eq_bigr => /= j _; rewrite !mxE !rmorphM mulrCA -!mulrA.
by congr (_ * _); rewrite mulrA mulrC /= thetaK.
Qed.
Lemma form_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite formC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
Definition ortho m (B : 'M_(m, n)) := orthomx theta M B.
Local Notation "B ^_|_" := (ortho B) : ring_scope.
Local Notation "A '_|_ B" := (A%MS <= B^_|_)%MS : ring_scope.
Lemma normalE u v : (u '_|_ v) = ('[u, v] == 0).
Proof.
by rewrite (sameP sub_kermxP eqP) mulmxA [_ *m _^t _]mx11_scalar fmorph_eq0.
Qed.
Lemma form_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v).
Proof. by rewrite normalE; apply/eqP. Qed.
Lemma normalP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), (u <= A)%MS -> (v <= B)%MS -> u '_|_ v)
(A '_|_ B).
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma normalC p q (A : 'M_(p, n)) (B : 'M_(q, n)) : (A '_|_ B) = (B '_|_ A).
Proof.
gen have nC : p q A B / A '_|_ B -> B '_|_ A; last by apply/idP/idP; apply/nC.
move=> AnB; apply/normalP => u v ? ?; rewrite normalE.
rewrite formC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -normalE (normalP _ _ AnB).
Qed.
Lemma normal_ortho_mx p (A : 'M_(p, n)) : ((A^_|_) '_|_ A).
Proof. by []. Qed.
Lemma normal_mx_ortho p (A : 'M_(p, n)) : (A '_|_ (A^_|_)).
Proof. by rewrite normalC. Qed.
Lemma rank_normal u : (\rank (u ^_|_) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Definition rad := 1%:M^_|_.
Lemma rad_ker : rad = kermx M.
Proof. by rewrite /rad /ortho /orthomx trmx1 map_mx1 mulmx1. Qed.
(* Pythagoras *)
Theorem formDd u v : u '_|_ v -> '[u + v] = '[u] + '[v].
Proof.
move=> uNv; rewrite formDl !formDr ['[v, u]]formC.
by rewrite ['[u, v]](form_eq0P _) // rmorph0 mulr0 addr0 add0r.
Qed.
Lemma formZ a u : '[a *: u]= (a * theta a) * '[u].
Proof. by rewrite formZl formZr mulrA. Qed.
Lemma formN u : '[- u] = '[u].
Proof. by rewrite formNr formNl opprK. Qed.
Lemma form_sign m u : '[(-1) ^+ m *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: odd; rewrite ?formN. Qed.
Lemma formD u v : let d := '[u, v] in
'[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite formDl !formDr ['[v, _]]formC [_ + '[v]]addrC addrACA. Qed.
Lemma formB u v : let d := '[u, v] in
'[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof. by rewrite formD formN !formNr rmorphN mulrN -opprD. Qed.
Lemma formBd u v : u '_|_ v -> '[u - v] = '[u] + '[v].
Proof.
by move=> uTv; rewrite formDd ?formN // normalE formNr oppr_eq0 -normalE.
Qed.
(* Lemma formJ u v : '[u ^ theta, v ^ theta] = (-1) ^+ eps * theta '[u, v]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* Lemma formJ u : '[u ^ theta] = (-1) ^+ eps * '[u]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* rewrite !map_mxM. *)
(* rewrite -map_mx_comp eq_map_mx_id //. *)
(* !linearZr_LR /=. linearZ. *)
(* linearZl. *)
(* rewrite trmx_sesqui. *)
(* rewrite mapmx. *)
(* rewrite map *)
(* apply/matrixP. *)
(* rewrite formC. *)
(* Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. *)
(* Lemma cfCauchySchwarz u v : *)
(* `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free (u :: v). *)
(* Proof. *)
(* rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. *)
(* have [-> | nz_v] /= := altP (v =P 0). *)
(* by apply/lerifP; rewrite !cfdot0r normCK mul0r mulr0. *)
(* without loss ou: u / '[u, v] = 0. *)
(* move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. *)
(* have ou: '[u1, v] = 0. *)
(* by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. *)
(* rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. *)
(* rewrite cfdotDl ou add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). *)
(* rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ou mulr0. *)
(* by have:= IHo _ ou; rewrite mulrDl -lerif_subLR subrr ou normCK mul0r. *)
(* rewrite ou normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. *)
(* rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_v) /=. *)
(* apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ou mulr0. *)
(* by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. *)
(* Qed. *)
End Sesquilinear.
Notation "eps_theta .-sesqui" := (sesqui _ eps_theta) : ring_scope.
Notation symmetric_form := (false, idfun).-sesqui.
Notation skew := (true, idfun).-sesqui.
Notation hermitian := (false, @Num.conj_op _).-sesqui.
HB.mixin Record isDotProduct (R : numDomainType) (U : lmodType R)
(op : U -> U -> R) := { neq0_dnorm_gt0 : forall u, u != 0 -> 0 < op u u }.
HB.structure Definition Dot (R : numDomainType) (U : lmodType R)
(theta : R -> R) :=
{op of isDotProduct R U op & @Hermitian R U false theta op}.
Notation "{ 'dot' U 'for' theta }" := (@Dot.type _ U theta)
(format "{ 'dot' U 'for' theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Notation "{ 'dot' U 'for' theta }" := (map theta (Phant U))
(format "{ 'dot' U 'for' theta }") : ring_scope.
Coercion base : class_of >-> Hermitian.class_of.
Coercion apply : map >-> Funclass.
Notation "[ 'dot' 'of' f 'as' g ]" := (@clone _ _ _ _ _ f g _ idfun idfun)
(format "[ 'dot' 'of' f 'as' g ]") : form_scope.
Notation "[ 'dot' 'of' f ]" := (@clone _ _ _ _ _ f f _ idfun idfun)
(format "[ 'dot' 'of' f ]") : form_scope.
Notation Dot fM := (pack fM idfun).
Notation is_dot := Dot.axiom.*)
Notation "{ 'symmetric' U }" := ({hermitian U for false & idfun})
(format "{ 'symmetric' U }") : ring_scope.
Notation "{ 'skew_symmetric' U }" := ({hermitian U for true & idfun})
(format "{ 'skew_symmetric' U }") : ring_scope.
Notation "{ 'hermitian_sym' U 'for' theta }" := ({hermitian U for false & theta})
(format "{ 'hermitian_sym' U 'for' theta }") : ring_scope.
Definition is_skew (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = true) /\ (theta =1 id).
Definition is_sym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false) /\ (theta =1 id).
Definition is_hermsym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false).
Section HermitianModuleTheory.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma hermC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof. by move: form => [? [[? ? ? ?] []]] /=. Qed.
Lemma hnormN u : '[- u] = '[u].
Proof. by rewrite linearNl linearNr opprK. Qed.
Lemma hnorm_sign n u : '[(-1) ^+ n *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?hnormN. Qed.
Lemma hnormD u v :
let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite /= addrAC -hermC linearDl 2!linearDr !addrA. Qed.
Lemma hnormB u v :
let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof.
by rewrite /= hnormD hnormN linearNr addrA rmorphN mulrN opprD addrA.
Qed.
Lemma hnormDd u v : '[u, v] = 0 -> '[u + v] = '[u] + '[v].
Proof. by move=> ouv; rewrite hnormD ouv rmorph0 mulr0 !addr0. Qed.
Lemma hnormBd u v : '[u, v] = 0 -> '[u - v] = '[u] + '[v].
Proof.
by move=> ouv; rewrite hnormDd ?hnormN// linearNr [X in - X]ouv oppr0.
Qed.
Local Notation "u '_|_ v" := ('[u, v] == 0) : ring_scope.
Definition ortho_rec (s1 s2 : seq U) :=
all [pred u | all [pred v | u '_|_ v] s2] s1.
Fixpoint pair_ortho_rec (s : seq U) :=
if s is v :: s' then ortho_rec [:: v] s' && pair_ortho_rec s' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal s := (0 \notin s) && pair_ortho_rec s.
Definition orthogonal s1 s2 := (@ortho_rec s1 s2).
Arguments orthogonal : simpl never.
Lemma orthogonal_cons u us vs :
orthogonal (u :: us) vs = orthogonal [:: u] vs && orthogonal us vs.
Proof. by rewrite /orthogonal /= andbT. Qed.
Definition orthonormal s := all [pred v | '[v] == 1] s && pair_ortho_rec s.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= linear0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
End HermitianModuleTheory.
Arguments orthogonal {R eps theta U} form s1 s2.
Arguments pairwise_orthogonal {R eps theta U} form s.
Arguments orthonormal {R eps theta U} form s.
Section HermitianIsometry.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U1 U2 : lmodType R) (form1 : {hermitian U1 for eps & theta})
(form2 : {hermitian U2 for eps & theta}).
Local Notation "''[' u , v ]_1" := (form1 u%R v%R) : ring_scope.
Local Notation "''[' u , v ]_2" := (form2 u%R v%R) : ring_scope.
Local Notation "''[' u ]_1" := (form1 u%R u%R) : ring_scope.
Local Notation "''[' u ]_2" := (form2 u%R u%R): ring_scope.
Definition isometry tau := forall u v, form1 (tau u) (tau v) = form2 u%R v%R.
Definition isometry_from_to mD tau mR :=
prop_in2 mD (inPhantom (isometry tau)) /\
prop_in1 mD (inPhantom (forall u, in_mem (tau u) mR)).
Local Notation "{ 'in' D , 'isometry' tau , 'to' R }" :=
(isometry_from_to (mem D) tau (mem R))
(format "{ 'in' D , 'isometry' tau , 'to' R }")
: type_scope.
End HermitianIsometry.
Section HermitianVectTheory.
Variables (R : fieldType) (eps : bool) (theta : {rmorphism R -> R}).
Variable (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma herm_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite hermC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
End HermitianVectTheory.
Section HermitianFinVectTheory.
Variables (F : fieldType) (eps : bool) (theta : {rmorphism F -> F}).
Variables (vT : vectType F) (form : {hermitian vT for eps & theta}).
Let n := \dim {:vT}.
Implicit Types (u v : vT) (U V : {vspace vT}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Let alpha v := (linfun (applyr form v : vT -> F^o)).
Definition orthov V := (\bigcap_(i < \dim V) lker (alpha (vbasis V)`_i))%VS.
Local Notation "U '_|_ V" := (U <= orthov V)%VS : vspace_scope.
Lemma mem_orthovPn V u : reflect (exists2 v, v \in V & '[u, v] != 0) (u \notin orthov V).
Proof.
apply: (iffP idP) => [u_orthovV|[v /coord_vbasis-> uvNorthov]]; last first.
apply/subv_bigcapP => uP.
rewrite linear_sumr big1 ?eqxx//= in uvNorthov.
move=> i _; have := uP i isT.
by rewrite -memvE memv_ker lfunE/= linearZr/= => /eqP/= ->; rewrite mulr0.
suff /existsP [i ui_neq0] : [exists i : 'I_(\dim V), '[u, (vbasis V)`_i] != 0].
by exists (vbasis V)`_i => //; rewrite vbasis_mem ?mem_nth ?size_tuple.
apply: contraNT u_orthovV; rewrite negb_exists => /forallP ui_eq0.
apply/subv_bigcapP => i _.
by rewrite -memvE memv_ker lfunE /= -[_ == _]negbK.
Qed.
Lemma mem_orthovP V u : reflect {in V, forall v, '[u, v] = 0} (u \in orthov V).
Proof.
apply: (iffP idP) => [/mem_orthovPn orthovNu v vV|/(_ _ _)/eqP orthov_u].
by apply/eqP/negP=> /negP Northov_uv; apply: orthovNu; exists v.
by apply/mem_orthovPn => -[v /orthov_u->].
Qed.
Lemma orthov1E u : orthov <[u]> = lker (alpha u).
Proof.
apply/eqP; rewrite eqEsubv; apply/andP.
split; apply/subvP=> v; rewrite memv_ker lfunE /=.
by move=> /mem_orthovP-> //; rewrite ?memv_line.
move=> vu_eq0; apply/mem_orthovP => w /vlineP[k->].
by apply/eqP; rewrite linearZ mulf_eq0 vu_eq0 orbT.
Qed.
Lemma orthovP U V : reflect {in U & V, forall u v, '[u, v] = 0} (U '_|_ V)%VS.
Proof.
apply: (iffP subvP); last by move=> H ??; apply/mem_orthovP=> ??; apply: H.
by move=> /(_ _ _)/mem_orthovP; move=> H ????; apply: H.
Qed.
Lemma orthov_sym U V : (U '_|_ V)%VS = (V '_|_ U)%VS.
Proof. by apply/orthovP/orthovP => eq0 ????; apply/eqP; rewrite herm_eq0C eq0. Qed.
Lemma mem_orthov1 v u : (u \in orthov <[v]>) = ('[u, v] == 0).
Proof. by rewrite orthov1E memv_ker lfunE. Qed.
Lemma orthov11 u v : (<[u]> '_|_ <[v]>)%VS = ('[u, v] == 0).
Proof. exact: mem_orthov1. Qed.
Lemma mem_orthov1_sym v u : (u \in orthov <[v]>) = (v \in orthov <[u]>).
Proof. exact: orthov_sym. Qed.
Lemma orthov0 : orthov 0 = fullv.
Proof.
apply/eqP; rewrite eqEsubv subvf.
apply/subvP => x _; rewrite mem_orthov1.
by rewrite linear0r.
Qed.
Lemma mem_orthov_sym V u : (u \in orthov V) = (V <= orthov <[u]>)%VS.
Proof. exact: orthov_sym. Qed.
Lemma leq_dim_orthov1 u V : ((\dim V).-1 <= \dim (V :&: orthov <[u]>))%N.
Proof.
rewrite -(limg_ker_dim (alpha u) V) -orthov1E.
have := dimvS (subvf (alpha u @: V)); rewrite dimvf addnC.
by case: (\dim _) => [|[]] // _; rewrite leq_pred.
Qed.
Lemma dim_img_form_eq1 u V : u \notin orthov V -> \dim (alpha u @: V)%VS = 1%N.
Proof.
move=> /mem_orthovPn [v vV Northov_uv]; apply/eqP; rewrite eqn_leq /=.
rewrite -[1%N as X in (_ <= X)%N](dimvf [the vectType F of F^o]) dimvS ?subvf//=.
have := @dimvS _ _ <['[v, u] : F^o]> (alpha u @: V).
rewrite -memvE dim_vline herm_eq0C Northov_uv; apply.
by apply/memv_imgP; exists v; rewrite ?memvf// !lfunE /=.
Qed.
Lemma eq_dim_orthov1 u V : u \notin orthov V -> (\dim V).-1 = \dim (V :&: orthov <[u]>).
Proof.
rewrite -(limg_ker_dim (alpha u) V) => /dim_img_form_eq1->.
by rewrite -orthov1E addn1.
Qed.
Lemma dim_img_form_eq0 u V : u \in orthov V -> \dim (alpha u @: V)%VS = 0%N.
Proof. by move=> uV; apply/eqP; rewrite dimv_eq0 -lkerE -orthov1E orthov_sym. Qed.
Lemma neq_dim_orthov1 u V : (\dim V > 0)%N ->
u \in orthov V -> ((\dim V).-1 < \dim (V :&: orthov <[u]>))%N.
Proof.
move=> V_gt0; rewrite -(limg_ker_dim (alpha u) V) -orthov1E => u_in.
rewrite dim_img_form_eq0 // addn0 (capv_idPl _) 1?orthov_sym //.
by case: (\dim _) V_gt0.
Qed.
Lemma leqif_dim_orthov1 u V : (\dim V > 0)%N ->
((\dim V).-1 <= \dim (V :&: orthov <[u]>) ?= iff (u \notin orthov V))%N.
Proof.
move=> Vr_gt0; apply/leqifP.
by case: (boolP (u \in _)) => /= [/neq_dim_orthov1->|/eq_dim_orthov1->].
Qed.
Lemma leqif_dim_orthov1_full u : (n > 0)%N ->
((\dim {:vT}).-1 <= \dim (orthov <[u]>) ?= iff (u \notin orthov fullv))%N.
Proof.
by move=> n_gt0; have := @leqif_dim_orthov1 u fullv; rewrite capfv; apply.
Qed.
(* Link between orthov and orthovgonality of sequences *)
Lemma orthogonal1P u v : reflect ('[u, v] = 0) (orthogonal form [:: u] [:: v]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP us vs :
reflect {in us & vs, forall u v, '[u, v] = 0} (orthogonal form us vs).
Proof.
apply: (iffP allP) => ousvs u => [v /ousvs/allP opus /opus/eqP // | /ousvs opus].
by apply/allP=> v /= /opus->.
Qed.
Lemma orthogonal_oppr S R : orthogonal form S (map -%R R) = orthogonal form S R.
Proof.
wlog suffices IH: S R / orthogonal form S R -> orthogonal form S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite linearNr /= oSR ?oppr0.
Qed.
Lemma orthogonalE us vs : (orthogonal form us vs) = (<<us>> '_|_ <<vs>>)%VS.
Proof.
apply/orthogonalP/orthovP => uvsP u v; last first.
by move=> uus vvs; rewrite uvsP // memv_span.
rewrite -[us]in_tupleE -[vs]in_tupleE => /coord_span-> /coord_span->.
rewrite linear_sumr big1 //= => i _.
rewrite linear_sumlz big1 //= => j _.
by rewrite linearZlr/= uvsP ?mulr0// mem_nth.
Qed.
Lemma orthovE U V : (U '_|_ V)%VS = orthogonal form (vbasis U) (vbasis V).
Proof. by rewrite orthogonalE !(span_basis (vbasisP _)). Qed.
Notation radv := (orthov fullv).
Lemma orthoDv U V W : (U + V '_|_ W)%VS = (U '_|_ W)%VS && (V '_|_ W)%VS.
Proof. by rewrite subv_add. Qed.
Lemma orthovD U V W : (U '_|_ V + W)%VS = (U '_|_ V)%VS && (U '_|_ W)%VS.
Proof. by rewrite ![(U '_|_ _)%VS]orthov_sym orthoDv. Qed.
Definition nondegenerate := radv == 0%VS.
Definition is_psymplectic := [/\ nondegenerate, is_skew form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_porthogonal := [/\ nondegenerate, is_sym form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_unitary := nondegenerate /\ (is_hermsym form).
End HermitianFinVectTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use is_psymplectic instead.")]
Notation is_symplectic := is_psymplectic (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use is_porthogonal instead.")]
Notation is_orthogonal := is_porthogonal (only parsing).
Arguments orthogonalP {F eps theta vT form us vs}.
Arguments orthovP {F eps theta vT form U V}.
Arguments mem_orthovPn {F eps theta vT form V u}.
Arguments mem_orthovP {F eps theta vT form V u}.
Section DotVectTheory.
Variables (C : numClosedFieldType).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma dnorm_geiff0 u : 0 <= '[u] ?= iff (u == 0).
Proof.
by apply/leifP; have [->|uN0] := altP eqP; rewrite ?linear0r ?neq0_dnorm_gt0.
Qed.
Lemma dnorm_ge0 u : 0 <= '[u]. Proof. by rewrite dnorm_geiff0. Qed.
Lemma dnorm_eq0 u : ('[u] == 0) = (u == 0).
Proof. by rewrite -dnorm_geiff0 eq_sym. Qed.
Lemma dnorm_gt0 u : (0 < '[u]) = (u != 0).
Proof. by rewrite lt_def dnorm_eq0 dnorm_ge0 andbT. Qed.
Lemma sqrt_dnorm_ge0 u : 0 <= sqrtC '[u].
Proof. by rewrite sqrtC_ge0 dnorm_ge0. Qed.
Lemma sqrt_dnorm_eq0 u : (sqrtC '[u] == 0) = (u == 0).
Proof. by rewrite sqrtC_eq0 dnorm_eq0. Qed.
Lemma sqrt_dnorm_gt0 u : (sqrtC '[u] > 0) = (u != 0).
Proof. by rewrite sqrtC_gt0 dnorm_gt0. Qed.
Lemma dnormZ a u : '[a *: u]= `|a| ^+ 2 * '[u].
Proof. by rewrite linearZl_LR linearZr_LR/= mulrA normCK. Qed.
Lemma dnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + d^*).
Proof. by rewrite hnormD mul1r. Qed.
Lemma dnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + d^*).
Proof. by rewrite hnormB mul1r. Qed.
End DotVectTheory.
#[global]
Hint Extern 0 (is_true (0 <= Dot.sort _ _ _
(* NB: This Hint is assuming ^*, a more precise pattern would be welcome *)))
=> apply: dnorm_ge0 : core.
Section HermitianTheory.
Variables (C : numClosedFieldType) (eps : bool) (theta : {rmorphism C -> C}).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal form S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi {}/IH IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?dnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi; rewrite !inE => /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
apply/eqP; rewrite hermC.
by move: (opS psi Spsi) => /= /eqP ->; rewrite rmorph0 mulr0.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal form (R ++ S) =
[&& pairwise_orthogonal form R, pairwise_orthogonal form S & orthogonal form R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT// all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma orthonormal_cat R S :
orthonormal form (R ++ S) =
[&& orthonormal form R, orthonormal form S & orthogonal form R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi] = (phi == psi)%:R})
(orthonormal form S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := altP eqP.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // linear0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal form S2 -> orthonormal form S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal form [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
End HermitianTheory.
Section DotFinVectTheory.
Variable C : numClosedFieldType.
Variables (U : vectType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal form S2 -> pairwise_orthogonal form S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal form S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0] = 0 := linear0r _ _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite linearZ /= oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 linearZ mulf_eq0 conjC_eq0 dnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal form S -> pairwise_orthogonal form (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_free S : orthonormal form S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Theorem CauchySchwarz (u v : U) :
`|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] /= := altP (v =P 0).
by apply/leifP; rewrite /= !linear0r normCK mul0r mulr0.
without loss ou: u / '[u, v] = 0.
move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v.
have ou: '[u1, v] = 0.
rewrite linearBl/=.
rewrite linearZl_LR.
by rewrite divfK ?dnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //.
rewrite linearDl /= ou add0r.
rewrite linearZl_LR/= normrM (ger0_norm (dnorm_ge0 _ _)).
rewrite exprMn mulrA -dnormZ hnormDd/=; last by rewrite linearZr_LR/= ou mulr0.
have:= IHo _ ou.
by rewrite mulrDl -leifBLR subrr ou normCK mul0r.
rewrite ou normCK mul0r; split; first by rewrite mulr_ge0.
rewrite eq_sym mulf_eq0 orbC dnorm_eq0 (negPf nz_v) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite linearZr_LR/= ou mulr0.
by rewrite dnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma CauchySchwarz_sqrt u v :
`|'[u, v]| <= sqrtC '[u] * sqrtC '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?nnegrE//.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM//= ?nnegrE//=.
exact: CauchySchwarz.
Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal form [:: phi] [:: psi]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal form [:: phi] S).
Proof.
by rewrite [orthogonal form _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (orthogonal form).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite hermC /= oRS ?rmorph0 ?mulr0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal form S [:: psi]).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite hermC /= oSpsi //= conjC0 mulr0.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal form (R1 ++ R2) S = orthogonal form R1 S && orthogonal form R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal form R (S1 ++ S2) = orthogonal form R S1 && orthogonal form R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal form R = pairwise_orthogonal form S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal S0 S : perm_eq S0 S -> orthonormal form S0 = orthonormal form S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthogonal_oppl S R : orthogonal form (map -%R S) R = orthogonal form S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma triangle_lerif u v :
sqrtC '[u + v] <= sqrtC '[u] + sqrtC '[v]
?= iff ~~ free [:: u; v] && (0 <= coord [tuple v] 0 u).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?nnegrE ?sqrtC_ge0//.
rewrite andbC sqrrD !sqrtCK addrAC dnormD (mono_leif (lerD2l _))/=.
rewrite -mulr_natr -[_ + _](divfK (negbT (pnatr_eq0 C 2))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n//.
have := leif_trans (leif_Re_Creal '[u, v]) (CauchySchwarz_sqrt u v).
rewrite ReE; congr (_ <= _ ?= iff _); apply: andb_id2r.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] := altP (v =P 0); first by rewrite linear0 coord0.
case/vlineP=> [x ->]; rewrite linearZl linearZ/= pmulr_lge0 ?dnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal form S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite linear_sumlz big1 // => i _; rewrite linear_sumr big1 // => j _.
by rewrite linearZlr/= oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : U & X \in <<S>>%VS &
{Y :U | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal form [:: Y] S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal form [:: Y] S}}.
- exists X => //; exists Y.
by rewrite hermC /= (span_orthogonal oYS) ?memv_span1 ?conjC0 // mulr0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[UU S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr UU V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi; rewrite !inE => /predU1P[-> | Spsi]; last first.
by rewrite linearBl linearZl_LR /= (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite linearBl !linearDr /= (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !linearZl_LR /= (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite linear0r !mul0r subrr.
by rewrite divfK ?dnorm_eq0 ?subrr.
Qed.
End DotFinVectTheory.
Arguments orthoP {C U form phi psi}.
Arguments pairwise_orthogonalP {C U form S}.
Arguments orthonormalP {C U form S}.
Arguments orthoPl {C U form phi S}.
Arguments orthoPr {C U form S psi}.
Section BuildIsometries.
Variables (C : numClosedFieldType) (U U1 U2 : vectType C).
Variables (form : {dot U for conjC}) (form1 : {dot U1 for conjC})
(form2 : {dot U2 for conjC}).
Definition normf1 := fun u => form1 u u.
Definition normf2 := fun u => form2 u u.
Lemma isometry_of_dnorm S tauS :
pairwise_orthogonal form1 S -> pairwise_orthogonal form2 tauS ->
map normf2 tauS = map normf1 S ->
{tau : {linear U1 -> U2} | map tau S = tauS
& {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite !linearZ/= !linear_sumlz; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !linearZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite /= -[RHS](nth_map 0 0 normf1) -?[LHS](nth_map 0 0 normf2) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry form2 form1 f} ->
{tau : {linear U1 -> U2} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have {}Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _] /=.
rewrite 2!{1}linear_sum /= !{1}linear_sumlz /=; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}linear_sumr; apply/eq_big_seq=> xi2 Sxi2 /=.
by rewrite !linearZ /= !linearZl !Dtau //= If.
Qed.
Lemma isometry_raddf_inj (tau : {additive U1 -> U2}) :
{in U1 &, isometry form2 form1 tau} ->
{in U1 &, forall u v, u - v \in U1} ->
{in U1 &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -(dnorm_eq0 form2) Itau ?linU // dnorm_eq0 subr_eq0 => /eqP.
Qed.
End BuildIsometries.
Section MatrixForms.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (M N P Q : 'M[R]_n).
Section Def.
Variable theta : R -> R.
Definition form_of_matrix m M (U V : 'M_(m, n)) := \tr (U *m M *m (V ^t theta)).
Definition matrix_of_form (form : 'rV[R]_n -> 'rV[R]_n -> R) : 'M[R]_n :=
\matrix_(i, j) form 'e_i 'e_j.
Implicit Type form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formE form i j : matrix_of_form form i j = form 'e_i 'e_j.
Proof. by rewrite mxE. Qed.
End Def.
Section FormOfMatrix.
Variables (m : nat) (M : 'M[R]_n).
Implicit Types (U V : 'M[R]_(m, n)).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' U , V ]" := (form_of_matrix theta M U%R V%R) : ring_scope.
Local Notation "''[' U ]" := '[U, U]%R : ring_scope.
Let form_of_matrix_is_linear U :
linear_for (theta \; *%R) (form_of_matrix theta M U).
Proof.
rewrite /form_of_matrix => k v w; rewrite -linearP/=.
by rewrite linearP map_mxD map_mxZ !mulmxDr !scalemxAr.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrix theta M U) (form_of_matrix_is_linear U).
Definition form_of_matrixr U := (form_of_matrix theta M)^~U.
Let form_of_matrixr_is_linear U : linear_for *%R (form_of_matrixr U).
Proof.
rewrite /form_of_matrixr /form_of_matrix => k v w.
by rewrite -linearP /= !mulmxDl -!scalemxAl.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrixr U) (form_of_matrixr_is_linear U).
(* TODO
Canonical form_of_matrixr_rev :=
[revop form_of_matrixr of form_of_matrix theta M].
*)
Lemma form_of_matrix_is_bilinear :
bilinear_for
(GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M).
Proof.
split=> [u'|u] a x y /=.
- by rewrite /form_of_matrix !mulmxDl linearD/= -!scalemxAl linearZ.
- rewrite /form_of_matrix -linearZ/= -linearD/= [in LHS]linearD/= map_mxD.
rewrite mulmxDr; congr (\tr (_ + _)).
rewrite scalemxAr; congr (_ *m _).
by rewrite linearZ/= map_mxZ.
Qed.
HB.instance Definition _ :=
bilinear_isBilinear.Build R _ _ _
(GRing.Scale.Law.clone _ _ ( *%R ) _)
(GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M)
form_of_matrix_is_bilinear.
(*Canonical form_of_matrix_is_bilinear := [the @bilinear _ _ _ _ of form_of_matrix theta M].*)
End FormOfMatrix.
Section FormOfMatrix1.
Variables (M : 'M[R]_n).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma rV_formee i j : '['e_i :'rV__, 'e_j] = M i j.
Proof.
rewrite /form_of_matrix -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE trace_mx11 !mxE.
Qed.
Lemma form_of_matrixK : matrix_of_form (form_of_matrix theta M) = M.
Proof. by apply/matrixP => i j; rewrite !mxE rV_formee. Qed.
Lemma rV_form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof.
by rewrite /form_of_matrix => -> u v; rewrite mulmx0 mul0mx trace_mx11 mxE.
Qed.
End FormOfMatrix1.
Section MatrixOfForm.
Variable (theta : {rmorphism R -> R}).
Variable form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formK : form_of_matrix theta (matrix_of_form form) =2 form.
Proof.
set f := (X in X =2 _); have f_eq i j : f 'e_i 'e_j = form 'e_i 'e_j.
by rewrite /f rV_formee mxE.
move=> u v; rewrite [u]row_sum_delta [v]row_sum_delta /f.
rewrite !linear_sum/=; apply: eq_bigr => j _.
rewrite !linear_sumlz/=; apply: eq_bigr => i _.
by rewrite !linearZlr/= -f_eq.
Qed.
End MatrixOfForm.
Section HermitianMx.
Variable eps : bool.
Section HermitianMxDef.
Variable theta : R -> R.
Definition hermitianmx :=
[qualify M : 'M_n | M == ((-1) ^+ eps) *: M ^t theta].
Fact hermitianmx_key : pred_key hermitianmx. Proof. by []. Qed.
Canonical hermitianmx_keyed := KeyedQualifier hermitianmx_key.
Structure hermitian_matrix := HermitianMx {
mx_of_hermitian :> 'M[R]_n;
_ : mx_of_hermitian \is hermitianmx }.
Lemma is_hermitianmxE M :
(M \is hermitianmx) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma is_hermitianmxP M :
reflect (M = (-1) ^+ eps *: M ^t theta) (M \is hermitianmx).
Proof. by rewrite is_hermitianmxE; apply/eqP. Qed.
Lemma hermitianmxE (M : hermitian_matrix) :
M = ((-1) ^+ eps) *: M ^t theta :> 'M__.
Proof. by apply/eqP; case: M. Qed.
Lemma trmx_hermitian (M : hermitian_matrix) :
M^T = ((-1) ^+ eps) *: M ^ theta :> 'M__.
Proof. by rewrite {1}hermitianmxE linearZ /= map_trmx trmxK. Qed.
End HermitianMxDef.
Section HermitianMxTheory.
Variables (theta : involutive_rmorphism R) (M : hermitian_matrix theta).
Lemma maptrmx_hermitian : M^t theta = (-1) ^+ eps *: (M : 'M__).
Proof.
rewrite trmx_hermitian map_mxZ rmorph_sign -map_mx_comp.
by rewrite (map_mx_id (rmorphK _)).
Qed.
Lemma form_of_matrix_is_hermitian m x y :
(@form_of_matrix theta m M) x y =
(-1) ^+ eps * theta ((@form_of_matrix theta m M) y x).
Proof.
rewrite {1}hermitianmxE /form_of_matrix.
rewrite -!(scalemxAr, scalemxAl) linearZ/=; congr (_ * _).
rewrite -mxtrace_tr -trace_map_mx !(trmx_mul, map_mxM, map_trmx, trmxK).
by rewrite -mulmxA -!map_mx_comp !(map_mx_id (rmorphK _)).
Qed.
HB.instance Definition _ m := @isHermitianSesquilinear.Build _ _ _ _ _
(@form_of_matrix_is_hermitian m).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Local Notation "B ^!" := (orthomx theta M B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B%MS^!)%MS : matrix_set_scope.
Lemma orthomxE u v : (u '_|_ v)%MS = ('[u, v] == 0).
Proof.
rewrite (sameP sub_kermxP eqP) mulmxA.
by rewrite [_ *m _^t _]mx11_scalar -trace_mx11 fmorph_eq0.
Qed.
Lemma hermmx_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v)%MS.
Proof. by rewrite orthomxE; apply/eqP. Qed.
Lemma orthomxP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), u <= A -> v <= B -> u '_|_ v)%MS
(A '_|_ B)%MS.
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma orthomx_sym p q (A : 'M_(p, n)) (B :'M_(q, n)) :
(A '_|_ B)%MS = (B '_|_ A)%MS.
Proof.
gen have nC : p q A B / (A '_|_ B -> B '_|_ A)%MS; last by apply/idP/idP; apply/nC.
move=> AnB; apply/orthomxP => u v ? ?; rewrite orthomxE.
rewrite hermC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -orthomxE (orthomxP _ _ AnB).
Qed.
Lemma ortho_ortho_mx p (A : 'M_(p, n)) : (A^! '_|_ A)%MS. Proof. by []. Qed.
Lemma ortho_mx_ortho p (A : 'M_(p, n)) : (A '_|_ A^!)%MS.
Proof. by rewrite orthomx_sym. Qed.
Lemma rank_orthomx u : (\rank (u ^!) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Local Notation radmx := (1%:M^!)%MS.
Lemma radmxE : radmx = kermx M.
Proof. by rewrite /orthomx /orthomx trmx1 map_mx1 mulmx1. Qed.
Lemma orthoNmx k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
((- A) '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by rewrite eqmx_opp. Qed.
Lemma orthomxN k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
(A '_|_ (- B))%MS = (A '_|_ B)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoNmx. Qed.
Lemma orthoDmx k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A + B '_|_ C)%MS = (A '_|_ C)%MS && (B '_|_ C)%MS.
Proof. by rewrite addsmxE !(sameP sub_kermxP eqP) mul_col_mx col_mx_eq0. Qed.
Lemma orthomxD k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A '_|_ B + C)%MS = (A '_|_ B)%MS && (A '_|_ C)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoDmx. Qed.
Lemma orthoZmx p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(a *: A '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite eqmx_scale. Qed.
Lemma orthomxZ p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(A '_|_ (a *: B))%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite ![(A '_|_ _)%MS]orthomx_sym orthoZmx. Qed.
Lemma eqmx_ortho p m (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) :
(A :=: B)%MS -> (A^! :=: B^!)%MS.
Proof.
move=> eqAB; apply/eqmxP.
by rewrite orthomx_sym -eqAB ortho_mx_ortho orthomx_sym eqAB ortho_mx_ortho.
Qed.
Lemma genmx_ortho p (A : 'M[R]_(p, n)) : (<<A>>^! :=: A^!)%MS.
Proof. exact: (eqmx_ortho (genmxE _)). Qed.
End HermitianMxTheory.
End HermitianMx.
End MatrixForms.
Notation symmetricmx := (hermitianmx _ false idfun).
Notation skewmx := (hermitianmx _ true idfun).
Notation hermsymmx := (hermitianmx _ false conjC).
Lemma hermitian1mx_subproof {C : numClosedFieldType} n : (1%:M : 'M[C]_n) \is hermsymmx.
Proof.
by rewrite qualifE /= expr0 scale1r tr_scalar_mx map_scalar_mx conjC1.
Qed.
Canonical hermitian1mx {C : numClosedFieldType} n :=
HermitianMx (@hermitian1mx_subproof C n).
|
Lattice.lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Floris van Doorn, Yaël Dillies
-/
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Data.Set.Lattice.Image
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Indexed unions and intersections of pointwise operations of sets
This file contains lemmas on taking the union and intersection over pointwise algebraic operations
on sets.
## Tags
set multiplication, set addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
assert_not_exists MulAction MonoidWithZero OrderedAddCommMonoid
open Function MulOpposite
variable {F α β γ : Type*}
namespace Set
/-! ### Set negation/inversion -/
section Inv
open Pointwise
variable {ι : Sort*} [Inv α]
@[to_additive (attr := simp)]
theorem iInter_inv (s : ι → Set α) : (⋂ i, s i)⁻¹ = ⋂ i, (s i)⁻¹ :=
preimage_iInter
@[to_additive (attr := simp)]
theorem sInter_inv (S : Set (Set α)) : (⋂₀ S)⁻¹ = ⋂ s ∈ S, s⁻¹ :=
preimage_sInter
@[to_additive (attr := simp)]
theorem iUnion_inv (s : ι → Set α) : (⋃ i, s i)⁻¹ = ⋃ i, (s i)⁻¹ :=
preimage_iUnion
@[to_additive (attr := simp)]
theorem sUnion_inv (S : Set (Set α)) : (⋃₀ S)⁻¹ = ⋃ s ∈ S, s⁻¹ :=
preimage_sUnion
end Inv
open Pointwise
/-! ### Set addition/multiplication -/
section Mul
variable {ι : Sort*} {κ : ι → Sort*} [Mul α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α}
@[to_additive]
theorem iUnion_mul_left_image : ⋃ a ∈ s, (a * ·) '' t = s * t :=
iUnion_image_left _
@[to_additive]
theorem iUnion_mul_right_image : ⋃ a ∈ t, (· * a) '' s = s * t :=
iUnion_image_right _
@[to_additive]
theorem iUnion_mul (s : ι → Set α) (t : Set α) : (⋃ i, s i) * t = ⋃ i, s i * t :=
image2_iUnion_left ..
@[to_additive]
theorem mul_iUnion (s : Set α) (t : ι → Set α) : (s * ⋃ i, t i) = ⋃ i, s * t i :=
image2_iUnion_right ..
@[to_additive]
theorem sUnion_mul (S : Set (Set α)) (t : Set α) : ⋃₀ S * t = ⋃ s ∈ S, s * t :=
image2_sUnion_left ..
@[to_additive]
theorem mul_sUnion (s : Set α) (T : Set (Set α)) : s * ⋃₀ T = ⋃ t ∈ T, s * t :=
image2_sUnion_right ..
@[to_additive]
theorem iUnion₂_mul (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) * t = ⋃ (i) (j), s i j * t :=
image2_iUnion₂_left ..
@[to_additive]
theorem mul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s * ⋃ (i) (j), t i j) = ⋃ (i) (j), s * t i j :=
image2_iUnion₂_right ..
@[to_additive]
theorem iInter_mul_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) * t ⊆ ⋂ i, s i * t :=
Set.image2_iInter_subset_left ..
@[to_additive]
theorem mul_iInter_subset (s : Set α) (t : ι → Set α) : (s * ⋂ i, t i) ⊆ ⋂ i, s * t i :=
image2_iInter_subset_right ..
@[to_additive]
lemma mul_sInter_subset (s : Set α) (T : Set (Set α)) :
s * ⋂₀ T ⊆ ⋂ t ∈ T, s * t := image2_sInter_right_subset s T (fun a b => a * b)
@[to_additive]
lemma sInter_mul_subset (S : Set (Set α)) (t : Set α) :
⋂₀ S * t ⊆ ⋂ s ∈ S, s * t := image2_sInter_left_subset S t (fun a b => a * b)
@[to_additive]
theorem iInter₂_mul_subset (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) * t ⊆ ⋂ (i) (j), s i j * t :=
image2_iInter₂_subset_left ..
@[to_additive]
theorem mul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) :
(s * ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s * t i j :=
image2_iInter₂_subset_right ..
end Mul
/-! ### Set subtraction/division -/
section Div
variable {ι : Sort*} {κ : ι → Sort*} [Div α] {s s₁ s₂ t t₁ t₂ u : Set α} {a b : α}
@[to_additive]
theorem iUnion_div_left_image : ⋃ a ∈ s, (a / ·) '' t = s / t :=
iUnion_image_left _
@[to_additive]
theorem iUnion_div_right_image : ⋃ a ∈ t, (· / a) '' s = s / t :=
iUnion_image_right _
@[to_additive]
theorem iUnion_div (s : ι → Set α) (t : Set α) : (⋃ i, s i) / t = ⋃ i, s i / t :=
image2_iUnion_left ..
@[to_additive]
theorem div_iUnion (s : Set α) (t : ι → Set α) : (s / ⋃ i, t i) = ⋃ i, s / t i :=
image2_iUnion_right ..
@[to_additive]
theorem sUnion_div (S : Set (Set α)) (t : Set α) : ⋃₀ S / t = ⋃ s ∈ S, s / t :=
image2_sUnion_left ..
@[to_additive]
theorem div_sUnion (s : Set α) (T : Set (Set α)) : s / ⋃₀ T = ⋃ t ∈ T, s / t :=
image2_sUnion_right ..
@[to_additive]
theorem iUnion₂_div (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) / t = ⋃ (i) (j), s i j / t :=
image2_iUnion₂_left ..
@[to_additive]
theorem div_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s / ⋃ (i) (j), t i j) = ⋃ (i) (j), s / t i j :=
image2_iUnion₂_right ..
@[to_additive]
theorem iInter_div_subset (s : ι → Set α) (t : Set α) : (⋂ i, s i) / t ⊆ ⋂ i, s i / t :=
image2_iInter_subset_left ..
@[to_additive]
theorem div_iInter_subset (s : Set α) (t : ι → Set α) : (s / ⋂ i, t i) ⊆ ⋂ i, s / t i :=
image2_iInter_subset_right ..
@[to_additive]
theorem sInter_div_subset (S : Set (Set α)) (t : Set α) : ⋂₀ S / t ⊆ ⋂ s ∈ S, s / t :=
image2_sInter_subset_left ..
@[to_additive]
theorem div_sInter_subset (s : Set α) (T : Set (Set α)) : s / ⋂₀ T ⊆ ⋂ t ∈ T, s / t :=
image2_sInter_subset_right ..
@[to_additive]
theorem iInter₂_div_subset (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) / t ⊆ ⋂ (i) (j), s i j / t :=
image2_iInter₂_subset_left ..
@[to_additive]
theorem div_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set α) :
(s / ⋂ (i) (j), t i j) ⊆ ⋂ (i) (j), s / t i j :=
image2_iInter₂_subset_right ..
end Div
/-! ### Translation/scaling of sets -/
section SMul
variable {ι : Sort*} {κ : ι → Sort*} [SMul α β] {s s₁ s₂ : Set α} {t t₁ t₂ u : Set β} {a : α}
{b : β}
@[to_additive] lemma iUnion_smul_left_image : ⋃ a ∈ s, a • t = s • t := iUnion_image_left _
@[to_additive]
lemma iUnion_smul_right_image : ⋃ a ∈ t, (· • a) '' s = s • t := iUnion_image_right _
@[to_additive]
lemma iUnion_smul (s : ι → Set α) (t : Set β) : (⋃ i, s i) • t = ⋃ i, s i • t :=
image2_iUnion_left ..
@[to_additive]
lemma smul_iUnion (s : Set α) (t : ι → Set β) : (s • ⋃ i, t i) = ⋃ i, s • t i :=
image2_iUnion_right ..
@[to_additive]
lemma sUnion_smul (S : Set (Set α)) (t : Set β) : ⋃₀ S • t = ⋃ s ∈ S, s • t :=
image2_sUnion_left ..
@[to_additive]
lemma smul_sUnion (s : Set α) (T : Set (Set β)) : s • ⋃₀ T = ⋃ t ∈ T, s • t :=
image2_sUnion_right ..
@[to_additive]
lemma iUnion₂_smul (s : ∀ i, κ i → Set α) (t : Set β) :
(⋃ i, ⋃ j, s i j) • t = ⋃ i, ⋃ j, s i j • t := image2_iUnion₂_left ..
@[to_additive]
lemma smul_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set β) :
(s • ⋃ i, ⋃ j, t i j) = ⋃ i, ⋃ j, s • t i j := image2_iUnion₂_right ..
@[to_additive]
lemma iInter_smul_subset (s : ι → Set α) (t : Set β) : (⋂ i, s i) • t ⊆ ⋂ i, s i • t :=
image2_iInter_subset_left ..
@[to_additive]
lemma smul_iInter_subset (s : Set α) (t : ι → Set β) : (s • ⋂ i, t i) ⊆ ⋂ i, s • t i :=
image2_iInter_subset_right ..
@[to_additive]
lemma sInter_smul_subset (S : Set (Set α)) (t : Set β) : ⋂₀ S • t ⊆ ⋂ s ∈ S, s • t :=
image2_sInter_left_subset S t (fun a x => a • x)
@[to_additive]
lemma smul_sInter_subset (s : Set α) (T : Set (Set β)) : s • ⋂₀ T ⊆ ⋂ t ∈ T, s • t :=
image2_sInter_right_subset s T (fun a x => a • x)
@[to_additive]
lemma iInter₂_smul_subset (s : ∀ i, κ i → Set α) (t : Set β) :
(⋂ i, ⋂ j, s i j) • t ⊆ ⋂ i, ⋂ j, s i j • t := image2_iInter₂_subset_left ..
@[to_additive]
lemma smul_iInter₂_subset (s : Set α) (t : ∀ i, κ i → Set β) :
(s • ⋂ i, ⋂ j, t i j) ⊆ ⋂ i, ⋂ j, s • t i j := image2_iInter₂_subset_right ..
@[to_additive (attr := simp)]
lemma iUnion_smul_set (s : Set α) (t : Set β) : ⋃ a ∈ s, a • t = s • t := iUnion_image_left _
end SMul
section SMulSet
variable {ι : Sort*} {κ : ι → Sort*} [SMul α β] {s t t₁ t₂ : Set β} {a : α} {b : β} {x y : β}
@[to_additive]
lemma smul_set_iUnion (a : α) (s : ι → Set β) : a • ⋃ i, s i = ⋃ i, a • s i :=
image_iUnion
@[to_additive]
lemma smul_set_iUnion₂ (a : α) (s : ∀ i, κ i → Set β) :
a • ⋃ i, ⋃ j, s i j = ⋃ i, ⋃ j, a • s i j := image_iUnion₂ ..
@[to_additive]
lemma smul_set_sUnion (a : α) (S : Set (Set β)) : a • ⋃₀ S = ⋃ s ∈ S, a • s := by
rw [sUnion_eq_biUnion, smul_set_iUnion₂]
@[to_additive]
lemma smul_set_iInter_subset (a : α) (t : ι → Set β) : a • ⋂ i, t i ⊆ ⋂ i, a • t i :=
image_iInter_subset ..
@[to_additive]
lemma smul_set_sInter_subset (a : α) (S : Set (Set β)) :
a • ⋂₀ S ⊆ ⋂ s ∈ S, a • s := image_sInter_subset ..
@[to_additive]
lemma smul_set_iInter₂_subset (a : α) (t : ∀ i, κ i → Set β) :
a • ⋂ i, ⋂ j, t i j ⊆ ⋂ i, ⋂ j, a • t i j := image_iInter₂_subset ..
end SMulSet
variable {s : Set α} {t : Set β} {a : α} {b : β}
section VSub
variable {ι : Sort*} {κ : ι → Sort*} [VSub α β] {s s₁ s₂ t t₁ t₂ : Set β} {u : Set α} {a : α}
{b c : β}
lemma iUnion_vsub_left_image : ⋃ a ∈ s, (a -ᵥ ·) '' t = s -ᵥ t := iUnion_image_left _
lemma iUnion_vsub_right_image : ⋃ a ∈ t, (· -ᵥ a) '' s = s -ᵥ t := iUnion_image_right _
lemma iUnion_vsub (s : ι → Set β) (t : Set β) : (⋃ i, s i) -ᵥ t = ⋃ i, s i -ᵥ t :=
image2_iUnion_left ..
lemma vsub_iUnion (s : Set β) (t : ι → Set β) : (s -ᵥ ⋃ i, t i) = ⋃ i, s -ᵥ t i :=
image2_iUnion_right ..
lemma sUnion_vsub (S : Set (Set β)) (t : Set β) : ⋃₀ S -ᵥ t = ⋃ s ∈ S, s -ᵥ t :=
image2_sUnion_left ..
lemma vsub_sUnion (s : Set β) (T : Set (Set β)) : s -ᵥ ⋃₀ T = ⋃ t ∈ T, s -ᵥ t :=
image2_sUnion_right ..
lemma iUnion₂_vsub (s : ∀ i, κ i → Set β) (t : Set β) :
(⋃ i, ⋃ j, s i j) -ᵥ t = ⋃ i, ⋃ j, s i j -ᵥ t := image2_iUnion₂_left ..
lemma vsub_iUnion₂ (s : Set β) (t : ∀ i, κ i → Set β) :
(s -ᵥ ⋃ i, ⋃ j, t i j) = ⋃ i, ⋃ j, s -ᵥ t i j := image2_iUnion₂_right ..
lemma iInter_vsub_subset (s : ι → Set β) (t : Set β) : (⋂ i, s i) -ᵥ t ⊆ ⋂ i, s i -ᵥ t :=
image2_iInter_subset_left ..
lemma vsub_iInter_subset (s : Set β) (t : ι → Set β) : (s -ᵥ ⋂ i, t i) ⊆ ⋂ i, s -ᵥ t i :=
image2_iInter_subset_right ..
lemma sInter_vsub_subset (S : Set (Set β)) (t : Set β) : ⋂₀ S -ᵥ t ⊆ ⋂ s ∈ S, s -ᵥ t :=
image2_sInter_subset_left ..
lemma vsub_sInter_subset (s : Set β) (T : Set (Set β)) : s -ᵥ ⋂₀ T ⊆ ⋂ t ∈ T, s -ᵥ t :=
image2_sInter_subset_right ..
lemma iInter₂_vsub_subset (s : ∀ i, κ i → Set β) (t : Set β) :
(⋂ i, ⋂ j, s i j) -ᵥ t ⊆ ⋂ i, ⋂ j, s i j -ᵥ t := image2_iInter₂_subset_left ..
lemma vsub_iInter₂_subset (s : Set β) (t : ∀ i, κ i → Set β) :
s -ᵥ ⋂ i, ⋂ j, t i j ⊆ ⋂ i, ⋂ j, s -ᵥ t i j := image2_iInter₂_subset_right ..
end VSub
end Set
|
Faithful.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Action.Defs
/-!
# Faithful group actions
This file provides typeclasses for faithful actions.
## Notation
- `a • b` is used as notation for `SMul.smul a b`.
- `a +ᵥ b` is used as notation for `VAdd.vadd a b`.
## Implementation details
This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles.
More sophisticated lemmas belong in `GroupTheory.GroupAction`.
## Tags
group action
-/
assert_not_exists MonoidWithZero
open Function (Injective Surjective)
variable {M G α : Type*}
/-! ### Faithful actions -/
/-- Typeclass for faithful actions. -/
class FaithfulVAdd (G : Type*) (P : Type*) [VAdd G P] : Prop where
/-- Two elements `g₁` and `g₂` are equal whenever they act in the same way on all points. -/
eq_of_vadd_eq_vadd : ∀ {g₁ g₂ : G}, (∀ p : P, g₁ +ᵥ p = g₂ +ᵥ p) → g₁ = g₂
/-- Typeclass for faithful actions. -/
@[to_additive]
class FaithfulSMul (M : Type*) (α : Type*) [SMul M α] : Prop where
/-- Two elements `m₁` and `m₂` are equal whenever they act in the same way on all points. -/
eq_of_smul_eq_smul : ∀ {m₁ m₂ : M}, (∀ a : α, m₁ • a = m₂ • a) → m₁ = m₂
export FaithfulSMul (eq_of_smul_eq_smul)
export FaithfulVAdd (eq_of_vadd_eq_vadd)
@[to_additive]
lemma smul_left_injective' [SMul M α] [FaithfulSMul M α] : Injective ((· • ·) : M → α → α) :=
fun _ _ h ↦ FaithfulSMul.eq_of_smul_eq_smul (congr_fun h)
/-- `Monoid.toMulAction` is faithful on cancellative monoids. -/
@[to_additive /-- `AddMonoid.toAddAction` is faithful on additive cancellative monoids. -/]
instance RightCancelMonoid.faithfulSMul [RightCancelMonoid α] : FaithfulSMul α α :=
⟨fun h ↦ mul_right_cancel (h 1)⟩
/-- `Monoid.toOppositeMulAction` is faithful on cancellative monoids. -/
@[to_additive /-- `AddMonoid.toOppositeAddAction` is faithful on additive cancellative monoids. -/]
instance LefttCancelMonoid.to_faithfulSMul_mulOpposite [LeftCancelMonoid α] : FaithfulSMul αᵐᵒᵖ α :=
⟨fun h ↦ MulOpposite.unop_injective <| mul_left_cancel (h 1)⟩
instance (R : Type*) [MulOneClass R] : FaithfulSMul R R := ⟨fun {r₁ r₂} h ↦ by simpa using h 1⟩
lemma faithfulSMul_iff_injective_smul_one (R A : Type*)
[MulOneClass A] [SMul R A] [IsScalarTower R A A] :
FaithfulSMul R A ↔ Injective (fun r : R ↦ r • (1 : A)) := by
refine ⟨fun ⟨h⟩ {r₁ r₂} hr ↦ h fun a ↦ ?_, fun h ↦ ⟨fun {r₁ r₂} hr ↦ h ?_⟩⟩
· simp only at hr
rw [← one_mul a, ← smul_mul_assoc, ← smul_mul_assoc, hr]
· simpa using hr 1
|
Whiskering.lean
|
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Sheaf
/-!
In this file we construct the functor `Sheaf J A ⥤ Sheaf J B` between sheaf categories
obtained by composition with a functor `F : A ⥤ B`.
In order for the sheaf condition to be preserved, `F` must preserve the correct limits.
The lemma `Presheaf.IsSheaf.comp` says that composition with such an `F` indeed preserves the
sheaf condition.
The functor between sheaf categories is called `sheafCompose J F`.
Given a natural transformation `η : F ⟶ G`, we obtain a natural transformation
`sheafCompose J F ⟶ sheafCompose J G`, which we call `sheafCompose_map J η`.
-/
namespace CategoryTheory
open CategoryTheory.Limits Functor
universe v₁ v₂ v₃ u₁ u₂ u₃
variable {C : Type u₁} [Category.{v₁} C]
variable {A : Type u₂} [Category.{v₂} A]
variable {B : Type u₃} [Category.{v₃} B]
variable (J : GrothendieckTopology C)
variable {U : C} (R : Presieve U)
variable (F G H : A ⥤ B) (η : F ⟶ G) (γ : G ⟶ H)
/-- Describes the property of a functor to "preserve sheaves". -/
class GrothendieckTopology.HasSheafCompose : Prop where
/-- For every sheaf `P`, `P ⋙ F` is a sheaf. -/
isSheaf (P : Cᵒᵖ ⥤ A) (hP : Presheaf.IsSheaf J P) : Presheaf.IsSheaf J (P ⋙ F)
variable [J.HasSheafCompose F] [J.HasSheafCompose G] [J.HasSheafCompose H]
/-- Composing a functor which `HasSheafCompose`, yields a functor between sheaf categories. -/
@[simps]
def sheafCompose : Sheaf J A ⥤ Sheaf J B where
obj G := ⟨G.val ⋙ F, GrothendieckTopology.HasSheafCompose.isSheaf G.val G.2⟩
map η := ⟨whiskerRight η.val _⟩
map_id _ := Sheaf.Hom.ext <| whiskerRight_id _
map_comp _ _ := Sheaf.Hom.ext <| whiskerRight_comp _ _ _
instance [F.Faithful] : (sheafCompose J F ⋙ sheafToPresheaf _ _).Faithful :=
show (sheafToPresheaf _ _ ⋙ (whiskeringRight Cᵒᵖ A B).obj F).Faithful from inferInstance
instance [F.Faithful] [F.Full] : (sheafCompose J F ⋙ sheafToPresheaf _ _).Full :=
show (sheafToPresheaf _ _ ⋙ (whiskeringRight Cᵒᵖ A B).obj F).Full from inferInstance
instance [F.Faithful] : (sheafCompose J F).Faithful :=
Functor.Faithful.of_comp (sheafCompose J F) (sheafToPresheaf _ _)
instance [F.Full] [F.Faithful] : (sheafCompose J F).Full :=
Functor.Full.of_comp_faithful (sheafCompose J F) (sheafToPresheaf _ _)
instance [F.ReflectsIsomorphisms] : (sheafCompose J F).ReflectsIsomorphisms where
reflects {G₁ G₂} f _ := by
rw [← isIso_iff_of_reflects_iso _ (sheafToPresheaf _ _),
← isIso_iff_of_reflects_iso _ ((whiskeringRight Cᵒᵖ A B).obj F)]
change IsIso ((sheafToPresheaf _ _).map ((sheafCompose J F).map f))
infer_instance
variable {F G}
/--
If `η : F ⟶ G` is a natural transformation then we obtain a morphism of functors
`sheafCompose J F ⟶ sheafCompose J G` by whiskering with `η` on the level of presheaves.
-/
def sheafCompose_map : sheafCompose J F ⟶ sheafCompose J G where
app := fun _ => .mk <| whiskerLeft _ η
@[simp]
lemma sheafCompose_id : sheafCompose_map (F := F) J (𝟙 _) = 𝟙 _ := rfl
@[simp]
lemma sheafCompose_comp :
sheafCompose_map J (η ≫ γ) = sheafCompose_map J η ≫ sheafCompose_map J γ := rfl
namespace GrothendieckTopology.Cover
variable (F G) {J}
variable (P : Cᵒᵖ ⥤ A) {X : C} (S : J.Cover X)
/-- The multicospan associated to a cover `S : J.Cover X` and a presheaf of the form `P ⋙ F`
is isomorphic to the composition of the multicospan associated to `S` and `P`,
composed with `F`. -/
@[simps!]
def multicospanComp : (S.index (P ⋙ F)).multicospan ≅ (S.index P).multicospan ⋙ F :=
NatIso.ofComponents
(fun t =>
match t with
| WalkingMulticospan.left _ => Iso.refl _
| WalkingMulticospan.right _ => Iso.refl _)
(by
rintro (a | b) (a | b) (f | f | f)
all_goals cat_disch)
/-- Mapping the multifork associated to a cover `S : J.Cover X` and a presheaf `P` with
respect to a functor `F` is isomorphic (upto a natural isomorphism of the underlying functors)
to the multifork associated to `S` and `P ⋙ F`. -/
def mapMultifork :
F.mapCone (S.multifork P) ≅
(Limits.Cones.postcompose (S.multicospanComp F P).hom).obj (S.multifork (P ⋙ F)) :=
Cones.ext (Iso.refl _)
end GrothendieckTopology.Cover
/--
Composing a sheaf with a functor preserving the limit of `(S.index P).multicospan` yields a functor
between sheaf categories.
-/
instance hasSheafCompose_of_preservesMulticospan (F : A ⥤ B)
[∀ (X : C) (S : J.Cover X) (P : Cᵒᵖ ⥤ A), PreservesLimit (S.index P).multicospan F] :
J.HasSheafCompose F where
isSheaf P hP := by
rw [Presheaf.isSheaf_iff_multifork] at hP ⊢
intro X S
obtain ⟨h⟩ := hP X S
replace h := isLimitOfPreserves F h
replace h := Limits.IsLimit.ofIsoLimit h (S.mapMultifork F P)
exact ⟨Limits.IsLimit.postcomposeHomEquiv (S.multicospanComp F P) _ h⟩
/--
Composing a sheaf with a functor preserving limits of the same size as the hom sets in `C` yields a
functor between sheaf categories.
Note: the size of the limit that `F` is required to preserve in
`hasSheafCompose_of_preservesMulticospan` is in general larger than this.
-/
instance hasSheafCompose_of_preservesLimitsOfSize [PreservesLimitsOfSize.{v₁, max u₁ v₁} F] :
J.HasSheafCompose F where
isSheaf _ hP := Presheaf.isSheaf_comp_of_isSheaf J _ F hP
variable {J}
lemma Sheaf.isSeparated {FA : A → A → Type*} {CA : A → Type*}
[∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] [J.HasSheafCompose (forget A)]
(F : Sheaf J A) : Presheaf.IsSeparated J F.val := by
rintro X S hS x y h
exact (Presieve.isSeparated_of_isSheaf _ _ ((isSheaf_iff_isSheaf_of_type _ _).1
((sheafCompose J (forget A)).obj F).2) S hS).ext (fun _ _ hf => h _ _ hf)
lemma Presheaf.IsSheaf.isSeparated {F : Cᵒᵖ ⥤ A} {FA : A → A → Type*} {CA : A → Type*}
[∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA]
[J.HasSheafCompose (forget A)] (hF : Presheaf.IsSheaf J F) :
Presheaf.IsSeparated J F :=
Sheaf.isSeparated ⟨F, hF⟩
end CategoryTheory
|
UniformOn.lean
|
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Bhavik Mehta
-/
import Mathlib.Probability.ConditionalProbability
import Mathlib.MeasureTheory.Measure.Count
/-!
# Classical probability
The classical formulation of probability states that the probability of an event occurring in a
finite probability space is the ratio of that event to all possible events.
This notion can be expressed with measure theory using
the counting measure. In particular, given the sets `s` and `t`, we define the probability of `t`
occurring in `s` to be `|s|⁻¹ * |s ∩ t|`. With this definition, we recover the probability over
the entire sample space when `s = Set.univ`.
Classical probability is often used in combinatorics and we prove some useful lemmas in this file
for that purpose.
## Main definition
* `ProbabilityTheory.uniformOn`: given a set `s`, `uniformOn s` is the counting measure
conditioned on `s`. This is a probability measure when `s` is finite and nonempty.
## Notes
The original aim of this file is to provide a measure theoretic method of describing the
probability an element of a set `s` satisfies some predicate `P`. Our current formulation still
allow us to describe this by abusing the definitional equality of sets and predicates by simply
writing `uniformOn s P`. We should avoid this however as none of the lemmas are written for
predicates.
-/
noncomputable section
open ProbabilityTheory
open MeasureTheory MeasurableSpace
namespace ProbabilityTheory
variable {Ω : Type*} [MeasurableSpace Ω] {s : Set Ω}
/-- Given a set `s`, `uniformOn s` is the uniform measure on `s`, defined as the counting measure
conditioned by `s`. One should think of `uniformOn s t` as the proportion of `s` that is contained
in `t`.
This is a probability measure when `s` is finite and nonempty and is given by
`ProbabilityTheory.uniformOn_isProbabilityMeasure`. -/
def uniformOn (s : Set Ω) : Measure Ω :=
Measure.count[|s]
instance {s : Set Ω} : IsZeroOrProbabilityMeasure (uniformOn s) := by
unfold uniformOn; infer_instance
@[simp]
theorem uniformOn_empty_meas : (uniformOn ∅ : Measure Ω) = 0 := by simp [uniformOn]
theorem uniformOn_empty {s : Set Ω} : uniformOn s ∅ = 0 := by simp
/-- See `uniformOn_eq_zero` for a version assuming `MeasurableSingletonClass Ω` instead of
`MeasurableSet s`. -/
@[simp] lemma uniformOn_eq_zero' (hs : MeasurableSet s) : uniformOn s = 0 ↔ s.Infinite ∨ s = ∅ := by
simp [uniformOn, hs]
/-- See `uniformOn_eq_zero'` for a version assuming `MeasurableSet s` instead of
`MeasurableSingletonClass Ω`. -/
@[simp] lemma uniformOn_eq_zero [MeasurableSingletonClass Ω] :
uniformOn s = 0 ↔ s.Infinite ∨ s = ∅ := by simp [uniformOn]
theorem finite_of_uniformOn_ne_zero {s t : Set Ω} (h : uniformOn s t ≠ 0) : s.Finite := by
by_contra hs'
simp [uniformOn, cond, Measure.count_apply_infinite hs'] at h
theorem uniformOn_univ [Fintype Ω] {s : Set Ω} :
uniformOn Set.univ s = Measure.count s / Fintype.card Ω := by
simp [uniformOn, cond_apply, ← ENNReal.div_eq_inv_mul]
variable [MeasurableSingletonClass Ω]
theorem uniformOn_isProbabilityMeasure {s : Set Ω} (hs : s.Finite) (hs' : s.Nonempty) :
IsProbabilityMeasure (uniformOn s) := by
apply cond_isProbabilityMeasure_of_finite
· rwa [Measure.count_ne_zero_iff]
· exact (Measure.count_apply_lt_top.2 hs).ne
theorem uniformOn_singleton (ω : Ω) (t : Set Ω) [Decidable (ω ∈ t)] :
uniformOn {ω} t = if ω ∈ t then 1 else 0 := by
rw [uniformOn, cond_apply (measurableSet_singleton ω), Measure.count_singleton, inv_one,
one_mul]
split_ifs
· rw [(by simpa : ({ω} : Set Ω) ∩ t = {ω}), Measure.count_singleton]
· simpa
variable {s t u : Set Ω}
theorem uniformOn_inter_self (hs : s.Finite) : uniformOn s (s ∩ t) = uniformOn s t := by
rw [uniformOn, cond_inter_self hs.measurableSet]
theorem uniformOn_self (hs : s.Finite) (hs' : s.Nonempty) : uniformOn s s = 1 := by
rw [uniformOn, cond_apply hs.measurableSet, Set.inter_self, ENNReal.inv_mul_cancel]
· rwa [Measure.count_ne_zero_iff]
· exact (Measure.count_apply_lt_top.2 hs).ne
theorem uniformOn_eq_one_of (hs : s.Finite) (hs' : s.Nonempty) (ht : s ⊆ t) :
uniformOn s t = 1 := by
haveI := uniformOn_isProbabilityMeasure hs hs'
refine eq_of_le_of_not_lt prob_le_one ?_
rw [not_lt, ← uniformOn_self hs hs']
exact measure_mono ht
theorem pred_true_of_uniformOn_eq_one (h : uniformOn s t = 1) : s ⊆ t := by
have hsf := finite_of_uniformOn_ne_zero (by rw [h]; exact one_ne_zero)
rw [uniformOn, cond_apply hsf.measurableSet, mul_comm] at h
replace h := ENNReal.eq_inv_of_mul_eq_one_left h
rw [inv_inv, Measure.count_apply_finite _ hsf, Measure.count_apply_finite _ (hsf.inter_of_left _),
Nat.cast_inj] at h
suffices s ∩ t = s by exact this ▸ fun x hx => hx.2
rw [← @Set.Finite.toFinset_inj _ _ _ (hsf.inter_of_left _) hsf]
exact Finset.eq_of_subset_of_card_le (Set.Finite.toFinset_mono s.inter_subset_left) h.ge
theorem uniformOn_eq_zero_iff (hs : s.Finite) : uniformOn s t = 0 ↔ s ∩ t = ∅ := by
simp [uniformOn, cond_apply hs.measurableSet, Measure.count_apply_eq_top, Set.not_infinite.2 hs,
Measure.count_apply_finite _ (hs.inter_of_left _)]
theorem uniformOn_of_univ (hs : s.Finite) (hs' : s.Nonempty) : uniformOn s Set.univ = 1 :=
uniformOn_eq_one_of hs hs' s.subset_univ
theorem uniformOn_inter (hs : s.Finite) :
uniformOn s (t ∩ u) = uniformOn (s ∩ t) u * uniformOn s t := by
by_cases hst : s ∩ t = ∅
· rw [hst, uniformOn_empty_meas, Measure.coe_zero, Pi.zero_apply, zero_mul,
uniformOn_eq_zero_iff hs, ← Set.inter_assoc, hst, Set.empty_inter]
rw [uniformOn, uniformOn, cond_apply hs.measurableSet, cond_apply hs.measurableSet,
cond_apply (hs.inter_of_left _).measurableSet, mul_comm _ (Measure.count (s ∩ t)),
← mul_assoc, mul_comm _ (Measure.count (s ∩ t)), ← mul_assoc, ENNReal.mul_inv_cancel, one_mul,
mul_comm, Set.inter_assoc]
· rwa [← Measure.count_eq_zero_iff] at hst
· exact (Measure.count_apply_lt_top.2 <| hs.inter_of_left _).ne
theorem uniformOn_inter' (hs : s.Finite) :
uniformOn s (t ∩ u) = uniformOn (s ∩ u) t * uniformOn s u := by
rw [← Set.inter_comm]
exact uniformOn_inter hs
theorem uniformOn_union (hs : s.Finite) (htu : Disjoint t u) :
uniformOn s (t ∪ u) = uniformOn s t + uniformOn s u := by
rw [uniformOn, cond_apply hs.measurableSet, cond_apply hs.measurableSet,
cond_apply hs.measurableSet, Set.inter_union_distrib_left, measure_union, mul_add]
exacts [htu.mono inf_le_right inf_le_right, (hs.inter_of_left _).measurableSet]
theorem uniformOn_compl (t : Set Ω) (hs : s.Finite) (hs' : s.Nonempty) :
uniformOn s t + uniformOn s tᶜ = 1 := by
rw [← uniformOn_union hs disjoint_compl_right, Set.union_compl_self,
(uniformOn_isProbabilityMeasure hs hs').measure_univ]
theorem uniformOn_disjoint_union (hs : s.Finite) (ht : t.Finite) (hst : Disjoint s t) :
uniformOn s u * uniformOn (s ∪ t) s + uniformOn t u * uniformOn (s ∪ t) t =
uniformOn (s ∪ t) u := by
rcases s.eq_empty_or_nonempty with (rfl | hs') <;> rcases t.eq_empty_or_nonempty with (rfl | ht')
· simp
· simp [uniformOn_self ht ht']
· simp [uniformOn_self hs hs']
rw [uniformOn, uniformOn, uniformOn, cond_apply hs.measurableSet,
cond_apply ht.measurableSet, cond_apply (hs.union ht).measurableSet,
cond_apply (hs.union ht).measurableSet, cond_apply (hs.union ht).measurableSet]
conv_lhs =>
rw [Set.union_inter_cancel_left, Set.union_inter_cancel_right,
mul_comm (Measure.count (s ∪ t))⁻¹, mul_comm (Measure.count (s ∪ t))⁻¹, ← mul_assoc,
← mul_assoc, mul_comm _ (Measure.count s), mul_comm _ (Measure.count t), ← mul_assoc,
← mul_assoc]
rw [ENNReal.mul_inv_cancel, ENNReal.mul_inv_cancel, one_mul, one_mul, ← add_mul, ← measure_union,
Set.union_inter_distrib_right, mul_comm]
exacts [hst.mono inf_le_left inf_le_left, (ht.inter_of_left _).measurableSet,
Measure.count_ne_zero ht', (Measure.count_apply_lt_top.2 ht).ne, Measure.count_ne_zero hs',
(Measure.count_apply_lt_top.2 hs).ne]
/-- A version of the law of total probability for counting probabilities. -/
theorem uniformOn_add_compl_eq (u t : Set Ω) (hs : s.Finite) :
uniformOn (s ∩ u) t * uniformOn s u + uniformOn (s ∩ uᶜ) t * uniformOn s uᶜ =
uniformOn s t := by
-- Porting note: The original proof used `conv_rhs`. However, that tactic timed out.
have : uniformOn s t = (uniformOn (s ∩ u) t * uniformOn (s ∩ u ∪ s ∩ uᶜ) (s ∩ u) +
uniformOn (s ∩ uᶜ) t * uniformOn (s ∩ u ∪ s ∩ uᶜ) (s ∩ uᶜ)) := by
rw [uniformOn_disjoint_union (hs.inter_of_left _) (hs.inter_of_left _)
(disjoint_compl_right.mono inf_le_right inf_le_right), Set.inter_union_compl]
rw [this]
simp [uniformOn_inter_self hs]
end ProbabilityTheory
|
Presheaf.lean
|
/-
Copyright (c) 2025 Pablo Donato. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Pablo Donato
-/
import Mathlib.CategoryTheory.Subobject.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback
/-!
# Subobjects presheaf
Following Section I.3 of [Sheaves in Geometry and Logic][MM92], we define the subobjects presheaf
`Subobject.presheaf C` mapping any object `X` to its type of subobjects `Subobject X`.
## Main definitions
Let `C` refer to a category with pullbacks.
* `CategoryTheory.Subobject.presheaf C` is the presheaf that sends every object `X : C` to its type
of subobjects `Subobject X`, and every morphism `f : X ⟶ Y` to the function `Subobject Y →
Subobject X` that maps every subobject of `Y` to its pullback along `f`.
## References
* [S. MacLane and I. Moerdijk, *Sheaves in geometry and logic: A first introduction to topos
theory*][MM92]
## Tags
subobject, representable functor, presheaf, topos theory
-/
open CategoryTheory Subobject
namespace Subobject
universe u v
variable (C : Type u) [Category.{v} C] [Limits.HasPullbacks C]
/-- This is the presheaf that sends every object `X : C` to its type of subobjects `Subobject X`,
and every morphism `f : X ⟶ Y` to the function `Subobject Y → Subobject X` that maps every
subobject of `Y` to its pullback along `f`. -/
@[simps]
noncomputable def presheaf : Cᵒᵖ ⥤ Type max u v where
obj X := Subobject X.unop
map f := (pullback f.unop).obj
map_id _ := by ext : 1; simp [pullback_id]
map_comp _ _ := by ext : 1; simp [pullback_comp]
end Subobject
|
AEEqOfLIntegral.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.StronglyMeasurable.ENNReal
import Mathlib.MeasureTheory.Measure.WithDensity
/-! # From equality of integrals to equality of functions
This file provides various statements of the general form "if two functions have the same integral
on all sets, then they are equal almost everywhere".
The different lemmas use various hypotheses on the class of functions, on the target space or on the
possible finiteness of the measure.
This file is about Lebesgue integrals. See the file `AEEqOfIntegral` for Bochner integrals.
## Main statements
The results listed below apply to two functions `f, g`, under the hypothesis that
for all measurable sets `s` with finite measure, `∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ`.
The conclusion is then `f =ᵐ[μ] g`. The main lemmas are:
* `ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite`: case of a sigma-finite measure.
* `AEMeasurable.ae_eq_of_forall_setLIntegral_eq`: for functions which are `AEMeasurable` and
have finite integral.
-/
open Filter
open scoped ENNReal NNReal MeasureTheory Topology
namespace MeasureTheory
variable {α : Type*} {m m0 : MeasurableSpace α} {μ : Measure α} {p : ℝ≥0∞}
theorem ae_const_le_iff_forall_lt_measure_zero {β} [LinearOrder β] [TopologicalSpace β]
[OrderTopology β] [FirstCountableTopology β] (f : α → β) (c : β) :
(∀ᵐ x ∂μ, c ≤ f x) ↔ ∀ b < c, μ {x | f x ≤ b} = 0 := by
rw [ae_iff]
push_neg
constructor
· intro h b hb
exact measure_mono_null (fun y hy => (lt_of_le_of_lt hy hb : _)) h
intro hc
by_cases h : ∀ b, c ≤ b
· have : {a : α | f a < c} = ∅ := by
apply Set.eq_empty_iff_forall_notMem.2 fun x hx => ?_
exact (lt_irrefl _ (lt_of_lt_of_le hx (h (f x)))).elim
simp [this]
by_cases H : ¬IsLUB (Set.Iio c) c
· have : c ∈ upperBounds (Set.Iio c) := fun y hy => le_of_lt hy
obtain ⟨b, b_up, bc⟩ : ∃ b : β, b ∈ upperBounds (Set.Iio c) ∧ b < c := by
simpa [IsLUB, IsLeast, this, lowerBounds] using H
exact measure_mono_null (fun x hx => b_up hx) (hc b bc)
push_neg at H h
obtain ⟨u, _, u_lt, u_lim, -⟩ :
∃ u : ℕ → β,
StrictMono u ∧ (∀ n : ℕ, u n < c) ∧ Tendsto u atTop (𝓝 c) ∧ ∀ n : ℕ, u n ∈ Set.Iio c :=
H.exists_seq_strictMono_tendsto_of_notMem (lt_irrefl c) h
have h_Union : {x | f x < c} = ⋃ n : ℕ, {x | f x ≤ u n} := by
ext1 x
simp_rw [Set.mem_iUnion, Set.mem_setOf_eq]
constructor <;> intro h
· obtain ⟨n, hn⟩ := ((tendsto_order.1 u_lim).1 _ h).exists; exact ⟨n, hn.le⟩
· obtain ⟨n, hn⟩ := h; exact hn.trans_lt (u_lt _)
rw [h_Union, measure_iUnion_null_iff]
intro n
exact hc _ (u_lt n)
lemma ae_le_const_iff_forall_gt_measure_zero {β} [LinearOrder β] [TopologicalSpace β]
[OrderTopology β] [FirstCountableTopology β] {μ : Measure α} (f : α → β) (c : β) :
(∀ᵐ x ∂μ, f x ≤ c) ↔ ∀ b, c < b → μ {x | b ≤ f x} = 0 :=
ae_const_le_iff_forall_lt_measure_zero (β := βᵒᵈ) _ _
theorem ae_le_of_forall_setLIntegral_le_of_sigmaFinite₀ [SigmaFinite μ]
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ) :
f ≤ᵐ[μ] g := by
have A : ∀ (ε N : ℝ≥0) (p : ℕ), 0 < ε →
μ ({x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanningSets μ p) = 0 := by
intro ε N p εpos
let s := {x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanningSets μ p
have s_lt_top : μ s < ∞ :=
(measure_mono (Set.inter_subset_right)).trans_lt (measure_spanningSets_lt_top μ p)
have A : (∫⁻ x in s, g x ∂μ) + ε * μ s ≤ (∫⁻ x in s, g x ∂μ) + 0 :=
calc
(∫⁻ x in s, g x ∂μ) + ε * μ s = (∫⁻ x in s, g x ∂μ) + ∫⁻ _ in s, ε ∂μ := by
simp only [lintegral_const, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply]
_ = ∫⁻ x in s, g x + ε ∂μ := (lintegral_add_right _ measurable_const).symm
_ ≤ ∫⁻ x in s, f x ∂μ :=
setLIntegral_mono_ae hf.restrict <| ae_of_all _ fun x hx => hx.1.1
_ ≤ (∫⁻ x in s, g x ∂μ) + 0 := by
rw [add_zero, ← Measure.restrict_toMeasurable s_lt_top.ne]
refine h _ (measurableSet_toMeasurable ..) ?_
rwa [measure_toMeasurable]
have B : (∫⁻ x in s, g x ∂μ) ≠ ∞ :=
(setLIntegral_lt_top_of_le_nnreal s_lt_top.ne ⟨N, fun _ h ↦ h.1.2⟩).ne
have : (ε : ℝ≥0∞) * μ s ≤ 0 := ENNReal.le_of_add_le_add_left B A
simpa only [ENNReal.coe_eq_zero, nonpos_iff_eq_zero, mul_eq_zero, εpos.ne', false_or]
obtain ⟨u, _, u_pos, u_lim⟩ :
∃ u : ℕ → ℝ≥0, StrictAnti u ∧ (∀ n, 0 < u n) ∧ Tendsto u atTop (𝓝 0) :=
exists_seq_strictAnti_tendsto (0 : ℝ≥0)
let s := fun n : ℕ => {x | g x + u n ≤ f x ∧ g x ≤ (n : ℝ≥0)} ∩ spanningSets μ n
have μs : ∀ n, μ (s n) = 0 := fun n => A _ _ _ (u_pos n)
have B : {x | f x ≤ g x}ᶜ ⊆ ⋃ n, s n := by
intro x hx
simp only [Set.mem_compl_iff, Set.mem_setOf, not_le] at hx
have L1 : ∀ᶠ n in atTop, g x + u n ≤ f x := by
have : Tendsto (fun n => g x + u n) atTop (𝓝 (g x + (0 : ℝ≥0))) :=
tendsto_const_nhds.add (ENNReal.tendsto_coe.2 u_lim)
simp only [ENNReal.coe_zero, add_zero] at this
exact this.eventually_le_const hx
have L2 : ∀ᶠ n : ℕ in (atTop : Filter ℕ), g x ≤ (n : ℝ≥0) :=
have : Tendsto (fun n : ℕ => ((n : ℝ≥0) : ℝ≥0∞)) atTop (𝓝 ∞) := by
simp only [ENNReal.coe_natCast]
exact ENNReal.tendsto_nat_nhds_top
this.eventually_const_le (hx.trans_le le_top)
apply Set.mem_iUnion.2
exact ((L1.and L2).and (eventually_mem_spanningSets μ x)).exists
refine le_antisymm ?_ bot_le
calc
μ {x : α | (fun x : α => f x ≤ g x) x}ᶜ ≤ μ (⋃ n, s n) := measure_mono B
_ ≤ ∑' n, μ (s n) := measure_iUnion_le _
_ = 0 := by simp only [μs, tsum_zero]
theorem ae_le_of_forall_setLIntegral_le_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞}
(hf : Measurable f)
(h : ∀ s, MeasurableSet s → μ s < ∞ → (∫⁻ x in s, f x ∂μ) ≤ ∫⁻ x in s, g x ∂μ) : f ≤ᵐ[μ] g :=
ae_le_of_forall_setLIntegral_le_of_sigmaFinite₀ hf.aemeasurable h
theorem ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite₀ [SigmaFinite μ]
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g := by
have A : f ≤ᵐ[μ] g :=
ae_le_of_forall_setLIntegral_le_of_sigmaFinite₀ hf fun s hs h's => le_of_eq (h s hs h's)
have B : g ≤ᵐ[μ] f :=
ae_le_of_forall_setLIntegral_le_of_sigmaFinite₀ hg fun s hs h's => ge_of_eq (h s hs h's)
filter_upwards [A, B] with x using le_antisymm
theorem ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞}
(hf : Measurable f) (hg : Measurable g)
(h : ∀ s, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) : f =ᵐ[μ] g :=
ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite₀ hf.aemeasurable hg.aemeasurable h
theorem AEMeasurable.ae_eq_of_forall_setLIntegral_eq {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ)
(hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) (hgi : ∫⁻ x, g x ∂μ ≠ ∞)
(hfg : ∀ ⦃s⦄, MeasurableSet s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) :
f =ᵐ[μ] g := by
have hf' : AEFinStronglyMeasurable f μ :=
ENNReal.aefinStronglyMeasurable_of_aemeasurable hfi hf
have hg' : AEFinStronglyMeasurable g μ :=
ENNReal.aefinStronglyMeasurable_of_aemeasurable hgi hg
let s := hf'.sigmaFiniteSet
let t := hg'.sigmaFiniteSet
suffices f =ᵐ[μ.restrict (s ∪ t)] g by
refine ae_of_ae_restrict_of_ae_restrict_compl _ this ?_
simp only [Set.compl_union]
have h1 : f =ᵐ[μ.restrict sᶜ] 0 := hf'.ae_eq_zero_compl
have h2 : g =ᵐ[μ.restrict tᶜ] 0 := hg'.ae_eq_zero_compl
rw [ae_restrict_iff' (hf'.measurableSet.compl.inter hg'.measurableSet.compl)]
rw [EventuallyEq, ae_restrict_iff' hf'.measurableSet.compl] at h1
rw [EventuallyEq, ae_restrict_iff' hg'.measurableSet.compl] at h2
filter_upwards [h1, h2] with x h1 h2 hx
rw [h1 (Set.inter_subset_left hx), h2 (Set.inter_subset_right hx)]
have := hf'.sigmaFinite_restrict
have := hg'.sigmaFinite_restrict
refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite₀ hf.restrict hg.restrict
fun u hu huμ ↦ ?_
rw [Measure.restrict_restrict hu]
rw [Measure.restrict_apply hu] at huμ
exact hfg (hu.inter (hf'.measurableSet.union hg'.measurableSet)) huμ
section PiSystem
variable {s : Set (Set α)} {f g : α → ℝ≥0∞}
theorem lintegral_eq_lintegral_of_isPiSystem
(h_eq : m0 = MeasurableSpace.generateFrom s) (h_inter : IsPiSystem s)
(basic : ∀ t ∈ s, ∫⁻ x in t, f x ∂μ = ∫⁻ x in t, g x ∂μ)
(h_univ : ∫⁻ x, f x ∂μ = ∫⁻ x, g x ∂μ) (hf_int : ∫⁻ x, f x ∂μ ≠ ∞) :
∀ t (_ : MeasurableSet t), ∫⁻ x in t, f x ∂μ = ∫⁻ x in t, g x ∂μ := by
refine MeasurableSpace.induction_on_inter h_eq h_inter ?_ basic ?_ ?_
· simp
· intro t ht h_eq
rw [setLIntegral_compl ht, setLIntegral_compl ht, h_eq, h_univ]
· refine ne_of_lt ?_
calc ∫⁻ x in t, g x ∂μ
_ ≤ ∫⁻ x, g x ∂μ := setLIntegral_le_lintegral t _
_ < ∞ := by rw [← h_univ]; exact hf_int.lt_top
· refine ne_of_lt ?_
calc ∫⁻ x in t, f x ∂μ
_ ≤ ∫⁻ x, f x ∂μ := setLIntegral_le_lintegral t _
_ < ∞ := hf_int.lt_top
· intro t htd htm h
simp_rw [lintegral_iUnion htm htd, h]
lemma lintegral_eq_lintegral_of_isPiSystem_of_univ_mem
(h_eq : m0 = MeasurableSpace.generateFrom s) (h_inter : IsPiSystem s) (h_univ : Set.univ ∈ s)
(basic : ∀ t ∈ s, ∫⁻ x in t, f x ∂μ = ∫⁻ x in t, g x ∂μ)
(hf_int : ∫⁻ x, f x ∂μ ≠ ∞) {t : Set α} (ht : MeasurableSet t) :
∫⁻ x in t, f x ∂μ = ∫⁻ x in t, g x ∂μ := by
refine lintegral_eq_lintegral_of_isPiSystem h_eq h_inter basic ?_ hf_int t ht
rw [← setLIntegral_univ, ← setLIntegral_univ g]
exact basic _ h_univ
/-- If two a.e.-measurable functions `α × β → ℝ≥0∞` with finite integrals have the same integral
on every rectangle, then they are almost everywhere equal. -/
lemma ae_eq_of_setLIntegral_prod_eq {β : Type*} {mβ : MeasurableSpace β}
{μ : Measure (α × β)} {f g : α × β → ℝ≥0∞}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ) (hf_int : ∫⁻ x, f x ∂μ ≠ ∞)
(h : ∀ ⦃s : Set α⦄ (_ : MeasurableSet s) ⦃t : Set β⦄ (_ : MeasurableSet t),
∫⁻ x in s ×ˢ t, f x ∂μ = ∫⁻ x in s ×ˢ t, g x ∂μ) :
f =ᵐ[μ] g := by
have hg_int : ∫⁻ x, g x ∂μ ≠ ∞ := by
rwa [← setLIntegral_univ, ← Set.univ_prod_univ, ← h .univ .univ, Set.univ_prod_univ,
setLIntegral_univ]
refine AEMeasurable.ae_eq_of_forall_setLIntegral_eq hf hg hf_int hg_int fun s hs _ ↦ ?_
refine lintegral_eq_lintegral_of_isPiSystem_of_univ_mem generateFrom_prod.symm isPiSystem_prod
?_ ?_ hf_int hs
· exact ⟨Set.univ, .univ, Set.univ, .univ, Set.univ_prod_univ⟩
· rintro _ ⟨s, hs, t, ht, rfl⟩
exact h hs ht
end PiSystem
section WithDensity
variable {m : MeasurableSpace α} {μ : Measure α}
theorem withDensity_eq_iff_of_sigmaFinite [SigmaFinite μ] {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ)
(hg : AEMeasurable g μ) : μ.withDensity f = μ.withDensity g ↔ f =ᵐ[μ] g :=
⟨fun hfg ↦ by
refine ae_eq_of_forall_setLIntegral_eq_of_sigmaFinite₀ hf hg fun s hs _ ↦ ?_
rw [← withDensity_apply f hs, ← withDensity_apply g hs, ← hfg], withDensity_congr_ae⟩
theorem withDensity_eq_iff {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ)
(hg : AEMeasurable g μ) (hfi : ∫⁻ x, f x ∂μ ≠ ∞) :
μ.withDensity f = μ.withDensity g ↔ f =ᵐ[μ] g :=
⟨fun hfg ↦ by
refine AEMeasurable.ae_eq_of_forall_setLIntegral_eq hf hg hfi ?_ fun s hs _ ↦ ?_
· rwa [← setLIntegral_univ, ← withDensity_apply g MeasurableSet.univ, ← hfg,
withDensity_apply f MeasurableSet.univ, setLIntegral_univ]
· rw [← withDensity_apply f hs, ← withDensity_apply g hs, ← hfg], withDensity_congr_ae⟩
end WithDensity
end MeasureTheory
|
AEEqFun.lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.MeasureTheory.Function.L1Space.Integrable
/-!
# `L¹` space
In this file we establish an API between `Integrable` and the space `L¹` of equivalence
classes of integrable functions, already defined as a special case of `L^p` spaces for `p = 1`.
## Notation
* `α →₁[μ] β` is the type of `L¹` space, where `α` is a `MeasureSpace` and `β` is a
`NormedAddCommGroup`. `f : α →ₘ β` is a "function" in `L¹`.
In comments, `[f]` is also used to denote an `L¹` function.
`₁` can be typed as `\1`.
## Tags
function space, l1
-/
noncomputable section
open EMetric ENNReal Filter MeasureTheory NNReal Set
variable {α β ε ε' : Type*} {m : MeasurableSpace α} {μ ν : Measure α}
variable [NormedAddCommGroup β] [TopologicalSpace ε] [ContinuousENorm ε]
[TopologicalSpace ε'] [ESeminormedAddMonoid ε']
namespace MeasureTheory
namespace AEEqFun
section
/-- A class of almost everywhere equal functions is `Integrable` if its function representative
is integrable. -/
def Integrable (f : α →ₘ[μ] ε) : Prop :=
MeasureTheory.Integrable f μ
theorem integrable_mk {f : α → ε} (hf : AEStronglyMeasurable f μ) :
Integrable (mk f hf : α →ₘ[μ] ε) ↔ MeasureTheory.Integrable f μ := by
simp only [Integrable]
apply integrable_congr
exact coeFn_mk f hf
theorem integrable_coeFn {f : α →ₘ[μ] ε} : MeasureTheory.Integrable f μ ↔ Integrable f := by
rw [← integrable_mk, mk_coeFn]
theorem integrable_zero : Integrable (0 : α →ₘ[μ] ε') :=
(MeasureTheory.integrable_zero α ε' μ).congr (coeFn_mk _ _).symm
end
section
theorem Integrable.neg {f : α →ₘ[μ] β} : Integrable f → Integrable (-f) :=
induction_on f fun _f hfm hfi => (integrable_mk _).2 ((integrable_mk hfm).1 hfi).neg
section
theorem integrable_iff_mem_L1 {f : α →ₘ[μ] β} : Integrable f ↔ f ∈ (α →₁[μ] β) := by
rw [← integrable_coeFn, ← memLp_one_iff_integrable, Lp.mem_Lp_iff_memLp]
-- TODO: generalise these lemmas to `ENormedSpace` or similar
theorem Integrable.add {f g : α →ₘ[μ] β} : Integrable f → Integrable g → Integrable (f + g) := by
refine induction_on₂ f g fun f hf g hg hfi hgi => ?_
simp only [integrable_mk, mk_add_mk] at hfi hgi ⊢
exact hfi.add hgi
theorem Integrable.sub {f g : α →ₘ[μ] β} (hf : Integrable f) (hg : Integrable g) :
Integrable (f - g) :=
(sub_eq_add_neg f g).symm ▸ hf.add hg.neg
end
section IsBoundedSMul
variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 β] [IsBoundedSMul 𝕜 β]
theorem Integrable.smul {c : 𝕜} {f : α →ₘ[μ] β} : Integrable f → Integrable (c • f) :=
induction_on f fun _f hfm hfi => (integrable_mk _).2 <|
by simpa using ((integrable_mk hfm).1 hfi).smul c
end IsBoundedSMul
end
end AEEqFun
namespace L1
theorem integrable_coeFn (f : α →₁[μ] β) : Integrable f μ := by
rw [← memLp_one_iff_integrable]
exact Lp.memLp f
theorem hasFiniteIntegral_coeFn (f : α →₁[μ] β) : HasFiniteIntegral f μ :=
(integrable_coeFn f).hasFiniteIntegral
@[fun_prop]
theorem stronglyMeasurable_coeFn (f : α →₁[μ] β) : StronglyMeasurable f :=
Lp.stronglyMeasurable f
@[fun_prop]
theorem measurable_coeFn [MeasurableSpace β] [BorelSpace β] (f : α →₁[μ] β) : Measurable f :=
(Lp.stronglyMeasurable f).measurable
@[fun_prop]
theorem aestronglyMeasurable_coeFn (f : α →₁[μ] β) : AEStronglyMeasurable f μ :=
Lp.aestronglyMeasurable f
@[fun_prop]
theorem aemeasurable_coeFn [MeasurableSpace β] [BorelSpace β] (f : α →₁[μ] β) : AEMeasurable f μ :=
(Lp.stronglyMeasurable f).measurable.aemeasurable
theorem edist_def (f g : α →₁[μ] β) : edist f g = ∫⁻ a, edist (f a) (g a) ∂μ := by
simp only [Lp.edist_def, eLpNorm, one_ne_zero, eLpNorm'_eq_lintegral_enorm, Pi.sub_apply,
toReal_one, ENNReal.rpow_one, ne_eq, not_false_eq_true, div_self, ite_false]
simp [edist_eq_enorm_sub]
theorem dist_def (f g : α →₁[μ] β) : dist f g = (∫⁻ a, edist (f a) (g a) ∂μ).toReal := by
simp_rw [dist_edist, edist_def]
theorem norm_def (f : α →₁[μ] β) : ‖f‖ = (∫⁻ a, ‖f a‖ₑ ∂μ).toReal := by
simp [Lp.norm_def, eLpNorm, eLpNorm'_eq_lintegral_enorm]
/-- Computing the norm of a difference between two L¹-functions. Note that this is not a
special case of `norm_def` since `(f - g) x` and `f x - g x` are not equal
(but only a.e.-equal). -/
theorem norm_sub_eq_lintegral (f g : α →₁[μ] β) : ‖f - g‖ = (∫⁻ x, ‖f x - g x‖ₑ ∂μ).toReal := by
rw [norm_def]
congr 1
rw [lintegral_congr_ae]
filter_upwards [Lp.coeFn_sub f g] with _ ha
simp only [ha, Pi.sub_apply]
theorem ofReal_norm_eq_lintegral (f : α →₁[μ] β) : ENNReal.ofReal ‖f‖ = ∫⁻ x, ‖f x‖ₑ ∂μ := by
rw [norm_def, ENNReal.ofReal_toReal]
exact ne_of_lt (hasFiniteIntegral_coeFn f)
/-- Computing the norm of a difference between two L¹-functions. Note that this is not a
special case of `ofReal_norm_eq_lintegral` since `(f - g) x` and `f x - g x` are not equal
(but only a.e.-equal). -/
theorem ofReal_norm_sub_eq_lintegral (f g : α →₁[μ] β) :
ENNReal.ofReal ‖f - g‖ = ∫⁻ x, ‖f x - g x‖ₑ ∂μ := by
simp_rw [ofReal_norm_eq_lintegral, ← edist_zero_eq_enorm]
apply lintegral_congr_ae
filter_upwards [Lp.coeFn_sub f g] with _ ha
simp only [ha, Pi.sub_apply]
end L1
namespace Integrable
/-- Construct the equivalence class `[f]` of an integrable function `f`, as a member of the
space `Lp β 1 μ`. -/
def toL1 (f : α → β) (hf : Integrable f μ) : α →₁[μ] β :=
(memLp_one_iff_integrable.2 hf).toLp f
@[simp]
theorem toL1_coeFn (f : α →₁[μ] β) (hf : Integrable f μ) : hf.toL1 f = f := by
simp [Integrable.toL1]
theorem coeFn_toL1 {f : α → β} (hf : Integrable f μ) : hf.toL1 f =ᵐ[μ] f :=
AEEqFun.coeFn_mk _ _
@[simp]
theorem toL1_zero (h : Integrable (0 : α → β) μ) : h.toL1 0 = 0 :=
rfl
@[simp]
theorem toL1_eq_mk (f : α → β) (hf : Integrable f μ) :
(hf.toL1 f : α →ₘ[μ] β) = AEEqFun.mk f hf.aestronglyMeasurable :=
rfl
@[simp]
theorem toL1_eq_toL1_iff (f g : α → β) (hf : Integrable f μ) (hg : Integrable g μ) :
toL1 f hf = toL1 g hg ↔ f =ᵐ[μ] g :=
MemLp.toLp_eq_toLp_iff _ _
theorem toL1_add (f g : α → β) (hf : Integrable f μ) (hg : Integrable g μ) :
toL1 (f + g) (hf.add hg) = toL1 f hf + toL1 g hg :=
rfl
theorem toL1_neg (f : α → β) (hf : Integrable f μ) : toL1 (-f) (Integrable.neg hf) = -toL1 f hf :=
rfl
theorem toL1_sub (f g : α → β) (hf : Integrable f μ) (hg : Integrable g μ) :
toL1 (f - g) (hf.sub hg) = toL1 f hf - toL1 g hg :=
rfl
theorem norm_toL1 (f : α → β) (hf : Integrable f μ) :
‖hf.toL1 f‖ = (∫⁻ a, edist (f a) 0 ∂μ).toReal := by
simp [toL1, Lp.norm_toLp, eLpNorm, eLpNorm'_eq_lintegral_enorm]
theorem enorm_toL1 {f : α → β} (hf : Integrable f μ) : ‖hf.toL1 f‖ₑ = ∫⁻ a, ‖f a‖ₑ ∂μ := by
simp only [Lp.enorm_def, toL1_eq_mk, eLpNorm_aeeqFun]
simp [eLpNorm, eLpNorm']
theorem norm_toL1_eq_lintegral_norm (f : α → β) (hf : Integrable f μ) :
‖hf.toL1 f‖ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ‖f a‖ ∂μ) := by
rw [norm_toL1, lintegral_norm_eq_lintegral_edist]
@[simp]
theorem edist_toL1_toL1 (f g : α → β) (hf : Integrable f μ) (hg : Integrable g μ) :
edist (hf.toL1 f) (hg.toL1 g) = ∫⁻ a, edist (f a) (g a) ∂μ := by
simp only [toL1, Lp.edist_toLp_toLp, eLpNorm, one_ne_zero, eLpNorm'_eq_lintegral_enorm,
Pi.sub_apply, toReal_one, ENNReal.rpow_one, ne_eq, not_false_eq_true, div_self, ite_false]
simp [edist_eq_enorm_sub]
theorem edist_toL1_zero (f : α → β) (hf : Integrable f μ) :
edist (hf.toL1 f) 0 = ∫⁻ a, edist (f a) 0 ∂μ := by
simp only [edist_zero_right, Lp.enorm_def, toL1_eq_mk, eLpNorm_aeeqFun]
apply eLpNorm_one_eq_lintegral_enorm
variable {𝕜 : Type*} [NormedRing 𝕜] [Module 𝕜 β] [IsBoundedSMul 𝕜 β]
theorem toL1_smul (f : α → β) (hf : Integrable f μ) (k : 𝕜) :
toL1 (fun a => k • f a) (hf.smul k) = k • toL1 f hf :=
rfl
theorem toL1_smul' (f : α → β) (hf : Integrable f μ) (k : 𝕜) :
toL1 (k • f) (hf.smul k) = k • toL1 f hf :=
rfl
end Integrable
end MeasureTheory
|
all_field.v
|
From mathcomp Require Export algC.
From mathcomp Require Export algebraics_fundamentals.
From mathcomp Require Export algnum.
From mathcomp Require Export closed_field.
From mathcomp Require Export cyclotomic.
From mathcomp Require Export falgebra.
From mathcomp Require Export fieldext.
From mathcomp Require Export finfield.
From mathcomp Require Export galois.
From mathcomp Require Export separable.
From mathcomp Require Export qfpoly.
|
Comp.lean
|
/-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import Mathlib.Data.PFunctor.Multivariate.Basic
import Mathlib.Data.QPF.Multivariate.Basic
/-!
# The composition of QPFs is itself a QPF
We define composition between one `n`-ary functor and `n` `m`-ary functors
and show that it preserves the QPF structure
-/
universe u
namespace MvQPF
open MvFunctor
variable {n m : ℕ} (F : TypeVec.{u} n → Type*) (G : Fin2 n → TypeVec.{u} m → Type u)
/-- Composition of an `n`-ary functor with `n` `m`-ary
functors gives us one `m`-ary functor -/
def Comp (v : TypeVec.{u} m) : Type _ :=
F fun i : Fin2 n ↦ G i v
namespace Comp
open MvPFunctor
variable {F G} {α β : TypeVec.{u} m} (f : α ⟹ β)
instance [I : Inhabited (F fun i : Fin2 n ↦ G i α)] : Inhabited (Comp F G α) := I
/-- Constructor for functor composition -/
protected def mk (x : F fun i ↦ G i α) : Comp F G α := x
/-- Destructor for functor composition -/
protected def get (x : Comp F G α) : F fun i ↦ G i α := x
@[simp]
protected theorem mk_get (x : Comp F G α) : Comp.mk (Comp.get x) = x := rfl
@[simp]
protected theorem get_mk (x : F fun i ↦ G i α) : Comp.get (Comp.mk x) = x := rfl
section
variable [MvFunctor F] [∀ i, MvFunctor <| G i]
/-- map operation defined on a vector of functors -/
protected def map' : (fun i : Fin2 n ↦ G i α) ⟹ fun i : Fin2 n ↦ G i β := fun _i ↦ map f
/-- The composition of functors is itself functorial -/
protected def map : (Comp F G) α → (Comp F G) β :=
(map fun _i ↦ map f : (F fun i ↦ G i α) → F fun i ↦ G i β)
instance : MvFunctor (Comp F G) where map f := Comp.map f
theorem map_mk (x : F fun i ↦ G i α) :
f <$$> Comp.mk x = Comp.mk ((fun i (x : G i α) ↦ f <$$> x) <$$> x) := rfl
theorem get_map (x : Comp F G α) :
Comp.get (f <$$> x) = (fun i (x : G i α) ↦ f <$$> x) <$$> Comp.get x := rfl
end
instance [MvQPF F] [∀ i, MvQPF <| G i] : MvQPF (Comp F G) where
P := MvPFunctor.comp (P F) fun i ↦ P <| G i
abs := Comp.mk ∘ (map fun _ ↦ abs) ∘ abs ∘ MvPFunctor.comp.get
repr {α} := MvPFunctor.comp.mk ∘ repr ∘
(map fun i ↦ (repr : G i α → (fun i : Fin2 n ↦ Obj (P (G i)) α) i)) ∘ Comp.get
abs_repr := by
intros
simp +unfoldPartialApp only [Function.comp_def, comp.get_mk, abs_repr,
map_map, TypeVec.comp, MvFunctor.id_map', Comp.mk_get]
abs_map := by
intros
simp only [(· ∘ ·)]
rw [← abs_map]
simp +unfoldPartialApp only [comp.get_map, map_map, TypeVec.comp,
abs_map, map_mk]
end Comp
end MvQPF
|
SimplexAlgorithm.lean
|
/-
Copyright (c) 2024 Vasily Nesterov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Vasily Nesterov
-/
import Mathlib.Tactic.Linarith.Datatypes
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm.PositiveVector
/-!
# The oracle based on Simplex Algorithm
This file contains hooks to enable the use of the Simplex Algorithm in `linarith`.
The algorithm's entry point is the function `Linarith.SimplexAlgorithm.findPositiveVector`.
See the file `PositiveVector.lean` for details of how the procedure works.
-/
namespace Mathlib.Tactic.Linarith.SimplexAlgorithm
/-- Preprocess the goal to pass it to `Linarith.SimplexAlgorithm.findPositiveVector`. -/
def preprocess (matType : ℕ → ℕ → Type) [UsableInSimplexAlgorithm matType] (hyps : List Comp)
(maxVar : ℕ) : matType (maxVar + 1) (hyps.length) × List Nat :=
let values : List (ℕ × ℕ × ℚ) := hyps.foldlIdx (init := []) fun idx cur comp =>
cur ++ comp.coeffs.map fun (var, c) => (var, idx, c)
let strictIndexes := hyps.findIdxs (·.str == Ineq.lt)
(ofValues values, strictIndexes)
/--
Extract the certificate from the `vec` found by `Linarith.SimplexAlgorithm.findPositiveVector`.
-/
def postprocess (vec : Array ℚ) : Std.HashMap ℕ ℕ :=
let common_den : ℕ := vec.foldl (fun acc item => acc.lcm item.den) 1
let vecNat : Array ℕ := vec.map (fun x : ℚ => (x * common_den).floor.toNat)
(∅ : Std.HashMap Nat Nat).insertMany <| vecNat.zipIdx.filterMap
fun ⟨item, idx⟩ => if item != 0 then some (idx, item) else none
end SimplexAlgorithm
open SimplexAlgorithm
/-- An oracle that uses the Simplex Algorithm. -/
def CertificateOracle.simplexAlgorithmSparse : CertificateOracle where
produceCertificate hyps maxVar := do
let (A, strictIndexes) := preprocess SparseMatrix hyps maxVar
let vec ← findPositiveVector A strictIndexes
return postprocess vec
/--
The same oracle as `CertificateOracle.simplexAlgorithmSparse`, but uses dense matrices. Works faster
on dense states.
-/
def CertificateOracle.simplexAlgorithmDense : CertificateOracle where
produceCertificate hyps maxVar := do
let (A, strictIndexes) := preprocess DenseMatrix hyps maxVar
let vec ← findPositiveVector A strictIndexes
return postprocess vec
end Mathlib.Tactic.Linarith
|
Extreme.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.Analysis.Convex.Hull
/-!
# Extreme sets
This file defines extreme sets and extreme points for sets in a module.
An extreme set of `A` is a subset of `A` that is as far as it can get in any outward direction: If
point `x` is in it and point `y ∈ A`, then the line passing through `x` and `y` leaves `A` at `x`.
This is an analytic notion of "being on the side of". It is weaker than being exposed (see
`IsExposed.isExtreme`).
## Main declarations
* `IsExtreme 𝕜 A B`: States that `B` is an extreme set of `A` (in the literature, `A` is often
implicit).
* `Set.extremePoints 𝕜 A`: Set of extreme points of `A` (corresponding to extreme singletons).
* `Convex.mem_extremePoints_iff_convex_diff`: A useful equivalent condition to being an extreme
point: `x` is an extreme point iff `A \ {x}` is convex.
## Implementation notes
The exact definition of extremeness has been carefully chosen so as to make as many lemmas
unconditional (in particular, the Krein-Milman theorem doesn't need the set to be convex!).
In practice, `A` is often assumed to be a convex set.
## References
See chapter 8 of [Barry Simon, *Convexity*][simon2011]
## TODO
Prove lemmas relating extreme sets and points to the intrinsic frontier.
-/
open Function Set Affine
variable {𝕜 E F ι : Type*} {M : ι → Type*}
section SMul
variable (𝕜) [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [SMul 𝕜 E]
/-- A set `B` is an extreme subset of `A` if `B ⊆ A` and all points of `B` only belong to open
segments whose ends are in `B`. -/
def IsExtreme (A B : Set E) : Prop :=
B ⊆ A ∧ ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → ∀ ⦃x⦄, x ∈ B → x ∈ openSegment 𝕜 x₁ x₂ → x₁ ∈ B ∧ x₂ ∈ B
/-- A point `x` is an extreme point of a set `A` if `x` belongs to no open segment with ends in
`A`, except for the obvious `openSegment x x`.
In order to prove that `x` is an extreme point of `A`,
it is convenient to use `mem_extremePoints_iff_left` to avoid repeating arguments twice. -/
def Set.extremePoints (A : Set E) : Set E :=
{ x ∈ A | ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x ∧ x₂ = x }
@[refl]
protected theorem IsExtreme.refl (A : Set E) : IsExtreme 𝕜 A A :=
⟨Subset.rfl, fun _ hx₁A _ hx₂A _ _ _ ↦ ⟨hx₁A, hx₂A⟩⟩
variable {𝕜} {A B C : Set E} {x : E}
protected theorem IsExtreme.rfl : IsExtreme 𝕜 A A :=
IsExtreme.refl 𝕜 A
@[trans]
protected theorem IsExtreme.trans (hAB : IsExtreme 𝕜 A B) (hBC : IsExtreme 𝕜 B C) :
IsExtreme 𝕜 A C := by
refine ⟨Subset.trans hBC.1 hAB.1, fun x₁ hx₁A x₂ hx₂A x hxC hx ↦ ?_⟩
obtain ⟨hx₁B, hx₂B⟩ := hAB.2 hx₁A hx₂A (hBC.1 hxC) hx
exact hBC.2 hx₁B hx₂B hxC hx
protected theorem IsExtreme.antisymm : AntiSymmetric (IsExtreme 𝕜 : Set E → Set E → Prop) :=
fun _ _ hAB hBA ↦ Subset.antisymm hBA.1 hAB.1
instance : IsPartialOrder (Set E) (IsExtreme 𝕜) where
refl := IsExtreme.refl 𝕜
trans _ _ _ := IsExtreme.trans
antisymm := IsExtreme.antisymm
theorem IsExtreme.inter (hAB : IsExtreme 𝕜 A B) (hAC : IsExtreme 𝕜 A C) :
IsExtreme 𝕜 A (B ∩ C) := by
use Subset.trans inter_subset_left hAB.1
rintro x₁ hx₁A x₂ hx₂A x ⟨hxB, hxC⟩ hx
obtain ⟨hx₁B, hx₂B⟩ := hAB.2 hx₁A hx₂A hxB hx
obtain ⟨hx₁C, hx₂C⟩ := hAC.2 hx₁A hx₂A hxC hx
exact ⟨⟨hx₁B, hx₁C⟩, hx₂B, hx₂C⟩
protected theorem IsExtreme.mono (hAC : IsExtreme 𝕜 A C) (hBA : B ⊆ A) (hCB : C ⊆ B) :
IsExtreme 𝕜 B C :=
⟨hCB, fun _ hx₁B _ hx₂B _ hxC hx ↦ hAC.2 (hBA hx₁B) (hBA hx₂B) hxC hx⟩
theorem isExtreme_iInter {ι : Sort*} [Nonempty ι] {F : ι → Set E}
(hAF : ∀ i : ι, IsExtreme 𝕜 A (F i)) : IsExtreme 𝕜 A (⋂ i : ι, F i) := by
obtain i := Classical.arbitrary ι
refine ⟨iInter_subset_of_subset i (hAF i).1, fun x₁ hx₁A x₂ hx₂A x hxF hx ↦ ?_⟩
simp_rw [mem_iInter] at hxF ⊢
have h := fun i ↦ (hAF i).2 hx₁A hx₂A (hxF i) hx
exact ⟨fun i ↦ (h i).1, fun i ↦ (h i).2⟩
theorem isExtreme_biInter {F : Set (Set E)} (hF : F.Nonempty) (hA : ∀ B ∈ F, IsExtreme 𝕜 A B) :
IsExtreme 𝕜 A (⋂ B ∈ F, B) := by
haveI := hF.to_subtype
simpa only [iInter_subtype] using isExtreme_iInter fun i : F ↦ hA _ i.2
theorem isExtreme_sInter {F : Set (Set E)} (hF : F.Nonempty) (hAF : ∀ B ∈ F, IsExtreme 𝕜 A B) :
IsExtreme 𝕜 A (⋂₀ F) := by simpa [sInter_eq_biInter] using isExtreme_biInter hF hAF
theorem mem_extremePoints : x ∈ A.extremePoints 𝕜 ↔
x ∈ A ∧ ∀ᵉ (x₁ ∈ A) (x₂ ∈ A), x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x ∧ x₂ = x :=
Iff.rfl
/-- In order to prove that a point `x` is an extreme point of a set `A`,
it suffices to show that `x ∈ A`
and for any `x₁`, `x₂` such that `x` belongs to the open segment `(x₁, x₂)`, we have `x₁ = x`.
The definition of `extremePoints` also requires `x₂ = x`, but this condition is redundant. -/
theorem mem_extremePoints_iff_left : x ∈ A.extremePoints 𝕜 ↔
x ∈ A ∧ ∀ x₁ ∈ A, ∀ x₂ ∈ A, x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x := by
refine ⟨fun h ↦ ⟨h.1, fun x₁ hx₁ x₂ hx₂ hx ↦ (h.2 hx₁ hx₂ hx).1⟩, ?_⟩
rintro ⟨hxA, Hx⟩
use hxA
refine fun x₁ hx₁ x₂ hx₂ hx ↦ ⟨Hx x₁ hx₁ x₂ hx₂ hx, Hx x₂ hx₂ x₁ hx₁ ?_⟩
rwa [openSegment_symm]
/-- x is an extreme point to A iff {x} is an extreme set of A. -/
@[simp] lemma isExtreme_singleton : IsExtreme 𝕜 A {x} ↔ x ∈ A.extremePoints 𝕜 := by
refine ⟨fun hx ↦ ⟨singleton_subset_iff.1 hx.1, fun x₁ hx₁ x₂ hx₂ ↦ hx.2 hx₁ hx₂ rfl⟩, ?_⟩
rintro ⟨hxA, hAx⟩
use singleton_subset_iff.2 hxA
rintro x₁ hx₁A x₂ hx₂A y (rfl : y = x)
exact hAx hx₁A hx₂A
alias ⟨IsExtreme.mem_extremePoints, _⟩ := isExtreme_singleton
theorem extremePoints_subset : A.extremePoints 𝕜 ⊆ A :=
fun _ hx ↦ hx.1
@[simp]
theorem extremePoints_empty : (∅ : Set E).extremePoints 𝕜 = ∅ :=
subset_empty_iff.1 extremePoints_subset
@[simp]
theorem extremePoints_singleton : ({x} : Set E).extremePoints 𝕜 = {x} :=
extremePoints_subset.antisymm <|
singleton_subset_iff.2 ⟨mem_singleton x, fun _ hx₁ _ hx₂ _ ↦ ⟨hx₁, hx₂⟩⟩
theorem inter_extremePoints_subset_extremePoints_of_subset (hBA : B ⊆ A) :
B ∩ A.extremePoints 𝕜 ⊆ B.extremePoints 𝕜 :=
fun _ ⟨hxB, hxA⟩ ↦ ⟨hxB, fun _ hx₁ _ hx₂ hx ↦ hxA.2 (hBA hx₁) (hBA hx₂) hx⟩
theorem IsExtreme.extremePoints_subset_extremePoints (hAB : IsExtreme 𝕜 A B) :
B.extremePoints 𝕜 ⊆ A.extremePoints 𝕜 :=
fun _ ↦ by simpa only [← isExtreme_singleton] using hAB.trans
theorem IsExtreme.extremePoints_eq (hAB : IsExtreme 𝕜 A B) :
B.extremePoints 𝕜 = B ∩ A.extremePoints 𝕜 :=
Subset.antisymm (fun _ hx ↦ ⟨hx.1, hAB.extremePoints_subset_extremePoints hx⟩)
(inter_extremePoints_subset_extremePoints_of_subset hAB.1)
end SMul
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommGroup E] [AddCommGroup F] [∀ i, AddCommGroup (M i)]
[Module 𝕜 E] [Module 𝕜 F] [∀ i, Module 𝕜 (M i)] {A B : Set E}
theorem IsExtreme.convex_diff [IsOrderedRing 𝕜] (hA : Convex 𝕜 A) (hAB : IsExtreme 𝕜 A B) :
Convex 𝕜 (A \ B) :=
convex_iff_openSegment_subset.2 fun _ ⟨hx₁A, hx₁B⟩ _ ⟨hx₂A, _⟩ _ hx ↦
⟨hA.openSegment_subset hx₁A hx₂A hx, fun hxB ↦ hx₁B (hAB.2 hx₁A hx₂A hxB hx).1⟩
@[simp]
theorem extremePoints_prod (s : Set E) (t : Set F) :
(s ×ˢ t).extremePoints 𝕜 = s.extremePoints 𝕜 ×ˢ t.extremePoints 𝕜 := by
ext
refine (and_congr_right fun hx ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩).trans and_and_and_comm
constructor
· rintro x₁ hx₁ x₂ hx₂ hx_fst
refine (h (mk_mem_prod hx₁ hx.2) (mk_mem_prod hx₂ hx.2) ?_).imp (congr_arg Prod.fst)
(congr_arg Prod.fst)
rw [← Prod.image_mk_openSegment_left]
exact ⟨_, hx_fst, rfl⟩
· rintro x₁ hx₁ x₂ hx₂ hx_snd
refine (h (mk_mem_prod hx.1 hx₁) (mk_mem_prod hx.1 hx₂) ?_).imp (congr_arg Prod.snd)
(congr_arg Prod.snd)
rw [← Prod.image_mk_openSegment_right]
exact ⟨_, hx_snd, rfl⟩
· rintro x₁ hx₁ x₂ hx₂ ⟨a, b, ha, hb, hab, hx'⟩
simp_rw [Prod.ext_iff]
exact and_and_and_comm.1
⟨h.1 hx₁.1 hx₂.1 ⟨a, b, ha, hb, hab, congr_arg Prod.fst hx'⟩,
h.2 hx₁.2 hx₂.2 ⟨a, b, ha, hb, hab, congr_arg Prod.snd hx'⟩⟩
@[simp]
theorem extremePoints_pi (s : ∀ i, Set (M i)) :
(univ.pi s).extremePoints 𝕜 = univ.pi fun i ↦ (s i).extremePoints 𝕜 := by
classical
ext x
simp only [mem_extremePoints, mem_pi, mem_univ, true_imp_iff, @forall_and ι]
refine and_congr_right fun hx ↦ ⟨fun h i ↦ ?_, fun h ↦ ?_⟩
· rintro x₁ hx₁ x₂ hx₂ hi
refine (h (update x i x₁) ?_ (update x i x₂) ?_ ?_).imp (fun h₁ ↦ by rw [← h₁, update_self])
fun h₂ ↦ by rw [← h₂, update_self]
iterate 2
rintro j
obtain rfl | hji := eq_or_ne j i
· rwa [update_self]
· rw [update_of_ne hji]
exact hx _
rw [← Pi.image_update_openSegment]
exact ⟨_, hi, update_eq_self _ _⟩
· rintro x₁ hx₁ x₂ hx₂ ⟨a, b, ha, hb, hab, hx'⟩
simp_rw [funext_iff, ← forall_and]
exact fun i ↦ h _ _ (hx₁ _) _ (hx₂ _) ⟨a, b, ha, hb, hab, congr_fun hx' _⟩
end OrderedSemiring
section OrderedRing
variable {L : Type*} [Ring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜]
[AddCommGroup E] [Module 𝕜 E] [AddCommGroup F] [Module 𝕜 F]
[EquivLike L E F] [LinearEquivClass L 𝕜 E F]
lemma image_extremePoints (f : L) (s : Set E) :
f '' extremePoints 𝕜 s = extremePoints 𝕜 (f '' s) := by
ext b
obtain ⟨a, rfl⟩ := EquivLike.surjective f b
have : ∀ x y, f '' openSegment 𝕜 x y = openSegment 𝕜 (f x) (f y) :=
image_openSegment _ (LinearMapClass.linearMap f).toAffineMap
simp only [mem_extremePoints, (EquivLike.surjective f).forall,
(EquivLike.injective f).mem_set_image, (EquivLike.injective f).eq_iff, ← this]
end OrderedRing
section LinearOrderedRing
variable [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] {A : Set E} {x : E}
/-- A useful restatement using `segment`: `x` is an extreme point iff the only (closed) segments
that contain it are those with `x` as one of their endpoints. -/
theorem mem_extremePoints_iff_forall_segment : x ∈ A.extremePoints 𝕜 ↔
x ∈ A ∧ ∀ᵉ (x₁ ∈ A) (x₂ ∈ A), x ∈ segment 𝕜 x₁ x₂ → x₁ = x ∨ x₂ = x := by
refine and_congr_right fun hxA ↦ forall₄_congr fun x₁ h₁ x₂ h₂ ↦ ?_
constructor
· rw [← insert_endpoints_openSegment]
rintro H (rfl | rfl | hx)
exacts [Or.inl rfl, Or.inr rfl, Or.inl <| (H hx).1]
· intro H hx
rcases H (openSegment_subset_segment _ _ _ hx) with (rfl | rfl)
exacts [⟨rfl, (left_mem_openSegment_iff.1 hx).symm⟩, ⟨right_mem_openSegment_iff.1 hx, rfl⟩]
theorem Convex.mem_extremePoints_iff_convex_diff (hA : Convex 𝕜 A) :
x ∈ A.extremePoints 𝕜 ↔ x ∈ A ∧ Convex 𝕜 (A \ {x}) := by
use fun hx ↦ ⟨hx.1, (isExtreme_singleton.2 hx).convex_diff hA⟩
rintro ⟨hxA, hAx⟩
refine mem_extremePoints_iff_forall_segment.2 ⟨hxA, fun x₁ hx₁ x₂ hx₂ hx ↦ ?_⟩
rw [convex_iff_segment_subset] at hAx
by_contra! h
exact (hAx ⟨hx₁, fun hx₁ ↦ h.1 (mem_singleton_iff.2 hx₁)⟩
⟨hx₂, fun hx₂ ↦ h.2 (mem_singleton_iff.2 hx₂)⟩ hx).2 rfl
theorem Convex.mem_extremePoints_iff_mem_diff_convexHull_diff (hA : Convex 𝕜 A) :
x ∈ A.extremePoints 𝕜 ↔ x ∈ A \ convexHull 𝕜 (A \ {x}) := by
rw [hA.mem_extremePoints_iff_convex_diff, hA.convex_remove_iff_notMem_convexHull_remove,
mem_diff]
theorem extremePoints_convexHull_subset : (convexHull 𝕜 A).extremePoints 𝕜 ⊆ A := by
rintro x hx
rw [(convex_convexHull 𝕜 _).mem_extremePoints_iff_convex_diff] at hx
by_contra h
exact (convexHull_min (subset_diff.2 ⟨subset_convexHull 𝕜 _, disjoint_singleton_right.2 h⟩) hx.2
hx.1).2 rfl
end LinearOrderedRing
|
LinearMap.lean
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Cayley-Hamilton theorem for f.g. modules.
Given a fixed finite spanning set `b : ι → M` of an `R`-module `M`, we say that a matrix `M`
represents an endomorphism `f : M →ₗ[R] M` if the matrix as an endomorphism of `ι → R` commutes
with `f` via the projection `(ι → R) →ₗ[R] M` given by `b`.
We show that every endomorphism has a matrix representation, and if `f.range ≤ I • ⊤` for some
ideal `I`, we may furthermore obtain a matrix representation whose entries fall in `I`.
This is used to conclude the Cayley-Hamilton theorem for f.g. modules over arbitrary rings.
-/
variable {ι : Type*} [Fintype ι]
variable {M : Type*} [AddCommGroup M] (R : Type*) [CommRing R] [Module R M] (I : Ideal R)
variable (b : ι → M)
open Polynomial Matrix
/-- The composition of a matrix (as an endomorphism of `ι → R`) with the projection
`(ι → R) →ₗ[R] M`. -/
def PiToModule.fromMatrix [DecidableEq ι] : Matrix ι ι R →ₗ[R] (ι → R) →ₗ[R] M :=
(LinearMap.llcomp R _ _ _ (Fintype.linearCombination R b)).comp algEquivMatrix'.symm.toLinearMap
theorem PiToModule.fromMatrix_apply [DecidableEq ι] (A : Matrix ι ι R) (w : ι → R) :
PiToModule.fromMatrix R b A w = Fintype.linearCombination R b (A *ᵥ w) :=
rfl
theorem PiToModule.fromMatrix_apply_single_one [DecidableEq ι] (A : Matrix ι ι R) (j : ι) :
PiToModule.fromMatrix R b A (Pi.single j 1) = ∑ i : ι, A i j • b i := by
rw [PiToModule.fromMatrix_apply, Fintype.linearCombination_apply, Matrix.mulVec_single]
simp_rw [MulOpposite.op_one, one_smul, col_apply]
/-- The endomorphisms of `M` acts on `(ι → R) →ₗ[R] M`, and takes the projection
to a `(ι → R) →ₗ[R] M`. -/
def PiToModule.fromEnd : Module.End R M →ₗ[R] (ι → R) →ₗ[R] M :=
LinearMap.lcomp _ _ (Fintype.linearCombination R b)
theorem PiToModule.fromEnd_apply (f : Module.End R M) (w : ι → R) :
PiToModule.fromEnd R b f w = f (Fintype.linearCombination R b w) :=
rfl
theorem PiToModule.fromEnd_apply_single_one [DecidableEq ι] (f : Module.End R M) (i : ι) :
PiToModule.fromEnd R b f (Pi.single i 1) = f (b i) := by
rw [PiToModule.fromEnd_apply, Fintype.linearCombination_apply_single, one_smul]
theorem PiToModule.fromEnd_injective (hb : Submodule.span R (Set.range b) = ⊤) :
Function.Injective (PiToModule.fromEnd R b) := by
intro x y e
ext m
obtain ⟨m, rfl⟩ : m ∈ LinearMap.range (Fintype.linearCombination R b) := by
rw [(Fintype.range_linearCombination R b).trans hb]
exact Submodule.mem_top
exact (LinearMap.congr_fun e m :)
section
variable {R} [DecidableEq ι]
/-- We say that a matrix represents an endomorphism of `M` if the matrix acting on `ι → R` is
equal to `f` via the projection `(ι → R) →ₗ[R] M` given by a fixed (spanning) set. -/
def Matrix.Represents (A : Matrix ι ι R) (f : Module.End R M) : Prop :=
PiToModule.fromMatrix R b A = PiToModule.fromEnd R b f
variable {b}
theorem Matrix.Represents.congr_fun {A : Matrix ι ι R} {f : Module.End R M} (h : A.Represents b f)
(x) : Fintype.linearCombination R b (A *ᵥ x) = f (Fintype.linearCombination R b x) :=
LinearMap.congr_fun h x
theorem Matrix.represents_iff {A : Matrix ι ι R} {f : Module.End R M} :
A.Represents b f ↔
∀ x, Fintype.linearCombination R b (A *ᵥ x) = f (Fintype.linearCombination R b x) :=
⟨fun e x => e.congr_fun x, fun H => LinearMap.ext fun x => H x⟩
theorem Matrix.represents_iff' {A : Matrix ι ι R} {f : Module.End R M} :
A.Represents b f ↔ ∀ j, ∑ i : ι, A i j • b i = f (b j) := by
constructor
· intro h i
have := LinearMap.congr_fun h (Pi.single i 1)
rwa [PiToModule.fromEnd_apply_single_one, PiToModule.fromMatrix_apply_single_one] at this
· intro h
ext
simp_rw [LinearMap.comp_apply, LinearMap.coe_single, PiToModule.fromEnd_apply_single_one,
PiToModule.fromMatrix_apply_single_one]
apply h
theorem Matrix.Represents.mul {A A' : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : Matrix.Represents b A' f') : (A * A').Represents b (f * f') := by
delta Matrix.Represents PiToModule.fromMatrix
rw [LinearMap.comp_apply, AlgEquiv.toLinearMap_apply, map_mul]
ext
dsimp [PiToModule.fromEnd]
rw [← h'.congr_fun, ← h.congr_fun]
rfl
theorem Matrix.Represents.one : (1 : Matrix ι ι R).Represents b 1 := by
delta Matrix.Represents PiToModule.fromMatrix
rw [LinearMap.comp_apply, AlgEquiv.toLinearMap_apply, map_one]
ext
rfl
theorem Matrix.Represents.add {A A' : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : Matrix.Represents b A' f') : (A + A').Represents b (f + f') := by
delta Matrix.Represents at h h' ⊢; rw [map_add, map_add, h, h']
theorem Matrix.Represents.zero : (0 : Matrix ι ι R).Represents b 0 := by
delta Matrix.Represents
rw [map_zero, map_zero]
theorem Matrix.Represents.smul {A : Matrix ι ι R} {f : Module.End R M} (h : A.Represents b f)
(r : R) : (r • A).Represents b (r • f) := by
delta Matrix.Represents at h ⊢
rw [map_smul, map_smul, h]
theorem Matrix.Represents.algebraMap (r : R) :
(algebraMap _ (Matrix ι ι R) r).Represents b (algebraMap _ (Module.End R M) r) := by
simpa only [Algebra.algebraMap_eq_smul_one] using Matrix.Represents.one.smul r
theorem Matrix.Represents.eq (hb : Submodule.span R (Set.range b) = ⊤)
{A : Matrix ι ι R} {f f' : Module.End R M} (h : A.Represents b f)
(h' : A.Represents b f') : f = f' :=
PiToModule.fromEnd_injective R b hb (h.symm.trans h')
variable (b R)
/-- The subalgebra of `Matrix ι ι R` that consists of matrices that actually represent
endomorphisms on `M`. -/
def Matrix.isRepresentation : Subalgebra R (Matrix ι ι R) where
carrier := { A | ∃ f : Module.End R M, A.Represents b f }
mul_mem' := fun ⟨f₁, e₁⟩ ⟨f₂, e₂⟩ => ⟨f₁ * f₂, e₁.mul e₂⟩
one_mem' := ⟨1, Matrix.Represents.one⟩
add_mem' := fun ⟨f₁, e₁⟩ ⟨f₂, e₂⟩ => ⟨f₁ + f₂, e₁.add e₂⟩
zero_mem' := ⟨0, Matrix.Represents.zero⟩
algebraMap_mem' r := ⟨algebraMap _ _ r, .algebraMap _⟩
variable (hb : Submodule.span R (Set.range b) = ⊤)
include hb
/-- The map sending a matrix to the endomorphism it represents. This is an `R`-algebra morphism. -/
noncomputable def Matrix.isRepresentation.toEnd :
Matrix.isRepresentation R b →ₐ[R] Module.End R M where
toFun A := A.2.choose
map_one' := (1 : Matrix.isRepresentation R b).2.choose_spec.eq hb Matrix.Represents.one
map_mul' A₁ A₂ := (A₁ * A₂).2.choose_spec.eq hb (A₁.2.choose_spec.mul A₂.2.choose_spec)
map_zero' := (0 : Matrix.isRepresentation R b).2.choose_spec.eq hb Matrix.Represents.zero
map_add' A₁ A₂ := (A₁ + A₂).2.choose_spec.eq hb (A₁.2.choose_spec.add A₂.2.choose_spec)
commutes' r :=
(algebraMap _ (Matrix.isRepresentation R b) r).2.choose_spec.eq hb (.algebraMap r)
theorem Matrix.isRepresentation.toEnd_represents (A : Matrix.isRepresentation R b) :
(A : Matrix ι ι R).Represents b (Matrix.isRepresentation.toEnd R b hb A) :=
A.2.choose_spec
theorem Matrix.isRepresentation.eq_toEnd_of_represents (A : Matrix.isRepresentation R b)
{f : Module.End R M} (h : (A : Matrix ι ι R).Represents b f) :
Matrix.isRepresentation.toEnd R b hb A = f :=
A.2.choose_spec.eq hb h
theorem Matrix.isRepresentation.toEnd_exists_mem_ideal (f : Module.End R M) (I : Ideal R)
(hI : LinearMap.range f ≤ I • ⊤) :
∃ M, Matrix.isRepresentation.toEnd R b hb M = f ∧ ∀ i j, M.1 i j ∈ I := by
have : ∀ x, f x ∈ LinearMap.range (Ideal.finsuppTotal ι M I b) := by
rw [Ideal.range_finsuppTotal, hb]
exact fun x => hI (LinearMap.mem_range_self f x)
choose bM' hbM' using this
let A : Matrix ι ι R := fun i j => bM' (b j) i
have : A.Represents b f := by
rw [Matrix.represents_iff']
dsimp [A]
intro j
specialize hbM' (b j)
rwa [Ideal.finsuppTotal_apply_eq_of_fintype] at hbM'
exact
⟨⟨A, f, this⟩, Matrix.isRepresentation.eq_toEnd_of_represents R b hb ⟨A, f, this⟩ this,
fun i j => (bM' (b j) i).prop⟩
theorem Matrix.isRepresentation.toEnd_surjective :
Function.Surjective (Matrix.isRepresentation.toEnd R b hb) := by
intro f
obtain ⟨M, e, -⟩ := Matrix.isRepresentation.toEnd_exists_mem_ideal R b hb f ⊤ (by simp)
exact ⟨M, e⟩
end
/-- The **Cayley-Hamilton Theorem** for f.g. modules over arbitrary rings states that for each
`R`-endomorphism `φ` of an `R`-module `M` such that `φ(M) ≤ I • M` for some ideal `I`, there
exists some `n` and some `aᵢ ∈ Iⁱ` such that `φⁿ + a₁ φⁿ⁻¹ + ⋯ + aₙ = 0`.
This is the version found in Eisenbud 4.3, which is slightly weaker than Matsumura 2.1
(this lacks the constraint on `n`), and is slightly stronger than Atiyah-Macdonald 2.4.
-/
theorem LinearMap.exists_monic_and_coeff_mem_pow_and_aeval_eq_zero_of_range_le_smul
[Module.Finite R M] (f : Module.End R M) (I : Ideal R) (hI : LinearMap.range f ≤ I • ⊤) :
∃ p : R[X], p.Monic ∧ (∀ k, p.coeff k ∈ I ^ (p.natDegree - k)) ∧ Polynomial.aeval f p = 0 := by
classical
cases subsingleton_or_nontrivial R
· exact ⟨0, Polynomial.monic_of_subsingleton _, by simp⟩
obtain ⟨s : Finset M, hs : Submodule.span R (s : Set M) = ⊤⟩ :=
Module.Finite.fg_top (R := R) (M := M)
obtain ⟨A, rfl, h⟩ :=
Matrix.isRepresentation.toEnd_exists_mem_ideal R ((↑) : s → M)
(by rw [Subtype.range_coe_subtype, Finset.setOf_mem, hs]) f I hI
refine ⟨A.1.charpoly, A.1.charpoly_monic, ?_, ?_⟩
· rw [A.1.charpoly_natDegree_eq_dim]
exact coeff_charpoly_mem_ideal_pow h
· rw [Polynomial.aeval_algHom_apply,
← map_zero (Matrix.isRepresentation.toEnd R ((↑) : s → M) _)]
congr 1
ext1
rw [Polynomial.aeval_subalgebra_coe, Matrix.aeval_self_charpoly, Subalgebra.coe_zero]
theorem LinearMap.exists_monic_and_aeval_eq_zero [Module.Finite R M] (f : Module.End R M) :
∃ p : R[X], p.Monic ∧ Polynomial.aeval f p = 0 :=
(LinearMap.exists_monic_and_coeff_mem_pow_and_aeval_eq_zero_of_range_le_smul R f ⊤ (by simp)).imp
fun _ h => h.imp_right And.right
|
Membership.lean
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Group.Subsemigroup.Basic
/-!
# Subsemigroups: membership criteria
In this file we prove various facts about membership in a subsemigroup.
The intent is to mimic `GroupTheory/Submonoid/Membership`, but currently this file is mostly a
stub and only provides rudimentary support.
* `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directed_on`,
`coe_sSup_of_directed_on`: the supremum of a directed collection of subsemigroup is their union.
## TODO
* Define the `FreeSemigroup` generated by a set. This might require some rather substantial
additions to low-level API. For example, developing the subtype of nonempty lists, then defining
a product on nonempty lists, powers where the exponent is a positive natural, et cetera.
Another option would be to define the `FreeSemigroup` as the subsemigroup (pushed to be a
semigroup) of the `FreeMonoid` consisting of non-identity elements.
## Tags
subsemigroup
-/
assert_not_exists MonoidWithZero
variable {ι : Sort*} {M : Type*}
section NonAssoc
variable [Mul M]
open Set
namespace Subsemigroup
-- TODO: this section can be generalized to `[MulMemClass B M] [CompleteLattice B]`
-- such that `complete_lattice.le` coincides with `set_like.le`
@[to_additive]
theorem mem_iSup_of_directed {S : ι → Subsemigroup M} (hS : Directed (· ≤ ·) S) {x : M} :
(x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
suffices x ∈ closure (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by
simpa only [closure_iUnion, closure_eq (S _)] using this
refine fun hx ↦ closure_induction (fun y hy ↦ mem_iUnion.mp hy) ?_ hx
rintro x y - - ⟨i, hi⟩ ⟨j, hj⟩
rcases hS i j with ⟨k, hki, hkj⟩
exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩
@[to_additive]
theorem coe_iSup_of_directed {S : ι → Subsemigroup M} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Subsemigroup M) : Set M) = ⋃ i, S i :=
Set.ext fun x => by simp [mem_iSup_of_directed hS]
@[to_additive]
theorem mem_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (· ≤ ·) S) {x : M} :
x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, exists_prop]
@[to_additive]
theorem coe_sSup_of_directed_on {S : Set (Subsemigroup M)} (hS : DirectedOn (· ≤ ·) S) :
(↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directed_on hS]
@[to_additive]
theorem mem_sup_left {S T : Subsemigroup M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by
have : S ≤ S ⊔ T := le_sup_left
tauto
@[to_additive]
theorem mem_sup_right {S T : Subsemigroup M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by
have : T ≤ S ⊔ T := le_sup_right
tauto
@[to_additive]
theorem mul_mem_sup {S T : Subsemigroup M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
mul_mem (mem_sup_left hx) (mem_sup_right hy)
@[to_additive]
theorem mem_iSup_of_mem {S : ι → Subsemigroup M} (i : ι) : ∀ {x : M}, x ∈ S i → x ∈ iSup S := by
have : S i ≤ iSup S := le_iSup _ _
tauto
@[to_additive]
theorem mem_sSup_of_mem {S : Set (Subsemigroup M)} {s : Subsemigroup M} (hs : s ∈ S) :
∀ {x : M}, x ∈ s → x ∈ sSup S := by
have : s ≤ sSup S := le_sSup hs
tauto
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds all elements of `S i` for all `i`, and is preserved under multiplication,
then it holds for all elements of the supremum of `S`. -/
@[to_additive (attr := elab_as_elim)
/-- An induction principle for elements of `⨆ i, S i`. If `C` holds all
elements of `S i` for all `i`, and is preserved under addition, then it holds for all elements of
the supremum of `S`. -/]
theorem iSup_induction (S : ι → Subsemigroup M) {C : M → Prop} {x₁ : M} (hx₁ : x₁ ∈ ⨆ i, S i)
(mem : ∀ i, ∀ x₂ ∈ S i, C x₂) (mul : ∀ x y, C x → C y → C (x * y)) : C x₁ := by
rw [iSup_eq_closure] at hx₁
refine closure_induction (fun x₂ hx₂ => ?_) (fun x y _ _ ↦ mul x y) hx₁
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx₂
exact mem _ _ hi
/-- A dependent version of `Subsemigroup.iSup_induction`. -/
@[to_additive (attr := elab_as_elim)
/-- A dependent version of `AddSubsemigroup.iSup_induction`. -/]
theorem iSup_induction' (S : ι → Subsemigroup M) {C : ∀ x, (x ∈ ⨆ i, S i) → Prop}
(mem : ∀ (i) (x) (hxS : x ∈ S i), C x (mem_iSup_of_mem i ‹_›))
(mul : ∀ x y hx hy, C x hx → C y hy → C (x * y) (mul_mem ‹_› ‹_›)) {x₁ : M}
(hx₁ : x₁ ∈ ⨆ i, S i) : C x₁ hx₁ := by
refine Exists.elim ?_ fun (hx₁' : x₁ ∈ ⨆ i, S i) (hc : C x₁ hx₁') => hc
refine @iSup_induction _ _ _ S (fun x' => ∃ hx'', C x' hx'') _ hx₁
(fun i x₂ hx₂ => ?_) fun x₃ y => ?_
· exact ⟨_, mem _ _ hx₂⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, mul _ _ _ _ Cx Cy⟩
end Subsemigroup
end NonAssoc
|
Braided.lean
|
/-
Copyright (c) 2025 Robin Carlier. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robin Carlier
-/
import Mathlib.CategoryTheory.Monoidal.DayConvolution
/-!
# Braidings for Day convolution
In this file, we show that if `C` is a braided monoidal category and
`V` also a braided monoidal category, then the Day convolution monoidal structure
on `C ⥤ V` is also braided monoidal. We prove it by constructing an explicit
braiding isomorphism whenever sufficient Day convolutions exist, and we
prove that it satisfies the forward and reverse hexagon identities.
Furthermore, we show that when both `C` and `V` are symmetric monoidal
categories, then the Day convolution monoidal structure is symmetric as well.
-/
universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅
namespace CategoryTheory.MonoidalCategory.DayConvolution
open scoped ExternalProduct
open Opposite
noncomputable section
variable {C : Type u₁} [Category.{v₁} C] {V : Type u₂} [Category.{v₂} V]
[MonoidalCategory C] [BraidedCategory C]
[MonoidalCategory V] [BraidedCategory V]
(F G : C ⥤ V)
section
variable [DayConvolution F G] [DayConvolution G F]
/-- The natural transformation `F ⊠ G ⟶ (tensor C) ⋙ (G ⊛ F)` that corepresents
the braiding morphism `F ⊛ G ⟶ G ⊛ F`. -/
@[simps]
def braidingHomCorepresenting : F ⊠ G ⟶ tensor C ⋙ G ⊛ F where
app _ := (β_ _ _).hom ≫ (unit G F).app (_, _) ≫ (G ⊛ F).map (β_ _ _).hom
naturality {x y} f := by simp [tensorHom_def, ← Functor.map_comp]
/-- The natural transformation `F ⊠ G ⟶ (tensor C) ⋙ (G ⊛ F)` that corepresents
the braiding morphism `F ⊛ G ⟶ G ⊛ F`. -/
@[simps]
def braidingInvCorepresenting : G ⊠ F ⟶ tensor C ⋙ F ⊛ G where
app _ := (β_ _ _).inv ≫ (unit F G).app (_, _) ≫ (F ⊛ G).map (β_ _ _).inv
naturality {x y} f := by simp [tensorHom_def, ← Functor.map_comp]
/-- The braiding isomorphism for Day convolution. -/
def braiding : F ⊛ G ≅ G ⊛ F where
hom := corepresentableBy F G|>.homEquiv.symm <| braidingHomCorepresenting F G
inv := corepresentableBy G F|>.homEquiv.symm <| braidingInvCorepresenting F G
hom_inv_id := by
apply Functor.hom_ext_of_isLeftKanExtension (F ⊛ G) (unit F G)
ext
simp [-tensor_obj]
inv_hom_id := by
apply Functor.hom_ext_of_isLeftKanExtension (G ⊛ F) (unit G F)
ext
simp [-tensor_obj]
@[reassoc (attr := simp)]
lemma unit_app_braiding_hom_app (x y : C) :
(unit F G).app (x, y) ≫ (braiding F G).hom.app (x ⊗ y) =
(β_ _ _).hom ≫ (unit G F).app (_, _) ≫ (G ⊛ F).map (β_ _ _).hom := by
change
(unit F G).app (x, y) ≫ (braiding F G).hom.app ((tensor C).obj (x, y)) = _
simp [braiding, braidingHomCorepresenting, -tensor_obj]
@[reassoc (attr := simp)]
lemma unit_app_braiding_inv_app (x y : C) :
(unit G F).app (x, y) ≫ (braiding F G).inv.app (x ⊗ y) =
(β_ _ _).inv ≫ (unit F G).app (_, _) ≫ (F ⊛ G).map (β_ _ _).inv := by
change
(unit G F).app (x, y) ≫ (braiding F G).inv.app ((tensor C).obj (x, y)) = _
simp [braiding, braidingHomCorepresenting, -tensor_obj]
end
variable {F G}
@[reassoc (attr := simp)]
lemma braiding_naturality_right (H : C ⥤ V) (η : F ⟶ G)
[DayConvolution F H] [DayConvolution H F]
[DayConvolution G H] [DayConvolution H G] :
DayConvolution.map (𝟙 H) η ≫ (braiding H G).hom =
(braiding H F).hom ≫ DayConvolution.map η (𝟙 H) := by
apply Functor.hom_ext_of_isLeftKanExtension (H ⊛ F) (unit H F)
ext ⟨_, _⟩
simp
@[reassoc (attr := simp)]
lemma braiding_naturality_left (η : F ⟶ G) (H : C ⥤ V)
[DayConvolution F H] [DayConvolution H F]
[DayConvolution G H] [DayConvolution H G] :
DayConvolution.map η (𝟙 H) ≫ (braiding G H).hom =
(braiding F H).hom ≫ DayConvolution.map (𝟙 H) η := by
apply Functor.hom_ext_of_isLeftKanExtension (F ⊛ H) (unit F H)
ext ⟨_, _⟩
simp
variable
[∀ (v : V) (d : C),
Limits.PreservesColimitsOfShape (CostructuredArrow (tensor C) d) (tensorLeft v)]
[∀ (v : V) (d : C),
Limits.PreservesColimitsOfShape (CostructuredArrow (tensor C) d) (tensorRight v)]
variable (F G) in
lemma hexagon_forward (H : C ⥤ V)
[DayConvolution F G] [DayConvolution G H] [DayConvolution F (G ⊛ H)]
[DayConvolution (F ⊛ G) H] [DayConvolution H F] [DayConvolution G (H ⊛ F)]
[DayConvolution (G ⊛ H) F] [DayConvolution G F] [DayConvolution (G ⊛ F) H]
[DayConvolution F H] [DayConvolution G (F ⊛ H)] :
(associator F G H).hom ≫ (braiding F (G ⊛ H)).hom ≫ (associator G H F).hom =
(DayConvolution.map (braiding F G).hom (𝟙 H)) ≫ (associator G F H).hom ≫
(DayConvolution.map (𝟙 G) (braiding F H).hom) := by
apply Functor.hom_ext_of_isLeftKanExtension ((F ⊛ G) ⊛ H) (unit _ H)
apply Functor.hom_ext_of_isLeftKanExtension ((F ⊛ G) ⊠ H)
(ExternalProduct.extensionUnitLeft (F ⊛ G) (unit F G) H)
ext ⟨⟨x, y⟩, z⟩
dsimp
simp only [whiskerLeft_id, Category.comp_id, associator_hom_unit_unit_assoc,
externalProductBifunctor_obj_obj, tensor_obj, NatTrans.naturality_assoc,
NatTrans.naturality, unit_app_braiding_hom_app_assoc,
BraidedCategory.braiding_tensor_left_hom, Functor.map_comp, Category.assoc,
Iso.map_hom_inv_id, BraidedCategory.braiding_naturality_right_assoc,
BraidedCategory.braiding_tensor_right_hom, Iso.map_inv_hom_id_assoc,
Iso.inv_hom_id_assoc, Iso.hom_inv_id_assoc, unit_app_map_app_assoc,
NatTrans.id_app, tensorHom_id]
simp only [← comp_whiskerRight_assoc, ← whiskerLeft_comp_assoc,
unit_app_braiding_hom_app]
simp only [whiskerLeft_comp, ← Functor.map_comp, Category.assoc,
Functor.comp_obj, tensor_obj, comp_whiskerRight,
whiskerRight_comp_unit_app_assoc, NatTrans.naturality_assoc,
NatTrans.naturality, associator_hom_unit_unit_assoc,
externalProductBifunctor_obj_obj, unit_app_map_app_assoc, NatTrans.id_app,
id_tensorHom]
rw [← BraidedCategory.hexagon_reverse, ← whiskerLeft_comp_assoc]
haveI := unit_app_braiding_hom_app F H x z =≫ (H ⊛ F).map (β_ z x).inv
dsimp at this
simp only [Category.assoc, Iso.map_hom_inv_id, Category.comp_id] at this
rw [← this, whiskerLeft_comp_assoc]
simp [← Functor.map_comp]
variable (F G) in
lemma hexagon_reverse (H : C ⥤ V)
[DayConvolution F G] [DayConvolution G H] [DayConvolution F (G ⊛ H)]
[DayConvolution (F ⊛ G) H] [DayConvolution H (F ⊛ G)] [DayConvolution H F]
[DayConvolution (H ⊛ F) G] [DayConvolution H G] [DayConvolution F (H ⊛ G)]
[DayConvolution F H] [DayConvolution (F ⊛ H) G] :
(associator F G H).inv ≫ (braiding (F ⊛ G) H).hom ≫ (associator H F G).inv =
(DayConvolution.map (𝟙 F) (braiding G H).hom) ≫ (associator F H G).inv ≫
(DayConvolution.map (braiding F H).hom (𝟙 G)) := by
apply Functor.hom_ext_of_isLeftKanExtension (F ⊛ G ⊛ H) (unit _ _)
apply Functor.hom_ext_of_isLeftKanExtension (F ⊠ (G ⊛ H))
(ExternalProduct.extensionUnitRight (G ⊛ H) (unit G H) F)
ext ⟨x, y, z⟩
dsimp
simp only [whiskerRight_tensor, id_whiskerRight, Category.id_comp,
Iso.inv_hom_id, associator_inv_unit_unit_assoc,
externalProductBifunctor_obj_obj, tensor_obj, NatTrans.naturality_assoc,
NatTrans.naturality, unit_app_braiding_hom_app_assoc,
BraidedCategory.braiding_tensor_right_hom, Functor.map_comp, Category.assoc,
Iso.map_inv_hom_id, Category.comp_id,
BraidedCategory.braiding_naturality_left_assoc,
BraidedCategory.braiding_tensor_left_hom, Iso.map_hom_inv_id_assoc,
Iso.hom_inv_id_assoc, Iso.inv_hom_id_assoc, unit_app_map_app_assoc,
NatTrans.id_app, id_tensorHom]
simp only [← comp_whiskerRight_assoc, ← whiskerLeft_comp_assoc,
unit_app_braiding_hom_app]
simp [← Functor.map_comp]
congr 2
rw [← BraidedCategory.hexagon_forward, ← comp_whiskerRight_assoc]
haveI := unit_app_braiding_hom_app F H x z =≫ (H ⊛ F).map (β_ z x).inv
dsimp at this
simp only [Category.assoc, Iso.map_hom_inv_id, Category.comp_id] at this
rw [← this, comp_whiskerRight_assoc]
simp [← Functor.map_comp]
end
section
variable {C : Type u₁} [Category.{v₁} C] {V : Type u₂} [Category.{v₂} V]
[MonoidalCategory C] [SymmetricCategory C]
[MonoidalCategory V] [SymmetricCategory V]
(F G : C ⥤ V)
lemma symmetry [DayConvolution F G] [DayConvolution G F] :
(braiding F G).hom ≫ (braiding G F).hom = 𝟙 _ := by
apply Functor.hom_ext_of_isLeftKanExtension (F ⊛ G) (unit F G)
ext ⟨x, y⟩
simp [← Functor.map_comp]
end
end CategoryTheory.MonoidalCategory.DayConvolution
|
Measure.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
import Mathlib.NumberTheory.Transcendental.Liouville.Residual
import Mathlib.NumberTheory.Transcendental.Liouville.LiouvilleWith
import Mathlib.Analysis.PSeries
/-!
# Volume of the set of Liouville numbers
In this file we prove that the set of Liouville numbers with exponent (irrationality measure)
strictly greater than two is a set of Lebesgue measure zero, see
`volume_iUnion_setOf_liouvilleWith`.
Since this set is a residual set, we show that the filters `residual` and `ae volume` are disjoint.
These filters correspond to two common notions of genericity on `ℝ`: residual sets and sets of full
measure. The fact that the filters are disjoint means that two mutually exclusive properties can be
“generic” at the same time (in the sense of different “genericity” filters).
## Tags
Liouville number, Lebesgue measure, residual, generic property
-/
open scoped Filter ENNReal Topology NNReal
open Filter Set Metric MeasureTheory Real
theorem setOf_liouvilleWith_subset_aux :
{ x : ℝ | ∃ p > 2, LiouvilleWith p x } ⊆
⋃ m : ℤ, (· + (m : ℝ)) ⁻¹' ⋃ n > (0 : ℕ),
{ x : ℝ | ∃ᶠ b : ℕ in atTop, ∃ a ∈ Finset.Icc (0 : ℤ) b,
|x - (a : ℤ) / b| < 1 / (b : ℝ) ^ (2 + 1 / n : ℝ) } := by
rintro x ⟨p, hp, hxp⟩
rcases exists_nat_one_div_lt (sub_pos.2 hp) with ⟨n, hn⟩
rw [lt_sub_iff_add_lt'] at hn
suffices ∀ y : ℝ, LiouvilleWith p y → y ∈ Ico (0 : ℝ) 1 → ∃ᶠ b : ℕ in atTop,
∃ a ∈ Finset.Icc (0 : ℤ) b, |y - a / b| < 1 / (b : ℝ) ^ (2 + 1 / (n + 1 : ℕ) : ℝ) by
simp only [mem_iUnion, mem_preimage]
have hx : x + ↑(-⌊x⌋) ∈ Ico (0 : ℝ) 1 := by
simp only [Int.floor_le, Int.lt_floor_add_one, add_neg_lt_iff_le_add', zero_add, and_self_iff,
mem_Ico, Int.cast_neg, le_add_neg_iff_add_le]
exact ⟨-⌊x⌋, n + 1, n.succ_pos, this _ (hxp.add_int _) hx⟩
clear hxp x; intro x hxp hx01
refine ((hxp.frequently_lt_rpow_neg hn).and_eventually (eventually_ge_atTop 1)).mono ?_
rintro b ⟨⟨a, -, hlt⟩, hb⟩
rw [rpow_neg b.cast_nonneg, ← one_div, ← Nat.cast_succ] at hlt
refine ⟨a, ?_, hlt⟩
replace hb : (1 : ℝ) ≤ b := Nat.one_le_cast.2 hb
have hb0 : (0 : ℝ) < b := zero_lt_one.trans_le hb
replace hlt : |x - a / b| < 1 / b := by
refine hlt.trans_le (one_div_le_one_div_of_le hb0 ?_)
calc
(b : ℝ) = (b : ℝ) ^ (1 : ℝ) := (rpow_one _).symm
_ ≤ (b : ℝ) ^ (2 + 1 / (n + 1 : ℕ) : ℝ) :=
rpow_le_rpow_of_exponent_le hb (one_le_two.trans ?_)
simpa using n.cast_add_one_pos.le
rw [sub_div' hb0.ne', abs_div, abs_of_pos hb0, div_lt_div_iff_of_pos_right hb0, abs_sub_lt_iff,
sub_lt_iff_lt_add, sub_lt_iff_lt_add, ← sub_lt_iff_lt_add'] at hlt
rw [Finset.mem_Icc, ← Int.lt_add_one_iff, ← Int.lt_add_one_iff, ← neg_lt_iff_pos_add, add_comm, ←
@Int.cast_lt ℝ, ← @Int.cast_lt ℝ]
push_cast
refine ⟨lt_of_le_of_lt ?_ hlt.1, hlt.2.trans_le ?_⟩
· simp only [mul_nonneg hx01.left b.cast_nonneg, neg_le_sub_iff_le_add, le_add_iff_nonneg_left]
· rw [add_le_add_iff_left]
exact mul_le_of_le_one_left hb0.le hx01.2.le
/-- The set of numbers satisfying the Liouville condition with some exponent `p > 2` has Lebesgue
measure zero. -/
@[simp]
theorem volume_iUnion_setOf_liouvilleWith :
volume (⋃ (p : ℝ) (_hp : 2 < p), { x : ℝ | LiouvilleWith p x }) = 0 := by
simp only [← setOf_exists, exists_prop]
refine measure_mono_null setOf_liouvilleWith_subset_aux ?_
rw [measure_iUnion_null_iff]; intro m; rw [measure_preimage_add_right]; clear m
refine (measure_biUnion_null_iff <| to_countable _).2 fun n (hn : 1 ≤ n) => ?_
generalize hr : (2 + 1 / n : ℝ) = r
replace hr : 2 < r := by simp [← hr, zero_lt_one.trans_le hn]
clear hn n
refine measure_setOf_frequently_eq_zero ?_
simp only [setOf_exists, ← exists_prop, ← Real.dist_eq, ← mem_ball, setOf_mem_eq]
set B : ℤ → ℕ → Set ℝ := fun a b => ball (a / b) (1 / (b : ℝ) ^ r)
have hB : ∀ a b, volume (B a b) = ↑((2 : ℝ≥0) / (b : ℝ≥0) ^ r) := fun a b ↦ by
rw [Real.volume_ball, mul_one_div, ← NNReal.coe_two, ← NNReal.coe_natCast, ← NNReal.coe_rpow,
← NNReal.coe_div, ENNReal.ofReal_coe_nnreal]
have : ∀ b : ℕ, volume (⋃ a ∈ Finset.Icc (0 : ℤ) b, B a b) ≤
↑(2 * ((b : ℝ≥0) ^ (1 - r) + (b : ℝ≥0) ^ (-r))) := fun b ↦
calc
volume (⋃ a ∈ Finset.Icc (0 : ℤ) b, B a b) ≤ ∑ a ∈ Finset.Icc (0 : ℤ) b, volume (B a b) :=
measure_biUnion_finset_le _ _
_ = ↑((b + 1) * (2 / (b : ℝ≥0) ^ r)) := by
simp only [hB, Int.card_Icc, Finset.sum_const, nsmul_eq_mul, sub_zero,
Int.toNat_natCast, ← Nat.cast_succ, ENNReal.coe_mul, ENNReal.coe_natCast]
_ = _ := by
have : 1 - r ≠ 0 := by linarith
rw [ENNReal.coe_inj]
simp [add_mul, div_eq_mul_inv, NNReal.rpow_neg, NNReal.rpow_sub' this, mul_add,
mul_left_comm]
refine ne_top_of_le_ne_top (ENNReal.tsum_coe_ne_top_iff_summable.2 ?_) (ENNReal.tsum_le_tsum this)
refine (Summable.add ?_ ?_).mul_left _ <;> simp only [NNReal.summable_rpow] <;> linarith
theorem ae_not_liouvilleWith : ∀ᵐ x, ∀ p > (2 : ℝ), ¬LiouvilleWith p x := by
simpa only [ae_iff, not_forall, Classical.not_not, setOf_exists] using
volume_iUnion_setOf_liouvilleWith
theorem ae_not_liouville : ∀ᵐ x, ¬Liouville x :=
ae_not_liouvilleWith.mono fun _ h₁ h₂ => h₁ 3 (by norm_num) (h₂.liouvilleWith 3)
/-- The set of Liouville numbers has Lebesgue measure zero. -/
@[simp]
theorem volume_setOf_liouville : volume { x : ℝ | Liouville x } = 0 := by
simpa only [ae_iff, Classical.not_not] using ae_not_liouville
/-- The filters `residual ℝ` and `ae volume` are disjoint. This means that there exists a residual
set of Lebesgue measure zero (e.g., the set of Liouville numbers). -/
theorem Real.disjoint_residual_ae : Disjoint (residual ℝ) (ae volume) :=
disjoint_of_disjoint_of_mem disjoint_compl_right eventually_residual_liouville ae_not_liouville
|
UrysohnsBounded.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.UrysohnsLemma
import Mathlib.Topology.ContinuousMap.Bounded.Basic
/-!
# Urysohn's lemma for bounded continuous functions
In this file we reformulate Urysohn's lemma `exists_continuous_zero_one_of_isClosed` in terms of
bounded continuous functions `X →ᵇ ℝ`. These lemmas live in a separate file because
`Topology.ContinuousMap.Bounded` imports too many other files.
## Tags
Urysohn's lemma, normal topological space
-/
open BoundedContinuousFunction
open Set Function
/-- **Urysohn's lemma**: if `s` and `t` are two disjoint closed sets in a normal topological
space `X`, then there exists a continuous function `f : X → ℝ` such that
* `f` equals zero on `s`;
* `f` equals one on `t`;
* `0 ≤ f x ≤ 1` for all `x`.
-/
theorem exists_bounded_zero_one_of_closed {X : Type*} [TopologicalSpace X] [NormalSpace X]
{s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) :
∃ f : X →ᵇ ℝ, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 :=
let ⟨f, hfs, hft, hf⟩ := exists_continuous_zero_one_of_isClosed hs ht hd
⟨⟨f, 1, fun _ _ => Real.dist_le_of_mem_Icc_01 (hf _) (hf _)⟩, hfs, hft, hf⟩
/-- Urysohn's lemma: if `s` and `t` are two disjoint closed sets in a normal topological space `X`,
and `a ≤ b` are two real numbers, then there exists a continuous function `f : X → ℝ` such that
* `f` equals `a` on `s`;
* `f` equals `b` on `t`;
* `a ≤ f x ≤ b` for all `x`.
-/
theorem exists_bounded_mem_Icc_of_closed_of_le {X : Type*} [TopologicalSpace X] [NormalSpace X]
{s t : Set X} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) {a b : ℝ} (hle : a ≤ b) :
∃ f : X →ᵇ ℝ, EqOn f (Function.const X a) s ∧ EqOn f (Function.const X b) t ∧
∀ x, f x ∈ Icc a b :=
let ⟨f, hfs, hft, hf01⟩ := exists_bounded_zero_one_of_closed hs ht hd
⟨BoundedContinuousFunction.const X a + (b - a) • f, fun x hx => by simp [hfs hx], fun x hx => by
simp [hft hx], fun x =>
⟨by dsimp; nlinarith [(hf01 x).1], by dsimp; nlinarith [(hf01 x).2]⟩⟩
|
Lex.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.Logic.Function.Defs
import Mathlib.Order.Defs.Unbundled
/-!
# Lexicographic order on a sigma type
This defines the lexicographical order of two arbitrary relations on a sigma type and proves some
lemmas about `PSigma.Lex`, which is defined in core Lean.
Given a relation in the index type and a relation on each summand, the lexicographical order on the
sigma type relates `a` and `b` if their summands are related or they are in the same summand and
related by the summand's relation.
## See also
Related files are:
* `Combinatorics.CoLex`: Colexicographic order on finite sets.
* `Data.List.Lex`: Lexicographic order on lists.
* `Data.Sigma.Order`: Lexicographic order on `Σ i, α i` per say.
* `Data.PSigma.Order`: Lexicographic order on `Σ' i, α i`.
* `Data.Prod.Lex`: Lexicographic order on `α × β`. Can be thought of as the special case of
`Sigma.Lex` where all summands are the same
-/
namespace Sigma
variable {ι : Type*} {α : ι → Type*} {r r₁ r₂ : ι → ι → Prop} {s s₁ s₂ : ∀ i, α i → α i → Prop}
{a b : Σ i, α i}
/-- The lexicographical order on a sigma type. It takes in a relation on the index type and a
relation for each summand. `a` is related to `b` iff their summands are related or they are in the
same summand and are related through the summand's relation. -/
inductive Lex (r : ι → ι → Prop) (s : ∀ i, α i → α i → Prop) : ∀ _ _ : Σ i, α i, Prop
| left {i j : ι} (a : α i) (b : α j) : r i j → Lex r s ⟨i, a⟩ ⟨j, b⟩
| right {i : ι} (a b : α i) : s i a b → Lex r s ⟨i, a⟩ ⟨i, b⟩
theorem lex_iff : Lex r s a b ↔ r a.1 b.1 ∨ ∃ h : a.1 = b.1, s b.1 (h.rec a.2) b.2 := by
constructor
· rintro (⟨a, b, hij⟩ | ⟨a, b, hab⟩)
· exact Or.inl hij
· exact Or.inr ⟨rfl, hab⟩
· obtain ⟨i, a⟩ := a
obtain ⟨j, b⟩ := b
dsimp only
rintro (h | ⟨rfl, h⟩)
· exact Lex.left _ _ h
· exact Lex.right _ _ h
instance Lex.decidable (r : ι → ι → Prop) (s : ∀ i, α i → α i → Prop) [DecidableEq ι]
[DecidableRel r] [∀ i, DecidableRel (s i)] : DecidableRel (Lex r s) := fun _ _ =>
decidable_of_decidable_of_iff lex_iff.symm
theorem Lex.mono (hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ i, α i}
(h : Lex r₁ s₁ a b) : Lex r₂ s₂ a b := by
obtain ⟨a, b, hij⟩ | ⟨a, b, hab⟩ := h
· exact Lex.left _ _ (hr _ _ hij)
· exact Lex.right _ _ (hs _ _ _ hab)
theorem Lex.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) {a b : Σ i, α i} (h : Lex r₁ s a b) :
Lex r₂ s a b :=
h.mono hr fun _ _ _ => id
theorem Lex.mono_right (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ i, α i} (h : Lex r s₁ a b) :
Lex r s₂ a b :=
h.mono (fun _ _ => id) hs
theorem lex_swap : Lex (Function.swap r) s a b ↔ Lex r (fun i => Function.swap (s i)) b a := by
constructor <;>
· rintro (⟨a, b, h⟩ | ⟨a, b, h⟩)
· exact Lex.left _ _ h
· exact Lex.right _ _ h
instance [∀ i, IsRefl (α i) (s i)] : IsRefl _ (Lex r s) :=
⟨fun ⟨_, _⟩ => Lex.right _ _ <| refl _⟩
instance [IsIrrefl ι r] [∀ i, IsIrrefl (α i) (s i)] : IsIrrefl _ (Lex r s) :=
⟨by
rintro _ (⟨a, b, hi⟩ | ⟨a, b, ha⟩)
· exact irrefl _ hi
· exact irrefl _ ha
⟩
instance [IsTrans ι r] [∀ i, IsTrans (α i) (s i)] : IsTrans _ (Lex r s) :=
⟨by
rintro _ _ _ (⟨a, b, hij⟩ | ⟨a, b, hab⟩) (⟨_, c, hk⟩ | ⟨_, c, hc⟩)
· exact Lex.left _ _ (_root_.trans hij hk)
· exact Lex.left _ _ hij
· exact Lex.left _ _ hk
· exact Lex.right _ _ (_root_.trans hab hc)⟩
instance [IsSymm ι r] [∀ i, IsSymm (α i) (s i)] : IsSymm _ (Lex r s) :=
⟨by
rintro _ _ (⟨a, b, hij⟩ | ⟨a, b, hab⟩)
· exact Lex.left _ _ (symm hij)
· exact Lex.right _ _ (symm hab)
⟩
attribute [local instance] IsAsymm.isIrrefl
instance [IsAsymm ι r] [∀ i, IsAntisymm (α i) (s i)] : IsAntisymm _ (Lex r s) :=
⟨by
rintro _ _ (⟨a, b, hij⟩ | ⟨a, b, hab⟩) (⟨_, _, hji⟩ | ⟨_, _, hba⟩)
· exact (asymm hij hji).elim
· exact (irrefl _ hij).elim
· exact (irrefl _ hji).elim
· exact congr_arg (Sigma.mk _ ·) <| antisymm hab hba⟩
instance [IsTrichotomous ι r] [∀ i, IsTotal (α i) (s i)] : IsTotal _ (Lex r s) :=
⟨by
rintro ⟨i, a⟩ ⟨j, b⟩
obtain hij | rfl | hji := trichotomous_of r i j
· exact Or.inl (Lex.left _ _ hij)
· obtain hab | hba := total_of (s i) a b
· exact Or.inl (Lex.right _ _ hab)
· exact Or.inr (Lex.right _ _ hba)
· exact Or.inr (Lex.left _ _ hji)⟩
instance [IsTrichotomous ι r] [∀ i, IsTrichotomous (α i) (s i)] : IsTrichotomous _ (Lex r s) :=
⟨by
rintro ⟨i, a⟩ ⟨j, b⟩
obtain hij | rfl | hji := trichotomous_of r i j
· exact Or.inl (Lex.left _ _ hij)
· obtain hab | rfl | hba := trichotomous_of (s i) a b
· exact Or.inl (Lex.right _ _ hab)
· exact Or.inr (Or.inl rfl)
· exact Or.inr (Or.inr <| Lex.right _ _ hba)
· exact Or.inr (Or.inr <| Lex.left _ _ hji)⟩
end Sigma
/-! ### `PSigma` -/
namespace PSigma
variable {ι : Sort*} {α : ι → Sort*} {r : ι → ι → Prop} {s : ∀ i, α i → α i → Prop}
theorem lex_iff {a b : Σ' i, α i} :
Lex r s a b ↔ r a.1 b.1 ∨ ∃ h : a.1 = b.1, s b.1 (h.rec a.2) b.2 := by
constructor
· rintro (⟨a, b, hij⟩ | ⟨i, hab⟩)
· exact Or.inl hij
· exact Or.inr ⟨rfl, hab⟩
· obtain ⟨i, a⟩ := a
obtain ⟨j, b⟩ := b
dsimp only
rintro (h | ⟨rfl, h⟩)
· exact Lex.left _ _ h
· exact Lex.right _ h
instance Lex.decidable (r : ι → ι → Prop) (s : ∀ i, α i → α i → Prop) [DecidableEq ι]
[DecidableRel r] [∀ i, DecidableRel (s i)] : DecidableRel (Lex r s) := fun _ _ =>
decidable_of_decidable_of_iff lex_iff.symm
theorem Lex.mono {r₁ r₂ : ι → ι → Prop} {s₁ s₂ : ∀ i, α i → α i → Prop}
(hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ' i, α i}
(h : Lex r₁ s₁ a b) : Lex r₂ s₂ a b := by
obtain ⟨a, b, hij⟩ | ⟨i, hab⟩ := h
· exact Lex.left _ _ (hr _ _ hij)
· exact Lex.right _ (hs _ _ _ hab)
theorem Lex.mono_left {r₁ r₂ : ι → ι → Prop} {s : ∀ i, α i → α i → Prop}
(hr : ∀ a b, r₁ a b → r₂ a b) {a b : Σ' i, α i} (h : Lex r₁ s a b) : Lex r₂ s a b :=
h.mono hr fun _ _ _ => id
theorem Lex.mono_right {r : ι → ι → Prop} {s₁ s₂ : ∀ i, α i → α i → Prop}
(hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ' i, α i} (h : Lex r s₁ a b) : Lex r s₂ a b :=
h.mono (fun _ _ => id) hs
end PSigma
|
FiniteExtension.lean
|
/-
Copyright (c) 2025 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.Analysis.Normed.Unbundled.AlgebraNorm
import Mathlib.Analysis.Normed.Unbundled.SeminormFromBounded
import Mathlib.Analysis.Normed.Unbundled.SmoothingSeminorm
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
/-!
# Basis.norm
In this file, we prove [BGR, Lemma 3.2.1./3][bosch-guntzer-remmert] : if `K` is a normed field
with a nonarchimedean power-multiplicative norm and `L/K` is a finite extension, then there exists
at least one power-multiplicative `K`-algebra norm on `L` extending the norm on `K`.
## Main Definitions
* `Basis.norm` : the function sending an element `x : L` to the maximum of the norms of its
coefficients with respect to the `K`-basis `B` of `L`.
## Main Results
* `norm_mul_le_const_mul_norm` : For any `K`-basis of `L`, `B.norm` is bounded with respect to
multiplication. That is, `∃ (c : ℝ), c > 0` such that
` ∀ (x y : L), B.norm (x * y) ≤ c * B.norm x * B.norm y`.
* `exists_nonarchimedean_pow_mul_seminorm_of_finiteDimensional` : if `K` is a normed field with a
nonarchimedean power-multiplicative norm and `L/K` is a finite extension, then there exists at
least one power-multiplicative `K`-algebra norm on `L` extending the norm on `K`. This is
[BGR, Lemma 3.2.1./3].
## References
* [S. Bosch, U. Güntzer, R. Remmert, *Non-Archimedean Analysis*][bosch-guntzer-remmert]
## Tags
Basis.norm, nonarchimedean
-/
noncomputable section
open Finset Module
section Ring
variable {K L : Type*} [NormedField K] [Ring L] [Algebra K L]
namespace Module.Basis
variable {ι : Type*} [Fintype ι] [Nonempty ι] (B : Basis ι K L)
/-- The function sending an element `x : L` to the maximum of the norms of its coefficients
with respect to the `K`-basis `B` of `L`. -/
def norm (x : L) : ℝ :=
Finset.sup' univ univ_nonempty (fun i : ι ↦ ‖B.repr x i‖)
/-- The norm of a coefficient `x_i` is less than or equal to the norm of `x`. -/
theorem norm_repr_le_norm {x : L} (i : ι) : ‖B.repr x i‖ ≤ B.norm x :=
Finset.le_sup' (fun i : ι ↦ ‖B.repr x i‖) (mem_univ i)
/-- For any `K`-basis of `L`, we have `B.norm 0 = 0`. -/
protected theorem norm_zero : B.norm 0 = 0 := by
simp [norm, map_zero, norm_zero]
/-- For any `K`-basis of `L`, and any `x : L`, we have `B.norm (-x) = B.norm x`. -/
protected theorem norm_neg (x : L) : B.norm (-x) = B.norm x := by
simp [norm, map_neg, Pi.neg_apply, _root_.norm_neg]
/-- For any `K`-basis of `L`, and any `x : L`, we have `0 ≤ B.norm x`. -/
protected theorem norm_nonneg (x : L) : 0 ≤ B.norm x := by
simp only [norm, le_sup'_iff, mem_univ, norm_nonneg, and_self, exists_const]
variable {B}
/-- For any `K`-basis `B` of `L` containing `1`, `B.norm` extends the norm on `K`. -/
theorem norm_extends {i : ι} (hBi : B i = (1 : L)) (x : K) :
B.norm ((algebraMap K L) x) = ‖x‖ := by
classical
simp only [norm, repr_algebraMap _ hBi]
apply le_antisymm
· aesop
· exact le_sup'_of_le _ (mem_univ i) (by simp)
/-- For any `K`-basis of `L`, if the norm on `K` is nonarchimedean, then so is `B.norm`. -/
theorem norm_isNonarchimedean (hna : IsNonarchimedean (Norm.norm : K → ℝ)) :
IsNonarchimedean B.norm := fun x y ↦ by
obtain ⟨ixy, _, hixy⟩ := exists_mem_eq_sup' univ_nonempty (fun i ↦ ‖(B.repr (x + y)) i‖)
have hxy : ‖B.repr (x + y) ixy‖ ≤ max ‖B.repr x ixy‖ ‖B.repr y ixy‖ := by
rw [LinearEquiv.map_add, Finsupp.coe_add, Pi.add_apply]; exact hna _ _
rw [Basis.norm, hixy]
rcases le_max_iff.mp hxy with (hx | hy)
· exact le_max_of_le_left (le_trans hx (norm_repr_le_norm B ixy))
· exact le_max_of_le_right (le_trans hy (norm_repr_le_norm B ixy))
/-- For any `K`-basis of `L`, `B.norm` is bounded with respect to multiplication. That is,
`∃ (c : ℝ), c > 0` such that ` ∀ (x y : L), B.norm (x * y) ≤ c * B.norm x * B.norm y`. -/
theorem norm_mul_le_const_mul_norm {i : ι} (hBi : B i = (1 : L))
(hna : IsNonarchimedean (Norm.norm : K → ℝ)) :
∃ (c : ℝ) (_ : 0 < c), ∀ x y : L, B.norm (x * y) ≤ c * B.norm x * B.norm y := by
-- The bounding constant `c` will be the maximum of the products `B.norm (B i * B j)`.
obtain ⟨c, _, hc⟩ := exists_mem_eq_sup' univ_nonempty (fun i : ι × ι ↦ B.norm (B i.1 * B i.2))
use B.norm (B c.1 * B c.2)
constructor
-- ∀ (x y : L), B.norm (x * y) ≤ B.norm (⇑B c.fst * ⇑B c.snd) * B.norm x * B.norm y
· intro x y
-- `ixy` is an index for which `‖B.repr (x*y) i‖` is maximum.
obtain ⟨ixy, _, hixy_def⟩ := exists_mem_eq_sup' univ_nonempty (fun i ↦ ‖(B.repr (x * y)) i‖)
-- We rewrite the LHS using `ixy`.
conv_lhs => simp only [Basis.norm]; rw [hixy_def, ← Basis.sum_repr B x, ← Basis.sum_repr B y]
rw [sum_mul, map_finset_sum]
simp_rw [smul_mul_assoc, LinearEquiv.map_smul, mul_sum, map_finset_sum,
mul_smul_comm, LinearEquiv.map_smul]
have hna' : IsNonarchimedean (NormedField.toMulRingNorm K) := hna
/- Since the norm is nonarchimidean, the norm of a finite sum is bounded by the maximum of the
norms of the summands. -/
obtain ⟨k, -, (hk : ‖∑ i : ι, (B.repr x i • ∑ i_1 : ι,
B.repr y i_1 • B.repr (B i * B i_1)) ixy‖ ≤
‖(B.repr x k • ∑ j : ι, B.repr y j • B.repr (B k * B j)) ixy‖)⟩ :=
IsNonarchimedean.finset_image_add hna'
(fun i ↦ (B.repr x i • ∑ i_1 : ι, B.repr y i_1 • B.repr (B i * B i_1)) ixy)
(univ : Finset ι)
simp only [Finsupp.coe_smul, Finsupp.coe_finset_sum, Pi.smul_apply, sum_apply, smul_eq_mul,
norm_mul] at hk ⊢
apply le_trans hk
-- We use the above property again.
obtain ⟨k', hk'⟩ : ∃ (k' : ι),
‖∑ j : ι, B.repr y j • B.repr (B k * B j) ixy‖ ≤
‖B.repr y k' • B.repr (B k * B k') ixy‖ := by
obtain ⟨k, hk0, hk⟩ := IsNonarchimedean.finset_image_add hna'
(fun i ↦ B.repr y i • B.repr (B k * B i) ixy) (univ : Finset ι)
exact ⟨k, hk⟩
apply le_trans (mul_le_mul_of_nonneg_left hk' (norm_nonneg _))
-- Now an easy computation leads to the desired conclusion.
rw [norm_smul, mul_assoc, mul_comm (B.norm (B c.fst * B c.snd)), ← mul_assoc]
exact mul_le_mul (mul_le_mul (B.norm_repr_le_norm _) (B.norm_repr_le_norm _)
(norm_nonneg _) (B.norm_nonneg _)) (le_trans (B.norm_repr_le_norm _)
(hc ▸ Finset.le_sup' (fun i : ι × ι ↦ B.norm (B i.1 * B i.2)) (mem_univ (k, k'))))
(norm_nonneg _) (mul_nonneg (B.norm_nonneg _) (B.norm_nonneg _))
-- `B c.1 * B c.2` is positive.
· have h_pos : (0 : ℝ) < B.norm (B i * B i) := by
have h1 : (1 : L) = (algebraMap K L) 1 := by rw [map_one]
rw [hBi, mul_one, h1, Basis.norm_extends hBi]
simp [norm_one, zero_lt_one]
exact lt_of_lt_of_le h_pos
(hc ▸ Finset.le_sup' (fun i : ι × ι ↦ B.norm (B i.1 * B i.2)) (mem_univ (i, i)))
/-- For any `k : K`, `y : L`, we have
`B.norm ((algebra_map K L) k * y) = B.norm ((algebra_map K L) k) * B.norm y`. -/
theorem norm_smul {ι : Type*} [Fintype ι] [Nonempty ι] {B : Basis ι K L} {i : ι}
(hBi : B i = (1 : L)) (k : K) (y : L) :
B.norm ((algebraMap K L) k * y) = B.norm ((algebraMap K L) k) * B.norm y := by
by_cases hk : k = 0
· rw [hk, map_zero, MulZeroClass.zero_mul, B.norm_zero, MulZeroClass.zero_mul]
· rw [norm_extends hBi]
obtain ⟨i, _, hi⟩ := exists_mem_eq_sup' univ_nonempty (fun i ↦ ‖B.repr y i‖)
obtain ⟨j, _, hj⟩ := exists_mem_eq_sup' univ_nonempty
(fun i ↦ ‖B.repr ((algebraMap K L) k * y) i‖)
have hij : ‖B.repr y i‖ = ‖B.repr y j‖ := by
rw [← hi]
apply le_antisymm _ (norm_repr_le_norm B j)
have hj' := Finset.le_sup' (fun i ↦ ‖B.repr ((algebraMap K L) k * y) i‖) (mem_univ i)
simp only [repr_smul', norm_mul, ← hi] at hj hj'
exact (mul_le_mul_left (lt_of_le_of_ne (norm_nonneg _)
(Ne.symm (norm_ne_zero_iff.mpr hk)))).mp (hj ▸ hj')
simp only [norm, hj]
rw [repr_smul', norm_mul, hi, hij]
end Module.Basis
end Ring
section Field
variable {K L : Type*} [NormedField K] [Field L] [Algebra K L]
/-- If `K` is a nonarchimedean normed field `L/K` is a finite extension, then there exists a
power-multiplicative nonarchimedean `K`-algebra norm on `L` extending the norm on `K`. -/
theorem exists_nonarchimedean_pow_mul_seminorm_of_finiteDimensional (hfd : FiniteDimensional K L)
(hna : IsNonarchimedean (norm : K → ℝ)) :
∃ f : AlgebraNorm K L, IsPowMul f ∧ (∀ (x : K), f ((algebraMap K L) x) = ‖x‖) ∧
IsNonarchimedean f := by
-- Choose a basis B = {1, e2,..., en} of the K-vector space L
set h1 : LinearIndepOn K id ({1} : Set L) :=
LinearIndepOn.id_singleton _ one_ne_zero
set ι := { x // x ∈ LinearIndepOn.extend h1 (Set.subset_univ ({1} : Set L)) }
set B : Basis ι K L := Basis.extend h1
letI hfin : Fintype ι := FiniteDimensional.fintypeBasisIndex B
haveI hem : Nonempty ι := B.index_nonempty
have h1L : (1 : L) ∈ LinearIndepOn.extend h1 _ :=
Basis.subset_extend _ (Set.mem_singleton (1 : L))
have hB1 : B ⟨1, h1L⟩ = (1 : L) := by rw [Basis.coe_extend, Subtype.coe_mk]
-- Define a function g : L → ℝ by setting g (∑ki • ei) = maxᵢ ‖ ki ‖
set g : L → ℝ := B.norm
-- g 0 = 0seminormFromBounded
have hg0 : g 0 = 0 := B.norm_zero
-- g takes nonnegative values
have hg_nonneg : ∀ x : L, 0 ≤ g x := fun x ↦ by simp only [g, Basis.norm]; simp
-- g extends the norm on K
have hg_ext : ∀ (x : K), g ((algebraMap K L) x) = ‖x‖ := Basis.norm_extends hB1
-- g is nonarchimedean
have hg_na : IsNonarchimedean g := Basis.norm_isNonarchimedean hna
-- g satisfies the triangle inequality
have hg_add : ∀ a b : L, g (a + b) ≤ g a + g b :=
fun _ _ ↦ IsNonarchimedean.add_le hg_nonneg hg_na
-- g (-a) = g a
have hg_neg : ∀ a : L, g (-a) = g a := B.norm_neg
-- g is multiplicatively bounded
obtain ⟨_, _, hg_bdd⟩ := Basis.norm_mul_le_const_mul_norm hB1 hna
-- g is a K-module norm
have hg_mul : ∀ (k : K) (y : L), g ((algebraMap K L) k * y) = g ((algebraMap K L) k) * g y :=
fun k y ↦ Basis.norm_smul hB1 k y
-- Using BGR Prop. 1.2.1/2, we can smooth g to a ring norm f on L that extends the norm on K.
set f := seminormFromBounded hg0 hg_nonneg hg_bdd hg_add hg_neg
have hf_na : IsNonarchimedean f := seminormFromBounded_isNonarchimedean hg_nonneg hg_bdd hg_na
have hf_1 : f 1 ≤ 1 := seminormFromBounded_one_le hg_nonneg hg_bdd
have hf_ext : ∀ (x : K), f ((algebraMap K L) x) = ‖x‖ :=
fun k ↦ hg_ext k ▸ seminormFromBounded_of_mul_apply hg_nonneg hg_bdd (hg_mul k)
-- Using BGR Prop. 1.3.2/1, we obtain from f a power multiplicative K-algebra norm on L
-- extending the norm on K.
set F' := smoothingSeminorm f hf_1 hf_na with hF'
have hF'_ext : ∀ k : K, F' ((algebraMap K L) k) = ‖k‖ := by
intro k
rw [← hf_ext _]
exact smoothingSeminorm_apply_of_map_mul_eq_mul f hf_1 hf_na
(seminormFromBounded_of_mul_is_mul hg_nonneg hg_bdd (hg_mul k))
have hF'_1 : F' 1 = 1 := by
have h1 : (1 : L) = (algebraMap K L) 1 := by rw [map_one]
simp only [h1, hF'_ext (1 : K), norm_one]
have hF'_0 : F' ≠ 0 := DFunLike.ne_iff.mpr ⟨(1 : L), by rw [hF'_1]; exact one_ne_zero⟩
set F : AlgebraNorm K L :=
{ RingSeminorm.toRingNorm F' hF'_0 with
smul' := fun k y ↦ by
have hk : ∀ y : L, f (algebraMap K L k * y) = f (algebraMap K L k) * f y :=
seminormFromBounded_of_mul_is_mul hg_nonneg hg_bdd (hg_mul k)
have hfk : ‖k‖ = (smoothingSeminorm f hf_1 hf_na) ((algebraMap K L) k) := by
rw [← hf_ext k, eq_comm, smoothingSeminorm_apply_of_map_mul_eq_mul f hf_1 hf_na hk]
simp only [hfk, hF']
-- TODO: There are missing `simp` lemmas here, that should be able to convert
-- `((smoothingSeminorm f hf_1 hf_na).toRingNorm ⋯).toRingSeminorm y` to
-- `(smoothingSeminorm f hf_1 hf_na y)`, after which the `erw` would work as a `rw`.
erw [← smoothingSeminorm_of_mul f hf_1 hf_na hk y]
rw [Algebra.smul_def]
rfl }
have hF_ext (k : K) : F ((algebraMap K L) k) = ‖k‖ := by
rw [← hf_ext]
exact smoothingSeminorm_apply_of_map_mul_eq_mul f hf_1 hf_na
(seminormFromBounded_of_mul_is_mul hg_nonneg hg_bdd (hg_mul k))
exact ⟨F, isPowMul_smoothingFun f hf_1, hF_ext, isNonarchimedean_smoothingFun f hf_1 hf_na⟩
end Field
|
Units.lean
|
/-
Copyright (c) 2023 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching, Ashvni Narayanan, Michael Stoll
-/
import Mathlib.Algebra.BigOperators.Associated
import Mathlib.Data.ZMod.Basic
import Mathlib.RingTheory.Coprime.Lemmas
/-!
# Lemmas about units in `ZMod`.
-/
assert_not_exists TwoSidedIdeal
namespace ZMod
variable {n m : ℕ}
/-- `unitsMap` is a group homomorphism that maps units of `ZMod m` to units of `ZMod n` when `n`
divides `m`. -/
def unitsMap (hm : n ∣ m) : (ZMod m)ˣ →* (ZMod n)ˣ := Units.map (castHom hm (ZMod n))
lemma unitsMap_def (hm : n ∣ m) : unitsMap hm = Units.map (castHom hm (ZMod n)) := rfl
lemma unitsMap_comp {d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
(unitsMap hm).comp (unitsMap hd) = unitsMap (dvd_trans hm hd) := by
simp only [unitsMap_def]
rw [← Units.map_comp]
exact congr_arg Units.map <| congr_arg RingHom.toMonoidHom <| castHom_comp hm hd
@[simp]
lemma unitsMap_self (n : ℕ) : unitsMap (dvd_refl n) = MonoidHom.id _ := by
simp [unitsMap, castHom_self]
/-- `unitsMap_val` shows that coercing from `(ZMod m)ˣ` to `ZMod n` gives the same result
when going via `(ZMod n)ˣ` and `ZMod m`. -/
lemma unitsMap_val (h : n ∣ m) (a : (ZMod m)ˣ) :
↑(unitsMap h a) = ((a : ZMod m).cast : ZMod n) := rfl
lemma isUnit_cast_of_dvd (hm : n ∣ m) (a : Units (ZMod m)) : IsUnit (cast (a : ZMod m) : ZMod n) :=
Units.isUnit (unitsMap hm a)
theorem unitsMap_surjective [hm : NeZero m] (h : n ∣ m) :
Function.Surjective (unitsMap h) := by
suffices ∀ x : ℕ, x.Coprime n → ∃ k : ℕ, (x + k * n).Coprime m by
intro x
have ⟨k, hk⟩ := this x.val.val (val_coe_unit_coprime x)
refine ⟨unitOfCoprime _ hk, Units.ext ?_⟩
have : NeZero n := ⟨fun hn ↦ hm.out (eq_zero_of_zero_dvd (hn ▸ h))⟩
simp [unitsMap_def, - castHom_apply]
intro x hx
let ps : Finset ℕ := {p ∈ m.primeFactors | ¬p ∣ x}
use ps.prod id
apply Nat.coprime_of_dvd
intro p pp hp hpn
by_cases hpx : p ∣ x
· have h := Nat.dvd_sub hp hpx
rw [add_comm, Nat.add_sub_cancel] at h
rcases pp.dvd_mul.mp h with h | h
· have ⟨q, hq, hq'⟩ := (pp.prime.dvd_finset_prod_iff id).mp h
rw [Finset.mem_filter, Nat.mem_primeFactors,
← (Nat.prime_dvd_prime_iff_eq pp hq.1.1).mp hq'] at hq
exact hq.2 hpx
· exact Nat.Prime.not_coprime_iff_dvd.mpr ⟨p, pp, hpx, h⟩ hx
· have pps : p ∈ ps := Finset.mem_filter.mpr ⟨Nat.mem_primeFactors.mpr ⟨pp, hpn, hm.out⟩, hpx⟩
have h := Nat.dvd_sub hp ((Finset.dvd_prod_of_mem id pps).mul_right n)
rw [Nat.add_sub_cancel] at h
contradiction
-- This needs `Nat.primeFactors`, so cannot go into `Mathlib/Data/ZMod/Basic.lean`.
open Nat in
lemma not_isUnit_of_mem_primeFactors {n p : ℕ} (h : p ∈ n.primeFactors) :
¬ IsUnit (p : ZMod n) := by
rw [isUnit_iff_coprime]
exact (Prime.dvd_iff_not_coprime <| prime_of_mem_primeFactors h).mp <| dvd_of_mem_primeFactors h
/-- Any element of `ZMod N` has the form `u * d` where `u` is a unit and `d` is a divisor of `N`. -/
lemma eq_unit_mul_divisor {N : ℕ} (a : ZMod N) :
∃ d : ℕ, d ∣ N ∧ ∃ (u : ZMod N), IsUnit u ∧ a = u * d := by
rcases eq_or_ne N 0 with rfl | hN
-- Silly special case : N = 0. Of no mathematical interest, but true, so let's prove it.
· change ℤ at a
rcases eq_or_ne a 0 with rfl | ha
· refine ⟨0, dvd_zero _, 1, isUnit_one, by rw [Nat.cast_zero, mul_zero]⟩
refine ⟨a.natAbs, dvd_zero _, Int.sign a, ?_, (Int.sign_mul_natAbs a).symm⟩
rcases lt_or_gt_of_ne ha with h | h
· simp only [Int.sign_eq_neg_one_of_neg h, IsUnit.neg_iff, isUnit_one]
· simp only [Int.sign_eq_one_of_pos h, isUnit_one]
-- now the interesting case
have : NeZero N := ⟨hN⟩
-- Define `d` as the GCD of a lift of `a` and `N`.
let d := a.val.gcd N
have hd : d ≠ 0 := Nat.gcd_ne_zero_right hN
obtain ⟨a₀, (ha₀ : _ = d * _)⟩ := a.val.gcd_dvd_left N
obtain ⟨N₀, (hN₀ : _ = d * _)⟩ := a.val.gcd_dvd_right N
refine ⟨d, ⟨N₀, hN₀⟩, ?_⟩
-- Show `a` is a unit mod `N / d`.
have hu₀ : IsUnit (a₀ : ZMod N₀) := by
refine (isUnit_iff_coprime _ _).mpr (Nat.isCoprime_iff_coprime.mp ?_)
obtain ⟨p, q, hpq⟩ : ∃ (p q : ℤ), d = a.val * p + N * q := ⟨_, _, Nat.gcd_eq_gcd_ab _ _⟩
rw [ha₀, hN₀, Nat.cast_mul, Nat.cast_mul, mul_assoc, mul_assoc, ← mul_add, eq_comm,
mul_comm _ p, mul_comm _ q] at hpq
exact ⟨p, q, Int.eq_one_of_mul_eq_self_right (Nat.cast_ne_zero.mpr hd) hpq⟩
-- Lift it arbitrarily to a unit mod `N`.
obtain ⟨u, hu⟩ := (unitsMap_surjective (⟨d, mul_comm d N₀ ▸ hN₀⟩ : N₀ ∣ N)) hu₀.unit
rw [unitsMap_def, ← Units.val_inj, Units.coe_map, IsUnit.unit_spec, MonoidHom.coe_coe] at hu
refine ⟨u.val, u.isUnit, ?_⟩
rw [← natCast_zmod_val a, ← natCast_zmod_val u.1, ha₀, ← Nat.cast_mul,
natCast_eq_natCast_iff, mul_comm _ d, Nat.ModEq]
simp only [hN₀, Nat.mul_mod_mul_left, Nat.mul_right_inj hd]
rw [← Nat.ModEq, ← natCast_eq_natCast_iff, ← hu, natCast_val, castHom_apply]
theorem coe_int_mul_inv_eq_one {n : ℕ} {x : ℤ} (h : IsCoprime x n) :
(x : ZMod n) * (x : ZMod n)⁻¹ = 1 := by
by_cases hn : n = 0
· simp only [hn, Nat.cast_zero, isCoprime_zero_right] at h
rcases Int.isUnit_eq_one_or h with h | h <;> simp [h]
haveI : NeZero n := ⟨hn⟩
rw [← natCast_zmod_val x]
apply coe_mul_inv_eq_one
rwa [Int.isCoprime_iff_gcd_eq_one, ← Int.gcd_emod, ← val_intCast] at h
theorem coe_int_inv_mul_eq_one {n : ℕ} {x : ℤ} (h : IsCoprime x n) :
(x : ZMod n)⁻¹ * (x : ZMod n) = 1 := by
rw [mul_comm, coe_int_mul_inv_eq_one h]
lemma coe_int_mul_val_inv {n : ℕ} [NeZero n] {m : ℤ} (h : IsCoprime m n) :
(m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by
rw [natCast_zmod_val, coe_int_mul_inv_eq_one h]
lemma coe_int_val_inv_mul {n : ℕ} [NeZero n] {m : ℤ} (h : IsCoprime m n) :
((m⁻¹ : ZMod n).val : ZMod n) * m = 1 := by
rw [mul_comm, coe_int_mul_val_inv h]
/-- The unit of `ZMod m` associated with an integer prime to `n`. -/
def unitOfIsCoprime {m : ℕ} (n : ℤ)
(h : IsCoprime n (m : ℤ)) : (ZMod m)ˣ where
val := n
inv := n⁻¹
val_inv := coe_int_mul_inv_eq_one h
inv_val := coe_int_inv_mul_eq_one h
@[simp]
theorem coe_unitOfIsCoprime {m : ℕ} (n : ℤ) (h : IsCoprime n ↑m) :
(unitOfIsCoprime n h : ZMod m) = n := rfl
theorem isUnit_inv {m : ℕ} {n : ℤ} (h : IsUnit (n : ZMod m)) :
IsUnit (n : ZMod m)⁻¹ := by
rw [isUnit_iff_exists]
exact ⟨n, inv_mul_of_unit _ h, mul_inv_of_unit _ h⟩
end ZMod
|
Pi.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Data.Set.Piecewise
/-!
# Pi instances for multiplicative actions
This file defines instances for `MulAction` and related structures on `Pi` types.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Prod.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
* `Mathlib/Algebra/Group/Action/Sum.lean`
-/
assert_not_exists MonoidWithZero
variable {ι M N : Type*} {α β γ : ι → Type*} (i : ι)
namespace Pi
@[to_additive]
instance smul' [∀ i, SMul (α i) (β i)] : SMul (∀ i, α i) (∀ i, β i) where smul s x i := s i • x i
@[to_additive]
lemma smul_def' [∀ i, SMul (α i) (β i)] (s : ∀ i, α i) (x : ∀ i, β i) : s • x = fun i ↦ s i • x i :=
rfl
@[to_additive (attr := simp)]
lemma smul_apply' [∀ i, SMul (α i) (β i)] (s : ∀ i, α i) (x : ∀ i, β i) : (s • x) i = s i • x i :=
rfl
@[to_additive]
instance isScalarTower [SMul M N] [∀ i, SMul N (α i)] [∀ i, SMul M (α i)]
[∀ i, IsScalarTower M N (α i)] : IsScalarTower M N (∀ i, α i) where
smul_assoc x y z := funext fun i ↦ smul_assoc x y (z i)
@[to_additive]
instance isScalarTower' [∀ i, SMul M (α i)] [∀ i, SMul (α i) (β i)] [∀ i, SMul M (β i)]
[∀ i, IsScalarTower M (α i) (β i)] : IsScalarTower M (∀ i, α i) (∀ i, β i) where
smul_assoc x y z := funext fun i ↦ smul_assoc x (y i) (z i)
@[to_additive]
instance isScalarTower'' [∀ i, SMul (α i) (β i)] [∀ i, SMul (β i) (γ i)] [∀ i, SMul (α i) (γ i)]
[∀ i, IsScalarTower (α i) (β i) (γ i)] : IsScalarTower (∀ i, α i) (∀ i, β i) (∀ i, γ i) where
smul_assoc x y z := funext fun i ↦ smul_assoc (x i) (y i) (z i)
@[to_additive]
instance smulCommClass [∀ i, SMul M (α i)] [∀ i, SMul N (α i)] [∀ i, SMulCommClass M N (α i)] :
SMulCommClass M N (∀ i, α i) where
smul_comm x y z := funext fun i ↦ smul_comm x y (z i)
@[to_additive]
instance smulCommClass' [∀ i, SMul M (β i)] [∀ i, SMul (α i) (β i)]
[∀ i, SMulCommClass M (α i) (β i)] : SMulCommClass M (∀ i, α i) (∀ i, β i) :=
⟨fun x y z => funext fun i ↦ smul_comm x (y i) (z i)⟩
@[to_additive]
instance smulCommClass'' [∀ i, SMul (β i) (γ i)] [∀ i, SMul (α i) (γ i)]
[∀ i, SMulCommClass (α i) (β i) (γ i)] : SMulCommClass (∀ i, α i) (∀ i, β i) (∀ i, γ i) where
smul_comm x y z := funext fun i ↦ smul_comm (x i) (y i) (z i)
@[to_additive]
instance isCentralScalar [∀ i, SMul M (α i)] [∀ i, SMul Mᵐᵒᵖ (α i)] [∀ i, IsCentralScalar M (α i)] :
IsCentralScalar M (∀ i, α i) where
op_smul_eq_smul _ _ := funext fun _ ↦ op_smul_eq_smul _ _
/-- If `α i` has a faithful scalar action for a given `i`, then so does `Π i, α i`. This is
not an instance as `i` cannot be inferred. -/
@[to_additive
/-- If `α i` has a faithful additive action for a given `i`, then
so does `Π i, α i`. This is not an instance as `i` cannot be inferred -/]
lemma faithfulSMul_at [∀ i, SMul M (α i)] [∀ i, Nonempty (α i)] (i : ι) [FaithfulSMul M (α i)] :
FaithfulSMul M (∀ i, α i) where
eq_of_smul_eq_smul h := eq_of_smul_eq_smul fun a : α i => by
classical
simpa using
congr_fun (h <| Function.update (fun j => Classical.choice (‹∀ i, Nonempty (α i)› j)) i a) i
@[to_additive]
instance faithfulSMul [Nonempty ι] [∀ i, SMul M (α i)] [∀ i, Nonempty (α i)]
[∀ i, FaithfulSMul M (α i)] : FaithfulSMul M (∀ i, α i) :=
let ⟨i⟩ := ‹Nonempty ι›
faithfulSMul_at i
@[to_additive]
instance mulAction (M) {m : Monoid M} [∀ i, MulAction M (α i)] : @MulAction M (∀ i, α i) m where
smul := (· • ·)
mul_smul _ _ _ := funext fun _ ↦ mul_smul _ _ _
one_smul _ := funext fun _ ↦ one_smul _ _
@[to_additive]
instance mulAction' {m : ∀ i, Monoid (α i)} [∀ i, MulAction (α i) (β i)] :
@MulAction (∀ i, α i) (∀ i, β i)
(@Pi.monoid ι α m) where
smul := (· • ·)
mul_smul _ _ _ := funext fun _ ↦ mul_smul _ _ _
one_smul _ := funext fun _ ↦ one_smul _ _
end Pi
namespace Function
/-- Non-dependent version of `Pi.smul`. Lean gets confused by the dependent instance if this
is not present. -/
@[to_additive
/-- Non-dependent version of `Pi.vadd`. Lean gets confused by the dependent instance
if this is not present. -/]
instance hasSMul {α : Type*} [SMul M α] : SMul M (ι → α) := Pi.instSMul
/-- Non-dependent version of `Pi.smulCommClass`. Lean gets confused by the dependent instance if
this is not present. -/
@[to_additive
/-- Non-dependent version of `Pi.vaddCommClass`. Lean gets confused by the dependent
instance if this is not present. -/]
instance smulCommClass {α : Type*} [SMul M α] [SMul N α] [SMulCommClass M N α] :
SMulCommClass M N (ι → α) := Pi.smulCommClass
@[to_additive]
lemma update_smul [∀ i, SMul M (α i)] [DecidableEq ι] (c : M) (f₁ : ∀ i, α i)
(i : ι) (x₁ : α i) : update (c • f₁) i (c • x₁) = c • update f₁ i x₁ :=
funext fun j => (apply_update (β := α) (fun _ ↦ (c • ·)) f₁ i x₁ j).symm
@[to_additive]
lemma extend_smul {M α β : Type*} [SMul M β] (r : M) (f : ι → α) (g : ι → β) (e : α → β) :
extend f (r • g) (r • e) = r • extend f g e := by
funext x
classical
simp only [extend_def, Pi.smul_apply]
split_ifs <;> rfl
end Function
namespace Set
@[to_additive]
lemma piecewise_smul [∀ i, SMul M (α i)] (s : Set ι) [∀ i, Decidable (i ∈ s)]
(c : M) (f₁ g₁ : ∀ i, α i) : s.piecewise (c • f₁) (c • g₁) = c • s.piecewise f₁ g₁ :=
s.piecewise_op (δ' := α) f₁ _ fun _ ↦ (c • ·)
end Set
|
CubicDiscriminant.lean
|
/-
Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.Tactic.IntervalCases
/-!
# Cubics and discriminants
This file defines cubic polynomials over a semiring and their discriminants over a splitting field.
## Main definitions
* `Cubic`: the structure representing a cubic polynomial.
* `Cubic.disc`: the discriminant of a cubic polynomial.
## Main statements
* `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if
the cubic has no duplicate roots.
## References
* https://en.wikipedia.org/wiki/Cubic_equation
* https://en.wikipedia.org/wiki/Discriminant
## Tags
cubic, discriminant, polynomial, root
-/
noncomputable section
/-- The structure representing a cubic polynomial. -/
@[ext]
structure Cubic (R : Type*) where
/-- The degree-3 coefficient -/
a : R
/-- The degree-2 coefficient -/
b : R
/-- The degree-1 coefficient -/
c : R
/-- The degree-0 coefficient -/
d : R
namespace Cubic
open Polynomial
variable {R S F K : Type*}
instance [Inhabited R] : Inhabited (Cubic R) :=
⟨⟨default, default, default, default⟩⟩
instance [Zero R] : Zero (Cubic R) :=
⟨⟨0, 0, 0, 0⟩⟩
section Basic
variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R]
/-- Convert a cubic polynomial to a polynomial. -/
def toPoly (P : Cubic R) : R[X] :=
C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d
theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} :
C w * (X - C x) * (X - C y) * (X - C z) =
toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by
simp only [toPoly, C_neg, C_add, C_mul]
ring1
theorem prod_X_sub_C_eq [CommRing S] {x y z : S} :
(X - C x) * (X - C y) * (X - C z) =
toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by
rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul]
/-! ### Coefficients -/
section Coeff
private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧
P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by
simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow]
norm_num
intro n hn
repeat' rw [if_neg]
any_goals omega
repeat' rw [zero_add]
@[simp]
theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 :=
coeffs.1 n hn
@[simp]
theorem coeff_eq_a : P.toPoly.coeff 3 = P.a :=
coeffs.2.1
@[simp]
theorem coeff_eq_b : P.toPoly.coeff 2 = P.b :=
coeffs.2.2.1
@[simp]
theorem coeff_eq_c : P.toPoly.coeff 1 = P.c :=
coeffs.2.2.2.1
@[simp]
theorem coeff_eq_d : P.toPoly.coeff 0 = P.d :=
coeffs.2.2.2.2
theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a]
theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b]
theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c]
theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d]
theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q :=
⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩
theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by
rw [toPoly, ha, C_0, zero_mul, zero_add]
theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d :=
of_a_eq_zero rfl
theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by
rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add]
theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d :=
of_b_eq_zero rfl rfl
theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by
rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add]
theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d :=
of_c_eq_zero rfl rfl rfl
theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly = 0 := by
rw [of_c_eq_zero ha hb hc, hd, C_0]
theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 :=
of_d_eq_zero rfl rfl rfl rfl
theorem zero : (0 : Cubic R).toPoly = 0 :=
of_d_eq_zero'
theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by
rw [← zero, toPoly_injective]
private theorem ne_zero (h0 : P.a ≠ 0 ∨ P.b ≠ 0 ∨ P.c ≠ 0 ∨ P.d ≠ 0) : P.toPoly ≠ 0 := by
contrapose! h0
rw [(toPoly_eq_zero_iff P).mp h0]
exact ⟨rfl, rfl, rfl, rfl⟩
theorem ne_zero_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp ne_zero).1 ha
theorem ne_zero_of_b_ne_zero (hb : P.b ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp ne_zero).2).1 hb
theorem ne_zero_of_c_ne_zero (hc : P.c ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc
theorem ne_zero_of_d_ne_zero (hd : P.d ≠ 0) : P.toPoly ≠ 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd
@[simp]
theorem leadingCoeff_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.leadingCoeff = P.a :=
leadingCoeff_cubic ha
theorem leadingCoeff_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a := by
simp [ha]
@[simp]
theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.leadingCoeff = P.b := by
rw [of_a_eq_zero ha, leadingCoeff_quadratic hb]
theorem leadingCoeff_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b := by
simp [hb]
@[simp]
theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.leadingCoeff = P.c := by
rw [of_b_eq_zero ha hb, leadingCoeff_linear hc]
theorem leadingCoeff_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c := by
simp [hc]
@[simp]
theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.leadingCoeff = P.d := by
rw [of_c_eq_zero ha hb hc, leadingCoeff_C]
theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d :=
leadingCoeff_of_c_eq_zero rfl rfl rfl
theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_a_ne_zero (ha ▸ one_ne_zero), ha]
theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic :=
monic_of_a_eq_one rfl
theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_b_ne_zero ha (hb ▸ one_ne_zero), hb]
theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic :=
monic_of_b_eq_one rfl rfl
theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc ▸ one_ne_zero), hc]
theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic :=
monic_of_c_eq_one rfl rfl rfl
theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) :
P.toPoly.Monic := by
rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd]
theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic :=
monic_of_d_eq_one rfl rfl rfl rfl
end Coeff
/-! ### Degrees -/
section Degree
/-- The equivalence between cubic polynomials and polynomials of degree at most three. -/
@[simps]
def equiv : Cubic R ≃ { p : R[X] // p.degree ≤ 3 } where
toFun P := ⟨P.toPoly, degree_cubic_le⟩
invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩
left_inv P := by ext <;> simp only [coeffs]
right_inv f := by
ext n
obtain hn | hn := le_or_gt n 3
· interval_cases n <;> simp only <;> ring_nf <;> try simp only [coeffs]
· rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2]
simpa using hn
@[simp]
theorem degree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.degree = 3 :=
degree_cubic ha
theorem degree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).degree = 3 := by
simp [ha]
theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≤ 2 := by
simpa only [of_a_eq_zero ha] using degree_quadratic_le
theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≤ 2 :=
degree_of_a_eq_zero rfl
@[simp]
theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.degree = 2 := by
rw [of_a_eq_zero ha, degree_quadratic hb]
theorem degree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).degree = 2 := by
simp [hb]
theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using degree_linear_le
theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≤ 1 :=
degree_of_b_eq_zero rfl rfl
@[simp]
theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.degree = 1 := by
rw [of_b_eq_zero ha hb, degree_linear hc]
theorem degree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 := by
simp [hc]
theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≤ 0 := by
simpa only [of_c_eq_zero ha hb hc] using degree_C_le
theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≤ 0 :=
degree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d ≠ 0) :
P.toPoly.degree = 0 := by
rw [of_c_eq_zero ha hb hc, degree_C hd]
theorem degree_of_d_ne_zero' (hd : d ≠ 0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 := by
simp [hd]
@[simp]
theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly.degree = ⊥ := by
rw [of_d_eq_zero ha hb hc hd, degree_zero]
theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero rfl rfl rfl rfl
@[simp]
theorem degree_of_zero : (0 : Cubic R).toPoly.degree = ⊥ :=
degree_of_d_eq_zero'
@[simp]
theorem natDegree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.natDegree = 3 :=
natDegree_cubic ha
theorem natDegree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).natDegree = 3 := by
simp [ha]
theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree ≤ 2 := by
simpa only [of_a_eq_zero ha] using natDegree_quadratic_le
theorem natDegree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).natDegree ≤ 2 :=
natDegree_of_a_eq_zero rfl
@[simp]
theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.natDegree = 2 := by
rw [of_a_eq_zero ha, natDegree_quadratic hb]
theorem natDegree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).natDegree = 2 := by
simp [hb]
theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree ≤ 1 := by
simpa only [of_b_eq_zero ha hb] using natDegree_linear_le
theorem natDegree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).natDegree ≤ 1 :=
natDegree_of_b_eq_zero rfl rfl
@[simp]
theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) :
P.toPoly.natDegree = 1 := by
rw [of_b_eq_zero ha hb, natDegree_linear hc]
theorem natDegree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).natDegree = 1 := by
simp [hc]
@[simp]
theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.natDegree = 0 := by
rw [of_c_eq_zero ha hb hc, natDegree_C]
theorem natDegree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).natDegree = 0 :=
natDegree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 :=
natDegree_of_c_eq_zero'
end Degree
/-! ### Map across a homomorphism -/
section Map
variable [Semiring S] {φ : R →+* S}
/-- Map a cubic polynomial across a semiring homomorphism. -/
def map (φ : R →+* S) (P : Cubic R) : Cubic S :=
⟨φ P.a, φ P.b, φ P.c, φ P.d⟩
theorem map_toPoly : (map φ P).toPoly = Polynomial.map φ P.toPoly := by
simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow]
end Map
end Basic
section Roots
open Multiset
/-! ### Roots over an extension -/
section Extension
variable {P : Cubic R} [CommRing R] [CommRing S] {φ : R →+* S}
/-- The roots of a cubic polynomial. -/
def roots [IsDomain R] (P : Cubic R) : Multiset R :=
P.toPoly.roots
theorem map_roots [IsDomain S] : (map φ P).roots = (Polynomial.map φ P.toPoly).roots := by
rw [roots, map_toPoly]
theorem mem_roots_iff [IsDomain R] (h0 : P.toPoly ≠ 0) (x : R) :
x ∈ P.roots ↔ P.a * x ^ 3 + P.b * x ^ 2 + P.c * x + P.d = 0 := by
rw [roots, mem_roots h0, IsRoot, toPoly]
simp only [eval_C, eval_X, eval_add, eval_mul, eval_pow]
theorem card_roots_le [IsDomain R] [DecidableEq R] : P.roots.toFinset.card ≤ 3 := by
apply (toFinset_card_le P.toPoly.roots).trans
by_cases hP : P.toPoly = 0
· exact (card_roots' P.toPoly).trans (by rw [hP, natDegree_zero]; exact zero_le 3)
· exact WithBot.coe_le_coe.1 ((card_roots hP).trans degree_cubic_le)
end Extension
variable {P : Cubic F} [Field F] [Field K] {φ : F →+* K} {x y z : K}
/-! ### Roots over a splitting field -/
section Split
theorem splits_iff_card_roots (ha : P.a ≠ 0) :
Splits φ P.toPoly ↔ Multiset.card (map φ P).roots = 3 := by
replace ha : (map φ P).a ≠ 0 := (_root_.map_ne_zero φ).mpr ha
nth_rw 1 [← RingHom.id_comp φ]
rw [roots, ← splits_map_iff, ← map_toPoly, Polynomial.splits_iff_card_roots,
← ((degree_eq_iff_natDegree_eq <| ne_zero_of_a_ne_zero ha).1 <| degree_of_a_ne_zero ha : _ = 3)]
theorem splits_iff_roots_eq_three (ha : P.a ≠ 0) :
Splits φ P.toPoly ↔ ∃ x y z : K, (map φ P).roots = {x, y, z} := by
rw [splits_iff_card_roots ha, card_eq_three]
theorem eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
(map φ P).toPoly = C (φ P.a) * (X - C x) * (X - C y) * (X - C z) := by
rw [map_toPoly,
eq_prod_roots_of_splits <|
(splits_iff_roots_eq_three ha).mpr <| Exists.intro x <| Exists.intro y <| Exists.intro z h3,
leadingCoeff_of_a_ne_zero ha, ← map_roots, h3]
change C (φ P.a) * ((X - C x) ::ₘ (X - C y) ::ₘ {X - C z}).prod = _
rw [prod_cons, prod_cons, prod_singleton, mul_assoc, mul_assoc]
theorem eq_sum_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
map φ P =
⟨φ P.a, φ P.a * -(x + y + z), φ P.a * (x * y + x * z + y * z), φ P.a * -(x * y * z)⟩ := by
apply_fun @toPoly _ _
· rw [eq_prod_three_roots ha h3, C_mul_prod_X_sub_C_eq]
· exact fun P Q ↦ (toPoly_injective P Q).mp
theorem b_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.b = φ P.a * -(x + y + z) := by
injection eq_sum_three_roots ha h3
theorem c_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.c = φ P.a * (x * y + x * z + y * z) := by
injection eq_sum_three_roots ha h3
theorem d_eq_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.d = φ P.a * -(x * y * z) := by
injection eq_sum_three_roots ha h3
end Split
/-! ### Discriminant over a splitting field -/
section Discriminant
/-- The discriminant of a cubic polynomial. -/
def disc {R : Type*} [Ring R] (P : Cubic R) : R :=
P.b ^ 2 * P.c ^ 2 - 4 * P.a * P.c ^ 3 - 4 * P.b ^ 3 * P.d - 27 * P.a ^ 2 * P.d ^ 2 +
18 * P.a * P.b * P.c * P.d
theorem disc_eq_prod_three_roots (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
φ P.disc = (φ P.a * φ P.a * (x - y) * (x - z) * (y - z)) ^ 2 := by
simp only [disc, RingHom.map_add, RingHom.map_sub, RingHom.map_mul, map_pow, map_ofNat]
rw [b_eq_three_roots ha h3, c_eq_three_roots ha h3, d_eq_three_roots ha h3]
ring1
theorem disc_ne_zero_iff_roots_ne (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
P.disc ≠ 0 ↔ x ≠ y ∧ x ≠ z ∧ y ≠ z := by
rw [← _root_.map_ne_zero φ, disc_eq_prod_three_roots ha h3, pow_two]
simp_rw [mul_ne_zero_iff, sub_ne_zero, _root_.map_ne_zero, and_self_iff, and_iff_right ha,
and_assoc]
theorem disc_ne_zero_iff_roots_nodup (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z}) :
P.disc ≠ 0 ↔ (map φ P).roots.Nodup := by
rw [disc_ne_zero_iff_roots_ne ha h3, h3]
change _ ↔ (x ::ₘ y ::ₘ {z}).Nodup
rw [nodup_cons, nodup_cons, mem_cons, mem_singleton, mem_singleton]
simp only [nodup_singleton]
tauto
theorem card_roots_of_disc_ne_zero [DecidableEq K] (ha : P.a ≠ 0) (h3 : (map φ P).roots = {x, y, z})
(hd : P.disc ≠ 0) : (map φ P).roots.toFinset.card = 3 := by
rw [toFinset_card_of_nodup <| (disc_ne_zero_iff_roots_nodup ha h3).mp hd,
← splits_iff_card_roots ha, splits_iff_roots_eq_three ha]
exact ⟨x, ⟨y, ⟨z, h3⟩⟩⟩
end Discriminant
end Roots
end Cubic
|
Defs.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.SetNotation
/-!
# Definition of complete lattices
This file contains the definition of complete lattices with suprema/infima of arbitrary sets.
## Main definitions
* `sSup` and `sInf` are the supremum and the infimum of a set;
* `iSup (f : ι → α)` and `iInf (f : ι → α)` are indexed supremum and infimum of a function,
defined as `sSup` and `sInf` of the range of this function;
* class `CompleteLattice`: a bounded lattice such that `sSup s` is always the least upper boundary
of `s` and `sInf s` is always the greatest lower boundary of `s`;
* class `CompleteLinearOrder`: a linear ordered complete lattice.
## Naming conventions
In lemma names,
* `sSup` is called `sSup`
* `sInf` is called `sInf`
* `⨆ i, s i` is called `iSup`
* `⨅ i, s i` is called `iInf`
* `⨆ i j, s i j` is called `iSup₂`. This is an `iSup` inside an `iSup`.
* `⨅ i j, s i j` is called `iInf₂`. This is an `iInf` inside an `iInf`.
* `⨆ i ∈ s, t i` is called `biSup` for "bounded `iSup`". This is the special case of `iSup₂`
where `j : i ∈ s`.
* `⨅ i ∈ s, t i` is called `biInf` for "bounded `iInf`". This is the special case of `iInf₂`
where `j : i ∈ s`.
## Notation
* `⨆ i, f i` : `iSup f`, the supremum of the range of `f`;
* `⨅ i, f i` : `iInf f`, the infimum of the range of `f`.
-/
open Function OrderDual Set
variable {α β γ : Type*} {ι ι' : Sort*} {κ : ι → Sort*} {κ' : ι' → Sort*}
instance OrderDual.supSet (α) [InfSet α] : SupSet αᵒᵈ :=
⟨(sInf : Set α → α)⟩
instance OrderDual.infSet (α) [SupSet α] : InfSet αᵒᵈ :=
⟨(sSup : Set α → α)⟩
/-- Note that we rarely use `CompleteSemilatticeSup`
(in fact, any such object is always a `CompleteLattice`, so it's usually best to start there).
Nevertheless it is sometimes a useful intermediate step in constructions.
-/
class CompleteSemilatticeSup (α : Type*) extends PartialOrder α, SupSet α where
/-- Any element of a set is less than the set supremum. -/
le_sSup : ∀ s, ∀ a ∈ s, a ≤ sSup s
/-- Any upper bound is more than the set supremum. -/
sSup_le : ∀ s a, (∀ b ∈ s, b ≤ a) → sSup s ≤ a
section
variable [CompleteSemilatticeSup α] {s t : Set α} {a b : α}
theorem le_sSup : a ∈ s → a ≤ sSup s :=
CompleteSemilatticeSup.le_sSup s a
theorem sSup_le : (∀ b ∈ s, b ≤ a) → sSup s ≤ a :=
CompleteSemilatticeSup.sSup_le s a
theorem isLUB_sSup (s : Set α) : IsLUB s (sSup s) :=
⟨fun _ ↦ le_sSup, fun _ ↦ sSup_le⟩
lemma isLUB_iff_sSup_eq : IsLUB s a ↔ sSup s = a :=
⟨(isLUB_sSup s).unique, by rintro rfl; exact isLUB_sSup _⟩
alias ⟨IsLUB.sSup_eq, _⟩ := isLUB_iff_sSup_eq
theorem le_sSup_of_le (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s :=
le_trans h (le_sSup hb)
@[gcongr]
theorem sSup_le_sSup (h : s ⊆ t) : sSup s ≤ sSup t :=
(isLUB_sSup s).mono (isLUB_sSup t) h
@[simp]
theorem sSup_le_iff : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a :=
isLUB_le_iff (isLUB_sSup s)
theorem le_sSup_iff : a ≤ sSup s ↔ ∀ b ∈ upperBounds s, a ≤ b :=
⟨fun h _ hb => le_trans h (sSup_le hb), fun hb => hb _ fun _ => le_sSup⟩
theorem le_iSup_iff {s : ι → α} : a ≤ iSup s ↔ ∀ b, (∀ i, s i ≤ b) → a ≤ b := by
simp [iSup, le_sSup_iff, upperBounds]
end
/-- Note that we rarely use `CompleteSemilatticeInf`
(in fact, any such object is always a `CompleteLattice`, so it's usually best to start there).
Nevertheless it is sometimes a useful intermediate step in constructions.
-/
class CompleteSemilatticeInf (α : Type*) extends PartialOrder α, InfSet α where
/-- Any element of a set is more than the set infimum. -/
sInf_le : ∀ s, ∀ a ∈ s, sInf s ≤ a
/-- Any lower bound is less than the set infimum. -/
le_sInf : ∀ s a, (∀ b ∈ s, a ≤ b) → a ≤ sInf s
section
variable [CompleteSemilatticeInf α] {s t : Set α} {a b : α}
theorem sInf_le : a ∈ s → sInf s ≤ a :=
CompleteSemilatticeInf.sInf_le s a
theorem le_sInf : (∀ b ∈ s, a ≤ b) → a ≤ sInf s :=
CompleteSemilatticeInf.le_sInf s a
theorem isGLB_sInf (s : Set α) : IsGLB s (sInf s) :=
⟨fun _ => sInf_le, fun _ => le_sInf⟩
lemma isGLB_iff_sInf_eq : IsGLB s a ↔ sInf s = a :=
⟨(isGLB_sInf s).unique, by rintro rfl; exact isGLB_sInf _⟩
alias ⟨IsGLB.sInf_eq, _⟩ := isGLB_iff_sInf_eq
theorem sInf_le_of_le (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a :=
le_trans (sInf_le hb) h
@[gcongr]
theorem sInf_le_sInf (h : s ⊆ t) : sInf t ≤ sInf s :=
(isGLB_sInf s).mono (isGLB_sInf t) h
@[simp]
theorem le_sInf_iff : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b :=
le_isGLB_iff (isGLB_sInf s)
theorem sInf_le_iff : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a :=
⟨fun h _ hb => le_trans (le_sInf hb) h, fun hb => hb _ fun _ => sInf_le⟩
theorem iInf_le_iff {s : ι → α} : iInf s ≤ a ↔ ∀ b, (∀ i, b ≤ s i) → b ≤ a := by
simp [iInf, sInf_le_iff, lowerBounds]
end
instance {α : Type*} [CompleteSemilatticeInf α] : CompleteSemilatticeSup αᵒᵈ where
le_sSup := @CompleteSemilatticeInf.sInf_le α _
sSup_le := @CompleteSemilatticeInf.le_sInf α _
instance {α : Type*} [CompleteSemilatticeSup α] : CompleteSemilatticeInf αᵒᵈ where
le_sInf := @CompleteSemilatticeSup.sSup_le α _
sInf_le := @CompleteSemilatticeSup.le_sSup α _
/-- A complete lattice is a bounded lattice which has suprema and infima for every subset. -/
class CompleteLattice (α : Type*) extends Lattice α, CompleteSemilatticeSup α,
CompleteSemilatticeInf α, BoundedOrder α
/-- Create a `CompleteLattice` from a `PartialOrder` and `InfSet`
that returns the greatest lower bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `CompleteLattice`
instance as
```
instance : CompleteLattice my_T where
inf := better_inf
le_inf := ...
inf_le_right := ...
inf_le_left := ...
-- don't care to fix sup, sSup, bot, top
__ := completeLatticeOfInf my_T _
```
-/
def completeLatticeOfInf (α : Type*) [H1 : PartialOrder α] [H2 : InfSet α]
(isGLB_sInf : ∀ s : Set α, IsGLB s (sInf s)) : CompleteLattice α where
__ := H1; __ := H2
bot := sInf univ
bot_le _ := (isGLB_sInf univ).1 trivial
top := sInf ∅
le_top a := (isGLB_sInf ∅).2 <| by simp
sup a b := sInf { x : α | a ≤ x ∧ b ≤ x }
inf a b := sInf {a, b}
le_inf a b c hab hac := by
apply (isGLB_sInf _).2
simp [*]
inf_le_right _ _ := (isGLB_sInf _).1 <| mem_insert_of_mem _ <| mem_singleton _
inf_le_left _ _ := (isGLB_sInf _).1 <| mem_insert _ _
sup_le a b c hac hbc := (isGLB_sInf _).1 <| by simp [*]
le_sup_left _ _ := (isGLB_sInf _).2 fun _ => And.left
le_sup_right _ _ := (isGLB_sInf _).2 fun _ => And.right
le_sInf s _ ha := (isGLB_sInf s).2 ha
sInf_le s _ ha := (isGLB_sInf s).1 ha
sSup s := sInf (upperBounds s)
le_sSup s _ ha := (isGLB_sInf (upperBounds s)).2 fun _ hb => hb ha
sSup_le s _ ha := (isGLB_sInf (upperBounds s)).1 ha
/-- Any `CompleteSemilatticeInf` is in fact a `CompleteLattice`.
Note that this construction has bad definitional properties:
see the doc-string on `completeLatticeOfInf`.
-/
def completeLatticeOfCompleteSemilatticeInf (α : Type*) [CompleteSemilatticeInf α] :
CompleteLattice α :=
completeLatticeOfInf α fun s => isGLB_sInf s
/-- Create a `CompleteLattice` from a `PartialOrder` and `SupSet`
that returns the least upper bound of a set. Usually this constructor provides
poor definitional equalities. If other fields are known explicitly, they should be
provided; for example, if `inf` is known explicitly, construct the `CompleteLattice`
instance as
```
instance : CompleteLattice my_T where
inf := better_inf
le_inf := ...
inf_le_right := ...
inf_le_left := ...
-- don't care to fix sup, sInf, bot, top
__ := completeLatticeOfSup my_T _
```
-/
def completeLatticeOfSup (α : Type*) [H1 : PartialOrder α] [H2 : SupSet α]
(isLUB_sSup : ∀ s : Set α, IsLUB s (sSup s)) : CompleteLattice α where
__ := H1; __ := H2
top := sSup univ
le_top _ := (isLUB_sSup univ).1 trivial
bot := sSup ∅
bot_le x := (isLUB_sSup ∅).2 <| by simp
sup a b := sSup {a, b}
sup_le a b c hac hbc := (isLUB_sSup _).2 (by simp [*])
le_sup_left _ _ := (isLUB_sSup _).1 <| mem_insert _ _
le_sup_right _ _ := (isLUB_sSup _).1 <| mem_insert_of_mem _ <| mem_singleton _
inf a b := sSup { x | x ≤ a ∧ x ≤ b }
le_inf a b c hab hac := (isLUB_sSup _).1 <| by simp [*]
inf_le_left _ _ := (isLUB_sSup _).2 fun _ => And.left
inf_le_right _ _ := (isLUB_sSup _).2 fun _ => And.right
sInf s := sSup (lowerBounds s)
sSup_le s _ ha := (isLUB_sSup s).2 ha
le_sSup s _ ha := (isLUB_sSup s).1 ha
sInf_le s _ ha := (isLUB_sSup (lowerBounds s)).2 fun _ hb => hb ha
le_sInf s _ ha := (isLUB_sSup (lowerBounds s)).1 ha
/-- Any `CompleteSemilatticeSup` is in fact a `CompleteLattice`.
Note that this construction has bad definitional properties:
see the doc-string on `completeLatticeOfSup`.
-/
def completeLatticeOfCompleteSemilatticeSup (α : Type*) [CompleteSemilatticeSup α] :
CompleteLattice α :=
completeLatticeOfSup α fun s => isLUB_sSup s
/-- A complete linear order is a linear order whose lattice structure is complete. -/
-- Note that we do not use `extends LinearOrder α`,
-- and instead construct the forgetful instance manually.
class CompleteLinearOrder (α : Type*) extends CompleteLattice α, BiheytingAlgebra α, Ord α where
/-- A linear order is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableLE : DecidableLE α
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ toDecidableLE
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableLT : DecidableLT α := @decidableLTOfDecidableLE _ _ toDecidableLE
compare a b := compareOfLessAndEq a b
/-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/
compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by
compareOfLessAndEq_rfl
instance CompleteLinearOrder.toLinearOrder [i : CompleteLinearOrder α] : LinearOrder α where
__ := i
min_def a b := by
split_ifs with h
· simp [h]
· simp [(CompleteLinearOrder.le_total a b).resolve_left h]
max_def a b := by
split_ifs with h
· simp [h]
· simp [(CompleteLinearOrder.le_total a b).resolve_left h]
namespace OrderDual
instance instCompleteLattice [CompleteLattice α] : CompleteLattice αᵒᵈ where
__ := instBoundedOrder α
le_sSup := @CompleteLattice.sInf_le α _
sSup_le := @CompleteLattice.le_sInf α _
sInf_le := @CompleteLattice.le_sSup α _
le_sInf := @CompleteLattice.sSup_le α _
instance instCompleteLinearOrder [CompleteLinearOrder α] : CompleteLinearOrder αᵒᵈ where
__ := instCompleteLattice
__ := instBiheytingAlgebra
__ := instLinearOrder α
end OrderDual
open OrderDual
section
section OrderDual
@[simp]
theorem toDual_sSup [SupSet α] (s : Set α) : toDual (sSup s) = sInf (ofDual ⁻¹' s) :=
rfl
@[simp]
theorem toDual_sInf [InfSet α] (s : Set α) : toDual (sInf s) = sSup (ofDual ⁻¹' s) :=
rfl
@[simp]
theorem ofDual_sSup [InfSet α] (s : Set αᵒᵈ) : ofDual (sSup s) = sInf (toDual ⁻¹' s) :=
rfl
@[simp]
theorem ofDual_sInf [SupSet α] (s : Set αᵒᵈ) : ofDual (sInf s) = sSup (toDual ⁻¹' s) :=
rfl
@[simp]
theorem toDual_iSup [SupSet α] (f : ι → α) : toDual (⨆ i, f i) = ⨅ i, toDual (f i) :=
rfl
@[simp]
theorem toDual_iInf [InfSet α] (f : ι → α) : toDual (⨅ i, f i) = ⨆ i, toDual (f i) :=
rfl
@[simp]
theorem ofDual_iSup [InfSet α] (f : ι → αᵒᵈ) : ofDual (⨆ i, f i) = ⨅ i, ofDual (f i) :=
rfl
@[simp]
theorem ofDual_iInf [SupSet α] (f : ι → αᵒᵈ) : ofDual (⨅ i, f i) = ⨆ i, ofDual (f i) :=
rfl
end OrderDual
section CompleteLinearOrder
variable [CompleteLinearOrder α] {s : Set α} {a b : α}
theorem lt_sSup_iff : b < sSup s ↔ ∃ a ∈ s, b < a :=
lt_isLUB_iff <| isLUB_sSup s
theorem sInf_lt_iff : sInf s < b ↔ ∃ a ∈ s, a < b :=
isGLB_lt_iff <| isGLB_sInf s
theorem sSup_eq_top : sSup s = ⊤ ↔ ∀ b < ⊤, ∃ a ∈ s, b < a :=
⟨fun h _ hb => lt_sSup_iff.1 <| hb.trans_eq h.symm, fun h =>
top_unique <|
le_of_not_gt fun h' =>
let ⟨_, ha, h⟩ := h _ h'
(h.trans_le <| le_sSup ha).false⟩
theorem sInf_eq_bot : sInf s = ⊥ ↔ ∀ b > ⊥, ∃ a ∈ s, a < b :=
@sSup_eq_top αᵒᵈ _ _
theorem lt_iSup_iff {f : ι → α} : a < iSup f ↔ ∃ i, a < f i :=
lt_sSup_iff.trans exists_range_iff
theorem iInf_lt_iff {f : ι → α} : iInf f < a ↔ ∃ i, f i < a :=
sInf_lt_iff.trans exists_range_iff
theorem lt_biSup_iff {s : Set β} {f : β → α} : a < ⨆ i ∈ s, f i ↔ ∃ i ∈ s, a < f i := by
simp [lt_iSup_iff]
theorem biInf_lt_iff {s : Set β} {f : β → α} : ⨅ i ∈ s, f i < a ↔ ∃ i ∈ s, f i < a := by
simp [iInf_lt_iff]
end CompleteLinearOrder
end
|
Result.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 Archive.Examples.IfNormalization.Statement
import Mathlib.Data.List.AList
import Mathlib.Tactic.Recall
/-!
# A solution to the if normalization challenge in Lean.
See `Statement.lean` for background.
-/
macro "◾" : tactic => `(tactic| aesop)
macro "◾" : term => `(term| by aesop)
namespace IfExpr
/-!
We add some local simp lemmas so we can unfold the definitions of the normalization condition.
-/
attribute [local simp] normalized hasNestedIf hasConstantIf hasRedundantIf disjoint vars
List.disjoint
attribute [local simp] apply_ite ite_eq_iff'
variable {b : Bool} {f : ℕ → Bool} {i : ℕ} {t e : IfExpr}
/-!
Simp lemmas for `eval`.
We don't want a `simp` lemma for `(ite i t e).eval` in general, only once we know the shape of `i`.
-/
@[simp] theorem eval_lit : (lit b).eval f = b := rfl
@[simp] theorem eval_var : (var i).eval f = f i := rfl
@[simp] theorem eval_ite_lit :
(ite (.lit b) t e).eval f = bif b then t.eval f else e.eval f := rfl
@[simp] theorem eval_ite_var :
(ite (.var i) t e).eval f = bif f i then t.eval f else e.eval f := rfl
@[simp] theorem eval_ite_ite {a b c d e : IfExpr} :
(ite (ite a b c) d e).eval f = (ite a (ite b d e) (ite c d e)).eval f := by
cases h : eval f a <;> simp_all [eval]
/-- Custom size function for if-expressions, used for proving termination. -/
@[simp] def normSize : IfExpr → Nat
| lit _ => 0
| var _ => 1
| .ite i t e => 2 * normSize i + max (normSize t) (normSize e) + 1
/-- Normalizes the expression at the same time as assigning all variables in
`e` to the literal booleans given by `l` -/
def normalize (l : AList (fun _ : ℕ => Bool)) :
(e : IfExpr) → { e' : IfExpr //
(∀ f, e'.eval f = e.eval (fun w => (l.lookup w).elim (f w) id))
∧ e'.normalized
∧ ∀ (v : ℕ), v ∈ vars e' → l.lookup v = none }
| lit b => ⟨lit b, ◾⟩
| var v =>
match h : l.lookup v with
| none => ⟨var v, ◾⟩
| some b => ⟨lit b, ◾⟩
| .ite (lit true) t e => have t' := normalize l t; ⟨t'.1, ◾⟩
| .ite (lit false) t e => have e' := normalize l e; ⟨e'.1, ◾⟩
| .ite (.ite a b c) t e => have i' := normalize l (.ite a (.ite b t e) (.ite c t e)); ⟨i'.1, ◾⟩
| .ite (var v) t e =>
match h : l.lookup v with
| none =>
have ⟨t', ht₁, ht₂, ht₃⟩ := normalize (l.insert v true) t
have ⟨e', he₁, he₂, he₃⟩ := normalize (l.insert v false) e
⟨if t' = e' then t' else .ite (var v) t' e', by
refine ⟨fun f => ?_, ?_, fun w b => ?_⟩
· -- eval = eval
simp? says simp only [apply_ite, eval_ite_var, ite_eq_iff']
cases hfv : f v
· simp_all
congr
ext w
by_cases w = v <;> ◾
· simp [h, ht₁]
congr
ext w
by_cases w = v <;> ◾
· -- normalized
have := ht₃ v
have := he₃ v
split <;> ◾
· -- lookup = none
have := ht₃ w
have := he₃ w
by_cases w = v <;> ◾⟩
| some b =>
have i' := normalize l (.ite (lit b) t e); ⟨i'.1, ◾⟩
termination_by e => e.normSize
/-
We recall the statement of the if-normalization problem.
We want a function from if-expressions to if-expressions,
that outputs normalized if-expressions and preserves meaning.
-/
recall IfNormalization :=
{ Z : IfExpr → IfExpr // ∀ e, (Z e).normalized ∧ (Z e).eval = e.eval }
example : IfNormalization :=
⟨_, fun e => ⟨(IfExpr.normalize ∅ e).2.2.1, by simp [(IfExpr.normalize ∅ e).2.1]⟩⟩
end IfExpr
|
Nondegenerate.lean
|
/-
Copyright (c) 2024 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.LinearAlgebra.BilinearForm.Basic
import Mathlib.LinearAlgebra.BilinearForm.Orthogonal
import Mathlib.LinearAlgebra.Dimension.Localization
import Mathlib.LinearAlgebra.QuadraticForm.Basic
import Mathlib.LinearAlgebra.RootSystem.BaseChange
import Mathlib.LinearAlgebra.RootSystem.Finite.CanonicalBilinear
/-!
# Nondegeneracy of the polarization on a finite root pairing
We show that if the base ring of a finite root pairing is linearly ordered, then the canonical
bilinear form is root-positive and positive-definite on the span of roots.
From these facts, it is easy to show that Coxeter weights in a finite root pairing are bounded
above by 4. Thus, the pairings of roots and coroots in a root pairing are restricted to the
interval `[-4, 4]`. Furthermore, a linearly independent pair of roots cannot have Coxeter weight 4.
For the case of crystallographic root pairings, we are thus reduced to a finite set of possible
options for each pair.
Another application is to the faithfulness of the Weyl group action on roots, and finiteness of the
Weyl group.
## Main results:
* `RootPairing.IsAnisotropic`: We say a finite root pairing is anisotropic if there are no roots /
coroots which have length zero wrt the root / coroot forms.
* `RootPairing.rootForm_pos_of_nonzero`: `RootForm` is strictly positive on non-zero linear
combinations of roots. This gives us a convenient way to eliminate certain Dynkin diagrams from
the classification, since it suffices to produce a nonzero linear combination of simple roots with
non-positive norm.
* `RootPairing.rootForm_restrict_nondegenerate_of_ordered`: The root form is non-degenerate if
the coefficients are ordered.
* `RootPairing.rootForm_restrict_nondegenerate_of_isAnisotropic`: the root form is
non-degenerate if the coefficients are a field and the pairing is crystallographic.
## References:
* [N. Bourbaki, *Lie groups and Lie algebras. Chapters 4--6*][bourbaki1968]
* [M. Demazure, *SGA III, Exposé XXI, Données Radicielles*][demazure1970]
## Todo
* Weyl-invariance of `RootForm` and `CorootForm`
* Faithfulness of Weyl group perm action, and finiteness of Weyl group, over ordered rings.
* Relation to Coxeter weight.
-/
noncomputable section
open Set Function
open Module hiding reflection
open Submodule (span)
namespace RootPairing
variable {ι R M N : Type*} [Fintype ι] [AddCommGroup M] [AddCommGroup N]
section CommRing
variable [CommRing R] [Module R M] [Module R N] (P : RootPairing ι R M N)
/-- We say a finite root pairing is anisotropic if there are no roots / coroots which have length
zero wrt the root / coroot forms.
Examples include crystallographic pairings in characteristic zero
`RootPairing.instIsAnisotropicOfIsCrystallographic` and pairings over ordered scalars.
`RootPairing.instIsAnisotropicOfLinearOrderedCommRing`. -/
class IsAnisotropic : Prop where
rootForm_root_ne_zero (i : ι) : P.RootForm (P.root i) (P.root i) ≠ 0
corootForm_coroot_ne_zero (i : ι) : P.CorootForm (P.coroot i) (P.coroot i) ≠ 0
instance [P.IsAnisotropic] : P.flip.IsAnisotropic where
rootForm_root_ne_zero := IsAnisotropic.corootForm_coroot_ne_zero
corootForm_coroot_ne_zero := IsAnisotropic.rootForm_root_ne_zero (P := P)
lemma isAnisotropic_of_isValuedIn (S : Type*)
[CommRing S] [LinearOrder S] [IsStrictOrderedRing S]
[Algebra S R] [FaithfulSMul S R] [P.IsValuedIn S] :
IsAnisotropic P where
rootForm_root_ne_zero i := (P.posRootForm S).form_apply_root_ne_zero i
corootForm_coroot_ne_zero i := (P.flip.posRootForm S).form_apply_root_ne_zero i
instance instIsAnisotropicOfIsCrystallographic [CharZero R] [P.IsCrystallographic] :
IsAnisotropic P :=
P.isAnisotropic_of_isValuedIn ℤ
/-- The root form of an anisotropic pairing as an invariant form. -/
@[simps] def toInvariantForm [P.IsAnisotropic] : P.InvariantForm where
form := P.RootForm
symm := P.rootForm_symmetric
ne_zero := IsAnisotropic.rootForm_root_ne_zero
isOrthogonal_reflection := P.rootForm_reflection_reflection_apply
section DomainAlg
variable (S : Type*) [CommRing S] [IsDomain R] [IsDomain S] [Algebra S R] [FaithfulSMul S R]
[P.IsValuedIn S] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N]
lemma finrank_range_polarization_eq_finrank_span_coroot [P.IsAnisotropic] :
finrank S (LinearMap.range (P.PolarizationIn S)) = finrank S (P.corootSpan S) := by
apply (Submodule.finrank_mono (P.range_polarizationIn_le_span_coroot S)).antisymm
have : IsReflexive R N := PerfectPairing.reflexive_right P.toPerfectPairing
have : NoZeroSMulDivisors S N := NoZeroSMulDivisors.trans_faithfulSMul S R N
have h_ne : ∏ i, (P.RootFormIn S (P.rootSpanMem S i) (P.rootSpanMem S i)) ≠ 0 := by
refine Finset.prod_ne_zero_iff.mpr fun i _ h ↦ ?_
have := (FaithfulSMul.algebraMap_eq_zero_iff S R).mpr h
rw [algebraMap_rootFormIn] at this
apply IsAnisotropic.rootForm_root_ne_zero i this
refine LinearMap.finrank_le_of_isSMulRegular (P.corootSpan S)
(LinearMap.range (M₂ := N) (P.PolarizationIn S))
(smul_right_injective N h_ne) ?_
intro _ hx
obtain ⟨c, hc⟩ := (Submodule.mem_span_range_iff_exists_fun S).mp hx
rw [← hc, Finset.smul_sum]
simp_rw [smul_smul, mul_comm, ← smul_smul]
exact Submodule.sum_smul_mem (LinearMap.range (P.PolarizationIn S)) c
fun j _ ↦ prod_rootFormIn_smul_coroot_mem_range_PolarizationIn P S j
/-- An auxiliary lemma en route to `RootPairing.finrank_corootSpan_eq`. -/
private lemma finrank_corootSpan_le [P.IsAnisotropic] :
finrank S (P.corootSpan S) ≤ finrank S (P.rootSpan S) := by
rw [← finrank_range_polarization_eq_finrank_span_coroot]
exact LinearMap.finrank_range_le (P.PolarizationIn S)
lemma finrank_corootSpan_eq [P.IsAnisotropic] :
finrank S (P.corootSpan S) = finrank S (P.rootSpan S) :=
le_antisymm (P.finrank_corootSpan_le S) (P.flip.finrank_corootSpan_le S)
lemma polarizationIn_Injective [P.IsAnisotropic] :
Function.Injective (P.PolarizationIn S) := by
have : IsReflexive R M := PerfectPairing.reflexive_left P.toPerfectPairing
have : NoZeroSMulDivisors S M := NoZeroSMulDivisors.trans_faithfulSMul S R M
rw [← LinearMap.ker_eq_bot, ← top_disjoint]
refine Submodule.disjoint_ker_of_finrank_le (L := ⊤) (P.PolarizationIn S) ?_
rw [finrank_top, ← finrank_corootSpan_eq, ← finrank_range_polarization_eq_finrank_span_coroot]
exact Submodule.finrank_mono <| le_of_eq <| LinearMap.range_eq_map (P.PolarizationIn S)
lemma exists_coroot_ne [P.IsAnisotropic]
{x : P.rootSpan S} (hx : x ≠ 0) :
∃ i, P.coroot'In S i x ≠ 0 := by
have hI := P.polarizationIn_Injective S
have h := (map_ne_zero_iff (P.PolarizationIn S) hI).mpr hx
rw [PolarizationIn_apply] at h
contrapose! h
exact Fintype.sum_eq_zero (fun a ↦ (P.coroot'In S a) x • P.coroot a) fun i ↦ by simp [h i]
end DomainAlg
section LinearOrderedCommRingAlg
variable (S : Type*) [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] [IsDomain R] [Algebra S R]
[FaithfulSMul S R] [P.IsValuedIn S] [Module S M] [IsScalarTower S R M] [Module S N]
[IsScalarTower S R N]
theorem posRootForm_posForm_pos_of_ne_zero {x : P.rootSpan S} (hx : x ≠ 0) :
0 < (P.posRootForm S).posForm x x := by
rw [posRootForm_posForm_apply_apply]
have := P.isAnisotropic_of_isValuedIn S
have : ∃ i ∈ Finset.univ, 0 < (P.coroot'In S i) x * (P.coroot'In S i) x := by
obtain ⟨i, hi⟩ := P.exists_coroot_ne S hx
use i
exact ⟨Finset.mem_univ i, mul_self_pos.mpr hi⟩
exact Finset.sum_pos' (fun i a ↦ mul_self_nonneg ((P.coroot'In S i) x)) this
lemma posRootForm_posForm_anisotropic :
(P.posRootForm S).posForm.toQuadraticMap.Anisotropic :=
fun _ hx ↦ Classical.byContradiction fun h ↦
(ne_of_lt (posRootForm_posForm_pos_of_ne_zero P S h)).symm hx
lemma posRootForm_posForm_nondegenerate :
(P.posRootForm S).posForm.Nondegenerate := by
refine LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot.mpr <| LinearMap.ker_eq_bot'.mpr ?_
intro x hx
contrapose! hx
rw [DFunLike.ne_iff]
use x
exact (posRootForm_posForm_pos_of_ne_zero P S hx).ne'
end LinearOrderedCommRingAlg
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R] [Module R M] [Module R N] (P : RootPairing ι R M N)
[P.IsAnisotropic]
@[simp]
lemma finrank_rootSpan_map_polarization_eq_finrank_corootSpan :
finrank R ((P.rootSpan R).map P.Polarization) = finrank R (P.corootSpan R) := by
rw [← P.finrank_range_polarization_eq_finrank_span_coroot R, range_polarizationIn]
/-- An auxiliary lemma en route to `RootPairing.finrank_corootSpan_eq'`. -/
private lemma finrank_corootSpan_le' :
finrank R (P.corootSpan R) ≤ finrank R (P.rootSpan R) := by
rw [← finrank_rootSpan_map_polarization_eq_finrank_corootSpan]
exact Submodule.finrank_map_le P.Polarization (P.rootSpan R)
/-- Equality of finranks when the base is a domain. -/
lemma finrank_corootSpan_eq' :
finrank R (P.corootSpan R) = finrank R (P.rootSpan R) :=
le_antisymm P.finrank_corootSpan_le' P.flip.finrank_corootSpan_le'
lemma disjoint_rootSpan_ker_rootForm :
Disjoint (P.rootSpan R) (LinearMap.ker P.RootForm) := by
have : IsReflexive R M := PerfectPairing.reflexive_left P.toPerfectPairing
rw [← P.ker_polarization_eq_ker_rootForm]
refine Submodule.disjoint_ker_of_finrank_le (L := P.rootSpan R) P.Polarization ?_
rw [P.finrank_rootSpan_map_polarization_eq_finrank_corootSpan, P.finrank_corootSpan_eq']
lemma disjoint_corootSpan_ker_corootForm :
Disjoint (P.corootSpan R) (LinearMap.ker P.CorootForm) :=
P.flip.disjoint_rootSpan_ker_rootForm
lemma _root_.RootSystem.rootForm_nondegenerate (P : RootSystem ι R M N) [P.IsAnisotropic] :
P.RootForm.Nondegenerate :=
LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot.mpr <| by
simpa using P.disjoint_rootSpan_ker_rootForm
end IsDomain
section Field
variable [Field R] [Module R M] [Module R N] (P : RootPairing ι R M N) [P.IsAnisotropic]
lemma isCompl_rootSpan_ker_rootForm :
IsCompl (P.rootSpan R) (LinearMap.ker P.RootForm) := by
have _iM : IsReflexive R M := PerfectPairing.reflexive_left P.toPerfectPairing
have _iN : IsReflexive R N := PerfectPairing.reflexive_right P.toPerfectPairing
refine (Submodule.isCompl_iff_disjoint _ _ ?_).mpr P.disjoint_rootSpan_ker_rootForm
have aux : finrank R M =
finrank R (P.rootSpan R) + finrank R (P.corootSpan R).dualAnnihilator := by
rw [P.toPerfectPairing.finrank_eq, ← P.finrank_corootSpan_eq',
Subspace.finrank_add_finrank_dualAnnihilator_eq (P.corootSpan R)]
rw [aux, add_le_add_iff_left]
convert Submodule.finrank_mono P.corootSpan_dualAnnihilator_le_ker_rootForm
exact (LinearEquiv.finrank_map_eq _ _).symm
lemma isCompl_corootSpan_ker_corootForm :
IsCompl (P.corootSpan R) (LinearMap.ker P.CorootForm) :=
P.flip.isCompl_rootSpan_ker_rootForm
lemma ker_rootForm_eq_dualAnnihilator :
LinearMap.ker P.RootForm = (P.corootSpan R).dualAnnihilator.map P.toDualLeft.symm := by
have _iM : IsReflexive R M := PerfectPairing.reflexive_left P.toPerfectPairing
have _iN : IsReflexive R N := PerfectPairing.reflexive_right P.toPerfectPairing
suffices finrank R (LinearMap.ker P.RootForm) = finrank R (P.corootSpan R).dualAnnihilator by
refine (Submodule.eq_of_le_of_finrank_eq P.corootSpan_dualAnnihilator_le_ker_rootForm ?_).symm
rw [this]
apply LinearEquiv.finrank_map_eq
have aux0 := Subspace.finrank_add_finrank_dualAnnihilator_eq (P.corootSpan R)
have aux1 := Submodule.finrank_add_eq_of_isCompl P.isCompl_rootSpan_ker_rootForm
rw [← P.finrank_corootSpan_eq', P.toPerfectPairing.finrank_eq] at aux1
omega
lemma ker_corootForm_eq_dualAnnihilator :
LinearMap.ker P.CorootForm = (P.rootSpan R).dualAnnihilator.map P.toDualRight.symm :=
P.flip.ker_rootForm_eq_dualAnnihilator
instance : P.IsBalanced where
isPerfectCompl :=
{ isCompl_left := by
simpa only [ker_rootForm_eq_dualAnnihilator] using P.isCompl_rootSpan_ker_rootForm
isCompl_right := by
simpa only [ker_corootForm_eq_dualAnnihilator] using P.isCompl_corootSpan_ker_corootForm }
/-- See also `RootPairing.rootForm_restrict_nondegenerate_of_ordered`.
Note that this applies to crystallographic root systems in characteristic zero via
`RootPairing.instIsAnisotropicOfIsCrystallographic`. -/
lemma rootForm_restrict_nondegenerate_of_isAnisotropic :
LinearMap.Nondegenerate (P.RootForm.restrict (P.rootSpan R)) :=
P.rootForm_symmetric.nondegenerate_restrict_of_isCompl_ker P.isCompl_rootSpan_ker_rootForm
@[simp]
lemma orthogonal_rootSpan_eq :
P.RootForm.orthogonal (P.rootSpan R) = LinearMap.ker P.RootForm := by
rw [← LinearMap.BilinForm.orthogonal_top_eq_ker P.rootForm_symmetric.isRefl]
refine le_antisymm ?_ (by intro; aesop)
rintro x hx y -
simp only [LinearMap.BilinForm.mem_orthogonal_iff, LinearMap.BilinForm.IsOrtho] at hx ⊢
obtain ⟨u, hu, v, hv, rfl⟩ : ∃ᵉ (u ∈ P.rootSpan R) (v ∈ LinearMap.ker P.RootForm), u + v = y := by
rw [← Submodule.mem_sup, P.isCompl_rootSpan_ker_rootForm.sup_eq_top]; exact Submodule.mem_top
simp only [LinearMap.mem_ker] at hv
simp [hx _ hu, hv]
@[simp]
lemma orthogonal_corootSpan_eq :
P.CorootForm.orthogonal (P.corootSpan R) = LinearMap.ker P.CorootForm :=
P.flip.orthogonal_rootSpan_eq
lemma rootSpan_eq_top_iff :
P.rootSpan R = ⊤ ↔ P.corootSpan R = ⊤ := by
have := P.toPerfectPairing.reflexive_left
have := P.toPerfectPairing.reflexive_right
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ <;> apply Submodule.eq_top_of_finrank_eq
· rw [P.finrank_corootSpan_eq', h, finrank_top, P.toPerfectPairing.finrank_eq]
· rw [← P.finrank_corootSpan_eq', h, finrank_top, P.toPerfectPairing.finrank_eq]
end Field
section LinearOrderedCommRing
variable [CommRing R] [LinearOrder R] [IsStrictOrderedRing R]
[Module R M] [Module R N] (P : RootPairing ι R M N)
instance instIsAnisotropicOfLinearOrderedCommRing : IsAnisotropic P :=
P.isAnisotropic_of_isValuedIn R
lemma zero_le_rootForm (x : M) :
0 ≤ P.RootForm x x :=
(P.rootForm_self_sum_of_squares x).nonneg
/-- See also `RootPairing.rootForm_restrict_nondegenerate_of_isAnisotropic`. -/
lemma rootForm_restrict_nondegenerate_of_ordered :
LinearMap.Nondegenerate (P.RootForm.restrict (P.rootSpan R)) :=
(P.RootForm.nondegenerate_restrict_iff_disjoint_ker P.zero_le_rootForm
P.rootForm_symmetric).mpr P.disjoint_rootSpan_ker_rootForm
lemma rootForm_self_eq_zero_iff {x : M} :
P.RootForm x x = 0 ↔ x ∈ LinearMap.ker P.RootForm :=
P.RootForm.apply_apply_same_eq_zero_iff P.zero_le_rootForm P.rootForm_symmetric
lemma eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero {x : M}
(hx : x ∈ P.rootSpan R) (hx' : P.RootForm x x = 0) :
x = 0 := by
have : x ∈ P.rootSpan R ⊓ LinearMap.ker P.RootForm := ⟨hx, P.rootForm_self_eq_zero_iff.mp hx'⟩
simpa [P.disjoint_rootSpan_ker_rootForm.eq_bot] using this
lemma rootForm_pos_of_ne_zero {x : M} (hx : x ∈ P.rootSpan R) (h : x ≠ 0) :
0 < P.RootForm x x := by
apply (P.zero_le_rootForm x).lt_of_ne
contrapose! h
exact P.eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero hx h.symm
lemma _root_.RootSystem.rootForm_anisotropic (P : RootSystem ι R M N) :
P.RootForm.toQuadraticMap.Anisotropic :=
fun x ↦ P.eq_zero_of_mem_rootSpan_of_rootForm_self_eq_zero <| by
simpa only [rootSpan, P.span_root_eq_top] using Submodule.mem_top
end LinearOrderedCommRing
end RootPairing
|
GrothendieckGroup.lean
|
/-
Copyright (c) 2025 Alex J. Best, Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Yaël Dillies
-/
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Grothendieck group
The Grothendieck group of a commutative monoid `M` is the "smallest" commutative group `G`
containing `M`, in the sense that monoid homs `M → H` are in bijection with monoid homs `G → H` for
any commutative group `H`.
Note that "Grothendieck group" also refers to the analogous construction in an abelian category
obtained by formally making the last term of each short exact sequence invertible.
### References
* [*Grothendieck group*, Wikipedia](https://en.wikipedia.org/wiki/Grothendieck_group#Grothendieck_group_of_a_commutative_monoid)
-/
open Function Localization
namespace Algebra
variable {M G : Type*} [CommMonoid M] [CommGroup G]
variable (M) in
/-- The Grothendieck group of a monoid `M` is the localization at its top submonoid. -/
@[to_additive
/-- The Grothendieck group of an additive monoid `M` is the localization at its top submonoid. -/]
abbrev GrothendieckGroup : Type _ := Localization (⊤ : Submonoid M)
namespace GrothendieckGroup
/-- The inclusion from a commutative monoid `M` to its Grothendieck group.
Note that this is only injective if `M` is cancellative. -/
@[to_additive
/-- The inclusion from an additive commutative monoid `M` to its Grothendieck group.
Note that this is only injective if `M` is cancellative. -/]
abbrev of : M →* GrothendieckGroup M := (monoidOf ⊤).toMonoidHom
@[to_additive]
lemma of_injective [IsCancelMul M] : Injective (of (M := M)) :=
fun m₁ m₂ ↦ by simp [of, ← mk_one_eq_monoidOf_mk, mk_eq_mk_iff']
@[to_additive]
instance : Inv (GrothendieckGroup M) where
inv := rec (fun m s ↦ (.mk s ⟨m, Submonoid.mem_top m⟩ : GrothendieckGroup M))
fun {m₁ m₂ s₁ s₂} h ↦ by simpa [r_iff_exists, mk_eq_mk_iff, eq_comm, mul_comm] using h
@[to_additive (attr := simp)]
lemma inv_mk (m : M) (s : (⊤ : Submonoid M)) : (mk m s)⁻¹ = .mk s ⟨m, Submonoid.mem_top _⟩ := rfl
/-- The Grothendieck group is a group. -/
@[to_additive /-- The Grothendieck group is a group. -/]
instance instCommGroup : CommGroup (GrothendieckGroup M) where
__ : CommMonoid (GrothendieckGroup M) := inferInstance
inv_mul_cancel a := by
cases a using ind
rw [inv_mk, mk_eq_monoidOf_mk', ←Submonoid.LocalizationMap.mk'_mul]
convert Submonoid.LocalizationMap.mk'_self' _ _
rw [mul_comm, Submonoid.coe_mul]
@[to_additive (attr := simp)]
lemma mk_div_mk (m₁ m₂ : M) (s₁ s₂ : (⊤ : Submonoid M)) :
mk m₁ s₁ / mk m₂ s₂ = .mk (m₁ * s₂) ⟨s₁ * m₂, Submonoid.mem_top _⟩ := by
simp [div_eq_mul_inv, mk_mul]; rfl
/-- A monoid homomorphism from a monoid `M` to a group `G` lifts to a group homomorphism from the
Grothendieck group of `M` to `G`. -/
@[to_additive (attr := simps symm_apply)
/-- A monoid homomorphism from a monoid `M` to a group `G` lifts to a group homomorphism from the
Grothendieck group of `M` to `G`. -/]
noncomputable def lift : (M →* G) ≃ (GrothendieckGroup M →* G) where
toFun f := (monoidOf ⊤).lift (g := f) fun _ ↦ Group.isUnit _
invFun f := f.comp of
left_inv f := by ext; simp
right_inv f := by ext; simp
@[to_additive]
lemma lift_apply (f : M →* G) (x : GrothendieckGroup M) :
lift f x = f ((monoidOf ⊤).sec x).1 / f ((monoidOf ⊤).sec x).2 := by
simp [lift, (monoidOf ⊤).lift_apply, div_eq_mul_inv]; congr
end Algebra.GrothendieckGroup
|
Representable.lean
|
/-
Copyright (c) 2024 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne, Joël Riou, Ravi Vakil
-/
import Mathlib.CategoryTheory.MorphismProperty.Limits
/-!
# Relatively representable morphisms
In this file we define and develop basic results about relatively representable morphisms.
Classically, a morphism `f : F ⟶ G` of presheaves is said to be representable if for any morphism
`g : yoneda.obj X ⟶ G`, there exists a pullback square of the following form
```
yoneda.obj Y --yoneda.map snd--> yoneda.obj X
| |
fst g
| |
v v
F ------------ f --------------> G
```
In this file, we define a notion of relative representability which works with respect to any
functor, and not just `yoneda`. The fact that a morphism `f : F ⟶ G` between presheaves is
representable in the classical case will then be given by `yoneda.relativelyRepresentable f`.
## Main definitions
Throughout this file, `F : C ⥤ D` is a functor between categories `C` and `D`.
* `Functor.relativelyRepresentable`: A morphism `f : X ⟶ Y` in `D` is said to be relatively
representable with respect to `F`, if for any `g : F.obj a ⟶ Y`, there exists a pullback square
of the following form
```
F.obj b --F.map snd--> F.obj a
| |
fst g
| |
v v
X ------- f --------> Y
```
* `MorphismProperty.relative`: Given a morphism property `P` in `C`, a morphism `f : X ⟶ Y` in `D`
satisfies `P.relative F` if it is relatively representable and for any `g : F.obj a ⟶ Y`, the
property `P` holds for any represented pullback of `f` by `g`.
## API
Given `hf : relativelyRepresentable f`, with `f : X ⟶ Y` and `g : F.obj a ⟶ Y`, we provide:
* `hf.pullback g` which is the object in `C` such that `F.obj (hf.pullback g)` is a
pullback of `f` and `g`.
* `hf.snd g` is the morphism `hf.pullback g ⟶ F.obj a`
* `hf.fst g` is the morphism `F.obj (hf.pullback g) ⟶ X`
* If `F` is full, and `f` is of type `F.obj c ⟶ G`, we also have `hf.fst' g : hf.pullback g ⟶ X`
which is the preimage under `F` of `hf.fst g`.
* `hom_ext`, `hom_ext'`, `lift`, `lift'` are variants of the universal property of
`F.obj (hf.pullback g)`, where as much as possible has been formulated internally to `C`.
For these theorems we also need that `F` is full and/or faithful.
* `symmetry` and `symmetryIso` are variants of the fact that pullbacks are symmetric for
representable morphisms, formulated internally to `C`. We assume that `F` is fully faithful here.
We also provide some basic API for dealing with triple pullbacks, i.e. given
`hf₁ : relativelyRepresentable f₁`, `f₂ : F.obj A₂ ⟶ X` and `f₃ : F.obj A₃ ⟶ X`, we define
`hf₁.pullback₃ f₂ f₃` to be the pullback of `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. We then develop
some API for working with this object, mirroring the usual API for pullbacks, but where as much
as possible is phrased internally to `C`.
## Main results
* `relativelyRepresentable.isMultiplicative`: The class of relatively representable morphisms is
multiplicative.
* `relativelyRepresentable.isStableUnderBaseChange`: Being relatively representable is stable under
base change.
* `relativelyRepresentable.of_isIso`: Isomorphisms are relatively representable.
-/
namespace CategoryTheory
open Category Limits MorphismProperty
universe v₁ v₂ u₁ u₂
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D)
/-- A morphism `f : X ⟶ Y` in `D` is said to be relatively representable if for any
`g : F.obj a ⟶ Y`, there exists a pullback square of the following form
```
F.obj b --F.map snd--> F.obj a
| |
fst g
| |
v v
X ------- f --------> Y
```
-/
def Functor.relativelyRepresentable : MorphismProperty D :=
fun X Y f ↦ ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), ∃ (b : C) (snd : b ⟶ a)
(fst : F.obj b ⟶ X), IsPullback fst (F.map snd) f g
namespace Functor.relativelyRepresentable
section
variable {F}
variable {X Y : D} {f : X ⟶ Y} (hf : F.relativelyRepresentable f)
{b : C} {f' : F.obj b ⟶ Y} (hf' : F.relativelyRepresentable f')
{a : C} (g : F.obj a ⟶ Y) (hg : F.relativelyRepresentable g)
/-- Let `f : X ⟶ Y` be a relatively representable morphism in `D`. Then, for any
`g : F.obj a ⟶ Y`, `hf.pullback g` denotes the (choice of) a corresponding object in `C` such that
there is a pullback square of the following form
```
hf.pullback g --F.map snd--> F.obj a
| |
fst g
| |
v v
X ---------- f ----------> Y
``` -/
noncomputable def pullback : C :=
(hf g).choose
/-- Given a representable morphism `f : X ⟶ Y`, then for any `g : F.obj a ⟶ Y`, `hf.snd g`
denotes the morphism in `C` giving rise to the following diagram
```
hf.pullback g --F.map (hf.snd g)--> F.obj a
| |
fst g
| |
v v
X -------------- f -------------> Y
``` -/
noncomputable abbrev snd : hf.pullback g ⟶ a :=
(hf g).choose_spec.choose
/-- Given a relatively representable morphism `f : X ⟶ Y`, then for any `g : F.obj a ⟶ Y`,
`hf.fst g` denotes the first projection in the following diagram, given by the defining property
of `f` being relatively representable
```
hf.pullback g --F.map (hf.snd g)--> F.obj a
| |
hf.fst g g
| |
v v
X -------------- f -------------> Y
``` -/
noncomputable abbrev fst : F.obj (hf.pullback g) ⟶ X :=
(hf g).choose_spec.choose_spec.choose
/-- When `F` is full, given a representable morphism `f' : F.obj b ⟶ Y`, then `hf'.fst' g` denotes
the preimage of `hf'.fst g` under `F`. -/
noncomputable abbrev fst' [Full F] : hf'.pullback g ⟶ b :=
F.preimage (hf'.fst g)
lemma map_fst' [Full F] : F.map (hf'.fst' g) = hf'.fst g :=
F.map_preimage _
lemma isPullback : IsPullback (hf.fst g) (F.map (hf.snd g)) f g :=
(hf g).choose_spec.choose_spec.choose_spec
@[reassoc]
lemma w : hf.fst g ≫ f = F.map (hf.snd g) ≫ g := (hf.isPullback g).w
/-- Variant of the pullback square when `F` is full, and given `f' : F.obj b ⟶ Y`. -/
lemma isPullback' [Full F] : IsPullback (F.map (hf'.fst' g)) (F.map (hf'.snd g)) f' g :=
(hf'.map_fst' _) ▸ hf'.isPullback g
@[reassoc]
lemma w' {X Y Z : C} {f : X ⟶ Z} (hf : F.relativelyRepresentable (F.map f)) (g : Y ⟶ Z)
[Full F] [Faithful F] : hf.fst' (F.map g) ≫ f = hf.snd (F.map g) ≫ g :=
F.map_injective <| by simp [(hf.w (F.map g))]
lemma isPullback_of_map {X Y Z : C} {f : X ⟶ Z} (hf : F.relativelyRepresentable (F.map f))
(g : Y ⟶ Z) [Full F] [Faithful F] :
IsPullback (hf.fst' (F.map g)) (hf.snd (F.map g)) f g :=
IsPullback.of_map F (hf.w' g) (hf.isPullback' (F.map g))
variable {g}
/-- Two morphisms `a b : c ⟶ hf.pullback g` are equal if
* Their compositions (in `C`) with `hf.snd g : hf.pullback ⟶ X` are equal.
* The compositions of `F.map a` and `F.map b` with `hf.fst g` are equal. -/
@[ext 100]
lemma hom_ext [Faithful F] {c : C} {a b : c ⟶ hf.pullback g}
(h₁ : F.map a ≫ hf.fst g = F.map b ≫ hf.fst g)
(h₂ : a ≫ hf.snd g = b ≫ hf.snd g) : a = b :=
F.map_injective <|
PullbackCone.IsLimit.hom_ext (hf.isPullback g).isLimit h₁ (by simpa using F.congr_map h₂)
/-- In the case of a representable morphism `f' : F.obj Y ⟶ G`, whose codomain lies
in the image of `F`, we get that two morphism `a b : Z ⟶ hf.pullback g` are equal if
* Their compositions (in `C`) with `hf'.snd g : hf.pullback ⟶ X` are equal.
* Their compositions (in `C`) with `hf'.fst' g : hf.pullback ⟶ Y` are equal. -/
@[ext]
lemma hom_ext' [Full F] [Faithful F] {c : C} {a b : c ⟶ hf'.pullback g}
(h₁ : a ≫ hf'.fst' g = b ≫ hf'.fst' g)
(h₂ : a ≫ hf'.snd g = b ≫ hf'.snd g) : a = b :=
hf'.hom_ext (by simpa [map_fst'] using F.congr_map h₁) h₂
section
variable {c : C} (i : F.obj c ⟶ X) (h : c ⟶ a) (hi : i ≫ f = F.map h ≫ g)
/-- The lift (in `C`) obtained from the universal property of `F.obj (hf.pullback g)`, in the
case when the cone point is in the image of `F.obj`. -/
noncomputable def lift [Full F] : c ⟶ hf.pullback g :=
F.preimage <| PullbackCone.IsLimit.lift (hf.isPullback g).isLimit _ _ hi
@[reassoc (attr := simp)]
lemma lift_fst [Full F] : F.map (hf.lift i h hi) ≫ hf.fst g = i := by
simpa [lift] using PullbackCone.IsLimit.lift_fst _ _ _ _
@[reassoc (attr := simp)]
lemma lift_snd [Full F] [Faithful F] : hf.lift i h hi ≫ hf.snd g = h :=
F.map_injective <| by simpa [lift] using PullbackCone.IsLimit.lift_snd _ _ _ _
end
section
variable {c : C} (i : c ⟶ b) (h : c ⟶ a) (hi : F.map i ≫ f' = F.map h ≫ g)
/-- Variant of `lift` in the case when the domain of `f` lies in the image of `F.obj`. Thus,
in this case, one can obtain the lift directly by giving two morphisms in `C`. -/
noncomputable def lift' [Full F] : c ⟶ hf'.pullback g := hf'.lift _ _ hi
@[reassoc (attr := simp)]
lemma lift'_fst [Full F] [Faithful F] : hf'.lift' i h hi ≫ hf'.fst' g = i :=
F.map_injective (by simp [lift'])
@[reassoc (attr := simp)]
lemma lift'_snd [Full F] [Faithful F] : hf'.lift' i h hi ≫ hf'.snd g = h := by
simp [lift']
end
/-- Given two representable morphisms `f' : F.obj b ⟶ Y` and `g : F.obj a ⟶ Y`, we
obtain an isomorphism `hf'.pullback g ⟶ hg.pullback f'`. -/
noncomputable def symmetry [Full F] : hf'.pullback g ⟶ hg.pullback f' :=
hg.lift' (hf'.snd g) (hf'.fst' g) (hf'.isPullback' _).w.symm
@[reassoc (attr := simp)]
lemma symmetry_fst [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.fst' f' = hf'.snd g := by
simp [symmetry]
@[reassoc (attr := simp)]
lemma symmetry_snd [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.snd f' = hf'.fst' g := by
simp [symmetry]
@[reassoc (attr := simp)]
lemma symmetry_symmetry [Full F] [Faithful F] : hf'.symmetry hg ≫ hg.symmetry hf' = 𝟙 _ :=
hom_ext' hf' (by simp) (by simp)
/-- The isomorphism given by `Presheaf.representable.symmetry`. -/
@[simps]
noncomputable def symmetryIso [Full F] [Faithful F] : hf'.pullback g ≅ hg.pullback f' where
hom := hf'.symmetry hg
inv := hg.symmetry hf'
instance [Full F] [Faithful F] : IsIso (hf'.symmetry hg) :=
(hf'.symmetryIso hg).isIso_hom
end
/-- When `C` has pullbacks, then `F.map f` is representable with respect to `F` for any
`f : a ⟶ b` in `C`. -/
lemma map [Full F] [HasPullbacks C] {a b : C} (f : a ⟶ b)
[∀ c (g : c ⟶ b), PreservesLimit (cospan f g) F] :
F.relativelyRepresentable (F.map f) := fun c g ↦ by
obtain ⟨g, rfl⟩ := F.map_surjective g
refine ⟨Limits.pullback f g, Limits.pullback.snd f g, F.map (Limits.pullback.fst f g), ?_⟩
apply F.map_isPullback <| IsPullback.of_hasPullback f g
lemma of_isIso {X Y : D} (f : X ⟶ Y) [IsIso f] : F.relativelyRepresentable f :=
fun a g ↦ ⟨a, 𝟙 a, g ≫ CategoryTheory.inv f, IsPullback.of_vert_isIso ⟨by simp⟩⟩
lemma isomorphisms_le : MorphismProperty.isomorphisms D ≤ F.relativelyRepresentable :=
fun _ _ f hf ↦ letI : IsIso f := hf; of_isIso F f
instance isMultiplicative : IsMultiplicative F.relativelyRepresentable where
id_mem _ := of_isIso F _
comp_mem {F G H} f g hf hg := fun X h ↦
⟨hf.pullback (hg.fst h), hf.snd (hg.fst h) ≫ hg.snd h, hf.fst (hg.fst h),
by simpa using IsPullback.paste_vert (hf.isPullback (hg.fst h)) (hg.isPullback h)⟩
instance isStableUnderBaseChange : IsStableUnderBaseChange F.relativelyRepresentable where
of_isPullback {X Y Y' X' f g f' g'} P₁ hg a h := by
refine ⟨hg.pullback (h ≫ f), hg.snd (h ≫ f), ?_, ?_⟩
· apply P₁.lift (hg.fst (h ≫ f)) (F.map (hg.snd (h ≫ f)) ≫ h) (by simpa using hg.w (h ≫ f))
· apply IsPullback.of_right' (hg.isPullback (h ≫ f)) P₁
instance respectsIso : RespectsIso F.relativelyRepresentable :=
(isStableUnderBaseChange F).respectsIso
end Functor.relativelyRepresentable
namespace MorphismProperty
open Functor.relativelyRepresentable
variable {X Y : D} (P : MorphismProperty C)
/-- Given a morphism property `P` in a category `C`, a functor `F : C ⥤ D` and a morphism
`f : X ⟶ Y` in `D`. Then `f` satisfies the morphism property `P.relative` with respect to `F` iff:
* The morphism is representable with respect to `F`
* For any morphism `g : F.obj a ⟶ Y`, the property `P` holds for any represented pullback of
`f` by `g`. -/
def relative : MorphismProperty D :=
fun X Y f ↦ F.relativelyRepresentable f ∧
∀ ⦃a b : C⦄ (g : F.obj a ⟶ Y) (fst : F.obj b ⟶ X) (snd : b ⟶ a)
(_ : IsPullback fst (F.map snd) f g), P snd
/-- Given a morphism property `P` in a category `C`, a morphism `f : F ⟶ G` of presheaves in the
category `Cᵒᵖ ⥤ Type v` satisfies the morphism property `P.presheaf` iff:
* The morphism is representable.
* For any morphism `g : F.obj a ⟶ G`, the property `P` holds for any represented pullback of
`f` by `g`.
This is implemented as a special case of the more general notion of `P.relative`, to the case when
the functor `F` is `yoneda`. -/
abbrev presheaf : MorphismProperty (Cᵒᵖ ⥤ Type v₁) := P.relative yoneda
variable {P} {F}
/-- A morphism satisfying `P.relative` is representable. -/
lemma relative.rep {f : X ⟶ Y} (hf : P.relative F f) : F.relativelyRepresentable f :=
hf.1
lemma relative.property {f : X ⟶ Y} (hf : P.relative F f) :
∀ ⦃a b : C⦄ (g : F.obj a ⟶ Y) (fst : F.obj b ⟶ X) (snd : b ⟶ a)
(_ : IsPullback fst (F.map snd) f g), P snd :=
hf.2
lemma relative.property_snd {f : X ⟶ Y} (hf : P.relative F f) {a : C} (g : F.obj a ⟶ Y) :
P (hf.rep.snd g) :=
hf.property g _ _ (hf.rep.isPullback g)
/-- Given a morphism property `P` which respects isomorphisms, then to show that a morphism
`f : X ⟶ Y` satisfies `P.relative` it suffices to show that:
* The morphism is representable.
* For any morphism `g : F.obj a ⟶ G`, the property `P` holds for *some* represented pullback
of `f` by `g`. -/
lemma relative.of_exists [F.Faithful] [F.Full] [P.RespectsIso] {f : X ⟶ Y}
(h₀ : ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), ∃ (b : C) (fst : F.obj b ⟶ X) (snd : b ⟶ a)
(_ : IsPullback fst (F.map snd) f g), P snd) : P.relative F f := by
refine ⟨fun a g ↦ ?_, fun a b g fst snd h ↦ ?_⟩
all_goals obtain ⟨c, g_fst, g_snd, BC, H⟩ := h₀ g
· refine ⟨c, g_snd, g_fst, BC⟩
· refine (P.arrow_mk_iso_iff ?_).2 H
exact Arrow.isoMk (F.preimageIso (h.isoIsPullback X (F.obj a) BC)) (Iso.refl _)
(F.map_injective (by simp))
lemma relative_of_snd [F.Faithful] [F.Full] [P.RespectsIso] {f : X ⟶ Y}
(hf : F.relativelyRepresentable f) (h : ∀ ⦃a : C⦄ (g : F.obj a ⟶ Y), P (hf.snd g)) :
P.relative F f :=
relative.of_exists (fun _ g ↦ ⟨hf.pullback g, hf.fst g, hf.snd g, hf.isPullback g, h g⟩)
/-- If `P : MorphismProperty C` is stable under base change, `F` is fully faithful and preserves
pullbacks, and `C` has all pullbacks, then for any `f : a ⟶ b` in `C`, `F.map f` satisfies
`P.relative` if `f` satisfies `P`. -/
lemma relative_map [F.Faithful] [F.Full] [HasPullbacks C] [IsStableUnderBaseChange P]
{a b : C} {f : a ⟶ b} [∀ c (g : c ⟶ b), PreservesLimit (cospan f g) F]
(hf : P f) : P.relative F (F.map f) := by
apply relative.of_exists
intro Y' g
obtain ⟨g, rfl⟩ := F.map_surjective g
exact ⟨_, _, _, (IsPullback.of_hasPullback f g).map F, P.pullback_snd _ _ hf⟩
lemma of_relative_map {a b : C} {f : a ⟶ b} (hf : P.relative F (F.map f)) : P f :=
hf.property (𝟙 _) (𝟙 _) f (IsPullback.id_horiz (F.map f))
lemma relative_map_iff [F.Faithful] [F.Full] [PreservesLimitsOfShape WalkingCospan F]
[HasPullbacks C] [IsStableUnderBaseChange P] {X Y : C} {f : X ⟶ Y} :
P.relative F (F.map f) ↔ P f :=
⟨fun hf ↦ of_relative_map hf, fun hf ↦ relative_map hf⟩
/-- If `P' : MorphismProperty C` is satisfied whenever `P` is, then also `P'.relative` is
satisfied whenever `P.relative` is. -/
lemma relative_monotone {P' : MorphismProperty C} (h : P ≤ P') :
P.relative F ≤ P'.relative F := fun _ _ _ hf ↦
⟨hf.rep, fun _ _ g fst snd BC ↦ h _ (hf.property g fst snd BC)⟩
section
variable (P)
lemma relative_isStableUnderBaseChange : IsStableUnderBaseChange (P.relative F) where
of_isPullback hfBC hg :=
⟨of_isPullback hfBC hg.rep,
fun _ _ _ _ _ BC ↦ hg.property _ _ _ (IsPullback.paste_horiz BC hfBC)⟩
instance relative_isStableUnderComposition [F.Faithful] [F.Full] [P.IsStableUnderComposition] :
IsStableUnderComposition (P.relative F) where
comp_mem {F G H} f g hf hg := by
refine ⟨comp_mem _ _ _ hf.1 hg.1, fun Z X p fst snd h ↦ ?_⟩
rw [← hg.1.lift_snd (fst ≫ f) snd (by simpa using h.w)]
refine comp_mem _ _ _ (hf.property (hg.1.fst p) fst _
(IsPullback.of_bot ?_ ?_ (hg.1.isPullback p))) (hg.property_snd p)
· rw [← Functor.map_comp, lift_snd]
exact h
· symm
apply hg.1.lift_fst
instance relative_respectsIso : RespectsIso (P.relative F) :=
(relative_isStableUnderBaseChange P).respectsIso
instance relative_isMultiplicative [F.Faithful] [F.Full] [P.IsMultiplicative] [P.RespectsIso] :
IsMultiplicative (P.relative F) where
id_mem X := relative.of_exists
(fun Y g ↦ ⟨Y, g, 𝟙 Y, by simpa using IsPullback.of_id_snd, id_mem _ _⟩)
end
section
-- TODO(Calle): This could be generalized to functors whose image forms a separating family.
/-- Morphisms satisfying `(monomorphism C).presheaf` are in particular monomorphisms. -/
lemma presheaf_monomorphisms_le_monomorphisms :
(monomorphisms C).presheaf ≤ monomorphisms _ := fun F G f hf ↦ by
suffices ∀ {X : C} {a b : yoneda.obj X ⟶ F}, a ≫ f = b ≫ f → a = b from
⟨fun _ _ h ↦ hom_ext_yoneda (fun _ _ ↦ this (by simp only [assoc, h]))⟩
intro X a b h
/- It suffices to show that the lifts of `a` and `b` to morphisms
`X ⟶ hf.rep.pullback g` are equal, where `g = a ≫ f = a ≫ f`. -/
suffices hf.rep.lift (g := a ≫ f) a (𝟙 X) (by simp) =
hf.rep.lift b (𝟙 X) (by simp [← h]) by
simpa using yoneda.congr_map this =≫ (hf.rep.fst (a ≫ f))
-- This follows from the fact that the induced maps `hf.rep.pullback g ⟶ X` are mono.
have : Mono (hf.rep.snd (a ≫ f)) := hf.property_snd (a ≫ f)
simp only [← cancel_mono (hf.rep.snd (a ≫ f)), lift_snd]
variable {G : Cᵒᵖ ⥤ Type v₁}
lemma presheaf_mono_of_le (hP : P ≤ MorphismProperty.monomorphisms C)
{X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : Mono f :=
MorphismProperty.presheaf_monomorphisms_le_monomorphisms _
(MorphismProperty.relative_monotone hP _ hf)
lemma fst'_self_eq_snd (hP : P ≤ MorphismProperty.monomorphisms C)
{X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : hf.rep.fst' f = hf.rep.snd f := by
have := P.presheaf_mono_of_le hP hf
apply yoneda.map_injective
rw [← cancel_mono f, (hf.rep.isPullback' f).w]
lemma isIso_fst'_self (hP : P ≤ MorphismProperty.monomorphisms C)
{X : C} {f : yoneda.obj X ⟶ G} (hf : P.presheaf f) : IsIso (hf.rep.fst' f) :=
have := P.presheaf_mono_of_le hP hf
have := (hf.rep.isPullback' f).isIso_fst_of_mono
Yoneda.fullyFaithful.isIso_of_isIso_map _
end
end MorphismProperty
namespace Functor.relativelyRepresentable
section Pullbacks₃
/-
In this section we develop some basic API that help deal with certain triple pullbacks obtained
from morphism `f₁ : F.obj A₁ ⟶ X` which is relatively representable with respect to some functor
`F : C ⥤ D`.
More precisely, given two objects `A₂` and `A₃` in `C`, and two morphisms `f₂ : A₂ ⟶ X` and
`f₃ : A₃ ⟶ X`, we can consider the pullbacks (in `D`) `(A₁ ×_X A₂)` and `(A₁ ×_X A₃)`
(which makes sense as objects in `C` due to `F` being relatively representable).
We can then consider the pullback, in `C`, of these two pullbacks. This is the object
`(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. In this section we develop some basic API for dealing with this
pullback. This is used in `Mathlib/AlgebraicGeometry/Sites/Representability.lean` to show that
representability is Zariski-local.
-/
variable {F : C ⥤ D} [Full F] {A₁ A₂ A₃ : C} {X : D}
{f₁ : F.obj A₁ ⟶ X} (hf₁ : F.relativelyRepresentable f₁)
(f₂ : F.obj A₂ ⟶ X) (f₃ : F.obj A₃ ⟶ X)
[HasPullback (hf₁.fst' f₂) (hf₁.fst' f₃)]
/-- The pullback `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. -/
noncomputable def pullback₃ := Limits.pullback (hf₁.fst' f₂) (hf₁.fst' f₃)
/-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₁`. -/
noncomputable def pullback₃.p₁ : hf₁.pullback₃ f₂ f₃ ⟶ A₁ := pullback.fst _ _ ≫ hf₁.fst' f₂
/-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₂`. -/
noncomputable def pullback₃.p₂ : hf₁.pullback₃ f₂ f₃ ⟶ A₂ := pullback.fst _ _ ≫ hf₁.snd f₂
/-- The morphism `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ A₃`. -/
noncomputable def pullback₃.p₃ : hf₁.pullback₃ f₂ f₃ ⟶ A₃ := pullback.snd _ _ ≫ hf₁.snd f₃
/-- The morphism `F.obj (A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃) ⟶ X`. -/
noncomputable def pullback₃.π : F.obj (pullback₃ hf₁ f₂ f₃) ⟶ X :=
F.map (p₁ hf₁ f₂ f₃) ≫ f₁
@[reassoc (attr := simp)]
lemma pullback₃.map_p₁_comp : F.map (p₁ hf₁ f₂ f₃) ≫ f₁ = π _ _ _ :=
rfl
@[reassoc (attr := simp)]
lemma pullback₃.map_p₂_comp : F.map (p₂ hf₁ f₂ f₃) ≫ f₂ = π _ _ _ := by
simp [π, p₁, p₂, ← hf₁.w f₂]
@[reassoc (attr := simp)]
lemma pullback₃.map_p₃_comp : F.map (p₃ hf₁ f₂ f₃) ≫ f₃ = π _ _ _ := by
simp [π, p₁, p₃, ← hf₁.w f₃, pullback.condition]
section
variable [Faithful F] {Z : C} (x₁ : Z ⟶ A₁) (x₂ : Z ⟶ A₂) (x₃ : Z ⟶ A₃)
(h₁₂ : F.map x₁ ≫ f₁ = F.map x₂ ≫ f₂)
(h₁₃ : F.map x₁ ≫ f₁ = F.map x₃ ≫ f₃)
/-- The lift obtained from the universal property of `(A₁ ×_X A₂) ×_{A₁} (A₁ ×_X A₃)`. -/
noncomputable def lift₃ : Z ⟶ pullback₃ hf₁ f₂ f₃ :=
pullback.lift (hf₁.lift' x₁ x₂ h₁₂)
(hf₁.lift' x₁ x₃ h₁₃) (by simp)
@[reassoc (attr := simp)]
lemma lift₃_p₁ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₁ hf₁ f₂ f₃ = x₁ := by
simp [lift₃, pullback₃.p₁]
@[reassoc (attr := simp)]
lemma lift₃_p₂ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₂ hf₁ f₂ f₃ = x₂ := by
simp [lift₃, pullback₃.p₂]
@[reassoc (attr := simp)]
lemma lift₃_p₃ : hf₁.lift₃ f₂ f₃ x₁ x₂ x₃ h₁₂ h₁₃ ≫ pullback₃.p₃ hf₁ f₂ f₃ = x₃ := by
simp [lift₃, pullback₃.p₃]
end
@[reassoc (attr := simp)]
lemma pullback₃.fst_fst'_eq_p₁ : pullback.fst _ _ ≫ hf₁.fst' f₂ = pullback₃.p₁ hf₁ f₂ f₃ := rfl
@[reassoc (attr := simp)]
lemma pullback₃.fst_snd_eq_p₂ : pullback.fst _ _ ≫ hf₁.snd f₂ = pullback₃.p₂ hf₁ f₂ f₃ := rfl
@[reassoc (attr := simp)]
lemma pullback₃.snd_snd_eq_p₃ : pullback.snd _ _ ≫ hf₁.snd f₃ = pullback₃.p₃ hf₁ f₂ f₃ := rfl
@[reassoc (attr := simp)]
lemma pullback₃.snd_fst'_eq_p₁ :
pullback.snd (hf₁.fst' f₂) (hf₁.fst' f₃) ≫ hf₁.fst' f₃ = pullback₃.p₁ hf₁ f₂ f₃ :=
pullback.condition.symm
variable {hf₁ f₂ f₃} in
@[ext]
lemma pullback₃.hom_ext [Faithful F] {Z : C} {φ φ' : Z ⟶ pullback₃ hf₁ f₂ f₃}
(h₁ : φ ≫ pullback₃.p₁ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₁ hf₁ f₂ f₃)
(h₂ : φ ≫ pullback₃.p₂ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₂ hf₁ f₂ f₃)
(h₃ : φ ≫ pullback₃.p₃ hf₁ f₂ f₃ = φ' ≫ pullback₃.p₃ hf₁ f₂ f₃) : φ = φ' := by
apply pullback.hom_ext <;> ext <;> simpa
end Pullbacks₃
end Functor.relativelyRepresentable
end CategoryTheory
|
cyclotomic.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 path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
cyclotomic.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 path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
Basic.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen,
Frédéric Dupuis, Heather Macbeth
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Action.Basic
import Mathlib.Algebra.GroupWithZero.Action.Units
import Mathlib.Algebra.Module.Equiv.Defs
import Mathlib.Algebra.Module.Hom
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.Algebra.Module.LinearMap.End
import Mathlib.Algebra.Module.Pi
import Mathlib.Algebra.Module.Prod
/-!
# Further results on (semi)linear equivalences.
-/
open Function
variable {R : Type*} {R₂ : Type*}
variable {K : Type*} {S : Type*} {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
section AddCommMonoid
namespace LinearEquiv
variable [Semiring R] [Semiring S] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂]
section RestrictScalars
variable (R)
variable [Module R M] [Module R M₂] [Module S M] [Module S M₂]
[LinearMap.CompatibleSMul M M₂ R S]
/-- If `M` and `M₂` are both `R`-semimodules and `S`-semimodules and `R`-semimodule structures
are defined by an action of `R` on `S` (formally, we have two scalar towers), then any `S`-linear
equivalence from `M` to `M₂` is also an `R`-linear equivalence.
See also `LinearMap.restrictScalars`. -/
@[simps]
def restrictScalars (f : M ≃ₗ[S] M₂) : M ≃ₗ[R] M₂ :=
{ f.toLinearMap.restrictScalars R with
toFun := f
invFun := f.symm
left_inv := f.left_inv
right_inv := f.right_inv }
theorem restrictScalars_injective :
Function.Injective (restrictScalars R : (M ≃ₗ[S] M₂) → M ≃ₗ[R] M₂) := fun _ _ h ↦
ext (LinearEquiv.congr_fun h :)
@[simp]
theorem restrictScalars_inj (f g : M ≃ₗ[S] M₂) :
f.restrictScalars R = g.restrictScalars R ↔ f = g :=
(restrictScalars_injective R).eq_iff
end RestrictScalars
theorem _root_.Module.End.isUnit_iff [Module R M] (f : Module.End R M) :
IsUnit f ↔ Function.Bijective f :=
⟨fun h ↦
Function.bijective_iff_has_inverse.mpr <|
⟨h.unit.inv,
⟨Module.End.isUnit_inv_apply_apply_of_isUnit h,
Module.End.isUnit_apply_inv_apply_of_isUnit h⟩⟩,
fun H ↦
let e : M ≃ₗ[R] M := { f, Equiv.ofBijective f H with }
⟨⟨_, e.symm, LinearMap.ext e.right_inv, LinearMap.ext e.left_inv⟩, rfl⟩⟩
@[deprecated (since := "2025-04-28")]
alias _root_.Module.End_isUnit_iff := _root_.Module.End.isUnit_iff
section Automorphisms
variable [Module R M]
instance automorphismGroup : Group (M ≃ₗ[R] M) where
mul f g := g.trans f
one := LinearEquiv.refl R M
inv f := f.symm
mul_assoc _ _ _ := rfl
mul_one _ := ext fun _ ↦ rfl
one_mul _ := ext fun _ ↦ rfl
inv_mul_cancel f := ext <| f.left_inv
lemma one_eq_refl : (1 : M ≃ₗ[R] M) = refl R M := rfl
lemma mul_eq_trans (f g : M ≃ₗ[R] M) : f * g = g.trans f := rfl
@[simp]
lemma coe_one : ↑(1 : M ≃ₗ[R] M) = id := rfl
@[simp]
lemma coe_toLinearMap_one : (↑(1 : M ≃ₗ[R] M) : M →ₗ[R] M) = LinearMap.id := rfl
@[simp]
lemma coe_toLinearMap_mul {e₁ e₂ : M ≃ₗ[R] M} :
(↑(e₁ * e₂) : M →ₗ[R] M) = (e₁ : M →ₗ[R] M) * (e₂ : M →ₗ[R] M) :=
rfl
theorem coe_pow (e : M ≃ₗ[R] M) (n : ℕ) : ⇑(e ^ n) = e^[n] := hom_coe_pow _ rfl (fun _ _ ↦ rfl) _ _
theorem pow_apply (e : M ≃ₗ[R] M) (n : ℕ) (m : M) : (e ^ n) m = e^[n] m := congr_fun (coe_pow e n) m
@[simp] lemma mul_apply (f : M ≃ₗ[R] M) (g : M ≃ₗ[R] M) (x : M) : (f * g) x = f (g x) := rfl
/-- Restriction from `R`-linear automorphisms of `M` to `R`-linear endomorphisms of `M`,
promoted to a monoid hom. -/
@[simps]
def automorphismGroup.toLinearMapMonoidHom : (M ≃ₗ[R] M) →* M →ₗ[R] M where
toFun e := e.toLinearMap
map_one' := rfl
map_mul' _ _ := rfl
/-- The tautological action by `M ≃ₗ[R] M` on `M`.
This generalizes `Function.End.applyMulAction`. -/
instance applyDistribMulAction : DistribMulAction (M ≃ₗ[R] M) M where
smul := (· <| ·)
smul_zero := LinearEquiv.map_zero
smul_add := LinearEquiv.map_add
one_smul _ := rfl
mul_smul _ _ _ := rfl
@[simp]
protected theorem smul_def (f : M ≃ₗ[R] M) (a : M) : f • a = f a :=
rfl
/-- `LinearEquiv.applyDistribMulAction` is faithful. -/
instance apply_faithfulSMul : FaithfulSMul (M ≃ₗ[R] M) M :=
⟨LinearEquiv.ext⟩
instance apply_smulCommClass [SMul S R] [SMul S M] [IsScalarTower S R M] :
SMulCommClass S (M ≃ₗ[R] M) M where
smul_comm r e m := (e.map_smul_of_tower r m).symm
instance apply_smulCommClass' [SMul S R] [SMul S M] [IsScalarTower S R M] :
SMulCommClass (M ≃ₗ[R] M) S M :=
SMulCommClass.symm _ _ _
end Automorphisms
section OfSubsingleton
variable (M M₂)
variable [Module R M] [Module R M₂] [Subsingleton M] [Subsingleton M₂]
/-- Any two modules that are subsingletons are isomorphic. -/
@[simps]
def ofSubsingleton : M ≃ₗ[R] M₂ :=
{ (0 : M →ₗ[R] M₂) with
toFun := fun _ ↦ 0
invFun := fun _ ↦ 0
left_inv := fun _ ↦ Subsingleton.elim _ _
right_inv := fun _ ↦ Subsingleton.elim _ _ }
@[simp]
theorem ofSubsingleton_self : ofSubsingleton M M = refl R M := by
ext
simp [eq_iff_true_of_subsingleton]
end OfSubsingleton
end LinearEquiv
namespace Module
/-- `g : R ≃+* S` is `R`-linear when the module structure on `S` is `Module.compHom S g` . -/
@[simps]
def compHom.toLinearEquiv {R S : Type*} [Semiring R] [Semiring S] (g : R ≃+* S) :
haveI := compHom S (↑g : R →+* S)
R ≃ₗ[R] S :=
letI := compHom S (↑g : R →+* S)
{ g with
toFun := (g : R → S)
invFun := (g.symm : S → R)
map_smul' := g.map_mul }
end Module
namespace DistribMulAction
variable (R M) [Semiring R] [AddCommMonoid M] [Module R M]
variable [Group S] [DistribMulAction S M] [SMulCommClass S R M]
/-- Each element of the group defines a linear equivalence.
This is a stronger version of `DistribMulAction.toAddEquiv`. -/
@[simps!]
def toLinearEquiv (s : S) : M ≃ₗ[R] M :=
{ toAddEquiv M s, toLinearMap R M s with }
/-- Each element of the group defines a module automorphism.
This is a stronger version of `DistribMulAction.toAddAut`. -/
@[simps]
def toModuleAut : S →* M ≃ₗ[R] M where
toFun := toLinearEquiv R M
map_one' := LinearEquiv.ext <| one_smul _
map_mul' _ _ := LinearEquiv.ext <| mul_smul _ _
end DistribMulAction
namespace AddEquiv
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R M₂]
variable (e : M ≃+ M₂)
/-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/
def toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : M ≃ₗ[R] M₂ :=
{ e with map_smul' := h }
@[simp]
theorem coe_toLinearEquiv (h : ∀ (c : R) (x), e (c • x) = c • e x) : ⇑(e.toLinearEquiv h) = e :=
rfl
@[simp]
theorem coe_toLinearEquiv_symm (h : ∀ (c : R) (x), e (c • x) = c • e x) :
⇑(e.toLinearEquiv h).symm = e.symm :=
rfl
/-- An additive equivalence between commutative additive monoids is a linear equivalence between
ℕ-modules -/
def toNatLinearEquiv : M ≃ₗ[ℕ] M₂ :=
e.toLinearEquiv fun c a ↦ by rw [map_nsmul]
@[simp]
theorem coe_toNatLinearEquiv : ⇑e.toNatLinearEquiv = e :=
rfl
@[simp]
theorem coe_symm_toNatLinearEquiv : ⇑e.toNatLinearEquiv.symm = e.symm :=
rfl
@[simp]
theorem toNatLinearEquiv_toAddEquiv : ↑e.toNatLinearEquiv = e :=
rfl
@[simp]
theorem _root_.LinearEquiv.toAddEquiv_toNatLinearEquiv (e : M ≃ₗ[ℕ] M₂) :
AddEquiv.toNatLinearEquiv ↑e = e :=
DFunLike.coe_injective rfl
@[simp]
theorem toNatLinearEquiv_symm : e.symm.toNatLinearEquiv = e.toNatLinearEquiv.symm :=
rfl
@[simp]
theorem toNatLinearEquiv_refl : (AddEquiv.refl M).toNatLinearEquiv = LinearEquiv.refl ℕ M :=
rfl
@[simp]
theorem toNatLinearEquiv_trans (e₂ : M₂ ≃+ M₃) :
(e.trans e₂).toNatLinearEquiv = e.toNatLinearEquiv.trans e₂.toNatLinearEquiv :=
rfl
end AddCommMonoid
section AddCommGroup
variable [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
variable (e : M ≃+ M₂)
/-- An additive equivalence between commutative additive groups is a linear
equivalence between ℤ-modules -/
def toIntLinearEquiv : M ≃ₗ[ℤ] M₂ :=
e.toLinearEquiv fun c a ↦ e.toAddMonoidHom.map_zsmul a c
@[simp]
theorem coe_toIntLinearEquiv : ⇑e.toIntLinearEquiv = e :=
rfl
@[simp]
theorem coe_symm_toIntLinearEquiv : ⇑e.toIntLinearEquiv.symm = e.symm :=
rfl
@[simp]
theorem toIntLinearEquiv_toAddEquiv : ↑e.toIntLinearEquiv = e := by
ext
rfl
@[simp]
theorem _root_.LinearEquiv.toAddEquiv_toIntLinearEquiv (e : M ≃ₗ[ℤ] M₂) :
AddEquiv.toIntLinearEquiv (e : M ≃+ M₂) = e :=
DFunLike.coe_injective rfl
@[simp]
theorem toIntLinearEquiv_symm : e.symm.toIntLinearEquiv = e.toIntLinearEquiv.symm :=
rfl
@[simp]
theorem toIntLinearEquiv_refl : (AddEquiv.refl M).toIntLinearEquiv = LinearEquiv.refl ℤ M :=
rfl
@[simp]
theorem toIntLinearEquiv_trans (e₂ : M₂ ≃+ M₃) :
(e.trans e₂).toIntLinearEquiv = e.toIntLinearEquiv.trans e₂.toIntLinearEquiv :=
rfl
end AddCommGroup
end AddEquiv
namespace LinearMap
variable (R S M)
variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M]
/-- The equivalence between R-linear maps from `R` to `M`, and points of `M` itself.
This says that the forgetful functor from `R`-modules to types is representable, by `R`.
This is an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`.
When `R` is commutative, we can take this to be the usual action with `S = R`.
Otherwise, `S = ℕ` shows that the equivalence is additive.
See note [bundled maps over different rings].
-/
@[simps]
def ringLmapEquivSelf [Module S M] [SMulCommClass R S M] : (R →ₗ[R] M) ≃ₗ[S] M :=
{ applyₗ' S (1 : R) with
toFun := fun f ↦ f 1
invFun := smulRight (1 : R →ₗ[R] R)
left_inv := fun f ↦ by
ext
simp only [coe_smulRight, Module.End.one_apply, smul_eq_mul, ← map_smul f, mul_one]
right_inv := fun x ↦ by simp }
end LinearMap
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℕ`-linear morphisms `A →ₗ[ℕ] B`.
-/
@[simps]
def addMonoidHomLequivNat {A B : Type*} (R : Type*) [Semiring R] [AddCommMonoid A]
[AddCommMonoid B] [Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℕ] B where
toFun := AddMonoidHom.toNatLinearMap
invFun := LinearMap.toAddMonoidHom
map_add' _ _ := rfl
map_smul' _ _ := rfl
/--
The `R`-linear equivalence between additive morphisms `A →+ B` and `ℤ`-linear morphisms `A →ₗ[ℤ] B`.
-/
@[simps]
def addMonoidHomLequivInt {A B : Type*} (R : Type*) [Semiring R] [AddCommGroup A] [AddCommGroup B]
[Module R B] : (A →+ B) ≃ₗ[R] A →ₗ[ℤ] B where
toFun := AddMonoidHom.toIntLinearMap
invFun := LinearMap.toAddMonoidHom
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- Ring equivalence between additive group endomorphisms of an `AddCommGroup` `A` and
`ℤ`-module endomorphisms of `A.` -/
@[simps] def addMonoidEndRingEquivInt (A : Type*) [AddCommGroup A] :
AddMonoid.End A ≃+* Module.End ℤ A :=
{ addMonoidHomLequivInt (B := A) ℤ with
map_mul' := fun _ _ ↦ rfl }
namespace LinearEquiv
section AddCommMonoid
section Subsingleton
variable [Semiring R] [Semiring R₂]
variable [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R₂ M₂]
variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
section Module
variable [Subsingleton M] [Subsingleton M₂]
/-- Between two zero modules, the zero map is an equivalence. -/
instance : Zero (M ≃ₛₗ[σ₁₂] M₂) :=
⟨{ (0 : M →ₛₗ[σ₁₂] M₂) with
toFun := 0
invFun := 0
right_inv := Subsingleton.elim _
left_inv := Subsingleton.elim _ }⟩
-- Even though these are implied by `Subsingleton.elim` via the `Unique` instance below, they're
-- nice to have as `rfl`-lemmas for `dsimp`.
@[simp]
theorem zero_symm : (0 : M ≃ₛₗ[σ₁₂] M₂).symm = 0 :=
rfl
@[simp]
theorem coe_zero : ⇑(0 : M ≃ₛₗ[σ₁₂] M₂) = 0 :=
rfl
theorem zero_apply (x : M) : (0 : M ≃ₛₗ[σ₁₂] M₂) x = 0 :=
rfl
/-- Between two zero modules, the zero map is the only equivalence. -/
instance : Unique (M ≃ₛₗ[σ₁₂] M₂) where
uniq _ := toLinearMap_injective (Subsingleton.elim _ _)
default := 0
end Module
instance uniqueOfSubsingleton [Subsingleton R] [Subsingleton R₂] : Unique (M ≃ₛₗ[σ₁₂] M₂) := by
haveI := Module.subsingleton R M
haveI := Module.subsingleton R₂ M₂
infer_instance
end Subsingleton
section Uncurry
variable [Semiring R]
variable [AddCommMonoid M] [Module R M]
variable (V V₂ R M)
/-- Linear equivalence between a curried and uncurried function.
Differs from `TensorProduct.curry`. -/
protected def curry : (V × V₂ → M) ≃ₗ[R] V → V₂ → M :=
{ Equiv.curry _ _ _ with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl }
@[simp]
theorem coe_curry : ⇑(LinearEquiv.curry R M V V₂) = curry :=
rfl
@[simp]
theorem coe_curry_symm : ⇑(LinearEquiv.curry R M V V₂).symm = uncurry :=
rfl
end Uncurry
section
variable [Semiring R] [Semiring R₂]
variable [AddCommMonoid M] [AddCommMonoid M₂]
variable {module_M : Module R M} {module_M₂ : Module R₂ M₂}
variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂}
variable (f : M →ₛₗ[σ₁₂] M₂) (g : M₂ →ₛₗ[σ₂₁] M)
/-- If a linear map has an inverse, it is a linear equivalence. -/
def ofLinear (h₁ : f.comp g = LinearMap.id) (h₂ : g.comp f = LinearMap.id) : M ≃ₛₗ[σ₁₂] M₂ :=
{ f with
invFun := g
left_inv := LinearMap.ext_iff.1 h₂
right_inv := LinearMap.ext_iff.1 h₁ }
@[simp]
theorem ofLinear_apply {h₁ h₂} (x : M) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) x = f x :=
rfl
@[simp]
theorem ofLinear_symm_apply {h₁ h₂} (x : M₂) : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm x = g x :=
rfl
@[simp]
theorem ofLinear_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂) = f := rfl
@[simp]
theorem ofLinear_symm_toLinearMap {h₁ h₂} : (ofLinear f g h₁ h₂ : M ≃ₛₗ[σ₁₂] M₂).symm = g := rfl
end
end AddCommMonoid
section Neg
variable (R) [Semiring R] [AddCommGroup M] [Module R M]
/-- `x ↦ -x` as a `LinearEquiv` -/
def neg : M ≃ₗ[R] M :=
{ Equiv.neg M, (-LinearMap.id : M →ₗ[R] M) with }
variable {R}
@[simp]
theorem coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id :=
rfl
theorem neg_apply (x : M) : neg R x = -x := by simp
@[simp]
theorem symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R :=
rfl
end Neg
section Semiring
open LinearMap
section Semilinear
variable {R₁ R₂ R₁' R₂' : Type*} {M₁ M₂ M₁' M₂' : Type*}
variable [Semiring R₁] [Semiring R₂] [Semiring R₁'] [Semiring R₂']
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₁'] [AddCommMonoid M₂']
variable [Module R₁ M₁] [Module R₂ M₂] [Module R₁' M₁'] [Module R₂' M₂']
variable {σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} {σ₁'₂' : R₁' →+* R₂'} {σ₂'₁' : R₂' →+* R₁'}
variable {σ₁₁' : R₁ →+* R₁'} {σ₂₂' : R₂ →+* R₂'}
variable {σ₂₁' : R₂ →+* R₁'} {σ₁₂' : R₁ →+* R₂'}
variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
variable [RingHomInvPair σ₁'₂' σ₂'₁'] [RingHomInvPair σ₂'₁' σ₁'₂']
variable [RingHomCompTriple σ₁₁' σ₁'₂' σ₁₂'] [RingHomCompTriple σ₂₁ σ₁₂' σ₂₂']
variable [RingHomCompTriple σ₂₂' σ₂'₁' σ₂₁'] [RingHomCompTriple σ₁₂ σ₂₁' σ₁₁']
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives an
additive isomorphism between the two function spaces.
See also `LinearEquiv.arrowCongr` for the linear version of this isomorphism. -/
@[simps] def arrowCongrAddEquiv (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') :
(M₁ →ₛₗ[σ₁₁'] M₁') ≃+ (M₂ →ₛₗ[σ₂₂'] M₂') where
toFun f := (e₂.comp f).comp e₁.symm.toLinearMap
invFun f := (e₂.symm.comp f).comp e₁.toLinearMap
left_inv f := by
ext x
simp only [symm_apply_apply, Function.comp_apply, coe_comp, coe_coe]
right_inv f := by
ext x
simp only [Function.comp_apply, apply_symm_apply, coe_comp, coe_coe]
map_add' f g := by
ext x
simp only [map_add, add_apply, Function.comp_apply, coe_comp, coe_coe]
/-- If `M` and `M₂` are linearly isomorphic then the endomorphism rings of `M` and `M₂`
are isomorphic.
See `LinearEquiv.conj` for the linear version of this isomorphism. -/
@[simps!] def conjRingEquiv (e : M₁ ≃ₛₗ[σ₁₂] M₂) : Module.End R₁ M₁ ≃+* Module.End R₂ M₂ where
__ := arrowCongrAddEquiv e e
map_mul' _ _ := by ext; simp [arrowCongrAddEquiv]
/-- A linear isomorphism between the domains an codomains of two spaces of linear maps gives a
linear isomorphism with respect to an action on the domains. -/
@[simps] def domMulActCongrRight [Semiring S] [Module S M₁]
[SMulCommClass R₁ S M₁] [RingHomCompTriple σ₁₂' σ₂'₁' σ₁₁']
(e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') : (M₁ →ₛₗ[σ₁₁'] M₁') ≃ₗ[Sᵈᵐᵃ] (M₁ →ₛₗ[σ₁₂'] M₂') where
__ := arrowCongrAddEquiv (.refl ..) e₂
map_smul' := DomMulAct.mk.forall_congr_right.mp fun _ _ ↦ by ext; simp
end Semilinear
end Semiring
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R M₂] [Module R M₃]
open LinearMap
/-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/
def smulOfUnit (a : Rˣ) : M ≃ₗ[R] M :=
DistribMulAction.toLinearEquiv R M a
section arrowCongr
-- Difference from above: `R₁` and `R₂` are commutative
/-!
The modules for `arrowCongr` and its lemmas below are related via the semilinearities
```
M₁ ←⎯⎯⎯σ₁₂⎯⎯⎯→ M₂ ←⎯⎯⎯σ₂₃⎯⎯⎯→ M₃
⏐ ⏐ ⏐
σ₁₁' σ₂₂' σ₃₃'
↓ ↓ ↓
M₁' ←⎯⎯σ₁'₂'⎯⎯→ M₂' ←⎯⎯σ₂'₃'⎯⎯→ M₃
⏐ ⏐
σ₁'₁'' σ₂'₂''
↓ ↓
M₁''←⎯σ₁''₂''⎯→ M₂''
```
where the horizontal direction corresponds to the `≃ₛₗ`s, and is needed for `arrowCongr_trans`,
while the vertical direction corresponds to the `→ₛₗ`s, and is needed `arrowCongr_comp`.
`Rᵢ` is not necessarily commutative, but `Rᵢ'` and `Rᵢ''` are.
-/
variable {R₁ R₂ R₃ R₁' R₂' R₃' R₁'' R₂'' : Type*} {M₁ M₂ M₃ M₁' M₂' M₃' M₁'' M₂'' : Type*}
variable [Semiring R₁] [Semiring R₂] [Semiring R₃]
variable [CommSemiring R₁'] [CommSemiring R₂'] [CommSemiring R₃']
variable [CommSemiring R₁''] [CommSemiring R₂'']
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [AddCommMonoid M₁'] [AddCommMonoid M₂'] [AddCommMonoid M₃']
variable [AddCommMonoid M₁''] [AddCommMonoid M₂'']
variable [Module R₁ M₁] [Module R₂ M₂] [Module R₃ M₃]
variable [Module R₁' M₁'] [Module R₂' M₂'] [Module R₃' M₃']
variable [Module R₁'' M₁''] [Module R₂'' M₂'']
-- horizontal edges and closures
variable {σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁}
variable {σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂}
variable {σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁}
variable {σ₁'₂' : R₁' →+* R₂'} {σ₂'₁' : R₂' →+* R₁'}
variable {σ₂'₃' : R₂' →+* R₃'} {σ₃'₂' : R₃' →+* R₂'}
variable {σ₁'₃' : R₁' →+* R₃'} {σ₃'₁' : R₃' →+* R₁'}
-- vertical edges and closures
variable {σ₁''₂'' : R₁'' →+* R₂''} {σ₂''₁'' : R₂'' →+* R₁''}
variable {σ₁₁' : R₁ →+* R₁'} {σ₂₂' : R₂ →+* R₂'} {σ₃₃' : R₃ →+* R₃'}
variable {σ₁'₁'' : R₁' →+* R₁''} {σ₂'₂'' : R₂' →+* R₂''}
variable {σ₁₁'' : R₁ →+* R₁''} {σ₂₂'' : R₂ →+* R₂''}
-- diagonals
variable {σ₂₁' : R₂ →+* R₁'} {σ₁₂' : R₁ →+* R₂'}
variable {σ₃₂' : R₃ →+* R₂'} {σ₂₃' : R₂ →+* R₃'}
variable {σ₃₁' : R₃ →+* R₁'} {σ₁₃' : R₁ →+* R₃'}
variable {σ₂'₁'' : R₂' →+* R₁''} {σ₁'₂'' : R₁' →+* R₂''}
variable {σ₂₁'' : R₂ →+* R₁''} {σ₁₂'' : R₁ →+* R₂''}
variable [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
variable [RingHomInvPair σ₁'₂' σ₂'₁'] [RingHomInvPair σ₂'₁' σ₁'₂']
variable [RingHomInvPair σ₂₃ σ₃₂] [RingHomInvPair σ₃₂ σ₂₃]
variable [RingHomInvPair σ₂'₃' σ₃'₂'] [RingHomInvPair σ₃'₂' σ₂'₃']
variable [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃]
variable [RingHomInvPair σ₁'₃' σ₃'₁'] [RingHomInvPair σ₃'₁' σ₁'₃']
variable [RingHomInvPair σ₁''₂'' σ₂''₁''] [RingHomInvPair σ₂''₁'' σ₁''₂'']
variable [RingHomCompTriple σ₁₁' σ₁'₁'' σ₁₁''] [RingHomCompTriple σ₂₂' σ₂'₂'' σ₂₂'']
variable [RingHomCompTriple σ₁₁' σ₁'₂' σ₁₂'] [RingHomCompTriple σ₂₁ σ₁₂' σ₂₂']
variable [RingHomCompTriple σ₂₂' σ₂'₁' σ₂₁'] [RingHomCompTriple σ₁₂ σ₂₁' σ₁₁']
variable [RingHomCompTriple σ₁₁' σ₁'₃' σ₁₃'] [RingHomCompTriple σ₃₁ σ₁₃' σ₃₃']
variable [RingHomCompTriple σ₃₃' σ₃'₁' σ₃₁'] [RingHomCompTriple σ₁₃ σ₃₁' σ₁₁']
variable [RingHomCompTriple σ₂₂' σ₂'₃' σ₂₃'] [RingHomCompTriple σ₃₂ σ₂₃' σ₃₃']
variable [RingHomCompTriple σ₃₃' σ₃'₂' σ₃₂'] [RingHomCompTriple σ₂₃ σ₃₂' σ₂₂']
variable [RingHomCompTriple σ₁₁'' σ₁''₂'' σ₁₂''] [RingHomCompTriple σ₂₁ σ₁₂'' σ₂₂'']
variable [RingHomCompTriple σ₂₂'' σ₂''₁'' σ₂₁''] [RingHomCompTriple σ₁₂ σ₂₁'' σ₁₁'']
variable [RingHomCompTriple σ₁'₁'' σ₁''₂'' σ₁'₂''] [RingHomCompTriple σ₂'₁' σ₁'₂'' σ₂'₂'']
variable [RingHomCompTriple σ₂'₂'' σ₂''₁'' σ₂'₁''] [RingHomCompTriple σ₁'₂' σ₂'₁'' σ₁'₁'']
variable [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁]
variable [RingHomCompTriple σ₁'₂' σ₂'₃' σ₁'₃'] [RingHomCompTriple σ₃'₂' σ₂'₁' σ₃'₁']
/-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a
linear isomorphism between the two function spaces.
See `LinearEquiv.arrowCongrAddEquiv` for the additive version of this isomorphism that works
over a not necessarily commutative semiring. -/
def arrowCongr (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') :
(M₁ →ₛₗ[σ₁₁'] M₁') ≃ₛₗ[σ₁'₂'] (M₂ →ₛₗ[σ₂₂'] M₂') where
__ := arrowCongrAddEquiv e₁ e₂
map_smul' c f := by ext; simp [arrowCongrAddEquiv, map_smulₛₗ]
@[simp]
theorem arrowCongr_apply (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : M₁ →ₛₗ[σ₁₁'] M₁')
(x : M₂) : arrowCongr e₁ e₂ f x = e₂ (f (e₁.symm x)) :=
rfl
@[simp]
theorem arrowCongr_symm_apply (e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : M₂ →ₛₗ[σ₂₂'] M₂')
(x : M₁) : (arrowCongr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) :=
rfl
theorem arrowCongr_comp
(e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₂ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (e₃ : M₁'' ≃ₛₗ[σ₁''₂''] M₂'')
(f : M₁ →ₛₗ[σ₁₁'] M₁') (g : M₁' →ₛₗ[σ₁'₁''] M₁'') :
arrowCongr e₁ e₃ (g.comp f) = (arrowCongr e₂ e₃ g).comp (arrowCongr e₁ e₂ f) := by
ext
simp only [symm_apply_apply, arrowCongr_apply, LinearMap.comp_apply]
theorem arrowCongr_trans
(e₁ : M₁ ≃ₛₗ[σ₁₂] M₂) (e₁' : M₁' ≃ₛₗ[σ₁'₂'] M₂')
(e₂ : M₂ ≃ₛₗ[σ₂₃] M₃) (e₂' : M₂' ≃ₛₗ[σ₂'₃'] M₃') :
((arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂' : (M₂ →ₛₗ[σ₂₂'] M₂') ≃ₛₗ[σ₂'₃'] _)) =
arrowCongr (e₁.trans e₂) (e₁'.trans e₂') :=
rfl
/-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to
themselves are linearly isomorphic.
See `LinearEquiv.conjRingEquiv` for the isomorphism between endomorphism rings,
which works over a not necessarily commutative semiring. -/
-- TODO: upgrade to AlgEquiv (but this file currently cannot import AlgEquiv)
def conj (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') : Module.End R₁' M₁' ≃ₛₗ[σ₁'₂'] Module.End R₂' M₂' :=
arrowCongr e e
theorem conj_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') :
e.conj f = ((↑e : M₁' →ₛₗ[σ₁'₂'] M₂').comp f).comp (e.symm : M₂' →ₛₗ[σ₂'₁'] M₁') :=
rfl
theorem conj_apply_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') (x : M₂') :
e.conj f x = e (f (e.symm x)) :=
rfl
theorem symm_conj_apply (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₂' M₂') :
e.symm.conj f = ((↑e.symm : M₂' →ₛₗ[σ₂'₁'] M₁').comp f).comp (e : M₁' →ₛₗ[σ₁'₂'] M₂') :=
rfl
theorem conj_comp (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f g : Module.End R₁' M₁') :
e.conj (g.comp f) = (e.conj g).comp (e.conj f) :=
arrowCongr_comp e e e f g
theorem conj_trans (e₁ : M₁' ≃ₛₗ[σ₁'₂'] M₂') (e₂ : M₂' ≃ₛₗ[σ₂'₃'] M₃') :
e₁.conj.trans e₂.conj = (e₁.trans e₂).conj :=
rfl
@[simp] lemma conj_conj_symm (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₂' M₂') :
e.conj (e.symm.conj f) = f := by ext; simp [conj_apply]
@[simp] lemma conj_symm_conj (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') (f : Module.End R₁' M₁') :
e.symm.conj (e.conj f) = f := by ext; simp [conj_apply]
@[simp]
theorem conj_id (e : M₁' ≃ₛₗ[σ₁'₂'] M₂') : e.conj LinearMap.id = LinearMap.id := by
ext
simp [conj_apply]
@[simp]
theorem conj_refl (f : Module.End R M) : (refl R M).conj f = f := rfl
end arrowCongr
/-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂`
and `M` into `M₃` are linearly isomorphic. -/
def congrRight (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ[R] M →ₗ[R] M₃ :=
arrowCongr (LinearEquiv.refl R M) f
variable (M) in
/-- An `R`-linear isomorphism between two `R`-modules `M₂` and `M₃` induces an `S`-linear
isomorphism between `M₂ →ₗ[R] M` and `M₃ →ₗ[R] M`, if `M` is both an `R`-module and an
`S`-module and their actions commute. -/
def congrLeft {R} (S) [Semiring R] [Semiring S] [Module R M₂] [Module R M₃] [Module R M]
[Module S M] [SMulCommClass R S M] (e : M₂ ≃ₗ[R] M₃) : (M₂ →ₗ[R] M) ≃ₗ[S] (M₃ →ₗ[R] M) where
__ := e.arrowCongrAddEquiv (.refl ..)
map_smul' _ _ := rfl
end CommSemiring
section Field
variable [Field K] [AddCommGroup M] [Module K M]
variable (K) (M)
open LinearMap
/-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/
@[simps!]
def smulOfNeZero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M :=
smulOfUnit <| Units.mk0 a ha
end Field
end LinearEquiv
namespace Equiv
variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂]
/-- An equivalence whose underlying function is linear is a linear equivalence. -/
def toLinearEquiv (e : M ≃ M₂) (h : IsLinearMap R (e : M → M₂)) : M ≃ₗ[R] M₂ :=
{ e, h.mk' e with }
end Equiv
section FunLeft
variable (R M) [Semiring R] [AddCommMonoid M] [Module R M]
variable {m n p : Type*}
namespace LinearMap
/-- Given an `R`-module `M` and a function `m → n` between arbitrary types,
construct a linear map `(n → M) →ₗ[R] (m → M)` -/
def funLeft (f : m → n) : (n → M) →ₗ[R] m → M where
toFun := (· ∘ f)
map_add' _ _ := rfl
map_smul' _ _ := rfl
@[simp]
theorem funLeft_apply (f : m → n) (g : n → M) (i : m) : funLeft R M f g i = g (f i) :=
rfl
@[simp]
theorem funLeft_id (g : n → M) : funLeft R M _root_.id g = g :=
rfl
theorem funLeft_comp (f₁ : n → p) (f₂ : m → n) :
funLeft R M (f₁ ∘ f₂) = (funLeft R M f₂).comp (funLeft R M f₁) :=
rfl
theorem funLeft_surjective_of_injective (f : m → n) (hf : Injective f) :
Surjective (funLeft R M f) :=
hf.surjective_comp_right
theorem funLeft_injective_of_surjective (f : m → n) (hf : Surjective f) :
Injective (funLeft R M f) :=
hf.injective_comp_right
end LinearMap
namespace LinearEquiv
open LinearMap
/-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types,
construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/
def funCongrLeft (e : m ≃ n) : (n → M) ≃ₗ[R] m → M :=
LinearEquiv.ofLinear (funLeft R M e) (funLeft R M e.symm)
(LinearMap.ext fun x ↦
funext fun i ↦ by rw [id_apply, ← funLeft_comp, Equiv.symm_comp_self, LinearMap.funLeft_id])
(LinearMap.ext fun x ↦
funext fun i ↦ by rw [id_apply, ← funLeft_comp, Equiv.self_comp_symm, LinearMap.funLeft_id])
@[simp]
theorem funCongrLeft_apply (e : m ≃ n) (x : n → M) : funCongrLeft R M e x = funLeft R M e x :=
rfl
@[simp]
theorem funCongrLeft_id : funCongrLeft R M (Equiv.refl n) = LinearEquiv.refl R (n → M) :=
rfl
@[simp]
theorem funCongrLeft_comp (e₁ : m ≃ n) (e₂ : n ≃ p) :
funCongrLeft R M (Equiv.trans e₁ e₂) =
LinearEquiv.trans (funCongrLeft R M e₂) (funCongrLeft R M e₁) :=
rfl
@[simp]
theorem funCongrLeft_symm (e : m ≃ n) : (funCongrLeft R M e).symm = funCongrLeft R M e.symm :=
rfl
end LinearEquiv
end FunLeft
section Pi
namespace LinearEquiv
/-- The product over `S ⊕ T` of a family of modules is isomorphic to the product of
(the product over `S`) and (the product over `T`).
This is `Equiv.sumPiEquivProdPi` as a `LinearEquiv`.
-/
@[simps -fullyApplied +simpRhs]
def sumPiEquivProdPi (R : Type*) [Semiring R] (S T : Type*) (A : S ⊕ T → Type*)
[∀ st, AddCommMonoid (A st)] [∀ st, Module R (A st)] :
(Π (st : S ⊕ T), A st) ≃ₗ[R] (Π (s : S), A (.inl s)) × (Π (t : T), A (.inr t)) where
__ := Equiv.sumPiEquivProdPi _
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- The product `Π t : α, f t` of a family of modules is linearly isomorphic to the module
`f ⬝` when `α` only contains `⬝`.
This is `Equiv.piUnique` as a `LinearEquiv`.
-/
@[simps -fullyApplied]
def piUnique {α : Type*} [Unique α] (R : Type*) [Semiring R] (f : α → Type*)
[∀ x, AddCommMonoid (f x)] [∀ x, Module R (f x)] : (Π t : α, f t) ≃ₗ[R] f default where
__ := Equiv.piUnique _
map_add' _ _ := rfl
map_smul' _ _ := rfl
end LinearEquiv
end Pi
end AddCommMonoid
|
EffectiveEpi.lean
|
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Dagur Asgeirsson
-/
import Mathlib.Topology.Category.CompHaus.Limits
import Mathlib.Topology.Category.CompHausLike.EffectiveEpi
/-!
# Effective epimorphisms in `CompHaus`
This file proves that `EffectiveEpi`, `Epi` and `Surjective` are all equivalent in `CompHaus`.
As a consequence we deduce from the material in
`Mathlib/Topology/Category/CompHausLike/EffectiveEpi.lean` that `CompHaus` is `Preregular`
and `Precoherent`.
We also prove that for a finite family of morphisms in `CompHaus` with fixed
target, the conditions jointly surjective, jointly epimorphic and effective epimorphic are all
equivalent.
## Projects
- Define regular categories, and show that `CompHaus` is regular.
- Define coherent categories, and show that `CompHaus` is actually coherent.
-/
universe u
open CategoryTheory Limits CompHausLike
namespace CompHaus
open List in
theorem effectiveEpi_tfae
{B X : CompHaus.{u}} (π : X ⟶ B) :
TFAE
[ EffectiveEpi π
, Epi π
, Function.Surjective π
] := by
tfae_have 1 → 2 := fun _ ↦ inferInstance
tfae_have 2 ↔ 3 := epi_iff_surjective π
tfae_have 3 → 1 := fun hπ ↦ ⟨⟨effectiveEpiStruct π hπ⟩⟩
tfae_finish
instance : Preregular CompHaus :=
preregular fun _ _ _ ↦ ((effectiveEpi_tfae _).out 0 2).mp
example : Precoherent CompHaus.{u} := inferInstance
-- TODO: prove this for `Type*`
open List in
theorem effectiveEpiFamily_tfae
{α : Type} [Finite α] {B : CompHaus.{u}}
(X : α → CompHaus.{u}) (π : (a : α) → (X a ⟶ B)) :
TFAE
[ EffectiveEpiFamily X π
, Epi (Sigma.desc π)
, ∀ b : B, ∃ (a : α) (x : X a), π a x = b
] := by
tfae_have 2 → 1
| _ => by
simpa [← effectiveEpi_desc_iff_effectiveEpiFamily, (effectiveEpi_tfae (Sigma.desc π)).out 0 1]
tfae_have 1 → 2
| _ => inferInstance
tfae_have 3 → 2
| e => by
rw [epi_iff_surjective]
intro b
obtain ⟨t, x, h⟩ := e b
refine ⟨Sigma.ι X t x, ?_⟩
change (Sigma.ι X t ≫ Sigma.desc π) x = _
simpa using h
tfae_have 2 → 3
| e => by
rw [epi_iff_surjective] at e
let i : ∐ X ≅ finiteCoproduct X :=
(colimit.isColimit _).coconePointUniqueUpToIso (finiteCoproduct.isColimit _)
intro b
obtain ⟨t, rfl⟩ := e b
let q := i.hom t
refine ⟨q.1,q.2,?_⟩
have : t = i.inv (i.hom t) := show t = (i.hom ≫ i.inv) t by simp only [i.hom_inv_id]; rfl
rw [this]
change _ = (i.inv ≫ Sigma.desc π) (i.hom t)
suffices i.inv ≫ Sigma.desc π = finiteCoproduct.desc X π by
rw [this]; rfl
rw [Iso.inv_comp_eq]
apply colimit.hom_ext
rintro ⟨a⟩
simp only [i, Discrete.functor_obj, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app,
colimit.comp_coconePointUniqueUpToIso_hom_assoc]
ext; rfl
tfae_finish
theorem effectiveEpiFamily_of_jointly_surjective
{α : Type} [Finite α] {B : CompHaus.{u}}
(X : α → CompHaus.{u}) (π : (a : α) → (X a ⟶ B))
(surj : ∀ b : B, ∃ (a : α) (x : X a), π a x = b) :
EffectiveEpiFamily X π :=
((effectiveEpiFamily_tfae X π).out 2 0).mp surj
end CompHaus
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.